Example #1
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            InputEventArgs inputEventArgs = e.StagingItem.Input;

            if ((inputEventArgs != null) && (inputEventArgs.Device == this))
            {
                if (inputEventArgs.Handled)
                {
                    RoutedEvent routedEvent = inputEventArgs.RoutedEvent;

                    if (routedEvent == Touch.PreviewTouchMoveEvent ||
                        routedEvent == Touch.TouchMoveEvent)
                    {
                        _lastMoveHandled = true;
                    }
                    else if (routedEvent == Touch.PreviewTouchDownEvent ||
                             routedEvent == Touch.TouchDownEvent)
                    {
                        _lastDownHandled = true;
                    }
                    else if (routedEvent == Touch.PreviewTouchUpEvent ||
                             routedEvent == Touch.TouchUpEvent)
                    {
                        _lastUpHandled = true;
                    }
                }
                else
                {
                    bool        forManipulation;
                    RoutedEvent promotedTouchEvent = PromotePreviewToMain(inputEventArgs.RoutedEvent, out forManipulation);
                    if (promotedTouchEvent != null)
                    {
                        TouchEventArgs promotedTouchEventArgs = CreateEventArgs(promotedTouchEvent);
                        e.PushInput(promotedTouchEventArgs, e.StagingItem);
                    }
                    else if (forManipulation)
                    {
                        UIElement manipulatableElement = GetManipulatableElement();
                        if (manipulatableElement != null)
                        {
                            PromoteMainToManipulation(manipulatableElement, (TouchEventArgs)inputEventArgs);
                        }
                    }
                }
            }
        }
Example #2
0
 private void PostProcessInput(object sender, ProcessInputEventArgs e)
 {
     if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
     {
         if (!e.StagingItem.Input.Handled)
         {
             InputReportEventArgs inputReportEventArgs = e.StagingItem.Input as InputReportEventArgs;
             if (inputReportEventArgs != null)
             {
                 RawAppCommandInputReport rawAppCommandInputReport = inputReportEventArgs.Report as RawAppCommandInputReport;
                 if (rawAppCommandInputReport != null)
                 {
                     IInputElement commandTarget = e.StagingItem.Input.OriginalSource as IInputElement;
                     if (commandTarget != null)
                     {
                         RoutedCommand command = GetRoutedCommand(rawAppCommandInputReport.AppCommand);
                         if (command != null)
                         {
                             // Send the app command to the tree to be handled by UIElements and ContentElements
                             // that will forward the event to CommandManager.
                             CommandDeviceEventArgs args = new CommandDeviceEventArgs(this, rawAppCommandInputReport.Timestamp, command);
                             args.RoutedEvent = CommandDeviceEvent;
                             args.Source      = commandTarget;
                             e.PushInput(args, e.StagingItem);
                         }
                     }
                 }
             }
         }
     }
     else if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent ||
              e.StagingItem.Input.RoutedEvent == Mouse.MouseUpEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.GotKeyboardFocusEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.LostKeyboardFocusEvent)
     {
         CommandManager.InvalidateRequerySuggested();
     }
 }
Example #3
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e) 
        {
            // PreviewKeyDown --> KeyDown 
            if(e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyDownEvent)
            {
                CheckForDisconnectedFocus();
 
                if(!e.StagingItem.Input.Handled)
                { 
                    KeyEventArgs previewKeyDown = (KeyEventArgs) e.StagingItem.Input; 

                    // Dig out the real key. 
                    bool isSystemKey = false;
                    bool isImeProcessed = false;
                    bool isDeadCharProcessed = false;
                    Key key = previewKeyDown.Key; 
                    if (key == Key.System)
                    { 
                        isSystemKey = true; 
                        key = previewKeyDown.RealKey;
                    } 
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true;
                        key = previewKeyDown.RealKey; 
                    }
                    else if (key == Key.DeadCharProcessed) 
                    { 
                        isDeadCharProcessed = true;
                        key = previewKeyDown.RealKey; 
                    }

                    KeyEventArgs keyDown = new KeyEventArgs(this, previewKeyDown.UnsafeInputSource, previewKeyDown.Timestamp, key);
                    keyDown.SetRepeat( previewKeyDown.IsRepeat ); 

                    // Mark the new event as SystemKey as appropriate. 
                    if (isSystemKey) 
                    {
                        keyDown.MarkSystem(); 
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate. 
                        keyDown.MarkImeProcessed();
                    } 
                    else if (isDeadCharProcessed) 
                    {
                        keyDown.MarkDeadCharProcessed(); 
                    }

                    keyDown.RoutedEvent=Keyboard.KeyDownEvent;
                    keyDown.ScanCode = previewKeyDown.ScanCode; 
                    keyDown.IsExtendedKey = previewKeyDown.IsExtendedKey;
                    e.PushInput(keyDown, e.StagingItem); 
                } 
            }
 
            // PreviewKeyUp --> KeyUp
            if(e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyUpEvent)
            {
                CheckForDisconnectedFocus(); 

                if(!e.StagingItem.Input.Handled) 
                { 
                    KeyEventArgs previewKeyUp = (KeyEventArgs) e.StagingItem.Input;
 
                    // Dig out the real key.
                    bool isSystemKey = false;
                    bool isImeProcessed = false;
                    bool isDeadCharProcessed = false; 
                    Key key = previewKeyUp.Key;
                    if (key == Key.System) 
                    { 
                        isSystemKey = true;
                        key = previewKeyUp.RealKey; 
                    }
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true; 
                        key = previewKeyUp.RealKey;
                    } 
                    else if(key == Key.DeadCharProcessed) 
                    {
                        isDeadCharProcessed = true; 
                        key = previewKeyUp.RealKey;
                    }

                    KeyEventArgs keyUp = new KeyEventArgs(this, previewKeyUp.UnsafeInputSource, previewKeyUp.Timestamp, key); 

                    // Mark the new event as SystemKey as appropriate. 
                    if (isSystemKey) 
                    {
                        keyUp.MarkSystem(); 
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate. 
                        keyUp.MarkImeProcessed();
                    } 
                    else if (isDeadCharProcessed) 
                    {
                        keyUp.MarkDeadCharProcessed(); 
                    }

                    keyUp.RoutedEvent=Keyboard.KeyUpEvent;
                    keyUp.ScanCode = previewKeyUp.ScanCode; 
                    keyUp.IsExtendedKey = previewKeyUp.IsExtendedKey;
                    e.PushInput(keyUp, e.StagingItem); 
                } 
            }
 
            RawKeyboardInputReport keyboardInput = ExtractRawKeyboardInputReport(e, InputManager.InputReportEvent);
            if(keyboardInput != null)
            {
                CheckForDisconnectedFocus(); 

                if(!e.StagingItem.Input.Handled) 
                { 
                    // In general, this is where we promote the non-redundant
                    // reported actions to our premier events. 
                    RawKeyboardActions actions = GetNonRedundantActions(e);

                    // Raw --> PreviewKeyDown
                    if((actions & RawKeyboardActions.KeyDown) == RawKeyboardActions.KeyDown) 
                    {
                        Key key = (Key) e.StagingItem.GetData(_tagKey); 
                        if(key != Key.None) 
                        {
                            KeyEventArgs previewKeyDown = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key); 
                            ScanCode scanCode = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyDown.ScanCode = scanCode.Code;
                            previewKeyDown.IsExtendedKey = scanCode.IsExtended;
                            if (keyboardInput.IsSystemKey) 
                            {
                                previewKeyDown.MarkSystem(); 
                            } 
                            previewKeyDown.RoutedEvent=Keyboard.PreviewKeyDownEvent;
                            e.PushInput(previewKeyDown, e.StagingItem); 
                        }
                    }

                    // Raw --> PreviewKeyUp 
                    if((actions & RawKeyboardActions.KeyUp) == RawKeyboardActions.KeyUp)
                    { 
                        Key key = (Key) e.StagingItem.GetData(_tagKey); 
                        if(key != Key.None)
                        { 
                            KeyEventArgs previewKeyUp = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key);
                            ScanCode scanCode = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyUp.ScanCode = scanCode.Code;
                            previewKeyUp.IsExtendedKey = scanCode.IsExtended; 
                            if (keyboardInput.IsSystemKey)
                            { 
                                previewKeyUp.MarkSystem(); 
                            }
                            previewKeyUp.RoutedEvent=Keyboard.PreviewKeyUpEvent; 
                            e.PushInput(previewKeyUp, e.StagingItem);
                        }
                    }
                } 

                // Deactivate 
                if((keyboardInput.Actions & RawKeyboardActions.Deactivate) == RawKeyboardActions.Deactivate) 
                {
                    if(IsActive) 
                    {
                        _activeSource = null;

                        // Even if handled, a keyboard deactivate results in a lost focus. 
                        ChangeFocus(null, e.StagingItem.Input.Timestamp);
                    } 
                } 
            }
        } 
Example #4
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            // PreviewKeyDown --> KeyDown
            if (e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyDownEvent)
            {
                CheckForDisconnectedFocus();

                if (!e.StagingItem.Input.Handled)
                {
                    KeyEventArgs previewKeyDown = (KeyEventArgs)e.StagingItem.Input;

                    // Dig out the real key.
                    bool isSystemKey         = false;
                    bool isImeProcessed      = false;
                    bool isDeadCharProcessed = false;
                    Key  key = previewKeyDown.Key;
                    if (key == Key.System)
                    {
                        isSystemKey = true;
                        key         = previewKeyDown.RealKey;
                    }
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true;
                        key            = previewKeyDown.RealKey;
                    }
                    else if (key == Key.DeadCharProcessed)
                    {
                        isDeadCharProcessed = true;
                        key = previewKeyDown.RealKey;
                    }

                    KeyEventArgs keyDown = new KeyEventArgs(this, previewKeyDown.UnsafeInputSource, previewKeyDown.Timestamp, key);
                    keyDown.SetRepeat(previewKeyDown.IsRepeat);

                    // Mark the new event as SystemKey as appropriate.
                    if (isSystemKey)
                    {
                        keyDown.MarkSystem();
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate.
                        keyDown.MarkImeProcessed();
                    }
                    else if (isDeadCharProcessed)
                    {
                        keyDown.MarkDeadCharProcessed();
                    }

                    keyDown.RoutedEvent   = Keyboard.KeyDownEvent;
                    keyDown.ScanCode      = previewKeyDown.ScanCode;
                    keyDown.IsExtendedKey = previewKeyDown.IsExtendedKey;
                    e.PushInput(keyDown, e.StagingItem);
                }
            }

            // PreviewKeyUp --> KeyUp
            if (e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyUpEvent)
            {
                CheckForDisconnectedFocus();

                if (!e.StagingItem.Input.Handled)
                {
                    KeyEventArgs previewKeyUp = (KeyEventArgs)e.StagingItem.Input;

                    // Dig out the real key.
                    bool isSystemKey         = false;
                    bool isImeProcessed      = false;
                    bool isDeadCharProcessed = false;
                    Key  key = previewKeyUp.Key;
                    if (key == Key.System)
                    {
                        isSystemKey = true;
                        key         = previewKeyUp.RealKey;
                    }
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true;
                        key            = previewKeyUp.RealKey;
                    }
                    else if (key == Key.DeadCharProcessed)
                    {
                        isDeadCharProcessed = true;
                        key = previewKeyUp.RealKey;
                    }

                    KeyEventArgs keyUp = new KeyEventArgs(this, previewKeyUp.UnsafeInputSource, previewKeyUp.Timestamp, key);

                    // Mark the new event as SystemKey as appropriate.
                    if (isSystemKey)
                    {
                        keyUp.MarkSystem();
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate.
                        keyUp.MarkImeProcessed();
                    }
                    else if (isDeadCharProcessed)
                    {
                        keyUp.MarkDeadCharProcessed();
                    }

                    keyUp.RoutedEvent   = Keyboard.KeyUpEvent;
                    keyUp.ScanCode      = previewKeyUp.ScanCode;
                    keyUp.IsExtendedKey = previewKeyUp.IsExtendedKey;
                    e.PushInput(keyUp, e.StagingItem);
                }
            }

            RawKeyboardInputReport keyboardInput = ExtractRawKeyboardInputReport(e, InputManager.InputReportEvent);

            if (keyboardInput != null)
            {
                CheckForDisconnectedFocus();

                if (!e.StagingItem.Input.Handled)
                {
                    // In general, this is where we promote the non-redundant
                    // reported actions to our premier events.
                    RawKeyboardActions actions = GetNonRedundantActions(e);

                    // Raw --> PreviewKeyDown
                    if ((actions & RawKeyboardActions.KeyDown) == RawKeyboardActions.KeyDown)
                    {
                        Key key = (Key)e.StagingItem.GetData(_tagKey);
                        if (key != Key.None)
                        {
                            KeyEventArgs previewKeyDown = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key);
                            ScanCode     scanCode       = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyDown.ScanCode      = scanCode.Code;
                            previewKeyDown.IsExtendedKey = scanCode.IsExtended;
                            if (keyboardInput.IsSystemKey)
                            {
                                previewKeyDown.MarkSystem();
                            }
                            previewKeyDown.RoutedEvent = Keyboard.PreviewKeyDownEvent;
                            e.PushInput(previewKeyDown, e.StagingItem);
                        }
                    }

                    // Raw --> PreviewKeyUp
                    if ((actions & RawKeyboardActions.KeyUp) == RawKeyboardActions.KeyUp)
                    {
                        Key key = (Key)e.StagingItem.GetData(_tagKey);
                        if (key != Key.None)
                        {
                            KeyEventArgs previewKeyUp = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key);
                            ScanCode     scanCode     = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyUp.ScanCode      = scanCode.Code;
                            previewKeyUp.IsExtendedKey = scanCode.IsExtended;
                            if (keyboardInput.IsSystemKey)
                            {
                                previewKeyUp.MarkSystem();
                            }
                            previewKeyUp.RoutedEvent = Keyboard.PreviewKeyUpEvent;
                            e.PushInput(previewKeyUp, e.StagingItem);
                        }
                    }
                }

                // Deactivate
                if ((keyboardInput.Actions & RawKeyboardActions.Deactivate) == RawKeyboardActions.Deactivate)
                {
                    if (IsActive)
                    {
                        _activeSource = null;

                        // Even if handled, a keyboard deactivate results in a lost focus.
                        ChangeFocus(null, e.StagingItem.Input.Timestamp);
                    }
                }
            }
        }
Example #5
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            // KeyUp
            if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent)
            {
                KeyEventArgs keyArgs = (KeyEventArgs)e.StagingItem.Input;
                if (!keyArgs.Handled)
                {
                    if (keyArgs.RealKey == Key.LeftAlt || keyArgs.RealKey == Key.RightAlt)
                    {
                        // Make sure both Alt keys are up.
                        ModifierKeys modifiers = keyArgs.KeyboardDevice.Modifiers;
                        if ((modifiers & ModifierKeys.Alt) == 0)
                        {
                            if (_altNumpadEntryMode)
                            {
                                _altNumpadEntryMode = false;

                                // Generate the Unicode equivalent if we
                                // actually entered a number via the numpad.
                                if (_altNumpadEntry != 0)
                                {
                                    _altNumpadcomposition.ClearTexts();
                                    if (_altNumpadConversionMode == AltNumpadConversionMode.OEMCodePage)
                                    {
                                        _altNumpadcomposition.SetText(GetCurrentOEMCPEncoding(_altNumpadEntry));
                                    }
                                    else if ((_altNumpadConversionMode == AltNumpadConversionMode.DefaultCodePage) ||
                                             (_altNumpadConversionMode == AltNumpadConversionMode.HexDefaultCodePage))
                                    {
                                        _altNumpadcomposition.SetText(CharacterEncoding(InputLanguageManager.Current.CurrentInputLanguage.TextInfo.ANSICodePage, _altNumpadEntry));
                                    }
                                    else if (_altNumpadConversionMode == AltNumpadConversionMode.HexUnicode)
                                    {
                                        Char[] chars = new Char[1];
                                        chars[0] = (Char)_altNumpadEntry;
                                        _altNumpadcomposition.SetText(new string(chars));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Someone handled Alt key up event, we cancel Alt-Numpad handling.
                    _altNumpadEntryMode      = false;
                    _altNumpadEntry          = 0;
                    _altNumpadConversionMode = AltNumpadConversionMode.OEMCodePage;
                }
            }

            // PreviewTextInputBegin --> TextInputStart
            else if (e.StagingItem.Input.RoutedEvent == TextCompositionManager.PreviewTextInputStartEvent)
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs)e.StagingItem.Input;
                if (!textArgs.Handled)
                {
                    TextCompositionEventArgs text = new TextCompositionEventArgs(textArgs.Device, textArgs.TextComposition);
                    text.RoutedEvent = TextCompositionManager.TextInputStartEvent;
                    text.Source      = textArgs.TextComposition.Source;
                    e.PushInput(text, e.StagingItem);
                }
            }

            // PreviewTextInputUpdate --> TextInputUpdate
            else if (e.StagingItem.Input.RoutedEvent == TextCompositionManager.PreviewTextInputUpdateEvent)
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs)e.StagingItem.Input;
                if (!textArgs.Handled)
                {
                    TextCompositionEventArgs text = new TextCompositionEventArgs(textArgs.Device, textArgs.TextComposition);
                    text.RoutedEvent = TextCompositionManager.TextInputUpdateEvent;
                    text.Source      = textArgs.TextComposition.Source;
                    e.PushInput(text, e.StagingItem);
                }
            }

            // PreviewTextInput --> TextInput
            else if (e.StagingItem.Input.RoutedEvent == TextCompositionManager.PreviewTextInputEvent)
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs)e.StagingItem.Input;
                if (!textArgs.Handled)
                {
                    TextCompositionEventArgs text = new TextCompositionEventArgs(textArgs.Device, textArgs.TextComposition);
                    text.RoutedEvent = TextCompositionManager.TextInputEvent;
                    text.Source      = textArgs.TextComposition.Source;
                    e.PushInput(text, e.StagingItem);
                }
            }

            // TextCompositioniBegin --> TextInput if this is AutomaticComplete.
            else if (e.StagingItem.Input.RoutedEvent == TextCompositionManager.TextInputStartEvent)
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs)e.StagingItem.Input;
                if (!textArgs.Handled)
                {
                    if (textArgs.TextComposition.AutoComplete == TextCompositionAutoComplete.On)
                    {
                        textArgs.Handled = UnsafeCompleteComposition(textArgs.TextComposition);
                    }
                }
            }

            // TextCompositionUpdate --> TextInput if this is AutomaticComplete.
            else if (e.StagingItem.Input.RoutedEvent == TextCompositionManager.TextInputUpdateEvent)
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs)e.StagingItem.Input;
                if (!textArgs.Handled)
                {
                    if ((textArgs.TextComposition == _deadCharTextComposition) &&
                        (_deadCharTextComposition.Composed))
                    {
                        //Clear the _deadCharTextComposition to handle re-entrant cases.
                        DeadCharTextComposition comp = _deadCharTextComposition;
                        _deadCharTextComposition = null;
                        textArgs.Handled         = UnsafeCompleteComposition(comp);
                    }
                }
            }


            // Raw to StartComposition.
            InputReportEventArgs input = e.StagingItem.Input as InputReportEventArgs;

            if (input != null)
            {
                if (input.Report.Type == InputType.Text && input.RoutedEvent == InputManager.InputReportEvent)
                {
                    RawTextInputReport textInput;
                    textInput = (RawTextInputReport)input.Report;

                    //
                    //



                    string inputText = new string(textInput.CharacterCode, 1);
                    bool   fDoneAltNumpadComposition = false;

                    if (_altNumpadcomposition != null)
                    {
                        // Generate TextInput event from WM_CHAR handler.
                        if (inputText.Equals(_altNumpadcomposition.Text))
                        {
                            fDoneAltNumpadComposition = true;
                        }
                        else
                        {
                            // The generated text from InputReport does not matched with _altNumpadcomposition.
                            // Cancel this composition and process the char from InputReport.
                            _altNumpadcomposition.ClearTexts();
                        }

                        _altNumpadcomposition.Complete();
                        ClearAltnumpadComposition();
                    }

                    if (!fDoneAltNumpadComposition)
                    {
                        if (textInput.IsDeadCharacter)
                        {
                            _deadCharTextComposition = new DeadCharTextComposition(_inputManager, (IInputElement)null, inputText, TextCompositionAutoComplete.Off, InputManager.Current.PrimaryKeyboardDevice);
                            if (textInput.IsSystemCharacter)
                            {
                                _deadCharTextComposition.MakeSystem();
                            }
                            else if (textInput.IsControlCharacter)
                            {
                                _deadCharTextComposition.MakeControl();
                            }

                            input.Handled = UnsafeStartComposition(_deadCharTextComposition);
                        }
                        else
                        {
                            if (_deadCharTextComposition != null)
                            {
                                input.Handled = CompleteDeadCharComposition(inputText,
                                                                            textInput.IsSystemCharacter,
                                                                            textInput.IsControlCharacter);
                            }
                            else
                            {
                                TextComposition composition = new TextComposition(_inputManager, (IInputElement)e.StagingItem.Input.Source, inputText, TextCompositionAutoComplete.On, InputManager.Current.PrimaryKeyboardDevice);
                                if (textInput.IsSystemCharacter)
                                {
                                    composition.MakeSystem();
                                }
                                else if (textInput.IsControlCharacter)
                                {
                                    composition.MakeControl();
                                }
                                input.Handled = UnsafeStartComposition(composition);
                            }
                        }
                    }
                }
            }
        }
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            // KeyUp 
            if(e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent)
            { 
                KeyEventArgs keyArgs = (KeyEventArgs) e.StagingItem.Input; 
                if(!keyArgs.Handled)
                { 
                    if(keyArgs.RealKey == Key.LeftAlt || keyArgs.RealKey == Key.RightAlt)
                    {
                        // Make sure both Alt keys are up.
                        ModifierKeys modifiers = keyArgs.KeyboardDevice.Modifiers; 
                        if((modifiers & ModifierKeys.Alt) == 0)
                        { 
                            if(_altNumpadEntryMode) 
                            {
                                _altNumpadEntryMode = false; 

                                // Generate the Unicode equivalent if we
                                // actually entered a number via the numpad.
                                if(_altNumpadEntry != 0) 
                                {
                                    _altNumpadcomposition.ClearTexts(); 
                                    if (_altNumpadConversionMode == AltNumpadConversionMode.OEMCodePage) 
                                    {
                                        _altNumpadcomposition.SetText(GetCurrentOEMCPEncoding(_altNumpadEntry)); 
                                    }
                                    else if ((_altNumpadConversionMode == AltNumpadConversionMode.DefaultCodePage) ||
                                             (_altNumpadConversionMode == AltNumpadConversionMode.HexDefaultCodePage))
                                    { 
                                        _altNumpadcomposition.SetText(CharacterEncoding(InputLanguageManager.Current.CurrentInputLanguage.TextInfo.ANSICodePage, _altNumpadEntry));
                                    } 
                                    else if (_altNumpadConversionMode == AltNumpadConversionMode.HexUnicode) 
                                    {
                                        Char[] chars = new Char[1]; 
                                        chars[0] = (Char) _altNumpadEntry;
                                        _altNumpadcomposition.SetText(new string(chars));
                                    }
                                } 
                            }
                        } 
                    } 
                }
                else 
                {
                    // Someone handled Alt key up event, we cancel Alt-Numpad handling.
                    _altNumpadEntryMode = false;
                    _altNumpadEntry = 0; 
                    _altNumpadConversionMode = AltNumpadConversionMode.OEMCodePage;
                } 
            } 

            // PreviewTextInputBegin --> TextInputStart 
            else if(e.StagingItem.Input.RoutedEvent == TextCompositionManager.PreviewTextInputStartEvent)
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs) e.StagingItem.Input;
                if(!textArgs.Handled) 
                {
                    TextCompositionEventArgs text = new TextCompositionEventArgs(textArgs.Device, textArgs.TextComposition); 
                    text.RoutedEvent=TextCompositionManager.TextInputStartEvent; 
                    text.Source= textArgs.TextComposition.Source;
                    e.PushInput(text, e.StagingItem); 
                }
            }

            // PreviewTextInputUpdate --> TextInputUpdate 
            else if(e.StagingItem.Input.RoutedEvent == TextCompositionManager.PreviewTextInputUpdateEvent)
            { 
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs) e.StagingItem.Input; 
                if(!textArgs.Handled)
                { 
                    TextCompositionEventArgs text = new TextCompositionEventArgs(textArgs.Device, textArgs.TextComposition);
                    text.RoutedEvent=TextCompositionManager.TextInputUpdateEvent;
                    text.Source= textArgs.TextComposition.Source;
                    e.PushInput(text, e.StagingItem); 
                }
            } 
 
            // PreviewTextInput --> TextInput
            else if(e.StagingItem.Input.RoutedEvent == TextCompositionManager.PreviewTextInputEvent) 
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs) e.StagingItem.Input;
                if(!textArgs.Handled)
                { 
                    TextCompositionEventArgs text = new TextCompositionEventArgs(textArgs.Device, textArgs.TextComposition);
                    text.RoutedEvent=TextCompositionManager.TextInputEvent; 
                    text.Source= textArgs.TextComposition.Source; 
                    e.PushInput(text, e.StagingItem);
                } 
            }

            // TextCompositioniBegin --> TextInput if this is AutomaticComplete.
            else if(e.StagingItem.Input.RoutedEvent == TextCompositionManager.TextInputStartEvent) 
            {
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs) e.StagingItem.Input; 
                if(!textArgs.Handled) 
                {
                    if (textArgs.TextComposition.AutoComplete == TextCompositionAutoComplete.On) 
                    {
                        textArgs.Handled = UnsafeCompleteComposition(textArgs.TextComposition);
                    }
                } 
            }
 
            // TextCompositionUpdate --> TextInput if this is AutomaticComplete. 
            else if(e.StagingItem.Input.RoutedEvent == TextCompositionManager.TextInputUpdateEvent)
            { 
                TextCompositionEventArgs textArgs = (TextCompositionEventArgs) e.StagingItem.Input;
                if(!textArgs.Handled)
                {
                    if ((textArgs.TextComposition == _deadCharTextComposition) && 
                         (_deadCharTextComposition.Composed))
                    { 
                        //Clear the _deadCharTextComposition to handle re-entrant cases. 
                        DeadCharTextComposition comp = _deadCharTextComposition;
                        _deadCharTextComposition = null; 
                        textArgs.Handled = UnsafeCompleteComposition(comp);
                    }
                }
            } 

 
            // Raw to StartComposition. 
            InputReportEventArgs input = e.StagingItem.Input as InputReportEventArgs;
            if(input != null) 
            {
                if(input.Report.Type == InputType.Text && input.RoutedEvent == InputManager.InputReportEvent)
                {
                    RawTextInputReport textInput; 
                    textInput = (RawTextInputReport)input.Report;
 
                    // 
                    //
 


                    string inputText = new string(textInput.CharacterCode, 1);
                    bool fDoneAltNumpadComposition = false; 

                    if (_altNumpadcomposition != null) 
                    { 
                        // Generate TextInput event from WM_CHAR handler.
                        if (inputText.Equals(_altNumpadcomposition.Text)) 
                        {
                            fDoneAltNumpadComposition = true;
                        }
                        else 
                        {
                            // The generated text from InputReport does not matched with _altNumpadcomposition. 
                            // Cancel this composition and process the char from InputReport. 
                            _altNumpadcomposition.ClearTexts();
                        } 

                        _altNumpadcomposition.Complete();
                        ClearAltnumpadComposition();
                    } 

                    if (!fDoneAltNumpadComposition) 
                    { 
                        if (textInput.IsDeadCharacter)
                        { 
                            _deadCharTextComposition = new DeadCharTextComposition(_inputManager, (IInputElement)null, inputText , TextCompositionAutoComplete.Off, InputManager.Current.PrimaryKeyboardDevice);
                            if (textInput.IsSystemCharacter)
                            {
                                _deadCharTextComposition.MakeSystem(); 
                            }
                            else if (textInput.IsControlCharacter) 
                            { 
                                _deadCharTextComposition.MakeControl();
                            } 

                            input.Handled = UnsafeStartComposition(_deadCharTextComposition);
                        }
                        else 
                        {
 
                            if(inputText != null) 
                            {
                                if (_deadCharTextComposition != null) 
                                {
                                    _deadCharTextComposition.ClearTexts();
                                    _deadCharTextComposition.SetText(inputText);
                                    _deadCharTextComposition.Composed = true; 
                                    if (textInput.IsSystemCharacter)
                                    { 
                                        _deadCharTextComposition.MakeSystem(); 
                                    }
                                    else if (textInput.IsControlCharacter) 
                                    {
                                        _deadCharTextComposition.MakeControl();
                                    }
                                    input.Handled = UnsafeUpdateComposition(_deadCharTextComposition); 
                                }
                                else 
                                { 
                                    TextComposition composition = new TextComposition(_inputManager, (IInputElement)e.StagingItem.Input.Source, inputText, TextCompositionAutoComplete.On, InputManager.Current.PrimaryKeyboardDevice);
                                    if (textInput.IsSystemCharacter) 
                                    {
                                        composition.MakeSystem();
                                    }
                                    else if (textInput.IsControlCharacter) 
                                    {
                                        composition.MakeControl(); 
                                    } 
                                    input.Handled = UnsafeStartComposition(composition);
                                } 
                            }
                        }
                    }
                } 
            }
        } 
Example #7
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            // PreviewMouseWheel --> MouseWheel
            if (e.StagingItem.Input.RoutedEvent == Mouse.PreviewMouseWheelEvent)
            {
                if (!e.StagingItem.Input.Handled)
                {
                    MouseWheelEventArgs previewWheel = (MouseWheelEventArgs) e.StagingItem.Input;
                    MouseWheelEventArgs wheel = new MouseWheelEventArgs(this, previewWheel.Timestamp, previewWheel.Delta);
                    wheel.RoutedEvent=Mouse.MouseWheelEvent;

                    #if SEND_WHEEL_EVENTS_TO_FOCUS
                    // wheel events are treated as if they came from the
                    // element with keyboard focus
                    wheel.Source = previewWheel.Source;
                    #endif

                    e.PushInput(wheel, e.StagingItem);
                }
            }

            // PreviewMouseDown --> MouseDown
            if (e.StagingItem.Input.RoutedEvent == Mouse.PreviewMouseDownEvent)
            {
                if (!e.StagingItem.Input.Handled)
                {
                    MouseButtonEventArgs previewDown = (MouseButtonEventArgs) e.StagingItem.Input;
                    MouseButtonEventArgs down = new MouseButtonEventArgs(this, previewDown.Timestamp, previewDown.ChangedButton, GetStylusDevice(e.StagingItem));
                    down.ClickCount = previewDown.ClickCount;
                    down.RoutedEvent=Mouse.MouseDownEvent;
                    e.PushInput(down, e.StagingItem);
                }
            }

            // PreviewMouseUp --> MouseUp
            if (e.StagingItem.Input.RoutedEvent == Mouse.PreviewMouseUpEvent)
            {
                if (!e.StagingItem.Input.Handled)
                {
                    MouseButtonEventArgs previewUp = (MouseButtonEventArgs) e.StagingItem.Input;
                    MouseButtonEventArgs up = new MouseButtonEventArgs(this, previewUp.Timestamp, previewUp.ChangedButton, GetStylusDevice(e.StagingItem));
                    up.RoutedEvent=Mouse.MouseUpEvent;
                    e.PushInput(up, e.StagingItem);
                }
            }

            // PreviewMouseMove --> MouseMove
            if (e.StagingItem.Input.RoutedEvent == Mouse.PreviewMouseMoveEvent)
            {
                if (!e.StagingItem.Input.Handled)
                {
                    MouseEventArgs previewMove = (MouseEventArgs) e.StagingItem.Input;
                    MouseEventArgs move = new MouseEventArgs(this, previewMove.Timestamp, GetStylusDevice(e.StagingItem));
                    move.RoutedEvent=Mouse.MouseMoveEvent;
                    e.PushInput(move, e.StagingItem);
                }
            }

            // We are finished processing the QueryCursor event.  Just update the
            // mouse cursor to be what was decided during the event route.
            if (e.StagingItem.Input.RoutedEvent == Mouse.QueryCursorEvent)
            {

                QueryCursorEventArgs queryCursor = (QueryCursorEventArgs)e.StagingItem.Input;


                SetCursor(queryCursor.Cursor);

            }

            if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
            {
                InputReportEventArgs inputReportEventArgs = e.StagingItem.Input as InputReportEventArgs;

                if (!inputReportEventArgs.Handled && inputReportEventArgs.Report.Type == InputType.Mouse)
                {
                    RawMouseInputReport rawMouseInputReport = (RawMouseInputReport) inputReportEventArgs.Report;

                    // Only process mouse input that is from our active visual manager.
                    if ((_inputSource != null) && (rawMouseInputReport.InputSource == _inputSource.Value))
                    {
                        // In general, this is where we promote the non-redundant
                        // reported actions to our premier events.
                        RawMouseActions actions = GetNonRedundantActions(e);

                        // Raw Activate --> Raw MouseMove
                        // Whenever the mouse device is activated we need to
                        // cause a mouse move so that elements realize that
                        // the mouse is over them again.  In most cases, the
                        // action that caused the mouse to activate is a move,
                        // but this is to guard against any other cases.
                        if ((actions & RawMouseActions.Activate) == RawMouseActions.Activate)
                        {
                            Synchronize();
                        }

                        // Raw --> PreviewMouseWheel
                        if ((actions & RawMouseActions.VerticalWheelRotate) == RawMouseActions.VerticalWheelRotate) // 
                        {
                            MouseWheelEventArgs previewWheel = new MouseWheelEventArgs(this, rawMouseInputReport.Timestamp, rawMouseInputReport.Wheel);

                            previewWheel.RoutedEvent=Mouse.PreviewMouseWheelEvent;

                            #if SEND_WHEEL_EVENTS_TO_FOCUS
                            // wheel events are treated as if they came from the
                            // element with keyboard focus
                            DependencyObject focus = Keyboard.FocusedElement as DependencyObject;
                            if (focus != null)
                            {
                                previewWheel.Source = focus;
                            }
                            #endif

                            e.PushInput(previewWheel, e.StagingItem);
                        }

                        // Raw --> PreviewMouseDown
                        if ((actions & RawMouseActions.Button1Press) == RawMouseActions.Button1Press)
                        {
                            MouseButtonEventArgs previewDown = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.Left, GetStylusDevice(e.StagingItem));

                            previewDown.RoutedEvent=Mouse.PreviewMouseDownEvent;
                            e.PushInput(previewDown, e.StagingItem);
                        }

                        // Raw --> PreviewMouseUp
                        if ((actions & RawMouseActions.Button1Release) == RawMouseActions.Button1Release)
                        {
                            MouseButtonEventArgs previewUp = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.Left, GetStylusDevice(e.StagingItem));

                            previewUp.RoutedEvent=Mouse.PreviewMouseUpEvent;
                            e.PushInput(previewUp, e.StagingItem);
                        }

                        // Raw --> PreviewMouseDown
                        if ((actions & RawMouseActions.Button2Press) == RawMouseActions.Button2Press)
                        {
                            MouseButtonEventArgs previewDown = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.Right, GetStylusDevice(e.StagingItem));

                            previewDown.RoutedEvent=Mouse.PreviewMouseDownEvent;
                            e.PushInput(previewDown, e.StagingItem);
                        }

                        // Raw --> PreviewMouseUp
                        if ((actions & RawMouseActions.Button2Release) == RawMouseActions.Button2Release)
                        {
                            MouseButtonEventArgs previewUp = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.Right, GetStylusDevice(e.StagingItem));

                            previewUp.RoutedEvent=Mouse.PreviewMouseUpEvent;
                            e.PushInput(previewUp, e.StagingItem);
                        }

                        // Raw --> PreviewMouseDown
                        if ((actions & RawMouseActions.Button3Press) == RawMouseActions.Button3Press)
                        {
                            MouseButtonEventArgs previewDown = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.Middle, GetStylusDevice(e.StagingItem));

                            previewDown.RoutedEvent=Mouse.PreviewMouseDownEvent;
                            e.PushInput(previewDown, e.StagingItem);
                        }

                        // Raw --> PreviewMouseUp
                        if ((actions & RawMouseActions.Button3Release) == RawMouseActions.Button3Release)
                        {
                            MouseButtonEventArgs previewUp = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.Middle, GetStylusDevice(e.StagingItem));

                            previewUp.RoutedEvent=Mouse.PreviewMouseUpEvent;
                            e.PushInput(previewUp, e.StagingItem);
                        }

                        // Raw --> PreviewMouseDown
                        if ((actions & RawMouseActions.Button4Press) == RawMouseActions.Button4Press)
                        {
                            MouseButtonEventArgs previewDown = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.XButton1, GetStylusDevice(e.StagingItem));

                            previewDown.RoutedEvent=Mouse.PreviewMouseDownEvent;
                            e.PushInput(previewDown, e.StagingItem);
                        }

                        // Raw --> PreviewMouseUp
                        if ((actions & RawMouseActions.Button4Release) == RawMouseActions.Button4Release)
                        {
                            MouseButtonEventArgs previewUp = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.XButton1, GetStylusDevice(e.StagingItem));

                            previewUp.RoutedEvent=Mouse.PreviewMouseUpEvent;
                            e.PushInput(previewUp, e.StagingItem);
                        }

                        // Raw --> PreviewMouseDown
                        if ((actions & RawMouseActions.Button5Press) == RawMouseActions.Button5Press)
                        {
                            MouseButtonEventArgs previewDown = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.XButton2, GetStylusDevice(e.StagingItem));

                            previewDown.RoutedEvent=Mouse.PreviewMouseDownEvent;
                            e.PushInput(previewDown, e.StagingItem);
                        }

                        // Raw --> PreviewMouseUp
                        if ((actions & RawMouseActions.Button5Release) == RawMouseActions.Button5Release)
                        {
                            MouseButtonEventArgs previewUp = new MouseButtonEventArgs(this, rawMouseInputReport.Timestamp, MouseButton.XButton2, GetStylusDevice(e.StagingItem));

                            previewUp.RoutedEvent=Mouse.PreviewMouseUpEvent;
                            e.PushInput(previewUp, e.StagingItem);
                        }

                        // Raw --> PreviewMouseMove
                        if ((actions & RawMouseActions.AbsoluteMove) == RawMouseActions.AbsoluteMove) // 
                        {
                            MouseEventArgs previewMove = new MouseEventArgs(this, rawMouseInputReport.Timestamp, GetStylusDevice(e.StagingItem));

                            previewMove.RoutedEvent=Mouse.PreviewMouseMoveEvent;
                            e.PushInput(previewMove, e.StagingItem);
                        }

                        // Raw --> QueryCursor
                        if ((actions & RawMouseActions.QueryCursor) == RawMouseActions.QueryCursor)
                        {
                            inputReportEventArgs.Handled = UpdateCursorPrivate();
                        }
                    }
                }
            }
        }
Example #8
0
 private void PostProcessInput( object sender, ProcessInputEventArgs e )
 {
     if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
     {
         if (!e.StagingItem.Input.Handled)
         {
             InputReportEventArgs inputReportEventArgs = e.StagingItem.Input as InputReportEventArgs;
             if (inputReportEventArgs != null)
             {
                 RawAppCommandInputReport rawAppCommandInputReport = inputReportEventArgs.Report as RawAppCommandInputReport;
                 if (rawAppCommandInputReport != null)
                 {
                     IInputElement commandTarget = e.StagingItem.Input.OriginalSource as IInputElement;
                     if (commandTarget != null)
                     {
                         RoutedCommand command = GetRoutedCommand(rawAppCommandInputReport.AppCommand);
                         if (command != null)
                         {
                             // Send the app command to the tree to be handled by UIElements and ContentElements
                             // that will forward the event to CommandManager.
                             CommandDeviceEventArgs args = new CommandDeviceEventArgs(this, rawAppCommandInputReport.Timestamp, command);
                             args.RoutedEvent = CommandDeviceEvent;
                             args.Source = commandTarget;
                             e.PushInput(args, e.StagingItem);
                         }
                     }
                 }
             }
         }
     }
     else if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent ||
              e.StagingItem.Input.RoutedEvent == Mouse.MouseUpEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.GotKeyboardFocusEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.LostKeyboardFocusEvent)
     {
         CommandManager.InvalidateRequerySuggested();
     }
 }
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            InputEventArgs inputEventArgs = e.StagingItem.Input;
            if ((inputEventArgs != null) && (inputEventArgs.Device == this))
            {
                if (inputEventArgs.Handled)
                {
                    RoutedEvent routedEvent = inputEventArgs.RoutedEvent;

                    if (routedEvent == Touch.PreviewTouchMoveEvent ||
                        routedEvent == Touch.TouchMoveEvent)
                    {
                        _lastMoveHandled = true;
                    }
                    else if (routedEvent == Touch.PreviewTouchDownEvent ||
                        routedEvent == Touch.TouchDownEvent)
                    {
                        _lastDownHandled = true;
                    }
                    else if (routedEvent == Touch.PreviewTouchUpEvent ||
                        routedEvent == Touch.TouchUpEvent)
                    {
                        _lastUpHandled = true;
                    }
                }
                else
                {
                    bool forManipulation;
                    RoutedEvent promotedTouchEvent = PromotePreviewToMain(inputEventArgs.RoutedEvent, out forManipulation);
                    if (promotedTouchEvent != null)
                    {
                        TouchEventArgs promotedTouchEventArgs = CreateEventArgs(promotedTouchEvent);
                        e.PushInput(promotedTouchEventArgs, e.StagingItem);
                    }
                    else if (forManipulation)
                    {
                        UIElement manipulatableElement = GetManipulatableElement();
                        if (manipulatableElement != null)
                        {
                            PromoteMainToManipulation(manipulatableElement, (TouchEventArgs)inputEventArgs);
                        }
                    }
                }
            }
        }
Example #10
0
		static void PromotePreviewToMain(ProcessInputEventArgs e, InputEventArgs input)
		{
			ContactEventArgs previewArgs = (ContactEventArgs)input;
			RoutedEvent mainEvent = GetMainEventFromPreviewEvent(input.RoutedEvent);
			if (mainEvent != null)
			{
				ContactEventArgs mainArgs;
				if (mainEvent == MultitouchScreen.NewContactEvent || mainEvent == MultitouchScreen.PreviewNewContactEvent)
				{
					NewContactEventArgs newContactEventArgs = (NewContactEventArgs)previewArgs;
					mainArgs = new NewContactEventArgs(newContactEventArgs.Contact, previewArgs.Timestamp);
				}
				else
					mainArgs = new ContactEventArgs(previewArgs.Contact, previewArgs.Timestamp);
				mainArgs.RoutedEvent = mainEvent;
				mainArgs.Source = previewArgs.Source;
				e.PushInput(mainArgs, e.StagingItem);
			}
		}
Example #11
0
		void PromoteRawToPreview(ProcessInputEventArgs e, RawMultitouchReport report)
		{
			ContactContext context = report.Context;
			RoutedEvent routedEvent = GetPreviewEventFromRawMultitouchState(context.Contact.State);
			if (report.Context.OverElement != null && routedEvent != null)
			{
				Contact contact = ContactsManager.ExistingContacts[report.Context.Contact.Id];
				ContactEventArgs args;
				if (routedEvent == MultitouchScreen.PreviewNewContactEvent)
					args = new NewContactEventArgs(contact, report.Timestamp);
				else
					args = new ContactEventArgs(contact, report.Timestamp);
				args.RoutedEvent = routedEvent;
				args.Source = report.Context.OverElement;
				e.PushInput(args, e.StagingItem);
			}
		}
Example #12
0
		void inputManager_PostProcessInput(object sender, ProcessInputEventArgs e)
		{
			InputEventArgs input = e.StagingItem.Input;
			if (input.RoutedEvent == PreviewRawInputEvent && !input.Handled)
				PromoteRawToPreview(e, (RawMultitouchReport)input);
			else if (input.Device != null && input.Device.GetType() == contactType)
			{
				if (!input.Handled)
					PromotePreviewToMain(e, input);
				
				if (input.RoutedEvent == MultitouchScreen.ContactRemovedEvent)
				{
					ContactEventArgs args = (ContactEventArgs)input;
					RawMultitouchReport report = args.Contact.InputArgs.Clone();
					report.CleanUp = true;
					e.PushInput(report, e.StagingItem);
				}
			}
		}
Example #13
0
        void PromotePreviewToMain(ProcessInputEventArgs e) 
        { 
            if (!e.StagingItem.Input.Handled)
            { 
                RoutedEvent eventMain = GetMainEventFromPreviewEvent(e.StagingItem.Input.RoutedEvent);
                if (eventMain != null)
                {
                    StylusEventArgs eventArgsPreview = (StylusEventArgs)e.StagingItem.Input; 
                    StylusDevice stylusDevice = eventArgsPreview.InputReport.StylusDevice;
 
                    StylusEventArgs eventArgsMain; 
                    if (eventMain == Stylus.StylusDownEvent ||
                        eventMain == Stylus.PreviewStylusDownEvent) 
                    {
                        StylusDownEventArgs downEventArgsPreview = (StylusDownEventArgs)eventArgsPreview;
                        eventArgsMain = new StylusDownEventArgs(stylusDevice, eventArgsPreview.Timestamp);
                    } 
                    else if (eventMain == Stylus.StylusButtonDownEvent ||
                        eventMain == Stylus.StylusButtonUpEvent) 
                    { 
                        StylusButtonEventArgs buttonEventArgsPreview = (StylusButtonEventArgs)eventArgsPreview;
                        eventArgsMain = new StylusButtonEventArgs(stylusDevice, eventArgsPreview.Timestamp, buttonEventArgsPreview.StylusButton); 
                    }
                    else if (eventMain != Stylus.StylusSystemGestureEvent)
                    {
                        eventArgsMain = new StylusEventArgs(stylusDevice, eventArgsPreview.Timestamp); 
                    }
                    else 
                    { 
                        StylusSystemGestureEventArgs previewSystemGesture = (StylusSystemGestureEventArgs)eventArgsPreview;
                        eventArgsMain = new StylusSystemGestureEventArgs(stylusDevice, 
                                                                         previewSystemGesture.Timestamp,
                                                                         previewSystemGesture.SystemGesture,
                                                                         previewSystemGesture.GestureX,
                                                                         previewSystemGesture.GestureY, 
                                                                         previewSystemGesture.ButtonState);
                    } 
                    eventArgsMain.InputReport = eventArgsPreview.InputReport; 
                    eventArgsMain.RoutedEvent = eventMain;
                    e.PushInput(eventArgsMain, e.StagingItem); 
                }
            }
            else
            { 
                // A TouchDevice is activated before TouchDown and deactivated after TouchUp
                // But if PreviewStylusUp event is handled by the user, it will 
                // never be promoted to TouchUp event leaving the TouchDevice in inconsistent 
                // active state. Hence deactivating touch device if it is active.
                StylusEventArgs stylusEventArgs = e.StagingItem.Input as StylusEventArgs; 
                if (stylusEventArgs != null &&
                    stylusEventArgs.RoutedEvent == Stylus.PreviewStylusUpEvent &&
                    stylusEventArgs.StylusDevice.TouchDevice.IsActive)
                { 
                    stylusEventArgs.StylusDevice.TouchDevice.OnDeactivate();
                } 
            } 
        }
Example #14
0
 void PromoteRawToPreview(RawStylusInputReport report, ProcessInputEventArgs e)
 {
     RoutedEvent routedEvent = GetPreviewEventFromRawStylusActions(report.Actions); 
     if (routedEvent != null && report.StylusDevice != null && !report.StylusDevice.IgnoreStroke)
     { 
         StylusEventArgs args; 
         if (routedEvent != Stylus.PreviewStylusSystemGestureEvent)
         { 
             if (routedEvent == Stylus.PreviewStylusDownEvent)
             {
                 args = new StylusDownEventArgs(report.StylusDevice, report.Timestamp);
             } 
             else
             { 
                 args = new StylusEventArgs(report.StylusDevice, report.Timestamp); 
              }
         } 
         else
         {
             RawStylusSystemGestureInputReport reportSg = (RawStylusSystemGestureInputReport)report;
             args = new StylusSystemGestureEventArgs(report.StylusDevice, 
                                                     report.Timestamp,
                                                     reportSg.SystemGesture, 
                                                     reportSg.GestureX, 
                                                     reportSg.GestureY,
                                                     reportSg.ButtonState); 
         }
         args.InputReport = report;
         args.RoutedEvent= routedEvent;
         e.PushInput(args, e.StagingItem); 
     }
 }