public virtual void ProcessLeftButtonDown()
        {
            if (_rightButtonDown)
                return;

            Selector = null;

            _diagram.CaptureMouse();

            _leftButtonDown = true;
            _leftButtonAction = MouseAction.None;

            ResetIsUnderCursor(_currentMousePosition.HasValue ? _currentMousePosition.Value : new Point(0, 0));
            _mouseDownOnItem = _itemUnderCursor;

            if (_diagram.Edges.Count != 0)
            {
                bool res = _diagram.Edges[0].HitTest(_currentMousePosition.Value);
            }

            if (_diagram.Selection.Contains(_itemUnderCursor) || _currentResizeDirection != ResizeDirection.None)
            {
                _leftButtonAction = MouseAction.MoveItem;
            }
            else
            {
                if (_mouseDownOnItem as DiagramNode != null || (_mouseDownOnItem as DiagramLabel != null
                    && (_mouseDownOnItem as DiagramLabel).Owner as DiagramNode != null))
                {
                    _leftButtonAction = MouseAction.CreateEdge;
                }
                else
                {
                    _leftButtonAction = MouseAction.MultiSelect;
                }
            }
            _leftButtonDownMousePosition = _currentMousePosition;
        }
        private void ExpandSelector(Point mousePosition, bool createSelector)
        {
            if (Selector == null)
            {
                if (createSelector)
                {
                    Selector = new DiagramSelector();
                    Selector.StartPoint = mousePosition;
                }
                return;
            }

            Selector.EndPoint = mousePosition;

            _diagram.InvalidateVisual();
        }
        private void UseSelector()
        {
            if (Selector == null)
                return;

            using (DiagramUpdateLock locker = new DiagramUpdateLock(_diagram))
            {
                Geometry selectorGeometry = Selector.Geometry;

                _diagram.Selection.Clear();

                foreach (var node in _diagram.Nodes)
                {
                    if (node.Geometry == null || node.NeedRecalc)
                        node.CalculateGeometry();

                    if (node.Geometry == null)
                        continue;

                    if (GeometryUtils.AreIntersectOrContain(node.Geometry, node.BorderPen,
                        selectorGeometry, GlobalData.SelectorBorderPen))
                    {
                        _diagram.Selection.Add(node);
                    }
                }

                Selector = null;
            }
        }
        public virtual void ProcessLeftButtonUp()
        {
            if (_offsetWorker != null)
            {
                _offsetWorker.CancelAsync();
                //_offsetWorker.
                //while (_offsetWorker.IsBusy) { }
                _offsetWorker = null;
            }

            if (_leftButtonDown && _leftButtonDownMousePosition != null && _currentMousePosition != null)
            {
                var isMouseMoved = MathUtils.Compare(GeometryUtils.Distance(_leftButtonDownMousePosition.Value, _currentMousePosition.Value), 0, GlobalData.PointPrecision) != 0;
                if (!isMouseMoved)
                {
                    ResetIsUnderCursor(_currentMousePosition.Value);
                    var selectionSucceded = SelectItem(_itemUnderCursor);
                    if (!selectionSucceded)
                    {
                        CreateNode(_currentMousePosition.Value);
                    }
                    else
                    {
                        RaiseLButtonClick();
                    }
                }
                else if (_leftButtonAction == MouseAction.MoveItem)
                {
                    ResizeDirection direction = _currentResizeDirection;
                    _currentResizeDirection = ResizeDirection.None;
                    SetupSelectionEdgesEndings(direction);
                }
                else if (_leftButtonAction == MouseAction.MultiSelect)
                {
                    UseSelector();
                }
                ChangeCursorKind(_currentMousePosition.Value);
            }

            _diagram.ReleaseMouseCapture();

            Selector = null;
            _leftButtonDown = false;
            _leftButtonDownMousePosition = null;
            _leftButtonAction = MouseAction.None;
        }