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