From ff8cdb6f36a6f1024c3295ca75be6c444209d407 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Thu, 8 Apr 2010 17:47:31 +0800 Subject: [PATCH] Clear the code for preedit text mode --- bus/engineproxy.c | 25 +++--------- bus/engineproxy.h | 6 --- bus/inputcontext.c | 87 +++++++++++++++++++++++------------------ bus/inputcontext.h | 1 + src/ibusmarshalers.list | 1 + 5 files changed, 55 insertions(+), 65 deletions(-) diff --git a/bus/engineproxy.c b/bus/engineproxy.c index 38a359d8..8526e7cc 100644 --- a/bus/engineproxy.c +++ b/bus/engineproxy.c @@ -145,12 +145,13 @@ bus_engine_proxy_class_init (BusEngineProxyClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - ibus_marshal_VOID__OBJECT_UINT_BOOLEAN, + ibus_marshal_VOID__OBJECT_UINT_BOOLEAN_UINT, G_TYPE_NONE, - 3, + 4, IBUS_TYPE_TEXT, G_TYPE_UINT, - G_TYPE_BOOLEAN); + G_TYPE_BOOLEAN, + G_TYPE_UINT); engine_signals[SHOW_PREEDIT_TEXT] = g_signal_new (I_("show-preedit-text"), @@ -448,9 +449,8 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy, if (!retval) goto failed; - engine->_preedit_focus_mode = mode; g_signal_emit (engine, engine_signals[UPDATE_PREEDIT_TEXT], 0, - text, cursor_pos, visible); + text, cursor_pos, visible, mode); if (g_object_is_floating (text)) g_object_unref (text); } @@ -688,21 +688,6 @@ bus_engine_proxy_set_capabilities (BusEngineProxy *engine, } } -guint -bus_engine_proxy_get_preedit_focus_mode (BusEngineProxy *engine) -{ - g_assert (BUS_IS_ENGINE_PROXY (engine)); - return engine->_preedit_focus_mode; -} - -void -bus_engine_proxy_set_preedit_focus_mode (BusEngineProxy *engine, - guint mode) -{ - g_assert (BUS_IS_ENGINE_PROXY (engine)); - engine->_preedit_focus_mode = mode; -} - void bus_engine_proxy_property_activate (BusEngineProxy *engine, const gchar *prop_name, diff --git a/bus/engineproxy.h b/bus/engineproxy.h index 76d730a2..7c2626f0 100644 --- a/bus/engineproxy.h +++ b/bus/engineproxy.h @@ -64,7 +64,6 @@ struct _BusEngineProxy { IBusPropList *prop_list; /* private member */ - guint _preedit_focus_mode; }; struct _BusEngineProxyClass { @@ -94,11 +93,6 @@ void bus_engine_proxy_focus_out (BusEngineProxy *engine); void bus_engine_proxy_reset (BusEngineProxy *engine); void bus_engine_proxy_set_capabilities (BusEngineProxy *engine, guint caps); -guint bus_engine_proxy_get_preedit_focus_mode - (BusEngineProxy *engine); -void bus_engine_proxy_set_preedit_focus_mode - (BusEngineProxy *engine, - guint mode); void bus_engine_proxy_page_up (BusEngineProxy *engine); void bus_engine_proxy_page_down (BusEngineProxy *engine); void bus_engine_proxy_cursor_up (BusEngineProxy *engine); diff --git a/bus/inputcontext.c b/bus/inputcontext.c index c9646392..ef489bed 100644 --- a/bus/inputcontext.c +++ b/bus/inputcontext.c @@ -79,11 +79,14 @@ static gboolean bus_input_context_send_signal (BusInputContext *context ...); static void bus_input_context_unset_engine (BusInputContext *context); +static void bus_input_context_commit_text (BusInputContext *context, + IBusText *text); static void bus_input_context_update_preedit_text (BusInputContext *context, IBusText *text, guint cursor_pos, - gboolean visible); + gboolean visible, + guint mode); static void bus_input_context_show_preedit_text (BusInputContext *context); static void bus_input_context_hide_preedit_text @@ -478,6 +481,7 @@ bus_input_context_init (BusInputContext *context) context->preedit_text = text_empty; context->preedit_cursor_pos = 0; context->preedit_visible = FALSE; + context->preedit_mode = IBUS_ENGINE_PREEDIT_CLEAR; g_object_ref_sink (text_empty); context->auxiliary_text = text_empty; @@ -1209,23 +1213,18 @@ bus_input_context_focus_in (BusInputContext *context) } static void -commit_preedit_text_with_focus_mode (BusInputContext *context) +bus_input_context_clear_preedit_text (BusInputContext *context) { - guint mode = IBUS_ENGINE_PREEDIT_CLEAR; + g_assert (BUS_IS_INPUT_CONTEXT (context)); - if (context->engine) { - mode = bus_engine_proxy_get_preedit_focus_mode (context->engine); - } - if (mode == IBUS_ENGINE_PREEDIT_COMMIT) { - if (context->engine && context->enabled) { - bus_input_context_send_signal (context, - "CommitText", - IBUS_TYPE_TEXT, &context->preedit_text, - G_TYPE_INVALID); - } - mode = IBUS_ENGINE_PREEDIT_CLEAR; - bus_engine_proxy_set_preedit_focus_mode (context->engine, mode); + if (context->preedit_visible && + context->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) { + bus_input_context_commit_text (context, context->preedit_text); } + + /* always clear preedit text */ + bus_input_context_update_preedit_text (context, + text_empty, 0, FALSE, IBUS_ENGINE_PREEDIT_CLEAR); } void @@ -1236,7 +1235,10 @@ bus_input_context_focus_out (BusInputContext *context) if (!context->has_focus) return; - commit_preedit_text_with_focus_mode (context); + bus_input_context_clear_preedit_text (context); + bus_input_context_update_auxiliary_text (context, text_empty, FALSE); + bus_input_context_update_lookup_table (context, lookup_table_empty, FALSE); + bus_input_context_register_properties (context, props_empty); if (context->engine && context->enabled) { bus_engine_proxy_focus_out (context->engine); @@ -1245,15 +1247,6 @@ bus_input_context_focus_out (BusInputContext *context) context->has_focus = FALSE; if (context->capabilities & IBUS_CAP_FOCUS) { - if (context->preedit_visible && !PREEDIT_CONDITION) { - g_signal_emit (context, context_signals[HIDE_PREEDIT_TEXT], 0); - } - if (context->auxiliary_visible && (context->capabilities & IBUS_CAP_AUXILIARY_TEXT) == 0) { - g_signal_emit (context, context_signals[HIDE_AUXILIARY_TEXT], 0); - } - if (context->auxiliary_visible && (context->capabilities & IBUS_CAP_LOOKUP_TABLE) == 0) { - g_signal_emit (context, context_signals[HIDE_LOOKUP_TABLE], 0); - } g_signal_emit (context, context_signals[FOCUS_OUT], 0); } } @@ -1304,11 +1297,30 @@ bus_input_context_property_activate (BusInputContext *context, } } +static void +bus_input_context_commit_text (BusInputContext *context, + IBusText *text) +{ + g_assert (BUS_IS_INPUT_CONTEXT (context)); + + if (!context->enabled) + return; + + if (text == text_empty || text == NULL) + return; + + bus_input_context_send_signal (context, + "CommitText", + IBUS_TYPE_TEXT, &text, + G_TYPE_INVALID); +} + static void bus_input_context_update_preedit_text (BusInputContext *context, IBusText *text, guint cursor_pos, - gboolean visible) + gboolean visible, + guint mode) { g_assert (BUS_IS_INPUT_CONTEXT (context)); @@ -1319,6 +1331,7 @@ bus_input_context_update_preedit_text (BusInputContext *context, context->preedit_text = (IBusText *) g_object_ref_sink (text ? text : text_empty); context->preedit_cursor_pos = cursor_pos; context->preedit_visible = visible; + context->preedit_mode = mode; if (PREEDIT_CONDITION) { bus_input_context_send_signal (context, @@ -1685,13 +1698,7 @@ _engine_commit_text_cb (BusEngineProxy *engine, g_assert (context->engine == engine); - if (!context->enabled) - return; - - bus_input_context_send_signal (context, - "CommitText", - IBUS_TYPE_TEXT, &text, - G_TYPE_INVALID); + bus_input_context_commit_text (context, text); } static void @@ -1743,6 +1750,7 @@ _engine_update_preedit_text_cb (BusEngineProxy *engine, IBusText *text, guint cursor_pos, gboolean visible, + guint mode, BusInputContext *context) { g_assert (BUS_IS_ENGINE_PROXY (engine)); @@ -1754,7 +1762,7 @@ _engine_update_preedit_text_cb (BusEngineProxy *engine, if (!context->enabled) return; - bus_input_context_update_preedit_text (context, text, cursor_pos, visible); + bus_input_context_update_preedit_text (context, text, cursor_pos, visible, mode); } static void @@ -1888,7 +1896,10 @@ bus_input_context_disable (BusInputContext *context) { g_assert (BUS_IS_INPUT_CONTEXT (context)); - commit_preedit_text_with_focus_mode (context); + bus_input_context_clear_preedit_text (context); + bus_input_context_update_auxiliary_text (context, text_empty, FALSE); + bus_input_context_update_lookup_table (context, lookup_table_empty, FALSE); + bus_input_context_register_properties (context, props_empty); if (context->engine) { bus_engine_proxy_focus_out (context->engine); @@ -1944,12 +1955,10 @@ bus_input_context_unset_engine (BusInputContext *context) { g_assert (BUS_IS_INPUT_CONTEXT (context)); - commit_preedit_text_with_focus_mode (context); - - bus_input_context_register_properties (context, props_empty); - bus_input_context_update_preedit_text (context, text_empty, 0, FALSE); + bus_input_context_clear_preedit_text (context); bus_input_context_update_auxiliary_text (context, text_empty, FALSE); bus_input_context_update_lookup_table (context, lookup_table_empty, FALSE); + bus_input_context_register_properties (context, props_empty); if (context->engine) { gint i; diff --git a/bus/inputcontext.h b/bus/inputcontext.h index a877dff6..ba3fdb27 100644 --- a/bus/inputcontext.h +++ b/bus/inputcontext.h @@ -76,6 +76,7 @@ struct _BusInputContext { IBusText *preedit_text; guint preedit_cursor_pos; gboolean preedit_visible; + guint preedit_mode; /* auxiliary text */ IBusText *auxiliary_text; diff --git a/src/ibusmarshalers.list b/src/ibusmarshalers.list index 2ee0d652..4473dab1 100644 --- a/src/ibusmarshalers.list +++ b/src/ibusmarshalers.list @@ -14,6 +14,7 @@ VOID:UINT,UINT VOID:INT,UINT VOID:UINT,UINT,UINT VOID:OBJECT,UINT,BOOL +VOID:OBJECT,UINT,BOOL,UINT VOID:OBJECT,BOOL VOID:BOXED,BOOL VOID:BOXED -- 2.34.1