2004-04-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[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 using System.Drawing.Printing;
12 using System.Runtime.Remoting;
13 using System.ComponentModel;
14 using System.Runtime.InteropServices;
15
16 namespace System.Windows.Forms {
17
18         // <summary>
19         //
20         // </summary>
21
22         public sealed class PrintDialog : CommonDialog {
23                 
24                 private bool allowPrintToFile;  
25                 private bool allowSelection;    
26                 private bool allowSomePages;    
27                 private bool showHelp;
28                 private bool showNetwork;       
29                 private bool printToFile;
30                 private PrintDocument document = null;
31                 private PrinterSettings printerSettings;
32
33                 //
34                 //  --- Constructor
35                 //              
36                 public PrintDialog(){
37                         Reset();                        
38                 }
39
40                 //
41                 //  --- Public Properties
42                 //              
43                 public bool AllowPrintToFile {
44                         get {return allowPrintToFile;}
45                         set {allowPrintToFile = value;}
46                 }
47                 
48                 public bool AllowSelection {
49                         get {return allowSelection;}
50                         set {allowSelection = value;}
51                 }
52                 
53                 public bool AllowSomePages {
54                         get {return allowSomePages;}
55                         set {allowSomePages = value;}
56                 }
57
58                 
59                 public PrintDocument Document {
60                         get {return document;}
61                         set {document = value;}
62                 }               
63                 
64                 public PrinterSettings PrinterSettings {
65                         get {return printerSettings;}
66                         set {printerSettings = value;}
67                 }
68                 
69                 public bool PrintToFile {
70                         get {return printToFile;}
71                         set {printToFile = value;}
72                 }
73
74                 public bool ShowHelp {          
75                         get {return showHelp;}
76                         set {showHelp = value;}
77                 }
78                 
79                 public bool ShowNetwork {
80                         get {return showNetwork;}
81                         set {showNetwork = value;}
82                 }
83                 
84                 
85
86                 //
87                 //  --- Public Methods
88                 //
89                                 
90                 public override void Reset(){
91                         
92                         allowPrintToFile = true;        
93                         allowSelection = false; 
94                         allowSomePages = false; 
95                         showHelp = false;
96                         showNetwork = true;     
97                         printToFile = false;
98                 }
99
100                 //
101                 //  --- Protected Methods
102                 //              
103                 protected override bool RunDialog(IntPtr hwndOwner)     {                       
104                         
105                         PRINTDLG pdlg = new PRINTDLG();
106                         pdlg.hwndOwner = hwndOwner;                                             
107                         pdlg.lStructSize  = (uint)Marshal.SizeOf(pdlg);                         
108                         pdlg.hDevMode = (IntPtr)0;
109                         pdlg.hDevNames = (IntPtr)0;
110                         pdlg.nFromPage = 0;
111                         pdlg.nToPage = 0;
112                         pdlg.nMinPage = 0;
113                         pdlg.nMaxPage = 0;      
114                         pdlg.nCopies = 0;
115                         pdlg.hInstance = (IntPtr)0;
116                         pdlg.lCustData = (IntPtr)0;
117                         pdlg.lpfnPrintHook = (IntPtr)0;
118                         pdlg.lpfnSetupHook = (IntPtr)0;
119                         pdlg.lpPrintTemplateName = (IntPtr)0;
120                         pdlg.lpSetupTemplateName = (IntPtr)0;
121                         pdlg.hPrintTemplate = (IntPtr)0;
122                         pdlg.hSetupTemplate = (IntPtr)0;
123                         pdlg.Flags = 0;                 
124                         
125                         if (!allowPrintToFile) pdlg.Flags |=  PrintDlgFlags.PD_DISABLEPRINTTOFILE;              
126                         if (!allowSelection) pdlg.Flags |=  PrintDlgFlags.PD_NOSELECTION;                               
127                         if (!allowSomePages) pdlg.Flags |=  PrintDlgFlags.PD_NOPAGENUMS;
128                         if (showHelp) pdlg.Flags |=  PrintDlgFlags.PD_SHOWHELP;                         
129                         if (!showNetwork) pdlg.Flags |=  PrintDlgFlags.PD_NONETWORKBUTTON;
130                         if (!printToFile) pdlg.Flags |=  PrintDlgFlags.PD_DISABLEPRINTTOFILE;
131                                                                         
132                         IntPtr lfBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(pdlg));
133                 Marshal.StructureToPtr(pdlg, lfBuffer, false);                  
134                         
135                         if (Win32_WineLess.PrintDlg(lfBuffer)){
136                                 
137                                 pdlg = (PRINTDLG)Marshal.PtrToStructure (lfBuffer, typeof (PRINTDLG));
138                                 
139                                 // TODO: PrinterSettings is not yet implemented, we should pass the values
140                                 // to that struct
141                                 //PrinterSettings.Copies =  pdlg.nCopies;
142                                 }
143                         
144                         return true;
145                 }
146          }
147 }