2004-05-26 Gonzalo Paniagua Javier <gonzalo@ximian.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 using System;
13 using System.ComponentModel;
14 using System.Web;
15 using System.Web.UI;
16
17 namespace System.Web.UI.WebControls
18 {
19         public sealed class DataGridPagerStyle : TableItemStyle
20         {
21                 DataGrid owner;
22
23                 private static int MODE         = (0x01 << 19);
24                 private static int NEXT_PG_TEXT = (0x01 << 20);
25                 private static int PG_BTN_COUNT = (0x01 << 21);
26                 private static int POSITION     = (0x01 << 22);
27                 private static int VISIBLE      = (0x01 << 23);
28                 private static int PREV_PG_TEXT = (0x01 << 24);
29
30                 internal DataGridPagerStyle(DataGrid owner): base()
31                 {
32                         this.owner = owner;
33                 }
34
35                 internal bool IsPagerOnTop
36                 {
37                         get {
38                                 PagerPosition p = Position;
39                                 return (p == PagerPosition.Top || p == PagerPosition.TopAndBottom);
40                         }
41                 }
42                 
43                 internal bool IsPagerOnBottom
44                 {
45                         get {
46                                 PagerPosition p = Position;
47                                 return (p == PagerPosition.Bottom || p == PagerPosition.TopAndBottom);
48                         }
49                 }
50
51                 [DefaultValue (typeof (PagerMode), "NextPrev"), Bindable (true), WebCategory ("Misc")]
52                 [NotifyParentProperty (true)]
53                 [WebSysDescription ("The mode used for displaying multiple pages.")]
54                 public PagerMode Mode
55                 {
56                         get
57                         {
58                                 if(IsSet(MODE))
59                                 {
60                                         return (PagerMode)ViewState["Mode"];
61                                 }
62                                 return PagerMode.NextPrev;
63                         }
64                         set
65                         {
66                                 if(!Enum.IsDefined(typeof(PagerMode), value))
67                                 {
68                                         throw new ArgumentOutOfRangeException("value");
69                                 }
70                                 ViewState["Mode"] = value;
71                                 Set(MODE);
72                         }
73                 }
74
75                 [DefaultValue (">"), Bindable (true), WebCategory ("Misc")]
76                 [NotifyParentProperty (true)]
77                 [WebSysDescription ("The text for the 'next page' button.")]
78                 public string NextPageText
79                 {
80                         get
81                         {
82                                 if(IsSet(NEXT_PG_TEXT))
83                                 {
84                                         return (string)ViewState["NextPageText"];
85                                 }
86                                 return "&gt;";
87                         }
88                         set
89                         {
90                                 ViewState["NextPageText"] = value;
91                                 Set(NEXT_PG_TEXT);
92                         }
93                 }
94
95                 [DefaultValue ("<"), Bindable (true), WebCategory ("Misc")]
96                 [NotifyParentProperty (true)]
97                 [WebSysDescription ("The text for the 'previous page' button.")]
98                 public string PrevPageText
99                 {
100                         get
101                         {
102                                 if(IsSet(PREV_PG_TEXT))
103                                 {
104                                         return (string)ViewState["PrevPageText"];
105                                 }
106                                 return "&lt;";
107                         }
108                         set
109                         {
110                                 ViewState["PrevPageText"] = value;
111                                 Set(PREV_PG_TEXT);
112                         }
113                 }
114
115                 [DefaultValue (10), Bindable (true), WebCategory ("Misc")]
116                 [NotifyParentProperty (true)]
117                 [WebSysDescription ("The maximum number of pages to show as direct links.")]
118                 public int PageButtonCount
119                 {
120                         get
121                         {
122                                 if(IsSet(PG_BTN_COUNT))
123                                 {
124                                         return (int)ViewState["PageButtonCount"];
125                                 }
126                                 return 10;
127                         }
128                         set
129                         {
130                                 if (value < 1)
131                                         throw new ArgumentOutOfRangeException("value");
132                                 
133                                 ViewState["PageButtonCount"] = value;
134                                 Set(PG_BTN_COUNT);
135                         }
136                 }
137
138                 [DefaultValue (typeof (PagerPosition), "Bottom"), Bindable (true), WebCategory ("Misc")]
139                 [NotifyParentProperty (true)]
140                 [WebSysDescription ("The position for the page display.")]
141                 public PagerPosition Position
142                 {
143                         get
144                         {
145                                 if(IsSet(POSITION))
146                                 {
147                                         return (PagerPosition)ViewState["Position"];
148                                 }
149                                 return PagerPosition.Bottom;
150                         }
151                         set
152                         {
153                                 if(!Enum.IsDefined(typeof(PagerPosition), value))
154                                 {
155                                         throw new ArgumentException();
156                                 }
157                                 ViewState["Position"] = value;
158                                 Set(POSITION);
159                         }
160                 }
161
162                 [DefaultValue (true), Bindable (true), WebCategory ("Misc")]
163                 [NotifyParentProperty (true)]
164                 [WebSysDescription ("Determines if paging functionallity is visible to the user.")]
165                 public bool Visible
166                 {
167                         get
168                         {
169                                 if(IsSet(VISIBLE))
170                                 {
171                                         return (bool)ViewState["PagerVisible"];
172                                 }
173                                 return true;
174                         }
175                         set
176                         {
177                                 ViewState["PagerVisible"] = value;
178                                 Set(VISIBLE);
179                                 owner.OnPagerChanged();
180                         }
181                 }
182
183                 public override void CopyFrom(Style s)
184                 {
185                         if(s != null && !s.IsEmpty)
186                         {
187                                 base.CopyFrom(s);
188                                 if(!(s is DataGridPagerStyle)) return;
189
190                                 DataGridPagerStyle from = (DataGridPagerStyle)s;
191                                 if(from.IsSet(MODE))
192                                 {
193                                         Mode = from.Mode;
194                                 }
195                                 if(from.IsSet(NEXT_PG_TEXT))
196                                 {
197                                         NextPageText = from.NextPageText;
198                                 }
199                                 if(from.IsSet(PG_BTN_COUNT))
200                                 {
201                                         PageButtonCount = from.PageButtonCount;
202                                 }
203                                 if(from.IsSet(POSITION))
204                                 {
205                                         Position = from.Position;
206                                 }
207                                 if(from.IsSet(VISIBLE))
208                                 {
209                                         Visible = from.Visible;
210                                 }
211                                 if(from.IsSet(PREV_PG_TEXT))
212                                 {
213                                         PrevPageText = from.PrevPageText;
214                                 }
215                         }
216                 }
217
218                 public override void MergeWith(Style s)
219                 {
220                         if(s != null && !s.IsEmpty)
221                         {
222                                 if(IsEmpty)
223                                 {
224                                         CopyFrom(s);
225                                         return;
226                                 }
227
228                                 base.MergeWith(s);
229
230                                 if(!(s is DataGridPagerStyle)) return;
231
232                                 DataGridPagerStyle with = (DataGridPagerStyle)s;
233                                 if(with.IsSet(MODE) && !IsSet(MODE))
234                                 {
235                                         Mode = with.Mode;
236                                 }
237                                 if(with.IsSet(NEXT_PG_TEXT) && !IsSet(NEXT_PG_TEXT))
238                                 {
239                                         NextPageText = with.NextPageText;
240                                 }
241                                 if(with.IsSet(PG_BTN_COUNT) && !IsSet(PG_BTN_COUNT))
242                                 {
243                                         PageButtonCount = with.PageButtonCount;
244                                 }
245                                 if(with.IsSet(POSITION) && !IsSet(POSITION))
246                                 {
247                                         Position = with.Position;
248                                 }
249                                 if(with.IsSet(VISIBLE) && !IsSet(VISIBLE))
250                                 {
251                                         Visible = with.Visible;
252                                 }
253                                 if(with.IsSet(PREV_PG_TEXT) && !IsSet(PREV_PG_TEXT))
254                                 {
255                                         PrevPageText = with.PrevPageText;
256                                 }
257                         }
258                 }
259
260                 public override void Reset()
261                 {
262                         if(IsSet(MODE))
263                         {
264                                 ViewState.Remove("Mode");
265                         }
266                         if(IsSet(NEXT_PG_TEXT))
267                         {
268                                 ViewState.Remove("NextPageText");
269                         }
270                         if(IsSet(PG_BTN_COUNT))
271                         {
272                                 ViewState.Remove("PageButtonCount");
273                         }
274                         if(IsSet(POSITION))
275                         {
276                                 ViewState.Remove("Position");
277                         }
278                         if(IsSet(VISIBLE))
279                         {
280                                 ViewState.Remove("PagerVisible");
281                         }
282                         if(IsSet(PREV_PG_TEXT))
283                         {
284                                 ViewState.Remove("PrevPageText");
285                         }
286                         base.Reset();
287                 }
288         }
289 }