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 | /** |
27 | * GtkPrintOperationPreview: |
28 | * |
29 | * `GtkPrintOperationPreview` is the interface that is used to |
30 | * implement print preview. |
31 | * |
32 | * A `GtkPrintOperationPreview` object is passed to the |
33 | * [signal@Gtk.PrintOperation::preview] signal by |
34 | * [class@Gtk.PrintOperation]. |
35 | */ |
36 | |
37 | static void gtk_print_operation_preview_base_init (gpointer g_iface); |
38 | |
39 | GType |
40 | gtk_print_operation_preview_get_type (void) |
41 | { |
42 | static GType print_operation_preview_type = 0; |
43 | |
44 | if (!print_operation_preview_type) |
45 | { |
46 | const GTypeInfo print_operation_preview_info = |
47 | { |
48 | sizeof (GtkPrintOperationPreviewIface), /* class_size */ |
49 | gtk_print_operation_preview_base_init, /* base_init */ |
50 | NULL, /* base_finalize */ |
51 | NULL, |
52 | NULL, /* class_finalize */ |
53 | NULL, /* class_data */ |
54 | 0, |
55 | 0, /* n_preallocs */ |
56 | NULL |
57 | }; |
58 | |
59 | print_operation_preview_type = |
60 | g_type_register_static (G_TYPE_INTERFACE, I_("GtkPrintOperationPreview" ), |
61 | info: &print_operation_preview_info, flags: 0); |
62 | |
63 | g_type_interface_add_prerequisite (interface_type: print_operation_preview_type, G_TYPE_OBJECT); |
64 | } |
65 | |
66 | return print_operation_preview_type; |
67 | } |
68 | |
69 | static void |
70 | gtk_print_operation_preview_base_init (gpointer g_iface) |
71 | { |
72 | static gboolean initialized = FALSE; |
73 | |
74 | if (!initialized) |
75 | { |
76 | /** |
77 | * GtkPrintOperationPreview::ready: |
78 | * @preview: the object on which the signal is emitted |
79 | * @context: the current `GtkPrintContext` |
80 | * |
81 | * The ::ready signal gets emitted once per preview operation, |
82 | * before the first page is rendered. |
83 | * |
84 | * A handler for this signal can be used for setup tasks. |
85 | */ |
86 | g_signal_new (I_("ready" ), |
87 | GTK_TYPE_PRINT_OPERATION_PREVIEW, |
88 | signal_flags: G_SIGNAL_RUN_LAST, |
89 | G_STRUCT_OFFSET (GtkPrintOperationPreviewIface, ready), |
90 | NULL, NULL, |
91 | NULL, |
92 | G_TYPE_NONE, n_params: 1, |
93 | GTK_TYPE_PRINT_CONTEXT); |
94 | |
95 | /** |
96 | * GtkPrintOperationPreview::got-page-size: |
97 | * @preview: the object on which the signal is emitted |
98 | * @context: the current `GtkPrintContext` |
99 | * @page_setup: the `GtkPageSetup` for the current page |
100 | * |
101 | * Emitted once for each page that gets rendered to the preview. |
102 | * |
103 | * A handler for this signal should update the @context |
104 | * according to @page_setup and set up a suitable cairo |
105 | * context, using [method@Gtk.PrintContext.set_cairo_context]. |
106 | */ |
107 | g_signal_new (I_("got-page-size" ), |
108 | GTK_TYPE_PRINT_OPERATION_PREVIEW, |
109 | signal_flags: G_SIGNAL_RUN_LAST, |
110 | G_STRUCT_OFFSET (GtkPrintOperationPreviewIface, got_page_size), |
111 | NULL, NULL, |
112 | c_marshaller: _gtk_marshal_VOID__OBJECT_OBJECT, |
113 | G_TYPE_NONE, n_params: 2, |
114 | GTK_TYPE_PRINT_CONTEXT, |
115 | GTK_TYPE_PAGE_SETUP); |
116 | |
117 | initialized = TRUE; |
118 | } |
119 | } |
120 | |
121 | /** |
122 | * gtk_print_operation_preview_render_page: |
123 | * @preview: a `GtkPrintOperationPreview` |
124 | * @page_nr: the page to render |
125 | * |
126 | * Renders a page to the preview. |
127 | * |
128 | * This is using the print context that was passed to the |
129 | * [signal@Gtk.PrintOperation::preview] handler together |
130 | * with @preview. |
131 | * |
132 | * A custom print preview should use this function to render |
133 | * the currently selected page. |
134 | * |
135 | * Note that this function requires a suitable cairo context to |
136 | * be associated with the print context. |
137 | */ |
138 | void |
139 | gtk_print_operation_preview_render_page (GtkPrintOperationPreview *preview, |
140 | int page_nr) |
141 | { |
142 | g_return_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview)); |
143 | |
144 | GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->render_page (preview, |
145 | page_nr); |
146 | } |
147 | |
148 | /** |
149 | * gtk_print_operation_preview_end_preview: |
150 | * @preview: a `GtkPrintOperationPreview` |
151 | * |
152 | * Ends a preview. |
153 | * |
154 | * This function must be called to finish a custom print preview. |
155 | */ |
156 | void |
157 | gtk_print_operation_preview_end_preview (GtkPrintOperationPreview *preview) |
158 | { |
159 | g_return_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview)); |
160 | |
161 | GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->end_preview (preview); |
162 | } |
163 | |
164 | /** |
165 | * gtk_print_operation_preview_is_selected: |
166 | * @preview: a `GtkPrintOperationPreview` |
167 | * @page_nr: a page number |
168 | * |
169 | * Returns whether the given page is included in the set of pages that |
170 | * have been selected for printing. |
171 | * |
172 | * Returns: %TRUE if the page has been selected for printing |
173 | */ |
174 | gboolean |
175 | gtk_print_operation_preview_is_selected (GtkPrintOperationPreview *preview, |
176 | int page_nr) |
177 | { |
178 | g_return_val_if_fail (GTK_IS_PRINT_OPERATION_PREVIEW (preview), FALSE); |
179 | |
180 | return GTK_PRINT_OPERATION_PREVIEW_GET_IFACE (preview)->is_selected (preview, page_nr); |
181 | } |
182 | |