1 /* GTK - The GIMP Toolkit
2  * gtkprintoperationpreview.c: Abstract print preview interface
3  * Copyright (C) 2006, Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "config.h"
20 
21 #include "gtkprintoperationpreview.h"
22 #include "gtkmarshalers.h"
23 #include "gtkintl.h"
24 
25 
26 static void gtk_print_operation_preview_base_init (gpointer g_iface);
27 
28 GType
gtk_print_operation_preview_get_type(void)29 gtk_print_operation_preview_get_type (void)
30 {
31   static GType print_operation_preview_type = 0;
32 
33   if (!print_operation_preview_type)
34     {
35       const GTypeInfo print_operation_preview_info =
36       {
37         sizeof (GtkPrintOperationPreviewIface), /* class_size */
38 	gtk_print_operation_preview_base_init,   /* base_init */
39 	NULL,		/* base_finalize */
40 	NULL,
41 	NULL,		/* class_finalize */
42 	NULL,		/* class_data */
43 	0,
44 	0,              /* n_preallocs */
45 	NULL
46       };
47 
48       print_operation_preview_type =
49 	g_type_register_static (G_TYPE_INTERFACE, I_("GtkPrintOperationPreview"),
50 				&print_operation_preview_info, 0);
51 
52       g_type_interface_add_prerequisite (print_operation_preview_type, G_TYPE_OBJECT);
53     }
54 
55   return print_operation_preview_type;
56 }
57 
58 static void
gtk_print_operation_preview_base_init(gpointer g_iface)59 gtk_print_operation_preview_base_init (gpointer g_iface)
60 {
61   static gboolean initialized = FALSE;
62 
63   if (!initialized)
64     {
65       /**
66        * GtkPrintOperationPreview::ready:
67        * @preview: the object on which the signal is emitted
68        * @context: the current #GtkPrintContext
69        *
70        * The ::ready signal gets emitted once per preview operation,
71        * before the first page is rendered.
72        *
73        * A handler for this signal can be used for setup tasks.
74        */
75       g_signal_new (I_("ready"),
76 		    GTK_TYPE_PRINT_OPERATION_PREVIEW,
77 		    G_SIGNAL_RUN_LAST,
78 		    G_STRUCT_OFFSET (GtkPrintOperationPreviewIface, ready),
79 		    NULL, NULL,
80 		    NULL,
81 		    G_TYPE_NONE, 1,
82 		    GTK_TYPE_PRINT_CONTEXT);
83 
84       /**
85        * GtkPrintOperationPreview::got-page-size:
86        * @preview: the object on which the signal is emitted
87        * @context: the current #GtkPrintContext
88        * @page_setup: the #GtkPageSetup for the current page
89        *
90        * The ::got-page-size signal is emitted once for each page
91        * that gets rendered to the preview.
92        *
93        * A handler for this signal should update the @context
94        * according to @page_setup and set up a suitable cairo
95        * context, using gtk_print_context_set_cairo_context().
96        */
97       g_signal_new (I_("got-page-size"),
98 		    GTK_TYPE_PRINT_OPERATION_PREVIEW,
99 		    G_SIGNAL_RUN_LAST,
100 		    G_STRUCT_OFFSET (GtkPrintOperationPreviewIface, got_page_size),
101 		    NULL, NULL,
102 		    _gtk_marshal_VOID__OBJECT_OBJECT,
103 		    G_TYPE_NONE, 2,
104 		    GTK_TYPE_PRINT_CONTEXT,
105 		    GTK_TYPE_PAGE_SETUP);
106 
107       initialized = TRUE;
108     }
109 }
110 
111 /**
112  * gtk_print_operation_preview_render_page:
113  * @preview: a #GtkPrintOperationPreview
114  * @page_nr: the page to render
115  *
116  * Renders a page to the preview, using the print context that
117  * was passed to the #GtkPrintOperation::preview handler together
118  * with @preview.
119  *
120  * A custom iprint preview should use this function in its ::expose
121  * handler to render the currently selected page.
122  *
123  * Note that this function requires a suitable cairo context to
124  * be associated with the print context.
125  *
126  * Since: 2.10
127  */
128 void
gtk_print_operation_preview_render_page(GtkPrintOperationPreview * preview,gint page_nr)129 gtk_print_operation_preview_render_page (GtkPrintOperationPreview *preview,
130 					 gint			   page_nr)
131 {
132   g_return_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview));
133 
134   GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->render_page (preview,
135 								page_nr);
136 }
137 
138 /**
139  * gtk_print_operation_preview_end_preview:
140  * @preview: a #GtkPrintOperationPreview
141  *
142  * Ends a preview.
143  *
144  * This function must be called to finish a custom print preview.
145  *
146  * Since: 2.10
147  */
148 void
gtk_print_operation_preview_end_preview(GtkPrintOperationPreview * preview)149 gtk_print_operation_preview_end_preview (GtkPrintOperationPreview *preview)
150 {
151   g_return_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview));
152 
153   GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->end_preview (preview);
154 }
155 
156 /**
157  * gtk_print_operation_preview_is_selected:
158  * @preview: a #GtkPrintOperationPreview
159  * @page_nr: a page number
160  *
161  * Returns whether the given page is included in the set of pages that
162  * have been selected for printing.
163  *
164  * Returns: %TRUE if the page has been selected for printing
165  *
166  * Since: 2.10
167  */
168 gboolean
gtk_print_operation_preview_is_selected(GtkPrintOperationPreview * preview,gint page_nr)169 gtk_print_operation_preview_is_selected (GtkPrintOperationPreview *preview,
170 					 gint                      page_nr)
171 {
172   g_return_val_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview), FALSE);
173 
174   return GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->is_selected (preview, page_nr);
175 }
176