Add licensing info
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / PrintDialog.cs
1 //
2 // System.Windows.Forms.PrintDialog
3 //
4 // Author:
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>
8 //
9 // (C) 2002-3 Ximian, Inc
10 //
11
12 //
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:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
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.
31 //
32 using System.Drawing.Printing;
33 using System.Runtime.Remoting;
34 using System.ComponentModel;
35 using System.Runtime.InteropServices;
36
37 namespace System.Windows.Forms {
38
39         // <summary>
40         //
41         // </summary>
42
43         public sealed class PrintDialog : CommonDialog {
44                 
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;
53
54                 //
55                 //  --- Constructor
56                 //              
57                 public PrintDialog(){
58                         Reset();                        
59                 }
60
61                 //
62                 //  --- Public Properties
63                 //              
64                 public bool AllowPrintToFile {
65                         get {return allowPrintToFile;}
66                         set {allowPrintToFile = value;}
67                 }
68                 
69                 public bool AllowSelection {
70                         get {return allowSelection;}
71                         set {allowSelection = value;}
72                 }
73                 
74                 public bool AllowSomePages {
75                         get {return allowSomePages;}
76                         set {allowSomePages = value;}
77                 }
78
79                 
80                 public PrintDocument Document {
81                         get {return document;}
82                         set {document = value;}
83                 }               
84                 
85                 public PrinterSettings PrinterSettings {
86                         get {return printerSettings;}
87                         set {printerSettings = value;}
88                 }
89                 
90                 public bool PrintToFile {
91                         get {return printToFile;}
92                         set {printToFile = value;}
93                 }
94
95                 public bool ShowHelp {          
96                         get {return showHelp;}
97                         set {showHelp = value;}
98                 }
99                 
100                 public bool ShowNetwork {
101                         get {return showNetwork;}
102                         set {showNetwork = value;}
103                 }
104                 
105                 
106
107                 //
108                 //  --- Public Methods
109                 //
110                                 
111                 public override void Reset(){
112                         
113                         allowPrintToFile = true;        
114                         allowSelection = false; 
115                         allowSomePages = false; 
116                         showHelp = false;
117                         showNetwork = true;     
118                         printToFile = false;
119                 }
120
121                 //
122                 //  --- Protected Methods
123                 //              
124                 protected override bool RunDialog(IntPtr hwndOwner)     {                       
125                         
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;
131                         pdlg.nFromPage = 0;
132                         pdlg.nToPage = 0;
133                         pdlg.nMinPage = 0;
134                         pdlg.nMaxPage = 0;      
135                         pdlg.nCopies = 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;
144                         pdlg.Flags = 0;                 
145                         
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;
152                                                                         
153                         IntPtr lfBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(pdlg));
154                 Marshal.StructureToPtr(pdlg, lfBuffer, false);                  
155                         
156                         if (Win32.PrintDlg(lfBuffer)){
157                                 
158                                 pdlg = (PRINTDLG)Marshal.PtrToStructure (lfBuffer, typeof (PRINTDLG));
159                                 
160                                 // TODO: PrinterSettings is not yet implemented, we should pass the values
161                                 // to that struct
162                                 //PrinterSettings.Copies =  pdlg.nCopies;
163                                 }
164                         
165                         return true;
166                 }
167          }
168 }