Exemplo n.º 1
0
        private static bool UnsafeCompleteComposition(TextComposition composition)
        {
            if (composition == null)
            {
                throw new ArgumentNullException("composition");
            }

            if (composition._InputManager == null)
            {
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_NoInputManager, "composition"));
            }

            if (composition.Stage == TextCompositionStage.None)
            {
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_TextCompositionNotStarted, "composition"));
            }

            if (composition.Stage == TextCompositionStage.Done)
            {
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_TextCompositionHasDone, "composition"));
            }

            composition.Stage = TextCompositionStage.Done;
            TextCompositionEventArgs textargs = new TextCompositionEventArgs(composition._InputDevice, composition);

            textargs.RoutedEvent = TextCompositionManager.PreviewTextInputEvent;
            textargs.Source      = composition.Source;
            return(composition._InputManager.ProcessInput(textargs));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Constructs an instance of the TextInputEventArgs class.
        /// </summary>
        /// <param name="inputDevice">
        ///     The input device to associate with this event.
        /// </param>
        /// <param name="composition">
        ///     The TextComposition object that contains the composition text and the composition state.
        /// </param>
        public TextCompositionEventArgs(InputDevice inputDevice, TextComposition composition) : base(inputDevice, Environment.TickCount)
        {
            if (composition == null)
            {
                throw new ArgumentNullException("composition");
            }

            _composition = composition;
        }
        /// <summary> 
        ///     Constructs an instance of the TextInputEventArgs class.
        /// </summary> 
        /// <param name="inputDevice"> 
        ///     The input device to associate with this event.
        /// </param> 
        /// <param name="composition">
        ///     The TextComposition object that contains the composition text and the composition state.
        /// </param>
        public TextCompositionEventArgs(InputDevice inputDevice, TextComposition composition) : base(inputDevice, Environment.TickCount) 
        {
            if (composition == null) 
            { 
                throw new ArgumentNullException("composition");
            } 

            _composition = composition;
        }
        static void source_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            var c = sender as Control;

            var target = GetTarget(c);

            var forwarded_textInput = new TextComposition(InputManager.Current, Keyboard.FocusedElement, e.Text);

            var new_e = new TextCompositionEventArgs(e.Device as KeyboardDevice, forwarded_textInput)
            {
                RoutedEvent = TextCompositionManager.TextInputEvent
            };

            target.RaiseEvent(new_e);
        }
Exemplo n.º 5
0
 public static bool StartComposition(TextComposition composition)
 {
     return(UnsafeStartComposition(composition));
 }
Exemplo n.º 6
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(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);
                                } 
                            }
                        }
                    }
                } 
            }
        } 
 public TextCompositionEventArgs(InputDevice inputDevice, TextComposition composition) : base (default(InputDevice), default(int))
 {
 }
Exemplo n.º 8
0
        /// <summary>
        /// Simulate the given KeyInput being sent to the given UIElement 
        /// </summary>
        public void SendKeyStroke(UIElement target, KeyInput keyInput)
        {
            Key key;
            ModifierKeys modKeys;
            if (!TryGetKeyForKeyInput(keyInput, out key, out modKeys))
            {
                throw new Exception();
            }

            ModifierKeysImpl = modKeys;
            try
            {
                // First step is preview key down 
                var keyEventArgs = new KeyEventArgs(
                    this,
                    new MockPresentationSource(),
                    0,
                    key);

                if (!RaiseEvents(target, keyEventArgs, Keyboard.PreviewKeyDownEvent, Keyboard.KeyDownEvent))
                {
                    var raiseUp = true;
                    if (char.IsLetterOrDigit(keyInput.Char))
                    {
                        var textComposition = new TextComposition(InputManager.Current, target, keyInput.Char.ToString());
                        var textCompositionEventArgs = new TextCompositionEventArgs(this, textComposition);
                        raiseUp = !RaiseEvents(target, textCompositionEventArgs, TextCompositionManager.TextInputEvent);
                    }

                    if (raiseUp)
                    {
                        RaiseEvents(target, keyEventArgs, Keyboard.PreviewKeyUpEvent, Keyboard.KeyUpEvent);
                    }
                }
            }
            finally
            {
                ModifierKeysImpl = ModifierKeys.None;
            }
        }
 public static bool StartComposition(TextComposition composition)
 {
   return default(bool);
 }
Exemplo n.º 10
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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        private TextComposition CreateTextComposition(string text)
        {
            var textComposition = new TextComposition(InputManager.Current, _wpfTextView.VisualElement, text);
            if (text.Length == 1 && Char.IsControl(text[0]))
            {
                var type = typeof(TextComposition);
                var method = type.GetMethod("MakeControl", BindingFlags.Instance | BindingFlags.NonPublic);
                method.Invoke(textComposition, new object[] { });
            }

            return textComposition;
        }
Exemplo n.º 12
0
 public static bool StartComposition(TextComposition composition)
 {
     return(default(bool));
 }
Exemplo n.º 13
0
		public TextCompositionEventArgs (InputDevice inputDevice, TextComposition composition)
			: base (inputDevice, /* XXX */ 0)
		{
		}
Exemplo n.º 14
0
 public static bool UpdateComposition(TextComposition composition)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public TextCompositionEventArgs(InputDevice inputDevice, TextComposition composition)
     : base(inputDevice, /* XXX */ 0)
 {
 }
Exemplo n.º 16
0
 public static bool UpdateComposition(TextComposition composition)
 {
     return(UnsafeUpdateComposition(composition));
 }
Exemplo n.º 17
0
 public static bool CompleteComposition(TextComposition composition)
 {
     return(UnsafeCompleteComposition(composition));
 }
Exemplo n.º 18
0
 public static bool StartComposition(TextComposition composition) 
 {
     return UnsafeStartComposition(composition);
 }
Exemplo n.º 19
0
        private void PreProcessInput(object sender, PreProcessInputEventArgs e)
        {
            // KeyDown --> Alt Numpad
            //
            // We eat Alt-NumPat keys and handle them by ourselves. Avalon has its own acceralator handler
            // and it may have a corrision with Win32k's AltNumPad handling. As a result, the AltNumPad cache
            // in Win32k's ToUnicodeEx() could be broken.
            //
            if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyDownEvent)
            {
                KeyEventArgs keyArgs = (KeyEventArgs)e.StagingItem.Input;
                if (!keyArgs.Handled)
                {
                    if (!_altNumpadEntryMode)
                    {
                        EnterAltNumpadEntryMode(keyArgs.RealKey);
                    }
                    else
                    {
                        if (HandleAltNumpadEntry(keyArgs.RealKey, keyArgs.ScanCode, keyArgs.IsExtendedKey))
                        {
                            if (_altNumpadcomposition == null)
                            {
                                _altNumpadcomposition = new TextComposition(_inputManager, (IInputElement)keyArgs.Source, "", TextCompositionAutoComplete.Off, keyArgs.Device);
                                keyArgs.Handled       = UnsafeStartComposition(_altNumpadcomposition);
                            }
                            else
                            {
                                _altNumpadcomposition.ClearTexts();
                                keyArgs.Handled = UnsafeUpdateComposition(_altNumpadcomposition);
                            }

                            // We ate this key for AltNumPad entry. None will be able to handle this.
                            e.Cancel();
                        }
                        else
                        {
                            // alt numpad entry was reset so composition needs to be finalized.
                            if (_altNumpadcomposition != null)
                            {
                                _altNumpadcomposition.ClearTexts();
                                _altNumpadcomposition.Complete();
                                ClearAltnumpadComposition();
                            }
                        }
                    }
                }
            }

            if (e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyDownEvent)
            {
                KeyEventArgs keyArgs = (KeyEventArgs)e.StagingItem.Input;
                //This makes sure that deadChar's do not get handled in commands
                //As a result they are unhandled KeyDown events that are sent to translate input.
                //
                if (!keyArgs.Handled &&
                    (_deadCharTextComposition != null) &&
                    (_deadCharTextComposition.Stage == TextCompositionStage.Started))
                {
                    keyArgs.MarkDeadCharProcessed();
                }
            }
        }
Exemplo n.º 20
0
 public static bool UpdateComposition(TextComposition composition)
 { 
     return UnsafeUpdateComposition(composition);
 }
 public static bool CompleteComposition(TextComposition composition)
 {
   return default(bool);
 }
Exemplo n.º 22
0
 public static bool CompleteComposition(TextComposition composition) 
 {
     return UnsafeCompleteComposition(composition); 
 }
Exemplo n.º 23
0
        private static bool UnsafeCompleteComposition(TextComposition composition)
        { 
            if (composition == null)
            { 
                throw new ArgumentNullException("composition"); 
            }
 
            if (composition._InputManager == null)
            {
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_NoInputManager, "composition"));
            } 

            if (composition.Stage == TextCompositionStage.None) 
            { 
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_TextCompositionNotStarted, "composition"));
            } 

            if (composition.Stage == TextCompositionStage.Done)
            {
                throw new ArgumentException(SR.Get(SRID.TextCompositionManager_TextCompositionHasDone, "composition")); 
            }
 
            composition.Stage = TextCompositionStage.Done; 
            TextCompositionEventArgs textargs = new TextCompositionEventArgs(composition._InputDevice, composition);
            textargs.RoutedEvent=TextCompositionManager.PreviewTextInputEvent; 
            textargs.Source= composition.Source;
            return composition._InputManager.ProcessInput(textargs);
        }
Exemplo n.º 24
0
        private void PreProcessInput(object sender, PreProcessInputEventArgs e) 
        {
            // KeyDown --> Alt Numpad
            //
            // We eat Alt-NumPat keys and handle them by ourselves. Avalon has its own acceralator handler 
            // and it may have a corrision with Win32k's AltNumPad handling. As a result, the AltNumPad cache
            // in Win32k's ToUnicodeEx() could be broken. 
            // 
            if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyDownEvent)
            { 
                KeyEventArgs keyArgs = (KeyEventArgs) e.StagingItem.Input;
                if (!keyArgs.Handled)
                {
                    if (!_altNumpadEntryMode) 
                    {
                        EnterAltNumpadEntryMode(keyArgs.RealKey); 
                    } 
                    else
                    { 
                        if (HandleAltNumpadEntry(keyArgs.RealKey, keyArgs.ScanCode, keyArgs.IsExtendedKey))
                        {
                            if (_altNumpadcomposition == null)
                            { 
                                _altNumpadcomposition = new TextComposition(_inputManager, (IInputElement)keyArgs.Source, "", TextCompositionAutoComplete.Off, keyArgs.Device);
                                keyArgs.Handled = UnsafeStartComposition(_altNumpadcomposition); 
                            } 
                            else
                            { 
                                _altNumpadcomposition.ClearTexts();
                                keyArgs.Handled = UnsafeUpdateComposition(_altNumpadcomposition);
                            }
 
                            // We ate this key for AltNumPad entry. None will be able to handle this.
                            e.Cancel(); 
                        } 
                        else
                        { 
                            // alt numpad entry was reset so composition needs to be finalized.
                            if (_altNumpadcomposition != null)
                            {
                                _altNumpadcomposition.ClearTexts(); 
                                _altNumpadcomposition.Complete();
                                ClearAltnumpadComposition(); 
                            } 
                        }
                    } 


                }
 

            } 
 
            if (e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyDownEvent)
            { 
                KeyEventArgs keyArgs = (KeyEventArgs)e.StagingItem.Input;
                //This makes sure that deadChar's do not get handled in commands
                //As a result they are unhandled KeyDown events that are sent to translate input.
                // 
                if (!keyArgs.Handled
                    && (_deadCharTextComposition != null) 
                    && (_deadCharTextComposition.Stage == TextCompositionStage.Started)) 
                {
                    keyArgs.MarkDeadCharProcessed(); 
                }
            }
        }
Exemplo n.º 25
0
		/// <summary>
		/// Performs text input.
		/// This raises the <see cref="TextEntering"/> event, replaces the selection with the text,
		/// and then raises the <see cref="TextEntered"/> event.
		/// </summary>
		public void PerformTextInput(string text)
		{
			TextComposition textComposition = new TextComposition(InputManager.Current, this, text);
			TextCompositionEventArgs e = new TextCompositionEventArgs(Keyboard.PrimaryDevice, textComposition);
			e.RoutedEvent = TextInputEvent;
			PerformTextInput(e);
		}
Exemplo n.º 26
0
		public static bool UpdateComposition (TextComposition composition)
		{
			throw new NotImplementedException ();
		}