Skip to content

Commit

Permalink
Add ibus_engine_update_preedit_text_with_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwarat committed Mar 16, 2010
1 parent 701265d commit 8ee3864
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 4 deletions.
18 changes: 18 additions & 0 deletions bus/engineproxy.c
Expand Up @@ -435,17 +435,20 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy,
gint cursor_pos;
gboolean visible;
gboolean retval;
guint mode;

retval = ibus_message_get_args (message,
&error,
IBUS_TYPE_TEXT, &text,
G_TYPE_UINT, &cursor_pos,
G_TYPE_BOOLEAN, &visible,
G_TYPE_UINT, &mode,
G_TYPE_INVALID);

if (!retval)
goto failed;

engine->_preedit_focus_mode = mode;
g_signal_emit (engine, engine_signals[UPDATE_PREEDIT_TEXT], 0,
text, cursor_pos, visible);
if (g_object_is_floating (text))
Expand Down Expand Up @@ -685,6 +688,21 @@ 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,
Expand Down
8 changes: 8 additions & 0 deletions bus/engineproxy.h
Expand Up @@ -62,6 +62,9 @@ struct _BusEngineProxy {
IBusEngineDesc *desc;
IBusKeymap *keymap;
IBusPropList *prop_list;

/* private member */
guint _preedit_focus_mode;
};

struct _BusEngineProxyClass {
Expand Down Expand Up @@ -91,6 +94,11 @@ 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);
Expand Down
30 changes: 30 additions & 0 deletions bus/inputcontext.c
Expand Up @@ -1211,11 +1211,26 @@ bus_input_context_focus_in (BusInputContext *context)
void
bus_input_context_focus_out (BusInputContext *context)
{
guint mode = IBUS_ENGINE_PREEDIT_CLEAR;
g_assert (BUS_IS_INPUT_CONTEXT (context));

if (!context->has_focus)
return;

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->engine && context->enabled) {
bus_engine_proxy_focus_out (context->engine);
}
Expand Down Expand Up @@ -1918,8 +1933,23 @@ const static struct {
static void
bus_input_context_unset_engine (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);
}

bus_input_context_register_properties (context, props_empty);
bus_input_context_update_preedit_text (context, text_empty, 0, FALSE);
bus_input_context_update_auxiliary_text (context, text_empty, FALSE);
Expand Down
4 changes: 4 additions & 0 deletions ibus/common.py
Expand Up @@ -124,6 +124,10 @@
IBUS_IFACE_INPUT_CONTEXT = "org.freedesktop.IBus.InputContext"
IBUS_IFACE_NOTIFICATIONS = "org.freedesktop.IBus.Notifications"

# define pre-edit commit mode when the focus is lost
IBUS_ENGINE_PREEDIT_CLEAR = 0
IBUS_ENGINE_PREEDIT_COMMIT = 1

# define orientation
ORIENTATION_HORIZONTAL = 0
ORIENTATION_VERTICAL = 1
Expand Down
5 changes: 3 additions & 2 deletions ibus/engine.py
Expand Up @@ -24,6 +24,7 @@
"EngineBase",
)

import common
import object
import serializable
import interface
Expand Down Expand Up @@ -85,9 +86,9 @@ def commit_text(self, text):
def forward_key_event(self, keyval, state):
return self.__proxy.ForwardKeyEvent(keyval, state)

def update_preedit_text(self, text, cursor_pos, visible):
def update_preedit_text(self, text, cursor_pos, visible, mode=common.IBUS_ENGINE_PREEDIT_CLEAR):
text = serializable.serialize_object(text)
return self.__proxy.UpdatePreeditText(text, cursor_pos, visible)
return self.__proxy.UpdatePreeditText(text, cursor_pos, visible, mode)

def show_preedit_text(self):
return self.__proxy.ShowPreeditText()
Expand Down
4 changes: 2 additions & 2 deletions ibus/interface/iengine.py
Expand Up @@ -104,8 +104,8 @@ def CommitText(self, text): pass
@signal(signature="uu")
def ForwardKeyEvent(self, keyval, state): pass

@signal(signature="vub")
def UpdatePreeditText(self, text, cursor_pos, visible): pass
@signal(signature="vubu")
def UpdatePreeditText(self, text, cursor_pos, visible, mode): pass

@signal()
def ShowPreeditText(self): pass
Expand Down
23 changes: 23 additions & 0 deletions src/ibusengine.c
Expand Up @@ -1040,12 +1040,35 @@ ibus_engine_update_preedit_text (IBusEngine *engine,
IBusText *text,
guint cursor_pos,
gboolean visible)
{
guint mode = IBUS_ENGINE_PREEDIT_CLEAR;

_send_signal (engine,
"UpdatePreeditText",
IBUS_TYPE_TEXT, &text,
G_TYPE_UINT, &cursor_pos,
G_TYPE_BOOLEAN, &visible,
G_TYPE_UINT, &mode,
G_TYPE_INVALID);

if (g_object_is_floating (text)) {
g_object_unref (text);
}
}

void
ibus_engine_update_preedit_text_with_mode (IBusEngine *engine,
IBusText *text,
guint cursor_pos,
gboolean visible,
IBusPreeditFocusMode mode)
{
_send_signal (engine,
"UpdatePreeditText",
IBUS_TYPE_TEXT, &text,
G_TYPE_UINT, &cursor_pos,
G_TYPE_BOOLEAN, &visible,
G_TYPE_UINT, &mode,
G_TYPE_INVALID);

if (g_object_is_floating (text)) {
Expand Down
24 changes: 24 additions & 0 deletions src/ibusengine.h
Expand Up @@ -178,6 +178,30 @@ void ibus_engine_update_preedit_text
guint cursor_pos,
gboolean visible);

/**
* ibus_engine_update_preedit_text_with_mode:
* @engine: An IBusEngine.
* @text: Update content.
* @cursor_pos: Current position of cursor
* @visible: Whether the pre-edit buffer is visible.
* @mode: Pre-edit commit mode when the focus is lost.
*
* Update the pre-edit buffer with commit mode.
* if mode is IBUS_ENGINE_PREEDIT_CLEAR,
* ibus_engine_update_preedit_text_with_mode is compatible with
* ibus_engine_update_preedit_text.
*
* (Note: The text object will be released, if it is floating.
* If caller want to keep the object, caller should make the object
* sink by g_object_ref_sink.)
*/
void ibus_engine_update_preedit_text_with_mode
(IBusEngine *engine,
IBusText *text,
guint cursor_pos,
gboolean visible,
IBusPreeditFocusMode mode);

/**
* ibus_engine_show_preedit_text:
* @engine: An IBusEngine.
Expand Down
12 changes: 12 additions & 0 deletions src/ibustypes.h
Expand Up @@ -111,6 +111,18 @@ typedef enum {
IBUS_CAP_SURROUNDING_TEXT = 1 << 5,
} IBusCapabilite;

/**
* IBusPreeditFocusMode:
* @IBUS_ENGINE_PREEDIT_CLEAR: pre-edit text is cleared.
* @IBUS_ENGINE_PREEDIT_COMMIT: pre-edit text is committed.
*
* Pre-edit commit mode when the focus is lost.
*/
typedef enum {
IBUS_ENGINE_PREEDIT_CLEAR = 0,
IBUS_ENGINE_PREEDIT_COMMIT = 1,
} IBusPreeditFocusMode;

/**
* IBusOrientation:
* @IBUS_ORIENTATION_HORIZONTAL: Horizontal orientation.
Expand Down

0 comments on commit 8ee3864

Please sign in to comment.