Merge pull request #5014 from vkargov/vk-kasha
[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 #pragma warning disable 649
52                 float hardMarginX;
53                 float hardMarginY;
54                 RectangleF printableArea;               
55                 PrinterSettings printerSettings;
56 #pragma warning restore 649
57                 
58                 public PageSettings() : this(new PrinterSettings())
59                 {
60                 }
61                 
62                 public PageSettings(PrinterSettings printerSettings)
63                 {
64                         PrinterSettings = printerSettings;
65                         
66                         this.color = printerSettings.DefaultPageSettings.color;
67                         this.landscape = printerSettings.DefaultPageSettings.landscape;
68                         this.paperSize = printerSettings.DefaultPageSettings.paperSize;
69                         this.paperSource = printerSettings.DefaultPageSettings.paperSource;
70                         this.printerResolution = printerSettings.DefaultPageSettings.printerResolution;
71                 }
72                 
73                 // used by PrinterSettings.DefaultPageSettings
74                 internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
75                 {
76                         PrinterSettings = printerSettings;
77                         this.color = color;
78                         this.landscape = landscape;
79                         this.paperSize = paperSize;
80                         this.paperSource = paperSource;
81                         this.printerResolution = printerResolution;
82                 }
83
84                 //props
85                 public Rectangle Bounds{
86                         get{
87                                 int width = this.paperSize.Width;
88                                 int height = this.paperSize.Height;
89                                 
90                                 width -= this.margins.Left + this.margins.Right;
91                                 height -= this.margins.Top + this.margins.Bottom;
92                                 
93                                 if (this.landscape) {
94                                         // swap width and height
95                                         int tmp = width;
96                                         width = height;
97                                         height = tmp;
98                                 }
99                                 return new Rectangle (this.margins.Left, this.margins.Top, width, height);
100                         }
101                 }
102                 
103                 public bool Color{
104                         get{
105                                 if (!this.printerSettings.IsValid)
106                                         throw new InvalidPrinterException(this.printerSettings);
107                                 return color;
108                         }
109                         set{
110                                 color = value;
111                         }
112                 }
113                 
114                 public bool Landscape {
115                         get{
116                                 if (!this.printerSettings.IsValid)
117                                         throw new InvalidPrinterException(this.printerSettings);
118                                 return landscape;
119                         }
120                         set{
121                                 landscape = value;
122                         }
123                 }
124                 
125                 public Margins Margins{
126                         get{
127                                 if (!this.printerSettings.IsValid)
128                                         throw new InvalidPrinterException(this.printerSettings);
129                                 return margins;
130                         }
131                         set{
132                                 margins = value;
133                         }
134                 }
135                 
136                 public PaperSize PaperSize{
137                         get{
138                                 if (!this.printerSettings.IsValid)
139                                         throw new InvalidPrinterException(this.printerSettings);
140                                 return paperSize;
141                         }
142                         set{
143                                 if (value != null)
144                                         paperSize = value;
145                         }
146                 }
147                 
148                 public PaperSource PaperSource{
149                         get{
150                                 if (!this.printerSettings.IsValid)
151                                         throw new InvalidPrinterException(this.printerSettings);
152                                 return paperSource;
153                         }
154                         set{
155                                 if (value != null)
156                                         paperSource = value;
157                         }
158                 }
159                 
160                 public PrinterResolution PrinterResolution{
161                         get{
162                                 if (!this.printerSettings.IsValid)
163                                         throw new InvalidPrinterException(this.printerSettings);
164                                 return printerResolution;
165                         }
166                         set{
167                                 if (value != null)
168                                         printerResolution = value;
169                         }
170                 }
171                 
172                 public PrinterSettings PrinterSettings{
173                         get{
174                                 return printerSettings;
175                         }
176                         set{
177                                 printerSettings = value;
178                         }
179                 }               
180                 public float HardMarginX {
181                         get {
182                                 return hardMarginX;
183                         }
184                 }
185                 
186                 public float HardMarginY {
187                         get {
188                                 return hardMarginY;
189                         }
190                 }
191                 
192                 public RectangleF PrintableArea {
193                         get {
194                                 return printableArea;
195                         }
196                 }
197
198
199                 public object Clone ()
200                 {
201                         // We do a deep copy
202                         PrinterResolution pres = new PrinterResolution (this.printerResolution.Kind, this.printerResolution.X, this.printerResolution.Y);
203                         PaperSource psource = new PaperSource (this.paperSource.Kind, this.paperSource.SourceName);
204                         PaperSize psize = new PaperSize (this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);
205                         psize.RawKind = (int)this.paperSize.Kind;
206
207                         PageSettings ps = new PageSettings (this.printerSettings, this.color, this.landscape,
208                                         psize, psource, pres);
209                         ps.Margins = (Margins) this.margins.Clone ();
210                         return ps;
211                 }
212
213
214                 [MonoTODO("PageSettings.CopyToHdevmode")]
215                 public void CopyToHdevmode (IntPtr hdevmode){
216                         throw new NotImplementedException ();
217                 }
218
219
220                 [MonoTODO("PageSettings.SetHdevmode")]
221                 public void SetHdevmode (IntPtr hdevmode){
222                         throw new NotImplementedException ();
223                 }       
224
225                 public override string ToString(){
226                         string ret = "[PageSettings: Color={0}";
227                         ret += ", Landscape={1}";
228                         ret += ", Margins={2}";
229                         ret += ", PaperSize={3}";
230                         ret += ", PaperSource={4}";
231                         ret += ", PrinterResolution={5}";
232                         ret += "]";
233                         
234                         return String.Format(ret, this.color, this.landscape, this.margins, this.paperSize, this.paperSource, this.printerResolution);
235                 }
236         }
237 }