[Previous] [Contents] [Index] [Next]

PpPrintStart()

Activate a print context

Synopsis:

PhDrawContext_t *PpPrintStart( 
                     PpPrintContext_t *pc );

Description:

This function makes the provided print context pc active (i.e. from this point until the print context is deactivated, everything drawn is part of the printed output). The print context is initialized if this hasn't already been done by a call to PpPrintOpen().

All subsequent Photon draw commands are routed through this print context until:

You can print widgets by damaging them and then calling PtFlush().


Note: A widget that's damaged while a print context is active isn't clipped by its parent; if you want the widget to be clipped, damage the parent instead.

Returns:

A pointer to the previously active draw context, or NULL if the print context couldn't be made active-see errno for the specific error.

Errors:

ESRCH
No output target is specified in the print context and no printer definition could be found

Examples:

To print the contents of a scroll area:

int print_it( PtWidget_t *widget, void *data, 
              PtCallbackInfo_t *cbinfo )
{
PhDim_t dim;

...

pc = PpPrintCreatePC();

// Set the default printer for this app only.
// This overrides the default printer set via 
// the "prsetup" utility
PpPrintSetPC( pc, INITIAL_PC, 0, Pp_PC_NAME, "R&D" );

// Pop up the standard print dialog and respond accordingly.
switch( PtPrintSelection( ABW_base, &pos, "Select Printer", 
                          pc, 0 ) )
    {

    // The user has selected print or preview -- PpPrintClose() 
    // handles the difference. 

    case Pt_PRINTSEL_PRINT:
    case Pt_PRINTSEL_PREVIEW:
        PtFlush(); // Ensure no draws are pending.

        // Set the source size to be the size of the scroll
        // area's canvas. The contents of the canvas will
        // be scaled to fit the page.
        PtWidgetDim( PtValidParent( ABW_my_scrollarea ), 
                     &dim );
        PpPrintSetPC( pc, INITIAL_PC, 0, Pp_PC_SOURCE_SIZE, 
                      &dim );
        PpPrintOpen( pc );
        if( PpPrintStart( pc ) )
        {
            // Force the canvas of the ScrollArea widget
            // to draw.
            PtDamageWidget( 
                PtValidParent( ABW_my_scrollarea ) );
            PtFlush();
        }

        // Deactivate the pc and produce the printed output.
        PpPrintClose( pc );

    case Pt_PRINTSEL_CANCEL:
        break;
}

// Release the pc and its resources.
PpPrintReleasePC( pc );

return Pt_CONTINUE;
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PpPrintClose(), PpPrintCreatePC(), PpPrintGetPC(), PpPrintNewPage(), PpPrintOpen(), PpPrintReleasePC(), PpPrintSetPC(), PpPrintStop(), PpPrintWidget()


[Previous] [Contents] [Index] [Next]