diff --git a/src/capi/io.rs b/src/capi/io.rs index 695bf11ab..0388cadc4 100644 --- a/src/capi/io.rs +++ b/src/capi/io.rs @@ -1546,6 +1546,7 @@ pub extern "C" fn chewing_cursor_Current(ctx: *const ChewingContext) -> c_int { ctx.editor.cursor() as c_int } +#[deprecated(note = "The chewing_cand_TotalPage function could achieve the same effect.")] #[tracing::instrument(skip(ctx), ret)] #[no_mangle] pub extern "C" fn chewing_cand_CheckDone(ctx: *const ChewingContext) -> c_int { diff --git a/src/capi/mod.rs b/src/capi/mod.rs index 8ca61ff72..7b5d40c29 100644 --- a/src/capi/mod.rs +++ b/src/capi/mod.rs @@ -1,6 +1,14 @@ #![deny(unsafe_op_in_unsafe_fn)] #![allow(unsafe_code)] +//! C compatible APIs. +//! +//! All items in this module are available via the C header file ``. +//! Function symbols are exposed from the libchewing shared library. +//! +//! Functions are organized into several modules according to the services +//! provided by them. + mod ffi; mod io; mod public; @@ -8,7 +16,7 @@ mod public; #[doc(hidden)] pub mod internal; -/// Initializes chewing context and environment settings +/// Initializes chewing context and environment settings. /// /// Most of the Chewing IM APIs require a [ChewingContext]. To create a /// ChewingContext you must use the [chewing_new] function. @@ -73,7 +81,7 @@ pub mod setup { /// Releases the resources used by the given Chewing IM instance. pub use super::io::chewing_delete; - /// Sets the selectAreaLen, maxChiSymbolLen and selKey parameter from pcd + /// Sets the selectAreaLen, maxChiSymbolLen and selKey parameter from pcd. /// /// The pcd argument is a pointer to a Chewing configuration data structure. /// See also the ChewingConfigData data type. @@ -143,5 +151,781 @@ pub mod setup { pub use super::public::CHEWING_LOG_ERROR; } -pub use io::*; -pub use public::*; +/// Keyboard input handling. +/// +/// Functions to handle key strokes. The return value of these functions is 0 on +/// success and -1 on failure. +pub mod input { + /// Handles all keys that do not have dedicated methods. + pub use super::io::chewing_handle_Default; + + /// Handles the Backspace key. + pub use super::io::chewing_handle_Backspace; + + /// Handles the Capslock key. + pub use super::io::chewing_handle_Capslock; + + /// Handles any number key with the Ctrl modifier. + /// + /// The value of key should be in the range between ASCII character code + /// from 0 to 9. + pub use super::io::chewing_handle_CtrlNum; + + /// Handles the Delete key. + pub use super::io::chewing_handle_Del; + + /// Handles the Enter or Return key. + pub use super::io::chewing_handle_Enter; + + /// Handles the Esc key. + pub use super::io::chewing_handle_Esc; + + /// Handles the Space key. + pub use super::io::chewing_handle_Space; + + /// Handles the Tab key. + pub use super::io::chewing_handle_Tab; + + /// Handles the Home key. + pub use super::io::chewing_handle_Home; + + /// Handles the End key. + pub use super::io::chewing_handle_End; + + /// Handles the Left key. + pub use super::io::chewing_handle_Left; + + /// Handles the Right key. + pub use super::io::chewing_handle_Right; + + /// Handles the Up key. + /// + /// See also [chewing_cand_close][super::candidates::chewing_cand_close] keyboardless API to close candidate + /// window. + pub use super::io::chewing_handle_Up; + + /// Handles the Down key. + /// + /// See also [super::io::chewing_cand_open] keyboardless API to open candidate window. + pub use super::io::chewing_handle_Down; + + /// Handles the Left key with the Shift modifier. + pub use super::io::chewing_handle_ShiftLeft; + + /// Handles the Right key with the Shift modifier. + pub use super::io::chewing_handle_ShiftRight; + + /// Handles the Space key with the Shift modifier. + pub use super::io::chewing_handle_ShiftSpace; + + /// Handles the PageUp key. + pub use super::io::chewing_handle_PageUp; + + /// Handles the PageDown key. + pub use super::io::chewing_handle_PageDown; + + /// Handles tapping the Tab key twice quickly. + pub use super::io::chewing_handle_DblTab; + + /// Handles any numeric key from the keypad. + /// + /// The value of key should be in the range between ASCII character code + /// from 0 to 9. + pub use super::io::chewing_handle_Numlock; +} + +/// Keyboard layout and variants setting. +/// +/// The Chewing IM supports many different keyboard layout and variants. Use +/// functions in this module to set the current keyboard layout for the context. +pub mod layout { + /// Sets the current keyboard layout for ctx. + /// + /// The kbtype argument must be a value defined in [KB]. + /// + /// The return value is 0 on success and -1 on failure. The keyboard type + /// will set to KB_DEFAULT if return value is -1. + pub use super::io::chewing_set_KBType; + + /// Returns the current keyboard layout index for ctx. + /// + /// The return value is the layout index defined in [KB]. + pub use super::io::chewing_get_KBType; + + /// Returns the the current layout name string of ctx. + /// + /// The return value is the name of the current layout, see also function + /// [chewing_KBStr2Num]. + /// + /// The returned pointer must be freed by + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_get_KBString; + + /// Converts the keyboard layout name from string to corresponding layout + /// index. + /// + /// If the string does not match any layout, this function returns + /// KB_DEFAULT. + /// + /// The string str might be one of the following layouts: + /// * KB_DEFAULT + /// * KB_HSU + /// * KB_IBM + /// * KB_GIN_YIEH + /// * KB_ET + /// * KB_ET26 + /// * KB_DVORAK + /// * KB_DVORAK_HSU + /// * KB_DVORAK_CP26 + /// * KB_HANYU_PINYIN + /// * KB_THL_PINYIN + /// * KB_MPS2_PINYIN + /// * KB_CARPALX + /// + /// See also [chewing_kbtype_Enumerate] for getting the list of supported + /// layouts programmatically. + pub use super::io::chewing_KBStr2Num; + + /// Returns the number of keyboard layouts supported by the Chewing IM. + pub use super::io::chewing_kbtype_Total; + + /// Starts the enumeration of the keyboard layouts. + /// + /// This function stores an iterator in the context. The iterator is only + /// destroyed after enumerate all keyboard layouts using + /// [chewing_kbtype_hasNext]. + pub use super::io::chewing_kbtype_Enumerate; + + /// Checks whether there are more keyboard layouts to enumerate. + /// + /// Returns 1 when there are more and 0 when it's the end of the iterator. + pub use super::io::chewing_kbtype_hasNext; + + /// Returns the current enumerated keyboard layout name. + /// + /// The returned string is emtpy string when enumeration is over. + /// + /// The returned value is a pointer to a character string. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_kbtype_String; + + /// Returns the current enumerated keyboard layout name. + /// + /// The returned string is emtpy string when enumeration is over. + /// + /// The return value is a const pointer to a character string. The pointer + /// is only valid immediately after checking the [chewing_kbtype_hasNext] + /// condition. + pub use super::io::chewing_kbtype_String_static; + + pub use super::public::KB; +} + +/// Input mode settings. +/// +/// The Chewing IM can switch between Chinese input mode or English mode. The +/// English mode supports input English characters directly. These functions set +/// the current input mode. +pub mod modes { + /// Sets the input mode to Chinese or English. + /// + /// The *mode* argument is one of the [CHINESE_MODE] and [SYMBOL_MODE] + /// constants. + pub use super::io::chewing_set_ChiEngMode; + + /// Returns the current Chinese/English mode setting. + pub use super::io::chewing_get_ChiEngMode; + + /// Sets the current punctuation input mode. + /// + /// The *mode* argument is one of the [FULLSHAPE_MODE] and [HALFSHAPE_MODE] + /// constants. + pub use super::io::chewing_set_ShapeMode; + + /// Returns the current punctuation mode. + pub use super::io::chewing_get_ShapeMode; + + pub use super::public::CHINESE_MODE; + pub use super::public::SYMBOL_MODE; + + pub use super::public::FULLSHAPE_MODE; + pub use super::public::HALFSHAPE_MODE; +} + +/// Candidate selection related functions. +/// +/// These functions can be used to transit the Chewing IM into candidate +/// selection state and enumerate candidates. +/// +/// # Keyboardless APIs +/// +/// The traditional chewing APIs are coupled to keyboards. They cause some +/// problems if the program like to design its own keyboard scheme, or if a +/// platform does not have certain keyboard keys (ex: mobile device). To +/// overcome these problems, the new keyboardless APIs are provided. With these +/// APIs, program can have better control over libchewing, instead of hacking +/// libchewing via fake keyboard event. +pub mod candidates { + /// Returns the number of pages of the candidates. + /// + /// If the return value is greater than zero, then the IM interface should + /// display a selection window of the candidates for the user to choose a + /// candidate. Otherwise hide the selection window. + pub use super::io::chewing_cand_TotalPage; + + /// Returns the current candidate page number. + /// + /// # Examples + /// + /// The candidates pagination could be displayed as: + /// + /// ```c + /// sprintf(buf, "[%d / %d]", + /// chewing_cand_CurrentPage(ctx), + /// chewing_cand_TotalPage(ctx)); + /// ``` + pub use super::io::chewing_cand_CurrentPage; + + /// Returns the number of the coices per page. + /// + /// See also the [chewing_set_candPerPage] function. + pub use super::io::chewing_cand_ChoicePerPage; + + /// Returns the total number of the available choices. + pub use super::io::chewing_cand_TotalChoice; + + /// Starts the enumeration of the candidates starting from the first one in + /// the current page. + /// + /// This function stores an iterator in the context. The iterator is only + /// destroyed after enumerate candidates using + /// [chewing_cand_hasNext]. + pub use super::io::chewing_cand_Enumerate; + + /// Checks if there are more candidates to enumerate. + /// + ///

+ /// ⚠ Warning: This function checks the end of total choices + /// instead of the end of current page. + ///

+ pub use super::io::chewing_cand_hasNext; + + /// Returns the current enumerated candidate string. + /// + /// The returned value is a pointer to a character string. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_cand_String; + + /// Returns the current enumerated candidate string. + /// + /// The returned string is emtpy string when enumeration is over. + /// + /// The return value is a const pointer to a character string. The pointer + /// is only valid immediately after checking the [chewing_cand_hasNext] + /// condition. + pub use super::io::chewing_cand_String_static; + + /// Checks if the candidates selection has finished. + /// + ///

+ /// ⚠ Warning: Not implemented. + ///

+ pub use super::io::chewing_cand_CheckDone; + + /// Sets the number of candidates returned per page. + /// + /// The setting is ignored if *n* is not between [MIN_SELKEY] and + /// [MAX_SELKEY] inclusive. + /// + /// The default value is MAX_SELKEY. + pub use super::io::chewing_set_candPerPage; + + /// Sets the key codes for candidate selection. + /// + /// *selkeys* is an ASCII code integer array of length [MAX_SELKEY]. The + /// second argument is unused. + /// + /// The default selection key is `1234567890`. + pub use super::io::chewing_set_selKey; + + /// Returns the current selection key setting. + /// + /// The returned value is a pointer to an integer array. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + pub use super::io::chewing_get_selKey; + + /// This function is no-op now. Use [chewing_set_selKey] instead. + pub use super::io::chewing_set_hsuSelKeyType; + + /// This function is no-op now. Use [chewing_get_selKey] instead. + pub use super::io::chewing_get_hsuSelKeyType; + + /// Opens the candidate selection window. + /// + /// This operation is only allowed when the IM editor is in entering state. + /// + /// Returns 0 when success, -1 otherwise. + pub use super::io::chewing_cand_open; + + /// Closes the candidate selection window. + /// + /// Returns 0 when success, -1 otherwise. + pub use super::io::chewing_cand_close; + + /// Returns the candidate string by its index. + /// + /// The *index* must be between 0 and [chewing_cand_TotalChoice] inclusive. + /// + /// The return value is a const pointer to a character string. The pointer + /// is only valid immediately after calling this function. + pub use super::io::chewing_cand_string_by_index_static; + + /// Selects the candidate by its index. + /// + /// The *index* must be between 0 and [chewing_cand_TotalChoice] inclusive. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the *index* is out of range or the candidate + /// selection window is not currently open. + pub use super::io::chewing_cand_choose_by_index; + + /// Sets the candidate list to the first (longest) candidate list. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the candidate selection window is not currently + /// open. + pub use super::io::chewing_cand_list_first; + + /// Sets the candidate list to the last (shortest) candidate list. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the candidate selection window is not currently + /// open. + pub use super::io::chewing_cand_list_last; + + /// Checks whether there is a next (shorter) candidate list. + /// + /// Returns 1 (true) when there is a next candidate list, 0 otherwise. + pub use super::io::chewing_cand_list_has_next; + + /// Checks whether there is a previous (longer) candidate list. + /// + /// Returns 1 (true) when there is a previous candidate list, 0 otherwise. + pub use super::io::chewing_cand_list_has_prev; + + /// Changes current candidate list to next candidate list. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the candidate selection window is not currently + /// open. + pub use super::io::chewing_cand_list_next; + + /// Changes current candidate list to previous candidate list. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the candidate selection window is not currently + /// open. + pub use super::io::chewing_cand_list_prev; + + pub use super::public::MAX_SELKEY; + pub use super::public::MIN_SELKEY; + + pub use super::public::HSU_SELKEY_TYPE1; + pub use super::public::HSU_SELKEY_TYPE2; +} + +/// Output handling. +pub mod output { + /// Checks whether the commit buffer has something to read. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_commit_Check; + + /// Returns the string in the commit buffer. + /// + /// The returned value is a pointer to a character string. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_commit_String; + + /// Returns the string in the commit buffer. + /// + /// The return value is a const pointer to a character string. The pointer + /// is only valid immediately after checking the [chewing_commit_Check] + /// condition. + pub use super::io::chewing_commit_String_static; + + /// Checks whether the previous keystroke is ignored or not. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_keystroke_CheckIgnore; + + /// Checks whether the previous keystroke is absorbed or not. + /// + /// Returns 1 when true, 0 when false. + /// + /// Absorbed key means the Chewing IM state machine has accepted the key and + /// changed its state accordingly. Caller should check various output + /// buffers to see if they need to update the display. + pub use super::io::chewing_keystroke_CheckAbsorb; + + /// Checks whether there is output in the pre-edit buffer. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_buffer_Check; + + /// Returns the length of the string in current pre-edit buffer. + /// + ///

+ /// ⚠ Warning: The length is calculated in terms of + /// unicode characters. One character might occupy multiple bytes. + ///

+ pub use super::io::chewing_buffer_Len; + + /// Returns the current output in the pre-edit buffer. + /// + /// The returned value is a pointer to a character string. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_buffer_String; + + /// Returns the current output in the pre-edit buffer. + /// + /// The return value is a const pointer to a character string. The pointer + /// is only valid immediately after checking the [chewing_buffer_Check] + /// condition. + pub use super::io::chewing_buffer_String_static; + + /// Returns whether there are phonetic pre-edit string in the buffer. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_bopomofo_Check; + + /// Returns whether there are phonetic pre-edit string in the buffer. Here + /// “zuin” means bopomofo, a phonetic system for transcribing Chinese, + /// especially Mandarin. + /// + /// Returns **0** when true, **1** when false. + /// + ///

+ /// ⚠ Warning: The return value of this function is + /// different from other newer functions that returns boolean value. + ///

+ pub use super::io::chewing_zuin_Check; + + /// Returns the phonetic characters in the pre-edit buffer. + /// + /// The return value is a const pointer to a character string. The pointer + /// is only valid immediately after checking the [chewing_bopomofo_Check] + /// condition. + pub use super::io::chewing_bopomofo_String_static; + + /// Returns the phonetic characters in the pre-edit buffer. + /// + /// The bopomofo_count argument is a output argument. It will contain the + /// number of phonetic characters in the returned string. + /// + /// The returned value is a pointer to a character string. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_zuin_String; + + /// Returns the current cursor position in the pre-edit buffer. + pub use super::io::chewing_cursor_Current; + + /// Starts the enumeration of intervals of recognized phrases. + /// + /// This function stores an iterator in the context. The iterator is only + /// destroyed after enumerate all intervals using + /// [chewing_interval_hasNext]. + pub use super::io::chewing_interval_Enumerate; + + /// Checks whether there are more intervals or not. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_interval_hasNext; + + /// Returns the current enumerated interval. + /// + /// The *it* argument is an output argument. + pub use super::io::chewing_interval_Get; + + /// Returns whether there is auxiliary string in the auxiliary buffer. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_aux_Check; + + /// Returns the length of the auxiliary string in the auxiliary buffer. + /// + ///

+ /// ⚠ Warning: The length is calculated in terms of + /// unicode characters. One character might occupy multiple bytes. + ///

+ pub use super::io::chewing_aux_Length; + + /// Returns the current auxiliary string. + /// + /// The returned value is a pointer to a character string. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_aux_String; + + /// Returns the current auxiliary string. + /// + /// The return value is a const pointer to a character string. The pointer + /// is only valid immediately after checking the [chewing_aux_Check] + /// condition. + pub use super::io::chewing_aux_String_static; + + /// Returns the phonetic sequence in the Chewing IM internal state machine. + /// + /// The return value is a pointer to a unsigned short array. The values in + /// the array is encoded Bopomofo phone. The memory must be freed by the + /// caller using function [chewing_free][super::setup::chewing_free]. + pub use super::io::chewing_get_phoneSeq; + + /// Returns the length of the phonetic sequence in the Chewing IM internal + /// state machine. + pub use super::io::chewing_get_phoneSeqLen; + + /// Converts the u16 encoded syllables to a bopomofo string. + /// + /// If both of the buf and the len are 0, this function will return buf + /// length for bopomofo including the null character so that caller can + /// prepare enough buffer for it. + /// + /// Returns 0 on success, -1 on failure. + pub use super::io::chewing_phone_to_bopomofo; + + /// Commits the current preedit buffer content to the commit buffer. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the IM editor is not in entering state. + pub use super::io::chewing_commit_preedit_buf; + + /// Clears the current preedit buffer content. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the IM editor is not in entering state. + pub use super::io::chewing_clean_preedit_buf; + + /// Clears the current bopomofo buffer content. + /// + /// Returns 0 when success, -1 otherwise. + /// + /// # Errors + /// + /// This function fails if the IM editor is not in entering state. + pub use super::io::chewing_clean_bopomofo_buf; + + pub use super::public::IntervalType; +} + +/// Userphrase handling. +pub mod userphrase { + /// Starts a userphrase enumeration. + /// + /// Caller shall call this function prior [chewing_userphrase_has_next] and + /// [chewing_userphrase_get] in order to enumerate userphrase correctly. + /// + /// This function stores an iterator in the context. The iterator is only + /// destroyed after enumerate all userphrases using + /// [chewing_userphrase_has_next]. + /// + /// Returns 0 on success, -1 on failure. + /// + /// # Examples + /// + /// ```c + /// chewing_userphrase_enumerate(ctx); + /// while (chewing_userphrase_has_next(ctx, &phrase_len, &bopomofo_len)) { + /// phrase = malloc(phrase_len); + /// if (!phrase) goto error; + /// bopomofo = malloc(bopomofo_len); + /// if (!bopomofo) goto error; + /// + /// chewing_userphrase_get(ctx, phrase, phrase_len, bopomofo, bopomofo_len); + /// /* do somthing */ + /// } + /// ``` + pub use super::io::chewing_userphrase_enumerate; + + /// Checks if there is another userphrase in current enumeration. + /// + /// The *phrase_len* and *bopomofo_len* are output buffer length needed by the userphrase and its bopomofo string. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_userphrase_has_next; + + /// Gets the current enumerated userphrase. + /// + /// The *phrase_buf* and *bopomofo_buf* are userphrase and its bopomofo + /// buffer provided by caller. The length of the buffers can be retrived + /// from [chewing_userphrase_has_next]. + /// + /// Returns 0 on success, -1 on failure. + pub use super::io::chewing_userphrase_get; + + /// Adds new userphrase to the user dictionary. + /// + /// Returns how many phrases are added, -1 on failure. + pub use super::io::chewing_userphrase_add; + + /// Removes a userphrase from the user dictionary. + /// + /// Returns how many phrases are removed, -1 on failure. + pub use super::io::chewing_userphrase_remove; + + /// Searchs if a userphrase is in the user dictionary. + /// + /// Returns 1 when true, 0 when false. + pub use super::io::chewing_userphrase_lookup; +} + +/// Global settings. +/// +/// The Chewing IM could be customized in some small details. These functions +/// provide the configuration interfaces to the front-end. +pub mod globals { + /// Sets the maximum number of the Chinese characters allowed in the + /// pre-edit buffer. + /// + /// If the pre-edit string is longer than this number then the leading part + /// will be committed automatically. The range of n shall between + /// [MIN_CHI_SYMBOL_LEN] and [MAX_CHI_SYMBOL_LEN]. + pub use super::io::chewing_set_maxChiSymbolLen; + + /// Returns the maximum number of the Chinese characters allowed in the + /// pre-edit buffer. + pub use super::io::chewing_get_maxChiSymbolLen; + + /// Sets the direction to add new phrases when using CtrlNum. + /// + /// The direction argument is 0 when the direction is backward and 1 when + /// the direction is forward. + pub use super::io::chewing_set_addPhraseDirection; + + /// Returns the direction to add new phrases when using CtrlNum. + /// + /// The direction argument is 0 when the direction is backward and 1 when + /// the direction is forward. + pub use super::io::chewing_get_addPhraseDirection; + + /// Sets whether the Space key is treated as a selection key. + /// + /// When the mode argument is 1, the Space key will initiate the candidates + /// selection mode. + pub use super::io::chewing_set_spaceAsSelection; + + /// Returns whether the Space key is treated as a selection key. + /// + /// Returns 1 when the Space key will initiate the candidates selection + /// mode. + pub use super::io::chewing_get_spaceAsSelection; + + /// Sets whether the Esc key will flush the current pre-edit buffer. + /// + /// When the mode argument is 1, the Esc key will flush the pre-edit buffer. + pub use super::io::chewing_set_escCleanAllBuf; + + /// Returns whether the Esc key will flush the current pre-edit buffer. + /// + /// Returns 1 when the Esc key will flush the pre-edit buffer. + pub use super::io::chewing_get_escCleanAllBuf; + + /// Sets whether the Chewing IM will automatically shift cursor after + /// selection. + pub use super::io::chewing_set_autoShiftCur; + + /// Returns whether the Chewing IM will automatically shift cursor after + /// selection. + pub use super::io::chewing_get_autoShiftCur; + + /// Sets the current normal/easy symbol mode. + /// + /// In easy symbol mode, the key be will changed to its related easy symbol + /// in swkb.dat. The format of swkb.dat is key symbol pair per line. The + /// valid value of key is [0-9A-Z]. The lower case character in key will be + /// changed to upper case when loading swkb.dat. However, in easy symbol + /// mode, only [0-9A-Z] are accepted. + /// + /// The mode argument is 0 for normal mode or other for easy symbol mode. + pub use super::io::chewing_set_easySymbolInput; + + /// Sets whether the phrase for candidates selection is before the cursor or + /// after the cursor. + pub use super::io::chewing_set_phraseChoiceRearward; + + /// Returns the phrase choice rearward setting. + pub use super::io::chewing_get_phraseChoiceRearward; + + /// Sets enable or disable the automatic learning. + /// + /// The mode argument is be one of the [AUTOLEARN_ENABLED] and + /// [AUTOLEARN_DISABLED] constants. + pub use super::io::chewing_set_autoLearn; + + /// Returns whether the automatic learning is enabled or disabled. + pub use super::io::chewing_get_autoLearn; + + pub use super::public::MAX_CHI_SYMBOL_LEN; + pub use super::public::MIN_CHI_SYMBOL_LEN; + + pub use super::public::MAX_PHONE_SEQ_LEN; + pub use super::public::MAX_PHRASE_LEN; + + pub use super::public::AUTOLEARN_DISABLED; + pub use super::public::AUTOLEARN_ENABLED; +} diff --git a/src/capi/public.rs b/src/capi/public.rs index 0391295da..5f8d12c77 100644 --- a/src/capi/public.rs +++ b/src/capi/public.rs @@ -6,41 +6,52 @@ use crate::{ editor::{keyboard::AnyKeyboardLayout, syllable::KeyboardLayoutCompat, Editor}, }; -/// Indicates chewing will translate keystrokes to Chinese characters +/// Indicates chewing will translate keystrokes to Chinese characters. pub const CHINESE_MODE: c_int = 1; -/// Indicates the input mode is translating keystrokes to symbols +/// Indicates the input mode is translating keystrokes to symbols. pub const SYMBOL_MODE: c_int = 0; -/// Indicates chewing will translate latin and puctuation characters to double-with characters +/// Indicates chewing will translate latin and puctuation characters to +/// double-with characters. pub const FULLSHAPE_MODE: c_int = 1; -/// Indicates chewing will not translate latin and puctuation characters +/// Indicates chewing will not translate latin and puctuation characters. pub const HALFSHAPE_MODE: c_int = 0; -/// Indicates automatic user phrase learning is disabled +/// Indicates automatic user phrase learning is disabled. pub const AUTOLEARN_DISABLED: usize = 1; -/// Indicates automatic user phrase learning is enabled +/// Indicates automatic user phrase learning is enabled. pub const AUTOLEARN_ENABLED: usize = 0; +/// The minimal size of pre-edit buffer. +pub const MIN_CHI_SYMBOL_LEN: usize = 0; +/// The maximum size of pre-edit buffer. +pub const MAX_CHI_SYMBOL_LEN: usize = MAX_PHONE_SEQ_LEN - MAX_PHRASE_LEN; +/// The size of internal buffer for pre-edit buffer. +pub const MAX_PHONE_SEQ_LEN: usize = 50; +/// The maximum phrase size. +pub const MAX_PHRASE_LEN: usize = 11; -/// The number of minimum candidates that are selectable via shortcut keys +/// The number of minimum candidates that are selectable via shortcut keys. pub const MIN_SELKEY: usize = 1; -/// The number of maximum candidates that are selectable via shortcut keys +/// The number of maximum candidates that are selectable via shortcut keys. pub const MAX_SELKEY: usize = 10; -/// Log level +/// Log level. pub const CHEWING_LOG_VERBOSE: usize = 1; -/// Log level +/// Log level. pub const CHEWING_LOG_DEBUG: usize = 2; -/// Log level +/// Log level. pub const CHEWING_LOG_INFO: usize = 3; -/// Log level +/// Log level. pub const CHEWING_LOG_WARN: usize = 4; -/// Log level +/// Log level. pub const CHEWING_LOG_ERROR: usize = 5; -/// Use "asdfjkl789" as selection key +/// Use "asdfjkl789" as selection key. +#[deprecated] pub const HSU_SELKEY_TYPE1: usize = 1; -/// Use "asdfzxcv89" as selection key +/// Use "asdfzxcv89" as selection key. +#[deprecated] pub const HSU_SELKEY_TYPE2: usize = 2; -/// Configuration for chewing runtime features +/// Configuration for chewing runtime features. /// /// Deprecated, use chewing_set_ series of functions to set parameters instead. /// @@ -69,7 +80,7 @@ pub struct IntervalType { pub to: c_int, } -/// Keyboard layout index +/// Keyboard layout index. /// /// cbindgen:prefix-with-name /// cbindgen:enum-trailing-values=[TypeNum] @@ -91,7 +102,7 @@ pub enum KB { Carpalx, } -/// Opaque context handle used for chewing APIs +/// Opaque context handle used for chewing APIs. /// /// cbindgen:rename-all=None pub struct ChewingContext {