[sre] Do we ever try to instantiate a generic instance? Assert that we don't.
[mono.git] / mcs / class / System.Drawing / System.Drawing.Printing / PageSettings.cs
1 //
2 // System.Drawing.PageSettings.cs
3 //
4 // Authors:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Herve Poussineau (hpoussineau@fr.st)
7 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 //
9 // (C) 2002 Ximian, Inc
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System;
36 using System.Runtime.InteropServices;
37
38 namespace System.Drawing.Printing
39 {
40         [Serializable]
41         public class PageSettings : ICloneable
42         {
43                 internal bool color;
44                 internal bool landscape;
45                 internal PaperSize paperSize;
46                 internal PaperSource paperSource;
47                 internal PrinterResolution printerResolution;
48
49                 // create a new default Margins object (is 1 inch for all margins)
50                 Margins margins = new Margins();
51
52                 float hardMarginX;
53                 float hardMarginY;
54                 RectangleF printableArea;               
55                 PrinterSettings printerSettings;
56                 
57                 public PageSettings() : this(new PrinterSettings())
58                 {
59                 }
60                 
61                 public PageSettings(PrinterSettings printerSettings)
62                 {
63                         PrinterSettings = printerSettings;
64                         
65                         this.color = printerSettings.DefaultPageSettings.color;
66                         this.landscape = printerSettings.DefaultPageSettings.landscape;
67                         this.paperSize = printerSettings.DefaultPageSettings.paperSize;
68                         this.paperSource = printerSettings.DefaultPageSettings.paperSource;
69                         this.printerResolution = printerSettings.DefaultPageSettings.printerResolution;
70                 }
71                 
72                 // used by PrinterSettings.DefaultPageSettings
73                 internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
74                 {
75                         PrinterSettings = printerSettings;
76                         this.color = color;
77                         this.landscape = landscape;
78                         this.paperSize = paperSize;
79                         this.paperSource = paperSource;
80                         this.printerResolution = printerResolution;
81                 }
82
83                 //props
84                 public Rectangle Bounds{
85                         get{
86                                 int width = this.paperSize.Width;
87                                 int height = this.paperSize.Height;
88                                 
89                                 width -= this.margins.Left + this.margins.Right;
90                                 height -= this.margins.Top + this.margins.Bottom;
91                                 
92                                 if (this.landscape) {
93                                         // swap width and height
94                                         int tmp = width;
95                                         width = height;
96                                         height = tmp;
97                                 }
98                                 return new Rectangle (this.margins.Left, this.margins.Top, width, height);
99                         }
100                 }
101                 
102                 public bool Color{
103                         get{
104                                 if (!this.printerSettings.IsValid)
105                                         throw new InvalidPrinterException(this.printerSettings);
106                                 return color;
107                         }
108                         set{
109                                 color = value;
110                         }
111                 }
112                 
113                 public bool Landscape {
114                         get{
115                                 if (!this.printerSettings.IsValid)
116                                         throw new InvalidPrinterException(this.printerSettings);
117                                 return landscape;
118                         }
119                         set{
120                                 landscape = value;
121                         }
122                 }
123                 
124                 public Margins Margins{
125                         get{
126                                 if (!this.printerSettings.IsValid)
127                                         throw new InvalidPrinterException(this.printerSettings);
128                                 return margins;
129                         }
130                         set{
131                                 margins = value;
132                         }
133                 }
134                 
135                 public PaperSize PaperSize{
136                         get{
137                                 if (!this.printerSettings.IsValid)
138                                         throw new InvalidPrinterException(this.printerSettings);
139                                 return paperSize;
140                         }
141                         set{
142                                 if (value != null)
143                                         paperSize = value;
144                         }
145                 }
146                 
147                 public PaperSource PaperSource{
148                         get{
149                                 if (!this.printerSettings.IsValid)
150                                         throw new InvalidPrinterException(this.printerSettings);
151                                 return paperSource;
152                         }
153                         set{
154                                 if (value != null)
155                                         paperSource = value;
156                         }
157                 }
158                 
159                 public PrinterResolution PrinterResolution{
160                         get{
161                                 if (!this.printerSettings.IsValid)
162                                         throw new InvalidPrinterException(this.printerSettings);
163                                 return printerResolution;
164                         }
165                         set{
166                                 if (value != null)
167                                         printerResolution = value;
168                         }
169                 }
170                 
171                 public PrinterSettings PrinterSettings{
172                         get{
173                                 return printerSettings;
174                         }
175                         set{
176                                 printerSettings = value;
177                         }
178                 }               
179                 public float HardMarginX {
180                         get {
181                                 return hardMarginX;
182                         }
183                 }
184                 
185                 public float HardMarginY {
186                         get {
187                                 return hardMarginY;
188                         }
189                 }
190                 
191                 public RectangleF PrintableArea {
192                         get {
193                                 return printableArea;
194                         }
195                 }
196
197
198                 public object Clone ()
199                 {
200                         // We do a deep copy
201                         PrinterResolution pres = new PrinterResolution (this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind);
202                         PaperSource psource = new PaperSource (this.paperSource.SourceName, this.paperSource.Kind);
203                         PaperSize psize = new PaperSize (this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);
204                         psize.SetKind (this.paperSize.Kind);
205
206                         PageSettings ps = new PageSettings (this.printerSettings, this.color, this.landscape,
207                                         psize, psource, pres);
208                         ps.Margins = (Margins) this.margins.Clone ();
209                         return ps;
210                 }
211
212
213                 [MonoTODO("PageSettings.CopyToHdevmode")]
214                 public void CopyToHdevmode (IntPtr hdevmode){
215                         throw new NotImplementedException ();
216                 }
217
218
219                 [MonoTODO("PageSettings.SetHdevmode")]
220                 public void SetHdevmode (IntPtr hdevmode){
221                         throw new NotImplementedException ();
222                 }       
223
224                 public override string ToString(){
225                         string ret = "[PageSettings: Color={0}";
226                         ret += ", Landscape={1}";
227                         ret += ", Margins={2}";
228                         ret += ", PaperSize={3}";
229                         ret += ", PaperSource={4}";
230                         ret += ", PrinterResolution={5}";
231                         ret += "]";
232                         
233                         return String.Format(ret, this.color, this.landscape, this.margins, this.paperSize, this.paperSource, this.printerResolution);
234                 }
235         }
236 }