Package org.eclipse.swt.printing

Examples of org.eclipse.swt.printing.PrinterData


  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) {
      int /*long*/ filePrinter = gtkPrinterFromPrinterData(data);
      if (filePrinter != 0) {
        defaultData = printerDataFromGtkPrinter(filePrinter);
        OS.g_object_unref(filePrinter);
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. */
      int /*long*/ 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);
    int /*long*/ 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;
    int /*long*/ hookId = 0;
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());
  printInfo.setOrientation(printerData.orientation == PrinterData.LANDSCAPE ? OS.NSLandscapeOrientation : OS.NSPortraitOrientation);
  NSMutableDictionary dict = printInfo.dictionary()
  dict.setValue(NSNumber.numberWithBool(printerData.collate), OS.NSPrintMustCollate);
  dict.setValue(NSNumber.numberWithInt(printerData.copyCount), OS.NSPrintCopies);
  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());
  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;
    Shell parent = getParent();
    panel.beginSheetWithPrintInfo(printInfo, parent.view.window(), delegate, OS.sel_panelDidEnd_returnCode_contextInfo_, 0);
    NSApplication application = NSApplication.sharedApplication();
    while (returnCode == -1) application.run();
    if (delegate != null) delegate.release();
    if (jniRef != 0) OS.DeleteGlobalRef(jniRef);
    response = returnCode;
  } else {
    response = (int)/*64*/panel.runModalWithPrintInfo(printInfo);
  }
  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

  /**
   * Startet den Druck.
   * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
   */
  public void handleEvent(Event event) {
    PrinterData data = Printer.getDefaultPrinterData();
    if (data == null) {
      SwtUtilities.sayError(GUI.instance.shell, "Kein Standarddrucker vorhanden!");
    }
    else {
      SwtUtilities.sayError(GUI.instance.shell, "Druck noch nicht realisiert!");
View Full Code Here

public class PrintCommand extends AbstractHandler {

  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    PrintDialog printDialog = new PrintDialog(HandlerUtil.getActiveShell(event));
    PrinterData printerData = printDialog.open();
   
    if(printerData != null ) {
      Printer printer = new Printer(printerData);
      if(printer.startJob("Text")) {
        GC gc = new GC(printer);
View Full Code Here

   *
   * @since 3.4
   */
  public void print(StyledTextPrintOptions options) {
    final PrintDialog dialog= new PrintDialog(fTextWidget.getShell(), SWT.PRIMARY_MODAL);
    final PrinterData data= dialog.open();

    if (data != null) {
      final Printer printer= new Printer(data);
      final Runnable styledTextPrinter= fTextWidget.print(printer, options);

View Full Code Here

     *
     * @param elementToPrint  the {@link Composite} to be printed.
     */
    public void print(Composite elementToPrint) {
        PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
        PrinterData printerData = dialog.open();
        if (printerData == null) {
            return; // Anwender hat abgebrochen.
        }
        startPrintJob(elementToPrint, printerData);
    }
View Full Code Here

  printerCallback.dispose ();
  return printer;
}

int /*long*/ GtkPrinterFunc_FindNamedPrinter (int /*long*/ printer, int /*long*/ user_data) {
  PrinterData pd = printerDataFromGtkPrinter(printer);
  if (pd.driver.equals(data.driver) && pd.name.equals(data.name)) {
    this.printer = printer;
    OS.g_object_ref(printer);
    return 1;
  } else if (OS.GTK_VERSION < OS.VERSION (2, 10, 12) && pd.driver.equals(GTK_LPR_BACKEND)) {
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.