2005-10-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataGridPagerStyle.cs
index 5fd349d98070996cc5c2721229a8f71be2d650b4..7c5f983cb317f50bc69d1856f528194dc968b6b9 100644 (file)
@@ -1,15 +1,3 @@
-//
-// System.Web.UI.WebControls.DataGridPagerStyle.cs
-//
-// Authors:
-//   Gaurav Vaish (gvaish@iitk.ac.in)
-//   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
-//
-// (C) Gaurav Vaish (2002)
-// (C) 2003 Andreas Nahr
-//
-
-//
 // 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
 // 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) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//     Peter Bartok    (pbartok@novell.com)
+//
+//
 
-using System;
 using System.ComponentModel;
-using System.Web;
-using System.Web.UI;
-
-namespace System.Web.UI.WebControls
-{
-       public sealed class DataGridPagerStyle : TableItemStyle
-       {
-               DataGrid owner;
-
-               private static int MODE         = (0x01 << 19);
-               private static int NEXT_PG_TEXT = (0x01 << 20);
-               private static int PG_BTN_COUNT = (0x01 << 21);
-               private static int POSITION     = (0x01 << 22);
-               private static int VISIBLE      = (0x01 << 23);
-               private static int PREV_PG_TEXT = (0x01 << 24);
-
-               internal DataGridPagerStyle(DataGrid owner): base()
-               {
-                       this.owner = owner;
+using System.Security.Permissions;
+
+namespace System.Web.UI.WebControls {
+
+       // CAS - no inheritance demand required because the class is sealed
+       [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       public sealed class DataGridPagerStyle : TableItemStyle {
+               #region Constructors
+               internal DataGridPagerStyle () {
                }
+               #endregion      // Constructors
 
-               internal bool IsPagerOnTop
-               {
+               #region Public Instance Properties
+#if ONLY_1_1
+               [Bindable(true)]
+#endif
+               [DefaultValue(PagerMode.NextPrev)]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Misc")]
+               public PagerMode Mode {
                        get {
-                               PagerPosition p = Position;
-                               return (p == PagerPosition.Top || p == PagerPosition.TopAndBottom);
+                               if ((styles & Styles.Mode) == 0) {
+                                       return PagerMode.NextPrev;
+                               }
+
+                               return (PagerMode)ViewState["Mode"];
+                       }
+
+                       set {
+                               styles |= Styles.Mode;
+                               ViewState["Mode"] = value;
                        }
                }
-               
-               internal bool IsPagerOnBottom
-               {
+
+#if NET_2_0
+               [Localizable (true)]
+#else
+               [Bindable(true)]
+#endif
+               [DefaultValue("&gt;")]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Misc")]
+               public string NextPageText {
                        get {
-                               PagerPosition p = Position;
-                               return (p == PagerPosition.Bottom || p == PagerPosition.TopAndBottom);
+                               if ((styles & Styles.NextPageText) == 0) {
+                                       return "&gt;";
+                               }
+
+                               return ViewState.GetString("NextPageText", "&gt;");
+                       }
+
+                       set {
+                               styles |= Styles.NextPageText;
+                               ViewState["NextPageText"] = value;
                        }
                }
 
-               [DefaultValue (typeof (PagerMode), "NextPrev"), Bindable (true), WebCategory ("Misc")]
-               [NotifyParentProperty (true)]
-               [WebSysDescription ("The mode used for displaying multiple pages.")]
-               public PagerMode Mode
-               {
-                       get
-                       {
-                               if(IsSet(MODE))
-                               {
-                                       return (PagerMode)ViewState["Mode"];
+#if ONLY_1_1
+               [Bindable(true)]
+#endif
+               [DefaultValue(10)]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Misc")]
+               public int PageButtonCount {
+                       get {
+                               if ((styles & Styles.PageButtonCount) == 0) {
+                                       return 10;
                                }
-                               return PagerMode.NextPrev;
+
+                               return ViewState.GetInt("PageButtonCount", 10);
                        }
-                       set
-                       {
-                               if(!Enum.IsDefined(typeof(PagerMode), value))
-                               {
-                                       throw new ArgumentOutOfRangeException("value");
+
+                       set {
+                               if (value < 1) {
+                                       throw new ArgumentOutOfRangeException("value", "PageButtonCount must be greater than 0");
                                }
-                               ViewState["Mode"] = value;
-                               Set(MODE);
+
+                               styles |= Styles.PageButtonCount;
+                               ViewState["PageButtonCount"] = value;
                        }
                }
 
-               [DefaultValue (">"), Bindable (true), WebCategory ("Misc")]
-               [NotifyParentProperty (true)]
-               [WebSysDescription ("The text for the 'next page' button.")]
-               public string NextPageText
-               {
-                       get
-                       {
-                               if(IsSet(NEXT_PG_TEXT))
-                               {
-                                       return (string)ViewState["NextPageText"];
+#if ONLY_1_1
+               [Bindable(true)]
+#endif
+               [DefaultValue(PagerPosition.Bottom)]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Misc")]
+               public PagerPosition Position {
+                       get {
+                               if ((styles & Styles.Position) == 0) {
+                                       return PagerPosition.Bottom;
                                }
-                               return "&gt;";
+
+                               return (PagerPosition)ViewState["Position"];
                        }
-                       set
-                       {
-                               ViewState["NextPageText"] = value;
-                               Set(NEXT_PG_TEXT);
+
+                       set {
+                               styles |= Styles.Position;
+                               ViewState["Position"] = value;
                        }
                }
 
-               [DefaultValue ("<"), Bindable (true), WebCategory ("Misc")]
-               [NotifyParentProperty (true)]
-               [WebSysDescription ("The text for the 'previous page' button.")]
-               public string PrevPageText
-               {
-                       get
-                       {
-                               if(IsSet(PREV_PG_TEXT))
-                               {
-                                       return (string)ViewState["PrevPageText"];
+#if NET_2_0
+               [Localizable (true)]
+#else
+               [Bindable(true)]
+#endif
+               [DefaultValue("&lt;")]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Misc")]
+               public string PrevPageText {
+                       get {
+                               if ((styles & Styles.NextPageText) == 0) {
+                                       return "&lt;";
                                }
-                               return "&lt;";
+
+                               return ViewState.GetString("PrevPageText", "&lt;");
                        }
-                       set
-                       {
+
+                       set {
+                               styles |= Styles.PrevPageText;
                                ViewState["PrevPageText"] = value;
-                               Set(PREV_PG_TEXT);
                        }
                }
 
-               [DefaultValue (10), Bindable (true), WebCategory ("Misc")]
-               [NotifyParentProperty (true)]
-               [WebSysDescription ("The maximum number of pages to show as direct links.")]
-               public int PageButtonCount
-               {
-                       get
-                       {
-                               if(IsSet(PG_BTN_COUNT))
-                               {
-                                       return (int)ViewState["PageButtonCount"];
+#if ONLY_1_1
+               [Bindable(true)]
+#endif
+               [DefaultValue(true)]
+               [NotifyParentProperty(true)]
+               [WebSysDescription ("")]
+               [WebCategory ("Misc")]
+               public bool Visible {
+                       get {
+                               if ((styles & Styles.Visible) == 0) {
+                                       return true;
                                }
-                               return 10;
+
+                               return ViewState.GetBool("Visible", true);
                        }
-                       set
-                       {
-                               if (value < 1)
-                                       throw new ArgumentOutOfRangeException("value");
-                                
-                               ViewState["PageButtonCount"] = value;
-                               Set(PG_BTN_COUNT);
+
+                       set {
+                               styles |= Styles.Visible;
+                               ViewState["Visible"] = value;
                        }
                }
+               #endregion      // Public Instance Properties
 
-               [DefaultValue (typeof (PagerPosition), "Bottom"), Bindable (true), WebCategory ("Misc")]
-               [NotifyParentProperty (true)]
-               [WebSysDescription ("The position for the page display.")]
-               public PagerPosition Position
-               {
-                       get
-                       {
-                               if(IsSet(POSITION))
-                               {
-                                       return (PagerPosition)ViewState["Position"];
-                               }
-                               return PagerPosition.Bottom;
+               #region Public Instance Methods
+               public override void CopyFrom(Style s) {
+                       base.CopyFrom (s);
+
+                       if (s == null || s.IsEmpty) {
+                               return;
                        }
-                       set
-                       {
-                               if(!Enum.IsDefined(typeof(PagerPosition), value))
-                               {
-                                       throw new ArgumentException();
-                               }
-                               ViewState["Position"] = value;
-                               Set(POSITION);
+
+                       if (((s.styles & Styles.Mode) != 0) && (((DataGridPagerStyle)s).Mode != PagerMode.NextPrev)) {
+                               this.Mode = ((DataGridPagerStyle)s).Mode;
                        }
-               }
 
-               [DefaultValue (true), Bindable (true), WebCategory ("Misc")]
-               [NotifyParentProperty (true)]
-               [WebSysDescription ("Determines if paging functionallity is visible to the user.")]
-               public bool Visible
-               {
-                       get
-                       {
-                               if(IsSet(VISIBLE))
-                               {
-                                       return (bool)ViewState["PagerVisible"];
-                               }
-                               return true;
+                       if (((s.styles & Styles.NextPageText) != 0) && (((DataGridPagerStyle)s).NextPageText != "&gt;")) {
+                               this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
                        }
-                       set
-                       {
-                               ViewState["PagerVisible"] = value;
-                               Set(VISIBLE);
-                               owner.OnPagerChanged();
+
+                       if (((s.styles & Styles.PageButtonCount) != 0) && (((DataGridPagerStyle)s).PageButtonCount != 10)) {
+                               this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
                        }
-               }
 
-               public override void CopyFrom(Style s)
-               {
-                       if(s != null && !s.IsEmpty)
-                       {
-                               base.CopyFrom(s);
-                               if(!(s is DataGridPagerStyle)) return;
-
-                               DataGridPagerStyle from = (DataGridPagerStyle)s;
-                               if(from.IsSet(MODE))
-                               {
-                                       Mode = from.Mode;
-                               }
-                               if(from.IsSet(NEXT_PG_TEXT))
-                               {
-                                       NextPageText = from.NextPageText;
-                               }
-                               if(from.IsSet(PG_BTN_COUNT))
-                               {
-                                       PageButtonCount = from.PageButtonCount;
-                               }
-                               if(from.IsSet(POSITION))
-                               {
-                                       Position = from.Position;
-                               }
-                               if(from.IsSet(VISIBLE))
-                               {
-                                       Visible = from.Visible;
-                               }
-                               if(from.IsSet(PREV_PG_TEXT))
-                               {
-                                       PrevPageText = from.PrevPageText;
-                               }
+                       if (((s.styles & Styles.Position) != 0) && (((DataGridPagerStyle)s).Position != PagerPosition.Bottom)) {
+                               this.Position = ((DataGridPagerStyle)s).Position;
+                       }
+
+                       if (((s.styles & Styles.PrevPageText) != 0) && (((DataGridPagerStyle)s).PrevPageText != "&lt;")) {
+                               this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
                        }
+
+                       if (((s.styles & Styles.Visible) != 0) && (((DataGridPagerStyle)s).Visible != true)) {
+                               this.Visible = ((DataGridPagerStyle)s).Visible;
+                       }
+
                }
 
-               public override void MergeWith(Style s)
-               {
-                       if(s != null && !s.IsEmpty)
-                       {
-                               if(IsEmpty)
-                               {
-                                       CopyFrom(s);
-                                       return;
-                               }
+               public override void MergeWith(Style s) {
+                       base.MergeWith (s);
 
-                               base.MergeWith(s);
+                       if (s == null || s.IsEmpty) {
+                               return;
+                       }
 
-                               if(!(s is DataGridPagerStyle)) return;
+                       if (((styles & Styles.Mode) == 0) && ((s.styles & Styles.Mode) != 0) && (((DataGridPagerStyle)s).Mode != PagerMode.NextPrev)) {
+                               this.Mode = ((DataGridPagerStyle)s).Mode;
+                       }
 
-                               DataGridPagerStyle with = (DataGridPagerStyle)s;
-                               if(with.IsSet(MODE) && !IsSet(MODE))
-                               {
-                                       Mode = with.Mode;
-                               }
-                               if(with.IsSet(NEXT_PG_TEXT) && !IsSet(NEXT_PG_TEXT))
-                               {
-                                       NextPageText = with.NextPageText;
-                               }
-                               if(with.IsSet(PG_BTN_COUNT) && !IsSet(PG_BTN_COUNT))
-                               {
-                                       PageButtonCount = with.PageButtonCount;
-                               }
-                               if(with.IsSet(POSITION) && !IsSet(POSITION))
-                               {
-                                       Position = with.Position;
-                               }
-                               if(with.IsSet(VISIBLE) && !IsSet(VISIBLE))
-                               {
-                                       Visible = with.Visible;
-                               }
-                               if(with.IsSet(PREV_PG_TEXT) && !IsSet(PREV_PG_TEXT))
-                               {
-                                       PrevPageText = with.PrevPageText;
-                               }
+                       if (((styles & Styles.NextPageText) == 0) && ((s.styles & Styles.NextPageText) != 0) && (((DataGridPagerStyle)s).NextPageText != "&gt;")) {
+                               this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
+                       }
+
+                       if (((styles & Styles.PageButtonCount) == 0) && ((s.styles & Styles.PageButtonCount) != 0) && (((DataGridPagerStyle)s).PageButtonCount != 10)) {
+                               this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
+                       }
+
+                       if (((styles & Styles.Position) == 0) && ((s.styles & Styles.Position) != 0) && (((DataGridPagerStyle)s).Position != PagerPosition.Bottom)) {
+                               this.Position = ((DataGridPagerStyle)s).Position;
+                       }
+
+                       if (((styles & Styles.PrevPageText) == 0) && ((s.styles & Styles.PrevPageText) != 0) && (((DataGridPagerStyle)s).PrevPageText != "&lt;")) {
+                               this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
+                       }
+
+                       if (((styles & Styles.Visible) == 0) && ((s.styles & Styles.Visible) != 0) && (((DataGridPagerStyle)s).Visible != true)) {
+                               this.Visible = ((DataGridPagerStyle)s).Visible;
                        }
                }
 
-               public override void Reset()
+               public override void Reset() {
+                       // We call base.Reset(), we don't need this
+                       //styles &= ~(Styles.Mode | Styles.NextPageText | Styles.PageButtonCount | Styles.Position | Styles.PrevPageText | Styles.Visible);
+
+                       ViewState.Remove("Mode");
+                       ViewState.Remove("NextPageText");
+                       ViewState.Remove("PageButtonCount");
+                       ViewState.Remove("Position");
+                       ViewState.Remove("PrevPageText");
+                       ViewState.Remove("Visible");
+
+                       base.Reset ();
+               }
+
+               internal override void LoadViewStateInternal()
                {
-                       if(IsSet(MODE))
-                       {
-                               ViewState.Remove("Mode");
+                       if (viewstate["Mode"] != null) {
+                               styles |= Styles.Mode;
                        }
-                       if(IsSet(NEXT_PG_TEXT))
-                       {
-                               ViewState.Remove("NextPageText");
+                       if (viewstate["NextPageText"] != null) {
+                               styles |= Styles.NextPageText;
                        }
-                       if(IsSet(PG_BTN_COUNT))
-                       {
-                               ViewState.Remove("PageButtonCount");
+                       if (viewstate["PageButtonCount"] != null) {
+                               styles |= Styles.PageButtonCount;
                        }
-                       if(IsSet(POSITION))
-                       {
-                               ViewState.Remove("Position");
+                       if (viewstate["Position"] != null) {
+                               styles |= Styles.Position;
                        }
-                       if(IsSet(VISIBLE))
-                       {
-                               ViewState.Remove("PagerVisible");
+                       if (viewstate["PrevPageText"] != null) {
+                               styles |= Styles.PrevPageText;
                        }
-                       if(IsSet(PREV_PG_TEXT))
-                       {
-                               ViewState.Remove("PrevPageText");
+                       if (viewstate["Visible"] != null) {
+                               styles |= Styles.Visible;
                        }
-                       base.Reset();
+
+                       base.LoadViewStateInternal();
                }
+               #endregion      // Public Instance Methods
        }
 }