Next Previous Contents

7. Printing

7.1 _print_dialog

        Void_Type        _print_dialog(print_context, callback [, cbarg1, ...])
This function will create a modal dialog which your guilet can use to query the user for common printing options. The print context argument can either be NULL (in which case a default context will be generated) or an instance of the GtkPrintContext structure, with fields
   title    text to display in dialog window title bar (default: "Print")
   dest     destination of generated output: 0 = printer (default), 1 = file
   cmd      operating system command used to generate a print job (default: "lpr")
   file     an output file name (default: "slgtk.ps")
   orient   page orientation: 0 = portrait (default), 1 = landscape
   size     page size: 0 = letter (default), 1 = legal, 2 = A4

The second argument is a reference to a function that will be called when the user presses the Print dialog button. This function should be defined to receive at least one argument (the print context, updated to reflect any input given within the dialog), and optionally any callback arguments specified when the dialog was invoked. It is is important to understand that this callback, rather than the print dialog itself, is responsible for output generation.

The following S-Lang snippet gives a mock usage of the print dialog, and intentionally avoids initializing several print context fields in order to show that the dialog gives them suitable default values.

define print_cb(context, callback_message)
{

   vmessage(callback_message);                  % sample callback arg usage

   variable file;
   if (context.dest == 0)                       % generate output to printer
        file = "temp.ps";                       % mock temp file name
   else
        file = context.file;                    % else dump output to user-
                                                % specified filename

   % the print dialog uses a callback function to provide the flexibility
   % of calling an application-specific output rendering method, such as
   % the following mocked-up "export_postscript" function

   %() = export_postscript(file);

   if (context.dest == 0) {
        () = system( sprintf("%s %s",context.cmd, file));
        () = remove(file);
   }
}

define launch_print_dialog()
{
   variable context = @GtkPrintContext;
   context.title = "MyApp Print Dialog";
   context.file = "MyApp.ps";
   _print_dialog(context, &print_cb, "Hello, from MyApp print callback!");
}

7.2 _print_context_new()

        GtkPrintContext =  _print_context_new()
This function will generate a GtkPrintContext structure with default values for all fields.


Next Previous Contents