Exemple #1
0
        internal void RegisterHwndForInput(InputManager inputManager, PresentationSource inputSource) 
        {
            HwndSource hwndSource = (HwndSource)inputSource; 
 
            // Query the transform from HwndTarget when the first window is created.
            if (!_transformInitialized) 
            {
                if (hwndSource != null && hwndSource.CompositionTarget != null)
                {
                    _transformToDevice = hwndSource.CompositionTarget.TransformToDevice; 
                    Debug.Assert(_transformToDevice.HasInverse);
                    _transformInitialized = true; 
                } 
            }
 
            // Keep track so we don't bother looking for changes if someone happened to query this before
            // an Avalon window was created where we get TabletAdd/Removed notification.
            bool initializedTablets = (_tabletDeviceCollection == null);
 
            // This causes EnableCore to be called on TabletPC systems which enabled stylus input!
            TabletDeviceCollection tablets = TabletDevices; 
 
            // Make sure that lock() does not cause reentrancy.
            using(Dispatcher.DisableProcessing()) 
            {
                lock (__penContextsLock)
                {
                    if (__penContextsMap.ContainsKey(inputSource)) 
                    {
                        throw new InvalidOperationException(SR.Get(SRID.PenService_WindowAlreadyRegistered)); 
                    } 

                    PenContexts penContexts = new PenContexts(inputManager.StylusLogic, inputSource); 

                    __penContextsMap[inputSource] = penContexts;

                    // If FIRST one set this as the one to manage TabletAdded/Removed notifications. 
                    if (__penContextsMap.Count == 1)
                    { 
                        // Make sure our view of TabletDevices is up to date we didn't just cause it 
                        // to be initialized and we had some real tablet devices.
                        if (!initializedTablets && tablets.Count > 0) 
                        {
                            tablets.UpdateTablets();
                        }
                    } 

                    // Detect if this window is disabled. If so then let the pencontexts know. 
                    int style = UnsafeNativeMethods.GetWindowLong(new HandleRef(this,hwndSource.CriticalHandle), NativeMethods.GWL_STYLE); 
                    if ((style & NativeMethods.WS_DISABLED) != 0)
                    { 
                        penContexts.IsWindowDisabled = true;
                    }

                    if ( _inputEnabled ) 
                        penContexts.Enable();
                } 
            } 
        }