Esempio n. 1
0
        protected virtual void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            StateBag viewState = ViewState;

            Color c;

            // ForeColor
            if (IsSet(PROP_FORECOLOR))
            {
                c = (Color)viewState["ForeColor"];
                if (!c.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(c));
                }
            }

            // BackColor
            if (IsSet(PROP_BACKCOLOR))
            {
                c = (Color)viewState["BackColor"];
                if (!c.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (IsSet(PROP_BORDERCOLOR))
            {
                c = (Color)viewState["BorderColor"];
                if (!c.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit        bu = this.BorderWidth;

            if (!bu.IsEmpty)
            {
                attributes.Add(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet)
                {
                    if (bu.Value != 0.0)
                    {
                        attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }
            else
            {
                if (bs != BorderStyle.NotSet)
                {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }

            // need to call the property get in case we have font properties from view state and have not
            // created the font object
            FontInfo font = Font;

            // Font.Names
            string[] names = font.Names;
            if (names.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.FontFamily, Style.FormatStringArray(names, ','));
            }

            // Font.Size
            FontUnit fu = font.Size;

            if (fu.IsEmpty == false)
            {
                attributes.Add(HtmlTextWriterStyle.FontSize, fu.ToString(CultureInfo.InvariantCulture));
            }

            // Font.Bold
            if (IsSet(PROP_FONT_BOLD))
            {
                if (font.Bold)
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "bold");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "normal");
                }
            }

            // Font.Italic
            if (IsSet(PROP_FONT_ITALIC))
            {
                if (font.Italic == true)
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "italic");
                }
                else
                {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "normal");
                }
            }

            //
            string textDecoration = String.Empty;

            if (font.Underline)
            {
                textDecoration = "underline";
            }
            if (font.Overline)
            {
                textDecoration += " overline";
            }
            if (font.Strikeout)
            {
                textDecoration += " line-through";
            }
            if (textDecoration.Length > 0)
            {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, textDecoration);
            }
            else
            {
                if (IsSet(PROP_FONT_UNDERLINE) || IsSet(PROP_FONT_OVERLINE) || IsSet(PROP_FONT_STRIKEOUT))
                {
                    attributes.Add(HtmlTextWriterStyle.TextDecoration, "none");
                }
            }

            Unit u;

            // Height
            if (IsSet(PROP_HEIGHT))
            {
                u = (Unit)viewState["Height"];
                if (!u.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (IsSet(PROP_WIDTH))
            {
                u = (Unit)viewState["Width"];
                if (!u.IsEmpty)
                {
                    attributes.Add(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }
        }
Esempio n. 2
0
        /// <include file='doc\Style.uex' path='docs/doc[@for="Style.AddAttributesToRender1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Adds all non-blank style attributes to the HTML output stream to be rendered
        ///       to the client.
        ///    </para>
        /// </devdoc>
        public virtual void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
        {
            StateBag viewState = ViewState;

            // CssClass
            if (IsSet(PROP_CSSCLASS))
            {
                string css = (string)(viewState["CssClass"]);
                if (css.Length > 0)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, css);
                }
            }

            Color c;
            Unit  u;

            // ForeColor
            if (IsSet(PROP_FORECOLOR))
            {
                c = (Color)(viewState["ForeColor"]);;
                if (!c.IsEmpty)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(c));
                }
            }

            // BackColor
            if (IsSet(PROP_BACKCOLOR))
            {
                c = (Color)(viewState["BackColor"]);
                if (!c.IsEmpty)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (IsSet(PROP_BORDERCOLOR))
            {
                c = (Color)(viewState["BorderColor"]);
                if (!c.IsEmpty)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit        bu = this.BorderWidth;

            if (!bu.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet)
                {
                    if (bu.Value != 0.0)
                    {
                        writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, Enum.Format(typeof(BorderStyle), bs, "G"));
                }
            }
            else
            {
                if (bs != BorderStyle.NotSet)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, Enum.Format(typeof(BorderStyle), bs, "G"));
                }
            }

            // need to call the property get in case we have font properties from view state and have not
            // created the font object
            FontInfo font = Font;

            // Font.Names
            string[] names = font.Names;
            if (names.Length > 0)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, Style.FormatStringArray(names, ','));
            }

            // Font.Size
            FontUnit fu = font.Size;

            if (fu.IsEmpty == false)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, fu.ToString(CultureInfo.InvariantCulture));
            }

            // CONSIDER: How do we determine whether to render "normal" for font-weight or font-style?
            //           How do we determine whether to render "none" for text-decoration?

            // Font.Bold
            bool fw = font.Bold;

            if (fw == true)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "bold");
            }
            // Font.Italic
            bool fi = font.Italic;

            if (fi == true)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontStyle, "italic");
            }

            bool   underline = font.Underline;
            bool   overline  = font.Overline;
            bool   strikeout = font.Strikeout;
            string td        = String.Empty;

            // CONSIDER, nikhilko: we need to detect not-set state and write out "none"
            if (underline)
            {
                td = "underline";
            }
            if (overline)
            {
                td += " overline";
            }
            if (strikeout)
            {
                td += " line-through";
            }
            if (td.Length > 0)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, td);
            }


            // Height
            if (IsSet(PROP_HEIGHT))
            {
                u = (Unit)(viewState["Height"]);
                if (u.IsEmpty == false)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (IsSet(PROP_WIDTH))
            {
                u = (Unit)(viewState["Width"]);
                if (u.IsEmpty == false)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }
        }