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