/* * editContextを作り直します。 */ void UpdateEditContext() { if (DesignMode.DesignModeEnabled) { // ビューデザイナーの中で動作している場合は何もしない。 return; } // CoreTextEditContextオブジェクトを作ります。 // IMEとのやりとりはこのオブジェクトを使います。 Debug.WriteLine("--->> CreateEditContext"); editContext = textServiceManager.CreateEditContext(); // IMEの各種のイベントハンドラを登録します。 Debug.WriteLine("--->> Subscribe IME Event"); editContext.CompositionStarted += EditContext_CompositionStarted; editContext.CompositionCompleted += EditContext_CompositionCompleted; editContext.FocusRemoved += EditContext_FocusRemoved; editContext.LayoutRequested += EditContext_LayoutRequested; editContext.NotifyFocusLeaveCompleted += EditContext_NotifyFocusLeaveCompleted; editContext.SelectionRequested += EditContext_SelectionRequested; editContext.SelectionUpdating += EditContext_SelectionUpdating; editContext.TextRequested += EditContext_TextRequested; editContext.TextUpdating += EditContext_TextUpdating; editContext.FormatUpdating += EditContext_FormatUpdating; // IMEにフォーカスの取得を知らせます。 Debug.WriteLine("--->> NotifyFocusEnter"); editContext.NotifyFocusEnter(); }
public TextActionsTest() { Helper.ExecuteOnUIThread(() => { CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView(); _textDocument = new TextDocument(manager.CreateEditContext()); }).Wait(); }
public MyEditBox() { this.InitializeComponent(); _coreWindow = CoreWindow.GetForCurrentThread(); _coreWindow.KeyDown += CoreWindow_KeyDown; _coreWindow.PointerPressed += CoreWindow_PointerPressed; CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView(); _editContext = manager.CreateEditContext(); // Get the Input Pane so we can programmatically hide and show it. _inputPane = InputPane.GetForCurrentView(); _editContext.InputScope = CoreTextInputScope.Text; _editContext.TextRequested += EditContext_TextRequested; // The system raises this event to request the current selection. _editContext.SelectionRequested += EditContext_SelectionRequested; // The system raises this event when it wants the edit control to remove focus. _editContext.FocusRemoved += EditContext_FocusRemoved; // The system raises this event to update text in the edit control. _editContext.TextUpdating += EditContext_TextUpdating; // The system raises this event to change the selection in the edit control. _editContext.SelectionUpdating += EditContext_SelectionUpdating; // The system raises this event to request layout information. // This is used to help choose a position for the IME candidate window. _editContext.LayoutRequested += EditContext_LayoutRequested; // The system raises this event to notify the edit control // that the string composition has started. _editContext.CompositionStarted += EditContext_CompositionStarted; // The system raises this event to notify the edit control // that the string composition is finished. _editContext.CompositionCompleted += EditContext_CompositionCompleted; }
public CustomEditControl() { this.InitializeComponent(); // The CoreTextEditContext processes text input, but other keys are // the apps's responsibility. _coreWindow = CoreWindow.GetForCurrentThread(); _coreWindow.KeyDown += CoreWindow_KeyDown; _coreWindow.PointerPressed += CoreWindow_PointerPressed; // Create a CoreTextEditContext for our custom edit control. CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView(); _editContext = manager.CreateEditContext(); // Get the Input Pane so we can programmatically hide and show it. _inputPane = InputPane.GetForCurrentView(); // For demonstration purposes, this sample sets the Input Pane display policy to Manual // so that it can manually show the software keyboard when the control gains focus and // dismiss it when the control loses focus. If you leave the policy as Automatic, then // the system will hide and show the Input Pane for you. Note that on Desktop, you will // need to implement the UIA text pattern to get expected automatic behavior. _editContext.InputPaneDisplayPolicy = CoreTextInputPaneDisplayPolicy.Manual; // Set the input scope to Text because this text box is for any text. // This also informs software keyboards to show their regular // text entry layout. There are many other input scopes and each will // inform a keyboard layout and text behavior. _editContext.InputScope = CoreTextInputScope.Text; // The system raises this event to request a specific range of text. _editContext.TextRequested += EditContext_TextRequested; // The system raises this event to request the current selection. _editContext.SelectionRequested += EditContext_SelectionRequested; // The system raises this event when it wants the edit control to remove focus. _editContext.FocusRemoved += EditContext_FocusRemoved; // The system raises this event to update text in the edit control. _editContext.TextUpdating += EditContext_TextUpdating; // The system raises this event to change the selection in the edit control. _editContext.SelectionUpdating += EditContext_SelectionUpdating; // The system raises this event when it wants the edit control // to apply formatting on a range of text. _editContext.FormatUpdating += EditContext_FormatUpdating; // The system raises this event to request layout information. // This is used to help choose a position for the IME candidate window. _editContext.LayoutRequested += EditContext_LayoutRequested; // The system raises this event to notify the edit control // that the string composition has started. _editContext.CompositionStarted += EditContext_CompositionStarted; // The system raises this event to notify the edit control // that the string composition is finished. _editContext.CompositionCompleted += EditContext_CompositionCompleted; // The system raises this event when the NotifyFocusLeave operation has // completed. Our sample does not use this event. // _editContext.NotifyFocusLeaveCompleted += EditContext_NotifyFocusLeaveCompleted; // Set our initial UI. UpdateTextUI(); UpdateFocusUI(); }
public MainPage() { this.InitializeComponent(); var textBoxCandidates = this.FindName("candidateBox") as TextBox; textBoxCandidates.IsEnabled = false; _coreWindow = CoreWindow.GetForCurrentThread(); _coreWindow.KeyDown += CoreWindow_KeyDown; _coreWindow.CharacterReceived += CoreWindow_CharacterReceived; _coreWindow.Activated += _coreWindow_Activated; // Create a CoreTextEditContext for our custom edit control. CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView(); _editContext = manager.CreateEditContext(); // Get the Input Pane so we can programmatically hide and show it. _inputPane = InputPane.GetForCurrentView(); _inputPane.Showing += (o, e) => _virtualKeyboardHeight = (int)e.OccludedRect.Height; _inputPane.Hiding += (o, e) => _virtualKeyboardHeight = 0; // For demonstration purposes, this sample sets the Input Pane display policy to Manual // so that it can manually show the software keyboard when the control gains focus and // dismiss it when the control loses focus. If you leave the policy as Automatic, then // the system will hide and show the Input Pane for you. Note that on Desktop, you will // need to implement the UIA text pattern to get expected automatic behavior. _editContext.InputPaneDisplayPolicy = CoreTextInputPaneDisplayPolicy.Manual; // Set the input scope to Text because this text box is for any text. // This also informs software keyboards to show their regular // text entry layout. There are many other input scopes and each will // inform a keyboard layout and text behavior. _editContext.InputScope = CoreTextInputScope.Text; // The system raises this event to request a specific range of text. _editContext.TextRequested += EditContext_TextRequested; // The system raises this event to request the current selection. _editContext.SelectionRequested += EditContext_SelectionRequested; // The system raises this event when it wants the edit control to remove focus. _editContext.FocusRemoved += EditContext_FocusRemoved; // The system raises this event to update text in the edit control. _editContext.TextUpdating += EditContext_TextUpdating; // The system raises this event to change the selection in the edit control. _editContext.SelectionUpdating += EditContext_SelectionUpdating; // The system raises this event to request layout information. // This is used to help choose a position for the IME candidate window. _editContext.LayoutRequested += EditContext_LayoutRequested; // The system raises this event to notify the edit control // that the string composition has started. _editContext.CompositionStarted += EditContext_CompositionStarted; // The system raises this event to notify the edit control // that the string composition is finished. _editContext.CompositionCompleted += EditContext_CompositionCompleted; // The system raises this event when the NotifyFocusLeave operation has // completed. Our sample does not use this event. // _editContext.NotifyFocusLeaveCompleted += EditContext_NotifyFocusLeaveCompleted; _timer = _coreWindow.DispatcherQueue.CreateTimer(); _timer.Interval = new TimeSpan(0, 0, 0, 0, 10); _timer.IsRepeating = false; _timer.Tick += (o, e) => { //Debug.WriteLine("Result text: {0}", (object)_lastResultText); foreach (var c in _lastResultText) { OnTextInput(c); } }; }
public CodeEditBox() { InitializeComponent(); Unloaded += CodeEditBox_Unloaded; _textFormat = new CanvasTextFormat { FontFamily = "Consolas", FontSize = 14 }; // Make the control focusable IsTabStop = true; // The CoreTextEditContext processes text input, but other keys are // the apps's responsibility. _coreWindow = CoreWindow.GetForCurrentThread(); _coreWindow.KeyDown += CoreWindow_KeyDown; _coreWindow.PointerPressed += CoreWindow_PointerPressed; // Create a CoreTextEditContext for our custom edit control. CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView(); _editContext = manager.CreateEditContext(); // Create a TextDocument where we will store the text data _textDocument = new TextDocument(_editContext); _textDocument.TextChanged += TextDocument_TextChanged; _textDocument.SelectionChanged += TextDocument_SelectionChanged; //! Automatic hide and show the Input Pane. Note that on Desktop, you will need to //! implement the UIA text pattern to get expected automatic behavior. _editContext.InputPaneDisplayPolicy = CoreTextInputPaneDisplayPolicy.Automatic; // Set the input scope to inform software keyboard layout and text behavior. _editContext.InputScope = CoreTextInputScope.Default; // The system raises this event when it wants the edit control to remove focus. _editContext.FocusRemoved += EditContext_FocusRemoved; // The system raises this event to request layout information. // This is used to help choose a position for the IME candidate window. _editContext.LayoutRequested += EditContext_LayoutRequested; // The system raises this event to notify the edit control // that the string composition has started. _editContext.CompositionStarted += EditContext_CompositionStarted; // The system raises this event to notify the edit control // that the string composition is finished. _editContext.CompositionCompleted += EditContext_CompositionCompleted; // The system raises this event when the NotifyFocusLeave operation has // completed. // _editContext.NotifyFocusLeaveCompleted += EditContext_NotifyFocusLeaveCompleted; // Focus state reporter // TODO: remove this GotFocus += CodeEditBox_FocusChanged; LostFocus += CodeEditBox_FocusChanged; CodeEditBox_FocusChanged(this, null); // Update rendertargets TextDisplay.SizeChanged += TextDisplay_SizeChanged; TextDisplay_SizeChanged(this, null); // Set our initial UI. UpdateUI(); }