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