From e81d077c852f43b635f10972479e36909a66d60c Mon Sep 17 00:00:00 2001 From: Severin Date: Sun, 7 Dec 2014 00:58:17 +0100 Subject: Input Method Editor (IME) support for text buttons Original patch by @random (D765) with some minor work done by @campbell and me. At this place, I'd like call out a number of people who were involved and deserve a big "Thank you!": * At the first place @randon who developed and submitted the patch * The Blendercn community which helped a lot with testing - espacially * @yuzukyo, @leon_cheung and @kjym3 * @campbellbarton, @mont29 and @sergey for their help and advises during * review * @ton who realized the importance of this early on and asked me for * reviewing We are still not finished, as this is only the first part of the implementaion, but there's more to come! --- source/blender/windowmanager/CMakeLists.txt | 6 ++++ source/blender/windowmanager/SConscript | 4 +++ source/blender/windowmanager/WM_api.h | 4 +++ source/blender/windowmanager/WM_types.h | 18 ++++++++++++ .../blender/windowmanager/intern/wm_event_system.c | 34 ++++++++++++++++++++++ source/blender/windowmanager/intern/wm_window.c | 17 +++++++++++ source/blender/windowmanager/wm_event_types.h | 7 +++++ source/blender/windowmanager/wm_window.h | 5 ++++ 8 files changed, 95 insertions(+) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 4cbadda1732..78b5d499644 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -130,6 +130,12 @@ if(WITH_BUILDINFO) add_definitions(-DWITH_BUILDINFO) endif() +if(WIN32) + if(WITH_INPUT_IME) + add_definitions(-DWITH_INPUT_IME) + endif() +endif() + if(WITH_COMPOSITOR) add_definitions(-DWITH_COMPOSITOR) endif() diff --git a/source/blender/windowmanager/SConscript b/source/blender/windowmanager/SConscript index 3c44ff6107c..a6f64f7cdae 100644 --- a/source/blender/windowmanager/SConscript +++ b/source/blender/windowmanager/SConscript @@ -69,6 +69,10 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', ' if env['BF_BUILDINFO']: defs.append('WITH_BUILDINFO') +if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'win64-mingw'): + if env['WITH_BF_IME']: + defs.append('WITH_INPUT_IME') + if env['WITH_BF_INTERNATIONAL']: defs.append('WITH_INTERNATIONAL') diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index ced7222b046..d2abfd419d1 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -462,6 +462,10 @@ void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4 float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float tilt[2]); bool WM_event_is_tablet(const struct wmEvent *event); +#ifdef WITH_INPUT_IME +bool WM_event_is_ime_switch(const struct wmEvent *event); +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 4b6b5e95366..d9924cfb053 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -570,6 +570,24 @@ typedef struct wmOperatorType { } wmOperatorType; +#ifdef WITH_INPUT_IME +/* *********** Input Method Editor (IME) *********** */ + +/* similar to GHOST_TEventImeData */ +typedef struct wmIMEData { + size_t result_len, composite_len; + + char *str_result; /* utf8 encoding */ + char *str_composite; /* utf8 encoding */ + + int cursor_pos; /* cursor position in the IME composition. */ + int sel_start; /* beginning of the selection */ + int sel_end; /* end of the selection */ + + bool is_ime_composing; +} wmIMEData; +#endif + /* **************** Paint Cursor ******************* */ typedef void (*wmPaintCursorDraw)(struct bContext *C, int, int, void *customdata); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index cca267a9fbb..3de34e7ca3f 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -3373,6 +3373,33 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U break; } +#ifdef WITH_INPUT_IME + case GHOST_kEventImeCompositionStart: + { + event.val = KM_PRESS; + win->ime_data = customdata; + win->ime_data->is_ime_composing = true; + event.type = WM_IME_COMPOSITE_START; + wm_event_add(win, &event); + break; + } + case GHOST_kEventImeComposition: + { + event.val = KM_PRESS; + event.type = WM_IME_COMPOSITE_EVENT; + wm_event_add(win, &event); + break; + } + case GHOST_kEventImeCompositionEnd: + { + event.val = KM_PRESS; + win->ime_data->is_ime_composing = false; + event.type = WM_IME_COMPOSITE_END; + wm_event_add(win, &event); + break; + } +#endif /* WITH_INPUT_IME */ + } #if 0 @@ -3479,5 +3506,12 @@ bool WM_event_is_tablet(const struct wmEvent *event) return (event->tablet_data) ? true : false; } +#ifdef WITH_INPUT_IME +/* most os using ctrl/oskey + space to switch ime, avoid added space */ +bool WM_event_is_ime_switch(const struct wmEvent *event) { + return event->val == KM_PRESS && event->type == SPACEKEY && + (event->ctrl || event->oskey || event->shift || event->alt); +} +#endif /** \} */ diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 46a20d3bf88..0b33dbb2c32 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1524,3 +1524,20 @@ bool WM_window_is_fullscreen(wmWindow *win) return win->windowstate == GHOST_kWindowStateFullScreen; } + +#ifdef WITH_INPUT_IME +void wm_window_IME_begin(wmWindow *win, int x, int y, int w, int h, bool complete) +{ + BLI_assert(win && (win->ime_data == NULL)); + + GHOST_BeginIME(win->ghostwin, x, win->sizey - y, w, h, complete); +} + +void wm_window_IME_end(wmWindow *win) +{ + BLI_assert(win && win->ime_data); + + GHOST_EndIME(win->ghostwin); + win->ime_data = NULL; +} +#endif /* WITH_INPUT_IME */ diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index fe6d3431183..2301405a8ea 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -86,6 +86,13 @@ enum { * paint and drawing tools however will want to handle these. */ INBETWEEN_MOUSEMOVE = 0x0011, +/* IME event, GHOST_kEventImeCompositionStart in ghost */ + WM_IME_COMPOSITE_START = 0x0014, +/* IME event, GHOST_kEventImeComposition in ghost */ + WM_IME_COMPOSITE_EVENT = 0x0015, +/* IME event, GHOST_kEventImeCompositionEnd in ghost */ + WM_IME_COMPOSITE_END = 0x0016, + /* *** Start of keyboard codes. *** */ /* standard keyboard. diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index 9c9c79d2f54..833234b0f13 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -69,6 +69,11 @@ wmWindow *wm_window_copy (bContext *C, wmWindow *winorig); void wm_window_testbreak (void); +#ifdef WITH_INPUT_IME +void wm_window_IME_begin (wmWindow *win, int x, int y, int w, int h, bool complete); +void wm_window_IME_end (wmWindow *win); +#endif + /* *************** window operators ************** */ int wm_window_duplicate_exec(bContext *C, struct wmOperator *op); int wm_window_fullscreen_toggle_exec(bContext *C, struct wmOperator *op); -- cgit v1.2.3