Beispiel #1
0
        internal PointerStylusDevice(PointerTabletDevice tabletDevice, UnsafeNativeMethods.POINTER_DEVICE_CURSOR_INFO cursorInfo)
        {
            _cursorInfo   = cursorInfo;
            _tabletDevice = tabletDevice;
            _pointerLogic = StylusLogic.GetCurrentStylusLogicAs <PointerLogic>();

            // Touch devices have a special set of handling code
            if (tabletDevice.Type == TabletDeviceType.Touch)
            {
                TouchDevice = new PointerTouchDevice(this);
            }

            _interactionEngine = new PointerInteractionEngine(this);

            _interactionEngine.InteractionDetected += HandleInteraction;

            List <StylusButton> buttons = new List <StylusButton>();

            // Create a button collection for this StylusDevice based off the button properties stored in the tablet
            // This needs to be done as each button instance has a StylusDevice owner that it uses to access the raw
            // data in the StylusDevice.
            foreach (var prop in _tabletDevice.DeviceInfo.StylusPointProperties)
            {
                if (prop.IsButton)
                {
                    StylusButton button = new StylusButton(StylusPointPropertyIds.GetStringRepresentation(prop.Id), prop.Id);
                    button.SetOwner(this);
                    buttons.Add(button);
                }
            }

            _stylusButtons = new StylusButtonCollection(buttons);
        }
Beispiel #2
0
        /// <summary>
        /// Retrieve the TabletDevice associated with the device id
        /// </summary>
        /// <param name="deviceId">The device id</param>
        /// <returns>The TabletDevice associated with the device id</returns>
        internal PointerTabletDevice GetByDeviceId(IntPtr deviceId)
        {
            PointerTabletDevice tablet = null;

            _tabletDeviceMap.TryGetValue(deviceId, out tablet);

            return(tablet);
        }
Beispiel #3
0
        /// <summary>
        /// Retrieves the latest device information from connected touch devices.
        /// </summary>
        internal void Refresh()
        {
            try
            {
                // Keep track of old tablets so that we can properly log connects/disconnects
                Dictionary <IntPtr, PointerTabletDevice> oldTablets = _tabletDeviceMap;

                _tabletDeviceMap = new Dictionary <IntPtr, PointerTabletDevice>();
                TabletDevices.Clear();

                uint deviceCount = 0;

                // Pattern is to first get the count, then declare an array of that size
                // which is then marshaled via the second call with the proper data.
                IsValid = UnsafeNativeMethods.GetPointerDevices(ref deviceCount, null);

                if (IsValid)
                {
                    UnsafeNativeMethods.POINTER_DEVICE_INFO[] deviceInfos
                        = new UnsafeNativeMethods.POINTER_DEVICE_INFO[deviceCount];

                    IsValid = UnsafeNativeMethods.GetPointerDevices(ref deviceCount, deviceInfos);

                    if (IsValid)
                    {
                        foreach (var deviceInfo in deviceInfos)
                        {
                            // Old PenIMC code gets this id via a straight cast from COM pointer address
                            // into an int32.  This does a very similar thing semantically using the pointer
                            // to the tablet from the WM_POINTER stack.  While it may have similar issues
                            // (chopping the upper bits, duplicate ids) we don't use this id internally
                            // and have never received complaints about this in the WISP stack.
                            int id = MS.Win32.NativeMethods.IntPtrToInt32(deviceInfo.device);

                            PointerTabletDeviceInfo ptdi = new PointerTabletDeviceInfo(id, deviceInfo);


                            // Don't add a device that fails initialization.  This means we will try a refresh
                            // next time around if we receive stylus input and the device is not available.
                            // <see cref="HwndPointerInputProvider.UpdateCurrentTabletAndStylus">
                            if (ptdi.TryInitialize())
                            {
                                PointerTabletDevice tablet = new PointerTabletDevice(ptdi);

                                if (!oldTablets.Remove(tablet.Device))
                                {
                                    // We only create a TabletDevice when one is connected (physically or virtually).
                                    // As such we have to log when there is no corresponding old tablet being refreshed.
                                    StylusTraceLogger.LogDeviceConnect(
                                        new StylusTraceLogger.StylusDeviceInfo(
                                            tablet.Id,
                                            tablet.Name,
                                            tablet.ProductId,
                                            tablet.TabletHardwareCapabilities,
                                            tablet.TabletSize,
                                            tablet.ScreenSize,
                                            tablet.Type,
                                            tablet.StylusDevices.Count));
                                }

                                _tabletDeviceMap[tablet.Device] = tablet;
                                TabletDevices.Add(tablet.TabletDevice);
                            }
                        }
                    }

                    // Any tablet leftover here was not refreshed from the previous set of tablets
                    // and should be logged as disconnected.
                    foreach (var oldTablet in oldTablets.Values)
                    {
                        StylusTraceLogger.LogDeviceDisconnect(oldTablet.Id);
                    }
                }
            }
            catch (Win32Exception)
            {
                IsValid = false;
            }
        }