2 // System.Web.UI.WebControls.PagerSettings.cs
\r
5 // Lluis Sanchez Gual (lluis@novell.com)
\r
7 // (C) 2005 Novell, Inc (http://www.novell.com)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
\r
10 // a copy of this software and associated documentation files (the
\r
11 // "Software"), to deal in the Software without restriction, including
\r
12 // without limitation the rights to use, copy, modify, merge, publish,
\r
13 // distribute, sublicense, and/or sell copies of the Software, and to
\r
14 // permit persons to whom the Software is furnished to do so, subject to
\r
15 // the following conditions:
\r
17 // The above copyright notice and this permission notice shall be
\r
18 // included in all copies or substantial portions of the Software.
\r
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
33 using System.ComponentModel;
\r
34 using System.Security.Permissions;
\r
36 namespace System.Web.UI.WebControls
\r
38 [TypeConverterAttribute (typeof(ExpandableObjectConverter))]
\r
39 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
\r
40 public sealed class PagerSettings: IStateManager
\r
42 StateBag ViewState = new StateBag ();
\r
45 public PagerSettings ()
\r
49 internal PagerSettings (Control ctrl)
\r
54 [WebCategoryAttribute ("Appearance")]
\r
55 [NotifyParentPropertyAttribute (true)]
\r
56 [UrlPropertyAttribute]
\r
57 [DefaultValueAttribute ("")]
\r
58 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
59 public string FirstPageImageUrl {
\r
61 object ob = ViewState ["FirstPageImageUrl"];
\r
62 if (ob != null) return (string) ob;
\r
63 return string.Empty;
\r
66 ViewState ["FirstPageImageUrl"] = value;
\r
67 RaisePropertyChanged ();
\r
71 [WebCategoryAttribute ("Appearance")]
\r
72 [DefaultValueAttribute ("<<")]
\r
73 [NotifyParentPropertyAttribute (true)]
\r
74 public string FirstPageText {
\r
76 object ob = ViewState ["FirstPageText"];
\r
77 if (ob != null) return (string) ob;
\r
81 ViewState ["FirstPageText"] = value;
\r
82 RaisePropertyChanged ();
\r
86 [WebCategoryAttribute ("Appearance")]
\r
87 [NotifyParentPropertyAttribute (true)]
\r
88 [UrlPropertyAttribute]
\r
89 [DefaultValueAttribute ("")]
\r
90 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
91 public string LastPageImageUrl {
\r
93 object ob = ViewState ["LastPageImageUrl"];
\r
94 if (ob != null) return (string) ob;
\r
95 return string.Empty;
\r
98 ViewState ["LastPageImageUrl"] = value;
\r
99 RaisePropertyChanged ();
\r
103 [NotifyParentPropertyAttribute (true)]
\r
104 [WebCategoryAttribute ("Appearance")]
\r
105 [DefaultValueAttribute (">>")]
\r
106 public string LastPageText {
\r
108 object ob = ViewState ["LastPageText"];
\r
109 if (ob != null) return (string) ob;
\r
113 ViewState ["LastPageText"] = value;
\r
114 RaisePropertyChanged ();
\r
118 [NotifyParentPropertyAttribute (true)]
\r
119 [WebCategoryAttribute ("Appearance")]
\r
120 [DefaultValueAttribute (PagerButtons.Numeric)]
\r
121 public PagerButtons Mode {
\r
123 object ob = ViewState ["Mode"];
\r
124 if (ob != null) return (PagerButtons) ob;
\r
125 return PagerButtons.Numeric;
\r
128 ViewState ["Mode"] = value;
\r
129 RaisePropertyChanged ();
\r
133 [WebCategoryAttribute ("Appearance")]
\r
134 [NotifyParentPropertyAttribute (true)]
\r
135 [UrlPropertyAttribute]
\r
136 [DefaultValueAttribute ("")]
\r
137 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
138 public string NextPageImageUrl {
\r
140 object ob = ViewState ["NextPageImageUrl"];
\r
141 if (ob != null) return (string) ob;
\r
142 return string.Empty;
\r
145 ViewState ["NextPageImageUrl"] = value;
\r
146 RaisePropertyChanged ();
\r
150 [WebCategoryAttribute ("Appearance")]
\r
151 [NotifyParentPropertyAttribute (true)]
\r
152 [DefaultValueAttribute (">")]
\r
153 public string NextPageText {
\r
155 object ob = ViewState ["NextPageText"];
\r
156 if (ob != null) return (string) ob;
\r
160 ViewState ["NextPageText"] = value;
\r
161 RaisePropertyChanged ();
\r
165 [WebCategoryAttribute ("Behavior")]
\r
166 [NotifyParentPropertyAttribute (true)]
\r
167 [DefaultValueAttribute (10)]
\r
168 public int PageButtonCount {
\r
170 object ob = ViewState ["PageButtonCount"];
\r
171 if (ob != null) return (int) ob;
\r
175 ViewState ["PageButtonCount"] = value;
\r
176 RaisePropertyChanged ();
\r
180 [WebCategoryAttribute ("Layout")]
\r
181 [DefaultValueAttribute (PagerPosition.Bottom)]
\r
182 [NotifyParentPropertyAttribute (true)]
\r
183 public PagerPosition Position {
\r
185 object ob = ViewState ["Position"];
\r
186 if (ob != null) return (PagerPosition) ob;
\r
187 return PagerPosition.Bottom;
\r
190 ViewState ["Position"] = value;
\r
194 [WebCategoryAttribute ("Appearance")]
\r
195 [NotifyParentPropertyAttribute (true)]
\r
196 [UrlPropertyAttribute]
\r
197 [DefaultValueAttribute ("")]
\r
198 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
199 public string PreviousPageImageUrl {
\r
201 object ob = ViewState ["PreviousPageImageUrl"];
\r
202 if (ob != null) return (string) ob;
\r
203 return string.Empty;
\r
206 ViewState ["PreviousPageImageUrl"] = value;
\r
207 RaisePropertyChanged ();
\r
211 [WebCategoryAttribute ("Appearance")]
\r
212 [DefaultValueAttribute ("<")]
\r
213 [NotifyParentPropertyAttribute (true)]
\r
214 public string PreviousPageText {
\r
216 object ob = ViewState ["PreviousPageText"];
\r
217 if (ob != null) return (string) ob;
\r
221 ViewState ["PreviousPageText"] = value;
\r
222 RaisePropertyChanged ();
\r
226 [WebCategoryAttribute ("Appearance")]
\r
227 [DefaultValueAttribute (true)]
\r
228 [NotifyParentPropertyAttribute (true)]
\r
229 public bool Visible {
\r
231 object ob = ViewState ["Visible"];
\r
232 if (ob != null) return (bool) ob;
\r
236 ViewState ["Visible"] = value;
\r
240 public event EventHandler PropertyChanged;
\r
242 void RaisePropertyChanged ()
\r
244 if (PropertyChanged != null)
\r
245 PropertyChanged (this, EventArgs.Empty);
\r
248 public override string ToString ()
\r
250 return string.Empty;
\r
253 void IStateManager.LoadViewState (object savedState)
\r
255 ViewState.LoadViewState (savedState);
\r
258 object IStateManager.SaveViewState ()
\r
260 return ViewState.SaveViewState();
\r
263 void IStateManager.TrackViewState ()
\r
265 ViewState.TrackViewState();
\r
268 bool IStateManager.IsTrackingViewState
\r
270 get { return ViewState.IsTrackingViewState; }
\r
273 internal Table CreatePagerControl (int currentPage, int pageCount)
\r
275 Table table = new Table ();
\r
276 TableRow row = new TableRow ();
\r
277 table.Rows.Add (row);
\r
279 int buttonCount = (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast) ? PageButtonCount : 1;
\r
280 int first = buttonCount * (currentPage / buttonCount);
\r
281 int last = first + buttonCount;
\r
282 if (last > pageCount) {
\r
284 if (last - first < buttonCount)
\r
285 first = last - buttonCount;
\r
291 if (Mode == PagerButtons.NumericFirstLast || Mode == PagerButtons.NextPreviousFirstLast) {
\r
293 row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
\r
297 if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast) {
\r
299 row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev"));
\r
303 if (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast) {
\r
305 row.Cells.Add (CreateCell ("...", string.Empty, "Page", first.ToString ()));
\r
306 for (int n = first; n < last; n++)
\r
307 row.Cells.Add (CreateCell ((n + 1).ToString (), string.Empty, (n != currentPage) ? "Page" : "", (n != currentPage) ? (n + 1).ToString () : ""));
\r
308 if (last < pageCount)
\r
309 row.Cells.Add (CreateCell ("...", string.Empty, "Page", (last + 1).ToString ()));
\r
313 if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast) {
\r
314 if (last < pageCount)
\r
315 row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next"));
\r
319 if (Mode == PagerButtons.NumericFirstLast || Mode == PagerButtons.NextPreviousFirstLast) {
\r
320 if (last < pageCount)
\r
321 row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
\r
327 TableCell CreateCell (string text, string image, string command, string argument) {
\r
328 TableCell cell = new TableCell ();
\r
331 if (String.IsNullOrEmpty (command)) {
\r
332 Label l = new Label ();
\r
337 button = (Control)DataControlButton.CreateButton (String.IsNullOrEmpty (image) ? ButtonType.Link : ButtonType.Image, ctrl, text, image, command, argument, true);
\r
339 cell.Controls.Add (button);
\r