Mercurial > projects > dwt-linux
comparison dwt/printing/PrintDialog.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 380bad9f6852 |
children | 5a30aa9820f3 |
comparison
equal
deleted
inserted
replaced
239:06a1f6829310 | 240:ce446666f5a2 |
---|---|
14 | 14 |
15 | 15 |
16 | 16 |
17 import dwt.DWT; | 17 import dwt.DWT; |
18 import dwt.DWTException; | 18 import dwt.DWTException; |
19 import dwt.internal.LONG; | |
19 import dwt.internal.gtk.OS; | 20 import dwt.internal.gtk.OS; |
20 import dwt.widgets.Dialog; | 21 import dwt.widgets.Dialog; |
21 import dwt.widgets.Display; | 22 import dwt.widgets.Display; |
22 import dwt.widgets.Shell; | 23 import dwt.widgets.Shell; |
23 import dwt.widgets.Widget; | 24 import dwt.widgets.Widget; |
37 * IMPORTANT: This class is intended to be subclassed <em>only</em> | 38 * IMPORTANT: This class is intended to be subclassed <em>only</em> |
38 * within the DWT implementation. | 39 * within the DWT implementation. |
39 * </p> | 40 * </p> |
40 */ | 41 */ |
41 public class PrintDialog : Dialog { | 42 public class PrintDialog : Dialog { |
43 PrinterData printerData; | |
42 int scope_ = PrinterData.ALL_PAGES; | 44 int scope_ = PrinterData.ALL_PAGES; |
43 int startPage = 1, endPage = 1; | 45 int startPage = 1, endPage = 1; |
44 bool printToFile = false; | 46 bool printToFile = false; |
45 | 47 |
46 GtkPrintUnixDialog* handle; | 48 GtkPrintUnixDialog* handle; |
47 int index; | 49 int index; |
48 char [] settingsData; | 50 char [] settingsData; |
49 | 51 |
50 static const String ADD_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk2.addIdleProc"; | 52 static const String GET_MODAL_DIALOG = "dwt.internal.gtk.getModalDialog"; |
51 static const String REMOVE_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk2.removeIdleProc"; | 53 static const String SET_MODAL_DIALOG = "dwt.internal.gtk.setModalDialog"; |
52 | 54 static const String ADD_IDLE_PROC_KEY = "dwt.internal.gtk.addIdleProc"; |
55 static const String REMOVE_IDLE_PROC_KEY = "dwt.internal.gtk.removeIdleProc"; | |
56 static const String GET_EMISSION_PROC_KEY = "dwt.internal.gtk.getEmissionProc"; | |
53 /** | 57 /** |
54 * Constructs a new instance of this class given only its parent. | 58 * Constructs a new instance of this class given only its parent. |
55 * | 59 * |
56 * @param parent a composite control which will be the parent of the new instance (cannot be null) | 60 * @param parent a composite control which will be the parent of the new instance (cannot be null) |
57 * | 61 * |
98 * @see DWT | 102 * @see DWT |
99 * @see Widget#checkSubclass | 103 * @see Widget#checkSubclass |
100 * @see Widget#getStyle | 104 * @see Widget#getStyle |
101 */ | 105 */ |
102 public this (Shell parent, int style) { | 106 public this (Shell parent, int style) { |
103 super (parent, style); | 107 super (parent, parent is null? style : checkStyleBit (parent, style)); |
104 checkSubclass (); | 108 checkSubclass (); |
105 } | 109 } |
106 | 110 |
107 protected override void checkSubclass() { | 111 /** |
112 * Sets the printer data that will be used when the dialog | |
113 * is opened. | |
114 * | |
115 * @param data the data that will be used when the dialog is opened | |
116 * | |
117 * @since 3.4 | |
118 */ | |
119 public void setPrinterData(PrinterData data) { | |
120 this.printerData = data; | |
121 } | |
122 | |
123 /** | |
124 * Returns the printer data that will be used when the dialog | |
125 * is opened. | |
126 * | |
127 * @return the data that will be used when the dialog is opened | |
128 * | |
129 * @since 3.4 | |
130 */ | |
131 public PrinterData getPrinterData() { | |
132 return printerData; | |
133 } | |
134 | |
135 static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) { | |
136 int mask = int0 | int1 | int2 | int3 | int4 | int5; | |
137 if ((style & mask) is 0) style |= int0; | |
138 if ((style & int0) !is 0) style = (style & ~mask) | int0; | |
139 if ((style & int1) !is 0) style = (style & ~mask) | int1; | |
140 if ((style & int2) !is 0) style = (style & ~mask) | int2; | |
141 if ((style & int3) !is 0) style = (style & ~mask) | int3; | |
142 if ((style & int4) !is 0) style = (style & ~mask) | int4; | |
143 if ((style & int5) !is 0) style = (style & ~mask) | int5; | |
144 return style; | |
145 } | |
146 | |
147 static int checkStyleBit (Shell parent, int style) { | |
148 style &= ~DWT.MIRRORED; | |
149 if ((style & (DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT)) is 0) { | |
150 if (parent !is null) { | |
151 if ((parent.getStyle () & DWT.LEFT_TO_RIGHT) !is 0) style |= DWT.LEFT_TO_RIGHT; | |
152 if ((parent.getStyle () & DWT.RIGHT_TO_LEFT) !is 0) style |= DWT.RIGHT_TO_LEFT; | |
153 } | |
154 } | |
155 return checkBits (style, DWT.LEFT_TO_RIGHT, DWT.RIGHT_TO_LEFT, 0, 0, 0, 0); | |
108 } | 156 } |
109 | 157 |
110 /** | 158 /** |
111 * Returns the print job scope that the user selected | 159 * Returns the print job scope that the user selected |
112 * before pressing OK in the dialog. This will be one | 160 * before pressing OK in the dialog. This will be one |
250 OS.GTK_PRINT_CAPABILITY_COLLATE | OS.GTK_PRINT_CAPABILITY_COPIES | OS.GTK_PRINT_CAPABILITY_PAGE_SET); | 298 OS.GTK_PRINT_CAPABILITY_COLLATE | OS.GTK_PRINT_CAPABILITY_COPIES | OS.GTK_PRINT_CAPABILITY_PAGE_SET); |
251 | 299 |
252 /* Set state into print dialog settings. */ | 300 /* Set state into print dialog settings. */ |
253 auto settings = OS.gtk_print_settings_new(); | 301 auto settings = OS.gtk_print_settings_new(); |
254 auto page_setup = OS.gtk_page_setup_new(); | 302 auto page_setup = OS.gtk_page_setup_new(); |
303 | |
304 if (printerData !is null) { | |
305 if (printerData.otherData !is null) { | |
306 Printer.restore(printerData.otherData, settings, page_setup); | |
307 } | |
308 /* Set values of settings from PrinterData. */ | |
309 Printer.setScope(settings, printerData.scope_, printerData.startPage, printerData.endPage); | |
310 //TODO: Should we look at printToFile, or driver/name for "Print to File", or both? (see gtk bug 345590) | |
311 if (printerData.printToFile) { | |
312 char* buffer = tango.stdc.stringz.toStringz(printerData.fileName); | |
313 OS.gtk_print_settings_set(settings, OS.GTK_PRINT_SETTINGS_OUTPUT_URI.ptr, buffer); | |
314 } | |
315 if (printerData.driver.equals("GtkPrintBackendFile") && printerData.name.equals("Print to File")) { //$NON-NLS-1$ //$NON-NLS-2$ | |
316 char* buffer = tango.stdc.stringz.toStringz(printerData.fileName); | |
317 OS.gtk_print_settings_set(settings, OS.GTK_PRINT_SETTINGS_OUTPUT_URI.ptr, buffer); | |
318 } | |
319 OS.gtk_print_settings_set_n_copies(settings, printerData.copyCount); | |
320 OS.gtk_print_settings_set_collate(settings, printerData.collate); | |
321 } | |
322 | |
255 Printer.setScope(settings, scope_, startPage, endPage); | 323 Printer.setScope(settings, scope_, startPage, endPage); |
324 | |
256 if (printToFile) { | 325 if (printToFile) { |
257 char* buffer = tango.stdc.stringz.toStringz( "Print to File" ); //$NON-NLS-1$ | 326 char* buffer = tango.stdc.stringz.toStringz( "Print to File" ); //$NON-NLS-1$ |
258 OS.gtk_print_settings_set_printer(settings, buffer); | 327 OS.gtk_print_settings_set_printer(settings, buffer); |
259 } | 328 } |
260 OS.gtk_print_unix_dialog_set_settings(handle, settings); | 329 OS.gtk_print_unix_dialog_set_settings(handle, settings); |
263 OS.g_object_unref(page_setup); | 332 OS.g_object_unref(page_setup); |
264 | 333 |
265 PrinterData data = null; | 334 PrinterData data = null; |
266 //TODO: Handle 'Print Preview' (GTK_RESPONSE_APPLY). | 335 //TODO: Handle 'Print Preview' (GTK_RESPONSE_APPLY). |
267 Display display = getParent() !is null ? getParent().getDisplay (): Display.getCurrent (); | 336 Display display = getParent() !is null ? getParent().getDisplay (): Display.getCurrent (); |
337 | |
338 int signalId = 0; | |
339 int /*long*/ hookId = 0; | |
340 if ((getStyle () & DWT.RIGHT_TO_LEFT) !is 0) { | |
341 signalId = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET()); | |
342 hookId = OS.g_signal_add_emission_hook (signalId, 0, cast(GSignalEmissionHook)cast(void*)(cast(LONG) display.getData (GET_EMISSION_PROC_KEY)).value, handle, null); | |
343 } | |
268 display.setData (ADD_IDLE_PROC_KEY, null); | 344 display.setData (ADD_IDLE_PROC_KEY, null); |
269 if (OS.gtk_dialog_run (handle) is OS.GTK_RESPONSE_OK) { | 345 Object oldModal = null; |
346 if (OS.gtk_window_get_modal (handle)) { | |
347 oldModal = display.getData (GET_MODAL_DIALOG); | |
348 display.setData (SET_MODAL_DIALOG, this); | |
349 } | |
350 int response = OS.gtk_dialog_run (handle); | |
351 if (OS.gtk_window_get_modal (handle)) { | |
352 display.setData (SET_MODAL_DIALOG, oldModal); | |
353 } | |
354 if ((getStyle () & DWT.RIGHT_TO_LEFT) !is 0) { | |
355 OS.g_signal_remove_emission_hook (signalId, hookId); | |
356 } | |
357 if (response is OS.GTK_RESPONSE_OK) { | |
270 auto printer = OS.gtk_print_unix_dialog_get_selected_printer(handle); | 358 auto printer = OS.gtk_print_unix_dialog_get_selected_printer(handle); |
271 if (printer !is null) { | 359 if (printer !is null) { |
360 | |
272 /* Get state from print dialog. */ | 361 /* Get state from print dialog. */ |
273 settings = OS.gtk_print_unix_dialog_get_settings(handle); // must unref | 362 settings = OS.gtk_print_unix_dialog_get_settings(handle); // must unref |
274 page_setup = OS.gtk_print_unix_dialog_get_page_setup(handle); // do not unref | 363 page_setup = OS.gtk_print_unix_dialog_get_page_setup(handle); // do not unref |
275 data = Printer.printerDataFromGtkPrinter(printer); | 364 data = Printer.printerDataFromGtkPrinter(printer); |
276 int print_pages = OS.gtk_print_settings_get_print_pages(settings); | 365 int print_pages = OS.gtk_print_settings_get_print_pages(settings); |