2 // System.Drawing.PageSettings.cs
5 // Dennis Hayes (dennish@Raytek.com)
6 // Herve Poussineau (hpoussineau@fr.st)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (C) 2002 Ximian, Inc
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
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.
36 using System.Runtime.InteropServices;
38 namespace System.Drawing.Printing
45 public class PageSettings : ICloneable
48 internal bool landscape;
49 internal PaperSize paperSize;
50 internal PaperSource paperSource;
51 internal PrinterResolution printerResolution;
53 // create a new default Margins object (is 1 inch for all margins)
54 Margins margins = new Margins();
58 RectangleF printableArea;
59 PrinterSettings printerSettings;
61 public PageSettings() : this(new PrinterSettings())
65 public PageSettings(PrinterSettings printerSettings)
67 PrinterSettings = printerSettings;
69 this.color = printerSettings.DefaultPageSettings.color;
70 this.landscape = printerSettings.DefaultPageSettings.landscape;
71 this.paperSize = printerSettings.DefaultPageSettings.paperSize;
72 this.paperSource = printerSettings.DefaultPageSettings.paperSource;
73 this.printerResolution = printerSettings.DefaultPageSettings.printerResolution;
76 // used by PrinterSettings.DefaultPageSettings
77 internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
79 PrinterSettings = printerSettings;
82 this.landscape = landscape;
83 this.paperSize = paperSize;
84 this.paperSource = paperSource;
85 this.printerResolution = printerResolution;
89 public Rectangle Bounds{
91 int width = this.paperSize.Width;
92 int height = this.paperSize.Height;
94 width -= this.margins.Left + this.margins.Right;
95 height -= this.margins.Top + this.margins.Bottom;
98 // swap width and height
103 return new Rectangle (this.margins.Left, this.margins.Top, width, height);
109 if (!this.printerSettings.IsValid)
110 throw new InvalidPrinterException(this.printerSettings);
118 public bool Landscape {
120 if (!this.printerSettings.IsValid)
121 throw new InvalidPrinterException(this.printerSettings);
129 public Margins Margins{
131 if (!this.printerSettings.IsValid)
132 throw new InvalidPrinterException(this.printerSettings);
140 public PaperSize PaperSize{
142 if (!this.printerSettings.IsValid)
143 throw new InvalidPrinterException(this.printerSettings);
151 public PaperSource PaperSource{
153 if (!this.printerSettings.IsValid)
154 throw new InvalidPrinterException(this.printerSettings);
162 public PrinterResolution PrinterResolution{
164 if (!this.printerSettings.IsValid)
165 throw new InvalidPrinterException(this.printerSettings);
166 return printerResolution;
169 printerResolution = value;
173 public PrinterSettings PrinterSettings{
175 return printerSettings;
178 printerSettings = value;
182 public float HardMarginX {
188 public float HardMarginY {
194 public RectangleF PrintableArea {
196 return printableArea;
202 public object Clone ()
205 PrinterResolution pres = new PrinterResolution (this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind);
206 PaperSource psource = new PaperSource (this.paperSource.SourceName, this.paperSource.Kind);
207 PaperSize psize = new PaperSize (this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);
208 psize.SetKind (this.paperSize.Kind);
210 PageSettings ps = new PageSettings (this.printerSettings, this.color, this.landscape,
211 psize, psource, pres);
212 ps.Margins = (Margins) this.margins.Clone ();
217 [MonoTODO("PageSettings.CopyToHdevmode")]
218 public void CopyToHdevmode (IntPtr hdevmode){
219 throw new NotImplementedException ();
223 [MonoTODO("PageSettings.SetHdevmode")]
224 public void SetHdevmode (IntPtr hdevmode){
225 throw new NotImplementedException ();
228 public override string ToString(){
229 string ret = "[PageSettings: Color={0}";
230 ret += ", Landscape={1}";
231 ret += ", Margins={2}";
232 ret += ", PaperSize={3}";
233 ret += ", PaperSource={4}";
234 ret += ", PrinterResolution={5}";
237 return String.Format(ret, this.color, this.landscape, this.margins, this.paperSize, this.paperSource, this.printerResolution);