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