Merge pull request #2084 from joelmartinez/mdoc-deletetestfix
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataGridPagerStyle.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005-2010 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Bartok    (pbartok@novell.com)
24 //
25 //
26
27 using System.ComponentModel;
28 using System.Security.Permissions;
29
30 namespace System.Web.UI.WebControls
31 {
32         // CAS - no inheritance demand required because the class is sealed
33         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
34         public sealed class DataGridPagerStyle : TableItemStyle
35         {
36                 [Flags]
37                 enum DataGridPagerStyles
38                 {
39                         Mode = 0x00100000,
40                         NextPageText = 0x00200000,
41                         PageButtonCount = 0x00400000,
42                         Position = 0x00800000,
43                         PrevPageText = 0x01000000,
44                         Visible = 0x02000000
45                 }
46
47                 #region Constructors
48                 internal DataGridPagerStyle ()
49                 {
50                 }
51                 #endregion      // Constructors
52
53                 #region Public Instance Properties
54                 [DefaultValue(PagerMode.NextPrev)]
55                 [NotifyParentProperty(true)]
56                 [WebSysDescription ("")]
57                 [WebCategory ("Misc")]
58                 public PagerMode Mode {
59                         get {
60                                 if (!CheckBit ((int) DataGridPagerStyles.Mode))
61                                         return PagerMode.NextPrev;
62
63                                 return (PagerMode)ViewState["Mode"];
64                         }
65
66                         set {
67                                 ViewState["Mode"] = value;
68                                 SetBit ((int) DataGridPagerStyles.Mode);
69                         }
70                 }
71
72                 [Localizable (true)]
73                 [DefaultValue(">")]
74                 [NotifyParentProperty(true)]
75                 [WebSysDescription ("")]
76                 [WebCategory ("Misc")]
77                 public string NextPageText {
78                         get {
79                                 if (!CheckBit ((int) DataGridPagerStyles.NextPageText))
80                                         return ">";
81
82                                 return ViewState.GetString("NextPageText", ">");
83                         }
84
85                         set {
86                                 ViewState["NextPageText"] = value;
87                                 SetBit ((int) DataGridPagerStyles.NextPageText);
88                         }
89                 }
90
91                 [DefaultValue(10)]
92                 [NotifyParentProperty(true)]
93                 [WebSysDescription ("")]
94                 [WebCategory ("Misc")]
95                 public int PageButtonCount {
96                         get {
97                                 if (!CheckBit ((int) DataGridPagerStyles.PageButtonCount))
98                                         return 10;
99
100                                 return ViewState.GetInt("PageButtonCount", 10);
101                         }
102
103                         set {
104                                 if (value < 1)
105                                         throw new ArgumentOutOfRangeException("value", "PageButtonCount must be greater than 0");
106
107                                 ViewState["PageButtonCount"] = value;
108                                 SetBit ((int) DataGridPagerStyles.PageButtonCount);
109                         }
110                 }
111
112                 [DefaultValue(PagerPosition.Bottom)]
113                 [NotifyParentProperty(true)]
114                 [WebSysDescription ("")]
115                 [WebCategory ("Misc")]
116                 public PagerPosition Position {
117                         get {
118                                 if (!CheckBit ((int) DataGridPagerStyles.Position))
119                                         return PagerPosition.Bottom;
120
121                                 return (PagerPosition)ViewState["Position"];
122                         }
123
124                         set {
125                                 ViewState["Position"] = value;
126                                 SetBit ((int) DataGridPagerStyles.Position);
127                         }
128                 }
129
130                 [Localizable (true)]
131                 [DefaultValue("&lt;")]
132                 [NotifyParentProperty(true)]
133                 [WebSysDescription ("")]
134                 [WebCategory ("Misc")]
135                 public string PrevPageText {
136                         get {
137                                 if (!CheckBit ((int) DataGridPagerStyles.PrevPageText))
138                                         return "&lt;";
139
140                                 return ViewState.GetString("PrevPageText", "&lt;");
141                         }
142
143                         set {
144                                 ViewState["PrevPageText"] = value;
145                                 SetBit ((int) DataGridPagerStyles.PrevPageText);
146                         }
147                 }
148
149                 [DefaultValue(true)]
150                 [NotifyParentProperty(true)]
151                 [WebSysDescription ("")]
152                 [WebCategory ("Misc")]
153                 public bool Visible {
154                         get {
155                                 if (!CheckBit ((int) DataGridPagerStyles.Visible))
156                                         return true;
157
158                                 return ViewState.GetBool("Visible", true);
159                         }
160
161                         set {
162                                 ViewState["Visible"] = value;
163                                 SetBit ((int) DataGridPagerStyles.Visible);
164                         }
165                 }
166                 #endregion      // Public Instance Properties
167
168                 #region Public Instance Methods
169                 public override void CopyFrom(Style s)
170                 {
171                         base.CopyFrom (s);
172
173                         if (s == null || s.IsEmpty)
174                                 return;
175
176                         if (s.CheckBit ((int) DataGridPagerStyles.Mode) && (((DataGridPagerStyle) s).Mode != PagerMode.NextPrev))
177                                 this.Mode = ((DataGridPagerStyle)s).Mode;
178
179                         if (s.CheckBit ((int) DataGridPagerStyles.NextPageText) && (((DataGridPagerStyle) s).NextPageText != "&gt;"))
180                                 this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
181
182                         if (s.CheckBit ((int) DataGridPagerStyles.PageButtonCount) && (((DataGridPagerStyle) s).PageButtonCount != 10))
183                                 this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
184
185                         if (s.CheckBit ((int) DataGridPagerStyles.Position) && (((DataGridPagerStyle) s).Position != PagerPosition.Bottom))
186                                 this.Position = ((DataGridPagerStyle)s).Position;
187
188                         if (s.CheckBit ((int) DataGridPagerStyles.PrevPageText) && (((DataGridPagerStyle) s).PrevPageText != "&lt;"))
189                                 this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
190
191                         if (s.CheckBit ((int) DataGridPagerStyles.Visible) && (((DataGridPagerStyle) s).Visible != true))
192                                 this.Visible = ((DataGridPagerStyle)s).Visible;
193                 }
194
195                 public override void MergeWith(Style s)
196                 {
197                         base.MergeWith (s);
198
199                         if (s == null || s.IsEmpty)
200                                 return;
201
202                         if (!CheckBit ((int) DataGridPagerStyles.Mode) && s.CheckBit ((int) DataGridPagerStyles.Mode) && (((DataGridPagerStyle) s).Mode != PagerMode.NextPrev))
203                                 this.Mode = ((DataGridPagerStyle)s).Mode;
204
205                         if (!CheckBit ((int) DataGridPagerStyles.NextPageText) && s.CheckBit ((int) DataGridPagerStyles.NextPageText) && (((DataGridPagerStyle) s).NextPageText != "&gt;"))
206                                 this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
207
208                         if (!CheckBit ((int) DataGridPagerStyles.PageButtonCount) && s.CheckBit ((int) DataGridPagerStyles.PageButtonCount) && (((DataGridPagerStyle) s).PageButtonCount != 10))
209                                 this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
210
211                         if (!CheckBit ((int) DataGridPagerStyles.Position) && s.CheckBit ((int) DataGridPagerStyles.Position) && (((DataGridPagerStyle) s).Position != PagerPosition.Bottom))
212                                 this.Position = ((DataGridPagerStyle)s).Position;
213
214                         if (!CheckBit ((int) DataGridPagerStyles.PrevPageText) && s.CheckBit ((int) DataGridPagerStyles.PrevPageText) && (((DataGridPagerStyle) s).PrevPageText != "&lt;"))
215                                 this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
216
217                         if (!CheckBit ((int) DataGridPagerStyles.Visible) && s.CheckBit ((int) DataGridPagerStyles.Visible) && (((DataGridPagerStyle) s).Visible != true))
218                                 this.Visible = ((DataGridPagerStyle)s).Visible;
219                 }
220
221                 public override void Reset ()
222                 {
223                         // We call base.Reset(), we don't need this
224                         //styles &= ~(Styles.Mode | Styles.NextPageText | Styles.PageButtonCount | Styles.Position | Styles.PrevPageText | Styles.Visible);
225
226                         ViewState.Remove("Mode");
227                         ViewState.Remove("NextPageText");
228                         ViewState.Remove("PageButtonCount");
229                         ViewState.Remove("Position");
230                         ViewState.Remove("PrevPageText");
231                         ViewState.Remove("Visible");
232
233                         base.Reset ();
234                 }
235                 #endregion      // Public Instance Methods
236         }
237 }