Exemple #1
0
        /////////////////////////////////////////////////////////////////////
        private void OnPostProcessInput(object sender, ProcessInputEventArgs e)
        {
            if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
            {
                InputReportEventArgs report = (InputReportEventArgs)e.StagingItem.Input;
                if (!report.Handled)
                {
                    if (report.Report.Type == InputType.Mouse)
                    {
                        RawMouseInputReport mouseReport = (RawMouseInputReport)report.Report;
                        if ((mouseReport.Actions & RawMouseActions.AbsoluteMove) == RawMouseActions.AbsoluteMove)
                        {
                            if ((Mouse.LeftButton == MouseButtonState.Pressed) ||
                                (Mouse.RightButton == MouseButtonState.Pressed))
                            {
                                RaiseToolTipClosingEvent(true /* reset */);
                            }
                            else
                            {
                                IInputElement directlyOver = Mouse.PrimaryDevice.RawDirectlyOver;
                                if (directlyOver != null)
                                {
                                    Point pt = Mouse.PrimaryDevice.GetPosition(directlyOver);

                                    // If possible, check that the mouse position is within the render bounds
                                    // (avoids mouse capture confusion).
                                    if (Mouse.CapturedMode != CaptureMode.None)
                                    {
                                        // Get the root visual
                                        PresentationSource source          = PresentationSource.CriticalFromVisual((DependencyObject)directlyOver);
                                        UIElement          rootAsUIElement = source != null ? source.RootVisual as UIElement : null;
                                        if (rootAsUIElement != null)
                                        {
                                            // Get mouse position wrt to root
                                            pt = Mouse.PrimaryDevice.GetPosition(rootAsUIElement);

                                            // Hittest to find the element the mouse is over
                                            IInputElement enabledHit;
                                            rootAsUIElement.InputHitTest(pt, out enabledHit, out directlyOver);

                                            // Find the position of the mouse relative the element that the mouse is over
                                            pt = Mouse.PrimaryDevice.GetPosition(directlyOver);
                                        }
                                        else
                                        {
                                            directlyOver = null;
                                        }
                                    }

                                    if (directlyOver != null)
                                    {
                                        // Process the mouse move
                                        OnMouseMove(directlyOver, pt);
                                    }
                                }
                            }
                        }
                        else if ((mouseReport.Actions & RawMouseActions.Deactivate) == RawMouseActions.Deactivate)
                        {
                            if (LastMouseDirectlyOver != null)
                            {
                                LastMouseDirectlyOver = null;
                                if (LastMouseOverWithToolTip != null)
                                {
                                    RaiseToolTipClosingEvent(true /* reset */);

                                    // When the user moves the cursor outside of the window,
                                    // clear the LastMouseOverWithToolTip property so if the user returns
                                    // the mouse to the same item, the tooltip will reappear.  If
                                    // the deactivation is coming from a window grabbing capture
                                    // (such as Drag and Drop) do not clear the property.
                                    if (MS.Win32.SafeNativeMethods.GetCapture() == IntPtr.Zero)
                                    {
                                        LastMouseOverWithToolTip = null;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyDownEvent)
            {
                ProcessKeyDown(sender, (KeyEventArgs)e.StagingItem.Input);
            }
            else if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent)
            {
                ProcessKeyUp(sender, (KeyEventArgs)e.StagingItem.Input);
            }
            else if (e.StagingItem.Input.RoutedEvent == Mouse.MouseUpEvent)
            {
                ProcessMouseUp(sender, (MouseButtonEventArgs)e.StagingItem.Input);
            }
            else if (e.StagingItem.Input.RoutedEvent == Mouse.MouseDownEvent)
            {
                RaiseToolTipClosingEvent(true /* reset */);
            }
        }
Exemple #2
0
 private void OnPostProcessInput(object sender, ProcessInputEventArgs e)
 {
     if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
     {
         InputReportEventArgs inputReportEventArgs = (InputReportEventArgs)e.StagingItem.Input;
         if (!inputReportEventArgs.Handled && inputReportEventArgs.Report.Type == InputType.Mouse)
         {
             RawMouseInputReport rawMouseInputReport = (RawMouseInputReport)inputReportEventArgs.Report;
             if ((rawMouseInputReport.Actions & RawMouseActions.AbsoluteMove) == RawMouseActions.AbsoluteMove)
             {
                 if (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed)
                 {
                     this.RaiseToolTipClosingEvent(true);
                     return;
                 }
                 IInputElement inputElement = Mouse.PrimaryDevice.RawDirectlyOver;
                 if (inputElement != null)
                 {
                     Point position = Mouse.PrimaryDevice.GetPosition(inputElement);
                     if (Mouse.CapturedMode != CaptureMode.None)
                     {
                         PresentationSource presentationSource = PresentationSource.CriticalFromVisual((DependencyObject)inputElement);
                         UIElement          uielement          = (presentationSource != null) ? (presentationSource.RootVisual as UIElement) : null;
                         if (uielement != null)
                         {
                             position = Mouse.PrimaryDevice.GetPosition(uielement);
                             IInputElement inputElement2;
                             uielement.InputHitTest(position, out inputElement2, out inputElement);
                             position = Mouse.PrimaryDevice.GetPosition(inputElement);
                         }
                         else
                         {
                             inputElement = null;
                         }
                     }
                     if (inputElement != null)
                     {
                         this.OnMouseMove(inputElement, position);
                         return;
                     }
                 }
             }
             else if ((rawMouseInputReport.Actions & RawMouseActions.Deactivate) == RawMouseActions.Deactivate && this.LastMouseDirectlyOver != null)
             {
                 this.LastMouseDirectlyOver = null;
                 if (this.LastMouseOverWithToolTip != null)
                 {
                     this.RaiseToolTipClosingEvent(true);
                     if (SafeNativeMethods.GetCapture() == IntPtr.Zero)
                     {
                         this.LastMouseOverWithToolTip = null;
                         return;
                     }
                 }
             }
         }
     }
     else
     {
         if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyDownEvent)
         {
             this.ProcessKeyDown(sender, (KeyEventArgs)e.StagingItem.Input);
             return;
         }
         if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent)
         {
             this.ProcessKeyUp(sender, (KeyEventArgs)e.StagingItem.Input);
             return;
         }
         if (e.StagingItem.Input.RoutedEvent == Mouse.MouseUpEvent)
         {
             this.ProcessMouseUp(sender, (MouseButtonEventArgs)e.StagingItem.Input);
             return;
         }
         if (e.StagingItem.Input.RoutedEvent == Mouse.MouseDownEvent)
         {
             this.RaiseToolTipClosingEvent(true);
         }
     }
 }