예제 #1
0
        /// <summary>
        /// </summary>
        public void CloseMSHTML()
        {
            hostControl.Resize -= new EventHandler(this.OnParentResize);

            try {
                if (propNotifyCookie != null)
                {
                    propNotifyCookie.Disconnect();
                    propNotifyCookie = null;
                }

                if (tridentDocument != null)
                {
                    tridentView      = null;
                    tridentDocument  = null;
                    tridentCmdTarget = null;
                    activeObject     = null;

                    if (adviseSinkCookie != 0)
                    {
                        tridentOleObject.Unadvise(adviseSinkCookie);
                        adviseSinkCookie = 0;
                    }

                    tridentOleObject.Close(Interop.OLECLOSE_NOSAVE);
                    tridentOleObject.SetClientSite(null);
                    tridentOleObject = null;
                }
            }
            catch (Exception e) {
                Debug.Fail(e.ToString());
            }
        }
예제 #2
0
        /// <summary>
        /// </summary>
        public void CreateMSHTML()
        {
            Debug.Assert(tridentDocument == null, "Must call CloseMSHTML before recreating.");

            bool created = false;

            try {
                // create the trident instance
                tridentDocument  = (Interop.IHTMLDocument2) new Interop.HTMLDocument();
                tridentOleObject = (Interop.IOleObject)tridentDocument;

                // hand it our Interop.IOleClientSite implementation
                tridentOleObject.SetClientSite((Interop.IOleClientSite) this);

                created = true;

                propNotifyCookie = new Interop.ConnectionPointCookie(tridentDocument, this, typeof(Interop.IPropertyNotifySink), false);

                tridentOleObject.Advise((Interop.IAdviseSink) this, out adviseSinkCookie);
                Debug.Assert(adviseSinkCookie != 0);

                tridentCmdTarget = (Interop.IOleCommandTarget)tridentDocument;
            }
            finally {
                if (created == false)
                {
                    tridentDocument  = null;
                    tridentOleObject = null;
                    tridentCmdTarget = null;
                }
            }
        }
예제 #3
0
        //REVIEW: Add a load method for stream and url

        /// <summary>
        /// Loads HTML content from a string into this control identified by the specified URL.
        /// If MSHTML has not yet been created, the loading is postponed until MSHTML has been created.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="url"></param>
        public void LoadHtml(string content, string url, string style)
        {
            if (content == null)
            {
                content = "";
            }

            if (!_isCreated)
            {
                _desiredContent = content;
                _desiredUrl     = url;
                _loadDesired    = true;
                return;
            }

            if (_fullDocumentMode == false)
            {
                content = CreateHtmlContent(content, style);
            }

            OnBeforeLoad();

            Interop.IStream stream = null;

            //First we create a COM stream
            IntPtr hglobal = Marshal.StringToHGlobalUni(content);

            Interop.CreateStreamOnHGlobal(hglobal, true, out stream);

            // Initialize a new document if there is nothing to load
            if (stream == null)
            {
                Interop.IPersistStreamInit psi = (Interop.IPersistStreamInit)_site.MSHTMLDocument;
                Debug.Assert(psi != null, "Expected IPersistStreamInit");
                psi.InitNew();
                psi = null;
            }
            else
            {
                Interop.IHTMLDocument2 document = _site.MSHTMLDocument;
                //If there is no specified URL load the document from the stream
                if (url == null)
                {
                    Interop.IPersistStreamInit psi = (Interop.IPersistStreamInit)document;
                    Debug.Assert(psi != null, "Expected IPersistStreamInit");
                    psi.Load(stream);
                    psi = null;
                }
                else
                {
                    //Otherwise we create a moniker and load the stream to that moniker
                }
            }
            _url = url;

            OnAfterLoad();
        }
예제 #4
0
 private Interop.IHTMLEventObj GetEventObject()
 {
     if (_element == null)
     {
         return(null);
     }
     _document = (Interop.IHTMLDocument2) this._element.GetDocument();
     Interop.IHTMLWindow2 window1 = _document.GetParentWindow();
     return(window1.@event);
 }
예제 #5
0
 protected HtmlEvents(IElement _element)
 {
     this._element = _element;
     Interop.IHTMLDocument2 _document = _element.HtmlEditor.GetActiveDocument(false);
     if (_document == null)
     {
         return;
     }
     window = _document.GetParentWindow();
 }
예제 #6
0
 internal HtmlWindow(Interop.IHTMLWindow2 window, IHtmlEditor editor)
 {
     this.editor = editor;
     try
     {
         this.window = window.parent;
         doc         = window.document;
     }
     catch
     {
     }
 }
예제 #7
0
 private Interop.IHTMLEventObj GetEventObject()
 {
     _document = (Interop.IHTMLDocument2) this._element.GetDocument();
     try
     {
         Interop.IHTMLWindow2 window1 = _document.GetParentWindow();
         return(window1.@event);
     }
     catch
     {
         return(null);
     }
 }
예제 #8
0
        /// <summary>
        /// </summary>
        public void CreateMSHTML()
        {
            bool created = false;

            try
            {
                // create our base instance
                this.htmlbaseDocument = (Interop.IHTMLDocument2) new Interop.HTMLDocument();

                this.activeObject = (Interop.IOleInPlaceActiveObject)htmlbaseDocument;
                this.windowHandle = new IntPtr();
                this.activeObject.GetWindow(out this.windowHandle);

                oleDocumentObject = (Interop.IOleObject)htmlbaseDocument;
                if (oleDocumentObject == null)
                {
                    throw new ApplicationException("InteropOleObject not created. No document available.");
                }
                // hand it our Interop.IOleClientSite implementation
                Win32.OleRun(htmlbaseDocument);
                oleDocumentObject.SetClientSite(this);
                Win32.OleLockRunning(htmlbaseDocument, true, false);
                created = true;
                // attach document and window base events
                propNotifyCookie = new ConnectionPointCookie(htmlbaseDocument, this, typeof(Interop.IPropertyNotifySink), false);
                // set document properties
                oleDocumentObject.SetHostNames("NetRix", "NetRix");
                // set ole events
                oleDocumentObject.Advise(this, out adviseSinkCookie);
                // set
                IConnectionPointContainer icpc = (IConnectionPointContainer)htmlbaseDocument;
                //find the source interface
                ////get IPropertyNotifySink interface
                //Guid g = new Guid("9BFBBC02-EFF1-101A-84ED-00AA00341D07");
                //icpc.FindConnectionPoint(ref g, out icp);
                ////pass a pointer to the host to the connection point
                //icp.Advise(this._site, out this._cookie);
            }
            catch (Exception ex)
            {
                Debug.Fail("CreateHtml failed", ex.Message);
            }
            finally
            {
                if (created == false)
                {
                    htmlbaseDocument  = null;
                    oleDocumentObject = null;
                }
            }
        }
예제 #9
0
 internal FrameWindow(Interop.IHTMLWindow2 window, MSHTMLSite relatedSite, HtmlEditor htmlEditor)
 {
     this._relatedSite          = relatedSite;
     this.window                = window;
     this.doc                   = (Interop.IHTMLDocument2)window.document;
     this.url                   = ((Interop.IHTMLLocation)((Interop.IHTMLWindow2)doc.GetParentWindow()).location).href;
     this.body                  = (Interop.IHTMLElement3)doc.GetBody();
     this.framebase             = ((Interop.IHTMLWindow4)window).frameElement;
     this.htmlFormatter         = new HtmlFormatter();
     this.CommandTarget         = (Interop.IOleCommandTarget)doc;
     this.winEvents             = new FrameEvents(window, htmlEditor);
     this.winEvents.Activate   += new EventHandler(winEvents_Activate);
     this.winEvents.DeActivate += new EventHandler(winEvents_DeActivate);
     this.nativeElement         = (FrameElement)htmlEditor.GenericElementFactory.CreateElement(framebase as Interop.IHTMLElement);
 }
예제 #10
0
 public void CloseMSHTML()
 {
     this.hostControl.Resize -= new EventHandler(this.OnParentResize);
     try
     {
         if (this.propNotifyCookie != null)
         {
             this.propNotifyCookie.Disconnect();
             this.propNotifyCookie = null;
         }
         if (this.tridentDocument != null)
         {
             this.tridentView = null;
             this.tridentDocument = null;
             this.tridentCmdTarget = null;
             this.activeObject = null;
             if (this.adviseSinkCookie != 0)
             {
                 this.tridentOleObject.Unadvise(this.adviseSinkCookie);
                 this.adviseSinkCookie = 0;
             }
             this.tridentOleObject.Close(1);
             this.tridentOleObject.SetClientSite(null);
             this.tridentOleObject = null;
         }
     }
     catch (Exception)
     {
     }
 }
        /// <summary>
        /// Synchronizes the selection state held in this object with the selection state in MSHTML
        /// </summary>
        /// <returns>true if the selection has changed</returns>
        public bool SynchronizeSelection()
        {
            //Get the selection object from the MSHTML document
            if (_document == null)
            {
                _document = _editor.MSHTMLDocument;
            }
            Interop.IHTMLSelectionObject selectionObj = _document.GetSelection();

            //Get the current selection from that selection object
            object currentSelection = null;

            try
            {
                currentSelection = selectionObj.CreateRange();
            }
            catch
            {
            }

            ArrayList         oldItems = _items;
            HtmlSelectionType oldType  = _type;
            int oldLength = _selectionLength;

            //Default to an empty selection
            _type            = HtmlSelectionType.Empty;
            _selectionLength = 0;
            if (currentSelection != null)
            {
                _mshtmlSelection = currentSelection;
                _items           = new ArrayList();
                //If it's a text selection
                if (currentSelection is Interop.IHTMLTxtRange)
                {
                    Interop.IHTMLTxtRange textRange = (Interop.IHTMLTxtRange)currentSelection;
                    //IntPtr ptr = Marshal.GetIUnknownForObject(textRange);
                    Interop.IHTMLElement parentElement = textRange.ParentElement();
                    // If the document is in full document mode or we're selecting a non-body tag, allow it to select
                    // otherwise, leave the selection as empty (since we don't want the body tag to be selectable on an ASP.NET
                    // User Control
                    if (IsSelectableElement(Element.GetWrapperFor(parentElement, _editor)))
                    {
                        //Add the parent of the text selection
                        if (parentElement != null)
                        {
                            _text = textRange.GetText();
                            if (_text != null)
                            {
                                _selectionLength = _text.Length;
                            }
                            else
                            {
                                _selectionLength = 0;
                            }
                            _type = HtmlSelectionType.TextSelection;
                            _items.Add(parentElement);
                        }
                    }
                }
                //If it's a control selection
                else if (currentSelection is Interop.IHtmlControlRange)
                {
                    Interop.IHtmlControlRange controlRange = (Interop.IHtmlControlRange)currentSelection;
                    int selectedCount = controlRange.GetLength();
                    //Add all elements selected
                    if (selectedCount > 0)
                    {
                        _type = HtmlSelectionType.ElementSelection;
                        for (int i = 0; i < selectedCount; i++)
                        {
                            Interop.IHTMLElement currentElement = controlRange.Item(i);
                            _items.Add(currentElement);
                        }
                        _selectionLength = selectedCount;
                    }
                }
            }
            _sameParentValid = false;

            bool selectionChanged = false;

            //Now check if there was a change of selection
            //If the two selections have different lengths, then the selection has changed
            if (_type != oldType)
            {
                selectionChanged = true;
            }
            else if (_selectionLength != oldLength)
            {
                selectionChanged = true;
            }
            else
            {
                if (_items != null)
                {
                    //If the two selections have a different element, then the selection has changed
                    for (int i = 0; i < _items.Count; i++)
                    {
                        if (_items[i] != oldItems[i])
                        {
                            selectionChanged = true;
                            break;
                        }
                    }
                }
            }
            if (selectionChanged)
            {
                //Set _elements to null so no one can retrieve a dirty copy of the selection element wrappers
                _elements = null;

                OnSelectionChanged();
                return(true);
            }

            return(false);
        }
예제 #12
0
 public void CreateMSHTML()
 {
     bool flag = false;
     try
     {
         this.tridentDocument = (Interop.IHTMLDocument2) new Interop.HTMLDocument();
         this.tridentOleObject = (Interop.IOleObject) this.tridentDocument;
         this.tridentOleObject.SetClientSite(this);
         flag = true;
         this.propNotifyCookie = new Interop.ConnectionPointCookie(this.tridentDocument, this, typeof(Interop.IPropertyNotifySink), false);
         this.tridentOleObject.Advise(this, out this.adviseSinkCookie);
         this.tridentCmdTarget = (Interop.IOleCommandTarget) this.tridentDocument;
     }
     finally
     {
         if (!flag)
         {
             this.tridentDocument = null;
             this.tridentOleObject = null;
             this.tridentCmdTarget = null;
         }
     }
 }
예제 #13
0
 /// <summary>
 /// </summary>
 public void Dispose()
 {
     try
     {
         int RefCount;
         if (propNotifyCookie != null)
         {
             propNotifyCookie.Dispose();
             propNotifyCookie = null;
         }
         if (winEvents != null)
         {
             winEvents.Dispose();
             winEvents = null;
         }
         try
         {
             Marshal.ReleaseComObject(window);
         }
         catch
         {
         }
         try
         {
             if (interopDocumentView != null)
             {
                 try
                 {
                     interopDocumentView.Show(0);
                 }
                 catch
                 {
                 }
                 try
                 {
                     interopDocumentView.UIActivate(0);
                 }
                 catch
                 {
                 }
                 try
                 {
                     interopDocumentView.SetInPlaceSite(null);
                 }
                 catch
                 {
                 }
                 long nullParam = 0L;
                 try
                 {
                     interopDocumentView.Close(nullParam);
                     do
                     {
                         RefCount = Marshal.ReleaseComObject(interopDocumentView);
                     } while (RefCount >= 0);
                 }
                 catch
                 {
                 }
                 finally
                 {
                     Marshal.FinalReleaseComObject(interopDocumentView);
                     interopDocumentView = null;
                 }
             }
         }
         catch
         {
         }
         if (oleDocumentObject != null)
         {
             try
             {
                 if (htmlEditor.Site == null || !htmlEditor.Site.DesignMode)
                 {
                     Marshal.FinalReleaseComObject(oleDocumentObject);
                     oleDocumentObject = null;
                 }
             }
             catch
             {
             }
         }
         if (htmlbaseDocument != null)
         {
             do
             {
                 RefCount = Marshal.ReleaseComObject(htmlbaseDocument);
             } while (RefCount >= 0);
             Marshal.FinalReleaseComObject(htmlbaseDocument);
             htmlbaseDocument = null;
         }
         if (interopDocumentView != null)
         {
             do
             {
                 RefCount = Marshal.ReleaseComObject(interopDocumentView);
             } while (RefCount >= 0);
         }
         if (activeObject != null)
         {
             do
             {
                 RefCount = Marshal.ReleaseComObject(activeObject);
             } while (RefCount >= 0);
             Marshal.FinalReleaseComObject(activeObject);
             activeObject = null;
         }
         interopDocumentView = null;
         htmlbaseDocument    = null;
         activeObject        = null;
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
예제 #14
0
        public Interop.IHTMLRenderStyle GetRenderStyle(Interop.IHTMLDocument2 ActiveDocument)
        {
            Interop.IHTMLRenderStyle renderStyle = ((Interop.IHTMLDocument4)ActiveDocument).createRenderStyle(null);
            renderStyle.defaultTextSelection = IsDefault ? "true" : "false";
            renderStyle.renderingPriority    = (int)this.priority;
            switch (lineType)
            {
            default:
            case LineType.None:
                renderStyle.textDecoration      = "none";
                renderStyle.textBackgroundColor = textBackgroundColor.ColorName;
                if (textColor.Type == ColorType.Auto || textColor.Type == ColorType.Inherit)
                {
                    renderStyle.textColor = ((Interop.IHTMLCurrentStyle)((Interop.IHTMLElement2)ActiveDocument.GetBody()).GetCurrentStyle()).getAttribute("color", 1);
                }
                else
                {
                    renderStyle.textColor = textColor.ColorName;
                }
                break;

            case LineType.Overline:
                renderStyle.textDecoration      = "overline";
                renderStyle.textDecorationColor = lineColor.ColorName;
                renderStyle.textBackgroundColor = textBackgroundColor.ColorName;
                if (textColor.Type == ColorType.Auto || textColor.Type == ColorType.Inherit)
                {
                    renderStyle.textColor = ((Interop.IHTMLCurrentStyle)((Interop.IHTMLElement2)ActiveDocument.GetBody()).GetCurrentStyle()).getAttribute("color", 1);
                }
                else
                {
                    renderStyle.textColor = textColor.ColorName;
                }
                break;

            case LineType.Underline:
                renderStyle.textDecoration      = "underline";
                renderStyle.textDecorationColor = lineColor.ColorName;
                renderStyle.textBackgroundColor = textBackgroundColor.ColorName;
                if (textColor.Type == ColorType.Auto || textColor.Type == ColorType.Inherit)
                {
                    renderStyle.textColor = ((Interop.IHTMLCurrentStyle)((Interop.IHTMLElement2)ActiveDocument.GetBody()).GetCurrentStyle()).getAttribute("color", 1);
                }
                else
                {
                    renderStyle.textColor = textColor.ColorName;
                }
                break;

            case LineType.LineThrough:
                renderStyle.textDecoration      = "line-through";
                renderStyle.textDecorationColor = lineColor.ColorName;
                renderStyle.textBackgroundColor = textBackgroundColor.ColorName;
                if (textColor.Type == ColorType.Auto || textColor.Type == ColorType.Inherit)
                {
                    renderStyle.textColor = ((Interop.IHTMLCurrentStyle)((Interop.IHTMLElement2)ActiveDocument.GetBody()).GetCurrentStyle()).getAttribute("color", 1);
                }
                else
                {
                    renderStyle.textColor = textColor.ColorName;
                }
                break;
            }
            string u;

            switch (underlineStyle)
            {
            case UnderlineStyle.Single:
                u = "single";
                break;

            case UnderlineStyle.Double:
                u = "double";
                break;

            case UnderlineStyle.Words:
                u = "words";
                break;

            case UnderlineStyle.Dotted:
                u = "dotted";
                break;

            case UnderlineStyle.Thick:
                u = "thick";
                break;

            case UnderlineStyle.Dash:
                u = "dash";
                break;

            case UnderlineStyle.DotDash:
                u = "dot-dash";
                break;

            case UnderlineStyle.DotDotDash:
                u = "dot-dot-dash";
                break;

            case UnderlineStyle.Wave:
                u = "wave";
                break;

            case UnderlineStyle.SingleAccounting:
                u = "single-accounting";
                break;

            case UnderlineStyle.DoubleAccounting:
                u = "double-accounting";
                break;

            case UnderlineStyle.ThickDash:
                u = "thick-dash";
                break;

            default:
            case UnderlineStyle.Undefined:
                u = "undefined";
                break;
            }
            renderStyle.textUnderlineStyle = u;
            string l;

            switch (lineThroughStyle)
            {
            default:
            case LineThroughStyle.Undefined:
                l = "undefined";
                break;

            case LineThroughStyle.Single:
                l = "single";
                break;

            case LineThroughStyle.Double:
                l = "double";
                break;
            }
            renderStyle.textLineThroughStyle = l;
            return(renderStyle);
        }
예제 #15
0
        /// <summary>
        /// Saves the HTML contained in control to a string and return it.
        /// </summary>
        /// <returns>string - The HTML in the control</returns>
        public string SaveHtml()
        {
            if (!IsCreated)
            {
                throw new Exception("HtmlControl.SaveHtml : No HTML to save!");
            }

            string content = String.Empty;

            try
            {
                OnBeforeSave();

                Interop.IHTMLDocument2 document = _site.MSHTMLDocument;

                if (_fullDocumentMode)
                {
                    // First save the document to a stream
                    Interop.IPersistStreamInit psi = (Interop.IPersistStreamInit)document;
                    Debug.Assert(psi != null, "Expected IPersistStreamInit");

                    Interop.IStream stream = null;
                    Interop.CreateStreamOnHGlobal(Interop.NullIntPtr, true, out stream);

                    psi.Save(stream, 1);

                    // Now copy the stream to the string
                    STATSTG stat = new STATSTG();
                    stream.Stat(stat, 1);
                    int    length = (int)stat.cbSize;
                    byte[] bytes  = new byte[length];

                    IntPtr hglobal;
                    Interop.GetHGlobalFromStream(stream, out hglobal);
                    Debug.Assert(hglobal != Interop.NullIntPtr, "Failed in GetHGlobalFromStream");

                    // First copy the stream to a byte array
                    IntPtr pointer = Interop.GlobalLock(hglobal);
                    if (pointer != Interop.NullIntPtr)
                    {
                        Marshal.Copy(pointer, bytes, 0, length);

                        Interop.GlobalUnlock(hglobal);

                        // Then create the string from the byte array (use a StreamReader to eat the preamble in the UTF8 encoding case)
                        StreamReader streamReader = null;
                        try
                        {
                            streamReader = new StreamReader(new MemoryStream(bytes), Encoding.Default);
                            content      = streamReader.ReadToEnd();
                        }
                        finally
                        {
                            if (streamReader != null)
                            {
                                streamReader.Close();
                            }
                        }
                    }
                }
                else
                {
                    // Save only the contents of the <body> tag
                    Interop.IHTMLElement bodyElement = document.GetBody();
                    Debug.Assert(bodyElement != null, "Could not get BODY element from document");

                    if (bodyElement != null)
                    {
                        content = SavePartialHtml(Element.GetWrapperFor(bodyElement, this));
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Fail("HtmlControl.SaveHtml" + e.ToString());
                content = String.Empty;
            }
            finally
            {
                OnAfterSave();
            }

            if (content == null)
            {
                content = String.Empty;
            }
            HtmlFormatter formatter = new HtmlFormatter();
            StringWriter  writer    = new StringWriter();

            formatter.Format(content, writer, new HtmlFormatterOptions(' ', 4, 80, true));

            return(writer.ToString());
        }
예제 #16
0
 public void OwningDoc(out Interop.IHTMLDocument2 ppDoc)
 {
     throw new Exception("The method or operation is not implemented.");
 }
예제 #17
0
        /// <summary>
        /// Creates the viewlink document.
        /// </summary>
        private void CreateControlView()
        {
            Interop.IHTMLDocument2 originDocument = (Interop.IHTMLDocument2)Element.GetDocument();
            Interop.IHTMLElement   htmlElement    = originDocument.CreateElement("HTML");
            Interop.IHTMLElement   headElement    = originDocument.CreateElement("HEAD");
            Interop.IHTMLElement   bodyElement    = originDocument.CreateElement("BODY");
            ((Interop.IHTMLElement2)htmlElement).InsertAdjacentElement("beforeBegin", headElement);
            ((Interop.IHTMLElement2)htmlElement).InsertAdjacentElement("afterBegin", bodyElement);
            _viewElement = bodyElement;
            _viewElement.SetAttribute("tabIndex", 1000, 0);
            baseDocument = (Interop.IHTMLDocument)_viewElement.GetDocument();
            try
            {
                elementDefaults = ((Interop.IElementBehaviorSiteOM2)_behaviorSite).GetDefaults();
            }
            catch
            {
                throw new ApplicationException("Wrong usage - acces to not properly attached master element");
            }
            XmlElementDesigner elementDesigner = Designer as XmlElementDesigner;

            if (_control == null || elementDesigner == null)
            {
                _viewElement.SetInnerHTML(String.Format(@"<div style=""border:dotted 1px red;background:Silver;width:220px;height:40px""><b>Error</b>:&nbsp;Element does not have a Designer attached (Element {0}:{1})</div>",
                                                        ((Interop.IHTMLElement2)_element).GetScopeName(),
                                                        _element.GetTagName()));
                ((Interop.IHTMLDocument2)baseDocument).SetDesignMode("Off");
                elementDefaults.SetViewLink(baseDocument);
                return;
            }
            else
            {
                _viewElement.SetInnerHTML(elementDesigner.GetDesignTimeHtml());
                elementDefaults.SetViewLink(baseDocument);
            }
            //done, set reference
            _control.ViewElementDefaults = elementDefaults;
            // end commands do basic document
            if (elementDesigner.DisableEditFocus)
            {
                //System.Threading.ThreadPool.QueueUserWorkItem(ExecuteCommand, (int)Interop.IDM.DISABLE_EDITFOCUS_UI);
            }

            // get viewlink specific properties from control element
            elementDefaults.SetFrozen(elementDesigner.FrozenEvents);    // true = event handler returns only master; false = event returns designtime html
            ((Interop.IHTMLElement3)_viewElement).contentEditable = InheritedDesignModeEnabled(_control.ContentEditable) ? "true" : "false";
            elementDefaults.SetViewMasterTab(elementDesigner.ViewMasterTab);
            elementDefaults.SetTabStop(elementDesigner.TabStop);
            elementDefaults.SetCanHaveHTML(elementDesigner.CanHaveHtml);
            elementDefaults.SetIsMultiLine(true);

            Interop.IHTMLStyle style        = ((Interop.IHTMLElement2)_viewElement).GetRuntimeStyle();
            ElementStyle       runtimeStyle = new ElementStyle(style);

            elementDesigner.SetRuntimeStyle(runtimeStyle);
            // assure that we don't see any unexpected scrollbars during resize operations
            ((Interop.IHTMLElement2)_element).GetRuntimeStyle().SetOverflow("hidden");
            object w = ((Interop.IHTMLElement)_element).GetStyle().GetWidth();

            elementDesigner.OnSetComponentDefaults();
            try
            {
                Interop.IHTMLDocument2 baseDocument2 = (Interop.IHTMLDocument2)baseDocument;
                int numSheets = 0;
                Interop.IHTMLStyleSheetsCollection baseDocumentStylesheets = originDocument.GetStyleSheets();
                if (baseDocumentStylesheets != null)
                {
                    numSheets = baseDocumentStylesheets.Length;
                }
                for (int j = 0; j < numSheets; j++)
                {
                    object local = j;
                    Interop.IHTMLStyleSheet sheetItem = (Interop.IHTMLStyleSheet)baseDocumentStylesheets.Item(local);
                    if (sheetItem != null)
                    {
                        int k = 0;
                        Interop.IHTMLStyleSheetRulesCollection rules = sheetItem.GetRules();
                        if (rules != null)
                        {
                            k = rules.GetLength();
                        }
                        if (k != 0)
                        {
                            Interop.IHTMLStyleSheet newSheet = baseDocument2.CreateStyleSheet(String.Empty, 0);
                            for (int i2 = 0; i2 < k; i2++)
                            {
                                Interop.IHTMLStyleSheetRule newRule = rules.Item(i2);
                                if (newRule != null)
                                {
                                    string selector = newRule.GetSelectorText();
                                    string content  = newRule.GetStyle().cssText;
                                    newSheet.AddRule(selector, content, i2);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            // once we have the viewlink created, establish a backlink
            elementDesigner.AssociatedViewLink = this;
        }
예제 #18
0
 private static void LoopNodes(Interop.IHTMLDOMNode node, Interop.IHTMLDOMNode targetNode, Interop.IHTMLDocument2 targetDoc)
 {
     while (node != null)
     {
         if (node.nodeName == "#text")
         {
             ((Interop.IHTMLElement)targetNode).InsertAdjacentHTML("BeforeEnd", node.nodeValue.ToString());
         }
         else
         {
             string elementName;
             if (((Interop.IHTMLElement2)node).GetScopeName() == "HTML")
             {
                 elementName = ((Interop.IHTMLElement)node).GetTagName();
             }
             else
             {
                 elementName = String.Format("{0}:{1}", ((Interop.IHTMLElement2)node).GetScopeName(), ((Interop.IHTMLElement)node).GetTagName());
             }
             Interop.IHTMLElement clone = targetDoc.CreateElement(elementName);
             ((Interop.IHTMLElement3)clone).mergeAttributes(((Interop.IHTMLElement)node), 0);
             if (node.hasChildNodes())
             {
                 Interop.IHTMLDOMChildrenCollection children =
                     node.childNodes as Interop.IHTMLDOMChildrenCollection;
                 if (children != null)
                 {
                     for (int i = 0; i < children.length; i++)
                     {
                         Interop.IHTMLDOMNode child = (Interop.IHTMLDOMNode)children.item(i);
                         LoopNodes(child, (Interop.IHTMLDOMNode)clone, targetDoc);
                     }
                 }
             }
         }
         node = node.nextSibling;
     }
 }
예제 #19
0
 public bool SynchronizeSelection()
 {
     if (this._document == null)
     {
         this._document = this._editor.MSHTMLDocument;
     }
     Interop.IHTMLSelectionObject selection = this._document.GetSelection();
     object obj3 = null;
     try
     {
         obj3 = selection.CreateRange();
     }
     catch
     {
     }
     ArrayList list = this._items;
     EditorSelectionType type = this._type;
     int num = this._selectionLength;
     this._type = EditorSelectionType.Empty;
     this._selectionLength = 0;
     if (obj3 != null)
     {
         this._mshtmlSelection = obj3;
         this._items = new ArrayList();
         if (obj3 is Interop.IHTMLTxtRange)
         {
             Interop.IHTMLTxtRange range = (Interop.IHTMLTxtRange) obj3;
             Interop.IHTMLElement element = range.ParentElement();
             if (element != null)
             {
                 this._text = range.GetText();
                 if (this._text != null)
                 {
                     this._selectionLength = this._text.Length;
                 }
                 else
                 {
                     this._selectionLength = 0;
                 }
                 this._type = EditorSelectionType.TextSelection;
                 if (this.IsSelectableElement(ElementWrapperTable.GetWrapper(element, this._editor)))
                 {
                     this._items.Add(element);
                 }
             }
         }
         else if (obj3 is Interop.IHtmlControlRange)
         {
             Interop.IHtmlControlRange range2 = (Interop.IHtmlControlRange) obj3;
             int length = range2.GetLength();
             if (length > 0)
             {
                 this._type = EditorSelectionType.ElementSelection;
                 for (int i = 0; i < length; i++)
                 {
                     Interop.IHTMLElement element2 = range2.Item(i);
                     this._items.Add(element2);
                 }
                 this._selectionLength = length;
             }
         }
     }
     this._sameParentValid = false;
     bool flag = false;
     if (this._type != type)
     {
         flag = true;
     }
     else if (this._selectionLength != num)
     {
         flag = true;
     }
     else
     {
         int count = 0;
         int num5 = 0;
         if (this._items != null)
         {
             count = this._items.Count;
         }
         if (list != null)
         {
             num5 = list.Count;
         }
         if (count != num5)
         {
             flag = true;
         }
         else if (this._items != null)
         {
             for (int j = 0; j < this._items.Count; j++)
             {
                 if (this._items[j] != list[j])
                 {
                     flag = true;
                     break;
                 }
             }
         }
     }
     if (flag)
     {
         this._elements = null;
         this._tableEditor = null;
         this.OnSelectionChanged();
         return true;
     }
     return false;
 }