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
70 [WebCategoryAttribute ("Appearance")]
\r
71 [DefaultValueAttribute ("<<")]
\r
72 [NotifyParentPropertyAttribute (true)]
\r
73 public string FirstPageText {
\r
75 object ob = ViewState ["FirstPageText"];
\r
76 if (ob != null) return (string) ob;
\r
80 ViewState ["FirstPageText"] = value;
\r
84 [WebCategoryAttribute ("Appearance")]
\r
85 [NotifyParentPropertyAttribute (true)]
\r
86 [UrlPropertyAttribute]
\r
87 [DefaultValueAttribute ("")]
\r
88 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
89 public string LastPageImageUrl {
\r
91 object ob = ViewState ["LastPageImageUrl"];
\r
92 if (ob != null) return (string) ob;
\r
93 return string.Empty;
\r
96 ViewState ["LastPageImageUrl"] = value;
\r
100 [NotifyParentPropertyAttribute (true)]
\r
101 [WebCategoryAttribute ("Appearance")]
\r
102 [DefaultValueAttribute (">>")]
\r
103 public string LastPageText {
\r
105 object ob = ViewState ["LastPageText"];
\r
106 if (ob != null) return (string) ob;
\r
110 ViewState ["LastPageText"] = value;
\r
114 [NotifyParentPropertyAttribute (true)]
\r
115 [WebCategoryAttribute ("Appearance")]
\r
116 [DefaultValueAttribute (PagerButtons.Numeric)]
\r
117 public PagerButtons Mode {
\r
119 object ob = ViewState ["Mode"];
\r
120 if (ob != null) return (PagerButtons) ob;
\r
121 return PagerButtons.Numeric;
\r
124 ViewState ["Mode"] = value;
\r
128 [WebCategoryAttribute ("Appearance")]
\r
129 [NotifyParentPropertyAttribute (true)]
\r
130 [UrlPropertyAttribute]
\r
131 [DefaultValueAttribute ("")]
\r
132 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
133 public string NextPageImageUrl {
\r
135 object ob = ViewState ["NextPageImageUrl"];
\r
136 if (ob != null) return (string) ob;
\r
137 return string.Empty;
\r
140 ViewState ["NextPageImageUrl"] = value;
\r
144 [WebCategoryAttribute ("Appearance")]
\r
145 [NotifyParentPropertyAttribute (true)]
\r
146 [DefaultValueAttribute (">")]
\r
147 public string NextPageText {
\r
149 object ob = ViewState ["NextPageText"];
\r
150 if (ob != null) return (string) ob;
\r
154 ViewState ["NextPageText"] = value;
\r
158 [WebCategoryAttribute ("Behavior")]
\r
159 [NotifyParentPropertyAttribute (true)]
\r
160 [DefaultValueAttribute (10)]
\r
161 public int PageButtonCount {
\r
163 object ob = ViewState ["PageButtonCount"];
\r
164 if (ob != null) return (int) ob;
\r
168 ViewState ["PageButtonCount"] = value;
\r
172 [WebCategoryAttribute ("Layout")]
\r
173 [DefaultValueAttribute (PagerPosition.Bottom)]
\r
174 [NotifyParentPropertyAttribute (true)]
\r
175 public PagerPosition Position {
\r
177 object ob = ViewState ["Position"];
\r
178 if (ob != null) return (PagerPosition) ob;
\r
179 return PagerPosition.Bottom;
\r
182 ViewState ["Position"] = value;
\r
186 [WebCategoryAttribute ("Appearance")]
\r
187 [NotifyParentPropertyAttribute (true)]
\r
188 [UrlPropertyAttribute]
\r
189 [DefaultValueAttribute ("")]
\r
190 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
191 public string PreviousPageImageUrl {
\r
193 object ob = ViewState ["PreviousPageImageUrl"];
\r
194 if (ob != null) return (string) ob;
\r
195 return string.Empty;
\r
198 ViewState ["PreviousPageImageUrl"] = value;
\r
202 [WebCategoryAttribute ("Appearance")]
\r
203 [DefaultValueAttribute ("<")]
\r
204 [NotifyParentPropertyAttribute (true)]
\r
205 public string PreviousPageText {
\r
207 object ob = ViewState ["PreviousPageText"];
\r
208 if (ob != null) return (string) ob;
\r
212 ViewState ["PreviousPageText"] = value;
\r
216 [WebCategoryAttribute ("Appearance")]
\r
217 [DefaultValueAttribute (true)]
\r
218 [NotifyParentPropertyAttribute (true)]
\r
219 public bool Visible {
\r
221 object ob = ViewState ["Visible"];
\r
222 if (ob != null) return (bool) ob;
\r
226 ViewState ["Visible"] = value;
\r
230 public override string ToString ()
\r
232 return string.Empty;
\r
235 void IStateManager.LoadViewState (object savedState)
\r
237 ViewState.LoadViewState (savedState);
\r
240 object IStateManager.SaveViewState ()
\r
242 return ViewState.SaveViewState();
\r
245 void IStateManager.TrackViewState ()
\r
247 ViewState.TrackViewState();
\r
250 bool IStateManager.IsTrackingViewState
\r
252 get { return ViewState.IsTrackingViewState; }
\r
255 internal Table CreatePagerControl (int currentPage, int pageCount)
\r
257 Table table = new Table ();
\r
258 TableRow row = new TableRow ();
\r
259 table.Rows.Add (row);
\r
261 if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast)
\r
263 if (currentPage > 0) {
\r
264 if (Mode == PagerButtons.NextPreviousFirstLast)
\r
265 row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
\r
266 row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev"));
\r
268 if (currentPage < pageCount - 1) {
\r
269 row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next"));
\r
270 if (Mode == PagerButtons.NextPreviousFirstLast)
\r
271 row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
\r
274 else if (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast)
\r
276 int first = currentPage / PageButtonCount;
\r
277 int last = first + PageButtonCount;
\r
278 if (last >= pageCount) last = pageCount;
\r
281 if (Mode == PagerButtons.NumericFirstLast)
\r
282 row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
\r
283 row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev"));
\r
286 for (int n = first; n < last; n++)
\r
287 row.Cells.Add (CreateCell ((n+1).ToString(), string.Empty, (n != currentPage) ? "Page" : "", (n+1).ToString()));
\r
289 if (last < pageCount - 1) {
\r
290 row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next"));
\r
291 if (Mode == PagerButtons.NumericFirstLast)
\r
292 row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
\r
298 TableCell CreateCell (string text, string image, string command, string argument)
\r
300 TableCell cell = new TableCell ();
\r
301 cell.Controls.Add (new DataControlButton (ctrl, text, image, command, argument, true));
\r