1a3e0fd82Sopenharmony_ci/*
2a3e0fd82Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License.
5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at
6a3e0fd82Sopenharmony_ci *
7a3e0fd82Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a3e0fd82Sopenharmony_ci *
9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and
13a3e0fd82Sopenharmony_ci * limitations under the License.
14a3e0fd82Sopenharmony_ci */
15a3e0fd82Sopenharmony_ci
16a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_INPUT_METHOD_MANAGER_H
17a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_INPUT_METHOD_MANAGER_H
18a3e0fd82Sopenharmony_ci
19a3e0fd82Sopenharmony_ci#include <string>
20a3e0fd82Sopenharmony_ci
21a3e0fd82Sopenharmony_ci#include "components/ui_view.h"
22a3e0fd82Sopenharmony_ci#include "gfx_utils/graphic_types.h"
23a3e0fd82Sopenharmony_ci
24a3e0fd82Sopenharmony_cinamespace OHOS {
25a3e0fd82Sopenharmony_ciclass InputMethodManager : public HeapBase {
26a3e0fd82Sopenharmony_cipublic:
27a3e0fd82Sopenharmony_ci    struct InputMethodParam {
28a3e0fd82Sopenharmony_ci        InputType inputType;
29a3e0fd82Sopenharmony_ci        std::string text;
30a3e0fd82Sopenharmony_ci        UIView* view; /* view param for mini system without Window feature */
31a3e0fd82Sopenharmony_ci    };
32a3e0fd82Sopenharmony_ci    /**
33a3e0fd82Sopenharmony_ci     * @brief Defines a input method listener. You need to register this listener when you use keyboard to input text.
34a3e0fd82Sopenharmony_ci     *        This listener will invoke when the edit text view get focused.
35a3e0fd82Sopenharmony_ci     */
36a3e0fd82Sopenharmony_ci    class InputMethodListener : public HeapBase {
37a3e0fd82Sopenharmony_ci    public:
38a3e0fd82Sopenharmony_ci        /**
39a3e0fd82Sopenharmony_ci         * @brief A destructor used to delete the <b>InputMethodListener</b> instance.
40a3e0fd82Sopenharmony_ci         */
41a3e0fd82Sopenharmony_ci        virtual ~InputMethodListener() {}
42a3e0fd82Sopenharmony_ci
43a3e0fd82Sopenharmony_ci        /**
44a3e0fd82Sopenharmony_ci         * @brief Invoke this method when edit text view get focused.
45a3e0fd82Sopenharmony_ci         * @param param  the param passed, see InputMethodParam.
46a3e0fd82Sopenharmony_ci         */
47a3e0fd82Sopenharmony_ci        virtual void OnShow(InputMethodParam& param) = 0;
48a3e0fd82Sopenharmony_ci
49a3e0fd82Sopenharmony_ci        /**
50a3e0fd82Sopenharmony_ci         * @brief Invoke this method when edit text view get blured.
51a3e0fd82Sopenharmony_ci         */
52a3e0fd82Sopenharmony_ci        virtual void OnHide() = 0;
53a3e0fd82Sopenharmony_ci    };
54a3e0fd82Sopenharmony_ci
55a3e0fd82Sopenharmony_ci    /**
56a3e0fd82Sopenharmony_ci     * @brief return InputMethodManager's singleton
57a3e0fd82Sopenharmony_ci     * @return InputMethodManager*
58a3e0fd82Sopenharmony_ci     */
59a3e0fd82Sopenharmony_ci    static InputMethodManager& GetInstance();
60a3e0fd82Sopenharmony_ci
61a3e0fd82Sopenharmony_ci    /**
62a3e0fd82Sopenharmony_ci     * @brief Called to show input method when the edit view focuse
63a3e0fd82Sopenharmony_ci     * @param UIView  the edit view
64a3e0fd82Sopenharmony_ci     */
65a3e0fd82Sopenharmony_ci    void ShowInputMethod(UIView* view);
66a3e0fd82Sopenharmony_ci
67a3e0fd82Sopenharmony_ci    /**
68a3e0fd82Sopenharmony_ci     * @brief Called to hide input method when the edit view blure
69a3e0fd82Sopenharmony_ci     */
70a3e0fd82Sopenharmony_ci    void HideInputMethod();
71a3e0fd82Sopenharmony_ci
72a3e0fd82Sopenharmony_ci    /**
73a3e0fd82Sopenharmony_ci     * @brief Sets a input method listener.
74a3e0fd82Sopenharmony_ci     * @param listener the input method listener.
75a3e0fd82Sopenharmony_ci     */
76a3e0fd82Sopenharmony_ci    void SetInputMethodListener(InputMethodListener* listener);
77a3e0fd82Sopenharmony_ci
78a3e0fd82Sopenharmony_ci    /**
79a3e0fd82Sopenharmony_ci     * @brief Call to insert text when keyboard select new input text.
80a3e0fd82Sopenharmony_ci     * @param text the input method listener.
81a3e0fd82Sopenharmony_ci     */
82a3e0fd82Sopenharmony_ci    void InsertText(std::string text);
83a3e0fd82Sopenharmony_ci
84a3e0fd82Sopenharmony_ci    /**
85a3e0fd82Sopenharmony_ci     * @brief Call to delete text when keyboard press delete button.
86a3e0fd82Sopenharmony_ci     * @param length the length of charactor to delete
87a3e0fd82Sopenharmony_ci     */
88a3e0fd82Sopenharmony_ci    void DeleteBackward(uint16_t length);
89a3e0fd82Sopenharmony_ci
90a3e0fd82Sopenharmony_ci    /**
91a3e0fd82Sopenharmony_ci     * @brief Sets the input type.
92a3e0fd82Sopenharmony_ci     * @param type the input type, see InputType
93a3e0fd82Sopenharmony_ci     */
94a3e0fd82Sopenharmony_ci    void SetInputType(InputType type);
95a3e0fd82Sopenharmony_ci
96a3e0fd82Sopenharmony_ci    /**
97a3e0fd82Sopenharmony_ci     * @brief Call function invoke after the keyboard showed.
98a3e0fd82Sopenharmony_ci     */
99a3e0fd82Sopenharmony_ci    void OnKeyboardShow();
100a3e0fd82Sopenharmony_ci
101a3e0fd82Sopenharmony_ci    /**
102a3e0fd82Sopenharmony_ci     * @brief Call function invoke after the keyboard hided.
103a3e0fd82Sopenharmony_ci     */
104a3e0fd82Sopenharmony_ci    void OnKeyboardHide();
105a3e0fd82Sopenharmony_ci
106a3e0fd82Sopenharmony_ci    /**
107a3e0fd82Sopenharmony_ci     * @brief Sets the cursor index.
108a3e0fd82Sopenharmony_ci     */
109a3e0fd82Sopenharmony_ci    void SetCursorIndex(uint16_t cursorIndex_);
110a3e0fd82Sopenharmony_ci
111a3e0fd82Sopenharmony_ci    uint16_t GetCursorIndex();
112a3e0fd82Sopenharmony_ci
113a3e0fd82Sopenharmony_ciprivate:
114a3e0fd82Sopenharmony_ci    InputMethodManager() {}
115a3e0fd82Sopenharmony_ci    ~InputMethodManager() {}
116a3e0fd82Sopenharmony_ci
117a3e0fd82Sopenharmony_ci    InputMethodManager(const InputMethodManager&) = delete;
118a3e0fd82Sopenharmony_ci    InputMethodManager& operator=(const InputMethodManager&) = delete;
119a3e0fd82Sopenharmony_ci    InputMethodManager(InputMethodManager&&) = delete;
120a3e0fd82Sopenharmony_ci    InputMethodManager& operator=(InputMethodManager&&) = delete;
121a3e0fd82Sopenharmony_ci
122a3e0fd82Sopenharmony_ci    InputMethodListener* inputMethodListener_ = nullptr;
123a3e0fd82Sopenharmony_ci    UIView* inputView_ = nullptr;
124a3e0fd82Sopenharmony_ci};
125a3e0fd82Sopenharmony_ci} // namespace OHOS
126a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_INPUT_METHOD_MANAGER_H
127