3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
25 #include <glib/gi18n.h>
31 #include <libglabels/libglabels.h>
38 /*===========================================*/
39 /* Private data types */
40 /*===========================================*/
42 struct _glPrintOpPrivate {
46 gboolean force_outline_flag;
50 gboolean outline_flag;
51 gboolean reverse_flag;
52 gboolean crop_marks_flag;
54 gboolean collate_flag;
64 struct _glPrintOpSettings
67 GtkPrintSettings *gtk_settings;
69 gboolean outline_flag;
70 gboolean reverse_flag;
71 gboolean crop_marks_flag;
72 gboolean collate_flag;
82 /*===========================================*/
84 /*===========================================*/
87 /*===========================================*/
88 /* Local function prototypes */
89 /*===========================================*/
91 static void gl_print_op_finalize (GObject *object);
93 static void set_page_size (glPrintOp *op,
96 static void begin_print_cb (GtkPrintOperation *operation,
97 GtkPrintContext *context,
100 static void draw_page_cb (GtkPrintOperation *operation,
101 GtkPrintContext *context,
106 /*****************************************************************************/
107 /* Boilerplate object stuff. */
108 /*****************************************************************************/
109 G_DEFINE_TYPE (glPrintOp, gl_print_op, GTK_TYPE_PRINT_OPERATION);
113 gl_print_op_class_init (glPrintOpClass *class)
115 GObjectClass *object_class = G_OBJECT_CLASS (class);
117 gl_debug (DEBUG_PRINT, "");
119 gl_print_op_parent_class = g_type_class_peek_parent (class);
121 object_class->finalize = gl_print_op_finalize;
126 gl_print_op_init (glPrintOp *op)
128 gl_debug (DEBUG_PRINT, "");
130 gtk_print_operation_set_use_full_page (GTK_PRINT_OPERATION (op), TRUE);
132 gtk_print_operation_set_unit (GTK_PRINT_OPERATION (op), GTK_UNIT_POINTS);
134 op->priv = g_new0 (glPrintOpPrivate, 1);
140 gl_print_op_finalize (GObject *object)
142 glPrintOp *op = GL_PRINT_OP (object);
144 gl_debug (DEBUG_PRINT, "");
146 g_return_if_fail (object != NULL);
147 g_return_if_fail (GL_IS_PRINT_OP (op));
148 g_return_if_fail (op->priv != NULL);
150 g_object_unref (G_OBJECT(op->priv->label));
151 g_free (op->priv->filename);
154 G_OBJECT_CLASS (gl_print_op_parent_class)->finalize (object);
160 /*****************************************************************************/
162 /*****************************************************************************/
164 gl_print_op_new (glLabel *label)
168 gl_debug (DEBUG_PRINT, "");
170 op = GL_PRINT_OP (g_object_new (GL_TYPE_PRINT_OP, NULL));
172 gl_print_op_construct (GL_PRINT_OP(op), label);
178 /*****************************************************************************/
179 /* Construct print op. */
180 /*****************************************************************************/
182 gl_print_op_construct (glPrintOp *op,
185 glMerge *merge = NULL;
186 const lglTemplateFrame *frame;
188 op->priv->label = label;
189 op->priv->force_outline_flag = FALSE;
191 merge = gl_label_get_merge (label);
192 frame = (lglTemplateFrame *)label->template->frames->data;
194 op->priv->merge_flag = (merge != NULL);
195 op->priv->n_sheets = 1;
197 op->priv->last = lgl_template_frame_get_n_labels (frame);
198 op->priv->n_copies = 1;
200 set_page_size (op, label);
202 gtk_print_operation_set_custom_tab_label ( GTK_PRINT_OPERATION (op),
205 g_signal_connect (G_OBJECT (op), "begin-print",
206 G_CALLBACK (begin_print_cb), label);
208 g_signal_connect (G_OBJECT (op), "draw-page",
209 G_CALLBACK (draw_page_cb), label);
213 /*****************************************************************************/
214 /* Set outline flag/checkbox. */
215 /*****************************************************************************/
217 gl_print_op_force_outline (glPrintOp *op)
219 op->priv->force_outline_flag = TRUE;
223 /*****************************************************************************/
224 /* Set outline flag/checkbox. */
225 /*****************************************************************************/
227 gl_print_op_is_outline_forced (glPrintOp *op)
229 return op->priv->force_outline_flag;
233 /*****************************************************************************/
234 /* Set job parameters. */
235 /*****************************************************************************/
237 gl_print_op_set_filename (glPrintOp *op,
240 gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION (op),
246 gl_print_op_set_n_sheets (glPrintOp *op,
249 op->priv->n_sheets = n_sheets;
254 gl_print_op_set_n_copies (glPrintOp *op,
257 op->priv->n_copies = n_copies;
262 gl_print_op_set_first (glPrintOp *op,
265 op->priv->first = first;
270 gl_print_op_set_last (glPrintOp *op,
273 op->priv->last = last;
278 gl_print_op_set_collate_flag (glPrintOp *op,
279 gboolean collate_flag)
281 op->priv->collate_flag = collate_flag;
286 gl_print_op_set_outline_flag (glPrintOp *op,
287 gboolean outline_flag)
289 op->priv->outline_flag = outline_flag;
294 gl_print_op_set_reverse_flag (glPrintOp *op,
295 gboolean reverse_flag)
297 op->priv->reverse_flag = reverse_flag;
302 gl_print_op_set_crop_marks_flag (glPrintOp *op,
303 gboolean crop_marks_flag)
305 op->priv->crop_marks_flag = crop_marks_flag;
309 /*****************************************************************************/
310 /* Get job parameters. */
311 /*****************************************************************************/
313 gl_print_op_get_filename (glPrintOp *op)
315 gchar *filename = NULL;
317 g_object_get (G_OBJECT (op),
318 "export_filename", filename,
326 gl_print_op_get_n_sheets (glPrintOp *op)
328 return op->priv->n_sheets;
333 gl_print_op_get_n_copies (glPrintOp *op)
335 return op->priv->n_copies;
340 gl_print_op_get_first (glPrintOp *op)
342 return op->priv->first;
347 gl_print_op_get_last (glPrintOp *op)
349 return op->priv->last;
354 gl_print_op_get_collate_flag (glPrintOp *op)
356 return op->priv->collate_flag;
361 gl_print_op_get_outline_flag (glPrintOp *op)
363 return op->priv->outline_flag;
368 gl_print_op_get_reverse_flag (glPrintOp *op)
370 return op->priv->reverse_flag;
375 gl_print_op_get_crop_marks_flag (glPrintOp *op)
377 return op->priv->crop_marks_flag;
381 /*--------------------------------------------------------------------------*/
382 /* PRIVATE. Set page size. */
383 /*--------------------------------------------------------------------------*/
385 set_page_size (glPrintOp *op,
392 gl_debug (DEBUG_PRINT, "begin");
394 paper = lgl_db_lookup_paper_from_id (label->template->paper_id);
400 name = gtk_paper_size_get_default ();
401 psize = gtk_paper_size_new (name);
403 gl_debug (DEBUG_PRINT, "Using default size = \"%s\"", name);
405 else if (lgl_db_is_paper_id_other (paper->id))
407 psize = gtk_paper_size_new_custom (paper->id,
409 label->template->page_width,
410 label->template->page_height,
412 gl_debug (DEBUG_PRINT, "Using custom size = %g x %g points",
413 label->template->page_width,
414 label->template->page_height);
419 psize = gtk_paper_size_new (paper->pwg_size);
420 gl_debug (DEBUG_PRINT, "Using PWG size \"%s\"", paper->pwg_size);
422 lgl_paper_free (paper);
424 su = gtk_page_setup_new ();
425 gtk_page_setup_set_paper_size (su, psize);
426 gtk_print_operation_set_default_page_setup (GTK_PRINT_OPERATION (op), su);
429 gtk_paper_size_free (psize);
431 gl_debug (DEBUG_PRINT, "end");
435 /*****************************************************************************/
436 /* Get print operation settings. */
437 /*****************************************************************************/
439 gl_print_op_get_settings (glPrintOp *print_op)
441 glPrintOpSettings *settings;
443 settings = g_new0 (glPrintOpSettings, 1);
447 settings->gtk_settings =
448 gtk_print_operation_get_print_settings (GTK_PRINT_OPERATION (print_op));
450 settings->outline_flag = print_op->priv->outline_flag;
451 settings->reverse_flag = print_op->priv->reverse_flag;
452 settings->crop_marks_flag = print_op->priv->crop_marks_flag;
453 settings->collate_flag = print_op->priv->collate_flag;
455 settings->first = print_op->priv->first;
456 settings->last = print_op->priv->last;
457 settings->n_sheets = print_op->priv->n_sheets;
458 settings->n_copies = print_op->priv->n_copies;
465 /*****************************************************************************/
466 /* Set print operation settings. */
467 /*****************************************************************************/
469 gl_print_op_set_settings (glPrintOp *print_op,
470 glPrintOpSettings *settings)
475 gtk_print_operation_set_print_settings (GTK_PRINT_OPERATION (print_op),
476 settings->gtk_settings);
478 print_op->priv->outline_flag = settings->outline_flag;
479 print_op->priv->reverse_flag = settings->reverse_flag;
480 print_op->priv->crop_marks_flag = settings->crop_marks_flag;
481 print_op->priv->collate_flag = settings->collate_flag;
483 print_op->priv->first = settings->first;
484 print_op->priv->last = settings->last;
485 print_op->priv->n_sheets = settings->n_sheets;
486 print_op->priv->n_copies = settings->n_copies;
492 /*****************************************************************************/
493 /* Free print operation settings structure. */
494 /*****************************************************************************/
496 gl_print_op_free_settings(glPrintOpSettings *settings)
501 if ( settings->gtk_settings )
503 g_object_unref (settings->gtk_settings);
511 /*--------------------------------------------------------------------------*/
512 /* PRIVATE. "Begin print" callback */
513 /*--------------------------------------------------------------------------*/
515 begin_print_cb (GtkPrintOperation *operation,
516 GtkPrintContext *context,
519 glPrintOp *op = GL_PRINT_OP (operation);
521 gtk_print_operation_set_n_pages (operation, op->priv->n_sheets);
526 /*--------------------------------------------------------------------------*/
527 /* PRIVATE. "Draw page" callback. */
528 /*--------------------------------------------------------------------------*/
530 draw_page_cb (GtkPrintOperation *operation,
531 GtkPrintContext *context,
535 glPrintOp *op = GL_PRINT_OP (operation);
538 cr = gtk_print_context_get_cairo_context (context);
540 if (!op->priv->merge_flag)
542 gl_print_simple_sheet (op->priv->label,
548 op->priv->outline_flag,
549 op->priv->reverse_flag,
550 op->priv->crop_marks_flag);
554 if (op->priv->collate_flag)
556 gl_print_collated_merge_sheet (op->priv->label,
561 op->priv->outline_flag,
562 op->priv->reverse_flag,
563 op->priv->crop_marks_flag,
568 gl_print_uncollated_merge_sheet (op->priv->label,
573 op->priv->outline_flag,
574 op->priv->reverse_flag,
575 op->priv->crop_marks_flag,
585 * Local Variables: -- emacs
587 * c-basic-offset: 8 -- emacs
588 * tab-width: 8 -- emacs
589 * indent-tabs-mode: nil -- emacs