Mercurial > sdl-ios-xcode
annotate EXCLUDE/GLIMM/src/IMM.cpp @ 4748:d1ce08e2697f
Added missing line to make things compile.
author | dewyatt |
---|---|
date | Tue, 06 Jul 2010 03:27:22 -0400 |
parents | 0aaa54fbd2bc |
children |
rev | line source |
---|---|
4741 | 1 #include "IMM.hpp" |
2 #include <stdexcept> | |
3 | |
4 IMM::IMM() : my_COM_Initialized(false), | |
5 my_Thread_Manager(0), | |
6 my_Window(0), | |
7 my_Context(0), | |
8 my_HKL(0), | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
9 my_Vertical_Candidates(false), |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
10 my_Enabled(false) |
4741 | 11 { |
12 | |
13 } | |
14 | |
15 IMM::~IMM() | |
16 { | |
17 Finalize(); | |
18 } | |
19 | |
20 void IMM::Initialize(HWND Window) | |
21 { | |
22 Finalize(); | |
23 | |
24 my_Window = Window; | |
25 | |
26 if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) | |
27 { | |
28 my_COM_Initialized = true; | |
29 if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<LPVOID *>(&my_Thread_Manager)))) | |
30 { | |
31 ITfDocumentMgr *Document_Manager = 0; | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
32 if (SUCCEEDED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager))) |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
33 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
34 if (Document_Manager) |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
35 Document_Manager->Release(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
36 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
37 else |
4741 | 38 printf("Warning: ITfThreadMgr->AssociateFocus failed\n"); |
39 } | |
40 else | |
41 printf("Warning: Failed to create ITfThreadMgr instance\n"); | |
42 } | |
43 else | |
44 printf("Warning: Failed to initialize COM\n"); | |
45 | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
46 ImmDisableTextFrameService((DWORD)-1); |
4741 | 47 |
48 my_Context = ImmGetContext(my_Window); | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
49 ImmReleaseContext(my_Window, my_Context); |
4741 | 50 if (!my_Context) |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
51 throw std::runtime_error("No context (No IME installed?)"); |
4741 | 52 |
53 Update_Input_Locale(); | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
54 Cancel_Composition(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
55 Disable(); |
4741 | 56 } |
57 | |
58 void IMM::Finalize() | |
59 { | |
60 if (my_Thread_Manager) | |
61 { | |
62 my_Thread_Manager->Release(); | |
63 my_Thread_Manager = 0; | |
64 } | |
65 if (my_COM_Initialized) | |
66 { | |
67 CoUninitialize(); | |
68 my_COM_Initialized = false; | |
69 } | |
70 } | |
71 | |
72 #define GET_LANG(hkl) LOWORD((hkl)) | |
73 #define GET_PRIMLANG(hkl) ((WORD)PRIMARYLANGID(GET_LANG((hkl)))) | |
74 #define GET_SUBLANG(hkl) SUBLANGID(GET_LANG((hkl))) | |
75 | |
76 void IMM::Update_Input_Locale() | |
77 { | |
78 static HKL Previous_HKL = 0; | |
79 my_HKL = GetKeyboardLayout(0); | |
80 if (Previous_HKL == my_HKL) | |
81 return; | |
82 | |
83 Previous_HKL = my_HKL; | |
84 my_Vertical_Candidates = false; | |
85 switch (GET_PRIMLANG(my_HKL)) | |
86 { | |
87 case LANG_CHINESE: | |
88 my_Vertical_Candidates = true; | |
89 switch (GET_SUBLANG(my_HKL)) | |
90 { | |
91 case SUBLANG_CHINESE_SIMPLIFIED: | |
92 my_Vertical_Candidates = false; | |
93 break; | |
94 } | |
95 break; | |
96 case LANG_JAPANESE: | |
97 my_Vertical_Candidates = true; | |
98 break; | |
99 } | |
100 } | |
101 | |
102 LRESULT IMM::Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam, bool &Ate) | |
103 { | |
104 Ate = false; | |
105 switch (Message) | |
106 { | |
107 case WM_INPUTLANGCHANGE: | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
108 Input_Language_Changed(); |
4741 | 109 break; |
110 case WM_IME_SETCONTEXT: | |
111 lParam = 0; | |
112 break; | |
113 case WM_IME_STARTCOMPOSITION: | |
114 Ate = true; | |
115 break; | |
116 case WM_IME_COMPOSITION: | |
117 { | |
118 Ate = true; | |
119 HIMC Context = ImmGetContext(Window); | |
120 if (!Context) | |
121 break; | |
122 | |
123 if (lParam & GCS_RESULTSTR) | |
124 { | |
125 LONG Length = ImmGetCompositionStringW(Context, GCS_RESULTSTR, 0, 0); | |
126 std::wstring Composition(Length / sizeof(wchar_t), 0); | |
127 Length = ImmGetCompositionStringW(Context, GCS_RESULTSTR, &Composition[0], Composition.size() * sizeof(Composition[0])); | |
128 printf("GCS_RESULTSTR: "); | |
129 for (LONG i = 0; i < Length / sizeof(wchar_t); ++i) | |
130 printf("U+%04X ", Composition[i]); | |
131 | |
132 printf("\n"); | |
133 } | |
134 if (lParam & GCS_COMPSTR) | |
135 { | |
136 LONG Length = ImmGetCompositionStringW(Context, GCS_COMPSTR, 0, 0); | |
137 std::wstring Composition(Length / sizeof(wchar_t), 0); | |
138 Length = ImmGetCompositionStringW(Context, GCS_COMPSTR, &Composition[0], Composition.size() * sizeof(Composition[0])); | |
139 printf("GCS_COMPSTR: "); | |
140 for (LONG i = 0; i < Length / sizeof(wchar_t); ++i) | |
141 printf("U+%04X ", Composition[i]); | |
142 | |
143 printf("\n"); | |
144 } | |
145 ImmReleaseContext(Window, Context); | |
146 } | |
147 break; | |
148 case WM_IME_ENDCOMPOSITION: | |
149 break; | |
150 case WM_IME_NOTIFY: | |
151 switch (wParam) | |
152 { | |
153 case IMN_SETCONVERSIONMODE: | |
154 | |
155 break; | |
156 case IMN_SETOPENSTATUS: | |
157 Update_Input_Locale(); | |
158 break; | |
159 case IMN_OPENCANDIDATE: | |
160 case IMN_CHANGECANDIDATE: | |
161 Ate = true; | |
162 break; | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
163 case IMN_CLOSECANDIDATE: |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
164 Ate = true; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
165 break; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
166 default: |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
167 Ate = true; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
168 break; |
4741 | 169 } |
170 break; | |
171 } | |
172 return 0; | |
173 } | |
4745
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
174 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
175 void IMM::Enable() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
176 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
177 ImmAssociateContext(my_Window, my_Context); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
178 Update_Input_Locale(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
179 my_Enabled = true; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
180 printf("* Enabled\n"); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
181 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
182 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
183 void IMM::Disable() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
184 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
185 ImmAssociateContext(my_Window, 0); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
186 my_Enabled = false; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
187 printf("* Disabled\n"); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
188 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
189 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
190 bool IMM::Is_Enabled() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
191 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
192 return my_Enabled; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
193 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
194 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
195 void IMM::Toggle() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
196 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
197 if (my_Enabled) |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
198 Disable(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
199 else |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
200 Enable(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
201 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
202 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
203 void IMM::Focus_Gained() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
204 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
205 if (my_Enabled) |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
206 Enable(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
207 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
208 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
209 void IMM::Focus_Lost() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
210 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
211 bool Enabled = my_Enabled; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
212 Cancel_Composition(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
213 Disable(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
214 my_Enabled = Enabled; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
215 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
216 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
217 void IMM::Cancel_Composition() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
218 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
219 HIMC hIMC = ImmGetContext(my_Window); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
220 if (!hIMC) |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
221 return; |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
222 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
223 ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
224 ImmNotifyIME(hIMC, NI_CLOSECANDIDATE, 0, 0); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
225 ImmReleaseContext(my_Window, hIMC); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
226 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
227 |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
228 void IMM::Input_Language_Changed() |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
229 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
230 Update_Input_Locale(); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
231 HWND hwndImeDef = ImmGetDefaultIMEWnd(my_Window); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
232 if (hwndImeDef) |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
233 { |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
234 SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
235 SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0); |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
236 } |
0aaa54fbd2bc
Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents:
4741
diff
changeset
|
237 } |