NamedCssStyleCollection RenderAnchorStyle(StyleBlock block, Style style, string styleName) { if (style == null || block == null) { return(null); } style.AlwaysRenderTextDecoration = true; NamedCssStyleCollection css = block.RegisterStyle(style, styleName); if (style.BorderStyle == BorderStyle.NotSet) { css.Add(HtmlTextWriterStyle.BorderStyle, "none"); } return(css); }
void RenderLevelStyles(StyleBlock block, int num, IList levelStyles, string name, string unitName = null, double indent = 0) { int stylesCount = levelStyles != null ? levelStyles.Count : 0; bool haveStyles = stylesCount > 0; if (!haveStyles || block == null) { return; } NamedCssStyleCollection css; Style style; bool haveIndent = !String.IsNullOrEmpty(unitName) && indent != 0; for (int i = 0; i < stylesCount; i++) { if ((i == 0 && !haveStyles)) { continue; } css = block.RegisterStyle(name + (i + 1)); if (haveStyles && stylesCount > i) { style = levelStyles [i] as Style; if (style != null) { style.AlwaysRenderTextDecoration = true; css.CopyFrom(style.GetStyleAttributes(null)); } } if (haveIndent && i > 0 && i < num) { css.Add(HtmlTextWriterStyle.PaddingLeft, indent.ToString(CultureInfo.InvariantCulture) + unitName); indent += indent; } } }
public StyleBlockStyles(string selector, StyleBlock styleControl) { this._selector = selector; this._styleControl = styleControl; }
public override void PreRender(Page page, HtmlHead head, ClientScriptManager csm, string cmenu, StringBuilder script) { Menu owner = Owner; script.AppendFormat("new Sys.WebForms.Menu ({{ element: '{0}', disappearAfter: {1}, orientation: '{2}', tabIndex: {3}, disabled: {4} }});", owner.ClientID, ClientScriptManager.GetScriptLiteral(owner.DisappearAfter), owner.Orientation.ToString().ToLowerInvariant(), ClientScriptManager.GetScriptLiteral(owner.TabIndex), (!owner.Enabled).ToString().ToLowerInvariant()); Type mt = typeof(Menu); if (!csm.IsClientScriptIncludeRegistered(mt, "MenuModern.js")) { string url = csm.GetWebResourceUrl(mt, "MenuModern.js"); csm.RegisterClientScriptInclude(mt, "MenuModern.js", url); } if (!owner.IncludeStyleBlock) { return; } if (head == null) { throw new InvalidOperationException("Using Menu.IncludeStyleBlock requires Page.Header to be non-null (e.g. <head runat=\"server\" />)."); } StyleBlock block = new StyleBlock(owner.ClientID); Style style = owner.ControlStyle; bool horizontal = owner.Orientation == Orientation.Horizontal; if (style != null) { block.RegisterStyle(style); } // #MenuId img.icon { border-style:none;vertical-align:middle; } block.RegisterStyle(HtmlTextWriterStyle.BorderStyle, "none", "img.icon") .Add(HtmlTextWriterStyle.VerticalAlign, "middle"); // #MenuId img.separator { border-style:none;display:block; } block.RegisterStyle(HtmlTextWriterStyle.BorderStyle, "none", "img.separator") .Add(HtmlTextWriterStyle.Display, "block"); // #MenuId img.horizontal-separator { border-style:none;vertical-align:middle; } if (horizontal) { block.RegisterStyle(HtmlTextWriterStyle.BorderStyle, "none", "img.horizontal-separator") .Add(HtmlTextWriterStyle.VerticalAlign, "middle"); } // #MenuId ul { list-style:none;margin:0;padding:0;width:auto; } block.RegisterStyle(HtmlTextWriterStyle.ListStyleType, "none", "ul") .Add(HtmlTextWriterStyle.Margin, "0") .Add(HtmlTextWriterStyle.Padding, "0") .Add(HtmlTextWriterStyle.Width, "auto"); SubMenuStyle sms = owner.StaticMenuStyleInternal; if (sms != null) { // #MenuId ul.static { ... } block.RegisterStyle(sms, "ul.static"); } // #MenuId ul.dynamic { ...; z-index:1; ... } NamedCssStyleCollection css = block.RegisterStyle("ul.dynamic"); sms = owner.DynamicMenuStyleInternal; if (sms != null) { sms.ForeColor = Color.Empty; css.Add(sms); } css.Add(HtmlTextWriterStyle.ZIndex, "1"); int num = owner.DynamicHorizontalOffset; if (num != 0) { css.Add(HtmlTextWriterStyle.MarginLeft, num + "px"); } num = owner.DynamicVerticalOffset; if (num != 0) { css.Add(HtmlTextWriterStyle.MarginTop, num + "px"); } // BUG: rendering of LevelSubMenuStyles throws InvalidCastException on .NET // but I suspect the code it is supposed to generate is as follows: // // #MenuId ul.levelX { ... } // // so we will just ignore the bug and go with the above code. RenderLevelStyles(block, num, owner.LevelSubMenuStyles, "ul.level"); // #MenuId a { text-decoration:none;white-space:nowrap;display:block; } block.RegisterStyle(HtmlTextWriterStyle.TextDecoration, "none", "a") .Add(HtmlTextWriterStyle.WhiteSpace, "nowrap") .Add(HtmlTextWriterStyle.Display, "block"); // #MenuId a.static { ... } RenderAnchorStyle(block, owner.StaticMenuItemStyleInternal, "a.static"); // #MenuId a.popout { background-image:url("...");background-repeat:no-repeat;background-position:right center;padding-right:14px; } bool needDynamicPopOut = false; string str = owner.StaticPopOutImageUrl; css = null; string urlFormat = "url(\"{0}\")"; if (String.IsNullOrEmpty(str)) { if (owner.StaticEnableDefaultPopOutImage) { css = block.RegisterStyle(HtmlTextWriterStyle.BackgroundImage, String.Format(urlFormat, GetArrowResourceUrl(owner)), "a.popout"); } else { needDynamicPopOut = true; } } else { css = block.RegisterStyle(HtmlTextWriterStyle.BackgroundImage, String.Format(urlFormat, str), "a.popout"); needDynamicPopOut = true; } if (css != null) { css.Add("background-repeat", "no-repeat") .Add("background-position", "right center") .Add(HtmlTextWriterStyle.PaddingRight, "14px"); } // #MenuId a.popout-dynamic { background:url("...") no-repeat right center;padding-right:14px; } str = owner.DynamicPopOutImageUrl; bool haveDynamicUrl = !String.IsNullOrEmpty(str); css = null; if (needDynamicPopOut || haveDynamicUrl) { urlFormat = "url(\"{0}\") no-repeat right center"; if (!haveDynamicUrl) { if (owner.DynamicEnableDefaultPopOutImage) { css = block.RegisterStyle(HtmlTextWriterStyle.BackgroundImage, String.Format(urlFormat, GetArrowResourceUrl(owner)), "a.popout-dynamic"); } } else { css = block.RegisterStyle(HtmlTextWriterStyle.BackgroundImage, String.Format(urlFormat, str), "a.popout-dynamic"); } } if (css != null) { haveDynamicPopOut = true; css.Add(HtmlTextWriterStyle.PaddingRight, "14px"); } // #MenuId a.dynamic { ... } RenderAnchorStyle(block, owner.DynamicMenuItemStyleInternal, "a.dynamic"); num = owner.StaticDisplayLevels; Unit ssmi = owner.StaticSubMenuIndent; string unitName; double indent; if (ssmi == Unit.Empty) { unitName = "em"; indent = 1; } else { unitName = Unit.GetExtension(ssmi.Type); indent = ssmi.Value; } // #MenuId a.levelX { ... } RenderLevelStyles(block, num, owner.LevelMenuItemStyles, "a.level", unitName, indent); // #MenuId a.selected.levelX { ... } RenderLevelStyles(block, num, owner.LevelSelectedStyles, "a.selected.level"); // #MenuId a.static.selected { ...;text-decoration:none; } RenderAnchorStyle(block, owner.StaticSelectedStyleInternal, "a.static.selected"); // #MenuId a.dynamic.selected { ...;text-decoration:none;border-style:none; } RenderAnchorStyle(block, owner.DynamicSelectedStyleInternal, "a.dynamic.selected"); // #MenuId a.static.highlighted { ... } style = owner.StaticHoverStyleInternal; if (style != null) { block.RegisterStyle(style, "a.static.highlighted"); } // #MenuId a.dynamic.highlighted { ... } style = owner.DynamicHoverStyleInternal; if (style != null) { block.RegisterStyle(style, "a.dynamic.highlighted"); } head.Controls.Add(block); }
private StyleBlock CreateStyleBlock() { StyleBlock styleBlock = new StyleBlock(); Style rootMenuItemStyle = Menu.RootMenuItemStyle; // drop the font and forecolor from the control style, those are applied // to the anchors directly with rootMenuItemStyle. Style menuStyle = null; if (!Menu.ControlStyle.IsEmpty) { menuStyle = new Style(); menuStyle.CopyFrom(Menu.ControlStyle); // Relative sizes should not be multiplied (VSWhidbey 457610) menuStyle.Font.Reset(); menuStyle.ForeColor = Color.Empty; } // Menu surrounding DIV style -- without ForeColor or Font, // those are applied directly to the '#Menu a' selector. styleBlock.AddStyleDefinition("#{0}", Menu.ClientID) .AddStyles(menuStyle); // Image styles styleBlock.AddStyleDefinition("#{0} img.icon", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.BorderStyle, "none") .AddStyle(HtmlTextWriterStyle.VerticalAlign, "middle"); styleBlock.AddStyleDefinition("#{0} img.separator", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.BorderStyle, "none") .AddStyle(HtmlTextWriterStyle.Display, "block"); if (Menu.Orientation == Orientation.Horizontal) { styleBlock.AddStyleDefinition("#{0} img.horizontal-separator", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.BorderStyle, "none") .AddStyle(HtmlTextWriterStyle.VerticalAlign, "middle"); } // Menu styles styleBlock.AddStyleDefinition("#{0} ul", Menu.ClientID) .AddStyle("list-style", "none") .AddStyle(HtmlTextWriterStyle.Margin, "0") .AddStyle(HtmlTextWriterStyle.Padding, "0") .AddStyle(HtmlTextWriterStyle.Width, "auto"); styleBlock.AddStyleDefinition("#{0} ul.static", Menu.ClientID) .AddStyles(Menu._staticMenuStyle); var ulDynamic = styleBlock.AddStyleDefinition("#{0} ul.dynamic", Menu.ClientID) .AddStyles(Menu._dynamicMenuStyle) .AddStyle(HtmlTextWriterStyle.ZIndex, "1"); if (Menu.DynamicHorizontalOffset != 0) { ulDynamic.AddStyle(HtmlTextWriterStyle.MarginLeft, Menu.DynamicHorizontalOffset.ToString(CultureInfo.InvariantCulture) + "px"); } if (Menu.DynamicVerticalOffset != 0) { ulDynamic.AddStyle(HtmlTextWriterStyle.MarginTop, Menu.DynamicVerticalOffset.ToString(CultureInfo.InvariantCulture) + "px"); } if (Menu._levelStyles != null) { int index = 1; foreach (SubMenuStyle style in Menu._levelStyles) { styleBlock.AddStyleDefinition("#{0} ul.level{1}", Menu.ClientID, index++) .AddStyles(style); } } // Menu item styles // MenuItems have a 14px default right padding. // This is necessary to prevent the default (and the typical) popout image from going under // the menu item text when it is one of the longer items in the parent menu. // It is 'px' based since its based on the image size not font size. styleBlock.AddStyleDefinition("#{0} a", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.WhiteSpace, "nowrap") .AddStyle(HtmlTextWriterStyle.Display, "block") .AddStyles(rootMenuItemStyle); var menuItemStatic = styleBlock.AddStyleDefinition("#{0} a.static", Menu.ClientID); if ((Menu.Orientation == Orientation.Horizontal) && ((Menu._staticItemStyle == null) || (Menu._staticItemStyle.HorizontalPadding.IsEmpty))) { menuItemStatic.AddStyle(HtmlTextWriterStyle.PaddingLeft, "0.15em") .AddStyle(HtmlTextWriterStyle.PaddingRight, "0.15em"); } menuItemStatic.AddStyles(Menu._staticItemStyle); if (Menu._staticItemStyle != null) { menuItemStatic.AddStyles(Menu._staticItemStyle.HyperLinkStyle); } if (!String.IsNullOrEmpty(StaticPopOutUrl)) { styleBlock.AddStyleDefinition("#{0} a.popout", Menu.ClientID) .AddStyle("background-image", "url(\"" + Menu.ResolveClientUrl(StaticPopOutUrl).Replace("\"", "\\\"") + "\")") .AddStyle("background-repeat", "no-repeat") .AddStyle("background-position", "right center") .AddStyle(HtmlTextWriterStyle.PaddingRight, "14px"); } if (!String.IsNullOrEmpty(DynamicPopOutUrl)) { // Check if dynamic popout is the same as the static one, so there's no need for a separate rule if (DynamicPopOutUrl != StaticPopOutUrl) { styleBlock.AddStyleDefinition("#{0} a.popout-dynamic", Menu.ClientID) .AddStyle("background", "url(\"" + Menu.ResolveClientUrl(DynamicPopOutUrl).Replace("\"", "\\\"") + "\") no-repeat right center") .AddStyle(HtmlTextWriterStyle.PaddingRight, "14px"); } } var styleBlockStyles = styleBlock.AddStyleDefinition("#{0} a.dynamic", Menu.ClientID) .AddStyles(Menu._dynamicItemStyle); if (Menu._dynamicItemStyle != null) { styleBlockStyles.AddStyles(Menu._dynamicItemStyle.HyperLinkStyle); } if (Menu._levelMenuItemStyles != null || Menu.StaticDisplayLevels > 1) { int lastIndex = Menu.StaticDisplayLevels; if (Menu._levelMenuItemStyles != null) { lastIndex = Math.Max(lastIndex, Menu._levelMenuItemStyles.Count); } for (int index = 0; index < lastIndex; ++index) { var style = styleBlock.AddStyleDefinition("#{0} a.level{1}", Menu.ClientID, index + 1); if (index > 0 && index < Menu.StaticDisplayLevels) { Unit indent = Menu.StaticSubMenuIndent; // The default value of Menu.StaticSubMenuIndent is Unit.Empty, and the effective default value // for list rendering is either 1em (vertical) or empty (horizontal). if (indent.IsEmpty && Menu.Orientation == Orientation.Vertical) { indent = new Unit(1, UnitType.Em); } if (!indent.IsEmpty && indent.Value != 0) { double indentValue = indent.Value * index; if (indentValue < Unit.MaxValue) { indent = new Unit(indentValue, indent.Type); } else { indent = new Unit(Unit.MaxValue, indent.Type); } style.AddStyle(HtmlTextWriterStyle.PaddingLeft, indent.ToString(CultureInfo.InvariantCulture)); } } if (Menu._levelMenuItemStyles != null && index < Menu._levelMenuItemStyles.Count) { var levelItemStyle = Menu._levelMenuItemStyles[index]; style.AddStyles(levelItemStyle).AddStyles(levelItemStyle.HyperLinkStyle); } } } styleBlockStyles = styleBlock.AddStyleDefinition("#{0} a.static.selected", Menu.ClientID) .AddStyles(Menu._staticSelectedStyle); if (Menu._staticSelectedStyle != null) { styleBlockStyles.AddStyles(Menu._staticSelectedStyle.HyperLinkStyle); } styleBlockStyles = styleBlock.AddStyleDefinition("#{0} a.dynamic.selected", Menu.ClientID) .AddStyles(Menu._dynamicSelectedStyle); if (Menu._dynamicSelectedStyle != null) { styleBlockStyles.AddStyles(Menu._dynamicSelectedStyle.HyperLinkStyle); } styleBlock.AddStyleDefinition("#{0} a.static.highlighted", Menu.ClientID) .AddStyles(Menu._staticHoverStyle); styleBlock.AddStyleDefinition("#{0} a.dynamic.highlighted", Menu.ClientID) .AddStyles(Menu._dynamicHoverStyle); if (Menu._levelSelectedStyles != null) { int index = 1; foreach (MenuItemStyle style in Menu._levelSelectedStyles) { styleBlock.AddStyleDefinition("#{0} a.selected.level{1}", Menu.ClientID, index++) .AddStyles(style).AddStyles(style.HyperLinkStyle); } } return(styleBlock); }
public StyleBlockStyles(string selector, StyleBlock styleControl) { _selector = selector; _styleControl = styleControl; }
public override void PreRender (Page page, HtmlHead head, ClientScriptManager csm, string cmenu, StringBuilder script) { Menu owner = Owner; script.AppendFormat ("new Sys.WebForms.Menu ({{ element: '{0}', disappearAfter: {1}, orientation: '{2}', tabIndex: {3}, disabled: {4} }});", owner.ClientID, ClientScriptManager.GetScriptLiteral (owner.DisappearAfter), owner.Orientation.ToString ().ToLowerInvariant (), ClientScriptManager.GetScriptLiteral (owner.TabIndex), (!owner.Enabled).ToString ().ToLowerInvariant ()); Type mt = typeof (Menu); if (!csm.IsClientScriptIncludeRegistered (mt, "MenuModern.js")) { string url = csm.GetWebResourceUrl (mt, "MenuModern.js"); csm.RegisterClientScriptInclude (mt, "MenuModern.js", url); } if (!owner.IncludeStyleBlock) return; if (head == null) throw new InvalidOperationException ("Using Menu.IncludeStyleBlock requires Page.Header to be non-null (e.g. <head runat=\"server\" />)."); StyleBlock block = new StyleBlock (owner.ClientID); Style style = owner.ControlStyle; bool horizontal = owner.Orientation == Orientation.Horizontal; if (style != null) block.RegisterStyle (style); // #MenuId img.icon { border-style:none;vertical-align:middle; } block.RegisterStyle (HtmlTextWriterStyle.BorderStyle, "none", "img.icon") .Add (HtmlTextWriterStyle.VerticalAlign, "middle"); // #MenuId img.separator { border-style:none;display:block; } block.RegisterStyle (HtmlTextWriterStyle.BorderStyle, "none", "img.separator") .Add (HtmlTextWriterStyle.Display, "block"); // #MenuId img.horizontal-separator { border-style:none;vertical-align:middle; } if (horizontal) block.RegisterStyle (HtmlTextWriterStyle.BorderStyle, "none", "img.horizontal-separator") .Add (HtmlTextWriterStyle.VerticalAlign, "middle"); // #MenuId ul { list-style:none;margin:0;padding:0;width:auto; } block.RegisterStyle (HtmlTextWriterStyle.ListStyleType, "none", "ul") .Add (HtmlTextWriterStyle.Margin, "0") .Add (HtmlTextWriterStyle.Padding, "0") .Add (HtmlTextWriterStyle.Width, "auto"); SubMenuStyle sms = owner.StaticMenuStyleInternal; if (sms != null) { // #MenuId ul.static { ... } block.RegisterStyle (sms, "ul.static"); } // #MenuId ul.dynamic { ...; z-index:1; ... } NamedCssStyleCollection css = block.RegisterStyle ("ul.dynamic"); sms = owner.DynamicMenuStyleInternal; if (sms != null) { sms.ForeColor = Color.Empty; css.Add (sms); } css.Add (HtmlTextWriterStyle.ZIndex, "1"); int num = owner.DynamicHorizontalOffset; if (num != 0) css.Add (HtmlTextWriterStyle.MarginLeft, num + "px"); num = owner.DynamicVerticalOffset; if (num != 0) css.Add (HtmlTextWriterStyle.MarginTop, num + "px"); // BUG: rendering of LevelSubMenuStyles throws InvalidCastException on .NET // but I suspect the code it is supposed to generate is as follows: // // #MenuId ul.levelX { ... } // // so we will just ignore the bug and go with the above code. RenderLevelStyles (block, num, owner.LevelSubMenuStyles, "ul.level"); // #MenuId a { text-decoration:none;white-space:nowrap;display:block; } block.RegisterStyle (HtmlTextWriterStyle.TextDecoration, "none", "a") .Add (HtmlTextWriterStyle.WhiteSpace, "nowrap") .Add (HtmlTextWriterStyle.Display, "block"); // #MenuId a.static { ... } RenderAnchorStyle (block, owner.StaticMenuItemStyleInternal, "a.static"); // #MenuId a.popout { background-image:url("...");background-repeat:no-repeat;background-position:right center;padding-right:14px; } bool needDynamicPopOut = false; string str = owner.StaticPopOutImageUrl; css = null; string urlFormat = "url(\"{0}\")"; if (String.IsNullOrEmpty (str)) { if (owner.StaticEnableDefaultPopOutImage) css = block.RegisterStyle (HtmlTextWriterStyle.BackgroundImage, String.Format (urlFormat, GetArrowResourceUrl (owner)), "a.popout"); else needDynamicPopOut = true; } else { css = block.RegisterStyle (HtmlTextWriterStyle.BackgroundImage, String.Format (urlFormat, str), "a.popout"); needDynamicPopOut = true; } if (css != null) css.Add ("background-repeat", "no-repeat") .Add ("background-position", "right center") .Add (HtmlTextWriterStyle.PaddingRight, "14px"); // #MenuId a.popout-dynamic { background:url("...") no-repeat right center;padding-right:14px; } str = owner.DynamicPopOutImageUrl; bool haveDynamicUrl = !String.IsNullOrEmpty (str); css = null; if (needDynamicPopOut || haveDynamicUrl) { urlFormat = "url(\"{0}\") no-repeat right center"; if (!haveDynamicUrl) { if (owner.DynamicEnableDefaultPopOutImage) css = block.RegisterStyle (HtmlTextWriterStyle.BackgroundImage, String.Format (urlFormat, GetArrowResourceUrl (owner)), "a.popout-dynamic"); } else css = block.RegisterStyle (HtmlTextWriterStyle.BackgroundImage, String.Format (urlFormat, str), "a.popout-dynamic"); } if (css != null) { haveDynamicPopOut = true; css.Add (HtmlTextWriterStyle.PaddingRight, "14px"); } // #MenuId a.dynamic { ... } RenderAnchorStyle (block, owner.DynamicMenuItemStyleInternal, "a.dynamic"); num = owner.StaticDisplayLevels; Unit ssmi = owner.StaticSubMenuIndent; string unitName; double indent; if (ssmi == Unit.Empty) { unitName = "em"; indent = 1; } else { unitName = Unit.GetExtension (ssmi.Type); indent = ssmi.Value; } // #MenuId a.levelX { ... } RenderLevelStyles (block, num, owner.LevelMenuItemStyles, "a.level", unitName, indent); // #MenuId a.selected.levelX { ... } RenderLevelStyles (block, num, owner.LevelSelectedStyles, "a.selected.level"); // #MenuId a.static.selected { ...;text-decoration:none; } RenderAnchorStyle (block, owner.StaticSelectedStyleInternal, "a.static.selected"); // #MenuId a.dynamic.selected { ...;text-decoration:none;border-style:none; } RenderAnchorStyle (block, owner.DynamicSelectedStyleInternal, "a.dynamic.selected"); // #MenuId a.static.highlighted { ... } style = owner.StaticHoverStyleInternal; if (style != null) block.RegisterStyle (style, "a.static.highlighted"); // #MenuId a.dynamic.highlighted { ... } style = owner.DynamicHoverStyleInternal; if (style != null) block.RegisterStyle (style, "a.dynamic.highlighted"); head.Controls.Add (block); }
void RenderLevelStyles (StyleBlock block, int num, IList levelStyles, string name, string unitName = null, double indent = 0) { int stylesCount = levelStyles != null ? levelStyles.Count : 0; bool haveStyles = stylesCount > 0; if (!haveStyles || block == null) return; NamedCssStyleCollection css; Style style; bool haveIndent = !String.IsNullOrEmpty (unitName) && indent != 0; for (int i = 0; i < stylesCount; i++) { if ((i == 0 && !haveStyles)) continue; css = block.RegisterStyle (name + (i + 1)); if (haveStyles && stylesCount > i) { style = levelStyles [i] as Style; if (style != null) { style.AlwaysRenderTextDecoration = true; css.CopyFrom (style.GetStyleAttributes (null)); } } if (haveIndent && i > 0 && i < num) { css.Add (HtmlTextWriterStyle.PaddingLeft, indent.ToString (CultureInfo.InvariantCulture) + unitName); indent += indent; } } }
NamedCssStyleCollection RenderAnchorStyle (StyleBlock block, Style style, string styleName) { if (style == null || block == null) return null; style.AlwaysRenderTextDecoration = true; NamedCssStyleCollection css = block.RegisterStyle (style, styleName); if (style.BorderStyle == BorderStyle.NotSet) css.Add (HtmlTextWriterStyle.BorderStyle, "none"); return css; }
private StyleBlock CreateStyleBlock() { StyleBlock styleBlock = new StyleBlock(); Style rootMenuItemStyle = Menu.RootMenuItemStyle; // drop the font and forecolor from the control style, those are applied // to the anchors directly with rootMenuItemStyle. Style menuStyle = null; if (!Menu.ControlStyle.IsEmpty) { menuStyle = new Style(); menuStyle.CopyFrom(Menu.ControlStyle); // Relative sizes should not be multiplied (VSWhidbey 457610) menuStyle.Font.Reset(); menuStyle.ForeColor = Color.Empty; } // Menu surrounding DIV style -- without ForeColor or Font, // those are applied directly to the '#Menu a' selector. styleBlock.AddStyleDefinition("#{0}", Menu.ClientID) .AddStyles(menuStyle); // Image styles styleBlock.AddStyleDefinition("#{0} img.icon", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.BorderStyle, "none") .AddStyle(HtmlTextWriterStyle.VerticalAlign, "middle"); styleBlock.AddStyleDefinition("#{0} img.separator", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.BorderStyle, "none") .AddStyle(HtmlTextWriterStyle.Display, "block"); if (Menu.Orientation == Orientation.Horizontal) { styleBlock.AddStyleDefinition("#{0} img.horizontal-separator", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.BorderStyle, "none") .AddStyle(HtmlTextWriterStyle.VerticalAlign, "middle"); } // Menu styles styleBlock.AddStyleDefinition("#{0} ul", Menu.ClientID) .AddStyle("list-style", "none") .AddStyle(HtmlTextWriterStyle.Margin, "0") .AddStyle(HtmlTextWriterStyle.Padding, "0") .AddStyle(HtmlTextWriterStyle.Width, "auto"); styleBlock.AddStyleDefinition("#{0} ul.static", Menu.ClientID) .AddStyles(Menu._staticMenuStyle); var ulDynamic = styleBlock.AddStyleDefinition("#{0} ul.dynamic", Menu.ClientID) .AddStyles(Menu._dynamicMenuStyle) .AddStyle(HtmlTextWriterStyle.ZIndex, "1"); if (Menu.DynamicHorizontalOffset != 0) { ulDynamic.AddStyle(HtmlTextWriterStyle.MarginLeft, Menu.DynamicHorizontalOffset.ToString(CultureInfo.InvariantCulture) + "px"); } if (Menu.DynamicVerticalOffset != 0) { ulDynamic.AddStyle(HtmlTextWriterStyle.MarginTop, Menu.DynamicVerticalOffset.ToString(CultureInfo.InvariantCulture) + "px"); } if (Menu._levelStyles != null) { int index = 1; foreach (SubMenuStyle style in Menu._levelStyles) { styleBlock.AddStyleDefinition("#{0} ul.level{1}", Menu.ClientID, index++) .AddStyles(style); } } // Menu item styles // MenuItems have a 14px default right padding. // This is necessary to prevent the default (and the typical) popout image from going under // the menu item text when it is one of the longer items in the parent menu. // It is 'px' based since its based on the image size not font size. styleBlock.AddStyleDefinition("#{0} a", Menu.ClientID) .AddStyle(HtmlTextWriterStyle.WhiteSpace, "nowrap") .AddStyle(HtmlTextWriterStyle.Display, "block") .AddStyles(rootMenuItemStyle); var menuItemStatic = styleBlock.AddStyleDefinition("#{0} a.static", Menu.ClientID); if ((Menu.Orientation == Orientation.Horizontal) && ((Menu._staticItemStyle == null) || (Menu._staticItemStyle.HorizontalPadding.IsEmpty))) { menuItemStatic.AddStyle(HtmlTextWriterStyle.PaddingLeft, "0.15em") .AddStyle(HtmlTextWriterStyle.PaddingRight, "0.15em"); } menuItemStatic.AddStyles(Menu._staticItemStyle); if (Menu._staticItemStyle != null) { menuItemStatic.AddStyles(Menu._staticItemStyle.HyperLinkStyle); } if (!String.IsNullOrEmpty(StaticPopOutUrl)) { styleBlock.AddStyleDefinition("#{0} a.popout", Menu.ClientID) .AddStyle("background-image", "url(\"" + Menu.ResolveClientUrl(StaticPopOutUrl).Replace("\"", "\\\"") + "\")") .AddStyle("background-repeat", "no-repeat") .AddStyle("background-position", "right center") .AddStyle(HtmlTextWriterStyle.PaddingRight, "14px"); } if (!String.IsNullOrEmpty(DynamicPopOutUrl)) { // Check if dynamic popout is the same as the static one, so there's no need for a separate rule if (DynamicPopOutUrl != StaticPopOutUrl) { styleBlock.AddStyleDefinition("#{0} a.popout-dynamic", Menu.ClientID) .AddStyle("background", "url(\"" + Menu.ResolveClientUrl(DynamicPopOutUrl).Replace("\"", "\\\"") + "\") no-repeat right center") .AddStyle(HtmlTextWriterStyle.PaddingRight, "14px"); } } var styleBlockStyles = styleBlock.AddStyleDefinition("#{0} a.dynamic", Menu.ClientID) .AddStyles(Menu._dynamicItemStyle); if (Menu._dynamicItemStyle != null) { styleBlockStyles.AddStyles(Menu._dynamicItemStyle.HyperLinkStyle); } if (Menu._levelMenuItemStyles != null || Menu.StaticDisplayLevels > 1) { int lastIndex = Menu.StaticDisplayLevels; if (Menu._levelMenuItemStyles != null) { lastIndex = Math.Max(lastIndex, Menu._levelMenuItemStyles.Count); } for (int index = 0; index < lastIndex; ++index) { var style = styleBlock.AddStyleDefinition("#{0} a.level{1}", Menu.ClientID, index + 1); if (index > 0 && index < Menu.StaticDisplayLevels) { Unit indent = Menu.StaticSubMenuIndent; // The default value of Menu.StaticSubMenuIndent is Unit.Empty, and the effective default value // for list rendering is either 1em (vertical) or empty (horizontal). if (indent.IsEmpty && Menu.Orientation == Orientation.Vertical) { indent = new Unit(1, UnitType.Em); } if (!indent.IsEmpty && indent.Value != 0) { double indentValue = indent.Value * index; if (indentValue < Unit.MaxValue) { indent = new Unit(indentValue, indent.Type); } else { indent = new Unit(Unit.MaxValue, indent.Type); } style.AddStyle(HtmlTextWriterStyle.PaddingLeft, indent.ToString(CultureInfo.InvariantCulture)); } } if (Menu._levelMenuItemStyles != null && index < Menu._levelMenuItemStyles.Count) { var levelItemStyle = Menu._levelMenuItemStyles[index]; style.AddStyles(levelItemStyle).AddStyles(levelItemStyle.HyperLinkStyle); } } } styleBlockStyles = styleBlock.AddStyleDefinition("#{0} a.static.selected", Menu.ClientID) .AddStyles(Menu._staticSelectedStyle); if (Menu._staticSelectedStyle != null) { styleBlockStyles.AddStyles(Menu._staticSelectedStyle.HyperLinkStyle); } styleBlockStyles = styleBlock.AddStyleDefinition("#{0} a.dynamic.selected", Menu.ClientID) .AddStyles(Menu._dynamicSelectedStyle); if (Menu._dynamicSelectedStyle != null) { styleBlockStyles.AddStyles(Menu._dynamicSelectedStyle.HyperLinkStyle); } styleBlock.AddStyleDefinition("#{0} a.static.highlighted", Menu.ClientID) .AddStyles(Menu._staticHoverStyle); styleBlock.AddStyleDefinition("#{0} a.dynamic.highlighted", Menu.ClientID) .AddStyles(Menu._dynamicHoverStyle); if (Menu._levelSelectedStyles != null) { int index = 1; foreach (MenuItemStyle style in Menu._levelSelectedStyles) { styleBlock.AddStyleDefinition("#{0} a.selected.level{1}", Menu.ClientID, index++) .AddStyles(style).AddStyles(style.HyperLinkStyle); } } return styleBlock; }