makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / msctf / inputprocessor.c
blob7cb59f9446033a26b4d3832c7e4ade2bbb23c6d9
1 /*
2 * ITfInputProcessorProfiles implementation
4 * Copyright 2009 Aric Stewart, CodeWeavers
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.
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.
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
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "wine/debug.h"
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winuser.h"
30 #include "shlwapi.h"
31 #include "winerror.h"
32 #include "objbase.h"
33 #include "olectl.h"
35 #include "msctf.h"
36 #include "msctf_internal.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
40 static const WCHAR szwLngp[] = {'L','a','n','g','u','a','g','e','P','r','o','f','i','l','e',0};
41 static const WCHAR szwEnable[] = {'E','n','a','b','l','e',0};
42 static const WCHAR szwTipfmt[] = {'%','s','\\','%','s',0};
43 static const WCHAR szwFullLangfmt[] = {'%','s','\\','%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
45 static const WCHAR szwAssemblies[] = {'A','s','s','e','m','b','l','i','e','s',0};
46 static const WCHAR szwDefault[] = {'D','e','f','a','u','l','t',0};
47 static const WCHAR szwProfile[] = {'P','r','o','f','i','l','e',0};
48 static const WCHAR szwDefaultFmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
50 typedef struct tagInputProcessorProfiles {
51 ITfInputProcessorProfiles ITfInputProcessorProfiles_iface;
52 ITfSource ITfSource_iface;
53 ITfInputProcessorProfileMgr ITfInputProcessorProfileMgr_iface;
54 /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
55 /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
56 LONG refCount;
58 LANGID currentLanguage;
60 struct list LanguageProfileNotifySink;
61 } InputProcessorProfiles;
63 typedef struct tagProfilesEnumGuid {
64 IEnumGUID IEnumGUID_iface;
65 LONG refCount;
67 HKEY key;
68 DWORD next_index;
69 } ProfilesEnumGuid;
71 typedef struct tagEnumTfLanguageProfiles {
72 IEnumTfLanguageProfiles IEnumTfLanguageProfiles_iface;
73 LONG refCount;
75 HKEY tipkey;
76 DWORD tip_index;
77 WCHAR szwCurrentClsid[39];
79 HKEY langkey;
80 DWORD lang_index;
82 LANGID langid;
83 ITfCategoryMgr *catmgr;
84 } EnumTfLanguageProfiles;
86 typedef struct {
87 IEnumTfInputProcessorProfiles IEnumTfInputProcessorProfiles_iface;
88 LONG ref;
89 } EnumTfInputProcessorProfiles;
91 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut);
92 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out);
94 static inline EnumTfInputProcessorProfiles *impl_from_IEnumTfInputProcessorProfiles(IEnumTfInputProcessorProfiles *iface)
96 return CONTAINING_RECORD(iface, EnumTfInputProcessorProfiles, IEnumTfInputProcessorProfiles_iface);
99 static HRESULT WINAPI EnumTfInputProcessorProfiles_QueryInterface(IEnumTfInputProcessorProfiles *iface,
100 REFIID riid, void **ppv)
102 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
104 if(IsEqualGUID(riid, &IID_IUnknown)) {
105 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
106 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
107 }else if(IsEqualGUID(riid, &IID_IEnumTfInputProcessorProfiles)) {
108 TRACE("(%p)->(IID_IEnumTfInputProcessorProfiles %p)\n", This, ppv);
109 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
110 }else {
111 *ppv = NULL;
112 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
113 return E_NOINTERFACE;
116 IUnknown_AddRef((IUnknown*)*ppv);
117 return S_OK;
120 static ULONG WINAPI EnumTfInputProcessorProfiles_AddRef(IEnumTfInputProcessorProfiles *iface)
122 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
123 LONG ref = InterlockedIncrement(&This->ref);
125 TRACE("(%p) ref=%d\n", This, ref);
127 return ref;
130 static ULONG WINAPI EnumTfInputProcessorProfiles_Release(IEnumTfInputProcessorProfiles *iface)
132 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
133 LONG ref = InterlockedDecrement(&This->ref);
135 TRACE("(%p) ref=%d\n", This, ref);
137 if(!ref)
138 HeapFree(GetProcessHeap(), 0, This);
140 return ref;
143 static HRESULT WINAPI EnumTfInputProcessorProfiles_Clone(IEnumTfInputProcessorProfiles *iface,
144 IEnumTfInputProcessorProfiles **ret)
146 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
147 FIXME("(%p)->(%p)\n", This, ret);
148 return E_NOTIMPL;
151 static HRESULT WINAPI EnumTfInputProcessorProfiles_Next(IEnumTfInputProcessorProfiles *iface, ULONG count,
152 TF_INPUTPROCESSORPROFILE *profile, ULONG *fetch)
154 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
156 FIXME("(%p)->(%u %p %p)\n", This, count, profile, fetch);
158 if(fetch)
159 *fetch = 0;
160 return S_FALSE;
163 static HRESULT WINAPI EnumTfInputProcessorProfiles_Reset(IEnumTfInputProcessorProfiles *iface)
165 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
166 FIXME("(%p)\n", This);
167 return E_NOTIMPL;
170 static HRESULT WINAPI EnumTfInputProcessorProfiles_Skip(IEnumTfInputProcessorProfiles *iface, ULONG count)
172 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
173 FIXME("(%p)->(%u)\n", This, count);
174 return E_NOTIMPL;
177 static const IEnumTfInputProcessorProfilesVtbl EnumTfInputProcessorProfilesVtbl = {
178 EnumTfInputProcessorProfiles_QueryInterface,
179 EnumTfInputProcessorProfiles_AddRef,
180 EnumTfInputProcessorProfiles_Release,
181 EnumTfInputProcessorProfiles_Clone,
182 EnumTfInputProcessorProfiles_Next,
183 EnumTfInputProcessorProfiles_Reset,
184 EnumTfInputProcessorProfiles_Skip
187 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfiles(ITfInputProcessorProfiles *iface)
189 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfiles_iface);
192 static inline InputProcessorProfiles *impl_from_ITfSource(ITfSource *iface)
194 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfSource_iface);
197 static inline ProfilesEnumGuid *impl_from_IEnumGUID(IEnumGUID *iface)
199 return CONTAINING_RECORD(iface, ProfilesEnumGuid, IEnumGUID_iface);
202 static inline EnumTfLanguageProfiles *impl_from_IEnumTfLanguageProfiles(IEnumTfLanguageProfiles *iface)
204 return CONTAINING_RECORD(iface, EnumTfLanguageProfiles, IEnumTfLanguageProfiles_iface);
207 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
209 TRACE("destroying %p\n", This);
211 free_sinks(&This->LanguageProfileNotifySink);
212 HeapFree(GetProcessHeap(),0,This);
215 static void add_userkey( REFCLSID rclsid, LANGID langid,
216 REFGUID guidProfile)
218 HKEY key;
219 WCHAR buf[39];
220 WCHAR buf2[39];
221 WCHAR fullkey[168];
222 DWORD disposition = 0;
223 ULONG res;
225 TRACE("\n");
227 StringFromGUID2(rclsid, buf, 39);
228 StringFromGUID2(guidProfile, buf2, 39);
229 swprintf(fullkey,ARRAY_SIZE(fullkey),szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
231 res = RegCreateKeyExW(HKEY_CURRENT_USER,fullkey, 0, NULL, 0,
232 KEY_READ | KEY_WRITE, NULL, &key, &disposition);
234 if (!res && disposition == REG_CREATED_NEW_KEY)
236 DWORD zero = 0x0;
237 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
240 if (!res)
241 RegCloseKey(key);
244 static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, void **ppv)
246 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
248 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
250 *ppv = &This->ITfInputProcessorProfiles_iface;
252 else if (IsEqualIID(iid, &IID_ITfInputProcessorProfileMgr))
254 *ppv = &This->ITfInputProcessorProfileMgr_iface;
256 else if (IsEqualIID(iid, &IID_ITfSource))
258 *ppv = &This->ITfSource_iface;
260 else
262 *ppv = NULL;
263 WARN("unsupported interface: %s\n", debugstr_guid(iid));
264 return E_NOINTERFACE;
267 ITfInputProcessorProfiles_AddRef(iface);
268 return S_OK;
271 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
273 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
274 return InterlockedIncrement(&This->refCount);
277 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
279 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
280 ULONG ret;
282 ret = InterlockedDecrement(&This->refCount);
283 if (ret == 0)
284 InputProcessorProfiles_Destructor(This);
285 return ret;
288 /*****************************************************
289 * ITfInputProcessorProfiles functions
290 *****************************************************/
291 static HRESULT WINAPI InputProcessorProfiles_Register(
292 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
294 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
295 HKEY tipkey;
296 WCHAR buf[39];
297 WCHAR fullkey[68];
299 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
301 StringFromGUID2(rclsid, buf, 39);
302 swprintf(fullkey,ARRAY_SIZE(fullkey),szwTipfmt,szwSystemTIPKey,buf);
304 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, NULL, 0,
305 KEY_READ | KEY_WRITE, NULL, &tipkey, NULL) != ERROR_SUCCESS)
306 return E_FAIL;
308 RegCloseKey(tipkey);
310 return S_OK;
313 static HRESULT WINAPI InputProcessorProfiles_Unregister(
314 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
316 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
317 WCHAR buf[39];
318 WCHAR fullkey[68];
320 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
322 StringFromGUID2(rclsid, buf, 39);
323 swprintf(fullkey,ARRAY_SIZE(fullkey),szwTipfmt,szwSystemTIPKey,buf);
325 RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
326 RegDeleteTreeW(HKEY_CURRENT_USER, fullkey);
328 return S_OK;
331 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
332 ITfInputProcessorProfiles *iface, REFCLSID rclsid,
333 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
334 ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
335 ULONG uIconIndex)
337 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
338 HKEY tipkey,fmtkey;
339 WCHAR buf[39];
340 WCHAR fullkey[100];
341 ULONG res;
342 DWORD disposition = 0;
344 static const WCHAR fmt2[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
345 static const WCHAR desc[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
346 static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
347 static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
349 TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
350 debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
351 debugstr_wn(pchIconFile,cchFile),uIconIndex);
353 StringFromGUID2(rclsid, buf, 39);
354 swprintf(fullkey,ARRAY_SIZE(fullkey),szwTipfmt,szwSystemTIPKey,buf);
356 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
357 &tipkey ) != ERROR_SUCCESS)
358 return E_FAIL;
360 StringFromGUID2(guidProfile, buf, 39);
361 swprintf(fullkey,ARRAY_SIZE(fullkey),fmt2,szwLngp,langid,buf);
363 res = RegCreateKeyExW(tipkey,fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
364 NULL, &fmtkey, &disposition);
366 if (!res)
368 DWORD zero = 0x0;
369 RegSetValueExW(fmtkey, desc, 0, REG_SZ, (const BYTE*)pchDesc, cchDesc * sizeof(WCHAR));
370 RegSetValueExW(fmtkey, icnf, 0, REG_SZ, (const BYTE*)pchIconFile, cchFile * sizeof(WCHAR));
371 RegSetValueExW(fmtkey, icni, 0, REG_DWORD, (LPBYTE)&uIconIndex, sizeof(DWORD));
372 if (disposition == REG_CREATED_NEW_KEY)
373 RegSetValueExW(fmtkey, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
374 RegCloseKey(fmtkey);
376 add_userkey(rclsid, langid, guidProfile);
378 RegCloseKey(tipkey);
380 if (!res)
381 return S_OK;
382 else
383 return E_FAIL;
386 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
387 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
388 REFGUID guidProfile)
390 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
391 FIXME("STUB:(%p)\n",This);
392 return E_NOTIMPL;
395 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
396 ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
398 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
399 TRACE("(%p) %p\n",This,ppEnum);
400 return ProfilesEnumGuid_Constructor(ppEnum);
403 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
404 ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
405 CLSID *pclsid, GUID *pguidProfile)
407 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
408 WCHAR fullkey[168];
409 WCHAR buf[39];
410 HKEY hkey;
411 DWORD count;
412 ULONG res;
414 TRACE("%p) %x %s %p %p\n",This, langid, debugstr_guid(catid),pclsid,pguidProfile);
416 if (!catid || !pclsid || !pguidProfile)
417 return E_INVALIDARG;
419 StringFromGUID2(catid, buf, 39);
420 swprintf(fullkey, ARRAY_SIZE(fullkey), szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
422 if (RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE,
423 &hkey ) != ERROR_SUCCESS)
424 return S_FALSE;
426 count = sizeof(buf);
427 res = RegQueryValueExW(hkey, szwDefault, 0, NULL, (LPBYTE)buf, &count);
428 if (res != ERROR_SUCCESS)
430 RegCloseKey(hkey);
431 return S_FALSE;
433 CLSIDFromString(buf,pclsid);
435 res = RegQueryValueExW(hkey, szwProfile, 0, NULL, (LPBYTE)buf, &count);
436 if (res == ERROR_SUCCESS)
437 CLSIDFromString(buf,pguidProfile);
439 RegCloseKey(hkey);
441 return S_OK;
444 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
445 ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
446 REFGUID guidProfiles)
448 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
449 WCHAR fullkey[168];
450 WCHAR buf[39];
451 HKEY hkey;
452 GUID catid;
453 HRESULT hr;
454 ITfCategoryMgr *catmgr;
455 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
456 &GUID_TFCAT_TIP_SPEECH,
457 &GUID_TFCAT_TIP_HANDWRITING };
459 TRACE("%p) %x %s %s\n",This, langid, debugstr_guid(rclsid),debugstr_guid(guidProfiles));
461 if (!rclsid || !guidProfiles)
462 return E_INVALIDARG;
464 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&catmgr);
466 if (FAILED(hr))
467 return hr;
469 if (ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
470 &catid, tipcats, 3) != S_OK)
471 hr = ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
472 &catid, NULL, 0);
473 ITfCategoryMgr_Release(catmgr);
475 if (FAILED(hr))
476 return E_FAIL;
478 StringFromGUID2(&catid, buf, 39);
479 swprintf(fullkey, ARRAY_SIZE(fullkey), szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
481 if (RegCreateKeyExW(HKEY_CURRENT_USER, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
482 NULL, &hkey, NULL ) != ERROR_SUCCESS)
483 return E_FAIL;
485 StringFromGUID2(rclsid, buf, 39);
486 RegSetValueExW(hkey, szwDefault, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
487 StringFromGUID2(guidProfiles, buf, 39);
488 RegSetValueExW(hkey, szwProfile, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
489 RegCloseKey(hkey);
491 return S_OK;
494 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
495 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
496 REFGUID guidProfiles)
498 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
499 HRESULT hr;
500 BOOL enabled;
501 TF_LANGUAGEPROFILE LanguageProfile;
503 TRACE("(%p) %s %x %s\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfiles));
505 if (langid != This->currentLanguage) return E_INVALIDARG;
507 if (get_active_textservice(rclsid,NULL))
509 TRACE("Already Active\n");
510 return E_FAIL;
513 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(iface, rclsid,
514 langid, guidProfiles, &enabled);
515 if (FAILED(hr) || !enabled)
517 TRACE("Not Enabled\n");
518 return E_FAIL;
521 LanguageProfile.clsid = *rclsid;
522 LanguageProfile.langid = langid;
523 LanguageProfile.guidProfile = *guidProfiles;
524 LanguageProfile.fActive = TRUE;
526 return add_active_textservice(&LanguageProfile);
529 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
530 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
531 GUID *pguidProfile)
533 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
534 TF_LANGUAGEPROFILE profile;
536 TRACE("(%p) %s %p %p\n",This,debugstr_guid(rclsid),plangid,pguidProfile);
538 if (!rclsid || !plangid || !pguidProfile)
539 return E_INVALIDARG;
541 if (get_active_textservice(rclsid, &profile))
543 *plangid = profile.langid;
544 *pguidProfile = profile.guidProfile;
545 return S_OK;
547 else
549 *pguidProfile = GUID_NULL;
550 return S_FALSE;
554 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
555 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
556 REFGUID guidProfile, BSTR *pbstrProfile)
558 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
559 FIXME("STUB:(%p)\n",This);
560 return E_NOTIMPL;
563 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
564 ITfInputProcessorProfiles *iface, LANGID *plangid)
566 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
567 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
569 if (!plangid)
570 return E_INVALIDARG;
572 *plangid = This->currentLanguage;
574 return S_OK;
577 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
578 ITfInputProcessorProfiles *iface, LANGID langid)
580 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
581 ITfLanguageProfileNotifySink *sink;
582 struct list *cursor;
583 BOOL accept;
585 FIXME("STUB:(%p)\n",This);
587 SINK_FOR_EACH(cursor, &This->LanguageProfileNotifySink, ITfLanguageProfileNotifySink, sink)
589 accept = TRUE;
590 ITfLanguageProfileNotifySink_OnLanguageChange(sink, langid, &accept);
591 if (!accept)
592 return E_FAIL;
595 /* TODO: On successful language change call OnLanguageChanged sink */
596 return E_NOTIMPL;
599 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
600 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
602 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
603 FIXME("Semi-STUB:(%p)\n",This);
604 *ppLangId = CoTaskMemAlloc(sizeof(LANGID));
605 **ppLangId = This->currentLanguage;
606 *pulCount = 1;
607 return S_OK;
610 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
611 ITfInputProcessorProfiles *iface, LANGID langid,
612 IEnumTfLanguageProfiles **ppEnum)
614 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
615 EnumTfLanguageProfiles *profenum;
616 HRESULT hr;
618 TRACE("(%p) %x %p\n",This,langid,ppEnum);
620 if (!ppEnum)
621 return E_INVALIDARG;
622 hr = EnumTfLanguageProfiles_Constructor(langid, &profenum);
623 *ppEnum = &profenum->IEnumTfLanguageProfiles_iface;
625 return hr;
628 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
629 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
630 REFGUID guidProfile, BOOL fEnable)
632 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
633 HKEY key;
634 WCHAR buf[39];
635 WCHAR buf2[39];
636 WCHAR fullkey[168];
637 ULONG res;
639 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
641 StringFromGUID2(rclsid, buf, 39);
642 StringFromGUID2(guidProfile, buf2, 39);
643 swprintf(fullkey,ARRAY_SIZE(fullkey),szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
645 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
647 if (!res)
649 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
650 RegCloseKey(key);
652 else
653 return E_FAIL;
655 return S_OK;
658 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
659 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
660 REFGUID guidProfile, BOOL *pfEnable)
662 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
663 HKEY key;
664 WCHAR buf[39];
665 WCHAR buf2[39];
666 WCHAR fullkey[168];
667 ULONG res;
669 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
671 if (!pfEnable)
672 return E_INVALIDARG;
674 StringFromGUID2(rclsid, buf, 39);
675 StringFromGUID2(guidProfile, buf2, 39);
676 swprintf(fullkey,ARRAY_SIZE(fullkey),szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
678 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
680 if (!res)
682 DWORD count = sizeof(DWORD);
683 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
684 RegCloseKey(key);
687 if (res) /* Try Default */
689 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
691 if (!res)
693 DWORD count = sizeof(DWORD);
694 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
695 RegCloseKey(key);
699 if (!res)
700 return S_OK;
701 else
702 return E_FAIL;
705 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
706 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
707 REFGUID guidProfile, BOOL fEnable)
709 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
710 HKEY key;
711 WCHAR buf[39];
712 WCHAR buf2[39];
713 WCHAR fullkey[168];
714 ULONG res;
716 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
718 StringFromGUID2(rclsid, buf, 39);
719 StringFromGUID2(guidProfile, buf2, 39);
720 swprintf(fullkey,ARRAY_SIZE(fullkey),szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
722 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
724 if (!res)
726 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
727 RegCloseKey(key);
729 else
730 return E_FAIL;
732 return S_OK;
735 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
736 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
737 REFGUID guidProfile, HKL hKL)
739 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
740 FIXME("STUB:(%p)\n",This);
741 return E_NOTIMPL;
744 static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl =
746 InputProcessorProfiles_QueryInterface,
747 InputProcessorProfiles_AddRef,
748 InputProcessorProfiles_Release,
749 InputProcessorProfiles_Register,
750 InputProcessorProfiles_Unregister,
751 InputProcessorProfiles_AddLanguageProfile,
752 InputProcessorProfiles_RemoveLanguageProfile,
753 InputProcessorProfiles_EnumInputProcessorInfo,
754 InputProcessorProfiles_GetDefaultLanguageProfile,
755 InputProcessorProfiles_SetDefaultLanguageProfile,
756 InputProcessorProfiles_ActivateLanguageProfile,
757 InputProcessorProfiles_GetActiveLanguageProfile,
758 InputProcessorProfiles_GetLanguageProfileDescription,
759 InputProcessorProfiles_GetCurrentLanguage,
760 InputProcessorProfiles_ChangeCurrentLanguage,
761 InputProcessorProfiles_GetLanguageList,
762 InputProcessorProfiles_EnumLanguageProfiles,
763 InputProcessorProfiles_EnableLanguageProfile,
764 InputProcessorProfiles_IsEnabledLanguageProfile,
765 InputProcessorProfiles_EnableLanguageProfileByDefault,
766 InputProcessorProfiles_SubstituteKeyboardLayout
769 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfileMgr(ITfInputProcessorProfileMgr *iface)
771 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfileMgr_iface);
774 static HRESULT WINAPI InputProcessorProfileMgr_QueryInterface(ITfInputProcessorProfileMgr *iface, REFIID riid, void **ppv)
776 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
777 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, riid, ppv);
780 static ULONG WINAPI InputProcessorProfileMgr_AddRef(ITfInputProcessorProfileMgr *iface)
782 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
783 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
786 static ULONG WINAPI InputProcessorProfileMgr_Release(ITfInputProcessorProfileMgr *iface)
788 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
789 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
792 static HRESULT WINAPI InputProcessorProfileMgr_ActivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
793 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
795 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
796 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
797 debugstr_guid(guidProfile), hkl, dwFlags);
798 return E_NOTIMPL;
801 static HRESULT WINAPI InputProcessorProfileMgr_DeactivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
802 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
804 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
805 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
806 debugstr_guid(guidProfile), hkl, dwFlags);
807 return E_NOTIMPL;
810 static HRESULT WINAPI InputProcessorProfileMgr_GetProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
811 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, TF_INPUTPROCESSORPROFILE *pProfile)
813 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
814 FIXME("(%p)->(%d %x %s %s %p %p)\n", This, dwProfileType, langid, debugstr_guid(clsid),
815 debugstr_guid(guidProfile), hkl, pProfile);
816 return E_NOTIMPL;
819 static HRESULT WINAPI InputProcessorProfileMgr_EnumProfiles(ITfInputProcessorProfileMgr *iface, LANGID langid,
820 IEnumTfInputProcessorProfiles **ppEnum)
822 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
823 EnumTfInputProcessorProfiles *enum_profiles;
825 TRACE("(%p)->(%x %p)\n", This, langid, ppEnum);
827 enum_profiles = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_profiles));
828 if(!enum_profiles)
829 return E_OUTOFMEMORY;
831 enum_profiles->IEnumTfInputProcessorProfiles_iface.lpVtbl = &EnumTfInputProcessorProfilesVtbl;
832 enum_profiles->ref = 1;
834 *ppEnum = &enum_profiles->IEnumTfInputProcessorProfiles_iface;
835 return S_OK;
838 static HRESULT WINAPI InputProcessorProfileMgr_ReleaseInputProcessor(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
839 DWORD dwFlags)
841 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
842 FIXME("(%p)->(%s %x)\n", This, debugstr_guid(rclsid), dwFlags);
843 return E_NOTIMPL;
846 static HRESULT WINAPI InputProcessorProfileMgr_RegisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
847 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR *pchIconFile,
848 ULONG cchFile, ULONG uIconIndex, HKL hklsubstitute, DWORD dwPreferredLayout, BOOL bEnabledByDefault,
849 DWORD dwFlags)
851 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
852 FIXME("(%p)->(%s %x %s %s %d %s %u %u %p %x %x %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile),
853 debugstr_w(pchDesc), cchDesc, debugstr_w(pchIconFile), cchFile, uIconIndex, hklsubstitute, dwPreferredLayout,
854 bEnabledByDefault, dwFlags);
855 return E_NOTIMPL;
858 static HRESULT WINAPI InputProcessorProfileMgr_UnregisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
859 LANGID langid, REFGUID guidProfile, DWORD dwFlags)
861 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
862 FIXME("(%p)->(%s %x %s %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), dwFlags);
863 return E_NOTIMPL;
866 static HRESULT WINAPI InputProcessorProfileMgr_GetActiveProfile(ITfInputProcessorProfileMgr *iface, REFGUID catid,
867 TF_INPUTPROCESSORPROFILE *pProfile)
869 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
870 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(catid), pProfile);
871 return E_NOTIMPL;
874 static const ITfInputProcessorProfileMgrVtbl InputProcessorProfileMgrVtbl = {
875 InputProcessorProfileMgr_QueryInterface,
876 InputProcessorProfileMgr_AddRef,
877 InputProcessorProfileMgr_Release,
878 InputProcessorProfileMgr_ActivateProfile,
879 InputProcessorProfileMgr_DeactivateProfile,
880 InputProcessorProfileMgr_GetProfile,
881 InputProcessorProfileMgr_EnumProfiles,
882 InputProcessorProfileMgr_ReleaseInputProcessor,
883 InputProcessorProfileMgr_RegisterProfile,
884 InputProcessorProfileMgr_UnregisterProfile,
885 InputProcessorProfileMgr_GetActiveProfile
888 /*****************************************************
889 * ITfSource functions
890 *****************************************************/
891 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
893 InputProcessorProfiles *This = impl_from_ITfSource(iface);
894 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, iid, ppvOut);
897 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
899 InputProcessorProfiles *This = impl_from_ITfSource(iface);
900 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
903 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
905 InputProcessorProfiles *This = impl_from_ITfSource(iface);
906 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
909 static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
910 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
912 InputProcessorProfiles *This = impl_from_ITfSource(iface);
914 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
916 if (!riid || !punk || !pdwCookie)
917 return E_INVALIDARG;
919 if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
920 return advise_sink(&This->LanguageProfileNotifySink, &IID_ITfLanguageProfileNotifySink,
921 COOKIE_MAGIC_IPPSINK, punk, pdwCookie);
923 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
924 return E_NOTIMPL;
927 static HRESULT WINAPI IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
929 InputProcessorProfiles *This = impl_from_ITfSource(iface);
931 TRACE("(%p) %x\n",This,pdwCookie);
933 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
934 return E_INVALIDARG;
936 return unadvise_sink(pdwCookie);
939 static const ITfSourceVtbl InputProcessorProfilesSourceVtbl =
941 IPPSource_QueryInterface,
942 IPPSource_AddRef,
943 IPPSource_Release,
944 IPPSource_AdviseSink,
945 IPPSource_UnadviseSink,
948 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
950 InputProcessorProfiles *This;
951 if (pUnkOuter)
952 return CLASS_E_NOAGGREGATION;
954 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
955 if (This == NULL)
956 return E_OUTOFMEMORY;
958 This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
959 This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
960 This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
961 This->refCount = 1;
962 This->currentLanguage = GetUserDefaultLCID();
964 list_init(&This->LanguageProfileNotifySink);
966 *ppOut = (IUnknown *)&This->ITfInputProcessorProfiles_iface;
967 TRACE("returning %p\n", *ppOut);
968 return S_OK;
971 /**************************************************
972 * IEnumGUID implementation for ITfInputProcessorProfiles::EnumInputProcessorInfo
973 **************************************************/
974 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
976 TRACE("destroying %p\n", This);
977 RegCloseKey(This->key);
978 HeapFree(GetProcessHeap(),0,This);
981 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
983 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
984 *ppvOut = NULL;
986 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
988 *ppvOut = &This->IEnumGUID_iface;
991 if (*ppvOut)
993 IEnumGUID_AddRef(iface);
994 return S_OK;
997 WARN("unsupported interface: %s\n", debugstr_guid(iid));
998 return E_NOINTERFACE;
1001 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
1003 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1004 return InterlockedIncrement(&This->refCount);
1007 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
1009 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1010 ULONG ret;
1012 ret = InterlockedDecrement(&This->refCount);
1013 if (ret == 0)
1014 ProfilesEnumGuid_Destructor(This);
1015 return ret;
1018 /*****************************************************
1019 * IEnumGuid functions
1020 *****************************************************/
1021 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
1022 ULONG celt, GUID *rgelt, ULONG *pceltFetched)
1024 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1025 ULONG fetched = 0;
1027 TRACE("(%p)\n",This);
1029 if (rgelt == NULL) return E_POINTER;
1031 if (This->key) while (fetched < celt)
1033 LSTATUS res;
1034 HRESULT hr;
1035 WCHAR catid[39];
1036 DWORD cName = 39;
1038 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1039 NULL, NULL, NULL, NULL);
1040 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1041 ++(This->next_index);
1043 hr = CLSIDFromString(catid, rgelt);
1044 if (FAILED(hr)) continue;
1046 ++fetched;
1047 ++rgelt;
1050 if (pceltFetched) *pceltFetched = fetched;
1051 return fetched == celt ? S_OK : S_FALSE;
1054 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
1056 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1057 TRACE("(%p)\n",This);
1059 This->next_index += celt;
1060 return S_OK;
1063 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
1065 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1066 TRACE("(%p)\n",This);
1067 This->next_index = 0;
1068 return S_OK;
1071 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
1072 IEnumGUID **ppenum)
1074 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1075 HRESULT res;
1077 TRACE("(%p)\n",This);
1079 if (ppenum == NULL) return E_POINTER;
1081 res = ProfilesEnumGuid_Constructor(ppenum);
1082 if (SUCCEEDED(res))
1084 ProfilesEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
1085 new_This->next_index = This->next_index;
1087 return res;
1090 static const IEnumGUIDVtbl EnumGUIDVtbl =
1092 ProfilesEnumGuid_QueryInterface,
1093 ProfilesEnumGuid_AddRef,
1094 ProfilesEnumGuid_Release,
1095 ProfilesEnumGuid_Next,
1096 ProfilesEnumGuid_Skip,
1097 ProfilesEnumGuid_Reset,
1098 ProfilesEnumGuid_Clone
1101 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
1103 ProfilesEnumGuid *This;
1105 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ProfilesEnumGuid));
1106 if (This == NULL)
1107 return E_OUTOFMEMORY;
1109 This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
1110 This->refCount = 1;
1112 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1113 KEY_READ | KEY_WRITE, NULL, &This->key, NULL) != ERROR_SUCCESS)
1115 HeapFree(GetProcessHeap(), 0, This);
1116 return E_FAIL;
1119 *ppOut = &This->IEnumGUID_iface;
1120 TRACE("returning %p\n", *ppOut);
1121 return S_OK;
1124 /**************************************************
1125 * IEnumTfLanguageProfiles implementation
1126 **************************************************/
1127 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
1129 TRACE("destroying %p\n", This);
1130 RegCloseKey(This->tipkey);
1131 if (This->langkey)
1132 RegCloseKey(This->langkey);
1133 ITfCategoryMgr_Release(This->catmgr);
1134 HeapFree(GetProcessHeap(),0,This);
1137 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
1139 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1141 *ppvOut = NULL;
1143 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
1145 *ppvOut = &This->IEnumTfLanguageProfiles_iface;
1148 if (*ppvOut)
1150 IEnumTfLanguageProfiles_AddRef(iface);
1151 return S_OK;
1154 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1155 return E_NOINTERFACE;
1158 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
1160 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1161 return InterlockedIncrement(&This->refCount);
1164 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
1166 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1167 ULONG ret;
1169 ret = InterlockedDecrement(&This->refCount);
1170 if (ret == 0)
1171 EnumTfLanguageProfiles_Destructor(This);
1172 return ret;
1175 /*****************************************************
1176 * IEnumGuid functions
1177 *****************************************************/
1178 static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LANGUAGEPROFILE *tflp)
1180 WCHAR fullkey[168];
1181 ULONG res;
1182 WCHAR profileid[39];
1183 DWORD cName = 39;
1184 GUID profile;
1186 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1188 if (This->langkey == NULL)
1190 swprintf(fullkey,ARRAY_SIZE(fullkey),fmt,This->szwCurrentClsid,szwLngp,This->langid);
1191 res = RegOpenKeyExW(This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1192 if (res)
1194 This->langkey = NULL;
1195 return -1;
1197 This->lang_index = 0;
1199 res = RegEnumKeyExW(This->langkey, This->lang_index, profileid, &cName,
1200 NULL, NULL, NULL, NULL);
1201 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1203 RegCloseKey(This->langkey);
1204 This->langkey = NULL;
1205 return -1;
1207 ++(This->lang_index);
1209 if (tflp)
1211 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
1212 &GUID_TFCAT_TIP_SPEECH,
1213 &GUID_TFCAT_TIP_HANDWRITING };
1214 res = CLSIDFromString(profileid, &profile);
1215 if (FAILED(res)) return 0;
1217 tflp->clsid = clsid;
1218 tflp->langid = This->langid;
1219 tflp->fActive = get_active_textservice(&clsid, NULL);
1220 tflp->guidProfile = profile;
1221 if (ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1222 &tflp->catid, tipcats, 3) != S_OK)
1223 ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1224 &tflp->catid, NULL, 0);
1227 return 1;
1230 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
1231 ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
1233 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1234 ULONG fetched = 0;
1236 TRACE("(%p)\n",This);
1238 if (pProfile == NULL) return E_POINTER;
1240 if (This->tipkey) while (fetched < ulCount)
1242 LSTATUS res;
1243 HRESULT hr;
1244 DWORD cName = 39;
1245 GUID clsid;
1247 res = RegEnumKeyExW(This->tipkey, This->tip_index,
1248 This->szwCurrentClsid, &cName, NULL, NULL, NULL, NULL);
1249 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1250 ++(This->tip_index);
1251 hr = CLSIDFromString(This->szwCurrentClsid, &clsid);
1252 if (FAILED(hr)) continue;
1254 while ( fetched < ulCount)
1256 INT res = next_LanguageProfile(This, clsid, pProfile);
1257 if (res == 1)
1259 ++fetched;
1260 ++pProfile;
1262 else if (res == -1)
1263 break;
1264 else
1265 continue;
1269 if (pcFetch) *pcFetch = fetched;
1270 return fetched == ulCount ? S_OK : S_FALSE;
1273 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
1275 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1276 FIXME("STUB (%p)\n",This);
1277 return E_NOTIMPL;
1280 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
1282 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1283 TRACE("(%p)\n",This);
1284 This->tip_index = 0;
1285 if (This->langkey)
1286 RegCloseKey(This->langkey);
1287 This->langkey = NULL;
1288 This->lang_index = 0;
1289 return S_OK;
1292 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
1293 IEnumTfLanguageProfiles **ppenum)
1295 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1296 EnumTfLanguageProfiles *new_This;
1297 HRESULT res;
1299 TRACE("(%p)\n",This);
1301 if (ppenum == NULL) return E_POINTER;
1303 res = EnumTfLanguageProfiles_Constructor(This->langid, &new_This);
1304 if (SUCCEEDED(res))
1306 new_This->tip_index = This->tip_index;
1307 lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
1309 if (This->langkey)
1311 WCHAR fullkey[168];
1312 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1314 swprintf(fullkey,ARRAY_SIZE(fullkey),fmt,This->szwCurrentClsid,szwLngp,This->langid);
1315 res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1316 new_This->lang_index = This->lang_index;
1318 *ppenum = &new_This->IEnumTfLanguageProfiles_iface;
1320 return res;
1323 static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
1325 EnumTfLanguageProfiles_QueryInterface,
1326 EnumTfLanguageProfiles_AddRef,
1327 EnumTfLanguageProfiles_Release,
1328 EnumTfLanguageProfiles_Clone,
1329 EnumTfLanguageProfiles_Next,
1330 EnumTfLanguageProfiles_Reset,
1331 EnumTfLanguageProfiles_Skip
1334 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out)
1336 HRESULT hr;
1337 EnumTfLanguageProfiles *This;
1339 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfLanguageProfiles));
1340 if (This == NULL)
1341 return E_OUTOFMEMORY;
1343 This->IEnumTfLanguageProfiles_iface.lpVtbl= &EnumTfLanguageProfilesVtbl;
1344 This->refCount = 1;
1345 This->langid = langid;
1347 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&This->catmgr);
1348 if (FAILED(hr))
1350 HeapFree(GetProcessHeap(),0,This);
1351 return hr;
1354 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1355 KEY_READ | KEY_WRITE, NULL, &This->tipkey, NULL) != ERROR_SUCCESS)
1357 HeapFree(GetProcessHeap(), 0, This);
1358 return E_FAIL;
1361 *out = This;
1362 TRACE("returning %p\n", *out);
1363 return S_OK;