2 // System.Web.UI.WebControls.Menu.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
36 using System.ComponentModel;
38 using System.Web.Handlers;
39 using System.Collections.Specialized;
42 namespace System.Web.UI.WebControls
44 [DefaultEvent ("MenuItemClick")]
45 [ControlValueProperty ("SelectedValue")]
46 [Designer ("System.Web.UI.Design.WebControls.MenuDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
47 public class Menu : HierarchicalDataBoundControl, IPostBackEventHandler, INamingContainer
49 MenuItemStyle dynamicMenuItemStyle;
50 SubMenuStyle dynamicMenuStyle;
51 MenuItemStyle dynamicSelectedStyle;
52 MenuItemStyle staticMenuItemStyle;
53 SubMenuStyle staticMenuStyle;
54 MenuItemStyle staticSelectedStyle;
55 Style staticHoverStyle;
56 Style dynamicHoverStyle;
58 MenuItemStyleCollection levelMenuItemStyles;
59 MenuItemStyleCollection levelSelectedStyles;
60 SubMenuStyleCollection levelSubMenuStyles;
61 ITemplate staticItemTemplate;
62 ITemplate dynamicItemTemplate;
64 MenuItemCollection items;
65 MenuItemBindingCollection dataBindings;
66 MenuItem selectedItem;
67 string selectedItemPath;
69 ArrayList dynamicMenus;
71 Hashtable _menuItemControls;
72 bool _requiresChildControlsDataBinding;
74 private static readonly object MenuItemClickEvent = new object();
75 private static readonly object MenuItemDataBoundEvent = new object();
77 public static readonly string MenuItemClickCommandName = "Click";
79 public event MenuEventHandler MenuItemClick {
80 add { Events.AddHandler (MenuItemClickEvent, value); }
81 remove { Events.RemoveHandler (MenuItemClickEvent, value); }
84 public event MenuEventHandler MenuItemDataBound {
85 add { Events.AddHandler (MenuItemDataBoundEvent, value); }
86 remove { Events.RemoveHandler (MenuItemDataBoundEvent, value); }
89 protected virtual void OnMenuItemClick (MenuEventArgs e)
92 MenuEventHandler eh = (MenuEventHandler) Events [MenuItemClickEvent];
93 if (eh != null) eh (this, e);
97 protected virtual void OnMenuItemDataBound (MenuEventArgs e)
100 MenuEventHandler eh = (MenuEventHandler) Events [MenuItemDataBoundEvent];
101 if (eh != null) eh (this, e);
105 [DefaultValueAttribute (null)]
106 [PersistenceMode (PersistenceMode.InnerProperty)]
107 [EditorAttribute ("System.Web.UI.Design.WebControls.MenuBindingsEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
108 [MergablePropertyAttribute (false)]
109 public MenuItemBindingCollection DataBindings {
111 if (dataBindings == null) {
112 dataBindings = new MenuItemBindingCollection ();
113 if (IsTrackingViewState)
114 ((IStateManager)dataBindings).TrackViewState();
121 [ThemeableAttribute (false)]
122 public int DisappearAfter {
124 object o = ViewState ["DisappearAfter"];
125 if (o != null) return (int)o;
129 ViewState["DisappearAfter"] = value;
133 [ThemeableAttribute (true)]
136 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
137 public string DynamicBottomSeparatorImageUrl {
139 object o = ViewState ["dbsiu"];
140 if (o != null) return (string)o;
144 ViewState["dbsiu"] = value;
148 [DefaultValueAttribute ("")]
149 public string DynamicItemFormatString {
151 object o = ViewState ["DynamicItemFormatString"];
152 if (o != null) return (string)o;
156 ViewState["DynamicItemFormatString"] = value;
162 [WebCategory ("Appearance")]
163 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
164 public string DynamicTopSeparatorImageUrl {
166 object o = ViewState ["dtsiu"];
167 if (o != null) return (string)o;
171 ViewState["dtsiu"] = value;
177 [WebCategory ("Appearance")]
178 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
179 public string StaticBottomSeparatorImageUrl {
181 object o = ViewState ["sbsiu"];
182 if (o != null) return (string)o;
186 ViewState["sbsiu"] = value;
192 [WebCategory ("Appearance")]
193 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
194 public string StaticTopSeparatorImageUrl {
196 object o = ViewState ["stsiu"];
197 if (o != null) return (string)o;
201 ViewState["stsiu"] = value;
205 [DefaultValue (Orientation.Vertical)]
206 public Orientation Orientation {
208 object o = ViewState ["Orientation"];
209 if (o != null) return (Orientation) o;
210 return Orientation.Vertical;
213 ViewState["Orientation"] = value;
218 [ThemeableAttribute (true)]
219 public int StaticDisplayLevels {
221 object o = ViewState ["StaticDisplayLevels"];
222 if (o != null) return (int)o;
226 if (value < 1) throw new ArgumentOutOfRangeException ();
227 ViewState["StaticDisplayLevels"] = value;
231 [DefaultValueAttribute ("")]
232 public string StaticItemFormatString {
234 object o = ViewState ["StaticItemFormatString"];
235 if (o != null) return (string)o;
239 ViewState["StaticItemFormatString"] = value;
243 [DefaultValue (typeof (Unit), "16px")]
244 [ThemeableAttribute (true)]
245 public Unit StaticSubMenuIndent {
247 object o = ViewState ["StaticSubMenuIndent"];
248 if (o != null) return (Unit)o;
249 return new Unit (16);
252 ViewState["StaticSubMenuIndent"] = value;
256 [ThemeableAttribute (true)]
258 public int MaximumDynamicDisplayLevels {
260 object o = ViewState ["MaximumDynamicDisplayLevels"];
261 if (o != null) return (int)o;
265 if (value < 0) throw new ArgumentOutOfRangeException ();
266 ViewState["MaximumDynamicDisplayLevels"] = value;
271 public int DynamicVerticalOffset {
273 object o = ViewState ["DynamicVerticalOffset"];
274 if (o != null) return (int)o;
278 ViewState["DynamicVerticalOffset"] = value;
283 public int DynamicHorizontalOffset {
285 object o = ViewState ["DynamicHorizontalOffset"];
286 if (o != null) return (int)o;
290 ViewState["DynamicHorizontalOffset"] = value;
294 [DefaultValue (true)]
295 public bool DynamicEnableDefaultPopOutImage {
297 object o = ViewState ["dedpoi"];
298 if (o != null) return (bool)o;
302 ViewState["dedpoi"] = value;
306 [DefaultValue (true)]
307 public bool StaticEnableDefaultPopOutImage {
309 object o = ViewState ["sedpoi"];
310 if (o != null) return (bool)o;
314 ViewState["sedpoi"] = value;
318 [DefaultValueAttribute (null)]
319 [PersistenceMode (PersistenceMode.InnerProperty)]
320 [Editor ("System.Web.UI.Design.MenuItemCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
321 [MergablePropertyAttribute (false)]
322 public MenuItemCollection Items {
325 items = new MenuItemCollection (this);
326 if (IsTrackingViewState)
327 ((IStateManager)items).TrackViewState();
334 public char PathSeparator {
336 object o = ViewState ["PathSeparator"];
337 if(o != null) return (char)o;
341 ViewState ["PathSeparator"] = value;
345 [DefaultValue (false)]
346 public bool ItemWrap {
348 object o = ViewState ["ItemWrap"];
349 if(o != null) return (bool)o;
353 ViewState ["ItemWrap"] = value;
357 [PersistenceMode (PersistenceMode.InnerProperty)]
358 [NotifyParentProperty (true)]
359 [DefaultValue (null)]
360 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
361 public MenuItemStyle DynamicMenuItemStyle {
363 if (dynamicMenuItemStyle == null) {
364 dynamicMenuItemStyle = new MenuItemStyle ();
365 if (IsTrackingViewState)
366 dynamicMenuItemStyle.TrackViewState();
368 return dynamicMenuItemStyle;
372 [PersistenceMode (PersistenceMode.InnerProperty)]
373 [NotifyParentProperty (true)]
374 [DefaultValue (null)]
375 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
376 public MenuItemStyle DynamicSelectedStyle {
378 if (dynamicSelectedStyle == null) {
379 dynamicSelectedStyle = new MenuItemStyle ();
380 if (IsTrackingViewState)
381 dynamicSelectedStyle.TrackViewState();
383 return dynamicSelectedStyle;
387 [PersistenceMode (PersistenceMode.InnerProperty)]
388 [NotifyParentProperty (true)]
389 [DefaultValue (null)]
390 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
391 public SubMenuStyle DynamicMenuStyle {
393 if (dynamicMenuStyle == null) {
394 dynamicMenuStyle = new SubMenuStyle ();
395 if (IsTrackingViewState)
396 dynamicMenuStyle.TrackViewState();
398 return dynamicMenuStyle;
402 [PersistenceMode (PersistenceMode.InnerProperty)]
403 [NotifyParentProperty (true)]
404 [DefaultValue (null)]
405 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
406 public MenuItemStyle StaticMenuItemStyle {
408 if (staticMenuItemStyle == null) {
409 staticMenuItemStyle = new MenuItemStyle ();
410 if (IsTrackingViewState)
411 staticMenuItemStyle.TrackViewState();
413 return staticMenuItemStyle;
417 [PersistenceMode (PersistenceMode.InnerProperty)]
418 [NotifyParentProperty (true)]
419 [DefaultValue (null)]
420 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
421 public MenuItemStyle StaticSelectedStyle {
423 if (staticSelectedStyle == null) {
424 staticSelectedStyle = new MenuItemStyle ();
425 if (IsTrackingViewState)
426 staticSelectedStyle.TrackViewState();
428 return staticSelectedStyle;
432 [PersistenceMode (PersistenceMode.InnerProperty)]
433 [NotifyParentProperty (true)]
434 [DefaultValue (null)]
435 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
436 public SubMenuStyle StaticMenuStyle {
438 if (staticMenuStyle == null) {
439 staticMenuStyle = new SubMenuStyle ();
440 if (IsTrackingViewState)
441 staticMenuStyle.TrackViewState();
443 return staticMenuStyle;
447 [DefaultValue (null)]
448 [PersistenceMode (PersistenceMode.InnerProperty)]
449 [Editor ("System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
450 public MenuItemStyleCollection LevelMenuItemStyles {
452 if (levelMenuItemStyles == null) {
453 levelMenuItemStyles = new MenuItemStyleCollection ();
454 if (IsTrackingViewState)
455 ((IStateManager)levelMenuItemStyles).TrackViewState();
457 return levelMenuItemStyles;
461 [DefaultValue (null)]
462 [PersistenceMode (PersistenceMode.InnerProperty)]
463 [Editor ("System.Web.UI.Design.WebControls.MenuItemStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
464 public MenuItemStyleCollection LevelSelectedStyles {
466 if (levelSelectedStyles == null) {
467 levelSelectedStyles = new MenuItemStyleCollection ();
468 if (IsTrackingViewState)
469 ((IStateManager)levelSelectedStyles).TrackViewState();
471 return levelSelectedStyles;
475 [DefaultValue (null)]
476 [PersistenceMode (PersistenceMode.InnerProperty)]
477 [Editor ("System.Web.UI.Design.WebControls.SubMenuStyleCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
478 public SubMenuStyleCollection LevelSubMenuStyles {
480 if (levelSubMenuStyles == null) {
481 levelSubMenuStyles = new SubMenuStyleCollection ();
482 if (IsTrackingViewState)
483 ((IStateManager)levelSubMenuStyles).TrackViewState();
485 return levelSubMenuStyles;
489 [PersistenceMode (PersistenceMode.InnerProperty)]
490 [NotifyParentProperty (true)]
491 [DefaultValue (null)]
492 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
493 public Style DynamicHoverStyle {
495 if (dynamicHoverStyle == null) {
496 dynamicHoverStyle = new Style ();
497 if (IsTrackingViewState)
498 dynamicHoverStyle.TrackViewState();
500 return dynamicHoverStyle;
504 [PersistenceMode (PersistenceMode.InnerProperty)]
505 [NotifyParentProperty (true)]
506 [DefaultValue (null)]
507 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
508 public Style StaticHoverStyle {
510 if (staticHoverStyle == null) {
511 staticHoverStyle = new Style ();
512 if (IsTrackingViewState)
513 staticHoverStyle.TrackViewState();
515 return staticHoverStyle;
521 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
522 public string ScrollDownImageUrl {
524 object o = ViewState ["sdiu"];
525 if (o != null) return (string)o;
529 ViewState["sdiu"] = value;
535 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
536 public string ScrollUpImageUrl {
538 object o = ViewState ["suiu"];
539 if (o != null) return (string)o;
543 ViewState["suiu"] = value;
548 public string ScrollDownText {
550 object o = ViewState ["ScrollDownText"];
551 if (o != null) return (string) o;
552 return Locale.GetText ("Scroll down");
555 ViewState["ScrollDownText"] = value;
560 public string ScrollUpText {
562 object o = ViewState ["ScrollUpText"];
563 if (o != null) return (string) o;
564 return Locale.GetText ("Scroll up");
567 ViewState["ScrollUpText"] = value;
572 public string DynamicPopOutImageTextFormatString
576 object o = ViewState ["dpoitf"];
577 if (o != null) return (string) o;
578 return Locale.GetText ("Expand {0}");
582 ViewState ["dpoitf"] = value;
589 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
590 public string DynamicPopOutImageUrl {
592 object o = ViewState ["dpoiu"];
593 if (o != null) return (string)o;
597 ViewState["dpoiu"] = value;
602 public string StaticPopOutImageTextFormatString
606 object o = ViewState ["spoitf"];
607 if (o != null) return (string) o;
608 return Locale.GetText ("Expand {0}");
612 ViewState ["spoitf"] = value;
619 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
620 public string StaticPopOutImageUrl {
622 object o = ViewState ["spoiu"];
623 if (o != null) return (string)o;
627 ViewState["spoiu"] = value;
632 public string Target {
634 object o = ViewState ["Target"];
635 if (o != null) return (string) o;
639 ViewState["Target"] = value;
643 [DefaultValue (null)]
644 [TemplateContainer (typeof(MenuItemTemplateContainer), BindingDirection.OneWay)]
645 [PersistenceMode (PersistenceMode.InnerProperty)]
647 public ITemplate StaticItemTemplate {
648 get { return staticItemTemplate; }
649 set { staticItemTemplate = value; }
652 [DefaultValue (null)]
653 [TemplateContainer (typeof(MenuItemTemplateContainer), BindingDirection.OneWay)]
654 [PersistenceMode (PersistenceMode.InnerProperty)]
656 public ITemplate DynamicItemTemplate {
657 get { return dynamicItemTemplate; }
658 set { dynamicItemTemplate = value; }
662 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
663 public MenuItem SelectedItem {
665 if (selectedItem == null && selectedItemPath != null) {
666 selectedItem = FindItemByPos (selectedItemPath);
675 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
676 public string SelectedValue {
677 get { return selectedItem != null ? selectedItem.Value : ""; }
682 public string SkipLinkText
685 object o = ViewState ["SkipLinkText"];
688 return "Skip Navigation Links";
691 ViewState ["SkipLinkText"] = value;
696 internal void SetSelectedItem (MenuItem item)
698 if (selectedItem == item) return;
700 selectedItemPath = item.Path;
703 public MenuItem FindItem (string valuePath)
705 if (valuePath == null) throw new ArgumentNullException ("valuePath");
706 string[] path = valuePath.Split (PathSeparator);
708 MenuItemCollection col = Items;
709 bool foundBranch = true;
710 while (col.Count > 0 && foundBranch) {
712 foreach (MenuItem item in col) {
713 if (item.Value == path [n]) {
714 if (++n == path.Length) return item;
715 col = item.ChildItems;
724 string GetBindingKey (string dataMember, int depth)
726 return dataMember + " " + depth;
729 internal MenuItemBinding FindBindingForItem (string type, int depth)
731 if (bindings == null) return null;
733 MenuItemBinding bin = (MenuItemBinding) bindings [GetBindingKey (type, depth)];
734 if (bin != null) return bin;
736 bin = (MenuItemBinding) bindings [GetBindingKey (type, -1)];
737 if (bin != null) return bin;
739 bin = (MenuItemBinding) bindings [GetBindingKey ("", depth)];
740 if (bin != null) return bin;
742 bin = (MenuItemBinding) bindings [GetBindingKey ("", -1)];
746 protected internal override void PerformDataBinding ()
748 base.PerformDataBinding ();
750 // Do not attempt to bind data if there is no
752 if (!IsBoundUsingDataSourceID && (DataSource == null)) {
753 EnsureChildControlsDataBound ();
757 HierarchicalDataSourceView data = GetData ("");
760 throw new InvalidOperationException ("No view returned by data source control.");
763 IHierarchicalEnumerable e = data.Select ();
764 FillBoundChildrenRecursive (e, Items);
766 CreateChildControlsForItems ();
767 ChildControlsCreated = true;
769 EnsureChildControlsDataBound ();
772 private void FillBoundChildrenRecursive (IHierarchicalEnumerable hEnumerable, MenuItemCollection itemCollection) {
773 foreach (object obj in hEnumerable) {
774 IHierarchyData hdata = hEnumerable.GetHierarchyData (obj);
775 MenuItem item = new MenuItem ();
776 itemCollection.Add (item);
778 OnMenuItemDataBound (new MenuEventArgs (item));
780 if (hdata == null || !hdata.HasChildren)
783 IHierarchicalEnumerable e = hdata.GetChildren ();
784 FillBoundChildrenRecursive (e, item.ChildItems);
788 protected void SetItemDataBound (MenuItem node, bool dataBound)
790 node.SetDataBound (dataBound);
793 protected void SetItemDataPath (MenuItem node, string dataPath)
795 node.SetDataPath (dataPath);
798 protected void SetItemDataItem (MenuItem node, object dataItem)
800 node.SetDataItem (dataItem);
803 protected internal virtual void RaisePostBackEvent (string eventArgument)
808 EnsureChildControls();
809 MenuItem item = FindItemByPos (eventArgument);
810 if (item == null) return;
811 item.Selected = true;
812 OnMenuItemClick (new MenuEventArgs (item));
815 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
817 RaisePostBackEvent (eventArgument);
820 MenuItem FindItemByPos (string path)
822 string[] indexes = path.Split ('_');
823 MenuItem item = null;
825 foreach (string index in indexes) {
826 int i = int.Parse (index);
828 if (i >= Items.Count) return null;
831 if (i >= item.ChildItems.Count) return null;
832 item = item.ChildItems [i];
838 protected override HtmlTextWriterTag TagKey {
839 get { return HtmlTextWriterTag.Table; }
842 protected override void TrackViewState()
846 base.TrackViewState();
847 if (dataBindings != null) {
848 ((IStateManager)dataBindings).TrackViewState ();
851 ((IStateManager)items).TrackViewState();
853 if (dynamicMenuItemStyle != null)
854 dynamicMenuItemStyle.TrackViewState ();
855 if (dynamicMenuStyle != null)
856 dynamicMenuStyle.TrackViewState ();
857 if (levelMenuItemStyles != null)
858 ((IStateManager)levelMenuItemStyles).TrackViewState();
859 if (levelSelectedStyles != null)
860 ((IStateManager)levelSelectedStyles).TrackViewState();
861 if (levelSubMenuStyles != null)
862 ((IStateManager)levelSubMenuStyles).TrackViewState();
863 if (dynamicSelectedStyle != null)
864 dynamicSelectedStyle.TrackViewState();
865 if (staticMenuItemStyle != null)
866 staticMenuItemStyle.TrackViewState ();
867 if (staticMenuStyle != null)
868 staticMenuStyle.TrackViewState ();
869 if (staticSelectedStyle != null)
870 staticSelectedStyle.TrackViewState();
871 if (staticHoverStyle != null)
872 staticHoverStyle.TrackViewState();
873 if (dynamicHoverStyle != null)
874 dynamicHoverStyle.TrackViewState();
877 protected override object SaveViewState()
879 object[] states = new object [14];
880 states[0] = base.SaveViewState ();
881 states[1] = dataBindings == null ? null : ((IStateManager)dataBindings).SaveViewState();
882 states[2] = items == null ? null : ((IStateManager)items).SaveViewState();
883 states[3] = dynamicMenuItemStyle == null ? null : dynamicMenuItemStyle.SaveViewState();
884 states[4] = dynamicMenuStyle == null ? null : dynamicMenuStyle.SaveViewState();
885 states[5] = levelMenuItemStyles == null ? null : ((IStateManager)levelMenuItemStyles).SaveViewState();
886 states[6] = levelSelectedStyles == null ? null : ((IStateManager)levelSelectedStyles).SaveViewState();
887 states[7] = dynamicSelectedStyle == null ? null : dynamicSelectedStyle.SaveViewState();
888 states[8] = (staticMenuItemStyle == null ? null : staticMenuItemStyle.SaveViewState());
889 states[9] = staticMenuStyle == null ? null : staticMenuStyle.SaveViewState();
890 states[10] = staticSelectedStyle == null ? null : staticSelectedStyle.SaveViewState();
891 states[11] = staticHoverStyle == null ? null : staticHoverStyle.SaveViewState();
892 states[12] = dynamicHoverStyle == null ? null : dynamicHoverStyle.SaveViewState();
893 states[13] = levelSubMenuStyles == null ? null : ((IStateManager)levelSubMenuStyles).SaveViewState();
895 for (int i = states.Length - 1; i >= 0; i--) {
896 if (states [i] != null)
903 protected override void LoadViewState (object savedState)
905 if (savedState == null)
908 object [] states = (object []) savedState;
909 base.LoadViewState (states[0]);
911 if (states[1] != null)
912 ((IStateManager)DataBindings).LoadViewState(states[1]);
913 if (states[2] != null)
914 ((IStateManager)Items).LoadViewState(states[2]);
915 if (states[3] != null)
916 DynamicMenuItemStyle.LoadViewState (states[3]);
917 if (states[4] != null)
918 DynamicMenuStyle.LoadViewState (states[4]);
919 if (states[5] != null)
920 ((IStateManager)LevelMenuItemStyles).LoadViewState(states[5]);
921 if (states[6] != null)
922 ((IStateManager)LevelSelectedStyles).LoadViewState(states[6]);
923 if (states[7] != null)
924 DynamicSelectedStyle.LoadViewState (states[7]);
925 if (states[8] != null)
926 StaticMenuItemStyle.LoadViewState (states[8]);
927 if (states[9] != null)
928 StaticMenuStyle.LoadViewState (states[9]);
929 if (states[10] != null)
930 StaticSelectedStyle.LoadViewState (states[10]);
931 if (states[11] != null)
932 StaticHoverStyle.LoadViewState (states[11]);
933 if (states[12] != null)
934 DynamicHoverStyle.LoadViewState (states[12]);
935 if (states[13] != null)
936 ((IStateManager)LevelSubMenuStyles).LoadViewState(states[13]);
939 protected internal override void OnInit (EventArgs e)
941 Page.RegisterRequiresControlState (this);
945 protected internal override void LoadControlState (object ob)
947 if (ob == null) return;
948 object[] state = (object[]) ob;
949 base.LoadControlState (state[0]);
950 selectedItemPath = state[1] as string;
953 protected internal override object SaveControlState ()
955 object bstate = base.SaveControlState ();
956 object mstate = selectedItemPath;
958 if (bstate != null || mstate != null)
959 return new object[] { bstate, mstate };
964 protected internal override void CreateChildControls ()
966 if (!IsBoundUsingDataSourceID && (DataSource == null)) {
967 CreateChildControlsForItems ();
974 private void CreateChildControlsForItems () {
976 // Check for HasChildViewState to avoid unnecessary calls to ClearChildViewState.
977 if (HasChildViewState)
978 ClearChildViewState ();
979 _menuItemControls = new Hashtable ();
980 CreateChildControlsForItems (Items);
981 _requiresChildControlsDataBinding = true;
984 private void CreateChildControlsForItems (MenuItemCollection items ) {
985 foreach (MenuItem item in items) {
986 bool isDynamicItem = IsDynamicItem (item);
987 if (isDynamicItem && dynamicItemTemplate != null) {
988 MenuItemTemplateContainer cter = new MenuItemTemplateContainer (item.Index, item);
989 dynamicItemTemplate.InstantiateIn (cter);
990 _menuItemControls [item] = cter;
993 else if (!isDynamicItem && staticItemTemplate != null) {
994 MenuItemTemplateContainer cter = new MenuItemTemplateContainer (item.Index, item);
995 staticItemTemplate.InstantiateIn (cter);
996 _menuItemControls [item] = cter;
999 if (item.HasChildData)
1000 CreateChildControlsForItems (item.ChildItems);
1004 protected override void EnsureDataBound ()
1006 base.EnsureDataBound ();
1008 EnsureChildControlsDataBound ();
1011 private void EnsureChildControlsDataBound () {
1012 if (!_requiresChildControlsDataBinding)
1014 DataBindChildren ();
1015 _requiresChildControlsDataBinding = false;
1019 protected override IDictionary GetDesignModeState ()
1021 throw new NotImplementedException ();
1025 protected override void SetDesignModeState (IDictionary data)
1027 throw new NotImplementedException ();
1030 public override ControlCollection Controls {
1031 get { return base.Controls; }
1034 public sealed override void DataBind ()
1040 protected override bool OnBubbleEvent (object source, EventArgs e)
1042 throw new NotImplementedException ();
1045 protected override void OnDataBinding (EventArgs e)
1047 EnsureChildControls ();
1048 base.OnDataBinding (e);
1051 protected internal override void OnPreRender (EventArgs e)
1053 base.OnPreRender (e);
1055 if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(Menu), "Menu.js")) {
1056 string url = Page.ClientScript.GetWebResourceUrl (typeof(Menu), "Menu.js");
1057 Page.ClientScript.RegisterClientScriptInclude (typeof(Menu), "Menu.js", url);
1060 string cmenu = ClientID + "_data";
1061 string script = string.Format ("var {0} = new Object ();\n", cmenu);
1062 script += string.Format ("{0}.disappearAfter = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DisappearAfter));
1063 script += string.Format ("{0}.vertical = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (Orientation == Orientation.Vertical));
1064 if (DynamicHorizontalOffset != 0)
1065 script += string.Format ("{0}.dho = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DynamicHorizontalOffset));
1066 if (DynamicVerticalOffset != 0)
1067 script += string.Format ("{0}.dvo = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (DynamicVerticalOffset));
1069 // The order in which styles are defined matters when more than one class
1070 // is assigned to an element
1072 if (dynamicMenuStyle != null)
1073 RegisterItemStyle (dynamicMenuStyle);
1074 if (staticMenuStyle != null)
1075 RegisterItemStyle (staticMenuStyle);
1077 if (staticMenuItemStyle != null)
1078 RegisterItemStyle (staticMenuItemStyle);
1080 if (dynamicMenuItemStyle != null)
1081 RegisterItemStyle (dynamicMenuItemStyle);
1083 if (levelSubMenuStyles != null)
1084 foreach (Style style in levelSubMenuStyles)
1085 RegisterItemStyle (style);
1087 if (levelMenuItemStyles != null)
1088 foreach (Style style in levelMenuItemStyles)
1089 RegisterItemStyle (style);
1091 if (staticSelectedStyle != null)
1092 RegisterItemStyle (staticSelectedStyle);
1093 if (dynamicSelectedStyle != null)
1094 RegisterItemStyle (dynamicSelectedStyle);
1096 if (levelSelectedStyles != null)
1097 foreach (Style style in levelSelectedStyles)
1098 RegisterItemStyle (style);
1100 if (dynamicHoverStyle != null)
1101 RegisterItemStyle (dynamicHoverStyle);
1102 if (staticHoverStyle != null)
1103 RegisterItemStyle (staticHoverStyle);
1105 if (staticHoverStyle != null)
1106 script += string.Format ("{0}.staticHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (staticHoverStyle.RegisteredCssClass));
1107 if (dynamicHoverStyle != null)
1108 script += string.Format ("{0}.dynamicHover = {1};\n", cmenu, ClientScriptManager.GetScriptLiteral (dynamicHoverStyle.RegisteredCssClass));
1110 Page.ClientScript.RegisterStartupScript (typeof(Menu), ClientID, script, true);
1112 if (dataBindings != null && dataBindings.Count > 0) {
1113 bindings = new Hashtable ();
1114 foreach (TreeNodeBinding bin in dataBindings) {
1115 string key = GetBindingKey (bin.DataMember, bin.Depth);
1116 bindings [key] = bin;
1123 void RegisterItemStyle (Style baseStyle)
1125 Page.Header.StyleSheet.RegisterStyle (baseStyle, this);
1126 Style ts = new Style ();
1127 ts.CopyTextStylesFrom (baseStyle);
1128 Page.Header.StyleSheet.CreateStyleRule (ts, this, "." + baseStyle.RegisteredCssClass + " A");
1131 protected internal override void Render (HtmlTextWriter writer)
1133 if (Items.Count > 0)
1134 base.Render (writer);
1137 protected override void AddAttributesToRender (HtmlTextWriter writer)
1139 RenderMenuBeginTagAttributes (writer, false, 0);
1142 public override void RenderBeginTag (HtmlTextWriter writer)
1144 if (SkipLinkText != "") {
1145 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1146 anchor.HRef = "#" + ClientID + "_SkipLink";
1148 Image img = new Image ();
1149 ClientScriptManager csm = new ClientScriptManager (null);
1150 img.ImageUrl = csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif");
1151 img.Attributes.Add ("height", "0");
1152 img.Attributes.Add ("width", "0");
1153 img.AlternateText = SkipLinkText;
1155 anchor.Controls.Add (img);
1156 anchor.Render (writer);
1158 base.RenderBeginTag (writer);
1161 public override void RenderEndTag (HtmlTextWriter writer)
1163 base.RenderEndTag (writer);
1165 // Render dynamic menus outside the main control tag
1166 if (dynamicMenus != null) {
1167 for (int n = 0; n < dynamicMenus.Count; n++) {
1168 MenuItem item = (MenuItem) dynamicMenus [n];
1169 RenderDynamicMenu (writer, item);
1172 dynamicMenus = null;
1174 if (SkipLinkText != "") {
1175 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1176 anchor.ID = "SkipLink";
1177 anchor.Render (writer);
1181 protected internal override void RenderContents (HtmlTextWriter writer)
1183 dynamicMenus = new ArrayList ();
1184 RenderMenuBody (writer, Items, Orientation == Orientation.Vertical, false);
1187 void RenderDynamicMenu (HtmlTextWriter writer, MenuItem item)
1189 if (dynamicMenuStyle != null)
1190 writer.AddAttribute ("class", dynamicMenuStyle.RegisteredCssClass);
1192 writer.AddStyleAttribute ("visibility", "hidden");
1193 writer.AddStyleAttribute ("position", "absolute");
1194 writer.AddStyleAttribute ("left", "0px");
1195 writer.AddStyleAttribute ("top", "0px");
1196 writer.AddAttribute ("id", GetItemClientId (item, "s"));
1197 writer.RenderBeginTag (HtmlTextWriterTag.Div);
1200 writer.AddAttribute ("id", GetItemClientId (item, "cu"));
1201 writer.AddStyleAttribute ("display", "block");
1202 writer.AddStyleAttribute ("text-align", "center");
1203 writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "u"));
1204 writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "u"));
1205 writer.RenderBeginTag (HtmlTextWriterTag.Div);
1207 string src = ScrollUpImageUrl != "" ? ScrollUpImageUrl : Page.ClientScript.GetWebResourceUrl (typeof(Menu), "arrow_up.gif");
1208 writer.AddAttribute ("src", src);
1209 writer.AddAttribute ("alt", ScrollUpText);
1210 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1211 writer.RenderEndTag (); // IMG
1213 writer.RenderEndTag (); // DIV scroll button
1215 writer.AddAttribute ("id", GetItemClientId (item, "cb")); // Scroll container
1216 writer.RenderBeginTag (HtmlTextWriterTag.Div);
1217 writer.AddAttribute ("id", GetItemClientId (item, "cc")); // Content
1218 writer.RenderBeginTag (HtmlTextWriterTag.Div);
1220 RenderMenu (writer, item.ChildItems, true, true, item.Depth + 1);
1222 writer.RenderEndTag (); // DIV Content
1223 writer.RenderEndTag (); // DIV Scroll container
1226 writer.AddAttribute ("id", GetItemClientId (item, "cd"));
1227 writer.AddStyleAttribute ("display", "block");
1228 writer.AddStyleAttribute ("text-align", "center");
1229 writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "d"));
1230 writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutScrollBtn ('{0}','{1}','{2}')", ClientID, item.Path, "d"));
1231 writer.RenderBeginTag (HtmlTextWriterTag.Div);
1233 src = ScrollDownImageUrl != "" ? ScrollDownImageUrl : Page.ClientScript.GetWebResourceUrl (typeof(Menu), "arrow_down.gif");
1234 writer.AddAttribute ("src", src);
1235 writer.AddAttribute ("alt", ScrollDownText);
1236 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1237 writer.RenderEndTag (); // IMG
1239 writer.RenderEndTag (); // DIV scroll button
1241 writer.RenderEndTag (); // DIV menu
1244 void RenderMenuBeginTagAttributes (HtmlTextWriter writer, bool dynamic, int menuLevel)
1246 writer.AddAttribute ("cellpadding", "0");
1247 writer.AddAttribute ("cellspacing", "0");
1248 writer.AddAttribute ("border", "0");
1250 string cls = menuLevel==0 ? ControlStyle.CssClass : string.Empty;
1252 if (!dynamic && staticMenuStyle != null)
1253 cls += " " + staticMenuStyle.RegisteredCssClass;
1255 if (levelSubMenuStyles != null && menuLevel < levelSubMenuStyles.Count)
1256 cls += " " + levelSubMenuStyles [menuLevel].RegisteredCssClass;
1258 if (cls.Length != 0)
1259 writer.AddAttribute ("class", cls);
1262 void RenderMenu (HtmlTextWriter writer, MenuItemCollection items, bool vertical, bool dynamic, int menuLevel)
1264 RenderMenuBeginTag (writer, dynamic, menuLevel);
1265 RenderMenuBody (writer, items, vertical, dynamic);
1266 RenderMenuEndTag (writer);
1269 void RenderMenuBeginTag (HtmlTextWriter writer, bool dynamic, int menuLevel)
1271 RenderMenuBeginTagAttributes (writer, dynamic, menuLevel);
1272 writer.RenderBeginTag (HtmlTextWriterTag.Table);
1275 void RenderMenuEndTag (HtmlTextWriter writer)
1277 writer.RenderEndTag ();
1280 void RenderMenuBody (HtmlTextWriter writer, MenuItemCollection items, bool vertical, bool dynamic)
1282 if (!vertical) writer.RenderBeginTag (HtmlTextWriterTag.Tr);
1284 for (int n=0; n<items.Count; n++) {
1285 MenuItem item = items [n];
1287 Unit itemSpacing = GetItemSpacing (item, dynamic);
1288 if (itemSpacing != Unit.Empty) {
1290 writer.AddAttribute ("height", itemSpacing.ToString());
1291 writer.RenderBeginTag (HtmlTextWriterTag.Tr);
1292 writer.RenderEndTag ();
1294 writer.AddAttribute ("width", itemSpacing.ToString());
1295 writer.RenderBeginTag (HtmlTextWriterTag.Td);
1296 writer.RenderEndTag ();
1300 RenderMenuItem (writer, item);
1303 if (!vertical) writer.RenderEndTag (); // TR
1306 private bool IsDynamicItem (MenuItem item) {
1307 return item.Depth + 1 > StaticDisplayLevels;
1310 void RenderMenuItem (HtmlTextWriter writer, MenuItem item)
1312 bool displayChildren = (item.Depth + 1 < StaticDisplayLevels + MaximumDynamicDisplayLevels);
1313 bool dynamicChildren = displayChildren && (item.Depth + 1 >= StaticDisplayLevels) && item.ChildItems.Count > 0;
1314 bool isDynamicItem = IsDynamicItem (item);
1315 bool vertical = (Orientation == Orientation.Vertical) || isDynamicItem;
1318 writer.RenderBeginTag (HtmlTextWriterTag.Tr);
1320 Style itemStyle = null;
1321 if (levelMenuItemStyles != null && item.Depth < levelMenuItemStyles.Count)
1322 itemStyle = levelMenuItemStyles [item.Depth];
1323 else if (isDynamicItem) {
1324 if (dynamicMenuItemStyle != null)
1325 itemStyle = dynamicMenuItemStyle;
1327 if (staticMenuItemStyle != null)
1328 itemStyle = staticMenuItemStyle;
1331 Style selectedStyle = null;
1332 if (item == SelectedItem) {
1333 if (levelSelectedStyles != null && item.Depth < levelSelectedStyles.Count)
1334 selectedStyle = levelSelectedStyles [item.Depth];
1335 else if (isDynamicItem) {
1336 if (dynamicSelectedStyle != null)
1337 selectedStyle = dynamicSelectedStyle;
1339 if (staticSelectedStyle != null)
1340 selectedStyle = staticSelectedStyle;
1345 if (itemStyle != null) cls += itemStyle.RegisteredCssClass + " ";
1346 if (selectedStyle != null) cls += selectedStyle.RegisteredCssClass + " ";
1348 writer.AddAttribute ("class", cls);
1350 string parentId = isDynamicItem ? "'" + item.Parent.Path + "'" : "null";
1351 if (dynamicChildren) {
1352 writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
1353 writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}')", ClientID, item.Path));
1354 } else if (isDynamicItem) {
1355 writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverDynamicLeafItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
1356 writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}',{2})", ClientID, item.Path, parentId));
1358 writer.AddAttribute ("onmouseover", string.Format ("javascript:Menu_OverStaticLeafItem ('{0}','{1}')", ClientID, item.Path));
1359 writer.AddAttribute ("onmouseout", string.Format ("javascript:Menu_OutItem ('{0}','{1}')", ClientID, item.Path));
1362 writer.AddAttribute ("id", GetItemClientId (item, "i"));
1364 writer.RenderBeginTag (HtmlTextWriterTag.Td);
1366 // Top separator image
1368 if (isDynamicItem && DynamicTopSeparatorImageUrl != "") {
1369 writer.AddAttribute ("src", DynamicTopSeparatorImageUrl);
1370 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1371 writer.RenderEndTag (); // IMG
1372 } else if (!isDynamicItem && StaticTopSeparatorImageUrl != "") {
1373 writer.AddAttribute ("src", StaticTopSeparatorImageUrl);
1374 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1375 writer.RenderEndTag (); // IMG
1380 writer.AddAttribute ("cellpadding", "0");
1381 writer.AddAttribute ("cellspacing", "0");
1382 writer.AddAttribute ("width", "100%");
1383 writer.RenderBeginTag (HtmlTextWriterTag.Table);
1384 writer.RenderBeginTag (HtmlTextWriterTag.Tr);
1386 if (item.Depth > 0 && !isDynamicItem) {
1387 writer.RenderBeginTag (HtmlTextWriterTag.Td);
1388 writer.AddStyleAttribute ("width", StaticSubMenuIndent.ToString ());
1389 writer.RenderBeginTag (HtmlTextWriterTag.Div);
1390 writer.RenderEndTag (); // DIV
1391 writer.RenderEndTag (); // TD
1394 if (item.ImageUrl != "") {
1395 writer.RenderBeginTag (HtmlTextWriterTag.Td);
1396 RenderItemHref (writer, item);
1397 writer.RenderBeginTag (HtmlTextWriterTag.A);
1398 writer.AddAttribute ("src", item.ImageUrl);
1399 writer.AddAttribute ("border", "0");
1400 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1401 writer.RenderEndTag (); // IMG
1402 writer.RenderEndTag (); // A
1403 writer.RenderEndTag (); // TD
1408 writer.AddAttribute ("width", "100%");
1410 writer.AddAttribute ("nowrap", "nowrap");
1411 writer.RenderBeginTag (HtmlTextWriterTag.Td);
1413 RenderItemHref (writer, item);
1414 writer.AddStyleAttribute ("text-decoration", "none");
1415 writer.RenderBeginTag (HtmlTextWriterTag.A);
1416 RenderItemContent (writer, item, isDynamicItem);
1417 writer.RenderEndTag (); // A
1419 writer.RenderEndTag (); // TD
1423 if (dynamicChildren) {
1424 string popOutImage = GetPopOutImage (item, isDynamicItem);
1425 if (popOutImage != null)
1427 writer.RenderBeginTag (HtmlTextWriterTag.Td);
1428 writer.AddAttribute ("src", popOutImage);
1429 writer.AddAttribute ("border", "0");
1430 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1431 writer.RenderEndTag (); // IMG
1432 writer.RenderEndTag (); // TD
1436 writer.RenderEndTag (); // TR
1437 writer.RenderEndTag (); // TABLE
1439 // Bottom separator image
1441 string separatorImg = item.SeparatorImageUrl;
1442 if (separatorImg.Length == 0) {
1443 if (isDynamicItem) separatorImg = DynamicBottomSeparatorImageUrl;
1444 else separatorImg = StaticBottomSeparatorImageUrl;
1446 if (separatorImg.Length > 0) {
1447 writer.AddAttribute ("src", separatorImg);
1448 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1449 writer.RenderEndTag (); // IMG
1455 if (displayChildren) {
1456 if (dynamicChildren) dynamicMenus.Add (item);
1458 writer.AddAttribute ("width", "100%");
1459 RenderMenu (writer, item.ChildItems, true, false, item.Depth + 1);
1463 writer.RenderEndTag (); // TD
1464 writer.RenderEndTag (); // TR
1466 writer.RenderEndTag (); // TD
1468 writer.RenderBeginTag (HtmlTextWriterTag.Td);
1469 if (displayChildren) {
1470 if (dynamicChildren) dynamicMenus.Add (item);
1471 else RenderMenu (writer, item.ChildItems, false, false, item.Depth + 1);
1473 writer.RenderEndTag (); // TD
1477 void RenderItemContent (HtmlTextWriter writer, MenuItem item, bool isDynamicItem) {
1478 if (_menuItemControls!=null && _menuItemControls [item] != null) {
1479 ((Control) _menuItemControls [item]).Render (writer);
1481 else if (isDynamicItem && DynamicItemFormatString.Length > 0) {
1482 writer.Write (string.Format (DynamicItemFormatString, item.Text));
1484 else if (!isDynamicItem && StaticItemFormatString.Length > 0) {
1485 writer.Write (string.Format (StaticItemFormatString, item.Text));
1488 writer.Write (item.Text);
1492 Unit GetItemSpacing (MenuItem item, bool dynamic)
1496 if (item.Selected) {
1497 if (levelSelectedStyles != null && item.Depth < levelSelectedStyles.Count) {
1498 itemSpacing = levelSelectedStyles [item.Depth].ItemSpacing;
1499 if (itemSpacing != Unit.Empty) return itemSpacing;
1502 if (dynamic) itemSpacing = DynamicSelectedStyle.ItemSpacing;
1503 else itemSpacing = StaticSelectedStyle.ItemSpacing;
1504 if (itemSpacing != Unit.Empty) return itemSpacing;
1507 if (levelMenuItemStyles != null && item.Depth < levelMenuItemStyles.Count) {
1508 itemSpacing = levelMenuItemStyles [item.Depth].ItemSpacing;
1509 if (itemSpacing != Unit.Empty) return itemSpacing;
1512 if (dynamic) return DynamicMenuItemStyle.ItemSpacing;
1513 else return StaticMenuItemStyle.ItemSpacing;
1516 string GetPopOutImage (MenuItem item, bool isDynamicItem)
1518 if (item.PopOutImageUrl != "")
1519 return item.PopOutImageUrl;
1521 if (isDynamicItem) {
1522 if (DynamicPopOutImageUrl != "")
1523 return DynamicPopOutImageUrl;
1524 if (DynamicEnableDefaultPopOutImage)
1525 return AssemblyResourceLoader.GetResourceUrl (typeof(Menu), "arrow_plus.gif");
1527 if (StaticPopOutImageUrl != "")
1528 return StaticPopOutImageUrl;
1529 if (StaticEnableDefaultPopOutImage)
1530 return AssemblyResourceLoader.GetResourceUrl (typeof(Menu), "arrow_plus.gif");
1535 void RenderItemHref (HtmlTextWriter writer, MenuItem item)
1537 if (!item.BranchEnabled) {
1538 writer.AddAttribute ("disabled", "true");
1540 else if (!item.Selectable) {
1541 writer.AddAttribute ("href", "#");
1542 writer.AddStyleAttribute ("cursor", "text");
1544 else if (item.NavigateUrl != "") {
1545 writer.AddAttribute ("href", item.NavigateUrl);
1546 if (item.Target != "")
1547 writer.AddAttribute ("target", item.Target);
1548 else if (Target != "")
1549 writer.AddAttribute ("target", Target);
1552 writer.AddAttribute ("href", GetClientEvent (item));
1557 string GetItemClientId (MenuItem item, string sufix)
1559 return ClientID + "_" + item.Path + sufix;
1562 string GetClientEvent (MenuItem item)
1564 return Page.ClientScript.GetPostBackClientHyperlink (this, item.Path);