annotate EXCLUDE/GLIMM/src/IMM.cpp @ 4741:bb189d44af16

Added GLIMM (using IMM instead of TSF) Uses small bit of TSF to fully disable cicero (TSF for non-TSF enabled apps)
author dewyatt
date Wed, 30 Jun 2010 17:29:20 -0400
parents
children 0aaa54fbd2bc
rev   line source
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
1 #include "IMM.hpp"
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
2 #include <stdexcept>
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
3
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
4 IMM::IMM() : my_COM_Initialized(false),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
5 my_Thread_Manager(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
6 my_Window(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
7 my_Context(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
8 my_HKL(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
9 my_Vertical_Candidates(false)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
10 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
11
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
12 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
13
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
14 IMM::~IMM()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
15 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
16 Finalize();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
17 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
18
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
19 void IMM::Initialize(HWND Window)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
20 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
21 Finalize();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
22
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
23 my_Window = Window;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
24
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
25 if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
26 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
27 my_COM_Initialized = true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
28 if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<LPVOID *>(&my_Thread_Manager))))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
29 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
30 ITfDocumentMgr *Document_Manager = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
31 if (FAILED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager)))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
32 printf("Warning: ITfThreadMgr->AssociateFocus failed\n");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
33
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
34 if (Document_Manager)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
35 Document_Manager->Release();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
36 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
37 else
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
38 printf("Warning: Failed to create ITfThreadMgr instance\n");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
39 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
40 else
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
41 printf("Warning: Failed to initialize COM\n");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
42
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
43 ImmDisableTextFrameService(-1);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
44
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
45 my_Context = ImmGetContext(my_Window);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
46 if (!ImmReleaseContext(my_Window, my_Context))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
47 throw std::runtime_error("Error releasing context");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
48
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
49 if (!my_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
50 throw std::runtime_error("No context");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
51
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
52 Update_Input_Locale();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
53 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
54
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
55 void IMM::Finalize()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
56 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
57 if (my_Thread_Manager)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
58 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
59 my_Thread_Manager->Release();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
60 my_Thread_Manager = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
61 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
62 if (my_COM_Initialized)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
63 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
64 CoUninitialize();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
65 my_COM_Initialized = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
66 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
67 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
68
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
69 #define GET_LANG(hkl) LOWORD((hkl))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
70 #define GET_PRIMLANG(hkl) ((WORD)PRIMARYLANGID(GET_LANG((hkl))))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
71 #define GET_SUBLANG(hkl) SUBLANGID(GET_LANG((hkl)))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
72
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
73 void IMM::Update_Input_Locale()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
74 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
75 static HKL Previous_HKL = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
76 my_HKL = GetKeyboardLayout(0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
77 if (Previous_HKL == my_HKL)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
78 return;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
79
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
80 Previous_HKL = my_HKL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
81 my_Vertical_Candidates = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
82 switch (GET_PRIMLANG(my_HKL))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
83 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
84 case LANG_CHINESE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
85 my_Vertical_Candidates = true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
86 switch (GET_SUBLANG(my_HKL))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
87 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
88 case SUBLANG_CHINESE_SIMPLIFIED:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
89 my_Vertical_Candidates = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
90 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
91 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
92 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
93 case LANG_JAPANESE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
94 my_Vertical_Candidates = true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
95 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
96 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
97 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
98
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
99 LRESULT IMM::Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam, bool &Ate)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
100 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
101 Ate = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
102 switch (Message)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
103 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
104 case WM_INPUTLANGCHANGE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
105 Update_Input_Locale();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
106 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
107 case WM_IME_SETCONTEXT:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
108 lParam = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
109 return DefWindowProcW(my_Window, Message, wParam, lParam);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
110 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
111 case WM_IME_STARTCOMPOSITION:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
112 Ate = true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
113 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
114 case WM_IME_COMPOSITION:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
115 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
116 Ate = true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
117 HIMC Context = ImmGetContext(Window);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
118 if (!Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
119 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
120
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
121 if (lParam & GCS_RESULTSTR)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
122 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
123 LONG Length = ImmGetCompositionStringW(Context, GCS_RESULTSTR, 0, 0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
124 std::wstring Composition(Length / sizeof(wchar_t), 0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
125 Length = ImmGetCompositionStringW(Context, GCS_RESULTSTR, &Composition[0], Composition.size() * sizeof(Composition[0]));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
126 printf("GCS_RESULTSTR: ");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
127 for (LONG i = 0; i < Length / sizeof(wchar_t); ++i)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
128 printf("U+%04X ", Composition[i]);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
129
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
130 printf("\n");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
131 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
132 if (lParam & GCS_COMPSTR)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
133 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
134 LONG Length = ImmGetCompositionStringW(Context, GCS_COMPSTR, 0, 0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
135 std::wstring Composition(Length / sizeof(wchar_t), 0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
136 Length = ImmGetCompositionStringW(Context, GCS_COMPSTR, &Composition[0], Composition.size() * sizeof(Composition[0]));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
137 printf("GCS_COMPSTR: ");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
138 for (LONG i = 0; i < Length / sizeof(wchar_t); ++i)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
139 printf("U+%04X ", Composition[i]);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
140
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
141 printf("\n");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
142 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
143 ImmReleaseContext(Window, Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
144 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
145 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
146 case WM_IME_ENDCOMPOSITION:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
147 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
148 case WM_IME_NOTIFY:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
149 switch (wParam)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
150 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
151 case IMN_SETCONVERSIONMODE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
152
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
153 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
154 case IMN_SETOPENSTATUS:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
155 Update_Input_Locale();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
156 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
157 case IMN_OPENCANDIDATE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
158 case IMN_CHANGECANDIDATE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
159 Ate = true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
160 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
161 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
162 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
163 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
164 return 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
165 }