Пример #1
0
        public RecognizerControl()
        {
            this.InitializeComponent();
            const double penSize = 4;
            // Initialize drawing attributes. These are used in inking mode.
            var drawingAttributes = new InkDrawingAttributes
            {
                Color          = Windows.UI.Colors.Red,
                Size           = new Windows.Foundation.Size(penSize, penSize),
                IgnorePressure = false,
                FitToCurve     = true
            };


            // Show the available recognizers
            _inkRecognizerContainer = new InkRecognizerContainer();
            _recoView = _inkRecognizerContainer.GetRecognizers();
            // Set the text services so we can query when language changes
            _textServiceManager = CoreTextServicesManager.GetForCurrentView();
            _textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            // Initialize the InkCanvas
            InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            InkCanvas.InkPresenter.InputDeviceTypes           = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;
            InkCanvas.InkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted;
            InkCanvas.InkPresenter.StrokeInput.StrokeEnded   += StrokeInput_StrokeEnded;

            _recoTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(2)
            };
            _recoTimer.Tick += _recoTimer_Tick;
        }
Пример #2
0
        public MainPage()
        {
            this.InitializeComponent();
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();

            drawingAttributes.Color          = Windows.UI.Colors.Black;
            drawingAttributes.Size           = new Size(4, 4);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve     = true;

            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            InkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;
        }
Пример #3
0
        /*
         *  ボタンがフォーカスを取得した。
         *  TextBlockはフォーカスの取得/喪失の管理ができないので、TextBlockの上に透明のRadioButtonをかぶせてフォーカスの管理をしています。
         */
        private async void OverlappedButton_GotFocus(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("<<--- Button GotFocus");

            if (DesignMode.DesignModeEnabled)
            {
                // ビューデザイナーの中で動作している場合は何もしない。

                return;
            }

            // グリッドの外枠を青にしてフォーカスの取得を視覚的にユーザーに示します。
            MainGrid.BorderBrush = new SolidColorBrush(Colors.Blue);

            if (textServiceManager == null)
            {
                // 初めての場合

                // 少し待たないと「漢字」キーが効かない。
                await Task.Delay(1000);

                // CoreTextServicesManagerを作ります。
                Debug.WriteLine("--->> GetForCurrentView");
                textServiceManager = CoreTextServicesManager.GetForCurrentView();

                // IMEの切り替えのイベントハンドラを登録します。
                Debug.WriteLine("--->> Subscribe InputLanguageChanged");
                textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;
            }

            // editContextを作り直します。
            UpdateEditContext();
        }
Пример #4
0
        /*
         *  ボタンがフォーカスを取得した。
         *  TextBlockはフォーカスの取得/喪失の管理ができないので、TextBlockの上に透明のRadioButtonをかぶせてフォーカスの管理をしています。
         */
        private async void OverlappedButton_GotFocus(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("<<--- Button GotFocus");

            if (DesignMode.DesignModeEnabled)
            {
                // ビューデザイナーの中で動作している場合は何もしない。

                return;
            }

            if (textServiceManager == null)
            {
                // 初めての場合

                // 少し待たないと「漢字」キーが効かない。
                await Task.Delay(500);

                // CoreTextServicesManagerを作ります。
                Debug.WriteLine("--->> GetForCurrentView");
                textServiceManager = CoreTextServicesManager.GetForCurrentView();

                // IMEの切り替えのイベントハンドラを登録します。
                Debug.WriteLine("--->> Subscribe InputLanguageChanged");
                textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;
            }

            // editContextを作り直します。
            UpdateEditContext();

            // 再描画します。
            Win2DCanvas.Invalidate();
        }
Пример #5
0
        public static async Task <List <EmojiGroup> > SearchAsync(IProtoService protoService, string query, EmojiSkinTone skin)
        {
            var result        = new List <EmojiData>();
            var inputLanguage = CoreTextServicesManager.GetForCurrentView().InputLanguage.LanguageTag;

            var response = await protoService.SendAsync(new SearchEmojis(query, false, new[] { inputLanguage }));

            if (response is Emojis suggestions)
            {
                foreach (var item in suggestions.EmojisValue)
                {
                    var emoji = item;
                    if (EmojiGroupInternal._skinEmojis.Contains(emoji) || EmojiGroupInternal._skinEmojis.Contains(emoji.TrimEnd('\uFE0F')))
                    {
                        result.Add(new EmojiSkinData(emoji, skin));
                    }
                    else
                    {
                        result.Add(new EmojiData(item));
                    }
                }
            }

            return(new List <EmojiGroup>
            {
                new EmojiGroup
                {
                    Title = result.Count > 0 ? Strings.Resources.SearchEmojiHint : Strings.Resources.NoEmojiFound,
                    Stickers = result.ToArray()
                }
            });
        }
Пример #6
0
 public TextActionsTest()
 {
     Helper.ExecuteOnUIThread(() =>
     {
         CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView();
         _textDocument = new TextDocument(manager.CreateEditContext());
     }).Wait();
 }
Пример #7
0
 public SearchStickerSetsCollection(IProtoService protoService, StickerType type, string query, long chatId)
 {
     _protoService  = protoService;
     _type          = type;
     _query         = query;
     _inputLanguage = CoreTextServicesManager.GetForCurrentView().InputLanguage.LanguageTag;
     _chatId        = chatId;
 }
Пример #8
0
        public MainPage()
        {
            InitializeComponent();
            _viewModel.LoadQuickTransactions();

            CoreTextServicesManager textServiceManager = CoreTextServicesManager.GetForCurrentView();

            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;
        }
        public Scenario2()
        {
            this.InitializeComponent();
            //read language related resource file .strings/en or zh-cn/resources.resw
            Run run1 = new Run();

            run1.Text = ResourceManagerHelper.ReadValue("Description2_p1");
            this.textDes.Inlines.Add(run1);
            this.textDes.Inlines.Add(new LineBreak());

            // Initialize drawing attributes. These are used in inking mode.
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();

            drawingAttributes.Color = Windows.UI.Colors.Red;
            double penSize = 4;

            drawingAttributes.Size           = new Windows.Foundation.Size(penSize, penSize);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve     = true;

            // Show the available recognizers
            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            // Initialize the InkCanvas
            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            this.SizeChanged += Scenario2_SizeChanged;
        }
        public Scenario2()
        {
            this.InitializeComponent();

            // Initialize drawing attributes. These are used in inking mode.
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();

            drawingAttributes.Color = Windows.UI.Colors.Red;
            double penSize = 4;

            drawingAttributes.Size           = new Windows.Foundation.Size(penSize, penSize);
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve     = true;

            // Show the available recognizers
            inkRecognizerContainer = new InkRecognizerContainer();
            recoView = inkRecognizerContainer.GetRecognizers();
            if (recoView.Count > 0)
            {
                foreach (InkRecognizer recognizer in recoView)
                {
                    RecoName.Items.Add(recognizer.Name);
                }
            }
            else
            {
                RecoName.IsEnabled = false;
                RecoName.Items.Add("No Recognizer Available");
            }
            RecoName.SelectedIndex = 0;

            // Set the text services so we can query when language changes
            textServiceManager = CoreTextServicesManager.GetForCurrentView();
            textServiceManager.InputLanguageChanged += TextServiceManager_InputLanguageChanged;

            SetDefaultRecognizerByCurrentInputMethodLanguageTag();

            // Initialize reco tooltip
            recoTooltip         = new ToolTip();
            recoTooltip.Content = InstallRecoText;
            ToolTipService.SetToolTip(InstallReco, recoTooltip);

            // Initialize the InkCanvas
            inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            this.Unloaded    += Scenario2_Unloaded;
            this.SizeChanged += Scenario2_SizeChanged;
        }
Пример #11
0
        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 async void FindStickers(string query)
 {
     if (string.IsNullOrWhiteSpace(query))
     {
         SearchStickers = null;
     }
     else
     {
         var items = SearchStickers = new SearchStickerSetsCollection(ProtoService, Aggregator, false, query, CoreTextServicesManager.GetForCurrentView().InputLanguage.LanguageTag);
         await items.LoadMoreItemsAsync(0);
     }
 }
Пример #13
0
 private async void FieldEmoji_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (string.IsNullOrWhiteSpace(FieldEmoji.Text))
     {
         EmojiCollection.Source = Toolbar.ItemsSource;
     }
     else
     {
         EmojiCollection.Source = await Emoji.SearchAsync(ViewModel.ProtoService, FieldEmoji.Text, _selected, CoreTextServicesManager.GetForCurrentView().InputLanguage.LanguageTag);
     }
 }
Пример #14
0
        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();
        }
Пример #15
0
 /// <summary>
 /// Instantiates the <see cref="RnLanguagesModule"/>.
 /// </summary>
 internal RnLanguagesModule(ReactContext _context)
 {
     this.context = _context;
     CoreTextServicesManager.GetForCurrentView().InputLanguageChanged +=
         OnLanguageChange;
 }
        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);
                }
            };
        }
Пример #17
0
        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();
        }