/// <include file='doc\StyleBuilderForm.uex' path='docs/doc[@for="StyleBuilderForm.SaveStringStyle"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected void SaveStringStyle()
        {
            Debug.Assert(styleType == STYLE_TYPE_STRING,
                         "SaveStringStyle must be called only when editing a string");

            Debug.Assert(editingStyle[0].GetPeerStyle() is IHTMLRuleStyle,
                         "Unexpected peer style for wrapper style");

            IHTMLRuleStyle style = (IHTMLRuleStyle)editingStyle[0].GetPeerStyle();

            styleObject = style.GetCssText();

            if (styleObject == null)
            {
                styleObject = "";
            }
        }
        /// <include file='doc\StyleBuilderForm.uex' path='docs/doc[@for="StyleBuilderForm.InitStyle"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected void InitStyle()
        {
            string styleValue = null;

            editingStyle = new IStyleBuilderStyle[1];
            switch (styleType)
            {
            case STYLE_TYPE_STRING:
                if (preview != null)
                {
                    IHTMLRuleStyle parseStyle = preview.GetParseStyleRule();
                    if (parseStyle != null)
                    {
                        styleValue = (string)styleObject;
                        parseStyle.SetCssText(styleValue);
                        editingStyle[0] = new CSSRuleStyle(parseStyle);
                    }
                }
                break;

            case STYLE_TYPE_INLINESTYLE:
            {
                IHTMLStyle style = (IHTMLStyle)styleObject;

                styleValue      = style.GetCssText();
                editingStyle[0] = new CSSInlineStyle(style);
            }
            break;

            case STYLE_TYPE_RULESTYLE:
            {
                IHTMLRuleStyle style = (IHTMLRuleStyle)styleObject;

                styleValue      = style.GetCssText();
                editingStyle[0] = new CSSRuleStyle(style);
            }
            break;
            }

            if (styleValue != null)
            {
                preview.SetSharedElementStyle(styleValue);
            }
        }
        ///////////////////////////////////////////////////////////////////////
        // Methods

        public virtual bool InitPreview(string baseUrl)
        {
            bool            result = false;
            IHTMLStyleSheet previewStyleSheet;
            IHTMLStyleSheetRulesCollection rulesCollection;
            IHTMLStyleSheetRule            style;
            IHTMLElement     documentElem;
            IHTMLBodyElement bodyElem;

            try {
                if ((baseUrl != null) && (baseUrl.Length != 0))
                {
                    SetBaseHref(baseUrl);
                }

                previewStyleSheet = previewDocument.CreateStyleSheet("", 0);
                if (previewStyleSheet == null)
                {
                    throw new Exception("Failed to create preview style sheet");
                }

                previewStyleSheet.SetCssText(PREVIEW_CSS);

                documentElem = previewDocument.GetBody();
                if (documentElem == null)
                {
                    throw new Exception("Failed to get body element from preview");
                }

                documentElem.SetInnerHTML(PREVIEW_HTML);

                bodyElem = (IHTMLBodyElement)documentElem;
                bodyElem.SetScroll("no");

                previewElement = GetElement("divPreview");
                if (previewElement == null)
                {
                    throw new Exception("Failed to get preview element");
                }

                sharedElement = GetElement("divShared");
                if (sharedElement == null)
                {
                    throw new Exception("Failed to get shared element");
                }

                rulesCollection = previewStyleSheet.GetRules();
                if (rulesCollection == null)
                {
                    throw new Exception("Failed to get style rules collection");
                }

                style = (IHTMLStyleSheetRule)rulesCollection.Item(0);
                if (style == null)
                {
                    throw new Exception("Failed to get style rule for parsing");
                }

                parseStyle = style.GetStyle();
                if (parseStyle == null)
                {
                    throw new Exception("Failed to get rule's style");
                }

                result = true;
            }
            catch (Exception e) {
                Debug.Fail(e.ToString());
                previewDocument = null;
            }

            return(result);
        }
 public virtual void ClosePreview()
 {
     parseStyle      = null;
     previewElement  = null;
     previewDocument = null;
 }
        ///////////////////////////////////////////////////////////////////////////
        // Constructor

        /// <include file='doc\CSSRuleStyle.uex' path='docs/doc[@for="CSSRuleStyle.CSSRuleStyle"]/*' />
        /// <devdoc>
        ///     Creates a new CSSRuleStyle wrapping the specified style
        /// </devdoc>
        public CSSRuleStyle(IHTMLRuleStyle style)
        {
            Debug.Assert(style != null, "Null style used for CSSRuleStyle");

            this.style = style;
        }