Mercurial > sdl-ios-xcode
comparison 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 |
comparison
equal
deleted
inserted
replaced
4744:34c3e6d69575 | 4745:0aaa54fbd2bc |
---|---|
4 IMM::IMM() : my_COM_Initialized(false), | 4 IMM::IMM() : my_COM_Initialized(false), |
5 my_Thread_Manager(0), | 5 my_Thread_Manager(0), |
6 my_Window(0), | 6 my_Window(0), |
7 my_Context(0), | 7 my_Context(0), |
8 my_HKL(0), | 8 my_HKL(0), |
9 my_Vertical_Candidates(false) | 9 my_Vertical_Candidates(false), |
10 my_Enabled(false) | |
10 { | 11 { |
11 | 12 |
12 } | 13 } |
13 | 14 |
14 IMM::~IMM() | 15 IMM::~IMM() |
26 { | 27 { |
27 my_COM_Initialized = true; | 28 my_COM_Initialized = true; |
28 if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<LPVOID *>(&my_Thread_Manager)))) | 29 if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<LPVOID *>(&my_Thread_Manager)))) |
29 { | 30 { |
30 ITfDocumentMgr *Document_Manager = 0; | 31 ITfDocumentMgr *Document_Manager = 0; |
31 if (FAILED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager))) | 32 if (SUCCEEDED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager))) |
33 { | |
34 if (Document_Manager) | |
35 Document_Manager->Release(); | |
36 } | |
37 else | |
32 printf("Warning: ITfThreadMgr->AssociateFocus failed\n"); | 38 printf("Warning: ITfThreadMgr->AssociateFocus failed\n"); |
33 | |
34 if (Document_Manager) | |
35 Document_Manager->Release(); | |
36 } | 39 } |
37 else | 40 else |
38 printf("Warning: Failed to create ITfThreadMgr instance\n"); | 41 printf("Warning: Failed to create ITfThreadMgr instance\n"); |
39 } | 42 } |
40 else | 43 else |
41 printf("Warning: Failed to initialize COM\n"); | 44 printf("Warning: Failed to initialize COM\n"); |
42 | 45 |
43 ImmDisableTextFrameService(-1); | 46 ImmDisableTextFrameService((DWORD)-1); |
44 | 47 |
45 my_Context = ImmGetContext(my_Window); | 48 my_Context = ImmGetContext(my_Window); |
46 if (!ImmReleaseContext(my_Window, my_Context)) | 49 ImmReleaseContext(my_Window, my_Context); |
47 throw std::runtime_error("Error releasing context"); | |
48 | |
49 if (!my_Context) | 50 if (!my_Context) |
50 throw std::runtime_error("No context"); | 51 throw std::runtime_error("No context (No IME installed?)"); |
51 | 52 |
52 Update_Input_Locale(); | 53 Update_Input_Locale(); |
54 Cancel_Composition(); | |
55 Disable(); | |
53 } | 56 } |
54 | 57 |
55 void IMM::Finalize() | 58 void IMM::Finalize() |
56 { | 59 { |
57 if (my_Thread_Manager) | 60 if (my_Thread_Manager) |
100 { | 103 { |
101 Ate = false; | 104 Ate = false; |
102 switch (Message) | 105 switch (Message) |
103 { | 106 { |
104 case WM_INPUTLANGCHANGE: | 107 case WM_INPUTLANGCHANGE: |
105 Update_Input_Locale(); | 108 Input_Language_Changed(); |
106 break; | 109 break; |
107 case WM_IME_SETCONTEXT: | 110 case WM_IME_SETCONTEXT: |
108 lParam = 0; | 111 lParam = 0; |
109 return DefWindowProcW(my_Window, Message, wParam, lParam); | |
110 break; | 112 break; |
111 case WM_IME_STARTCOMPOSITION: | 113 case WM_IME_STARTCOMPOSITION: |
112 Ate = true; | 114 Ate = true; |
113 break; | 115 break; |
114 case WM_IME_COMPOSITION: | 116 case WM_IME_COMPOSITION: |
156 break; | 158 break; |
157 case IMN_OPENCANDIDATE: | 159 case IMN_OPENCANDIDATE: |
158 case IMN_CHANGECANDIDATE: | 160 case IMN_CHANGECANDIDATE: |
159 Ate = true; | 161 Ate = true; |
160 break; | 162 break; |
163 case IMN_CLOSECANDIDATE: | |
164 Ate = true; | |
165 break; | |
166 default: | |
167 Ate = true; | |
168 break; | |
161 } | 169 } |
162 break; | 170 break; |
163 } | 171 } |
164 return 0; | 172 return 0; |
165 } | 173 } |
174 | |
175 void IMM::Enable() | |
176 { | |
177 ImmAssociateContext(my_Window, my_Context); | |
178 Update_Input_Locale(); | |
179 my_Enabled = true; | |
180 printf("* Enabled\n"); | |
181 } | |
182 | |
183 void IMM::Disable() | |
184 { | |
185 ImmAssociateContext(my_Window, 0); | |
186 my_Enabled = false; | |
187 printf("* Disabled\n"); | |
188 } | |
189 | |
190 bool IMM::Is_Enabled() | |
191 { | |
192 return my_Enabled; | |
193 } | |
194 | |
195 void IMM::Toggle() | |
196 { | |
197 if (my_Enabled) | |
198 Disable(); | |
199 else | |
200 Enable(); | |
201 } | |
202 | |
203 void IMM::Focus_Gained() | |
204 { | |
205 if (my_Enabled) | |
206 Enable(); | |
207 } | |
208 | |
209 void IMM::Focus_Lost() | |
210 { | |
211 bool Enabled = my_Enabled; | |
212 Cancel_Composition(); | |
213 Disable(); | |
214 my_Enabled = Enabled; | |
215 } | |
216 | |
217 void IMM::Cancel_Composition() | |
218 { | |
219 HIMC hIMC = ImmGetContext(my_Window); | |
220 if (!hIMC) | |
221 return; | |
222 | |
223 ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); | |
224 ImmNotifyIME(hIMC, NI_CLOSECANDIDATE, 0, 0); | |
225 ImmReleaseContext(my_Window, hIMC); | |
226 } | |
227 | |
228 void IMM::Input_Language_Changed() | |
229 { | |
230 Update_Input_Locale(); | |
231 HWND hwndImeDef = ImmGetDefaultIMEWnd(my_Window); | |
232 if (hwndImeDef) | |
233 { | |
234 SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0); | |
235 SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0); | |
236 } | |
237 } |