mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-27 00:41:04 +00:00
feature:add capi
Signed-off-by: wuchengwen <wuchengwen4@huawei.com>
This commit is contained in:
parent
a63e339066
commit
b4ccbedc77
40
.clang-format
Normal file
40
.clang-format
Normal file
@ -0,0 +1,40 @@
|
||||
# Run command below to format a file
|
||||
# clang-format -i --style=file <file>
|
||||
|
||||
# complete clang-format rule, reference:
|
||||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
|
||||
# WebKit format rule details, reference:
|
||||
# https://webkit.org/code-style-guidelines/
|
||||
# https://gitee.com/mirrors/WebKit/blob/main/.clang-format
|
||||
BasedOnStyle: Webkit
|
||||
# works on C and C++ files
|
||||
Language: Cpp
|
||||
|
||||
PointerAlignment: Right
|
||||
AlignTrailingComments: true
|
||||
AlignConsecutiveMacros: Consecutive
|
||||
# case statements indent one layer
|
||||
IndentCaseLabels: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
SpaceBeforeParens: ControlStatementsExceptControlMacros
|
||||
SpacesInCStyleCastParentheses: false
|
||||
AlignEscapedNewlines: Left
|
||||
NamespaceIndentation: None
|
||||
FixNamespaceComments: true
|
||||
BreakConstructorInitializers: AfterColon
|
||||
AlignArrayOfStructures: Left
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BreakBeforeTernaryOperators: false
|
||||
SpaceAroundPointerQualifiers: Both
|
||||
# iterator macros declaretion,avoid being treated as function call
|
||||
ForEachMacros:
|
||||
- 'LIST_FOR_EACH_ENTRY'
|
||||
- 'LIST_FOR_EACH_ENTRY_SAFE'
|
||||
- 'LIST_FOR_EACH'
|
||||
- 'LIST_FOR_EACH_SAFE'
|
||||
SortIncludes: CaseInsensitive
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
ColumnLimit: 120
|
@ -65,7 +65,8 @@
|
||||
"//base/inputmethod/imf/interfaces/inner_api/inputmethod_controller:inputmethod_client",
|
||||
"//base/inputmethod/imf/frameworks/js/napi/inputmethodclient:inputmethod",
|
||||
"//base/inputmethod/imf/frameworks/js/napi/inputmethodlist:inputmethodlist",
|
||||
"//base/inputmethod/imf/frameworks/js/napi/inputmethodpanel:panel"
|
||||
"//base/inputmethod/imf/frameworks/js/napi/inputmethodpanel:panel",
|
||||
"//base/inputmethod/imf/frameworks/ndk:ohinputmethod"
|
||||
],
|
||||
"service_group": [
|
||||
"//base/inputmethod/imf/etc/init:inputmethodservice.cfg",
|
||||
|
47
frameworks/ndk/BUILD.gn
Normal file
47
frameworks/ndk/BUILD.gn
Normal file
@ -0,0 +1,47 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import("//base/inputmethod/imf/inputmethod.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_shared_library("ohinputmethod") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
cfi_vcall_icall_only = true
|
||||
debug = false
|
||||
}
|
||||
output_name = "ohinputmethod"
|
||||
output_extension = "so"
|
||||
|
||||
sources = [
|
||||
"src/native_input_method_texteditor_proxy.cpp",
|
||||
"src/native_inputmethod_api.cpp",
|
||||
"src/native_text_changed_listener.cpp",
|
||||
]
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${inputmethod_path}/interfaces/kits/c",
|
||||
]
|
||||
deps = [ "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_single",
|
||||
]
|
||||
|
||||
innerapi_tags = [ "ndk" ]
|
||||
subsystem_name = "inputmethod"
|
||||
part_name = "imf"
|
||||
}
|
104
frameworks/ndk/include/native_text_editor.h
Normal file
104
frameworks/ndk/include/native_text_editor.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef NATIVE_TEXT_EDITOR_H
|
||||
#define NATIVE_TEXT_EDITOR_H
|
||||
#include "input_method_controller.h"
|
||||
#include "inputmethod_controller_capi.h"
|
||||
|
||||
struct OH_InputMethod_PrivateCommand {
|
||||
std::string key;
|
||||
std::variant<std::string, bool, int32_t> value;
|
||||
};
|
||||
|
||||
struct OH_InputMethod_CursorInfo {
|
||||
double left = -1.0;
|
||||
double top = -1.0;
|
||||
double width = -1.0;
|
||||
double height = -1.0;
|
||||
};
|
||||
|
||||
struct OH_InputMethod_TextAvoidInfo {
|
||||
double positionY;
|
||||
double height;
|
||||
};
|
||||
struct OH_InputMethod_TextConfig {
|
||||
InputMethod_TextInputType inputType;
|
||||
InputMethod_EnterKeyType enterKeyType;
|
||||
bool previewTextSupported;
|
||||
OH_InputMethod_CursorInfo cursorInfo;
|
||||
OH_InputMethod_TextAvoidInfo avoidInfo;
|
||||
int32_t selectionStart;
|
||||
int32_t selectionEnd;
|
||||
int32_t windowId;
|
||||
};
|
||||
|
||||
struct OH_InputMethod_TextEditorProxy {
|
||||
OH_TextEditorProxy_GetTextConfigFunc getTextConfigFunc;
|
||||
OH_TextEditorProxy_InsertTextFunc insertTextFunc;
|
||||
OH_TextEditorProxy_DeleteForwardFunc deleteForwardFunc;
|
||||
OH_TextEditorProxy_DeleteBackwardFunc deleteBackwardFunc;
|
||||
OH_TextEditorProxy_SendKeyboardStatusFunc sendKeyboardStatusFunc;
|
||||
OH_TextEditorProxy_SendEnterKeyTypeFunc sendEnterKeyFunc;
|
||||
OH_TextEditorProxy_MoveCursor moveCursorFunc;
|
||||
OH_TextEditorProxy_HandleSetSelectionFunc handleSetSelectionFunc;
|
||||
OH_TextEditorProxy_HandleExtendActionFunc handleExtendActionFunc;
|
||||
OH_TextEditorProxy_GetLeftTextOfCursorFunc getLeftTextOfCursorFunc;
|
||||
OH_TextEditorProxy_GetRightTextOfCursorFunc getRightTextOfCursorFunc;
|
||||
OH_TextEditorProxy_GetTextIndexAtCursorFunc getTextIndexAtCursorFunc;
|
||||
OH_TextEditorProxy_ReceivePrivateCommand receivePrivateCommandFunc;
|
||||
OH_TextEditorProxy_SetPreviewTextFunc setPreviewTextFunc;
|
||||
OH_TextEditorProxy_FinishTextPreview finishTextPreviewFunc;
|
||||
};
|
||||
|
||||
int32_t ErrorCodeConvert(int32_t code);
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class NativeTextChangedListener : public OHOS::MiscServices::OnTextChangedListener {
|
||||
public:
|
||||
explicit NativeTextChangedListener(OH_InputMethod_TextEditorProxy *textEditor) : textEditor_(textEditor) {};
|
||||
~NativeTextChangedListener() {};
|
||||
void InsertText(const std::u16string &text) override;
|
||||
void DeleteForward(int32_t length) override;
|
||||
void DeleteBackward(int32_t length) override;
|
||||
void SendKeyboardStatus(const OHOS::MiscServices::KeyboardStatus &status) override;
|
||||
void SendFunctionKey(const OHOS::MiscServices::FunctionKey &functionKey) override;
|
||||
void MoveCursor(const OHOS::MiscServices::Direction direction) override;
|
||||
void HandleSetSelection(int32_t start, int32_t end) override;
|
||||
void HandleExtendAction(int32_t action) override;
|
||||
std::u16string GetLeftTextOfCursor(int32_t number) override;
|
||||
std::u16string GetRightTextOfCursor(int32_t number) override;
|
||||
int32_t GetTextIndexAtCursor() override;
|
||||
int32_t ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
|
||||
int32_t SetPreviewText(const std::u16string &text, const OHOS::MiscServices::Range &range) override;
|
||||
void FinishTextPreview() override;
|
||||
|
||||
// empty impl
|
||||
void SendKeyEventFromInputMethod(const KeyEvent &event) override {};
|
||||
void SetKeyboardStatus(bool status) override {};
|
||||
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override {};
|
||||
|
||||
private:
|
||||
InputMethod_KeyboardStatus ConvertToCKeyboardStatus(OHOS::MiscServices::KeyboardStatus status);
|
||||
InputMethod_EnterKeyType ConvertToCEnterKeyType(OHOS::MiscServices::EnterKeyType enterKeyType);
|
||||
InputMethod_Direction ConvertToCDirection(OHOS::MiscServices::Direction direction);
|
||||
InputMethod_ExtendAction ConvertToCExtendAction(int32_t action);
|
||||
|
||||
constexpr static int32_t MAX_TEXT_LENGTH = 8 * 1024;
|
||||
|
||||
OH_InputMethod_TextEditorProxy *textEditor_;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
#endif // NATIVE_TEXT_EDITOR_H
|
898
frameworks/ndk/src/native_input_method_texteditor_proxy.cpp
Normal file
898
frameworks/ndk/src/native_input_method_texteditor_proxy.cpp
Normal file
@ -0,0 +1,898 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "global.h"
|
||||
#include "native_text_editor.h"
|
||||
|
||||
using namespace OHOS::MiscServices;
|
||||
OH_InputMethod_TextEditorProxy *OH_TextEditorProxy_New()
|
||||
{
|
||||
return new OH_InputMethod_TextEditorProxy();
|
||||
}
|
||||
void OH_TextEditorProxy_Delete(OH_InputMethod_TextEditorProxy *proxy)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return;
|
||||
}
|
||||
delete proxy;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetGetTextConfigFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextConfigFunc getTextConfigFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (getTextConfigFunc == nullptr) {
|
||||
IMSA_HILOGE("getTextConfigFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->getTextConfigFunc = getTextConfigFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextEditorProxy_SetInsertTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_InsertTextFunc insertTextFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (insertTextFunc == nullptr) {
|
||||
IMSA_HILOGE("insertTextFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
proxy->insertTextFunc = insertTextFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetDeleteForwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteForwardFunc deleteForwardFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (deleteForwardFunc == nullptr) {
|
||||
IMSA_HILOGE("deleteForwardFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->deleteForwardFunc = deleteForwardFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetDeleteBackwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteBackwardFunc deleteBackwardFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (deleteBackwardFunc == nullptr) {
|
||||
IMSA_HILOGE("deleteBackwardFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->deleteBackwardFunc = deleteBackwardFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetSendKeyboardStatusFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendKeyboardStatusFunc sendKeyboardStatusFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (sendKeyboardStatusFunc == nullptr) {
|
||||
IMSA_HILOGE("sendKeyboardStatusFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->sendKeyboardStatusFunc = sendKeyboardStatusFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetSendEnterKeyFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendEnterKeyTypeFunc sendEnterKeyFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (sendEnterKeyFunc == nullptr) {
|
||||
IMSA_HILOGE("sendEnterKeyFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->sendEnterKeyFunc = sendEnterKeyFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetMoveCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_MoveCursor moveCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (moveCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("moveCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->moveCursorFunc = moveCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetHandleSetSelectionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleSetSelectionFunc handleSetSelectionFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (handleSetSelectionFunc == nullptr) {
|
||||
IMSA_HILOGE("handleSetSelectionFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->handleSetSelectionFunc = handleSetSelectionFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetHandleExtendActionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleExtendActionFunc handleExtendActionFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (handleExtendActionFunc == nullptr) {
|
||||
IMSA_HILOGE("handleExtendActionFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->handleExtendActionFunc = handleExtendActionFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetGetLeftTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetLeftTextOfCursorFunc getLeftTextOfCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (getLeftTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getLeftTextOfCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->getLeftTextOfCursorFunc = getLeftTextOfCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextEditorProxy_SetGetRightTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetRightTextOfCursorFunc getRightTextOfCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (getRightTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getRightTextOfCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->getRightTextOfCursorFunc = getRightTextOfCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextEditorProxy_SetGetTextIndexAtCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextIndexAtCursorFunc getTextIndexAtCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (getTextIndexAtCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getTextIndexAtCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->getTextIndexAtCursorFunc = getTextIndexAtCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_SetReceivePrivateCommandFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_ReceivePrivateCommand receivePrivateCommandFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (receivePrivateCommandFunc == nullptr) {
|
||||
IMSA_HILOGE("receivePrivateCommandFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->receivePrivateCommandFunc = receivePrivateCommandFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextEditorProxy_SetSetPreviewTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SetPreviewTextFunc setPreviewTextFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (setPreviewTextFunc == nullptr) {
|
||||
IMSA_HILOGE("setPreviewTextFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->setPreviewTextFunc = setPreviewTextFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextEditorProxy_SetFinishTextPreviewFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_FinishTextPreview finishTextPreviewFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (finishTextPreviewFunc == nullptr) {
|
||||
IMSA_HILOGE("finishTextPreviewFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
proxy->finishTextPreviewFunc = finishTextPreviewFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetGetTextConfigFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextConfigFunc *getTextConfigFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (getTextConfigFunc == nullptr) {
|
||||
IMSA_HILOGE("getTextConfigFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*getTextConfigFunc = proxy->getTextConfigFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetInsertTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_InsertTextFunc *insertTextFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (insertTextFunc == nullptr) {
|
||||
IMSA_HILOGE("insertTextFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*insertTextFunc = proxy->insertTextFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextEditorProxy_GetDeleteForwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteForwardFunc *deleteForwardFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (deleteForwardFunc == nullptr) {
|
||||
IMSA_HILOGE("deleteForwardFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*deleteForwardFunc = proxy->deleteForwardFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetDeleteBackwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteBackwardFunc *deleteBackwardFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (deleteBackwardFunc == nullptr) {
|
||||
IMSA_HILOGE("deleteBackwardFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*deleteBackwardFunc = proxy->deleteBackwardFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetSendKeyboardStatusFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendKeyboardStatusFunc *sendKeyboardStatusFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (sendKeyboardStatusFunc == nullptr) {
|
||||
IMSA_HILOGE("sendKeyboardStatusFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*sendKeyboardStatusFunc = proxy->sendKeyboardStatusFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetSendEnterKeyFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendEnterKeyTypeFunc *sendEnterKeyFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (sendEnterKeyFunc == nullptr) {
|
||||
IMSA_HILOGE("sendEnterKeyFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*sendEnterKeyFunc = proxy->sendEnterKeyFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetMoveCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_MoveCursor *moveCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (moveCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("moveCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*moveCursorFunc = proxy->moveCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetHandleSetSelectionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleSetSelectionFunc *handleSetSelectionFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (handleSetSelectionFunc == nullptr) {
|
||||
IMSA_HILOGE("handleSetSelectionFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*handleSetSelectionFunc = proxy->handleSetSelectionFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetHandleExtendActionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleExtendActionFunc *handleExtendActionFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (handleExtendActionFunc == nullptr) {
|
||||
IMSA_HILOGE("handleExtendActionFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*handleExtendActionFunc = proxy->handleExtendActionFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetGetLeftTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetLeftTextOfCursorFunc *getLeftTextOfCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (getLeftTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getLeftTextOfCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*getLeftTextOfCursorFunc = proxy->getLeftTextOfCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetGetRightTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetRightTextOfCursorFunc *getRightTextOfCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (getRightTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getRightTextOfCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*getRightTextOfCursorFunc = proxy->getRightTextOfCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetGetTextIndexAtCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextIndexAtCursorFunc *getTextIndexAtCursorFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (getTextIndexAtCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getTextIndexAtCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*getTextIndexAtCursorFunc = proxy->getTextIndexAtCursorFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetReceivePrivateCommandFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_ReceivePrivateCommand *receivePrivateCommandFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (receivePrivateCommandFunc == nullptr) {
|
||||
IMSA_HILOGE("receivePrivateCommandFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*receivePrivateCommandFunc = proxy->receivePrivateCommandFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetSetPreviewTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SetPreviewTextFunc *setPreviewTextFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (setPreviewTextFunc == nullptr) {
|
||||
IMSA_HILOGE("setPreviewTextFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*setPreviewTextFunc = proxy->setPreviewTextFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextEditorProxy_GetFinishTextPreviewFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_FinishTextPreview *finishTextPreviewFunc)
|
||||
{
|
||||
if (proxy == nullptr) {
|
||||
IMSA_HILOGE("proxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (finishTextPreviewFunc == nullptr) {
|
||||
IMSA_HILOGE("finishTextPreviewFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*finishTextPreviewFunc = proxy->finishTextPreviewFunc;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
OH_InputMethod_TextConfig *OH_TextConfig_New()
|
||||
{
|
||||
return new OH_InputMethod_TextConfig();
|
||||
}
|
||||
void OH_TextConfig_Delete(OH_InputMethod_TextConfig *config)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
delete config;
|
||||
}
|
||||
int32_t OH_TextConfig_SetInputType(OH_InputMethod_TextConfig *config, InputMethod_TextInputType inputType)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
config->inputType = inputType;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_SetEnterKeyType(OH_InputMethod_TextConfig *config, InputMethod_EnterKeyType enterKeyType)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
config->enterKeyType = enterKeyType;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_SetIsPreviewTextSupported(OH_InputMethod_TextConfig *config, bool supported)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
config->previewTextSupported = supported;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextConfig_SetSelection(OH_InputMethod_TextConfig *config, int32_t start, int32_t end)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
config->selectionStart = start;
|
||||
config->selectionEnd = end;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_SetWindowId(OH_InputMethod_TextConfig *config, int32_t windowId)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
config->windowId = windowId;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_TextConfig_GetInputType(OH_InputMethod_TextConfig *config, InputMethod_TextInputType *inputType)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (inputType == nullptr) {
|
||||
IMSA_HILOGE("inputType is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*inputType = config->inputType;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_GetEnterKeyType(OH_InputMethod_TextConfig *config, InputMethod_EnterKeyType *enterKeyType)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (enterKeyType == nullptr) {
|
||||
IMSA_HILOGE("enterKeyType is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*enterKeyType = config->enterKeyType;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_IsPreviewTextSupported(OH_InputMethod_TextConfig *config, bool *supported)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (supported == nullptr) {
|
||||
IMSA_HILOGE("supported is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*supported = config->previewTextSupported;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_GetCursorInfo(OH_InputMethod_TextConfig *config, OH_InputMethod_CursorInfo **cursorInfo)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (cursorInfo == nullptr) {
|
||||
IMSA_HILOGE("cursorInfo is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*cursorInfo = &config->cursorInfo;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_GetSelection(OH_InputMethod_TextConfig *config, int32_t *start, int32_t *end)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*start = config->selectionStart;
|
||||
*end = config->selectionEnd;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_TextConfig_GetWindowId(OH_InputMethod_TextConfig *config, int32_t *windowId)
|
||||
{
|
||||
if (config == nullptr) {
|
||||
IMSA_HILOGE("config is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*windowId = config->windowId;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
OH_InputMethod_TextAvoidInfo *OH_InputMethod_TextAvoidInfo_New(double positionY, double height)
|
||||
{
|
||||
return new OH_InputMethod_TextAvoidInfo({ positionY, height });
|
||||
}
|
||||
void OH_InputMethod_TextAvoidInfo_Delete(OH_InputMethod_TextAvoidInfo *info)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
IMSA_HILOGE("info is nullptr");
|
||||
return;
|
||||
}
|
||||
delete info;
|
||||
}
|
||||
int32_t OH_InputMethod_TextAvoidInfo_SetPositionY(OH_InputMethod_TextAvoidInfo *info, double positionY)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
IMSA_HILOGE("info is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
info->positionY = positionY;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_TextAvoidInfo_SetHeight(OH_InputMethod_TextAvoidInfo *info, double height)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
IMSA_HILOGE("info is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
info->height = height;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_TextAvoidInfo_GetPositionY(OH_InputMethod_TextAvoidInfo *info, double *positionY)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
IMSA_HILOGE("info is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*positionY = info->positionY;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_TextAvoidInfo_GetHeight(OH_InputMethod_TextAvoidInfo *info, double *height)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
IMSA_HILOGE("info is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*height = info->height;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
OH_InputMethod_PrivateCommand *OH_InputMethod_PrivateCommand_New(char key[], size_t keyLength)
|
||||
{
|
||||
return new OH_InputMethod_PrivateCommand({ std::string(key, keyLength), false });
|
||||
}
|
||||
void OH_InputMethod_PrivateCommand_Delete(OH_InputMethod_PrivateCommand *command)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return;
|
||||
}
|
||||
delete command;
|
||||
}
|
||||
int32_t OH_InputMethod_PrivateCommand_SetKey(OH_InputMethod_PrivateCommand *command, char key[], size_t keyLength)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (key == nullptr) {
|
||||
IMSA_HILOGE("key is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
command->key = std::string(key, keyLength);
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_PrivateCommand_SetBoolValue(OH_InputMethod_PrivateCommand *command, bool value)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
command->value = value;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_PrivateCommand_SetIntValue(OH_InputMethod_PrivateCommand *command, int32_t value)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
command->value = value;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_PrivateCommand_SetStrValue(
|
||||
OH_InputMethod_PrivateCommand *command, char value[], size_t valueLength)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (value == nullptr) {
|
||||
IMSA_HILOGE("value is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
command->value = std::string(value, valueLength);
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_InputMethod_PrivateCommand_GetKey(OH_InputMethod_PrivateCommand *command, char **key, size_t keyLength)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (key == nullptr) {
|
||||
IMSA_HILOGE("key is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*key = const_cast<char *>(command->key.c_str());
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_InputMethod_PrivateCommand_GetValueType(
|
||||
OH_InputMethod_PrivateCommand *command, InputMethod_CommandValueType *type)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (type == nullptr) {
|
||||
IMSA_HILOGE("type is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (std::holds_alternative<bool>(command->value)) {
|
||||
*type = COMMAND_VALUE_TYPE_BOOL;
|
||||
} else if (std::holds_alternative<int32_t>(command->value)) {
|
||||
*type = COMMAND_VALUE_TYPE_INT32;
|
||||
} else if (std::holds_alternative<std::string>(command->value)) {
|
||||
*type = COMMAND_VALUE_TYPE_STRING;
|
||||
} else {
|
||||
IMSA_HILOGE("value is not bool or int or string");
|
||||
*type = COMMAND_VALUE_TYPE_NONE;
|
||||
}
|
||||
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_InputMethod_PrivateCommand_GetBoolValue(OH_InputMethod_PrivateCommand *command, bool *value)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (value == nullptr) {
|
||||
IMSA_HILOGE("value is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (!std::holds_alternative<bool>(command->value)) {
|
||||
IMSA_HILOGE("value is not bool");
|
||||
return ErrorCode::ERROR_KEYWORD_NOT_FOUND;
|
||||
}
|
||||
*value = std::get<bool>(command->value);
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_PrivateCommand_GetIntValue(OH_InputMethod_PrivateCommand *command, int32_t *value)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (value == nullptr) {
|
||||
IMSA_HILOGE("value is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (!std::holds_alternative<int32_t>(command->value)) {
|
||||
IMSA_HILOGE("value is not int32_t");
|
||||
return ErrorCode::ERROR_KEYWORD_NOT_FOUND;
|
||||
}
|
||||
|
||||
*value = std::get<int32_t>(command->value);
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethod_PrivateCommand_GetStrValue(
|
||||
OH_InputMethod_PrivateCommand *command, char **value, size_t valueLength)
|
||||
{
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (value == nullptr) {
|
||||
IMSA_HILOGE("value is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (!std::holds_alternative<std::string>(command->value)) {
|
||||
IMSA_HILOGE("value is not string");
|
||||
return ErrorCode::ERROR_KEYWORD_NOT_FOUND;
|
||||
}
|
||||
|
||||
*value = const_cast<char *>(std::get<std::string>(command->value).c_str());
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
const std::map<int32_t, int32_t> ERROR_CODE_MAP = {
|
||||
{ ErrorCode::ERROR_CONTROLLER_INVOKING_FAILED, INPUT_METHOD_ERR_CONTROLLER },
|
||||
{ ErrorCode::ERROR_STATUS_PERMISSION_DENIED, INPUT_METHOD_ERR_PERMISSION },
|
||||
{ ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION, INPUT_METHOD_ERR_SYSTEM_PERMISSION },
|
||||
{ ErrorCode::ERROR_REMOTE_CLIENT_DIED, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_NOT_FOUND, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_NULL_POINTER, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_NOT_FOCUSED, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_NOT_EDITABLE, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_NOT_BOUND, INPUT_METHOD_ERR_DETACHED },
|
||||
{ ErrorCode::ERROR_CLIENT_ADD_FAILED, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_NULL_POINTER, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_BAD_PARAMETERS, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_SERVICE_START_FAILED, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_IME_START_FAILED, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_KBD_SHOW_FAILED, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_KBD_HIDE_FAILED, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_IME_NOT_STARTED, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_EX_NULL_POINTER, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_PERSIST_CONFIG, INPUT_METHOD_ERR_CONFPERSIST },
|
||||
{ ErrorCode::ERROR_PACKAGE_MANAGER, INPUT_METHOD_ERR_PACKAGEMANAGER },
|
||||
{ ErrorCode::ERROR_EX_UNSUPPORTED_OPERATION, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_EX_SERVICE_SPECIFIC, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_EX_PARCELABLE, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_EX_ILLEGAL_STATE, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_IME_START_INPUT_FAILED, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_NOT_IME, INPUT_METHOD_ERR_IME },
|
||||
{ ErrorCode::ERROR_IME, INPUT_METHOD_ERR_IMENGINE },
|
||||
{ ErrorCode::ERROR_PARAMETER_CHECK_FAILED, INPUT_METHOD_ERR_PARAMCHECK },
|
||||
{ ErrorCode::ERROR_ENABLE_IME, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_NOT_CURRENT_IME, INPUT_METHOD_ERR_IMMS },
|
||||
{ ErrorCode::ERROR_GET_TEXT_CONFIG, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_INVALID_PRIVATE_COMMAND_SIZE, INPUT_METHOD_ERR_PARAMCHECK },
|
||||
{ ErrorCode::ERROR_TEXT_LISTENER_ERROR, INPUT_METHOD_ERR_IMCLIENT },
|
||||
{ ErrorCode::ERROR_INVALID_RANGE, INPUT_METHOD_ERR_PARAMCHECK },
|
||||
};
|
||||
|
||||
constexpr int32_t ERROR_CODE_QUERY_FAILED = 1;
|
||||
int32_t ErrorCodeConvert(int32_t code)
|
||||
{
|
||||
IMSA_HILOGD("Convert start.");
|
||||
auto iter = ERROR_CODE_MAP.find(code);
|
||||
if (iter != ERROR_CODE_MAP.end()) {
|
||||
IMSA_HILOGE("ErrorCode: %{public}d", iter->second);
|
||||
return iter->second;
|
||||
}
|
||||
IMSA_HILOGD("Convert end.");
|
||||
return ERROR_CODE_QUERY_FAILED;
|
||||
}
|
355
frameworks/ndk/src/native_inputmethod_api.cpp
Normal file
355
frameworks/ndk/src/native_inputmethod_api.cpp
Normal file
@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "global.h"
|
||||
#include "input_method_controller.h"
|
||||
#include "input_method_utils.h"
|
||||
#include "inputmethod_controller_capi.h"
|
||||
#include "native_text_editor.h"
|
||||
|
||||
using namespace OHOS::MiscServices;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
struct OH_InputMethod_AttachOptions {
|
||||
bool showKeyboard;
|
||||
};
|
||||
|
||||
struct OH_InputMethod_InputMethodProxy {
|
||||
OH_InputMethod_TextEditorProxy *textEditor = nullptr;
|
||||
OHOS::sptr<NativeTextChangedListener> listener = nullptr;
|
||||
};
|
||||
|
||||
OH_InputMethod_InputMethodProxy *g_inputMethodProxy = nullptr;
|
||||
std::mutex g_textEditorProxyMapMutex;
|
||||
|
||||
int32_t OH_InputMethodProxy_ShowKeyboard(OH_InputMethod_InputMethodProxy *inputMethodProxy)
|
||||
{
|
||||
return ErrorCodeConvert(InputMethodController::GetInstance()->ShowCurrentInput());
|
||||
}
|
||||
int32_t OH_InputMethodProxy_HideKeyboard(OH_InputMethod_InputMethodProxy *inputMethodProxy)
|
||||
{
|
||||
return ErrorCodeConvert(InputMethodController::GetInstance()->HideCurrentInput());
|
||||
}
|
||||
int32_t OH_InputMethodProxy_NotifySelectionChange(
|
||||
OH_InputMethod_InputMethodProxy *inputMethodProxy, char16_t text[], size_t length, int start, int end)
|
||||
{
|
||||
return ErrorCodeConvert(
|
||||
InputMethodController::GetInstance()->OnSelectionChange(std::u16string(text, length), start, end));
|
||||
}
|
||||
int32_t OH_InputMethodProxy_NotifyConfigurationChange(OH_InputMethod_InputMethodProxy *inputMethodProxy,
|
||||
InputMethod_EnterKeyType enterKey, InputMethod_TextInputType textType)
|
||||
{
|
||||
Configuration info;
|
||||
info.SetEnterKeyType(static_cast<EnterKeyType>(enterKey));
|
||||
info.SetTextInputType(static_cast<TextInputType>(textType));
|
||||
return ErrorCodeConvert(InputMethodController::GetInstance()->OnConfigurationChange(info));
|
||||
}
|
||||
|
||||
OH_InputMethod_CursorInfo *OH_CursorInfo_New(double left, double top, double width, double height)
|
||||
{
|
||||
return new OH_InputMethod_CursorInfo({ left, top, width, height });
|
||||
}
|
||||
void OH_CursorInfo_Delete(OH_InputMethod_CursorInfo *cursorInfo)
|
||||
{
|
||||
if (cursorInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
delete cursorInfo;
|
||||
}
|
||||
|
||||
int32_t OH_CursorInfo_SetRect(
|
||||
OH_InputMethod_CursorInfo *cursorInfo, double left, double top, double width, double height)
|
||||
{
|
||||
if (cursorInfo == nullptr) {
|
||||
IMSA_HILOGE("cursorInfo is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
cursorInfo->left = left;
|
||||
cursorInfo->top = top;
|
||||
cursorInfo->width = width;
|
||||
cursorInfo->height = height;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_CursorInfo_GetRect(
|
||||
OH_InputMethod_CursorInfo *cursorInfo, double *left, double *top, double *width, double *height)
|
||||
{
|
||||
if (cursorInfo == nullptr) {
|
||||
IMSA_HILOGE("cursorInfo is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (left == nullptr || top == nullptr || width == nullptr || height == nullptr) {
|
||||
IMSA_HILOGE("invalid parameter");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
*left = cursorInfo->left;
|
||||
*top = cursorInfo->top;
|
||||
*width = cursorInfo->width;
|
||||
*height = cursorInfo->height;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
int32_t OH_InputMethodProxy_NotifyCursorUpdate(
|
||||
OH_InputMethod_InputMethodProxy *inputMethodProxy, OH_InputMethod_CursorInfo *cursorInfo)
|
||||
{
|
||||
if (cursorInfo == nullptr) {
|
||||
IMSA_HILOGE("cursorInfo is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
return ErrorCodeConvert(InputMethodController::GetInstance()->OnCursorUpdate(
|
||||
CursorInfo({ cursorInfo->left, cursorInfo->top, cursorInfo->width, cursorInfo->height })));
|
||||
}
|
||||
|
||||
int32_t OH_InputMethodProxy_SendPrivateCommand(OH_InputMethod_PrivateCommand *privateCommand[], size_t size)
|
||||
{
|
||||
if (privateCommand == nullptr) {
|
||||
IMSA_HILOGE("privateCommand is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, PrivateDataValue> command;
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (privateCommand[i] == nullptr) {
|
||||
IMSA_HILOGE("privateCommand[%zu] is nullptr", i);
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
command.emplace(privateCommand[i]->key, privateCommand[i]->value);
|
||||
}
|
||||
return ErrorCodeConvert(InputMethodController::GetInstance()->SendPrivateCommand(command));
|
||||
}
|
||||
|
||||
OH_InputMethod_AttachOptions *OH_AttachOptions_New(bool showKeyboard)
|
||||
{
|
||||
return new OH_InputMethod_AttachOptions({ showKeyboard });
|
||||
}
|
||||
void OH_AttachOptions_Delete(OH_InputMethod_AttachOptions *options)
|
||||
{
|
||||
if (options == nullptr) {
|
||||
return;
|
||||
}
|
||||
delete options;
|
||||
}
|
||||
int32_t OH_AttachOptions_SetShowKeyboard(OH_InputMethod_AttachOptions *options, bool showKeyboard)
|
||||
{
|
||||
if (options == nullptr) {
|
||||
IMSA_HILOGE("options is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
options->showKeyboard = showKeyboard;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_AttachOptions_IsShowKeyboard(OH_InputMethod_AttachOptions *options, bool *showKeyboard)
|
||||
{
|
||||
if (options == nullptr) {
|
||||
IMSA_HILOGE("options is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (showKeyboard == nullptr) {
|
||||
IMSA_HILOGE("showKeyboard is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*showKeyboard = options->showKeyboard;
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
static int32_t GetInputMethodProxy(OH_InputMethod_TextEditorProxy *textEditor)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(g_textEditorProxyMapMutex);
|
||||
if (g_inputMethodProxy != nullptr && textEditor == g_inputMethodProxy->textEditor) {
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
if (g_inputMethodProxy != nullptr && textEditor != g_inputMethodProxy->textEditor) {
|
||||
g_inputMethodProxy->listener = nullptr;
|
||||
delete g_inputMethodProxy;
|
||||
g_inputMethodProxy = nullptr;
|
||||
}
|
||||
OHOS::sptr<NativeTextChangedListener> listener = new NativeTextChangedListener(textEditor);
|
||||
if (listener == nullptr) {
|
||||
IMSA_HILOGE("new NativeTextChangedListener failed");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
g_inputMethodProxy = new OH_InputMethod_InputMethodProxy({ textEditor, listener });
|
||||
if (g_inputMethodProxy == nullptr) {
|
||||
IMSA_HILOGE("new OH_InputMethod_InputMethodProxy failed");
|
||||
listener = nullptr;
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
static int32_t IsValidTextEditorProxy(OH_InputMethod_TextEditorProxy *textEditor)
|
||||
{
|
||||
if (textEditor == nullptr) {
|
||||
IMSA_HILOGE("textEditor is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->getTextConfigFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->getTextConfigFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->insertTextFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->insertTextFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->deleteForwardFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->deleteForwardFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->deleteBackwardFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->deleteBackwardFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->sendKeyboardStatusFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->sendKeyboardStatusFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (textEditor->sendEnterKeyFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->sendEnterKeyFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->moveCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->moveCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->handleSetSelectionFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->handleSetSelectionFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->handleExtendActionFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->handleExtendActionFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->getLeftTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->getLeftTextOfCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->getRightTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->getRightTextOfCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (textEditor->getTextIndexAtCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->getTextIndexAtCursorFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (textEditor->receivePrivateCommandFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->receivePrivateCommandFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
if (textEditor->setPreviewTextFunc == nullptr) {
|
||||
IMSA_HILOGE("textEditor->setPreviewTextFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor->finishTextPreviewFunc) {
|
||||
IMSA_HILOGE("textEditor->finishTextPreviewFunc is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
return INPUT_METHOD_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_InputMethodController_Attach(OH_InputMethod_TextEditorProxy *textEditor,
|
||||
OH_InputMethod_AttachOptions *options, OH_InputMethod_InputMethodProxy **inputMethodProxy)
|
||||
{
|
||||
if ((IsValidTextEditorProxy(textEditor) != INPUT_METHOD_ERR_OK) || options == nullptr ||
|
||||
inputMethodProxy == nullptr) {
|
||||
IMSA_HILOGE("invalid parameter");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
int32_t errCode = GetInputMethodProxy(textEditor);
|
||||
if (errCode != INPUT_METHOD_ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
OH_InputMethod_TextConfig config;
|
||||
textEditor->getTextConfigFunc(textEditor, &config);
|
||||
|
||||
TextConfig textConfig = {
|
||||
.inputAttribute = {
|
||||
.inputPattern = static_cast<InputMethod_TextInputType>(config.inputType),
|
||||
.enterKeyType = static_cast<InputMethod_EnterKeyType>(config.enterKeyType),
|
||||
.isTextPreviewSupported = config.previewTextSupported,
|
||||
},
|
||||
.cursorInfo = {
|
||||
.left = config.cursorInfo.left,
|
||||
.top = config.cursorInfo.top,
|
||||
.width = config.cursorInfo.width,
|
||||
.height = config.cursorInfo.height,
|
||||
},
|
||||
.range = {
|
||||
.start = config.selectionStart,
|
||||
.end = config.selectionEnd,
|
||||
},
|
||||
.windowId = config.windowId,
|
||||
.positionY = config.avoidInfo.positionY,
|
||||
.height = config.avoidInfo.height,
|
||||
};
|
||||
|
||||
auto controller = InputMethodController::GetInstance();
|
||||
OHOS::sptr<NativeTextChangedListener> listener = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(g_textEditorProxyMapMutex);
|
||||
listener = g_inputMethodProxy->listener;
|
||||
}
|
||||
errCode = controller->Attach(listener, options->showKeyboard, textConfig);
|
||||
if (errCode == ErrorCode::NO_ERROR) {
|
||||
std::lock_guard<std::mutex> guard(g_textEditorProxyMapMutex);
|
||||
*inputMethodProxy = g_inputMethodProxy;
|
||||
} else {
|
||||
errCode = ErrorCodeConvert(errCode);
|
||||
}
|
||||
|
||||
return errCode;
|
||||
}
|
||||
|
||||
int32_t OH_InputMethodController_Detach(OH_InputMethod_InputMethodProxy *inputMethodProxy)
|
||||
{
|
||||
if (inputMethodProxy == nullptr) {
|
||||
IMSA_HILOGE("inputMethodProxy is nullptr");
|
||||
return INPUT_METHOD_ERR_NULL_POINTER;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(g_textEditorProxyMapMutex);
|
||||
if (g_inputMethodProxy != nullptr && inputMethodProxy == g_inputMethodProxy) {
|
||||
g_inputMethodProxy->listener = nullptr;
|
||||
delete g_inputMethodProxy;
|
||||
g_inputMethodProxy = nullptr;
|
||||
}
|
||||
}
|
||||
return ErrorCodeConvert(InputMethodController::GetInstance()->Close());
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
357
frameworks/ndk/src/native_text_changed_listener.cpp
Normal file
357
frameworks/ndk/src/native_text_changed_listener.cpp
Normal file
@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "input_method_utils.h"
|
||||
#include "native_text_editor.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
void NativeTextChangedListener::InsertText(const std::u16string &text)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->insertTextFunc == nullptr) {
|
||||
IMSA_HILOGE("insertTextFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->insertTextFunc(textEditor_, text.c_str(), text.length());
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::DeleteForward(int32_t length)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->deleteForwardFunc == nullptr) {
|
||||
IMSA_HILOGE("deleteForwardFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->deleteForwardFunc(textEditor_, length);
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::DeleteBackward(int32_t length)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->deleteBackwardFunc == nullptr) {
|
||||
IMSA_HILOGE("deleteBackwardFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->deleteBackwardFunc(textEditor_, length);
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::SendKeyboardStatus(const OHOS::MiscServices::KeyboardStatus &status)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->sendKeyboardStatusFunc == nullptr) {
|
||||
IMSA_HILOGE("sendKeyboardStatusFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->sendKeyboardStatusFunc(textEditor_, ConvertToCKeyboardStatus(status));
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::SendFunctionKey(const OHOS::MiscServices::FunctionKey &functionKey)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->sendEnterKeyFunc == nullptr) {
|
||||
IMSA_HILOGE("sendEnterKeyFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
auto enterKeyType = ConvertToCEnterKeyType(functionKey.GetEnterKeyType());
|
||||
|
||||
textEditor_->sendEnterKeyFunc(textEditor_, enterKeyType);
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::MoveCursor(const OHOS::MiscServices::Direction direction)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->moveCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("moveCursorFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->moveCursorFunc(textEditor_, ConvertToCDirection(direction));
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::HandleSetSelection(int32_t start, int32_t end)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->handleSetSelectionFunc == nullptr) {
|
||||
IMSA_HILOGE("handleSetSelectionFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->handleSetSelectionFunc(textEditor_, start, end);
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::HandleExtendAction(int32_t action)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->handleExtendActionFunc == nullptr) {
|
||||
IMSA_HILOGE("handleExtendActionFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->handleExtendActionFunc(textEditor_, ConvertToCExtendAction(action));
|
||||
}
|
||||
|
||||
std::u16string NativeTextChangedListener::GetLeftTextOfCursor(int32_t number)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return u"";
|
||||
}
|
||||
|
||||
if (textEditor_->getLeftTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getLeftTextOfCursorFunc is nullptr");
|
||||
return u"";
|
||||
}
|
||||
|
||||
if (number <= 0 || number > MAX_TEXT_LENGTH) {
|
||||
IMSA_HILOGE("number is invalid");
|
||||
return u"";
|
||||
}
|
||||
|
||||
size_t length = number + 1;
|
||||
char16_t *text = new char16_t[length];
|
||||
if (text == nullptr) {
|
||||
IMSA_HILOGE("text is nullptr");
|
||||
return u"";
|
||||
}
|
||||
|
||||
textEditor_->getLeftTextOfCursorFunc(textEditor_, number, text, &length);
|
||||
|
||||
std::u16string textStr(text, length);
|
||||
delete[] text;
|
||||
return textStr;
|
||||
}
|
||||
|
||||
std::u16string NativeTextChangedListener::GetRightTextOfCursor(int32_t number)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return u"";
|
||||
}
|
||||
|
||||
if (textEditor_->getRightTextOfCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getRightTextOfCursorFunc is nullptr");
|
||||
return u"";
|
||||
}
|
||||
|
||||
if (number <= 0 || number > MAX_TEXT_LENGTH) {
|
||||
IMSA_HILOGE("number is invalid");
|
||||
return u"";
|
||||
}
|
||||
|
||||
size_t length = number + 1;
|
||||
char16_t *text = new char16_t[length];
|
||||
if (text == nullptr) {
|
||||
IMSA_HILOGE("text is nullptr");
|
||||
return u"";
|
||||
}
|
||||
|
||||
textEditor_->getRightTextOfCursorFunc(textEditor_, number, text, &length);
|
||||
std::u16string textStr(text, length);
|
||||
delete[] text;
|
||||
return textStr;
|
||||
}
|
||||
|
||||
int32_t NativeTextChangedListener::GetTextIndexAtCursor()
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (textEditor_->getTextIndexAtCursorFunc == nullptr) {
|
||||
IMSA_HILOGE("getTextIndexAtCursorFunc is nullptr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return textEditor_->getTextIndexAtCursorFunc(textEditor_);
|
||||
}
|
||||
|
||||
int32_t NativeTextChangedListener::ReceivePrivateCommand(
|
||||
const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor_->receivePrivateCommandFunc == nullptr) {
|
||||
IMSA_HILOGE("receivePrivateCommandFunc is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
OH_InputMethod_PrivateCommand **command = new OH_InputMethod_PrivateCommand *[privateCommand.size()];
|
||||
if (command == nullptr) {
|
||||
IMSA_HILOGE("command is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
size_t index = 0;
|
||||
for (auto &item : privateCommand) {
|
||||
command[index] = new OH_InputMethod_PrivateCommand();
|
||||
command[index]->key = item.first;
|
||||
command[index]->value = item.second;
|
||||
++index;
|
||||
}
|
||||
|
||||
auto errCode = textEditor_->receivePrivateCommandFunc(textEditor_, command, privateCommand.size());
|
||||
|
||||
for (size_t i = 0; i < index; ++i) {
|
||||
delete command[i];
|
||||
}
|
||||
delete[] command;
|
||||
return errCode;
|
||||
}
|
||||
|
||||
int32_t NativeTextChangedListener::SetPreviewText(const std::u16string &text, const OHOS::MiscServices::Range &range)
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (textEditor_->setPreviewTextFunc == nullptr) {
|
||||
IMSA_HILOGE("setPreviewTextFunc is nullptr");
|
||||
return ErrorCode::ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
return textEditor_->setPreviewTextFunc(textEditor_, text.c_str(), text.length(), range.start, range.end);
|
||||
}
|
||||
|
||||
void NativeTextChangedListener::FinishTextPreview()
|
||||
{
|
||||
if (textEditor_ == nullptr) {
|
||||
IMSA_HILOGE("textEditor_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEditor_->finishTextPreviewFunc == nullptr) {
|
||||
IMSA_HILOGE("finishTextPreviewFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
textEditor_->finishTextPreviewFunc(textEditor_);
|
||||
}
|
||||
|
||||
InputMethod_KeyboardStatus NativeTextChangedListener::ConvertToCKeyboardStatus(
|
||||
OHOS::MiscServices::KeyboardStatus status)
|
||||
{
|
||||
switch (status) {
|
||||
case OHOS::MiscServices::KeyboardStatus::HIDE:
|
||||
return KEYBOARD_STATUS_HIDE;
|
||||
case OHOS::MiscServices::KeyboardStatus::SHOW:
|
||||
return KEYBOARD_STATUS_SHOW;
|
||||
default:
|
||||
return KEYBOARD_STATUS_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
InputMethod_EnterKeyType NativeTextChangedListener::ConvertToCEnterKeyType(
|
||||
OHOS::MiscServices::EnterKeyType enterKeyType)
|
||||
{
|
||||
switch (enterKeyType) {
|
||||
case OHOS::MiscServices::EnterKeyType::NONE:
|
||||
return ENTER_KEY_NONE;
|
||||
case OHOS::MiscServices::EnterKeyType::GO:
|
||||
return ENTER_KEY_GO;
|
||||
case OHOS::MiscServices::EnterKeyType::SEARCH:
|
||||
return ENTER_KEY_SEARCH;
|
||||
case OHOS::MiscServices::EnterKeyType::SEND:
|
||||
return ENTER_KEY_SEND;
|
||||
case OHOS::MiscServices::EnterKeyType::NEXT:
|
||||
return ENTER_KEY_NEXT;
|
||||
case OHOS::MiscServices::EnterKeyType::DONE:
|
||||
return ENTER_KEY_DONE;
|
||||
case OHOS::MiscServices::EnterKeyType::PREVIOUS:
|
||||
return ENTER_KEY_PREVIOUS;
|
||||
case OHOS::MiscServices::EnterKeyType::NEW_LINE:
|
||||
return ENTER_KEY_NEWLINE;
|
||||
default:
|
||||
return ENTER_KEY_UNSPECIFIED;
|
||||
}
|
||||
}
|
||||
|
||||
InputMethod_Direction NativeTextChangedListener::ConvertToCDirection(OHOS::MiscServices::Direction direction)
|
||||
{
|
||||
switch (direction) {
|
||||
case OHOS::MiscServices::Direction::NONE:
|
||||
return DIRECTION_NONE;
|
||||
case OHOS::MiscServices::Direction::UP:
|
||||
return DIRECTION_UP;
|
||||
case OHOS::MiscServices::Direction::DOWN:
|
||||
return DIRECTION_DOWN;
|
||||
case OHOS::MiscServices::Direction::LEFT:
|
||||
return DIRECTION_LEFT;
|
||||
case OHOS::MiscServices::Direction::RIGHT:
|
||||
return DIRECTION_RIGHT;
|
||||
default:
|
||||
return DIRECTION_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
InputMethod_ExtendAction NativeTextChangedListener::ConvertToCExtendAction(int32_t action)
|
||||
{
|
||||
switch (action) {
|
||||
case static_cast<int32_t>(OHOS::MiscServices::ExtendAction::SELECT_ALL):
|
||||
return EXTEND_ACTION_SELECT_ALL;
|
||||
case static_cast<int32_t>(OHOS::MiscServices::ExtendAction::CUT):
|
||||
return EXTEND_ACTION_CUT;
|
||||
case static_cast<int32_t>(OHOS::MiscServices::ExtendAction::COPY):
|
||||
return EXTEND_ACTION_COPY;
|
||||
case static_cast<int32_t>(OHOS::MiscServices::ExtendAction::PASTE):
|
||||
return EXTEND_ACTION_PASTE;
|
||||
default:
|
||||
IMSA_HILOGE("invalid action:%{public}d", action);
|
||||
return EXTEND_ACTION_SELECT_ALL;
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
284
interfaces/kits/c/inputmethod_controller_capi.h
Normal file
284
interfaces/kits/c/inputmethod_controller_capi.h
Normal file
@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_INPUTMETHOD_CONTROLLER_CAPI_H
|
||||
#define OHOS_INPUTMETHOD_CONTROLLER_CAPI_H
|
||||
/**
|
||||
* @addtogroup InputMethod
|
||||
* @{
|
||||
*
|
||||
* @brief InputMethod Controller API.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file inputmethod_controller_capi.h
|
||||
*
|
||||
* @brief xxxx
|
||||
*
|
||||
* @library libohinputmethod.so
|
||||
* @kit IMEKit
|
||||
* @syscap SystemCapability.MiscServices.InputMethodFramework
|
||||
* @since 12
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
typedef enum {
|
||||
KEYBOARD_STATUS_NONE = 0,
|
||||
KEYBOARD_STATUS_HIDE = 1,
|
||||
KEYBOARD_STATUS_SHOW = 2,
|
||||
} InputMethod_KeyboardStatus;
|
||||
|
||||
typedef enum {
|
||||
ENTER_KEY_UNSPECIFIED = 0,
|
||||
ENTER_KEY_NONE = 1,
|
||||
ENTER_KEY_GO = 2,
|
||||
ENTER_KEY_SEARCH = 3,
|
||||
ENTER_KEY_SEND = 4,
|
||||
ENTER_KEY_NEXT = 5,
|
||||
ENTER_KEY_DONE = 6,
|
||||
ENTER_KEY_PREVIOUS = 7,
|
||||
ENTER_KEY_NEWLINE = 8,
|
||||
} InputMethod_EnterKeyType;
|
||||
|
||||
typedef enum {
|
||||
DIRECTION_NONE = 0,
|
||||
DIRECTION_UP = 1,
|
||||
DIRECTION_DOWN = 2,
|
||||
DIRECTION_LEFT = 3,
|
||||
DIRECTION_RIGHT = 4,
|
||||
} InputMethod_Direction;
|
||||
|
||||
typedef enum {
|
||||
EXTEND_ACTION_SELECT_ALL = 0,
|
||||
EXTEND_ACTION_CUT = 3,
|
||||
EXTEND_ACTION_COPY = 4,
|
||||
EXTEND_ACTION_PASTE = 5,
|
||||
} InputMethod_ExtendAction;
|
||||
|
||||
typedef enum {
|
||||
TEXT_INPUT_TYPE_NONE = -1,
|
||||
TEXT_INPUT_TYPE_TEXT = 0,
|
||||
TEXT_INPUT_TYPE_MULTILINE = 1,
|
||||
TEXT_INPUT_TYPE_NUMBER = 2,
|
||||
TEXT_INPUT_TYPE_PHONE = 3,
|
||||
TEXT_INPUT_TYPE_DATETIME = 4,
|
||||
TEXT_INPUT_TYPE_EMAIL_ADDRESS = 5,
|
||||
TEXT_INPUT_TYPE_URL = 6,
|
||||
TEXT_INPUT_TYPE_VISIBLE_PASSWORD = 7,
|
||||
TEXT_INPUT_TYPE_NUMBER_PASSWORD = 8,
|
||||
TEXT_INPUT_TYPE_SCREEN_LOCK_PASSWORD = 9,
|
||||
TEXT_INPUT_TYPE_USER_NAME = 10,
|
||||
TEXT_INPUT_TYPE_NEW_PASSWORD = 11,
|
||||
TEXT_INPUT_TYPE_NUMBER_DECIMAL = 12,
|
||||
} InputMethod_TextInputType;
|
||||
|
||||
typedef enum {
|
||||
COMMAND_VALUE_TYPE_NONE = 0,
|
||||
COMMAND_VALUE_TYPE_STRING = 1,
|
||||
COMMAND_VALUE_TYPE_BOOL = 2,
|
||||
COMMAND_VALUE_TYPE_INT32 = 3,
|
||||
} InputMethod_CommandValueType;
|
||||
|
||||
typedef enum {
|
||||
INPUT_METHOD_ERR_OK = 0,
|
||||
INPUT_METHOD_ERR_PERMISSION = 201,
|
||||
INPUT_METHOD_ERR_SYSTEM_PERMISSION = 202,
|
||||
INPUT_METHOD_ERR_PARAMCHECK = 401,
|
||||
INPUT_METHOD_ERR_UNSUPPORTED = 801,
|
||||
INPUT_METHOD_ERR_PACKAGEMANAGER = 12800001,
|
||||
INPUT_METHOD_ERR_IMENGINE = 12800002,
|
||||
INPUT_METHOD_ERR_IMCLIENT = 12800003,
|
||||
INPUT_METHOD_ERR_IME = 12800004,
|
||||
INPUT_METHOD_ERR_CONFPERSIST = 12800005,
|
||||
INPUT_METHOD_ERR_CONTROLLER = 12800006,
|
||||
INPUT_METHOD_ERR_SETTINGS = 12800007,
|
||||
INPUT_METHOD_ERR_IMMS = 12800008,
|
||||
INPUT_METHOD_ERR_DETACHED = 12800009,
|
||||
INPUT_METHOD_ERR_NULL_POINTER = 12800010,
|
||||
} InputMethod_ErrorCode;
|
||||
|
||||
typedef struct OH_InputMethod_CursorInfo OH_InputMethod_CursorInfo;
|
||||
typedef struct OH_InputMethod_TextConfig OH_InputMethod_TextConfig;
|
||||
typedef struct OH_InputMethod_TextEditorProxy OH_InputMethod_TextEditorProxy;
|
||||
typedef struct OH_InputMethod_InputMethodProxy OH_InputMethod_InputMethodProxy;
|
||||
typedef struct OH_InputMethod_AttachOptions OH_InputMethod_AttachOptions;
|
||||
typedef struct OH_InputMethod_TextAvoidInfo OH_InputMethod_TextAvoidInfo;
|
||||
typedef struct OH_InputMethod_PrivateCommand OH_InputMethod_PrivateCommand;
|
||||
|
||||
int32_t OH_InputMethodController_Attach(OH_InputMethod_TextEditorProxy *textEditorProxy,
|
||||
OH_InputMethod_AttachOptions *options, OH_InputMethod_InputMethodProxy **inputMethodProxy);
|
||||
int32_t OH_InputMethodController_Detach(OH_InputMethod_InputMethodProxy *inputMethodProxy);
|
||||
|
||||
int32_t OH_InputMethodProxy_ShowKeyboard(OH_InputMethod_InputMethodProxy *inputMethodProxy);
|
||||
int32_t OH_InputMethodProxy_HideKeyboard(OH_InputMethod_InputMethodProxy *inputMethodProxy);
|
||||
int32_t OH_InputMethodProxy_NotifySelectionChange(
|
||||
OH_InputMethod_InputMethodProxy *inputMethodProxy, char16_t text[], size_t length, int start, int end);
|
||||
int32_t OH_InputMethodProxy_NotifyConfigurationChange(OH_InputMethod_InputMethodProxy *inputMethodProxy,
|
||||
InputMethod_EnterKeyType enterKey, InputMethod_TextInputType textType);
|
||||
int32_t OH_InputMethodProxy_NotifyCursorUpdate(
|
||||
OH_InputMethod_InputMethodProxy *inputMethodProxy, OH_InputMethod_CursorInfo *cursorInfo);
|
||||
int32_t OH_InputMethodProxy_SendPrivateCommand(OH_InputMethod_PrivateCommand *privateCommand[], size_t size);
|
||||
|
||||
OH_InputMethod_CursorInfo *OH_CursorInfo_New(double left, double top, double width, double height);
|
||||
void OH_CursorInfo_Delete(OH_InputMethod_CursorInfo *cursorInfo);
|
||||
int32_t OH_CursorInfo_SetRect(
|
||||
OH_InputMethod_CursorInfo *cursorInfo, double left, double top, double width, double height);
|
||||
int32_t OH_CursorInfo_GetRect(
|
||||
OH_InputMethod_CursorInfo *cursorInfo, double *left, double *top, double *width, double *height);
|
||||
|
||||
OH_InputMethod_TextConfig *OH_TextConfig_New();
|
||||
void OH_TextConfig_Delete(OH_InputMethod_TextConfig *config);
|
||||
int32_t OH_TextConfig_SetInputType(OH_InputMethod_TextConfig *config, InputMethod_TextInputType inputType);
|
||||
int32_t OH_TextConfig_SetEnterKeyType(OH_InputMethod_TextConfig *config, InputMethod_EnterKeyType enterKeyType);
|
||||
int32_t OH_TextConfig_SetIsPreviewTextSupported(OH_InputMethod_TextConfig *config, bool supported);
|
||||
int32_t OH_TextConfig_SetSelection(OH_InputMethod_TextConfig *config, int32_t start, int32_t end);
|
||||
int32_t OH_TextConfig_SetWindowId(OH_InputMethod_TextConfig *config, int32_t windowId);
|
||||
|
||||
int32_t OH_TextConfig_GetInputType(OH_InputMethod_TextConfig *config, InputMethod_TextInputType *inputType);
|
||||
int32_t OH_TextConfig_GetEnterKeyType(OH_InputMethod_TextConfig *config, InputMethod_EnterKeyType *enterKeyType);
|
||||
int32_t OH_TextConfig_IsPreviewTextSupported(OH_InputMethod_TextConfig *config, bool *supported);
|
||||
int32_t OH_TextConfig_GetCursorInfo(OH_InputMethod_TextConfig *config, OH_InputMethod_CursorInfo *cursorInfo);
|
||||
int32_t OH_TextConfig_GetSelection(OH_InputMethod_TextConfig *config, int32_t *start, int32_t *end);
|
||||
int32_t OH_TextConfig_GetWindowId(OH_InputMethod_TextConfig *config, int32_t *windowId);
|
||||
|
||||
typedef void (*OH_TextEditorProxy_GetTextConfigFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, OH_InputMethod_TextConfig *config);
|
||||
typedef void (*OH_TextEditorProxy_InsertTextFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, const char16_t *text, size_t length);
|
||||
typedef void (*OH_TextEditorProxy_DeleteForwardFunc)(OH_InputMethod_TextEditorProxy *textEditorProxy, int32_t length);
|
||||
typedef void (*OH_TextEditorProxy_DeleteBackwardFunc)(OH_InputMethod_TextEditorProxy *textEditorProxy, int32_t length);
|
||||
typedef void (*OH_TextEditorProxy_SendKeyboardStatusFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, InputMethod_KeyboardStatus keyboardStatus);
|
||||
typedef void (*OH_TextEditorProxy_SendEnterKeyTypeFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, InputMethod_EnterKeyType enterKeyType);
|
||||
typedef void (*OH_TextEditorProxy_MoveCursor)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, InputMethod_Direction direction);
|
||||
typedef void (*OH_TextEditorProxy_HandleSetSelectionFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, int32_t start, int32_t end);
|
||||
typedef void (*OH_TextEditorProxy_HandleExtendActionFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, InputMethod_ExtendAction action);
|
||||
typedef void (*OH_TextEditorProxy_GetLeftTextOfCursorFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, int32_t number, char16_t text[], size_t *length);
|
||||
typedef void (*OH_TextEditorProxy_GetRightTextOfCursorFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, int32_t number, char16_t text[], size_t *length);
|
||||
typedef int32_t (*OH_TextEditorProxy_GetTextIndexAtCursorFunc)(OH_InputMethod_TextEditorProxy *textEditorProxy);
|
||||
typedef int32_t (*OH_TextEditorProxy_ReceivePrivateCommand)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, OH_InputMethod_PrivateCommand *privateCommand[], size_t size);
|
||||
typedef int32_t (*OH_TextEditorProxy_SetPreviewTextFunc)(
|
||||
OH_InputMethod_TextEditorProxy *textEditorProxy, const char16_t text[], size_t length, int32_t start, int32_t end);
|
||||
typedef void (*OH_TextEditorProxy_FinishTextPreview)(OH_InputMethod_TextEditorProxy *textEditorProxy);
|
||||
|
||||
OH_InputMethod_TextEditorProxy *OH_TextEditorProxy_New();
|
||||
void OH_TextEditorProxy_Delete(OH_InputMethod_TextEditorProxy *proxy);
|
||||
int32_t OH_TextEditorProxy_SetGetTextConfigFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextConfigFunc getTextConfigFunc);
|
||||
int32_t OH_TextEditorProxy_SetInsertTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_InsertTextFunc insertTextFunc);
|
||||
int32_t OH_TextEditorProxy_SetDeleteForwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteForwardFunc deleteForwardFunc);
|
||||
int32_t OH_TextEditorProxy_SetDeleteBackwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteBackwardFunc deleteBackwardFunc);
|
||||
int32_t OH_TextEditorProxy_SetSendKeyboardStatusFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendKeyboardStatusFunc sendKeyboardStatusFunc);
|
||||
int32_t OH_TextEditorProxy_SetSendEnterKeyFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendEnterKeyTypeFunc sendEnterKeyFunc);
|
||||
int32_t OH_TextEditorProxy_SetMoveCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_MoveCursor moveCursorFunc);
|
||||
int32_t OH_TextEditorProxy_SetHandleSetSelectionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleSetSelectionFunc handleSetSelectionFunc);
|
||||
int32_t OH_TextEditorProxy_SetHandleExtendActionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleExtendActionFunc handleExtendActionFunc);
|
||||
int32_t OH_TextEditorProxy_SetGetLeftTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetLeftTextOfCursorFunc getLeftTextOfCursorFunc);
|
||||
int32_t OH_TextEditorProxy_SetGetRightTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetRightTextOfCursorFunc getRightTextOfCursorFunc);
|
||||
int32_t OH_TextEditorProxy_SetGetTextIndexAtCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextIndexAtCursorFunc getTextIndexAtCursorFunc);
|
||||
int32_t OH_TextEditorProxy_SetReceivePrivateCommandFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_ReceivePrivateCommand receivePrivateCommandFunc);
|
||||
int32_t OH_TextEditorProxy_SetSetPreviewTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SetPreviewTextFunc setPreviewTextFunc);
|
||||
int32_t OH_TextEditorProxy_SetFinishTextPreviewFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_FinishTextPreview finishTextPreviewFunc);
|
||||
|
||||
int32_t OH_TextEditorProxy_GetGetTextConfigFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextConfigFunc *getTextConfigFunc);
|
||||
int32_t OH_TextEditorProxy_GetInsertTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_InsertTextFunc *insertTextFunc);
|
||||
int32_t OH_TextEditorProxy_GetDeleteForwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteForwardFunc *deleteForwardFunc);
|
||||
int32_t OH_TextEditorProxy_GetDeleteBackwardFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_DeleteBackwardFunc *deleteBackwardFunc);
|
||||
int32_t OH_TextEditorProxy_GetSendKeyboardStatusFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendKeyboardStatusFunc *sendKeyboardStatusFunc);
|
||||
int32_t OH_TextEditorProxy_GetSendEnterKeyFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SendEnterKeyTypeFunc *sendEnterKeyFunc);
|
||||
int32_t OH_TextEditorProxy_GetMoveCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_MoveCursor *moveCursorFunc);
|
||||
int32_t OH_TextEditorProxy_GetHandleSetSelectionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleSetSelectionFunc *handleSetSelectionFunc);
|
||||
int32_t OH_TextEditorProxy_GetHandleExtendActionFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_HandleExtendActionFunc *handleExtendActionFunc);
|
||||
int32_t OH_TextEditorProxy_GetGetLeftTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetLeftTextOfCursorFunc *getLeftTextOfCursorFunc);
|
||||
int32_t OH_TextEditorProxy_GetGetRightTextOfCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetRightTextOfCursorFunc *getRightTextOfCursorFunc);
|
||||
int32_t OH_TextEditorProxy_GetGetTextIndexAtCursorFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_GetTextIndexAtCursorFunc *getTextIndexAtCursorFunc);
|
||||
int32_t OH_TextEditorProxy_GetReceivePrivateCommandFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_ReceivePrivateCommand *receivePrivateCommandFunc);
|
||||
int32_t OH_TextEditorProxy_GetSetPreviewTextFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_SetPreviewTextFunc *setPreviewTextFunc);
|
||||
int32_t OH_TextEditorProxy_GetFinishTextPreviewFunc(
|
||||
OH_InputMethod_TextEditorProxy *proxy, OH_TextEditorProxy_FinishTextPreview *finishTextPreviewFunc);
|
||||
|
||||
OH_InputMethod_AttachOptions *OH_AttachOptions_New(bool showKeyboard);
|
||||
void OH_AttachOptions_Delete(OH_InputMethod_AttachOptions *options);
|
||||
int32_t OH_AttachOptions_IsShowKeyboard(OH_InputMethod_AttachOptions *options, bool *showKeyboard);
|
||||
|
||||
OH_InputMethod_TextAvoidInfo *OH_InputMethod_TextAvoidInfo_New(double positionY, double height);
|
||||
void OH_InputMethod_TextAvoidInfo_Delete(OH_InputMethod_TextAvoidInfo *info);
|
||||
int32_t OH_InputMethod_TextAvoidInfo_SetPositionY(OH_InputMethod_TextAvoidInfo *info, double positionY);
|
||||
int32_t OH_InputMethod_TextAvoidInfo_SetHeight(OH_InputMethod_TextAvoidInfo *info, double height);
|
||||
int32_t OH_InputMethod_TextAvoidInfo_GetPositionY(OH_InputMethod_TextAvoidInfo *info, double *positionY);
|
||||
int32_t OH_InputMethod_TextAvoidInfo_GetHeight(OH_InputMethod_TextAvoidInfo *info, double *height);
|
||||
|
||||
OH_InputMethod_PrivateCommand *OH_InputMethod_PrivateCommand_New(char key[], size_t keyLength);
|
||||
void OH_InputMethod_PrivateCommand_Delete(OH_InputMethod_PrivateCommand *command);
|
||||
int32_t OH_InputMethod_PrivateCommand_SetKey(OH_InputMethod_PrivateCommand *command, char key[], size_t keyLength);
|
||||
int32_t OH_InputMethod_PrivateCommand_SetBoolValue(OH_InputMethod_PrivateCommand *command, bool value);
|
||||
int32_t OH_InputMethod_PrivateCommand_SetIntValue(OH_InputMethod_PrivateCommand *command, int32_t value);
|
||||
int32_t OH_InputMethod_PrivateCommand_SetStrValue(
|
||||
OH_InputMethod_PrivateCommand *command, char value[], size_t valueLength);
|
||||
|
||||
int32_t OH_InputMethod_PrivateCommand_GetKey(OH_InputMethod_PrivateCommand *command, char **key, size_t keyLength);
|
||||
int32_t OH_InputMethod_PrivateCommand_GetValueType(
|
||||
OH_InputMethod_PrivateCommand *command, InputMethod_CommandValueType *type);
|
||||
int32_t OH_InputMethod_PrivateCommand_GetBoolValue(OH_InputMethod_PrivateCommand *command, bool *value);
|
||||
int32_t OH_InputMethod_PrivateCommand_GetIntValue(OH_InputMethod_PrivateCommand *command, int32_t *value);
|
||||
int32_t OH_InputMethod_PrivateCommand_GetStrValue(
|
||||
OH_InputMethod_PrivateCommand *command, char **value, size_t valueLength);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif // OHOS_INPUTMETHOD_CONTROLLER_CAPI_H
|
Loading…
Reference in New Issue
Block a user