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
27 #include "wine/debug.h"
37 #include "wine/unicode.h"
38 #include "wine/list.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 typedef struct tagInputProcessorProfilesSink {
53 /* InputProcessorProfile Sinks */
55 ITfLanguageProfileNotifySink *pITfLanguageProfileNotifySink;
57 } InputProcessorProfilesSink;
59 typedef struct tagInputProcessorProfiles {
60 const ITfInputProcessorProfilesVtbl *InputProcessorProfilesVtbl;
61 const ITfSourceVtbl *SourceVtbl;
62 /* const ITfInputProcessorProfileMgrVtbl *InputProcessorProfileMgrVtbl; */
63 /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
64 /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
67 LANGID currentLanguage;
69 struct list LanguageProfileNotifySink;
70 } InputProcessorProfiles;
72 typedef struct tagProfilesEnumGuid {
73 const IEnumGUIDVtbl *Vtbl;
80 typedef struct tagEnumTfLanguageProfiles {
81 const IEnumTfLanguageProfilesVtbl *Vtbl;
86 WCHAR szwCurrentClsid[39];
92 ITfCategoryMgr *catmgr;
93 } EnumTfLanguageProfiles;
95 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut);
96 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut);
98 static inline InputProcessorProfiles *impl_from_ITfSourceVtbl(ITfSource *iface)
100 return (InputProcessorProfiles *)((char *)iface - FIELD_OFFSET(InputProcessorProfiles,SourceVtbl));
103 static void free_sink(InputProcessorProfilesSink *sink)
105 IUnknown_Release(sink->interfaces.pIUnknown);
106 HeapFree(GetProcessHeap(),0,sink);
109 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
111 struct list *cursor, *cursor2;
112 TRACE("destroying %p\n", This);
115 LIST_FOR_EACH_SAFE(cursor, cursor2, &This->LanguageProfileNotifySink)
117 InputProcessorProfilesSink* sink = LIST_ENTRY(cursor,InputProcessorProfilesSink,entry);
122 HeapFree(GetProcessHeap(),0,This);
125 static void add_userkey( REFCLSID rclsid, LANGID langid,
132 DWORD disposition = 0;
137 StringFromGUID2(rclsid, buf, 39);
138 StringFromGUID2(guidProfile, buf2, 39);
139 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
141 res = RegCreateKeyExW(HKEY_CURRENT_USER,fullkey, 0, NULL, 0,
142 KEY_READ | KEY_WRITE, NULL, &key, &disposition);
144 if (!res && disposition == REG_CREATED_NEW_KEY)
147 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
154 static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, LPVOID *ppvOut)
156 InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
159 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
163 else if (IsEqualIID(iid, &IID_ITfSource))
165 *ppvOut = &This->SourceVtbl;
170 IUnknown_AddRef(iface);
174 WARN("unsupported interface: %s\n", debugstr_guid(iid));
175 return E_NOINTERFACE;
178 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
180 InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
181 return InterlockedIncrement(&This->refCount);
184 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
186 InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
189 ret = InterlockedDecrement(&This->refCount);
191 InputProcessorProfiles_Destructor(This);
195 /*****************************************************
196 * ITfInputProcessorProfiles functions
197 *****************************************************/
198 static HRESULT WINAPI InputProcessorProfiles_Register(
199 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
201 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
206 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
208 StringFromGUID2(rclsid, buf, 39);
209 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
211 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, NULL, 0,
212 KEY_READ | KEY_WRITE, NULL, &tipkey, NULL) != ERROR_SUCCESS)
220 static HRESULT WINAPI InputProcessorProfiles_Unregister(
221 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
225 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
227 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
229 StringFromGUID2(rclsid, buf, 39);
230 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
232 RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
233 RegDeleteTreeW(HKEY_CURRENT_USER, fullkey);
238 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
239 ITfInputProcessorProfiles *iface, REFCLSID rclsid,
240 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
241 ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
248 DWORD disposition = 0;
250 static const WCHAR fmt2[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
251 static const WCHAR desc[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
252 static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
253 static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
255 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
257 TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
258 debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
259 debugstr_wn(pchIconFile,cchFile),uIconIndex);
261 StringFromGUID2(rclsid, buf, 39);
262 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
264 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
265 &tipkey ) != ERROR_SUCCESS)
268 StringFromGUID2(guidProfile, buf, 39);
269 sprintfW(fullkey,fmt2,szwLngp,langid,buf);
271 res = RegCreateKeyExW(tipkey,fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
272 NULL, &fmtkey, &disposition);
277 RegSetValueExW(fmtkey, desc, 0, REG_SZ, (LPBYTE)pchDesc, cchDesc * sizeof(WCHAR));
278 RegSetValueExW(fmtkey, icnf, 0, REG_SZ, (LPBYTE)pchIconFile, cchFile * sizeof(WCHAR));
279 RegSetValueExW(fmtkey, icni, 0, REG_DWORD, (LPBYTE)&uIconIndex, sizeof(DWORD));
280 if (disposition == REG_CREATED_NEW_KEY)
281 RegSetValueExW(fmtkey, szwEnable, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
284 add_userkey(rclsid, langid, guidProfile);
294 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
295 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
298 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
299 FIXME("STUB:(%p)\n",This);
303 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
304 ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
306 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
307 TRACE("(%p) %p\n",This,ppEnum);
308 return ProfilesEnumGuid_Constructor(ppEnum);
311 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
312 ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
313 CLSID *pclsid, GUID *pguidProfile)
315 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
316 FIXME("STUB:(%p)\n",This);
320 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
321 ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
322 REFGUID guidProfiles)
324 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
325 FIXME("STUB:(%p)\n",This);
329 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
330 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
331 REFGUID guidProfiles)
335 TF_LANGUAGEPROFILE LanguageProfile;
336 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
338 TRACE("(%p) %s %x %s\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfiles));
340 if (langid != This->currentLanguage) return E_INVALIDARG;
342 if (get_active_textservice(rclsid,NULL))
344 TRACE("Already Active\n");
348 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(iface, rclsid,
349 langid, guidProfiles, &enabled);
350 if (FAILED(hr) || !enabled)
352 TRACE("Not Enabled\n");
356 LanguageProfile.clsid = *rclsid;
357 LanguageProfile.langid = langid;
358 LanguageProfile.guidProfile = *guidProfiles;
360 hr = add_active_textservice(&LanguageProfile);
365 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
366 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
369 TF_LANGUAGEPROFILE profile;
370 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
372 TRACE("(%p) %s %p %p\n",This,debugstr_guid(rclsid),plangid,pguidProfile);
374 if (!rclsid || !plangid || !pguidProfile)
377 if (get_active_textservice(rclsid, &profile))
379 *plangid = profile.langid;
380 *pguidProfile = profile.guidProfile;
385 *pguidProfile = GUID_NULL;
390 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
391 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
392 REFGUID guidProfile, BSTR *pbstrProfile)
394 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
395 FIXME("STUB:(%p)\n",This);
399 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
400 ITfInputProcessorProfiles *iface, LANGID *plangid)
402 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
403 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
408 *plangid = This->currentLanguage;
413 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
414 ITfInputProcessorProfiles *iface, LANGID langid)
416 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
417 FIXME("STUB:(%p)\n",This);
421 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
422 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
424 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
425 FIXME("Semi-STUB:(%p)\n",This);
426 *ppLangId = CoTaskMemAlloc(sizeof(LANGID));
427 **ppLangId = This->currentLanguage;
432 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
433 ITfInputProcessorProfiles *iface, LANGID langid,
434 IEnumTfLanguageProfiles **ppEnum)
436 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
437 TRACE("(%p) %x %p\n",This,langid,ppEnum);
438 return EnumTfLanguageProfiles_Constructor(langid, ppEnum);
441 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
442 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
443 REFGUID guidProfile, BOOL fEnable)
451 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
452 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
454 StringFromGUID2(rclsid, buf, 39);
455 StringFromGUID2(guidProfile, buf2, 39);
456 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
458 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
462 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
471 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
472 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
473 REFGUID guidProfile, BOOL *pfEnable)
481 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
482 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
487 StringFromGUID2(rclsid, buf, 39);
488 StringFromGUID2(guidProfile, buf2, 39);
489 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
491 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
495 DWORD count = sizeof(DWORD);
496 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
500 if (res) /* Try Default */
502 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
506 DWORD count = sizeof(DWORD);
507 res = RegQueryValueExW(key, szwEnable, 0, NULL, (LPBYTE)pfEnable, &count);
518 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
519 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
520 REFGUID guidProfile, BOOL fEnable)
528 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
529 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
531 StringFromGUID2(rclsid, buf, 39);
532 StringFromGUID2(guidProfile, buf2, 39);
533 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
535 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
539 RegSetValueExW(key, szwEnable, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
548 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
549 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
550 REFGUID guidProfile, HKL hKL)
552 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
553 FIXME("STUB:(%p)\n",This);
558 static const ITfInputProcessorProfilesVtbl InputProcessorProfiles_InputProcessorProfilesVtbl =
560 InputProcessorProfiles_QueryInterface,
561 InputProcessorProfiles_AddRef,
562 InputProcessorProfiles_Release,
564 InputProcessorProfiles_Register,
565 InputProcessorProfiles_Unregister,
566 InputProcessorProfiles_AddLanguageProfile,
567 InputProcessorProfiles_RemoveLanguageProfile,
568 InputProcessorProfiles_EnumInputProcessorInfo,
569 InputProcessorProfiles_GetDefaultLanguageProfile,
570 InputProcessorProfiles_SetDefaultLanguageProfile,
571 InputProcessorProfiles_ActivateLanguageProfile,
572 InputProcessorProfiles_GetActiveLanguageProfile,
573 InputProcessorProfiles_GetLanguageProfileDescription,
574 InputProcessorProfiles_GetCurrentLanguage,
575 InputProcessorProfiles_ChangeCurrentLanguage,
576 InputProcessorProfiles_GetLanguageList,
577 InputProcessorProfiles_EnumLanguageProfiles,
578 InputProcessorProfiles_EnableLanguageProfile,
579 InputProcessorProfiles_IsEnabledLanguageProfile,
580 InputProcessorProfiles_EnableLanguageProfileByDefault,
581 InputProcessorProfiles_SubstituteKeyboardLayout
584 /*****************************************************
585 * ITfSource functions
586 *****************************************************/
587 static HRESULT WINAPI IPPSource_QueryInterface(ITfSource *iface, REFIID iid, LPVOID *ppvOut)
589 InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
590 return InputProcessorProfiles_QueryInterface((ITfInputProcessorProfiles *)This, iid, *ppvOut);
593 static ULONG WINAPI IPPSource_AddRef(ITfSource *iface)
595 InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
596 return InputProcessorProfiles_AddRef((ITfInputProcessorProfiles*)This);
599 static ULONG WINAPI IPPSource_Release(ITfSource *iface)
601 InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
602 return InputProcessorProfiles_Release((ITfInputProcessorProfiles *)This);
605 static WINAPI HRESULT IPPSource_AdviseSink(ITfSource *iface,
606 REFIID riid, IUnknown *punk, DWORD *pdwCookie)
608 InputProcessorProfilesSink *ipps;
609 InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
611 TRACE("(%p) %s %p %p\n",This,debugstr_guid(riid),punk,pdwCookie);
613 if (!riid || !punk || !pdwCookie)
616 if (IsEqualIID(riid, &IID_ITfLanguageProfileNotifySink))
618 ipps = HeapAlloc(GetProcessHeap(),0,sizeof(InputProcessorProfilesSink));
620 return E_OUTOFMEMORY;
621 if (FAILED(IUnknown_QueryInterface(punk, riid, (LPVOID *)&ipps->interfaces.pITfLanguageProfileNotifySink)))
623 HeapFree(GetProcessHeap(),0,ipps);
624 return CONNECT_E_CANNOTCONNECT;
626 list_add_head(&This->LanguageProfileNotifySink,&ipps->entry);
627 *pdwCookie = generate_Cookie(COOKIE_MAGIC_IPPSINK, ipps);
631 FIXME("(%p) Unhandled Sink: %s\n",This,debugstr_guid(riid));
635 TRACE("cookie %x\n",*pdwCookie);
640 static WINAPI HRESULT IPPSource_UnadviseSink(ITfSource *iface, DWORD pdwCookie)
642 InputProcessorProfilesSink *sink;
643 InputProcessorProfiles *This = impl_from_ITfSourceVtbl(iface);
645 TRACE("(%p) %x\n",This,pdwCookie);
647 if (get_Cookie_magic(pdwCookie)!=COOKIE_MAGIC_IPPSINK)
650 sink = (InputProcessorProfilesSink*)remove_Cookie(pdwCookie);
652 return CONNECT_E_NOCONNECTION;
654 list_remove(&sink->entry);
660 static const ITfSourceVtbl InputProcessorProfiles_SourceVtbl =
662 IPPSource_QueryInterface,
666 IPPSource_AdviseSink,
667 IPPSource_UnadviseSink,
670 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
672 InputProcessorProfiles *This;
674 return CLASS_E_NOAGGREGATION;
676 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
678 return E_OUTOFMEMORY;
680 This->InputProcessorProfilesVtbl= &InputProcessorProfiles_InputProcessorProfilesVtbl;
681 This->SourceVtbl = &InputProcessorProfiles_SourceVtbl;
683 This->currentLanguage = GetUserDefaultLCID();
685 list_init(&This->LanguageProfileNotifySink);
687 TRACE("returning %p\n", This);
688 *ppOut = (IUnknown *)This;
692 /**************************************************
693 * IEnumGUID implementaion for ITfInputProcessorProfiles::EnumInputProcessorInfo
694 **************************************************/
695 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid *This)
697 TRACE("destroying %p\n", This);
698 RegCloseKey(This->key);
699 HeapFree(GetProcessHeap(),0,This);
702 static HRESULT WINAPI ProfilesEnumGuid_QueryInterface(IEnumGUID *iface, REFIID iid, LPVOID *ppvOut)
704 ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
707 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumGUID))
714 IUnknown_AddRef(iface);
718 WARN("unsupported interface: %s\n", debugstr_guid(iid));
719 return E_NOINTERFACE;
722 static ULONG WINAPI ProfilesEnumGuid_AddRef(IEnumGUID *iface)
724 ProfilesEnumGuid *This = (ProfilesEnumGuid*)iface;
725 return InterlockedIncrement(&This->refCount);
728 static ULONG WINAPI ProfilesEnumGuid_Release(IEnumGUID *iface)
730 ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
733 ret = InterlockedDecrement(&This->refCount);
735 ProfilesEnumGuid_Destructor(This);
739 /*****************************************************
740 * IEnumGuid functions
741 *****************************************************/
742 static HRESULT WINAPI ProfilesEnumGuid_Next( LPENUMGUID iface,
743 ULONG celt, GUID *rgelt, ULONG *pceltFetched)
745 ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
748 TRACE("(%p)\n",This);
750 if (rgelt == NULL) return E_POINTER;
752 if (This->key) while (fetched < celt)
759 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
760 NULL, NULL, NULL, NULL);
761 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
762 ++(This->next_index);
764 hr = CLSIDFromString(catid, rgelt);
765 if (FAILED(hr)) continue;
771 if (pceltFetched) *pceltFetched = fetched;
772 return fetched == celt ? S_OK : S_FALSE;
775 static HRESULT WINAPI ProfilesEnumGuid_Skip( LPENUMGUID iface, ULONG celt)
777 ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
778 TRACE("(%p)\n",This);
780 This->next_index += celt;
784 static HRESULT WINAPI ProfilesEnumGuid_Reset( LPENUMGUID iface)
786 ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
787 TRACE("(%p)\n",This);
788 This->next_index = 0;
792 static HRESULT WINAPI ProfilesEnumGuid_Clone( LPENUMGUID iface,
795 ProfilesEnumGuid *This = (ProfilesEnumGuid *)iface;
798 TRACE("(%p)\n",This);
800 if (ppenum == NULL) return E_POINTER;
802 res = ProfilesEnumGuid_Constructor(ppenum);
805 ProfilesEnumGuid *new_This = (ProfilesEnumGuid *)*ppenum;
806 new_This->next_index = This->next_index;
811 static const IEnumGUIDVtbl IEnumGUID_Vtbl ={
812 ProfilesEnumGuid_QueryInterface,
813 ProfilesEnumGuid_AddRef,
814 ProfilesEnumGuid_Release,
816 ProfilesEnumGuid_Next,
817 ProfilesEnumGuid_Skip,
818 ProfilesEnumGuid_Reset,
819 ProfilesEnumGuid_Clone
822 static HRESULT ProfilesEnumGuid_Constructor(IEnumGUID **ppOut)
824 ProfilesEnumGuid *This;
826 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ProfilesEnumGuid));
828 return E_OUTOFMEMORY;
830 This->Vtbl= &IEnumGUID_Vtbl;
833 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
834 KEY_READ | KEY_WRITE, NULL, &This->key, NULL) != ERROR_SUCCESS)
837 TRACE("returning %p\n", This);
838 *ppOut = (IEnumGUID*)This;
842 /**************************************************
843 * IEnumTfLanguageProfiles implementaion
844 **************************************************/
845 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles *This)
847 TRACE("destroying %p\n", This);
848 RegCloseKey(This->tipkey);
850 RegCloseKey(This->langkey);
851 ITfCategoryMgr_Release(This->catmgr);
852 HeapFree(GetProcessHeap(),0,This);
855 static HRESULT WINAPI EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles *iface, REFIID iid, LPVOID *ppvOut)
857 EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
860 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IEnumTfLanguageProfiles))
867 IUnknown_AddRef(iface);
871 WARN("unsupported interface: %s\n", debugstr_guid(iid));
872 return E_NOINTERFACE;
875 static ULONG WINAPI EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles *iface)
877 EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles*)iface;
878 return InterlockedIncrement(&This->refCount);
881 static ULONG WINAPI EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles *iface)
883 EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
886 ret = InterlockedDecrement(&This->refCount);
888 EnumTfLanguageProfiles_Destructor(This);
892 /*****************************************************
893 * IEnumGuid functions
894 *****************************************************/
895 static INT next_LanguageProfile(EnumTfLanguageProfiles *This, CLSID clsid, TF_LANGUAGEPROFILE *tflp)
903 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
905 if (This->langkey == NULL)
907 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
908 res = RegOpenKeyExW(This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
911 This->langkey = NULL;
914 This->lang_index = 0;
916 res = RegEnumKeyExW(This->langkey, This->lang_index, profileid, &cName,
917 NULL, NULL, NULL, NULL);
918 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
920 RegCloseKey(This->langkey);
921 This->langkey = NULL;
924 ++(This->lang_index);
928 static const GUID * tipcats[3] = { &GUID_TFCAT_TIP_KEYBOARD,
929 &GUID_TFCAT_TIP_SPEECH,
930 &GUID_TFCAT_TIP_HANDWRITING };
931 res = CLSIDFromString(profileid, &profile);
932 if (FAILED(res)) return 0;
935 tflp->langid = This->langid;
936 tflp->fActive = get_active_textservice(&clsid, NULL);
937 tflp->guidProfile = profile;
938 if (ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
939 &tflp->catid, tipcats, 3) != S_OK)
940 ITfCategoryMgr_FindClosestCategory(This->catmgr, &clsid,
941 &tflp->catid, NULL, 0);
947 static HRESULT WINAPI EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles *iface,
948 ULONG ulCount, TF_LANGUAGEPROFILE *pProfile, ULONG *pcFetch)
950 EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
953 TRACE("(%p)\n",This);
955 if (pProfile == NULL) return E_POINTER;
957 if (This->tipkey) while (fetched < ulCount)
964 res = RegEnumKeyExW(This->tipkey, This->tip_index,
965 This->szwCurrentClsid, &cName, NULL, NULL, NULL, NULL);
966 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
968 hr = CLSIDFromString(This->szwCurrentClsid, &clsid);
969 if (FAILED(hr)) continue;
971 while ( fetched < ulCount)
973 INT res = next_LanguageProfile(This, clsid, pProfile);
986 if (pcFetch) *pcFetch = fetched;
987 return fetched == ulCount ? S_OK : S_FALSE;
990 static HRESULT WINAPI EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles* iface, ULONG celt)
992 EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
993 FIXME("STUB (%p)\n",This);
997 static HRESULT WINAPI EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles* iface)
999 EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
1000 TRACE("(%p)\n",This);
1001 This->tip_index = 0;
1003 RegCloseKey(This->langkey);
1004 This->langkey = NULL;
1005 This->lang_index = 0;
1009 static HRESULT WINAPI EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles *iface,
1010 IEnumTfLanguageProfiles **ppenum)
1012 EnumTfLanguageProfiles *This = (EnumTfLanguageProfiles *)iface;
1015 TRACE("(%p)\n",This);
1017 if (ppenum == NULL) return E_POINTER;
1019 res = EnumTfLanguageProfiles_Constructor(This->langid, ppenum);
1022 EnumTfLanguageProfiles *new_This = (EnumTfLanguageProfiles *)*ppenum;
1023 new_This->tip_index = This->tip_index;
1024 lstrcpynW(new_This->szwCurrentClsid,This->szwCurrentClsid,39);
1029 static const WCHAR fmt[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1031 sprintfW(fullkey,fmt,This->szwCurrentClsid,szwLngp,This->langid);
1032 res = RegOpenKeyExW(new_This->tipkey, fullkey, 0, KEY_READ | KEY_WRITE, &This->langkey);
1033 new_This->lang_index = This->lang_index;
1039 static const IEnumTfLanguageProfilesVtbl IEnumTfLanguageProfiles_Vtbl ={
1040 EnumTfLanguageProfiles_QueryInterface,
1041 EnumTfLanguageProfiles_AddRef,
1042 EnumTfLanguageProfiles_Release,
1044 EnumTfLanguageProfiles_Clone,
1045 EnumTfLanguageProfiles_Next,
1046 EnumTfLanguageProfiles_Reset,
1047 EnumTfLanguageProfiles_Skip
1050 static HRESULT EnumTfLanguageProfiles_Constructor(LANGID langid, IEnumTfLanguageProfiles **ppOut)
1053 EnumTfLanguageProfiles *This;
1055 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EnumTfLanguageProfiles));
1057 return E_OUTOFMEMORY;
1059 This->Vtbl= &IEnumTfLanguageProfiles_Vtbl;
1061 This->langid = langid;
1063 hr = CategoryMgr_Constructor(NULL,(IUnknown**)&This->catmgr);
1066 HeapFree(GetProcessHeap(),0,This);
1070 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szwSystemTIPKey, 0, NULL, 0,
1071 KEY_READ | KEY_WRITE, NULL, &This->tipkey, NULL) != ERROR_SUCCESS)
1074 TRACE("returning %p\n", This);
1075 *ppOut = (IEnumTfLanguageProfiles*)This;