コード例 #1
0
        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);
        }
コード例 #2
0
        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;
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: MenuListRenderer.cs プロジェクト: alisci01/mono
		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);
		}
コード例 #5
0
ファイル: MenuListRenderer.cs プロジェクト: alisci01/mono
		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;
				}
			}
		}
コード例 #6
0
ファイル: MenuListRenderer.cs プロジェクト: alisci01/mono
		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;
		}