New test.
[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 #if NET_2_0
41         [Serializable]
42 #else
43         [ComVisible (false)]
44 #endif
45         public class PageSettings : ICloneable
46         {
47                 bool _Color;
48                 bool _Landscape;
49                 float _HardMarginX;\r
50                 float _HardMarginY;
51                 RectangleF _PrintableArea;
52                 // create a new default Margins object (is 1 inch for all margins)
53                 Margins _Margins = new Margins();
54                 PaperSize _PaperSize;
55                 PaperSource _PaperSource;
56                 PrinterResolution _PrinterResolution;
57                 PrinterSettings _PrinterSettings;
58                 
59                 public PageSettings() : this(new PrinterSettings())
60                 {
61                 }
62                 
63                 public PageSettings(PrinterSettings printerSettings)
64                 {
65                         PrinterSettings = printerSettings;
66                         
67                         Color = printerSettings.DefaultPageSettings.Color;
68                         Landscape = printerSettings.DefaultPageSettings.Landscape;
69                         PaperSize = printerSettings.DefaultPageSettings.PaperSize;
70                         PaperSource = printerSettings.DefaultPageSettings.PaperSource;
71                         PrinterResolution = printerSettings.DefaultPageSettings.PrinterResolution;
72                 }
73                 
74                 // used by PrinterSettings.DefaultPageSettings
75                 internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
76                 {
77                         PrinterSettings = printerSettings;
78                         
79                         Color = color;
80                         Landscape = landscape;
81                         PaperSize = paperSize;
82                         PaperSource = paperSource;
83                         PrinterResolution = printerResolution;
84                 }
85
86                 //props
87                 public Rectangle Bounds{
88                         get{
89                                 int width = this.PaperSize.Width;
90                                 int height = this.PaperSize.Height;
91                                 
92                                 width -= this.Margins.Left + this.Margins.Right;
93                                 height -= this.Margins.Top + this.Margins.Bottom;
94                                 
95                                 if (this.Landscape) {
96                                         // swap width and height
97                                         int tmp = width;
98                                         width = height;
99                                         height = tmp;
100                                 }
101                                 return new Rectangle (Margins.Left, Margins.Top, width, height);
102                         }
103                 }
104                 
105                 public bool Color{
106                         get{
107                                 return _Color;
108                         }
109                         set{
110                                 _Color = value;
111                         }
112                 }
113                 
114                 public bool Landscape {
115                         get{
116                                 return _Landscape;
117                         }
118                         set{
119                                 _Landscape = value;
120                         }
121                 }
122                 
123                 public Margins Margins{
124                         get{
125                                 return _Margins;
126                         }
127                         set{
128                                 _Margins = value;
129                         }
130                 }
131                 
132                 public PaperSize PaperSize{
133                         get{
134                                 return _PaperSize;
135                         }
136                         set{
137                                 _PaperSize = value;
138                         }
139                 }
140                 
141                 public PaperSource PaperSource{
142                         get{
143                                 return _PaperSource;
144                         }
145                         set{
146                                 _PaperSource = value;
147                         }
148                 }
149                 
150                 public PrinterResolution PrinterResolution{
151                         get{
152                                 return _PrinterResolution;
153                         }
154                         set{
155                                 _PrinterResolution = value;
156                         }
157                 }
158                 
159                 public PrinterSettings PrinterSettings{
160                         get{
161                                 return _PrinterSettings;
162                         }
163                         set{
164                                 _PrinterSettings = value;
165                         }
166                 }               
167 #if NET_2_0
168                 public float HardMarginX {
169                         get {
170                                 return _HardMarginX;
171                         }
172                 }
173                 \r
174                 public float HardMarginY {
175                         get {
176                                 return _HardMarginY;
177                         }
178                 }
179                 
180                 public RectangleF PrintableArea {
181                         get {
182                                 return _PrintableArea;
183                         }
184                 }
185 #endif\r
186
187
188                 public object Clone(){
189                         return new PageSettings(this.PrinterSettings);
190                 }
191
192
193                 [MonoTODO("PageSettings.CopyToHdevmode")]
194                 public void CopyToHdevmode (IntPtr hdevmode){
195                         throw new NotImplementedException ();
196                 }
197
198
199                 [MonoTODO("PageSettings.SetHdevmode")]
200                 public void SetHdevmode (IntPtr hdevmode){
201                         throw new NotImplementedException ();
202                 }       
203
204                 public override string ToString(){
205                         string ret = "[PageSettings: Color={0}";
206                         ret += ", Landscape={1}";
207                         ret += ", Margins={2}";
208                         ret += ", PaperSize={3}";
209                         ret += ", PaperSource={4}";
210                         ret += ", PrinterResolution={5}";
211                         ret += "]";
212                         
213                         return String.Format(ret, this.Color, this.Landscape, this.Margins, this.PaperSize, this.PaperSource, this.PrinterResolution);
214                 }
215         }
216 }