Exemplo n.º 1
0
        //void Interop.IHTMLElementEvents.Invoke(int dispid, ref Guid g, int lcid, int dwFlags, ref Interop.DISPPARAMS pdp, object pvarRes, ref Interop.EXCEPINFO pei, out int nArgError)
        void Interop.IHTMLGenericEvents.Invoke(int dispid, ref Guid g, int lcid, int dwFlags, Interop.DISPPARAMS pdp, object[] pvarRes, Interop.EXCEPINFO pei, int[] nArgError)
        {
            nArgError = new int[] { Interop.S_FALSE };
            if (!EventsEnabled)
            {
                return;
            }
            if (_element == null)
            {
                return;
            }
            _eventobj = this.GetEventObject();
            //System.Diagnostics.Debug.WriteLine(_eventobj.type, _eventobj.srcElement.GetTagName());
            if (_eventobj == null)
            {
                return;
            }
            if (_eventobj.srcElement != null)
            {
                // refire on document level to support global events in NetRix main
                if (docEvents.Contains(_eventobj.type))
                {
                    Interop.IHTMLDocument4 doc4   = (Interop.IHTMLDocument4)_element.GetDocument();
                    Interop.IHTMLEventObj  newObj = doc4.createEventObject(_eventobj);
                    doc4.fireEvent(String.Concat("on", _eventobj.type), newObj);
                }
            }
            _editor.SetMousePointer(false);

            if (ElementEvent != null)
            {
                ElementEvent(this, _eventobj);
            }
            # region Event Type Switch Block
Exemplo n.º 2
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;
        }