explorer: Added stub IServiceProvider support for shell browser window.
[wine.git] / dlls / msctf / inputprocessor.c
blob89eb7466eb48a4f8f9726c2bea2b19bc84ced6b6
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"
38 #include "wine/list.h"
40 #include "msctf.h"
41 #include "msctf_internal.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
45 static const WCHAR szwLngp[] = {'L','a','n','g','u','a','g','e','P','r','o','f','i','l','e',0};
46 static const WCHAR szwEnable[] = {'E','n','a','b','l','e',0};
47 static const WCHAR szwTipfmt[] = {'%','s','\\','%','s',0};
48 static const WCHAR szwFullLangfmt[] = {'%','s','\\','%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
50 static const WCHAR szwAssemblies[] = {'A','s','s','e','m','b','l','i','e','s',0};
51 static const WCHAR szwDefault[] = {'D','e','f','a','u','l','t',0};
52 static const WCHAR szwProfile[] = {'P','r','o','f','i','l','e',0};
53 static const WCHAR szwDefaultFmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
55 typedef struct tagInputProcessorProfilesSink {
56 struct list entry;
57 union {
58 /* InputProcessorProfile Sinks */
59 IUnknown *pIUnknown;
60 ITfLanguageProfileNotifySink *pITfLanguageProfileNotifySink;
61 } interfaces;
62 } InputProcessorProfilesSink;
64 typedef struct tagInputProcessorProfiles {
65 ITfInputProcessorProfiles ITfInputProcessorProfiles_iface;
66 ITfSource ITfSource_iface;
67 ITfInputProcessorProfileMgr ITfInputProcessorProfileMgr_iface;
68 /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
69 /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
70 LONG refCount;
72 LANGID currentLanguage;
74 struct list LanguageProfileNotifySink;
75 } InputProcessorProfiles;
77 typedef struct tagProfilesEnumGuid {
78 IEnumGUID IEnumGUID_iface;
79 LONG refCount;
81 HKEY key;
82 DWORD next_index;
83 } ProfilesEnumGuid;
85 typedef struct tagEnumTfLanguageProfiles {
86 IEnumTfLanguageProfiles IEnumTfLanguageProfiles_iface;
87 LONG refCount;
89 HKEY tipkey;
90 DWORD tip_index;
91 WCHAR szwCurrentClsid[39];
93 HKEY langkey;
94 DWORD lang_index;
96 LANGID langid;
97 ITfCategoryMgr *catmgr;
98 } EnumTfLanguageProfiles;
100 typedef struct {
101 IEnumTfInputProcessorProfiles IEnumTfInputProcessorProfiles_iface;
102 LONG ref;
103 } EnumTfInputProcessorProfiles;
105 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut);
106 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut);
108 static inline EnumTfInputProcessorProfiles *impl_from_IEnumTfInputProcessorProfiles(IEnumTfInputProcessorProfiles *iface)
110 return CONTAINING_RECORD(iface, EnumTfInputProcessorProfiles, IEnumTfInputProcessorProfiles_iface);
113 static HRESULT WINAPI EnumTfInputProcessorProfiles_QueryInterface(IEnumTfInputProcessorProfiles *iface,
114 REFIID riid, void **ppv)
116 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
118 if(IsEqualGUID(riid, &IID_IUnknown)) {
119 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
120 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
121 }else if(IsEqualGUID(riid, &IID_IEnumTfInputProcessorProfiles)) {
122 TRACE("(%p)->(IID_IEnumTfInputProcessorProfiles %p)\n", This, ppv);
123 *ppv = &This->IEnumTfInputProcessorProfiles_iface;
124 }else {
125 *ppv = NULL;
126 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
127 return E_NOINTERFACE;
130 IUnknown_AddRef((IUnknown*)*ppv);
131 return S_OK;
134 static ULONG WINAPI EnumTfInputProcessorProfiles_AddRef(IEnumTfInputProcessorProfiles *iface)
136 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
137 LONG ref = InterlockedIncrement(&This->ref);
139 TRACE("(%p) ref=%d\n", This, ref);
141 return ref;
144 static ULONG WINAPI EnumTfInputProcessorProfiles_Release(IEnumTfInputProcessorProfiles *iface)
146 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
147 LONG ref = InterlockedDecrement(&This->ref);
149 TRACE("(%p) ref=%d\n", This, ref);
151 if(!ref)
152 HeapFree(GetProcessHeap(), 0, This);
154 return ref;
157 static HRESULT WINAPI EnumTfInputProcessorProfiles_Clone(IEnumTfInputProcessorProfiles *iface,
158 IEnumTfInputProcessorProfiles **ret)
160 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
161 FIXME("(%p)->(%p)\n", This, ret);
162 return E_NOTIMPL;
165 static HRESULT WINAPI EnumTfInputProcessorProfiles_Next(IEnumTfInputProcessorProfiles *iface, ULONG count,
166 TF_INPUTPROCESSORPROFILE *profile, ULONG *fetch)
168 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
170 FIXME("(%p)->(%u %p %p)\n", This, count, profile, fetch);
172 if(fetch)
173 *fetch = 0;
174 return S_FALSE;
177 static HRESULT WINAPI EnumTfInputProcessorProfiles_Reset(IEnumTfInputProcessorProfiles *iface)
179 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
180 FIXME("(%p)\n", This);
181 return E_NOTIMPL;
184 static HRESULT WINAPI EnumTfInputProcessorProfiles_Skip(IEnumTfInputProcessorProfiles *iface, ULONG count)
186 EnumTfInputProcessorProfiles *This = impl_from_IEnumTfInputProcessorProfiles(iface);
187 FIXME("(%p)->(%u)\n", This, count);
188 return E_NOTIMPL;
191 static const IEnumTfInputProcessorProfilesVtbl EnumTfInputProcessorProfilesVtbl = {
192 EnumTfInputProcessorProfiles_QueryInterface,
193 EnumTfInputProcessorProfiles_AddRef,
194 EnumTfInputProcessorProfiles_Release,
195 EnumTfInputProcessorProfiles_Clone,
196 EnumTfInputProcessorProfiles_Next,
197 EnumTfInputProcessorProfiles_Reset,
198 EnumTfInputProcessorProfiles_Skip
201 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfiles(ITfInputProcessorProfiles *iface)
203 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfiles_iface);
206 static inline InputProcessorProfiles *impl_from_ITfSource(ITfSource *iface)
208 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfSource_iface);
211 static inline ProfilesEnumGuid *impl_from_IEnumGUID(IEnumGUID *iface)
213 return CONTAINING_RECORD(iface, ProfilesEnumGuid, IEnumGUID_iface);
216 static inline EnumTfLanguageProfiles *impl_from_IEnumTfLanguageProfiles(IEnumTfLanguageProfiles *iface)
218 return CONTAINING_RECORD(iface, EnumTfLanguageProfiles, IEnumTfLanguageProfiles_iface);
221 static void free_sink(InputProcessorProfilesSink *sink)
223 IUnknown_Release(sink->interfaces.pIUnknown);
224 HeapFree(GetProcessHeap(),0,sink);
227 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
229 struct list *cursor, *cursor2;
230 TRACE("destroying %p\n", This);
232 /* free sinks */
233 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->LanguageProfileNotifySink)
235 InputProcessorProfilesSink* sink = LIST_ENTRY(cursor,InputProcessorProfilesSink,entry);
236 list_remove(cursor);
237 free_sink(sink);
240 HeapFree(GetProcessHeap(),0,This);
243 static void add_userkey( REFCLSID rclsid, LANGID langid,
244 REFGUID guidProfile)
246 HKEY key;
247 WCHAR buf[39];
248 WCHAR buf2[39];
249 WCHAR fullkey[168];
250 DWORD disposition = 0;
251 ULONG res;
253 TRACE("\n");
255 StringFromGUID2(rclsid, buf, 39);
256 StringFromGUID2(guidProfile, buf2, 39);
257 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
259 res = RegCreateKeyExW(HKEY_CURRENT_USER,fullkey, 0, NULL, 0,
260 KEY_READ | KEY_WRITE, NULL, &key, &disposition);
262 if (!res && disposition == REG_CREATED_NEW_KEY)
264 DWORD zero = 0x0;
265 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
268 if (!res)
269 RegCloseKey(key);
272 static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, void **ppv)
274 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
276 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
278 *ppv = &This->ITfInputProcessorProfiles_iface;
280 else if (IsEqualIID(iid, &IID_ITfInputProcessorProfileMgr))
282 *ppv = &This->ITfInputProcessorProfileMgr_iface;
284 else if (IsEqualIID(iid, &IID_ITfSource))
286 *ppv = &This->ITfSource_iface;
288 else
290 *ppv = NULL;
291 WARN("unsupported interface: %s\n", debugstr_guid(iid));
292 return E_NOINTERFACE;
295 ITfInputProcessorProfiles_AddRef(iface);
296 return S_OK;
299 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
301 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
302 return InterlockedIncrement(&This->refCount);
305 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
307 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
308 ULONG ret;
310 ret = InterlockedDecrement(&This->refCount);
311 if (ret == 0)
312 InputProcessorProfiles_Destructor(This);
313 return ret;
316 /*****************************************************
317 * ITfInputProcessorProfiles functions
318 *****************************************************/
319 static HRESULT WINAPI InputProcessorProfiles_Register(
320 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
322 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
323 HKEY tipkey;
324 WCHAR buf[39];
325 WCHAR fullkey[68];
327 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
329 StringFromGUID2(rclsid, buf, 39);
330 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
332 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, NULL, 0,
333 KEY_READ | KEY_WRITE, NULL, &tipkey, NULL) != ERROR_SUCCESS)
334 return E_FAIL;
336 RegCloseKey(tipkey);
338 return S_OK;
341 static HRESULT WINAPI InputProcessorProfiles_Unregister(
342 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
344 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
345 WCHAR buf[39];
346 WCHAR fullkey[68];
348 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
350 StringFromGUID2(rclsid, buf, 39);
351 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
353 RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
354 RegDeleteTreeW(HKEY_CURRENT_USER, fullkey);
356 return S_OK;
359 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
360 ITfInputProcessorProfiles *iface, REFCLSID rclsid,
361 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
362 ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
363 ULONG uIconIndex)
365 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
366 HKEY tipkey,fmtkey;
367 WCHAR buf[39];
368 WCHAR fullkey[100];
369 ULONG res;
370 DWORD disposition = 0;
372 static const WCHAR fmt2[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
373 static const WCHAR desc[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
374 static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
375 static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
377 TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
378 debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
379 debugstr_wn(pchIconFile,cchFile),uIconIndex);
381 StringFromGUID2(rclsid, buf, 39);
382 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
384 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
385 &tipkey ) != ERROR_SUCCESS)
386 return E_FAIL;
388 StringFromGUID2(guidProfile, buf, 39);
389 sprintfW(fullkey,fmt2,szwLngp,langid,buf);
391 res = RegCreateKeyExW(tipkey,fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
392 NULL, &fmtkey, &disposition);
394 if (!res)
396 DWORD zero = 0x0;
397 RegSetValueExW(fmtkey, desc, 0, REG_SZ, (const BYTE*)pchDesc, cchDesc * sizeof(WCHAR));
398 RegSetValueExW(fmtkey, icnf, 0, REG_SZ, (const BYTE*)pchIconFile, cchFile * sizeof(WCHAR));
399 RegSetValueExW(fmtkey, icni, 0, REG_DWORD, (LPBYTE)&uIconIndex, sizeof(DWORD));
400 if (disposition == REG_CREATED_NEW_KEY)
401 RegSetValueExW(fmtkey, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
402 RegCloseKey(fmtkey);
404 add_userkey(rclsid, langid, guidProfile);
406 RegCloseKey(tipkey);
408 if (!res)
409 return S_OK;
410 else
411 return E_FAIL;
414 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
415 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
416 REFGUID guidProfile)
418 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
419 FIXME("STUB:(%p)\n",This);
420 return E_NOTIMPL;
423 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
424 ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
426 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
427 TRACE("(%p) %p\n",This,ppEnum);
428 return ProfilesEnumGuid_Constructor(ppEnum);
431 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
432 ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
433 CLSID *pclsid, GUID *pguidProfile)
435 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
436 WCHAR fullkey[168];
437 WCHAR buf[39];
438 HKEY hkey;
439 DWORD count;
440 ULONG res;
442 TRACE("%p) %x %s %p %p\n",This, langid, debugstr_guid(catid),pclsid,pguidProfile);
444 if (!catid || !pclsid || !pguidProfile)
445 return E_INVALIDARG;
447 StringFromGUID2(catid, buf, 39);
448 sprintfW(fullkey, szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
450 if (RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE,
451 &hkey ) != ERROR_SUCCESS)
452 return S_FALSE;
454 count = sizeof(buf);
455 res = RegQueryValueExW(hkey, szwDefault, 0, NULL, (LPBYTE)buf, &count);
456 if (res != ERROR_SUCCESS)
458 RegCloseKey(hkey);
459 return S_FALSE;
461 CLSIDFromString(buf,pclsid);
463 res = RegQueryValueExW(hkey, szwProfile, 0, NULL, (LPBYTE)buf, &count);
464 if (res == ERROR_SUCCESS)
465 CLSIDFromString(buf,pguidProfile);
467 RegCloseKey(hkey);
469 return S_OK;
472 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
473 ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
474 REFGUID guidProfiles)
476 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
477 WCHAR fullkey[168];
478 WCHAR buf[39];
479 HKEY hkey;
480 GUID catid;
481 HRESULT hr;
482 ITfCategoryMgr *catmgr;
483 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
484 &GUID_TFCAT_TIP_SPEECH,
485 &GUID_TFCAT_TIP_HANDWRITING };
487 TRACE("%p) %x %s %s\n",This, langid, debugstr_guid(rclsid),debugstr_guid(guidProfiles));
489 if (!rclsid || !guidProfiles)
490 return E_INVALIDARG;
492 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&catmgr);
494 if (FAILED(hr))
495 return hr;
497 if (ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
498 &catid, tipcats, 3) != S_OK)
499 hr = ITfCategoryMgr_FindClosestCategory(catmgr, rclsid,
500 &catid, NULL, 0);
501 ITfCategoryMgr_Release(catmgr);
503 if (FAILED(hr))
504 return E_FAIL;
506 StringFromGUID2(&catid, buf, 39);
507 sprintfW(fullkey, szwDefaultFmt, szwSystemCTFKey, szwAssemblies, langid, buf);
509 if (RegCreateKeyExW(HKEY_CURRENT_USER, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
510 NULL, &hkey, NULL ) != ERROR_SUCCESS)
511 return E_FAIL;
513 StringFromGUID2(rclsid, buf, 39);
514 RegSetValueExW(hkey, szwDefault, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
515 StringFromGUID2(guidProfiles, buf, 39);
516 RegSetValueExW(hkey, szwProfile, 0, REG_SZ, (LPBYTE)buf, sizeof(buf));
517 RegCloseKey(hkey);
519 return S_OK;
522 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
523 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
524 REFGUID guidProfiles)
526 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
527 HRESULT hr;
528 BOOL enabled;
529 TF_LANGUAGEPROFILE LanguageProfile;
531 TRACE("(%p) %s %x %s\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfiles));
533 if (langid != This->currentLanguage) return E_INVALIDARG;
535 if (get_active_textservice(rclsid,NULL))
537 TRACE("Already Active\n");
538 return E_FAIL;
541 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(iface, rclsid,
542 langid, guidProfiles, &enabled);
543 if (FAILED(hr) || !enabled)
545 TRACE("Not Enabled\n");
546 return E_FAIL;
549 LanguageProfile.clsid = *rclsid;
550 LanguageProfile.langid = langid;
551 LanguageProfile.guidProfile = *guidProfiles;
553 hr = add_active_textservice(&LanguageProfile);
555 return hr;
558 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
559 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
560 GUID *pguidProfile)
562 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
563 TF_LANGUAGEPROFILE profile;
565 TRACE("(%p) %s %p %p\n",This,debugstr_guid(rclsid),plangid,pguidProfile);
567 if (!rclsid || !plangid || !pguidProfile)
568 return E_INVALIDARG;
570 if (get_active_textservice(rclsid, &profile))
572 *plangid = profile.langid;
573 *pguidProfile = profile.guidProfile;
574 return S_OK;
576 else
578 *pguidProfile = GUID_NULL;
579 return S_FALSE;
583 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
584 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
585 REFGUID guidProfile, BSTR *pbstrProfile)
587 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
588 FIXME("STUB:(%p)\n",This);
589 return E_NOTIMPL;
592 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
593 ITfInputProcessorProfiles *iface, LANGID *plangid)
595 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
596 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
598 if (!plangid)
599 return E_INVALIDARG;
601 *plangid = This->currentLanguage;
603 return S_OK;
606 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
607 ITfInputProcessorProfiles *iface, LANGID langid)
609 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
610 struct list *cursor;
611 BOOL accept;
613 FIXME("STUB:(%p)\n",This);
615 LIST_FOR_EACH(cursor, &This->LanguageProfileNotifySink)
617 InputProcessorProfilesSink* sink = LIST_ENTRY(cursor,InputProcessorProfilesSink,entry);
618 accept = TRUE;
619 ITfLanguageProfileNotifySink_OnLanguageChange(sink->interfaces.pITfLanguageProfileNotifySink, langid, &accept);
620 if (!accept)
621 return E_FAIL;
624 /* TODO: On successful language change call OnLanguageChanged sink */
625 return E_NOTIMPL;
628 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
629 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
631 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
632 FIXME("Semi-STUB:(%p)\n",This);
633 *ppLangId = CoTaskMemAlloc(sizeof(LANGID));
634 **ppLangId = This->currentLanguage;
635 *pulCount = 1;
636 return S_OK;
639 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
640 ITfInputProcessorProfiles *iface, LANGID langid,
641 IEnumTfLanguageProfiles **ppEnum)
643 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
644 TRACE("(%p) %x %p\n",This,langid,ppEnum);
645 return EnumTfLanguageProfiles_Constructor(langid, ppEnum);
648 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
649 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
650 REFGUID guidProfile, BOOL fEnable)
652 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
653 HKEY key;
654 WCHAR buf[39];
655 WCHAR buf2[39];
656 WCHAR fullkey[168];
657 ULONG res;
659 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
661 StringFromGUID2(rclsid, buf, 39);
662 StringFromGUID2(guidProfile, buf2, 39);
663 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
665 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
667 if (!res)
669 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
670 RegCloseKey(key);
672 else
673 return E_FAIL;
675 return S_OK;
678 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
679 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
680 REFGUID guidProfile, BOOL *pfEnable)
682 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
683 HKEY key;
684 WCHAR buf[39];
685 WCHAR buf2[39];
686 WCHAR fullkey[168];
687 ULONG res;
689 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
691 if (!pfEnable)
692 return E_INVALIDARG;
694 StringFromGUID2(rclsid, buf, 39);
695 StringFromGUID2(guidProfile, buf2, 39);
696 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
698 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
700 if (!res)
702 DWORD count = sizeof(DWORD);
703 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
704 RegCloseKey(key);
707 if (res) /* Try Default */
709 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
711 if (!res)
713 DWORD count = sizeof(DWORD);
714 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
715 RegCloseKey(key);
719 if (!res)
720 return S_OK;
721 else
722 return E_FAIL;
725 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
726 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
727 REFGUID guidProfile, BOOL fEnable)
729 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
730 HKEY key;
731 WCHAR buf[39];
732 WCHAR buf2[39];
733 WCHAR fullkey[168];
734 ULONG res;
736 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
738 StringFromGUID2(rclsid, buf, 39);
739 StringFromGUID2(guidProfile, buf2, 39);
740 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
742 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
744 if (!res)
746 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
747 RegCloseKey(key);
749 else
750 return E_FAIL;
752 return S_OK;
755 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
756 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
757 REFGUID guidProfile, HKL hKL)
759 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfiles(iface);
760 FIXME("STUB:(%p)\n",This);
761 return E_NOTIMPL;
764 static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl =
766 InputProcessorProfiles_QueryInterface,
767 InputProcessorProfiles_AddRef,
768 InputProcessorProfiles_Release,
769 InputProcessorProfiles_Register,
770 InputProcessorProfiles_Unregister,
771 InputProcessorProfiles_AddLanguageProfile,
772 InputProcessorProfiles_RemoveLanguageProfile,
773 InputProcessorProfiles_EnumInputProcessorInfo,
774 InputProcessorProfiles_GetDefaultLanguageProfile,
775 InputProcessorProfiles_SetDefaultLanguageProfile,
776 InputProcessorProfiles_ActivateLanguageProfile,
777 InputProcessorProfiles_GetActiveLanguageProfile,
778 InputProcessorProfiles_GetLanguageProfileDescription,
779 InputProcessorProfiles_GetCurrentLanguage,
780 InputProcessorProfiles_ChangeCurrentLanguage,
781 InputProcessorProfiles_GetLanguageList,
782 InputProcessorProfiles_EnumLanguageProfiles,
783 InputProcessorProfiles_EnableLanguageProfile,
784 InputProcessorProfiles_IsEnabledLanguageProfile,
785 InputProcessorProfiles_EnableLanguageProfileByDefault,
786 InputProcessorProfiles_SubstituteKeyboardLayout
789 static inline InputProcessorProfiles *impl_from_ITfInputProcessorProfileMgr(ITfInputProcessorProfileMgr *iface)
791 return CONTAINING_RECORD(iface, InputProcessorProfiles, ITfInputProcessorProfileMgr_iface);
794 static HRESULT WINAPI InputProcessorProfileMgr_QueryInterface(ITfInputProcessorProfileMgr *iface, REFIID riid, void **ppv)
796 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
797 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, riid, ppv);
800 static ULONG WINAPI InputProcessorProfileMgr_AddRef(ITfInputProcessorProfileMgr *iface)
802 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
803 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
806 static ULONG WINAPI InputProcessorProfileMgr_Release(ITfInputProcessorProfileMgr *iface)
808 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
809 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
812 static HRESULT WINAPI InputProcessorProfileMgr_ActivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
813 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
815 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
816 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
817 debugstr_guid(guidProfile), hkl, dwFlags);
818 return E_NOTIMPL;
821 static HRESULT WINAPI InputProcessorProfileMgr_DeactivateProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
822 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
824 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
825 FIXME("(%p)->(%d %x %s %s %p %x)\n", This, dwProfileType, langid, debugstr_guid(clsid),
826 debugstr_guid(guidProfile), hkl, dwFlags);
827 return E_NOTIMPL;
830 static HRESULT WINAPI InputProcessorProfileMgr_GetProfile(ITfInputProcessorProfileMgr *iface, DWORD dwProfileType,
831 LANGID langid, REFCLSID clsid, REFGUID guidProfile, HKL hkl, TF_INPUTPROCESSORPROFILE *pProfile)
833 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
834 FIXME("(%p)->(%d %x %s %s %p %p)\n", This, dwProfileType, langid, debugstr_guid(clsid),
835 debugstr_guid(guidProfile), hkl, pProfile);
836 return E_NOTIMPL;
839 static HRESULT WINAPI InputProcessorProfileMgr_EnumProfiles(ITfInputProcessorProfileMgr *iface, LANGID langid,
840 IEnumTfInputProcessorProfiles **ppEnum)
842 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
843 EnumTfInputProcessorProfiles *enum_profiles;
845 TRACE("(%p)->(%x %p)\n", This, langid, ppEnum);
847 enum_profiles = HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_profiles));
848 if(!enum_profiles)
849 return E_OUTOFMEMORY;
851 enum_profiles->IEnumTfInputProcessorProfiles_iface.lpVtbl = &EnumTfInputProcessorProfilesVtbl;
852 enum_profiles->ref = 1;
854 *ppEnum = &enum_profiles->IEnumTfInputProcessorProfiles_iface;
855 return S_OK;
858 static HRESULT WINAPI InputProcessorProfileMgr_ReleaseInputProcessor(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
859 DWORD dwFlags)
861 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
862 FIXME("(%p)->(%s %x)\n", This, debugstr_guid(rclsid), dwFlags);
863 return E_NOTIMPL;
866 static HRESULT WINAPI InputProcessorProfileMgr_RegisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
867 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc, ULONG cchDesc, const WCHAR *pchIconFile,
868 ULONG cchFile, ULONG uIconIndex, HKL hklsubstitute, DWORD dwPreferredLayout, BOOL bEnabledByDefault,
869 DWORD dwFlags)
871 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
872 FIXME("(%p)->(%s %x %s %s %d %s %u %u %p %x %x %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile),
873 debugstr_w(pchDesc), cchDesc, debugstr_w(pchIconFile), cchFile, uIconIndex, hklsubstitute, dwPreferredLayout,
874 bEnabledByDefault, dwFlags);
875 return E_NOTIMPL;
878 static HRESULT WINAPI InputProcessorProfileMgr_UnregisterProfile(ITfInputProcessorProfileMgr *iface, REFCLSID rclsid,
879 LANGID langid, REFGUID guidProfile, DWORD dwFlags)
881 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
882 FIXME("(%p)->(%s %x %s %x)\n", This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), dwFlags);
883 return E_NOTIMPL;
886 static HRESULT WINAPI InputProcessorProfileMgr_GetActiveProfile(ITfInputProcessorProfileMgr *iface, REFGUID catid,
887 TF_INPUTPROCESSORPROFILE *pProfile)
889 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
890 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(catid), pProfile);
891 return E_NOTIMPL;
894 static const ITfInputProcessorProfileMgrVtbl InputProcessorProfileMgrVtbl = {
895 InputProcessorProfileMgr_QueryInterface,
896 InputProcessorProfileMgr_AddRef,
897 InputProcessorProfileMgr_Release,
898 InputProcessorProfileMgr_ActivateProfile,
899 InputProcessorProfileMgr_DeactivateProfile,
900 InputProcessorProfileMgr_GetProfile,
901 InputProcessorProfileMgr_EnumProfiles,
902 InputProcessorProfileMgr_ReleaseInputProcessor,
903 InputProcessorProfileMgr_RegisterProfile,
904 InputProcessorProfileMgr_UnregisterProfile,
905 InputProcessorProfileMgr_GetActiveProfile
908 /*****************************************************
909 * ITfSource functions
910 *****************************************************/
911 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
913 InputProcessorProfiles *This = impl_from_ITfSource(iface);
914 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, iid, ppvOut);
917 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
919 InputProcessorProfiles *This = impl_from_ITfSource(iface);
920 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
923 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
925 InputProcessorProfiles *This = impl_from_ITfSource(iface);
926 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
929 static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
930 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
932 InputProcessorProfiles *This = impl_from_ITfSource(iface);
933 InputProcessorProfilesSink *ipps;
935 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
937 if (!riid || !punk || !pdwCookie)
938 return E_INVALIDARG;
940 if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
942 ipps = HeapAlloc(GetProcessHeap(),0,sizeof(InputProcessorProfilesSink));
943 if (!ipps)
944 return E_OUTOFMEMORY;
945 if (FAILED(IUnknown_QueryInterface(punk, riid, (LPVOID *)&ipps->interfaces.pITfLanguageProfileNotifySink)))
947 HeapFree(GetProcessHeap(),0,ipps);
948 return CONNECT_E_CANNOTCONNECT;
950 list_add_head(&This->LanguageProfileNotifySink,&ipps->entry);
951 *pdwCookie = generate_Cookie(COOKIE_MAGIC_IPPSINK, ipps);
953 else
955 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
956 return E_NOTIMPL;
959 TRACE("cookie %x\n",*pdwCookie);
961 return S_OK;
964 static HRESULT WINAPI IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
966 InputProcessorProfiles *This = impl_from_ITfSource(iface);
967 InputProcessorProfilesSink *sink;
969 TRACE("(%p) %x\n",This,pdwCookie);
971 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
972 return E_INVALIDARG;
974 sink = remove_Cookie(pdwCookie);
975 if (!sink)
976 return CONNECT_E_NOCONNECTION;
978 list_remove(&sink->entry);
979 free_sink(sink);
981 return S_OK;
984 static const ITfSourceVtbl InputProcessorProfilesSourceVtbl =
986 IPPSource_QueryInterface,
987 IPPSource_AddRef,
988 IPPSource_Release,
989 IPPSource_AdviseSink,
990 IPPSource_UnadviseSink,
993 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
995 InputProcessorProfiles *This;
996 if (pUnkOuter)
997 return CLASS_E_NOAGGREGATION;
999 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
1000 if (This == NULL)
1001 return E_OUTOFMEMORY;
1003 This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
1004 This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
1005 This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
1006 This->refCount = 1;
1007 This->currentLanguage = GetUserDefaultLCID();
1009 list_init(&This->LanguageProfileNotifySink);
1011 *ppOut = (IUnknown *)&This->ITfInputProcessorProfiles_iface;
1012 TRACE("returning %p\n", *ppOut);
1013 return S_OK;
1016 /**************************************************
1017 * IEnumGUID implementation for ITfInputProcessorProfiles::EnumInputProcessorInfo
1018 **************************************************/
1019 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
1021 TRACE("destroying %p\n", This);
1022 RegCloseKey(This->key);
1023 HeapFree(GetProcessHeap(),0,This);
1026 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
1028 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1029 *ppvOut = NULL;
1031 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
1033 *ppvOut = &This->IEnumGUID_iface;
1036 if (*ppvOut)
1038 IEnumGUID_AddRef(iface);
1039 return S_OK;
1042 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1043 return E_NOINTERFACE;
1046 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
1048 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1049 return InterlockedIncrement(&This->refCount);
1052 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
1054 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1055 ULONG ret;
1057 ret = InterlockedDecrement(&This->refCount);
1058 if (ret == 0)
1059 ProfilesEnumGuid_Destructor(This);
1060 return ret;
1063 /*****************************************************
1064 * IEnumGuid functions
1065 *****************************************************/
1066 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
1067 ULONG celt, GUID *rgelt, ULONG *pceltFetched)
1069 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1070 ULONG fetched = 0;
1072 TRACE("(%p)\n",This);
1074 if (rgelt == NULL) return E_POINTER;
1076 if (This->key) while (fetched < celt)
1078 LSTATUS res;
1079 HRESULT hr;
1080 WCHAR catid[39];
1081 DWORD cName = 39;
1083 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1084 NULL, NULL, NULL, NULL);
1085 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1086 ++(This->next_index);
1088 hr = CLSIDFromString(catid, rgelt);
1089 if (FAILED(hr)) continue;
1091 ++fetched;
1092 ++rgelt;
1095 if (pceltFetched) *pceltFetched = fetched;
1096 return fetched == celt ? S_OK : S_FALSE;
1099 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
1101 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1102 TRACE("(%p)\n",This);
1104 This->next_index += celt;
1105 return S_OK;
1108 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
1110 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1111 TRACE("(%p)\n",This);
1112 This->next_index = 0;
1113 return S_OK;
1116 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
1117 IEnumGUID **ppenum)
1119 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1120 HRESULT res;
1122 TRACE("(%p)\n",This);
1124 if (ppenum == NULL) return E_POINTER;
1126 res = ProfilesEnumGuid_Constructor(ppenum);
1127 if (SUCCEEDED(res))
1129 ProfilesEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
1130 new_This->next_index = This->next_index;
1132 return res;
1135 static const IEnumGUIDVtbl EnumGUIDVtbl =
1137 ProfilesEnumGuid_QueryInterface,
1138 ProfilesEnumGuid_AddRef,
1139 ProfilesEnumGuid_Release,
1140 ProfilesEnumGuid_Next,
1141 ProfilesEnumGuid_Skip,
1142 ProfilesEnumGuid_Reset,
1143 ProfilesEnumGuid_Clone
1146 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
1148 ProfilesEnumGuid *This;
1150 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ProfilesEnumGuid));
1151 if (This == NULL)
1152 return E_OUTOFMEMORY;
1154 This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
1155 This->refCount = 1;
1157 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1158 KEY_READ | KEY_WRITE, NULL, &This->key, NULL) != ERROR_SUCCESS)
1160 HeapFree(GetProcessHeap(), 0, This);
1161 return E_FAIL;
1164 *ppOut = &This->IEnumGUID_iface;
1165 TRACE("returning %p\n", *ppOut);
1166 return S_OK;
1169 /**************************************************
1170 * IEnumTfLanguageProfiles implementation
1171 **************************************************/
1172 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
1174 TRACE("destroying %p\n", This);
1175 RegCloseKey(This->tipkey);
1176 if (This->langkey)
1177 RegCloseKey(This->langkey);
1178 ITfCategoryMgr_Release(This->catmgr);
1179 HeapFree(GetProcessHeap(),0,This);
1182 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
1184 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1186 *ppvOut = NULL;
1188 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
1190 *ppvOut = &This->IEnumTfLanguageProfiles_iface;
1193 if (*ppvOut)
1195 IEnumTfLanguageProfiles_AddRef(iface);
1196 return S_OK;
1199 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1200 return E_NOINTERFACE;
1203 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
1205 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1206 return InterlockedIncrement(&This->refCount);
1209 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
1211 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1212 ULONG ret;
1214 ret = InterlockedDecrement(&This->refCount);
1215 if (ret == 0)
1216 EnumTfLanguageProfiles_Destructor(This);
1217 return ret;
1220 /*****************************************************
1221 * IEnumGuid functions
1222 *****************************************************/
1223 static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LANGUAGEPROFILE *tflp)
1225 WCHAR fullkey[168];
1226 ULONG res;
1227 WCHAR profileid[39];
1228 DWORD cName = 39;
1229 GUID profile;
1231 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1233 if (This->langkey == NULL)
1235 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1236 res = RegOpenKeyExW(This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1237 if (res)
1239 This->langkey = NULL;
1240 return -1;
1242 This->lang_index = 0;
1244 res = RegEnumKeyExW(This->langkey, This->lang_index, profileid, &cName,
1245 NULL, NULL, NULL, NULL);
1246 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1248 RegCloseKey(This->langkey);
1249 This->langkey = NULL;
1250 return -1;
1252 ++(This->lang_index);
1254 if (tflp)
1256 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
1257 &GUID_TFCAT_TIP_SPEECH,
1258 &GUID_TFCAT_TIP_HANDWRITING };
1259 res = CLSIDFromString(profileid, &profile);
1260 if (FAILED(res)) return 0;
1262 tflp->clsid = clsid;
1263 tflp->langid = This->langid;
1264 tflp->fActive = get_active_textservice(&clsid, NULL);
1265 tflp->guidProfile = profile;
1266 if (ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1267 &tflp->catid, tipcats, 3) != S_OK)
1268 ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1269 &tflp->catid, NULL, 0);
1272 return 1;
1275 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
1276 ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
1278 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1279 ULONG fetched = 0;
1281 TRACE("(%p)\n",This);
1283 if (pProfile == NULL) return E_POINTER;
1285 if (This->tipkey) while (fetched < ulCount)
1287 LSTATUS res;
1288 HRESULT hr;
1289 DWORD cName = 39;
1290 GUID clsid;
1292 res = RegEnumKeyExW(This->tipkey, This->tip_index,
1293 This->szwCurrentClsid, &cName, NULL, NULL, NULL, NULL);
1294 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1295 ++(This->tip_index);
1296 hr = CLSIDFromString(This->szwCurrentClsid, &clsid);
1297 if (FAILED(hr)) continue;
1299 while ( fetched < ulCount)
1301 INT res = next_LanguageProfile(This, clsid, pProfile);
1302 if (res == 1)
1304 ++fetched;
1305 ++pProfile;
1307 else if (res == -1)
1308 break;
1309 else
1310 continue;
1314 if (pcFetch) *pcFetch = fetched;
1315 return fetched == ulCount ? S_OK : S_FALSE;
1318 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
1320 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1321 FIXME("STUB (%p)\n",This);
1322 return E_NOTIMPL;
1325 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
1327 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1328 TRACE("(%p)\n",This);
1329 This->tip_index = 0;
1330 if (This->langkey)
1331 RegCloseKey(This->langkey);
1332 This->langkey = NULL;
1333 This->lang_index = 0;
1334 return S_OK;
1337 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
1338 IEnumTfLanguageProfiles **ppenum)
1340 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1341 HRESULT res;
1343 TRACE("(%p)\n",This);
1345 if (ppenum == NULL) return E_POINTER;
1347 res = EnumTfLanguageProfiles_Constructor(This->langid, ppenum);
1348 if (SUCCEEDED(res))
1350 EnumTfLanguageProfiles *new_This = (EnumTfLanguageProfiles *)*ppenum;
1351 new_This->tip_index = This->tip_index;
1352 lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
1354 if (This->langkey)
1356 WCHAR fullkey[168];
1357 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1359 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1360 res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1361 new_This->lang_index = This->lang_index;
1364 return res;
1367 static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
1369 EnumTfLanguageProfiles_QueryInterface,
1370 EnumTfLanguageProfiles_AddRef,
1371 EnumTfLanguageProfiles_Release,
1372 EnumTfLanguageProfiles_Clone,
1373 EnumTfLanguageProfiles_Next,
1374 EnumTfLanguageProfiles_Reset,
1375 EnumTfLanguageProfiles_Skip
1378 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut)
1380 HRESULT hr;
1381 EnumTfLanguageProfiles *This;
1383 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfLanguageProfiles));
1384 if (This == NULL)
1385 return E_OUTOFMEMORY;
1387 This->IEnumTfLanguageProfiles_iface.lpVtbl= &EnumTfLanguageProfilesVtbl;
1388 This->refCount = 1;
1389 This->langid = langid;
1391 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&This->catmgr);
1392 if (FAILED(hr))
1394 HeapFree(GetProcessHeap(),0,This);
1395 return hr;
1398 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1399 KEY_READ | KEY_WRITE, NULL, &This->tipkey, NULL) != ERROR_SUCCESS)
1401 HeapFree(GetProcessHeap(), 0, This);
1402 return E_FAIL;
1405 *ppOut = &This->IEnumTfLanguageProfiles_iface;
1406 TRACE("returning %p\n", *ppOut);
1407 return S_OK;