예제 #1
0
        internal override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (selectPosition.HasValue && e.ChangedButton == dragButton)
            {
                if (beginSelect)
                {
                    border.Visibility = Visibility.Collapsed;
                    border.Dispose();
                    border = null;

                    beginSelect = false;
                }

                selectPosition = null;
            }
        }
예제 #2
0
        internal override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (isFirstMove)
            {
                return;
            }

            if (startPoint == GetMousePositionRelativeToContent())
            {
                bool overItem = false;
                foreach (var item in items)
                {
                    if (item.IsEditing)
                    {
                        continue;
                    }
                    Rect itemRect = GetPositionOf(item);
                    if (itemRect.Contains(startPoint))
                    {
                        overItem = true;
                        break;
                    }
                }

                if (!overItem)
                {
                    List <object> itemsToUnselect = new List <object>();
                    foreach (var item in TreeView.SelectedItems)
                    {
                        itemsToUnselect.Add(item);
                    }

                    ((SelectionMultiple)TreeView.Selection).SelectByRectangle(new List <object>(), itemsToUnselect);
                }
            }

            mouseDown = false;
            if (border != null)
            {
                border.Visibility = Visibility.Collapsed;
                border.Dispose();
                border    = null;
                e.Handled = true;
            }
        }
예제 #3
0
        internal override void OnMouseMove(MouseEventArgs e)
        {
            if (selectPosition.HasValue)
            {
                if (!beginSelect)
                {
                    // detect select
                    var dragDiff = selectPosition.Value - e.GetPosition(TreeView);
                    if ((Math.Abs(dragDiff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(dragDiff.Y) > SystemParameters.MinimumVerticalDragDistance))
                    {
                        // begin select
                        border      = new BorderSelectionAdorner(TreeView);
                        beginSelect = true;
                    }
                }

                if (beginSelect)
                {
                    HandleInput(e);
                }
            }
        }
예제 #4
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                if (isFirstMove)
                {
                    isFirstMove = false;
                    border      = new BorderSelectionAdorner(content);
                    if (!SelectionMultiple.IsControlKeyDown)
                    {
                        content.ClearSelectionByRectangle();
                    }
                }

                Point  currentPoint = Mouse.GetPosition(content);
                double width        = currentPoint.X - startPoint.X;
                double height       = currentPoint.Y - startPoint.Y;
                double left         = startPoint.X;
                double top          = startPoint.Y;
                double x            = startPoint.X < currentPoint.X ? startPoint.X : currentPoint.X;
                double y            = startPoint.Y < currentPoint.Y ? startPoint.Y : currentPoint.Y;

                // System.Diagnostics.Debug.WriteLine(string.Format("Drawing: {0};{1};{2};{3}",startPoint.X,startPoint.Y,width,height));
                if (width < 0)
                {
                    width = Math.Abs(width);
                    left  = startPoint.X - width;
                }

                if (height < 0)
                {
                    height = Math.Abs(height);
                    top    = startPoint.Y - height;
                }

                border.Width  = width;
                border.Height = height;
                border.UpdatePosition(new Point(x, y));

                double right  = left + width;
                double bottom = top + height;

                // System.Diagnostics.Debug.WriteLine(string.Format("left:{1};right:{2};top:{3};bottom:{4}", null, left, right, top, bottom));
                foreach (var item in items)
                {
                    if (!item.IsVisible)
                    {
                        continue;
                    }

                    FrameworkElement itemContent = (FrameworkElement)item.Template.FindName("headerBorder", item);
                    Point            p           = itemContent.TransformToAncestor(content).Transform(new Point());
                    double           itemLeft    = p.X;
                    double           itemRight   = p.X + itemContent.ActualWidth;
                    double           itemTop     = p.Y;
                    double           itemBottom  = p.Y + itemContent.ActualHeight;

                    // System.Diagnostics.Debug.WriteLine(string.Format("element:{0};itemleft:{1};itemright:{2};itemtop:{3};itembottom:{4}",item.DataContext,itemLeft,itemRight,itemTop,itemBottom));
                    if (!(itemLeft > right || itemRight < left || itemTop > bottom || itemBottom < top))
                    {
                        if (!content.SelectedItems.Contains(item.DataContext))
                        {
                            ((SelectionMultiple)content.Selection).SelectByRectangle(item);
                        }

                        // System.Diagnostics.Debug.WriteLine("Is selected: " + item);
                    }
                    else
                    {
                        if (!SelectionMultiple.IsControlKeyDown)
                        {
                            ((SelectionMultiple)content.Selection).UnSelectByRectangle(item);
                        }
                    }
                }

                e.Handled = true;
            }
        }
예제 #5
0
        private void HandleInput(RoutedEventArgs e)
        {
            if (mouseDown)
            {
                if (Mouse.LeftButton == MouseButtonState.Released)
                {
                    mouseDown = false;
                    if (border != null)
                    {
                        border.Visibility = Visibility.Collapsed;
                        border.Dispose();
                    }

                    return;
                }

                if (startPoint == GetMousePositionRelativeToContent())
                {
                    return;
                }

                List <object> itemsToSelect   = new List <object>();
                List <object> itemsToUnSelect = new List <object>();

                // if the mouse position or the start point is outside the window, we trim it inside
                Point currentPoint      = TrimPointToVisibleArea(GetMousePositionRelativeToContent());
                Point trimmedStartPoint = TrimPointToVisibleArea(startPoint);

                if (isFirstMove)
                {
                    isFirstMove = false;
                    border      = new BorderSelectionAdorner(TreeView);
                }

                Rect selectionRect = new Rect(currentPoint, trimmedStartPoint);
                border.UpdatePosition(selectionRect);


                if (isFirstMove)
                {
                    if (!SelectionMultiple.IsControlKeyDown)
                    {
                        foreach (var item in TreeView.SelectedItems)
                        {
                            var  treeViewItem = TreeView.GetTreeViewItemFor(item);
                            Rect itemRect     = GetPositionOf(treeViewItem);

                            if (!selectionRect.IntersectsWith(itemRect))
                            {
                                itemsToUnSelect.Add(item);
                            }
                        }
                    }
                }

                foreach (var item in items)
                {
                    if (!item.IsVisible || item.IsEditing)
                    {
                        continue;
                    }

                    Rect itemRect = GetPositionOf(item);

                    if (selectionRect.IntersectsWith(itemRect))
                    {
                        if (isFirstMove)
                        {
                            itemsToSelect.Add(item.DataContext);
                        }
                        else
                        {
                            if (!TreeView.SelectedItems.Contains(item.DataContext))
                            {
                                itemsToSelect.Add(item.DataContext);
                            }
                        }
                    }
                    else
                    {
                        if (!SelectionMultiple.IsControlKeyDown && TreeView.SelectedItems.Contains(item.DataContext))
                        {
                            itemsToUnSelect.Add(item.DataContext);
                        }
                    }
                }

                ((SelectionMultiple)TreeView.Selection).SelectByRectangle(itemsToSelect, itemsToUnSelect);
                e.Handled = true;
            }
        }
        internal override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (isFirstMove) return;

            if (startPoint == GetMousePositionRelativeToContent())
            {
                bool overItem = false;
                foreach (var item in items)
                {
                    if (item.IsEditing) continue;
                    Rect itemRect = GetPositionOf(item);
                    if (itemRect.Contains(startPoint))
                    {
                        overItem = true;
                        break;
                    }
                }

                if (!overItem)
                {
                    List<object> itemsToUnselect = new List<object>();
                    foreach (var item in TreeView.SelectedItems)
                    {
                        itemsToUnselect.Add(item);
                    }

                    ((SelectionMultiple)TreeView.Selection).SelectByRectangle(new List<object>(), itemsToUnselect);
                }
            }

            mouseDown = false;
            if (border != null)
            {
                border.Visibility = Visibility.Collapsed;
                border.Dispose();
                border = null;
                e.Handled = true;
            }
        }
        private void HandleInput(RoutedEventArgs e)
        {
            if (mouseDown)
            {
                if (Mouse.LeftButton == MouseButtonState.Released)
                {
                    mouseDown = false;
                    if (border != null)
                    {
                        border.Visibility = Visibility.Collapsed;
                        border.Dispose();
                    }

                    return;
                }

                if (startPoint == GetMousePositionRelativeToContent()) return;

                List<object> itemsToSelect = new List<object>();
                List<object> itemsToUnSelect = new List<object>();

                // if the mouse position or the start point is outside the window, we trim it inside
                Point currentPoint = TrimPointToVisibleArea(GetMousePositionRelativeToContent());
                Point trimmedStartPoint = TrimPointToVisibleArea(startPoint);

                if (isFirstMove)
                {
                    isFirstMove = false;
                    border = new BorderSelectionAdorner(TreeView);
                }

                Rect selectionRect = new Rect(currentPoint, trimmedStartPoint);
                border.UpdatePosition(selectionRect);


                if (isFirstMove)
                {
                    if (!SelectionMultiple.IsControlKeyDown)
                    {
                        foreach (var item in TreeView.SelectedItems)
                        {
                            var treeViewItem = TreeView.GetTreeViewItemFor(item);
                            Rect itemRect = GetPositionOf(treeViewItem);

                            if (!selectionRect.IntersectsWith(itemRect))
                            {
                                itemsToUnSelect.Add(item);
                            }
                        }
                    }
                }

                foreach (var item in items)
                {
                    if (!item.IsVisible || item.IsEditing)
                    {
                        continue;
                    }

                    Rect itemRect = GetPositionOf(item);

                    if (selectionRect.IntersectsWith(itemRect))
                    {
                        if (isFirstMove)
                        {
                            itemsToSelect.Add(item.DataContext);
                        }
                        else
                        {
                            if (!TreeView.SelectedItems.Contains(item.DataContext))
                            {
                                itemsToSelect.Add(item.DataContext);
                            }
                        }
                    }
                    else
                    {
                        if (!SelectionMultiple.IsControlKeyDown && TreeView.SelectedItems.Contains(item.DataContext))
                        {
                            itemsToUnSelect.Add(item.DataContext);
                        }
                    }
                }

                ((SelectionMultiple)TreeView.Selection).SelectByRectangle(itemsToSelect, itemsToUnSelect);
                e.Handled = true;
            }
        }