2006-03-15 Chris Toshok <toshok@ximian.com>
authorChris Toshok <toshok@novell.com>
Wed, 15 Mar 2006 17:48:20 +0000 (17:48 -0000)
committerChris Toshok <toshok@novell.com>
Wed, 15 Mar 2006 17:48:20 +0000 (17:48 -0000)
* SiteMapDataSourceView.cs (OnDataSourceViewChanged): override.

* SiteMapDataSource.cs (StartingNodeOffset): new property.
(GetStartNode): add code to handle StartNodeOffset < 0.

* CompositeControl.cs
(ICompositeControlDesignerAccessor.RecreateChildControls): just
call the non-iface method.

* DataBoundControl.cs (GetDataSource): this is likely wrong, but
traverse up the naming container tree looking for our datasource
if we're bound using a DataSourceID.  This fixes things in the
sitemap1 test, which uses a mixture of templates and
ContentPlaceholders with the sitemapdatasource and sitemappath at
different levels in the naming container tree (let along the
itemnode template.)

* SiteMapPath.cs (DataBind): implement this by chaining up to
base.DataBind, then by looping over our children, emitting
OnItemDataBound for each SiteMapNodeItem.
(AddAttributesToRender): remove.
(CreateChildControls): call DataBind as the final step here..  I
have, of course, no idea if this is right.
(CreateControlHierarchy): don't databind our children here, as
they need to be in the Controls collection before we do.
(RenderContents): render our accessibility/screenreader stuff
here, if SkipLinkText != "".

svn path=/trunk/mcs/; revision=58030

mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/CompositeControl.cs
mcs/class/System.Web/System.Web.UI.WebControls/DataBoundControl.cs
mcs/class/System.Web/System.Web.UI.WebControls/SiteMapDataSource.cs
mcs/class/System.Web/System.Web.UI.WebControls/SiteMapDataSourceView.cs
mcs/class/System.Web/System.Web.UI.WebControls/SiteMapPath.cs

index 8fa250d270241fd61b250ea7660bdbaf944f578c..82cdb80166ab90505cfd3e2b8494acdbe4903196 100644 (file)
@@ -1,3 +1,33 @@
+2006-03-15  Chris Toshok  <toshok@ximian.com>
+
+       * SiteMapDataSourceView.cs (OnDataSourceViewChanged): override.
+
+       * SiteMapDataSource.cs (StartingNodeOffset): new property.
+       (GetStartNode): add code to handle StartNodeOffset < 0.
+
+       * CompositeControl.cs
+       (ICompositeControlDesignerAccessor.RecreateChildControls): just
+       call the non-iface method.
+
+       * DataBoundControl.cs (GetDataSource): this is likely wrong, but
+       traverse up the naming container tree looking for our datasource
+       if we're bound using a DataSourceID.  This fixes things in the
+       sitemap1 test, which uses a mixture of templates and
+       ContentPlaceholders with the sitemapdatasource and sitemappath at
+       different levels in the naming container tree (let along the
+       itemnode template.)
+
+       * SiteMapPath.cs (DataBind): implement this by chaining up to
+       base.DataBind, then by looping over our children, emitting
+       OnItemDataBound for each SiteMapNodeItem.
+       (AddAttributesToRender): remove.
+       (CreateChildControls): call DataBind as the final step here..  I
+       have, of course, no idea if this is right.
+       (CreateControlHierarchy): don't databind our children here, as
+       they need to be in the Controls collection before we do.
+       (RenderContents): render our accessibility/screenreader stuff
+       here, if SkipLinkText != "".
+
 2006-03-15  Vladimir Krasnov  <vladimirk@mainsoft.com>
 
        * DataGridPagerStyle.cs: fixed PrevPageText property
index e1145dcb2f38a3f371fad9d1764ba48ee246b2dc..2d006b14aef402e755ec392236d5e40742faed29 100644 (file)
@@ -60,12 +60,9 @@ namespace System.Web.UI.WebControls {
                        base.Render (w);
                }
 
-               [MonoTODO("not sure exactly what this one does..")]
                void ICompositeControlDesignerAccessor.RecreateChildControls ()
                {
-                       /* for now just call CreateChildControls to force
-                        * the recreation of our children. */
-                       CreateChildControls ();
+                       RecreateChildControls ();
                }
 
                [MonoTODO("not sure exactly what this one does..")]
index 7c14828aa1f0c0d546475d397ca6e0f61ad5bdea..19611db6573bc592f8fff4e08c6bc58dc2f9ee0b 100644 (file)
@@ -65,7 +65,18 @@ namespace System.Web.UI.WebControls {
                protected virtual IDataSource GetDataSource ()
                {
                        if (IsBoundUsingDataSourceID) {
-                               Control ctrl = NamingContainer.FindControl (DataSourceID);
+                               Control namingContainer;
+                               Control ctrl = null;
+
+                               namingContainer = NamingContainer;
+                               
+                               while (namingContainer != null) {
+                                       ctrl = namingContainer.FindControl (DataSourceID);
+                                       if (ctrl != null)
+                                               break;
+                                       namingContainer = namingContainer.NamingContainer;
+                               }
+
                                if (ctrl == null)
                                        throw new HttpException (string.Format ("A control with ID '{0}' could not be found.", DataSourceID));
                                if (!(ctrl is IDataSource))
index fceea4f217886b27e3d1426a67dfe7ba776427e5..1aa88f78ca5b98ba8fb08462fa6bbd44abd849d6 100644 (file)
@@ -93,11 +93,7 @@ namespace System.Web.UI.WebControls
                
                [DefaultValueAttribute ("")]
                public virtual string SiteMapProvider {
-                       get {
-                               object o = ViewState ["SiteMapProvider"];
-                               if (o != null) return (string) o;
-                               else return string.Empty;
-                       }
+                       get { return ViewState.GetString ("SiteMapProvider", ""); }
                        set {
                                ViewState ["SiteMapProvider"] = value;
                                OnDataSourceChanged (EventArgs.Empty);
@@ -108,24 +104,22 @@ namespace System.Web.UI.WebControls
                [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
                [UrlPropertyAttribute]
                public virtual string StartingNodeUrl {
-                       get {
-                               object o = ViewState ["StartingNodeUrl"];
-                               if (o != null) return (string) o;
-                               else return string.Empty;
-                       }
+                       get { return ViewState.GetString ("StartingNodeUrl", ""); }
                        set {
                                ViewState ["StartingNodeUrl"] = value;
                                OnDataSourceChanged (EventArgs.Empty);
                        }
                }
+
+               [DefaultValue (0)]
+               public virtual int StartingNodeOffset {
+                       get { return ViewState.GetInt ("StartingNodeOffset", 0); }
+                       set { ViewState["StartingNodeOffset"] = value; }
+               }
                
                [DefaultValueAttribute (false)]
                public virtual bool StartFromCurrentNode {
-                       get {
-                               object o = ViewState ["StartFromCurrentNode"];
-                               if (o != null) return (bool) o;
-                               else return false;
-                       }
+                       get { return ViewState.GetBool ("StartFromCurrentNode", false); }
                        set {
                                ViewState ["StartFromCurrentNode"] = value;
                                OnDataSourceChanged (EventArgs.Empty);
@@ -134,11 +128,7 @@ namespace System.Web.UI.WebControls
                
                [DefaultValueAttribute (true)]
                public virtual bool ShowStartingNode {
-                       get {
-                               object o = ViewState ["ShowStartingNode"];
-                               if (o != null) return (bool) o;
-                               else return true;
-                       }
+                       get { return ViewState.GetBool ("ShowStartingNode", true); }
                        set {
                                ViewState ["ShowStartingNode"] = value;
                                OnDataSourceChanged (EventArgs.Empty);
@@ -167,8 +157,11 @@ namespace System.Web.UI.WebControls
                                return new SiteMapHierarchicalDataSourceView (node.ChildNodes);
                }
                
+               [MonoTODO ("handle StartNodeOffsets > 0")]
                SiteMapNode GetStartNode (string viewPath)
                {
+                       SiteMapNode starting_node;
+
                        if (viewPath != null && viewPath.Length != 0) {
                                string url = MapUrl (StartingNodeUrl);
                                return Provider.FindSiteMapNode (url);
@@ -176,16 +169,30 @@ namespace System.Web.UI.WebControls
                        else if (StartFromCurrentNode) {
                                if (StartingNodeUrl.Length != 0)
                                        throw new InvalidOperationException ("StartingNodeUrl can't be set if StartFromCurrentNode is set to true.");
-                               return Provider.CurrentNode;
+                               starting_node = Provider.CurrentNode;
                        }
                        else if (StartingNodeUrl.Length != 0) {
                                string url = MapUrl (StartingNodeUrl);
                                SiteMapNode node = Provider.FindSiteMapNode (url);
                                if (node == null) throw new ArgumentException ("Can't find a site map node for the url: " + StartingNodeUrl);
-                               return node;
+
+                               starting_node = node;
                        }
                        else
-                               return Provider.RootNode;
+                               starting_node = Provider.RootNode;
+
+                       int i;
+                       if (StartingNodeOffset < 0) {
+                               for (i = StartingNodeOffset; i < 0; i ++) {
+                                       if (starting_node.ParentNode == null)
+                                               break;
+                                       starting_node = starting_node.ParentNode;
+                               }
+                       }
+                       else if (StartingNodeOffset > 0) {
+                       }
+
+                       return starting_node;
                }
                
                string MapUrl (string url)
index a86906c2b4e68c115d2b937b59fda87f26ffd6be..8074194bbc48d007387ecbb8c88b1e22af7326d7 100644 (file)
@@ -64,6 +64,13 @@ namespace System.Web.UI.WebControls
                        arguments.RaiseUnsupportedCapabilitiesError (this);
                        return collection;
                }
+
+               [MonoTODO]
+               protected override void OnDataSourceViewChanged (EventArgs e)
+               {
+                       base.OnDataSourceViewChanged (e);
+               }
+
        }
 }
 #endif
index bd9894c0a3190082581ee6f8475fc0152dbd2ff2..aa0ca7f45698df38e4f4eb6c35bc6f513c7eefaa 100644 (file)
@@ -33,6 +33,7 @@
 using System;
 using System.Collections;
 using System.ComponentModel;
+using System.Web.UI.HtmlControls;
 
 namespace System.Web.UI.WebControls
 {
@@ -80,10 +81,10 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [DefaultValueAttribute (null)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
-           [NotifyParentPropertyAttribute (true)]\r
-           [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
+               [DefaultValueAttribute (null)]
+               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
+               [NotifyParentPropertyAttribute (true)]
+               [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                public Style CurrentNodeStyle {
                        get {
                                if (currentNodeStyle == null) {
@@ -98,16 +99,16 @@ namespace System.Web.UI.WebControls
                [DefaultValue (null)]
                [TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
                [PersistenceMode (PersistenceMode.InnerProperty)]
-           [Browsable (false)]
+               [Browsable (false)]
                public virtual ITemplate CurrentNodeTemplate {
                        get { return currentNodeTemplate; }
                        set { currentNodeTemplate = value; UpdateControls (); }
                }
                
-           [DefaultValueAttribute (null)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
-           [NotifyParentPropertyAttribute (true)]\r
-           [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
+               [DefaultValueAttribute (null)]
+               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
+               [NotifyParentPropertyAttribute (true)]
+               [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                public Style NodeStyle {
                        get {
                                if (nodeStyle == null) {
@@ -122,20 +123,16 @@ namespace System.Web.UI.WebControls
                [DefaultValue (null)]
                [TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
                [PersistenceMode (PersistenceMode.InnerProperty)]
-           [Browsable (false)]
+               [Browsable (false)]
                public virtual ITemplate NodeTemplate {
                        get { return nodeTemplate; }
                        set { nodeTemplate = value; UpdateControls (); }
                }
                
-           [DefaultValueAttribute (-1)]\r
-           [ThemeableAttribute (false)]\r
+               [DefaultValueAttribute (-1)]
+               [ThemeableAttribute (false)]
                public virtual int ParentLevelsDisplayed {
-                       get {
-                               object ob = ViewState ["ParentLevelsDisplayed"];
-                               if (ob != null) return (int) ob;
-                               else return -1;
-                       }
+                       get { return ViewState.GetInt ("ParentLevelsDisplayed", -1); }
                        set {
                                if (value < -1) throw new ArgumentOutOfRangeException ("value");
                                ViewState ["ParentLevelsDisplayed"] = value;
@@ -143,13 +140,9 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [DefaultValueAttribute (PathDirection.RootToCurrent)]\r
+               [DefaultValueAttribute (PathDirection.RootToCurrent)]
                public virtual PathDirection PathDirection {
-                       get {
-                               object ob = ViewState ["PathDirection"];
-                               if (ob != null) return (PathDirection) ob;
-                               else return PathDirection.RootToCurrent;
-                       }
+                       get { return (PathDirection)ViewState.GetInt ("PathDirection", (int)PathDirection.RootToCurrent); }
                        set {
                                if (value != PathDirection.RootToCurrent && value != PathDirection.CurrentToRoot)
                                        throw new ArgumentOutOfRangeException ("value");
@@ -158,24 +151,20 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [DefaultValueAttribute (" > ")]\r
-           [LocalizableAttribute (true)]\r
+               [DefaultValueAttribute (" > ")]
+               [LocalizableAttribute (true)]
                public virtual string PathSeparator {
-                       get {
-                               object ob = ViewState ["PathSeparator"];
-                               if (ob != null) return (string) ob;
-                               else return " > ";
-                       }
+                       get { return ViewState.GetString ("PathSeparator", ">"); }
                        set {
                                ViewState ["PathSeparator"] = value;
                                UpdateControls ();
                        }
                }
                
-           [DefaultValueAttribute (null)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
-           [NotifyParentPropertyAttribute (true)]\r
-           [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
+               [DefaultValueAttribute (null)]
+               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
+               [NotifyParentPropertyAttribute (true)]
+               [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                public Style PathSeparatorStyle {
                        get {
                                if (pathSeparatorStyle == null) {
@@ -190,14 +179,14 @@ namespace System.Web.UI.WebControls
                [DefaultValue (null)]
                [TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
                [PersistenceMode (PersistenceMode.InnerProperty)]
-           [Browsable (false)]
+               [Browsable (false)]
                public virtual ITemplate PathSeparatorTemplate {
                        get { return pathSeparatorTemplate; }
                        set { pathSeparatorTemplate = value; UpdateControls (); }
                }
                
-           [BrowsableAttribute (false)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
+               [BrowsableAttribute (false)]
+               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
                public SiteMapProvider Provider {
                        get {
                                if (provider == null) {
@@ -219,23 +208,19 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [DefaultValueAttribute (false)]\r
+               [DefaultValueAttribute (false)]
                public virtual bool RenderCurrentNodeAsLink {
-                       get {
-                               object o = ViewState ["RenderCurrentNodeAsLink"];
-                               if (o != null) return (bool) o;
-                               else return false;
-                       }
+                       get { return ViewState.GetBool ("RenderCurrentNodeAsLink", false); }
                        set {
                                ViewState ["RenderCurrentNodeAsLink"] = value;
                                UpdateControls ();
                        }
                }
                
-           [DefaultValueAttribute (null)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]\r
-           [NotifyParentPropertyAttribute (true)]\r
-           [PersistenceModeAttribute (PersistenceMode.InnerProperty)]\r
+               [DefaultValueAttribute (null)]
+               [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
+               [NotifyParentPropertyAttribute (true)]
+               [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                public Style RootNodeStyle {
                        get {
                                if (rootNodeStyle == null) {
@@ -250,34 +235,26 @@ namespace System.Web.UI.WebControls
                [DefaultValue (null)]
                [TemplateContainer (typeof(SiteMapNodeItem), BindingDirection.OneWay)]
                [PersistenceMode (PersistenceMode.InnerProperty)]
-           [Browsable (false)]
+               [Browsable (false)]
                public virtual ITemplate RootNodeTemplate {
                        get { return rootNodeTemplate; }
                        set { rootNodeTemplate = value; UpdateControls (); }
                }
                
-           [DefaultValueAttribute (true)]\r
-           [ThemeableAttribute (false)]\r
+               [DefaultValueAttribute (true)]
+               [ThemeableAttribute (false)]
                public virtual bool ShowToolTips {
-                       get {
-                               object o = ViewState ["ShowToolTips"];
-                               if (o != null) return (bool) o;
-                               else return true;
-                       }
+                       get { return ViewState.GetBool ("ShowToolTips", true); }
                        set {
                                ViewState ["ShowToolTips"] = value;
                                UpdateControls ();
                        }
                }
                
-           [DefaultValueAttribute ("")]\r
-           [ThemeableAttribute (false)]\r
+               [DefaultValueAttribute ("")]
+               [ThemeableAttribute (false)]
                public virtual string SiteMapProvider {
-                       get {
-                               object o = ViewState ["SiteMapProvider"];
-                               if (o != null) return (string) o;
-                               else return string.Empty;
-                       }
+                       get { return ViewState.GetString ("SiteMapProvider", ""); }
                        set {
                                ViewState ["SiteMapProvider"] = value;
                                UpdateControls ();
@@ -285,15 +262,10 @@ namespace System.Web.UI.WebControls
                }
 
                [Localizable (true)]
-               [MonoTODO]
                public virtual string SkipLinkText 
                {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return ViewState.GetString ("SkipLinkText", "Skip Navigation Links"); }
+                       set { ViewState["SkipLinkText"] = value; }
                }
                
                
@@ -302,23 +274,27 @@ namespace System.Web.UI.WebControls
                        ChildControlsCreated = false;
                }
 
-               [MonoTODO]
                public override void DataBind ()
                {
-                       throw new NotImplementedException ();
-               }
-               
-               protected override void AddAttributesToRender (HtmlTextWriter writer)
-               {
-                       base.AddAttributesToRender (writer);
+                       base.DataBind ();
+
+                       /* the child controls get bound in
+                        * base.DataBind */
+                       foreach (Control c in Controls) {
+                               if (c is SiteMapNodeItem) {
+                                       SiteMapNodeItem it = (SiteMapNodeItem)c;
+                                       OnItemDataBound (new SiteMapNodeItemEventArgs (it));
+                               }
+                       }
                }
                
                protected internal override void CreateChildControls ()
                {
                        Controls.Clear ();
                        CreateControlHierarchy ();
+                       DataBind ();
                }
-               
+
                protected virtual void CreateControlHierarchy ()
                {
                        ArrayList nodes = new ArrayList ();
@@ -351,9 +327,6 @@ namespace System.Web.UI.WebControls
                                SiteMapNodeItemEventArgs args = new SiteMapNodeItemEventArgs (it);
                                OnItemCreated (args);
                                
-                               it.DataBind ();
-                               OnItemDataBound (args);
-                               
                                nodes.Add (it);
                                node = node.ParentNode;
                                levels--;
@@ -461,12 +434,13 @@ namespace System.Web.UI.WebControls
                        if (states[4] != null) ((IStateManager)RootNodeStyle).LoadViewState (states[4]);
                }
 
-               [MonoTODO]
+               [MonoTODO ("why override?")]
                protected override void OnDataBinding (EventArgs e)
                {
-                       throw new NotImplementedException ();
+                       base.OnDataBinding (e);
                }
                
+               [MonoTODO ("why override?")]
                protected internal override void Render (HtmlTextWriter w)
                {
                        base.Render (w);
@@ -474,7 +448,31 @@ namespace System.Web.UI.WebControls
 
                protected internal override void RenderContents (HtmlTextWriter w)
                {
+                       string skip_id = ClientID + "_SkipLink";
+
+                       if (SkipLinkText != "") {
+                               HtmlAnchor anchor = new HtmlAnchor ();
+                               anchor.HRef = "#" + skip_id;
+
+                               HtmlImage img = new HtmlImage ();
+                               img.Src = Page.ClientScript.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif");
+                               img.Width = 0;
+                               img.Height = 0;
+                               img.Alt = SkipLinkText;
+                               img.Border = 0;
+
+                               anchor.Controls.Add (img);
+
+                               anchor.Render (w);
+                       }
+
                        base.RenderContents (w);
+
+                       if (SkipLinkText != "") {
+                               HtmlAnchor anchor = new HtmlAnchor ();
+                               anchor.ID = skip_id;
+                               anchor.Render (w);
+                       }
                }
                
                protected override object SaveViewState ()