2005-02-02 Lluis Sanchez Gual <lluis@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataGridPagerStyle.cs
1 //
2 // System.Web.UI.WebControls.DataGridPagerStyle.cs
3 //
4 // Authors:
5 //   Gaurav Vaish (gvaish@iitk.ac.in)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
10 //
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.ComponentModel;
35 using System.Web;
36 using System.Web.UI;
37
38 namespace System.Web.UI.WebControls
39 {
40         public sealed class DataGridPagerStyle : TableItemStyle
41         {
42                 DataGrid owner;
43
44                 private static int MODE         = (0x01 << 19);
45                 private static int NEXT_PG_TEXT = (0x01 << 20);
46                 private static int PG_BTN_COUNT = (0x01 << 21);
47                 private static int POSITION     = (0x01 << 22);
48                 private static int VISIBLE      = (0x01 << 23);
49                 private static int PREV_PG_TEXT = (0x01 << 24);
50
51                 internal DataGridPagerStyle(DataGrid owner): base()
52                 {
53                         this.owner = owner;
54                 }
55
56                 internal bool IsPagerOnTop
57                 {
58                         get {
59                                 PagerPosition p = Position;
60                                 return (p == PagerPosition.Top || p == PagerPosition.TopAndBottom);
61                         }
62                 }
63                 
64                 internal bool IsPagerOnBottom
65                 {
66                         get {
67                                 PagerPosition p = Position;
68                                 return (p == PagerPosition.Bottom || p == PagerPosition.TopAndBottom);
69                         }
70                 }
71
72 #if !NET_2_0
73                 [Bindable (true)]
74 #endif
75                 [DefaultValue (typeof (PagerMode), "NextPrev"), WebCategory ("Misc")]
76                 [NotifyParentProperty (true)]
77                 [WebSysDescription ("The mode used for displaying multiple pages.")]
78                 public PagerMode Mode
79                 {
80                         get
81                         {
82                                 if(IsSet(MODE))
83                                 {
84                                         return (PagerMode)ViewState["Mode"];
85                                 }
86                                 return PagerMode.NextPrev;
87                         }
88                         set
89                         {
90                                 if(!Enum.IsDefined(typeof(PagerMode), value))
91                                 {
92                                         throw new ArgumentOutOfRangeException("value");
93                                 }
94                                 ViewState["Mode"] = value;
95                                 Set(MODE);
96                         }
97                 }
98
99 #if NET_2_0
100                 [Localizable (true)]
101 #else
102                 [Bindable (true)]
103 #endif
104                 [DefaultValue (">"), WebCategory ("Misc")]
105                 [NotifyParentProperty (true)]
106                 [WebSysDescription ("The text for the 'next page' button.")]
107                 public string NextPageText
108                 {
109                         get
110                         {
111                                 if(IsSet(NEXT_PG_TEXT))
112                                 {
113                                         return (string)ViewState["NextPageText"];
114                                 }
115                                 return "&gt;";
116                         }
117                         set
118                         {
119                                 ViewState["NextPageText"] = value;
120                                 Set(NEXT_PG_TEXT);
121                         }
122                 }
123
124 #if NET_2_0
125                 [Localizable (true)]
126 #else
127                 [Bindable (true)]
128 #endif
129                 [DefaultValue ("<"), WebCategory ("Misc")]
130                 [NotifyParentProperty (true)]
131                 [WebSysDescription ("The text for the 'previous page' button.")]
132                 public string PrevPageText
133                 {
134                         get
135                         {
136                                 if(IsSet(PREV_PG_TEXT))
137                                 {
138                                         return (string)ViewState["PrevPageText"];
139                                 }
140                                 return "&lt;";
141                         }
142                         set
143                         {
144                                 ViewState["PrevPageText"] = value;
145                                 Set(PREV_PG_TEXT);
146                         }
147                 }
148
149 #if !NET_2_0
150                 [Bindable (true)]
151 #endif
152                 [DefaultValue (10), WebCategory ("Misc")]
153                 [NotifyParentProperty (true)]
154                 [WebSysDescription ("The maximum number of pages to show as direct links.")]
155                 public int PageButtonCount
156                 {
157                         get
158                         {
159                                 if(IsSet(PG_BTN_COUNT))
160                                 {
161                                         return (int)ViewState["PageButtonCount"];
162                                 }
163                                 return 10;
164                         }
165                         set
166                         {
167                                 if (value < 1)
168                                         throw new ArgumentOutOfRangeException("value");
169                                 
170                                 ViewState["PageButtonCount"] = value;
171                                 Set(PG_BTN_COUNT);
172                         }
173                 }
174
175 #if !NET_2_0
176                 [Bindable (true)]
177 #endif
178                 [DefaultValue (typeof (PagerPosition), "Bottom"), WebCategory ("Misc")]
179                 [NotifyParentProperty (true)]
180                 [WebSysDescription ("The position for the page display.")]
181                 public PagerPosition Position
182                 {
183                         get
184                         {
185                                 if(IsSet(POSITION))
186                                 {
187                                         return (PagerPosition)ViewState["Position"];
188                                 }
189                                 return PagerPosition.Bottom;
190                         }
191                         set
192                         {
193                                 if(!Enum.IsDefined(typeof(PagerPosition), value))
194                                 {
195                                         throw new ArgumentException();
196                                 }
197                                 ViewState["Position"] = value;
198                                 Set(POSITION);
199                         }
200                 }
201
202 #if NET_2_0
203                 [Localizable (true)]
204 #else
205                 [Bindable (true)]
206 #endif
207                 [DefaultValue (true), WebCategory ("Misc")]
208                 [NotifyParentProperty (true)]
209                 [WebSysDescription ("Determines if paging functionallity is visible to the user.")]
210                 public bool Visible
211                 {
212                         get
213                         {
214                                 if(IsSet(VISIBLE))
215                                 {
216                                         return (bool)ViewState["PagerVisible"];
217                                 }
218                                 return true;
219                         }
220                         set
221                         {
222                                 ViewState["PagerVisible"] = value;
223                                 Set(VISIBLE);
224                                 owner.OnPagerChanged();
225                         }
226                 }
227
228                 public override void CopyFrom(Style s)
229                 {
230                         if(s != null && !s.IsEmpty)
231                         {
232                                 base.CopyFrom(s);
233                                 if(!(s is DataGridPagerStyle)) return;
234
235                                 DataGridPagerStyle from = (DataGridPagerStyle)s;
236                                 if(from.IsSet(MODE))
237                                 {
238                                         Mode = from.Mode;
239                                 }
240                                 if(from.IsSet(NEXT_PG_TEXT))
241                                 {
242                                         NextPageText = from.NextPageText;
243                                 }
244                                 if(from.IsSet(PG_BTN_COUNT))
245                                 {
246                                         PageButtonCount = from.PageButtonCount;
247                                 }
248                                 if(from.IsSet(POSITION))
249                                 {
250                                         Position = from.Position;
251                                 }
252                                 if(from.IsSet(VISIBLE))
253                                 {
254                                         Visible = from.Visible;
255                                 }
256                                 if(from.IsSet(PREV_PG_TEXT))
257                                 {
258                                         PrevPageText = from.PrevPageText;
259                                 }
260                         }
261                 }
262
263                 public override void MergeWith(Style s)
264                 {
265                         if(s != null && !s.IsEmpty)
266                         {
267                                 if(IsEmpty)
268                                 {
269                                         CopyFrom(s);
270                                         return;
271                                 }
272
273                                 base.MergeWith(s);
274
275                                 if(!(s is DataGridPagerStyle)) return;
276
277                                 DataGridPagerStyle with = (DataGridPagerStyle)s;
278                                 if(with.IsSet(MODE) && !IsSet(MODE))
279                                 {
280                                         Mode = with.Mode;
281                                 }
282                                 if(with.IsSet(NEXT_PG_TEXT) && !IsSet(NEXT_PG_TEXT))
283                                 {
284                                         NextPageText = with.NextPageText;
285                                 }
286                                 if(with.IsSet(PG_BTN_COUNT) && !IsSet(PG_BTN_COUNT))
287                                 {
288                                         PageButtonCount = with.PageButtonCount;
289                                 }
290                                 if(with.IsSet(POSITION) && !IsSet(POSITION))
291                                 {
292                                         Position = with.Position;
293                                 }
294                                 if(with.IsSet(VISIBLE) && !IsSet(VISIBLE))
295                                 {
296                                         Visible = with.Visible;
297                                 }
298                                 if(with.IsSet(PREV_PG_TEXT) && !IsSet(PREV_PG_TEXT))
299                                 {
300                                         PrevPageText = with.PrevPageText;
301                                 }
302                         }
303                 }
304
305                 public override void Reset()
306                 {
307                         if(IsSet(MODE))
308                         {
309                                 ViewState.Remove("Mode");
310                         }
311                         if(IsSet(NEXT_PG_TEXT))
312                         {
313                                 ViewState.Remove("NextPageText");
314                         }
315                         if(IsSet(PG_BTN_COUNT))
316                         {
317                                 ViewState.Remove("PageButtonCount");
318                         }
319                         if(IsSet(POSITION))
320                         {
321                                 ViewState.Remove("Position");
322                         }
323                         if(IsSet(VISIBLE))
324                         {
325                                 ViewState.Remove("PagerVisible");
326                         }
327                         if(IsSet(PREV_PG_TEXT))
328                         {
329                                 ViewState.Remove("PrevPageText");
330                         }
331                         base.Reset();
332                 }
333         }
334 }