Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_handlers.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| data->postbut = but; | data->postbut = but; | ||||
| data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static char unicode_input[10] = {0}; | |||||
| static int ui_handle_unicode_input(uiBut *but, | |||||
| uiHandleButtonData *data, | |||||
| const wmEvent *event, | |||||
| bool *changed) | |||||
| { | |||||
| if (ELEM(event->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY)) { | |||||
| if (event->val == KM_PRESS) { | |||||
| /* Alt first held down, so clear any saved input. */ | |||||
| unicode_input[0] = 0; | |||||
| return WM_UI_HANDLER_CONTINUE; | |||||
| } | |||||
| else if (event->val == KM_RELEASE && unicode_input[0]) { | |||||
| /* Alt released so deal with any previous entry. */ | |||||
| uint val = strtoul(unicode_input, NULL, 16); | |||||
| if (val > 31 && val < 0x10FFFF) { | |||||
| char utf8[10] = {0}; | |||||
| char32_t utf32[2] = {val, 0}; | |||||
| const int utf8_buf_len = BLI_str_utf32_as_utf8(utf8, utf32, 5); | |||||
| *changed = ui_textedit_insert_buf(but, data, utf8, utf8_buf_len); | |||||
| return *changed ? WM_UI_HANDLER_BREAK : WM_UI_HANDLER_CONTINUE; | |||||
| } | |||||
| } | |||||
| } | |||||
| if (event->modifier & KM_ALT && event->val == KM_PRESS) { | |||||
| /* Holding Alt while pressing a key. */ | |||||
| char ch = 0; | |||||
| if ((event->type >= EVT_ZEROKEY && event->type <= EVT_NINEKEY) || | |||||
| (event->type >= EVT_AKEY && event->type <= EVT_FKEY)) { | |||||
| ch = event->type; | |||||
| } | |||||
| else if (event->type >= EVT_PAD0 && event->type <= EVT_PAD9) { | |||||
| ch = event->type - 102; | |||||
| } | |||||
| if (ch) { | |||||
| int len = BLI_strnlen(unicode_input, ARRAY_SIZE(unicode_input)); | |||||
| if (len < ARRAY_SIZE(unicode_input) - 1) { | |||||
| unicode_input[len] = ch; | |||||
| unicode_input[len + 1] = 0; | |||||
| return WM_UI_HANDLER_BREAK; | |||||
| } | |||||
| } | |||||
| } | |||||
| return WM_UI_HANDLER_CONTINUE; | |||||
| } | |||||
| static void ui_do_but_textedit( | static void ui_do_but_textedit( | ||||
| bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| int retval = WM_UI_HANDLER_CONTINUE; | int retval = WM_UI_HANDLER_CONTINUE; | ||||
| bool changed = false, inbox = false, update = false, skip_undo_push = false; | bool changed = false, inbox = false, update = false, skip_undo_push = false; | ||||
| #ifdef WITH_INPUT_IME | #ifdef WITH_INPUT_IME | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | |||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| retval = ui_handle_unicode_input(but, data, event, &changed); | |||||
| if (event->val == KM_PRESS && !is_ime_composing) { | if (event->val == KM_PRESS && !is_ime_composing) { | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case EVT_VKEY: | case EVT_VKEY: | ||||
| case EVT_XKEY: | case EVT_XKEY: | ||||
| case EVT_CKEY: | case EVT_CKEY: | ||||
| #if defined(__APPLE__) | #if defined(__APPLE__) | ||||
| if (ELEM(event->modifier, KM_OSKEY, KM_CTRL)) | if (ELEM(event->modifier, KM_OSKEY, KM_CTRL)) | ||||
| #else | #else | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||