| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- //
- // System.Web.UI.WebControls.PagerSettings.cs
- //
- // Authors:
- // Lluis Sanchez Gual ([email protected])
- //
- // (C) 2005 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
- //
- #if NET_2_0
- using System.ComponentModel;
- using System.Security.Permissions;
- namespace System.Web.UI.WebControls
- {
- [TypeConverterAttribute (typeof(ExpandableObjectConverter))]
- [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- public sealed class PagerSettings: IStateManager
- {
- StateBag ViewState = new StateBag ();
- Control ctrl;
-
- public PagerSettings ()
- {
- }
-
- internal PagerSettings (Control ctrl)
- {
- this.ctrl = ctrl;
- }
- [WebCategoryAttribute ("Appearance")]
- [NotifyParentPropertyAttribute (true)]
- [UrlPropertyAttribute]
- [DefaultValueAttribute ("")]
- [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- public string FirstPageImageUrl {
- get {
- object ob = ViewState ["FirstPageImageUrl"];
- if (ob != null) return (string) ob;
- return string.Empty;
- }
- set {
- ViewState ["FirstPageImageUrl"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute ("<<")]
- [NotifyParentPropertyAttribute (true)]
- public string FirstPageText {
- get {
- object ob = ViewState ["FirstPageText"];
- if (ob != null) return (string) ob;
- return "<<";
- }
- set {
- ViewState ["FirstPageText"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [NotifyParentPropertyAttribute (true)]
- [UrlPropertyAttribute]
- [DefaultValueAttribute ("")]
- [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- public string LastPageImageUrl {
- get {
- object ob = ViewState ["LastPageImageUrl"];
- if (ob != null) return (string) ob;
- return string.Empty;
- }
- set {
- ViewState ["LastPageImageUrl"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [NotifyParentPropertyAttribute (true)]
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute (">>")]
- public string LastPageText {
- get {
- object ob = ViewState ["LastPageText"];
- if (ob != null) return (string) ob;
- return ">>";
- }
- set {
- ViewState ["LastPageText"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [NotifyParentPropertyAttribute (true)]
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute (PagerButtons.Numeric)]
- public PagerButtons Mode {
- get {
- object ob = ViewState ["Mode"];
- if (ob != null) return (PagerButtons) ob;
- return PagerButtons.Numeric;
- }
- set {
- ViewState ["Mode"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [NotifyParentPropertyAttribute (true)]
- [UrlPropertyAttribute]
- [DefaultValueAttribute ("")]
- [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- public string NextPageImageUrl {
- get {
- object ob = ViewState ["NextPageImageUrl"];
- if (ob != null) return (string) ob;
- return string.Empty;
- }
- set {
- ViewState ["NextPageImageUrl"] = value;
- RaisePropertyChanged ();
- }
- }
- [WebCategoryAttribute ("Appearance")]
- [NotifyParentPropertyAttribute (true)]
- [DefaultValueAttribute (">")]
- public string NextPageText {
- get {
- object ob = ViewState ["NextPageText"];
- if (ob != null) return (string) ob;
- return ">";
- }
- set {
- ViewState ["NextPageText"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [WebCategoryAttribute ("Behavior")]
- [NotifyParentPropertyAttribute (true)]
- [DefaultValueAttribute (10)]
- public int PageButtonCount {
- get {
- object ob = ViewState ["PageButtonCount"];
- if (ob != null) return (int) ob;
- return 10;
- }
- set {
- ViewState ["PageButtonCount"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [WebCategoryAttribute ("Layout")]
- [DefaultValueAttribute (PagerPosition.Bottom)]
- [NotifyParentPropertyAttribute (true)]
- public PagerPosition Position {
- get {
- object ob = ViewState ["Position"];
- if (ob != null) return (PagerPosition) ob;
- return PagerPosition.Bottom;
- }
- set {
- ViewState ["Position"] = value;
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [NotifyParentPropertyAttribute (true)]
- [UrlPropertyAttribute]
- [DefaultValueAttribute ("")]
- [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- public string PreviousPageImageUrl {
- get {
- object ob = ViewState ["PreviousPageImageUrl"];
- if (ob != null) return (string) ob;
- return string.Empty;
- }
- set {
- ViewState ["PreviousPageImageUrl"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute ("<")]
- [NotifyParentPropertyAttribute (true)]
- public string PreviousPageText {
- get {
- object ob = ViewState ["PreviousPageText"];
- if (ob != null) return (string) ob;
- return "<";
- }
- set {
- ViewState ["PreviousPageText"] = value;
- RaisePropertyChanged ();
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute (true)]
- [NotifyParentPropertyAttribute (true)]
- public bool Visible {
- get {
- object ob = ViewState ["Visible"];
- if (ob != null) return (bool) ob;
- return true;
- }
- set {
- ViewState ["Visible"] = value;
- }
- }
- public event EventHandler PropertyChanged;
- void RaisePropertyChanged ()
- {
- if (PropertyChanged != null)
- PropertyChanged (this, EventArgs.Empty);
- }
- public override string ToString ()
- {
- return string.Empty;
- }
- void IStateManager.LoadViewState (object savedState)
- {
- ViewState.LoadViewState (savedState);
- }
-
- object IStateManager.SaveViewState ()
- {
- return ViewState.SaveViewState();
- }
-
- void IStateManager.TrackViewState ()
- {
- ViewState.TrackViewState();
- }
-
- bool IStateManager.IsTrackingViewState
- {
- get { return ViewState.IsTrackingViewState; }
- }
-
- internal Table CreatePagerControl (int currentPage, int pageCount, Style style)
- {
- Table table = new Table ();
- TableRow row = new TableRow ();
- table.Rows.Add (row);
- if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast)
- {
- if (currentPage > 0) {
- if (Mode == PagerButtons.NextPreviousFirstLast)
- row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First", style));
- row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev", style));
- }
- if (currentPage < pageCount - 1) {
- row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next", style));
- if (Mode == PagerButtons.NextPreviousFirstLast)
- row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last", style));
- }
- }
- else if (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast)
- {
- int pbc = PageButtonCount;
- int cp = currentPage + 1;
- int pbp = pbc <= cp ? cp / pbc : 0;
- int first = cp < pbc ? 0 : (cp + (pbp % pbc) - (pbc + pbp)) + 1;
- int last = first + pbc;
- if (last >= pageCount) last = pageCount;
-
- if (first > 0) {
- if (Mode == PagerButtons.NumericFirstLast)
- row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First", style));
- row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev", style));
- }
-
- for (int n = first; n < last; n++)
- row.Cells.Add (CreateCell ((n + 1).ToString (), string.Empty, (n != currentPage) ? "Page" : "", (n + 1).ToString (), style));
-
- if (last < pageCount - 1) {
- row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next", style));
- if (Mode == PagerButtons.NumericFirstLast)
- row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last", style));
- }
- }
- return table;
- }
- TableCell CreateCell (string text, string image, string command, string argument, Style style) {
- TableCell cell = new TableCell ();
- DataControlButton button = new DataControlButton (ctrl, text, image, command, argument, true);
- if (image.Length > 0)
- button.ButtonType = ButtonType.Image;
- else if (command.Length > 0 && style != null)
- button.ForeColor = style.ForeColor;
-
- cell.Controls.Add (button);
- return cell;
- }
- }
- }
- #endif
|