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.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 lglTemplate *template;
187 const lglTemplateFrame *frame;
189 op->priv->label = label;
190 op->priv->force_outline_flag = FALSE;
192 merge = gl_label_get_merge (label);
193 template = gl_label_get_template (label);
194 frame = (lglTemplateFrame *)template->frames->data;
196 op->priv->merge_flag = (merge != NULL);
197 op->priv->n_sheets = 1;
199 op->priv->last = lgl_template_frame_get_n_labels (frame);
200 op->priv->n_copies = 1;
202 set_page_size (op, label);
204 gtk_print_operation_set_custom_tab_label ( GTK_PRINT_OPERATION (op),
207 g_signal_connect (G_OBJECT (op), "begin-print",
208 G_CALLBACK (begin_print_cb), label);
210 g_signal_connect (G_OBJECT (op), "draw-page",
211 G_CALLBACK (draw_page_cb), label);
215 /*****************************************************************************/
216 /* Set outline flag/checkbox. */
217 /*****************************************************************************/
219 gl_print_op_force_outline (glPrintOp *op)
221 op->priv->force_outline_flag = TRUE;
225 /*****************************************************************************/
226 /* Set outline flag/checkbox. */
227 /*****************************************************************************/
229 gl_print_op_is_outline_forced (glPrintOp *op)
231 return op->priv->force_outline_flag;
235 /*****************************************************************************/
236 /* Set job parameters. */
237 /*****************************************************************************/
239 gl_print_op_set_filename (glPrintOp *op,
242 gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION (op),
248 gl_print_op_set_n_sheets (glPrintOp *op,
251 op->priv->n_sheets = n_sheets;
256 gl_print_op_set_n_copies (glPrintOp *op,
259 op->priv->n_copies = n_copies;
264 gl_print_op_set_first (glPrintOp *op,
267 op->priv->first = first;
272 gl_print_op_set_last (glPrintOp *op,
275 op->priv->last = last;
280 gl_print_op_set_collate_flag (glPrintOp *op,
281 gboolean collate_flag)
283 op->priv->collate_flag = collate_flag;
288 gl_print_op_set_outline_flag (glPrintOp *op,
289 gboolean outline_flag)
291 op->priv->outline_flag = outline_flag;
296 gl_print_op_set_reverse_flag (glPrintOp *op,
297 gboolean reverse_flag)
299 op->priv->reverse_flag = reverse_flag;
304 gl_print_op_set_crop_marks_flag (glPrintOp *op,
305 gboolean crop_marks_flag)
307 op->priv->crop_marks_flag = crop_marks_flag;
311 /*****************************************************************************/
312 /* Get job parameters. */
313 /*****************************************************************************/
315 gl_print_op_get_filename (glPrintOp *op)
317 gchar *filename = NULL;
319 g_object_get (G_OBJECT (op),
320 "export_filename", filename,
328 gl_print_op_get_n_sheets (glPrintOp *op)
330 return op->priv->n_sheets;
335 gl_print_op_get_n_copies (glPrintOp *op)
337 return op->priv->n_copies;
342 gl_print_op_get_first (glPrintOp *op)
344 return op->priv->first;
349 gl_print_op_get_last (glPrintOp *op)
351 return op->priv->last;
356 gl_print_op_get_collate_flag (glPrintOp *op)
358 return op->priv->collate_flag;
363 gl_print_op_get_outline_flag (glPrintOp *op)
365 return op->priv->outline_flag;
370 gl_print_op_get_reverse_flag (glPrintOp *op)
372 return op->priv->reverse_flag;
377 gl_print_op_get_crop_marks_flag (glPrintOp *op)
379 return op->priv->crop_marks_flag;
383 /*--------------------------------------------------------------------------*/
384 /* PRIVATE. Set page size. */
385 /*--------------------------------------------------------------------------*/
387 set_page_size (glPrintOp *op,
390 const lglTemplate *template;
395 gl_debug (DEBUG_PRINT, "begin");
397 template = gl_label_get_template (label);
398 paper = lgl_db_lookup_paper_from_id (template->paper_id);
404 name = gtk_paper_size_get_default ();
405 psize = gtk_paper_size_new (name);
407 gl_debug (DEBUG_PRINT, "Using default size = \"%s\"", name);
409 else if (lgl_db_is_paper_id_other (paper->id))
411 psize = gtk_paper_size_new_custom (paper->id,
413 template->page_width,
414 template->page_height,
416 gl_debug (DEBUG_PRINT, "Using custom size = %g x %g points",
417 template->page_width,
418 template->page_height);
423 psize = gtk_paper_size_new (paper->pwg_size);
424 gl_debug (DEBUG_PRINT, "Using PWG size \"%s\"", paper->pwg_size);
426 lgl_paper_free (paper);
428 su = gtk_page_setup_new ();
429 gtk_page_setup_set_paper_size (su, psize);
430 gtk_print_operation_set_default_page_setup (GTK_PRINT_OPERATION (op), su);
433 gtk_paper_size_free (psize);
435 gl_debug (DEBUG_PRINT, "end");
439 /*****************************************************************************/
440 /* Get print operation settings. */
441 /*****************************************************************************/
443 gl_print_op_get_settings (glPrintOp *print_op)
445 glPrintOpSettings *settings;
447 settings = g_new0 (glPrintOpSettings, 1);
451 settings->gtk_settings =
452 gtk_print_operation_get_print_settings (GTK_PRINT_OPERATION (print_op));
454 settings->outline_flag = print_op->priv->outline_flag;
455 settings->reverse_flag = print_op->priv->reverse_flag;
456 settings->crop_marks_flag = print_op->priv->crop_marks_flag;
457 settings->collate_flag = print_op->priv->collate_flag;
459 settings->first = print_op->priv->first;
460 settings->last = print_op->priv->last;
461 settings->n_sheets = print_op->priv->n_sheets;
462 settings->n_copies = print_op->priv->n_copies;
469 /*****************************************************************************/
470 /* Set print operation settings. */
471 /*****************************************************************************/
473 gl_print_op_set_settings (glPrintOp *print_op,
474 glPrintOpSettings *settings)
479 gtk_print_operation_set_print_settings (GTK_PRINT_OPERATION (print_op),
480 settings->gtk_settings);
482 print_op->priv->outline_flag = settings->outline_flag;
483 print_op->priv->reverse_flag = settings->reverse_flag;
484 print_op->priv->crop_marks_flag = settings->crop_marks_flag;
485 print_op->priv->collate_flag = settings->collate_flag;
487 print_op->priv->first = settings->first;
488 print_op->priv->last = settings->last;
489 print_op->priv->n_sheets = settings->n_sheets;
490 print_op->priv->n_copies = settings->n_copies;
496 /*****************************************************************************/
497 /* Free print operation settings structure. */
498 /*****************************************************************************/
500 gl_print_op_free_settings(glPrintOpSettings *settings)
505 if ( settings->gtk_settings )
507 g_object_unref (settings->gtk_settings);
515 /*--------------------------------------------------------------------------*/
516 /* PRIVATE. "Begin print" callback */
517 /*--------------------------------------------------------------------------*/
519 begin_print_cb (GtkPrintOperation *operation,
520 GtkPrintContext *context,
523 glPrintOp *op = GL_PRINT_OP (operation);
525 gtk_print_operation_set_n_pages (operation, op->priv->n_sheets);
530 /*--------------------------------------------------------------------------*/
531 /* PRIVATE. "Draw page" callback. */
532 /*--------------------------------------------------------------------------*/
534 draw_page_cb (GtkPrintOperation *operation,
535 GtkPrintContext *context,
539 glPrintOp *op = GL_PRINT_OP (operation);
542 cr = gtk_print_context_get_cairo_context (context);
544 if (!op->priv->merge_flag)
546 gl_print_simple_sheet (op->priv->label,
552 op->priv->outline_flag,
553 op->priv->reverse_flag,
554 op->priv->crop_marks_flag);
558 if (op->priv->collate_flag)
560 gl_print_collated_merge_sheet (op->priv->label,
565 op->priv->outline_flag,
566 op->priv->reverse_flag,
567 op->priv->crop_marks_flag,
572 gl_print_uncollated_merge_sheet (op->priv->label,
577 op->priv->outline_flag,
578 op->priv->reverse_flag,
579 op->priv->crop_marks_flag,
589 * Local Variables: -- emacs
591 * c-basic-offset: 8 -- emacs
592 * tab-width: 8 -- emacs
593 * indent-tabs-mode: nil -- emacs