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