msctf: Don't crash on NULL input in EnumLanguageProfiles().
[wine.git] / dlls / msctf / inputprocessor.c
blobfca78e446df7b416aaf551f095e7184ca046b46c
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 "config.h"
23 #include <stdarg.h>
25 #define COBJMACROS
27 #include "wine/debug.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winuser.h"
32 #include "shlwapi.h"
33 #include "winerror.h"
34 #include "objbase.h"
35 #include "olectl.h"
37 #include "wine/unicode.h"
39 #include "msctf.h"
40 #include "msctf_internal.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
44 static const WCHAR szwLngp[] = {'L','a','n','g','u','a','g','e','P','r','o','f','i','l','e',0};
45 static const WCHAR szwEnable[] = {'E','n','a','b','l','e',0};
46 static const WCHAR szwTipfmt[] = {'%','s','\\','%','s',0};
47 static const WCHAR szwFullLangfmt[] = {'%','s','\\','%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
49 static const WCHAR szwAssemblies[] = {'A','s','s','e','m','b','l','i','e','s',0};
50 static const WCHAR szwDefault[] = {'D','e','f','a','u','l','t',0};
51 static const WCHAR szwProfile[] = {'P','r','o','f','i','l','e',0};
52 static const WCHAR szwDefaultFmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
54 typedef struct tagInputProcessorProfiles {
55 ITfInputProcessorProfiles ITfInputProcessorProfiles_iface;
56 ITfSource ITfSource_iface;
57 ITfInputProcessorProfileMgr ITfInputProcessorProfileMgr_iface;
58 /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
59 /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
60 LONG refCount;
62 LANGID currentLanguage;
64 struct list LanguageProfileNotifySink;
65 } InputProcessorProfiles;
67 typedef struct tagProfilesEnumGuid {
68 IEnumGUID IEnumGUID_iface;
69 LONG refCount;
71 HKEY key;
72 DWORD next_index;
73 } ProfilesEnumGuid;
75 typedef struct tagEnumTfLanguageProfiles {
76 IEnumTfLanguageProfiles IEnumTfLanguageProfiles_iface;
77 LONG refCount;
79 HKEY tipkey;
80 DWORD tip_index;
81 WCHAR szwCurrentClsid[39];
83 HKEY langkey;
84 DWORD lang_index;
86 LANGID langid;
87 ITfCategoryMgr *catmgr;
88 } EnumTfLanguageProfiles;
90 typedef struct {
91 IEnumTfInputProcessorProfiles IEnumTfInputProcessorProfiles_iface;
92 LONG ref;
93 } EnumTfInputProcessorProfiles;
95 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut);
96 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut);
98 static inline EnumTfInputProcessorProfiles *impl_from_IEnumTfInputProcessorProfiles(IEnumTfInputProcessorProfiles *iface)
100 return CONTAINING_RECORD(iface, EnumTfInputProcessorProfiles, IEnumTfInputProcessorProfiles_iface);
103 static HRESULT WINAPI EnumTfInputProcessorProfiles_QueryInterface(IEnumTfInputProcessorProfiles *iface,
104 REFIID riid, void **ppv)
106 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
108 if(IsEqualGUID(riid, &IID_IUnknown)) {
109 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
110 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
111 }else if(IsEqualGUID(riid, &IID_IEnumTfInputProcessorProfiles)) {
112 TRACE("(%p)->(IID_IEnumTfInputProcessorProfiles %p)\n", This, ppv);
113 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
114 }else {
115 *ppv = NULL;
116 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
117 return E_NOINTERFACE;
120 IUnknown_AddRef((IUnknown*)*ppv);
121 return S_OK;
124 static ULONG WINAPI EnumTfInputProcessorProfiles_AddRef(IEnumTfInputProcessorProfiles *iface)
126 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
127 LONG ref = InterlockedIncrement(&This->ref);
129 TRACE("(%p) ref=%d\n", This, ref);
131 return ref;
134 static ULONG WINAPI EnumTfInputProcessorProfiles_Release(IEnumTfInputProcessorProfiles *iface)
136 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
137 LONG ref = InterlockedDecrement(&This->ref);
139 TRACE("(%p) ref=%d\n", This, ref);
141 if(!ref)
142 HeapFree(GetProcessHeap(), 0, This);
144 return ref;
147 static HRESULT WINAPI EnumTfInputProcessorProfiles_Clone(IEnumTfInputProcessorProfiles *iface,
148 IEnumTfInputProcessorProfiles **ret)
150 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
151 FIXME("(%p)->(%p)\n", This, ret);
152 return E_NOTIMPL;
155 static HRESULT WINAPI EnumTfInputProcessorProfiles_Next(IEnumTfInputProcessorProfiles *iface, ULONG count,
156 TF_INPUTPROCESSORPROFILE *profile, ULONG *fetch)
158 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
160 FIXME("(%p)->(%u %p %p)\n", This, count, profile, fetch);
162 if(fetch)
163 *fetch = 0;
164 return S_FALSE;
167 static HRESULT WINAPI EnumTfInputProcessorProfiles_Reset(IEnumTfInputProcessorProfiles *iface)
169 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
170 FIXME("(%p)\n", This);
171 return E_NOTIMPL;
174 static HRESULT WINAPI EnumTfInputProcessorProfiles_Skip(IEnumTfInputProcessorProfiles *iface, ULONG count)
176 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
177 FIXME("(%p)->(%u)\n", This, count);
178 return E_NOTIMPL;
181 static const IEnumTfInputProcessorProfilesVtbl EnumTfInputProcessorProfilesVtbl = {
182 EnumTfInputProcessorProfiles_QueryInterface,
183 EnumTfInputProcessorProfiles_AddRef,
184 EnumTfInputProcessorProfiles_Release,
185 EnumTfInputProcessorProfiles_Clone,
186 EnumTfInputProcessorProfiles_Next,
187 EnumTfInputProcessorProfiles_Reset,
188 EnumTfInputProcessorProfiles_Skip
191 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfiles(ITfInputProcessorProfiles *iface)
193 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfiles_iface);
196 static inline InputProcessorProfiles *impl_from_ITfSource(ITfSource *iface)
198 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfSource_iface);
201 static inline ProfilesEnumGuid *impl_from_IEnumGUID(IEnumGUID *iface)
203 return CONTAINING_RECORD(iface, ProfilesEnumGuid, IEnumGUID_iface);
206 static inline EnumTfLanguageProfiles *impl_from_IEnumTfLanguageProfiles(IEnumTfLanguageProfiles *iface)
208 return CONTAINING_RECORD(iface, EnumTfLanguageProfiles, IEnumTfLanguageProfiles_iface);
211 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
213 TRACE("destroying %p\n", This);
215 free_sinks(&This->LanguageProfileNotifySink);
216 HeapFree(GetProcessHeap(),0,This);
219 static void add_userkey( REFCLSID rclsid, LANGID langid,
220 REFGUID guidProfile)
222 HKEY key;
223 WCHAR buf[39];
224 WCHAR buf2[39];
225 WCHAR fullkey[168];
226 DWORD disposition = 0;
227 ULONG res;
229 TRACE("\n");
231 StringFromGUID2(rclsid, buf, 39);
232 StringFromGUID2(guidProfile, buf2, 39);
233 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
235 res = RegCreateKeyExW(HKEY_CURRENT_USER,fullkey, 0, NULL, 0,
236 KEY_READ | KEY_WRITE, NULL, &key, &disposition);
238 if (!res && disposition == REG_CREATED_NEW_KEY)
240 DWORD zero = 0x0;
241 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
244 if (!res)
245 RegCloseKey(key);
248 static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, void **ppv)
250 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
252 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
254 *ppv = &This->ITfInputProcessorProfiles_iface;
256 else if (IsEqualIID(iid, &IID_ITfInputProcessorProfileMgr))
258 *ppv = &This->ITfInputProcessorProfileMgr_iface;
260 else if (IsEqualIID(iid, &IID_ITfSource))
262 *ppv = &This->ITfSource_iface;
264 else
266 *ppv = NULL;
267 WARN("unsupported interface: %s\n", debugstr_guid(iid));
268 return E_NOINTERFACE;
271 ITfInputProcessorProfiles_AddRef(iface);
272 return S_OK;
275 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
277 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
278 return InterlockedIncrement(&This->refCount);
281 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
283 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
284 ULONG ret;
286 ret = InterlockedDecrement(&This->refCount);
287 if (ret == 0)
288 InputProcessorProfiles_Destructor(This);
289 return ret;
292 /*****************************************************
293 * ITfInputProcessorProfiles functions
294 *****************************************************/
295 static HRESULT WINAPI InputProcessorProfiles_Register(
296 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
298 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
299 HKEY tipkey;
300 WCHAR buf[39];
301 WCHAR fullkey[68];
303 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
305 StringFromGUID2(rclsid, buf, 39);
306 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
308 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, NULL, 0,
309 KEY_READ | KEY_WRITE, NULL, &tipkey, NULL) != ERROR_SUCCESS)
310 return E_FAIL;
312 RegCloseKey(tipkey);
314 return S_OK;
317 static HRESULT WINAPI InputProcessorProfiles_Unregister(
318 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
320 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
321 WCHAR buf[39];
322 WCHAR fullkey[68];
324 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
326 StringFromGUID2(rclsid, buf, 39);
327 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
329 RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
330 RegDeleteTreeW(HKEY_CURRENT_USER, fullkey);
332 return S_OK;
335 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
336 ITfInputProcessorProfiles *iface, REFCLSID rclsid,
337 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
338 ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
339 ULONG uIconIndex)
341 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
342 HKEY tipkey,fmtkey;
343 WCHAR buf[39];
344 WCHAR fullkey[100];
345 ULONG res;
346 DWORD disposition = 0;
348 static const WCHAR fmt2[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
349 static const WCHAR desc[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
350 static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
351 static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
353 TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
354 debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
355 debugstr_wn(pchIconFile,cchFile),uIconIndex);
357 StringFromGUID2(rclsid, buf, 39);
358 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
360 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
361 &tipkey ) != ERROR_SUCCESS)
362 return E_FAIL;
364 StringFromGUID2(guidProfile, buf, 39);
365 sprintfW(fullkey,fmt2,szwLngp,langid,buf);
367 res = RegCreateKeyExW(tipkey,fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
368 NULL, &fmtkey, &disposition);
370 if (!res)
372 DWORD zero = 0x0;
373 RegSetValueExW(fmtkey, desc, 0, REG_SZ, (const BYTE*)pchDesc, cchDesc * sizeof(WCHAR));
374 RegSetValueExW(fmtkey, icnf, 0, REG_SZ, (const BYTE*)pchIconFile, cchFile * sizeof(WCHAR));
375 RegSetValueExW(fmtkey, icni, 0, REG_DWORD, (LPBYTE)&uIconIndex, sizeof(DWORD));
376 if (disposition == REG_CREATED_NEW_KEY)
377 RegSetValueExW(fmtkey, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
378 RegCloseKey(fmtkey);
380 add_userkey(rclsid, langid, guidProfile);
382 RegCloseKey(tipkey);
384 if (!res)
385 return S_OK;
386 else
387 return E_FAIL;
390 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
391 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
392 REFGUID guidProfile)
394 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
395 FIXME("STUB:(%p)\n",This);
396 return E_NOTIMPL;
399 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
400 ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
402 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
403 TRACE("(%p) %p\n",This,ppEnum);
404 return ProfilesEnumGuid_Constructor(ppEnum);
407 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
408 ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
409 CLSID *pclsid, GUID *pguidProfile)
411 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
412 WCHAR fullkey[168];
413 WCHAR buf[39];
414 HKEY hkey;
415 DWORD count;
416 ULONG res;
418 TRACE("%p) %x %s %p %p\n",This, langid, debugstr_guid(catid),pclsid,pguidProfile);
420 if (!catid || !pclsid || !pguidProfile)
421 return E_INVALIDARG;
423 StringFromGUID2(catid, buf, 39);
424 sprintfW(fullkey, szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
426 if (RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE,
427 &hkey ) != ERROR_SUCCESS)
428 return S_FALSE;
430 count = sizeof(buf);
431 res = RegQueryValueExW(hkey, szwDefault, 0, NULL, (LPBYTE)buf, &count);
432 if (res != ERROR_SUCCESS)
434 RegCloseKey(hkey);
435 return S_FALSE;
437 CLSIDFromString(buf,pclsid);
439 res = RegQueryValueExW(hkey, szwProfile, 0, NULL, (LPBYTE)buf, &count);
440 if (res == ERROR_SUCCESS)
441 CLSIDFromString(buf,pguidProfile);
443 RegCloseKey(hkey);
445 return S_OK;
448 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
449 ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
450 REFGUID guidProfiles)
452 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
453 WCHAR fullkey[168];
454 WCHAR buf[39];
455 HKEY hkey;
456 GUID catid;
457 HRESULT hr;
458 ITfCategoryMgr *catmgr;
459 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
460 &GUID_TFCAT_TIP_SPEECH,
461 &GUID_TFCAT_TIP_HANDWRITING };
463 TRACE("%p) %x %s %s\n",This, langid, debugstr_guid(rclsid),debugstr_guid(guidProfiles));
465 if (!rclsid || !guidProfiles)
466 return E_INVALIDARG;
468 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&catmgr);
470 if (FAILED(hr))
471 return hr;
473 if (ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
474 &catid, tipcats, 3) != S_OK)
475 hr = ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
476 &catid, NULL, 0);
477 ITfCategoryMgr_Release(catmgr);
479 if (FAILED(hr))
480 return E_FAIL;
482 StringFromGUID2(&catid, buf, 39);
483 sprintfW(fullkey, szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
485 if (RegCreateKeyExW(HKEY_CURRENT_USER, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
486 NULL, &hkey, NULL ) != ERROR_SUCCESS)
487 return E_FAIL;
489 StringFromGUID2(rclsid, buf, 39);
490 RegSetValueExW(hkey, szwDefault, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
491 StringFromGUID2(guidProfiles, buf, 39);
492 RegSetValueExW(hkey, szwProfile, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
493 RegCloseKey(hkey);
495 return S_OK;
498 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
499 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
500 REFGUID guidProfiles)
502 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
503 HRESULT hr;
504 BOOL enabled;
505 TF_LANGUAGEPROFILE LanguageProfile;
507 TRACE("(%p) %s %x %s\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfiles));
509 if (langid != This->currentLanguage) return E_INVALIDARG;
511 if (get_active_textservice(rclsid,NULL))
513 TRACE("Already Active\n");
514 return E_FAIL;
517 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(iface, rclsid,
518 langid, guidProfiles, &enabled);
519 if (FAILED(hr) || !enabled)
521 TRACE("Not Enabled\n");
522 return E_FAIL;
525 LanguageProfile.clsid = *rclsid;
526 LanguageProfile.langid = langid;
527 LanguageProfile.guidProfile = *guidProfiles;
528 LanguageProfile.fActive = TRUE;
530 return add_active_textservice(&LanguageProfile);
533 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
534 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
535 GUID *pguidProfile)
537 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
538 TF_LANGUAGEPROFILE profile;
540 TRACE("(%p) %s %p %p\n",This,debugstr_guid(rclsid),plangid,pguidProfile);
542 if (!rclsid || !plangid || !pguidProfile)
543 return E_INVALIDARG;
545 if (get_active_textservice(rclsid, &profile))
547 *plangid = profile.langid;
548 *pguidProfile = profile.guidProfile;
549 return S_OK;
551 else
553 *pguidProfile = GUID_NULL;
554 return S_FALSE;
558 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
559 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
560 REFGUID guidProfile, BSTR *pbstrProfile)
562 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
563 FIXME("STUB:(%p)\n",This);
564 return E_NOTIMPL;
567 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
568 ITfInputProcessorProfiles *iface, LANGID *plangid)
570 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
571 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
573 if (!plangid)
574 return E_INVALIDARG;
576 *plangid = This->currentLanguage;
578 return S_OK;
581 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
582 ITfInputProcessorProfiles *iface, LANGID langid)
584 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
585 ITfLanguageProfileNotifySink *sink;
586 struct list *cursor;
587 BOOL accept;
589 FIXME("STUB:(%p)\n",This);
591 SINK_FOR_EACH(cursor, &This->LanguageProfileNotifySink, ITfLanguageProfileNotifySink, sink)
593 accept = TRUE;
594 ITfLanguageProfileNotifySink_OnLanguageChange(sink, langid, &accept);
595 if (!accept)
596 return E_FAIL;
599 /* TODO: On successful language change call OnLanguageChanged sink */
600 return E_NOTIMPL;
603 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
604 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
606 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
607 FIXME("Semi-STUB:(%p)\n",This);
608 *ppLangId = CoTaskMemAlloc(sizeof(LANGID));
609 **ppLangId = This->currentLanguage;
610 *pulCount = 1;
611 return S_OK;
614 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
615 ITfInputProcessorProfiles *iface, LANGID langid,
616 IEnumTfLanguageProfiles **ppEnum)
618 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
619 TRACE("(%p) %x %p\n",This,langid,ppEnum);
621 if (!ppEnum)
622 return E_INVALIDARG;
624 return EnumTfLanguageProfiles_Constructor(langid, ppEnum);
627 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
628 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
629 REFGUID guidProfile, BOOL fEnable)
631 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
632 HKEY key;
633 WCHAR buf[39];
634 WCHAR buf2[39];
635 WCHAR fullkey[168];
636 ULONG res;
638 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
640 StringFromGUID2(rclsid, buf, 39);
641 StringFromGUID2(guidProfile, buf2, 39);
642 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
644 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
646 if (!res)
648 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
649 RegCloseKey(key);
651 else
652 return E_FAIL;
654 return S_OK;
657 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
658 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
659 REFGUID guidProfile, BOOL *pfEnable)
661 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
662 HKEY key;
663 WCHAR buf[39];
664 WCHAR buf2[39];
665 WCHAR fullkey[168];
666 ULONG res;
668 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
670 if (!pfEnable)
671 return E_INVALIDARG;
673 StringFromGUID2(rclsid, buf, 39);
674 StringFromGUID2(guidProfile, buf2, 39);
675 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
677 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
679 if (!res)
681 DWORD count = sizeof(DWORD);
682 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
683 RegCloseKey(key);
686 if (res) /* Try Default */
688 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
690 if (!res)
692 DWORD count = sizeof(DWORD);
693 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
694 RegCloseKey(key);
698 if (!res)
699 return S_OK;
700 else
701 return E_FAIL;
704 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
705 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
706 REFGUID guidProfile, BOOL fEnable)
708 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
709 HKEY key;
710 WCHAR buf[39];
711 WCHAR buf2[39];
712 WCHAR fullkey[168];
713 ULONG res;
715 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
717 StringFromGUID2(rclsid, buf, 39);
718 StringFromGUID2(guidProfile, buf2, 39);
719 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
721 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
723 if (!res)
725 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
726 RegCloseKey(key);
728 else
729 return E_FAIL;
731 return S_OK;
734 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
735 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
736 REFGUID guidProfile, HKL hKL)
738 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
739 FIXME("STUB:(%p)\n",This);
740 return E_NOTIMPL;
743 static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl =
745 InputProcessorProfiles_QueryInterface,
746 InputProcessorProfiles_AddRef,
747 InputProcessorProfiles_Release,
748 InputProcessorProfiles_Register,
749 InputProcessorProfiles_Unregister,
750 InputProcessorProfiles_AddLanguageProfile,
751 InputProcessorProfiles_RemoveLanguageProfile,
752 InputProcessorProfiles_EnumInputProcessorInfo,
753 InputProcessorProfiles_GetDefaultLanguageProfile,
754 InputProcessorProfiles_SetDefaultLanguageProfile,
755 InputProcessorProfiles_ActivateLanguageProfile,
756 InputProcessorProfiles_GetActiveLanguageProfile,
757 InputProcessorProfiles_GetLanguageProfileDescription,
758 InputProcessorProfiles_GetCurrentLanguage,
759 InputProcessorProfiles_ChangeCurrentLanguage,
760 InputProcessorProfiles_GetLanguageList,
761 InputProcessorProfiles_EnumLanguageProfiles,
762 InputProcessorProfiles_EnableLanguageProfile,
763 InputProcessorProfiles_IsEnabledLanguageProfile,
764 InputProcessorProfiles_EnableLanguageProfileByDefault,
765 InputProcessorProfiles_SubstituteKeyboardLayout
768 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfileMgr(ITfInputProcessorProfileMgr *iface)
770 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfileMgr_iface);
773 static HRESULT WINAPI InputProcessorProfileMgr_QueryInterface(ITfInputProcessorProfileMgr *iface, REFIID riid, void **ppv)
775 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
776 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, riid, ppv);
779 static ULONG WINAPI InputProcessorProfileMgr_AddRef(ITfInputProcessorProfileMgr *iface)
781 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
782 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
785 static ULONG WINAPI InputProcessorProfileMgr_Release(ITfInputProcessorProfileMgr *iface)
787 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
788 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
791 static HRESULT WINAPI InputProcessorProfileMgr_ActivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
792 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
794 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
795 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
796 debugstr_guid(guidProfile), hkl, dwFlags);
797 return E_NOTIMPL;
800 static HRESULT WINAPI InputProcessorProfileMgr_DeactivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
801 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
803 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
804 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
805 debugstr_guid(guidProfile), hkl, dwFlags);
806 return E_NOTIMPL;
809 static HRESULT WINAPI InputProcessorProfileMgr_GetProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
810 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, TF_INPUTPROCESSORPROFILE *pProfile)
812 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
813 FIXME("(%p)->(%d %x %s %s %p %p)\n", This, dwProfileType, langid, debugstr_guid(clsid),
814 debugstr_guid(guidProfile), hkl, pProfile);
815 return E_NOTIMPL;
818 static HRESULT WINAPI InputProcessorProfileMgr_EnumProfiles(ITfInputProcessorProfileMgr *iface, LANGID langid,
819 IEnumTfInputProcessorProfiles **ppEnum)
821 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
822 EnumTfInputProcessorProfiles *enum_profiles;
824 TRACE("(%p)->(%x %p)\n", This, langid, ppEnum);
826 enum_profiles = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_profiles));
827 if(!enum_profiles)
828 return E_OUTOFMEMORY;
830 enum_profiles->IEnumTfInputProcessorProfiles_iface.lpVtbl = &EnumTfInputProcessorProfilesVtbl;
831 enum_profiles->ref = 1;
833 *ppEnum = &enum_profiles->IEnumTfInputProcessorProfiles_iface;
834 return S_OK;
837 static HRESULT WINAPI InputProcessorProfileMgr_ReleaseInputProcessor(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
838 DWORD dwFlags)
840 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
841 FIXME("(%p)->(%s %x)\n", This, debugstr_guid(rclsid), dwFlags);
842 return E_NOTIMPL;
845 static HRESULT WINAPI InputProcessorProfileMgr_RegisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
846 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR *pchIconFile,
847 ULONG cchFile, ULONG uIconIndex, HKL hklsubstitute, DWORD dwPreferredLayout, BOOL bEnabledByDefault,
848 DWORD dwFlags)
850 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
851 FIXME("(%p)->(%s %x %s %s %d %s %u %u %p %x %x %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile),
852 debugstr_w(pchDesc), cchDesc, debugstr_w(pchIconFile), cchFile, uIconIndex, hklsubstitute, dwPreferredLayout,
853 bEnabledByDefault, dwFlags);
854 return E_NOTIMPL;
857 static HRESULT WINAPI InputProcessorProfileMgr_UnregisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
858 LANGID langid, REFGUID guidProfile, DWORD dwFlags)
860 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
861 FIXME("(%p)->(%s %x %s %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), dwFlags);
862 return E_NOTIMPL;
865 static HRESULT WINAPI InputProcessorProfileMgr_GetActiveProfile(ITfInputProcessorProfileMgr *iface, REFGUID catid,
866 TF_INPUTPROCESSORPROFILE *pProfile)
868 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
869 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(catid), pProfile);
870 return E_NOTIMPL;
873 static const ITfInputProcessorProfileMgrVtbl InputProcessorProfileMgrVtbl = {
874 InputProcessorProfileMgr_QueryInterface,
875 InputProcessorProfileMgr_AddRef,
876 InputProcessorProfileMgr_Release,
877 InputProcessorProfileMgr_ActivateProfile,
878 InputProcessorProfileMgr_DeactivateProfile,
879 InputProcessorProfileMgr_GetProfile,
880 InputProcessorProfileMgr_EnumProfiles,
881 InputProcessorProfileMgr_ReleaseInputProcessor,
882 InputProcessorProfileMgr_RegisterProfile,
883 InputProcessorProfileMgr_UnregisterProfile,
884 InputProcessorProfileMgr_GetActiveProfile
887 /*****************************************************
888 * ITfSource functions
889 *****************************************************/
890 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
892 InputProcessorProfiles *This = impl_from_ITfSource(iface);
893 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, iid, ppvOut);
896 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
898 InputProcessorProfiles *This = impl_from_ITfSource(iface);
899 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
902 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
904 InputProcessorProfiles *This = impl_from_ITfSource(iface);
905 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
908 static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
909 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
911 InputProcessorProfiles *This = impl_from_ITfSource(iface);
913 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
915 if (!riid || !punk || !pdwCookie)
916 return E_INVALIDARG;
918 if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
919 return advise_sink(&This->LanguageProfileNotifySink, &IID_ITfLanguageProfileNotifySink,
920 COOKIE_MAGIC_IPPSINK, punk, pdwCookie);
922 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
923 return E_NOTIMPL;
926 static HRESULT WINAPI IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
928 InputProcessorProfiles *This = impl_from_ITfSource(iface);
930 TRACE("(%p) %x\n",This,pdwCookie);
932 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
933 return E_INVALIDARG;
935 return unadvise_sink(pdwCookie);
938 static const ITfSourceVtbl InputProcessorProfilesSourceVtbl =
940 IPPSource_QueryInterface,
941 IPPSource_AddRef,
942 IPPSource_Release,
943 IPPSource_AdviseSink,
944 IPPSource_UnadviseSink,
947 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
949 InputProcessorProfiles *This;
950 if (pUnkOuter)
951 return CLASS_E_NOAGGREGATION;
953 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
954 if (This == NULL)
955 return E_OUTOFMEMORY;
957 This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
958 This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
959 This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
960 This->refCount = 1;
961 This->currentLanguage = GetUserDefaultLCID();
963 list_init(&This->LanguageProfileNotifySink);
965 *ppOut = (IUnknown *)&This->ITfInputProcessorProfiles_iface;
966 TRACE("returning %p\n", *ppOut);
967 return S_OK;
970 /**************************************************
971 * IEnumGUID implementation for ITfInputProcessorProfiles::EnumInputProcessorInfo
972 **************************************************/
973 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
975 TRACE("destroying %p\n", This);
976 RegCloseKey(This->key);
977 HeapFree(GetProcessHeap(),0,This);
980 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
982 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
983 *ppvOut = NULL;
985 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
987 *ppvOut = &This->IEnumGUID_iface;
990 if (*ppvOut)
992 IEnumGUID_AddRef(iface);
993 return S_OK;
996 WARN("unsupported interface: %s\n", debugstr_guid(iid));
997 return E_NOINTERFACE;
1000 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
1002 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1003 return InterlockedIncrement(&This->refCount);
1006 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
1008 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1009 ULONG ret;
1011 ret = InterlockedDecrement(&This->refCount);
1012 if (ret == 0)
1013 ProfilesEnumGuid_Destructor(This);
1014 return ret;
1017 /*****************************************************
1018 * IEnumGuid functions
1019 *****************************************************/
1020 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
1021 ULONG celt, GUID *rgelt, ULONG *pceltFetched)
1023 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1024 ULONG fetched = 0;
1026 TRACE("(%p)\n",This);
1028 if (rgelt == NULL) return E_POINTER;
1030 if (This->key) while (fetched < celt)
1032 LSTATUS res;
1033 HRESULT hr;
1034 WCHAR catid[39];
1035 DWORD cName = 39;
1037 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1038 NULL, NULL, NULL, NULL);
1039 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1040 ++(This->next_index);
1042 hr = CLSIDFromString(catid, rgelt);
1043 if (FAILED(hr)) continue;
1045 ++fetched;
1046 ++rgelt;
1049 if (pceltFetched) *pceltFetched = fetched;
1050 return fetched == celt ? S_OK : S_FALSE;
1053 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
1055 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1056 TRACE("(%p)\n",This);
1058 This->next_index += celt;
1059 return S_OK;
1062 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
1064 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1065 TRACE("(%p)\n",This);
1066 This->next_index = 0;
1067 return S_OK;
1070 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
1071 IEnumGUID **ppenum)
1073 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1074 HRESULT res;
1076 TRACE("(%p)\n",This);
1078 if (ppenum == NULL) return E_POINTER;
1080 res = ProfilesEnumGuid_Constructor(ppenum);
1081 if (SUCCEEDED(res))
1083 ProfilesEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
1084 new_This->next_index = This->next_index;
1086 return res;
1089 static const IEnumGUIDVtbl EnumGUIDVtbl =
1091 ProfilesEnumGuid_QueryInterface,
1092 ProfilesEnumGuid_AddRef,
1093 ProfilesEnumGuid_Release,
1094 ProfilesEnumGuid_Next,
1095 ProfilesEnumGuid_Skip,
1096 ProfilesEnumGuid_Reset,
1097 ProfilesEnumGuid_Clone
1100 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
1102 ProfilesEnumGuid *This;
1104 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ProfilesEnumGuid));
1105 if (This == NULL)
1106 return E_OUTOFMEMORY;
1108 This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
1109 This->refCount = 1;
1111 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1112 KEY_READ | KEY_WRITE, NULL, &This->key, NULL) != ERROR_SUCCESS)
1114 HeapFree(GetProcessHeap(), 0, This);
1115 return E_FAIL;
1118 *ppOut = &This->IEnumGUID_iface;
1119 TRACE("returning %p\n", *ppOut);
1120 return S_OK;
1123 /**************************************************
1124 * IEnumTfLanguageProfiles implementation
1125 **************************************************/
1126 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
1128 TRACE("destroying %p\n", This);
1129 RegCloseKey(This->tipkey);
1130 if (This->langkey)
1131 RegCloseKey(This->langkey);
1132 ITfCategoryMgr_Release(This->catmgr);
1133 HeapFree(GetProcessHeap(),0,This);
1136 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
1138 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1140 *ppvOut = NULL;
1142 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
1144 *ppvOut = &This->IEnumTfLanguageProfiles_iface;
1147 if (*ppvOut)
1149 IEnumTfLanguageProfiles_AddRef(iface);
1150 return S_OK;
1153 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1154 return E_NOINTERFACE;
1157 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
1159 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1160 return InterlockedIncrement(&This->refCount);
1163 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
1165 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1166 ULONG ret;
1168 ret = InterlockedDecrement(&This->refCount);
1169 if (ret == 0)
1170 EnumTfLanguageProfiles_Destructor(This);
1171 return ret;
1174 /*****************************************************
1175 * IEnumGuid functions
1176 *****************************************************/
1177 static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LANGUAGEPROFILE *tflp)
1179 WCHAR fullkey[168];
1180 ULONG res;
1181 WCHAR profileid[39];
1182 DWORD cName = 39;
1183 GUID profile;
1185 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1187 if (This->langkey == NULL)
1189 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1190 res = RegOpenKeyExW(This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1191 if (res)
1193 This->langkey = NULL;
1194 return -1;
1196 This->lang_index = 0;
1198 res = RegEnumKeyExW(This->langkey, This->lang_index, profileid, &cName,
1199 NULL, NULL, NULL, NULL);
1200 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1202 RegCloseKey(This->langkey);
1203 This->langkey = NULL;
1204 return -1;
1206 ++(This->lang_index);
1208 if (tflp)
1210 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
1211 &GUID_TFCAT_TIP_SPEECH,
1212 &GUID_TFCAT_TIP_HANDWRITING };
1213 res = CLSIDFromString(profileid, &profile);
1214 if (FAILED(res)) return 0;
1216 tflp->clsid = clsid;
1217 tflp->langid = This->langid;
1218 tflp->fActive = get_active_textservice(&clsid, NULL);
1219 tflp->guidProfile = profile;
1220 if (ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1221 &tflp->catid, tipcats, 3) != S_OK)
1222 ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1223 &tflp->catid, NULL, 0);
1226 return 1;
1229 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
1230 ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
1232 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1233 ULONG fetched = 0;
1235 TRACE("(%p)\n",This);
1237 if (pProfile == NULL) return E_POINTER;
1239 if (This->tipkey) while (fetched < ulCount)
1241 LSTATUS res;
1242 HRESULT hr;
1243 DWORD cName = 39;
1244 GUID clsid;
1246 res = RegEnumKeyExW(This->tipkey, This->tip_index,
1247 This->szwCurrentClsid, &cName, NULL, NULL, NULL, NULL);
1248 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1249 ++(This->tip_index);
1250 hr = CLSIDFromString(This->szwCurrentClsid, &clsid);
1251 if (FAILED(hr)) continue;
1253 while ( fetched < ulCount)
1255 INT res = next_LanguageProfile(This, clsid, pProfile);
1256 if (res == 1)
1258 ++fetched;
1259 ++pProfile;
1261 else if (res == -1)
1262 break;
1263 else
1264 continue;
1268 if (pcFetch) *pcFetch = fetched;
1269 return fetched == ulCount ? S_OK : S_FALSE;
1272 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
1274 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1275 FIXME("STUB (%p)\n",This);
1276 return E_NOTIMPL;
1279 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
1281 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1282 TRACE("(%p)\n",This);
1283 This->tip_index = 0;
1284 if (This->langkey)
1285 RegCloseKey(This->langkey);
1286 This->langkey = NULL;
1287 This->lang_index = 0;
1288 return S_OK;
1291 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
1292 IEnumTfLanguageProfiles **ppenum)
1294 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1295 HRESULT res;
1297 TRACE("(%p)\n",This);
1299 if (ppenum == NULL) return E_POINTER;
1301 res = EnumTfLanguageProfiles_Constructor(This->langid, ppenum);
1302 if (SUCCEEDED(res))
1304 EnumTfLanguageProfiles *new_This = (EnumTfLanguageProfiles *)*ppenum;
1305 new_This->tip_index = This->tip_index;
1306 lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
1308 if (This->langkey)
1310 WCHAR fullkey[168];
1311 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1313 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1314 res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1315 new_This->lang_index = This->lang_index;
1318 return res;
1321 static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
1323 EnumTfLanguageProfiles_QueryInterface,
1324 EnumTfLanguageProfiles_AddRef,
1325 EnumTfLanguageProfiles_Release,
1326 EnumTfLanguageProfiles_Clone,
1327 EnumTfLanguageProfiles_Next,
1328 EnumTfLanguageProfiles_Reset,
1329 EnumTfLanguageProfiles_Skip
1332 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut)
1334 HRESULT hr;
1335 EnumTfLanguageProfiles *This;
1337 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfLanguageProfiles));
1338 if (This == NULL)
1339 return E_OUTOFMEMORY;
1341 This->IEnumTfLanguageProfiles_iface.lpVtbl= &EnumTfLanguageProfilesVtbl;
1342 This->refCount = 1;
1343 This->langid = langid;
1345 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&This->catmgr);
1346 if (FAILED(hr))
1348 HeapFree(GetProcessHeap(),0,This);
1349 return hr;
1352 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1353 KEY_READ | KEY_WRITE, NULL, &This->tipkey, NULL) != ERROR_SUCCESS)
1355 HeapFree(GetProcessHeap(), 0, This);
1356 return E_FAIL;
1359 *ppOut = &This->IEnumTfLanguageProfiles_iface;
1360 TRACE("returning %p\n", *ppOut);
1361 return S_OK;