PrinterData[] printers = Printer.getPrinterList(); if (printers.length > 0) return printers[0]; return null;
if (OS.GTK_VERSION < OS.VERSION (2, 9, 0)) { return Printer.getDefaultPrinterData(); } else { byte [] titleBytes = Converter.wcsToMbcs (null, getText(), true); int  topHandle = getParent().handle; while (topHandle != 0 && !OS.GTK_IS_WINDOW(topHandle)) { topHandle = OS.gtk_widget_get_parent(topHandle); } handle = OS.gtk_print_unix_dialog_new(titleBytes, topHandle);   OS.gtk_print_unix_dialog_set_current_page(handle, -1);  OS.gtk_print_unix_dialog_set_manual_capabilities(handle, OS.GTK_PRINT_CAPABILITY_COLLATE | OS.GTK_PRINT_CAPABILITY_COPIES | OS.GTK_PRINT_CAPABILITY_PAGE_SET);   int  settings = OS.gtk_print_settings_new(); int  page_setup = OS.gtk_page_setup_new(); Printer.setScope(settings, scope, startPage, endPage); if (printToFile) { byte [] buffer = Converter.wcsToMbcs (null, "Print to File", true); OS.gtk_print_settings_set_printer(settings, buffer); } OS.gtk_print_unix_dialog_set_settings(handle, settings); OS.gtk_print_unix_dialog_set_page_setup(handle, page_setup); OS.g_object_unref(settings); OS.g_object_unref(page_setup);  PrinterData data = null;  if (OS.gtk_dialog_run (handle) == OS.GTK_RESPONSE_OK) { int  printer = OS.gtk_print_unix_dialog_get_selected_printer(handle); if (printer != 0) {  settings = OS.gtk_print_unix_dialog_get_settings(handle); page_setup = OS.gtk_print_unix_dialog_get_page_setup(handle); data = Printer.printerDataFromGtkPrinter(printer); int print_pages = OS.gtk_print_settings_get_print_pages(settings); switch (print_pages) { case OS.GTK_PRINT_PAGES_ALL: scope = PrinterData.ALL_PAGES; break; case OS.GTK_PRINT_PAGES_RANGES: scope = PrinterData.PAGE_RANGE; int[] num_ranges = new int[1]; int  page_ranges = OS.gtk_print_settings_get_page_ranges(settings, num_ranges); int [] pageRange = new int[2]; int length = num_ranges[0]; int min = Integer.MAX_VALUE, max = 0; for (int i = 0; i < length; i++) { OS.memmove(pageRange, page_ranges + i * pageRange.length * 4, pageRange.length * 4); min = Math.min(min, pageRange[0] + 1); max = Math.max(max, pageRange[1] + 1); } OS.g_free(page_ranges); startPage = min == Integer.MAX_VALUE ? 1 : min; endPage = max == 0 ? 1 : max; break; case OS.GTK_PRINT_PAGES_CURRENT:  scope = PrinterData.SELECTION; startPage = endPage = OS.gtk_print_unix_dialog_get_current_page(handle); break; }  printToFile = data.name.equals("Print to File"); if (printToFile) { int  address = OS.gtk_print_settings_get(settings, OS.GTK_PRINT_SETTINGS_OUTPUT_URI); int length = OS.strlen (address); byte [] buffer = new byte [length]; OS.memmove (buffer, address, length); data.fileName = new String (Converter.mbcsToWcs (null, buffer)); }  data.scope = scope; data.startPage = startPage; data.endPage = endPage; data.printToFile = printToFile; data.copyCount = OS.gtk_print_settings_get_n_copies(settings); data.collate = OS.gtk_print_settings_get_collate(settings);   Callback printSettingsCallback = new Callback(this, "GtkPrintSettingsFunc", 3); int  GtkPrintSettingsFunc = printSettingsCallback.getAddress(); if (GtkPrintSettingsFunc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); index = 0; settingsData = new byte[1024]; OS.gtk_print_settings_foreach (settings, GtkPrintSettingsFunc, 0); printSettingsCallback.dispose (); index++;   store("orientation", OS.gtk_page_setup_get_orientation(page_setup)); store("top_margin", OS.gtk_page_setup_get_top_margin(page_setup, OS.GTK_UNIT_MM)); store("bottom_margin", OS.gtk_page_setup_get_bottom_margin(page_setup, OS.GTK_UNIT_MM)); store("left_margin", OS.gtk_page_setup_get_left_margin(page_setup, OS.GTK_UNIT_MM)); store("right_margin", OS.gtk_page_setup_get_right_margin(page_setup, OS.GTK_UNIT_MM)); int  paper_size = OS.gtk_page_setup_get_paper_size(page_setup); storeBytes("paper_size_name", OS.gtk_paper_size_get_name(paper_size)); storeBytes("paper_size_display_name", OS.gtk_paper_size_get_display_name(paper_size)); storeBytes("paper_size_ppd_name", OS.gtk_paper_size_get_ppd_name(paper_size)); store("paper_size_width", OS.gtk_paper_size_get_width(paper_size, OS.GTK_UNIT_MM)); store("paper_size_height", OS.gtk_paper_size_get_height(paper_size, OS.GTK_UNIT_MM)); store("paper_size_is_custom", OS.gtk_paper_size_is_custom(paper_size)); data.otherData = settingsData; OS.g_object_unref(settings); } } OS.gtk_widget_destroy (handle); return data; }
public PrinterData open() {	/* Return the first printer in the list */	PrinterData[] printers = Printer.getPrinterList();	if (printers.length > 0) return printers[0];	return null;}