diff --git a/core/include/keyman/keyman_core_api.h b/core/include/keyman/keyman_core_api.h index 3e4451f6124..e744e6bf608 100644 --- a/core/include/keyman/keyman_core_api.h +++ b/core/include/keyman/keyman_core_api.h @@ -115,7 +115,6 @@ typedef uint32_t km_core_status; // Status return code. // Opaque object types. // -typedef struct km_core_context km_core_context; typedef struct km_core_keyboard km_core_keyboard; typedef struct km_core_state km_core_state; typedef struct km_core_options km_core_options; @@ -155,357 +154,7 @@ The final status code KM_CORE_STATUS_OS_ERROR is intended to allow encapsulating a platform error code; the remaining 31 low bits are the error code returned by the OS for cases where the failure mode is platform specific. For HRESULT codes this only permits failure codes to be passed. - - -### Context -The context is the text prior to the insertion point (caret, cursor). -The context is constructed by the Platform layer, typically by interrogating the -Client Application. The context will be updated by the engine for keystroke -events. If the Platform layer code caches the context, the context should be -reset when a context state change is detected. Context state changes can occur -when the user uses the mouse to move the insertion point, uses cursor keys, -switches applications or input fields, or presses hotkeys such as Ctrl+N to -start a new document. The full set of context state change triggers is up to the -Platform layer. - -Context can also contain positional Markers (also known as 'deadkeys' in kmn -keyboards), which are transitory state flags that are erased whenever a context -state change is detected. Markers are always controlled by the Engine. - -Contexts are always owned by their state. They may be set to a list of -context_items or interrogated for their current list of context items. -```c -*/ -enum km_core_context_type { - KM_CORE_CT_END, - KM_CORE_CT_CHAR, - KM_CORE_CT_MARKER -}; - -typedef struct { - uint8_t type; - uint8_t _reserved[3]; - union { - km_core_usv character; - uint32_t marker; - }; -} km_core_context_item; - -#define KM_CORE_CONTEXT_ITEM_END {KM_CORE_CT_END, {0,}, {0,}} -/* -``` -### `km_core_context_items_from_utf16` -##### Description: -Convert a UTF16 encoded Unicode string into an array of `km_core_context_item` -structures. Allocates memory as needed. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated for the - output buffer. -- `KM_CORE_STATUS_INVALID_UTF`: In the event the UTF16 string cannot be decoded - because it contains unpaired surrogate codeunits. -##### Parameters: -- __text__: a pointer to a null terminated array of utf16 encoded data. -- __out_ptr__: a pointer to the result variable: - A pointer to the start of the `km_core_context_item` array containing the - representation of the input string. - Terminated with a type of `KM_CORE_CT_END`. Must be disposed of with - `km_core_context_items_dispose`. - -```c -*/ -KMN_API -km_core_status -km_core_context_items_from_utf16(km_core_cp const *text, - km_core_context_item **out_ptr); - -/* -``` -### `km_core_context_items_from_utf8` -##### Description: -Convert an UTF8 encoded Unicode string into an array of `km_core_context_item` -structures. Allocates memory as needed. -##### Status: -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_NO_MEM`: In the event it cannot allocate enough memory for the - output buffer. -- `KM_CORE_STATUS_INVALID_UTF`: In the event the UTF8 string cannot be -decoded. -##### Parameters: -- __text__: a pointer to a null terminated array of utf8 encoded data. -- __out_ptr__: a pointer to the result variable: - A pointer to the start of the `km_core_context_item` array containing the - representation of the input string. - Terminated with a type of `KM_CORE_CT_END`. - -```c -*/ -KMN_API -km_core_status -km_core_context_items_from_utf8(char const *text, - km_core_context_item **out_ptr); - -/* -``` -### `km_core_context_items_to_utf16` -##### Description: -Convert a context item array into a UTF-16 encoded string placing it into -the supplied buffer of specified size, and return the number of code units -actually used in the conversion. If null is passed as the buffer the -number of codeunits required is returned. Any markers in the context will -not be included in the output buffer. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_INSUFFICENT_BUFFER`: If the buffer is not large enough. - `buf_size` will contain the space required. The contents of the buffer are - undefined. -##### Parameters: -- __context_items__: A pointer to the start of an array `km_core_context_item`. - Must be terminated with a type of `KM_CORE_CT_END`. -- __buf__: A pointer to the buffer to place the UTF-16 string into. - May be null to request size calculation. -- __buf_size__: a pointer to the result variable: - The size of the supplied buffer in codeunits if `buf` is given. - On return will be the size required if `buf` is null. - -```c -*/ -KMN_API -km_core_status -km_core_context_items_to_utf16(km_core_context_item const *item, - km_core_cp *buf, - size_t *buf_size); - -/* -``` -### `km_core_context_items_to_utf8` -##### Description: -Convert a context item array into a UTF-8 encoded string placing it into -the supplied buffer of specified size, and return the number of code units -actually used in the conversion. If null is passed as the buffer the -number of codeunits required is returned. Any markers in the context will -not be included in the output buffer. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_INSUFFICENT_BUFFER`: If the buffer is not large enough. - `buf_size` will contain the space required. The contents of the buffer are - undefined. -##### Parameters: -- __context_items__: A pointer to the start of an array `km_core_context_item`. - Must be terminated with a type of `KM_CORE_CT_END`. -- __buf__: A pointer to the buffer to place the UTF-8 string into. - May be null to request size calculation. -- __buf_size__: a pointer to the result variable: - The size of the supplied buffer in codeunits if `buf` is given. - On return will be the size required if `buf` is null. - -```c -*/ -KMN_API -km_core_status -km_core_context_items_to_utf8(km_core_context_item const *item, - char *buf, - size_t *buf_size); - -/* -``` -### `km_core_context_items_to_utf32` -##### Description: -Convert a context item array into a UTF-32 encoded string placing it into -the supplied buffer of specified size, and return the number of codepoints -actually used in the conversion. If null is passed as the buffer the -number of codepoints required is returned. Any markers in the context will -not be included in the output buffer. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_INSUFFICENT_BUFFER`: If the buffer is not large enough. - `buf_size` will contain the space required. The contents of the buffer are - undefined. -##### Parameters: -- __context_items__: A pointer to the start of an array `km_core_context_item`. - Must be terminated with a type of `KM_CORE_CT_END`. -- __buf__: A pointer to the buffer to place the UTF-32 string into. - May be null to request size calculation. -- __buf_size__: a pointer to the result variable: - The size of the supplied buffer in codepoints if `buf` is given. - On return will be the size required if `buf` is null. - -```c -*/ -KMN_API -km_core_status -km_core_context_items_to_utf32(km_core_context_item const *item, - km_core_usv *buf, - size_t *buf_size); - -/* -``` -### `km_core_context_items_dispose` -##### Description: -Free the allocated memory belonging to a `km_core_context_item` array previously -returned by `km_core_context_items_from_utf16` or `km_core_context_get` -##### Parameters: -- __context_items__: A pointer to the start of the `km_core_context_item` array - to be disposed of. - -```c -*/ -KMN_API -void -km_core_context_items_dispose(km_core_context_item *context_items); - -/* -``` -### `km_core_context_set` -##### Description: -Replace the contents of the current context with a new sequence of -`km_core_context_item` entries. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated to - grow the context buffer internally. -##### Parameters: -- __context__: A pointer to an opaque context object -- __context_items__: A pointer to the start of the `km_core_context_item` - array containing the new context. It must be terminated with an item - of type `KM_CORE_CT_END`. - -```c -*/ -KMN_API -km_core_status -km_core_context_set(km_core_context *context, - km_core_context_item const *context_items); - -/* -``` -### `km_core_context_get` -##### Description: -Copies all items in the context into a new array and returns the new array. -This must be disposed of by caller using `km_core_context_items_dispose`. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated for the - output buffer. -##### Parameters: -- __context_items__: A pointer to the start of an array `km_core_context_item`. -- __out__: a pointer to the result variable: - A pointer to the start of the `km_core_context_item` array containing a - copy of the context. Terminated with a type of `KM_CORE_CT_END`. Must be - disposed of with `km_core_context_items_dispose`. - -```c -*/ -KMN_API -km_core_status -km_core_context_get(km_core_context const *context_items, - km_core_context_item **out); - -/* -``` -### `km_core_context_clear` -##### Description: -Removes all context_items from the internal array. If `context` is -null, has no effect. -##### Parameters: -- __context__: A pointer to an opaque context object - -```c -*/ -KMN_API -void -km_core_context_clear(km_core_context *); - -/* -``` -### `km_core_context_length` -##### Description: -Return the number of items in the context. -##### Return: -The number of items in the context, and will return 0 if passed a null `context` -pointer. -##### Parameters: -- __context__: A pointer to an opaque context object - -```c -*/ -KMN_API -size_t -km_core_context_length(km_core_context *); - -/* -``` -### `km_core_context_append` -##### Description: -Add more items to the end (insertion point) of the context. If these exceed the -maximum context length the same number of items will be dropped from the -beginning of the context. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated to - grow the context buffer internally. -##### Parameters: -- __context__: A pointer to an opaque context object. -- __context_items__: A pointer to the start of the `KM_CORE_CT_END` terminated - array of `km_core_context_item` to append. - -```c -*/ -KMN_API -km_core_status -km_core_context_append(km_core_context *context, - km_core_context_item const *context_items); - -/* -``` -### `km_core_context_shrink` -##### Description: -Remove a specified number of items from the end of the context, optionally -add up to the same number of the supplied items to the front of the context. -##### Return status: -- `KM_CORE_STATUS_OK`: On success. -- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. -- `KM_CORE_STATUS_NO_MEM`: in the event it cannot allocated enough memory to grow - the context internally. -##### Parameters: -- __context__: A pointer to an opaque context object. -- __num__: The number of items to remove from the end of context. -- __context_items__: Pointer to the start of the `KM_CORE_CT_END` terminated - array of `km_core_context_item` to add to the front. Up to `num` items will - be prepended. This may be null if not required. - -```c */ -KMN_API -km_core_status -km_core_context_shrink(km_core_context *context, - size_t num, - km_core_context_item const *prefix); - -/* -``` -### `km_core_context_item_list_size` -##### Description: -Return the length of a terminated `km_core_context_item` array. -##### Return: -The number of items in the list, not including terminating item, -or 0 if `context_items` is null. -##### Parameters: -- __context_items__: A pointer to a `KM_CORE_CT_END` terminated array of - `km_core_context_item` values. - -```c -*/ -KMN_API -size_t -km_core_context_item_list_size(km_core_context_item const *context_items); /* ``` @@ -1104,46 +753,6 @@ KMN_API void km_core_state_dispose(km_core_state *state); -/* -``` -### `km_core_state_context` -##### Description: -Get access to the state object's context. -##### Return: -A pointer to an opaque state object. This pointer is valid for the lifetime -of the state object. If null is passed in, then null is returned. -##### Parameters: -- __state__: A pointer to the opaque state object to be queried. - -```c -*/ -KMN_API -km_core_context * -km_core_state_context(km_core_state *state); - - -KMN_API -km_core_context * -km_core_state_app_context(km_core_state *state); - -/* -``` -### `km_core_state_get_intermediate_context` -##### Description: -Get access to the state object's keyboard processor's intermediate context. This context -is used during an IMX callback, part way through processing a keystroke. -##### Return: -A pointer to an context item array. Must be disposed of by a call -to `km_core_context_items_dispose`. -##### Parameters: -- __state__: A pointer to the opaque state object to be queried. - -```c -*/ -KMN_API -km_core_status -km_core_state_get_intermediate_context(km_core_state *state, km_core_context_item ** context_items); - /* ``` ### Context Debug Reporting diff --git a/core/include/keyman/keyman_core_api_context.h b/core/include/keyman/keyman_core_api_context.h new file mode 100644 index 00000000000..59347402141 --- /dev/null +++ b/core/include/keyman/keyman_core_api_context.h @@ -0,0 +1,486 @@ +/* + * Keyman is copyright (C) SIL International. MIT License. + * + * Keyman Keyboard Processor API - Debugger Interfaces + * + * The debugger interfaces are still very dependent on .kmx + * objects. + * + * Note: this file is subject to change; the debugger + * interfaces are not stable across versions. + * + */ + +#pragma once + +#include +#include +#include +#include + +// Currently, the Core unit tests use private context APIs defined in +// keyman_core_api_context.h, which are unused by other consumers. We are +// hoping to remove these entirely in the future, so we restrict access +// by default with this macro. Keyman Core internally uses these functions +// #define _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +#if defined(__cplusplus) +extern "C" +{ +#endif + +typedef struct km_core_context km_core_context; + +// ---------------------------------------------------------------------------------- +// Context APIs are now available only to the keyboard debugger, IMX, and Core unit +// tests (17.0) +// ---------------------------------------------------------------------------------- + +/* +### Context +The context is the text prior to the insertion point (caret, cursor). The +context is constructed by the Platform layer, typically by interrogating the +Client Application. The context will be updated by the engine for keystroke +events. If the Platform layer code caches the context, the context should be +reset when a context state change is detected. Context state changes can occur +when the user uses the mouse to move the insertion point, uses cursor keys, +switches applications or input fields, or presses hotkeys such as Ctrl+N to +start a new document. The full set of context state change triggers is up to the +Platform layer. + +Context can also contain positional Markers (also known as 'deadkeys' in kmn +keyboards), which are transitory state flags that are erased whenever a context +state change is detected. Markers are always controlled by the Engine. + +Contexts are always owned by their state. They may be set to a list of +context_items or interrogated for their current list of context items. + +Core maintains and caches the context. Engine can update the context with +`km_core_state_context_set_if_needed` and `km_core_state_context_clear`. These +two functions are available in keyman_core_api.h. + +The Keyboard Debugger in Keyman Developer, and IMX in Keyman for Windows, make +use of the context functionality in this header, but these functions should not +be used in other places. +```c +*/ +enum km_core_context_type { + KM_CORE_CT_END, + KM_CORE_CT_CHAR, + KM_CORE_CT_MARKER +}; + +typedef struct { + uint8_t type; + uint8_t _reserved[3]; + union { + km_core_usv character; + uint32_t marker; + }; +} km_core_context_item; + +#define KM_CORE_CONTEXT_ITEM_END {KM_CORE_CT_END, {0,}, {0,}} + +/* +``` +### `km_core_state_get_intermediate_context` +##### Description: +Get access to the state object's keyboard processor's intermediate context. This context +is used during an IMX callback, part way through processing a keystroke. +##### Return: +A pointer to an context item array. Must be disposed of by a call +to `km_core_context_items_dispose`. +##### Parameters: +- __state__: A pointer to the opaque state object to be queried. + +```c +*/ +KMN_API +km_core_status +km_core_state_get_intermediate_context(km_core_state *state, km_core_context_item ** context_items); + +/* +``` +### `km_core_context_items_dispose` +##### Description: +Free the allocated memory belonging to a `km_core_context_item` array previously +returned by `km_core_context_items_from_utf16` or `km_core_context_get` +##### Parameters: +- __context_items__: A pointer to the start of the `km_core_context_item` array + to be disposed of. + +```c +*/ +KMN_API +void +km_core_context_items_dispose(km_core_context_item *context_items); + +/** + * Get access to the state object's cached context. + * @param state A pointer to the opaque state object to be queried. + * @returns A pointer to an opaque context object. This pointer is valid for the + * lifetime of the state object. If null is passed in, then null is + * returned. + */ +KMN_API +km_core_context * +km_core_state_context(km_core_state *state); + +/** + * Get access to the state object's application context. + * @param state A pointer to the opaque state object to be queried. + * @returns A pointer to an opaque context object. This pointer is valid for the + * lifetime of the state object. If null is passed in, then null is + * returned. + */ +KMN_API +km_core_context * +km_core_state_app_context(km_core_state *state); + +/* +``` +### `km_core_context_items_from_utf16` +##### Description: +Convert a UTF16 encoded Unicode string into an array of `km_core_context_item` +structures. Allocates memory as needed. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated for the + output buffer. +- `KM_CORE_STATUS_INVALID_UTF`: In the event the UTF16 string cannot be decoded + because it contains unpaired surrogate codeunits. +##### Parameters: +- __text__: a pointer to a null terminated array of utf16 encoded data. +- __out_ptr__: a pointer to the result variable: + A pointer to the start of the `km_core_context_item` array containing the + representation of the input string. + Terminated with a type of `KM_CORE_CT_END`. Must be disposed of with + `km_core_context_items_dispose`. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_items_from_utf16(km_core_cp const *text, + km_core_context_item **out_ptr); + +#endif + +/* +``` +### `km_core_context_items_from_utf8` +##### Description: +Convert an UTF8 encoded Unicode string into an array of `km_core_context_item` +structures. Allocates memory as needed. +##### Status: +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_NO_MEM`: In the event it cannot allocate enough memory for the + output buffer. +- `KM_CORE_STATUS_INVALID_UTF`: In the event the UTF8 string cannot be +decoded. +##### Parameters: +- __text__: a pointer to a null terminated array of utf8 encoded data. +- __out_ptr__: a pointer to the result variable: + A pointer to the start of the `km_core_context_item` array containing the + representation of the input string. + Terminated with a type of `KM_CORE_CT_END`. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_items_from_utf8(char const *text, + km_core_context_item **out_ptr); + +#endif + +/* +``` +### `km_core_context_items_to_utf16` +##### Description: +Convert a context item array into a UTF-16 encoded string placing it into +the supplied buffer of specified size, and return the number of code units +actually used in the conversion. If null is passed as the buffer the +number of codeunits required is returned. Any markers in the context will +not be included in the output buffer. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_INSUFFICENT_BUFFER`: If the buffer is not large enough. + `buf_size` will contain the space required. The contents of the buffer are + undefined. +##### Parameters: +- __context_items__: A pointer to the start of an array `km_core_context_item`. + Must be terminated with a type of `KM_CORE_CT_END`. +- __buf__: A pointer to the buffer to place the UTF-16 string into. + May be null to request size calculation. +- __buf_size__: a pointer to the result variable: + The size of the supplied buffer in codeunits if `buf` is given. + On return will be the size required if `buf` is null. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_items_to_utf16(km_core_context_item const *item, + km_core_cp *buf, + size_t *buf_size); + +#endif + +/* +``` +### `km_core_context_items_to_utf8` +##### Description: +Convert a context item array into a UTF-8 encoded string placing it into +the supplied buffer of specified size, and return the number of code units +actually used in the conversion. If null is passed as the buffer the +number of codeunits required is returned. Any markers in the context will +not be included in the output buffer. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_INSUFFICENT_BUFFER`: If the buffer is not large enough. + `buf_size` will contain the space required. The contents of the buffer are + undefined. +##### Parameters: +- __context_items__: A pointer to the start of an array `km_core_context_item`. + Must be terminated with a type of `KM_CORE_CT_END`. +- __buf__: A pointer to the buffer to place the UTF-8 string into. + May be null to request size calculation. +- __buf_size__: a pointer to the result variable: + The size of the supplied buffer in codeunits if `buf` is given. + On return will be the size required if `buf` is null. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_items_to_utf8(km_core_context_item const *item, + char *buf, + size_t *buf_size); + +#endif + +/* +``` +### `km_core_context_items_to_utf32` +##### Description: +Convert a context item array into a UTF-32 encoded string placing it into +the supplied buffer of specified size, and return the number of codepoints +actually used in the conversion. If null is passed as the buffer the +number of codepoints required is returned. Any markers in the context will +not be included in the output buffer. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_INSUFFICENT_BUFFER`: If the buffer is not large enough. + `buf_size` will contain the space required. The contents of the buffer are + undefined. +##### Parameters: +- __context_items__: A pointer to the start of an array `km_core_context_item`. + Must be terminated with a type of `KM_CORE_CT_END`. +- __buf__: A pointer to the buffer to place the UTF-32 string into. + May be null to request size calculation. +- __buf_size__: a pointer to the result variable: + The size of the supplied buffer in codepoints if `buf` is given. + On return will be the size required if `buf` is null. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_items_to_utf32(km_core_context_item const *item, + km_core_usv *buf, + size_t *buf_size); + +#endif + +/* +``` +### `km_core_context_set` +##### Description: +Replace the contents of the current context with a new sequence of +`km_core_context_item` entries. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated to + grow the context buffer internally. +##### Parameters: +- __context__: A pointer to an opaque context object +- __context_items__: A pointer to the start of the `km_core_context_item` + array containing the new context. It must be terminated with an item + of type `KM_CORE_CT_END`. + +```c +*/ +KMN_API +km_core_status +km_core_context_set(km_core_context *context, + km_core_context_item const *context_items); + +/* +``` +### `km_core_context_get` +##### Description: +Copies all items in the context into a new array and returns the new array. +This must be disposed of by caller using `km_core_context_items_dispose`. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated for the + output buffer. +##### Parameters: +- __context_items__: A pointer to the start of an array `km_core_context_item`. +- __out__: a pointer to the result variable: + A pointer to the start of the `km_core_context_item` array containing a + copy of the context. Terminated with a type of `KM_CORE_CT_END`. Must be + disposed of with `km_core_context_items_dispose`. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_get(km_core_context const *context_items, + km_core_context_item **out); + +#endif + +/* +``` +### `km_core_context_clear` +##### Description: +Removes all context_items from the internal array. If `context` is +null, has no effect. +##### Parameters: +- __context__: A pointer to an opaque context object + +```c +*/ +KMN_API +void +km_core_context_clear(km_core_context *); + +/* +``` +### `km_core_context_length` +##### Description: +Return the number of items in the context. +##### Return: +The number of items in the context, and will return 0 if passed a null `context` +pointer. +##### Parameters: +- __context__: A pointer to an opaque context object + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +size_t +km_core_context_length(km_core_context *); + +#endif + +/* +``` +### `km_core_context_append` +##### Description: +Add more items to the end (insertion point) of the context. If these exceed the +maximum context length the same number of items will be dropped from the +beginning of the context. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_NO_MEM`: In the event not enough memory can be allocated to + grow the context buffer internally. +##### Parameters: +- __context__: A pointer to an opaque context object. +- __context_items__: A pointer to the start of the `KM_CORE_CT_END` terminated + array of `km_core_context_item` to append. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_append(km_core_context *context, + km_core_context_item const *context_items); + +#endif + +/* +``` +### `km_core_context_shrink` +##### Description: +Remove a specified number of items from the end of the context, optionally +add up to the same number of the supplied items to the front of the context. +##### Return status: +- `KM_CORE_STATUS_OK`: On success. +- `KM_CORE_STATUS_INVALID_ARGUMENT`: If non-optional parameters are null. +- `KM_CORE_STATUS_NO_MEM`: in the event it cannot allocated enough memory to grow + the context internally. +##### Parameters: +- __context__: A pointer to an opaque context object. +- __num__: The number of items to remove from the end of context. +- __context_items__: Pointer to the start of the `KM_CORE_CT_END` terminated + array of `km_core_context_item` to add to the front. Up to `num` items will + be prepended. This may be null if not required. + +```c +*/ + +#ifdef _KM_CORE_ACCESS_PRIVATE_CONTEXT_API + +KMN_API +km_core_status +km_core_context_shrink(km_core_context *context, + size_t num, + km_core_context_item const *prefix); + +#endif + +/* +``` +### `km_core_context_item_list_size` +##### Description: +Return the length of a terminated `km_core_context_item` array. +##### Return: +The number of items in the list, not including terminating item, +or 0 if `context_items` is null. +##### Parameters: +- __context_items__: A pointer to a `KM_CORE_CT_END` terminated array of + `km_core_context_item` values. + +```c +*/ +KMN_API +size_t +km_core_context_item_list_size(km_core_context_item const *context_items); + +#if defined(__cplusplus) +} // extern "C" +#endif diff --git a/core/meson.build b/core/meson.build index 716faca2dc2..e6b1fd8fa1a 100644 --- a/core/meson.build +++ b/core/meson.build @@ -29,6 +29,9 @@ python = py.find_installation() # For now, we use KM_CORE_LIBRARY to inject the km::core::kmx namespace defns += ['-DKM_CORE_LIBRARY'] +# See keyman_core_api_context.h +defns += ['-D_KM_CORE_ACCESS_PRIVATE_CONTEXT_API'] + # #define DEBUG when we are on a debug build if get_option('buildtype') == 'debug' add_global_arguments('-DDEBUG', language : 'cpp') diff --git a/core/src/action.cpp b/core/src/action.cpp index f4565844d76..d2e0613b141 100644 --- a/core/src/action.cpp +++ b/core/src/action.cpp @@ -11,7 +11,6 @@ #include #include -#include #include "action.hpp" #include "state.hpp" diff --git a/core/src/action.hpp b/core/src/action.hpp index 06038c31222..d8ee401e97f 100644 --- a/core/src/action.hpp +++ b/core/src/action.hpp @@ -8,7 +8,7 @@ #pragma once -#include +#include "keyman_core.h" #include namespace km { diff --git a/core/src/context.hpp b/core/src/context.hpp index dba7bec0608..36831f6d14c 100644 --- a/core/src/context.hpp +++ b/core/src/context.hpp @@ -9,7 +9,7 @@ #pragma once #include #include -#include +#include "keyman_core.h" // Forward declarations class json; diff --git a/core/src/debug.hpp b/core/src/debug.hpp index a68d9f1e578..33de3dd3247 100644 --- a/core/src/debug.hpp +++ b/core/src/debug.hpp @@ -9,8 +9,7 @@ #include #include -#include -#include +#include "keyman_core.h" namespace km { namespace core diff --git a/core/src/keyboard.hpp b/core/src/keyboard.hpp index 6dd8517ce10..142bf40e860 100644 --- a/core/src/keyboard.hpp +++ b/core/src/keyboard.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include "keyman_core.h" #include "option.hpp" #include "path.hpp" diff --git a/core/src/keyman_core.h b/core/src/keyman_core.h new file mode 100644 index 00000000000..8750b7b93ef --- /dev/null +++ b/core/src/keyman_core.h @@ -0,0 +1,5 @@ +#pragma once + +#include +#include +#include \ No newline at end of file diff --git a/core/src/km_core_action_api.cpp b/core/src/km_core_action_api.cpp index 1177ec71fcc..db8a5c8820a 100644 --- a/core/src/km_core_action_api.cpp +++ b/core/src/km_core_action_api.cpp @@ -10,7 +10,8 @@ #include #include -#include +#include "keyman_core.h" + #include "jsonpp.hpp" #include "processor.hpp" diff --git a/core/src/km_core_context_api.cpp b/core/src/km_core_context_api.cpp index 46522710c03..ddf49e21e15 100644 --- a/core/src/km_core_context_api.cpp +++ b/core/src/km_core_context_api.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include "keyman_core.h" #include "context.hpp" #include "jsonpp.hpp" diff --git a/core/src/km_core_debug_api.cpp b/core/src/km_core_debug_api.cpp index 2c6433a522c..75e34b0b0cd 100644 --- a/core/src/km_core_debug_api.cpp +++ b/core/src/km_core_debug_api.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include "keyman_core.h" #include "processor.hpp" #include "state.hpp" diff --git a/core/src/km_core_keyboard_api.cpp b/core/src/km_core_keyboard_api.cpp index ae825ca4025..964f73ca072 100644 --- a/core/src/km_core_keyboard_api.cpp +++ b/core/src/km_core_keyboard_api.cpp @@ -11,7 +11,8 @@ #include #include -#include +#include "keyman_core.h" + #include "keyboard.hpp" #include "processor.hpp" #include "kmx/kmx_processor.hpp" diff --git a/core/src/km_core_options_api.cpp b/core/src/km_core_options_api.cpp index 3cb0745fa90..4ea5c740622 100644 --- a/core/src/km_core_options_api.cpp +++ b/core/src/km_core_options_api.cpp @@ -11,7 +11,8 @@ #include #include -#include +#include "keyman_core.h" + #include "processor.hpp" #include "jsonpp.hpp" diff --git a/core/src/km_core_processevent_api.cpp b/core/src/km_core_processevent_api.cpp index 5295d39af7b..7d5109a6b21 100644 --- a/core/src/km_core_processevent_api.cpp +++ b/core/src/km_core_processevent_api.cpp @@ -8,7 +8,8 @@ History: 17 Oct 2018 - TSE - Initial implementation. */ -#include +#include "keyman_core.h" + #include "processor.hpp" #include "state.hpp" diff --git a/core/src/km_core_state_api.cpp b/core/src/km_core_state_api.cpp index eb430ba5ac0..7b7e74f6341 100644 --- a/core/src/km_core_state_api.cpp +++ b/core/src/km_core_state_api.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include "keyman_core.h" #include "jsonpp.hpp" #include "processor.hpp" diff --git a/core/src/km_core_state_context_set_if_needed.cpp b/core/src/km_core_state_context_set_if_needed.cpp index b79044455e0..72b80f6f51b 100644 --- a/core/src/km_core_state_context_set_if_needed.cpp +++ b/core/src/km_core_state_context_set_if_needed.cpp @@ -9,7 +9,7 @@ */ #include -#include +#include "keyman_core.h" #include "processor.hpp" #include "state.hpp" diff --git a/core/src/kmx/kmx_base.h b/core/src/kmx/kmx_base.h index fed03bc6450..e798ff56b79 100644 --- a/core/src/kmx/kmx_base.h +++ b/core/src/kmx/kmx_base.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include "keyman_core.h" #if defined(_WIN32) || defined(_WIN64) #define snprintf _snprintf diff --git a/core/src/kmx/kmx_options.h b/core/src/kmx/kmx_options.h index 14c280e411c..cf038ac7dc4 100644 --- a/core/src/kmx/kmx_options.h +++ b/core/src/kmx/kmx_options.h @@ -4,7 +4,7 @@ #include #include -#include +#include "keyman_core.h" #include "option.hpp" #include "kmx_base.h" diff --git a/core/src/kmx/kmx_processor.cpp b/core/src/kmx/kmx_processor.cpp index 1fa0734e074..95a9a094564 100644 --- a/core/src/kmx/kmx_processor.cpp +++ b/core/src/kmx/kmx_processor.cpp @@ -1,4 +1,4 @@ -#include +#include "keyman_core.h" #include "state.hpp" #include "kmx/kmx_processor.hpp" #include diff --git a/core/src/kmx/kmx_processor.hpp b/core/src/kmx/kmx_processor.hpp index 490bda53c6f..08b2c1d242f 100644 --- a/core/src/kmx/kmx_processor.hpp +++ b/core/src/kmx/kmx_processor.hpp @@ -9,7 +9,7 @@ #pragma once #include -#include +#include "keyman_core.h" #include "kmx/kmx_processevent.h" #include "keyboard.hpp" #include "processor.hpp" diff --git a/core/src/ldml/ldml_processor.hpp b/core/src/ldml/ldml_processor.hpp index a66d151fde0..238b3322156 100644 --- a/core/src/ldml/ldml_processor.hpp +++ b/core/src/ldml/ldml_processor.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include "keyman_core.h" #include "processor.hpp" #include "option.hpp" #include "ldml_vkeys.hpp" diff --git a/core/src/ldml/ldml_vkeys.hpp b/core/src/ldml/ldml_vkeys.hpp index 22dea817efc..ed3368dc7e7 100644 --- a/core/src/ldml/ldml_vkeys.hpp +++ b/core/src/ldml/ldml_vkeys.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include "keyman_core.h" namespace km { namespace core { diff --git a/core/src/mock/mock_processor.hpp b/core/src/mock/mock_processor.hpp index a3ec3c1caa2..87a99a49df7 100644 --- a/core/src/mock/mock_processor.hpp +++ b/core/src/mock/mock_processor.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include "keyman_core.h" #include "processor.hpp" #include "option.hpp" diff --git a/core/src/option.hpp b/core/src/option.hpp index 43f33970497..60026798cfd 100644 --- a/core/src/option.hpp +++ b/core/src/option.hpp @@ -12,7 +12,8 @@ #include -#include +#include "keyman_core.h" + // Forward declarations class json; diff --git a/core/src/path.hpp b/core/src/path.hpp index be6ae61422a..aee70ad8ba9 100644 --- a/core/src/path.hpp +++ b/core/src/path.hpp @@ -12,7 +12,8 @@ #include #include -#include +#include "keyman_core.h" + #include "jsonpp.hpp" #include "utfcodec.hpp" diff --git a/core/src/processor.hpp b/core/src/processor.hpp index 7a6ed5aa334..8925ad65d13 100644 --- a/core/src/processor.hpp +++ b/core/src/processor.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include "keyman_core.h" #include "keyboard.hpp" diff --git a/core/src/state.hpp b/core/src/state.hpp index 0b98cc9e245..c3afff50293 100644 --- a/core/src/state.hpp +++ b/core/src/state.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include "keyman_core.h" #include "context.hpp" #include "option.hpp" diff --git a/core/tests/unit/kmnkbd/action_api.cpp b/core/tests/unit/kmnkbd/action_api.cpp index 6a84eafa2df..a9e0058b569 100644 --- a/core/tests/unit/kmnkbd/action_api.cpp +++ b/core/tests/unit/kmnkbd/action_api.cpp @@ -6,7 +6,7 @@ History: 23 Oct 2023 - MCD - Initial implementation. */ #include -#include +#include "keyman_core.h" #include "path.hpp" #include "action.hpp" diff --git a/core/tests/unit/kmnkbd/action_items.hpp b/core/tests/unit/kmnkbd/action_items.hpp index 5b4723fd571..dc5ac666b69 100644 --- a/core/tests/unit/kmnkbd/action_items.hpp +++ b/core/tests/unit/kmnkbd/action_items.hpp @@ -1,4 +1,4 @@ -#include +#include "keyman_core.h" #include #include diff --git a/core/tests/unit/kmnkbd/action_set_api.cpp b/core/tests/unit/kmnkbd/action_set_api.cpp index d3c06cc9c73..2f69f2babad 100644 --- a/core/tests/unit/kmnkbd/action_set_api.cpp +++ b/core/tests/unit/kmnkbd/action_set_api.cpp @@ -6,7 +6,8 @@ History: 23 Oct 2023 - MCD - Initial implementation. */ #include -#include + +#include "keyman_core.h" #include "path.hpp" #include "action.hpp" diff --git a/core/tests/unit/kmnkbd/context_api.cpp b/core/tests/unit/kmnkbd/context_api.cpp index d5225eb24f5..149ebf9556d 100644 --- a/core/tests/unit/kmnkbd/context_api.cpp +++ b/core/tests/unit/kmnkbd/context_api.cpp @@ -10,7 +10,8 @@ mutation functions. */ #include -#include + +#include "keyman_core.h" #include "context.hpp" #include "utfcodec.hpp" diff --git a/core/tests/unit/kmnkbd/debug_api.cpp b/core/tests/unit/kmnkbd/debug_api.cpp index 502f95cc474..33138884774 100644 --- a/core/tests/unit/kmnkbd/debug_api.cpp +++ b/core/tests/unit/kmnkbd/debug_api.cpp @@ -10,7 +10,9 @@ #include #include #include -#include + +#include "keyman_core.h" + #include "path.hpp" #include "state.hpp" #include "kmx/kmx_base.h" diff --git a/core/tests/unit/kmnkbd/debug_items.hpp b/core/tests/unit/kmnkbd/debug_items.hpp index 400f499bd2c..ae5f0e8cbd5 100644 --- a/core/tests/unit/kmnkbd/debug_items.hpp +++ b/core/tests/unit/kmnkbd/debug_items.hpp @@ -1,6 +1,5 @@ #include -#include -#include +#include "keyman_core.h" #include "kmx/kmx_base.h" #include "kmx/kmx_xstring.h" diff --git a/core/tests/unit/kmnkbd/keyboard_api.cpp b/core/tests/unit/kmnkbd/keyboard_api.cpp index 95365e901cb..bf232d69afb 100644 --- a/core/tests/unit/kmnkbd/keyboard_api.cpp +++ b/core/tests/unit/kmnkbd/keyboard_api.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include "keyman_core.h" #include "path.hpp" //#include "keyboard.hpp" diff --git a/core/tests/unit/kmnkbd/options_api.cpp b/core/tests/unit/kmnkbd/options_api.cpp index a831180f411..7c04478fe77 100644 --- a/core/tests/unit/kmnkbd/options_api.cpp +++ b/core/tests/unit/kmnkbd/options_api.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include "keyman_core.h" #include "option.hpp" #include "state.hpp" diff --git a/core/tests/unit/kmnkbd/state_api.cpp b/core/tests/unit/kmnkbd/state_api.cpp index e3d17175890..07acd8bdd4b 100644 --- a/core/tests/unit/kmnkbd/state_api.cpp +++ b/core/tests/unit/kmnkbd/state_api.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include "keyman_core.h" #include "path.hpp" #include "state.hpp" diff --git a/core/tests/unit/kmx/kmx.cpp b/core/tests/unit/kmx/kmx.cpp index 794c744a7c4..1e94f4cf867 100644 --- a/core/tests/unit/kmx/kmx.cpp +++ b/core/tests/unit/kmx/kmx.cpp @@ -17,6 +17,8 @@ #include #include +#include "keyman_core.h" + #include #include diff --git a/core/tests/unit/ldml/ldml.cpp b/core/tests/unit/ldml/ldml.cpp index 453ef8ac8e7..db95141eba5 100644 --- a/core/tests/unit/ldml/ldml.cpp +++ b/core/tests/unit/ldml/ldml.cpp @@ -24,6 +24,8 @@ #include #include +#include "keyman_core.h" + #include // for surrogate pair macros #include "ldml_test_source.hpp" diff --git a/core/tests/unit/ldml/ldml_test_utils.hpp b/core/tests/unit/ldml/ldml_test_utils.hpp index 1d876365bbb..ec180200ed3 100644 --- a/core/tests/unit/ldml/ldml_test_utils.hpp +++ b/core/tests/unit/ldml/ldml_test_utils.hpp @@ -13,7 +13,8 @@ #include // for char to vk mapping tables #include // for surrogate pair macros #include -#include + +#include "keyman_core.h" namespace km { namespace tests { diff --git a/core/tests/unit/ldml/test_context_normalization.cpp b/core/tests/unit/ldml/test_context_normalization.cpp index c3215ce4a3f..11a3b8ca0e9 100644 --- a/core/tests/unit/ldml/test_context_normalization.cpp +++ b/core/tests/unit/ldml/test_context_normalization.cpp @@ -6,7 +6,7 @@ History: 15 Jan 2024 - MCD - Initial implementation. */ #include -#include +#include "keyman_core.h" #include "path.hpp" #include "action.hpp" diff --git a/windows/src/engine/keyman32/keymanengine.h b/windows/src/engine/keyman32/keymanengine.h index c0db193fdfb..9befcb302ad 100644 --- a/windows/src/engine/keyman32/keymanengine.h +++ b/windows/src/engine/keyman32/keymanengine.h @@ -40,6 +40,7 @@ #include #include "../../../../common/windows/cpp/include/legacy_kmx_file.h" #include +#include // for intermediate context #include /***************************************************************************/