gdi32: Use NtGdiPolyPolyDraw for PolylineTo implementation.
[wine.git] / dlls / msctf / inputprocessor.c
blobac7fad6754815b67ac1cf1acd437cc532d72e7a2
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 static int once;
871 if (!once++)
873 InputProcessorProfiles *This = impl_from_ITfInputProcessorProfileMgr(iface);
874 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(catid), pProfile);
877 return E_NOTIMPL;
880 static const ITfInputProcessorProfileMgrVtbl InputProcessorProfileMgrVtbl = {
881 InputProcessorProfileMgr_QueryInterface,
882 InputProcessorProfileMgr_AddRef,
883 InputProcessorProfileMgr_Release,
884 InputProcessorProfileMgr_ActivateProfile,
885 InputProcessorProfileMgr_DeactivateProfile,
886 InputProcessorProfileMgr_GetProfile,
887 InputProcessorProfileMgr_EnumProfiles,
888 InputProcessorProfileMgr_ReleaseInputProcessor,
889 InputProcessorProfileMgr_RegisterProfile,
890 InputProcessorProfileMgr_UnregisterProfile,
891 InputProcessorProfileMgr_GetActiveProfile
894 /*****************************************************
895 * ITfSource functions
896 *****************************************************/
897 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
899 InputProcessorProfiles *This = impl_from_ITfSource(iface);
900 return ITfInputProcessorProfiles_QueryInterface(&This->ITfInputProcessorProfiles_iface, iid, ppvOut);
903 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
905 InputProcessorProfiles *This = impl_from_ITfSource(iface);
906 return ITfInputProcessorProfiles_AddRef(&This->ITfInputProcessorProfiles_iface);
909 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
911 InputProcessorProfiles *This = impl_from_ITfSource(iface);
912 return ITfInputProcessorProfiles_Release(&This->ITfInputProcessorProfiles_iface);
915 static HRESULT WINAPI IPPSource_AdviseSink(ITfSource *iface,
916 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
918 InputProcessorProfiles *This = impl_from_ITfSource(iface);
920 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
922 if (!riid || !punk || !pdwCookie)
923 return E_INVALIDARG;
925 if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
926 return advise_sink(&This->LanguageProfileNotifySink, &IID_ITfLanguageProfileNotifySink,
927 COOKIE_MAGIC_IPPSINK, punk, pdwCookie);
929 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
930 return E_NOTIMPL;
933 static HRESULT WINAPI IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
935 InputProcessorProfiles *This = impl_from_ITfSource(iface);
937 TRACE("(%p) %x\n",This,pdwCookie);
939 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
940 return E_INVALIDARG;
942 return unadvise_sink(pdwCookie);
945 static const ITfSourceVtbl InputProcessorProfilesSourceVtbl =
947 IPPSource_QueryInterface,
948 IPPSource_AddRef,
949 IPPSource_Release,
950 IPPSource_AdviseSink,
951 IPPSource_UnadviseSink,
954 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
956 InputProcessorProfiles *This;
957 if (pUnkOuter)
958 return CLASS_E_NOAGGREGATION;
960 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
961 if (This == NULL)
962 return E_OUTOFMEMORY;
964 This->ITfInputProcessorProfiles_iface.lpVtbl= &InputProcessorProfilesVtbl;
965 This->ITfSource_iface.lpVtbl = &InputProcessorProfilesSourceVtbl;
966 This->ITfInputProcessorProfileMgr_iface.lpVtbl = &InputProcessorProfileMgrVtbl;
967 This->refCount = 1;
968 This->currentLanguage = GetUserDefaultLCID();
970 list_init(&This->LanguageProfileNotifySink);
972 *ppOut = (IUnknown *)&This->ITfInputProcessorProfiles_iface;
973 TRACE("returning %p\n", *ppOut);
974 return S_OK;
977 /**************************************************
978 * IEnumGUID implementation for ITfInputProcessorProfiles::EnumInputProcessorInfo
979 **************************************************/
980 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
982 TRACE("destroying %p\n", This);
983 RegCloseKey(This->key);
984 HeapFree(GetProcessHeap(),0,This);
987 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
989 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
990 *ppvOut = NULL;
992 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
994 *ppvOut = &This->IEnumGUID_iface;
997 if (*ppvOut)
999 IEnumGUID_AddRef(iface);
1000 return S_OK;
1003 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1004 return E_NOINTERFACE;
1007 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
1009 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1010 return InterlockedIncrement(&This->refCount);
1013 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
1015 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1016 ULONG ret;
1018 ret = InterlockedDecrement(&This->refCount);
1019 if (ret == 0)
1020 ProfilesEnumGuid_Destructor(This);
1021 return ret;
1024 /*****************************************************
1025 * IEnumGuid functions
1026 *****************************************************/
1027 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
1028 ULONG celt, GUID *rgelt, ULONG *pceltFetched)
1030 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1031 ULONG fetched = 0;
1033 TRACE("(%p)\n",This);
1035 if (rgelt == NULL) return E_POINTER;
1037 if (This->key) while (fetched < celt)
1039 LSTATUS res;
1040 HRESULT hr;
1041 WCHAR catid[39];
1042 DWORD cName = 39;
1044 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1045 NULL, NULL, NULL, NULL);
1046 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1047 ++(This->next_index);
1049 hr = CLSIDFromString(catid, rgelt);
1050 if (FAILED(hr)) continue;
1052 ++fetched;
1053 ++rgelt;
1056 if (pceltFetched) *pceltFetched = fetched;
1057 return fetched == celt ? S_OK : S_FALSE;
1060 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
1062 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1063 TRACE("(%p)\n",This);
1065 This->next_index += celt;
1066 return S_OK;
1069 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
1071 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1072 TRACE("(%p)\n",This);
1073 This->next_index = 0;
1074 return S_OK;
1077 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
1078 IEnumGUID **ppenum)
1080 ProfilesEnumGuid *This = impl_from_IEnumGUID(iface);
1081 HRESULT res;
1083 TRACE("(%p)\n",This);
1085 if (ppenum == NULL) return E_POINTER;
1087 res = ProfilesEnumGuid_Constructor(ppenum);
1088 if (SUCCEEDED(res))
1090 ProfilesEnumGuid *new_This = impl_from_IEnumGUID(*ppenum);
1091 new_This->next_index = This->next_index;
1093 return res;
1096 static const IEnumGUIDVtbl EnumGUIDVtbl =
1098 ProfilesEnumGuid_QueryInterface,
1099 ProfilesEnumGuid_AddRef,
1100 ProfilesEnumGuid_Release,
1101 ProfilesEnumGuid_Next,
1102 ProfilesEnumGuid_Skip,
1103 ProfilesEnumGuid_Reset,
1104 ProfilesEnumGuid_Clone
1107 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
1109 ProfilesEnumGuid *This;
1111 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ProfilesEnumGuid));
1112 if (This == NULL)
1113 return E_OUTOFMEMORY;
1115 This->IEnumGUID_iface.lpVtbl= &EnumGUIDVtbl;
1116 This->refCount = 1;
1118 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1119 KEY_READ | KEY_WRITE, NULL, &This->key, NULL) != ERROR_SUCCESS)
1121 HeapFree(GetProcessHeap(), 0, This);
1122 return E_FAIL;
1125 *ppOut = &This->IEnumGUID_iface;
1126 TRACE("returning %p\n", *ppOut);
1127 return S_OK;
1130 /**************************************************
1131 * IEnumTfLanguageProfiles implementation
1132 **************************************************/
1133 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
1135 TRACE("destroying %p\n", This);
1136 RegCloseKey(This->tipkey);
1137 if (This->langkey)
1138 RegCloseKey(This->langkey);
1139 ITfCategoryMgr_Release(This->catmgr);
1140 HeapFree(GetProcessHeap(),0,This);
1143 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
1145 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1147 *ppvOut = NULL;
1149 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
1151 *ppvOut = &This->IEnumTfLanguageProfiles_iface;
1154 if (*ppvOut)
1156 IEnumTfLanguageProfiles_AddRef(iface);
1157 return S_OK;
1160 WARN("unsupported interface: %s\n", debugstr_guid(iid));
1161 return E_NOINTERFACE;
1164 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
1166 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1167 return InterlockedIncrement(&This->refCount);
1170 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
1172 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1173 ULONG ret;
1175 ret = InterlockedDecrement(&This->refCount);
1176 if (ret == 0)
1177 EnumTfLanguageProfiles_Destructor(This);
1178 return ret;
1181 /*****************************************************
1182 * IEnumGuid functions
1183 *****************************************************/
1184 static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LANGUAGEPROFILE *tflp)
1186 WCHAR fullkey[168];
1187 ULONG res;
1188 WCHAR profileid[39];
1189 DWORD cName = 39;
1190 GUID profile;
1192 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1194 if (This->langkey == NULL)
1196 swprintf(fullkey,ARRAY_SIZE(fullkey),fmt,This->szwCurrentClsid,szwLngp,This->langid);
1197 res = RegOpenKeyExW(This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1198 if (res)
1200 This->langkey = NULL;
1201 return -1;
1203 This->lang_index = 0;
1205 res = RegEnumKeyExW(This->langkey, This->lang_index, profileid, &cName,
1206 NULL, NULL, NULL, NULL);
1207 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1209 RegCloseKey(This->langkey);
1210 This->langkey = NULL;
1211 return -1;
1213 ++(This->lang_index);
1215 if (tflp)
1217 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
1218 &GUID_TFCAT_TIP_SPEECH,
1219 &GUID_TFCAT_TIP_HANDWRITING };
1220 res = CLSIDFromString(profileid, &profile);
1221 if (FAILED(res)) return 0;
1223 tflp->clsid = clsid;
1224 tflp->langid = This->langid;
1225 tflp->fActive = get_active_textservice(&clsid, NULL);
1226 tflp->guidProfile = profile;
1227 if (ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1228 &tflp->catid, tipcats, 3) != S_OK)
1229 ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
1230 &tflp->catid, NULL, 0);
1233 return 1;
1236 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
1237 ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
1239 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1240 ULONG fetched = 0;
1242 TRACE("(%p)\n",This);
1244 if (pProfile == NULL) return E_POINTER;
1246 if (This->tipkey) while (fetched < ulCount)
1248 LSTATUS res;
1249 HRESULT hr;
1250 DWORD cName = 39;
1251 GUID clsid;
1253 res = RegEnumKeyExW(This->tipkey, This->tip_index,
1254 This->szwCurrentClsid, &cName, NULL, NULL, NULL, NULL);
1255 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1256 ++(This->tip_index);
1257 hr = CLSIDFromString(This->szwCurrentClsid, &clsid);
1258 if (FAILED(hr)) continue;
1260 while ( fetched < ulCount)
1262 INT res = next_LanguageProfile(This, clsid, pProfile);
1263 if (res == 1)
1265 ++fetched;
1266 ++pProfile;
1268 else if (res == -1)
1269 break;
1270 else
1271 continue;
1275 if (pcFetch) *pcFetch = fetched;
1276 return fetched == ulCount ? S_OK : S_FALSE;
1279 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
1281 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1282 FIXME("STUB (%p)\n",This);
1283 return E_NOTIMPL;
1286 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
1288 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1289 TRACE("(%p)\n",This);
1290 This->tip_index = 0;
1291 if (This->langkey)
1292 RegCloseKey(This->langkey);
1293 This->langkey = NULL;
1294 This->lang_index = 0;
1295 return S_OK;
1298 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
1299 IEnumTfLanguageProfiles **ppenum)
1301 EnumTfLanguageProfiles *This = impl_from_IEnumTfLanguageProfiles(iface);
1302 EnumTfLanguageProfiles *new_This;
1303 HRESULT res;
1305 TRACE("(%p)\n",This);
1307 if (ppenum == NULL) return E_POINTER;
1309 res = EnumTfLanguageProfiles_Constructor(This->langid, &new_This);
1310 if (SUCCEEDED(res))
1312 new_This->tip_index = This->tip_index;
1313 lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
1315 if (This->langkey)
1317 WCHAR fullkey[168];
1318 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1320 swprintf(fullkey,ARRAY_SIZE(fullkey),fmt,This->szwCurrentClsid,szwLngp,This->langid);
1321 res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1322 new_This->lang_index = This->lang_index;
1324 *ppenum = &new_This->IEnumTfLanguageProfiles_iface;
1326 return res;
1329 static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl =
1331 EnumTfLanguageProfiles_QueryInterface,
1332 EnumTfLanguageProfiles_AddRef,
1333 EnumTfLanguageProfiles_Release,
1334 EnumTfLanguageProfiles_Clone,
1335 EnumTfLanguageProfiles_Next,
1336 EnumTfLanguageProfiles_Reset,
1337 EnumTfLanguageProfiles_Skip
1340 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, EnumTfLanguageProfiles **out)
1342 HRESULT hr;
1343 EnumTfLanguageProfiles *This;
1345 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfLanguageProfiles));
1346 if (This == NULL)
1347 return E_OUTOFMEMORY;
1349 This->IEnumTfLanguageProfiles_iface.lpVtbl= &EnumTfLanguageProfilesVtbl;
1350 This->refCount = 1;
1351 This->langid = langid;
1353 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&This->catmgr);
1354 if (FAILED(hr))
1356 HeapFree(GetProcessHeap(),0,This);
1357 return hr;
1360 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1361 KEY_READ | KEY_WRITE, NULL, &This->tipkey, NULL) != ERROR_SUCCESS)
1363 HeapFree(GetProcessHeap(), 0, This);
1364 return E_FAIL;
1367 *out = This;
1368 TRACE("returning %p\n", *out);
1369 return S_OK;