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;
54 RectangleF _PrintableArea;
55 // create a new default Margins object (is 1 inch for all margins)
56 Margins _Margins = new Margins();
57 PrinterSettings _PrinterSettings;
59 public PageSettings() : this(new PrinterSettings())
63 public PageSettings(PrinterSettings printerSettings)
65 PrinterSettings = printerSettings;
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;
74 // used by PrinterSettings.DefaultPageSettings
75 internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
77 PrinterSettings = printerSettings;
80 _Landscape = landscape;
81 _PaperSize = paperSize;
82 _PaperSource = paperSource;
83 _PrinterResolution = printerResolution;
87 public Rectangle Bounds{
89 int width = this.PaperSize.Width;
90 int height = this.PaperSize.Height;
92 width -= this.Margins.Left + this.Margins.Right;
93 height -= this.Margins.Top + this.Margins.Bottom;
96 // swap width and height
101 return new Rectangle (Margins.Left, Margins.Top, width, height);
107 if (!this._PrinterSettings.IsValid)
108 throw new InvalidPrinterException(this._PrinterSettings);
116 public bool Landscape {
118 if (!this._PrinterSettings.IsValid)
119 throw new InvalidPrinterException(this._PrinterSettings);
127 public Margins Margins{
129 if (!this._PrinterSettings.IsValid)
130 throw new InvalidPrinterException(this._PrinterSettings);
138 public PaperSize PaperSize{
140 if (!this._PrinterSettings.IsValid)
141 throw new InvalidPrinterException(this._PrinterSettings);
149 public PaperSource PaperSource{
151 if (!this._PrinterSettings.IsValid)
152 throw new InvalidPrinterException(this._PrinterSettings);
156 _PaperSource = value;
160 public PrinterResolution PrinterResolution{
162 if (!this._PrinterSettings.IsValid)
163 throw new InvalidPrinterException(this._PrinterSettings);
164 return _PrinterResolution;
167 _PrinterResolution = value;
171 public PrinterSettings PrinterSettings{
173 return _PrinterSettings;
176 _PrinterSettings = value;
180 public float HardMarginX {
186 public float HardMarginY {
192 public RectangleF PrintableArea {
194 return _PrintableArea;
200 public object Clone(){
201 return new PageSettings(this.PrinterSettings);
205 [MonoTODO("PageSettings.CopyToHdevmode")]
206 public void CopyToHdevmode (IntPtr hdevmode){
207 throw new NotImplementedException ();
211 [MonoTODO("PageSettings.SetHdevmode")]
212 public void SetHdevmode (IntPtr hdevmode){
213 throw new NotImplementedException ();
216 public override string ToString(){
217 string ret = "[PageSettings: Color={0}";
218 ret += ", Landscape={1}";
219 ret += ", Margins={2}";
220 ret += ", PaperSize={3}";
221 ret += ", PaperSource={4}";
222 ret += ", PrinterResolution={5}";
225 return String.Format(ret, this.Color, this.Landscape, this.Margins, this.PaperSize, this.PaperSource, this.PrinterResolution);