Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings for inputmethod from IME-kit #26

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ document-features = { version = "0.2", optional = true }
ohos-drawing-sys = { path = "components/drawing", version = "0.1", optional = true}
ohos-deviceinfo-sys = { version = "0.1", optional = true, path = "components/deviceinfo"}
hitrace-sys = { version = "0.1.2", optional = true, path = "components/hitrace"}
ohos-ime-sys = { version = "0.1", optional = true, path = "components/inputmethod"}

[features]
default = ["api-10"]
Expand All @@ -29,6 +30,8 @@ drawing = ["dep:ohos-drawing-sys"]
hilog = []
## Enables bindings to `hitrace`
hitrace = ["dep:hitrace-sys"]
## Enables bindings to `inputmethod` from the IME-Kit. Empty if API-level < 12.
inputmethod = ["dep:ohos-ime-sys"]
## Enables bindings to `napi`
napi = []
## Enables bindings to `native_buffer`
Expand All @@ -46,6 +49,8 @@ all-components = [
"deviceinfo",
"drawing",
"hilog",
"hitrace",
"inputmethod",
"napi",
"native_buffer",
"native_image",
Expand All @@ -71,7 +76,8 @@ api-11 = ["api-10",
api-12 = ["api-11",
"ohos-deviceinfo-sys?/api-12",
"ohos-drawing-sys?/api-12",
"hitrace-sys?/api-12"
"hitrace-sys?/api-12",
"ohos-ime-sys?/api-12"
]
## Document available features when building the documentation
document-features = ["dep:document-features"]
Expand Down
33 changes: 33 additions & 0 deletions components/inputmethod/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "ohos-ime-sys"
version = "0.1.0"
edition = "2021"
description = "Bindings to the `inputmethod` API of OpenHarmony"
license = "Apache-2.0"
repository = "https://github.com/openharmony-rs/ohos-sys"
keywords = ["OpenHarmony", "HarmonyOS", "ffi", "ime", "inputmethod"]
exclude = ["src/**/*_nopublish.rs"]
readme = "README.md"

[dependencies]
document-features = { version = "0.2", optional = true }

[features]
default = []

#! ### OpenHarmony API level
#! The `inputmethod` API was added in API-level 12.
#! Defaults to no bindings at all, to maintain feature composability in `ohos-sys`.
#! Optionally enable one of the `api-*` features to get access to bindings for newer
#! OpenHarmony versions.

## **EXPERIMENTAL**: Enables bindings for OpenHarmony API-level 12 (beta-1).
## Will stabilize once the final version has been released.
api-12 = []
## Document available features when building the documentation
document-features = ["dep:document-features"]

[package.metadata.docs.rs]
features = ["document-features"]
targets = ["aarch64-unknown-linux-ohos", "armv7-unknown-linux-ohos", "x86_64-unknown-linux-ohos"]
all-features = true
11 changes: 11 additions & 0 deletions components/inputmethod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenHarmony Inputmethod bindings

Raw rust-bindings for the native `inputmethod` from the IME-Kit on OpenHarmony. hiTraceMeter provides APIs for system performance tracing.
Available since OpenHarmony 5.0 (API-level 12).
Please view the [HarmonyOS reference] for usage details (Link to the OpenHarmony documentation not available yet).

[HarmonyOS reference]: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/_input_method-V5

## License

Licensed under the Apache-2.0 license, matching the license of OpenHarmony.
2 changes: 2 additions & 0 deletions components/inputmethod/src/attach_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod attach_options_api12;
pub use attach_options_api12::*;
40 changes: 40 additions & 0 deletions components/inputmethod/src/attach_options/attach_options_api12.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* automatically generated by rust-bindgen 0.69.4 */

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use crate::types::*;

#[repr(C)]
pub struct InputMethod_AttachOptions {
_unused: [u8; 0],
}
extern "C" {
/** @brief Create a new {@link InputMethod_AttachOptions} instance.

@param showKeyboard Represents whether to show the keyboard.
@return If the creation succeeds, a pointer to the newly created {@link InputMethod_AttachOptions}
instance is returned. If the creation fails, NULL is returned, possible cause is insufficient memory.
@since 12*/
pub fn OH_AttachOptions_Create(showKeyboard: bool) -> *mut InputMethod_AttachOptions;
/** @brief Delete a {@link InputMethod_AttachOptions} instance.

@param options Represents a pointer to an {@link InputMethod_AttachOptions} instance which will be destroyed.
@since 12*/
pub fn OH_AttachOptions_Destroy(options: *mut InputMethod_AttachOptions);
/** @brief Get showKeyboard value from {@link InputMethod_AttachOptions}.

@param options Represents a pointer to an {@link InputMethod_AttachOptions} instance which will be get value from.
@param showKeyboard Represents showKeyboard value.
true - need to show keyboard.
false - no need to show keyboard.
@return Returns a specific error code.
{@link IME_ERR_OK} - success.
{@link IME_ERR_NULL_POINTER} - unexpected null pointer.
Specific error codes can be referenced {@link InputMethod_ErrorCode}.
@since 12*/
pub fn OH_AttachOptions_IsShowKeyboard(
options: *mut InputMethod_AttachOptions,
showKeyboard: *mut bool,
) -> InputMethod_ErrorCode;
}
2 changes: 2 additions & 0 deletions components/inputmethod/src/controller.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod controller_api12;
pub use controller_api12::*;
48 changes: 48 additions & 0 deletions components/inputmethod/src/controller/controller_api12.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* automatically generated by rust-bindgen 0.69.4 */

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use crate::attach_options::InputMethod_AttachOptions;
use crate::inputmethod_proxy::InputMethod_InputMethodProxy;
use crate::text_editor_proxy::InputMethod_TextEditorProxy;
use crate::types::*;

extern "C" {
/** @brief Attach application to the input method service.

@param textEditorProxy Represents a pointer to an {@link InputMethod_TextEditorProxy} instance.
The caller needs to manage the lifecycle of textEditorProxy.
If the call succeeds, caller cannot release textEditorProxy until the next attach or detach call.
@param options Represents a pointer to an {@link InputMethod_AttachOptions} instance.
The options when attaching input method.
@param inputMethodProxy Represents a pointer to an {@link InputMethod_InputMethodProxy} instance.
Lifecycle is mantianed until the next attach or detach call.
@return Returns a specific error code.
{@link IME_ERR_OK} - success.
{@link IME_ERR_PARAMCHECK} - parameter check failed.
{@link IME_ERR_IMCLIENT} - input method client error.
{@link IME_ERR_IMMS} - input method manager service error.
{@link IME_ERR_NULL_POINTER} - unexpected null pointer.
Specific error codes can be referenced {@link InputMethod_ErrorCode}.
@since 12*/
pub fn OH_InputMethodController_Attach(
textEditorProxy: *mut InputMethod_TextEditorProxy,
options: *mut InputMethod_AttachOptions,
inputMethodProxy: *mut *mut InputMethod_InputMethodProxy,
) -> InputMethod_ErrorCode;
/** @brief Detach application from the input method service.

@param inputMethodProxy Represents a pointer to an {@link InputMethod_InputMethodProxy} instance.
The inputMethodProxy is obtained from {@link OH_InputMethodController_Attach}.
@return Returns a specific error code.
{@link IME_ERR_OK} - success.
{@link IME_ERR_IMCLIENT} - input method client error.
{@link IME_ERR_IMMS} - input method manager service error.
{@link IME_ERR_NULL_POINTER} - unexpected null pointer.
Specific error codes can be referenced {@link InputMethod_ErrorCode}.
@since 12*/
pub fn OH_InputMethodController_Detach(
inputMethodProxy: *mut InputMethod_InputMethodProxy,
) -> InputMethod_ErrorCode;
}
2 changes: 2 additions & 0 deletions components/inputmethod/src/cursor_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod cursor_info_api12;
pub use cursor_info_api12::*;
71 changes: 71 additions & 0 deletions components/inputmethod/src/cursor_info/cursor_info_api12.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* automatically generated by rust-bindgen 0.69.4 */

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use crate::types::*;

#[repr(C)]
pub struct InputMethod_CursorInfo {
_unused: [u8; 0],
}
extern "C" {
/** @brief Create a new {@link InputMethod_CursorInfo} instance.

@param left The left point of the cursor and must be absolute coordinate of the physical screen.
@param top The top point of the cursor and must be absolute coordinate of the physical screen.
@param width The width of the cursor.
@param height The height of the cursor.
@return If the creation succeeds, a pointer to the newly created {@link InputMethod_CursorInfo}
instance is returned. If the creation fails, NULL is returned, possible cause is insufficient memory.
@since 12*/
pub fn OH_CursorInfo_Create(
left: f64,
top: f64,
width: f64,
height: f64,
) -> *mut InputMethod_CursorInfo;
/** @brief Destroy a {@link InputMethod_CursorInfo} instance.

@param cursorInfo Represents a pointer to an {@link InputMethod_CursorInfo} instance which will be destroyed.
@since 12*/
pub fn OH_CursorInfo_Destroy(cursorInfo: *mut InputMethod_CursorInfo);
/** @brief Set cursor info.

@param cursorInfo Represents a pointer to an {@link InputMethod_CursorInfo} instance.
@param left The left point of the cursor and must be absolute coordinate of the physical screen.
@param top The top point of the cursor and must be absolute coordinate of the physical screen.
@param width The width of the cursor.
@param height The height of the cursor.
@return Returns a specific error code.
{@link IME_ERR_OK} - success.
{@link IME_ERR_NULL_POINTER} - unexpected null pointer.
Specific error codes can be referenced {@link InputMethod_ErrorCode}.
@since 12*/
pub fn OH_CursorInfo_SetRect(
cursorInfo: *mut InputMethod_CursorInfo,
left: f64,
top: f64,
width: f64,
height: f64,
) -> InputMethod_ErrorCode;
/** @brief Get cursor info.

@param cursorInfo Represents a pointer to an {@link InputMethod_CursorInfo} instance.
@param left The left point of the cursor and must be absolute coordinate of the physical screen.
@param top The top point of the cursor and must be absolute coordinate of the physical screen.
@param width The width of the cursor.
@param height The height of the cursor.
@return Returns a specific error code.
{@link IME_ERR_OK} - success.
{@link IME_ERR_NULL_POINTER} - unexpected null pointer.
Specific error codes can be referenced {@link InputMethod_ErrorCode}.
@since 12*/
pub fn OH_CursorInfo_GetRect(
cursorInfo: *mut InputMethod_CursorInfo,
left: *mut f64,
top: *mut f64,
width: *mut f64,
height: *mut f64,
) -> InputMethod_ErrorCode;
}
2 changes: 2 additions & 0 deletions components/inputmethod/src/inputmethod_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod inputmethod_proxy_api12;
pub use inputmethod_proxy_api12::*;
Loading