コード例 #1
0
ファイル: StyleBlock.cs プロジェクト: pmq20/mono_forked
        public NamedCssStyleCollection RegisterStyle(HtmlTextWriterStyle key, string value, string styleName = null)
        {
            if (styleName == null)
            {
                styleName = String.Empty;
            }

            NamedCssStyleCollection style = GetStyle(styleName);

            style.Add(key, value);

            return(style);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: StyleBlock.cs プロジェクト: pmq20/mono_forked
        public NamedCssStyleCollection RegisterStyle(Style style, string name = null)
        {
            if (style == null)
            {
                throw new ArgumentNullException("style");
            }

            if (name == null)
            {
                name = String.Empty;
            }

            NamedCssStyleCollection cssStyle = GetStyle(name);

            cssStyle.CopyFrom(style.GetStyleAttributes(null));

            return(cssStyle);
        }
コード例 #4
0
ファイル: StyleBlock.cs プロジェクト: pmq20/mono_forked
        NamedCssStyleCollection GetStyle(string name)
        {
            List <NamedCssStyleCollection> cssStyles = CssStyles;
            NamedCssStyleCollection        style;

            if (!cssStyleIndex.TryGetValue(name, out style))
            {
                style = new NamedCssStyleCollection(name);
                cssStyleIndex.Add(name, style);
                cssStyles.Add(style);
            }

            if (style == null)
            {
                throw new InvalidOperationException(String.Format("Internal error. Stylesheet for style {0} is null.", name));
            }

            return(style);
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: StyleBlock.cs プロジェクト: nobled/mono
		NamedCssStyleCollection GetStyle (string name)
		{
			List <NamedCssStyleCollection> cssStyles = CssStyles;
			NamedCssStyleCollection style;

			if (!cssStyleIndex.TryGetValue (name, out style)) {
				style = new NamedCssStyleCollection (name);
				cssStyleIndex.Add (name, style);
				cssStyles.Add (style);
			}

			if (style == null)
				throw new InvalidOperationException (String.Format ("Internal error. Stylesheet for style {0} is null.", name));
			
			return style;
		}