Пример #1
0
        /*
         *  入力コントロールの位置と入力テキストの位置を聞いてきた。
         */
        private void EditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs ev)
        {
            Debug.WriteLine("<<--- LayoutRequested range:{0}-{1}", ev.Request.Range.StartCaretPosition, ev.Request.Range.EndCaretPosition);

            // メインウインドウを囲む矩形を得ます。
            Rect wnd_rect = CoreApplication.GetCurrentView().CoreWindow.Bounds;

            // TextBlockのページ内の位置を得ます。
            Point edit_pos = EditText.TransformToVisual(this).TransformPoint(new Point(0, 0));

            // TextBlockのスクリーン座標を計算します。
            double edit_screen_x = wnd_rect.X + edit_pos.X;
            double edit_screen_y = wnd_rect.Y + edit_pos.Y;

            // TextBlockを囲む矩形のスクリーン座標を返します。
            ev.Request.LayoutBounds.ControlBounds = new Rect(edit_screen_x, edit_screen_y, EditText.ActualWidth, EditText.ActualHeight);

            // TextBlock内の指定した位置までのRunの幅を得ます。
            double text_x = MeasureTextWidth(ev.Request.Range.EndCaretPosition);

            // 選択位置のテキストのスクリーン座標を計算します。
            double text_screen_x = edit_screen_x + text_x;

            // 選択範囲のテキストを囲む矩形をスクリーン座標で返します。
            ev.Request.LayoutBounds.TextBounds = new Rect(text_screen_x, edit_screen_y, 0, EditText.ActualHeight);
        }
Пример #2
0
        /*
         *  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();
        }
Пример #3
0
        /*
         *  テキストの選択位置を聞いてきた。
         */
        private void EditContext_SelectionRequested(CoreTextEditContext sender, CoreTextSelectionRequestedEventArgs ev)
        {
            Debug.WriteLine("<<--- SelectionRequested : {0}-{1}", Selection.StartCaretPosition, Selection.EndCaretPosition);

            // アプリ内で持っているテキストの選択位置を返します。
            ev.Request.Selection = Selection;
        }
Пример #4
0
        /*
         *  アプリ内で持っているテキストが欲しいと言ってきた。
         *  CoreTextEditContextを作るとこれが呼ばれます。
         */
        private void EditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs ev)
        {
            // TextBlockの中のカーソル以外のRunの文字からテキストを作ります。
            ev.Request.Text = new string((from x in EditText.Inlines where x != Cursor select((Run)x).Text[0]).ToArray());

            Debug.WriteLine("<<--- TextRequested : {0}-{1} [{2}]", ev.Request.Range.StartCaretPosition, ev.Request.Range.EndCaretPosition, ev.Request.Text);
        }
Пример #5
0
        /*
         *  かな漢字変換の途中で表示するテキストの書式を指定してきた。
         */
        private void EditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs ev)
        {
            Debug.WriteLine("<<--- FormatUpdating: BG:{0} cancel:{1} range:({2},{3}) reason:{4} result:{5} color:{6} under-line:({7},{8})",
                            (ev.BackgroundColor == null ? "null" : ev.BackgroundColor.Value.ToString()),
                            ev.IsCanceled,
                            ev.Range.StartCaretPosition, ev.Range.EndCaretPosition,
                            ev.Reason,
                            ev.Result,
                            (ev.TextColor == null ? "null" : ev.TextColor.Value.ToString()),
                            (ev.UnderlineColor == null ? "null" : ev.UnderlineColor.Value.ToString()),
                            (ev.UnderlineType == null ? "null" : ev.UnderlineType.Value.ToString())
                            );

            if (ev.UnderlineType != null)
            {
                // 下線がnullでない場合

                // 選択範囲の文字の下線を指定します。
                for (int i = ev.Range.StartCaretPosition; i < ev.Range.EndCaretPosition; i++)
                {
                    // TCharはstructなので Chars[i]=ev.UnderlineType.Value; と書くとエラーになります。
                    TChar ch = Chars[i];
                    ch.Underline = ev.UnderlineType.Value;
                    Chars[i]     = ch;
                }
            }

            // 再描画します。
            Win2DCanvas.Invalidate();
        }
Пример #6
0
        /*
         *  テキストの内容の変化を通知してきた。
         */
        private void EditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs ev)
        {
            Debug.WriteLine("<<--- TextUpdating:({0},{1})->({2},{3}) [{4}] {5}",
                            ev.Range.StartCaretPosition, ev.Range.EndCaretPosition,
                            ev.NewSelection.StartCaretPosition, ev.NewSelection.EndCaretPosition,
                            ev.Text,
                            ev.Result
                            );

            // カーソルがあると文字の操作に邪魔なので、いったん取り除きます。
            RemoveCursor();

            // 以前の選択位置の文字を末尾から取り除いていきます。
            for (int i = ev.Range.EndCaretPosition - 1; ev.Range.StartCaretPosition <= i; i--)
            {
                EditText.Inlines.RemoveAt(i);
            }

            // 新しいテキストを挿入します。
            for (int i = 0; i < ev.Text.Length; i++)
            {
                // 1文字ごとにRunを作ります。
                Run txt = new Run();
                txt.Text = ev.Text.Substring(i, 1);

                // RunをTextBlockに挿入します。
                EditText.Inlines.Insert(ev.Range.StartCaretPosition + i, txt);
            }

            // アプリ内で持っているテキストの選択位置を更新します。
            Selection = ev.NewSelection;

            // カーソルを挿入します。
            InsertCursor();
        }
        void EditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
        {
            if (!_compositionStarted) // Only update text  when composition is started.
            {
                args.Result = CoreTextTextUpdatingResult.Failed;
                return;
            }

            CoreTextRange range        = args.Range;
            string        newText      = args.Text;
            CoreTextRange newSelection = args.NewSelection;

            // Modify the internal text store.
            _inputBuffer = _inputBuffer.Substring(0, range.StartCaretPosition) +
                           newText +
                           _inputBuffer.Substring(Math.Min(_inputBuffer.Length, range.EndCaretPosition));

            // You can set the proper font or direction for the updated text based on the language by checking
            // args.InputLanguage.  We will not do that in this sample.

            // Modify the current selection.
            newSelection.EndCaretPosition = newSelection.StartCaretPosition;

            // Update the selection of the edit context. There is no need to notify the system
            // because the system itself changed the selection.
            SetSelection(newSelection);

            //var compStr = _inputBuffer;
            //compStr = compStr.Insert(_selection.StartCaretPosition, "|");
            //Debug.WriteLine("composition text: {0}, cursor pos: {1}", (object)compStr, _selection.StartCaretPosition);
            OnTextComposition(_inputBuffer, _selection.StartCaretPosition);
        }
Пример #8
0
        void EditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs args)
        {
            //CoreTextLayoutRequest request = args.Request;

            //// Get the screen coordinates of the entire control and the selected text.
            //// This information is used to position the IME candidate window.

            //// First, get the coordinates of the edit control and the selection
            //// relative to the Window.
            //Rect contentRect = GetElementRect(ContentPanel);
            //Rect selectionRect = GetElementRect(SelectionText);

            //// Next, convert to screen coordinates in view pixels.
            //Rect windowBounds = Window.Current.CoreWindow.Bounds;
            //contentRect.X += windowBounds.X;
            //contentRect.Y += windowBounds.Y;
            //selectionRect.X += windowBounds.X;
            //selectionRect.Y += windowBounds.Y;

            //// Finally, scale up to raw pixels.
            //double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            //contentRect = ScaleRect(contentRect, scaleFactor);
            //selectionRect = ScaleRect(selectionRect, scaleFactor);

            //// This is the bounds of the selection.
            //// Note: If you return bounds with 0 width and 0 height, candidates will not appear while typing.
            //request.LayoutBounds.TextBounds = selectionRect;

            ////This is the bounds of the whole control
            //request.LayoutBounds.ControlBounds = contentRect;
        }
Пример #9
0
        // Return the specified range of text. Note that the system may ask for more text
        // than exists in the text buffer.
        void EditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs args)
        {
            CoreTextTextRequest request = args.Request;

            request.Text = _text.Substring(
                request.Range.StartCaretPosition,
                Math.Min(request.Range.EndCaretPosition, _text.Length) - request.Range.StartCaretPosition);
        }
Пример #10
0
        /*
         *  入力コントロールの位置と入力テキストの位置を聞いてきた。
         */
        private void EditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs ev)
        {
            Debug.WriteLine("<<--- LayoutRequested range:{0}-{1}", ev.Request.Range.StartCaretPosition, ev.Request.Range.EndCaretPosition);


            // メインウインドウを囲む矩形を得ます。
            Rect wnd_rect = CoreApplication.GetCurrentView().CoreWindow.Bounds;

            // Canvasのページ内の位置を得ます。
            FrameworkElement root = this;

            for (root = this; root.Parent is FrameworkElement;)
            {
                root = root.Parent as FrameworkElement;
            }

            Point edit_pos = TransformToVisual(root).TransformPoint(new Point(0, 0));

            // Canvasのスクリーン座標を計算します。
            double edit_screen_x = wnd_rect.X + edit_pos.X;
            double edit_screen_y = wnd_rect.Y + edit_pos.Y;

            // Canvasを囲む矩形のスクリーン座標を返します。
            Rect canvas_rect = new Rect(edit_screen_x, edit_screen_y, Win2DCanvas.ActualWidth, Win2DCanvas.ActualHeight);

            ev.Request.LayoutBounds.ControlBounds = canvas_rect;

            // 選択位置の語句を描画した図形または直前の図形のリストを得ます。(選択位置が文書の末尾にある場合は直前の図形を使います。)
            var draw_list = from x in DrawList where x.StartPos <= SelCurrent && SelCurrent <= x.EndPos select x;

            if (draw_list.Any())
            {
                // 図形を得られた場合

                // 語句を描画した図形を得ます。
                TShape phrase_shape = draw_list.First();

                // 描画した語句の先頭から選択位置までのテキストのサイズを得ます。
                Size sz = MeasureText(StringFromRange(phrase_shape.StartPos, SelCurrent), TextFormat);

                // 選択位置のテキストを囲む矩形を計算します。
                Rect text_rect;
                text_rect.X      = canvas_rect.X + phrase_shape.Bounds.X + sz.Width;
                text_rect.Y      = canvas_rect.Y + phrase_shape.Bounds.Y;
                text_rect.Width  = SpaceWidth;
                text_rect.Height = sz.Height;

                // 選択範囲のテキストを囲む矩形をスクリーン座標で返します。
                ev.Request.LayoutBounds.TextBounds = text_rect;
            }
            else
            {
                // 図形を得られない場合

                // 選択範囲のテキストを囲む矩形はCanvasを囲む矩形とします。
                ev.Request.LayoutBounds.TextBounds = canvas_rect;
            }
        }
Пример #11
0
        void EditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs args)
        {
            // Set the new selection to the value specified by the system.
            CoreTextRange range = args.Selection;

            // Update the selection of the edit context. There is no need to notify the system
            // because the system itself changed the selection.
            SetSelection(range);
        }
Пример #12
0
        /*
         *  テキストの選択位置の変化を通知してきた。
         */
        private void EditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs ev)
        {
            Debug.WriteLine("<<--- SelectionUpdating: cancel:{0} result:{1} ({2},{3})",
                            ev.IsCanceled,
                            ev.Result,
                            ev.Selection.StartCaretPosition, ev.Selection.EndCaretPosition
                            );

            // アプリ内で持っているテキストの選択位置を更新します。
            SelOrigin  = ev.Selection.StartCaretPosition;
            SelCurrent = ev.Selection.EndCaretPosition;
        }
Пример #13
0
        /*
         *  かな漢字変換が終わって入力テキストが確定した。
         */
        private void EditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs ev)
        {
            StringWriter sw = new StringWriter();

            // 文節ごとのテキスト位置と漢字の読みを得ます。
            foreach (CoreTextCompositionSegment seg in ev.CompositionSegments)
            {
                sw.Write("({0},{1}):{2} ", seg.Range.StartCaretPosition, seg.Range.EndCaretPosition, seg.PreconversionString);
            }

            Debug.WriteLine("<<--- CompositionCompleted:{0} {1}", ev.IsCanceled, sw.ToString());
        }
        void EditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs args)
        {
            // Set the new selection to the value specified by the system.
            CoreTextRange range = args.Selection;

            // Update the selection of the edit context. There is no need to notify the system
            // because the system itself changed the selection.
            SetSelection(range);

            //var compStr = _inputBuffer;
            //compStr = compStr.Insert(_selection.StartCaretPosition, "|");
            //Debug.WriteLine("composition text: {0}, cursor pos: {1}", (object)compStr, _selection.StartCaretPosition);

            OnTextComposition(_inputBuffer, _selection.StartCaretPosition);
        }
Пример #15
0
        /*
         *  かな漢字変換の途中で表示するテキストの書式を指定してきた。
         */
        private void EditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs ev)
        {
            Debug.WriteLine("<<--- FormatUpdating: BG:{0} cancel:{1} range:({2},{3}) reason:{4} result:{5} color:{6} under-line:({7},{8})",
                            (ev.BackgroundColor == null ? "null" : ev.BackgroundColor.Value.ToString()),
                            ev.IsCanceled,
                            ev.Range.StartCaretPosition, ev.Range.EndCaretPosition,
                            ev.Reason,
                            ev.Result,
                            (ev.TextColor == null ? "null" : ev.TextColor.Value.ToString()),
                            (ev.UnderlineColor == null ? "null" : ev.UnderlineColor.Value.ToString()),
                            (ev.UnderlineType == null ? "null" : ev.UnderlineType.Value.ToString())
                            );

            // カーソルがあると文字の操作に邪魔なので、いったん取り除きます。
            RemoveCursor();

            // 選択範囲の文字の書式を設定します。
            for (int i = ev.Range.StartCaretPosition; i < ev.Range.EndCaretPosition; i++)
            {
                // 文字を含むRunを得ます。
                Run r = (Run)EditText.Inlines[i];

                // 下線の種類によってRunの色を変えます。 ( Runには下線のプロパティがないので。 )
                switch (ev.UnderlineType)
                {
                case UnderlineType.Wave:
                    r.Foreground = BlueBrush;
                    break;

                case UnderlineType.Thick:
                    r.Foreground = GreenBrush;
                    break;

                case UnderlineType.Thin:
                    r.Foreground = RedBrush;
                    break;

                case UnderlineType.None:
                case UnderlineType.Undefined:
                default:
                    r.Foreground = BlackBrush;
                    break;
                }
            }

            // カーソルを挿入します。
            InsertCursor();
        }
Пример #16
0
        /*
         *  テキストの内容の変化を通知してきた。
         */
        private void EditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs ev)
        {
            Debug.WriteLine("<<--- TextUpdating:({0},{1})->({2},{3}) [{4}] {5} {6}",
                            ev.Range.StartCaretPosition, ev.Range.EndCaretPosition,
                            ev.NewSelection.StartCaretPosition, ev.NewSelection.EndCaretPosition,
                            ev.Text,
                            ev.Result,
                            MeasureText(ev.Text, TextFormat)
                            );

            // テキストを変更して、変更情報をアンドゥ/リドゥのスタックにプッシュします。
            PushUndoRedoStack(ev.Range.StartCaretPosition, ev.Range.EndCaretPosition, ev.Text, UndoStack);

            // 再描画します。
            Win2DCanvas.Invalidate();
        }
Пример #17
0
        /*
         *  テキストの選択位置の変化を通知してきた。
         */
        private void EditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs ev)
        {
            Debug.WriteLine("<<--- SelectionUpdating: cancel:{0} result:{1} ({2},{3})",
                            ev.IsCanceled,
                            ev.Result,
                            ev.Selection.StartCaretPosition, ev.Selection.EndCaretPosition
                            );

            // カーソルがあると文字の操作に邪魔なので、いったん取り除きます。
            RemoveCursor();

            // アプリ内で持っているテキストの選択位置を更新します。
            Selection = ev.Selection;

            // カーソルを挿入します。
            InsertCursor();
        }
        void EditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs args)
        {
            _lastResultText = _inputBuffer;
            _coreWindow.DispatcherQueue.TryEnqueue(() =>
            {
                ReplaceText(new CoreTextRange {
                    StartCaretPosition = 0, EndCaretPosition = _inputBuffer.Length
                }, string.Empty);
            });

            if (!_timer.IsRunning)
            {
                _timer.Start();
            }

            OnTextComposition(string.Empty, 0);

            _compositionStarted = false;
        }
Пример #19
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;
        }
Пример #20
0
        void EditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
        {
            CoreTextRange range        = args.Range;
            string        newText      = args.Text;
            CoreTextRange newSelection = args.NewSelection;

            // Modify the internal text store.
            _text = _text.Substring(0, range.StartCaretPosition) +
                    newText +
                    _text.Substring(Math.Min(_text.Length, range.EndCaretPosition));

            // You can set the proper font or direction for the updated text based on the language by checking
            // args.InputLanguage.  We will not do that in this sample.

            // Modify the current selection.
            newSelection.EndCaretPosition = newSelection.StartCaretPosition;

            // Update the selection of the edit context. There is no need to notify the system
            // because the system itself changed the selection.
            SetSelection(newSelection);
        }
Пример #21
0
        void EditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs args)
        {
            // The following code specifies how you would apply any formatting to the specified range of text
            // For this sample, we do not make any changes to the format.

            // Apply text color if specified.
            // A null value indicates that the default should be used.
            if (args.TextColor != null)
            {
                //InternalSetTextColor(args.Range, args.TextColor.Value);
            }
            else
            {
                //InternalSetDefaultTextColor(args.Range);
            }

            // Apply background color if specified.
            // A null value indicates that the default should be used.
            if (args.BackgroundColor != null)
            {
                //InternalSetBackgroundColor(args.Range, args.BackgroundColor.Value);
            }
            else
            {
                //InternalSetDefaultBackgroundColor(args.Range);
            }

            // Apply underline if specified.
            // A null value indicates that the default should be used.
            if (args.UnderlineType != null)
            {
                //TextDecoration underline = new TextDecoration(args.Range,args.UnderlineType.Value,args.UnderlineColor.Value);

                //InternalAddTextDecoration(underline);
            }
            else
            {
                //InternalRemoveTextDecoration(args.Range);
            }
        }
Пример #22
0
        async void EditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
        {
            CoreTextRange range        = args.Range;
            string        newText      = args.Text;
            CoreTextRange newSelection = args.NewSelection;

            var line = _content[CurrentLine].Text;

            //// Modify the internal text store.
            _content[CurrentLine].Text = line.Substring(0, range.StartCaretPosition) +
                                         newText +
                                         line.Substring(Math.Min(line.Length, range.EndCaretPosition));

            if (_content[CurrentLine].Text.Trim().ToLower().StartsWith("todo:") && _content[CurrentLine] is not TodoTextItem)
            {
                var todoItem = new TodoTextItem()
                {
                    Text = _content[CurrentLine].Text.Trim().Substring(5)
                };
                // convert item to todo
                _content.RemoveAt(CurrentLine);
                _content.Insert(CurrentLine, todoItem);
                newSelection.StartCaretPosition = newSelection.EndCaretPosition = 0;

                // had to add this to make sure it works
                await Task.Delay(2);

                SetSelectionAndNotify(newSelection);
            }
            else
            {
                //// Modify the current selection.
                newSelection.EndCaretPosition = newSelection.StartCaretPosition;

                //// Update the selection of the edit context. There is no need to notify the system
                //// because the system itself changed the selection.
                SetSelection(newSelection);
            }
        }
Пример #23
0
        void EditContext_SelectionRequested(CoreTextEditContext sender, CoreTextSelectionRequestedEventArgs args)
        {
            CoreTextSelectionRequest request = args.Request;

            request.Selection = _selection;
        }
Пример #24
0
 /*
  *  IME側の理由で入力フォーカスがなくなった。
  *  これがどのタイミングで呼ばれるかは不明。
  */
 private void EditContext_FocusRemoved(CoreTextEditContext sender, object ev)
 {
     Debug.WriteLine("<<--- FocusRemoved");
 }
Пример #25
0
 void EditContext_FocusRemoved(CoreTextEditContext sender, object args)
 {
     RemoveInternalFocusWorker();
 }
Пример #26
0
        /*
         *  アプリ内で持っているテキストが欲しいと言ってきた。
         *  CoreTextEditContextを作るとこれが呼ばれます。
         */
        private void EditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs ev)
        {
            ev.Request.Text = StringFromRange(ev.Request.Range.StartCaretPosition, ev.Request.Range.EndCaretPosition);

            Debug.WriteLine("<<--- TextRequested : {0}-{1}", ev.Request.Range.StartCaretPosition, ev.Request.Range.EndCaretPosition);
        }
 // Return the current selection.
 void EditContext_SelectionRequested(CoreTextEditContext sender, CoreTextSelectionRequestedEventArgs args)
 {
     CoreTextSelectionRequest request = args.Request;
     request.Selection = _selection;
 }
        void EditContext_SelectionUpdating(CoreTextEditContext sender, CoreTextSelectionUpdatingEventArgs args)
        {
            // Set the new selection to the value specified by the system.
            CoreTextRange range = args.Selection;

            // Update the selection of the edit context. There is no need to notify the system
            // because the system itself changed the selection.
            SetSelection(range);
        }
Пример #29
0
 void EditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs args)
 {
 }
Пример #30
0
 /*
  *  フォーカス喪失の通知が完了した。
  *  アプリからNotifyFocusLeaveを呼んだら、このメソッドが呼ばれます。
  */
 private void EditContext_NotifyFocusLeaveCompleted(CoreTextEditContext sender, object ev)
 {
     Debug.WriteLine("<<--- NotifyFocusLeaveCompleted");
 }
        void EditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs args)
        {
            // The following code specifies how you would apply any formatting to the specified range of text
            // For this sample, we do not make any changes to the format.

            // Apply text color if specified.
            // A null value indicates that the default should be used.
            if (args.TextColor != null)
            {
                //InternalSetTextColor(args.Range, args.TextColor.Value);
            }
            else
            {
                //InternalSetDefaultTextColor(args.Range);
            }

            // Apply background color if specified.
            // A null value indicates that the default should be used.
            if (args.BackgroundColor != null)
            {
                //InternalSetBackgroundColor(args.Range, args.BackgroundColor.Value);
            }
            else
            {
                //InternalSetDefaultBackgroundColor(args.Range);
            }

            // Apply underline if specified.
            // A null value indicates that the default should be used.
            if (args.UnderlineType != null)
            {
                //TextDecoration underline = new TextDecoration(args.Range,args.UnderlineType.Value,args.UnderlineColor.Value);

                //InternalAddTextDecoration(underline);
            }
            else
            {
                //InternalRemoveTextDecoration(args.Range);
            }
        }
        void EditContext_LayoutRequested(CoreTextEditContext sender, CoreTextLayoutRequestedEventArgs args)
        {
            CoreTextLayoutRequest request = args.Request;

            // Get the screen coordinates of the entire control and the selected text.
            // This information is used to position the IME candidate window.

            // First, get the coordinates of the edit control and the selection
            // relative to the Window.
            Rect contentRect = GetElementRect(ContentPanel);
            Rect selectionRect = GetElementRect(SelectionText);

            // Next, convert to screen coordinates in view pixels.
            Rect windowBounds = Window.Current.CoreWindow.Bounds;
            contentRect.X += windowBounds.X;
            contentRect.Y += windowBounds.Y;
            selectionRect.X += windowBounds.X;
            selectionRect.Y += windowBounds.Y;

            // Finally, scale up to raw pixels.
            double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            contentRect = ScaleRect(contentRect, scaleFactor);
            selectionRect = ScaleRect(selectionRect, scaleFactor);

            // This is the bounds of the selection.
            // Note: If you return bounds with 0 width and 0 height, candidates will not appear while typing.
            request.LayoutBounds.TextBounds = selectionRect;

            //This is the bounds of the whole control
            request.LayoutBounds.ControlBounds = contentRect;
        }
 void EditContext_CompositionCompleted(CoreTextEditContext sender, CoreTextCompositionCompletedEventArgs args)
 {
 }
        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();
        }
 // Return the specified range of text. Note that the system may ask for more text
 // than exists in the text buffer.
 void EditContext_TextRequested(CoreTextEditContext sender, CoreTextTextRequestedEventArgs args)
 {
     CoreTextTextRequest request = args.Request;
     request.Text = _text.Substring(
         request.Range.StartCaretPosition,
         Math.Min(request.Range.EndCaretPosition, _text.Length) - request.Range.StartCaretPosition);
 }
Пример #36
0
 /*
  *  かな漢字変換を開始した。
  */
 private void EditContext_CompositionStarted(CoreTextEditContext sender, CoreTextCompositionStartedEventArgs ev)
 {
     Debug.WriteLine("<<--- CompositionStarted");
 }
 void EditContext_FocusRemoved(CoreTextEditContext sender, object args)
 {
     RemoveInternalFocusWorker();
 }
        void EditContext_TextUpdating(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs args)
        {
            CoreTextRange range = args.Range;
            string newText = args.Text;
            CoreTextRange newSelection = args.NewSelection;

            // Modify the internal text store.
            _text = _text.Substring(0, range.StartCaretPosition) +
                newText +
                _text.Substring(Math.Min(_text.Length, range.EndCaretPosition));

            // You can set the proper font or direction for the updated text based on the language by checking
            // args.InputLanguage.  We will not do that in this sample.

            // Modify the current selection.
            newSelection.EndCaretPosition = newSelection.StartCaretPosition;

            // Update the selection of the edit context. There is no need to notify the system
            // because the system itself changed the selection.
            SetSelection(newSelection);
        }
 public CoreTextEditContextEvents(CoreTextEditContext This)
 {
     this.This = This;
 }
Пример #40
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();
        }