public static MarkupRange GetEditableRange(IHTMLElement e, MshtmlMarkupServices markupServices)
        {
            IHTMLElement3 editableElement = null;

            while (e != null)
            {
                if (((IHTMLElement3)e).isContentEditable)
                {
                    editableElement = (IHTMLElement3)e;
                    if (ElementFilters.IsBlockElement(e))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                e = e.parentElement;
            }

            if (editableElement != null)
            {
                return(markupServices.CreateMarkupRange((IHTMLElement)editableElement, false));
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Provide drop feedback
        /// </summary>
        /// <param name="screenPoint">screen-point</param>
        /// <param name="keyState">key-state</param>
        /// <param name="supportedEffects">supported effects</param>
        /// <returns>actual effect</returns>
        public override DragDropEffects ProvideDragFeedback(Point screenPoint, int keyState, DragDropEffects supportedEffects)
        {
            // update insertion point
            try
            {
                currentCaretLocation = EditorContext.MoveCaretToScreenPoint(screenPoint);

                //move the caret markup pointer to the new caret location
                currentCaretLocation.MoveMarkupPointerToCaret(caretPointer.PointerRaw);

                //determine if this location is content editable, if not provide None feedback
                //since that is not a valid drop location
                IHTMLElement3 element = (IHTMLElement3)caretPointer.CurrentScope;
                bool          visible = false;
                currentCaretLocation.IsVisible(out visible);
                if (!element.isContentEditable || !visible)
                {
                    return(DragDropEffects.None);
                }
            }
            catch (Exception ex)
            {
                if (ex is COMException)
                {
                    int errorCode = ((COMException)ex).ErrorCode;
                    if (errorCode == IE_CTL_E.INVALIDLINE || errorCode == IE_CTL_E.UNPOSITIONEDELEMENT || errorCode == IE_CTL_E.UNPOSITIONEDPOINTER)
                    {
                        return(DragDropEffects.None);
                    }
                }

                Trace.Fail("Exception thrown while providing drag feedback: " + ex);

                //bug fix 1115: eat the exception if one is thrown while placing the caret.
                //this can occur when attempting to move the caret into an HTML control (such as an image or table)
                return(DragDropEffects.None);
            }

            // provide feedback depending upon what we are processing
            switch (dragType)
            {
            case DragType.ExternalHtml:
                if (!EditorContext.CanDrop(caretPointer.CurrentScope, DataMeister))
                {
                    return(DragDropEffects.None);
                }

                // for external html provide move and copy (prefer move -- this allows
                // us to smoothly handle the moving of images around the document)
                return(ProvideMoveAsDefaultWithCopyOverride(keyState, supportedEffects));

            default:
                return(DragDropEffects.None);
            }
        }
Example #3
0
    public ElementAdapter( object element )
      : base( element )
    {

      _raw = element;

      _element = element as IHTMLElement;
      _element2 = element as IHTMLElement2;
      _element3 = element as IHTMLElement3;
      _element4 = element as IHTMLElement4;

    }
Example #4
0
        public void Click()
        {
            object         refObj   = null;
            IHTMLDocument4 document = node.document as IHTMLDocument4;
            IHTMLElement3  element  = (IHTMLElement3)node;

            IHTMLEventObj eventObject = document.CreateEventObject(ref refObj);
            object        eventRef    = eventObject;

            element.FireEvent("onMouseDown", ref eventRef);
            element.FireEvent("onMouseUp", ref eventRef);
            node.click();
            parent.WaitForLoadToComplete();
        }
Example #5
0
        /// <summary>
        /// Pushes the values from the specified line in the item array to the selected line in
        /// the browser
        /// </summary>
        public static void PushToSelectedLine(int rowIndex, string[] items, IHTMLDocument3 doc3, DataGridView dgvText)
        {
            // Iterate over all of the INPUT elements to find those wanting the project hours
            IHTMLElementCollection allInputs = doc3.getElementsByTagName("input");

            for (int i = 0; i < allInputs.length; i++)
            {
                // We're looking for an INPUT whose id contains "reg_value" and not "IsDirty"
                // this is enough to get the INPUTS for the hours
                IHTMLElement e   = allInputs.item(i);
                int          pos = e.id.IndexOf("reg_value");
                if (pos > -1 && !e.id.Contains("IsDirty"))
                {
                    // Get the single digit index of this current INPUT - this matches to our column index
                    string id = e.id.Substring(pos + 9);
                    if (char.IsDigit(id[0]))
                    {
                        int   index          = int.Parse(id.Substring(0, 1)) + 1;
                        Color originalColour = dgvText.Rows[rowIndex].Cells[index].Style.BackColor;
                        dgvText.Rows[rowIndex].Cells[index].Style.BackColor = Color.Gold;
                        e.click();
                        System.Threading.Thread.Sleep(100);

                        var stringToInsert = items[index];
                        try
                        {
                            // Try to use agresso culture setting
                            decimal value = decimal.Parse(items[index], System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                            stringToInsert = value.ToString(AgressoCulture.NumberFormat);
                        }
                        catch (Exception)
                        {
                            // Revert to old behaviour
                        }

                        e.innerText = stringToInsert;
                        IHTMLElement3 e3 = e as IHTMLElement3;
                        if (e3 != null)
                        {
                            e3.FireEvent("onchange");
                            Marshal.ReleaseComObject(e3);
                        }
                        dgvText.Rows[rowIndex].Cells[index].Style.BackColor = originalColour;
                    }
                }
                Marshal.ReleaseComObject(e);
            }
            Marshal.ReleaseComObject(allInputs);
        }
Example #6
0
        private IHTMLElement CreateNodeForCentering()
        {
            // Create markup services using the element's document that we are analyzing
            MshtmlMarkupServices MarkupServices = new MshtmlMarkupServices(_element.document as IMarkupServicesRaw);
            MarkupPointer        end            = MarkupServices.CreateMarkupPointer();
            MarkupPointer        start          = MarkupServices.CreateMarkupPointer();

            // Find the element that we will want to wrap.
            IHTMLElement elementToEncapsulate = _element;

            // If the elements parent is an A, we will also want to
            // wrap the A and not just the image inside
            if (_element.parentElement.tagName == "A")
            {
                elementToEncapsulate = _element.parentElement;
            }

            // Move the starting pointer to before the begining of the element we want to wrap
            start.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin);

            // Find this elements parent
            IHTMLElement3 currentBlockScope = start.CurrentBlockScope() as IHTMLElement3;

            // If its parent is also the div that is around the post
            // we need to actually create a new div and just put it around the element

            // If it is splittable block, split it
            // e.g "<DIV>Blah<IMG/>Blah</DIV>" => "<DIV>Blah</DIV><DIV><IMG/></DIV><DIV>Blah</DIV>"
            if (!IsBodyElement(currentBlockScope))
            {
                // We are in a block that can be split so split it at the begining and end
                MarkupHelpers.SplitBlockForInsertionOrBreakout(MarkupServices, null, start);
                end.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);
                MarkupHelpers.SplitBlockForInsertionOrBreakout(MarkupServices, null, end);

                // Position start back to the beginning of our element
                start.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin);
            }

            // Now we can wrap it in an P tag (centering node)
            end.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);
            IHTMLElement centeringElement = MarkupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_P, string.Empty);

            MarkupServices.InsertElement(centeringElement, start, end);
            return(centeringElement);
        }
Example #7
0
        static void DispatchChangeEventTry2(
            WebControl awc,
            int iIndex,
            string sControl,
            IHTMLSelectElement ihie,
            IHTMLOptionElement ihoe,
            IHTMLDocument2 oDoc2)
        {
            object dummy = null;
            IHTMLDocument4 oDoc4 = (IHTMLDocument4) oDoc2;
            object eventObj = oDoc4.CreateEventObject(ref dummy);
            IHTMLEventObj2 obj2 = (IHTMLEventObj2) eventObj;

            IHTMLElement3 ihe3 = (IHTMLElement3) ihie;
            awc.ResetNav();
            awc.ReportNavState("Before FireEvent");
//            ihe3.FireEvent("onchange", ref eventObj);

            HtmlElement head = awc.AxWeb.Document.GetElementsByTagName("head")[0];
            HtmlElement scriptEl = awc.AxWeb.Document.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement) scriptEl.DomElement;

            // element.text = $"function changeSelect() {{ $'({sControl}').trigger('change'); }}";
            element.text = "function triggerOnChange() "
                           + "{{ "
                           +
//                           "alert('im here'); " +
                           $"var ctl = document.getElementById('{sControl}'); "
                           +
//                           "alert(ctl); "+
                           "var evt = document.createEvent('HTMLEvents'); "
                           + "evt.initEvent('change', false, true); "
                           + "ctl.dispatchEvent(evt);"
                           + "}} ";
            // element.text = $"function triggerOnChange() {{ alert('{sControl}');}}";
            head.AppendChild(scriptEl);

            // ArbWeb.AwMainForm.DebugModelessWait();
            awc.AxWeb.Document.InvokeScript("triggerOnChange");
            // ArbWeb.AwMainForm.DebugModelessWait();
            awc.ReportNavState("After FireEvent");
            awc.WaitForBrowserReady();
            awc.WaitDoLog(500);
        }
Example #8
0
        private void Type(string value)
        {
            object         refObj   = null;
            IHTMLDocument4 document = node.document as IHTMLDocument4;
            IHTMLElement3  element  = (IHTMLElement3)node;

            string val = "";

            foreach (char c in value)
            {
                IHTMLEventObj eventObject = document.CreateEventObject(ref refObj);
                eventObject.keyCode = c;
                object eventRef = eventObject;
                val += c;
                element.FireEvent("onKeyDown", ref eventRef);
                element.FireEvent("onKeyPress", ref eventRef);
                node.setAttribute("value", val, 0);
                element.FireEvent("onKeyUp", ref eventRef);
            }
        }
Example #9
0
        protected override void OnElementAttached()
        {
            if (EditorContext.EditMode)
            {
                IHTMLElement3 e3 = HTMLElement as IHTMLElement3;
                if (!e3.isContentEditable)
                {
                    e3.contentEditable = "true";
                }
            }

            base.OnElementAttached();

            SetPaintColors(HTMLElement);

            EditorContext.PreHandleEvent += new HtmlEditDesignerEventHandler(EditorContext_PreHandleEvent);
            EditorContext.CommandKey     += new KeyEventHandler(EditorContext_CommandKey);
            EditorContext.KeyDown        += new HtmlEventHandler(EditorContext_KeyDown);
            EditorContext.KeyUp          += new HtmlEventHandler(EditorContext_KeyUp);

            _elementBehaviorAttached = true;
        }
        /// <summary>
        /// Gets the parent link element (if any) for the passed element
        /// </summary>
        /// <param name="element">element</param>
        /// <returns>link element (or null if this element or one of its parents are not a link)</returns>
        private IHTMLElement GetLinkElement(IHTMLElement element)
        {
            // never exhibit this behavior for an image element
            if (SuppressForImages)
            {
                if (element is IHTMLImgElement)
                {
                    return(null);
                }
            }

            // search up the parent heirarchy
            while (element != null)
            {
                // if it is an anchor that has an HREF (exclude anchors with only NAME)
                // then stop searching
                if (element is IHTMLAnchorElement)
                {
                    string href = element.getAttribute("href", 2) as string;
                    if (href != null && !(SuppressForLocalUrls && UrlHelper.IsFileUrl(href)))
                    {
                        IHTMLElement3 anchorElement3 = (IHTMLElement3)element;
                        if (!SuppressForNonEditableRegions || anchorElement3.isContentEditable)
                        {
                            return(element);
                        }
                    }
                }

                // search parent
                element = element.parentElement;
            }

            // didn't find an anchor
            return(null);
        }
        private void fireKeyEvents(IHTMLElement3 elem)
        {
            object dummy = null;
            object eventObj = _doc.CreateEventObject(ref dummy);

            ((IHTMLEventObj)eventObj).keyCode = _keyCode;

            KeyEventStatus thisKeyStatus = new KeyEventStatus();
            thisKeyStatus.keyDownFired = elem.FireEvent("onkeydown", ref eventObj);
            thisKeyStatus.keyPressFired = elem.FireEvent("onkeypress", ref eventObj);
            thisKeyStatus.keyUpFired = elem.FireEvent("onkeyup", ref eventObj);
            _keyEvents.Add(thisKeyStatus);
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Text"/> class.
 /// </summary>
 /// <param name="ae"></param>
 public Text(IHTMLElement ihe)
     : base(ihe)
 {
     this.ihie = (IHTMLInputElement)ihe;
     this.ihe3 = (IHTMLElement3)ihe;
 }
Example #13
0
 private bool IsBodyElement(IHTMLElement3 element)
 {
     return(element != null && element.contentEditable == "true" &&
            (((IHTMLElement)element).className == "postBody" || element is IHTMLBodyElement));
 }
 private bool IsBodyElement(IHTMLElement3 element)
 {
     return element != null && element.contentEditable == "true" &&
            (((IHTMLElement)element).className == "postBody" || element is IHTMLBodyElement);
 }