ChangeLog: Updated ChangeLog.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / BaseDataList.cs
index 5e7c1df7a735ad982de075ac68ac9e3ebfb37902..877a8de841abee74ca86d8e2211e881bd654be52 100755 (executable)
@@ -1,35 +1,56 @@
-/**\r
- * Namespace: System.Web.UI.WebControls\r
- * Class:     BaseDataList\r
- *\r
- * Author:  Gaurav Vaish\r
- * Maintainer: gvaish@iitk.ac.in\r
- * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>\r
- * Implementation: yes\r
- * Status:  100%\r
- *\r
- * (C) Gaurav Vaish (2001)\r
- */\r
+//
+// System.Web.UI.WebControls.BaseDataList.cs
+//
+// Authors:
+//   Gaurav Vaish (gvaish@iitk.ac.in)
+//   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+//
+// (C) Gaurav Vaish (2001)
+// (C) 2003 Andreas Nahr
+//\r
+
+//
+// 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.
+//
 \r
 using System;\r
-using System.ComponentModel;\r
+using System.ComponentModel;
+using System.ComponentModel.Design;\r
 using System.Collections;\r
 using System.Web;\r
-using System.Web.UI;\r
+using System.Web.UI;
+using System.Web.Util;\r
 \r
 namespace System.Web.UI.WebControls\r
 {\r
        [DefaultEvent("SelectedIndexChanged")]\r
        [DefaultProperty("DataSource")]\r
-       //TODO: [Designer("??")]\r
+       [Designer("System.Web.UI.Design.WebControls.BaseDataListDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]\r
        public abstract class BaseDataList: WebControl\r
        {\r
                private  static readonly object SelectedIndexChangedEvent = new object();\r
                internal static string          ItemCountViewStateKey     = "_!ItemCount";\r
-               \r
+\r
                private DataKeyCollection dataKeys;\r
                private object            dataSource;\r
-               \r
+\r
                public BaseDataList() : base()\r
                {\r
                }\r
@@ -40,12 +61,26 @@ namespace System.Web.UI.WebControls
                                return true;\r
                        return false;\r
                }\r
-               \r
-               public override void DataBind()\r
+\r
+               public override ControlCollection Controls\r
                {\r
+                       get\r
+                       {\r
+                               EnsureChildControls();\r
+                               return base.Controls;\r
+                       }\r
+               }\r
+\r
+               public override void DataBind()\r
+               {
+                       #if NET_2_0
+                       RequiresDataBinding = false;
+                       #endif\r
                        OnDataBinding(EventArgs.Empty);\r
                }\r
-               \r
+\r
+               [WebCategory("Action")]\r
+               [WebSysDescription("BaseDataList_OnSelectedIndexChanged")]\r
                public event EventHandler SelectedIndexChanged\r
                {\r
                        add\r
@@ -57,7 +92,11 @@ namespace System.Web.UI.WebControls
                                Events.RemoveHandler(SelectedIndexChangedEvent, value);\r
                        }\r
                }\r
-               \r
+\r
+               [Bindable(true)]\r
+               [DefaultValue(-1)]\r
+               [WebCategory("Layout")]\r
+               [WebSysDescription("BaseDataList_CellPadding")]\r
                public virtual int CellPadding\r
                {\r
                        get\r
@@ -71,7 +110,11 @@ namespace System.Web.UI.WebControls
                                ((TableStyle)ControlStyle).CellPadding = value;\r
                        }\r
                }\r
-               \r
+\r
+               [Bindable(true)]\r
+               [DefaultValue(-1)]\r
+               [WebCategory("Layout")]\r
+               [WebSysDescription("BaseDataList_CellSpacing")]\r
                public virtual int CellSpacing\r
                {\r
                        get\r
@@ -85,7 +128,10 @@ namespace System.Web.UI.WebControls
                                ((TableStyle)ControlStyle).CellSpacing = value;\r
                        }\r
                }\r
-               \r
+\r
+               [DefaultValue("")]\r
+               [WebCategory("Data")]\r
+               [WebSysDescription("BaseDataList_DataKeyField")]\r
                public virtual string DataKeyField\r
                {\r
                        get\r
@@ -100,7 +146,10 @@ namespace System.Web.UI.WebControls
                                ViewState["DataKeyField"] = value;\r
                        }\r
                }\r
-               \r
+\r
+               [Browsable(true)]\r
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\r
+               [WebSysDescription("BaseDataList_DataKeys")]\r
                public DataKeyCollection DataKeys\r
                {\r
                        get\r
@@ -108,10 +157,13 @@ namespace System.Web.UI.WebControls
                                if( dataKeys==null )\r
                                        dataKeys = new DataKeyCollection(DataKeysArray);\r
                                return dataKeys;\r
-                               \r
+\r
                        }\r
                }\r
-               \r
+\r
+               [DefaultValue("")]\r
+               [WebCategory("Data")]\r
+               [WebSysDescription("BaseDataList_DataMember")]\r
                public string DataMember\r
                {\r
                        get\r
@@ -126,25 +178,30 @@ namespace System.Web.UI.WebControls
                                ViewState["DataMember"] = value;\r
                        }\r
                }\r
-               \r
-               public virtual object DataSource\r
-               {\r
-                       get\r
-                       {\r
-                               return dataSource;\r
-                       }\r
-                       set\r
-                       {\r
-                               if( (value!=null) && ( value is IListSource || value is IEnumerable) )\r
-                               {\r
-                                       dataSource = value;\r
-                               } else\r
-                               {\r
-                                       throw new ArgumentException(HttpRuntime.FormatResourceString("Invalid_DataSource_Type", ID));\r
-                               }\r
-                       }\r
-               }\r
 \r
+               [Bindable(true)]\r
+               [DefaultValue(null)]\r
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\r
+               [WebCategory("Data")]\r
+               [WebSysDescription("BaseDataList_DataSource")]\r
+               public virtual object DataSource {
+                       get {
+                               return dataSource;
+                       }
+                       set {
+                               if (value == null || value is IListSource || value is IEnumerable) {
+                                       dataSource = value;
+                               } else {
+                                       throw new ArgumentException (HttpRuntime.FormatResourceString (
+                                                               "Invalid_DataSource_Type", ID));
+                               }
+                       }
+               }
+
+               [Bindable(true)]\r
+               [DefaultValue(GridLines.Both)]\r
+               [WebCategory("Appearance")]\r
+               [WebSysDescription("BaseDataList_GridLines")]\r
                public virtual GridLines GridLines\r
                {\r
                        get\r
@@ -157,8 +214,15 @@ namespace System.Web.UI.WebControls
                        {\r
                                ((TableStyle)ControlStyle).GridLines = value;\r
                        }\r
-               }\r
-               \r
+               }
+
+               // LAMESPEC HorizontalAlign has a Category attribute, this should obviously be a WebCategory attribute
+               // but is defined incorrectly in the MS framework\r
+\r
+               [Bindable(true)]\r
+               [DefaultValue(HorizontalAlign.NotSet)]\r
+               [Category("Layout")]\r
+               [WebSysDescription("BaseDataList_HorizontalAlign")]\r
                public virtual HorizontalAlign HorizontalAlign\r
                {\r
                        get\r
@@ -172,7 +236,7 @@ namespace System.Web.UI.WebControls
                                ((TableStyle)ControlStyle).HorizontalAlign = value;\r
                        }\r
                }\r
-               \r
+\r
                protected ArrayList DataKeysArray\r
                {\r
                        get\r
@@ -186,7 +250,7 @@ namespace System.Web.UI.WebControls
                                return (ArrayList)o;\r
                        }\r
                }\r
-               \r
+\r
                protected override void AddParsedSubObject(object o)\r
                {\r
                        // Preventing literal controls from being added as children.\r
@@ -197,11 +261,11 @@ namespace System.Web.UI.WebControls
                        Controls.Clear();\r
                        if(ViewState[ItemCountViewStateKey]!=null)\r
                        {\r
-                               CreateControlHierarchy(true);\r
+                               CreateControlHierarchy(false);\r
                                ClearChildViewState();\r
                        }\r
                }\r
-               \r
+\r
                protected override void OnDataBinding(EventArgs e)\r
                {\r
                        base.OnDataBinding(e);\r
@@ -211,7 +275,7 @@ namespace System.Web.UI.WebControls
                        ChildControlsCreated = true;\r
                        TrackViewState();\r
                }\r
-               \r
+\r
                protected virtual void OnSelectedIndexChanged(EventArgs e)\r
                {\r
                        if(Events != null)\r
@@ -221,14 +285,110 @@ namespace System.Web.UI.WebControls
                                        eh(this, e);\r
                        }\r
                }\r
-               \r
+\r
                protected override void Render(HtmlTextWriter writer)\r
                {\r
                        PrepareControlHierarchy();\r
-                       base.RenderContents(writer);\r
+                       RenderContents(writer);\r
                }\r
-               \r
+\r
                protected abstract void PrepareControlHierarchy();\r
-               protected abstract void CreateControlHierarchy(bool useDataSource);\r
+               protected abstract void CreateControlHierarchy(bool useDataSource);
+               
+               #if NET_2_0
+
+                       
+                       // should be `internal protected' (why, oh WHY did they do that !?!)
+                       protected override void OnInit (EventArgs e)
+                       {
+                               base.OnInit(e);
+                               inited = true;
+                               if (!Page.IsPostBack)
+                                       RequiresDataBinding = true;
+                       }
+                       
+                       // should be `internal protected' (why, oh WHY did they do that !?!)
+                       protected override void OnLoad (EventArgs e)
+                       {
+                               IDataSource ds = GetDataSourceObject () as IDataSource;
+                               if (ds != null && DataSourceID != "")
+                                       ds.DataSourceChanged += new EventHandler (OnDataSourceChanged);
+                               
+                               base.OnLoad(e);
+                       }
+                       
+                       // should be `internal protected' (why, oh WHY did they do that !?!)
+                       protected override void OnPreRender (EventArgs e)
+                       {
+                               EnsureDataBound ();
+                               base.OnPreRender (e);
+                       }
+                               
+                       protected void EnsureDataBound ()
+                       {
+                               if (RequiresDataBinding && DataSourceID != "")
+                                       DataBind ();
+                       }
+                       
+                       protected virtual object GetDataSourceObject ()
+                       {
+                               if (DataSourceID != "")
+                                       return (IDataSource) NamingContainer.FindControl (DataSourceID);
+                               
+                               return DataSource;
+                       }
+                       
+                       protected virtual IEnumerable GetResolvedDataSource ()
+                       {
+                               if (DataSource != null && DataSourceID != "")
+                                       throw new HttpException ();
+                               
+                               IDataSource ds = this.GetDataSourceObject () as IDataSource;
+                               if (ds != null && DataSourceID != "")
+                                       return ds.GetView (DataMember).Select ();
+                               else if (DataSource != null)
+                                       return DataSourceHelper.GetResolvedDataSource (DataSource, DataMember);
+                               else
+                                       return null; 
+                       }
+                       
+                       protected void OnDataSourceChanged (object sender, EventArgs e)
+                       {
+                               RequiresDataBinding = true;
+                       }
+                       
+                       public virtual string DataSourceID {
+                               get {
+                                       object o = ViewState ["DataSourceID"];
+                                       if (o != null)
+                                               return (string)o;
+                                       
+                                       return String.Empty;
+                               }
+                               set {
+                                       if (inited)
+                                               RequiresDataBinding = true;
+                                       
+                                       ViewState ["DataSourceID"] = value;
+                               }
+                       }
+                       
+                       bool requiresDataBinding;
+                       protected bool RequiresDataBinding {
+                               get { return requiresDataBinding; }
+                               set { requiresDataBinding = value; }
+                       }
+                       
+                       protected bool inited;
+                               
+               #else
+                       internal IEnumerable GetResolvedDataSource ()
+                       {
+                               if (DataSource != null)
+                                       return DataSourceHelper.GetResolvedDataSource (DataSource, DataMember);
+                               else
+                                       return null; 
+                       }
+               #endif\r
        }\r
 }\r