Debian Codegraph @

gtk/src/printoperation.hg

raw
1 /* Copyright (C) 2006 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <glibmm/object.h>
18
19 #include <gtkmm/pagesetup.h>
20 #include <gtkmm/printcontext.h>
21 #include <gtkmm/printoperationpreview.h>
22 #include <gtkmm/printsettings.h>
23 #include <gtkmm/window.h>
24
25 _DEFS(gtkmm,gtk)
26 _PINCLUDE(glibmm/private/object_p.h)
27 _PINCLUDE(gtk/gtk.h)
28
29 namespace Gtk
30 {
31
32 _WRAP_ENUM(PrintStatus, GtkPrintStatus, decl_prefix GTKMM_API)
33 _WRAP_ENUM(PrintOperationResult, GtkPrintOperationResult, decl_prefix GTKMM_API)
34 _WRAP_ENUM(PrintOperationAction, GtkPrintOperationAction, decl_prefix GTKMM_API)
35 _WRAP_GERROR(PrintError, GtkPrintError, GTK_PRINT_ERROR, decl_prefix GTKMM_API)
36
37 /** @defgroup Printing Printing
38 */
39
40 /** PrintOperation is the high-level, portable printing API. It looks a bit different than other
41 * GTK+ dialogs such as the FileChooser, since some platforms don't expose enough infrastructure
42 * to implement a good print dialog. On such platforms, PrintOperation uses the native print
43 * dialog. On platforms which do not provide a native print dialog, GTK+ uses its own, see PrintUnixDialog.
44 *
45 * The typical way to use the high-level printing API is to create a PrintOperation object
46 * when the user chooses to print. Then you set some properties on it,such as the page size, any PrintSettings
47 * from previous print operations, the number of pages, the current page, etc.
48 *
49 * Then you start the print operation by calling run(). It will then show a dialog to
50 * let the user select a printer and options. When the user finishes the dialog various signals will be
51 * emitted by the PrintOperation for you to handle, the main one being draw_page. You should then
52 * render the page on the provided PrintContext using Cairo.
53 *
54 * @newin{2,10}
55 *
56 * @ingroup Printing
57 */
58 class GTKMM_API PrintOperation :
59 public Glib::Object,
60 public PrintOperationPreview
61 {
62 _CLASS_GOBJECT(PrintOperation, GtkPrintOperation, GTK_PRINT_OPERATION, Glib::Object, GObject, , , GTKMM_API)
63 _IMPLEMENTS_INTERFACE(PrintOperationPreview)
64
65 protected:
66 _CTOR_DEFAULT
67
68 public:
69 _WRAP_CREATE()
70
71 _WRAP_METHOD(void set_default_page_setup(const Glib::RefPtr<PageSetup>& default_page_setup),
72 gtk_print_operation_set_default_page_setup)
73
74 _WRAP_METHOD(Glib::RefPtr<PageSetup> get_default_page_setup(), gtk_print_operation_get_default_page_setup, refreturn)
75 _WRAP_METHOD(Glib::RefPtr<const PageSetup> get_default_page_setup() const, gtk_print_operation_get_default_page_setup, refreturn, constversion)
76
77 _WRAP_METHOD(void set_print_settings(const Glib::RefPtr<PrintSettings>& print_settings),
78 gtk_print_operation_set_print_settings)
79
80 _WRAP_METHOD(Glib::RefPtr<PrintSettings> get_print_settings(), gtk_print_operation_get_print_settings, refreturn)
81 _WRAP_METHOD(Glib::RefPtr<const PrintSettings> get_print_settings() const, gtk_print_operation_get_print_settings, refreturn, constversion)
82
83 _WRAP_METHOD(void set_job_name(const Glib::ustring& job_name), gtk_print_operation_set_job_name)
84 _WRAP_METHOD(void set_n_pages(int n_pages), gtk_print_operation_set_n_pages)
85 _WRAP_METHOD(void set_current_page(int current_page), gtk_print_operation_set_current_page)
86 _WRAP_METHOD(void set_use_full_page(bool use_full_page = true), gtk_print_operation_set_use_full_page)
87 _WRAP_METHOD(void set_unit(Unit unit), gtk_print_operation_set_unit)
88 _WRAP_METHOD(void set_export_filename(const std::string& filename), gtk_print_operation_set_export_filename)
89 _WRAP_METHOD(void set_track_print_status(bool track_status = true), gtk_print_operation_set_track_print_status)
90 _WRAP_METHOD(void set_show_progress (bool show_progress = true), gtk_print_operation_set_show_progress)
91 _WRAP_METHOD(void set_allow_async(bool allow_async = true), gtk_print_operation_set_allow_async)
92 _WRAP_METHOD(void set_custom_tab_label(const Glib::ustring& label), gtk_print_operation_set_custom_tab_label)
93
94 #m4 _CONVERSION(`GtkPrintOperationAction',`PrintOperationAction',`($2)$3')
95
96 /** See the run() method that takes both action and parent parameters.
97 */
98 PrintOperationResult run(PrintOperationAction action = PRINT_OPERATION_ACTION_PRINT_DIALOG);
99
100 _WRAP_METHOD(PrintOperationResult run(PrintOperationAction action, Window& parent), gtk_print_operation_run, errthrow)
101
102 _WRAP_METHOD(PrintStatus get_status() const, gtk_print_operation_get_status)
103 _WRAP_METHOD(Glib::ustring get_status_string() const, gtk_print_operation_get_status_string)
104 _WRAP_METHOD(void cancel(), gtk_print_operation_cancel)
105 _WRAP_METHOD(bool is_finished() const, gtk_print_operation_is_finished)
106
107 _WRAP_METHOD(void draw_page_finish(), gtk_print_operation_draw_page_finish)
108 _WRAP_METHOD(void set_defer_drawing(), gtk_print_operation_set_defer_drawing)
109
110
111 _WRAP_METHOD(void set_support_selection(bool support_selection = true), gtk_print_operation_set_support_selection)
112 _WRAP_METHOD(bool get_support_selection() const, gtk_print_operation_get_support_selection)
113 _WRAP_METHOD(void set_has_selection(bool has_selection = true), gtk_print_operation_set_has_selection)
114 _WRAP_METHOD(bool get_has_selection() const, gtk_print_operation_get_has_selection)
115
116 _WRAP_METHOD(void set_embed_page_setup(bool embed = true), gtk_print_operation_set_embed_page_setup)
117 _WRAP_METHOD(bool get_embed_page_setup() const, gtk_print_operation_get_embed_page_setup)
118 _WRAP_METHOD(int get_n_pages_to_print() const, gtk_print_operation_get_n_pages_to_print)
119
120 _IGNORE(gtk_print_run_page_setup_dialog, gtk_print_run_page_setup_dialog_async)
121
122 #m4 _CONVERSION(`GtkPrintOperationResult',`PrintOperationResult',`($2)$3')
123
124 _IGNORE(gtk_print_operation_get_error)
125
126 //TODO: point out in the docs that the PrintOperationResult enum may also indicate
127 // that an error occurred, and in that case it is up to him to handle it.
128 _WRAP_SIGNAL(void done(PrintOperationResult result), "done")
129
130 #m4 _CONVERSION(`GtkPrintContext*',`const Glib::RefPtr<PrintContext>&',`Glib::wrap($3, true)')
131 _WRAP_SIGNAL(void begin_print(const Glib::RefPtr<PrintContext>& context), "begin_print")
132 _WRAP_SIGNAL(bool paginate(const Glib::RefPtr<PrintContext>& context), "paginate")
133
134 #m4 _CONVERSION(`GtkPageSetup*',`const Glib::RefPtr<PageSetup>&',`Glib::wrap($3, true)')
135 _WRAP_SIGNAL(void request_page_setup(const Glib::RefPtr<PrintContext>& context, int page_no, const Glib::RefPtr<PageSetup>& setup), "request_page_setup")
136 _WRAP_SIGNAL(void draw_page(const Glib::RefPtr<PrintContext>& context, int page_nr), "draw_page")
137 _WRAP_SIGNAL(void end_print(const Glib::RefPtr<PrintContext>& context), "end_print")
138 _WRAP_SIGNAL(void status_changed(), "status_changed")
139
140 #m4 _CONVERSION(`Widget*',`GObject*',`G_OBJECT(Glib::unwrap($3))')
141 #m4 _CONVERSION(`GObject*',`Widget*',`Glib::wrap(GTK_WIDGET($3))')
142 _WRAP_SIGNAL(Widget* create_custom_widget(), "create_custom_widget")
143
144 _WRAP_SIGNAL(void custom_widget_apply(Widget* widget), "custom_widget_apply")
145
146 #m4 _CONVERSION(`GtkPrintOperationPreview*', `const Glib::RefPtr<PrintOperationPreview>&', `Glib::wrap($3, true)')
147 #m4 _CONVERSION(`const Glib::RefPtr<PrintOperationPreview>&', `GtkPrintOperationPreview*', `(Glib::unwrap($3))')
148
149 #m4 _CONVERSION(`Window*',`GtkWindow*',`Glib::unwrap($3)')
150
151 //TODO: This is causing crashes. Is it still causing crashes? murrayc.
152 _WRAP_SIGNAL(bool preview(const Glib::RefPtr<PrintOperationPreview>& preview, const Glib::RefPtr<PrintContext>& context, Window* parent), "preview")
153
154 //TODO: Remove no_default_handler when we can break ABI.
155 #m4 _CONVERSION(`GtkPrintSettings*', `const Glib::RefPtr<PrintSettings>&', `Glib::wrap($3, true)')
156 _WRAP_SIGNAL(void update_custom_widget(Widget* widget, const Glib::RefPtr<PageSetup>& setup, const Glib::RefPtr<PrintSettings>& settings), "update_custom_widget", no_default_handler)
157
158 _WRAP_PROPERTY("default_page_setup", Glib::RefPtr<PageSetup>)
159 _WRAP_PROPERTY("print_settings", Glib::RefPtr<PrintSettings>)
160 _WRAP_PROPERTY("job_name", Glib::ustring)
161 _WRAP_PROPERTY("n_pages", int)
162 _WRAP_PROPERTY("current_page", int)
163 _WRAP_PROPERTY("use_full_page", bool)
164 _WRAP_PROPERTY("track-print-status", bool)
165 _WRAP_PROPERTY("unit", Unit)
166 _WRAP_PROPERTY("show_progress", bool)
167 _WRAP_PROPERTY("allow_async", bool)
168 _WRAP_PROPERTY("export_filename", std::string)
169 _WRAP_PROPERTY("status", PrintStatus)
170 _WRAP_PROPERTY("status_string", Glib::ustring)
171 _WRAP_PROPERTY("custom_tab_label", Glib::ustring)
172 _WRAP_PROPERTY("support-selection", bool)
173 _WRAP_PROPERTY("has-selection", bool)
174 _WRAP_PROPERTY("embed-page-setup", bool)
175 _WRAP_PROPERTY("n-pages-to-print", int)
176 };
177
178 //TODO: Make these static members of a class instead of non-class functions?
179
180 //Note: gtk_run_page_setup_dialog() can take a null page_setup object, but the application should always
181 //store and reuse a page_setup object, so I see no need to provide an overload for that. murrayc.
182 //TODO: The parent parameter may also be null, so maybe we should add an overload for that.
183
184 /** Runs a page setup dialog, letting the user modify the values from page_setup.
185 * If the user cancels the dialog, the returned PageSetup is identical to that passed in @a page_setup,
186 * otherwise it contains the modifications done in the dialog.
187 *
188 * Note that this function may use a recursive mainloop to show the page setup dialog.
189 * See run_page_setup_dialog_async() if this is a problem.
190 *
191 * @param parent Transient parent.
192 * @param page_setup An existing GtkPageSetup.
193 * @param print_settings Print settings.
194 * @result A new PageSetup object.
195 *
196 * @since 2.10
197 */
198 GTKMM_API
199 Glib::RefPtr<PageSetup> run_page_setup_dialog(Window& parent,
200 const Glib::RefPtr<const PageSetup>& page_setup,
201 const Glib::RefPtr<const PrintSettings>& print_settings);
202
203 /** Runs a page setup dialog, letting the user modify the values from page_setup.
204 * If the user cancels the dialog, the returned PageSetup is identical to that passed in @a page_setup,
205 * otherwise it contains the modifications done in the dialog.
206 *
207 * Note that this function may use a recursive mainloop to show the page setup dialog.
208 * See run_page_setup_dialog_async() if this is a problem.
209 *
210 * @param parent Transient parent.
211 * @param print_settings Print settings.
212 * @result A new PageSetup object.
213 *
214 * @since 2.22
215 */
216 GTKMM_API
217 Glib::RefPtr<PageSetup> run_page_setup_dialog(Window& parent,
218 const Glib::RefPtr<const PrintSettings>& print_settings);
219
220 /** For example,
221 * void on_setup_done(const Glib::RefPtr<PageSetup>& page_setup);
222 */
223 typedef sigc::slot< void, const Glib::RefPtr<PageSetup>& > SlotPrintSetupDone;
224
225 /** Runs a page setup dialog, letting the user modify the values from page_setup.
226 *
227 * In contrast to run_page_setup_dialog(), this function returns after showing the
228 * page setup dialog on platforms that support this, and calls the @a slot from a
229 * signal handler for the ::response signal of the dialog.
230 *
231 * @param parent Transient parent.
232 * @param page_setup An existing GtkPageSetup.
233 * @param print_settings Print settings.
234 * @result A new PageSetup object.
235 * @param slot
236 *
237 * @since 2.10
238 */
239 GTKMM_API
240 void run_page_setup_dialog_async(Window& parent,
241 const Glib::RefPtr<const PageSetup>& page_setup,
242 const Glib::RefPtr<const PrintSettings>& print_settings,
243 const SlotPrintSetupDone& slot);
244
245 /** Runs a page setup dialog, letting the user modify the values from page_setup.
246 *
247 * In contrast to run_page_setup_dialog(), this function returns after showing the
248 * page setup dialog on platforms that support this, and calls the @a slot from a
249 * signal handler for the ::response signal of the dialog.
250 *
251 * @param parent Transient parent.
252 * @param print_settings Print settings.
253 * @result A new PageSetup object.
254 * @param slot
255 *
256 * @since 2.22
257 */
258 GTKMM_API
259 void run_page_setup_dialog_async(Window& parent,
260 const Glib::RefPtr<const PrintSettings>& print_settings,
261 const SlotPrintSetupDone& slot);
262
263 } // namespace Gtk