void DragAndDropItem_PointerMoved(object sender, PointerRoutedEventArgs e)
#endif
        {
            UIElement uielement = (UIElement)sender;

            if (_isPointerCaptured)
            {
                // Calculate the new position of the object:
#if SLMIGRATION
                double deltaH = e.GetPosition(null).X - _pointerX;
                double deltaV = e.GetPosition(null).Y - _pointerY;
#else
                double deltaH = e.GetCurrentPoint(null).Position.X - _pointerX;
                double deltaV = e.GetCurrentPoint(null).Position.Y - _pointerY;
#endif
                _objectLeft = deltaH + _objectLeft;
                _objectTop  = deltaV + _objectTop;

                // Update the object position:
                Canvas.SetLeft(uielement, _objectLeft);
                Canvas.SetTop(uielement, _objectTop);

                // Remember the pointer position:
#if SLMIGRATION
                _pointerX = e.GetPosition(null).X;
                _pointerY = e.GetPosition(null).Y;
#else
                _pointerX = e.GetCurrentPoint(null).Position.X;
                _pointerY = e.GetCurrentPoint(null).Position.Y;
#endif
            }
        }
Exemplo n.º 2
0
        private double?GetHorizontalPanelMousePosition(PointerRoutedEventArgs e)
#endif
        {
            // take into account the scrubber _horizontalThumb size
            double thumbWidth = (ThumbElement == null) ? 0 : ThumbElement.ActualWidth;
            double panelWidth = Panel.ActualWidth - thumbWidth;

            if (panelWidth > 0)
            {
                double range = Maximum - Minimum;

                // calculate the new newValue based on mouse position
#if SILVERLIGHT
                Point mousePosition = e.GetPosition(Panel);
#else
                Point mousePosition = e.GetCurrentPoint(Panel).Position;
#endif
                double x = mousePosition.X - thumbWidth / 2;
                x = Math.Min(Math.Max(0, x), panelWidth);
                double value = (x * range) / panelWidth;

                // offset from the min newValue
                value += Minimum;

                return(value);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
 private void rtb_PointerMoved(object sender, PointerRoutedEventArgs e)
 {
     lastRTBPointerMoved = e;
     if (btnHighlight.IsChecked.Value)
     {
         foreach (Rect r in m_selectionRect)
         {
             if (r.Contains(e.GetPosition(highlightCanvas)))
             {
                 if (highlightRect == null)
                 {
                     highlightRect = CreateHighlightRectangle(r);
                 }
                 else
                 {
                     highlightRect.Visibility = System.Windows.Visibility.Visible;
                     highlightRect.Width      = r.Width;
                     highlightRect.Height     = r.Height;
                     Canvas.SetLeft(highlightRect, r.Left);
                     Canvas.SetTop(highlightRect, r.Top);
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        private double?GetVerticalPanelMousePosition(PointerRoutedEventArgs e)
#endif
        {
            // take into account the scrubber _horizontalThumb size
            double thumbHeight = (ThumbElement == null) ? 0 : ThumbElement.ActualHeight;
            double panelHeight = Panel.ActualHeight - thumbHeight;

            if (panelHeight > 0)
            {
                double range = Maximum - Minimum;

                // calculate the new newValue based on mouse position
#if SILVERLIGHT
                Point mousePosition = e.GetPosition(Panel);
#else
                Point mousePosition = e.GetCurrentPoint(Panel).Position;
#endif
                double y = mousePosition.Y - thumbHeight / 2;
                y = Math.Min(Math.Max(0, y), panelHeight);
                double value = ((panelHeight - y) * range) / panelHeight;

                // offset from the min newValue
                value += Minimum;

                return(value);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        private void rtb_MouseRightButtonUp(object sender, PointerRoutedEventArgs e)
        {
            //Construct and display the context menu

            RTBContextMenu menu = new RTBContextMenu(rtb);

            menu.Show(e.GetPosition(LayoutRoot));
        }
Exemplo n.º 6
0
 public Point GetDataCoordinates(PointerRoutedEventArgs args)
 {
     if (Chart != null)
     {
         Point position = args.GetPosition(Chart.View.Viewport);
         return(Chart.View.PointToData(position));
     }
     return(new Point(double.NaN, double.NaN));
 }
        void DragAndDropItem_PointerPressed(object sender, PointerRoutedEventArgs e)
#endif
        {
            UIElement uielement = (UIElement)sender;

            _objectLeft = Canvas.GetLeft(uielement);
            _objectTop  = Canvas.GetTop(uielement);

#if SLMIGRATION
            _pointerX = e.GetPosition(null).X;
            _pointerY = e.GetPosition(null).Y;
            uielement.CaptureMouse();
#else
            _pointerX = e.GetCurrentPoint(null).Position.X;
            _pointerY = e.GetCurrentPoint(null).Position.Y;
            uielement.CapturePointer(e.Pointer);
#endif
            _isPointerCaptured = true;
        }
Exemplo n.º 8
0
        public bool AllowMouseLeftButtonDown(PointerRoutedEventArgs e)
#endif
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            bool enabled = Control.IsEnabled;

            if (enabled)
            {
                // Get the current position and time
                DateTime now = DateTime.UtcNow;
#if MIGRATION
                Point position = e.GetPosition(Control);
#else
                Point position = e.GetCurrentPoint(Control).Position;
#endif

                // Compute the deltas from the last click
                double timeDelta    = (now - LastClickTime).TotalMilliseconds;
                Point  lastPosition = LastClickPosition;
                double dx           = position.X - lastPosition.X;
                double dy           = position.Y - lastPosition.Y;
                double distance     = dx * dx + dy * dy;

                // Check if the values fall under the sequential click temporal
                // and spatial thresholds
                if (timeDelta < SequentialClickThresholdInMilliseconds &&
                    distance < SequentialClickThresholdInPixelsSquared)
                {
                    // TODO: Does each click have to be within the single time
                    // threshold on WPF?
                    ClickCount++;
                }
                else
                {
                    ClickCount = 1;
                }

                // Set the new position and time
                LastClickTime     = now;
                LastClickPosition = position;

                // Raise the event
                IsPressed = true;
            }
            else
            {
                ClickCount = 1;
            }

            return(enabled);
        }
Exemplo n.º 9
0
        void RL_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            Canvas c = ChartPhoto.getDrawObjectCanvas();

            //if (c.Children.Contains(RL)) { c.Children.Remove(RL); }
            buttonRS.Foreground = new SolidColorBrush(Colors.Blue);
            c.PointerMoved     -= new PointerEventHandler(RL_PointerMoved);
            c.PointerPressed   -= new PointerEventHandler(RL_PointerPressed);

            rl = Convert.ToInt32(e.GetPosition(c).X / c.Width * ChartPhoto.getPhoto().PixelWidth);
            ToolTipService.SetToolTip(buttonRS, rl.ToString());
        }
Exemplo n.º 10
0
        private static Windows.Foundation.Point GetPositionInArea(GraphAreaBase area, PointerRoutedEventArgs e)
#endif
        {
            if (area != null)
            {
#if WPF
                var pos = e.GetPosition(area);
#elif METRO
                var pos = e.GetCurrentPoint(area as UIElement).Position;
#endif
                return(pos);
            }
            throw new GX_InvalidDataException("DragBehavior.GetPositionInArea() - The input element must be a child of a GraphAreaBase.");
        }
Exemplo n.º 11
0
        static void UIElement_PointerEntered(object sender, PointerRoutedEventArgs e)
#endif
        {
            UIElement uielement = (UIElement)sender;

            if (uielement.INTERNAL_AssignedToolTip != null &&
                uielement.INTERNAL_AssignedToolTip.IsOpen == false)
            {
#if MIGRATION
                Point absoluteCoordinates = e.GetPosition(null);
#else
                Point absoluteCoordinates = e.GetCurrentPoint(null).Position;
#endif
                Point absoluteCoordinatesShiftedToBeBelowThePointer = new Point(absoluteCoordinates.X, absoluteCoordinates.Y + 20);
                uielement.INTERNAL_AssignedToolTip.INTERNAL_OpenAtCoordinates(absoluteCoordinatesShiftedToBeBelowThePointer);
            }
        }
Exemplo n.º 12
0
        void c_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            Canvas c = ChartPhoto.getDrawObjectCanvas();

            buttonInterActiveTest.Foreground = new SolidColorBrush(Colors.Blue);
            c.PointerMoved   -= new PointerEventHandler(c_PointerMoved);
            c.PointerPressed -= new PointerEventHandler(c_PointerPressed);
            if (!testHelper.TestChartNull())
            {
                return;
            }
            ;
            int ph = Convert.ToInt32(e.GetPosition(ChartPhoto).Y / ChartPhoto.Height * ChartPhoto.getPhoto().PixelHeight);
            int n  = (testHelper.CurrentChart as AberrationChart).getCenterBlackLineNum();

            textBlackLength.Text = (testHelper.CurrentChart as AberrationChart).getLineLength(ph, 0, n).ToString();
        }
Exemplo n.º 13
0
        void HtmlCanvas_PointerMoved(object sender, PointerRoutedEventArgs e)
#endif
        {
            // Get the cursor position relative to this HtmlCanvas
#if MIGRATION
            Point pos = e.GetPosition(this);
#else
            Point pos = e.GetCurrentPoint(this).Position;
#endif

            // Get a stack of the HtmlCanvasElement directly under the cursor and all his parents
            // (Parent1, Parent2, ..., ElementDirectlyUnderTheCursor)
            HtmlCanvasElement[] elements = GetPointedElements(this, pos.X, pos.Y).ToArray();

            HtmlCanvasPointerRoutedEventArgs e2 = new HtmlCanvasPointerRoutedEventArgs(e, this);

            // Loop backward on every element of the stack
            for (int i = 0; i < elements.Length && !e.Handled; ++i)
            {
                // Remove the last element of the stack and call its OnPointerMoved() method
                elements[i].OnPointerMoved(e2);
            }

            if (_LastPointerMove != null)
            {
                e2 = new HtmlCanvasPointerRoutedEventArgs(e, this);
                for (int i = 0; i < elements.Length && !e.Handled; ++i)
                {
                    if (Array.IndexOf(_LastPointerMove, elements[i]) == -1)
                    {
                        elements[i].OnPointerEntered(e2);
                    }
                }

                e2 = new HtmlCanvasPointerRoutedEventArgs(e, this);
                for (int i = 0; i < _LastPointerMove.Length && !e.Handled; ++i)
                {
                    if (Array.IndexOf(elements, _LastPointerMove[i]) == -1)
                    {
                        _LastPointerMove[i].OnPointerExited(e2);
                    }
                }
            }

            _LastPointerMove = elements;
        }
Exemplo n.º 14
0
 protected override void OnPointerMoved(PointerRoutedEventArgs e)
 {
     if (!isInResize)
     {
         PointerPoint pp = e.GetCurrentPoint(null);
         Point        p  = e.GetPosition(this.dataGrid);
         if (pp.Properties.IsLeftButtonPressed)
         {
             DragPopup(p);
             e.Handled = true;
         }
         mouseVerticalPosition   = pp.Position.Y;
         mouseHorizontalPosition = pp.Position.X;
     }
     this.CapturePointer(e.Pointer);
     base.OnPointerMoved(e);
 }
Exemplo n.º 15
0
        void RL_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (RL == null)
            {
                RL                 = new Line();
                RL.Stroke          = new SolidColorBrush(Colors.Green);
                RL.StrokeThickness = 2;
            }
            Canvas c = ChartPhoto.getDrawObjectCanvas();

            if (!c.Children.Contains(RL))
            {
                c.Children.Add(RL);
                RL.Stroke          = new SolidColorBrush(Colors.Green);
                RL.StrokeThickness = 2;
            }

            RL.Y1 = 0;
            RL.Y2 = c.Height;
            RL.X1 = RL.X2 = e.GetPosition(c).X;
        }
Exemplo n.º 16
0
        private bool IsPointerOverThisControl(PointerRoutedEventArgs e)
#endif
        {
            Size actualSize   = this.INTERNAL_GetActualWidthAndHeight();
            var  actualWidth  = actualSize.Width;
            var  actualHeight = actualSize.Height;

            if (!double.IsNaN(actualWidth) && !double.IsNaN(actualHeight))
            {
#if MIGRATION
                var position = e.GetPosition(this);
#else
                var position = e.GetCurrentPoint(this).Position;
#endif
                return(position.X > 0 && position.Y > 0 && position.X < actualWidth && position.Y < actualHeight);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 17
0
        void ChartPanel_MouseMove(object sender, PointerRoutedEventArgs e)
        {
            int  num  = Children.Count;
            bool flag = false;

            for (int i = 0; i < num; i++)
            {
                ChartPanelObject obj2 = Children[i];
                if (obj2.Action == ChartPanelAction.MouseMove)
                {
                    Point position = e.GetPosition(Chart.View.Viewport);
                    if (obj2.Attach != ChartPanelAttach.None)
                    {
                        int           num3;
                        int           num4;
                        MeasureOption x = MeasureOption.X;
                        if (obj2.Attach == ChartPanelAttach.DataY)
                        {
                            x = MeasureOption.Y;
                        }
                        else if (obj2.Attach == ChartPanelAttach.DataXY)
                        {
                            x = MeasureOption.XY;
                        }
                        DataDistanceFromPoint(position, x, out num3, out num4);
                        if ((num3 >= 0) && (num4 >= 0))
                        {
                            position = Chart.View.DataIndexToPoint(num3, num4);
                        }
                    }
                    position = Chart.View.PointToData(obj2.AxisX, obj2.AxisY, position);
                    obj2.SetPoint(position);
                    flag = true;
                }
            }
            if (flag)
            {
                base.InvalidateArrange();
            }
        }
        private static void OnDragging(object sender, PointerRoutedEventArgs e)
#endif
        {
            var obj = sender as DependencyObject;

            if (!GetIsDragging(obj))
            {
                return;
            }

#if WPF
            Point pos = e.GetPosition(obj as IInputElement);
#elif METRO
            Point pos = e.GetCurrentPoint(obj as UIElement).Position;
#endif
            double horizontalChange = (pos.X - GetOriginalX(obj)) * _scale.X;
            double verticalChange   = (pos.Y - GetOriginalY(obj)) * _scale.Y;
            if (GetIsTagged(obj))
            {
                var vc = obj as VertexControl;
                if (vc == null)
                {
                    Debug.WriteLine("OnDragging() -> Tagged and dragged the wrong object?");
                    return;
                }
                foreach (var item in vc.RootArea.GetAllVertexControls())
                {
                    if (GetIsTagged(item))
                    {
                        UpdateCoordinates(item, horizontalChange, verticalChange);
                    }
                }
            }
            else
            {
                UpdateCoordinates(obj, horizontalChange, verticalChange);
            }
            e.Handled = true;
        }
        private static void OnDragStarted(object sender, PointerRoutedEventArgs e)
#endif
        {
            var obj = sender as DependencyObject;

            //we are starting the drag
            SetIsDragging(obj, true);

#if WPF
            var pos = e.GetPosition(obj as IInputElement);
#elif METRO
            var pos = e.GetCurrentPoint(obj as UIElement).Position;
#endif

            //save the position of the mouse to the start position
            SetOriginalX(obj, pos.X);
            SetOriginalY(obj, pos.Y);

            //capture the mouse
#if WPF
            var element = obj as IInputElement;
            if (element != null)
            {
                element.CaptureMouse();
                element.MouseMove -= OnDragging;
                element.MouseMove += OnDragging;
            }
            //else throw new GX_InvalidDataException("The control must be a descendent of the FrameworkElement or FrameworkContentElement!");
            e.Handled = false;
#elif METRO
            var element = obj as FrameworkElement;
            if (element != null)
            {
                element.CapturePointer(e.Pointer);
                element.PointerMoved += OnDragging;
            }
            e.Handled = true;
#endif
        }
Exemplo n.º 20
0
        void HtmlCanvas_PointerReleased(object sender, PointerRoutedEventArgs e)
#endif
        {
            // Get the cursor position relative to this HtmlCanvas
#if MIGRATION
            Point pos = e.GetPosition(this);
#else
            Point pos = e.GetCurrentPoint(this).Position;
#endif

            // Get a stack of the HtmlCanvasElement directly under the cursor and all his parents
            // (Parent1, Parent2, ..., ElementDirectlyUnderTheCursor)
            Stack <HtmlCanvasElement> elements = GetPointedElements(this, pos.X, pos.Y);

            HtmlCanvasPointerRoutedEventArgs e2 = new HtmlCanvasPointerRoutedEventArgs(e, this);

            // Loop backward on every element of the stack
            while (!e.Handled && elements.Count > 0)
            {
                // Remove the last element of the stack and call its OnPointerMoved() method
                elements.Pop().OnPointerReleased(e2);
            }
        }
Exemplo n.º 21
0
        private void DragDropTarget_PointerPressed(object sender, PointerRoutedEventArgs e)
#endif
        {
            //----------------------------------
            // DRAG OPERATION STARTS HERE
            //----------------------------------

            // Prevent the PointerPressed event from bubbling up so that if there are two nested DragDropTargets, only the inner one will be dragged:
            e.Handled = true;

            // We verify that drag operation is not taking place, which can lead a case if we missed the pointer released event due to a glitch such as moving the mouse outside the browser and releasing
            if (!_isPointerCaptured)
            {
                // Reset some variables:
                _isDragCancelled = false;
                _previousdragDropTargetUnderPointer = null;

                // Remember the current pointer position:
#if MIGRATION
                _pointerX = e.GetPosition(null).X;
                _pointerY = e.GetPosition(null).Y;
#else
                _pointerX = e.GetCurrentPoint(null).Position.X;
                _pointerY = e.GetCurrentPoint(null).Position.Y;
#endif
                // Get the source DragDropTarget element that is under the pointer, if any:
                DragDropTarget <TItemsControlType, TItemContainerType> sourceDragDropTarget = GetDragDropTargetUnderPointer(_pointerX, _pointerY, out _sourceItemContainer);
                if (sourceDragDropTarget != this)
                {
                    throw new Exception("The DragDropTarget is not supposed to support dragging an outer DragDropTarget in case of nested DragDropTargets.");
                }

                // We do something only if the source exists (ie. if an item was found under the pointer):
                if (_sourceItemContainer != null)
                {
                    // Get a reference to the ItemsControl:
                    _sourceItemsControl = (TItemsControlType)this.Content; // Note: there is no risk of InvalidCastException because the type has been tested before, and the derived class (PanelDragDropTarget) also verifies the type in the "OnContentChanged" method.

                    // Capture the pointer so that when dragged outside the DragDropPanel, we can still get its position:
    #if MIGRATION
                    this.CaptureMouse();
    #else
                    this.CapturePointer(e.Pointer);
    #endif
                    // Remember that the pointer is currently captured:
                    _isPointerCaptured = true;
                    _capturedPointer   = e.Pointer;

                    //Size of the content
                    double height;
                    double width;
                    if (_sourceItemContainer is FrameworkElement)
                    {
                        Size actualSize = (_sourceItemContainer as FrameworkElement).INTERNAL_GetActualWidthAndHeight();
                        height = actualSize.Height;
                        width  = actualSize.Width;
                    }
                    else
                    {
                        height = double.NaN;
                        width  = double.NaN;
                    }

                    // Prepare the arguments of the "ItemDragStarting" event:
                    Selection           selection                 = new Selection(_sourceItemContainer);
                    SelectionCollection selectionCollection       = SelectionCollection.ToSelectionCollection(selection);
                    ItemDragEventArgs   itemDragStartingEventArgs = new ItemDragEventArgs(selectionCollection);

                    // Raise the "ItemDragStarting" event:
                    if (ItemDragStarting != null)
                    {
                        ItemDragStarting(this, itemDragStartingEventArgs);
                    }

                    // Show the popup, unless the user has cancelled the drag operation:
                    if (itemDragStartingEventArgs.Handled && itemDragStartingEventArgs.Cancel)
                    {
                        //----------------------------------
                        // CANCELLED BY USER
                        //----------------------------------

                        if (_isPointerCaptured)
                        {
                            // Stop capturing the pointer:
                            _isPointerCaptured = false;

#if MIGRATION
                            this.ReleaseMouseCapture();
#else
                            this.ReleasePointerCapture(_capturedPointer);
#endif
                        }
                    }
                    else
                    {
                        //----------------------------------
                        // SHOW POPUP
                        //----------------------------------

                        // Put a placeholder in place of the source that will occupy the same space. This is useful to: 1) let the user drop over the source itself (cf. "ItemDroppedOnSource" event), and 2) prevent the other elements from being displaced during the drag operation.
                        RemoveSourceAndPutTransparentPlaceholderInPlace(height, width);

                        // Put the source into a popup:
                        StackPanel stackPanelInPopUp = GeneratePopupContent(_sourceItemContainer, out _iconStop, out _iconArrow);
                        this._popup = new Popup()
                        {
                            Child = stackPanelInPopUp,
                            HorizontalAlignment        = HorizontalAlignment.Left,
                            VerticalAlignment          = VerticalAlignment.Top,
                            HorizontalContentAlignment = HorizontalAlignment.Left,
                            VerticalContentAlignment   = VerticalAlignment.Top,
                            IsHitTestVisible           = false
                        };

                        // Set the popup position:
                        this._popup.HorizontalOffset = this._pointerX;
                        this._popup.VerticalOffset   = this._pointerY;

                        // Show the popup:
                        this._popup.IsOpen = true;
                    }
                }
            }
        }