Example #1
0
        /////////////////////////////////////////////////////////////////////////

        internal PenContexts(WispLogic stylusLogic, PresentationSource inputSource)
        {
            HwndSource hwndSource = inputSource as HwndSource;

            if (hwndSource == null || IntPtr.Zero == (hwndSource).CriticalHandle)
            {
                throw new InvalidOperationException(SR.Get(SRID.Stylus_PenContextFailure));
            }

            _stylusLogic = stylusLogic;
            _inputSource = new SecurityCriticalData <HwndSource>(hwndSource);
        }
Example #2
0
        internal void UpdateSizeDeltas(StylusPointDescription description, WispLogic stylusLogic)
        {
            // Query default settings for mouse drag and double tap (with minimum of 1x1 size).
            Size mouseDragDefault = new Size(Math.Max(1, SafeSystemMetrics.DragDeltaX / 2),
                                             Math.Max(1, SafeSystemMetrics.DragDeltaY / 2));
            Size mouseDoubleTapDefault = new Size(Math.Max(1, SafeSystemMetrics.DoubleClickDeltaX / 2),
                                                  Math.Max(1, SafeSystemMetrics.DoubleClickDeltaY / 2));

            StylusPointPropertyInfo xProperty = description.GetPropertyInfo(StylusPointProperties.X);
            StylusPointPropertyInfo yProperty = description.GetPropertyInfo(StylusPointProperties.Y);

            uint dwXValue = GetPropertyValue(xProperty);
            uint dwYValue = GetPropertyValue(yProperty);

            if (dwXValue != 0 && dwYValue != 0)
            {
                _cancelSize = new Size((int)Math.Round((ScreenSize.Width * stylusLogic.CancelDelta) / dwXValue),
                                       (int)Math.Round((ScreenSize.Height * stylusLogic.CancelDelta) / dwYValue));

                // Make sure we return whole numbers (pixels are whole numbers) and take the maximum
                // value between mouse and stylus settings to be safe.
                _cancelSize.Width  = Math.Max(mouseDragDefault.Width, _cancelSize.Width);
                _cancelSize.Height = Math.Max(mouseDragDefault.Height, _cancelSize.Height);

                _doubleTapSize = new Size((int)Math.Round((ScreenSize.Width * stylusLogic.DoubleTapDelta) / dwXValue),
                                          (int)Math.Round((ScreenSize.Height * stylusLogic.DoubleTapDelta) / dwYValue));

                // Make sure we return whole numbers (pixels are whole numbers) and take the maximum
                // value between mouse and stylus settings to be safe.
                _doubleTapSize.Width  = Math.Max(mouseDoubleTapDefault.Width, _doubleTapSize.Width);
                _doubleTapSize.Height = Math.Max(mouseDoubleTapDefault.Height, _doubleTapSize.Height);
            }
            else
            {
                // If no info to do the calculation then use the mouse settings for the default.
                _doubleTapSize = mouseDoubleTapDefault;
                _cancelSize    = mouseDragDefault;
            }

            _forceUpdateSizeDeltas = false;
        }
Example #3
0
        internal WispTabletDeviceCollection()
        {
            WispLogic stylusLogic = StylusLogic.GetCurrentStylusLogicAs <WispLogic>();
            bool      enabled     = stylusLogic.Enabled;

            if (!enabled)
            {
                enabled = ShouldEnableTablets();
            }

            // If enabled or we are a tabletpc (vista sets dynamically if digitizers present) then enable the pen!
            if (enabled)
            {
                UpdateTablets(); // Create the tablet device collection!

                // Enable stylus input on all hwnds if we have not yet done so.
                if (!stylusLogic.Enabled)
                {
                    stylusLogic.EnableCore();
                }
            }
        }
Example #4
0
        IntPtr IStylusInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            IntPtr result = IntPtr.Zero;

            // It is possible to be re-entered during disposal.  Just return.
            if (null == _source || null == _source.Value)
            {
                return(result);
            }

            switch (msg)
            {
            case WindowMessage.WM_ENABLE:
                _stylusLogic.Value.OnWindowEnableChanged(hwnd, (int)NativeMethods.IntPtrToInt32(wParam) == 0);
                break;

            case WindowMessage.WM_TABLET_QUERYSYSTEMGESTURESTATUS:
                handled = true;

                NativeMethods.POINT pt1 = new NativeMethods.POINT(
                    NativeMethods.SignedLOWORD(lParam),
                    NativeMethods.SignedHIWORD(lParam));
                SafeNativeMethods.ScreenToClient(new HandleRef(this, hwnd), pt1);
                Point ptClient1 = new Point(pt1.x, pt1.y);

                IInputElement inputElement = StylusDevice.LocalHitTest(_source.Value, ptClient1);
                if (inputElement != null)
                {
                    // walk up the parent chain
                    DependencyObject elementCur             = (DependencyObject)inputElement;
                    bool             isPressAndHoldEnabled  = Stylus.GetIsPressAndHoldEnabled(elementCur);
                    bool             isFlicksEnabled        = Stylus.GetIsFlicksEnabled(elementCur);
                    bool             isTapFeedbackEnabled   = Stylus.GetIsTapFeedbackEnabled(elementCur);
                    bool             isTouchFeedbackEnabled = Stylus.GetIsTouchFeedbackEnabled(elementCur);

                    uint flags = 0;

                    if (!isPressAndHoldEnabled)
                    {
                        flags |= TABLET_PRESSANDHOLD_DISABLED;
                    }

                    if (!isTapFeedbackEnabled)
                    {
                        flags |= TABLET_TAPFEEDBACK_DISABLED;
                    }

                    if (isTouchFeedbackEnabled)
                    {
                        flags |= TABLET_TOUCHUI_FORCEON;
                    }
                    else
                    {
                        flags |= TABLET_TOUCHUI_FORCEOFF;
                    }

                    if (!isFlicksEnabled)
                    {
                        flags |= TABLET_FLICKS_DISABLED;
                    }

                    result = new IntPtr(flags);
                }
                break;

            case WindowMessage.WM_TABLET_FLICK:
                handled = true;

                int flickData = NativeMethods.IntPtrToInt32(wParam);

                // We always handle any scroll actions if we are enabled.  We do this when we see the SystemGesture Flick come through.
                // Note: Scrolling happens on window flicked on even if it is not the active window.
                if (_stylusLogic != null && _stylusLogic.Value.Enabled && (WispLogic.GetFlickAction(flickData) == StylusLogic.FlickAction.Scroll))
                {
                    result = new IntPtr(0x0001);     // tell UIHub the flick has already been handled.
                }
                break;
            }

            if (handled && EventTrace.IsEnabled(EventTrace.Keyword.KeywordInput | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info))
            {
                EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientInputMessage, EventTrace.Keyword.KeywordInput | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info,
                                                    (_source.Value.CompositionTarget != null ? _source.Value.CompositionTarget.Dispatcher.GetHashCode() : 0),
                                                    hwnd.ToInt64(),
                                                    msg,
                                                    (int)wParam,
                                                    (int)lParam);
            }

            return(result);
        }