f744d63752a1e5ef50dec3575d4dd750d336bdfc
[reactos.git] / dll / win32 / msctf / inputprocessor.c
1 /*
2 * ITfInputProcessorProfiles implementation
3 *
4 * Copyright 2009 Aric Stewart, CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "msctf_internal.h"
22
23 static const WCHAR szwLngp[] = {'L','a','n','g','u','a','g','e','P','r','o','f','i','l','e',0};
24 static const WCHAR szwEnable[] = {'E','n','a','b','l','e',0};
25 static const WCHAR szwTipfmt[] = {'%','s','\\','%','s',0};
26 static const WCHAR szwFullLangfmt[] = {'%','s','\\','%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
27
28 static const WCHAR szwAssemblies[] = {'A','s','s','e','m','b','l','i','e','s',0};
29 static const WCHAR szwDefault[] = {'D','e','f','a','u','l','t',0};
30 static const WCHAR szwProfile[] = {'P','r','o','f','i','l','e',0};
31 static const WCHAR szwDefaultFmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
32
33 typedef struct tagInputProcessorProfiles {
34 ITfInputProcessorProfiles ITfInputProcessorProfiles_iface;
35 ITfSource ITfSource_iface;
36 ITfInputProcessorProfileMgr ITfInputProcessorProfileMgr_iface;
37 /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
38 /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
39 LONG refCount;
40
41 LANGID currentLanguage;
42
43 struct list LanguageProfileNotifySink;
44 } InputProcessorProfiles;
45
46 typedef struct tagProfilesEnumGuid {
47 IEnumGUID IEnumGUID_iface;
48 LONG refCount;
49
50 HKEY key;
51 DWORD next_index;
52 } ProfilesEnumGuid;
53
54 typedef struct tagEnumTfLanguageProfiles {
55 IEnumTfLanguageProfiles IEnumTfLanguageProfiles_iface;
56 LONG refCount;
57
58 HKEY tipkey;
59 DWORD tip_index;
60 WCHAR szwCurrentClsid[39];
61
62 HKEY langkey;
63 DWORD lang_index;
64
65 LANGID langid;
66 ITfCategoryMgr *catmgr;
67 } EnumTfLanguageProfiles;
68
69 typedef struct {
70 IEnumTfInputProcessorProfiles IEnumTfInputProcessorProfiles_iface;
71 LONG ref;
72 } EnumTfInputProcessorProfiles;
73
74 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut);
75 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out);
76
77 static inline EnumTfInputProcessorProfiles *impl_from_IEnumTfInputProcessorProfiles(IEnumTfInputProcessorProfiles *iface)
78 {
79 return CONTAINING_RECORD(iface, EnumTfInputProcessorProfiles, IEnumTfInputProcessorProfiles_iface);
80 }
81
82 static HRESULT WINAPI EnumTfInputProcessorProfiles_QueryInterface(IEnumTfInputProcessorProfiles *iface,
83 REFIID riid, void **ppv)
84 {
85 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
86
87 if(IsEqualGUID(riid, &IID_IUnknown)) {
88 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
89 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
90 }else if(IsEqualGUID(riid, &IID_IEnumTfInputProcessorProfiles)) {
91 TRACE("(%p)->(IID_IEnumTfInputProcessorProfiles %p)\n", This, ppv);
92 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
93 }else {
94 *ppv = NULL;
95 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
96 return E_NOINTERFACE;
97 }
98
99 IUnknown_AddRef((IUnknown*)*ppv);
100 return S_OK;
101 }
102
103 static ULONG WINAPI EnumTfInputProcessorProfiles_AddRef(IEnumTfInputProcessorProfiles *iface)
104 {
105 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
106 LONG ref = InterlockedIncrement(&This->ref);
107
108 TRACE("(%p) ref=%d\n", This, ref);
109
110 return ref;
111 }
112
113 static ULONG WINAPI EnumTfInputProcessorProfiles_Release(IEnumTfInputProcessorProfiles *iface)
114 {
115 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
116 LONG ref = InterlockedDecrement(&This->ref);
117
118 TRACE("(%p) ref=%d\n", This, ref);
119
120 if(!ref)
121 HeapFree(GetProcessHeap(), 0, This);
122
123 return ref;
124 }
125
126 static HRESULT WINAPI EnumTfInputProcessorProfiles_Clone(IEnumTfInputProcessorProfiles *iface,
127 IEnumTfInputProcessorProfiles **ret)
128 {
129 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
130 FIXME("(%p)->(%p)\n", This, ret);
131 return E_NOTIMPL;
132 }
133
134 static HRESULT WINAPI EnumTfInputProcessorProfiles_Next(IEnumTfInputProcessorProfiles *iface, ULONG count,
135 TF_INPUTPROCESSORPROFILE *profile, ULONG *fetch)
136 {
137 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
138
139 FIXME("(%p)->(%u %p %p)\n", This, count, profile, fetch);
140
141 if(fetch)
142 *fetch = 0;
143 return S_FALSE;
144 }
145
146 static HRESULT WINAPI EnumTfInputProcessorProfiles_Reset(IEnumTfInputProcessorProfiles *iface)
147 {
148 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
149 FIXME("(%p)\n", This);
150 return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI EnumTfInputProcessorProfiles_Skip(IEnumTfInputProcessorProfiles *iface, ULONG count)
154 {
155 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
156 FIXME("(%p)->(%u)\n", This, count);
157 return E_NOTIMPL;
158 }
159
160 static const IEnumTfInputProcessorProfilesVtbl EnumTfInputProcessorProfilesVtbl = {
161 EnumTfInputProcessorProfiles_QueryInterface,
162 EnumTfInputProcessorProfiles_AddRef,
163 EnumTfInputProcessorProfiles_Release,
164 EnumTfInputProcessorProfiles_Clone,
165 EnumTfInputProcessorProfiles_Next,
166 EnumTfInputProcessorProfiles_Reset,
167 EnumTfInputProcessorProfiles_Skip
168 };
169
170 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfiles(ITfInputProcessorProfiles *iface)
171 {
172 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfiles_iface);
173 }
174
175 static inline InputProcessorProfiles *impl_from_ITfSource(ITfSource *iface)
176 {
177 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfSource_iface);
178 }
179
180 static inline ProfilesEnumGuid *impl_from_IEnumGUID(IEnumGUID *iface)
181 {
182 return CONTAINING_RECORD(iface, ProfilesEnumGuid, IEnumGUID_iface);
183 }
184
185 static inline EnumTfLanguageProfiles *impl_from_IEnumTfLanguageProfiles(IEnumTfLanguageProfiles *iface)
186 {
187 return CONTAINING_RECORD(iface, EnumTfLanguageProfiles, IEnumTfLanguageProfiles_iface);
188 }
189
190 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
191 {
192 TRACE("destroying %p\n", This);
193
194 free_sinks(&This->LanguageProfileNotifySink);
195 HeapFree(GetProcessHeap(),0,This);
196 }
197
198 static void add_userkey( REFCLSID rclsid, LANGID langid,
199 REFGUID guidProfile)
200 {
201 HKEY key;
202 WCHAR buf[39];
203 WCHAR buf2[39];
204 WCHAR fullkey[168];
205 DWORD disposition = 0;
206 ULONG res;
207
208 TRACE("\n");
209
210 StringFromGUID2(rclsid, buf, 39);
211 StringFromGUID2(guidProfile, buf2, 39);
212 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
213
214 res = RegCreateKeyExW(HKEY_CURRENT_USER,fullkey, 0, NULL, 0,
215 KEY_READ | KEY_WRITE, NULL, &key, &disposition);
216
217 if (!res && disposition == REG_CREATED_NEW_KEY)
218 {
219 DWORD zero = 0x0;
220 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
221 }
222
223 if (!res)
224 RegCloseKey(key);
225 }
226
227 static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, void **ppv)
228 {
229 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
230
231 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
232 {
233 *ppv = &This->ITfInputProcessorProfiles_iface;
234 }
235 else if (IsEqualIID(iid, &IID_ITfInputProcessorProfileMgr))
236 {
237 *ppv = &This->ITfInputProcessorProfileMgr_iface;
238 }
239 else if (IsEqualIID(iid, &IID_ITfSource))
240 {
241 *ppv = &This->ITfSource_iface;
242 }
243 else
244 {
245 *ppv = NULL;
246 WARN("unsupported interface: %s\n", debugstr_guid(iid));
247 return E_NOINTERFACE;
248 }
249
250 ITfInputProcessorProfiles_AddRef(iface);
251 return S_OK;
252 }
253
254 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
255 {
256 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
257 return InterlockedIncrement(&This->refCount);
258 }
259
260 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
261 {
262 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
263 ULONG ret;
264
265 ret = InterlockedDecrement(&This->refCount);
266 if (ret == 0)
267 InputProcessorProfiles_Destructor(This);
268 return ret;
269 }
270
271 /*****************************************************
272 * ITfInputProcessorProfiles functions
273 *****************************************************/
274 static HRESULT WINAPI InputProcessorProfiles_Register(
275 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
276 {
277 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
278 HKEY tipkey;
279 WCHAR buf[39];
280 WCHAR fullkey[68];
281
282 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
283
284 StringFromGUID2(rclsid, buf, 39);
285 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
286
287 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, NULL, 0,
288 KEY_READ | KEY_WRITE, NULL, &tipkey, NULL) != ERROR_SUCCESS)
289 return E_FAIL;
290
291 RegCloseKey(tipkey);
292
293 return S_OK;
294 }
295
296 static HRESULT WINAPI InputProcessorProfiles_Unregister(
297 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
298 {
299 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
300 WCHAR buf[39];
301 WCHAR fullkey[68];
302
303 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
304
305 StringFromGUID2(rclsid, buf, 39);
306 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
307
308 RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
309 RegDeleteTreeW(HKEY_CURRENT_USER, fullkey);
310
311 return S_OK;
312 }
313
314 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
315 ITfInputProcessorProfiles *iface, REFCLSID rclsid,
316 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
317 ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
318 ULONG uIconIndex)
319 {
320 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
321 HKEY tipkey,fmtkey;
322 WCHAR buf[39];
323 WCHAR fullkey[100];
324 ULONG res;
325 DWORD disposition = 0;
326
327 static const WCHAR fmt2[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
328 static const WCHAR desc[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
329 static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
330 static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
331
332 TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
333 debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
334 debugstr_wn(pchIconFile,cchFile),uIconIndex);
335
336 StringFromGUID2(rclsid, buf, 39);
337 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
338
339 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
340 &tipkey ) != ERROR_SUCCESS)
341 return E_FAIL;
342
343 StringFromGUID2(guidProfile, buf, 39);
344 sprintfW(fullkey,fmt2,szwLngp,langid,buf);
345
346 res = RegCreateKeyExW(tipkey,fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
347 NULL, &fmtkey, &disposition);
348
349 if (!res)
350 {
351 DWORD zero = 0x0;
352 RegSetValueExW(fmtkey, desc, 0, REG_SZ, (const BYTE*)pchDesc, cchDesc * sizeof(WCHAR));
353 RegSetValueExW(fmtkey, icnf, 0, REG_SZ, (const BYTE*)pchIconFile, cchFile * sizeof(WCHAR));
354 RegSetValueExW(fmtkey, icni, 0, REG_DWORD, (LPBYTE)&uIconIndex, sizeof(DWORD));
355 if (disposition == REG_CREATED_NEW_KEY)
356 RegSetValueExW(fmtkey, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
357 RegCloseKey(fmtkey);
358
359 add_userkey(rclsid, langid, guidProfile);
360 }
361 RegCloseKey(tipkey);
362
363 if (!res)
364 return S_OK;
365 else
366 return E_FAIL;
367 }
368
369 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
370 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
371 REFGUID guidProfile)
372 {
373 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
374 FIXME("STUB:(%p)\n",This);
375 return E_NOTIMPL;
376 }
377
378 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
379 ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
380 {
381 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
382 TRACE("(%p) %p\n",This,ppEnum);
383 return ProfilesEnumGuid_Constructor(ppEnum);
384 }
385
386 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
387 ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
388 CLSID *pclsid, GUID *pguidProfile)
389 {
390 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
391 WCHAR fullkey[168];
392 WCHAR buf[39];
393 HKEY hkey;
394 DWORD count;
395 ULONG res;
396
397 TRACE("%p) %x %s %p %p\n",This, langid, debugstr_guid(catid),pclsid,pguidProfile);
398
399 if (!catid || !pclsid || !pguidProfile)
400 return E_INVALIDARG;
401
402 StringFromGUID2(catid, buf, 39);
403 sprintfW(fullkey, szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
404
405 if (RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE,
406 &hkey ) != ERROR_SUCCESS)
407 return S_FALSE;
408
409 count = sizeof(buf);
410 res = RegQueryValueExW(hkey, szwDefault, 0, NULL, (LPBYTE)buf, &count);
411 if (res != ERROR_SUCCESS)
412 {
413 RegCloseKey(hkey);
414 return S_FALSE;
415 }
416 CLSIDFromString(buf,pclsid);
417
418 res = RegQueryValueExW(hkey, szwProfile, 0, NULL, (LPBYTE)buf, &count);
419 if (res == ERROR_SUCCESS)
420 CLSIDFromString(buf,pguidProfile);
421
422 RegCloseKey(hkey);
423
424 return S_OK;
425 }
426
427 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
428 ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
429 REFGUID guidProfiles)
430 {
431 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
432 WCHAR fullkey[168];
433 WCHAR buf[39];
434 HKEY hkey;
435 GUID catid;
436 HRESULT hr;
437 ITfCategoryMgr *catmgr;
438 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
439 &GUID_TFCAT_TIP_SPEECH,
440 &GUID_TFCAT_TIP_HANDWRITING };
441
442 TRACE("%p) %x %s %s\n",This, langid, debugstr_guid(rclsid),debugstr_guid(guidProfiles));
443
444 if (!rclsid || !guidProfiles)
445 return E_INVALIDARG;
446
447 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&catmgr);
448
449 if (FAILED(hr))
450 return hr;
451
452 if (ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
453 &catid, tipcats, 3) != S_OK)
454 hr = ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
455 &catid, NULL, 0);
456 ITfCategoryMgr_Release(catmgr);
457
458 if (FAILED(hr))
459 return E_FAIL;
460
461 StringFromGUID2(&catid, buf, 39);
462 sprintfW(fullkey, szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
463
464 if (RegCreateKeyExW(HKEY_CURRENT_USER, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
465 NULL, &hkey, NULL ) != ERROR_SUCCESS)
466 return E_FAIL;
467
468 StringFromGUID2(rclsid, buf, 39);
469 RegSetValueExW(hkey, szwDefault, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
470 StringFromGUID2(guidProfiles, buf, 39);
471 RegSetValueExW(hkey, szwProfile, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
472 RegCloseKey(hkey);
473
474 return S_OK;
475 }
476
477 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
478 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
479 REFGUID guidProfiles)
480 {
481 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
482 HRESULT hr;
483 BOOL enabled;
484 TF_LANGUAGEPROFILE LanguageProfile;
485
486 TRACE("(%p) %s %x %s\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfiles));
487
488 if (langid != This->currentLanguage) return E_INVALIDARG;
489
490 if (get_active_textservice(rclsid,NULL))
491 {
492 TRACE("Already Active\n");
493 return E_FAIL;
494 }
495
496 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(iface, rclsid,
497 langid, guidProfiles, &enabled);
498 if (FAILED(hr) || !enabled)
499 {
500 TRACE("Not Enabled\n");
501 return E_FAIL;
502 }
503
504 LanguageProfile.clsid = *rclsid;
505 LanguageProfile.langid = langid;
506 LanguageProfile.guidProfile = *guidProfiles;
507 LanguageProfile.fActive = TRUE;
508
509 return add_active_textservice(&LanguageProfile);
510 }
511
512 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
513 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
514 GUID *pguidProfile)
515 {
516 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
517 TF_LANGUAGEPROFILE profile;
518
519 TRACE("(%p) %s %p %p\n",This,debugstr_guid(rclsid),plangid,pguidProfile);
520
521 if (!rclsid || !plangid || !pguidProfile)
522 return E_INVALIDARG;
523
524 if (get_active_textservice(rclsid, &profile))
525 {
526 *plangid = profile.langid;
527 *pguidProfile = profile.guidProfile;
528 return S_OK;
529 }
530 else
531 {
532 *pguidProfile = GUID_NULL;
533 return S_FALSE;
534 }
535 }
536
537 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
538 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
539 REFGUID guidProfile, BSTR *pbstrProfile)
540 {
541 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
542 FIXME("STUB:(%p)\n",This);
543 return E_NOTIMPL;
544 }
545
546 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
547 ITfInputProcessorProfiles *iface, LANGID *plangid)
548 {
549 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
550 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
551
552 if (!plangid)
553 return E_INVALIDARG;
554
555 *plangid = This->currentLanguage;
556
557 return S_OK;
558 }
559
560 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
561 ITfInputProcessorProfiles *iface, LANGID langid)
562 {
563 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
564 ITfLanguageProfileNotifySink *sink;
565 struct list *cursor;
566 BOOL accept;
567
568 FIXME("STUB:(%p)\n",This);
569
570 SINK_FOR_EACH(cursor, &This->LanguageProfileNotifySink, ITfLanguageProfileNotifySink, sink)
571 {
572 accept = TRUE;
573 ITfLanguageProfileNotifySink_OnLanguageChange(sink, langid, &accept);
574 if (!accept)
575 return E_FAIL;
576 }
577
578 /* TODO: On successful language change call OnLanguageChanged sink */
579 return E_NOTIMPL;
580 }
581
582 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
583 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
584 {
585 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
586 FIXME("Semi-STUB:(%p)\n",This);
587 *ppLangId = CoTaskMemAlloc(sizeof(LANGID));
588 **ppLangId = This->currentLanguage;
589 *pulCount = 1;
590 return S_OK;
591 }
592
593 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
594 ITfInputProcessorProfiles *iface, LANGID langid,
595 IEnumTfLanguageProfiles **ppEnum)
596 {
597 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
598 EnumTfLanguageProfiles *profenum;
599 HRESULT hr;
600
601 TRACE("(%p) %x %p\n",This,langid,ppEnum);
602
603 if (!ppEnum)
604 return E_INVALIDARG;
605 hr = EnumTfLanguageProfiles_Constructor(langid, &profenum);
606 *ppEnum = &profenum->IEnumTfLanguageProfiles_iface;
607
608 return hr;
609 }
610
611 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
612 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
613 REFGUID guidProfile, BOOL fEnable)
614 {
615 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
616 HKEY key;
617 WCHAR buf[39];
618 WCHAR buf2[39];
619 WCHAR fullkey[168];
620 ULONG res;
621
622 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
623
624 StringFromGUID2(rclsid, buf, 39);
625 StringFromGUID2(guidProfile, buf2, 39);
626 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
627
628 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
629
630 if (!res)
631 {
632 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
633 RegCloseKey(key);
634 }
635 else
636 return E_FAIL;
637
638 return S_OK;
639 }
640
641 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
642 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
643 REFGUID guidProfile, BOOL *pfEnable)
644 {
645 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
646 HKEY key;
647 WCHAR buf[39];
648 WCHAR buf2[39];
649 WCHAR fullkey[168];
650 ULONG res;
651
652 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
653
654 if (!pfEnable)
655 return E_INVALIDARG;
656
657 StringFromGUID2(rclsid, buf, 39);
658 StringFromGUID2(guidProfile, buf2, 39);
659 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
660
661 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
662
663 if (!res)
664 {
665 DWORD count = sizeof(DWORD);
666 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
667 RegCloseKey(key);
668 }
669
670 if (res) /* Try Default */
671 {
672 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
673
674 if (!res)
675 {
676 DWORD count = sizeof(DWORD);
677 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
678 RegCloseKey(key);
679 }
680 }
681
682 if (!res)
683 return S_OK;
684 else
685 return E_FAIL;
686 }
687
688 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
689 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
690 REFGUID guidProfile, BOOL fEnable)
691 {
692 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
693 HKEY key;
694 WCHAR buf[39];
695 WCHAR buf2[39];
696 WCHAR fullkey[168];
697 ULONG res;
698
699 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
700
701 StringFromGUID2(rclsid, buf, 39);
702 StringFromGUID2(guidProfile, buf2, 39);
703 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
704
705 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
706
707 if (!res)
708 {
709 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
710 RegCloseKey(key);
711 }
712 else
713 return E_FAIL;
714
715 return S_OK;
716 }
717
718 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
719 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
720 REFGUID guidProfile, HKL hKL)
721 {
722 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
723 FIXME("STUB:(%p)\n",This);
724 return E_NOTIMPL;
725 }
726
727 static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl =
728 {
729 InputProcessorProfiles_QueryInterface,
730 InputProcessorProfiles_AddRef,
731 InputProcessorProfiles_Release,
732 InputProcessorProfiles_Register,
733 InputProcessorProfiles_Unregister,
734 InputProcessorProfiles_AddLanguageProfile,
735 InputProcessorProfiles_RemoveLanguageProfile,
736 InputProcessorProfiles_EnumInputProcessorInfo,
737 InputProcessorProfiles_GetDefaultLanguageProfile,
738 InputProcessorProfiles_SetDefaultLanguageProfile,
739 InputProcessorProfiles_ActivateLanguageProfile,
740 InputProcessorProfiles_GetActiveLanguageProfile,
741 InputProcessorProfiles_GetLanguageProfileDescription,
742 InputProcessorProfiles_GetCurrentLanguage,
743 InputProcessorProfiles_ChangeCurrentLanguage,
744 InputProcessorProfiles_GetLanguageList,
745 InputProcessorProfiles_EnumLanguageProfiles,
746 InputProcessorProfiles_EnableLanguageProfile,
747 InputProcessorProfiles_IsEnabledLanguageProfile,
748 InputProcessorProfiles_EnableLanguageProfileByDefault,
749 InputProcessorProfiles_SubstituteKeyboardLayout
750 };
751
752 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfileMgr(ITfInputProcessorProfileMgr *iface)
753 {
754 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfileMgr_iface);
755 }
756
757 static HRESULT WINAPI InputProcessorProfileMgr_QueryInterface(ITfInputProcessorProfileMgr *iface, REFIID riid, void **ppv)
758 {
759 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
760 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, riid, ppv);
761 }
762
763 static ULONG WINAPI InputProcessorProfileMgr_AddRef(ITfInputProcessorProfileMgr *iface)
764 {
765 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
766 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
767 }
768
769 static ULONG WINAPI InputProcessorProfileMgr_Release(ITfInputProcessorProfileMgr *iface)
770 {
771 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
772 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
773 }
774
775 static HRESULT WINAPI InputProcessorProfileMgr_ActivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
776 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
777 {
778 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
779 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
780 debugstr_guid(guidProfile), hkl, dwFlags);
781 return E_NOTIMPL;
782 }
783
784 static HRESULT WINAPI InputProcessorProfileMgr_DeactivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
785 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
786 {
787 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
788 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
789 debugstr_guid(guidProfile), hkl, dwFlags);
790 return E_NOTIMPL;
791 }
792
793 static HRESULT WINAPI InputProcessorProfileMgr_GetProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
794 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, TF_INPUTPROCESSORPROFILE *pProfile)
795 {
796 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
797 FIXME("(%p)->(%d %x %s %s %p %p)\n", This, dwProfileType, langid, debugstr_guid(clsid),
798 debugstr_guid(guidProfile), hkl, pProfile);
799 return E_NOTIMPL;
800 }
801
802 static HRESULT WINAPI InputProcessorProfileMgr_EnumProfiles(ITfInputProcessorProfileMgr *iface, LANGID langid,
803 IEnumTfInputProcessorProfiles **ppEnum)
804 {
805 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
806 EnumTfInputProcessorProfiles *enum_profiles;
807
808 TRACE("(%p)->(%x %p)\n", This, langid, ppEnum);
809
810 enum_profiles = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_profiles));
811 if(!enum_profiles)
812 return E_OUTOFMEMORY;
813
814 enum_profiles->IEnumTfInputProcessorProfiles_iface.lpVtbl = &EnumTfInputProcessorProfilesVtbl;
815 enum_profiles->ref = 1;
816
817 *ppEnum = &enum_profiles->IEnumTfInputProcessorProfiles_iface;
818 return S_OK;
819 }
820
821 static HRESULT WINAPI InputProcessorProfileMgr_ReleaseInputProcessor(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
822 DWORD dwFlags)
823 {
824 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
825 FIXME("(%p)->(%s %x)\n", This, debugstr_guid(rclsid), dwFlags);
826 return E_NOTIMPL;
827 }
828
829 static HRESULT WINAPI InputProcessorProfileMgr_RegisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
830 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR *pchIconFile,
831 ULONG cchFile, ULONG uIconIndex, HKL hklsubstitute, DWORD dwPreferredLayout, BOOL bEnabledByDefault,
832 DWORD dwFlags)
833 {
834 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
835 FIXME("(%p)->(%s %x %s %s %d %s %u %u %p %x %x %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile),
836 debugstr_w(pchDesc), cchDesc, debugstr_w(pchIconFile), cchFile, uIconIndex, hklsubstitute, dwPreferredLayout,
837 bEnabledByDefault, dwFlags);
838 return E_NOTIMPL;
839 }
840
841 static HRESULT WINAPI InputProcessorProfileMgr_UnregisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
842 LANGID langid, REFGUID guidProfile, DWORD dwFlags)
843 {
844 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
845 FIXME("(%p)->(%s %x %s %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), dwFlags);
846 return E_NOTIMPL;
847 }
848
849 static HRESULT WINAPI InputProcessorProfileMgr_GetActiveProfile(ITfInputProcessorProfileMgr *iface, REFGUID catid,
850 TF_INPUTPROCESSORPROFILE *pProfile)
851 {
852 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
853 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(catid), pProfile);
854 return E_NOTIMPL;
855 }
856
857 static const ITfInputProcessorProfileMgrVtbl InputProcessorProfileMgrVtbl = {
858 InputProcessorProfileMgr_QueryInterface,
859 InputProcessorProfileMgr_AddRef,
860 InputProcessorProfileMgr_Release,
861 InputProcessorProfileMgr_ActivateProfile,
862 InputProcessorProfileMgr_DeactivateProfile,
863 InputProcessorProfileMgr_GetProfile,
864 InputProcessorProfileMgr_EnumProfiles,
865 InputProcessorProfileMgr_ReleaseInputProcessor,
866 InputProcessorProfileMgr_RegisterProfile,
867 InputProcessorProfileMgr_UnregisterProfile,
868 InputProcessorProfileMgr_GetActiveProfile
869 };
870
871 /*****************************************************
872 * ITfSource functions
873 *****************************************************/
874 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
875 {
876 InputProcessorProfiles *This = impl_from_ITfSource(iface);
877 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, iid, ppvOut);
878 }
879
880 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
881 {
882 InputProcessorProfiles *This = impl_from_ITfSource(iface);
883 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
884 }
885
886 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
887 {
888 InputProcessorProfiles *This = impl_from_ITfSource(iface);
889 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
890 }
891
892 static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
893 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
894 {
895 InputProcessorProfiles *This = impl_from_ITfSource(iface);
896
897 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
898
899 if (!riid || !punk || !pdwCookie)
900 return E_INVALIDARG;
901
902 if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
903 return advise_sink(&This->LanguageProfileNotifySink, &IID_ITfLanguageProfileNotifySink,
904 COOKIE_MAGIC_IPPSINK, punk, pdwCookie);
905
906 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
907 return E_NOTIMPL;
908 }
909
910 static HRESULT WINAPI IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
911 {
912 InputProcessorProfiles *This = impl_from_ITfSource(iface);
913
914 TRACE("(%p) %x\n",This,pdwCookie);
915
916 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
917 return E_INVALIDARG;
918
919 return unadvise_sink(pdwCookie);
920 }
921
922 static const ITfSourceVtbl InputProcessorProfilesSourceVtbl =
923 {
924 IPPSource_QueryInterface,
925 IPPSource_AddRef,
926 IPPSource_Release,
927 IPPSource_AdviseSink,
928 IPPSource_UnadviseSink,
929 };
930
931 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
932 {
933 InputProcessorProfiles *This;
934 if (pUnkOuter)
935 return CLASS_E_NOAGGREGATION;
936
937 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
938 if (This == NULL)
939 return E_OUTOFMEMORY;
940
941 This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
942 This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
943 This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
944 This->refCount = 1;
945 This->currentLanguage = GetUserDefaultLCID();
946
947 list_init(&This->LanguageProfileNotifySink);
948
949 *ppOut = (IUnknown *)&This->ITfInputProcessorProfiles_iface;
950 TRACE("returning %p\n", *ppOut);
951 return S_OK;
952 }
953
954 /**************************************************
955 * IEnumGUID implementation for ITfInputProcessorProfiles::EnumInputProcessorInfo
956 **************************************************/
957 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
958 {
959 TRACE("destroying %p\n", This);
960 RegCloseKey(This->key);
961 HeapFree(GetProcessHeap(),0,This);
962 }
963
964 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
965 {
966 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
967 *ppvOut = NULL;
968
969 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
970 {
971 *ppvOut = &This->IEnumGUID_iface;
972 }
973
974 if (*ppvOut)
975 {
976 IEnumGUID_AddRef(iface);
977 return S_OK;
978 }
979
980 WARN("unsupported interface: %s\n", debugstr_guid(iid));
981 return E_NOINTERFACE;
982 }
983
984 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
985 {
986 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
987 return InterlockedIncrement(&This->refCount);
988 }
989
990 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
991 {
992 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
993 ULONG ret;
994
995 ret = InterlockedDecrement(&This->refCount);
996 if (ret == 0)
997 ProfilesEnumGuid_Destructor(This);
998 return ret;
999 }
1000
1001 /*****************************************************
1002 * IEnumGuid functions
1003 *****************************************************/
1004 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
1005 ULONG celt, GUID *rgelt, ULONG *pceltFetched)
1006 {
1007 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1008 ULONG fetched = 0;
1009
1010 TRACE("(%p)\n",This);
1011
1012 if (rgelt == NULL) return E_POINTER;
1013
1014 if (This->key) while (fetched < celt)
1015 {
1016 LSTATUS res;
1017 HRESULT hr;
1018 WCHAR catid[39];
1019 DWORD cName = 39;
1020
1021 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1022 NULL, NULL, NULL, NULL);
1023 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1024 ++(This->next_index);
1025
1026 hr = CLSIDFromString(catid, rgelt);
1027 if (FAILED(hr)) continue;
1028
1029 ++fetched;
1030 ++rgelt;
1031 }
1032
1033 if (pceltFetched) *pceltFetched = fetched;
1034 return fetched == celt ? S_OK : S_FALSE;
1035 }
1036
1037 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
1038 {
1039 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1040 TRACE("(%p)\n",This);
1041
1042 This->next_index += celt;
1043 return S_OK;
1044 }
1045
1046 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
1047 {
1048 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1049 TRACE("(%p)\n",This);
1050 This->next_index = 0;
1051 return S_OK;
1052 }
1053
1054 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
1055 IEnumGUID **ppenum)
1056 {
1057 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1058 HRESULT res;
1059
1060 TRACE("(%p)\n",This);
1061
1062 if (ppenum == NULL) return E_POINTER;
1063
1064 res = ProfilesEnumGuid_Constructor(ppenum);
1065 if (SUCCEEDED(res))
1066 {
1067 ProfilesEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
1068 new_This->next_index = This->next_index;
1069 }
1070 return res;
1071 }
1072
1073 static const IEnumGUIDVtbl EnumGUIDVtbl =
1074 {
1075 ProfilesEnumGuid_QueryInterface,
1076 ProfilesEnumGuid_AddRef,
1077 ProfilesEnumGuid_Release,
1078 ProfilesEnumGuid_Next,
1079 ProfilesEnumGuid_Skip,
1080 ProfilesEnumGuid_Reset,
1081 ProfilesEnumGuid_Clone
1082 };
1083
1084 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
1085 {
1086 ProfilesEnumGuid *This;
1087
1088 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ProfilesEnumGuid));
1089 if (This == NULL)
1090 return E_OUTOFMEMORY;
1091
1092 This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
1093 This->refCount = 1;
1094
1095 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1096 KEY_READ | KEY_WRITE, NULL, &This->key, NULL) != ERROR_SUCCESS)
1097 {
1098 HeapFree(GetProcessHeap(), 0, This);
1099 return E_FAIL;
1100 }
1101
1102 *ppOut = &This->IEnumGUID_iface;
1103 TRACE("returning %p\n", *ppOut);
1104 return S_OK;
1105 }
1106
1107 /**************************************************
1108 * IEnumTfLanguageProfiles implementation
1109 **************************************************/
1110 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
1111 {
1112 TRACE("destroying %p\n", This);
1113 RegCloseKey(This->tipkey);
1114 if (This->langkey)
1115 RegCloseKey(This->langkey);
1116 ITfCategoryMgr_Release(This->catmgr);
1117 HeapFree(GetProcessHeap(),0,This);
1118 }
1119
1120 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
1121 {
1122 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1123
1124 *ppvOut = NULL;
1125
1126 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
1127 {
1128 *ppvOut = &This->IEnumTfLanguageProfiles_iface;
1129 }
1130
1131 if (*ppvOut)
1132 {
1133 IEnumTfLanguageProfiles_AddRef(iface);
1134 return S_OK;
1135 }
1136
1137 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1138 return E_NOINTERFACE;
1139 }
1140
1141 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
1142 {
1143 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1144 return InterlockedIncrement(&This->refCount);
1145 }
1146
1147 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
1148 {
1149 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1150 ULONG ret;
1151
1152 ret = InterlockedDecrement(&This->refCount);
1153 if (ret == 0)
1154 EnumTfLanguageProfiles_Destructor(This);
1155 return ret;
1156 }
1157
1158 /*****************************************************
1159 * IEnumGuid functions
1160 *****************************************************/
1161 static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LANGUAGEPROFILE *tflp)
1162 {
1163 WCHAR fullkey[168];
1164 ULONG res;
1165 WCHAR profileid[39];
1166 DWORD cName = 39;
1167 GUID profile;
1168
1169 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1170
1171 if (This->langkey == NULL)
1172 {
1173 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1174 res = RegOpenKeyExW(This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1175 if (res)
1176 {
1177 This->langkey = NULL;
1178 return -1;
1179 }
1180 This->lang_index = 0;
1181 }
1182 res = RegEnumKeyExW(This->langkey, This->lang_index, profileid, &cName,
1183 NULL, NULL, NULL, NULL);
1184 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1185 {
1186 RegCloseKey(This->langkey);
1187 This->langkey = NULL;
1188 return -1;
1189 }
1190 ++(This->lang_index);
1191
1192 if (tflp)
1193 {
1194 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
1195 &GUID_TFCAT_TIP_SPEECH,
1196 &GUID_TFCAT_TIP_HANDWRITING };
1197 res = CLSIDFromString(profileid, &profile);
1198 if (FAILED(res)) return 0;
1199
1200 tflp->clsid = clsid;
1201 tflp->langid = This->langid;
1202 tflp->fActive = get_active_textservice(&clsid, NULL);
1203 tflp->guidProfile = profile;
1204 if (ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1205 &tflp->catid, tipcats, 3) != S_OK)
1206 ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1207 &tflp->catid, NULL, 0);
1208 }
1209
1210 return 1;
1211 }
1212
1213 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
1214 ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
1215 {
1216 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1217 ULONG fetched = 0;
1218
1219 TRACE("(%p)\n",This);
1220
1221 if (pProfile == NULL) return E_POINTER;
1222
1223 if (This->tipkey) while (fetched < ulCount)
1224 {
1225 LSTATUS res;
1226 HRESULT hr;
1227 DWORD cName = 39;
1228 GUID clsid;
1229
1230 res = RegEnumKeyExW(This->tipkey, This->tip_index,
1231 This->szwCurrentClsid, &cName, NULL, NULL, NULL, NULL);
1232 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1233 ++(This->tip_index);
1234 hr = CLSIDFromString(This->szwCurrentClsid, &clsid);
1235 if (FAILED(hr)) continue;
1236
1237 while ( fetched < ulCount)
1238 {
1239 INT res = next_LanguageProfile(This, clsid, pProfile);
1240 if (res == 1)
1241 {
1242 ++fetched;
1243 ++pProfile;
1244 }
1245 else if (res == -1)
1246 break;
1247 else
1248 continue;
1249 }
1250 }
1251
1252 if (pcFetch) *pcFetch = fetched;
1253 return fetched == ulCount ? S_OK : S_FALSE;
1254 }
1255
1256 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
1257 {
1258 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1259 FIXME("STUB (%p)\n",This);
1260 return E_NOTIMPL;
1261 }
1262
1263 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
1264 {
1265 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1266 TRACE("(%p)\n",This);
1267 This->tip_index = 0;
1268 if (This->langkey)
1269 RegCloseKey(This->langkey);
1270 This->langkey = NULL;
1271 This->lang_index = 0;
1272 return S_OK;
1273 }
1274
1275 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
1276 IEnumTfLanguageProfiles **ppenum)
1277 {
1278 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1279 EnumTfLanguageProfiles *new_This;
1280 HRESULT res;
1281
1282 TRACE("(%p)\n",This);
1283
1284 if (ppenum == NULL) return E_POINTER;
1285
1286 res = EnumTfLanguageProfiles_Constructor(This->langid, &new_This);
1287 if (SUCCEEDED(res))
1288 {
1289 new_This->tip_index = This->tip_index;
1290 lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
1291
1292 if (This->langkey)
1293 {
1294 WCHAR fullkey[168];
1295 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1296
1297 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1298 res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1299 new_This->lang_index = This->lang_index;
1300 }
1301 *ppenum = &new_This->IEnumTfLanguageProfiles_iface;
1302 }
1303 return res;
1304 }
1305
1306 static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
1307 {
1308 EnumTfLanguageProfiles_QueryInterface,
1309 EnumTfLanguageProfiles_AddRef,
1310 EnumTfLanguageProfiles_Release,
1311 EnumTfLanguageProfiles_Clone,
1312 EnumTfLanguageProfiles_Next,
1313 EnumTfLanguageProfiles_Reset,
1314 EnumTfLanguageProfiles_Skip
1315 };
1316
1317 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out)
1318 {
1319 HRESULT hr;
1320 EnumTfLanguageProfiles *This;
1321
1322 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfLanguageProfiles));
1323 if (This == NULL)
1324 return E_OUTOFMEMORY;
1325
1326 This->IEnumTfLanguageProfiles_iface.lpVtbl= &EnumTfLanguageProfilesVtbl;
1327 This->refCount = 1;
1328 This->langid = langid;
1329
1330 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&This->catmgr);
1331 if (FAILED(hr))
1332 {
1333 HeapFree(GetProcessHeap(),0,This);
1334 return hr;
1335 }
1336
1337 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1338 KEY_READ | KEY_WRITE, NULL, &This->tipkey, NULL) != ERROR_SUCCESS)
1339 {
1340 HeapFree(GetProcessHeap(), 0, This);
1341 return E_FAIL;
1342 }
1343
1344 *out = This;
1345 TRACE("returning %p\n", *out);
1346 return S_OK;
1347 }