changeset 20707:59932ff02821 draft

-Change: [Win32] Position the IME candidate window at the caret position.
author Michael Lutz <michi@icosahedron.de>
date Mon, 15 Apr 2013 13:59:24 +0200
parents 79930f9362c3
children bd8f5e4c1617
files src/video/win32_v.cpp
diffstat 1 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -517,6 +517,42 @@
 	ImmReleaseContext(hwnd, hIMC);
 }
 
+/** Set the position of the candidate window. */
+static void SetCandidatePos(HWND hwnd)
+{
+	DEBUG(driver, 0, "SetCandidatePos");
+
+	HIMC hIMC = ImmGetContext(hwnd);
+	if (hIMC != NULL) {
+		CANDIDATEFORM cf;
+		cf.dwIndex = 0;
+		cf.dwStyle = CFS_EXCLUDE;
+
+		if (EditBoxInGlobalFocus()) {
+			Point pt = _focused_window->GetCaretPosition();
+			cf.ptCurrentPos.x = _focused_window->left + pt.x;
+			cf.ptCurrentPos.y = _focused_window->top  + pt.y;
+			if (_focused_window->window_class == WC_CONSOLE) {
+				cf.rcArea.left   = _focused_window->left;
+				cf.rcArea.top    = _focused_window->top;
+				cf.rcArea.right  = _focused_window->left + _focused_window->width;
+				cf.rcArea.bottom = _focused_window->top  + _focused_window->height;
+			} else {
+				cf.rcArea.left   = _focused_window->left + _focused_window->nested_focus->pos_x;
+				cf.rcArea.top    = _focused_window->top  + _focused_window->nested_focus->pos_y;
+				cf.rcArea.right  = cf.rcArea.left + _focused_window->nested_focus->current_x;
+				cf.rcArea.bottom = cf.rcArea.top  + _focused_window->nested_focus->current_y;
+			}
+		} else {
+			cf.ptCurrentPos.x = 0;
+			cf.ptCurrentPos.y = 0;
+			SetRectEmpty(&cf.rcArea);
+		}
+		ImmSetCandidateWindow(hIMC, &cf);
+	}
+	ImmReleaseContext(hwnd, hIMC);
+}
+
 /** Handle WM_IME_COMPOSITION messages. */
 static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
@@ -554,6 +590,7 @@
 #else
 
 static void SetCompositionPos(HWND hwnd) {}
+static void SetCandidatePos(HWND hwnd) {}
 static void CancelIMEComposition(HWND hwnd) {}
 
 #endif /* !defined(WINCE) || _WIN32_WCE >= 0x400 */
@@ -701,6 +738,10 @@
 		case WM_IME_COMPOSITION:
 			return HandleIMEComposition(hwnd, wParam, lParam);
 
+		case WM_IME_NOTIFY:
+			if (wParam == IMN_OPENCANDIDATE) SetCandidatePos(hwnd);
+			break;
+
 #if !defined(UNICODE)
 		case WM_IME_CHAR:
 			if (GB(wParam, 8, 8) != 0) {
@@ -1246,4 +1287,5 @@
 {
 	CancelIMEComposition(_wnd.main_wnd);
 	SetCompositionPos(_wnd.main_wnd);
+	SetCandidatePos(_wnd.main_wnd);
 }