示例#1
0
 /// <summary>
 /// Handle mouse move to handle hover cursor and text selection.
 /// </summary>
 /// <param name="parent">the control hosting the html to set cursor and invalidate</param>
 /// <param name="loc">the location of the mouse on the html</param>
 public void HandleMouseMove(Control parent, Point loc)
 {
     if ((Control.MouseButtons & MouseButtons.Left) != 0)
     {
         if (_mouseDownOnSelectedWord)
         {
             StartDragDrop(parent);
         }
         else
         {
             HandleSelection(parent, loc, !_isDoubleClickSelect);
             _inSelection = _selectionStart != null && _selectionEnd != null && (_selectionStart != _selectionEnd || _selectionStartIndex != _selectionEndIndex);
         }
     }
     else
     {
         // Handle mouse hover over the html to change the cursor depending if hovering word, link of other.
         var link = DomUtils.GetLinkBox(_root, loc);
         if (link != null)
         {
             parent.Cursor = Cursors.Hand;
         }
         else
         {
             var word = DomUtils.GetCssBoxWord(_root, loc);
             parent.Cursor = word != null && !word.IsImage && !word.Selected ? Cursors.IBeam : Cursors.Default;
         }
     }
 }
示例#2
0
        /// <summary>
        /// Handle mouse down to handle selection.
        /// </summary>
        /// <param name="parent">the control hosting the html to invalidate</param>
        /// <param name="loc">the location of the mouse on the html</param>
        /// <param name="isMouseInContainer"> </param>
        public void HandleMouseDown(Control parent, Point loc, bool isMouseInContainer)
        {
            bool clear = !isMouseInContainer;

            if (isMouseInContainer)
            {
                _isDoubleClickSelect     = (DateTime.Now - _lastMouseDown).TotalMilliseconds < 400;
                _lastMouseDown           = DateTime.Now;
                _mouseDownOnSelectedWord = false;

                if (_root.HtmlContainer.IsSelectionEnabled && (Control.MouseButtons & MouseButtons.Left) != 0)
                {
                    var word = DomUtils.GetCssBoxWord(_root, loc);
                    if (word != null && word.Selected)
                    {
                        _mouseDownOnSelectedWord = true;
                    }
                    else
                    {
                        clear = true;
                    }
                }
                else if ((Control.MouseButtons & MouseButtons.Right) != 0)
                {
                    var rect = DomUtils.GetCssBoxWord(_root, loc);
                    var link = DomUtils.GetLinkBox(_root, loc);
                    if (_root.HtmlContainer.IsContextMenuEnabled)
                    {
                        _contextMenuHandler.ShowContextMenu(parent, rect, link);
                    }
                    clear = rect == null || !rect.Selected;
                }
            }

            if (clear)
            {
                ClearSelection();
                parent.Invalidate();
            }
        }