From 92c668c423d28086fd4b8033a3bb51f527e91313 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Tue, 6 Feb 2024 21:37:30 +0900 Subject: [PATCH] style: switch to use clang-format --- README.md | 7 +- pre-commit | 16 +- src/GSettingsBackend.c | 71 +- src/GSettingsBackend.h | 28 +- src/IBusChewingApplier.c | 119 +- src/IBusChewingLookupTable.c | 41 +- src/IBusChewingLookupTable.h | 31 +- src/IBusChewingPreEdit-private.h | 118 +- src/IBusChewingPreEdit.c | 479 ++++---- src/IBusChewingPreEdit.h | 196 ++-- src/IBusChewingProperties.c | 345 +++--- src/IBusChewingProperties.h | 74 +- src/IBusChewingUtil.c | 144 ++- src/IBusChewingUtil.h | 42 +- src/MakerDialogBackend.c | 28 +- src/MakerDialogBackend.h | 61 +- src/MakerDialogProperty.c | 194 ++-- src/MakerDialogProperty.h | 128 +-- src/MakerDialogPropertySpec.h | 29 +- src/MakerDialogUtil.c | 45 +- src/MakerDialogUtil.h | 74 +- src/ibus-chewing-engine-private.h | 69 +- src/ibus-chewing-engine.c | 1166 ++++++++++---------- src/ibus-chewing-engine.h | 145 ++- src/main.c | 86 +- src/setup/ibus-setup-chewing-application.c | 1 - src/setup/ibus-setup-chewing-application.h | 3 - src/setup/ibus-setup-chewing-window.c | 3 +- src/setup/ibus-setup-chewing-window.h | 3 - src/setup/main.c | 1 + test/IBusChewingPreEdit-test.c | 385 +++---- test/IBusChewingUtil-test.c | 10 +- test/MakerDialogBackend-test.c | 102 +- test/MakerDialogUtil-test.c | 38 +- test/ibus-chewing-engine-test.c | 76 +- test/test-util.h | 3 +- 36 files changed, 2107 insertions(+), 2254 deletions(-) diff --git a/README.md b/README.md index e9f1d00..b1c5753 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # IBus-Chewing -IBus-Chewing is an IBus front-end of Chewing, an intelligent Chinese input method for Zhuyin (BoPoMoFo) users. +IBus-Chewing is an IBus front-end of Chewing, an intelligent Chinese input +method for Zhuyin (BoPoMoFo) users. Following documents provide further instruction: @@ -16,7 +17,9 @@ Bugs and enhancement can be filed to either: # Development -We use **[K&R](https://en.wikipedia.org/wiki/Indent_style#K.26R_style), 4 spaces** coding style to make our review easier, so if you like to contribute, please set the git pre-commit hook by: +We use LLVM coding style to make our review easier, so if you like to +contribute, please install clang-format and set the git pre-commit hook by: + ```sh ln -s ../../pre-commit .git/hooks/pre-commit ``` diff --git a/pre-commit b/pre-commit index bea751e..49474bd 100755 --- a/pre-commit +++ b/pre-commit @@ -9,15 +9,15 @@ function exit_print_error(){ - if [[ -z $Indent ]];then - echo "Please install 'indent' and put it in system PATH," > /dev/stderr + if [[ -z $clang_format ]];then + echo "Please install 'clang-format' and put it in system PATH," > /dev/stderr echo "or specify it in 'git config hooks.indent'" > /dev/stderr exit 1 fi } trap exit_print_error EXIT -Indent="$(git config hooks.indent)" || Indent=$(which indent 2>/dev/null) +clang_format="$(git config hooks.indent)" || clang_format=$(command -v clang-format 2>/dev/null) if git rev-parse --verify HEAD >/dev/null 2>&1; then Against=HEAD @@ -39,16 +39,10 @@ while read File; do Ext=${File##*.} case $Ext in c|h) - echo "Indenting " $File > /dev/stderr - "$Indent" -kr --no-tabs\ - --line-length 80\ - --blank-lines-after-declarations\ - --preprocessor-indentation 4\ - "$File" + echo "clang-format " $File > /dev/stderr + $clang_format -i $File ;; esac - echo "Chopping " $File > /dev/stderr - sed -r -i -e 's/[[:blank:]]+$//' $File git add "$File" done < <(git diff --cached --name-only $Against) diff --git a/src/GSettingsBackend.c b/src/GSettingsBackend.c index 3976ee7..b181b2a 100644 --- a/src/GSettingsBackend.c +++ b/src/GSettingsBackend.c @@ -16,16 +16,16 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ -#include -#include -#include "MakerDialogUtil.h" #include "GSettingsBackend.h" +#include "MakerDialogUtil.h" +#include +#include -gchar *mkdg_g_variant_to_string(GVariant * gVar) -{ +gchar *mkdg_g_variant_to_string(GVariant *gVar) { static gchar result[MAKER_DIALOG_VALUE_LENGTH]; result[0] = '\0'; @@ -65,9 +65,8 @@ gchar *mkdg_g_variant_to_string(GVariant * gVar) #define KEY_BUFFER_SIZE 300 -GValue *mkdg_g_settings_read_value(GSettings * settings, - GValue * value, const gchar * key) -{ +GValue *mkdg_g_settings_read_value(GSettings *settings, GValue *value, + const gchar *key) { GVariant *confValue = g_settings_get_value(settings, key); mkdg_log(DEBUG, "mkdg_g_settings_read_value(-,-,%s)", key); @@ -80,38 +79,30 @@ GValue *mkdg_g_settings_read_value(GSettings * settings, return value; } - /*============================================ * Interface routines */ -gchar *mkdg_g_settings_backend_get_key(MkdgBackend * backend, - const gchar * section, - const gchar * key, gpointer userData) -{ - return (gchar *) key; +gchar *mkdg_g_settings_backend_get_key(MkdgBackend *backend, + const gchar *section, const gchar *key, + gpointer userData) { + return (gchar *)key; } -GValue *mkdg_g_settings_backend_read_value(MkdgBackend * backend, - GValue * value, - const gchar * section, - const gchar * key, gpointer userData) -{ - GSettings *config = (GSettings *) backend->config; +GValue *mkdg_g_settings_backend_read_value(MkdgBackend *backend, GValue *value, + const gchar *section, + const gchar *key, + gpointer userData) { + GSettings *config = (GSettings *)backend->config; return mkdg_g_settings_read_value(config, value, key); } - -gboolean mkdg_g_settings_backend_write_value(MkdgBackend * - backend, - GValue * - value, - const gchar * - section, - const gchar * - key, gpointer userData) -{ - GSettings *config = (GSettings *) backend->config; +gboolean mkdg_g_settings_backend_write_value(MkdgBackend *backend, + GValue *value, + const gchar *section, + const gchar *key, + gpointer userData) { + GSettings *config = (GSettings *)backend->config; GVariant *confValue = g_variant_ref_sink(mkdg_g_value_to_g_variant(value)); mkdg_log(DEBUG, "mkdg_g_settings_write_value(-,%s,%s) %s", @@ -122,22 +113,20 @@ gboolean mkdg_g_settings_backend_write_value(MkdgBackend * g_settings_sync(); if (!result) { mkdg_log(ERROR, - "mkdg_g_settings_backend_write_value(-,%s,%s,%s,-): Fail g_settings_set_value", + "mkdg_g_settings_backend_write_value(-,%s,%s,%s,-): Fail " + "g_settings_set_value", mkdg_g_value_to_string(value), section, key); } g_variant_unref(confValue); return result; } -MkdgBackend *mkdg_g_settings_backend_new(const gchar * - schemaId, - const gchar * - basePath, gpointer auxData) -{ +MkdgBackend *mkdg_g_settings_backend_new(const gchar *schemaId, + const gchar *basePath, + gpointer auxData) { GSettings *client = g_settings_new(schemaId); - MkdgBackend *result = - mkdg_backend_new(GSETTINGS_BACKEND_ID, (gpointer) client, basePath, - auxData); + MkdgBackend *result = mkdg_backend_new(GSETTINGS_BACKEND_ID, + (gpointer)client, basePath, auxData); result->getKeyFunc = mkdg_g_settings_backend_get_key; result->readFunc = mkdg_g_settings_backend_read_value; diff --git a/src/GSettingsBackend.h b/src/GSettingsBackend.h index f8d725a..0e23231 100644 --- a/src/GSettingsBackend.h +++ b/src/GSettingsBackend.h @@ -16,7 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ /** @@ -30,17 +31,16 @@ */ #ifndef _MKDG_GSETTINGS_BACKEND_H_ -# define _MKDG_GSETTINGS_BACKEND_H_ -# include -# include -# include -# include "MakerDialogPropertySpec.h" -# include "MakerDialogBackend.h" -# define GSETTINGS_BACKEND_ID "gsettings" - -GValue *mkdg_g_settings_read_value(GSettings * settings, - GValue * value, const gchar * key); +#define _MKDG_GSETTINGS_BACKEND_H_ +#include "MakerDialogBackend.h" +#include "MakerDialogPropertySpec.h" +#include +#include +#include +#define GSETTINGS_BACKEND_ID "gsettings" +GValue *mkdg_g_settings_read_value(GSettings *settings, GValue *value, + const gchar *key); /** * mkdg_g_settings_backend_new: @@ -52,8 +52,8 @@ GValue *mkdg_g_settings_read_value(GSettings * settings, * */ -MkdgBackend *mkdg_g_settings_backend_new(const gchar * schemaId, - const gchar * basePath, +MkdgBackend *mkdg_g_settings_backend_new(const gchar *schemaId, + const gchar *basePath, gpointer auxData); -#endif /* _MKDG_GSETTINGS_BACKEND_H_ */ +#endif /* _MKDG_GSETTINGS_BACKEND_H_ */ diff --git a/src/IBusChewingApplier.c b/src/IBusChewingApplier.c index 01e6cab..051a649 100644 --- a/src/IBusChewingApplier.c +++ b/src/IBusChewingApplier.c @@ -1,9 +1,8 @@ -#include -#include "IBusChewingPreEdit.h" #include "IBusChewingLookupTable.h" +#include "IBusChewingPreEdit.h" +#include -static ChewingKbType kbType_id_get_index(const gchar * kbType_id) -{ +static ChewingKbType kbType_id_get_index(const gchar *kbType_id) { ChewingKbType i = 0; for (i = 0; kbType_ids[i] != NULL; i++) { @@ -14,71 +13,61 @@ static ChewingKbType kbType_id_get_index(const gchar * kbType_id) return CHEWING_KBTYPE_INVALID; } - /*============================================ * Callback routines */ -gboolean KBType_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean KBType_apply_callback(PropertyContext *ctx, gpointer userData) { GValue *value = &(ctx->value); IBUS_CHEWING_LOG(DEBUG, "KBType_apply_callback(%s,%s)", ctx->spec->key, mkdg_g_value_to_string(value)); ChewingKbType kbType = kbType_id_get_index(g_value_get_string(value)); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; chewing_set_KBType(icPreEdit->context, kbType); return TRUE; } -gboolean selKeys_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean selKeys_apply_callback(PropertyContext *ctx, gpointer userData) { GValue *value = &(ctx->value); - IBUS_CHEWING_LOG(DEBUG, "selKeys_apply_callback(%s,%s)", - ctx->spec->key, mkdg_g_value_to_string(value)); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBUS_CHEWING_LOG(DEBUG, "selKeys_apply_callback(%s,%s)", ctx->spec->key, + mkdg_g_value_to_string(value)); + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; - ibus_chewing_lookup_table_resize(icPreEdit->iTable, - icPreEdit->iProperties, + ibus_chewing_lookup_table_resize(icPreEdit->iTable, icPreEdit->iProperties, icPreEdit->context); return TRUE; } -gboolean autoShiftCur_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean autoShiftCur_apply_callback(PropertyContext *ctx, gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; chewing_set_autoShiftCur(icPreEdit->context, (g_value_get_boolean(value)) ? 1 : 0); return TRUE; } -gboolean -addPhraseDirection_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean addPhraseDirection_apply_callback(PropertyContext *ctx, + gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; chewing_set_addPhraseDirection(icPreEdit->context, (g_value_get_boolean(value)) ? 1 : 0); return TRUE; } - -gboolean -cleanBufferFocusOut_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean cleanBufferFocusOut_apply_callback(PropertyContext *ctx, + gpointer userData) { return TRUE; } - -gboolean -easySymbolInput_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean easySymbolInput_apply_callback(PropertyContext *ctx, + gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; chewing_set_easySymbolInput(icPreEdit->context, (g_value_get_boolean(value)) ? 1 : 0); @@ -86,10 +75,10 @@ easySymbolInput_apply_callback(PropertyContext * ctx, gpointer userData) return TRUE; } -gboolean escCleanAllBuf_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean escCleanAllBuf_apply_callback(PropertyContext *ctx, + gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; chewing_set_escCleanAllBuf(icPreEdit->context, (g_value_get_boolean(value)) ? 1 : 0); @@ -97,27 +86,26 @@ gboolean escCleanAllBuf_apply_callback(PropertyContext * ctx, gpointer userData) } /* Additional symbol buffer length */ -gboolean -maxChiSymbolLen_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean maxChiSymbolLen_apply_callback(PropertyContext *ctx, + gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; - chewing_set_maxChiSymbolLen(icPreEdit->context, g_value_get_int(value) + 5); /* 5 for incomplete bopomofos */ + chewing_set_maxChiSymbolLen(icPreEdit->context, + g_value_get_int(value) + + 5); /* 5 for incomplete bopomofos */ return TRUE; } -gboolean - defaultEnglishLetterCase_apply_callback - (PropertyContext * ctx, gpointer userData) { +gboolean defaultEnglishLetterCase_apply_callback(PropertyContext *ctx, + gpointer userData) { /* Use MkdgProperty directly, no need to call IBusChewingEngine */ return TRUE; } -gboolean syncCapsLock_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean syncCapsLock_apply_callback(PropertyContext *ctx, gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; const gchar *str = g_value_get_string(value); if (strcmp(str, "keyboard") == 0) { @@ -127,65 +115,58 @@ gboolean syncCapsLock_apply_callback(PropertyContext * ctx, gpointer userData) ibus_chewing_pre_edit_set_flag(icPreEdit, FLAG_SYNC_FROM_IM); ibus_chewing_pre_edit_clear_flag(icPreEdit, FLAG_SYNC_FROM_KEYBOARD); } else { - ibus_chewing_pre_edit_clear_flag(icPreEdit, - FLAG_SYNC_FROM_IM - | FLAG_SYNC_FROM_KEYBOARD); + ibus_chewing_pre_edit_clear_flag( + icPreEdit, FLAG_SYNC_FROM_IM | FLAG_SYNC_FROM_KEYBOARD); } return TRUE; } -gboolean candPerPage_apply_callback(PropertyContext * ctx, gpointer userData) -{ - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; +gboolean candPerPage_apply_callback(PropertyContext *ctx, gpointer userData) { + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; - ibus_chewing_lookup_table_resize(icPreEdit->iTable, - icPreEdit->iProperties, + ibus_chewing_lookup_table_resize(icPreEdit->iTable, icPreEdit->iProperties, icPreEdit->context); return TRUE; } -gboolean showPageNumber_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean showPageNumber_apply_callback(PropertyContext *ctx, + gpointer userData) { /* Use MkdgProperty directly, no need to call IBusChewingEngine */ return TRUE; } -gboolean - phraseChoiceRearward_apply_callback - (PropertyContext * ctx, gpointer userData) { +gboolean phraseChoiceRearward_apply_callback(PropertyContext *ctx, + gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; chewing_set_phraseChoiceRearward(icPreEdit->context, (g_value_get_boolean(value)) ? 1 : 0); return TRUE; } -gboolean -spaceAsSelection_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean spaceAsSelection_apply_callback(PropertyContext *ctx, + gpointer userData) { GValue *value = &(ctx->value); - IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *) ctx->parent; + IBusChewingPreEdit *icPreEdit = (IBusChewingPreEdit *)ctx->parent; chewing_set_spaceAsSelection(icPreEdit->context, (g_value_get_boolean(value)) ? 1 : 0); return TRUE; } -gboolean plainZhuyin_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean plainZhuyin_apply_callback(PropertyContext *ctx, gpointer userData) { /* Use MkdgProperty directly, no need to call IBusChewingEngine */ return TRUE; } -gboolean verticalLookupTable_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean verticalLookupTable_apply_callback(PropertyContext *ctx, + gpointer userData) { /* Use MkdgProperty directly, no need to call IBusChewingEngine */ return TRUE; } -gboolean chiEngToggle_apply_callback(PropertyContext * ctx, gpointer userData) -{ +gboolean chiEngToggle_apply_callback(PropertyContext *ctx, gpointer userData) { /* Use MkdgProperty directly, no need to call IBusChewingEngine */ return TRUE; } diff --git a/src/IBusChewingLookupTable.c b/src/IBusChewingLookupTable.c index b683c0c..9f2ce78 100644 --- a/src/IBusChewingLookupTable.c +++ b/src/IBusChewingLookupTable.c @@ -1,26 +1,24 @@ -#include "IBusChewingUtil.h" #include "IBusChewingLookupTable.h" +#include "IBusChewingUtil.h" #include "MakerDialogProperty.h" -IBusLookupTable *ibus_chewing_lookup_table_new(IBusChewingProperties * - iProperties, - ChewingContext * context) -{ +IBusLookupTable * +ibus_chewing_lookup_table_new(IBusChewingProperties *iProperties, + ChewingContext *context) { guint size = 10; gboolean cursorShow = TRUE; gboolean wrapAround = TRUE; - IBusLookupTable *iTable = ibus_lookup_table_new - (size, 0, cursorShow, wrapAround); + IBusLookupTable *iTable = + ibus_lookup_table_new(size, 0, cursorShow, wrapAround); ibus_chewing_lookup_table_resize(iTable, iProperties, context); return iTable; } -void ibus_chewing_lookup_table_resize(IBusLookupTable * iTable, - IBusChewingProperties * iProperties, - ChewingContext * context) -{ +void ibus_chewing_lookup_table_resize(IBusLookupTable *iTable, + IBusChewingProperties *iProperties, + ChewingContext *context) { gint selKSym[MAX_SELKEY]; const gchar *selKeyStr = mkdg_properties_get_string_by_key(iProperties->properties, "sel-keys"); @@ -38,10 +36,10 @@ void ibus_chewing_lookup_table_resize(IBusLookupTable * iTable, ibus_lookup_table_set_page_size(iTable, len); for (i = 0; i < len; i++) { - selKSym[i] = (gint) selKeyStr[i]; + selKSym[i] = (gint)selKeyStr[i]; - iText = g_object_ref_sink(ibus_text_new_from_printf - ("%c.", toupper(selKeyStr[i]))); + iText = g_object_ref_sink( + ibus_text_new_from_printf("%c.", toupper(selKeyStr[i]))); ibus_lookup_table_set_label(iTable, i, iText); g_object_unref(iText); } @@ -49,17 +47,15 @@ void ibus_chewing_lookup_table_resize(IBusLookupTable * iTable, chewing_set_candPerPage(context, len); chewing_set_selKey(context, selKSym, len); - gboolean verticalLookupTable = - mkdg_properties_get_boolean_by_key(iProperties->properties, - "vertical-lookup-table"); + gboolean verticalLookupTable = mkdg_properties_get_boolean_by_key( + iProperties->properties, "vertical-lookup-table"); ibus_lookup_table_set_orientation(iTable, verticalLookupTable); } -guint ibus_chewing_lookup_table_update(IBusLookupTable * iTable, - IBusChewingProperties * iProperties, - ChewingContext * context) -{ +guint ibus_chewing_lookup_table_update(IBusLookupTable *iTable, + IBusChewingProperties *iProperties, + ChewingContext *context) { IBusText *iText = NULL; guint i; gint choicePerPage = chewing_cand_ChoicePerPage(context); @@ -67,7 +63,8 @@ guint ibus_chewing_lookup_table_update(IBusLookupTable * iTable, gint currentPage = chewing_cand_CurrentPage(context); IBUS_CHEWING_LOG(INFO, - "***** ibus_chewing_lookup_table_update(): choicePerPage=%d, totalChoice=%d, currentPage=%d", + "***** ibus_chewing_lookup_table_update(): " + "choicePerPage=%d, totalChoice=%d, currentPage=%d", choicePerPage, totalChoice, currentPage); ibus_lookup_table_clear(iTable); diff --git a/src/IBusChewingLookupTable.h b/src/IBusChewingLookupTable.h index 5c8d1c5..ee3c8da 100644 --- a/src/IBusChewingLookupTable.h +++ b/src/IBusChewingLookupTable.h @@ -16,7 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ /** @@ -31,21 +32,21 @@ */ #ifndef _IBUS_CHEWING_LOOKUP_TABLE_H_ -# define _IBUS_CHEWING_LOOKUP_TABLE_H_ -# include -# include -# include "IBusChewingProperties.h" +#define _IBUS_CHEWING_LOOKUP_TABLE_H_ +#include "IBusChewingProperties.h" +#include +#include -IBusLookupTable *ibus_chewing_lookup_table_new(IBusChewingProperties * - iProperties, - ChewingContext * context); +IBusLookupTable * +ibus_chewing_lookup_table_new(IBusChewingProperties *iProperties, + ChewingContext *context); -void ibus_chewing_lookup_table_resize(IBusLookupTable * iTable, - IBusChewingProperties * iProperties, - ChewingContext * context); +void ibus_chewing_lookup_table_resize(IBusLookupTable *iTable, + IBusChewingProperties *iProperties, + ChewingContext *context); -guint ibus_chewing_lookup_table_update(IBusLookupTable * iTable, - IBusChewingProperties * iProperties, - ChewingContext * context); +guint ibus_chewing_lookup_table_update(IBusLookupTable *iTable, + IBusChewingProperties *iProperties, + ChewingContext *context); -#endif /* _IBUS_CHEWING_LOOKUP_TABLE_H_ */ +#endif /* _IBUS_CHEWING_LOOKUP_TABLE_H_ */ diff --git a/src/IBusChewingPreEdit-private.h b/src/IBusChewingPreEdit-private.h index 8271c27..de2ec42 100644 --- a/src/IBusChewingPreEdit-private.h +++ b/src/IBusChewingPreEdit-private.h @@ -16,7 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ /* @@ -24,58 +25,101 @@ * Put it here so they can be tested. */ #ifndef _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_ -# define _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_ +#define _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_ /*== Frequent used shortcut ==*/ -# define cursor_current chewing_cursor_Current(self->context) -# define total_choice chewing_cand_TotalChoice(self->context) -# define default_english_case_short (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "default-english-case"), "lowercase")) ? 'l' : \ - (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "default-english-case"), "uppercase") ? 'u' : 'n') -# define chi_eng_toggle_key (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "caps_lock")) ? 'c' : \ - (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "shift")) ? 's' : \ - (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "shift_l")) ? 'l' : \ - (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string(self, "chi-eng-mode-toggle"), "shift_r") ? 'r' : 'n') +#define cursor_current chewing_cursor_Current(self->context) +#define total_choice chewing_cand_TotalChoice(self->context) +#define default_english_case_short \ + (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string( \ + self, "default-english-case"), \ + "lowercase")) \ + ? 'l' \ + : (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string( \ + self, "default-english-case"), \ + "uppercase") \ + ? 'u' \ + : 'n') +#define chi_eng_toggle_key \ + (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string( \ + self, "chi-eng-mode-toggle"), \ + "caps_lock")) \ + ? 'c' \ + : (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string( \ + self, "chi-eng-mode-toggle"), \ + "shift")) \ + ? 's' \ + : (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string( \ + self, "chi-eng-mode-toggle"), \ + "shift_l")) \ + ? 'l' \ + : (STRING_EQUALS(ibus_chewing_pre_edit_get_property_string( \ + self, "chi-eng-mode-toggle"), \ + "shift_r") \ + ? 'r' \ + : 'n') /*== Conditional Expression Shortcut ==*/ -# define is_plain_zhuyin ibus_chewing_pre_edit_get_property_boolean(self, "plain-zhuyin") -# define bpmf_check ibus_chewing_bopomofo_check(self->context) -# define table_is_showing ibus_chewing_pre_edit_has_flag(self, FLAG_TABLE_SHOW) - -# define is_capslock (umaskedMod == IBUS_LOCK_MASK) -# define is_shift_only (maskedMod == IBUS_SHIFT_MASK) -# define is_shift (unmaskedMod & IBUS_SHIFT_MASK) -# define is_ctrl_only (maskedMod == IBUS_CONTROL_MASK) -# define buffer_is_empty (ibus_chewing_pre_edit_is_empty(self)) +#define is_plain_zhuyin \ + ibus_chewing_pre_edit_get_property_boolean(self, "plain-zhuyin") +#define bpmf_check ibus_chewing_bopomofo_check(self->context) +#define table_is_showing ibus_chewing_pre_edit_has_flag(self, FLAG_TABLE_SHOW) +#define is_capslock (umaskedMod == IBUS_LOCK_MASK) +#define is_shift_only (maskedMod == IBUS_SHIFT_MASK) +#define is_shift (unmaskedMod & IBUS_SHIFT_MASK) +#define is_ctrl_only (maskedMod == IBUS_CONTROL_MASK) +#define buffer_is_empty (ibus_chewing_pre_edit_is_empty(self)) /*== Event processing ==*/ /* We only recognize the combination of shift, control and alt */ -# define modifiers_mask(unmaskedMod) unmaskedMod & (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK) +#define modifiers_mask(unmaskedMod) \ + unmaskedMod &(IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK) /** * filter_modifier: * @allowed Allowed modifler. * - * allowed=0 means only the keysym is allowed, no shift, alt, control are allowed. - * allowed=IBUS_SHIFT_MASK means both keysym without modifier or shift are allowed. + * allowed=0 means only the keysym is allowed, no shift, alt, control are + * allowed. allowed=IBUS_SHIFT_MASK means both keysym without modifier or shift + * are allowed. */ -# define filter_modifiers(allowed) KeyModifiers maskedMod = modifiers_mask(unmaskedMod); \ - if ( (maskedMod) & (~(allowed))){ return EVENT_RESPONSE_IGNORE; } -# define absorb_when_release if (event_is_released(unmaskedMod)) { return EVENT_RESPONSE_ABSORB; } -# define ignore_when_release if (event_is_released(unmaskedMod)) { return EVENT_RESPONSE_IGNORE; } -# define ignore_when_buffer_is_empty if (buffer_is_empty) { return EVENT_RESPONSE_IGNORE; } -# define ignore_when_buffer_is_empty_and_table_not_showing if (buffer_is_empty && !table_is_showing) { return EVENT_RESPONSE_IGNORE; } +#define filter_modifiers(allowed) \ + KeyModifiers maskedMod = modifiers_mask(unmaskedMod); \ + if ((maskedMod) & (~(allowed))) { \ + return EVENT_RESPONSE_IGNORE; \ + } +#define absorb_when_release \ + if (event_is_released(unmaskedMod)) { \ + return EVENT_RESPONSE_ABSORB; \ + } +#define ignore_when_release \ + if (event_is_released(unmaskedMod)) { \ + return EVENT_RESPONSE_IGNORE; \ + } +#define ignore_when_buffer_is_empty \ + if (buffer_is_empty) { \ + return EVENT_RESPONSE_IGNORE; \ + } +#define ignore_when_buffer_is_empty_and_table_not_showing \ + if (buffer_is_empty && !table_is_showing) { \ + return EVENT_RESPONSE_IGNORE; \ + } -# define event_is_released(unmaskedMod) ((unmaskedMod & IBUS_RELEASE_MASK) !=0 ) -# define event_process_or_ignore(cond) (cond) ? EVENT_RESPONSE_PROCESS: EVENT_RESPONSE_IGNORE +#define event_is_released(unmaskedMod) ((unmaskedMod & IBUS_RELEASE_MASK) != 0) +#define event_process_or_ignore(cond) \ + (cond) ? EVENT_RESPONSE_PROCESS : EVENT_RESPONSE_IGNORE -# define handle_log(funcName) IBUS_CHEWING_LOG(INFO, "* self_handle_%s(-,%x(%s),%x(%s))", funcName, kSym, key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod)); +#define handle_log(funcName) \ + IBUS_CHEWING_LOG(INFO, "* self_handle_%s(-,%x(%s),%x(%s))", funcName, \ + kSym, key_sym_get_name(kSym), unmaskedMod, \ + modifiers_to_string(unmaskedMod)); -KSym self_key_sym_fix(IBusChewingPreEdit * self, - KSym kSym, KeyModifiers unmaskedMod); +KSym self_key_sym_fix(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod); -EventResponse self_handle_key_sym_default(IBusChewingPreEdit * self, - KSym kSym, KeyModifiers unmaskedMod); +EventResponse self_handle_key_sym_default(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod); -void ibus_chewing_pre_edit_update(IBusChewingPreEdit * self); -#endif /* _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_ */ +void ibus_chewing_pre_edit_update(IBusChewingPreEdit *self); +#endif /* _IBUS_CHEWING_PRE_EDIT_PRIVATE_H_ */ diff --git a/src/IBusChewingPreEdit.c b/src/IBusChewingPreEdit.c index d51d572..8ea6a67 100644 --- a/src/IBusChewingPreEdit.c +++ b/src/IBusChewingPreEdit.c @@ -1,16 +1,15 @@ -#include -#include -#include "IBusChewingUtil.h" -#include "IBusChewingProperties.h" #include "IBusChewingPreEdit.h" #include "IBusChewingPreEdit-private.h" +#include "IBusChewingProperties.h" +#include "IBusChewingUtil.h" +#include +#include /************************************** * Methods */ -IBusChewingPreEdit *ibus_chewing_pre_edit_new(MkdgBackend * backend) -{ +IBusChewingPreEdit *ibus_chewing_pre_edit_new(MkdgBackend *backend) { IBusChewingPreEdit *self = g_new0(IBusChewingPreEdit, 1); self->iProperties = ibus_chewing_properties_new(backend, self, NULL); @@ -25,7 +24,7 @@ IBusChewingPreEdit *ibus_chewing_pre_edit_new(MkdgBackend * backend) gchar buf[100]; g_snprintf(buf, 100, "%s/.chewing", getenv("HOME")); -#if !CHEWING_CHECK_VERSION(0,4,0) +#if !CHEWING_CHECK_VERSION(0, 4, 0) gint ret = chewing_Init(QUOTE_ME(CHEWING_DATADIR_REAL), buf); if (ret) { @@ -37,14 +36,12 @@ IBusChewingPreEdit *ibus_chewing_pre_edit_new(MkdgBackend * backend) self->context = chewing_new(); chewing_set_ChiEngMode(self->context, CHINESE_MODE); - self->iTable = - g_object_ref_sink(ibus_chewing_lookup_table_new - (self->iProperties, self->context)); + self->iTable = g_object_ref_sink( + ibus_chewing_lookup_table_new(self->iProperties, self->context)); return self; } -void ibus_chewing_pre_edit_free(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_free(IBusChewingPreEdit *self) { /* properties need not be freed here */ chewing_delete(self->context); g_string_free(self->preEdit, TRUE); @@ -54,23 +51,21 @@ void ibus_chewing_pre_edit_free(IBusChewingPreEdit * self) g_free(self); } -gchar *ibus_chewing_pre_edit_get_bopomofo_string(IBusChewingPreEdit * self) -{ -#if CHEWING_CHECK_VERSION(0,4,0) +gchar *ibus_chewing_pre_edit_get_bopomofo_string(IBusChewingPreEdit *self) { +#if CHEWING_CHECK_VERSION(0, 4, 0) const gchar *buf = chewing_bopomofo_String_static(self->context); + return g_strdup(buf); #else return chewing_zuin_String(self->context, &(self->bpmfLen)); #endif } -void ibus_chewing_pre_edit_use_all_configure(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_use_all_configure(IBusChewingPreEdit *self) { mkdg_properties_use_all(self->iProperties->properties, NULL); } -void ibus_chewing_pre_edit_update_outgoing(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_update_outgoing(IBusChewingPreEdit *self) { if (ibus_chewing_pre_edit_has_flag(self, FLAG_UPDATED_OUTGOING)) { /* Commit already sent to outgoing, no need to update again */ return; @@ -85,19 +80,20 @@ void ibus_chewing_pre_edit_update_outgoing(IBusChewingPreEdit * self) ibus_chewing_pre_edit_set_flag(self, FLAG_UPDATED_OUTGOING); } IBUS_CHEWING_LOG(INFO, "outgoing=|%s|\n", self->outgoing->str); - IBUS_CHEWING_LOG(DEBUG, - "ibus_chewing_pre_edit_update_outgoing(-): return: outgoing=|%s|", - self->outgoing->str); + IBUS_CHEWING_LOG( + DEBUG, + "ibus_chewing_pre_edit_update_outgoing(-): return: outgoing=|%s|", + self->outgoing->str); } -void ibus_chewing_pre_edit_update(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_update(IBusChewingPreEdit *self) { IBUS_CHEWING_LOG(DEBUG, "* ibus_chewing_pre_edit_update(-)"); /* Make preEdit */ gchar *bufferStr = chewing_buffer_String(self->context); gchar *bpmfStr = ibus_chewing_pre_edit_get_bopomofo_string(self); - self->bpmfLen = (gint) g_utf8_strlen(bpmfStr, -1); + + self->bpmfLen = (gint)g_utf8_strlen(bpmfStr, -1); g_string_assign(self->preEdit, ""); gint i; @@ -105,7 +101,8 @@ void ibus_chewing_pre_edit_update(IBusChewingPreEdit * self) gunichar uniCh; IBUS_CHEWING_LOG(INFO, - "* ibus_chewing_pre_edit_update(-) bufferStr=|%s|, bpmfStr=|%s| bpmfLen=%d cursor=%d", + "* ibus_chewing_pre_edit_update(-) bufferStr=|%s|, " + "bpmfStr=|%s| bpmfLen=%d cursor=%d", bufferStr, bpmfStr, self->bpmfLen, cursor_current); for (i = 0; i < chewing_buffer_Len(self->context) && cP != NULL; i++) { @@ -129,37 +126,33 @@ void ibus_chewing_pre_edit_update(IBusChewingPreEdit * self) ibus_chewing_pre_edit_update_outgoing(self); } -guint ibus_chewing_pre_edit_length(IBusChewingPreEdit * self) -{ +guint ibus_chewing_pre_edit_length(IBusChewingPreEdit *self) { return self->preEdit->len; } -guint ibus_chewing_pre_edit_word_length(IBusChewingPreEdit * self) -{ +guint ibus_chewing_pre_edit_word_length(IBusChewingPreEdit *self) { return self->wordLen; } -guint ibus_chewing_pre_edit_word_limit(IBusChewingPreEdit * self) -{ +guint ibus_chewing_pre_edit_word_limit(IBusChewingPreEdit *self) { return chewing_get_maxChiSymbolLen(self->context); } -gchar *ibus_chewing_pre_edit_get_pre_edit(IBusChewingPreEdit * self) -{ +gchar *ibus_chewing_pre_edit_get_pre_edit(IBusChewingPreEdit *self) { return self->preEdit->str; } -gchar *ibus_chewing_pre_edit_get_outgoing(IBusChewingPreEdit * self) -{ +gchar *ibus_chewing_pre_edit_get_outgoing(IBusChewingPreEdit *self) { return self->outgoing->str; } -/* currently, ibus_chewing_pre_edit_force_commit() is called only by test cases. */ -void ibus_chewing_pre_edit_force_commit(IBusChewingPreEdit * self) -{ - IBUS_CHEWING_LOG(INFO, - "ibus_chewing_pre_edit_force_commit(-) bpmf_check=%d buffer_check=%d", - bpmf_check, chewing_buffer_Check(self->context)); +/* currently, ibus_chewing_pre_edit_force_commit() is called only by test cases. + */ +void ibus_chewing_pre_edit_force_commit(IBusChewingPreEdit *self) { + IBUS_CHEWING_LOG( + INFO, + "ibus_chewing_pre_edit_force_commit(-) bpmf_check=%d buffer_check=%d", + bpmf_check, chewing_buffer_Check(self->context)); /* Ignore the context and commit whatever in preedit buffer */ g_string_append(self->outgoing, self->preEdit->str); @@ -167,18 +160,16 @@ void ibus_chewing_pre_edit_force_commit(IBusChewingPreEdit * self) ibus_chewing_pre_edit_update(self); } -void ibus_chewing_pre_edit_clear(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_clear(IBusChewingPreEdit *self) { IBUS_CHEWING_LOG(INFO, "ibus_chewing_pre_edit_clear(-)"); ibus_chewing_pre_edit_clear_outgoing(self); ibus_chewing_pre_edit_clear_pre_edit(self); } -void ibus_chewing_pre_edit_clear_bopomofo(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_clear_bopomofo(IBusChewingPreEdit *self) { IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_pre_edit_clear_bopomofo(-)"); - /* Esc key can close candidate list, clear bopomofo, and clear + /* Esc key can close candidate list, clear bopomofo, and clear * the whole pre-edit buffer. Make sure it acts as we expected. */ if (table_is_showing) { @@ -190,8 +181,7 @@ void ibus_chewing_pre_edit_clear_bopomofo(IBusChewingPreEdit * self) } } -void ibus_chewing_pre_edit_clear_pre_edit(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_clear_pre_edit(IBusChewingPreEdit *self) { IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_pre_edit_clear_pre_edit(-)"); ibus_chewing_pre_edit_clear_bopomofo(self); @@ -207,27 +197,23 @@ void ibus_chewing_pre_edit_clear_pre_edit(IBusChewingPreEdit * self) ibus_chewing_pre_edit_update(self); } -void ibus_chewing_pre_edit_clear_outgoing(IBusChewingPreEdit * self) -{ +void ibus_chewing_pre_edit_clear_outgoing(IBusChewingPreEdit *self) { IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_pre_edit_clear_outgoing(-)"); g_string_assign(self->outgoing, ""); } #define is_chinese ibus_chewing_pre_edit_get_chi_eng_mode(self) #define is_full_shape ibus_chewing_pre_edit_get_full_half_mode(self) -gboolean ibus_chewing_pre_edit_get_chi_eng_mode(IBusChewingPreEdit * self) -{ +gboolean ibus_chewing_pre_edit_get_chi_eng_mode(IBusChewingPreEdit *self) { return chewing_get_ChiEngMode(self->context) != 0; } -gboolean ibus_chewing_pre_edit_get_full_half_mode(IBusChewingPreEdit * self) -{ +gboolean ibus_chewing_pre_edit_get_full_half_mode(IBusChewingPreEdit *self) { return chewing_get_ShapeMode(self->context) != 0; } -void ibus_chewing_pre_edit_set_chi_eng_mode(IBusChewingPreEdit * self, - gboolean chineseMode) -{ +void ibus_chewing_pre_edit_set_chi_eng_mode(IBusChewingPreEdit *self, + gboolean chineseMode) { /* Clear bopomofo when toggling Chi-Eng Mode */ if (!chineseMode && is_chinese && bpmf_check) { ibus_chewing_pre_edit_clear_bopomofo(self); @@ -235,9 +221,8 @@ void ibus_chewing_pre_edit_set_chi_eng_mode(IBusChewingPreEdit * self, chewing_set_ChiEngMode(self->context, (chineseMode) ? 1 : 0); } -void ibus_chewing_pre_edit_set_full_half_mode(IBusChewingPreEdit * self, - gboolean fullShapeMode) -{ +void ibus_chewing_pre_edit_set_full_half_mode(IBusChewingPreEdit *self, + gboolean fullShapeMode) { if (is_chinese && bpmf_check) { /* Clear bopomofo when toggling Full-Half Mode */ ibus_chewing_pre_edit_clear_bopomofo(self); @@ -248,19 +233,17 @@ void ibus_chewing_pre_edit_set_full_half_mode(IBusChewingPreEdit * self, /************************************** * ibus_chewing_pre_edit key processing */ -KSym self_key_sym_fix(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +KSym self_key_sym_fix(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { gchar caseConversionMode = default_english_case_short; gchar toggleChinese = chi_eng_toggle_key; - if (toggleChinese != 'c') { caseConversionMode = 'n'; } if (is_chinese) { - /* + /* * Ignore the status of CapsLock, thus */ if (is_shift) { @@ -291,21 +274,20 @@ KSym self_key_sym_fix(IBusChewingPreEdit * self, KSym kSym, return kSym; } -EventResponse self_handle_key_sym_default(IBusChewingPreEdit * self, - KSym kSym, KeyModifiers unmaskedMod) -{ +EventResponse self_handle_key_sym_default(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK); if (!is_full_shape && !is_chinese) { - /* Users treat English Sub-mode as IM Disabled, - * So key strokes should be passed to client directly. Github 144. - */ - ignore_when_buffer_is_empty_and_table_not_showing; + /* Users treat English Sub-mode as IM Disabled, + * So key strokes should be passed to client directly. Github 144. + */ + ignore_when_buffer_is_empty_and_table_not_showing; } handle_log("key_sym_default"); - /* Seem like we need to disable easy symbol temporarily + /* Seem like we need to disable easy symbol temporarily * otherwise the key won't process */ gint easySymbolInput = chewing_get_easySymbolInput(self->context); @@ -341,8 +323,7 @@ EventResponse self_handle_key_sym_default(IBusChewingPreEdit * self, break; } - IBUS_CHEWING_LOG(DEBUG, - "self_handle_key_sym_default() ret=%d response=%d", + IBUS_CHEWING_LOG(DEBUG, "self_handle_key_sym_default() ret=%d response=%d", ret, response); /* Restore easySymbolInput */ chewing_set_easySymbolInput(self->context, easySymbolInput); @@ -350,37 +331,34 @@ EventResponse self_handle_key_sym_default(IBusChewingPreEdit * self, } /* Return FALSE if the key should not be processed with input method */ -EventResponse self_handle_num(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_num(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK | IBUS_CONTROL_MASK); if ((maskedMod == 0) && !is_full_shape && !is_chinese) { - /* Users treat English Sub-mode as IM Disabled, - * So key strokes should be passed to client directly. Github 144. - */ - ignore_when_buffer_is_empty_and_table_not_showing; - } + /* Users treat English Sub-mode as IM Disabled, + * So key strokes should be passed to client directly. Github 144. + */ + ignore_when_buffer_is_empty_and_table_not_showing; + } ignore_when_release; handle_log("num"); if (is_ctrl_only) { - return - event_process_or_ignore(!chewing_handle_CtrlNum - (self->context, kSym)); + return event_process_or_ignore( + !chewing_handle_CtrlNum(self->context, kSym)); } /* maskedMod = 0 */ return self_handle_key_sym_default(self, kSym, unmaskedMod); } -EventResponse self_handle_num_keypad(IBusChewingPreEdit * self, - KSym kSym, KeyModifiers unmaskedMod) -{ +EventResponse self_handle_num_keypad(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK | IBUS_CONTROL_MASK); if ((maskedMod == 0) && (!is_full_shape)) { - /* Let libchewing handles Keypad keys only when needed. - * Otherwise it might cause some issues. Github 144. - */ - ignore_when_buffer_is_empty_and_table_not_showing; + /* Let libchewing handles Keypad keys only when needed. + * Otherwise it might cause some issues. Github 144. + */ + ignore_when_buffer_is_empty_and_table_not_showing; } ignore_when_release; handle_log("num_keypad"); @@ -392,9 +370,8 @@ EventResponse self_handle_num_keypad(IBusChewingPreEdit * self, } if (is_ctrl_only) { - return - event_process_or_ignore(!chewing_handle_CtrlNum - (self->context, kSymEquiv)); + return event_process_or_ignore( + !chewing_handle_CtrlNum(self->context, kSymEquiv)); } /* maskedMod = 0 */ @@ -403,17 +380,16 @@ EventResponse self_handle_num_keypad(IBusChewingPreEdit * self, ibus_chewing_pre_edit_set_chi_eng_mode(self, FALSE); - EventResponse - response = self_handle_key_sym_default(self, kSymEquiv, unmaskedMod); + EventResponse response = + self_handle_key_sym_default(self, kSymEquiv, unmaskedMod); chewing_set_ChiEngMode(self->context, origChiEngMode); return response; } -EventResponse self_handle_caps_lock(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_caps_lock(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); gchar toggleChinese = chi_eng_toggle_key; @@ -433,15 +409,14 @@ EventResponse self_handle_caps_lock(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Capslock(self->context)); } -EventResponse self_handle_shift_left(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_shift_left(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK); handle_log("shift_left"); gchar toggleChinese = chi_eng_toggle_key; - if (toggleChinese != 's' && toggleChinese != 'l' ) { + if (toggleChinese != 's' && toggleChinese != 'l') { return EVENT_RESPONSE_IGNORE; } @@ -452,7 +427,8 @@ EventResponse self_handle_shift_left(IBusChewingPreEdit * self, KSym kSym, /* keyLast != Shift means Shift is just part of combination, * thus should not be recognized as single Shift key */ - if (self->keyLast != IBUS_KEY_Shift_L && self->keyLast != IBUS_KEY_Shift_R) { + if (self->keyLast != IBUS_KEY_Shift_L && + self->keyLast != IBUS_KEY_Shift_R) { return EVENT_RESPONSE_ABSORB; } @@ -460,15 +436,14 @@ EventResponse self_handle_shift_left(IBusChewingPreEdit * self, KSym kSym, return EVENT_RESPONSE_ABSORB; } -EventResponse self_handle_shift_right(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_shift_right(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK); handle_log("shift_right"); gchar toggleChinese = chi_eng_toggle_key; - if (toggleChinese != 's' && toggleChinese != 'r' ) { + if (toggleChinese != 's' && toggleChinese != 'r') { return EVENT_RESPONSE_IGNORE; } @@ -479,7 +454,8 @@ EventResponse self_handle_shift_right(IBusChewingPreEdit * self, KSym kSym, /* keyLast != Shift means Shift is just part of combination, * thus should not be recognized as single Shift key */ - if (self->keyLast != IBUS_KEY_Shift_L && self->keyLast != IBUS_KEY_Shift_R) { + if (self->keyLast != IBUS_KEY_Shift_L && + self->keyLast != IBUS_KEY_Shift_R) { return EVENT_RESPONSE_ABSORB; } @@ -487,9 +463,8 @@ EventResponse self_handle_shift_right(IBusChewingPreEdit * self, KSym kSym, return EVENT_RESPONSE_ABSORB; } -EventResponse self_handle_page_up(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_page_up(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -508,9 +483,8 @@ EventResponse self_handle_page_up(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_PageUp(self->context)); } -EventResponse self_handle_page_down(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_page_down(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -526,16 +500,15 @@ EventResponse self_handle_page_down(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_PageDown(self->context)); } -EventResponse self_handle_space(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_space(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK | IBUS_CONTROL_MASK); - if (!is_shift_only && !is_chinese && !is_full_shape) { - /* Let libchewing handles Keypad keys only when needed. - * Otherwise it might cause some issues. Github 144. - */ - ignore_when_buffer_is_empty_and_table_not_showing; + if (!is_shift_only && !is_chinese && !is_full_shape) { + /* Let libchewing handles Keypad keys only when needed. + * Otherwise it might cause some issues. Github 144. + */ + ignore_when_buffer_is_empty_and_table_not_showing; } ignore_when_release; @@ -546,7 +519,7 @@ EventResponse self_handle_space(IBusChewingPreEdit * self, KSym kSym, return EVENT_RESPONSE_PROCESS; } - /* Bug of libchewing: + /* Bug of libchewing: * If "Space as selection" is not enabled, Space key cannot be used * to turn pages or switch the length of candidate lis. */ @@ -554,7 +527,7 @@ EventResponse self_handle_space(IBusChewingPreEdit * self, KSym kSym, return self_handle_page_down(self, kSym, unmaskedMod); } - /* Bug of libchewing: + /* Bug of libchewing: * when "space to select" is enabled, chewing_handle_Space() will * ignore the first space. Therefore, use chewing_handle_Space() * only if the buffer is not empty and we want to select. @@ -569,9 +542,8 @@ EventResponse self_handle_space(IBusChewingPreEdit * self, KSym kSym, } } -EventResponse self_handle_return(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_return(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -579,6 +551,7 @@ EventResponse self_handle_return(IBusChewingPreEdit * self, KSym kSym, if (table_is_showing) { int cursorInPage = ibus_lookup_table_get_cursor_in_page(self->iTable); + cursorInPage = chewing_get_selKey(self->context)[cursorInPage]; return self_handle_key_sym_default(self, cursorInPage, unmaskedMod); } @@ -593,15 +566,15 @@ EventResponse self_handle_return(IBusChewingPreEdit * self, KSym kSym, return response; } -EventResponse self_handle_backspace(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_backspace(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; - absorb_when_release; // Triggers focus-out and focus-in on ignore, so use absorb. + absorb_when_release; // Triggers focus-out and focus-in on ignore, so use + // absorb. handle_log("backspace"); -#if !CHEWING_CHECK_VERSION(0,4,0) +#if !CHEWING_CHECK_VERSION(0, 4, 0) if (table_is_showing) { return event_process_or_ignore(!chewing_handle_Esc(self->context)); } @@ -610,9 +583,8 @@ EventResponse self_handle_backspace(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Backspace(self->context)); } -EventResponse self_handle_delete(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_delete(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -621,9 +593,8 @@ EventResponse self_handle_delete(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Del(self->context)); } -EventResponse self_handle_escape(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_escape(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -632,23 +603,23 @@ EventResponse self_handle_escape(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Esc(self->context)); } -EventResponse self_handle_left(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_left(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; handle_log("left"); if (is_shift_only) { - return - event_process_or_ignore(!chewing_handle_ShiftLeft(self->context)); + return event_process_or_ignore( + !chewing_handle_ShiftLeft(self->context)); } if (table_is_showing) { - if(!ibus_chewing_pre_edit_is_vertical_table(self)) { + if (!ibus_chewing_pre_edit_is_vertical_table(self)) { /* horizontal look-up table */ int pos = ibus_lookup_table_get_cursor_in_page(self->iTable); + if (pos) { ibus_lookup_table_cursor_up(self->iTable); return EVENT_RESPONSE_ABSORB; @@ -661,18 +632,18 @@ EventResponse self_handle_left(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Left(self->context)); } -EventResponse self_handle_up(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_up(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; handle_log("up"); if (table_is_showing) { - if(ibus_chewing_pre_edit_is_vertical_table(self)) { + if (ibus_chewing_pre_edit_is_vertical_table(self)) { /* vertical look-up table */ int pos = ibus_lookup_table_get_cursor_in_page(self->iTable); + if (pos) { ibus_lookup_table_cursor_up(self->iTable); return EVENT_RESPONSE_ABSORB; @@ -685,25 +656,26 @@ EventResponse self_handle_up(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Up(self->context)); } -EventResponse self_handle_right(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_right(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; handle_log("right"); if (is_shift_only) { - return - event_process_or_ignore(!chewing_handle_ShiftRight(self->context)); + return event_process_or_ignore( + !chewing_handle_ShiftRight(self->context)); } if (table_is_showing) { - if(!ibus_chewing_pre_edit_is_vertical_table(self)) { + if (!ibus_chewing_pre_edit_is_vertical_table(self)) { /* horizontal look-up table */ - int numberCand = ibus_lookup_table_get_number_of_candidates(self->iTable); - int cursorInPage = ibus_lookup_table_get_cursor_in_page(self->iTable) + 1; + int numberCand = + ibus_lookup_table_get_number_of_candidates(self->iTable); + int cursorInPage = + ibus_lookup_table_get_cursor_in_page(self->iTable) + 1; if (cursorInPage != numberCand) { ibus_lookup_table_cursor_down(self->iTable); return EVENT_RESPONSE_ABSORB; @@ -716,20 +688,21 @@ EventResponse self_handle_right(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Right(self->context)); } -EventResponse self_handle_down(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_down(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; handle_log("down"); if (table_is_showing) { - if(ibus_chewing_pre_edit_is_vertical_table(self)) { + if (ibus_chewing_pre_edit_is_vertical_table(self)) { /* vertical look-up table */ - int numberCand = ibus_lookup_table_get_number_of_candidates(self->iTable); - int cursorInPage = ibus_lookup_table_get_cursor_in_page(self->iTable) + 1; + int numberCand = + ibus_lookup_table_get_number_of_candidates(self->iTable); + int cursorInPage = + ibus_lookup_table_get_cursor_in_page(self->iTable) + 1; if (cursorInPage != numberCand) { ibus_lookup_table_cursor_down(self->iTable); return EVENT_RESPONSE_ABSORB; @@ -743,9 +716,8 @@ EventResponse self_handle_down(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Down(self->context)); } -EventResponse self_handle_tab(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_tab(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -754,9 +726,8 @@ EventResponse self_handle_tab(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Tab(self->context)); } -EventResponse self_handle_home(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_home(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -765,9 +736,8 @@ EventResponse self_handle_home(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_Home(self->context)); } -EventResponse self_handle_end(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_end(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(0); ignore_when_buffer_is_empty_and_table_not_showing; ignore_when_release; @@ -776,16 +746,14 @@ EventResponse self_handle_end(IBusChewingPreEdit * self, KSym kSym, return event_process_or_ignore(!chewing_handle_End(self->context)); } -EventResponse self_handle_special(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_special(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { /* KSym >=128 is special key, which IM ignore. */ return EVENT_RESPONSE_IGNORE; } -EventResponse self_handle_default(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ +EventResponse self_handle_default(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { filter_modifiers(IBUS_SHIFT_MASK); ignore_when_release; handle_log("default"); @@ -794,107 +762,74 @@ EventResponse self_handle_default(IBusChewingPreEdit * self, KSym kSym, } KeyHandlingRule keyHandlingRules[] = { - {IBUS_KEY_0, IBUS_KEY_9, self_handle_num} - , + {IBUS_KEY_0, IBUS_KEY_9, self_handle_num}, - {IBUS_KEY_KP_0, IBUS_KEY_KP_9, self_handle_num_keypad} - , + {IBUS_KEY_KP_0, IBUS_KEY_KP_9, self_handle_num_keypad}, - {IBUS_KEY_Caps_Lock, IBUS_KEY_Caps_Lock, self_handle_caps_lock} - , + {IBUS_KEY_Caps_Lock, IBUS_KEY_Caps_Lock, self_handle_caps_lock}, - {IBUS_KEY_Shift_L, IBUS_KEY_Shift_L, self_handle_shift_left} - , + {IBUS_KEY_Shift_L, IBUS_KEY_Shift_L, self_handle_shift_left}, - {IBUS_KEY_Shift_R, IBUS_KEY_Shift_R, self_handle_shift_right} - , + {IBUS_KEY_Shift_R, IBUS_KEY_Shift_R, self_handle_shift_right}, - {IBUS_KEY_space, IBUS_KEY_space, self_handle_space} - , + {IBUS_KEY_space, IBUS_KEY_space, self_handle_space}, - {IBUS_KEY_Return, IBUS_KEY_Return, self_handle_return} - , + {IBUS_KEY_Return, IBUS_KEY_Return, self_handle_return}, - {IBUS_KEY_KP_Enter, IBUS_KEY_KP_Enter, self_handle_return} - , + {IBUS_KEY_KP_Enter, IBUS_KEY_KP_Enter, self_handle_return}, - {IBUS_KEY_BackSpace, IBUS_KEY_BackSpace, self_handle_backspace} - , + {IBUS_KEY_BackSpace, IBUS_KEY_BackSpace, self_handle_backspace}, - {IBUS_KEY_Delete, IBUS_KEY_Delete, self_handle_delete} - , + {IBUS_KEY_Delete, IBUS_KEY_Delete, self_handle_delete}, - {IBUS_KEY_KP_Delete, IBUS_KEY_KP_Delete, self_handle_delete} - , + {IBUS_KEY_KP_Delete, IBUS_KEY_KP_Delete, self_handle_delete}, - {IBUS_KEY_Escape, IBUS_KEY_Escape, self_handle_escape} - , + {IBUS_KEY_Escape, IBUS_KEY_Escape, self_handle_escape}, - {IBUS_KEY_Left, IBUS_KEY_Left, self_handle_left} - , + {IBUS_KEY_Left, IBUS_KEY_Left, self_handle_left}, - {IBUS_KEY_KP_Left, IBUS_KEY_KP_Left, self_handle_left} - , + {IBUS_KEY_KP_Left, IBUS_KEY_KP_Left, self_handle_left}, - {IBUS_KEY_Up, IBUS_KEY_Up, self_handle_up} - , + {IBUS_KEY_Up, IBUS_KEY_Up, self_handle_up}, - {IBUS_KEY_KP_Up, IBUS_KEY_KP_Up, self_handle_up} - , + {IBUS_KEY_KP_Up, IBUS_KEY_KP_Up, self_handle_up}, - {IBUS_KEY_Right, IBUS_KEY_Right, self_handle_right} - , + {IBUS_KEY_Right, IBUS_KEY_Right, self_handle_right}, - {IBUS_KEY_KP_Right, IBUS_KEY_KP_Right, self_handle_right} - , + {IBUS_KEY_KP_Right, IBUS_KEY_KP_Right, self_handle_right}, - {IBUS_KEY_Down, IBUS_KEY_Down, self_handle_down} - , + {IBUS_KEY_Down, IBUS_KEY_Down, self_handle_down}, - {IBUS_KEY_KP_Down, IBUS_KEY_KP_Down, self_handle_down} - , + {IBUS_KEY_KP_Down, IBUS_KEY_KP_Down, self_handle_down}, - {IBUS_KEY_Page_Up, IBUS_KEY_Page_Up, self_handle_page_up} - , + {IBUS_KEY_Page_Up, IBUS_KEY_Page_Up, self_handle_page_up}, - {IBUS_KEY_KP_Page_Up, IBUS_KEY_KP_Page_Up, self_handle_page_up} - , + {IBUS_KEY_KP_Page_Up, IBUS_KEY_KP_Page_Up, self_handle_page_up}, - {IBUS_KEY_Page_Down, IBUS_KEY_Page_Down, self_handle_page_down} - , + {IBUS_KEY_Page_Down, IBUS_KEY_Page_Down, self_handle_page_down}, - {IBUS_KEY_KP_Page_Down, IBUS_KEY_KP_Page_Down, self_handle_page_down} - , + {IBUS_KEY_KP_Page_Down, IBUS_KEY_KP_Page_Down, self_handle_page_down}, - {IBUS_KEY_Tab, IBUS_KEY_Tab, self_handle_tab} - , + {IBUS_KEY_Tab, IBUS_KEY_Tab, self_handle_tab}, - {IBUS_KEY_Home, IBUS_KEY_Home, self_handle_home} - , + {IBUS_KEY_Home, IBUS_KEY_Home, self_handle_home}, - {IBUS_KEY_KP_Home, IBUS_KEY_KP_Home, self_handle_home} - , + {IBUS_KEY_KP_Home, IBUS_KEY_KP_Home, self_handle_home}, - {IBUS_KEY_End, IBUS_KEY_End, self_handle_end} - , + {IBUS_KEY_End, IBUS_KEY_End, self_handle_end}, - {IBUS_KEY_KP_End, IBUS_KEY_KP_End, self_handle_end} - , + {IBUS_KEY_KP_End, IBUS_KEY_KP_End, self_handle_end}, - {IBUS_KP_Multiply, IBUS_KP_Divide, self_handle_num_keypad} - , + {IBUS_KP_Multiply, IBUS_KP_Divide, self_handle_num_keypad}, - {32, 127, self_handle_default} - , + {32, 127, self_handle_default}, /* we need only printable ascii characters (32~127) and keys * like enter, esc, backspace ... etc. The rest can be ignored. */ - {0, G_MAXUINT, self_handle_special} - , + {0, G_MAXUINT, self_handle_special}, }; -static KeyHandlingRule *self_key_sym_find_key_handling_rule(KSym kSym) -{ +static KeyHandlingRule *self_key_sym_find_key_handling_rule(KSym kSym) { gint i; for (i = 0; keyHandlingRules[i].kSymLower != 0; i++) { @@ -906,21 +841,25 @@ static KeyHandlingRule *self_key_sym_find_key_handling_rule(KSym kSym) return &(keyHandlingRules[i]); } -#define handle_key(kSym, unmaskedMod) (self_key_sym_find_key_handling_rule(kSym))->keyFunc(self, kSym, unmaskedMod) - -#define process_key_debug(prompt) IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_pre_edit_process_key(): %s flags=%x buff_check=%d bpmf_check=%d cursor=%d total_choice=%d is_chinese=%d is_full_shape=%d is_plain_zhuyin=%d" ,\ - prompt, self->flags, chewing_buffer_Check(self->context),\ - bpmf_check, cursor_current, total_choice, is_chinese, is_full_shape, is_plain_zhuyin) +#define handle_key(kSym, unmaskedMod) \ + (self_key_sym_find_key_handling_rule(kSym)) \ + ->keyFunc(self, kSym, unmaskedMod) +#define process_key_debug(prompt) \ + IBUS_CHEWING_LOG(DEBUG, \ + "ibus_chewing_pre_edit_process_key(): %s flags=%x " \ + "buff_check=%d bpmf_check=%d cursor=%d total_choice=%d " \ + "is_chinese=%d is_full_shape=%d is_plain_zhuyin=%d", \ + prompt, self->flags, chewing_buffer_Check(self->context), \ + bpmf_check, cursor_current, total_choice, is_chinese, \ + is_full_shape, is_plain_zhuyin) /* keyCode should be converted to kSym already */ -gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit * self, KSym kSym, - KeyModifiers unmaskedMod) -{ - IBUS_CHEWING_LOG(INFO, - "***** ibus_chewing_pre_edit_process_key(-,%x(%s),%x(%s))", - kSym, key_sym_get_name(kSym), - unmaskedMod, modifiers_to_string(unmaskedMod)); +gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod) { + IBUS_CHEWING_LOG( + INFO, "***** ibus_chewing_pre_edit_process_key(-,%x(%s),%x(%s))", kSym, + key_sym_get_name(kSym), unmaskedMod, modifiers_to_string(unmaskedMod)); process_key_debug("Before response"); /* Find corresponding rule */ @@ -928,8 +867,7 @@ gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit * self, KSym kSym, response = handle_key(kSym, unmaskedMod); - IBUS_CHEWING_LOG(DEBUG, - "ibus_chewing_pre_edit_process_key() response=%x", + IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_pre_edit_process_key() response=%x", response); process_key_debug("After response"); self->keyLast = kSym; @@ -942,11 +880,11 @@ gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit * self, KSym kSym, break; } - /** + /** *Plain zhuyin mode */ if (is_plain_zhuyin && !bpmf_check) { - /* libchewing functions are used here to skip the check + /* libchewing functions are used here to skip the check * that handle_key functions perform. */ if (kSym == IBUS_KEY_Escape) { @@ -974,9 +912,8 @@ gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit * self, KSym kSym, ibus_chewing_pre_edit_update(self); - guint candidateCount = - ibus_chewing_lookup_table_update(self->iTable, self->iProperties, - self->context); + guint candidateCount = ibus_chewing_lookup_table_update( + self->iTable, self->iProperties, self->context); IBUS_CHEWING_LOG(INFO, "ibus_chewing_pre_edit_process_key() candidateCount=%d", @@ -990,10 +927,9 @@ gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit * self, KSym kSym, return TRUE; } -KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit * self, +KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit *self, KSym keySym, guint keyCode, - KeyModifiers unmaskedMod) -{ + KeyModifiers unmaskedMod) { KSym kSym = keySym; if (!is_chinese) { @@ -1005,9 +941,8 @@ KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit * self, /* Use en_US keyboard layout */ /* ibus_keymap_lookup_key_sym treats keycode >= 256 */ /* as IBUS_VoidSymbol */ - kSym = - ibus_keymap_lookup_keysym(ibus_keymap_get("us"), keyCode, - unmaskedMod); + kSym = ibus_keymap_lookup_keysym(ibus_keymap_get("us"), keyCode, + unmaskedMod); if (kSym == IBUS_VoidSymbol) { /* Restore key_sym */ kSym = keySym; diff --git a/src/IBusChewingPreEdit.h b/src/IBusChewingPreEdit.h index a6df0a3..440bb87 100644 --- a/src/IBusChewingPreEdit.h +++ b/src/IBusChewingPreEdit.h @@ -16,7 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ /** @@ -29,31 +30,33 @@ * IBusChewingPreEdit is core of ibus-chewing. * It processes incoming key events and manage pre-edit and outgoing buffer. * - * IBusChewingEngine uses the pre-edit and outgoing buffer to show to the end user. + * IBusChewingEngine uses the pre-edit and outgoing buffer to show to the end + * user. */ #ifndef _IBUS_CHEWING_PRE_EDIT_H_ -# define _IBUS_CHEWING_PRE_EDIT_H_ -# include -# include -# include -# include "MakerDialogBackend.h" -# include "IBusChewingUtil.h" -# include "IBusChewingLookupTable.h" -# include "IBusChewingProperties.h" - -# define UTF8_MAX_BYTES 4 -# ifndef IBUS_CHEWING_MAX_WORD -# define IBUS_CHEWING_MAX_WORD 100 -# endif -# define IBUS_CHEWING_MAX_BYTES UTF8_MAX_BYTES * IBUS_CHEWING_MAX_WORD +#define _IBUS_CHEWING_PRE_EDIT_H_ +#include "IBusChewingLookupTable.h" +#include "IBusChewingProperties.h" +#include "IBusChewingUtil.h" +#include "MakerDialogBackend.h" +#include +#include +#include + +#define UTF8_MAX_BYTES 4 +#ifndef IBUS_CHEWING_MAX_WORD +#define IBUS_CHEWING_MAX_WORD 100 +#endif +#define IBUS_CHEWING_MAX_BYTES UTF8_MAX_BYTES *IBUS_CHEWING_MAX_WORD /** * IBusChewingPreEditFlag: * @FLAG_SYNC_FROM_IM: Sync the Chinese mode with input method * @FLAG_SYNC_FROM_KEYBOARD: Sync the Chinese mode with Caps Lock status * @FLAG_TABLE_SHOW: Lookup table is shown. - * @FLAG_UPDATED_OUTGOING: The commit string is already send to outgoing, to avoid double committing. + * @FLAG_UPDATED_OUTGOING: The commit string is already send to outgoing, to + * avoid double committing. * */ typedef enum { @@ -67,7 +70,8 @@ typedef enum { * IBusChewingPreEdit: * @context: chewing input context. * @preEdit: String that are not ready to be committed to engine. - * @outgoing: String to be committed to engine. (Usually means completed string). + * @outgoing: String to be committed to engine. (Usually means completed + * string). * @flags: Misc flags. * @keyLast: Last effective key. * @bpmfLen: Length of bopomofo chars in unicode characters. @@ -90,55 +94,93 @@ typedef struct { IBusEngine *engine; } IBusChewingPreEdit; -IBusChewingPreEdit *ibus_chewing_pre_edit_new(MkdgBackend * backend); +IBusChewingPreEdit *ibus_chewing_pre_edit_new(MkdgBackend *backend); -void ibus_chewing_pre_edit_free(IBusChewingPreEdit * self); +void ibus_chewing_pre_edit_free(IBusChewingPreEdit *self); -# define ibus_chewing_pre_edit_get_property(self,propertyKey) mkdg_properties_find_by_key(self->iProperties->properties, propertyKey) +#define ibus_chewing_pre_edit_get_property(self, propertyKey) \ + mkdg_properties_find_by_key(self->iProperties->properties, propertyKey) -# define ibus_chewing_pre_edit_get_property_boolean(self,propertyKey) mkdg_properties_get_boolean_by_key(self->iProperties->properties, propertyKey) +#define ibus_chewing_pre_edit_get_property_boolean(self, propertyKey) \ + mkdg_properties_get_boolean_by_key(self->iProperties->properties, \ + propertyKey) -# define ibus_chewing_pre_edit_get_property_int(self,propertyKey) mkdg_properties_get_int_by_key(self->iProperties->properties, propertyKey) +#define ibus_chewing_pre_edit_get_property_int(self, propertyKey) \ + mkdg_properties_get_int_by_key(self->iProperties->properties, propertyKey) -# define ibus_chewing_pre_edit_get_property_string(self,propertyKey) mkdg_properties_get_string_by_key(self->iProperties->properties, propertyKey) +#define ibus_chewing_pre_edit_get_property_string(self, propertyKey) \ + mkdg_properties_get_string_by_key(self->iProperties->properties, \ + propertyKey) -# define ibus_chewing_pre_edit_set_property_boolean(self,propertyKey,boolValue) mkdg_properties_set_boolean_by_key(self->iProperties->properties, propertyKey, boolValue) +#define ibus_chewing_pre_edit_set_property_boolean(self, propertyKey, \ + boolValue) \ + mkdg_properties_set_boolean_by_key(self->iProperties->properties, \ + propertyKey, boolValue) -# define ibus_chewing_pre_edit_set_property_int(self,propertyKey,intValue) mkdg_properties_set_int_by_key(self->iProperties->properties, propertyKey, intValue) +#define ibus_chewing_pre_edit_set_property_int(self, propertyKey, intValue) \ + mkdg_properties_set_int_by_key(self->iProperties->properties, propertyKey, \ + intValue) -# define ibus_chewing_pre_edit_set_property_string(self,propertyKey,strValue) mkdg_properties_set_string_by_key(self->iProperties->properties,propertyKey,strValue) +#define ibus_chewing_pre_edit_set_property_string(self, propertyKey, strValue) \ + mkdg_properties_set_string_by_key(self->iProperties->properties, \ + propertyKey, strValue) -# define ibus_chewing_pre_edit_is_system_keyboard_layout(self) ibus_chewing_properties_read_boolean_general(self->iProperties, "ibus/general", "use-system-keyboard-layout", NULL) +#define ibus_chewing_pre_edit_is_system_keyboard_layout(self) \ + ibus_chewing_properties_read_boolean_general( \ + self->iProperties, "ibus/general", "use-system-keyboard-layout", NULL) -# define ibus_chewing_pre_edit_is_vertical_table(self) mkdg_properties_get_boolean_by_key(self->iProperties->properties, "vertical-lookup-table") +#define ibus_chewing_pre_edit_is_vertical_table(self) \ + mkdg_properties_get_boolean_by_key(self->iProperties->properties, \ + "vertical-lookup-table") -# define ibus_chewing_pre_edit_apply_property(self,propertyKey) mkdg_properties_apply_by_key(self->iProperties->properties, propertyKey, NULL) +#define ibus_chewing_pre_edit_apply_property(self, propertyKey) \ + mkdg_properties_apply_by_key(self->iProperties->properties, propertyKey, \ + NULL) -# define ibus_chewing_pre_edit_save_property_boolean(self,propertyKey,boolValue) mkdg_properties_save_boolean_by_key(self->iProperties->properties, propertyKey, boolValue, NULL) +#define ibus_chewing_pre_edit_save_property_boolean(self, propertyKey, \ + boolValue) \ + mkdg_properties_save_boolean_by_key(self->iProperties->properties, \ + propertyKey, boolValue, NULL) -# define ibus_chewing_pre_edit_save_property_int(self,propertyKey,intValue) mkdg_properties_save_int_by_key(self->iProperties->properties, propertyKey, intValue, NULL) +#define ibus_chewing_pre_edit_save_property_int(self, propertyKey, intValue) \ + mkdg_properties_save_int_by_key(self->iProperties->properties, \ + propertyKey, intValue, NULL) -# define ibus_chewing_pre_edit_save_property_string(self,propertyKey,strValue) mkdg_properties_save_string_by_key(self->iProperties->properties,propertyKey,strValue, NULL) +#define ibus_chewing_pre_edit_save_property_string(self, propertyKey, \ + strValue) \ + mkdg_properties_save_string_by_key(self->iProperties->properties, \ + propertyKey, strValue, NULL) -# define ibus_chewing_pre_edit_set_apply_property_boolean(self, propertyKey,boolValue) ibus_chewing_pre_edit_set_property_boolean(self,propertyKey,boolValue); ibus_chewing_pre_edit_apply_property(self,propertyKey) +#define ibus_chewing_pre_edit_set_apply_property_boolean(self, propertyKey, \ + boolValue) \ + ibus_chewing_pre_edit_set_property_boolean(self, propertyKey, boolValue); \ + ibus_chewing_pre_edit_apply_property(self, propertyKey) -# define ibus_chewing_pre_edit_set_apply_property_int(self, propertyKey,intValue) ibus_chewing_pre_edit_set_property_int(self,propertyKey,intValue); ibus_chewing_pre_edit_apply_property(self,propertyKey) +#define ibus_chewing_pre_edit_set_apply_property_int(self, propertyKey, \ + intValue) \ + ibus_chewing_pre_edit_set_property_int(self, propertyKey, intValue); \ + ibus_chewing_pre_edit_apply_property(self, propertyKey) -# define ibus_chewing_pre_edit_set_apply_property_string(self, propertyKey,stringValue) ibus_chewing_pre_edit_set_property_string(self,propertyKey,stringValue); ibus_chewing_pre_edit_apply_property(self,propertyKey) +#define ibus_chewing_pre_edit_set_apply_property_string(self, propertyKey, \ + stringValue) \ + ibus_chewing_pre_edit_set_property_string(self, propertyKey, stringValue); \ + ibus_chewing_pre_edit_apply_property(self, propertyKey) -void ibus_chewing_pre_edit_use_all_configure(IBusChewingPreEdit * self); +void ibus_chewing_pre_edit_use_all_configure(IBusChewingPreEdit *self); -guint ibus_chewing_pre_edit_length(IBusChewingPreEdit * self); +guint ibus_chewing_pre_edit_length(IBusChewingPreEdit *self); -guint ibus_chewing_pre_edit_word_length(IBusChewingPreEdit * self); +guint ibus_chewing_pre_edit_word_length(IBusChewingPreEdit *self); -guint ibus_chewing_pre_edit_word_limit(IBusChewingPreEdit * self); +guint ibus_chewing_pre_edit_word_limit(IBusChewingPreEdit *self); -# define ibus_chewing_pre_edit_is_empty(self) (ibus_chewing_pre_edit_length(self) ==0) +#define ibus_chewing_pre_edit_is_empty(self) \ + (ibus_chewing_pre_edit_length(self) == 0) -# define ibus_chewing_pre_edit_is_full(self) (self->wordLen >= ibus_chewing_pre_edit_word_limit(self)) +#define ibus_chewing_pre_edit_is_full(self) \ + (self->wordLen >= ibus_chewing_pre_edit_word_limit(self)) -# define ibus_chewing_pre_edit_is_outgoing_empty(self) (self->outgoing->len==0) +#define ibus_chewing_pre_edit_is_outgoing_empty(self) (self->outgoing->len == 0) /** * ibus_chewing_pre_edit_get_pre_edit: @@ -148,7 +190,7 @@ guint ibus_chewing_pre_edit_word_limit(IBusChewingPreEdit * self); * Return the content of pre-edit buffer in UTF-8 encoded string format. * No need to free it. */ -gchar *ibus_chewing_pre_edit_get_pre_edit(IBusChewingPreEdit * self); +gchar *ibus_chewing_pre_edit_get_pre_edit(IBusChewingPreEdit *self); /** * ibus_chewing_pre_edit_get_outgoing: @@ -158,39 +200,43 @@ gchar *ibus_chewing_pre_edit_get_pre_edit(IBusChewingPreEdit * self); * Return the content of outgoing buffer in UTF-8 encoded string format. * No need to free it. */ -gchar *ibus_chewing_pre_edit_get_outgoing(IBusChewingPreEdit * self); +gchar *ibus_chewing_pre_edit_get_outgoing(IBusChewingPreEdit *self); -# define ibus_chewing_pre_edit_has_flag(self,f) mkdg_has_flag(self->flags,f) -# define ibus_chewing_pre_edit_set_flag(self,f) mkdg_set_flag(self->flags,f) -# define ibus_chewing_pre_edit_clear_flag(self,f) mkdg_clear_flag(self->flags,f) +#define ibus_chewing_pre_edit_has_flag(self, f) mkdg_has_flag(self->flags, f) +#define ibus_chewing_pre_edit_set_flag(self, f) mkdg_set_flag(self->flags, f) +#define ibus_chewing_pre_edit_clear_flag(self, f) \ + mkdg_clear_flag(self->flags, f) -void ibus_chewing_pre_edit_force_commit(IBusChewingPreEdit * self); -void ibus_chewing_pre_edit_clear(IBusChewingPreEdit * self); -void ibus_chewing_pre_edit_clear_bopomofo(IBusChewingPreEdit * self); -void ibus_chewing_pre_edit_clear_pre_edit(IBusChewingPreEdit * self); -void ibus_chewing_pre_edit_clear_outgoing(IBusChewingPreEdit * self); +void ibus_chewing_pre_edit_force_commit(IBusChewingPreEdit *self); +void ibus_chewing_pre_edit_clear(IBusChewingPreEdit *self); +void ibus_chewing_pre_edit_clear_bopomofo(IBusChewingPreEdit *self); +void ibus_chewing_pre_edit_clear_pre_edit(IBusChewingPreEdit *self); +void ibus_chewing_pre_edit_clear_outgoing(IBusChewingPreEdit *self); -gboolean ibus_chewing_pre_edit_get_chi_eng_mode(IBusChewingPreEdit * self); -gboolean ibus_chewing_pre_edit_get_full_half_mode(IBusChewingPreEdit * self); +gboolean ibus_chewing_pre_edit_get_chi_eng_mode(IBusChewingPreEdit *self); +gboolean ibus_chewing_pre_edit_get_full_half_mode(IBusChewingPreEdit *self); -void ibus_chewing_pre_edit_set_chi_eng_mode(IBusChewingPreEdit * self, +void ibus_chewing_pre_edit_set_chi_eng_mode(IBusChewingPreEdit *self, gboolean chineseMode); -void ibus_chewing_pre_edit_set_full_half_mode(IBusChewingPreEdit * self, +void ibus_chewing_pre_edit_set_full_half_mode(IBusChewingPreEdit *self, gboolean fullShapeMode); -# define ibus_chewing_pre_edit_toggle_chi_eng_mode(self) ibus_chewing_pre_edit_set_chi_eng_mode(self, !ibus_chewing_pre_edit_get_chi_eng_mode(self)) -# define ibus_chewing_pre_edit_toggle_full_half_mode(self) ibus_chewing_pre_edit_set_full_half_mode(self, !ibus_chewing_pre_edit_get_full_half_mode(self)) - -gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit * self, - KSym kSym, KeyModifiers unmaskedMod); +#define ibus_chewing_pre_edit_toggle_chi_eng_mode(self) \ + ibus_chewing_pre_edit_set_chi_eng_mode( \ + self, !ibus_chewing_pre_edit_get_chi_eng_mode(self)) +#define ibus_chewing_pre_edit_toggle_full_half_mode(self) \ + ibus_chewing_pre_edit_set_full_half_mode( \ + self, !ibus_chewing_pre_edit_get_full_half_mode(self)) +gboolean ibus_chewing_pre_edit_process_key(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod); /** * ibus_chewing_pre_edit_key_code_to_key_sym: * * Convert keycode to key_sym. */ -KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit * self, +KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit *self, KSym keySym, guint keyCode, KeyModifiers unmaskedMod); @@ -199,22 +245,23 @@ KSym ibus_chewing_pre_edit_key_code_to_key_sym(IBusChewingPreEdit * self, * @returns: 1 if bopomofo buffer is non-empty; 0 if bopomofo buffer is empty. * */ -# if CHEWING_CHECK_VERSION(0,4,0) -# define ibus_chewing_bopomofo_check chewing_bopomofo_Check -# else -# define ibus_chewing_bopomofo_check !chewing_zuin_Check -# endif -gchar *ibus_chewing_pre_edit_get_bopomofo_string(IBusChewingPreEdit * self); +#if CHEWING_CHECK_VERSION(0, 4, 0) +#define ibus_chewing_bopomofo_check chewing_bopomofo_Check +#else +#define ibus_chewing_bopomofo_check !chewing_zuin_Check +#endif +gchar *ibus_chewing_pre_edit_get_bopomofo_string(IBusChewingPreEdit *self); typedef enum { EVENT_RESPONSE_PROCESS = 0, /* Event process by IM */ - EVENT_RESPONSE_ABSORB, /* Event throw away by IM (e.g. Release event) */ - EVENT_RESPONSE_IGNORE, /* Event that should be passed to application, but not process by IM */ + EVENT_RESPONSE_ABSORB, /* Event throw away by IM (e.g. Release event) */ + EVENT_RESPONSE_IGNORE, /* Event that should be passed to application, but + not process by IM */ EVENT_RESPONSE_UNDECIDED, } EventResponse; -typedef EventResponse(*KeyHandlingFunc) (IBusChewingPreEdit * self, - KSym kSym, KeyModifiers unmaskedMod); +typedef EventResponse (*KeyHandlingFunc)(IBusChewingPreEdit *self, KSym kSym, + KeyModifiers unmaskedMod); typedef struct { KSym kSymLower; @@ -222,5 +269,4 @@ typedef struct { KeyHandlingFunc keyFunc; } KeyHandlingRule; - -#endif /* _IBUS_CHEWING_PRE_EDIT_H_ */ +#endif /* _IBUS_CHEWING_PRE_EDIT_H_ */ diff --git a/src/IBusChewingProperties.c b/src/IBusChewingProperties.c index d2ce8ba..f466df4 100644 --- a/src/IBusChewingProperties.c +++ b/src/IBusChewingProperties.c @@ -1,253 +1,168 @@ #define GETTEXT_PACKAGE "gtk30" -#include -#include -#include "MakerDialogUtil.h" -#include "MakerDialogProperty.h" -#include "IBusChewingUtil.h" #include "IBusChewingProperties.h" #include "GSettingsBackend.h" +#include "IBusChewingUtil.h" +#include "MakerDialogProperty.h" +#include "MakerDialogUtil.h" +#include +#include -#define PAGE_EDITING N_("Editing") -#define PAGE_SELECTING N_("Selecting") -#define PAGE_KEYBOARD N_("Keyboard") - -const gchar *kbType_ids[] = { - N_("default"), - N_("hsu"), - N_("ibm"), - N_("gin_yieh"), - N_("eten"), - N_("eten26"), - N_("dvorak"), - N_("dvorak_hsu"), - N_("dachen_26"), - N_("hanyu"), -#if CHEWING_CHECK_VERSION(0,3,4) - N_("thl_pinying"), - N_("mps2_pinyin"), +#define PAGE_EDITING N_("Editing") +#define PAGE_SELECTING N_("Selecting") +#define PAGE_KEYBOARD N_("Keyboard") + +const gchar *kbType_ids[] = {N_("default"), + N_("hsu"), + N_("ibm"), + N_("gin_yieh"), + N_("eten"), + N_("eten26"), + N_("dvorak"), + N_("dvorak_hsu"), + N_("dachen_26"), + N_("hanyu"), +#if CHEWING_CHECK_VERSION(0, 3, 4) + N_("thl_pinying"), + N_("mps2_pinyin"), #endif - NULL -}; + NULL}; #define SELKEYS_ARRAY_SIZE 8 const gchar *selKeys_array[SELKEYS_ARRAY_SIZE + 1] = { - "1234567890", - "asdfghjkl;", - "asdfzxcv89", - "asdfjkl789", - "aoeu;qjkix", /* Dvorak */ + "1234567890", "asdfghjkl;", "asdfzxcv89", + "asdfjkl789", "aoeu;qjkix", /* Dvorak */ "aoeuhtnsid", /* Dvorak */ "aoeuidhtns", /* Dvorak */ - "1234qweras", - NULL -}; + "1234qweras", NULL}; const gchar *propDefaultEnglishLettercase_array[] = { - N_("no default"), - N_("lowercase"), - N_("uppercase"), - NULL -}; + N_("no default"), N_("lowercase"), N_("uppercase"), NULL}; -const gchar *syncCapsLock_strs[] = { - NC_("Sync", "disable"), - NC_("Sync", "keyboard"), - NC_("Sync", "input method"), - NULL -}; +const gchar *syncCapsLock_strs[] = {NC_("Sync", "disable"), + NC_("Sync", "keyboard"), + NC_("Sync", "input method"), NULL}; -const gchar *outputCharsets[] = { - N_("Auto"), - N_("Big5"), - N_("UTF8"), - NULL -}; +const gchar *outputCharsets[] = {N_("Auto"), N_("Big5"), N_("UTF8"), NULL}; -const gchar *chiEngToggle[] = { - N_("caps_lock"), - N_("shift"), - N_("shift_l"), - N_("shift_r"), - NULL -}; +const gchar *chiEngToggle[] = {N_("caps_lock"), N_("shift"), N_("shift_l"), + N_("shift_r"), NULL}; MkdgPropertySpec propSpecs[] = { {G_TYPE_STRING, "kb-type", PAGE_KEYBOARD, N_("Keyboard Type"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "default", kbType_ids, NULL, 0, 0, KBType_apply_callback, MKDG_PROPERTY_FLAG_NO_NEW | MKDG_PROPERTY_FLAG_HAS_TRANSLATION, - N_("Select Zhuyin keyboard layout"), NULL} - , + N_("Select Zhuyin keyboard layout"), NULL}, {G_TYPE_STRING, "sel-keys", PAGE_KEYBOARD, N_("Selection keys"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, "1234567890", selKeys_array, NULL, - 0, - 0, - selKeys_apply_callback, - MKDG_PROPERTY_FLAG_NO_NEW, - N_ - ("Keys used to select candidate. For example \"asdfghjkl;\", press 'a' to select the 1st candidate, 's' for 2nd, and so on."), - NULL} - , + IBUS_CHEWING_PROPERTIES_SUBSECTION, "1234567890", selKeys_array, NULL, 0, + 0, selKeys_apply_callback, MKDG_PROPERTY_FLAG_NO_NEW, + N_("Keys used to select candidate. For example \"asdfghjkl;\", press 'a' " + "to select the 1st candidate, 's' for 2nd, and so on."), + NULL}, /*== The callback will be handled in IBusChewingEngine.gob ==*/ - {G_TYPE_BOOLEAN, "show-systray", PAGE_KEYBOARD, - N_("Show systray icons"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, "1", NULL, NULL, 0, 1, - NULL, 0, - N_ - ("On: Show Chinese/English and Full/Half shape status as a systray icon\n" - "Off: Do not show the status icon"), NULL} - , - {G_TYPE_BOOLEAN, "auto-shift-cur", PAGE_EDITING, - N_("Auto move cursor"), + {G_TYPE_BOOLEAN, "show-systray", PAGE_KEYBOARD, N_("Show systray icons"), + IBUS_CHEWING_PROPERTIES_SUBSECTION, "1", NULL, NULL, 0, 1, NULL, 0, + N_("On: Show Chinese/English and Full/Half shape status as a systray " + "icon\n" + "Off: Do not show the status icon"), + NULL}, + {G_TYPE_BOOLEAN, "auto-shift-cur", PAGE_EDITING, N_("Auto move cursor"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "1", NULL, NULL, 0, 1, autoShiftCur_apply_callback, 0, - N_("Automatically move the cursor to the next character after selection"), NULL} - , + N_("Automatically move the cursor to the next character after selection"), + NULL}, {G_TYPE_BOOLEAN, "add-phrase-direction", PAGE_EDITING, - N_("Add phrase before the cursor"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, "1", NULL, NULL, 0, 1, - addPhraseDirection_apply_callback, 0, - N_("Use Ctrl + Numbers (2-9) to add new phrase before the cursor"), NULL} - , + N_("Add phrase before the cursor"), IBUS_CHEWING_PROPERTIES_SUBSECTION, + "1", NULL, NULL, 0, 1, addPhraseDirection_apply_callback, 0, + N_("Use Ctrl + Numbers (2-9) to add new phrase before the cursor"), NULL}, {G_TYPE_BOOLEAN, "clean-buffer-focus-out", PAGE_EDITING, N_("Clean pre-edit buffer when focus out"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, NULL, 0, 1, cleanBufferFocusOut_apply_callback, 0, - N_ - ("On: Clean pre-edit buffer when focus out to prevent program crash\n" - "Off: Keep what you already type for convenience"), NULL} - , - {G_TYPE_BOOLEAN, "easy-symbol-input", PAGE_EDITING, - N_("Easy symbol input"), + N_("On: Clean pre-edit buffer when focus out to prevent program crash\n" + "Off: Keep what you already type for convenience"), + NULL}, + {G_TYPE_BOOLEAN, "easy-symbol-input", PAGE_EDITING, N_("Easy symbol input"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "1", NULL, NULL, 0, 1, easySymbolInput_apply_callback, 0, - N_("Press shift to input Chinese punctuation symbols"), NULL} - , + N_("Press shift to input Chinese punctuation symbols"), NULL}, {G_TYPE_BOOLEAN, "esc-clean-all-buf", PAGE_EDITING, - N_("Esc clean all buffer"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, NULL, 0, 1, - escCleanAllBuf_apply_callback, 0, - N_("Escape key cleans the text in pre-edit-buffer"), NULL} - , + N_("Esc clean all buffer"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, + NULL, 0, 1, escCleanAllBuf_apply_callback, 0, + N_("Escape key cleans the text in pre-edit-buffer"), NULL}, {G_TYPE_INT, "max-chi-symbol-len", PAGE_EDITING, - N_("Maximum Chinese characters"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, "20", NULL, NULL, 11, 33, - maxChiSymbolLen_apply_callback, 0, - N_ - ("Maximum Chinese characters in pre-edit buffer, not including inputing Zhuyin symbols."), - NULL} - , - { - G_TYPE_STRING, - "chi-eng-mode-toggle", - PAGE_EDITING, + N_("Maximum Chinese characters"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "20", + NULL, NULL, 11, 33, maxChiSymbolLen_apply_callback, 0, + N_("Maximum Chinese characters in pre-edit buffer, not including inputing " + "Zhuyin symbols."), + NULL}, + {G_TYPE_STRING, "chi-eng-mode-toggle", PAGE_EDITING, N_("Chinese/Alphanumeric Mode Toggle Key"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, - "caps_lock", - chiEngToggle, - NULL, - 0, - 0, + IBUS_CHEWING_PROPERTIES_SUBSECTION, "caps_lock", chiEngToggle, NULL, 0, 0, chiEngToggle_apply_callback, - MKDG_PROPERTY_FLAG_NO_NEW | MKDG_PROPERTY_FLAG_HAS_TRANSLATION, - NULL, - NULL - } - , - { - G_TYPE_STRING, "default-english-case", PAGE_EDITING, + MKDG_PROPERTY_FLAG_NO_NEW | MKDG_PROPERTY_FLAG_HAS_TRANSLATION, NULL, + NULL}, + {G_TYPE_STRING, "default-english-case", PAGE_EDITING, N_("Default English letter case\n" "(Only effective when Caps Lock is the toggle key)"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "lowercase", propDefaultEnglishLettercase_array, NULL, 0, 1, defaultEnglishLetterCase_apply_callback, MKDG_PROPERTY_FLAG_NO_NEW | MKDG_PROPERTY_FLAG_HAS_TRANSLATION, - N_ - ("no control: No default letter case. Not recommend if you use multiple keyboards or synergy\n" - "lowercase: Default to lowercase, press shift for uppercase.\n" - "uppercase: Default to uppercase, press shift for lowercase."), - NULL} - , + N_("no control: No default letter case. Not recommend if you use multiple " + "keyboards or synergy\n" + "lowercase: Default to lowercase, press shift for uppercase.\n" + "uppercase: Default to uppercase, press shift for lowercase."), + NULL}, /* Sync between CapsLock and IM */ {G_TYPE_STRING, "sync-caps-lock", PAGE_EDITING, - N_("Sync between CapsLock and IM"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, "keyboard", syncCapsLock_strs, - "Sync", - 0, 1, - syncCapsLock_apply_callback, + N_("Sync between CapsLock and IM"), IBUS_CHEWING_PROPERTIES_SUBSECTION, + "keyboard", syncCapsLock_strs, "Sync", 0, 1, syncCapsLock_apply_callback, MKDG_PROPERTY_FLAG_NO_NEW | MKDG_PROPERTY_FLAG_HAS_TRANSLATION, - N_ - ("Occasionally, the CapsLock status does not match the IM, this option determines how these status be synchronized. Valid values:\n" - "\"disable\": Do nothing\n" - "\"keyboard\": IM status follows keyboard status\n" - "\"IM\": Keyboard status follows IM status"), NULL} - , - { - G_TYPE_BOOLEAN, "plain-zhuyin", PAGE_SELECTING, - N_("Plain Zhuyin mode"), + N_("Occasionally, the CapsLock status does not match the IM, this option " + "determines how these status be synchronized. Valid values:\n" + "\"disable\": Do nothing\n" + "\"keyboard\": IM status follows keyboard status\n" + "\"IM\": Keyboard status follows IM status"), + NULL}, + {G_TYPE_BOOLEAN, "plain-zhuyin", PAGE_SELECTING, N_("Plain Zhuyin mode"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, NULL, 0, 1, plainZhuyin_apply_callback, 0, - N_ - ("In plain Zhuyin mode, automatic candidate selection and related options are disabled or ignored."), - NULL} - , - { - G_TYPE_UINT, "cand-per-page", PAGE_SELECTING, - N_("Candidate per page"), + N_("In plain Zhuyin mode, automatic candidate selection and related " + "options are disabled or ignored."), + NULL}, + {G_TYPE_UINT, "cand-per-page", PAGE_SELECTING, N_("Candidate per page"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "5", NULL, NULL, 4, 10, - candPerPage_apply_callback, 0, - N_("Number of candidate per page."), - NULL} - , - { - G_TYPE_BOOLEAN, "show-page-number", PAGE_SELECTING, - N_("Show page number"), + candPerPage_apply_callback, 0, N_("Number of candidate per page."), NULL}, + {G_TYPE_BOOLEAN, "show-page-number", PAGE_SELECTING, N_("Show page number"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, NULL, 0, 1, showPageNumber_apply_callback, 0, - N_("Display the page number of the candidate list."), - NULL} - , - { - G_TYPE_BOOLEAN, "phrase-choice-from-last", PAGE_SELECTING, - N_("Choose phrases from backward"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, "1", NULL, NULL, 0, 1, - phraseChoiceRearward_apply_callback, 0, - N_("Open candidate list from the back of a phrase, without moving the cursor to the front."), - NULL} - , - { - G_TYPE_BOOLEAN, "space-as-selection", PAGE_SELECTING, - N_("Space to select"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, - "0", NULL, NULL, 0, 1, - spaceAsSelection_apply_callback, 0, - "Press Space to select the candidate.", - NULL} - , - { - G_TYPE_BOOLEAN, "vertical-lookup-table", PAGE_SELECTING, - N_("Vertical Lookup Table"), - IBUS_CHEWING_PROPERTIES_SUBSECTION, - "0", NULL, NULL, 0, 1, - verticalLookupTable_apply_callback, 0, - "Use vertical lookup table.", - NULL} - , - { - G_TYPE_INVALID, "", "", "", - IBUS_CHEWING_PROPERTIES_SUBSECTION, "", NULL, NULL, 0, 0, - NULL, 0, NULL, NULL} - , + N_("Display the page number of the candidate list."), NULL}, + {G_TYPE_BOOLEAN, "phrase-choice-from-last", PAGE_SELECTING, + N_("Choose phrases from backward"), IBUS_CHEWING_PROPERTIES_SUBSECTION, + "1", NULL, NULL, 0, 1, phraseChoiceRearward_apply_callback, 0, + N_("Open candidate list from the back of a phrase, without moving the " + "cursor to the front."), + NULL}, + {G_TYPE_BOOLEAN, "space-as-selection", PAGE_SELECTING, + N_("Space to select"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, NULL, + 0, 1, spaceAsSelection_apply_callback, 0, + "Press Space to select the candidate.", NULL}, + {G_TYPE_BOOLEAN, "vertical-lookup-table", PAGE_SELECTING, + N_("Vertical Lookup Table"), IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, + NULL, 0, 1, verticalLookupTable_apply_callback, 0, + "Use vertical lookup table.", NULL}, + {G_TYPE_INVALID, "", "", "", IBUS_CHEWING_PROPERTIES_SUBSECTION, "", NULL, + NULL, 0, 0, NULL, 0, NULL, NULL}, }; /*============================================ * Class methods */ -IBusChewingProperties *ibus_chewing_properties_new(MkdgBackend * backend, +IBusChewingProperties *ibus_chewing_properties_new(MkdgBackend *backend, gpointer parent, - gpointer auxData) -{ + gpointer auxData) { IBusChewingProperties *self = g_new0(IBusChewingProperties, 1); self->properties = @@ -258,8 +173,7 @@ IBusChewingProperties *ibus_chewing_properties_new(MkdgBackend * backend, return self; } -static GString *ibus_section_to_schema(const gchar * section) -{ +static GString *ibus_section_to_schema(const gchar *section) { GString *result = g_string_new("org.freedesktop"); gchar **strArr = g_strsplit(section, "/", -1); gint i; @@ -271,49 +185,42 @@ static GString *ibus_section_to_schema(const gchar * section) return result; } -GValue *ibus_chewing_properties_read_general(IBusChewingProperties * self, - GValue * value, - const gchar * section, - const gchar * key, - gpointer userData) -{ +GValue *ibus_chewing_properties_read_general(IBusChewingProperties *self, + GValue *value, + const gchar *section, + const gchar *key, + gpointer userData) { g_assert(self); g_assert(value); if (STRING_EQUALS(self->properties->backend->id, GSETTINGS_BACKEND_ID)) { GSettings *confObj; - if (!g_hash_table_contains(self->confObjTable, (gpointer) section)) { + if (!g_hash_table_contains(self->confObjTable, (gpointer)section)) { GString *schemaIdStr = ibus_section_to_schema(section); confObj = g_settings_new(schemaIdStr->str); - g_hash_table_insert(self->confObjTable, (gpointer) section, - (gpointer) confObj); + g_hash_table_insert(self->confObjTable, (gpointer)section, + (gpointer)confObj); g_string_free(schemaIdStr, TRUE); } else { - confObj = - (GSettings *) g_hash_table_lookup(self->confObjTable, - (gconstpointer) section); + confObj = (GSettings *)g_hash_table_lookup(self->confObjTable, + (gconstpointer)section); } g_assert(confObj); return mkdg_g_settings_read_value(confObj, value, key); } - return mkdg_backend_read(self->properties->backend, value, section, - key, userData); + return mkdg_backend_read(self->properties->backend, value, section, key, + userData); } -gboolean -ibus_chewing_properties_read_boolean_general(IBusChewingProperties - * self, - const gchar * - section, - const gchar * key, - gpointer userData) -{ - GValue gValue = { 0 }; +gboolean ibus_chewing_properties_read_boolean_general( + IBusChewingProperties *self, const gchar *section, const gchar *key, + gpointer userData) { + GValue gValue = {0}; g_value_init(&gValue, G_TYPE_BOOLEAN); ibus_chewing_properties_read_general(self, &gValue, section, key, userData); gboolean result = g_value_get_boolean(&gValue); g_value_unset(&gValue); return result; -} \ No newline at end of file +} diff --git a/src/IBusChewingProperties.h b/src/IBusChewingProperties.h index 304d22c..e59ec8b 100644 --- a/src/IBusChewingProperties.h +++ b/src/IBusChewingProperties.h @@ -1,9 +1,9 @@ #ifndef _IBUS_CHEWING_PROPERTIES_H_ -# define _IBUS_CHEWING_PROPERTIES_H_ -# include -# include -# include "MakerDialogProperty.h" -# include "MakerDialogBackend.h" +#define _IBUS_CHEWING_PROPERTIES_H_ +#include "MakerDialogBackend.h" +#include "MakerDialogProperty.h" +#include +#include typedef struct { MkdgProperties *properties; @@ -11,75 +11,71 @@ typedef struct { } IBusChewingProperties; /* GConf/dconf section under PROJECT_SCHEMA_BASE */ -# define IBUS_CHEWING_PROPERTIES_SUBSECTION QUOTE_ME(PROJECT_SCHEMA_SECTION) +#define IBUS_CHEWING_PROPERTIES_SUBSECTION QUOTE_ME(PROJECT_SCHEMA_SECTION) -IBusChewingProperties *ibus_chewing_properties_new(MkdgBackend * backend, +IBusChewingProperties *ibus_chewing_properties_new(MkdgBackend *backend, gpointer parent, gpointer auxData); -GValue *ibus_chewing_properties_read_general(IBusChewingProperties * self, - GValue * value, - const gchar * section, - const gchar * key, +GValue *ibus_chewing_properties_read_general(IBusChewingProperties *self, + GValue *value, + const gchar *section, + const gchar *key, gpointer userData); -gboolean ibus_chewing_properties_read_boolean_general(IBusChewingProperties - * self, - const gchar * - section, - const gchar * key, - gpointer userData); +gboolean ibus_chewing_properties_read_boolean_general( + IBusChewingProperties *self, const gchar *section, const gchar *key, + gpointer userData); /*============================================ * Callback functions */ -gboolean KBType_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean KBType_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean selKeys_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean selKeys_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean showSystray_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean showSystray_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean autoShiftCur_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean autoShiftCur_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean addPhraseDirection_apply_callback(PropertyContext * ctx, +gboolean addPhraseDirection_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean cleanBufferFocusOut_apply_callback(PropertyContext * ctx, +gboolean cleanBufferFocusOut_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean easySymbolInput_apply_callback(PropertyContext * ctx, +gboolean easySymbolInput_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean escCleanAllBuf_apply_callback(PropertyContext * ctx, - gpointer userData); +gboolean escCleanAllBuf_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean maxChiSymbolLen_apply_callback(PropertyContext * ctx, +gboolean maxChiSymbolLen_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean forceLowercaseEnglish_apply_callback(PropertyContext * ctx, +gboolean forceLowercaseEnglish_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean syncCapsLock_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean syncCapsLock_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean candPerPage_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean candPerPage_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean phraseChoiceRearward_apply_callback(PropertyContext * ctx, +gboolean phraseChoiceRearward_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean showPageNumber_apply_callback(PropertyContext * ctx, - gpointer userData); +gboolean showPageNumber_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean spaceAsSelection_apply_callback(PropertyContext * ctx, +gboolean spaceAsSelection_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean defaultEnglishLetterCase_apply_callback(PropertyContext * ctx, +gboolean defaultEnglishLetterCase_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean plainZhuyin_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean plainZhuyin_apply_callback(PropertyContext *ctx, gpointer userData); -gboolean verticalLookupTable_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean verticalLookupTable_apply_callback(PropertyContext *ctx, + gpointer userData); -gboolean chiEngToggle_apply_callback(PropertyContext * ctx, gpointer userData); +gboolean chiEngToggle_apply_callback(PropertyContext *ctx, gpointer userData); extern MkdgPropertySpec propSpecs[]; @@ -91,4 +87,4 @@ extern const gchar *syncCapsLock_strs[]; extern const gchar *outputCharsets[]; -#endif /* _IBUS_CHEWING_PROPERTIES_H_ */ +#endif /* _IBUS_CHEWING_PROPERTIES_H_ */ diff --git a/src/IBusChewingUtil.c b/src/IBusChewingUtil.c index 50ab800..6122a95 100644 --- a/src/IBusChewingUtil.c +++ b/src/IBusChewingUtil.c @@ -8,26 +8,23 @@ /*===================================== * Tone */ -const gchar *toneKeys[] = { - "6347", //Default - "jfds", //hsu - "uiop", //ibm - "zaq1", //gin-yieh - "4321", //eten - "kjfd", //eten26 - "6347", //dvorak - "thdn", //dvorak_hsu - "yert", //dachen_26 - "1234", //hanyu - NULL -}; +const gchar *toneKeys[] = {"6347", // Default + "jfds", // hsu + "uiop", // ibm + "zaq1", // gin-yieh + "4321", // eten + "kjfd", // eten26 + "6347", // dvorak + "thdn", // dvorak_hsu + "yert", // dachen_26 + "1234", // hanyu + NULL}; /*===================================== * Key */ -KSym key_sym_KP_to_normal(KSym k) -{ +KSym key_sym_KP_to_normal(KSym k) { if (k < IBUS_KP_0 || k > IBUS_KP_9) { switch (k) { case IBUS_KP_Multiply: @@ -49,20 +46,103 @@ KSym key_sym_KP_to_normal(KSym k) return k - IBUS_KP_0 + IBUS_0; } -const char asciiConst[] = - " \0" "!\0" "\"\0" "#\0" "$\0" "%\0" "&\0" "'\0" "(\0" ")\0" - "*\0" "+\0" ",\0" "-\0" ".\0" "/\0" "0\0" "1\0" "2\0" "3\0" - "4\0" "5\0" "6\0" "7\0" "8\0" "9\0" ":\0" ";\0" "<\0" "=\0" - ">\0" "?\0" "@\0" "A\0" "B\0" "C\0" "D\0" "E\0" "F\0" "G\0" - "H\0" "I\0" "J\0" "K\0" "L\0" "M\0" "N\0" "O\0" "P\0" "Q\0" - "R\0" "S\0" "T\0" "U\0" "V\0" "W\0" "X\0" "Y\0" "Z\0" "[\0" - "\\\0" "]\0" "^\0" "_\0" "`\0" "a\0" "b\0" "c\0" "d\0" "e\0" - "f\0" "g\0" "h\0" "i\0" "j\0" "k\0" "l\0" "m\0" "n\0" "o\0" - "p\0" "q\0" "r\0" "s\0" "t\0" "u\0" "v\0" "w\0" "x\0" "y\0" - "z\0" "{\0" "|\0" "}\0" "~\0"; +const char asciiConst[] = " \0" + "!\0" + "\"\0" + "#\0" + "$\0" + "%\0" + "&\0" + "'\0" + "(\0" + ")\0" + "*\0" + "+\0" + ",\0" + "-\0" + ".\0" + "/\0" + "0\0" + "1\0" + "2\0" + "3\0" + "4\0" + "5\0" + "6\0" + "7\0" + "8\0" + "9\0" + ":\0" + ";\0" + "<\0" + "=\0" + ">\0" + "?\0" + "@\0" + "A\0" + "B\0" + "C\0" + "D\0" + "E\0" + "F\0" + "G\0" + "H\0" + "I\0" + "J\0" + "K\0" + "L\0" + "M\0" + "N\0" + "O\0" + "P\0" + "Q\0" + "R\0" + "S\0" + "T\0" + "U\0" + "V\0" + "W\0" + "X\0" + "Y\0" + "Z\0" + "[\0" + "\\\0" + "]\0" + "^\0" + "_\0" + "`\0" + "a\0" + "b\0" + "c\0" + "d\0" + "e\0" + "f\0" + "g\0" + "h\0" + "i\0" + "j\0" + "k\0" + "l\0" + "m\0" + "n\0" + "o\0" + "p\0" + "q\0" + "r\0" + "s\0" + "t\0" + "u\0" + "v\0" + "w\0" + "x\0" + "y\0" + "z\0" + "{\0" + "|\0" + "}\0" + "~\0"; -const char *key_sym_get_name(KSym k) -{ +const char *key_sym_get_name(KSym k) { switch (k) { case 0: return ""; @@ -194,8 +274,7 @@ const char *key_sym_get_name(KSym k) * Modifiers */ -const gchar *modifier_get_string(guint modifier) -{ +const gchar *modifier_get_string(guint modifier) { switch (modifier) { case 0: return ""; @@ -234,8 +313,7 @@ const gchar *modifier_get_string(guint modifier) } #define MODIFIER_BUFFER_SIZE 100 -const gchar *modifiers_to_string(guint modifier) -{ +const gchar *modifiers_to_string(guint modifier) { static gchar modifierBuf[MODIFIER_BUFFER_SIZE]; g_strlcpy(modifierBuf, "", MODIFIER_BUFFER_SIZE); @@ -257,4 +335,4 @@ const gchar *modifiers_to_string(guint modifier) } } return modifierBuf; -} \ No newline at end of file +} diff --git a/src/IBusChewingUtil.h b/src/IBusChewingUtil.h index 835734c..a8a5c4a 100644 --- a/src/IBusChewingUtil.h +++ b/src/IBusChewingUtil.h @@ -16,30 +16,29 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ #ifndef _IBUS_CHEWING_UTIL_H_ -# define _IBUS_CHEWING_UTIL_H_ -# include -# include -# include -# include -# include +#define _IBUS_CHEWING_UTIL_H_ +#include +#include +#include +#include +#include -# define ZHUYIN_BUFFER_SIZE 12 +#define ZHUYIN_BUFFER_SIZE 12 -# define CHEWING_CHECK_VERSION(major,minor,patch) \ - (CHEWING_VERSION_MAJOR > (major) || \ - (CHEWING_VERSION_MAJOR == (major) && CHEWING_VERSION_MINOR > (minor)) || \ - (CHEWING_VERSION_MAJOR == (major) && CHEWING_VERSION_MINOR == (minor) && \ - CHEWING_VERSION_PATCH >= (patch) \ - )\ - ) +#define CHEWING_CHECK_VERSION(major, minor, patch) \ + (CHEWING_VERSION_MAJOR > (major) || \ + (CHEWING_VERSION_MAJOR == (major) && CHEWING_VERSION_MINOR > (minor)) || \ + (CHEWING_VERSION_MAJOR == (major) && CHEWING_VERSION_MINOR == (minor) && \ + CHEWING_VERSION_PATCH >= (patch))) -# define IBUS_CHEWING_LOG_DOMAIN "ibus-chewing" +#define IBUS_CHEWING_LOG_DOMAIN "ibus-chewing" -# define IBUS_CHEWING_LOG(level, msg, args...) \ +#define IBUS_CHEWING_LOG(level, msg, args...) \ mkdg_log_domain(IBUS_CHEWING_LOG_DOMAIN, level, msg, ##args) typedef guint KSym; @@ -58,10 +57,11 @@ typedef enum { CHEWING_KBTYPE_DVORAK_HSU, CHEWING_KBTYPE_DACHEN_CP26, CHEWING_KBTYPE_HAN_YU -# if CHEWING_CHECK_VERSION(0,3,4) - , CHEWING_KBTYPE_LUOMA_PINYIN, +#if CHEWING_CHECK_VERSION(0, 3, 4) + , + CHEWING_KBTYPE_LUOMA_PINYIN, CHEWING_KBTYPE_MSP2 -# endif +#endif } ChewingKbType; KSym key_sym_KP_to_normal(KSym k); @@ -72,4 +72,4 @@ const gchar *modifier_get_string(guint modifier); const gchar *modifiers_to_string(guint modifier); -#endif /* _IBUS_CHEWING_UTIL_H_ */ +#endif /* _IBUS_CHEWING_UTIL_H_ */ diff --git a/src/MakerDialogBackend.c b/src/MakerDialogBackend.c index fad3f86..7947c79 100644 --- a/src/MakerDialogBackend.c +++ b/src/MakerDialogBackend.c @@ -1,9 +1,8 @@ -#include "MakerDialogUtil.h" #include "MakerDialogBackend.h" +#include "MakerDialogUtil.h" -MkdgBackend *mkdg_backend_new(const gchar * id, gpointer config, - const gchar * basePath, gpointer auxData) -{ +MkdgBackend *mkdg_backend_new(const gchar *id, gpointer config, + const gchar *basePath, gpointer auxData) { g_assert(config); g_assert(!STRING_IS_EMPTY(id)); MkdgBackend *result = g_new0(MkdgBackend, 1); @@ -16,24 +15,19 @@ MkdgBackend *mkdg_backend_new(const gchar * id, gpointer config, return result; } -gchar *mkdg_backend_get_key(MkdgBackend * backend, - const gchar * section, const gchar * key, - gpointer userData) -{ +gchar *mkdg_backend_get_key(MkdgBackend *backend, const gchar *section, + const gchar *key, gpointer userData) { return backend->getKeyFunc(backend, section, key, userData); } - -GValue *mkdg_backend_read(MkdgBackend * backend, GValue * value, - const gchar * section, const gchar * key, - gpointer userData) -{ +GValue *mkdg_backend_read(MkdgBackend *backend, GValue *value, + const gchar *section, const gchar *key, + gpointer userData) { return backend->readFunc(backend, value, section, key, userData); } -gboolean mkdg_backend_write(MkdgBackend * backend, GValue * value, - const gchar * section, const gchar * key, - gpointer userData) -{ +gboolean mkdg_backend_write(MkdgBackend *backend, GValue *value, + const gchar *section, const gchar *key, + gpointer userData) { return backend->writeFunc(backend, value, section, key, userData); } diff --git a/src/MakerDialogBackend.h b/src/MakerDialogBackend.h index 33c5469..8d12d91 100644 --- a/src/MakerDialogBackend.h +++ b/src/MakerDialogBackend.h @@ -16,7 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ /** @@ -26,44 +27,43 @@ * @stability: Stable * @include: MakerDailogBackend.h * - * A MakerDialog backend provides an interface to configuration service like GConf2 or dconf + * A MakerDialog backend provides an interface to configuration service like + * GConf2 or dconf */ #ifndef _MAKER_DIALOG_BACKEND_H_ -# define _MAKER_DIALOG_BACKEND_H_ -# include -# include +#define _MAKER_DIALOG_BACKEND_H_ +#include +#include typedef struct MkdgBackend_ MkdgBackend; - /** * MkdgBackendFlag: - * @MKDG_BACKEND_FLAG_DISCONNECTED: Disconnect from backend, so the backend works without connect to real service. + * @MKDG_BACKEND_FLAG_DISCONNECTED: Disconnect from backend, so the backend + * works without connect to real service. * * MakerDialog backend flags. - * + * */ -typedef enum { - MKDG_BACKEND_FLAG_DISCONNECTED = 1 -} MkdgBackendFlag; +typedef enum { MKDG_BACKEND_FLAG_DISCONNECTED = 1 } MkdgBackendFlag; -typedef gchar *(*BackendGetKeyFunc) (MkdgBackend * backend, - const gchar * section, - const gchar * key, gpointer userData); +typedef gchar *(*BackendGetKeyFunc)(MkdgBackend *backend, const gchar *section, + const gchar *key, gpointer userData); -typedef GValue *(*BackendReadFunc) (MkdgBackend * backend, GValue * value, - const gchar * section, - const gchar * key, gpointer userData); +typedef GValue *(*BackendReadFunc)(MkdgBackend *backend, GValue *value, + const gchar *section, const gchar *key, + gpointer userData); -typedef gboolean(*BackendWriteFunc) (MkdgBackend * backend, GValue * value, - const gchar * section, - const gchar * key, gpointer userData); +typedef gboolean (*BackendWriteFunc)(MkdgBackend *backend, GValue *value, + const gchar *section, const gchar *key, + gpointer userData); /** * MkdgBackend: * @id: A string that identify the backend. * @config: A configuration service - * @basePath: All keys and sub-sections of this project should be put under this path (with trailing '/') + * @basePath: All keys and sub-sections of this project should be put under this + * path (with trailing '/') * @readFunc: Callback function for load * @writeFunc: Callback function for save * @auxData: Auxiliary data that might be useful. @@ -81,19 +81,18 @@ struct MkdgBackend_ { gpointer auxData; }; -MkdgBackend *mkdg_backend_new(const gchar * id, gpointer config, - const gchar * basePath, gpointer auxData); +MkdgBackend *mkdg_backend_new(const gchar *id, gpointer config, + const gchar *basePath, gpointer auxData); -gchar *mkdg_backend_get_key(MkdgBackend * backend, - const gchar * section, const gchar * key, - gpointer userData); +gchar *mkdg_backend_get_key(MkdgBackend *backend, const gchar *section, + const gchar *key, gpointer userData); -GValue *mkdg_backend_read(MkdgBackend * backend, GValue * value, - const gchar * section, const gchar * key, +GValue *mkdg_backend_read(MkdgBackend *backend, GValue *value, + const gchar *section, const gchar *key, gpointer userData); -gboolean mkdg_backend_write(MkdgBackend * backend, GValue * value, - const gchar * section, const gchar * key, +gboolean mkdg_backend_write(MkdgBackend *backend, GValue *value, + const gchar *section, const gchar *key, gpointer userData); -#endif /* _MAKER_DIALOG_BACKEND_H_ */ +#endif /* _MAKER_DIALOG_BACKEND_H_ */ diff --git a/src/MakerDialogProperty.c b/src/MakerDialogProperty.c index 1a55b91..d54af97 100644 --- a/src/MakerDialogProperty.c +++ b/src/MakerDialogProperty.c @@ -1,36 +1,35 @@ -#include -#include -#include "MakerDialogUtil.h" #include "MakerDialogProperty.h" +#include "MakerDialogUtil.h" +#include +#include /*============================================ * PropertyContext Methods */ -static gboolean property_context_from_string(PropertyContext * ctx, const gchar * str) -{ +static gboolean property_context_from_string(PropertyContext *ctx, + const gchar *str) { if (ctx == NULL) { return FALSE; } return mkdg_g_value_from_string(&(ctx->value), str); } -void property_context_default(PropertyContext * ctx) -{ +void property_context_default(PropertyContext *ctx) { mkdg_log(DEBUG, "property_context_default(%s)", ctx->spec->key); gboolean ret = property_context_from_string(ctx, ctx->spec->defaultValue); if (!ret) { mkdg_log(WARN, - "property_context_default(%s): failed to convert string %s, return NULL", + "property_context_default(%s): failed to convert string %s, " + "return NULL", ctx->spec->key, ctx->spec->defaultValue); } } -PropertyContext *property_context_new(MkdgPropertySpec * spec, - MkdgBackend * backend, - gpointer parent, gpointer auxData) -{ +PropertyContext *property_context_new(MkdgPropertySpec *spec, + MkdgBackend *backend, gpointer parent, + gpointer auxData) { if (spec == NULL) { return NULL; } @@ -64,21 +63,21 @@ PropertyContext *property_context_new(MkdgPropertySpec * spec, /* apply: Context -> apply callback */ /* use: load then apply */ /* assign: save then apply */ -GValue *property_context_read(PropertyContext * ctx, gpointer userData) -{ +GValue *property_context_read(PropertyContext *ctx, gpointer userData) { if (ctx == NULL) { return NULL; } mkdg_log(DEBUG, "property_context_read(%s,-)", ctx->spec->key); - if (mkdg_has_flag(ctx->spec->propertyFlags, MKDG_PROPERTY_FLAG_NO_BACKEND)) { + if (mkdg_has_flag(ctx->spec->propertyFlags, + MKDG_PROPERTY_FLAG_NO_BACKEND)) { return NULL; } if (ctx->backend == NULL) { return NULL; } - GValue *result = mkdg_backend_read(ctx->backend, &(ctx->value), - ctx->spec->subSection, - ctx->spec->key, userData); + GValue *result = + mkdg_backend_read(ctx->backend, &(ctx->value), ctx->spec->subSection, + ctx->spec->key, userData); if (result == NULL) { mkdg_log(WARN, "property_context_read(%s): failed to read key", @@ -87,13 +86,13 @@ GValue *property_context_read(PropertyContext * ctx, gpointer userData) return result; } -gboolean property_context_write(PropertyContext * ctx, gpointer userData) -{ +gboolean property_context_write(PropertyContext *ctx, gpointer userData) { if (ctx == NULL) { return FALSE; } mkdg_log(DEBUG, "property_context_read(%s,-)", ctx->spec->key); - if (mkdg_has_flag(ctx->spec->propertyFlags, MKDG_PROPERTY_FLAG_NO_BACKEND)) { + if (mkdg_has_flag(ctx->spec->propertyFlags, + MKDG_PROPERTY_FLAG_NO_BACKEND)) { return FALSE; } if (ctx->backend == NULL) { @@ -104,19 +103,17 @@ gboolean property_context_write(PropertyContext * ctx, gpointer userData) userData); } -GValue *property_context_get(PropertyContext * ctx) -{ +GValue *property_context_get(PropertyContext *ctx) { if (ctx == NULL) { mkdg_log(WARN, "property_context_get(-): ctx is NULL"); return NULL; } - mkdg_log(DEBUG, "property_context_get(%s): value=%s", - ctx->spec->key, mkdg_g_value_to_string(&(ctx->value))); + mkdg_log(DEBUG, "property_context_get(%s): value=%s", ctx->spec->key, + mkdg_g_value_to_string(&(ctx->value))); return &(ctx->value); } -gboolean property_context_set(PropertyContext * ctx, GValue * value) -{ +gboolean property_context_set(PropertyContext *ctx, GValue *value) { if (ctx == NULL) { mkdg_log(WARN, "property_context_set(-): ctx is NULL"); return FALSE; @@ -132,16 +129,14 @@ gboolean property_context_set(PropertyContext * ctx, GValue * value) return TRUE; } -GValue *property_context_load(PropertyContext * ctx, gpointer userData) -{ +GValue *property_context_load(PropertyContext *ctx, gpointer userData) { mkdg_log(DEBUG, "property_context_load(%s,-)", ctx->spec->key); property_context_read(ctx, userData); return property_context_get(ctx); } -gboolean property_context_save(PropertyContext * ctx, GValue * value, - gpointer userData) -{ +gboolean property_context_save(PropertyContext *ctx, GValue *value, + gpointer userData) { mkdg_log(DEBUG, "property_context_save(%s,-)", ctx->spec->key); if (!property_context_set(ctx, value)) { return FALSE; @@ -149,12 +144,12 @@ gboolean property_context_save(PropertyContext * ctx, GValue * value, return property_context_write(ctx, userData); } -gboolean property_context_apply(PropertyContext * ctx, gpointer userData) -{ +gboolean property_context_apply(PropertyContext *ctx, gpointer userData) { if (ctx == NULL || ctx->parent == NULL) { - mkdg_log(WARN, - "property_context_apply(%s): either ctx or ctx->parent is NULL", - ctx->spec->key); + mkdg_log( + WARN, + "property_context_apply(%s): either ctx or ctx->parent is NULL", + ctx->spec->key); return FALSE; } if (ctx->spec->applyFunc == NULL) { @@ -162,13 +157,12 @@ gboolean property_context_apply(PropertyContext * ctx, gpointer userData) ctx->spec->key); return TRUE; } - mkdg_log(DEBUG, "property_context_apply(%s,-): value %s", - ctx->spec->key, mkdg_g_value_to_string(&(ctx->value))); + mkdg_log(DEBUG, "property_context_apply(%s,-): value %s", ctx->spec->key, + mkdg_g_value_to_string(&(ctx->value))); return ctx->spec->applyFunc(ctx, userData); } -gboolean property_context_use(PropertyContext * ctx, gpointer userData) -{ +gboolean property_context_use(PropertyContext *ctx, gpointer userData) { mkdg_log(DEBUG, "property_context_use(%s,-)", ctx->spec->key); GValue *ret = property_context_load(ctx, userData); @@ -181,24 +175,21 @@ gboolean property_context_use(PropertyContext * ctx, gpointer userData) return property_context_apply(ctx, userData); } -void property_context_free(PropertyContext * ctx) -{ +void property_context_free(PropertyContext *ctx) { mkdg_log(INFO, "property_context_free(%s,-)", ctx->spec->key); g_value_unset(&(ctx->value)); g_free(ctx); } - /*============================================ * MkdgProperties Methods */ /* This alone is sufficient to generate schemas */ MkdgProperties *mkdg_properties_from_spec_array(MkdgPropertySpec specs[], - MkdgBackend * backend, + MkdgBackend *backend, gpointer parent, - gpointer auxData) -{ + gpointer auxData) { gsize arraySize = 0; gsize i; @@ -211,17 +202,16 @@ MkdgProperties *mkdg_properties_from_spec_array(MkdgPropertySpec specs[], result->contexts = g_ptr_array_sized_new(arraySize); result->auxData = auxData; for (i = 0; i < arraySize; i++) { - PropertyContext *ctx = property_context_new(&specs[i], backend, - parent, auxData); + PropertyContext *ctx = + property_context_new(&specs[i], backend, parent, auxData); - g_ptr_array_add(result->contexts, (gpointer) ctx); + g_ptr_array_add(result->contexts, (gpointer)ctx); } return result; } -PropertyContext *mkdg_properties_find_by_key(MkdgProperties * properties, - const gchar * key) -{ +PropertyContext *mkdg_properties_find_by_key(MkdgProperties *properties, + const gchar *key) { gsize i; for (i = 0; i < mkdg_properties_size(properties); i++) { @@ -234,15 +224,13 @@ PropertyContext *mkdg_properties_find_by_key(MkdgProperties * properties, return NULL; } -PropertyContext *mkdg_properties_index(MkdgProperties * properties, guint index) -{ - return (PropertyContext *) - g_ptr_array_index(properties->contexts, index); +PropertyContext *mkdg_properties_index(MkdgProperties *properties, + guint index) { + return (PropertyContext *)g_ptr_array_index(properties->contexts, index); } -GValue *mkdg_properties_get_by_key(MkdgProperties * properties, - const gchar * key) -{ +GValue *mkdg_properties_get_by_key(MkdgProperties *properties, + const gchar *key) { if (properties == NULL) { return NULL; } @@ -251,9 +239,8 @@ GValue *mkdg_properties_get_by_key(MkdgProperties * properties, return property_context_get(ctx); } -gboolean mkdg_properties_set_by_key(MkdgProperties * properties, - const gchar * key, GValue * value) -{ +gboolean mkdg_properties_set_by_key(MkdgProperties *properties, + const gchar *key, GValue *value) { if (properties == NULL) { return FALSE; } @@ -262,11 +249,10 @@ gboolean mkdg_properties_set_by_key(MkdgProperties * properties, return property_context_set(ctx, value); } -gboolean mkdg_properties_set_boolean_by_key(MkdgProperties * properties, - const gchar * key, - gboolean boolValue) -{ - GValue gValue = { 0 }; +gboolean mkdg_properties_set_boolean_by_key(MkdgProperties *properties, + const gchar *key, + gboolean boolValue) { + GValue gValue = {0}; g_value_init(&gValue, G_TYPE_BOOLEAN); g_value_set_boolean(&gValue, boolValue); gboolean result = mkdg_properties_set_by_key(properties, key, &gValue); @@ -275,10 +261,9 @@ gboolean mkdg_properties_set_boolean_by_key(MkdgProperties * properties, return result; } -gboolean mkdg_properties_set_int_by_key(MkdgProperties * properties, - const gchar * key, gint intValue) -{ - GValue gValue = { 0 }; +gboolean mkdg_properties_set_int_by_key(MkdgProperties *properties, + const gchar *key, gint intValue) { + GValue gValue = {0}; g_value_init(&gValue, G_TYPE_INT); g_value_set_int(&gValue, intValue); gboolean result = mkdg_properties_set_by_key(properties, key, &gValue); @@ -287,11 +272,10 @@ gboolean mkdg_properties_set_int_by_key(MkdgProperties * properties, return result; } -gboolean mkdg_properties_set_string_by_key(MkdgProperties * properties, - const gchar * key, - const gchar * stringValue) -{ - GValue gValue = { 0 }; +gboolean mkdg_properties_set_string_by_key(MkdgProperties *properties, + const gchar *key, + const gchar *stringValue) { + GValue gValue = {0}; g_value_init(&gValue, G_TYPE_STRING); g_value_set_string(&gValue, stringValue); gboolean result = mkdg_properties_set_by_key(properties, key, &gValue); @@ -300,9 +284,8 @@ gboolean mkdg_properties_set_string_by_key(MkdgProperties * properties, return result; } -GValue *mkdg_properties_load_by_key(MkdgProperties * properties, - const gchar * key, gpointer userData) -{ +GValue *mkdg_properties_load_by_key(MkdgProperties *properties, + const gchar *key, gpointer userData) { if (properties == NULL) { return NULL; } @@ -311,10 +294,9 @@ GValue *mkdg_properties_load_by_key(MkdgProperties * properties, return property_context_load(ctx, userData); } -gboolean mkdg_properties_save_by_key(MkdgProperties * properties, - const gchar * key, GValue * value, - gpointer userData) -{ +gboolean mkdg_properties_save_by_key(MkdgProperties *properties, + const gchar *key, GValue *value, + gpointer userData) { if (properties == NULL) { return FALSE; } @@ -323,12 +305,11 @@ gboolean mkdg_properties_save_by_key(MkdgProperties * properties, return property_context_save(ctx, value, userData); } -gboolean mkdg_properties_save_boolean_by_key(MkdgProperties * properties, - const gchar * key, +gboolean mkdg_properties_save_boolean_by_key(MkdgProperties *properties, + const gchar *key, gboolean boolValue, - gpointer userData) -{ - GValue gValue = { 0 }; + gpointer userData) { + GValue gValue = {0}; g_value_init(&gValue, G_TYPE_BOOLEAN); g_value_set_boolean(&gValue, boolValue); gboolean result = @@ -337,11 +318,10 @@ gboolean mkdg_properties_save_boolean_by_key(MkdgProperties * properties, return result; } -gboolean mkdg_properties_save_int_by_key(MkdgProperties * properties, - const gchar * key, gint intValue, - gpointer userData) -{ - GValue gValue = { 0 }; +gboolean mkdg_properties_save_int_by_key(MkdgProperties *properties, + const gchar *key, gint intValue, + gpointer userData) { + GValue gValue = {0}; g_value_init(&gValue, G_TYPE_INT); g_value_set_int(&gValue, intValue); gboolean result = @@ -350,12 +330,11 @@ gboolean mkdg_properties_save_int_by_key(MkdgProperties * properties, return result; } -gboolean mkdg_properties_save_string_by_key(MkdgProperties * properties, - const gchar * key, - const gchar * stringValue, - gpointer userData) -{ - GValue gValue = { 0 }; +gboolean mkdg_properties_save_string_by_key(MkdgProperties *properties, + const gchar *key, + const gchar *stringValue, + gpointer userData) { + GValue gValue = {0}; g_value_init(&gValue, G_TYPE_STRING); g_value_set_string(&gValue, stringValue); gboolean result = @@ -364,9 +343,8 @@ gboolean mkdg_properties_save_string_by_key(MkdgProperties * properties, return result; } -gboolean mkdg_properties_apply_by_key(MkdgProperties * properties, - const gchar * key, gpointer userData) -{ +gboolean mkdg_properties_apply_by_key(MkdgProperties *properties, + const gchar *key, gpointer userData) { if (properties == NULL) { return FALSE; } @@ -375,13 +353,12 @@ gboolean mkdg_properties_apply_by_key(MkdgProperties * properties, return property_context_apply(ctx, userData); } -gsize mkdg_properties_size(MkdgProperties * properties) -{ +gsize mkdg_properties_size(MkdgProperties *properties) { return properties->contexts->len; } -gboolean mkdg_properties_use_all(MkdgProperties * properties, gpointer userData) -{ +gboolean mkdg_properties_use_all(MkdgProperties *properties, + gpointer userData) { gsize i; gboolean result = TRUE; @@ -396,8 +373,7 @@ gboolean mkdg_properties_use_all(MkdgProperties * properties, gpointer userData) return result; } -void mkdg_properties_free(MkdgProperties * properties) -{ +void mkdg_properties_free(MkdgProperties *properties) { gsize i; for (i = 0; i < mkdg_properties_size(properties); i++) { diff --git a/src/MakerDialogProperty.h b/src/MakerDialogProperty.h index 20ed1c2..fb9cbaa 100644 --- a/src/MakerDialogProperty.h +++ b/src/MakerDialogProperty.h @@ -16,7 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ /** @@ -30,18 +31,19 @@ */ #ifndef _MAKER_DIALOG_PROPERTY_H_ -# define _MAKER_DIALOG_PROPERTY_H_ -# include -# include -# include "MakerDialogUtil.h" -# include "MakerDialogPropertySpec.h" -# include "MakerDialogBackend.h" +#define _MAKER_DIALOG_PROPERTY_H_ +#include "MakerDialogBackend.h" +#include "MakerDialogPropertySpec.h" +#include "MakerDialogUtil.h" +#include +#include struct _PropertyContext { MkdgPropertySpec *spec; - GValue value; // -# include +#define _MAKER_DIALOG_PROPERTY_SPEC_H_ +#include +#include /** * MkdgPropertyFlags: * @MKDG_PROPERTY_FLAG_INVISIBLE: The property is not visible in UI. - * @MKDG_PROPERTY_FLAG_INSENSITIVE: The property is gray-out and not editable. + * @MKDG_PROPERTY_FLAG_INSENSITIVE: The property is gray-out and not + * editable. * @MKDG_PROPERTY_FLAG_NO_NEW: The property does not accept new values. - * @MKDG_PROPERTY_FLAG_HAS_TRANSLATION: The property should show translated value. - * @MKDG_PROPERTY_FLAG_NO_BACKEND: The property has no backend, thus will not be saved. + * @MKDG_PROPERTY_FLAG_HAS_TRANSLATION: The property should show translated + * value. + * @MKDG_PROPERTY_FLAG_NO_BACKEND: The property has no backend, thus will + * not be saved. * * MakerDialog flag controls how the property displayed in UI. */ @@ -55,7 +60,7 @@ typedef enum { typedef struct _PropertyContext PropertyContext; -typedef gboolean(*MkdgApplyFunc) (PropertyContext * ctx, gpointer userData); +typedef gboolean (*MkdgApplyFunc)(PropertyContext *ctx, gpointer userData); /** * MkdgPropertySpec: @@ -71,7 +76,7 @@ typedef gboolean(*MkdgApplyFunc) (PropertyContext * ctx, gpointer userData); * @applyFunc: Callback function for apply the value. * @propertyFlags: Property Flags. * @tooltip: Tooltip of this property (Translatable). - * @auxData: Auxiliary data that might be needed somewhere. + * @auxData: Auxiliary data that might be needed somewhere. * * A Property Spec describe the characteristic of a property. */ @@ -96,4 +101,4 @@ typedef struct { gpointer auxData; } MkdgPropertySpec; -#endif /* _MAKER_DIALOG_PROPERTY_SPEC_H_ */ +#endif /* _MAKER_DIALOG_PROPERTY_SPEC_H_ */ diff --git a/src/MakerDialogUtil.c b/src/MakerDialogUtil.c index fab211d..3b4b41e 100644 --- a/src/MakerDialogUtil.c +++ b/src/MakerDialogUtil.c @@ -1,6 +1,6 @@ -#include -#include #include "MakerDialogUtil.h" +#include +#include static MkdgLogLevel debugLevel = WARN; @@ -8,19 +8,12 @@ static MkdgLogLevel debugLevel = WARN; static gchar mkdgLogDomain[MKDG_LOG_DOMAIN_LEN] = "MKDG"; static FILE *logFile = NULL; -void mkdg_log_set_level(MkdgLogLevel level) -{ - debugLevel = level; -} +void mkdg_log_set_level(MkdgLogLevel level) { debugLevel = level; } -void mkdg_log_set_file(FILE * file) -{ - logFile = file; -} +void mkdg_log_set_file(FILE *file) { logFile = file; } -void mkdg_logv_domain(const gchar * domain, MkdgLogLevel level, - const gchar * format, va_list argList) -{ +void mkdg_logv_domain(const gchar *domain, MkdgLogLevel level, + const gchar *format, va_list argList) { if (level > debugLevel) return; GLogLevelFlags flagSet; @@ -56,8 +49,7 @@ void mkdg_logv_domain(const gchar * domain, MkdgLogLevel level, } } -void mkdg_log(MkdgLogLevel level, const gchar * format, ...) -{ +void mkdg_log(MkdgLogLevel level, const gchar *format, ...) { if (level > debugLevel) return; va_list argList; @@ -67,9 +59,8 @@ void mkdg_log(MkdgLogLevel level, const gchar * format, ...) va_end(argList); } -void mkdg_log_domain(const gchar * domain, MkdgLogLevel level, - const gchar * format, ...) -{ +void mkdg_log_domain(const gchar *domain, MkdgLogLevel level, + const gchar *format, ...) { if (level > debugLevel) return; va_list argList; @@ -79,8 +70,7 @@ void mkdg_log_domain(const gchar * domain, MkdgLogLevel level, va_end(argList); } -gboolean mkdg_g_value_reset(GValue * value, GType type, gboolean overwrite) -{ +gboolean mkdg_g_value_reset(GValue *value, GType type, gboolean overwrite) { if (!G_IS_VALUE(value)) { g_value_init(value, type); } @@ -94,9 +84,7 @@ gboolean mkdg_g_value_reset(GValue * value, GType type, gboolean overwrite) return TRUE; } - -gchar *mkdg_g_value_to_string(GValue * value) -{ +gchar *mkdg_g_value_to_string(GValue *value) { static gchar result[MAKER_DIALOG_VALUE_LENGTH]; result[0] = '\0'; @@ -130,8 +118,7 @@ gchar *mkdg_g_value_to_string(GValue * value) return result; } -gboolean mkdg_g_value_from_string(GValue * value, const gchar * str) -{ +gboolean mkdg_g_value_from_string(GValue *value, const gchar *str) { mkdg_log(DEBUG, "mkdg_g_value_from_string(-,%s)", str); if (!G_IS_VALUE(value)) { mkdg_log(ERROR, "mkdg_g_value_from_string(): Failed to get GType"); @@ -189,8 +176,7 @@ gboolean mkdg_g_value_from_string(GValue * value, const gchar * str) return FALSE; } -void mkdg_g_variant_to_g_value(GVariant * gVar, GValue * value) -{ +void mkdg_g_variant_to_g_value(GVariant *gVar, GValue *value) { const GVariantType *gVType = g_variant_get_type(gVar); if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_BOOLEAN)) { @@ -212,8 +198,7 @@ void mkdg_g_variant_to_g_value(GVariant * gVar, GValue * value) } } -GVariant *mkdg_g_value_to_g_variant(GValue * value) -{ +GVariant *mkdg_g_value_to_g_variant(GValue *value) { GType gType = G_VALUE_TYPE(value); GVariant *gVar = NULL; @@ -240,4 +225,4 @@ GVariant *mkdg_g_value_to_g_variant(GValue * value) break; } return gVar; -} \ No newline at end of file +} diff --git a/src/MakerDialogUtil.h b/src/MakerDialogUtil.h index c4b3eba..2f07edf 100644 --- a/src/MakerDialogUtil.h +++ b/src/MakerDialogUtil.h @@ -16,7 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ /** @@ -32,10 +33,10 @@ */ #ifndef _MAKER_DIALOG_UTIL_H_ -# define _MAKER_DIALOG_UTIL_H_ -# include -# include -# include +#define _MAKER_DIALOG_UTIL_H_ +#include +#include +#include /** * MkdgLogLevel: @@ -48,67 +49,56 @@ * Message verbose level, from low to high. Similar to Log level of Gtk. * */ -typedef enum { - ERROR, - WARN, - MSG, - INFO, - DEBUG -} MkdgLogLevel; +typedef enum { ERROR, WARN, MSG, INFO, DEBUG } MkdgLogLevel; void mkdg_log_set_level(MkdgLogLevel level); -void mkdg_log_set_file(FILE * file); +void mkdg_log_set_file(FILE *file); -void mkdg_log(MkdgLogLevel level, const gchar * format, ...); +void mkdg_log(MkdgLogLevel level, const gchar *format, ...); -void mkdg_log_domain(const gchar * domain, MkdgLogLevel level, - const gchar * format, ...); +void mkdg_log_domain(const gchar *domain, MkdgLogLevel level, + const gchar *format, ...); -gchar *mkdg_g_value_to_string(GValue * value); +gchar *mkdg_g_value_to_string(GValue *value); -gboolean mkdg_g_value_reset(GValue * value, GType type, gboolean overwrite); +gboolean mkdg_g_value_reset(GValue *value, GType type, gboolean overwrite); -gboolean mkdg_g_value_from_string(GValue * value, const gchar * str); +gboolean mkdg_g_value_from_string(GValue *value, const gchar *str); -gint mkdg_g_ptr_array_find_string(GPtrArray * array, const gchar * str); +gint mkdg_g_ptr_array_find_string(GPtrArray *array, const gchar *str); -# define mkdg_g_value_is_boolean(value) (G_VALUE_TYPE(value)==G_TYPE_BOOLEAN) +#define mkdg_g_value_is_boolean(value) (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN) -# define mkdg_g_value_is_int(value) (G_VALUE_TYPE(value)==G_TYPE_INT) +#define mkdg_g_value_is_int(value) (G_VALUE_TYPE(value) == G_TYPE_INT) -# define mkdg_g_value_is_uint(value) (G_VALUE_TYPE(value)==G_TYPE_UINT) +#define mkdg_g_value_is_uint(value) (G_VALUE_TYPE(value) == G_TYPE_UINT) -# define mkdg_g_value_is_string(value) (G_VALUE_TYPE(value)==G_TYPE_STRING) +#define mkdg_g_value_is_string(value) (G_VALUE_TYPE(value) == G_TYPE_STRING) -void mkdg_g_variant_to_g_value(GVariant * gVar, GValue * value); - -GVariant *mkdg_g_value_to_g_variant(GValue * value); +void mkdg_g_variant_to_g_value(GVariant *gVar, GValue *value); +GVariant *mkdg_g_value_to_g_variant(GValue *value); /************************************** * String Utility Macros and Functions */ -# define QUOTE_ME_INNER(s) #s -# define QUOTE_ME(s) QUOTE_ME_INNER(s) +#define QUOTE_ME_INNER(s) #s +#define QUOTE_ME(s) QUOTE_ME_INNER(s) -# define STRING_IS_EMPTY(str) \ - (!str || \ - (str[0] == '\0')\ - ) +#define STRING_IS_EMPTY(str) (!str || (str[0] == '\0')) -# define STRING_EQUALS(str1, str2) \ - ((str1==NULL && str2==NULL) ||\ - ((str1!=NULL && str2!=NULL) && strcmp(str1, str2)==0) \ - ) +#define STRING_EQUALS(str1, str2) \ + ((str1 == NULL && str2 == NULL) || \ + ((str1 != NULL && str2 != NULL) && strcmp(str1, str2) == 0)) /************************************** * Flag Utility Macros */ -# define mkdg_clear_flag(flagSet, flag) (flagSet &= ~(flag)) -# define mkdg_has_flag(flagSet, flag) ((flagSet & flag) == flag) -# define mkdg_set_flag(flagSet, flag) (flagSet |= flag) -# define MAKER_DIALOG_VALUE_LENGTH 200 -#endif /* _MAKER_DIALOG_UTIL_H_ */ +#define mkdg_clear_flag(flagSet, flag) (flagSet &= ~(flag)) +#define mkdg_has_flag(flagSet, flag) ((flagSet & flag) == flag) +#define mkdg_set_flag(flagSet, flag) (flagSet |= flag) +#define MAKER_DIALOG_VALUE_LENGTH 200 +#endif /* _MAKER_DIALOG_UTIL_H_ */ diff --git a/src/ibus-chewing-engine-private.h b/src/ibus-chewing-engine-private.h index 93667ff..22548b5 100644 --- a/src/ibus-chewing-engine-private.h +++ b/src/ibus-chewing-engine-private.h @@ -16,21 +16,22 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ -#include -#include -#include #include -#include +#include +#include #include +#include +#include #define GETTEXT_PACKAGE "gtk30" -#include -#include -#include "IBusChewingUtil.h" -#include "IBusChewingProperties.h" -#include "IBusChewingPreEdit.h" #include "GSettingsBackend.h" +#include "IBusChewingPreEdit.h" +#include "IBusChewingProperties.h" +#include "IBusChewingUtil.h" +#include +#include #ifndef __IBUS_CHEWING_ENGINE_PRIVATE_H__ #define __IBUS_CHEWING_ENGINE_PRIVATE_H__ @@ -41,42 +42,38 @@ extern "C" { #endif /* __cplusplus */ - - -void ibus_chewing_engine_handle_Default(IBusChewingEngine * self, - guint keyval, +void ibus_chewing_engine_handle_Default(IBusChewingEngine *self, guint keyval, gboolean shiftPressed); #define self_handle_Default ibus_chewing_engine_handle_Default -void ibus_chewing_engine_candidate_clicked(IBusEngine * engine, - guint index, guint button, - guint state); -void ibus_chewing_engine_property_activate(IBusEngine * engine, - const gchar * prop_name, +void ibus_chewing_engine_candidate_clicked(IBusEngine *engine, guint index, + guint button, guint state); +void ibus_chewing_engine_property_activate(IBusEngine *engine, + const gchar *prop_name, guint prop_state); -void ibus_chewing_engine_set_content_type(IBusEngine * engine, - guint purpose, guint hints); +void ibus_chewing_engine_set_content_type(IBusEngine *engine, guint purpose, + guint hints); -void refresh_pre_edit_text(IBusChewingEngine * self); -void update_pre_edit_text(IBusChewingEngine * self); -void refresh_aux_text(IBusChewingEngine * self); -void update_aux_text(IBusChewingEngine * self); -void update_lookup_table(IBusChewingEngine * self); -void refresh_outgoing_text(IBusChewingEngine * self); -void commit_text(IBusChewingEngine * self); +void refresh_pre_edit_text(IBusChewingEngine *self); +void update_pre_edit_text(IBusChewingEngine *self); +void refresh_aux_text(IBusChewingEngine *self); +void update_aux_text(IBusChewingEngine *self); +void update_lookup_table(IBusChewingEngine *self); +void refresh_outgoing_text(IBusChewingEngine *self); +void commit_text(IBusChewingEngine *self); struct _IBusChewingEnginePrivate { - EngineFlag statusFlags; - IBusCapabilite capabilite; - ChewingInputStyle inputStyle; + EngineFlag statusFlags; + IBusCapabilite capabilite; + ChewingInputStyle inputStyle; }; -void ibus_chewing_engine_use_setting (IBusChewingEngine * self); -void ibus_chewing_engine_restore_mode (IBusChewingEngine * self); -void ibus_chewing_engine_update (IBusChewingEngine * self); -void ibus_chewing_engine_refresh_property (IBusChewingEngine * self, const gchar * prop_name); +void ibus_chewing_engine_use_setting(IBusChewingEngine *self); +void ibus_chewing_engine_restore_mode(IBusChewingEngine *self); +void ibus_chewing_engine_update(IBusChewingEngine *self); +void ibus_chewing_engine_refresh_property(IBusChewingEngine *self, + const gchar *prop_name); #ifdef __cplusplus } #endif /* __cplusplus */ - #endif diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c index 7c07fa0..20c6993 100644 --- a/src/ibus-chewing-engine.c +++ b/src/ibus-chewing-engine.c @@ -16,28 +16,30 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ -#include -#include -#include #include -#include +#include +#include #include +#include +#include #define GETTEXT_PACKAGE "gtk30" -#include -#include -#include -#include "IBusChewingUtil.h" -#include "IBusChewingProperties.h" -#include "IBusChewingPreEdit.h" #include "GSettingsBackend.h" +#include "IBusChewingPreEdit.h" +#include "IBusChewingProperties.h" +#include "IBusChewingUtil.h" +#include +#include +#include #define GOB_VERSION_MAJOR 2 #define GOB_VERSION_MINOR 0 #define GOB_VERSION_PATCHLEVEL 20 -#define selfp ((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private (self)) +#define selfp \ + ((IBusChewingEnginePrivate *)ibus_chewing_engine_get_instance_private(self)) #include /* memset() */ @@ -53,40 +55,41 @@ #define ___GOB_UNLIKELY(expr) (expr) #endif /* G_LIKELY */ static const GEnumValue _chewing_input_style_values[] = { - { CHEWING_INPUT_STYLE_IN_APPLICATION, (char *)"CHEWING_INPUT_STYLE_IN_APPLICATION", (char *)"in-application" }, - { CHEWING_INPUT_STYLE_IN_CANDIDATE, (char *)"CHEWING_INPUT_STYLE_IN_CANDIDATE", (char *)"in-candidate" }, - { 0, NULL, NULL } -}; - -GType -chewing_input_style_get_type (void) -{ - static GType type = 0; - if ___GOB_UNLIKELY(type == 0) - type = g_enum_register_static ("ChewingInputStyle", _chewing_input_style_values); - return type; + {CHEWING_INPUT_STYLE_IN_APPLICATION, + (char *)"CHEWING_INPUT_STYLE_IN_APPLICATION", (char *)"in-application"}, + {CHEWING_INPUT_STYLE_IN_CANDIDATE, + (char *)"CHEWING_INPUT_STYLE_IN_CANDIDATE", (char *)"in-candidate"}, + {0, NULL, NULL}}; + +GType chewing_input_style_get_type(void) { + static GType type = 0; + + if ___GOB_UNLIKELY (type == 0) + type = g_enum_register_static("ChewingInputStyle", + _chewing_input_style_values); + return type; } static const GEnumValue _engine_flag_values[] = { - { ENGINE_FLAG_INITIALIZED, (char *)"ENGINE_FLAG_INITIALIZED", (char *)"initialized" }, - { ENGINE_FLAG_ENABLED, (char *)"ENGINE_FLAG_ENABLED", (char *)"enabled" }, - { ENGINE_FLAG_FOCUS_IN, (char *)"ENGINE_FLAG_FOCUS_IN", (char *)"focus-in" }, - { ENGINE_FLAG_IS_PASSWORD, (char *)"ENGINE_FLAG_IS_PASSWORD", (char *)"is-password" }, - { ENGINE_FLAG_PROPERTIES_REGISTERED, (char *)"ENGINE_FLAG_PROPERTIES_REGISTERED", (char *)"properties-registered" }, - { 0, NULL, NULL } -}; - -GType -engine_flag_get_type (void) -{ - static GType type = 0; - if ___GOB_UNLIKELY(type == 0) - type = g_enum_register_static ("EngineFlag", _engine_flag_values); - return type; + {ENGINE_FLAG_INITIALIZED, (char *)"ENGINE_FLAG_INITIALIZED", + (char *)"initialized"}, + {ENGINE_FLAG_ENABLED, (char *)"ENGINE_FLAG_ENABLED", (char *)"enabled"}, + {ENGINE_FLAG_FOCUS_IN, (char *)"ENGINE_FLAG_FOCUS_IN", (char *)"focus-in"}, + {ENGINE_FLAG_IS_PASSWORD, (char *)"ENGINE_FLAG_IS_PASSWORD", + (char *)"is-password"}, + {ENGINE_FLAG_PROPERTIES_REGISTERED, + (char *)"ENGINE_FLAG_PROPERTIES_REGISTERED", + (char *)"properties-registered"}, + {0, NULL, NULL}}; + +GType engine_flag_get_type(void) { + static GType type = 0; + + if ___GOB_UNLIKELY (type == 0) + type = g_enum_register_static("EngineFlag", _engine_flag_values); + return type; } - - extern gint ibus_chewing_verbose; #define IBUS_CHEWING_MAIN @@ -104,23 +107,37 @@ extern gint ibus_chewing_verbose; typedef IBusChewingEngine Self; typedef IBusChewingEngineClass SelfClass; -G_DEFINE_TYPE_WITH_CODE(IBusChewingEngine, ibus_chewing_engine, IBUS_TYPE_ENGINE, G_ADD_PRIVATE(IBusChewingEngine)); +G_DEFINE_TYPE_WITH_CODE(IBusChewingEngine, ibus_chewing_engine, + IBUS_TYPE_ENGINE, G_ADD_PRIVATE(IBusChewingEngine)); /* here are local prototypes */ -static void ibus_chewing_engine_constructor (IBusChewingEngine * self) G_GNUC_UNUSED; -static IBusProperty * ibus_chewing_engine_get_ibus_property_by_name (IBusChewingEngine * self, const gchar * prop_name) G_GNUC_UNUSED; -static void ___b_ibus_chewing_engine_reset (IBusEngine * engine) G_GNUC_UNUSED; -static void ___c_ibus_chewing_engine_page_up (IBusEngine * engine) G_GNUC_UNUSED; -static void ___d_ibus_chewing_engine_page_down (IBusEngine * engine) G_GNUC_UNUSED; -static void ___e_ibus_chewing_engine_cursor_up (IBusEngine * engine) G_GNUC_UNUSED; -static void ___f_ibus_chewing_engine_cursor_down (IBusEngine * engine) G_GNUC_UNUSED; -static void ___10_ibus_chewing_engine_enable (IBusEngine * engine) G_GNUC_UNUSED; -static void ___11_ibus_chewing_engine_disable (IBusEngine * engine) G_GNUC_UNUSED; -static void ___12_ibus_chewing_engine_focus_in (IBusEngine * engine) G_GNUC_UNUSED; -static void ___13_ibus_chewing_engine_focus_out (IBusEngine * engine) G_GNUC_UNUSED; -static void ___14_ibus_chewing_engine_set_capabilities (IBusEngine * engine, guint caps) G_GNUC_UNUSED; -static void ___15_ibus_chewing_engine_property_show (IBusEngine * engine, const gchar * prop_name) G_GNUC_UNUSED; -static void ___16_ibus_chewing_engine_property_hide (IBusEngine * engine, const gchar * prop_name) G_GNUC_UNUSED; +static void +ibus_chewing_engine_constructor(IBusChewingEngine *self) G_GNUC_UNUSED; +static IBusProperty *ibus_chewing_engine_get_ibus_property_by_name( + IBusChewingEngine *self, const gchar *prop_name) G_GNUC_UNUSED; +static void ___b_ibus_chewing_engine_reset(IBusEngine *engine) G_GNUC_UNUSED; +static void ___c_ibus_chewing_engine_page_up(IBusEngine *engine) G_GNUC_UNUSED; +static void +___d_ibus_chewing_engine_page_down(IBusEngine *engine) G_GNUC_UNUSED; +static void +___e_ibus_chewing_engine_cursor_up(IBusEngine *engine) G_GNUC_UNUSED; +static void +___f_ibus_chewing_engine_cursor_down(IBusEngine *engine) G_GNUC_UNUSED; +static void ___10_ibus_chewing_engine_enable(IBusEngine *engine) G_GNUC_UNUSED; +static void ___11_ibus_chewing_engine_disable(IBusEngine *engine) G_GNUC_UNUSED; +static void +___12_ibus_chewing_engine_focus_in(IBusEngine *engine) G_GNUC_UNUSED; +static void +___13_ibus_chewing_engine_focus_out(IBusEngine *engine) G_GNUC_UNUSED; +static void +___14_ibus_chewing_engine_set_capabilities(IBusEngine *engine, + guint caps) G_GNUC_UNUSED; +static void +___15_ibus_chewing_engine_property_show(IBusEngine *engine, + const gchar *prop_name) G_GNUC_UNUSED; +static void +___16_ibus_chewing_engine_property_hide(IBusEngine *engine, + const gchar *prop_name) G_GNUC_UNUSED; /* pointer to the class of our parent */ static IBusEngineClass *parent_class = NULL; @@ -132,125 +149,142 @@ static IBusEngineClass *parent_class = NULL; #define self_refresh_property ibus_chewing_engine_refresh_property #define self_refresh_property_list ibus_chewing_engine_refresh_property_list #define self_hide_property_list ibus_chewing_engine_hide_property_list -#define self_get_ibus_property_by_name ibus_chewing_engine_get_ibus_property_by_name - -#define ibus_chewing_engine_has_status_flag(self, f) mkdg_has_flag(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->statusFlags, f) -#define ibus_chewing_engine_set_status_flag(self, f) mkdg_set_flag(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->statusFlags, f) -#define ibus_chewing_engine_clear_status_flag(self, f) mkdg_clear_flag(((IBusChewingEnginePrivate*)ibus_chewing_engine_get_instance_private(self))->statusFlags, f) - -#define is_password(self) ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_IS_PASSWORD) -#define ibus_chewing_engine_is_chinese_mode(self) ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) - -#define ibus_text_is_empty(iText) ((iText == NULL) || STRING_IS_EMPTY(iText->text)) +#define self_get_ibus_property_by_name \ + ibus_chewing_engine_get_ibus_property_by_name + +#define ibus_chewing_engine_has_status_flag(self, f) \ + mkdg_has_flag(((IBusChewingEnginePrivate *) \ + ibus_chewing_engine_get_instance_private(self)) \ + ->statusFlags, \ + f) +#define ibus_chewing_engine_set_status_flag(self, f) \ + mkdg_set_flag(((IBusChewingEnginePrivate *) \ + ibus_chewing_engine_get_instance_private(self)) \ + ->statusFlags, \ + f) +#define ibus_chewing_engine_clear_status_flag(self, f) \ + mkdg_clear_flag(((IBusChewingEnginePrivate *) \ + ibus_chewing_engine_get_instance_private(self)) \ + ->statusFlags, \ + f) + +#define is_password(self) \ + ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_IS_PASSWORD) +#define ibus_chewing_engine_is_chinese_mode(self) \ + ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) + +#define ibus_text_is_empty(iText) \ + ((iText == NULL) || STRING_IS_EMPTY(iText->text)) /* a macro for creating a new object of our type */ -#define GET_NEW ((IBusChewingEngine *)g_object_new(ibus_chewing_engine_get_type(), NULL)) +#define GET_NEW \ + ((IBusChewingEngine *)g_object_new(ibus_chewing_engine_get_type(), NULL)) /* a function for creating a new object of our type */ #include -static IBusChewingEngine * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED; -static IBusChewingEngine * -GET_NEW_VARG (const char *first, ...) -{ - IBusChewingEngine *ret; - va_list ap; - va_start (ap, first); - ret = (IBusChewingEngine *)g_object_new_valist (ibus_chewing_engine_get_type (), first, ap); - va_end (ap); - return ret; +static IBusChewingEngine *GET_NEW_VARG(const char *first, ...) G_GNUC_UNUSED; +static IBusChewingEngine *GET_NEW_VARG(const char *first, ...) { + IBusChewingEngine *ret; + va_list ap; + + va_start(ap, first); + ret = (IBusChewingEngine *)g_object_new_valist( + ibus_chewing_engine_get_type(), first, ap); + va_end(ap); + return ret; } - -static GObject * -___constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) -{ +static GObject *___constructor(GType type, guint n_construct_properties, + GObjectConstructParam *construct_properties) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::constructor" - GObject *obj_self; - IBusChewingEngine *self; - obj_self = G_OBJECT_CLASS (parent_class)->constructor (type, n_construct_properties, construct_properties); - self = IBUS_CHEWING_ENGINE (obj_self); - ibus_chewing_engine_constructor (self); - return obj_self; + GObject *obj_self; + IBusChewingEngine *self; + + obj_self = + G_OBJECT_CLASS(parent_class) + ->constructor(type, n_construct_properties, construct_properties); + self = IBUS_CHEWING_ENGINE(obj_self); + ibus_chewing_engine_constructor(self); + return obj_self; } -#undef __GOB_FUNCTION__ +#undef __GOB_FUNCTION__ -static void -___finalize(GObject *obj_self) -{ +static void ___finalize(GObject *obj_self) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::finalize" - IBusChewingEngine *self G_GNUC_UNUSED = IBUS_CHEWING_ENGINE (obj_self); - gpointer priv G_GNUC_UNUSED = selfp; - if(self->icPreEdit) { ibus_chewing_pre_edit_free ((gpointer) self->icPreEdit); self->icPreEdit = NULL; } - if(self->preEditText) { g_object_unref ((gpointer) self->preEditText); self->preEditText = NULL; } - if(self->auxText) { g_object_unref ((gpointer) self->auxText); self->auxText = NULL; } - if(self->outgoingText) { g_object_unref ((gpointer) self->outgoingText); self->outgoingText = NULL; } - if(self->InputMode) { g_object_unref ((gpointer) self->InputMode); self->InputMode = NULL; } - if(self->AlnumSize) { g_object_unref ((gpointer) self->AlnumSize); self->AlnumSize = NULL; } - if(self->setup_prop) { g_object_unref ((gpointer) self->setup_prop); self->setup_prop = NULL; } - if(self->prop_list) { g_object_unref ((gpointer) self->prop_list); self->prop_list = NULL; } - if(G_OBJECT_CLASS(parent_class)->finalize) \ - (* G_OBJECT_CLASS(parent_class)->finalize)(obj_self); + IBusChewingEngine *self G_GNUC_UNUSED = IBUS_CHEWING_ENGINE(obj_self); + gpointer priv G_GNUC_UNUSED = selfp; + + if (self->icPreEdit) { + ibus_chewing_pre_edit_free((gpointer)self->icPreEdit); + self->icPreEdit = NULL; + } + if (self->preEditText) { + g_object_unref((gpointer)self->preEditText); + self->preEditText = NULL; + } + if (self->auxText) { + g_object_unref((gpointer)self->auxText); + self->auxText = NULL; + } + if (self->outgoingText) { + g_object_unref((gpointer)self->outgoingText); + self->outgoingText = NULL; + } + if (self->InputMode) { + g_object_unref((gpointer)self->InputMode); + self->InputMode = NULL; + } + if (self->AlnumSize) { + g_object_unref((gpointer)self->AlnumSize); + self->AlnumSize = NULL; + } + if (self->setup_prop) { + g_object_unref((gpointer)self->setup_prop); + self->setup_prop = NULL; + } + if (self->prop_list) { + g_object_unref((gpointer)self->prop_list); + self->prop_list = NULL; + } + if (G_OBJECT_CLASS(parent_class)->finalize) + (*G_OBJECT_CLASS(parent_class)->finalize)(obj_self); } + #undef __GOB_FUNCTION__ -static void -ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) -{ +static void ibus_chewing_engine_init(IBusChewingEngine *self G_GNUC_UNUSED) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::init" - self->icPreEdit = NULL; - self->sDialog = NULL; - self->preEditText = NULL; - self->auxText = NULL; - self->outgoingText = NULL; - self->logFile = NULL; - selfp->statusFlags = 0; - selfp->capabilite = 0; - self->InputMode = - g_object_ref_sink(ibus_property_new - ("InputMode", - PROP_TYPE_NORMAL, - SELF_GET_CLASS(self)->InputMode_label_chi, - NULL, - SELF_GET_CLASS(self)->InputMode_tooltip, - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL)) - ; - self->AlnumSize = - g_object_ref_sink(ibus_property_new - ("AlnumSize", - PROP_TYPE_NORMAL, - SELF_GET_CLASS(self)->AlnumSize_label_half, - NULL, - SELF_GET_CLASS(self)->AlnumSize_tooltip, - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL)) - ; - self->setup_prop = - g_object_ref_sink(ibus_property_new - ("setup_prop", - PROP_TYPE_NORMAL, - SELF_GET_CLASS(self)->setup_prop_label, - NULL, - SELF_GET_CLASS(self)->setup_prop_tooltip, - TRUE, - TRUE, - PROP_STATE_UNCHECKED, - NULL)) - ; - self->prop_list = - g_object_ref_sink(ibus_prop_list_new()) - ; - self->keymap_us = ibus_keymap_get("us") ; - { + self->icPreEdit = NULL; + self->sDialog = NULL; + self->preEditText = NULL; + self->auxText = NULL; + self->outgoingText = NULL; + self->logFile = NULL; + selfp->statusFlags = 0; + selfp->capabilite = 0; + self->InputMode = g_object_ref_sink( + ibus_property_new("InputMode", PROP_TYPE_NORMAL, + SELF_GET_CLASS(self)->InputMode_label_chi, NULL, + SELF_GET_CLASS(self)->InputMode_tooltip, TRUE, TRUE, + PROP_STATE_UNCHECKED, NULL)); + self->AlnumSize = g_object_ref_sink( + ibus_property_new("AlnumSize", PROP_TYPE_NORMAL, + SELF_GET_CLASS(self)->AlnumSize_label_half, NULL, + SELF_GET_CLASS(self)->AlnumSize_tooltip, TRUE, TRUE, + PROP_STATE_UNCHECKED, NULL)); + self->setup_prop = g_object_ref_sink(ibus_property_new( + "setup_prop", PROP_TYPE_NORMAL, SELF_GET_CLASS(self)->setup_prop_label, + NULL, SELF_GET_CLASS(self)->setup_prop_tooltip, TRUE, TRUE, + PROP_STATE_UNCHECKED, NULL)); + self->prop_list = g_object_ref_sink(ibus_prop_list_new()); + self->keymap_us = ibus_keymap_get("us"); + { /* initialize the object here */ IBUS_CHEWING_LOG(INFO, "init() %sinitialized", - (selfp->statusFlags & ENGINE_FLAG_INITIALIZED) ? "" : "un"); + (selfp->statusFlags & ENGINE_FLAG_INITIALIZED) ? "" + : "un"); if (selfp->statusFlags & ENGINE_FLAG_INITIALIZED) { return; } @@ -263,7 +297,8 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) if (logFilename != NULL) { self->logFile = fopen(logFilename, "w+"); if (self->logFile == NULL) { - IBUS_CHEWING_LOG(WARN, "init() Cannot write to logfile %s, ignored", + IBUS_CHEWING_LOG(WARN, + "init() Cannot write to logfile %s, ignored", logFilename); } else { mkdg_log_set_file(self->logFile); @@ -274,7 +309,7 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) MkdgBackend *backend = mkdg_g_settings_backend_new(QUOTE_ME(PROJECT_SCHEMA_ID), - QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); + QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); self->icPreEdit = ibus_chewing_pre_edit_new(backend); } @@ -291,80 +326,64 @@ ibus_chewing_engine_init (IBusChewingEngine * self G_GNUC_UNUSED) ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_INITIALIZED); IBUS_CHEWING_LOG(DEBUG, "init() Done"); - - } + } } + #undef __GOB_FUNCTION__ -static void -ibus_chewing_engine_class_init (IBusChewingEngineClass * klass G_GNUC_UNUSED) -{ +static void +ibus_chewing_engine_class_init(IBusChewingEngineClass *klass G_GNUC_UNUSED) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::class_init" - GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) klass; - IBusEngineClass *ibus_engine_class = (IBusEngineClass *)klass; - - klass->InputMode_label_chi = - g_object_ref_sink(ibus_text_new_from_static_string(_("Chinese Mode"))) - ; - klass->InputMode_label_eng = - g_object_ref_sink(ibus_text_new_from_static_string(_("Alphanumeric Mode"))) - ; - klass->InputMode_tooltip = - g_object_ref_sink(ibus_text_new_from_static_string - (_("Click to toggle Chinese/Alphanumeric Mode"))) - ; - klass->InputMode_symbol_chi = - g_object_ref_sink(ibus_text_new_from_static_string("中")) - ; - klass->InputMode_symbol_eng = - g_object_ref_sink(ibus_text_new_from_static_string("英")) - ; - klass->AlnumSize_label_full = - g_object_ref_sink(ibus_text_new_from_static_string(_("Fullwidth Form"))) - ; - klass->AlnumSize_label_half = - g_object_ref_sink(ibus_text_new_from_static_string(_("Halfwidth Form"))) - ; - klass->AlnumSize_tooltip = - g_object_ref_sink(ibus_text_new_from_static_string - (_("Click to toggle Halfwidth/Fullwidth Form"))) - ; - klass->AlnumSize_symbol_full = - g_object_ref_sink(ibus_text_new_from_static_string("全")) - ; - klass->AlnumSize_symbol_half = - g_object_ref_sink(ibus_text_new_from_static_string("半")) - ; - klass->setup_prop_label = - g_object_ref_sink(ibus_text_new_from_static_string(_("IBus-Chewing Preferences"))) - ; - klass->setup_prop_tooltip = - g_object_ref_sink(ibus_text_new_from_static_string - (_("Click to configure IBus-Chewing"))) - ; - klass->setup_prop_symbol = - g_object_ref_sink(ibus_text_new_from_static_string("訂")) - ; - klass->emptyText = - g_object_ref_sink(ibus_text_new_from_static_string("")) - ; - - parent_class = g_type_class_ref (IBUS_TYPE_ENGINE); - - ibus_engine_class->reset = ___b_ibus_chewing_engine_reset; - ibus_engine_class->page_up = ___c_ibus_chewing_engine_page_up; - ibus_engine_class->page_down = ___d_ibus_chewing_engine_page_down; - ibus_engine_class->cursor_up = ___e_ibus_chewing_engine_cursor_up; - ibus_engine_class->cursor_down = ___f_ibus_chewing_engine_cursor_down; - ibus_engine_class->enable = ___10_ibus_chewing_engine_enable; - ibus_engine_class->disable = ___11_ibus_chewing_engine_disable; - ibus_engine_class->focus_in = ___12_ibus_chewing_engine_focus_in; - ibus_engine_class->focus_out = ___13_ibus_chewing_engine_focus_out; - ibus_engine_class->set_capabilities = ___14_ibus_chewing_engine_set_capabilities; - ibus_engine_class->property_show = ___15_ibus_chewing_engine_property_show; - ibus_engine_class->property_hide = ___16_ibus_chewing_engine_property_hide; - g_object_class->constructor = ___constructor; - g_object_class->finalize = ___finalize; - { + GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass *)klass; + IBusEngineClass *ibus_engine_class = (IBusEngineClass *)klass; + + klass->InputMode_label_chi = + g_object_ref_sink(ibus_text_new_from_static_string(_("Chinese Mode"))); + klass->InputMode_label_eng = g_object_ref_sink( + ibus_text_new_from_static_string(_("Alphanumeric Mode"))); + klass->InputMode_tooltip = + g_object_ref_sink(ibus_text_new_from_static_string( + _("Click to toggle Chinese/Alphanumeric Mode"))); + klass->InputMode_symbol_chi = + g_object_ref_sink(ibus_text_new_from_static_string("中")); + klass->InputMode_symbol_eng = + g_object_ref_sink(ibus_text_new_from_static_string("英")); + klass->AlnumSize_label_full = g_object_ref_sink( + ibus_text_new_from_static_string(_("Fullwidth Form"))); + klass->AlnumSize_label_half = g_object_ref_sink( + ibus_text_new_from_static_string(_("Halfwidth Form"))); + klass->AlnumSize_tooltip = + g_object_ref_sink(ibus_text_new_from_static_string( + _("Click to toggle Halfwidth/Fullwidth Form"))); + klass->AlnumSize_symbol_full = + g_object_ref_sink(ibus_text_new_from_static_string("全")); + klass->AlnumSize_symbol_half = + g_object_ref_sink(ibus_text_new_from_static_string("半")); + klass->setup_prop_label = g_object_ref_sink( + ibus_text_new_from_static_string(_("IBus-Chewing Preferences"))); + klass->setup_prop_tooltip = g_object_ref_sink( + ibus_text_new_from_static_string(_("Click to configure IBus-Chewing"))); + klass->setup_prop_symbol = + g_object_ref_sink(ibus_text_new_from_static_string("訂")); + klass->emptyText = g_object_ref_sink(ibus_text_new_from_static_string("")); + + parent_class = g_type_class_ref(IBUS_TYPE_ENGINE); + + ibus_engine_class->reset = ___b_ibus_chewing_engine_reset; + ibus_engine_class->page_up = ___c_ibus_chewing_engine_page_up; + ibus_engine_class->page_down = ___d_ibus_chewing_engine_page_down; + ibus_engine_class->cursor_up = ___e_ibus_chewing_engine_cursor_up; + ibus_engine_class->cursor_down = ___f_ibus_chewing_engine_cursor_down; + ibus_engine_class->enable = ___10_ibus_chewing_engine_enable; + ibus_engine_class->disable = ___11_ibus_chewing_engine_disable; + ibus_engine_class->focus_in = ___12_ibus_chewing_engine_focus_in; + ibus_engine_class->focus_out = ___13_ibus_chewing_engine_focus_out; + ibus_engine_class->set_capabilities = + ___14_ibus_chewing_engine_set_capabilities; + ibus_engine_class->property_show = ___15_ibus_chewing_engine_property_show; + ibus_engine_class->property_hide = ___16_ibus_chewing_engine_property_hide; + g_object_class->constructor = ___constructor; + g_object_class->finalize = ___finalize; + { ibus_engine_class->property_activate = ibus_chewing_engine_property_activate; @@ -376,134 +395,145 @@ ibus_chewing_engine_class_init (IBusChewingEngineClass * klass G_GNUC_UNUSED) ibus_engine_class->set_content_type = ibus_chewing_engine_set_content_type; #endif - - } + } } -#undef __GOB_FUNCTION__ - +#undef __GOB_FUNCTION__ -static void -ibus_chewing_engine_constructor (IBusChewingEngine * self G_GNUC_UNUSED) -{ +static void +ibus_chewing_engine_constructor(IBusChewingEngine *self G_GNUC_UNUSED) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::constructor" -{ - - /* GOB need this for generating constructor */ - }} + { /* GOB need this for generating constructor */ + } +} + #undef __GOB_FUNCTION__ -void -ibus_chewing_engine_use_setting (IBusChewingEngine * self) -{ +void ibus_chewing_engine_use_setting(IBusChewingEngine *self) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::use_setting" - g_return_if_fail (self != NULL); - g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); -{ - + g_return_if_fail(self != NULL); + g_return_if_fail(IBUS_IS_CHEWING_ENGINE(self)); + { + IBUS_CHEWING_LOG(INFO, "use_setting()"); ibus_chewing_pre_edit_use_all_configure(self->icPreEdit); /* Input style */ - if (ibus_chewing_properties_read_boolean_general(self->icPreEdit->iProperties, - "ibus/general", "embed-preedit-text", NULL)) { + if (ibus_chewing_properties_read_boolean_general( + self->icPreEdit->iProperties, "ibus/general", + "embed-preedit-text", NULL)) { selfp->inputStyle = CHEWING_INPUT_STYLE_IN_APPLICATION; } else { selfp->inputStyle = CHEWING_INPUT_STYLE_IN_CANDIDATE; } - }} + } +} + #undef __GOB_FUNCTION__ -void -ibus_chewing_engine_restore_mode (IBusChewingEngine * self) -{ +void ibus_chewing_engine_restore_mode(IBusChewingEngine *self) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::restore_mode" - g_return_if_fail (self != NULL); - g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); -{ - - IBUS_CHEWING_LOG(DEBUG, "restore_mode() statusFlags=%x", selfp->statusFlags); + g_return_if_fail(self != NULL); + g_return_if_fail(IBUS_IS_CHEWING_ENGINE(self)); + { + + IBUS_CHEWING_LOG(DEBUG, "restore_mode() statusFlags=%x", + selfp->statusFlags); GdkDisplay *display = gdk_display_get_default(); + if (display != NULL) { GdkSeat *seat = gdk_display_get_default_seat(display); + if (seat != NULL) { GdkDevice *keyboard = gdk_seat_get_keyboard(seat); + /* Restore Led Mode only make sense if display is available */ - if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_IM)) { - IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_IM (deprecated)"); - } else if (keyboard != NULL && ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) { - IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_KEYBOARD"); - gboolean caps_lock_on = gdk_device_get_caps_lock_state(keyboard); - chewing_set_ChiEngMode(self->icPreEdit->context, caps_lock_on ? 0 : CHINESE_MODE); + if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, + FLAG_SYNC_FROM_IM)) { + IBUS_CHEWING_LOG( + DEBUG, "restore_mode() FLAG_SYNC_FROM_IM (deprecated)"); + } else if (keyboard != NULL && + ibus_chewing_pre_edit_has_flag( + self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) { + IBUS_CHEWING_LOG(DEBUG, + "restore_mode() FLAG_SYNC_FROM_KEYBOARD"); + gboolean caps_lock_on = + gdk_device_get_caps_lock_state(keyboard); + chewing_set_ChiEngMode(self->icPreEdit->context, + caps_lock_on ? 0 : CHINESE_MODE); } } self_refresh_property(self, "InputMode"); } - }} + } +} + #undef __GOB_FUNCTION__ -void -ibus_chewing_engine_update (IBusChewingEngine * self) -{ +void ibus_chewing_engine_update(IBusChewingEngine *self) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::update" - g_return_if_fail (self != NULL); - g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); -{ - + g_return_if_fail(self != NULL); + g_return_if_fail(IBUS_IS_CHEWING_ENGINE(self)); + { + IBUS_CHEWING_LOG(DEBUG, "update() statusFlags=%x", selfp->statusFlags); commit_text(self); update_pre_edit_text(self); update_aux_text(self); - IBUS_CHEWING_LOG(DEBUG, - "update() nPhoneSeq=%d statusFlags=%x", + IBUS_CHEWING_LOG(DEBUG, "update() nPhoneSeq=%d statusFlags=%x", chewing_get_phoneSeqLen(self->icPreEdit->context), selfp->statusFlags); update_lookup_table(self); - }} + } +} + #undef __GOB_FUNCTION__ -void -ibus_chewing_engine_refresh_property (IBusChewingEngine * self, const gchar * prop_name) -{ +void ibus_chewing_engine_refresh_property(IBusChewingEngine *self, + const gchar *prop_name) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::refresh_property" - g_return_if_fail (self != NULL); - g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); -{ - + g_return_if_fail(self != NULL); + g_return_if_fail(IBUS_IS_CHEWING_ENGINE(self)); + { + #ifndef UNIT_TEST - IBUS_CHEWING_LOG(DEBUG, "refresh_property(%s) status=%x", - prop_name, selfp->statusFlags); + IBUS_CHEWING_LOG(DEBUG, "refresh_property(%s) status=%x", prop_name, + selfp->statusFlags); if (STRING_EQUALS(prop_name, "InputMode")) { - ibus_property_set_label(self->InputMode, - ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) ? - SELF_GET_CLASS(self)->InputMode_label_chi : - SELF_GET_CLASS(self)->InputMode_label_eng); + ibus_property_set_label( + self->InputMode, + ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) + ? SELF_GET_CLASS(self)->InputMode_label_chi + : SELF_GET_CLASS(self)->InputMode_label_eng); #if IBUS_CHECK_VERSION(1, 5, 0) - ibus_property_set_symbol(self->InputMode, - ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) ? - SELF_GET_CLASS(self)->InputMode_symbol_chi : - SELF_GET_CLASS(self)->InputMode_symbol_eng); + ibus_property_set_symbol( + self->InputMode, + ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) + ? SELF_GET_CLASS(self)->InputMode_symbol_chi + : SELF_GET_CLASS(self)->InputMode_symbol_eng); #endif ibus_engine_update_property(IBUS_ENGINE(self), self->InputMode); } else if (STRING_EQUALS(prop_name, "AlnumSize")) { - ibus_property_set_label(self->AlnumSize, - chewing_get_ShapeMode(self->icPreEdit->context) ? - SELF_GET_CLASS(self)->AlnumSize_label_full : - SELF_GET_CLASS(self)->AlnumSize_label_half); + ibus_property_set_label( + self->AlnumSize, + chewing_get_ShapeMode(self->icPreEdit->context) + ? SELF_GET_CLASS(self)->AlnumSize_label_full + : SELF_GET_CLASS(self)->AlnumSize_label_half); #if IBUS_CHECK_VERSION(1, 5, 0) - ibus_property_set_symbol(self->AlnumSize, - chewing_get_ShapeMode(self->icPreEdit->context) ? - SELF_GET_CLASS(self)->AlnumSize_symbol_full : - SELF_GET_CLASS(self)->AlnumSize_symbol_half); + ibus_property_set_symbol( + self->AlnumSize, + chewing_get_ShapeMode(self->icPreEdit->context) + ? SELF_GET_CLASS(self)->AlnumSize_symbol_full + : SELF_GET_CLASS(self)->AlnumSize_symbol_half); #endif if (selfp->statusFlags & ENGINE_FLAG_PROPERTIES_REGISTERED) @@ -512,12 +542,14 @@ ibus_chewing_engine_refresh_property (IBusChewingEngine * self, const gchar * pr } else if (STRING_EQUALS(prop_name, "setup_prop")) { #if IBUS_CHECK_VERSION(1, 5, 0) ibus_property_set_symbol(self->setup_prop, - SELF_GET_CLASS(self)->setup_prop_symbol); + SELF_GET_CLASS(self)->setup_prop_symbol); #endif ibus_engine_update_property(IBUS_ENGINE(self), self->setup_prop); } #endif - }} + } +} + #undef __GOB_FUNCTION__ /** @@ -526,20 +558,20 @@ ibus_chewing_engine_refresh_property (IBusChewingEngine * self, const gchar * pr * * Refresh the property list (language bar). **/ -void -ibus_chewing_engine_refresh_property_list (IBusChewingEngine * self) -{ +void ibus_chewing_engine_refresh_property_list(IBusChewingEngine *self) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::refresh_property_list" - g_return_if_fail (self != NULL); - g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); -{ - + g_return_if_fail(self != NULL); + g_return_if_fail(IBUS_IS_CHEWING_ENGINE(self)); + { + #ifndef UNIT_TEST self_refresh_property(self, "InputMode"); self_refresh_property(self, "AlnumSize"); self_refresh_property(self, "setup_prop"); #endif - }} + } +} + #undef __GOB_FUNCTION__ /** @@ -548,29 +580,29 @@ ibus_chewing_engine_refresh_property_list (IBusChewingEngine * self) * * Hide the property list (language bar). **/ -void -ibus_chewing_engine_hide_property_list (IBusChewingEngine * self) -{ +void ibus_chewing_engine_hide_property_list(IBusChewingEngine *self) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::hide_property_list" - g_return_if_fail (self != NULL); - g_return_if_fail (IBUS_IS_CHEWING_ENGINE (self)); -{ - + g_return_if_fail(self != NULL); + g_return_if_fail(IBUS_IS_CHEWING_ENGINE(self)); + { + #ifndef UNIT_TEST IBUS_ENGINE_GET_CLASS(self)->property_hide(IBUS_ENGINE(self), "AlnumSize"); #endif - }} + } +} + #undef __GOB_FUNCTION__ -static IBusProperty * -ibus_chewing_engine_get_ibus_property_by_name (IBusChewingEngine * self, const gchar * prop_name) -{ +static IBusProperty * +ibus_chewing_engine_get_ibus_property_by_name(IBusChewingEngine *self, + const gchar *prop_name) { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::get_ibus_property_by_name" - g_return_val_if_fail (self != NULL, (IBusProperty * )0); - g_return_val_if_fail (IBUS_IS_CHEWING_ENGINE (self), (IBusProperty * )0); -{ - + g_return_val_if_fail(self != NULL, (IBusProperty *)0); + g_return_val_if_fail(IBUS_IS_CHEWING_ENGINE(self), (IBusProperty *)0); + { + if (STRING_EQUALS(prop_name, "InputMode")) { return self->InputMode; } else if (STRING_EQUALS(prop_name, "AlnumSize")) { @@ -578,206 +610,269 @@ ibus_chewing_engine_get_ibus_property_by_name (IBusChewingEngine * self, const g } else if (STRING_EQUALS(prop_name, "setup_prop")) { return self->setup_prop; } - IBUS_CHEWING_LOG(MSG, "get_ibus_property_by_name(%s): NULL is returned", prop_name); + IBUS_CHEWING_LOG(MSG, "get_ibus_property_by_name(%s): NULL is returned", + prop_name); return NULL; - }} + } +} + #undef __GOB_FUNCTION__ -static void -___b_ibus_chewing_engine_reset (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->reset) \ - (* IBUS_ENGINE_CLASS(parent_class)->reset)(___engine); } +static void ___b_ibus_chewing_engine_reset(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->reset) \ + (*IBUS_ENGINE_CLASS(parent_class)->reset)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::reset" -{ - + { + Self *self = SELF(engine); + ibus_chewing_engine_reset(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___c_ibus_chewing_engine_page_up (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->page_up) \ - (* IBUS_ENGINE_CLASS(parent_class)->page_up)(___engine); } +static void ___c_ibus_chewing_engine_page_up(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->page_up) \ + (*IBUS_ENGINE_CLASS(parent_class)->page_up)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::page_up" -{ - + { + Self *self = SELF(engine); + if (is_password(self)) return; ibus_chewing_pre_edit_process_key(self->icPreEdit, IBUS_KEY_Page_Up, 0); self_update(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___d_ibus_chewing_engine_page_down (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->page_down) \ - (* IBUS_ENGINE_CLASS(parent_class)->page_down)(___engine); } +static void ___d_ibus_chewing_engine_page_down(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->page_down) \ + (*IBUS_ENGINE_CLASS(parent_class)->page_down)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::page_down" -{ - + { + Self *self = SELF(engine); + if (is_password(self)) return; - ibus_chewing_pre_edit_process_key(self->icPreEdit, IBUS_KEY_Page_Down, 0); + ibus_chewing_pre_edit_process_key(self->icPreEdit, IBUS_KEY_Page_Down, + 0); self_update(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___e_ibus_chewing_engine_cursor_up (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->cursor_up) \ - (* IBUS_ENGINE_CLASS(parent_class)->cursor_up)(___engine); } +static void ___e_ibus_chewing_engine_cursor_up(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->cursor_up) \ + (*IBUS_ENGINE_CLASS(parent_class)->cursor_up)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::cursor_up" -{ - + { + Self *self = SELF(engine); + if (is_password(self)) return; ibus_chewing_pre_edit_process_key(self->icPreEdit, IBUS_KEY_Up, 0); self_update(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___f_ibus_chewing_engine_cursor_down (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->cursor_down) \ - (* IBUS_ENGINE_CLASS(parent_class)->cursor_down)(___engine); } +static void +___f_ibus_chewing_engine_cursor_down(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->cursor_down) \ + (*IBUS_ENGINE_CLASS(parent_class)->cursor_down)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::cursor_down" -{ - + { + Self *self = SELF(engine); + if (is_password(self)) return; ibus_chewing_pre_edit_process_key(self->icPreEdit, IBUS_KEY_Down, 0); self_update(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___10_ibus_chewing_engine_enable (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->enable) \ - (* IBUS_ENGINE_CLASS(parent_class)->enable)(___engine); } +static void ___10_ibus_chewing_engine_enable(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->enable) \ + (*IBUS_ENGINE_CLASS(parent_class)->enable)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::enable" -{ - + { + Self *self = SELF(engine); + ibus_chewing_engine_enable(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___11_ibus_chewing_engine_disable (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->disable) \ - (* IBUS_ENGINE_CLASS(parent_class)->disable)(___engine); } +static void ___11_ibus_chewing_engine_disable(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->disable) \ + (*IBUS_ENGINE_CLASS(parent_class)->disable)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::disable" -{ - + { + Self *self = SELF(engine); + ibus_chewing_engine_disable(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___12_ibus_chewing_engine_focus_in (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->focus_in) \ - (* IBUS_ENGINE_CLASS(parent_class)->focus_in)(___engine); } +static void ___12_ibus_chewing_engine_focus_in(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->focus_in) \ + (*IBUS_ENGINE_CLASS(parent_class)->focus_in)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::focus_in" -{ - + { + Self *self = SELF(engine); + ibus_chewing_engine_focus_in(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___13_ibus_chewing_engine_focus_out (IBusEngine * engine G_GNUC_UNUSED) -#define PARENT_HANDLER(___engine) \ - { if(IBUS_ENGINE_CLASS(parent_class)->focus_out) \ - (* IBUS_ENGINE_CLASS(parent_class)->focus_out)(___engine); } +static void +___13_ibus_chewing_engine_focus_out(IBusEngine *engine G_GNUC_UNUSED) +#define PARENT_HANDLER(___engine) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->focus_out) \ + (*IBUS_ENGINE_CLASS(parent_class)->focus_out)(___engine); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::focus_out" -{ - + { + Self *self = SELF(engine); + ibus_chewing_engine_focus_out(self); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___14_ibus_chewing_engine_set_capabilities (IBusEngine * engine G_GNUC_UNUSED, guint caps) -#define PARENT_HANDLER(___engine,___caps) \ - { if(IBUS_ENGINE_CLASS(parent_class)->set_capabilities) \ - (* IBUS_ENGINE_CLASS(parent_class)->set_capabilities)(___engine,___caps); } +static void +___14_ibus_chewing_engine_set_capabilities(IBusEngine *engine G_GNUC_UNUSED, + guint caps) +#define PARENT_HANDLER(___engine, ___caps) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->set_capabilities) \ + (*IBUS_ENGINE_CLASS(parent_class)->set_capabilities)(___engine, \ + ___caps); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::set_capabilities" -{ - + { + Self *self = SELF(engine); + selfp->capabilite = caps; IBUS_CHEWING_LOG(MSG, "***** set_capabilities(%x): statusFlags=%x", caps, selfp->statusFlags); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___15_ibus_chewing_engine_property_show (IBusEngine * engine G_GNUC_UNUSED, const gchar * prop_name) -#define PARENT_HANDLER(___engine,___prop_name) \ - { if(IBUS_ENGINE_CLASS(parent_class)->property_show) \ - (* IBUS_ENGINE_CLASS(parent_class)->property_show)(___engine,___prop_name); } +static void +___15_ibus_chewing_engine_property_show(IBusEngine *engine G_GNUC_UNUSED, + const gchar *prop_name) +#define PARENT_HANDLER(___engine, ___prop_name) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->property_show) \ + (*IBUS_ENGINE_CLASS(parent_class)->property_show)(___engine, \ + ___prop_name); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::property_show" -{ - + { + IBUS_CHEWING_LOG(INFO, "property_show(-, %s)", prop_name); Self *self = SELF(engine); IBusProperty *prop = self_get_ibus_property_by_name(self, prop_name); + ibus_property_set_visible(prop, TRUE); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER -static void -___16_ibus_chewing_engine_property_hide (IBusEngine * engine G_GNUC_UNUSED, const gchar * prop_name) -#define PARENT_HANDLER(___engine,___prop_name) \ - { if(IBUS_ENGINE_CLASS(parent_class)->property_hide) \ - (* IBUS_ENGINE_CLASS(parent_class)->property_hide)(___engine,___prop_name); } +static void +___16_ibus_chewing_engine_property_hide(IBusEngine *engine G_GNUC_UNUSED, + const gchar *prop_name) +#define PARENT_HANDLER(___engine, ___prop_name) \ + { \ + if (IBUS_ENGINE_CLASS(parent_class)->property_hide) \ + (*IBUS_ENGINE_CLASS(parent_class)->property_hide)(___engine, \ + ___prop_name); \ + } { #define __GOB_FUNCTION__ "IBus:Chewing:Engine::property_hide" -{ - + { + IBUS_CHEWING_LOG(INFO, "property_hide(-, %s)", prop_name); Self *self = SELF(engine); IBusProperty *prop = self_get_ibus_property_by_name(self, prop_name); + ibus_property_set_visible(prop, FALSE); - }} + } +} + #undef __GOB_FUNCTION__ #undef PARENT_HANDLER @@ -785,14 +880,13 @@ ___16_ibus_chewing_engine_property_hide (IBusEngine * engine G_GNUC_UNUSED, cons * ibus_chewing_engine_start: * @self: IBusChewingEngine instance. * - * This is different with init. This will be called in the beginning of + * This is different with init. This will be called in the beginning of * reset, enable, and focus_in for setup. */ -void ibus_chewing_engine_start(IBusChewingEngine * self) -{ +void ibus_chewing_engine_start(IBusChewingEngine *self) { #ifndef UNIT_TEST - if (!ibus_chewing_engine_has_status_flag - (self, ENGINE_FLAG_PROPERTIES_REGISTERED)) { + if (!ibus_chewing_engine_has_status_flag( + self, ENGINE_FLAG_PROPERTIES_REGISTERED)) { IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), "InputMode"); IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self), @@ -807,7 +901,6 @@ void ibus_chewing_engine_start(IBusChewingEngine * self) ibus_chewing_engine_use_setting(self); ibus_chewing_engine_restore_mode(self); ibus_chewing_engine_refresh_property_list(self); - } /** @@ -815,10 +908,10 @@ void ibus_chewing_engine_start(IBusChewingEngine * self) * @self: IBusChewingEngine instance. * * Reset the outgoing and pre_edit buffer and cursor - * chewing_reset will NOT called here, as it will chnage the KBType and input mode. + * chewing_reset will NOT called here, as it will chnage the KBType and input + * mode. */ -void ibus_chewing_engine_reset(IBusChewingEngine * self) -{ +void ibus_chewing_engine_reset(IBusChewingEngine *self) { IBUS_CHEWING_LOG(MSG, "* reset"); /* Always clean buffer */ @@ -828,31 +921,25 @@ void ibus_chewing_engine_reset(IBusChewingEngine * self) ibus_engine_hide_auxiliary_text(engine); ibus_engine_hide_lookup_table(engine); - ibus_engine_update_preedit_text(engine, - IBUS_CHEWING_ENGINE_GET_CLASS(self)->emptyText, 0, FALSE); + ibus_engine_update_preedit_text( + engine, IBUS_CHEWING_ENGINE_GET_CLASS(self)->emptyText, 0, FALSE); #endif } -void ibus_chewing_engine_enable(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* enable(): statusFlags=%x", - selfp->statusFlags); +void ibus_chewing_engine_enable(IBusChewingEngine *self) { + IBUS_CHEWING_LOG(MSG, "* enable(): statusFlags=%x", selfp->statusFlags); ibus_chewing_engine_start(self); ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_ENABLED); } -void ibus_chewing_engine_disable(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* disable(): statusFlags=%x", - selfp->statusFlags); +void ibus_chewing_engine_disable(IBusChewingEngine *self) { + IBUS_CHEWING_LOG(MSG, "* disable(): statusFlags=%x", selfp->statusFlags); ibus_chewing_engine_clear_status_flag(self, ENGINE_FLAG_ENABLED); } -void ibus_chewing_engine_focus_in(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* focus_in(): statusFlags=%x", - selfp->statusFlags); +void ibus_chewing_engine_focus_in(IBusChewingEngine *self) { + IBUS_CHEWING_LOG(MSG, "* focus_in(): statusFlags=%x", selfp->statusFlags); ibus_chewing_engine_start(self); /* Shouldn't have anything to commit when Focus-in */ ibus_chewing_pre_edit_clear(self->icPreEdit); @@ -865,17 +952,14 @@ void ibus_chewing_engine_focus_in(IBusChewingEngine * self) selfp->statusFlags); } -void ibus_chewing_engine_focus_out(IBusChewingEngine * self) -{ - IBUS_CHEWING_LOG(MSG, "* focus_out(): statusFlags=%x", - selfp->statusFlags); - ibus_chewing_engine_clear_status_flag(self, - ENGINE_FLAG_FOCUS_IN | - ENGINE_FLAG_PROPERTIES_REGISTERED); +void ibus_chewing_engine_focus_out(IBusChewingEngine *self) { + IBUS_CHEWING_LOG(MSG, "* focus_out(): statusFlags=%x", selfp->statusFlags); + ibus_chewing_engine_clear_status_flag( + self, ENGINE_FLAG_FOCUS_IN | ENGINE_FLAG_PROPERTIES_REGISTERED); ibus_chewing_engine_hide_property_list(self); - if (ibus_chewing_pre_edit_get_property_boolean - (self->icPreEdit, "clean-buffer-focus-out")) { + if (ibus_chewing_pre_edit_get_property_boolean(self->icPreEdit, + "clean-buffer-focus-out")) { /* Clean the buffer when focus out */ ibus_chewing_pre_edit_clear(self->icPreEdit); refresh_pre_edit_text(self); @@ -885,14 +969,11 @@ void ibus_chewing_engine_focus_out(IBusChewingEngine * self) IBUS_CHEWING_LOG(DEBUG, "focus_out(): return"); } - - #if IBUS_CHECK_VERSION(1, 5, 4) -void ibus_chewing_engine_set_content_type(IBusEngine * engine, - guint purpose, guint hints) -{ - IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_set_content_type(%d, %d)", - purpose, hints); +void ibus_chewing_engine_set_content_type(IBusEngine *engine, guint purpose, + guint hints) { + IBUS_CHEWING_LOG(DEBUG, "ibus_chewing_set_content_type(%d, %d)", purpose, + hints); IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); @@ -910,8 +991,7 @@ void ibus_chewing_engine_set_content_type(IBusEngine * engine, * */ -void parent_commit_text(IBusEngine * iEngine) -{ +void parent_commit_text(IBusEngine *iEngine) { IBusChewingEngine *self = IBUS_CHEWING_ENGINE(iEngine); IBUS_CHEWING_LOG(MSG, "* parent_commit_text(-): outgoingText=%s", @@ -923,37 +1003,30 @@ void parent_commit_text(IBusEngine * iEngine) #endif } -void parent_update_pre_edit_text(IBusEngine * iEngine, - IBusText * iText, guint cursor_pos, - gboolean visible) -{ +void parent_update_pre_edit_text(IBusEngine *iEngine, IBusText *iText, + guint cursor_pos, gboolean visible) { #ifdef UNIT_TEST - printf("* parent_update_pre_edit_text(-, %s, %u, %x)\n", - iText->text, cursor_pos, visible); + printf("* parent_update_pre_edit_text(-, %s, %u, %x)\n", iText->text, + cursor_pos, visible); #else ibus_engine_update_preedit_text(iEngine, iText, cursor_pos, visible); #endif } -void parent_update_pre_edit_text_with_mode(IBusEngine * iEngine, - IBusText * iText, - guint cursor_pos, - gboolean visible, - IBusPreeditFocusMode mode) -{ +void parent_update_pre_edit_text_with_mode(IBusEngine *iEngine, IBusText *iText, + guint cursor_pos, gboolean visible, + IBusPreeditFocusMode mode) { #ifdef UNIT_TEST - printf - ("* parent_update_pre_edit_text_with_mode(-, %s, %u, %x, %x)\n", - iText->text, cursor_pos, visible, mode); + printf("* parent_update_pre_edit_text_with_mode(-, %s, %u, %x, %x)\n", + iText->text, cursor_pos, visible, mode); #else - ibus_engine_update_preedit_text_with_mode - (iEngine, iText, cursor_pos, visible, mode); + ibus_engine_update_preedit_text_with_mode(iEngine, iText, cursor_pos, + visible, mode); #endif } -void parent_update_auxiliary_text(IBusEngine * iEngine, - IBusText * iText, gboolean visible) -{ +void parent_update_auxiliary_text(IBusEngine *iEngine, IBusText *iText, + gboolean visible) { #ifdef UNIT_TEST printf("* parent_update_auxiliary_text(-, %s, %x)\n", (iText) ? iText->text : "NULL", visible); @@ -967,50 +1040,42 @@ void parent_update_auxiliary_text(IBusEngine * iEngine, #endif } -IBusText *decorate_pre_edit(IBusChewingPreEdit * icPreEdit, - IBusCapabilite capabilite) -{ +IBusText *decorate_pre_edit(IBusChewingPreEdit *icPreEdit, + IBusCapabilite capabilite) { gchar *preEdit = ibus_chewing_pre_edit_get_pre_edit(icPreEdit); IBusText *iText = ibus_text_new_from_string(preEdit); gint chiSymbolCursor = chewing_cursor_Current(icPreEdit->context); - gint charLen = (gint) g_utf8_strlen(preEdit, -1); + gint charLen = (gint)g_utf8_strlen(preEdit, -1); - IBUS_CHEWING_LOG(DEBUG, "decorate_pre_edit() cursor=%d preEdit=%s charLen=%d", + IBUS_CHEWING_LOG(DEBUG, + "decorate_pre_edit() cursor=%d preEdit=%s charLen=%d", chiSymbolCursor, preEdit, charLen); /* Use single underline to mark whole pre-edit buffer */ - ibus_text_append_attribute(iText, - IBUS_ATTR_TYPE_UNDERLINE, - IBUS_ATTR_UNDERLINE_SINGLE, - 0, charLen); + ibus_text_append_attribute(iText, IBUS_ATTR_TYPE_UNDERLINE, + IBUS_ATTR_UNDERLINE_SINGLE, 0, charLen); /* Use background color to show current cursor */ if (chiSymbolCursor < charLen) { - ibus_text_append_attribute(iText, - IBUS_ATTR_TYPE_BACKGROUND, - 0x00c8c8f0, + ibus_text_append_attribute(iText, IBUS_ATTR_TYPE_BACKGROUND, 0x00c8c8f0, chiSymbolCursor, chiSymbolCursor + 1); - ibus_text_append_attribute(iText, - IBUS_ATTR_TYPE_FOREGROUND, - 0x00000000, + ibus_text_append_attribute(iText, IBUS_ATTR_TYPE_FOREGROUND, 0x00000000, chiSymbolCursor, chiSymbolCursor + 1); } return iText; } -void refresh_pre_edit_text(IBusChewingEngine * self) -{ - IBusText *iText = - decorate_pre_edit(self->icPreEdit, selfp->capabilite); +void refresh_pre_edit_text(IBusChewingEngine *self) { + IBusText *iText = decorate_pre_edit(self->icPreEdit, selfp->capabilite); + if (self->preEditText) { g_object_unref(self->preEditText); } self->preEditText = g_object_ref_sink(iText); } -void update_pre_edit_text(IBusChewingEngine * self) -{ +void update_pre_edit_text(IBusChewingEngine *self) { refresh_pre_edit_text(self); gboolean visible = TRUE; gint bpmfLen = self->icPreEdit->bpmfLen; @@ -1024,13 +1089,12 @@ void update_pre_edit_text(IBusChewingEngine * self) mode = IBUS_ENGINE_PREEDIT_COMMIT; } - parent_update_pre_edit_text_with_mode(IBUS_ENGINE(self), - self->preEditText, - cursor_current + bpmfLen, visible, mode); + parent_update_pre_edit_text_with_mode(IBUS_ENGINE(self), self->preEditText, + cursor_current + bpmfLen, visible, + mode); } -void refresh_aux_text(IBusChewingEngine * self) -{ +void refresh_aux_text(IBusChewingEngine *self) { IBUS_CHEWING_LOG(INFO, "refresh_aux_text()"); if (self->auxText != NULL) { @@ -1041,9 +1105,8 @@ void refresh_aux_text(IBusChewingEngine * self) * Use auxText to show messages from libchewing, such as "已有:". */ - gboolean showPageNumber = - ibus_chewing_pre_edit_get_property_boolean(self->icPreEdit, - "show-page-number"); + gboolean showPageNumber = ibus_chewing_pre_edit_get_property_boolean( + self->icPreEdit, "show-page-number"); if (chewing_aux_Length(self->icPreEdit->context) > 0) { IBUS_CHEWING_LOG(INFO, "update_aux_text() chewing_aux_Length=%x", @@ -1053,25 +1116,26 @@ void refresh_aux_text(IBusChewingEngine * self) IBUS_CHEWING_LOG(INFO, "update_aux_text() auxStr=%s", auxStr); self->auxText = g_object_ref_sink(ibus_text_new_from_string(auxStr)); g_free(auxStr); - } else if (showPageNumber && (chewing_cand_TotalPage(self->icPreEdit->context) > 0)) { + } else if (showPageNumber && + (chewing_cand_TotalPage(self->icPreEdit->context) > 0)) { int TotalPage = chewing_cand_TotalPage(self->icPreEdit->context); - int currentPage = chewing_cand_CurrentPage(self->icPreEdit->context) + 1; - self->auxText = g_object_ref_sink(ibus_text_new_from_printf("(%i/%i)", currentPage, TotalPage)); + int currentPage = + chewing_cand_CurrentPage(self->icPreEdit->context) + 1; + self->auxText = g_object_ref_sink( + ibus_text_new_from_printf("(%i/%i)", currentPage, TotalPage)); } else { /* clear out auxText, otherwise it will be displayed continually. */ self->auxText = g_object_ref_sink(ibus_text_new_from_static_string("")); } } -void update_aux_text(IBusChewingEngine * self) -{ +void update_aux_text(IBusChewingEngine *self) { IBUS_CHEWING_LOG(DEBUG, "update_aux_text()"); refresh_aux_text(self); parent_update_auxiliary_text(IBUS_ENGINE(self), self->auxText, TRUE); } -void update_lookup_table(IBusChewingEngine * self) -{ +void update_lookup_table(IBusChewingEngine *self) { IBUS_CHEWING_LOG(DEBUG, "update_lookup_table() CurrentPage=%d", chewing_cand_CurrentPage(self->icPreEdit->context)); @@ -1093,8 +1157,7 @@ void update_lookup_table(IBusChewingEngine * self) } } -void refresh_outgoing_text(IBusChewingEngine * self) -{ +void refresh_outgoing_text(IBusChewingEngine *self) { gchar *outgoingStr = ibus_chewing_pre_edit_get_outgoing(self->icPreEdit); IBUS_CHEWING_LOG(INFO, "refresh_outgoing_text() outgoingStr=|%s|", @@ -1109,28 +1172,26 @@ void refresh_outgoing_text(IBusChewingEngine * self) self->outgoingText->text); } -void commit_text(IBusChewingEngine * self) -{ +void commit_text(IBusChewingEngine *self) { refresh_outgoing_text(self); - if (!ibus_text_is_empty(self->outgoingText) - || !ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_FOCUS_IN)) { + if (!ibus_text_is_empty(self->outgoingText) || + !ibus_chewing_engine_has_status_flag(self, ENGINE_FLAG_FOCUS_IN)) { parent_commit_text(IBUS_ENGINE(self)); } ibus_chewing_pre_edit_clear_outgoing(self->icPreEdit); } +#include "IBusChewingProperties.h" #include "ibus-chewing-engine-private.h" #include "ibus-chewing-engine.h" -#include "IBusChewingProperties.h" -gboolean ibus_chewing_engine_process_key_event(IBusEngine * engine, - KSym keySym, guint keycode, - KeyModifiers unmaskedMod) -{ +gboolean ibus_chewing_engine_process_key_event(IBusEngine *engine, KSym keySym, + guint keycode, + KeyModifiers unmaskedMod) { IBUS_CHEWING_LOG(MSG, "******** process_key_event(-,%x(%s),%x,%x) %s", - keySym, key_sym_get_name(keySym), keycode, - unmaskedMod, modifiers_to_string(unmaskedMod)); + keySym, key_sym_get_name(keySym), keycode, unmaskedMod, + modifiers_to_string(unmaskedMod)); IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); @@ -1140,18 +1201,16 @@ gboolean ibus_chewing_engine_process_key_event(IBusEngine * engine, if (is_password(self)) return FALSE; - KSym kSym = - ibus_chewing_pre_edit_key_code_to_key_sym(self->icPreEdit, keySym, - keycode, - unmaskedMod); + KSym kSym = ibus_chewing_pre_edit_key_code_to_key_sym( + self->icPreEdit, keySym, keycode, unmaskedMod); - gboolean result = ibus_chewing_pre_edit_process_key(self->icPreEdit, kSym, - unmaskedMod); + gboolean result = + ibus_chewing_pre_edit_process_key(self->icPreEdit, kSym, unmaskedMod); IBUS_CHEWING_LOG(MSG, "process_key_event() result=%d", result); ibus_chewing_engine_update(self); - if (kSym == IBUS_KEY_Shift_L || kSym == IBUS_KEY_Shift_R || + if (kSym == IBUS_KEY_Shift_L || kSym == IBUS_KEY_Shift_R || kSym == IBUS_KEY_Caps_Lock) { /* Refresh property list (language bar) only when users toggle * Chi-Eng Mode or Shape Mode with Shift or Caps Lock, otherwise @@ -1166,12 +1225,9 @@ gboolean ibus_chewing_engine_process_key_event(IBusEngine * engine, /*=================================================== * Mouse events */ -void ibus_chewing_engine_candidate_clicked(IBusEngine * engine, - guint index, guint button, - guint state) -{ - IBUS_CHEWING_LOG(INFO, - "*** candidate_clicked(-, %x, %x, %x) ... proceed.", +void ibus_chewing_engine_candidate_clicked(IBusEngine *engine, guint index, + guint button, guint state) { + IBUS_CHEWING_LOG(INFO, "*** candidate_clicked(-, %x, %x, %x) ... proceed.", index, button, state); IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); @@ -1183,7 +1239,7 @@ void ibus_chewing_engine_candidate_clicked(IBusEngine * engine, } if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_TABLE_SHOW)) { gint *selKeys = chewing_get_selKey(self->icPreEdit->context); - KSym k = (KSym) selKeys[index]; + KSym k = (KSym)selKeys[index]; ibus_chewing_pre_edit_process_key(self->icPreEdit, k, 0); g_free(selKeys); @@ -1194,10 +1250,9 @@ void ibus_chewing_engine_candidate_clicked(IBusEngine * engine, } } -void ibus_chewing_engine_property_activate(IBusEngine * engine, - const gchar * prop_name, - guint prop_state) -{ +void ibus_chewing_engine_property_activate(IBusEngine *engine, + const gchar *prop_name, + guint prop_state) { IBUS_CHEWING_LOG(INFO, "property_activate(-, %s, %u)", prop_name, prop_state); IBusChewingEngine *self = IBUS_CHEWING_ENGINE(engine); @@ -1205,8 +1260,7 @@ void ibus_chewing_engine_property_activate(IBusEngine * engine, if (STRING_EQUALS(prop_name, "InputMode")) { /* Toggle Chinese <-> English */ ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit); - IBUS_CHEWING_LOG(INFO, - "property_activate chinese=%d", + IBUS_CHEWING_LOG(INFO, "property_activate chinese=%d", ibus_chewing_engine_is_chinese_mode(self)); ibus_chewing_engine_refresh_property(self, prop_name); } else if (STRING_EQUALS(prop_name, "AlnumSize")) { @@ -1218,9 +1272,7 @@ void ibus_chewing_engine_property_activate(IBusEngine * engine, /* open preferences window */ system(QUOTE_ME(LIBEXEC_DIR) "/ibus-setup-chewing"); } else { - IBUS_CHEWING_LOG(DEBUG, - "property_activate(-, %s, %u) not recognized", + IBUS_CHEWING_LOG(DEBUG, "property_activate(-, %s, %u) not recognized", prop_name, prop_state); } - } diff --git a/src/ibus-chewing-engine.h b/src/ibus-chewing-engine.h index 32afc88..777f3f8 100644 --- a/src/ibus-chewing-engine.h +++ b/src/ibus-chewing-engine.h @@ -16,25 +16,26 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ -#include -#include -#include #include -#include +#include +#include #include +#include +#include #define GETTEXT_PACKAGE "gtk30" -#include -#include -#include -#include "IBusChewingUtil.h" -#include "IBusChewingProperties.h" -#include "IBusChewingPreEdit.h" #include "GSettingsBackend.h" +#include "IBusChewingPreEdit.h" +#include "IBusChewingProperties.h" +#include "IBusChewingUtil.h" +#include +#include +#include -#include #include +#include #ifndef __IBUS_CHEWING_ENGINE_H__ #define __IBUS_CHEWING_ENGINE_H__ @@ -42,26 +43,22 @@ extern "C" { #endif /* __cplusplus */ - typedef enum { - CHEWING_INPUT_STYLE_IN_APPLICATION, - CHEWING_INPUT_STYLE_IN_CANDIDATE + CHEWING_INPUT_STYLE_IN_APPLICATION, + CHEWING_INPUT_STYLE_IN_CANDIDATE } ChewingInputStyle; #define CHEWING_TYPE_INPUT_STYLE chewing_input_style_get_type() -GType chewing_input_style_get_type (void) G_GNUC_CONST; - +GType chewing_input_style_get_type(void) G_GNUC_CONST; typedef enum { - ENGINE_FLAG_INITIALIZED = 0x1, - ENGINE_FLAG_ENABLED = 0x2, - ENGINE_FLAG_FOCUS_IN = 0x4, - ENGINE_FLAG_IS_PASSWORD = 0x8, - ENGINE_FLAG_PROPERTIES_REGISTERED = 0x10 + ENGINE_FLAG_INITIALIZED = 0x1, + ENGINE_FLAG_ENABLED = 0x2, + ENGINE_FLAG_FOCUS_IN = 0x4, + ENGINE_FLAG_IS_PASSWORD = 0x8, + ENGINE_FLAG_PROPERTIES_REGISTERED = 0x10 } EngineFlag; #define ENGINE_TYPE_FLAG engine_flag_get_type() -GType engine_flag_get_type (void) G_GNUC_CONST; - - +GType engine_flag_get_type(void) G_GNUC_CONST; extern MkdgPropertySpec propSpecs[]; extern const gchar *page_labels[]; @@ -70,17 +67,25 @@ extern GtkResponseType button_responses[]; #define cursor_current chewing_cursor_Current(self->icPreEdit->context) - /* * Type checking and casting macros */ -#define IBUS_TYPE_CHEWING_ENGINE (ibus_chewing_engine_get_type()) -#define IBUS_CHEWING_ENGINE(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), ibus_chewing_engine_get_type(), IBusChewingEngine) -#define IBUS_CHEWING_ENGINE_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), ibus_chewing_engine_get_type(), IBusChewingEngine const) -#define IBUS_CHEWING_ENGINE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), ibus_chewing_engine_get_type(), IBusChewingEngineClass) -#define IBUS_IS_CHEWING_ENGINE(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), ibus_chewing_engine_get_type ()) - -#define IBUS_CHEWING_ENGINE_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), ibus_chewing_engine_get_type(), IBusChewingEngineClass) +#define IBUS_TYPE_CHEWING_ENGINE (ibus_chewing_engine_get_type()) +#define IBUS_CHEWING_ENGINE(obj) \ + G_TYPE_CHECK_INSTANCE_CAST((obj), ibus_chewing_engine_get_type(), \ + IBusChewingEngine) +#define IBUS_CHEWING_ENGINE_CONST(obj) \ + G_TYPE_CHECK_INSTANCE_CAST((obj), ibus_chewing_engine_get_type(), \ + IBusChewingEngine const) +#define IBUS_CHEWING_ENGINE_CLASS(klass) \ + G_TYPE_CHECK_CLASS_CAST((klass), ibus_chewing_engine_get_type(), \ + IBusChewingEngineClass) +#define IBUS_IS_CHEWING_ENGINE(obj) \ + G_TYPE_CHECK_INSTANCE_TYPE((obj), ibus_chewing_engine_get_type()) + +#define IBUS_CHEWING_ENGINE_GET_CLASS(obj) \ + G_TYPE_INSTANCE_GET_CLASS((obj), ibus_chewing_engine_get_type(), \ + IBusChewingEngineClass) /* Private structure type */ typedef struct _IBusChewingEnginePrivate IBusChewingEnginePrivate; @@ -93,20 +98,20 @@ typedef struct _IBusChewingEnginePrivate IBusChewingEnginePrivate; typedef struct _IBusChewingEngine IBusChewingEngine; #endif struct _IBusChewingEngine { - IBusEngine __parent__; - /*< public >*/ - IBusChewingPreEdit * icPreEdit; - GtkWidget * sDialog; - IBusText * preEditText; - IBusText * auxText; - IBusText * outgoingText; - IBusProperty * InputMode; - IBusProperty * AlnumSize; - IBusProperty * setup_prop; - IBusPropList * prop_list; - /*< private >*/ - FILE * logFile; /* protected */ - IBusKeymap * keymap_us; /* protected */ + IBusEngine __parent__; + /*< public > */ + IBusChewingPreEdit *icPreEdit; + GtkWidget *sDialog; + IBusText *preEditText; + IBusText *auxText; + IBusText *outgoingText; + IBusProperty *InputMode; + IBusProperty *AlnumSize; + IBusProperty *setup_prop; + IBusPropList *prop_list; + /*< private > */ + FILE *logFile; /* protected */ + IBusKeymap *keymap_us; /* protected */ }; /* @@ -114,45 +119,39 @@ struct _IBusChewingEngine { */ typedef struct _IBusChewingEngineClass IBusChewingEngineClass; struct _IBusChewingEngineClass { - IBusEngineClass __parent__; - IBusText * InputMode_label_chi; - IBusText * InputMode_label_eng; - IBusText * InputMode_tooltip; - IBusText * InputMode_symbol_chi; - IBusText * InputMode_symbol_eng; - IBusText * AlnumSize_label_full; - IBusText * AlnumSize_label_half; - IBusText * AlnumSize_tooltip; - IBusText * AlnumSize_symbol_full; - IBusText * AlnumSize_symbol_half; - IBusText * setup_prop_label; - IBusText * setup_prop_tooltip; - IBusText * setup_prop_symbol; - IBusText * emptyText; + IBusEngineClass __parent__; + IBusText *InputMode_label_chi; + IBusText *InputMode_label_eng; + IBusText *InputMode_tooltip; + IBusText *InputMode_symbol_chi; + IBusText *InputMode_symbol_eng; + IBusText *AlnumSize_label_full; + IBusText *AlnumSize_label_half; + IBusText *AlnumSize_tooltip; + IBusText *AlnumSize_symbol_full; + IBusText *AlnumSize_symbol_half; + IBusText *setup_prop_label; + IBusText *setup_prop_tooltip; + IBusText *setup_prop_symbol; + IBusText *emptyText; }; - /* * Public methods */ -GType ibus_chewing_engine_get_type (void) G_GNUC_CONST; -void ibus_chewing_engine_refresh_property_list (IBusChewingEngine * self); -void ibus_chewing_engine_hide_property_list (IBusChewingEngine * self); - +GType ibus_chewing_engine_get_type(void) G_GNUC_CONST; +void ibus_chewing_engine_refresh_property_list(IBusChewingEngine *self); +void ibus_chewing_engine_hide_property_list(IBusChewingEngine *self); void ibus_chewing_engine_reset(IBusChewingEngine *self); void ibus_chewing_engine_enable(IBusChewingEngine *self); void ibus_chewing_engine_disable(IBusChewingEngine *self); void ibus_chewing_engine_focus_in(IBusChewingEngine *self); void ibus_chewing_engine_focus_out(IBusChewingEngine *self); -gboolean ibus_chewing_engine_process_key_event(IBusEngine *self, - guint key_sym, - guint keycode, - guint modifiers); - +gboolean ibus_chewing_engine_process_key_event(IBusEngine *self, guint key_sym, + guint keycode, guint modifiers); #ifdef __cplusplus } #endif /* __cplusplus */ - #endif diff --git a/src/main.c b/src/main.c index 1be5dfd..595ebee 100644 --- a/src/main.c +++ b/src/main.c @@ -17,16 +17,17 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ -#include -#include -#include +#include "IBusChewingUtil.h" +#include "ibus-chewing-engine.h" #include #include -#include "ibus-chewing-engine.h" -#include "IBusChewingUtil.h" +#include +#include +#include static IBusBus *bus = NULL; static IBusFactory *factory = NULL; @@ -37,12 +38,11 @@ static gboolean ibus = FALSE; static gboolean xml = FALSE; gint ibus_chewing_verbose = VERBOSE_LEVEL; - static const GOptionEntry entries[] = { {"show_flags", 's', 0, G_OPTION_ARG_NONE, &showFlags, "Show compile flag only", NULL}, - {"ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, - "component is executed by ibus", NULL}, + {"ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", + NULL}, {"verbose", 'v', 0, G_OPTION_ARG_INT, &ibus_chewing_verbose, "Verbose level. The higher the level, the more the debug messages.", "[integer]"}, @@ -51,15 +51,12 @@ static const GOptionEntry entries[] = { {NULL}, }; - -static void ibus_disconnected_cb(IBusBus * bus, gpointer user_data) -{ +static void ibus_disconnected_cb(IBusBus *bus, gpointer user_data) { g_debug("bus disconnected"); ibus_quit(); } -static void start_component(void) -{ +static void start_component(void) { IBUS_CHEWING_LOG(INFO, "start_component"); ibus_init(); bus = ibus_bus_new(); @@ -74,33 +71,25 @@ static void start_component(void) IBusComponent *component = NULL; if (xml) { - component = ibus_component_new_from_file(QUOTE_ME(DATA_DIR) - "/ibus/component/chewing.xml"); + component = ibus_component_new_from_file( + QUOTE_ME(DATA_DIR) "/ibus/component/chewing.xml"); } else { - component = ibus_component_new(QUOTE_ME(PROJECT_SCHEMA_ID), - _("Chewing component"), - QUOTE_ME(PRJ_VER), "GPLv2+", - _("Peng Huang, Ding-Yi Chen"), - "http://code.google.com/p/ibus", - QUOTE_ME(LIBEXEC_DIR) - "/ibus-engine-chewing --ibus", - QUOTE_ME(PROJECT_NAME)); + component = ibus_component_new( + QUOTE_ME(PROJECT_SCHEMA_ID), _("Chewing component"), + QUOTE_ME(PRJ_VER), "GPLv2+", _("Peng Huang, Ding-Yi Chen"), + "http://code.google.com/p/ibus", + QUOTE_ME(LIBEXEC_DIR) "/ibus-engine-chewing --ibus", + QUOTE_ME(PROJECT_NAME)); } - IBusEngineDesc *engineDesc = - ibus_engine_desc_new_varargs - ("name", "chewing", - "longname", _("Chewing"), - "description", _("Chinese chewing input method"), - "language", "zh_TW", - "license", "GPLv2+", - "author", _("Peng Huang, Ding-Yi Chen"), - "icon", QUOTE_ME(PRJ_DATA_DIR)"/icons/"QUOTE_ME(PROJECT_NAME)".png", - "layout", "us", - "setup", QUOTE_ME(LIBEXEC_DIR)"/ibus-setup-chewing", - "version", QUOTE_ME(PRJ_VER), - "textdomain", QUOTE_ME(PROJECT_NAME), - NULL); + IBusEngineDesc *engineDesc = ibus_engine_desc_new_varargs( + "name", "chewing", "longname", _("Chewing"), "description", + _("Chinese chewing input method"), "language", "zh_TW", "license", + "GPLv2+", "author", _("Peng Huang, Ding-Yi Chen"), "icon", + QUOTE_ME(PRJ_DATA_DIR) "/icons/" QUOTE_ME(PROJECT_NAME) ".png", + "layout", "us", "setup", QUOTE_ME(LIBEXEC_DIR) "/ibus-setup-chewing", + "version", QUOTE_ME(PRJ_VER), "textdomain", QUOTE_ME(PROJECT_NAME), + NULL); ibus_component_add_engine(component, engineDesc); @@ -119,18 +108,12 @@ static void start_component(void) ibus_main(); } -const char *locale_env_strings[] = { - "LC_ALL", - "LANG", - "LANGUAGE", - "GDM_LANG", - NULL -}; +const char *locale_env_strings[] = {"LC_ALL", "LANG", "LANGUAGE", "GDM_LANG", + NULL}; -void determine_locale() -{ +void determine_locale() { #ifndef STRING_BUFFER_SIZE -# define STRING_BUFFER_SIZE 100 +#define STRING_BUFFER_SIZE 100 #endif gchar *localePtr = NULL; gchar localeStr[STRING_BUFFER_SIZE]; @@ -158,9 +141,7 @@ void determine_locale() IBUS_CHEWING_LOG(INFO, "determine_locale %s", localeStr); } - -int main(gint argc, gchar * argv[]) -{ +int main(gint argc, gchar *argv[]) { GError *error = NULL; GOptionContext *context; @@ -187,8 +168,7 @@ int main(gint argc, gchar * argv[]) if (showFlags) { printf("PROJECT_NAME=" QUOTE_ME(PROJECT_NAME) "\n"); printf("DATA_DIR=" QUOTE_ME(DATA_DIR) "\n"); - printf("CHEWING_DATADIR_REAL=" QUOTE_ME(CHEWING_DATADIR_REAL) - "\n"); + printf("CHEWING_DATADIR_REAL=" QUOTE_ME(CHEWING_DATADIR_REAL) "\n"); } else { start_component(); } diff --git a/src/setup/ibus-setup-chewing-application.c b/src/setup/ibus-setup-chewing-application.c index 4eb837a..e7e3666 100644 --- a/src/setup/ibus-setup-chewing-application.c +++ b/src/setup/ibus-setup-chewing-application.c @@ -27,7 +27,6 @@ struct _IbusSetupChewingApplication { G_DEFINE_TYPE(IbusSetupChewingApplication, ibus_setup_chewing_application, ADW_TYPE_APPLICATION) - IbusSetupChewingApplication * ibus_setup_chewing_application_new(const char *application_id, GApplicationFlags flags) { diff --git a/src/setup/ibus-setup-chewing-application.h b/src/setup/ibus-setup-chewing-application.h index 0f37b4e..d97fc85 100644 --- a/src/setup/ibus-setup-chewing-application.h +++ b/src/setup/ibus-setup-chewing-application.h @@ -23,14 +23,11 @@ #include G_BEGIN_DECLS - #define IBUS_SETUP_CHEWING_TYPE_APPLICATION \ (ibus_setup_chewing_application_get_type()) - G_DECLARE_FINAL_TYPE(IbusSetupChewingApplication, ibus_setup_chewing_application, IBUS_SETUP_CHEWING, APPLICATION, AdwApplication) - IbusSetupChewingApplication * ibus_setup_chewing_application_new(const char *application_id, GApplicationFlags flags); diff --git a/src/setup/ibus-setup-chewing-window.c b/src/setup/ibus-setup-chewing-window.c index ba2769a..195e2be 100644 --- a/src/setup/ibus-setup-chewing-window.c +++ b/src/setup/ibus-setup-chewing-window.c @@ -46,11 +46,9 @@ struct _IbusSetupChewingWindow { G_DEFINE_FINAL_TYPE(IbusSetupChewingWindow, ibus_setup_chewing_window, ADW_TYPE_PREFERENCES_WINDOW) - #define bind_child(child_id) \ gtk_widget_class_bind_template_child(widget_class, IbusSetupChewingWindow, \ child_id) - static void ibus_setup_chewing_window_class_init(IbusSetupChewingWindowClass *klass) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); @@ -132,6 +130,7 @@ static GVariant *id_set_mapping(const GValue *value, const GVariantType *expected_type, gpointer user_data) { gchar **ids_list = (gchar **)user_data; + return g_variant_new_string(ids_list[g_value_get_uint(value)]); } diff --git a/src/setup/ibus-setup-chewing-window.h b/src/setup/ibus-setup-chewing-window.h index 112a119..067e74f 100644 --- a/src/setup/ibus-setup-chewing-window.h +++ b/src/setup/ibus-setup-chewing-window.h @@ -23,10 +23,7 @@ #include G_BEGIN_DECLS - #define IBUS_SETUP_CHEWING_TYPE_WINDOW (ibus_setup_chewing_window_get_type()) - G_DECLARE_FINAL_TYPE(IbusSetupChewingWindow, ibus_setup_chewing_window, IBUS_SETUP_CHEWING, WINDOW, AdwPreferencesWindow) - G_END_DECLS diff --git a/src/setup/main.c b/src/setup/main.c index 3599dea..d0ce8fb 100644 --- a/src/setup/main.c +++ b/src/setup/main.c @@ -40,6 +40,7 @@ static void application_quit(gpointer user_data) { int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; + g_autoptr(IbusSetupChewingApplication) app = NULL; int ret; diff --git a/test/IBusChewingPreEdit-test.c b/test/IBusChewingPreEdit-test.c index 6b79a1f..bba1c7e 100644 --- a/test/IBusChewingPreEdit-test.c +++ b/test/IBusChewingPreEdit-test.c @@ -1,48 +1,48 @@ -#include #include +#include + +#include "GSettingsBackend.h" #include "IBusChewingPreEdit.h" -#include "IBusChewingPreEdit-private.h" #include "IBusChewingUtil.h" -#include "GSettingsBackend.h" #include "MakerDialogUtil.h" #include "test-util.h" + +#include "IBusChewingPreEdit-private.h" + #define TEST_RUN_THIS(f) add_test_case("IBusChewingPreEdit", f) -#define TEST_CASE_INIT() reset_properties_default(self);\ - ibus_chewing_pre_edit_clear(self);\ - ibus_chewing_pre_edit_set_full_half_mode(self,FALSE);\ - ibus_chewing_pre_edit_set_chi_eng_mode(self,TRUE) +#define TEST_CASE_INIT() \ + reset_properties_default(self); \ + ibus_chewing_pre_edit_clear(self); \ + ibus_chewing_pre_edit_set_full_half_mode(self, FALSE); \ + ibus_chewing_pre_edit_set_chi_eng_mode(self, TRUE) static IBusChewingPreEdit *self = NULL; /*== Utility functions start ==*/ -#define assert_pre_edit_substring(needle, begin, length) assert_substring(ibus_chewing_pre_edit_get_pre_edit(self), needle, begin, length) - - +#define assert_pre_edit_substring(needle, begin, length) \ + assert_substring(ibus_chewing_pre_edit_get_pre_edit(self), needle, begin, \ + length) -void assert_outgoing_pre_edit(const gchar * outgoing, const gchar * pre_edit) -{ +void assert_outgoing_pre_edit(const gchar *outgoing, const gchar *pre_edit) { g_assert_cmpstr(outgoing, ==, ibus_chewing_pre_edit_get_outgoing(self)); g_assert_cmpstr(pre_edit, ==, ibus_chewing_pre_edit_get_pre_edit(self)); } -void assert_substring(const gchar * haystack, const gchar * needle, - gint begin, gint length) -{ +void assert_substring(const gchar *haystack, const gchar *needle, gint begin, + gint length) { gchar *subStr = g_utf8_substring(haystack, begin, begin + length); g_assert_cmpstr(subStr, ==, needle); g_free(subStr); } -void key_press_from_key_sym(KSym keySym, KeyModifiers modifiers) -{ +void key_press_from_key_sym(KSym keySym, KeyModifiers modifiers) { switch (keySym) { case IBUS_KEY_Shift_L: case IBUS_KEY_Shift_R: ibus_chewing_pre_edit_process_key(self, keySym, modifiers); - ibus_chewing_pre_edit_process_key(self, keySym, - modifiers | IBUS_RELEASE_MASK | - IBUS_SHIFT_MASK); + ibus_chewing_pre_edit_process_key( + self, keySym, modifiers | IBUS_RELEASE_MASK | IBUS_SHIFT_MASK); break; default: if (modifiers & IBUS_SHIFT_MASK) { @@ -52,32 +52,27 @@ void key_press_from_key_sym(KSym keySym, KeyModifiers modifiers) ibus_chewing_pre_edit_process_key(self, keySym, modifiers | IBUS_RELEASE_MASK); if (modifiers & IBUS_SHIFT_MASK) { - ibus_chewing_pre_edit_process_key(self, IBUS_KEY_Shift_L, - IBUS_SHIFT_MASK | - IBUS_RELEASE_MASK); + ibus_chewing_pre_edit_process_key( + self, IBUS_KEY_Shift_L, IBUS_SHIFT_MASK | IBUS_RELEASE_MASK); } break; - } - printf - ("key_press_from_key_sym(%x(%s),%x), buffer=|%s| outgoing=|%s|\n", - keySym, key_sym_get_name(keySym), modifiers, - ibus_chewing_pre_edit_get_pre_edit(self), - ibus_chewing_pre_edit_get_outgoing(self)); + printf("key_press_from_key_sym(%x(%s),%x), buffer=|%s| outgoing=|%s|\n", + keySym, key_sym_get_name(keySym), modifiers, + ibus_chewing_pre_edit_get_pre_edit(self), + ibus_chewing_pre_edit_get_outgoing(self)); } -void key_press_from_string(const gchar * keySeq) -{ +void key_press_from_string(const gchar *keySeq) { gint i; for (i = 0; i < strlen(keySeq); i++) { - key_press_from_key_sym((guint) keySeq[i], 0); + key_press_from_key_sym((guint)keySeq[i], 0); } } -void reset_properties_default(IBusChewingPreEdit * self) -{ +void reset_properties_default(IBusChewingPreEdit *self) { gsize size = mkdg_properties_size(self->iProperties->properties); for (gsize i = 0; i < size; i++) { @@ -88,73 +83,63 @@ void reset_properties_default(IBusChewingPreEdit * self) } /*== Unit cases start ==*/ -EventResponse filter_modifiers_test_0_0() -{ +EventResponse filter_modifiers_test_0_0() { KeyModifiers allow = 0, unmaskedMod = 0; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } -EventResponse filter_modifiers_test_0_shift() -{ +EventResponse filter_modifiers_test_0_shift() { KeyModifiers allow = 0, unmaskedMod = IBUS_SHIFT_MASK; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } -EventResponse filter_modifiers_test_0_control() -{ +EventResponse filter_modifiers_test_0_control() { KeyModifiers allow = 0, unmaskedMod = IBUS_CONTROL_MASK; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } -EventResponse filter_modifiers_test_0_shift_control() -{ +EventResponse filter_modifiers_test_0_shift_control() { KeyModifiers allow = 0, unmaskedMod = IBUS_SHIFT_MASK | IBUS_CONTROL_MASK; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } -EventResponse filter_modifiers_test_shift_0() -{ +EventResponse filter_modifiers_test_shift_0() { KeyModifiers allow = IBUS_SHIFT_MASK, unmaskedMod = 0; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } -EventResponse filter_modifiers_test_shift_shift() -{ +EventResponse filter_modifiers_test_shift_shift() { KeyModifiers allow = IBUS_SHIFT_MASK, unmaskedMod = IBUS_SHIFT_MASK; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } -EventResponse filter_modifiers_test_shift_control() -{ +EventResponse filter_modifiers_test_shift_control() { KeyModifiers allow = IBUS_SHIFT_MASK, unmaskedMod = IBUS_CONTROL_MASK; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } -EventResponse filter_modifiers_test_shift_shift_control() -{ - KeyModifiers allow = IBUS_SHIFT_MASK, unmaskedMod = - IBUS_SHIFT_MASK | IBUS_CONTROL_MASK; +EventResponse filter_modifiers_test_shift_shift_control() { + KeyModifiers allow = IBUS_SHIFT_MASK, + unmaskedMod = IBUS_SHIFT_MASK | IBUS_CONTROL_MASK; filter_modifiers(allow); return EVENT_RESPONSE_PROCESS; } - -void filter_modifiers_test() -{ +void filter_modifiers_test() { g_assert(filter_modifiers_test_0_0() == EVENT_RESPONSE_PROCESS); g_assert(filter_modifiers_test_0_shift() == EVENT_RESPONSE_IGNORE); g_assert(filter_modifiers_test_0_control() == EVENT_RESPONSE_IGNORE); @@ -167,8 +152,7 @@ void filter_modifiers_test() EVENT_RESPONSE_IGNORE); } -void self_key_sym_fix_test() -{ +void self_key_sym_fix_test() { ibus_chewing_pre_edit_set_chi_eng_mode(self, FALSE); ibus_chewing_pre_edit_set_property_string(self, "chi-eng-mode-toggle", @@ -183,13 +167,12 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'A', IBUS_SHIFT_MASK) == 'A'); g_assert(self_key_sym_fix(self, 'a', IBUS_LOCK_MASK) == 'a'); g_assert(self_key_sym_fix(self, 'A', IBUS_LOCK_MASK) == 'A'); - g_assert(self_key_sym_fix(self, 'a', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'a'); - g_assert(self_key_sym_fix(self, 'A', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'A'); + g_assert(self_key_sym_fix(self, 'a', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'a'); + g_assert(self_key_sym_fix(self, 'A', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'A'); - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "lowercase"); g_assert(self_key_sym_fix(self, '2', 0) == '2'); g_assert(self_key_sym_fix(self, 'b', 0) == 'b'); @@ -198,13 +181,12 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'B', IBUS_SHIFT_MASK) == 'B'); g_assert(self_key_sym_fix(self, 'b', IBUS_LOCK_MASK) == 'b'); g_assert(self_key_sym_fix(self, 'B', IBUS_LOCK_MASK) == 'b'); - g_assert(self_key_sym_fix(self, 'b', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'B'); - g_assert(self_key_sym_fix(self, 'B', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'B'); + g_assert(self_key_sym_fix(self, 'b', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'B'); + g_assert(self_key_sym_fix(self, 'B', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'B'); - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "uppercase"); g_assert(self_key_sym_fix(self, 'c', 0) == 'C'); g_assert(self_key_sym_fix(self, 'C', 0) == 'C'); @@ -212,10 +194,10 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'C', IBUS_SHIFT_MASK) == 'c'); g_assert(self_key_sym_fix(self, 'c', IBUS_LOCK_MASK) == 'C'); g_assert(self_key_sym_fix(self, 'C', IBUS_LOCK_MASK) == 'C'); - g_assert(self_key_sym_fix(self, 'c', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'c'); - g_assert(self_key_sym_fix(self, 'C', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'c'); + g_assert(self_key_sym_fix(self, 'c', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'c'); + g_assert(self_key_sym_fix(self, 'C', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'c'); ibus_chewing_pre_edit_set_property_string(self, "chi-eng-mode-toggle", "shift"); @@ -228,14 +210,13 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK) == 'D'); g_assert(self_key_sym_fix(self, 'd', IBUS_LOCK_MASK) == 'd'); g_assert(self_key_sym_fix(self, 'D', IBUS_LOCK_MASK) == 'D'); - g_assert(self_key_sym_fix(self, 'd', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'd'); - g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'D'); + g_assert(self_key_sym_fix(self, 'd', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'd'); + g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'D'); /* This should act as "no control" */ - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "lowercase"); g_assert(self_key_sym_fix(self, 'd', 0) == 'd'); g_assert(self_key_sym_fix(self, 'D', 0) == 'D'); @@ -243,14 +224,13 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK) == 'D'); g_assert(self_key_sym_fix(self, 'd', IBUS_LOCK_MASK) == 'd'); g_assert(self_key_sym_fix(self, 'D', IBUS_LOCK_MASK) == 'D'); - g_assert(self_key_sym_fix(self, 'd', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'd'); - g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'D'); + g_assert(self_key_sym_fix(self, 'd', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'd'); + g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'D'); /* This should act as "no control" */ - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "uppercase"); g_assert(self_key_sym_fix(self, 'd', 0) == 'd'); g_assert(self_key_sym_fix(self, 'D', 0) == 'D'); @@ -258,10 +238,10 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK) == 'D'); g_assert(self_key_sym_fix(self, 'd', IBUS_LOCK_MASK) == 'd'); g_assert(self_key_sym_fix(self, 'D', IBUS_LOCK_MASK) == 'D'); - g_assert(self_key_sym_fix(self, 'd', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'd'); - g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'D'); + g_assert(self_key_sym_fix(self, 'd', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'd'); + g_assert(self_key_sym_fix(self, 'D', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'D'); /* In Chinese mode, the case should be determine by the shift, not the * case itself. @@ -281,13 +261,12 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'E', IBUS_SHIFT_MASK) == 'E'); g_assert(self_key_sym_fix(self, 'e', IBUS_LOCK_MASK) == 'e'); g_assert(self_key_sym_fix(self, 'E', IBUS_LOCK_MASK) == 'e'); - g_assert(self_key_sym_fix(self, 'e', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'E'); - g_assert(self_key_sym_fix(self, 'E', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'E'); + g_assert(self_key_sym_fix(self, 'e', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'E'); + g_assert(self_key_sym_fix(self, 'E', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'E'); - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "lowercase"); g_assert(self_key_sym_fix(self, 'f', 0) == 'f'); g_assert(self_key_sym_fix(self, 'F', 0) == 'f'); @@ -295,13 +274,12 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'F', IBUS_SHIFT_MASK) == 'F'); g_assert(self_key_sym_fix(self, 'f', IBUS_LOCK_MASK) == 'f'); g_assert(self_key_sym_fix(self, 'F', IBUS_LOCK_MASK) == 'f'); - g_assert(self_key_sym_fix(self, 'f', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'F'); - g_assert(self_key_sym_fix(self, 'F', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'F'); + g_assert(self_key_sym_fix(self, 'f', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'F'); + g_assert(self_key_sym_fix(self, 'F', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'F'); - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "uppercase"); g_assert(self_key_sym_fix(self, 'g', 0) == 'g'); g_assert(self_key_sym_fix(self, 'G', 0) == 'g'); @@ -309,10 +287,10 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'G', IBUS_SHIFT_MASK) == 'G'); g_assert(self_key_sym_fix(self, 'g', IBUS_LOCK_MASK) == 'g'); g_assert(self_key_sym_fix(self, 'G', IBUS_LOCK_MASK) == 'g'); - g_assert(self_key_sym_fix(self, 'g', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'G'); - g_assert(self_key_sym_fix(self, 'G', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'G'); + g_assert(self_key_sym_fix(self, 'g', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'G'); + g_assert(self_key_sym_fix(self, 'G', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'G'); ibus_chewing_pre_edit_set_property_string(self, "chi-eng-mode-toggle", "shift"); @@ -325,13 +303,12 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'H', IBUS_SHIFT_MASK) == 'H'); g_assert(self_key_sym_fix(self, 'h', IBUS_LOCK_MASK) == 'h'); g_assert(self_key_sym_fix(self, 'H', IBUS_LOCK_MASK) == 'h'); - g_assert(self_key_sym_fix(self, 'h', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'H'); - g_assert(self_key_sym_fix(self, 'H', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'H'); + g_assert(self_key_sym_fix(self, 'h', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'H'); + g_assert(self_key_sym_fix(self, 'H', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'H'); - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "lowercase"); g_assert(self_key_sym_fix(self, 'i', 0) == 'i'); g_assert(self_key_sym_fix(self, 'I', 0) == 'i'); @@ -339,13 +316,12 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'I', IBUS_SHIFT_MASK) == 'I'); g_assert(self_key_sym_fix(self, 'i', IBUS_LOCK_MASK) == 'i'); g_assert(self_key_sym_fix(self, 'I', IBUS_LOCK_MASK) == 'i'); - g_assert(self_key_sym_fix(self, 'i', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'I'); - g_assert(self_key_sym_fix(self, 'I', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'I'); + g_assert(self_key_sym_fix(self, 'i', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'I'); + g_assert(self_key_sym_fix(self, 'I', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'I'); - ibus_chewing_pre_edit_set_property_string(self, - "default-english-case", + ibus_chewing_pre_edit_set_property_string(self, "default-english-case", "uppercase"); g_assert(self_key_sym_fix(self, 'j', 0) == 'j'); g_assert(self_key_sym_fix(self, 'J', 0) == 'j'); @@ -353,14 +329,13 @@ void self_key_sym_fix_test() g_assert(self_key_sym_fix(self, 'J', IBUS_SHIFT_MASK) == 'J'); g_assert(self_key_sym_fix(self, 'j', IBUS_LOCK_MASK) == 'j'); g_assert(self_key_sym_fix(self, 'J', IBUS_LOCK_MASK) == 'j'); - g_assert(self_key_sym_fix(self, 'j', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'J'); - g_assert(self_key_sym_fix(self, 'J', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) - == 'J'); + g_assert(self_key_sym_fix(self, 'j', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'J'); + g_assert(self_key_sym_fix(self, 'J', IBUS_SHIFT_MASK | IBUS_LOCK_MASK) == + 'J'); } -void self_handle_key_sym_default_test() -{ +void self_handle_key_sym_default_test() { TEST_CASE_INIT(); EventResponse eResponse = self_handle_key_sym_default(self, 'q', 0); @@ -406,14 +381,10 @@ void self_handle_key_sym_default_test() } /*== Test cases start ==*/ -void free_test() -{ - ibus_chewing_pre_edit_free(self); -} +void free_test() { ibus_chewing_pre_edit_free(self); } /* Chinese mode: "中文" (5j/ jp6) and Enter*/ -void process_key_normal_test() -{ +void process_key_normal_test() { TEST_CASE_INIT(); key_press_from_string("5j/ jp6"); assert_outgoing_pre_edit("", "中文"); @@ -424,12 +395,10 @@ void process_key_normal_test() ibus_chewing_pre_edit_clear(self); assert_outgoing_pre_edit("", ""); - } /* 他不重,他是我兄弟。 */ -void process_key_text_with_symbol_test() -{ +void process_key_text_with_symbol_test() { TEST_CASE_INIT(); key_press_from_string("w8 "); key_press_from_key_sym(IBUS_KEY_Down, 0); @@ -454,8 +423,7 @@ void process_key_text_with_symbol_test() /* Mix english and chinese */ /* "這是ibus-chewing 輸入法"*/ -void process_key_mix_test() -{ +void process_key_mix_test() { TEST_CASE_INIT(); ibus_chewing_pre_edit_set_property_string(self, "chi-eng-mode-toggle", @@ -473,8 +441,7 @@ void process_key_mix_test() assert_outgoing_pre_edit("", ""); } -void process_key_incomplete_char_test() -{ +void process_key_incomplete_char_test() { TEST_CASE_INIT(); key_press_from_string("u"); ibus_chewing_pre_edit_force_commit(self); @@ -484,8 +451,7 @@ void process_key_incomplete_char_test() assert_outgoing_pre_edit("", ""); } -void process_key_buffer_full_handling_test() -{ +void process_key_buffer_full_handling_test() { TEST_CASE_INIT(); key_press_from_string("ji3ru8 ap6fu06u.3vul3ck6"); key_press_from_key_sym(IBUS_KEY_less, IBUS_SHIFT_MASK); @@ -498,14 +464,12 @@ void process_key_buffer_full_handling_test() } /* 程式 */ -void process_key_down_arrow_test() -{ +void process_key_down_arrow_test() { TEST_CASE_INIT(); - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "plain-zhuyin", FALSE); - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "phrase-choice-from-last", - TRUE); + ibus_chewing_pre_edit_set_apply_property_boolean(self, "plain-zhuyin", + FALSE); + ibus_chewing_pre_edit_set_apply_property_boolean( + self, "phrase-choice-from-last", TRUE); key_press_from_string("t/6g4"); key_press_from_key_sym(IBUS_KEY_Down, 0); key_press_from_string("1"); @@ -526,9 +490,9 @@ void process_key_down_arrow_test() /* Test shift then caps then caps then shift */ /* String: 我要去 Brisbane 了。Daddy 好嗎 */ /* Bug before 1.5.0 */ -/* Should be okay to remove this since we force users to choose between caps and shift */ -void process_key_shift_and_caps_test() -{ +/* Should be okay to remove this since we force users to choose between caps and + * shift */ +void process_key_shift_and_caps_test() { #if 0 TEST_CASE_INIT(); @@ -581,10 +545,9 @@ void process_key_shift_and_caps_test() #endif } -void full_half_shape_test() -{ - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "plain-zhuyin", FALSE); +void full_half_shape_test() { + ibus_chewing_pre_edit_set_apply_property_boolean(self, "plain-zhuyin", + FALSE); g_assert(ibus_chewing_pre_edit_get_chi_eng_mode(self)); ibus_chewing_pre_edit_toggle_chi_eng_mode(self); g_assert(!ibus_chewing_pre_edit_get_chi_eng_mode(self)); @@ -603,10 +566,9 @@ void full_half_shape_test() ibus_chewing_pre_edit_toggle_chi_eng_mode(self); } -void plain_zhuyin_test() -{ - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "plain-zhuyin", TRUE); +void plain_zhuyin_test() { + ibus_chewing_pre_edit_set_apply_property_boolean(self, "plain-zhuyin", + TRUE); g_assert(ibus_chewing_pre_edit_get_property_boolean(self, "plain-zhuyin")); @@ -628,10 +590,9 @@ void plain_zhuyin_test() } /* 你好,*/ -void plain_zhuyin_shift_symbol_test() -{ - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "plain-zhuyin", TRUE); +void plain_zhuyin_shift_symbol_test() { + ibus_chewing_pre_edit_set_apply_property_boolean(self, "plain-zhuyin", + TRUE); g_assert(ibus_chewing_pre_edit_get_property_boolean(self, "plain-zhuyin")); ibus_chewing_pre_edit_set_property_string(self, "chi-eng-mode-toggle", @@ -676,10 +637,9 @@ void plain_zhuyin_shift_symbol_test() assert_outgoing_pre_edit("", ""); } -void plain_zhuyin_full_half_shape_test() -{ - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "plain-zhuyin", TRUE); +void plain_zhuyin_full_half_shape_test() { + ibus_chewing_pre_edit_set_apply_property_boolean(self, "plain-zhuyin", + TRUE); g_assert(ibus_chewing_pre_edit_get_chi_eng_mode(self)); ibus_chewing_pre_edit_toggle_chi_eng_mode(self); g_assert(!ibus_chewing_pre_edit_get_chi_eng_mode(self)); @@ -697,58 +657,51 @@ void plain_zhuyin_full_half_shape_test() assert_outgoing_pre_edit("", ""); } -void test_ibus_chewing_pre_edit_clear_bopomofo() -{ +void test_ibus_chewing_pre_edit_clear_bopomofo() { TEST_CASE_INIT(); - key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ + key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ assert_outgoing_pre_edit("", "你ㄏㄠ"); ibus_chewing_pre_edit_clear_bopomofo(self); assert_outgoing_pre_edit("", "你"); } -void test_ibus_chewing_pre_edit_clear_pre_edit() -{ +void test_ibus_chewing_pre_edit_clear_pre_edit() { TEST_CASE_INIT(); - key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ + key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ assert_outgoing_pre_edit("", "你ㄏㄠ"); ibus_chewing_pre_edit_clear_pre_edit(self); assert_outgoing_pre_edit("", ""); } -void test_ibus_chewing_pre_edit_set_chi_eng_mode() -{ +void test_ibus_chewing_pre_edit_set_chi_eng_mode() { TEST_CASE_INIT(); - key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ + key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ ibus_chewing_pre_edit_set_chi_eng_mode(self, FALSE); g_assert(chewing_get_ChiEngMode(self->context) == 0); assert_outgoing_pre_edit("", "你"); } -void test_space_as_selection() -{ -/* GitHub #79: Cannot input space when "space to select" is enabled */ +void test_space_as_selection() { + /* GitHub #79: Cannot input space when "space to select" is enabled */ TEST_CASE_INIT(); - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "space-as-selection", + ibus_chewing_pre_edit_set_apply_property_boolean(self, "space-as-selection", TRUE); key_press_from_key_sym(IBUS_KEY_space, 0); assert_outgoing_pre_edit(" ", ""); } -void test_arrow_keys_buffer_empty() -{ -/* GitHub #50: Cannot use Up, Down, PgUp, Ese ... etc. within "`" menu */ +void test_arrow_keys_buffer_empty() { + /* GitHub #50: Cannot use Up, Down, PgUp, Ese ... etc. within "`" menu */ TEST_CASE_INIT(); - ibus_chewing_pre_edit_set_apply_property_boolean(self, - "vertical-lookup-table", - TRUE); + ibus_chewing_pre_edit_set_apply_property_boolean( + self, "vertical-lookup-table", TRUE); key_press_from_string("`"); g_assert(ibus_chewing_pre_edit_has_flag(self, FLAG_TABLE_SHOW)); @@ -770,9 +723,8 @@ void test_arrow_keys_buffer_empty() g_assert(!ibus_chewing_pre_edit_has_flag(self, FLAG_TABLE_SHOW)); } -void test_ctrl_1_open_candidate_list() -{ -/* GitHub #63: Cannnot add user-phrase via ctrl+num */ +void test_ctrl_1_open_candidate_list() { + /* GitHub #63: Cannnot add user-phrase via ctrl+num */ TEST_CASE_INIT(); @@ -781,9 +733,8 @@ void test_ctrl_1_open_candidate_list() key_press_from_key_sym(IBUS_KEY_Escape, 0); } -void test_kp_eng_mode() -{ -/* Eng-Mode: keypad outputs numbers directly */ +void test_kp_eng_mode() { + /* Eng-Mode: keypad outputs numbers directly */ TEST_CASE_INIT(); @@ -796,13 +747,13 @@ void test_kp_eng_mode() assert_outgoing_pre_edit("", ""); } -void test_kp_eng_mode_buffer() -{ -/* Eng-Mode: When buffer is not empty, keypad outputs numbers into buffer. */ +void test_kp_eng_mode_buffer() { + /* Eng-Mode: When buffer is not empty, keypad outputs numbers into buffer. + */ TEST_CASE_INIT(); - key_press_from_string("su3cl3"); /* 你好 */ + key_press_from_string("su3cl3"); /* 你好 */ ibus_chewing_pre_edit_set_chi_eng_mode(self, FALSE); g_assert(chewing_get_ChiEngMode(self->context) == 0); key_press_from_key_sym(IBUS_KP_1, 0); @@ -811,9 +762,8 @@ void test_kp_eng_mode_buffer() assert_outgoing_pre_edit("", "你好190"); } -void test_kp_chi_mode() -{ -/* Chi-Mode: keypad outputs numbers by default */ +void test_kp_chi_mode() { + /* Chi-Mode: keypad outputs numbers by default */ TEST_CASE_INIT(); @@ -828,15 +778,14 @@ void test_kp_chi_mode() g_assert(chewing_get_ChiEngMode(self->context) == 1); } -void test_kp_chi_mode_buffer() -{ -/* Chi-Mode: When buffer is not empty, keypad outputs numbers into buffer */ +void test_kp_chi_mode_buffer() { + /* Chi-Mode: When buffer is not empty, keypad outputs numbers into buffer */ TEST_CASE_INIT(); g_assert(chewing_get_ChiEngMode(self->context) == 1); - key_press_from_string("su3cl3"); /* 你好 */ + key_press_from_string("su3cl3"); /* 你好 */ key_press_from_key_sym(IBUS_KP_1, 0); key_press_from_key_sym(IBUS_KEY_KP_9, 0); key_press_from_key_sym(IBUS_KP_0, 0); @@ -846,24 +795,22 @@ void test_kp_chi_mode_buffer() g_assert(chewing_get_ChiEngMode(self->context) == 1); } -void test_kp_chi_incomplete() -{ -/* Chi-Mode with bopmofos (incomplete characters): - * clear bopomofos and output numbers into buffer. - */ +void test_kp_chi_incomplete() { + /* Chi-Mode with bopmofos (incomplete characters): + * clear bopomofos and output numbers into buffer. + */ TEST_CASE_INIT(); g_assert(chewing_get_ChiEngMode(self->context) == 1); - key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ + key_press_from_string("su3cl"); /* 你ㄏㄠ (尚未完成組字) */ key_press_from_key_sym(IBUS_KP_1, 0); assert_outgoing_pre_edit("", "你1"); } -void test_kp_selecting() -{ -/* While selecting candidates: select or do nothing */ +void test_kp_selecting() { + /* While selecting candidates: select or do nothing */ TEST_CASE_INIT(); @@ -876,16 +823,15 @@ void test_kp_selecting() key_press_from_key_sym(IBUS_KP_1, 0); assert_outgoing_pre_edit("", "※…"); -// TODO: need to check if selkeys are 1234567890 + // TODO: need to check if selkeys are 1234567890 } -void test_kp_other_keys() -{ +void test_kp_other_keys() { TEST_CASE_INIT(); g_assert(chewing_get_ChiEngMode(self->context) == 1); - key_press_from_string("su3cl3"); /* 你好 */ + key_press_from_string("su3cl3"); /* 你好 */ key_press_from_key_sym(IBUS_KP_Multiply, 0); key_press_from_key_sym(IBUS_KP_Add, 0); key_press_from_key_sym(IBUS_KP_Separator, 0); @@ -898,8 +844,7 @@ void test_kp_other_keys() g_assert(chewing_get_ChiEngMode(self->context) == 1); } -void test_keypad() -{ +void test_keypad() { test_kp_eng_mode(); test_kp_eng_mode_buffer(); test_kp_chi_mode(); @@ -909,12 +854,10 @@ void test_keypad() test_kp_other_keys(); } -gint main(gint argc, gchar ** argv) -{ +gint main(gint argc, gchar **argv) { g_test_init(&argc, &argv, NULL); - MkdgBackend *backend = - mkdg_g_settings_backend_new(QUOTE_ME(PROJECT_SCHEMA_ID), - QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); + MkdgBackend *backend = mkdg_g_settings_backend_new( + QUOTE_ME(PROJECT_SCHEMA_ID), QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); mkdg_log_set_level(DEBUG); self = ibus_chewing_pre_edit_new(backend); ibus_chewing_pre_edit_use_all_configure(self); diff --git a/test/IBusChewingUtil-test.c b/test/IBusChewingUtil-test.c index c6f207d..d304531 100644 --- a/test/IBusChewingUtil-test.c +++ b/test/IBusChewingUtil-test.c @@ -1,11 +1,10 @@ +#include "IBusChewingUtil.h" +#include "test-util.h" #include #include -#include "test-util.h" -#include "IBusChewingUtil.h" #define TEST_RUN_THIS(f) add_test_case("IBusChewingUtil", f) -void key_sym_get_name_test() -{ +void key_sym_get_name_test() { /* Test */ guint kSym; @@ -18,8 +17,7 @@ void key_sym_get_name_test() g_assert_cmpstr(key_sym_get_name(-1), ==, "WARN"); } -gint main(gint argc, gchar ** argv) -{ +gint main(gint argc, gchar **argv) { g_test_init(&argc, &argv, NULL); mkdg_log_set_level(INFO); TEST_RUN_THIS(key_sym_get_name_test); diff --git a/test/MakerDialogBackend-test.c b/test/MakerDialogBackend-test.c index 425296c..3052aa9 100644 --- a/test/MakerDialogBackend-test.c +++ b/test/MakerDialogBackend-test.c @@ -1,20 +1,19 @@ +#include "GSettingsBackend.h" +#include "MakerDialogBackend.h" +#include "MakerDialogUtil.h" +#include "test-util.h" +#include +#include #include #include #include -#include -#include -#include "test-util.h" -#include "MakerDialogUtil.h" -#include "MakerDialogBackend.h" -#include "GSettingsBackend.h" #define TEST_RUN_THIS(f) add_test_case("MakerDialogBackend", f) #define COMMAND_BUFFER_SIZE 200 #define FILE_BUFFER_SIZE 1024 MkdgBackend *backend = NULL; -gchar *command_run_obtain_output(const gchar * cmd) -{ +gchar *command_run_obtain_output(const gchar *cmd) { mkdg_log(DEBUG, "command_run_obtain_output(%s)\n", cmd); static gchar readBuffer[FILE_BUFFER_SIZE]; FILE *stream = popen(cmd, "r"); @@ -35,8 +34,7 @@ gchar *command_run_obtain_output(const gchar * cmd) return line; } -GValue *backend_command_get_key_value(const gchar * key, GValue * value) -{ +GValue *backend_command_get_key_value(const gchar *key, GValue *value) { gchar cmdBuf[COMMAND_BUFFER_SIZE]; gchar *cKey = mkdg_backend_get_key(backend, NULL, key, NULL); @@ -54,8 +52,7 @@ GValue *backend_command_get_key_value(const gchar * key, GValue * value) return value; } -void backend_command_set_key_value(const gchar * key, GValue * value) -{ +void backend_command_set_key_value(const gchar *key, GValue *value) { gchar *valueStr = mkdg_g_value_to_string(value); if (mkdg_g_value_is_boolean(value)) { @@ -64,15 +61,13 @@ void backend_command_set_key_value(const gchar * key, GValue * value) gchar cmdBuf[COMMAND_BUFFER_SIZE]; gchar *cKey = mkdg_backend_get_key(backend, NULL, key, NULL); - g_snprintf(cmdBuf, COMMAND_BUFFER_SIZE, - "gsettings set %s %s %s", + g_snprintf(cmdBuf, COMMAND_BUFFER_SIZE, "gsettings set %s %s %s", QUOTE_ME(PROJECT_SCHEMA_ID), cKey, valueStr); command_run_obtain_output(cmdBuf); } -gboolean mkdg_g_value_is_equal(GValue * value1, GValue * value2) -{ +gboolean mkdg_g_value_is_equal(GValue *value1, GValue *value2) { switch (G_VALUE_TYPE(value1)) { case G_TYPE_BOOLEAN: return (g_value_get_boolean(value1) == g_value_get_boolean(value2)); @@ -81,22 +76,20 @@ gboolean mkdg_g_value_is_equal(GValue * value1, GValue * value2) case G_TYPE_UINT: return (g_value_get_uint(value1) == g_value_get_uint(value2)); case G_TYPE_STRING: - return (STRING_EQUALS - (g_value_get_string(value1), g_value_get_string(value2))); + return (STRING_EQUALS(g_value_get_string(value1), + g_value_get_string(value2))); default: break; } return FALSE; } -void backup_key_to_g_value(const gchar * key, GType gType, GValue * value) -{ +void backup_key_to_g_value(const gchar *key, GType gType, GValue *value) { g_value_init(value, gType); backend_command_get_key_value(key, value); } -void change_new_value_from_orig_value(GValue * newValue, GValue * origValue) -{ +void change_new_value_from_orig_value(GValue *newValue, GValue *origValue) { g_value_init(newValue, G_VALUE_TYPE(origValue)); gchar *tempStr = NULL; @@ -105,16 +98,14 @@ void change_new_value_from_orig_value(GValue * newValue, GValue * origValue) g_value_set_boolean(newValue, !g_value_get_boolean(origValue)); break; case G_TYPE_INT: - g_value_set_int(newValue, - (g_value_get_int(origValue) > - 0) ? g_value_get_int(origValue) - - 1 : g_value_get_int(origValue) + 1); + g_value_set_int(newValue, (g_value_get_int(origValue) > 0) + ? g_value_get_int(origValue) - 1 + : g_value_get_int(origValue) + 1); break; case G_TYPE_UINT: - g_value_set_uint(newValue, - (g_value_get_uint(origValue) > - 0) ? g_value_get_uint(origValue) - - 1 : g_value_get_uint(origValue) + 1); + g_value_set_uint(newValue, (g_value_get_uint(origValue) > 0) + ? g_value_get_uint(origValue) - 1 + : g_value_get_uint(origValue) + 1); break; case G_TYPE_STRING: tempStr = g_strdup_printf("%sx", g_value_get_string(origValue)); @@ -125,34 +116,31 @@ void change_new_value_from_orig_value(GValue * newValue, GValue * origValue) } } -void write_key_with_g_value(const gchar * key, GValue * value) -{ - mkdg_backend_write(backend, value, QUOTE_ME(PROJECT_SCHEMA_SECTION), - key, NULL); +void write_key_with_g_value(const gchar *key, GValue *value) { + mkdg_backend_write(backend, value, QUOTE_ME(PROJECT_SCHEMA_SECTION), key, + NULL); } -void assert_new_value_is_written(const gchar * key, GValue * newValue) -{ - GValue storedGValue = { 0 }; +void assert_new_value_is_written(const gchar *key, GValue *newValue) { + GValue storedGValue = {0}; g_value_init(&storedGValue, G_VALUE_TYPE(newValue)); backend_command_get_key_value(key, &storedGValue); g_assert(mkdg_g_value_is_equal(newValue, &storedGValue)); g_value_unset(&storedGValue); } -void mkdg_g_value_from_string_test(const gchar * key, GType gType) -{ - GValue origGValue = { 0 }; +void mkdg_g_value_from_string_test(const gchar *key, GType gType) { + GValue origGValue = {0}; backup_key_to_g_value(key, gType, &origGValue); - GValue newGValue = { 0 }; + GValue newGValue = {0}; change_new_value_from_orig_value(&newGValue, &origGValue); write_key_with_g_value(key, &newGValue); assert_new_value_is_written(key, &newGValue); /* - * Restore the origValue + * Restore the origValue */ write_key_with_g_value(key, &origGValue); @@ -160,53 +148,47 @@ void mkdg_g_value_from_string_test(const gchar * key, GType gType) g_value_unset(&newGValue); } -void mkdg_g_value_from_string_boolean_test() -{ +void mkdg_g_value_from_string_boolean_test() { mkdg_g_value_from_string_test("plain-zhuyin", G_TYPE_BOOLEAN); } -void mkdg_g_value_from_string_int_test() -{ +void mkdg_g_value_from_string_int_test() { mkdg_g_value_from_string_test("max-chi-symbol-len", G_TYPE_INT); } -void mkdg_g_value_from_string_uint_test() -{ +void mkdg_g_value_from_string_uint_test() { mkdg_g_value_from_string_test("cand-per-page", G_TYPE_UINT); } -void mkdg_g_value_from_string_string_test() -{ +void mkdg_g_value_from_string_string_test() { mkdg_g_value_from_string_test("max-chi-symbol-len", G_TYPE_INT); } -void int_w_test() -{ +void int_w_test() { #define GCONF_KEY "max-chi-symbol-len" - GValue origValue = { 0 }; + GValue origValue = {0}; g_value_init(&origValue, G_TYPE_BOOLEAN); backend_command_get_key_value(GCONF_KEY, &origValue); - GValue newValue = { 0 }; + GValue newValue = {0}; g_value_init(&newValue, G_TYPE_BOOLEAN); g_value_set_int(&newValue, !g_value_get_int(&origValue)); - mkdg_backend_write(backend, &newValue, - QUOTE_ME(PROJECT_SCHEMA_SECTION), GCONF_KEY, NULL); + mkdg_backend_write(backend, &newValue, QUOTE_ME(PROJECT_SCHEMA_SECTION), + GCONF_KEY, NULL); - GValue storedValue = { 0 }; + GValue storedValue = {0}; g_value_init(&storedValue, G_TYPE_BOOLEAN); backend_command_get_key_value(GCONF_KEY, &storedValue); g_assert(mkdg_g_value_is_equal(&newValue, &storedValue)); /* - * Restore the original value + * Restore the original value */ backend_command_set_key_value(GCONF_KEY, &origValue); #undef GCONF_KEY } -gint main(gint argc, gchar ** argv) -{ +gint main(gint argc, gchar **argv) { g_test_init(&argc, &argv, NULL); backend = mkdg_g_settings_backend_new(QUOTE_ME(PROJECT_SCHEMA_ID), QUOTE_ME(PROJECT_SCHEMA_DIR), NULL); diff --git a/test/MakerDialogUtil-test.c b/test/MakerDialogUtil-test.c index a8b5fb1..d7cf6f1 100644 --- a/test/MakerDialogUtil-test.c +++ b/test/MakerDialogUtil-test.c @@ -1,12 +1,11 @@ -#include -#include "test-util.h" #include "MakerDialogUtil.h" +#include "test-util.h" +#include #define TEST_RUN_THIS(f) add_test_case("MakerDialogUtil", f) -void mkdg_g_value_to_string_test() -{ +void mkdg_g_value_to_string_test() { /* Test int */ - GValue intValue = { 0 }; + GValue intValue = {0}; g_value_init(&intValue, G_TYPE_INT); g_value_set_int(&intValue, 0); g_assert_cmpstr("0", ==, mkdg_g_value_to_string(&intValue)); @@ -16,7 +15,7 @@ void mkdg_g_value_to_string_test() g_value_unset(&intValue); /* Test uint */ - GValue uintValue = { 0 }; + GValue uintValue = {0}; g_value_init(&uintValue, G_TYPE_UINT); g_value_set_uint(&uintValue, 0); g_assert_cmpstr("0", ==, mkdg_g_value_to_string(&uintValue)); @@ -26,7 +25,7 @@ void mkdg_g_value_to_string_test() g_value_unset(&uintValue); /* Test boolean */ - GValue booleanValue = { 0 }; + GValue booleanValue = {0}; g_value_init(&booleanValue, G_TYPE_BOOLEAN); g_value_set_boolean(&booleanValue, TRUE); g_assert_cmpstr("1", ==, mkdg_g_value_to_string(&booleanValue)); @@ -36,10 +35,9 @@ void mkdg_g_value_to_string_test() g_value_unset(&booleanValue); } -void mkdg_g_value_from_string_test() -{ +void mkdg_g_value_from_string_test() { /* Test int */ - GValue intValue = { 0 }; + GValue intValue = {0}; g_value_init(&intValue, G_TYPE_INT); mkdg_g_value_from_string(&intValue, "0"); @@ -51,7 +49,7 @@ void mkdg_g_value_from_string_test() g_value_unset(&intValue); /* Test uint */ - GValue uintValue = { 0 }; + GValue uintValue = {0}; g_value_init(&uintValue, G_TYPE_UINT); mkdg_g_value_from_string(&uintValue, "0"); @@ -63,7 +61,7 @@ void mkdg_g_value_from_string_test() g_value_unset(&uintValue); /* Test boolean */ - GValue booleanValue = { 0 }; + GValue booleanValue = {0}; g_value_init(&booleanValue, G_TYPE_BOOLEAN); mkdg_g_value_from_string(&booleanValue, "1"); @@ -87,20 +85,17 @@ void mkdg_g_value_from_string_test() g_value_unset(&booleanValue); } - /************************************** * String Utility Macros */ -void QUOTE_ME_test() -{ -#define PRJ_TEST MKDG +void QUOTE_ME_test() { +#define PRJ_TEST MKDG g_assert_cmpstr("MKDG", ==, QUOTE_ME(PRJ_TEST)); #undef PRJ_TEST } -void STRING_IS_EMPTY_test() -{ +void STRING_IS_EMPTY_test() { gchar *nulStr = NULL; g_assert(STRING_IS_EMPTY(nulStr)); @@ -108,8 +103,7 @@ void STRING_IS_EMPTY_test() g_assert(!STRING_IS_EMPTY("NULL")); } -void STRING_EQUALS_test() -{ +void STRING_EQUALS_test() { gchar *nulStr = NULL; g_assert(STRING_EQUALS("", "")); @@ -119,9 +113,7 @@ void STRING_EQUALS_test() g_assert(STRING_EQUALS("YO\"", "YO\"")); } - -gint main(gint argc, gchar ** argv) -{ +gint main(gint argc, gchar **argv) { g_test_init(&argc, &argv, NULL); TEST_RUN_THIS(mkdg_g_value_to_string_test); TEST_RUN_THIS(mkdg_g_value_from_string_test); diff --git a/test/ibus-chewing-engine-test.c b/test/ibus-chewing-engine-test.c index b9ac647..10623f1 100644 --- a/test/ibus-chewing-engine-test.c +++ b/test/ibus-chewing-engine-test.c @@ -1,20 +1,18 @@ -#include -#include "ibus-chewing-engine.h" -#include "ibus-chewing-engine-private.h" #include "MakerDialogUtil.h" +#include "ibus-chewing-engine-private.h" +#include "ibus-chewing-engine.h" #include "test-util.h" +#include #define TEST_RUN_THIS(f) add_test_case("ibus-chewing-engine", f) static IBusChewingEngine *engine = NULL; -IBusChewingEngine *ibus_chewing_engine_new() -{ - return (IBusChewingEngine *) g_object_new(IBUS_TYPE_CHEWING_ENGINE, NULL); +IBusChewingEngine *ibus_chewing_engine_new() { + return (IBusChewingEngine *)g_object_new(IBUS_TYPE_CHEWING_ENGINE, NULL); } -void check_output(const gchar * outgoing, const gchar * preEdit, - const gchar * aux) -{ +void check_output(const gchar *outgoing, const gchar *preEdit, + const gchar *aux) { g_assert(engine->outgoingText); g_assert(engine->outgoingText->text); printf("outgoingText->text=%s\n", engine->outgoingText->text); @@ -25,10 +23,9 @@ void check_output(const gchar * outgoing, const gchar * preEdit, g_assert_cmpint(strlen(aux), ==, strlen(engine->auxText->text)); } -void focus_out_then_focus_in_with_aux_text_test() -{ - gboolean cleanBufferFocusOut = ibus_chewing_pre_edit_get_property_boolean - (engine->icPreEdit, "clean-buffer-focus-out"); +void focus_out_then_focus_in_with_aux_text_test() { + gboolean cleanBufferFocusOut = ibus_chewing_pre_edit_get_property_boolean( + engine->icPreEdit, "clean-buffer-focus-out"); ibus_chewing_pre_edit_save_property_boolean(engine->icPreEdit, "add-phrase-direction", TRUE); @@ -37,27 +34,28 @@ void focus_out_then_focus_in_with_aux_text_test() ibus_chewing_engine_focus_in(engine); ibus_chewing_engine_enable(engine); ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24, 0); - ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), - 'j', 0x24, IBUS_RELEASE_MASK); + ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24, + IBUS_RELEASE_MASK); ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '3', 0x04, 0); - ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), - '3', 0x04, IBUS_RELEASE_MASK); + ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '3', 0x04, + IBUS_RELEASE_MASK); ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24, 0); - ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), - 'j', 0x24, IBUS_RELEASE_MASK); + ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24, + IBUS_RELEASE_MASK); ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '3', 0x04, 0); - ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), - '3', 0x04, IBUS_RELEASE_MASK); - ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), - '2', 0x03, IBUS_CONTROL_MASK); - ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), - '2', 0x03, IBUS_RELEASE_MASK); + ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '3', 0x04, + IBUS_RELEASE_MASK); + ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '2', 0x03, + IBUS_CONTROL_MASK); + ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '2', 0x03, + IBUS_RELEASE_MASK); check_output("", "五五", "已有:五五"); /* focus out should not touch Texts */ ibus_chewing_engine_focus_out(engine); - g_assert(cleanBufferFocusOut == ibus_chewing_pre_edit_get_property_boolean - (engine->icPreEdit, "clean-buffer-focus-out")); + g_assert(cleanBufferFocusOut == + ibus_chewing_pre_edit_get_property_boolean( + engine->icPreEdit, "clean-buffer-focus-out")); if (cleanBufferFocusOut) { check_output("", "", ""); @@ -73,23 +71,19 @@ void focus_out_then_focus_in_with_aux_text_test() check_output("", "", ""); } -void focus_out_then_focus_in_with_aux_text_clean_buffer_on_test() -{ +void focus_out_then_focus_in_with_aux_text_clean_buffer_on_test() { ibus_chewing_pre_edit_save_property_boolean(engine->icPreEdit, "clean-buffer-focus-out", TRUE); focus_out_then_focus_in_with_aux_text_test(); } -void focus_out_then_focus_in_with_aux_text_clean_buffer_off_test() -{ - ibus_chewing_pre_edit_save_property_boolean(engine->icPreEdit, - "clean-buffer-focus-out", - FALSE); +void focus_out_then_focus_in_with_aux_text_clean_buffer_off_test() { + ibus_chewing_pre_edit_save_property_boolean( + engine->icPreEdit, "clean-buffer-focus-out", FALSE); focus_out_then_focus_in_with_aux_text_test(); } -gint main(gint argc, gchar ** argv) -{ +gint main(gint argc, gchar **argv) { g_test_init(&argc, &argv, NULL); mkdg_log_set_level(DEBUG); engine = ibus_chewing_engine_new(); @@ -98,15 +92,13 @@ gint main(gint argc, gchar ** argv) ibus_chewing_pre_edit_set_apply_property_boolean(engine->icPreEdit, "plain-zhuyin", FALSE); - gboolean cleanBufferFocusOut = - ibus_chewing_pre_edit_get_property_boolean(engine->icPreEdit, - "clean-buffer-focus-out"); + gboolean cleanBufferFocusOut = ibus_chewing_pre_edit_get_property_boolean( + engine->icPreEdit, "clean-buffer-focus-out"); TEST_RUN_THIS(focus_out_then_focus_in_with_aux_text_clean_buffer_off_test); TEST_RUN_THIS(focus_out_then_focus_in_with_aux_text_clean_buffer_on_test); - ibus_chewing_pre_edit_save_property_boolean(engine->icPreEdit, - "clean-buffer-focus-out", - cleanBufferFocusOut); + ibus_chewing_pre_edit_save_property_boolean( + engine->icPreEdit, "clean-buffer-focus-out", cleanBufferFocusOut); return g_test_run(); } diff --git a/test/test-util.h b/test/test-util.h index e69160e..348fe26 100644 --- a/test/test-util.h +++ b/test/test-util.h @@ -3,4 +3,5 @@ * Utility test macros and functions. */ -#define add_test_case(item, testCase) g_test_add_func("/ibus-chewing/" item "/" QUOTE_ME(testCase), testCase) +#define add_test_case(item, testCase) \ + g_test_add_func("/ibus-chewing/" item "/" QUOTE_ME(testCase), testCase)