This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[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                 [DefaultValue (typeof (PagerMode), "NextPrev"), Bindable (true), WebCategory ("Misc")]
73                 [NotifyParentProperty (true)]
74                 [WebSysDescription ("The mode used for displaying multiple pages.")]
75                 public PagerMode Mode
76                 {
77                         get
78                         {
79                                 if(IsSet(MODE))
80                                 {
81                                         return (PagerMode)ViewState["Mode"];
82                                 }
83                                 return PagerMode.NextPrev;
84                         }
85                         set
86                         {
87                                 if(!Enum.IsDefined(typeof(PagerMode), value))
88                                 {
89                                         throw new ArgumentOutOfRangeException("value");
90                                 }
91                                 ViewState["Mode"] = value;
92                                 Set(MODE);
93                         }
94                 }
95
96                 [DefaultValue (">"), Bindable (true), WebCategory ("Misc")]
97                 [NotifyParentProperty (true)]
98                 [WebSysDescription ("The text for the 'next page' button.")]
99                 public string NextPageText
100                 {
101                         get
102                         {
103                                 if(IsSet(NEXT_PG_TEXT))
104                                 {
105                                         return (string)ViewState["NextPageText"];
106                                 }
107                                 return "&gt;";
108                         }
109                         set
110                         {
111                                 ViewState["NextPageText"] = value;
112                                 Set(NEXT_PG_TEXT);
113                         }
114                 }
115
116                 [DefaultValue ("<"), Bindable (true), WebCategory ("Misc")]
117                 [NotifyParentProperty (true)]
118                 [WebSysDescription ("The text for the 'previous page' button.")]
119                 public string PrevPageText
120                 {
121                         get
122                         {
123                                 if(IsSet(PREV_PG_TEXT))
124                                 {
125                                         return (string)ViewState["PrevPageText"];
126                                 }
127                                 return "&lt;";
128                         }
129                         set
130                         {
131                                 ViewState["PrevPageText"] = value;
132                                 Set(PREV_PG_TEXT);
133                         }
134                 }
135
136                 [DefaultValue (10), Bindable (true), WebCategory ("Misc")]
137                 [NotifyParentProperty (true)]
138                 [WebSysDescription ("The maximum number of pages to show as direct links.")]
139                 public int PageButtonCount
140                 {
141                         get
142                         {
143                                 if(IsSet(PG_BTN_COUNT))
144                                 {
145                                         return (int)ViewState["PageButtonCount"];
146                                 }
147                                 return 10;
148                         }
149                         set
150                         {
151                                 if (value < 1)
152                                         throw new ArgumentOutOfRangeException("value");
153                                 
154                                 ViewState["PageButtonCount"] = value;
155                                 Set(PG_BTN_COUNT);
156                         }
157                 }
158
159                 [DefaultValue (typeof (PagerPosition), "Bottom"), Bindable (true), WebCategory ("Misc")]
160                 [NotifyParentProperty (true)]
161                 [WebSysDescription ("The position for the page display.")]
162                 public PagerPosition Position
163                 {
164                         get
165                         {
166                                 if(IsSet(POSITION))
167                                 {
168                                         return (PagerPosition)ViewState["Position"];
169                                 }
170                                 return PagerPosition.Bottom;
171                         }
172                         set
173                         {
174                                 if(!Enum.IsDefined(typeof(PagerPosition), value))
175                                 {
176                                         throw new ArgumentException();
177                                 }
178                                 ViewState["Position"] = value;
179                                 Set(POSITION);
180                         }
181                 }
182
183                 [DefaultValue (true), Bindable (true), WebCategory ("Misc")]
184                 [NotifyParentProperty (true)]
185                 [WebSysDescription ("Determines if paging functionallity is visible to the user.")]
186                 public bool Visible
187                 {
188                         get
189                         {
190                                 if(IsSet(VISIBLE))
191                                 {
192                                         return (bool)ViewState["PagerVisible"];
193                                 }
194                                 return true;
195                         }
196                         set
197                         {
198                                 ViewState["PagerVisible"] = value;
199                                 Set(VISIBLE);
200                                 owner.OnPagerChanged();
201                         }
202                 }
203
204                 public override void CopyFrom(Style s)
205                 {
206                         if(s != null && !s.IsEmpty)
207                         {
208                                 base.CopyFrom(s);
209                                 if(!(s is DataGridPagerStyle)) return;
210
211                                 DataGridPagerStyle from = (DataGridPagerStyle)s;
212                                 if(from.IsSet(MODE))
213                                 {
214                                         Mode = from.Mode;
215                                 }
216                                 if(from.IsSet(NEXT_PG_TEXT))
217                                 {
218                                         NextPageText = from.NextPageText;
219                                 }
220                                 if(from.IsSet(PG_BTN_COUNT))
221                                 {
222                                         PageButtonCount = from.PageButtonCount;
223                                 }
224                                 if(from.IsSet(POSITION))
225                                 {
226                                         Position = from.Position;
227                                 }
228                                 if(from.IsSet(VISIBLE))
229                                 {
230                                         Visible = from.Visible;
231                                 }
232                                 if(from.IsSet(PREV_PG_TEXT))
233                                 {
234                                         PrevPageText = from.PrevPageText;
235                                 }
236                         }
237                 }
238
239                 public override void MergeWith(Style s)
240                 {
241                         if(s != null && !s.IsEmpty)
242                         {
243                                 if(IsEmpty)
244                                 {
245                                         CopyFrom(s);
246                                         return;
247                                 }
248
249                                 base.MergeWith(s);
250
251                                 if(!(s is DataGridPagerStyle)) return;
252
253                                 DataGridPagerStyle with = (DataGridPagerStyle)s;
254                                 if(with.IsSet(MODE) && !IsSet(MODE))
255                                 {
256                                         Mode = with.Mode;
257                                 }
258                                 if(with.IsSet(NEXT_PG_TEXT) && !IsSet(NEXT_PG_TEXT))
259                                 {
260                                         NextPageText = with.NextPageText;
261                                 }
262                                 if(with.IsSet(PG_BTN_COUNT) && !IsSet(PG_BTN_COUNT))
263                                 {
264                                         PageButtonCount = with.PageButtonCount;
265                                 }
266                                 if(with.IsSet(POSITION) && !IsSet(POSITION))
267                                 {
268                                         Position = with.Position;
269                                 }
270                                 if(with.IsSet(VISIBLE) && !IsSet(VISIBLE))
271                                 {
272                                         Visible = with.Visible;
273                                 }
274                                 if(with.IsSet(PREV_PG_TEXT) && !IsSet(PREV_PG_TEXT))
275                                 {
276                                         PrevPageText = with.PrevPageText;
277                                 }
278                         }
279                 }
280
281                 public override void Reset()
282                 {
283                         if(IsSet(MODE))
284                         {
285                                 ViewState.Remove("Mode");
286                         }
287                         if(IsSet(NEXT_PG_TEXT))
288                         {
289                                 ViewState.Remove("NextPageText");
290                         }
291                         if(IsSet(PG_BTN_COUNT))
292                         {
293                                 ViewState.Remove("PageButtonCount");
294                         }
295                         if(IsSet(POSITION))
296                         {
297                                 ViewState.Remove("Position");
298                         }
299                         if(IsSet(VISIBLE))
300                         {
301                                 ViewState.Remove("PagerVisible");
302                         }
303                         if(IsSet(PREV_PG_TEXT))
304                         {
305                                 ViewState.Remove("PrevPageText");
306                         }
307                         base.Reset();
308                 }
309         }
310 }