Beispiel #1
0
            public OwnerContext(BaseMenuRenderer container)
            {
                if (container == null)
                {
                    throw new ArgumentNullException("container");
                }

                this.container = container;
                Menu owner = container.Owner;
                Page page  = owner.Page;

                Header               = page != null ? page.Header : null;
                ClientID             = owner.ClientID;
                IsVertical           = owner.Orientation == Orientation.Vertical;
                StaticSubMenuIndent  = owner.StaticSubMenuIndent;
                SelectedItem         = owner.SelectedItem;
                ControlLinkStyle     = owner.ControlLinkStyle;
                StaticDisplayLevels  = owner.StaticDisplayLevels;
                StaticMenuItemStyle  = owner.StaticMenuItemStyleInternal;
                DynamicMenuItemStyle = owner.DynamicMenuItemStyleInternal;
                LevelMenuItemStyles  = owner.LevelMenuItemStyles;
            }
Beispiel #2
0
			public OwnerContext (BaseMenuRenderer container)
			{
				if (container == null)
					throw new ArgumentNullException ("container");

				this.container = container;
				Menu owner = container.Owner;
				Page page = owner.Page;

				Header = page != null ? page.Header : null;
				ClientID = owner.ClientID;
				IsVertical = owner.Orientation == Orientation.Vertical;
				StaticSubMenuIndent = owner.StaticSubMenuIndent;
				SelectedItem = owner.SelectedItem;
				ControlLinkStyle = owner.ControlLinkStyle;
				StaticDisplayLevels = owner.StaticDisplayLevels;
				StaticMenuItemStyle = owner.StaticMenuItemStyleInternal;
				DynamicMenuItemStyle = owner.DynamicMenuItemStyleInternal;
				LevelMenuItemStyles = owner.LevelMenuItemStyles;
			}
Beispiel #3
0
        public override void PreRender(Page page, HtmlHead head, ClientScriptManager csm, string cmenu, StringBuilder script)
        {
            Menu                    owner = Owner;
            MenuItemStyle           staticMenuItemStyle     = owner.StaticMenuItemStyleInternal;
            SubMenuStyle            staticMenuStyle         = owner.StaticMenuStyleInternal;
            MenuItemStyle           dynamicMenuItemStyle    = owner.DynamicMenuItemStyleInternal;
            SubMenuStyle            dynamicMenuStyle        = owner.DynamicMenuStyleInternal;
            MenuItemStyleCollection levelMenuItemStyles     = owner.LevelMenuItemStyles;
            List <Style>            levelMenuItemLinkStyles = owner.LevelMenuItemLinkStyles;
            SubMenuStyleCollection  levelSubMenuStyles      = owner.LevelSubMenuStylesInternal;
            MenuItemStyle           staticSelectedStyle     = owner.StaticSelectedStyleInternal;
            MenuItemStyle           dynamicSelectedStyle    = owner.DynamicSelectedStyleInternal;
            MenuItemStyleCollection levelSelectedStyles     = owner.LevelSelectedStylesInternal;
            List <Style>            levelSelectedLinkStyles = owner.LevelSelectedLinkStyles;
            Style                   staticHoverStyle        = owner.StaticHoverStyleInternal;
            Style                   dynamicHoverStyle       = owner.DynamicHoverStyleInternal;

            if (!csm.IsClientScriptIncludeRegistered(typeof(Menu), "Menu.js"))
            {
                string url = csm.GetWebResourceUrl(typeof(Menu), "Menu.js");
                csm.RegisterClientScriptInclude(typeof(Menu), "Menu.js", url);
            }

            script.AppendFormat(onPreRenderScript,
                                cmenu,
                                page.IsMultiForm ? page.theForm : "window",
                                ClientScriptManager.GetScriptLiteral(owner.DisappearAfter),
                                ClientScriptManager.GetScriptLiteral(owner.Orientation == Orientation.Vertical));

            if (owner.DynamicHorizontalOffset != 0)
            {
                script.Append(String.Concat(cmenu, ".dho = ", ClientScriptManager.GetScriptLiteral(owner.DynamicHorizontalOffset), ";\n"));
            }
            if (owner.DynamicVerticalOffset != 0)
            {
                script.Append(String.Concat(cmenu, ".dvo = ", ClientScriptManager.GetScriptLiteral(owner.DynamicVerticalOffset), ";\n"));
            }

            // The order in which styles are defined matters when more than one class
            // is assigned to an element
            RegisterStyle(owner.PopOutBoxStyle, head);
            RegisterStyle(owner.ControlStyle, owner.ControlLinkStyle, head);

            if (staticMenuItemStyle != null)
            {
                RegisterStyle(owner.StaticMenuItemStyle, owner.StaticMenuItemLinkStyle, head);
            }

            if (staticMenuStyle != null)
            {
                RegisterStyle(owner.StaticMenuStyle, head);
            }

            if (dynamicMenuItemStyle != null)
            {
                RegisterStyle(owner.DynamicMenuItemStyle, owner.DynamicMenuItemLinkStyle, head);
            }

            if (dynamicMenuStyle != null)
            {
                RegisterStyle(owner.DynamicMenuStyle, head);
            }

            if (levelMenuItemStyles != null && levelMenuItemStyles.Count > 0)
            {
                levelMenuItemLinkStyles = new List <Style> (levelMenuItemStyles.Count);
                foreach (Style style in levelMenuItemStyles)
                {
                    Style linkStyle = new Style();
                    levelMenuItemLinkStyles.Add(linkStyle);
                    RegisterStyle(style, linkStyle, head);
                }
            }

            if (levelSubMenuStyles != null)
            {
                foreach (Style style in levelSubMenuStyles)
                {
                    RegisterStyle(style, head);
                }
            }

            if (staticSelectedStyle != null)
            {
                RegisterStyle(staticSelectedStyle, owner.StaticSelectedLinkStyle, head);
            }

            if (dynamicSelectedStyle != null)
            {
                RegisterStyle(dynamicSelectedStyle, owner.DynamicSelectedLinkStyle, head);
            }

            if (levelSelectedStyles != null && levelSelectedStyles.Count > 0)
            {
                levelSelectedLinkStyles = new List <Style> (levelSelectedStyles.Count);
                foreach (Style style in levelSelectedStyles)
                {
                    Style linkStyle = new Style();
                    levelSelectedLinkStyles.Add(linkStyle);
                    RegisterStyle(style, linkStyle, head);
                }
            }

            if (staticHoverStyle != null)
            {
                if (head == null)
                {
                    throw new InvalidOperationException("Using Menu.StaticHoverStyle requires Page.Header to be non-null (e.g. <head runat=\"server\" />).");
                }
                RegisterStyle(staticHoverStyle, owner.StaticHoverLinkStyle, head);
                script.Append(String.Concat(cmenu, ".staticHover = ", ClientScriptManager.GetScriptLiteral(staticHoverStyle.RegisteredCssClass), ";\n"));
                script.Append(String.Concat(cmenu, ".staticLinkHover = ", ClientScriptManager.GetScriptLiteral(owner.StaticHoverLinkStyle.RegisteredCssClass), ";\n"));
            }

            if (dynamicHoverStyle != null)
            {
                if (head == null)
                {
                    throw new InvalidOperationException("Using Menu.DynamicHoverStyle requires Page.Header to be non-null (e.g. <head runat=\"server\" />).");
                }
                RegisterStyle(dynamicHoverStyle, owner.DynamicHoverLinkStyle, head);
                script.Append(String.Concat(cmenu, ".dynamicHover = ", ClientScriptManager.GetScriptLiteral(dynamicHoverStyle.RegisteredCssClass), ";\n"));
                script.Append(String.Concat(cmenu, ".dynamicLinkHover = ", ClientScriptManager.GetScriptLiteral(owner.DynamicHoverLinkStyle.RegisteredCssClass), ";\n"));
            }
        }
Beispiel #4
0
        protected override void RenderMenuItem(HtmlTextWriter writer, MenuItem item, bool vertical, bool notLast, bool isFirst, OwnerContext oc)
        {
            Menu   owner           = Owner;
            bool   displayChildren = owner.DisplayChildren(item);
            bool   isDynamicItem   = IsDynamicItem(owner, item);
            int    itemLevel       = item.Depth + 1;
            string str;

            writer.RenderBeginTag(HtmlTextWriterTag.Li);

            if (isDynamicItem)
            {
                RenderSeparatorImage(owner, writer, oc.DynamicTopSeparatorImageUrl, true);
            }
            else
            {
                RenderSeparatorImage(owner, writer, oc.StaticTopSeparatorImageUrl, true);
            }

            var linkStyle = new Style();

            if (displayChildren && (isDynamicItem || itemLevel >= oc.StaticDisplayLevels))
            {
                AddCssClass(linkStyle, isDynamicItem && haveDynamicPopOut ? "popout-dynamic" : "popout");
            }
            AddCssClass(linkStyle, "level" + itemLevel);

            MenuItemStyleCollection levelStyles = oc.LevelMenuItemStyles;

            if (levelStyles != null && levelStyles.Count >= itemLevel)
            {
                MenuItemStyle style    = levelStyles [itemLevel - 1];
                string        cssClass = style.CssClass;
                if (!String.IsNullOrEmpty(cssClass))
                {
                    AddCssClass(linkStyle, cssClass);
                }
            }

            if (owner.SelectedItem == item)
            {
                AddCssClass(linkStyle, "selected");
            }

            str = item.ToolTip;
            if (!String.IsNullOrEmpty(str))
            {
                writer.AddAttribute("title", str);
            }
            linkStyle.AddAttributesToRender(writer);
            RenderItemHref(owner, writer, item);
            writer.RenderBeginTag(HtmlTextWriterTag.A);
            owner.RenderItemContent(writer, item, isDynamicItem);
            writer.RenderEndTag();

            str = item.SeparatorImageUrl;
            if (String.IsNullOrEmpty(str))
            {
                if (isDynamicItem)
                {
                    str = oc.DynamicBottomSeparatorImageUrl;
                }
                else
                {
                    str = oc.StaticBottomSeparatorImageUrl;
                }
            }
            RenderSeparatorImage(owner, writer, str, true);

            // if (itemLevel == 1)
            //  writer.RenderEndTag (); // </li>

            if (displayChildren)
            {
                owner.RenderMenu(writer, item.ChildItems, vertical, isDynamicItem, itemLevel, notLast);
            }

            if (itemLevel > 0)
            {
                writer.RenderEndTag();                  // </li>
            }
        }