[Bf-blender-cvs] [316bae9] input_method_editor: General Review Changes

Severin noreply at git.blender.org
Wed Nov 26 00:42:15 CET 2014


Commit: 316bae9fe859b11820d3fcbf3ae362afbde70d61
Author: Severin
Date:   Wed Nov 26 00:34:24 2014 +0100
Branches: input_method_editor
https://developer.blender.org/rB316bae9fe859b11820d3fcbf3ae362afbde70d61

General Review Changes

Main changes:
* avoid using MEM_mallocN on every redraw
* continue implementation of WITH_INPUT_IME CMake flag
* whitespace and code style cleanups

===================================================================

M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_console/CMakeLists.txt
M	source/blender/editors/space_console/console_draw.c
M	source/blender/editors/space_console/space_console.c
M	source/blender/editors/space_info/CMakeLists.txt
M	source/blender/editors/space_info/textview.c
M	source/blender/editors/space_text/CMakeLists.txt
M	source/blender/editors/space_text/space_text.c
M	source/blender/editors/space_text/text_draw.c
M	source/blender/windowmanager/WM_types.h

===================================================================

diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index a09e431..5ae5ec0 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -1055,7 +1055,7 @@ GHOST_TSuccess GHOST_WindowWin32::endProgressBar()
 void GHOST_WindowWin32::beginIME(GHOST_TInt32 x, GHOST_TInt32 y, GHOST_TInt32 w, GHOST_TInt32 h, int completed)
 {
 	h = 20; /* text height */
-	this->getImeInput()->BeginIME(this->getHWND(),	GHOST_Rect(x, y-h, x, y), (bool)completed);
+	this->getImeInput()->BeginIME(this->getHWND(),	GHOST_Rect(x, y - h , x, y), (bool)completed);
 }
 
 
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 981603f..905c865 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1008,5 +1008,5 @@ void UI_butstore_unregister(uiButStore *bs_handle, uiBut **but_p);
 int UI_calc_float_precision(int prec, double value);
 
 /* Utility */
-extern void ui_region_to_window(const struct ARegion *ar, int *x, int *y);
+void ui_region_to_window(const struct ARegion *ar, int *x, int *y);
 #endif  /* __UI_INTERFACE_H__ */
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index fd69ebc..e83dd02 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -2430,11 +2430,14 @@ static bool ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, const in
 /* enable ime, and set up uibut ime data */
 static void ui_textedit_ime_begin(wmWindow *win, uiBut *UNUSED(but))
 {
+	/* XXX Is this really needed? */
 	int x, y;
+
 	/* enable IME and position to cursor, it's a trick */
 	x = win->eventstate->x;
 	/* flip y and move down a bit, prevent the IME panel cover the edit button */
 	y = win->eventstate->y - 12;
+
 	wm_window_IME_begin(win, x, y, 0, 0, true);
 }
 
@@ -2446,8 +2449,10 @@ static void ui_textedit_ime_end(wmWindow *win, uiBut *UNUSED(but))
 
 void ui_but_ime_reposition(uiBut *but, int x, int y, int complete) 
 {
+	BLI_assert(but->active);
+
 	ui_region_to_window(but->active->region, &x, &y);
-	wm_window_IME_begin(but->active->window, x, y-4, 0, 0, complete);
+	wm_window_IME_begin(but->active->window, x, y - 4, 0, 0, complete);
 }
 
 wmImeData *ui_but_get_ime_data(uiBut *but) 
@@ -2517,19 +2522,17 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
 	but->flag &= ~UI_BUT_REDALERT;
 
 	ui_but_update(but);
-	
-#ifdef WITH_INPUT_IME
+
 	WM_cursor_modal_set(win, BC_TEXTEDITCURSOR);
 
+#ifdef WITH_INPUT_IME
 	ui_textedit_ime_begin(win, but);
-#else
-	(void)win;
 #endif
 }
 
 static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
 {
-	wmWindow *win;
+	wmWindow *win = CTX_wm_window(C);
 
 	if (but) {
 		if (ui_but_is_utf8(but)) {
@@ -2560,14 +2563,11 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
 		but->editstr = NULL;
 		but->pos = -1;
 	}
-
-#ifdef WITH_INPUT_IME
-	win = CTX_wm_window(C);
+	
 	WM_cursor_modal_restore(win);
 
+#ifdef WITH_INPUT_IME
 	ui_textedit_ime_end(win, but);
-#else
-	(void)win;
 #endif
 }
 
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 457907b..ab1a859 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1239,7 +1239,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
 {
 	int drawstr_left_len = UI_MAX_DRAW_STR;
-	const char *drawstr = but->drawstr;
+	char *drawstr = but->drawstr;
 	const char *drawstr_right = NULL;
 	char *drawstr_edit = NULL;
 	bool use_right_only = false;
@@ -1278,16 +1278,9 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
 
 			if (ime && ime->composite_len) {
 				/* insert composite string into cursor pos */
-				char *str;
-				size_t len, slen;
-				len = strlen(but->editstr);
-				slen = ime->composite_len;
-				str = MEM_mallocN(sizeof(char) * (slen + len + 1), "drawstr edit buffer");
-				memcpy(str, but->editstr, sizeof(char) * but->pos);
-				memcpy(str + but->pos, ime->composite, sizeof(char) * slen);
-				memcpy(str + but->pos + slen, but->editstr + but->pos, sizeof(char) + (len - but->pos));
-				str[len + slen] = '\0';
-				drawstr = drawstr_edit = str;
+				BLI_snprintf(drawstr, UI_MAX_DRAW_STR, "%s%s%s", /* XXX drawstr is limited to 400 chars - check if that's enough */
+				             but->editstr, ime->composite,
+				             but->editstr + but->pos);
 			}
 			else {
 #else
@@ -1331,8 +1324,9 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
 		vpos = but->pos;
 #ifdef WITH_INPUT_IME
 		/* if is ime compositing, move the cursor */
-		if (ime && ime->composite_len && ime->cursor_position != -1)
+		if (ime && ime->composite_len && ime->cursor_position != -1) {
 			vpos += ime->cursor_position;
+		}
 #else
 		(void)ime;
 #endif
@@ -1495,9 +1489,6 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
 		rect->xmax -= UI_TEXT_CLIP_MARGIN;
 		UI_fontstyle_draw(fstyle, rect, drawstr_right);
 	}
-
-	if (drawstr_edit)
-		MEM_freeN(drawstr_edit);
 }
 
 /* draws text and icons for buttons */
diff --git a/source/blender/editors/space_console/CMakeLists.txt b/source/blender/editors/space_console/CMakeLists.txt
index ecfb1f0..1353d94 100644
--- a/source/blender/editors/space_console/CMakeLists.txt
+++ b/source/blender/editors/space_console/CMakeLists.txt
@@ -47,6 +47,12 @@ if(WITH_PYTHON)
 	add_definitions(-DWITH_PYTHON)
 endif()
 
+if(WIN32)
+	if(WITH_INPUT_IME)
+		add_definitions(-DWITH_INPUT_IME)
+	endif()
+endif()
+
 add_definitions(${GL_DEFINITIONS})
 
 blender_add_lib(bf_editor_space_console "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c
index 055a877..187fe25 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -212,12 +212,13 @@ static int console_textview_line_color(struct TextViewContext *tvc, unsigned cha
 		        (xy[1] + pen[1] + tvc->lheight)
 				);
 
+#ifdef WITH_INPUT_IME
 		/* cursor following */
 		if (tvc->ime && tvc->ime->composite_len) {
-			int *tmp = tvc->ime->tmp;
-			tmp[0] = (xy[0] + pen[0]) + 1;
-			tmp[1] = (xy[1] + pen[1]) - 1;
+			tvc->ime->cursor_xy[0] = (xy[0] + pen[0]) + 1;
+			tvc->ime->cursor_xy[1] = (xy[1] + pen[1]) - 1;
 		}
+#endif
 
 	}
 
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index c90e666..1396829 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -235,8 +235,9 @@ static void console_main_area_draw(const bContext *C, ARegion *ar)
 #ifdef WITH_INPUT_IME
 	wmWindow *win = CTX_wm_window(C);
 	wmImeData *ime = win->ime_data;
-	int ime_active = ime && ime->composite_len &&
-					 BLI_rcti_isect_pt_v(&ar->winrct, &win->eventstate->x);
+	bool is_ime_active = ime &&
+	                     ime->composite_len &&
+	                     BLI_rcti_isect_pt_v(&ar->winrct, &win->eventstate->x);
 #endif
 
 	if (BLI_listbase_is_empty(&sc->scrollback))
@@ -255,28 +256,29 @@ static void console_main_area_draw(const bContext *C, ARegion *ar)
 
 #ifdef WITH_INPUT_IME
 	/* get cursor position from console_textview_main and repositon ime window */
-	if (ime_active) {
+	if (is_ime_active) {
 		ConsoleLine *line = (ConsoleLine *)sc->history.last;
-		int *xy = MEM_callocN(sizeof(int[3]), "console cursor pos");
+
+		ime->cursor_pos_text = line->cursor + strlen(sc->prompt);
 		sc->ime = ime;
-		ime->tmp = xy;
-		/* [0~1] last cursor coord in the window, [2] cursor pos in text */
-		xy[2] = line->cursor + strlen(sc->prompt);
 	}
-	else
+	else {
 		sc->ime = NULL;
-#endif /* WITH_INPUT_IME */
+	}
 
 	console_textview_main(sc, ar);
 
-#ifdef WITH_INPUT_IME
-	if (ime_active) {
-		int *xy = ime->tmp;
-		ime->tmp = NULL;
-		ui_region_to_window(ar, xy, xy+1);
-		wm_window_IME_begin(win, xy[0] + 5, xy[1], 0, 0, false);
-		MEM_freeN(xy);
+	if (is_ime_active) {
+		int x = ime->cursor_xy[0];
+		int y = ime->cursor_xy[1];
+
+		ui_region_to_window(ar, &x, &y);
+		wm_window_IME_begin(win, x + 5, y, 0, 0, false);
+
+		ime->cursor_xy[0] = ime->cursor_xy[1] = 0;
 	}
+#else
+	console_textview_main(sc, ar);
 #endif /* WITH_INPUT_IME */
 	
 	/* reset view matrix */
diff --git a/source/blender/editors/space_info/CMakeLists.txt b/source/blender/editors/space_info/CMakeLists.txt
index 46ea251..34c1475 100644
--- a/source/blender/editors/space_info/CMakeLists.txt
+++ b/source/blender/editors/space_info/CMakeLists.txt
@@ -54,6 +54,12 @@ if(WITH_INTERNATIONAL)
 	add_definitions(-DWITH_INTERNATIONAL)
 endif()
 
+if(WIN32)
+	if(WITH_INPUT_IME)
+		add_definitions(-DWITH_INPUT_IME)
+	endif()
+endif()
+
 add_definitions(${GL_DEFINITIONS})
 
 blender_add_lib(bf_editor_space_info "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c
index 7589464..c1c3864 100644
--- a/source/blender/editors/space_info/textview.c
+++ b/source/blender/editors/space_info/textview.c
@@ -37,6 +37,7 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_string.h"
 #include "BLI_string_utf8.h"
 
 #include "BIF_gl.h"
@@ -143,28 +144,23 @@ static int console_draw_string(ConsoleDrawContext *cdc, const char *str, int str
 	int tot_lines;            /* total number of lines for wrapping */
 	int *offsets;             /* offsets of line beginnings for wrapping */
 	int y_next;
-	const int mono = blf_mono_font;
-	char *buf = NULL;
+	const int mono = blf_mono_font;;
 	int cursor;
 
-	if (cdc->ime && !cdc->ime->tmp)
-		cdc->ime = NULL;
-
-	if (cdc->ime && cdc->ime->composite_len) {
-		size_t len, slen;
-		cursor = ((int *)cdc-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list