[MSCTF] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / reactos / 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 RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
332 RegDeleteTreeW(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 LanguageProfile.fActive = TRUE;
531
532 return add_active_textservice(&LanguageProfile);
533 }
534
535 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
536 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
537 GUID *pguidProfile)
538 {
539 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
540 TF_LANGUAGEPROFILE profile;
541
542 TRACE("(%p) %s %p %p\n",This,debugstr_guid(rclsid),plangid,pguidProfile);
543
544 if (!rclsid || !plangid || !pguidProfile)
545 return E_INVALIDARG;
546
547 if (get_active_textservice(rclsid, &profile))
548 {
549 *plangid = profile.langid;
550 *pguidProfile = profile.guidProfile;
551 return S_OK;
552 }
553 else
554 {
555 *pguidProfile = GUID_NULL;
556 return S_FALSE;
557 }
558 }
559
560 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
561 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
562 REFGUID guidProfile, BSTR *pbstrProfile)
563 {
564 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
565 FIXME("STUB:(%p)\n",This);
566 return E_NOTIMPL;
567 }
568
569 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
570 ITfInputProcessorProfiles *iface, LANGID *plangid)
571 {
572 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
573 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
574
575 if (!plangid)
576 return E_INVALIDARG;
577
578 *plangid = This->currentLanguage;
579
580 return S_OK;
581 }
582
583 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
584 ITfInputProcessorProfiles *iface, LANGID langid)
585 {
586 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
587 struct list *cursor;
588 BOOL accept;
589
590 FIXME("STUB:(%p)\n",This);
591
592 LIST_FOR_EACH(cursor, &This->LanguageProfileNotifySink)
593 {
594 InputProcessorProfilesSink* sink = LIST_ENTRY(cursor,InputProcessorProfilesSink,entry);
595 accept = TRUE;
596 ITfLanguageProfileNotifySink_OnLanguageChange(sink->interfaces.pITfLanguageProfileNotifySink, langid, &accept);
597 if (!accept)
598 return E_FAIL;
599 }
600
601 /* TODO: On successful language change call OnLanguageChanged sink */
602 return E_NOTIMPL;
603 }
604
605 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
606 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
607 {
608 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
609 FIXME("Semi-STUB:(%p)\n",This);
610 *ppLangId = CoTaskMemAlloc(sizeof(LANGID));
611 **ppLangId = This->currentLanguage;
612 *pulCount = 1;
613 return S_OK;
614 }
615
616 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
617 ITfInputProcessorProfiles *iface, LANGID langid,
618 IEnumTfLanguageProfiles **ppEnum)
619 {
620 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
621 TRACE("(%p) %x %p\n",This,langid,ppEnum);
622 return EnumTfLanguageProfiles_Constructor(langid, ppEnum);
623 }
624
625 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
626 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
627 REFGUID guidProfile, BOOL fEnable)
628 {
629 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
630 HKEY key;
631 WCHAR buf[39];
632 WCHAR buf2[39];
633 WCHAR fullkey[168];
634 ULONG res;
635
636 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
637
638 StringFromGUID2(rclsid, buf, 39);
639 StringFromGUID2(guidProfile, buf2, 39);
640 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
641
642 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
643
644 if (!res)
645 {
646 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
647 RegCloseKey(key);
648 }
649 else
650 return E_FAIL;
651
652 return S_OK;
653 }
654
655 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
656 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
657 REFGUID guidProfile, BOOL *pfEnable)
658 {
659 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
660 HKEY key;
661 WCHAR buf[39];
662 WCHAR buf2[39];
663 WCHAR fullkey[168];
664 ULONG res;
665
666 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
667
668 if (!pfEnable)
669 return E_INVALIDARG;
670
671 StringFromGUID2(rclsid, buf, 39);
672 StringFromGUID2(guidProfile, buf2, 39);
673 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
674
675 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
676
677 if (!res)
678 {
679 DWORD count = sizeof(DWORD);
680 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
681 RegCloseKey(key);
682 }
683
684 if (res) /* Try Default */
685 {
686 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
687
688 if (!res)
689 {
690 DWORD count = sizeof(DWORD);
691 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
692 RegCloseKey(key);
693 }
694 }
695
696 if (!res)
697 return S_OK;
698 else
699 return E_FAIL;
700 }
701
702 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
703 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
704 REFGUID guidProfile, BOOL fEnable)
705 {
706 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
707 HKEY key;
708 WCHAR buf[39];
709 WCHAR buf2[39];
710 WCHAR fullkey[168];
711 ULONG res;
712
713 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
714
715 StringFromGUID2(rclsid, buf, 39);
716 StringFromGUID2(guidProfile, buf2, 39);
717 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
718
719 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
720
721 if (!res)
722 {
723 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
724 RegCloseKey(key);
725 }
726 else
727 return E_FAIL;
728
729 return S_OK;
730 }
731
732 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
733 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
734 REFGUID guidProfile, HKL hKL)
735 {
736 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
737 FIXME("STUB:(%p)\n",This);
738 return E_NOTIMPL;
739 }
740
741 static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl =
742 {
743 InputProcessorProfiles_QueryInterface,
744 InputProcessorProfiles_AddRef,
745 InputProcessorProfiles_Release,
746 InputProcessorProfiles_Register,
747 InputProcessorProfiles_Unregister,
748 InputProcessorProfiles_AddLanguageProfile,
749 InputProcessorProfiles_RemoveLanguageProfile,
750 InputProcessorProfiles_EnumInputProcessorInfo,
751 InputProcessorProfiles_GetDefaultLanguageProfile,
752 InputProcessorProfiles_SetDefaultLanguageProfile,
753 InputProcessorProfiles_ActivateLanguageProfile,
754 InputProcessorProfiles_GetActiveLanguageProfile,
755 InputProcessorProfiles_GetLanguageProfileDescription,
756 InputProcessorProfiles_GetCurrentLanguage,
757 InputProcessorProfiles_ChangeCurrentLanguage,
758 InputProcessorProfiles_GetLanguageList,
759 InputProcessorProfiles_EnumLanguageProfiles,
760 InputProcessorProfiles_EnableLanguageProfile,
761 InputProcessorProfiles_IsEnabledLanguageProfile,
762 InputProcessorProfiles_EnableLanguageProfileByDefault,
763 InputProcessorProfiles_SubstituteKeyboardLayout
764 };
765
766 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfileMgr(ITfInputProcessorProfileMgr *iface)
767 {
768 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfileMgr_iface);
769 }
770
771 static HRESULT WINAPI InputProcessorProfileMgr_QueryInterface(ITfInputProcessorProfileMgr *iface, REFIID riid, void **ppv)
772 {
773 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
774 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, riid, ppv);
775 }
776
777 static ULONG WINAPI InputProcessorProfileMgr_AddRef(ITfInputProcessorProfileMgr *iface)
778 {
779 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
780 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
781 }
782
783 static ULONG WINAPI InputProcessorProfileMgr_Release(ITfInputProcessorProfileMgr *iface)
784 {
785 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
786 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
787 }
788
789 static HRESULT WINAPI InputProcessorProfileMgr_ActivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
790 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
791 {
792 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
793 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
794 debugstr_guid(guidProfile), hkl, dwFlags);
795 return E_NOTIMPL;
796 }
797
798 static HRESULT WINAPI InputProcessorProfileMgr_DeactivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
799 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
800 {
801 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
802 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
803 debugstr_guid(guidProfile), hkl, dwFlags);
804 return E_NOTIMPL;
805 }
806
807 static HRESULT WINAPI InputProcessorProfileMgr_GetProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
808 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, TF_INPUTPROCESSORPROFILE *pProfile)
809 {
810 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
811 FIXME("(%p)->(%d %x %s %s %p %p)\n", This, dwProfileType, langid, debugstr_guid(clsid),
812 debugstr_guid(guidProfile), hkl, pProfile);
813 return E_NOTIMPL;
814 }
815
816 static HRESULT WINAPI InputProcessorProfileMgr_EnumProfiles(ITfInputProcessorProfileMgr *iface, LANGID langid,
817 IEnumTfInputProcessorProfiles **ppEnum)
818 {
819 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
820 EnumTfInputProcessorProfiles *enum_profiles;
821
822 TRACE("(%p)->(%x %p)\n", This, langid, ppEnum);
823
824 enum_profiles = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_profiles));
825 if(!enum_profiles)
826 return E_OUTOFMEMORY;
827
828 enum_profiles->IEnumTfInputProcessorProfiles_iface.lpVtbl = &EnumTfInputProcessorProfilesVtbl;
829 enum_profiles->ref = 1;
830
831 *ppEnum = &enum_profiles->IEnumTfInputProcessorProfiles_iface;
832 return S_OK;
833 }
834
835 static HRESULT WINAPI InputProcessorProfileMgr_ReleaseInputProcessor(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
836 DWORD dwFlags)
837 {
838 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
839 FIXME("(%p)->(%s %x)\n", This, debugstr_guid(rclsid), dwFlags);
840 return E_NOTIMPL;
841 }
842
843 static HRESULT WINAPI InputProcessorProfileMgr_RegisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
844 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR *pchIconFile,
845 ULONG cchFile, ULONG uIconIndex, HKL hklsubstitute, DWORD dwPreferredLayout, BOOL bEnabledByDefault,
846 DWORD dwFlags)
847 {
848 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
849 FIXME("(%p)->(%s %x %s %s %d %s %u %u %p %x %x %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile),
850 debugstr_w(pchDesc), cchDesc, debugstr_w(pchIconFile), cchFile, uIconIndex, hklsubstitute, dwPreferredLayout,
851 bEnabledByDefault, dwFlags);
852 return E_NOTIMPL;
853 }
854
855 static HRESULT WINAPI InputProcessorProfileMgr_UnregisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
856 LANGID langid, REFGUID guidProfile, DWORD dwFlags)
857 {
858 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
859 FIXME("(%p)->(%s %x %s %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), dwFlags);
860 return E_NOTIMPL;
861 }
862
863 static HRESULT WINAPI InputProcessorProfileMgr_GetActiveProfile(ITfInputProcessorProfileMgr *iface, REFGUID catid,
864 TF_INPUTPROCESSORPROFILE *pProfile)
865 {
866 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
867 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(catid), pProfile);
868 return E_NOTIMPL;
869 }
870
871 static const ITfInputProcessorProfileMgrVtbl InputProcessorProfileMgrVtbl = {
872 InputProcessorProfileMgr_QueryInterface,
873 InputProcessorProfileMgr_AddRef,
874 InputProcessorProfileMgr_Release,
875 InputProcessorProfileMgr_ActivateProfile,
876 InputProcessorProfileMgr_DeactivateProfile,
877 InputProcessorProfileMgr_GetProfile,
878 InputProcessorProfileMgr_EnumProfiles,
879 InputProcessorProfileMgr_ReleaseInputProcessor,
880 InputProcessorProfileMgr_RegisterProfile,
881 InputProcessorProfileMgr_UnregisterProfile,
882 InputProcessorProfileMgr_GetActiveProfile
883 };
884
885 /*****************************************************
886 * ITfSource functions
887 *****************************************************/
888 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
889 {
890 InputProcessorProfiles *This = impl_from_ITfSource(iface);
891 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, iid, ppvOut);
892 }
893
894 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
895 {
896 InputProcessorProfiles *This = impl_from_ITfSource(iface);
897 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
898 }
899
900 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
901 {
902 InputProcessorProfiles *This = impl_from_ITfSource(iface);
903 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
904 }
905
906 static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
907 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
908 {
909 InputProcessorProfiles *This = impl_from_ITfSource(iface);
910 InputProcessorProfilesSink *ipps;
911
912 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
913
914 if (!riid || !punk || !pdwCookie)
915 return E_INVALIDARG;
916
917 if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
918 {
919 ipps = HeapAlloc(GetProcessHeap(),0,sizeof(InputProcessorProfilesSink));
920 if (!ipps)
921 return E_OUTOFMEMORY;
922 if (FAILED(IUnknown_QueryInterface(punk, riid, (LPVOID *)&ipps->interfaces.pITfLanguageProfileNotifySink)))
923 {
924 HeapFree(GetProcessHeap(),0,ipps);
925 return CONNECT_E_CANNOTCONNECT;
926 }
927 list_add_head(&This->LanguageProfileNotifySink,&ipps->entry);
928 *pdwCookie = generate_Cookie(COOKIE_MAGIC_IPPSINK, ipps);
929 }
930 else
931 {
932 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
933 return E_NOTIMPL;
934 }
935
936 TRACE("cookie %x\n",*pdwCookie);
937
938 return S_OK;
939 }
940
941 static HRESULT WINAPI IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
942 {
943 InputProcessorProfiles *This = impl_from_ITfSource(iface);
944 InputProcessorProfilesSink *sink;
945
946 TRACE("(%p) %x\n",This,pdwCookie);
947
948 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
949 return E_INVALIDARG;
950
951 sink = remove_Cookie(pdwCookie);
952 if (!sink)
953 return CONNECT_E_NOCONNECTION;
954
955 list_remove(&sink->entry);
956 free_sink(sink);
957
958 return S_OK;
959 }
960
961 static const ITfSourceVtbl InputProcessorProfilesSourceVtbl =
962 {
963 IPPSource_QueryInterface,
964 IPPSource_AddRef,
965 IPPSource_Release,
966 IPPSource_AdviseSink,
967 IPPSource_UnadviseSink,
968 };
969
970 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
971 {
972 InputProcessorProfiles *This;
973 if (pUnkOuter)
974 return CLASS_E_NOAGGREGATION;
975
976 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
977 if (This == NULL)
978 return E_OUTOFMEMORY;
979
980 This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
981 This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
982 This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
983 This->refCount = 1;
984 This->currentLanguage = GetUserDefaultLCID();
985
986 list_init(&This->LanguageProfileNotifySink);
987
988 *ppOut = (IUnknown *)&This->ITfInputProcessorProfiles_iface;
989 TRACE("returning %p\n", *ppOut);
990 return S_OK;
991 }
992
993 /**************************************************
994 * IEnumGUID implementation for ITfInputProcessorProfiles::EnumInputProcessorInfo
995 **************************************************/
996 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
997 {
998 TRACE("destroying %p\n", This);
999 RegCloseKey(This->key);
1000 HeapFree(GetProcessHeap(),0,This);
1001 }
1002
1003 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
1004 {
1005 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1006 *ppvOut = NULL;
1007
1008 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
1009 {
1010 *ppvOut = &This->IEnumGUID_iface;
1011 }
1012
1013 if (*ppvOut)
1014 {
1015 IEnumGUID_AddRef(iface);
1016 return S_OK;
1017 }
1018
1019 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1020 return E_NOINTERFACE;
1021 }
1022
1023 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
1024 {
1025 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1026 return InterlockedIncrement(&This->refCount);
1027 }
1028
1029 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
1030 {
1031 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1032 ULONG ret;
1033
1034 ret = InterlockedDecrement(&This->refCount);
1035 if (ret == 0)
1036 ProfilesEnumGuid_Destructor(This);
1037 return ret;
1038 }
1039
1040 /*****************************************************
1041 * IEnumGuid functions
1042 *****************************************************/
1043 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
1044 ULONG celt, GUID *rgelt, ULONG *pceltFetched)
1045 {
1046 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1047 ULONG fetched = 0;
1048
1049 TRACE("(%p)\n",This);
1050
1051 if (rgelt == NULL) return E_POINTER;
1052
1053 if (This->key) while (fetched < celt)
1054 {
1055 LSTATUS res;
1056 HRESULT hr;
1057 WCHAR catid[39];
1058 DWORD cName = 39;
1059
1060 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1061 NULL, NULL, NULL, NULL);
1062 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1063 ++(This->next_index);
1064
1065 hr = CLSIDFromString(catid, rgelt);
1066 if (FAILED(hr)) continue;
1067
1068 ++fetched;
1069 ++rgelt;
1070 }
1071
1072 if (pceltFetched) *pceltFetched = fetched;
1073 return fetched == celt ? S_OK : S_FALSE;
1074 }
1075
1076 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
1077 {
1078 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1079 TRACE("(%p)\n",This);
1080
1081 This->next_index += celt;
1082 return S_OK;
1083 }
1084
1085 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
1086 {
1087 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1088 TRACE("(%p)\n",This);
1089 This->next_index = 0;
1090 return S_OK;
1091 }
1092
1093 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
1094 IEnumGUID **ppenum)
1095 {
1096 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1097 HRESULT res;
1098
1099 TRACE("(%p)\n",This);
1100
1101 if (ppenum == NULL) return E_POINTER;
1102
1103 res = ProfilesEnumGuid_Constructor(ppenum);
1104 if (SUCCEEDED(res))
1105 {
1106 ProfilesEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
1107 new_This->next_index = This->next_index;
1108 }
1109 return res;
1110 }
1111
1112 static const IEnumGUIDVtbl EnumGUIDVtbl =
1113 {
1114 ProfilesEnumGuid_QueryInterface,
1115 ProfilesEnumGuid_AddRef,
1116 ProfilesEnumGuid_Release,
1117 ProfilesEnumGuid_Next,
1118 ProfilesEnumGuid_Skip,
1119 ProfilesEnumGuid_Reset,
1120 ProfilesEnumGuid_Clone
1121 };
1122
1123 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
1124 {
1125 ProfilesEnumGuid *This;
1126
1127 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ProfilesEnumGuid));
1128 if (This == NULL)
1129 return E_OUTOFMEMORY;
1130
1131 This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
1132 This->refCount = 1;
1133
1134 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1135 KEY_READ | KEY_WRITE, NULL, &This->key, NULL) != ERROR_SUCCESS)
1136 {
1137 HeapFree(GetProcessHeap(), 0, This);
1138 return E_FAIL;
1139 }
1140
1141 *ppOut = &This->IEnumGUID_iface;
1142 TRACE("returning %p\n", *ppOut);
1143 return S_OK;
1144 }
1145
1146 /**************************************************
1147 * IEnumTfLanguageProfiles implementation
1148 **************************************************/
1149 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
1150 {
1151 TRACE("destroying %p\n", This);
1152 RegCloseKey(This->tipkey);
1153 if (This->langkey)
1154 RegCloseKey(This->langkey);
1155 ITfCategoryMgr_Release(This->catmgr);
1156 HeapFree(GetProcessHeap(),0,This);
1157 }
1158
1159 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
1160 {
1161 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1162
1163 *ppvOut = NULL;
1164
1165 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
1166 {
1167 *ppvOut = &This->IEnumTfLanguageProfiles_iface;
1168 }
1169
1170 if (*ppvOut)
1171 {
1172 IEnumTfLanguageProfiles_AddRef(iface);
1173 return S_OK;
1174 }
1175
1176 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1177 return E_NOINTERFACE;
1178 }
1179
1180 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
1181 {
1182 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1183 return InterlockedIncrement(&This->refCount);
1184 }
1185
1186 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
1187 {
1188 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1189 ULONG ret;
1190
1191 ret = InterlockedDecrement(&This->refCount);
1192 if (ret == 0)
1193 EnumTfLanguageProfiles_Destructor(This);
1194 return ret;
1195 }
1196
1197 /*****************************************************
1198 * IEnumGuid functions
1199 *****************************************************/
1200 static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LANGUAGEPROFILE *tflp)
1201 {
1202 WCHAR fullkey[168];
1203 ULONG res;
1204 WCHAR profileid[39];
1205 DWORD cName = 39;
1206 GUID profile;
1207
1208 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1209
1210 if (This->langkey == NULL)
1211 {
1212 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1213 res = RegOpenKeyExW(This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1214 if (res)
1215 {
1216 This->langkey = NULL;
1217 return -1;
1218 }
1219 This->lang_index = 0;
1220 }
1221 res = RegEnumKeyExW(This->langkey, This->lang_index, profileid, &cName,
1222 NULL, NULL, NULL, NULL);
1223 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1224 {
1225 RegCloseKey(This->langkey);
1226 This->langkey = NULL;
1227 return -1;
1228 }
1229 ++(This->lang_index);
1230
1231 if (tflp)
1232 {
1233 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
1234 &GUID_TFCAT_TIP_SPEECH,
1235 &GUID_TFCAT_TIP_HANDWRITING };
1236 res = CLSIDFromString(profileid, &profile);
1237 if (FAILED(res)) return 0;
1238
1239 tflp->clsid = clsid;
1240 tflp->langid = This->langid;
1241 tflp->fActive = get_active_textservice(&clsid, NULL);
1242 tflp->guidProfile = profile;
1243 if (ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1244 &tflp->catid, tipcats, 3) != S_OK)
1245 ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1246 &tflp->catid, NULL, 0);
1247 }
1248
1249 return 1;
1250 }
1251
1252 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
1253 ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
1254 {
1255 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1256 ULONG fetched = 0;
1257
1258 TRACE("(%p)\n",This);
1259
1260 if (pProfile == NULL) return E_POINTER;
1261
1262 if (This->tipkey) while (fetched < ulCount)
1263 {
1264 LSTATUS res;
1265 HRESULT hr;
1266 DWORD cName = 39;
1267 GUID clsid;
1268
1269 res = RegEnumKeyExW(This->tipkey, This->tip_index,
1270 This->szwCurrentClsid, &cName, NULL, NULL, NULL, NULL);
1271 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1272 ++(This->tip_index);
1273 hr = CLSIDFromString(This->szwCurrentClsid, &clsid);
1274 if (FAILED(hr)) continue;
1275
1276 while ( fetched < ulCount)
1277 {
1278 INT res = next_LanguageProfile(This, clsid, pProfile);
1279 if (res == 1)
1280 {
1281 ++fetched;
1282 ++pProfile;
1283 }
1284 else if (res == -1)
1285 break;
1286 else
1287 continue;
1288 }
1289 }
1290
1291 if (pcFetch) *pcFetch = fetched;
1292 return fetched == ulCount ? S_OK : S_FALSE;
1293 }
1294
1295 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
1296 {
1297 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1298 FIXME("STUB (%p)\n",This);
1299 return E_NOTIMPL;
1300 }
1301
1302 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
1303 {
1304 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1305 TRACE("(%p)\n",This);
1306 This->tip_index = 0;
1307 if (This->langkey)
1308 RegCloseKey(This->langkey);
1309 This->langkey = NULL;
1310 This->lang_index = 0;
1311 return S_OK;
1312 }
1313
1314 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
1315 IEnumTfLanguageProfiles **ppenum)
1316 {
1317 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1318 HRESULT res;
1319
1320 TRACE("(%p)\n",This);
1321
1322 if (ppenum == NULL) return E_POINTER;
1323
1324 res = EnumTfLanguageProfiles_Constructor(This->langid, ppenum);
1325 if (SUCCEEDED(res))
1326 {
1327 EnumTfLanguageProfiles *new_This = (EnumTfLanguageProfiles *)*ppenum;
1328 new_This->tip_index = This->tip_index;
1329 lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
1330
1331 if (This->langkey)
1332 {
1333 WCHAR fullkey[168];
1334 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1335
1336 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1337 res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1338 new_This->lang_index = This->lang_index;
1339 }
1340 }
1341 return res;
1342 }
1343
1344 static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
1345 {
1346 EnumTfLanguageProfiles_QueryInterface,
1347 EnumTfLanguageProfiles_AddRef,
1348 EnumTfLanguageProfiles_Release,
1349 EnumTfLanguageProfiles_Clone,
1350 EnumTfLanguageProfiles_Next,
1351 EnumTfLanguageProfiles_Reset,
1352 EnumTfLanguageProfiles_Skip
1353 };
1354
1355 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut)
1356 {
1357 HRESULT hr;
1358 EnumTfLanguageProfiles *This;
1359
1360 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfLanguageProfiles));
1361 if (This == NULL)
1362 return E_OUTOFMEMORY;
1363
1364 This->IEnumTfLanguageProfiles_iface.lpVtbl= &EnumTfLanguageProfilesVtbl;
1365 This->refCount = 1;
1366 This->langid = langid;
1367
1368 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&This->catmgr);
1369 if (FAILED(hr))
1370 {
1371 HeapFree(GetProcessHeap(),0,This);
1372 return hr;
1373 }
1374
1375 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1376 KEY_READ | KEY_WRITE, NULL, &This->tipkey, NULL) != ERROR_SUCCESS)
1377 {
1378 HeapFree(GetProcessHeap(), 0, This);
1379 return E_FAIL;
1380 }
1381
1382 *ppOut = &This->IEnumTfLanguageProfiles_iface;
1383 TRACE("returning %p\n", *ppOut);
1384 return S_OK;
1385 }