Example #1
0
        internal PenContext[] CreateContexts(IntPtr hwnd, PenContexts contexts)
        {
            int c = Count + _deferredTablets.Count;

            PenContext[] ctxs = new PenContext[c];

            int i = 0;

            foreach (TabletDevice tablet in _tablets)
            {
                ctxs[i++] = tablet.As <WispTabletDevice>().CreateContext(hwnd, contexts);
            }

            // DevDiv:1078091
            // We need to re-enable contexts for anything that is marked
            // as a pending disposal.  This is so we continue getting any
            // Wisp messages that might be waiting to come over the shared
            // memory channel.
            foreach (TabletDevice tablet in _deferredTablets)
            {
                ctxs[i++] = tablet.As <WispTabletDevice>().CreateContext(hwnd, contexts);
            }

            return(ctxs);
        }
        internal override void UpdateState(UIElement element)
        {
            bool unhookPenContexts = true;

            // Disable processing of the queue during blocking operations to prevent unrelated reentrancy
            // which a call to Lock() can cause.
            using (element.Dispatcher.DisableProcessing())
            {
                // See if we should be enabled
                if (element.IsVisible && element.IsEnabled && element.IsHitTestVisible)
                {
                    PresentationSource presentationSource = PresentationSource.CriticalFromVisual(element as Visual);

                    if (presentationSource != null)
                    {
                        unhookPenContexts = false;

                        // Are we currently hooked up?  If not then hook up.
                        if (_penContexts == null)
                        {
                            InputManager inputManager = (InputManager)element.Dispatcher.InputManager;
                            PenContexts  penContexts  = StylusLogic.GetCurrentStylusLogicAs <WispLogic>().GetPenContextsFromHwnd(presentationSource);

                            // _penContexts must be non null or don't do anything.
                            if (penContexts != null)
                            {
                                _penContexts = penContexts;

                                lock (penContexts.SyncRoot)
                                {
                                    penContexts.AddStylusPlugInCollection(Wrapper);

                                    foreach (StylusPlugIn spi in Wrapper)
                                    {
                                        spi.InvalidateIsActiveForInput(); // Uses _penContexts being set to determine active state.
                                    }
                                    // NTRAID:WINDOWSOS#1677277-2006/06/05-WAYNEZEN,
                                    // Normally the Rect will be updated when we receive the LayoutUpdate.
                                    // However there could be a race condition which the LayoutUpdate gets received
                                    // before the properties like IsVisible being set.
                                    // So we should always force to call OnLayoutUpdated whenever the input is active.
                                    Wrapper.OnLayoutUpdated(this.Wrapper, EventArgs.Empty);
                                }
                            }
                        }
                    }
                }

                if (unhookPenContexts)
                {
                    Unhook();
                }
            }
        }