# HG changeset patch # User Frank Benoit # Date 1202920804 -3600 # Node ID cc00a2772bf45f55793ceaa7e10cf7f9118367f0 # Parent af0e7b559478a5b39c69222cc4158e2eac171b2d PrintDialog diff -r af0e7b559478 -r cc00a2772bf4 dwt/printing/PrintDialog.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/printing/PrintDialog.d Wed Feb 13 17:40:04 2008 +0100 @@ -0,0 +1,339 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ +module dwt.printing.PrintDialog; + + +import dwt.DWT; +import dwt.DWTException; +import dwt.internal.win32.OS; +import dwt.widgets.Control; +import dwt.widgets.Dialog; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Widget; + +import dwt.printing.Printer; +import dwt.printing.PrinterData; + +import dwt.dwthelper.utils; + +/** + * Instances of this class allow the user to select + * a printer and various print-related parameters + * prior to starting a print job. + *

+ * IMPORTANT: This class is intended to be subclassed only + * within the DWT implementation. + *

+ */ + +public class PrintDialog : Dialog { + int scope_ = PrinterData.ALL_PAGES; + int startPage = 1, endPage = 1; + bool printToFile = false; + +/** + * Constructs a new instance of this class given only its parent. + * + * @param parent a composite control which will be the parent of the new instance (cannot be null) + * + * @exception IllegalArgumentException + * @exception DWTException + * + * @see DWT + * @see Widget#checkSubclass + * @see Widget#getStyle + */ +public this (Shell parent) { + this (parent, DWT.PRIMARY_MODAL); +} + +/** + * Constructs a new instance of this class given its parent + * and a style value describing its behavior and appearance. + *

+ * The style value is either one of the style constants defined in + * class DWT which is applicable to instances of this + * class, or must be built by bitwise OR'ing together + * (that is, using the int "|" operator) two or more + * of those DWT style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + *

+ * + * @param parent a composite control which will be the parent of the new instance (cannot be null) + * @param style the style of control to construct + * + * @exception IllegalArgumentException + * @exception DWTException + * + * @see DWT + * @see Widget#checkSubclass + * @see Widget#getStyle + */ +public this (Shell parent, int style) { + super (parent, style); + checkSubclass (); +} + +/** + * Returns the print job scope that the user selected + * before pressing OK in the dialog. This will be one + * of the following values: + *
+ *
ALL_PAGES
+ *
Print all pages in the current document
+ *
PAGE_RANGE
+ *
Print the range of pages specified by startPage and endPage
+ *
SELECTION
+ *
Print the current selection
+ *
+ * + * @return the scope setting that the user selected + */ +public int getScope() { + return scope_; +} + +/** + * Sets the scope of the print job. The user will see this + * setting when the dialog is opened. This can have one of + * the following values: + *
+ *
ALL_PAGES
+ *
Print all pages in the current document
+ *
PAGE_RANGE
+ *
Print the range of pages specified by startPage and endPage
+ *
SELECTION
+ *
Print the current selection
+ *
+ * + * @param scope the scope setting when the dialog is opened + */ +public void setScope(int scope_) { + this.scope_ = scope_; +} + +/** + * Returns the start page setting that the user selected + * before pressing OK in the dialog. + *

+ * This value can be from 1 to the maximum number of pages for the platform. + * Note that it is only valid if the scope is PAGE_RANGE. + *

+ * + * @return the start page setting that the user selected + */ +public int getStartPage() { + return startPage; +} + +/** + * Sets the start page that the user will see when the dialog + * is opened. + *

+ * This value can be from 1 to the maximum number of pages for the platform. + * Note that it is only valid if the scope is PAGE_RANGE. + *

+ * + * @param startPage the startPage setting when the dialog is opened + */ +public void setStartPage(int startPage) { + this.startPage = startPage; +} + +/** + * Returns the end page setting that the user selected + * before pressing OK in the dialog. + *

+ * This value can be from 1 to the maximum number of pages for the platform. + * Note that it is only valid if the scope is PAGE_RANGE. + *

+ * + * @return the end page setting that the user selected + */ +public int getEndPage() { + return endPage; +} + +/** + * Sets the end page that the user will see when the dialog + * is opened. + *

+ * This value can be from 1 to the maximum number of pages for the platform. + * Note that it is only valid if the scope is PAGE_RANGE. + *

+ * + * @param endPage the end page setting when the dialog is opened + */ +public void setEndPage(int endPage) { + this.endPage = endPage; +} + +/** + * Returns the 'Print to file' setting that the user selected + * before pressing OK in the dialog. + * + * @return the 'Print to file' setting that the user selected + */ +public bool getPrintToFile() { + return printToFile; +} + +/** + * Sets the 'Print to file' setting that the user will see + * when the dialog is opened. + * + * @param printToFile the 'Print to file' setting when the dialog is opened + */ +public void setPrintToFile(bool printToFile) { + this.printToFile = printToFile; +} + +protected void checkSubclass() { + char[] name = this.classinfo.name; + char[] validName = PrintDialog.classinfo.name; + if (validName!=/*eq*/name) { + DWT.error(DWT.ERROR_INVALID_SUBCLASS); + } +} + +/** + * Makes the receiver visible and brings it to the front + * of the display. + * + * @return a printer data object describing the desired print job parameters + * + * @exception DWTException + */ +public PrinterData open() { + PRINTDLG pd; + pd.lStructSize = PRINTDLG.sizeof; + Control parent = getParent(); + if (parent !is null) pd.hwndOwner = parent.handle; + pd.Flags = OS.PD_USEDEVMODECOPIESANDCOLLATE; + if (printToFile) pd.Flags |= OS.PD_PRINTTOFILE; + switch (scope_) { + case PrinterData.PAGE_RANGE: pd.Flags |= OS.PD_PAGENUMS; break; + case PrinterData.SELECTION: pd.Flags |= OS.PD_SELECTION; break; + default: pd.Flags |= OS.PD_ALLPAGES; + } + pd.nMinPage = 1; + pd.nMaxPage = cast(ushort)-1; + pd.nFromPage = cast(short) Math.min (0xFFFF, Math.max (1, startPage)); + pd.nToPage = cast(short) Math.min (0xFFFF, Math.max (1, endPage)); + + Display display = parent.getDisplay(); + Shell [] shells = display.getShells(); + if ((getStyle() & (DWT.APPLICATION_MODAL | DWT.SYSTEM_MODAL)) !is 0) { + for (int i=0; i