diff EXCLUDE/GLIMM/src/IMM.cpp @ 4745:0aaa54fbd2bc

Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
author dewyatt
date Tue, 06 Jul 2010 02:06:17 -0400
parents bb189d44af16
children
line wrap: on
line diff
--- a/EXCLUDE/GLIMM/src/IMM.cpp	Tue Jul 06 02:00:15 2010 -0400
+++ b/EXCLUDE/GLIMM/src/IMM.cpp	Tue Jul 06 02:06:17 2010 -0400
@@ -6,7 +6,8 @@
 			 my_Window(0),
 			 my_Context(0),
 			 my_HKL(0),
-			 my_Vertical_Candidates(false)
+			 my_Vertical_Candidates(false),
+			 my_Enabled(false)
 {
 
 }
@@ -28,11 +29,13 @@
 		if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<LPVOID *>(&my_Thread_Manager))))
 		{
 			ITfDocumentMgr *Document_Manager = 0;
-			if (FAILED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager)))
+			if (SUCCEEDED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager)))
+			{
+				if (Document_Manager)
+					Document_Manager->Release();
+			}
+			else
 				printf("Warning: ITfThreadMgr->AssociateFocus failed\n");
-
-			if (Document_Manager)
-				Document_Manager->Release();
 		}
 		else
 			printf("Warning: Failed to create ITfThreadMgr instance\n");
@@ -40,16 +43,16 @@
 	else
 		printf("Warning: Failed to initialize COM\n");
 
-	ImmDisableTextFrameService(-1);
+	ImmDisableTextFrameService((DWORD)-1);
 
 	my_Context = ImmGetContext(my_Window);
-	if (!ImmReleaseContext(my_Window, my_Context))
-		throw std::runtime_error("Error releasing context");
-
+	ImmReleaseContext(my_Window, my_Context);
 	if (!my_Context)
-		throw std::runtime_error("No context");
+		throw std::runtime_error("No context (No IME installed?)");
 
 	Update_Input_Locale();
+	Cancel_Composition();
+	Disable();
 }
 
 void IMM::Finalize()
@@ -102,11 +105,10 @@
 	switch (Message)
 	{
 	case WM_INPUTLANGCHANGE:
-		Update_Input_Locale();
+		Input_Language_Changed();
 		break;
 	case WM_IME_SETCONTEXT:
 		lParam = 0;
-		return DefWindowProcW(my_Window, Message, wParam, lParam);
 		break;
 	case WM_IME_STARTCOMPOSITION:
 		Ate = true;
@@ -158,8 +160,78 @@
 		case IMN_CHANGECANDIDATE:
 			Ate = true;
 			break;
+		case IMN_CLOSECANDIDATE:
+			Ate = true;
+			break;
+		default:
+			Ate = true;
+			break;
 		}
 		break;
 	}
 	return 0;
 }
+
+void IMM::Enable()
+{
+	ImmAssociateContext(my_Window, my_Context);
+	Update_Input_Locale();
+	my_Enabled = true;
+	printf("* Enabled\n");
+}
+
+void IMM::Disable()
+{
+	ImmAssociateContext(my_Window, 0);
+	my_Enabled = false;
+	printf("* Disabled\n");
+}
+
+bool IMM::Is_Enabled()
+{
+	return my_Enabled;
+}
+
+void IMM::Toggle()
+{
+	if (my_Enabled)
+		Disable();
+	else
+		Enable();
+}
+
+void IMM::Focus_Gained()
+{
+	if (my_Enabled)
+		Enable();
+}
+
+void IMM::Focus_Lost()
+{
+	bool Enabled = my_Enabled;
+	Cancel_Composition();
+	Disable();
+	my_Enabled = Enabled;
+}
+
+void IMM::Cancel_Composition()
+{
+	HIMC hIMC = ImmGetContext(my_Window);
+	if (!hIMC)
+		return;
+
+	ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
+	ImmNotifyIME(hIMC, NI_CLOSECANDIDATE, 0, 0);
+	ImmReleaseContext(my_Window, hIMC);
+}
+
+void IMM::Input_Language_Changed()
+{
+	Update_Input_Locale();
+	HWND hwndImeDef = ImmGetDefaultIMEWnd(my_Window);
+	if (hwndImeDef)
+	{
+		SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0);
+		SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0);
+	}
+}