2006-12-14 Igor Zelmanovich <igorz@mainsoft.com>
[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 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                 #endregion      // Constructors
51
52                 #region Public Instance Properties
53 #if ONLY_1_1
54                 [Bindable(true)]
55 #endif
56                 [DefaultValue(PagerMode.NextPrev)]
57                 [NotifyParentProperty(true)]
58                 [WebSysDescription ("")]
59                 [WebCategory ("Misc")]
60                 public PagerMode Mode {
61                         get {
62                                 if (!CheckBit ((int) DataGridPagerStyles.Mode)) {
63                                         return PagerMode.NextPrev;
64                                 }
65
66                                 return (PagerMode)ViewState["Mode"];
67                         }
68
69                         set {
70                                 ViewState["Mode"] = value;
71                                 SetBit ((int) DataGridPagerStyles.Mode);
72                         }
73                 }
74
75 #if NET_2_0
76                 [Localizable (true)]
77 #else
78                 [Bindable(true)]
79 #endif
80                 [DefaultValue("&gt;")]
81                 [NotifyParentProperty(true)]
82                 [WebSysDescription ("")]
83                 [WebCategory ("Misc")]
84                 public string NextPageText {
85                         get {
86                                 if (!CheckBit ((int) DataGridPagerStyles.NextPageText)) {
87                                         return "&gt;";
88                                 }
89
90                                 return ViewState.GetString("NextPageText", "&gt;");
91                         }
92
93                         set {
94                                 ViewState["NextPageText"] = value;
95                                 SetBit ((int) DataGridPagerStyles.NextPageText);
96                         }
97                 }
98
99 #if ONLY_1_1
100                 [Bindable(true)]
101 #endif
102                 [DefaultValue(10)]
103                 [NotifyParentProperty(true)]
104                 [WebSysDescription ("")]
105                 [WebCategory ("Misc")]
106                 public int PageButtonCount {
107                         get {
108                                 if (!CheckBit ((int) DataGridPagerStyles.PageButtonCount)) {
109                                         return 10;
110                                 }
111
112                                 return ViewState.GetInt("PageButtonCount", 10);
113                         }
114
115                         set {
116                                 if (value < 1) {
117                                         throw new ArgumentOutOfRangeException("value", "PageButtonCount must be greater than 0");
118                                 }
119
120                                 ViewState["PageButtonCount"] = value;
121                                 SetBit ((int) DataGridPagerStyles.PageButtonCount);
122                         }
123                 }
124
125 #if ONLY_1_1
126                 [Bindable(true)]
127 #endif
128                 [DefaultValue(PagerPosition.Bottom)]
129                 [NotifyParentProperty(true)]
130                 [WebSysDescription ("")]
131                 [WebCategory ("Misc")]
132                 public PagerPosition Position {
133                         get {
134                                 if (!CheckBit ((int) DataGridPagerStyles.Position)) {
135                                         return PagerPosition.Bottom;
136                                 }
137
138                                 return (PagerPosition)ViewState["Position"];
139                         }
140
141                         set {
142                                 ViewState["Position"] = value;
143                                 SetBit ((int) DataGridPagerStyles.Position);
144                         }
145                 }
146
147 #if NET_2_0
148                 [Localizable (true)]
149 #else
150                 [Bindable(true)]
151 #endif
152                 [DefaultValue("&lt;")]
153                 [NotifyParentProperty(true)]
154                 [WebSysDescription ("")]
155                 [WebCategory ("Misc")]
156                 public string PrevPageText {
157                         get {
158                                 if (!CheckBit ((int) DataGridPagerStyles.PrevPageText)) {
159                                         return "&lt;";
160                                 }
161
162                                 return ViewState.GetString("PrevPageText", "&lt;");
163                         }
164
165                         set {
166                                 ViewState["PrevPageText"] = value;
167                                 SetBit ((int) DataGridPagerStyles.PrevPageText);
168                         }
169                 }
170
171 #if ONLY_1_1
172                 [Bindable(true)]
173 #endif
174                 [DefaultValue(true)]
175                 [NotifyParentProperty(true)]
176                 [WebSysDescription ("")]
177                 [WebCategory ("Misc")]
178                 public bool Visible {
179                         get {
180                                 if (!CheckBit ((int) DataGridPagerStyles.Visible)) {
181                                         return true;
182                                 }
183
184                                 return ViewState.GetBool("Visible", true);
185                         }
186
187                         set {
188                                 ViewState["Visible"] = value;
189                                 SetBit ((int) DataGridPagerStyles.Visible);
190                         }
191                 }
192                 #endregion      // Public Instance Properties
193
194                 #region Public Instance Methods
195                 public override void CopyFrom(Style s) {
196                         base.CopyFrom (s);
197
198                         if (s == null || s.IsEmpty) {
199                                 return;
200                         }
201
202                         if (s.CheckBit ((int) DataGridPagerStyles.Mode) && (((DataGridPagerStyle) s).Mode != PagerMode.NextPrev)) {
203                                 this.Mode = ((DataGridPagerStyle)s).Mode;
204                         }
205
206                         if (s.CheckBit ((int) DataGridPagerStyles.NextPageText) && (((DataGridPagerStyle) s).NextPageText != "&gt;")) {
207                                 this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
208                         }
209
210                         if (s.CheckBit ((int) DataGridPagerStyles.PageButtonCount) && (((DataGridPagerStyle) s).PageButtonCount != 10)) {
211                                 this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
212                         }
213
214                         if (s.CheckBit ((int) DataGridPagerStyles.Position) && (((DataGridPagerStyle) s).Position != PagerPosition.Bottom)) {
215                                 this.Position = ((DataGridPagerStyle)s).Position;
216                         }
217
218                         if (s.CheckBit ((int) DataGridPagerStyles.PrevPageText) && (((DataGridPagerStyle) s).PrevPageText != "&lt;")) {
219                                 this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
220                         }
221
222                         if (s.CheckBit ((int) DataGridPagerStyles.Visible) && (((DataGridPagerStyle) s).Visible != true)) {
223                                 this.Visible = ((DataGridPagerStyle)s).Visible;
224                         }
225
226                 }
227
228                 public override void MergeWith(Style s) {
229                         base.MergeWith (s);
230
231                         if (s == null || s.IsEmpty) {
232                                 return;
233                         }
234
235                         if (!CheckBit ((int) DataGridPagerStyles.Mode) && s.CheckBit ((int) DataGridPagerStyles.Mode) && (((DataGridPagerStyle) s).Mode != PagerMode.NextPrev)) {
236                                 this.Mode = ((DataGridPagerStyle)s).Mode;
237                         }
238
239                         if (!CheckBit ((int) DataGridPagerStyles.NextPageText) && s.CheckBit ((int) DataGridPagerStyles.NextPageText) && (((DataGridPagerStyle) s).NextPageText != "&gt;")) {
240                                 this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
241                         }
242
243                         if (!CheckBit ((int) DataGridPagerStyles.PageButtonCount) && s.CheckBit ((int) DataGridPagerStyles.PageButtonCount) && (((DataGridPagerStyle) s).PageButtonCount != 10)) {
244                                 this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
245                         }
246
247                         if (!CheckBit ((int) DataGridPagerStyles.Position) && s.CheckBit ((int) DataGridPagerStyles.Position) && (((DataGridPagerStyle) s).Position != PagerPosition.Bottom)) {
248                                 this.Position = ((DataGridPagerStyle)s).Position;
249                         }
250
251                         if (!CheckBit ((int) DataGridPagerStyles.PrevPageText) && s.CheckBit ((int) DataGridPagerStyles.PrevPageText) && (((DataGridPagerStyle) s).PrevPageText != "&lt;")) {
252                                 this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
253                         }
254
255                         if (!CheckBit ((int) DataGridPagerStyles.Visible) && s.CheckBit ((int) DataGridPagerStyles.Visible) && (((DataGridPagerStyle) s).Visible != true)) {
256                                 this.Visible = ((DataGridPagerStyle)s).Visible;
257                         }
258                 }
259
260                 public override void Reset() {
261                         // We call base.Reset(), we don't need this
262                         //styles &= ~(Styles.Mode | Styles.NextPageText | Styles.PageButtonCount | Styles.Position | Styles.PrevPageText | Styles.Visible);
263
264                         ViewState.Remove("Mode");
265                         ViewState.Remove("NextPageText");
266                         ViewState.Remove("PageButtonCount");
267                         ViewState.Remove("Position");
268                         ViewState.Remove("PrevPageText");
269                         ViewState.Remove("Visible");
270
271                         base.Reset ();
272                 }
273
274                 internal override void LoadViewStateInternal()
275                 {
276                         if (viewstate["Mode"] != null) {
277                                 SetBit ((int) DataGridPagerStyles.Mode);
278                         }
279                         if (viewstate["NextPageText"] != null) {
280                                 SetBit ((int) DataGridPagerStyles.NextPageText);
281                         }
282                         if (viewstate["PageButtonCount"] != null) {
283                                 SetBit ((int) DataGridPagerStyles.PageButtonCount);
284                         }
285                         if (viewstate["Position"] != null) {
286                                 SetBit ((int) DataGridPagerStyles.Position);
287                         }
288                         if (viewstate["PrevPageText"] != null) {
289                                 SetBit ((int) DataGridPagerStyles.PrevPageText);
290                         }
291                         if (viewstate["Visible"] != null) {
292                                 SetBit ((int) DataGridPagerStyles.Visible);
293                         }
294
295                         base.LoadViewStateInternal();
296                 }
297                 #endregion      // Public Instance Methods
298         }
299 }