Esempio n. 1
0
        private void Toolbox_MouseMove(object sender, MouseEventArgs e)
        {
            if (!_draggingItem)
            {
                return;
            }

            // Get the current mouse position
            Point  mousePosition = e.GetPosition(null);
            Vector diff          = _mouseStartPosition - mousePosition;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                var listBoxItem = VisualTreeUtility.FindParent <ListBoxItem>(
                    (DependencyObject)e.OriginalSource);

                if (listBoxItem == null)
                {
                    return;
                }

                var itemViewModel = (ToolboxItemViewModel)_toolbox.ItemContainerGenerator.
                                    ItemFromContainer(listBoxItem);

                var dragData = new DataObject(ToolboxDragDrop.DataFormat, itemViewModel.Model);
                DragDrop.DoDragDrop(listBoxItem, dragData, DragDropEffects.Move);
            }
        }
        static DataGridCell GetCell(DataGrid grid, DataGridRow row, int col)
        {
            grid.ScrollIntoView(row, grid.Columns[col]);
            var presenter =
                (DataGridCellsPresenter)VisualTreeUtility.GetCoreElement(row, typeof(DataGridCellsPresenter));

            return((DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(col));
        }
Esempio n. 3
0
        private void Toolbox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var listBoxItem = VisualTreeUtility.FindParent <ListBoxItem>(
                (DependencyObject)e.OriginalSource);

            _draggingItem = listBoxItem != null;

            _mouseStartPosition = e.GetPosition(_toolbox);
        }
        static Visual GetCoreElement(MenuItem item, string typeFullName)
        {
            var element = VisualTreeUtility.GetCoreElement(item, typeFullName);

            if (element == null)
            {
                throw new NotSupportedException(ResourcesLocal3.Instance.ErrorNotFoundElement);
            }
            return(element);
        }
Esempio n. 5
0
        /// <summary>
        /// Computes the coordinates, relative to the parent <see cref="GraphControl" />, of this connector.
        /// This is used to correctly position any connections that may be connected to this connector.
        /// (Say that 10 times fast.)
        /// </summary>
        private void UpdatePosition()
        {
            var parentGraphControl = VisualTreeUtility.FindParent <GraphControl>(this);

            if (parentGraphControl == null)
            {
                return;
            }

            var centerPoint = new Point(ActualWidth / 2, ActualHeight / 2);

            Position = TransformToAncestor(parentGraphControl).Transform(centerPoint);
        }
Esempio n. 6
0
 public void Delete()
 {
     if (_pane != null)
     {
         UIThreadExecutor.Execute((Action)(() =>
         {
             ListViewItem item = (ListViewItem)_pane.ELearningLabMainPanel.listView
                                 .ItemContainerGenerator.ContainerFromIndex(0);
             Button deleteButton = VisualTreeUtility.FindByName("deleteButton", item) as Button;
             if (deleteButton != null)
             {
                 deleteButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
             }
         }));
     }
 }
Esempio n. 7
0
    private static void DoUpdateTransform(ListView view)
    {
        ScrollViewer scroller = VisualTreeUtility.FindDescendant <ScrollViewer>(view);

        if (scroller != null)
        {
            Transform        transform = GetContentTransform(view);
            FrameworkElement header    = VisualTreeUtility.FindDescendant <ScrollViewer>(scroller);
            if (header != null)
            {
                header.LayoutTransform = transform;
            }
            FrameworkElement content = scroller.Template.FindName("PART_ScrollContentPresenter", scroller) as FrameworkElement;
            if (content != null)
            {
                content.LayoutTransform = transform;
            }
        }
    }
Esempio n. 8
0
        /*
         * protected override void OnDragEnter(DragEventArgs e)
         * {
         *      e.Effects = ValidateDrag(e.OriginalSource, e) ? DragDropEffects.Copy : DragDropEffects.None;
         *      e.Handled = true;
         * }
         *
         * protected override void OnDragOver(DragEventArgs e)
         * {
         *      e.Effects = ValidateDrag(e.OriginalSource, e) ? DragDropEffects.Copy : DragDropEffects.None;
         *      e.Handled = true;
         * }
         *
         * protected override void OnDrop(DragEventArgs e)
         * {
         *      if (ValidateDrag(e.OriginalSource, e))
         *              OnDropAction(e.OriginalSource, e);
         *
         *      e.Handled = true;
         * }
         *
         * private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
         * {
         *      UpdateSelection(e, false);
         * }
         *
         * private void OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
         * {
         *      _didDrag = false;
         *
         *      if (_didSelect)
         *      {
         *              _didSelect = false;
         *              return;
         *      }
         *
         *      if (e.OriginalSource != null)
         *              UpdateSelection(e, true);
         * }
         *
         * private void OnPreviewMouseMove(object sender, MouseEventArgs e)
         * {
         *      var mousePosition = e.GetPosition(null);
         *      var diff = _mouseDownPosition - mousePosition;
         *
         *      if (!_isDragging && e.LeftButton == MouseButtonState.Pressed &&
         *              (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
         *               Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
         *      {
         *              var treeViewItem = VisualTreeUtility.FindParent<TreeViewItem>((DependencyObject)Mouse.DirectlyOver);
         *
         *              if (treeViewItem == null)
         *                      return;
         *
         *              if (_adornerEnabled)
         *              {
         *                      var adornerBitmap = new RenderTargetBitmap((int)TreeView.ActualWidth, (int)TreeView.ActualHeight, 96,
         *                              96,
         *                              PixelFormats.Pbgra32);
         *
         *                      var drawingVisual = new DrawingVisual();
         *
         *                      using (var dc = drawingVisual.RenderOpen())
         *                      {
         *                              VisualTreeUtility.Where(TreeView, visual =>
         *                              {
         *                                      var tvi = visual as TreeViewItem;
         *
         *                                      if (tvi == null) return false;
         *                                      if (!((CustomTreeItem)tvi.DataContext).IsSelected) return false;
         *
         *                                      // get the border so children don't get drawn
         *                                      var bd = (Border)VisualTreeUtility.First(tvi, x => (x as Border)?.Name == "Bd");
         *                                      var relativePos = bd.TranslatePoint(new Point(0, 0), TreeView);
         *
         *                                      var rt = new RenderTargetBitmap((int)bd.ActualWidth * 2, (int)bd.ActualHeight, 96, 96,
         *                                              PixelFormats.Pbgra32);
         *                                      rt.Render(bd);
         *
         *                                      dc.DrawImage(rt, new Rect(relativePos, new Size(bd.ActualWidth * 2, bd.ActualHeight)));
         *
         *                                      return false;
         *                              });
         *                      }
         *
         *                      adornerBitmap.Render(drawingVisual);
         *
         *                      _dragAdorner.Source = (DependencyObject)e.OriginalSource;
         *                      _dragAdorner.Image = adornerBitmap;
         *                      _dragAdorner.IsDragging = true;
         *                      _dragAdorner.Offset = e.GetPosition(TreeView);
         *
         *                      _adornerTimer.Start();
         *              }
         *
         *              var dragData = GetDragDataFunc();
         *              DragDrop.DoDragDrop(treeViewItem, dragData, DragDropEffects.Copy | DragDropEffects.None);
         *
         *              Debug.WriteLine("didDrag set to true");
         *              _didDrag = true;
         *      }
         * }
         */

        /// <summary>
        /// Updates the selection.
        /// </summary>
        /// <param name="e">Mouse button event argument.</param>
        /// <param name="allowSelectionClick">
        /// If the clicked item is already selected, this argument determines if other items
        /// should be deselected.
        /// </param>
        private bool UpdateSelection(MouseButtonEventArgs e, bool allowSelectionClick)
        {
            var treeItemVisual    = VisualTreeUtility.FindParent <TreeViewItem>((DependencyObject)e.OriginalSource);
            var treeItemViewModel = (CustomTreeItem)treeItemVisual?.DataContext;

            var clickPoint  = e.GetPosition(TreeView);
            var controlDown = Keyboard.IsKeyDown(System.Windows.Input.Key.LeftCtrl);
            var shiftDown   = Keyboard.IsKeyDown(System.Windows.Input.Key.LeftShift);

            /*
             * if (_didDrag)
             * {
             *      Debug.WriteLine("DRAG CANCEL: _didDrag == true");
             *      _didDrag = false;
             *      return;
             * }*/

            if (!(treeItemVisual == null && shiftDown) && (treeItemVisual == null || shiftDown))
            {
                Game.Selection.ClearSelection();
            }

            if (treeItemVisual == null)
            {
                Debug.WriteLine("DRAG CANCEL: treeeItemVisual == null");
                return(false);
            }

            if (e.ClickCount == 2 && e.ButtonState == MouseButtonState.Pressed)
            {
                var codeContainer = treeItemViewModel.Instance as LuaSourceContainer;

                if (codeContainer != null)
                {
                    var doc = new CodeEditorViewModel(codeContainer);

                    Editor.Current.Shell.OpenDocument(doc);

                    codeContainer.Destroyed.Event += () => doc.TryClose();
                }
            }

            if (treeItemViewModel.IsSelected && !allowSelectionClick)
            {
                Debug.WriteLine("DRAG CANCEL: (treeItemViewModel.IsSelected && !allowSelectionClick) == true");
                return(false);
            }

            if (!controlDown && !shiftDown)
            {
                Game.Selection.ClearSelection();
            }

            if (shiftDown && _lastSelected != null)
            {
                var needsReversed = clickPoint.Y < _lastPoint.Y;

                VisualTreeUtility.ForEach(TreeView, visual =>
                {
                    var tvi = visual as TreeViewItem;
                    if (tvi == null)
                    {
                        return;
                    }
                    var relPoint = tvi.TranslatePoint(new Point(0, 0), TreeView);

                    var check = needsReversed
                                                ? (relPoint.Y > clickPoint.Y && relPoint.Y < _lastPoint.Y)
                                                : (relPoint.Y <clickPoint.Y && relPoint.Y> _lastPoint.Y);

                    if (check)
                    {
                        Game.Selection.Select(((CustomTreeItem)tvi.DataContext).Instance);
                    }
                });
            }

            if (shiftDown && _lastSelected != null)
            {
                Game.Selection.Select(_lastSelected.Instance);

                _didSelect = true;
            }

            if (controlDown)
            {
                if (treeItemViewModel.Instance.IsSelected)
                {
                    Game.Selection.Deselect(treeItemViewModel.Instance);
                }
                else
                {
                    Game.Selection.Select(treeItemViewModel.Instance);
                    _didSelect = true;
                }
            }
            else
            {
                Game.Selection.Select(treeItemViewModel.Instance);
                _didSelect = true;
            }

            if (!shiftDown)
            {
                _lastSelected = treeItemViewModel;
                _lastPoint    = clickPoint;
            }

            return(true);
        }
Esempio n. 9
0
        private void OnGlobalMouseHookMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (SelectionRectangle.Visibility == Visibility.Visible)
            {
                var mousePos     = new Point(e.X, e.Y) - Grid.PointToScreen(new Point(0, 0));
                var mouseDownPos = _mouseDownPosition;

                if (mousePos.X < 0)
                {
                    mousePos.X = 0;
                }
                if (mousePos.X > Grid.ActualWidth)
                {
                    mousePos.X = Grid.ActualWidth;
                }
                if (mousePos.Y < 0)
                {
                    mousePos.Y = 0;
                }
                if (mousePos.Y > Grid.ActualHeight)
                {
                    mousePos.Y = Grid.ActualHeight;
                }

                if (mouseDownPos.X < mousePos.X)
                {
                    Canvas.SetLeft(SelectionRectangle, mouseDownPos.X);
                    SelectionRectangle.Width = mousePos.X - mouseDownPos.X;
                }
                else
                {
                    Canvas.SetLeft(SelectionRectangle, mousePos.X);
                    SelectionRectangle.Width = mouseDownPos.X - mousePos.X;
                }

                if (mouseDownPos.Y < mousePos.Y)
                {
                    Canvas.SetTop(SelectionRectangle, mouseDownPos.Y);
                    SelectionRectangle.Height = mousePos.Y - mouseDownPos.Y;
                }
                else
                {
                    Canvas.SetTop(SelectionRectangle, mousePos.Y);
                    SelectionRectangle.Height = mouseDownPos.Y - mousePos.Y;
                }

                VisualTreeUtility.ForEach(TreeView, element =>
                {
                    var tvi = element as TreeViewItem;

                    if (tvi != null)
                    {
                        var bounds =
                            tvi.TransformToAncestor(Grid)
                            .TransformBounds(new Rect(0.0, 0.0, tvi.ActualWidth, tvi.ActualHeight));
                        var rect = new Rect(0.0, 0.0, Grid.ActualWidth, Grid.ActualHeight);

                        var data = (ExplorerItem)tvi.DataContext;

                        if (!_dragSelectedItems.Contains(data))
                        {
                            if (rect.Contains(bounds.TopLeft) || rect.Contains(bounds.BottomRight))
                            {
                                _dragSelectedItems.Add(data);
                            }
                            else
                            {
                                _dragSelectedItems.Remove(data);
                            }
                        }
                    }
                });
            }
        }
        private static bool ParentIsDropDownScrollViewer(DependencyObject dependencyObject)
        {
            var parent = VisualTreeUtility.FindParent <ScrollViewer>(dependencyObject);

            return(parent != null && parent.Name == "DropDownScrollViewer");
        }
 private static bool ParentIsEditableListBoxControl(DependencyObject dependencyObject)
 {
     return(VisualTreeUtility.FindParent <EditableListBoxControl>(dependencyObject) != null);
 }