From 825a3d837a33f226c879cd02ad15c3fba57e8b2c Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 23 Jan 2012 23:30:42 +1000 Subject: Update the EFL to what I'm actually using, coz I'm using some stuff not yet released. --- .../src/modules/immodules/xim/ecore_imf_xim.c | 614 +++++++++++++-------- 1 file changed, 398 insertions(+), 216 deletions(-) (limited to 'libraries/ecore/src/modules/immodules/xim/ecore_imf_xim.c') diff --git a/libraries/ecore/src/modules/immodules/xim/ecore_imf_xim.c b/libraries/ecore/src/modules/immodules/xim/ecore_imf_xim.c index 7c40606..ea7ee7f 100644 --- a/libraries/ecore/src/modules/immodules/xim/ecore_imf_xim.c +++ b/libraries/ecore/src/modules/immodules/xim/ecore_imf_xim.c @@ -1,3 +1,7 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + #include #include #include @@ -12,9 +16,6 @@ #include #include #include -#ifdef HAVE_CONFIG_H -# include -#endif #define CLAMP(x, low, high) (x > high) ? high : (x < low) ? low : x #define _(x) x @@ -23,6 +24,8 @@ static Eina_List *open_ims = NULL; #endif +#define FEEDBACK_MASK (XIMReverse | XIMUnderline | XIMHighlight) + typedef struct _XIM_Im_Info XIM_Im_Info; struct _XIM_Im_Info { @@ -51,6 +54,7 @@ struct _Ecore_IMF_Context_Data Eina_Bool finalizing; Eina_Bool has_focus; Eina_Bool in_toplevel; + XIMFeedback *feedbacks; XIMCallback preedit_start_cb; XIMCallback preedit_done_cb; @@ -63,40 +67,62 @@ Ecore_IMF_Context_Data *imf_context_data_new(); void imf_context_data_destroy(Ecore_IMF_Context_Data *imf_context_data); #ifdef ENABLE_XIM -static void reinitialize_ic(Ecore_IMF_Context *ctx); -static void reinitialize_all_ics(XIM_Im_Info *info); -static void set_ic_client_window(Ecore_IMF_Context *ctx, - Ecore_X_Window window); -static int preedit_start_callback(XIC xic, - XPointer client_data, - XPointer call_data); -static void preedit_done_callback(XIC xic, - XPointer client_data, - XPointer call_data); -static int xim_text_to_utf8(Ecore_IMF_Context *ctx, - XIMText *xim_text, - char **text); -static void preedit_draw_callback(XIC xic, - XPointer client_data, - XIMPreeditDrawCallbackStruct *call_data); -static void preedit_caret_callback(XIC xic, - XPointer client_data, - XIMPreeditCaretCallbackStruct *call_data); +static void add_feedback_attr(Eina_List **attrs, + const char *str, + XIMFeedback feedback, + int start_pos, + int end_pos); + +static void reinitialize_ic(Ecore_IMF_Context *ctx); +static void reinitialize_all_ics(XIM_Im_Info *info); +static void set_ic_client_window(Ecore_IMF_Context *ctx, + Ecore_X_Window window); +static int preedit_start_callback(XIC xic, + XPointer client_data, + XPointer call_data); +static void preedit_done_callback(XIC xic, + XPointer client_data, + XPointer call_data); +static int xim_text_to_utf8(Ecore_IMF_Context *ctx, + XIMText *xim_text, + char **text); +static void preedit_draw_callback(XIC xic, + XPointer client_data, + XIMPreeditDrawCallbackStruct *call_data); +static void preedit_caret_callback(XIC xic, + XPointer client_data, + XIMPreeditCaretCallbackStruct *call_data); static XVaNestedList preedit_callback_set(Ecore_IMF_Context *ctx); static XIC get_ic(Ecore_IMF_Context *ctx); static XIM_Im_Info *get_im(Ecore_X_Window window, - char *locale); + char *locale); static void xim_info_try_im(XIM_Im_Info *info); static void xim_info_display_closed(Ecore_X_Display *display, - int is_error, - XIM_Im_Info *info); -static void xim_instantiate_callback(Display *display, - XPointer client_data, - XPointer call_data); -static void setup_im(XIM_Im_Info *info); -static void xim_destroy_callback(XIM xim, - XPointer client_data, - XPointer call_data); + int is_error, + XIM_Im_Info *info); +static void xim_instantiate_callback(Display *display, + XPointer client_data, + XPointer call_data); +static void setup_im(XIM_Im_Info *info); +static void xim_destroy_callback(XIM xim, + XPointer client_data, + XPointer call_data); +#endif + +#ifdef ENABLE_XIM +static unsigned int +utf8_offset_to_index(const char *str, int offset) +{ + int index = 0; + int i; + for (i = 0; i < offset; i++) + { + eina_unicode_utf8_get_next(str, &index); + } + + return index; +} + #endif static void @@ -107,7 +133,7 @@ _ecore_imf_context_xim_add(Ecore_IMF_Context *ctx) Ecore_IMF_Context_Data *imf_context_data = NULL; imf_context_data = imf_context_data_new(); - if(!imf_context_data) return; + if (!imf_context_data) return; imf_context_data->use_preedit = EINA_TRUE; imf_context_data->finalizing = EINA_FALSE; @@ -115,6 +141,8 @@ _ecore_imf_context_xim_add(Ecore_IMF_Context *ctx) imf_context_data->in_toplevel = EINA_FALSE; ecore_imf_context_data_set(ctx, imf_context_data); +#else + (void)ctx; #endif } @@ -127,48 +155,53 @@ _ecore_imf_context_xim_del(Ecore_IMF_Context *ctx) imf_context_data = ecore_imf_context_data_get(ctx); imf_context_data->finalizing = EINA_TRUE; - if(imf_context_data->im_info && !imf_context_data->im_info->ics->next) + if (imf_context_data->im_info && !imf_context_data->im_info->ics->next) { - if(imf_context_data->im_info->reconnecting == EINA_TRUE) + if (imf_context_data->im_info->reconnecting == EINA_TRUE) { Ecore_X_Display *dsp; dsp = ecore_x_display_get(); - XUnregisterIMInstantiateCallback (dsp, - NULL, NULL, NULL, - xim_instantiate_callback, - (XPointer)imf_context_data->im_info); + XUnregisterIMInstantiateCallback(dsp, + NULL, NULL, NULL, + xim_instantiate_callback, + (XPointer)imf_context_data->im_info); } - else if(imf_context_data->im_info->im) + else if (imf_context_data->im_info->im) { XIMCallback im_destroy_callback; im_destroy_callback.client_data = NULL; im_destroy_callback.callback = NULL; - XSetIMValues (imf_context_data->im_info->im, - XNDestroyCallback, &im_destroy_callback, - NULL); + XSetIMValues(imf_context_data->im_info->im, + XNDestroyCallback, &im_destroy_callback, + NULL); } } set_ic_client_window(ctx, 0); imf_context_data_destroy(imf_context_data); +#else + (void)ctx; #endif } static void _ecore_imf_context_xim_client_window_set(Ecore_IMF_Context *ctx, - void *window) + void *window) { EINA_LOG_DBG("in"); #ifdef ENABLE_XIM set_ic_client_window(ctx, (Ecore_X_Window)((Ecore_Window)window)); +#else + (void)ctx; + (void)window; #endif } static void _ecore_imf_context_xim_preedit_string_get(Ecore_IMF_Context *ctx, - char **str, - int *cursor_pos) + char **str, + int *cursor_pos) { EINA_LOG_DBG("in"); #ifdef ENABLE_XIM @@ -180,25 +213,73 @@ _ecore_imf_context_xim_preedit_string_get(Ecore_IMF_Context *ctx, { utf8 = eina_unicode_unicode_to_utf8(imf_context_data->preedit_chars, &len); - if(str) - *str = utf8; + if (str) + *str = utf8; else - free(utf8); + free(utf8); } else { - if(str) - *str = NULL; - if(cursor_pos) - *cursor_pos = 0; + if (str) + *str = NULL; + if (cursor_pos) + *cursor_pos = 0; } - if(cursor_pos) + if (cursor_pos) *cursor_pos = imf_context_data->preedit_cursor; #else - if(str) + (void)ctx; + if (str) + *str = NULL; + if (cursor_pos) + *cursor_pos = 0; +#endif +} + +static void +_ecore_imf_context_xim_preedit_string_with_attributes_get(Ecore_IMF_Context *ctx, + char **str, + Eina_List **attrs, + int *cursor_pos) +{ + EINA_LOG_DBG("in"); + +#ifdef ENABLE_XIM + Ecore_IMF_Context_Data *imf_context_data = ecore_imf_context_data_get(ctx); + + _ecore_imf_context_xim_preedit_string_get(ctx, str, cursor_pos); + + if (!attrs) return; + if (!imf_context_data || !imf_context_data->feedbacks) return; + + int i = 0; + XIMFeedback last_feedback = 0; + int start = -1; + + for (i = 0; i < imf_context_data->preedit_length; i++) + { + XIMFeedback new_feedback = imf_context_data->feedbacks[i] & FEEDBACK_MASK; + + if (new_feedback != last_feedback) + { + if (start >= 0) + add_feedback_attr(attrs, *str, last_feedback, start, i); + + last_feedback = new_feedback; + start = i; + } + } + + if (start >= 0) + add_feedback_attr(attrs, *str, last_feedback, start, i); +#else + (void)ctx; + if (str) *str = NULL; - if(cursor_pos) + if (attrs) + *attrs = NULL; + if (cursor_pos) *cursor_pos = 0; #endif } @@ -213,7 +294,7 @@ _ecore_imf_context_xim_focus_in(Ecore_IMF_Context *ctx) imf_context_data = ecore_imf_context_data_get(ctx); ic = imf_context_data->ic; imf_context_data->has_focus = EINA_TRUE; - if(ic) + if (ic) { char *str; @@ -226,6 +307,8 @@ _ecore_imf_context_xim_focus_in(Ecore_IMF_Context *ctx) XSetICFocus(ic); } +#else + (void)ctx; #endif } @@ -237,13 +320,15 @@ _ecore_imf_context_xim_focus_out(Ecore_IMF_Context *ctx) XIC ic; Ecore_IMF_Context_Data *imf_context_data; imf_context_data = ecore_imf_context_data_get(ctx); - if(imf_context_data->has_focus == EINA_TRUE) + if (imf_context_data->has_focus == EINA_TRUE) { imf_context_data->has_focus = EINA_FALSE; ic = imf_context_data->ic; - if(ic) + if (ic) XUnsetICFocus(ic); } +#else + (void)ctx; #endif } @@ -263,18 +348,18 @@ _ecore_imf_context_xim_reset(Ecore_IMF_Context *ctx) imf_context_data = ecore_imf_context_data_get(ctx); ic = imf_context_data->ic; - if(!ic) + if (!ic) return; - if(imf_context_data->preedit_length == 0) + if (imf_context_data->preedit_length == 0) return; preedit_attr = XVaCreateNestedList(0, XNPreeditState, &preedit_state, NULL); - if(!XGetICValues(ic, - XNPreeditAttributes, preedit_attr, - NULL)) + if (!XGetICValues(ic, + XNPreeditAttributes, preedit_attr, + NULL)) have_preedit_state = EINA_TRUE; XFree(preedit_attr); @@ -284,38 +369,49 @@ _ecore_imf_context_xim_reset(Ecore_IMF_Context *ctx) preedit_attr = XVaCreateNestedList(0, XNPreeditState, preedit_state, NULL); - if(have_preedit_state) + if (have_preedit_state) XSetICValues(ic, XNPreeditAttributes, preedit_attr, NULL); XFree(preedit_attr); - if(imf_context_data->preedit_length) + if (imf_context_data->feedbacks) + { + free(imf_context_data->feedbacks); + imf_context_data->feedbacks = NULL; + } + + if (imf_context_data->preedit_length) { imf_context_data->preedit_length = 0; free(imf_context_data->preedit_chars); imf_context_data->preedit_chars = NULL; + ecore_imf_context_preedit_changed_event_add(ctx); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL); } - if(result) + if (result) { - char *result_utf8 = strdup(result); - if(result_utf8) - { - ecore_imf_context_commit_event_add(ctx, result_utf8); - free(result_utf8); - } + char *result_utf8 = strdup(result); + if (result_utf8) + { + ecore_imf_context_commit_event_add(ctx, result_utf8); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_COMMIT, result_utf8); + free(result_utf8); + } } - XFree (result); + XFree(result); +#else + (void)ctx; #endif } static void _ecore_imf_context_xim_use_preedit_set(Ecore_IMF_Context *ctx, - Eina_Bool use_preedit) + Eina_Bool use_preedit) { EINA_LOG_DBG("in"); #ifdef ENABLE_XIM @@ -324,17 +420,53 @@ _ecore_imf_context_xim_use_preedit_set(Ecore_IMF_Context *ctx, use_preedit = use_preedit != EINA_FALSE; - if(imf_context_data->use_preedit != use_preedit) + if (imf_context_data->use_preedit != use_preedit) { imf_context_data->use_preedit = use_preedit; reinitialize_ic(ctx); } +#else + (void)ctx; + (void)use_preedit; #endif } +#ifdef ENABLE_XIM +static void +add_feedback_attr(Eina_List **attrs, + const char *str, + XIMFeedback feedback, + int start_pos, + int end_pos) +{ + Ecore_IMF_Preedit_Attr *attr = NULL; + + unsigned int start_index = utf8_offset_to_index(str, start_pos); + unsigned int end_index = utf8_offset_to_index(str, end_pos); + + if (feedback & FEEDBACK_MASK) + { + attr = (Ecore_IMF_Preedit_Attr *)calloc(1, sizeof(Ecore_IMF_Preedit_Attr)); + attr->start_index = start_index; + attr->end_index = end_index; + *attrs = eina_list_append(*attrs, (void *)attr); + } + + if (feedback & XIMUnderline) + attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB1; + + if (feedback & XIMReverse) + attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB2; + + if (feedback & XIMHighlight) + attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB3; +} + +#endif + static void -_ecore_imf_context_xim_cursor_location_set (Ecore_IMF_Context *ctx, - int x, int y, int w, int h) +_ecore_imf_context_xim_cursor_location_set(Ecore_IMF_Context *ctx, + int x, int y, int w, int h) { EINA_LOG_DBG("%s in", __FUNCTION__); @@ -342,7 +474,7 @@ _ecore_imf_context_xim_cursor_location_set (Ecore_IMF_Context *ctx, Ecore_IMF_Context_Data *imf_context_data; XIC ic; XVaNestedList preedit_attr; - XPoint spot; + XPoint spot; imf_context_data = ecore_imf_context_data_get(ctx); ic = imf_context_data->ic; @@ -351,15 +483,20 @@ _ecore_imf_context_xim_cursor_location_set (Ecore_IMF_Context *ctx, spot.x = x; spot.y = y + h; - - preedit_attr = XVaCreateNestedList (0, - XNSpotLocation, &spot, - NULL); - XSetICValues (ic, - XNPreeditAttributes, preedit_attr, - NULL); + + preedit_attr = XVaCreateNestedList(0, + XNSpotLocation, &spot, + NULL); + XSetICValues(ic, + XNPreeditAttributes, preedit_attr, + NULL); XFree(preedit_attr); +#else + (void)ctx; + (void)x; + (void)y; + (void)h; #endif (void)(w); // yes w is unused, but only a bi-product of the algorithm } @@ -371,19 +508,19 @@ _ecore_x_event_reverse_modifiers(unsigned int state) unsigned int modifiers = 0; /**< "Control" is pressed */ - if(state & ECORE_IMF_KEYBOARD_MODIFIER_CTRL) + if (state & ECORE_IMF_KEYBOARD_MODIFIER_CTRL) modifiers |= ControlMask; /**< "Alt" is pressed */ - if(state & ECORE_IMF_KEYBOARD_MODIFIER_ALT) + if (state & ECORE_IMF_KEYBOARD_MODIFIER_ALT) modifiers |= Mod1Mask; /**< "Shift" is pressed */ - if(state & ECORE_IMF_KEYBOARD_MODIFIER_SHIFT) + if (state & ECORE_IMF_KEYBOARD_MODIFIER_SHIFT) modifiers |= ShiftMask; /**< "Win" (between "Ctrl" and "A */ - if(state & ECORE_IMF_KEYBOARD_MODIFIER_WIN) + if (state & ECORE_IMF_KEYBOARD_MODIFIER_WIN) modifiers |= Mod5Mask; return modifiers; @@ -395,14 +532,14 @@ _ecore_x_event_reverse_locks(unsigned int state) unsigned int locks = 0; /**< "Num" lock is active */ - if(state & ECORE_IMF_KEYBOARD_LOCK_NUM) + if (state & ECORE_IMF_KEYBOARD_LOCK_NUM) locks |= Mod3Mask; - if(state & ECORE_IMF_KEYBOARD_LOCK_CAPS) + if (state & ECORE_IMF_KEYBOARD_LOCK_CAPS) locks |= LockMask; -#if 0 /* FIXME: add mask. */ - if(state & ECORE_IMF_KEYBOARD_LOCK_SCROLL) +#if 0 /* FIXME: add mask. */ + if (state & ECORE_IMF_KEYBOARD_LOCK_SCROLL) ; #endif @@ -411,12 +548,12 @@ _ecore_x_event_reverse_locks(unsigned int state) static KeyCode _keycode_get(Ecore_X_Display *dsp, - const char *keyname) + const char *keyname) { KeyCode keycode; // EINA_LOG_DBG("keyname:%s keysym:%lu", keyname, XStringToKeysym(keyname)); - if(strcmp(keyname, "Keycode-0") == 0) + if (strcmp(keyname, "Keycode-0") == 0) { keycode = 0; } @@ -430,9 +567,9 @@ _keycode_get(Ecore_X_Display *dsp, #endif static Eina_Bool -_ecore_imf_context_xim_filter_event(Ecore_IMF_Context *ctx, +_ecore_imf_context_xim_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, - Ecore_IMF_Event *event) + Ecore_IMF_Event *event) { EINA_LOG_DBG("%s in", __FUNCTION__); #ifdef ENABLE_XIM @@ -451,12 +588,12 @@ _ecore_imf_context_xim_filter_event(Ecore_IMF_Context *ctx, imf_context_data = ecore_imf_context_data_get(ctx); ic = imf_context_data->ic; - if(!ic) + if (!ic) { ic = get_ic(ctx); } - if(type == ECORE_IMF_EVENT_KEY_DOWN) + if (type == ECORE_IMF_EVENT_KEY_DOWN) { XKeyPressedEvent xev; Ecore_IMF_Event_Key_Down *ev = (Ecore_IMF_Event_Key_Down *)event; @@ -481,7 +618,7 @@ _ecore_imf_context_xim_filter_event(Ecore_IMF_Context *ctx, xev.keycode = _keycode_get(dsp, ev->keyname); xev.same_screen = True; - if(ic) + if (ic) { Status mbstatus; #ifdef X_HAVE_UTF8_STRING @@ -563,15 +700,16 @@ _ecore_imf_context_xim_filter_event(Ecore_IMF_Context *ctx, } } - if(compose) + if (compose) { Eina_Unicode *unicode; int len; unicode = eina_unicode_utf8_to_unicode(compose, &len); - if(!unicode) abort(); - if(unicode[0] >= 0x20 && unicode[0] != 0x7f) + if (!unicode) abort(); + if (unicode[0] >= 0x20 && unicode[0] != 0x7f) { ecore_imf_context_commit_event_add(ctx, compose); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_COMMIT, compose); result = EINA_TRUE; } free(compose); @@ -581,6 +719,9 @@ _ecore_imf_context_xim_filter_event(Ecore_IMF_Context *ctx, return result; #else + (void)ctx; + (void)type; + (void)event; return EINA_FALSE; #endif } @@ -608,7 +749,7 @@ static Ecore_IMF_Context_Class xim_class = { .use_preedit_set = _ecore_imf_context_xim_use_preedit_set, .input_mode_set = NULL, .filter_event = _ecore_imf_context_xim_filter_event, - .preedit_string_with_attributes_get = NULL, + .preedit_string_with_attributes_get = _ecore_imf_context_xim_preedit_string_with_attributes_get, .prediction_allow_set = NULL, .autocapital_type_set = NULL, .control_panel_show = NULL, @@ -627,7 +768,7 @@ xim_imf_module_create(void) Ecore_IMF_Context *ctx = NULL; ctx = ecore_imf_context_new(&xim_class); - if(!ctx) + if (!ctx) goto error; return ctx; @@ -686,15 +827,15 @@ imf_context_data_new() char *locale; locale = setlocale(LC_CTYPE, ""); - if(!locale) return NULL; + if (!locale) return NULL; - if(!XSupportsLocale()) return NULL; + if (!XSupportsLocale()) return NULL; imf_context_data = calloc(1, sizeof(Ecore_IMF_Context_Data)); - if(!imf_context_data) return NULL; + if (!imf_context_data) return NULL; imf_context_data->locale = strdup(locale); - if(!imf_context_data->locale) goto error; + if (!imf_context_data->locale) goto error; return imf_context_data; error: @@ -705,19 +846,26 @@ error: void imf_context_data_destroy(Ecore_IMF_Context_Data *imf_context_data) { - if(!imf_context_data) + if (!imf_context_data) return; - if(imf_context_data->ic) + if (imf_context_data->ic) XDestroyIC(imf_context_data->ic); free(imf_context_data->preedit_chars); + + if (imf_context_data->feedbacks) + { + free(imf_context_data->feedbacks); + imf_context_data->feedbacks = NULL; + } + free(imf_context_data->locale); free(imf_context_data); } static int -preedit_start_callback(XIC xic __UNUSED__, +preedit_start_callback(XIC xic __UNUSED__, XPointer client_data, XPointer call_data __UNUSED__) { @@ -726,14 +874,16 @@ preedit_start_callback(XIC xic __UNUSED__, Ecore_IMF_Context_Data *imf_context_data; imf_context_data = ecore_imf_context_data_get(ctx); - if(imf_context_data->finalizing == EINA_FALSE) - ecore_imf_context_preedit_start_event_add(ctx); - + if (imf_context_data->finalizing == EINA_FALSE) + { + ecore_imf_context_preedit_start_event_add(ctx); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_START, NULL); + } return -1; } static void -preedit_done_callback(XIC xic __UNUSED__, +preedit_done_callback(XIC xic __UNUSED__, XPointer client_data, XPointer call_data __UNUSED__) { @@ -742,30 +892,34 @@ preedit_done_callback(XIC xic __UNUSED__, Ecore_IMF_Context_Data *imf_context_data; imf_context_data = ecore_imf_context_data_get(ctx); - if(imf_context_data->preedit_length) + if (imf_context_data->preedit_length) { imf_context_data->preedit_length = 0; free(imf_context_data->preedit_chars); imf_context_data->preedit_chars = NULL; ecore_imf_context_preedit_changed_event_add(ctx); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL); } - if(imf_context_data->finalizing == EINA_FALSE) - ecore_imf_context_preedit_end_event_add(ctx); + if (imf_context_data->finalizing == EINA_FALSE) + { + ecore_imf_context_preedit_end_event_add(ctx); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_END, NULL); + } } /* FIXME */ static int xim_text_to_utf8(Ecore_IMF_Context *ctx __UNUSED__, - XIMText *xim_text, - char **text) + XIMText *xim_text, + char **text) { int text_length = 0; char *result = NULL; - if(xim_text && xim_text->string.multi_byte) + if (xim_text && xim_text->string.multi_byte) { - if(xim_text->encoding_is_wchar) + if (xim_text->encoding_is_wchar) { EINA_LOG_WARN("Wide character return from Xlib not currently supported"); *text = NULL; @@ -774,7 +928,7 @@ xim_text_to_utf8(Ecore_IMF_Context *ctx __UNUSED__, /* XXX Convert to UTF-8 */ result = strdup(xim_text->string.multi_byte); - if(result) + if (result) { text_length = eina_unicode_utf8_get_len(result); if (text_length != xim_text->length) @@ -798,8 +952,8 @@ xim_text_to_utf8(Ecore_IMF_Context *ctx __UNUSED__, } static void -preedit_draw_callback(XIC xic __UNUSED__, - XPointer client_data, +preedit_draw_callback(XIC xic __UNUSED__, + XPointer client_data, XIMPreeditDrawCallbackStruct *call_data) { EINA_LOG_DBG("in"); @@ -811,59 +965,83 @@ preedit_draw_callback(XIC xic __UNUSED__, Eina_Unicode *new_text = NULL; Eina_UStrbuf *preedit_bufs = NULL; int new_text_length; + int i = 0; preedit_bufs = eina_ustrbuf_new(); - if(imf_context_data->preedit_chars) { - ret = eina_ustrbuf_append(preedit_bufs, imf_context_data->preedit_chars); - if(ret == EINA_FALSE) goto done; - } + if (imf_context_data->preedit_chars) + { + ret = eina_ustrbuf_append(preedit_bufs, imf_context_data->preedit_chars); + if (ret == EINA_FALSE) goto done; + } new_text_length = xim_text_to_utf8(ctx, t, &tmp); - if(tmp) + if (tmp) { int tmp_len; new_text = eina_unicode_utf8_to_unicode((const char *)tmp, &tmp_len); free(tmp); } - if(t == NULL) { - /* delete string */ - ret = eina_ustrbuf_remove(preedit_bufs, - call_data->chg_first, call_data->chg_length); - } else if(call_data->chg_length == 0) { - /* insert string */ - ret = eina_ustrbuf_insert(preedit_bufs, new_text, call_data->chg_first); - } else if(call_data->chg_length > 0) { - /* replace string */ - ret = eina_ustrbuf_remove(preedit_bufs, - call_data->chg_first, call_data->chg_length); - if(ret == EINA_FALSE) goto done; - - ret = eina_ustrbuf_insert_n(preedit_bufs, new_text, - new_text_length, call_data->chg_first); - if(ret == EINA_FALSE) goto done; - } else { - ret = EINA_FALSE; - } - - done: - if(ret == EINA_TRUE) { - free(imf_context_data->preedit_chars); - imf_context_data->preedit_chars = + if (t == NULL) + { + /* delete string */ + ret = eina_ustrbuf_remove(preedit_bufs, + call_data->chg_first, call_data->chg_length); + } + else if (call_data->chg_length == 0) + { + /* insert string */ + ret = eina_ustrbuf_insert(preedit_bufs, new_text, call_data->chg_first); + } + else if (call_data->chg_length > 0) + { + /* replace string */ + ret = eina_ustrbuf_remove(preedit_bufs, + call_data->chg_first, call_data->chg_length); + if (ret == EINA_FALSE) goto done; + + ret = eina_ustrbuf_insert_n(preedit_bufs, new_text, + new_text_length, call_data->chg_first); + if (ret == EINA_FALSE) goto done; + } + else { + ret = EINA_FALSE; + } + +done: + if (ret == EINA_TRUE) + { + free(imf_context_data->preedit_chars); + imf_context_data->preedit_chars = eina_ustrbuf_string_steal(preedit_bufs); - imf_context_data->preedit_length = + imf_context_data->preedit_length = eina_unicode_strlen(imf_context_data->preedit_chars); - ecore_imf_context_preedit_changed_event_add(ctx); - } + if (imf_context_data->feedbacks) + { + free(imf_context_data->feedbacks); + imf_context_data->feedbacks = NULL; + } + + if (imf_context_data->preedit_length > 0) + { + imf_context_data->feedbacks = calloc(imf_context_data->preedit_length, sizeof(XIMFeedback)); + + for (i = 0; i < imf_context_data->preedit_length; i++) + imf_context_data->feedbacks[i] = t->feedback[i]; + } + + ecore_imf_context_preedit_changed_event_add(ctx); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL); + } free(new_text); eina_ustrbuf_free(preedit_bufs); } static void -preedit_caret_callback(XIC xic __UNUSED__, - XPointer client_data, +preedit_caret_callback(XIC xic __UNUSED__, + XPointer client_data, XIMPreeditCaretCallbackStruct *call_data) { EINA_LOG_DBG("in"); @@ -871,12 +1049,15 @@ preedit_caret_callback(XIC xic __UNUSED__, Ecore_IMF_Context_Data *imf_context_data; imf_context_data = ecore_imf_context_data_get(ctx); - if(call_data->direction == XIMAbsolutePosition) + if (call_data->direction == XIMAbsolutePosition) { // printf("call_data->position:%d\n", call_data->position); - imf_context_data->preedit_cursor = call_data->position; - if(imf_context_data->finalizing == EINA_FALSE) - ecore_imf_context_preedit_changed_event_add(ctx); + imf_context_data->preedit_cursor = call_data->position; + if (imf_context_data->finalizing == EINA_FALSE) + { + ecore_imf_context_preedit_changed_event_add(ctx); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL); + } } } @@ -917,7 +1098,7 @@ get_ic(Ecore_IMF_Context *ctx) XIC ic; imf_context_data = ecore_imf_context_data_get(ctx); ic = imf_context_data->ic; - if(!ic) + if (!ic) { XIM_Im_Info *im_info = imf_context_data->im_info; XVaNestedList preedit_attr = NULL; @@ -930,7 +1111,7 @@ get_ic(Ecore_IMF_Context *ctx) EINA_LOG_WARN("Doesn't open XIM."); return NULL; } - + // supported styles #if 0 int i; @@ -940,23 +1121,23 @@ get_ic(Ecore_IMF_Context *ctx) { printf("%i: ", i); if (im_info->xim_styles->supported_styles[i] & XIMPreeditCallbacks) - printf("XIMPreeditCallbacks | "); + printf("XIMPreeditCallbacks | "); if (im_info->xim_styles->supported_styles[i] & XIMPreeditPosition) - printf("XIMPreeditPosition | "); + printf("XIMPreeditPosition | "); if (im_info->xim_styles->supported_styles[i] & XIMPreeditArea) - printf("XIMPreeditArea | "); + printf("XIMPreeditArea | "); if (im_info->xim_styles->supported_styles[i] & XIMPreeditNothing) - printf("XIMPreeditNothing | "); + printf("XIMPreeditNothing | "); if (im_info->xim_styles->supported_styles[i] & XIMPreeditNone) - printf("XIMPreeditNone | "); + printf("XIMPreeditNone | "); if (im_info->xim_styles->supported_styles[i] & XIMStatusArea) - printf("XIMStatusArea | "); + printf("XIMStatusArea | "); if (im_info->xim_styles->supported_styles[i] & XIMStatusCallbacks) - printf("XIMStatusCallbacks | "); + printf("XIMStatusCallbacks | "); if (im_info->xim_styles->supported_styles[i] & XIMStatusNothing) - printf("XIMStatusNothing | "); + printf("XIMStatusNothing | "); if (im_info->xim_styles->supported_styles[i] & XIMStatusNone) - printf("XIMStatusNone | "); + printf("XIMStatusNone | "); printf("\n"); } } @@ -969,12 +1150,12 @@ get_ic(Ecore_IMF_Context *ctx) { if (im_info->supports_cursor) { - // kinput2 DOES do this... + // kinput2 DOES do this... XFontSet fs; char **missing_charset_list; int missing_charset_count; char *def_string; - + im_style |= XIMPreeditPosition; im_style |= XIMStatusNothing; fs = XCreateFontSet(ecore_x_display_get(), @@ -995,7 +1176,7 @@ get_ic(Ecore_IMF_Context *ctx) } name = XNPreeditAttributes; } - else + else { im_style |= XIMPreeditNothing; im_style |= XIMStatusNothing; @@ -1009,18 +1190,18 @@ get_ic(Ecore_IMF_Context *ctx) name, preedit_attr, NULL); } XFree(preedit_attr); - if(ic) + if (ic) { unsigned long mask = 0xaaaaaaaa; - XGetICValues (ic, - XNFilterEvents, &mask, - NULL); + XGetICValues(ic, + XNFilterEvents, &mask, + NULL); imf_context_data->mask = mask; ecore_x_event_mask_set(imf_context_data->win, mask); } imf_context_data->ic = ic; - if(ic && imf_context_data->has_focus == EINA_TRUE) + if (ic && imf_context_data->has_focus == EINA_TRUE) XSetICFocus(ic); } @@ -1032,16 +1213,17 @@ reinitialize_ic(Ecore_IMF_Context *ctx) { Ecore_IMF_Context_Data *imf_context_data = ecore_imf_context_data_get(ctx); XIC ic = imf_context_data->ic; - if(ic) + if (ic) { XDestroyIC(ic); imf_context_data->ic = NULL; - if(imf_context_data->preedit_length) + if (imf_context_data->preedit_length) { imf_context_data->preedit_length = 0; free(imf_context_data->preedit_chars); imf_context_data->preedit_chars = NULL; ecore_imf_context_preedit_changed_event_add(ctx); + ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL); } } } @@ -1052,13 +1234,13 @@ reinitialize_all_ics(XIM_Im_Info *info) Eina_List *tmp_list; Ecore_IMF_Context *ctx; - EINA_LIST_FOREACH(info->ics, tmp_list, ctx) + EINA_LIST_FOREACH (info->ics, tmp_list, ctx) reinitialize_ic(ctx); } static void set_ic_client_window(Ecore_IMF_Context *ctx, - Ecore_X_Window window) + Ecore_X_Window window) { EINA_LOG_DBG("in"); Ecore_IMF_Context_Data *imf_context_data = ecore_imf_context_data_get(ctx); @@ -1069,7 +1251,7 @@ set_ic_client_window(Ecore_IMF_Context *ctx, old_win = imf_context_data->win; EINA_LOG_DBG("old_win:%d window:%d ", old_win, window); - if(old_win != 0 && old_win != window) /* XXX how do check window... */ + if (old_win != 0 && old_win != window) /* XXX how do check window... */ { XIM_Im_Info *info; info = imf_context_data->im_info; @@ -1079,7 +1261,7 @@ set_ic_client_window(Ecore_IMF_Context *ctx, imf_context_data->win = window; - if(window) /* XXX */ + if (window) /* XXX */ { XIM_Im_Info *info = NULL; info = get_im(window, imf_context_data->locale); @@ -1092,17 +1274,17 @@ set_ic_client_window(Ecore_IMF_Context *ctx, static XIM_Im_Info * get_im(Ecore_X_Window window, - char *locale) + char *locale) { EINA_LOG_DBG("in"); Eina_List *l; XIM_Im_Info *im_info = NULL; XIM_Im_Info *info = NULL; - EINA_LIST_FOREACH(open_ims, l, im_info) { - if(strcmp(im_info->locale, locale) == 0) + EINA_LIST_FOREACH (open_ims, l, im_info) { + if (strcmp(im_info->locale, locale) == 0) { - if(im_info->im) + if (im_info->im) { return im_info; } @@ -1113,10 +1295,10 @@ get_im(Ecore_X_Window window, } } - if(!info) + if (!info) { info = calloc(1, sizeof(XIM_Im_Info)); - if(!info) return NULL; + if (!info) return NULL; open_ims = eina_list_prepend(open_ims, info); info->win = window; info->locale = strdup(locale); @@ -1137,13 +1319,13 @@ xim_info_try_im(XIM_Im_Info *info) if (info->reconnecting == EINA_TRUE) return; - if(XSupportsLocale()) + if (XSupportsLocale()) { - if (!XSetLocaleModifiers ("")) + if (!XSetLocaleModifiers("")) EINA_LOG_WARN("Unable to set locale modifiers with XSetLocaleModifiers()"); dsp = ecore_x_display_get(); info->im = XOpenIM(dsp, NULL, NULL, NULL); - if(!info->im) + if (!info->im) { XRegisterIMInstantiateCallback(dsp, NULL, NULL, NULL, @@ -1158,8 +1340,8 @@ xim_info_try_im(XIM_Im_Info *info) static void xim_info_display_closed(Ecore_X_Display *display __UNUSED__, - int is_error __UNUSED__, - XIM_Im_Info *info) + int is_error __UNUSED__, + XIM_Im_Info *info) { Eina_List *ics, *tmp_list; Ecore_IMF_Context *ctx; @@ -1169,21 +1351,21 @@ xim_info_display_closed(Ecore_X_Display *display __UNUSED__, ics = info->ics; info->ics = NULL; - EINA_LIST_FOREACH(ics, tmp_list, ctx) + EINA_LIST_FOREACH (ics, tmp_list, ctx) set_ic_client_window(ctx, 0); - EINA_LIST_FREE(ics, ctx) { + EINA_LIST_FREE (ics, ctx) { Ecore_IMF_Context_Data *imf_context_data; imf_context_data = ecore_imf_context_data_get(ctx); imf_context_data_destroy(imf_context_data); } - free (info->locale); + free(info->locale); if (info->im) - XCloseIM (info->im); + XCloseIM(info->im); - free (info); + free(info); } static void @@ -1203,11 +1385,11 @@ xim_instantiate_callback(Display *display, } info->im = im; - setup_im (info); + setup_im(info); - XUnregisterIMInstantiateCallback (display, NULL, NULL, NULL, - xim_instantiate_callback, - (XPointer)info); + XUnregisterIMInstantiateCallback(display, NULL, NULL, NULL, + xim_instantiate_callback, + (XPointer)info); info->reconnecting = EINA_FALSE; } @@ -1217,7 +1399,7 @@ setup_im(XIM_Im_Info *info) XIMValuesList *ic_values = NULL; XIMCallback im_destroy_callback; - if(!info->im) + if (!info->im) return; im_destroy_callback.client_data = (XPointer)info; @@ -1239,25 +1421,25 @@ setup_im(XIM_Im_Info *info) { if (!strcmp(ic_values->supported_values[i], XNStringConversionCallback)) - info->supports_string_conversion = EINA_TRUE; + info->supports_string_conversion = EINA_TRUE; if (!strcmp(ic_values->supported_values[i], XNCursor)) - info->supports_cursor = EINA_TRUE; + info->supports_cursor = EINA_TRUE; } #if 0 printf("values........\n"); for (i = 0; i < ic_values->count_values; i++) - printf("%s\n", ic_values->supported_values[i]); + printf("%s\n", ic_values->supported_values[i]); printf("styles........\n"); for (i = 0; i < info->xim_styles->count_styles; i++) - printf("%lx\n", info->xim_styles->supported_styles[i]); + printf("%lx\n", info->xim_styles->supported_styles[i]); #endif XFree(ic_values); } } static void -xim_destroy_callback(XIM xim __UNUSED__, +xim_destroy_callback(XIM xim __UNUSED__, XPointer client_data, XPointer call_data __UNUSED__) { -- cgit v1.1