Esempio n. 1
0
 void ApplyCascadingStyleSheet()
 {
     if (control != null)
     {
         IHTMLDocument2 htmlDoc = control.GetDocument();
         if (htmlDoc != null)
         {
             htmlDoc.CreateStyleSheet(cssStyleSheet, 0);
         }
     }
 }
        ///////////////////////////////////////////////////////////////////////
        // 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);
        }