Package org.eclipse.swt.printing

Examples of org.eclipse.swt.printing.PrinterData


* @param data the data that will be used when the dialog is opened or null to use default data
*
* @since 3.4
*/
public void setPrinterData(PrinterData data) {
  if (data == null) data = new PrinterData();
  this.printerData = data;
}
View Full Code Here


*    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
*    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public PrinterData open() {
  PrinterData data = null;
  NSPrintPanel panel = NSPrintPanel.printPanel();
  NSPrintInfo printInfo = new NSPrintInfo(NSPrintInfo.sharedPrintInfo().copy());
  if (printerData.duplex != SWT.DEFAULT) {
    int /*long*/ settings = printInfo.PMPrintSettings();
    int duplex = printerData.duplex == PrinterData.DUPLEX_SHORT_EDGE ? OS.kPMDuplexTumble
        : printerData.duplex == PrinterData.DUPLEX_LONG_EDGE ? OS.kPMDuplexNoTumble
        : OS.kPMDuplexNone;
    OS.PMSetDuplex(settings, duplex);
  }
  /* Updating printInfo from PMPrintSettings overrides values in the printInfo dictionary. */
  printInfo.updateFromPMPrintSettings();
  if (printerData.name != null) {
    NSPrinter printer = NSPrinter.printerWithName(NSString.stringWith(printerData.name));
    if (printer != null) {
      printInfo.setPrinter(printer);
    }
  }
  NSMutableDictionary dict = printInfo.dictionary();
  dict.setValue(NSNumber.numberWithBool(printerData.collate), OS.NSPrintMustCollate);
  dict.setValue(NSNumber.numberWithInt(printerData.copyCount), OS.NSPrintCopies);
  dict.setValue(NSNumber.numberWithInt(printerData.orientation == PrinterData.LANDSCAPE ? OS.NSLandscapeOrientation : OS.NSPortraitOrientation), OS.NSPrintOrientation);
  if (printerData.printToFile) {
    dict.setValue(OS.NSPrintSaveJob, OS.NSPrintJobDisposition);
  }
  if (printerData.fileName != null && printerData.fileName.length() > 0) {
    dict.setValue(NSString.stringWith(printerData.fileName), OS.NSPrintSavePath);
  }
  dict.setValue(NSNumber.numberWithBool(printerData.scope == PrinterData.ALL_PAGES), OS.NSPrintAllPages);
  if (printerData.scope == PrinterData.PAGE_RANGE) {
    dict.setValue(NSNumber.numberWithInt(printerData.startPage), OS.NSPrintFirstPage);
    dict.setValue(NSNumber.numberWithInt(printerData.endPage), OS.NSPrintLastPage);
  }
  panel.setOptions(OS.NSPrintPanelShowsPageSetupAccessory | panel.options());
  Shell parent = getParent();
  Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
  int response;
  if ((getStyle () & SWT.SHEET) != 0) {
    initClasses();
    SWTPrintPanelDelegate delegate = (SWTPrintPanelDelegate)new SWTPrintPanelDelegate().alloc().init();
    int /*long*/ jniRef = OS.NewGlobalRef(this);
    if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
    OS.object_setInstanceVariable(delegate.id, SWT_OBJECT, jniRef);
    returnCode = -1;
    panel.beginSheetWithPrintInfo(printInfo, parent.view.window(), delegate, OS.sel_panelDidEnd_returnCode_contextInfo_, 0);
    while (returnCode == -1) {
      if (!display.readAndDispatch()) display.sleep();
    }
    if (delegate != null) delegate.release();
    if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
    response = returnCode;
  } else {
    display.setData(SET_MODAL_DIALOG, this);
    response = (int)/*64*/panel.runModalWithPrintInfo(printInfo);
  }
  display.setData(SET_MODAL_DIALOG, null);
  if (response != OS.NSCancelButton) {
    NSPrinter printer = printInfo.printer();
    NSString str = printer.name();
    data = new PrinterData(Printer.DRIVER, str.getString());
    data.printToFile = printInfo.jobDisposition().isEqual(OS.NSPrintSaveJob);
    if (data.printToFile) {
      NSString filename = new NSString(dict.objectForKey(OS.NSPrintSavePath));
      data.fileName = filename.getString();
    }
View Full Code Here

* @param data the data that will be used when the dialog is opened or null to use default data
*
* @since 3.4
*/
public void setPrinterData(PrinterData data) {
  if (data == null) data = new PrinterData();
  this.printerData = data;
}
View Full Code Here

    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;
View Full Code Here

* @param data the data that will be used when the dialog is opened or null to use default data
*
* @since 3.4
*/
public void setPrinterData(PrinterData data) {
  if (data == null) data = new PrinterData();
  this.printerData = data;
}
View Full Code Here

*    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
*    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public PrinterData open() {
  PrinterData data = null;
  NSPrintPanel panel = NSPrintPanel.printPanel();
  NSPrintInfo printInfo = new NSPrintInfo(NSPrintInfo.sharedPrintInfo().copy());
  if (printerData.duplex != SWT.DEFAULT) {
    long /*int*/ settings = printInfo.PMPrintSettings();
    int duplex = printerData.duplex == PrinterData.DUPLEX_SHORT_EDGE ? OS.kPMDuplexTumble
        : printerData.duplex == PrinterData.DUPLEX_LONG_EDGE ? OS.kPMDuplexNoTumble
        : OS.kPMDuplexNone;
    OS.PMSetDuplex(settings, duplex);
  }
  /* Updating printInfo from PMPrintSettings overrides values in the printInfo dictionary. */
  printInfo.updateFromPMPrintSettings();
  if (printerData.name != null) {
    NSPrinter printer = NSPrinter.printerWithName(NSString.stringWith(printerData.name));
    if (printer != null) {
      printInfo.setPrinter(printer);
    }
  }
  NSMutableDictionary dict = printInfo.dictionary();
  dict.setValue(NSNumber.numberWithBool(printerData.collate), OS.NSPrintMustCollate);
  dict.setValue(NSNumber.numberWithInt(printerData.copyCount), OS.NSPrintCopies);
  dict.setValue(NSNumber.numberWithInt(printerData.orientation == PrinterData.LANDSCAPE ? OS.NSLandscapeOrientation : OS.NSPortraitOrientation), OS.NSPrintOrientation);
  if (printerData.printToFile) {
    dict.setValue(OS.NSPrintSaveJob, OS.NSPrintJobDisposition);
  }
  if (printerData.fileName != null && printerData.fileName.length() > 0) {
    dict.setValue(NSString.stringWith(printerData.fileName), OS.NSPrintSavePath);
  }
  dict.setValue(NSNumber.numberWithBool(printerData.scope == PrinterData.ALL_PAGES), OS.NSPrintAllPages);
  if (printerData.scope == PrinterData.PAGE_RANGE) {
    dict.setValue(NSNumber.numberWithInt(printerData.startPage), OS.NSPrintFirstPage);
    dict.setValue(NSNumber.numberWithInt(printerData.endPage), OS.NSPrintLastPage);
  }
  panel.setOptions(OS.NSPrintPanelShowsPageSetupAccessory | panel.options());
  Shell parent = getParent();
  Display display = parent != null ? parent.getDisplay() : Display.getCurrent();
  int response;
  if ((getStyle () & SWT.SHEET) != 0) {
    initClasses();
    SWTPrintPanelDelegate delegate = (SWTPrintPanelDelegate)new SWTPrintPanelDelegate().alloc().init();
    long /*int*/ jniRef = OS.NewGlobalRef(this);
    if (jniRef == 0) SWT.error(SWT.ERROR_NO_HANDLES);
    OS.object_setInstanceVariable(delegate.id, SWT_OBJECT, jniRef);
    returnCode = -1;
    panel.beginSheetWithPrintInfo(printInfo, parent.view.window(), delegate, OS.sel_panelDidEnd_returnCode_contextInfo_, 0);
    while (returnCode == -1) {
      if (!display.readAndDispatch()) display.sleep();
    }
    if (delegate != null) delegate.release();
    if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
    response = returnCode;
  } else {
    display.setData(SET_MODAL_DIALOG, this);
    response = (int)/*64*/panel.runModalWithPrintInfo(printInfo);
  }
  display.setData(SET_MODAL_DIALOG, null);
  if (response != OS.NSCancelButton) {
    NSPrinter printer = printInfo.printer();
    NSString str = printer.name();
    data = new PrinterData(Printer.DRIVER, str.getString());
    data.printToFile = printInfo.jobDisposition().isEqual(OS.NSPrintSaveJob);
    if (data.printToFile) {
      NSString filename = new NSString(dict.objectForKey(OS.NSPrintSavePath));
      data.fileName = filename.getString();
    }
View Full Code Here

  printerCallback.dispose ();
  return findPrinter;
}

static long /*int*/ GtkPrinterFunc_FindNamedPrinter (long /*int*/ printer, long /*int*/ user_data) {
  PrinterData pd = printerDataFromGtkPrinter(printer);
  if ((pd.driver.equals(findData.driver) && pd.name.equals(findData.name))
      || (pd.driver.equals(GTK_FILE_BACKEND)) && findData.printToFile && findData.driver == null && findData.name == null) {
      // TODO: GTK_FILE_BACKEND is not GTK API (see gtk bug 345590)
    findPrinter = printer;
    OS.g_object_ref(printer);
View Full Code Here

  length = OS.strlen (address);
  buffer = new byte [length];
  OS.memmove (buffer, address, length);
  String name = new String (Converter.mbcsToWcs (null, buffer));

  return new PrinterData (backendType, name);
}
View Full Code Here

  OS.g_free(uriPtr);
  return uri;
}

static DeviceData checkNull (PrinterData data) {
  if (data == null) data = new PrinterData();
  if (data.driver == null || data.name == null) {
    PrinterData defaultData = null;
    if (data.printToFile) {
      long /*int*/ filePrinter = gtkPrinterFromPrinterData(data);
      if (filePrinter != 0) {
        defaultData = printerDataFromGtkPrinter(filePrinter);
        OS.g_object_unref(filePrinter);
View Full Code Here

  printerCallback.dispose ();
  return findPrinter;
}

static int /*long*/ GtkPrinterFunc_FindNamedPrinter (int /*long*/ printer, int /*long*/ user_data) {
  PrinterData pd = printerDataFromGtkPrinter(printer);
  if ((pd.driver.equals(findData.driver) && pd.name.equals(findData.name))
      || (pd.driver.equals(GTK_FILE_BACKEND)) && findData.printToFile && findData.driver == null && findData.name == null) {
      // TODO: GTK_FILE_BACKEND is not GTK API (see gtk bug 345590)
    findPrinter = printer;
    OS.g_object_ref(printer);
View Full Code Here

TOP

Related Classes of org.eclipse.swt.printing.PrinterData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.