Session Functions
[Printing]


Data Structures

struct  PrintSession

Functions

PrintSessiongnc_print_session_create (gboolean hand_built_pages)
void gnc_print_session_destroy (PrintSession *ps)
void gnc_print_session_done (PrintSession *ps)


Function Documentation

PrintSession* gnc_print_session_create ( gboolean  hand_built_pages  ) 

Create a new print 'session'. Once created, a series of commands can be issued on the session to create the output page. The output will be printed when the session is done. This function will present the standard print/preview selection box to the user and wait for the result.

If the hand_built_pages argument is set to TRUE, this function will perform a couple of extra setup steps. Specifically it will call the gnome begin page, set color and set font functions. The code will also call close page when the gnc_print_session_done function is called.

Parameters:
hand_built_pages If TRUE, this funciton will perform extra setup.
Returns:
A pointer to the data structure describing this print session.

Definition at line 130 of file print-session.c.

00131 {
00132   PrintSession * ps = g_new0(PrintSession, 1);
00133   GnomePrintConfig *config;
00134   GtkWidget *dialog;
00135   gint response;
00136 
00137   /* Ask the user what to do with the output */
00138   config = gnome_print_config_default();
00139   ps->job = gnome_print_job_new(config);
00140   g_object_unref(config);
00141   dialog = gnome_print_dialog_new(ps->job, (guchar *) _("Print GnuCash Document"), 0);
00142   response = gtk_dialog_run(GTK_DIALOG(dialog));
00143   switch (response) {
00144     case GNOME_PRINT_DIALOG_RESPONSE_PRINT: 
00145     case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
00146       gtk_widget_destroy(dialog);
00147       ps->context = gnome_print_job_get_context(ps->job);
00148       break;
00149     
00150     default:
00151       gtk_widget_destroy(dialog);
00152       g_object_unref(ps->job);
00153       g_free(ps);
00154       return NULL;
00155   }
00156 
00157   ps->hand_built_pages = hand_built_pages;
00158   ps->print_type = response;
00159 
00160   ps->default_font = gnome_font_find_closest((guchar *)"Sans Regular", 12);
00161 
00162   if (hand_built_pages) {
00163     gnome_print_beginpage(ps->context, (guchar *)"");
00164     gnome_print_setrgbcolor(ps->context, 0.0, 0.0, 0.0);
00165     gnome_print_setfont(ps->context, ps->default_font);
00166   }
00167   return ps;
00168 }

void gnc_print_session_destroy ( PrintSession ps  ) 

Destroy a print 'session' without producing any output.

Parameters:
ps A pointer to the session to be destroyed.

Definition at line 171 of file print-session.c.

00172 {
00173   g_object_unref(ps->job);
00174   g_object_unref(ps->default_font);
00175 
00176   g_free(ps);
00177 }

void gnc_print_session_done ( PrintSession ps  ) 

Finish a print 'session'. The output from this session will be printed to the device selected when the session was created.

Parameters:
ps A pointer to the session to be closed.

Definition at line 181 of file print-session.c.

00182 {
00183   GtkWidget *widget;
00184 
00185   if (ps->hand_built_pages) {
00186     gnome_print_showpage(ps->context);
00187   }
00188   gnome_print_job_close (ps->job);
00189 
00190   switch (ps->print_type) {
00191     case GNOME_PRINT_DIALOG_RESPONSE_PRINT: 
00192       gnome_print_job_print(ps->job);
00193       break;
00194 
00195     case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
00196       widget = gnome_print_job_preview_new(ps->job, (guchar*)"Print Preview");
00197       gtk_widget_show(widget);
00198       break;
00199     
00200     default:
00201       break;
00202   }
00203 }


Generated on Fri Oct 10 05:06:57 2008 for GnuCash by  doxygen 1.5.2