2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / System.Drawing / System.Drawing.Printing / PaperSize.cs
1 //
2 // System.Drawing.PaperSize.cs
3 //
4 // Author:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Herve Poussineau (hpoussineau@fr.st)
7 //
8 // (C) 2002 Ximian, Inc
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33 using System;
34
35 namespace System.Drawing.Printing
36 {
37         /// <summary>
38         /// Summary description for PaperSize.
39         /// </summary>
40 #if NET_2_0
41         [Serializable]
42 #endif
43         public class PaperSize
44         {
45                 string name;
46                 int width;
47                 int height;
48                 PaperKind kind;
49                 internal bool is_default;
50                 
51 #if NET_2_0
52                 public PaperSize ()
53                 {
54
55                 }
56 #endif          
57                 public PaperSize(string name, int width, int height)
58                 {
59                         this.width = width;
60                         this.height = height;
61                         this.name = name;
62                 }
63
64                 internal PaperSize(string name, int width, int height, PaperKind kind, bool isDefault)
65                 {
66                         this.width = width;
67                         this.height = height;
68                         this.name = name;
69                         this.is_default = isDefault;
70                 }
71
72                 public int Width{
73                         get{
74                                 return width;
75                         }set
76                          {
77                                 if (kind != PaperKind.Custom)
78                                         throw new ArgumentException();
79                                  width = value;
80                          }
81                 }
82                 public int Height{
83                         get{
84                                 return height;
85                         }set
86                          {
87                                 if (kind != PaperKind.Custom)
88                                         throw new ArgumentException();
89                                  height = value;
90                          }
91                 }
92
93                 public string PaperName{
94                         get{
95                                 return name;
96                         }
97                         set{
98                                 if (kind != PaperKind.Custom)
99                                         throw new ArgumentException();
100                                  name = value;
101                          }
102                 }
103         
104                 public PaperKind Kind{
105                         get{
106                                 // .net ignores the values that are less than 0
107                                 // the value returned is not used internally, however.
108                                 if (kind > PaperKind.PrcEnvelopeNumber10Rotated)
109                                         return PaperKind.Custom;
110
111                                 return kind;
112                         }
113                 }
114 #if NET_2_0
115                 public int RawKind {
116                         get {
117                                 return (int)kind;
118                         }
119                         set {
120                                 kind = (PaperKind)value;
121                         }
122                 }
123
124 #endif
125         
126                 internal bool IsDefault {
127                         get { return this.is_default; }
128                         set { this.is_default = value; }
129                 }
130
131
132                 internal void SetKind (PaperKind k) {kind = k;}
133
134                 public override string ToString(){
135                         string ret = "[PaperSize {0} Kind={1} Height={2} Width={3}]";
136                         return String.Format(ret, this.PaperName, this.Kind, this.Height, this.Width);
137                 }
138         }
139 }