public void Add(HtmlTextWriterStyle key, string value)
        {
            if (_intTable == null)
            {
                _intTable = new HybridDictionary();
            }
            _intTable[(int)key] = value;

            string name = CssTextWriter.GetStyleName(key);

            if (name.Length != 0)
            {
                // Remove from the other table to avoid duplicates.
                if (_table == null)
                {
                    ParseString();
                }

                _table.Remove(name);
            }

            if (_state != null)
            {
                // keep style attribute synchronized
                _state["style"] = BuildString();
            }
            _style = null;
        }
        /// <devdoc>
        ///    <para>
        ///       Adds a style to the CssStyleCollection.
        ///    </para>
        /// </devdoc>
        public void Add(string key, string value)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            if (_table == null)
            {
                ParseString();
            }
            _table[key] = value;

            if (_intTable != null)
            {
                // Remove from the other table to avoid duplicates.
                HtmlTextWriterStyle style = CssTextWriter.GetStyleKey(key);
                if (style != (HtmlTextWriterStyle)(-1))
                {
                    _intTable.Remove(style);
                }
            }

            if (_state != null)
            {
                // keep style attribute synchronized
                _state["style"] = BuildString();
            }
            _style = null;
        }
 public void Add(string key, string value)
 {
     if (string.IsNullOrEmpty(key))
     {
         throw new ArgumentNullException("key");
     }
     if (this._table == null)
     {
         this.ParseString();
     }
     this._table[key] = value;
     if (this._intTable != null)
     {
         HtmlTextWriterStyle styleKey = CssTextWriter.GetStyleKey(key);
         if (styleKey != ~HtmlTextWriterStyle.BackgroundColor)
         {
             this._intTable.Remove(styleKey);
         }
     }
     if (this._state != null)
     {
         this._state["style"] = this.BuildString();
     }
     this._style = null;
 }
        private string GetCssStyleRenderString(Type htmlTextWriterType)
        {
            // Nothing to do if no styles are registered.
            if (_registeredStyleInfo == null)
            {
                return(null);
            }

            // Create an empty cssStringWriter
            StringWriter cssStringWriter = new StringWriter(CultureInfo.CurrentCulture);

            // Create a new HtmlTextWriter, with the same type as the current one
            HtmlTextWriter cssHtmlTextWriter =
                Page.CreateHtmlTextWriterFromType(cssStringWriter, htmlTextWriterType);

            CssTextWriter cssWriter = new CssTextWriter(cssHtmlTextWriter);

            foreach (SelectorStyleInfo si in _registeredStyleInfo)
            {
                HtmlHead.RenderCssRule(cssWriter, si.selector, si.style, si.urlResolver);
            }

            // Return the css style rendered string
            return(cssStringWriter.ToString());
        }
 private string BuildString()
 {
     if (((this._table == null) || (this._table.Count == 0)) && ((this._intTable == null) || (this._intTable.Count == 0)))
     {
         return null;
     }
     StringWriter writer = new StringWriter();
     CssTextWriter writer2 = new CssTextWriter(writer);
     this.Render(writer2);
     return writer.ToString();
 }
        private string BuildString()
        {
            if (((this._table == null) || (this._table.Count == 0)) && ((this._intTable == null) || (this._intTable.Count == 0)))
            {
                return(null);
            }
            StringWriter  writer  = new StringWriter();
            CssTextWriter writer2 = new CssTextWriter(writer);

            this.Render(writer2);
            return(writer.ToString());
        }
        private string GetCssStyleRenderString(Type htmlTextWriterType)
        {
            if (this._registeredStyleInfo == null)
            {
                return(null);
            }
            StringWriter  tw        = new StringWriter(CultureInfo.CurrentCulture);
            CssTextWriter cssWriter = new CssTextWriter(Page.CreateHtmlTextWriterFromType(tw, htmlTextWriterType));

            foreach (SelectorStyleInfo info in this._registeredStyleInfo)
            {
                HtmlHead.RenderCssRule(cssWriter, info.selector, info.style, info.urlResolver);
            }
            return(tw.ToString());
        }
        /*  BuildString
         *  Form the style string from data contained in the
         *  hash table
         */
        private string BuildString()
        {
            // if the tables are null, there is nothing to build
            if (((_table == null) || (_table.Count == 0)) &&
                ((_intTable == null) || (_intTable.Count == 0)))
            {
                return(null);
            }

            StringWriter  sw     = new StringWriter();
            CssTextWriter writer = new CssTextWriter(sw);

            Render(writer);
            return(sw.ToString());
        }
 internal void Render(CssTextWriter writer)
 {
     if ((this._table != null) && (this._table.Count > 0))
     {
         foreach (DictionaryEntry entry in this._table)
         {
             writer.WriteAttribute((string)entry.Key, (string)entry.Value);
         }
     }
     if ((this._intTable != null) && (this._intTable.Count > 0))
     {
         foreach (DictionaryEntry entry2 in this._intTable)
         {
             writer.WriteAttribute((HtmlTextWriterStyle)entry2.Key, (string)entry2.Value);
         }
     }
 }
        /*
         * Automatically adds new keys.
         */

        /// <devdoc>
        ///    <para>
        ///       Gets or sets a specified CSS value.
        ///    </para>
        /// </devdoc>
        public string this[string key] {
            get {
                if (_table == null)
                {
                    ParseString();
                }
                string value = (string)_table[key];

                if (value == null)
                {
                    HtmlTextWriterStyle style = CssTextWriter.GetStyleKey(key);
                    if (style != (HtmlTextWriterStyle)(-1))
                    {
                        value = this[style];
                    }
                }

                return(value);
            }
            set {
                Add(key, value);
            }
        }
        public void Add(HtmlTextWriterStyle key, string value)
        {
            if (this._intTable == null)
            {
                this._intTable = new HybridDictionary();
            }
            this._intTable[(int)key] = value;
            string styleName = CssTextWriter.GetStyleName(key);

            if (styleName.Length != 0)
            {
                if (this._table == null)
                {
                    this.ParseString();
                }
                this._table.Remove(styleName);
            }
            if (this._state != null)
            {
                this._state["style"] = this.BuildString();
            }
            this._style = null;
        }
 public string this[string key]
 {
     get
     {
         if (this._table == null)
         {
             this.ParseString();
         }
         string str = (string)this._table[key];
         if (str == null)
         {
             HtmlTextWriterStyle styleKey = CssTextWriter.GetStyleKey(key);
             if (styleKey != ~HtmlTextWriterStyle.BackgroundColor)
             {
                 str = this[styleKey];
             }
         }
         return(str);
     }
     set
     {
         this.Add(key, value);
     }
 }
 private string GetCssStyleRenderString(Type htmlTextWriterType)
 {
     if (this._registeredStyleInfo == null)
     {
         return null;
     }
     StringWriter tw = new StringWriter(CultureInfo.CurrentCulture);
     CssTextWriter cssWriter = new CssTextWriter(Page.CreateHtmlTextWriterFromType(tw, htmlTextWriterType));
     foreach (SelectorStyleInfo info in this._registeredStyleInfo)
     {
         HtmlHead.RenderCssRule(cssWriter, info.selector, info.style, info.urlResolver);
     }
     return tw.ToString();
 }
    private string GetCssStyleRenderString(Type htmlTextWriterType) {
        // Nothing to do if no styles are registered.
        if (_registeredStyleInfo == null) {
            return null;
        }

        // Create an empty cssStringWriter
        StringWriter cssStringWriter = new StringWriter(CultureInfo.CurrentCulture);

        // Create a new HtmlTextWriter, with the same type as the current one
        HtmlTextWriter cssHtmlTextWriter = 
            Page.CreateHtmlTextWriterFromType(cssStringWriter, htmlTextWriterType);

        CssTextWriter cssWriter = new CssTextWriter(cssHtmlTextWriter);

        foreach (SelectorStyleInfo si in _registeredStyleInfo) {
            HtmlHead.RenderCssRule(cssWriter, si.selector, si.style, si.urlResolver);
        }

        // Return the css style rendered string
        return cssStringWriter.ToString();
    }
 /// <devdoc>
 /// Render out the attribute collection into a CSS TextWriter. This
 /// effectively renders the value of an inline style attribute.
 /// </devdoc>
 internal void Render(CssTextWriter writer) {
     if (_table != null && _table.Count > 0) {
         foreach (DictionaryEntry entry in _table) {
             writer.WriteAttribute((string)entry.Key, (string)entry.Value);
         }
     }
     if (_intTable != null && _intTable.Count > 0) {
         foreach (DictionaryEntry entry in _intTable) {
             writer.WriteAttribute((HtmlTextWriterStyle)entry.Key, (string)entry.Value);
         }
     }
 }
        /*  BuildString
         *  Form the style string from data contained in the 
         *  hash table
         */
        private string BuildString() {
            // if the tables are null, there is nothing to build
            if (((_table == null) || (_table.Count == 0)) &&
                ((_intTable == null) || (_intTable.Count == 0))) {
                return null;
            }

            StringWriter sw = new StringWriter();
            CssTextWriter writer = new CssTextWriter(sw);

            Render(writer);
            return sw.ToString();
        }
Beispiel #17
0
        internal static void RenderCssRule(CssTextWriter cssWriter, string selector,
            Style style, IUrlResolutionService urlResolver) {

            cssWriter.WriteBeginCssRule(selector);

            CssStyleCollection attrs = style.GetStyleAttributes(urlResolver);
            attrs.Render(cssWriter);

            cssWriter.WriteEndCssRule();
        }
Beispiel #18
0
            public void Render(HtmlTextWriter writer) {
                if ((_styles == null) && (_selectorStyles == null) && CSSStyleString == null) {
                    return;
                }

                writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                writer.RenderBeginTag(HtmlTextWriterTag.Style);

                CssTextWriter cssWriter = new CssTextWriter(writer);
                if (_styles != null) {
                    for (int i = 0; i < _styles.Count; i++) {
                        StyleInfo si = (StyleInfo)_styles[i];

                        string cssClass = si.style.RegisteredCssClass;
                        if (cssClass.Length != 0) {
                            RenderCssRule(cssWriter, "." + cssClass, si.style, si.urlResolver);
                        }
                    }
                }

                if (_selectorStyles != null) {
                    for (int i = 0; i < _selectorStyles.Count; i++) {
                        SelectorStyleInfo si = (SelectorStyleInfo)_selectorStyles[i];
                        RenderCssRule(cssWriter, si.selector, si.style, si.urlResolver);
                    }
                }

                if (CSSStyleString != null) {
                    writer.Write(CSSStyleString);
                }

                writer.RenderEndTag();
            }
 public void Render(HtmlTextWriter writer)
 {
     if (((this._styles != null) || (this._selectorStyles != null)) || (this.CSSStyleString != null))
     {
         writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
         writer.RenderBeginTag(HtmlTextWriterTag.Style);
         CssTextWriter cssWriter = new CssTextWriter(writer);
         if (this._styles != null)
         {
             for (int i = 0; i < this._styles.Count; i++)
             {
                 StyleInfo info = (StyleInfo) this._styles[i];
                 string registeredCssClass = info.style.RegisteredCssClass;
                 if (registeredCssClass.Length != 0)
                 {
                     HtmlHead.RenderCssRule(cssWriter, "." + registeredCssClass, info.style, info.urlResolver);
                 }
             }
         }
         if (this._selectorStyles != null)
         {
             for (int j = 0; j < this._selectorStyles.Count; j++)
             {
                 SelectorStyleInfo info2 = (SelectorStyleInfo) this._selectorStyles[j];
                 HtmlHead.RenderCssRule(cssWriter, info2.selector, info2.style, info2.urlResolver);
             }
         }
         if (this.CSSStyleString != null)
         {
             writer.Write(this.CSSStyleString);
         }
         writer.RenderEndTag();
     }
 }