String printerName = printerData.name;
if (printerName == null && printerData.printToFile) {
/* Find the printer name corresponding to the file backend. */
long /*int*/ printer = Printer.gtkPrinterFromPrinterData(printerData);
if (printer != 0) {
PrinterData data = Printer.printerDataFromGtkPrinter(printer);
printerName = data.name;
OS.g_object_unref(printer);
}
}
if (printerName != null) {
byte [] nameBytes = Converter.wcsToMbcs (null, printerName, true);
OS.gtk_print_settings_set_printer(settings, nameBytes);
}
switch (printerData.scope) {
case PrinterData.ALL_PAGES:
OS.gtk_print_settings_set_print_pages(settings, OS.GTK_PRINT_PAGES_ALL);
break;
case PrinterData.PAGE_RANGE:
OS.gtk_print_settings_set_print_pages(settings, OS.GTK_PRINT_PAGES_RANGES);
int [] pageRange = new int[2];
pageRange[0] = printerData.startPage - 1;
pageRange[1] = printerData.endPage - 1;
OS.gtk_print_settings_set_page_ranges(settings, pageRange, 1);
break;
case PrinterData.SELECTION:
//TODO: Not correctly implemented. May need new API. For now, set to ALL. (see gtk bug 344519)
OS.gtk_print_settings_set_print_pages(settings, OS.GTK_PRINT_PAGES_ALL);
break;
}
if ((printerData.printToFile || Printer.GTK_FILE_BACKEND.equals(printerData.driver)) && printerData.fileName != null) {
// TODO: GTK_FILE_BACKEND is not GTK API (see gtk bug 345590)
byte [] uri = Printer.uriFromFilename(printerData.fileName);
if (uri != null) {
OS.gtk_print_settings_set(settings, OS.GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
}
}
OS.gtk_print_settings_set_n_copies(settings, printerData.copyCount);
OS.gtk_print_settings_set_collate(settings, printerData.collate);
/*
* Bug in GTK. The unix dialog gives priority to the value of the non-API
* field cups-Duplex in the print_settings (which we preserve in otherData).
* The fix is to manually clear cups-Duplex before setting the duplex field.
*/
byte [] keyBuffer = Converter.wcsToMbcs (null, "cups-Duplex", true);
OS.gtk_print_settings_set(settings, keyBuffer, (byte[]) null);
if (printerData.duplex != SWT.DEFAULT) {
int duplex = printerData.duplex == PrinterData.DUPLEX_LONG_EDGE ? OS.GTK_PRINT_DUPLEX_HORIZONTAL
: printerData.duplex == PrinterData.DUPLEX_SHORT_EDGE ? OS.GTK_PRINT_DUPLEX_VERTICAL
: OS.GTK_PRINT_DUPLEX_SIMPLEX;
OS.gtk_print_settings_set_duplex (settings, duplex);
}
int orientation = printerData.orientation == PrinterData.LANDSCAPE ? OS.GTK_PAGE_ORIENTATION_LANDSCAPE : OS.GTK_PAGE_ORIENTATION_PORTRAIT;
OS.gtk_print_settings_set_orientation(settings, orientation);
OS.gtk_page_setup_set_orientation(page_setup, orientation);
OS.gtk_print_unix_dialog_set_settings(handle, settings);
OS.gtk_print_unix_dialog_set_page_setup(handle, page_setup);
if (OS.GTK_VERSION >= OS.VERSION (2, 18, 0)) {
OS.gtk_print_unix_dialog_set_embed_page_setup(handle, true);
}
OS.g_object_unref(settings);
OS.g_object_unref(page_setup);
long /*int*/ group = OS.gtk_window_get_group(0);
OS.gtk_window_group_add_window (group, handle);
OS.gtk_window_set_modal(handle, true);
PrinterData data = null;
//TODO: Handle 'Print Preview' (GTK_RESPONSE_APPLY).
Display display = getParent() != null ? getParent().getDisplay (): Display.getCurrent ();
int signalId = 0;
long /*int*/ hookId = 0;