2 // System.Windows.Forms.PrintDialog
5 // stubbed out by Paul Osman (paul.osman@sympatico.ca)
6 // Dennis Hayes (dennish@raytek.com)
7 // Implemented by Jordi Mas i Hernàndez <jmas@softcatala.org>
9 // (C) 2002-3 Ximian, Inc
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Drawing.Printing;
33 using System.Runtime.Remoting;
34 using System.ComponentModel;
35 using System.Runtime.InteropServices;
37 namespace System.Windows.Forms {
43 public sealed class PrintDialog : CommonDialog {
45 private bool allowPrintToFile;
46 private bool allowSelection;
47 private bool allowSomePages;
48 private bool showHelp;
49 private bool showNetwork;
50 private bool printToFile;
51 private PrintDocument document = null;
52 private PrinterSettings printerSettings;
62 // --- Public Properties
64 public bool AllowPrintToFile {
65 get {return allowPrintToFile;}
66 set {allowPrintToFile = value;}
69 public bool AllowSelection {
70 get {return allowSelection;}
71 set {allowSelection = value;}
74 public bool AllowSomePages {
75 get {return allowSomePages;}
76 set {allowSomePages = value;}
80 public PrintDocument Document {
81 get {return document;}
82 set {document = value;}
85 public PrinterSettings PrinterSettings {
86 get {return printerSettings;}
87 set {printerSettings = value;}
90 public bool PrintToFile {
91 get {return printToFile;}
92 set {printToFile = value;}
95 public bool ShowHelp {
96 get {return showHelp;}
97 set {showHelp = value;}
100 public bool ShowNetwork {
101 get {return showNetwork;}
102 set {showNetwork = value;}
108 // --- Public Methods
111 public override void Reset(){
113 allowPrintToFile = true;
114 allowSelection = false;
115 allowSomePages = false;
122 // --- Protected Methods
124 protected override bool RunDialog(IntPtr hwndOwner) {
126 PRINTDLG pdlg = new PRINTDLG();
127 pdlg.hwndOwner = hwndOwner;
128 pdlg.lStructSize = (uint)Marshal.SizeOf(pdlg);
129 pdlg.hDevMode = (IntPtr)0;
130 pdlg.hDevNames = (IntPtr)0;
136 pdlg.hInstance = (IntPtr)0;
137 pdlg.lCustData = (IntPtr)0;
138 pdlg.lpfnPrintHook = (IntPtr)0;
139 pdlg.lpfnSetupHook = (IntPtr)0;
140 pdlg.lpPrintTemplateName = (IntPtr)0;
141 pdlg.lpSetupTemplateName = (IntPtr)0;
142 pdlg.hPrintTemplate = (IntPtr)0;
143 pdlg.hSetupTemplate = (IntPtr)0;
146 if (!allowPrintToFile) pdlg.Flags |= PrintDlgFlags.PD_DISABLEPRINTTOFILE;
147 if (!allowSelection) pdlg.Flags |= PrintDlgFlags.PD_NOSELECTION;
148 if (!allowSomePages) pdlg.Flags |= PrintDlgFlags.PD_NOPAGENUMS;
149 if (showHelp) pdlg.Flags |= PrintDlgFlags.PD_SHOWHELP;
150 if (!showNetwork) pdlg.Flags |= PrintDlgFlags.PD_NONETWORKBUTTON;
151 if (!printToFile) pdlg.Flags |= PrintDlgFlags.PD_DISABLEPRINTTOFILE;
153 IntPtr lfBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(pdlg));
154 Marshal.StructureToPtr(pdlg, lfBuffer, false);
156 if (Win32.PrintDlg(lfBuffer)){
158 pdlg = (PRINTDLG)Marshal.PtrToStructure (lfBuffer, typeof (PRINTDLG));
160 // TODO: PrinterSettings is not yet implemented, we should pass the values
162 //PrinterSettings.Copies = pdlg.nCopies;