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 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
{
58 /* InputProcessorProfile Sinks */
60 ITfLanguageProfileNotifySink
*pITfLanguageProfileNotifySink
;
62 } InputProcessorProfilesSink
;
64 typedef struct tagInputProcessorProfiles
{
65 ITfInputProcessorProfiles ITfInputProcessorProfiles_iface
;
66 ITfSource ITfSource_iface
;
67 /* const ITfInputProcessorProfileMgrVtbl *InputProcessorProfileMgrVtbl; */
68 /* const ITfInputProcessorProfilesExVtbl *InputProcessorProfilesExVtbl; */
69 /* const ITfInputProcessorProfileSubstituteLayoutVtbl *InputProcessorProfileSubstituteLayoutVtbl; */
72 LANGID currentLanguage
;
74 struct list LanguageProfileNotifySink
;
75 } InputProcessorProfiles
;
77 typedef struct tagProfilesEnumGuid
{
78 IEnumGUID IEnumGUID_iface
;
85 typedef struct tagEnumTfLanguageProfiles
{
86 IEnumTfLanguageProfiles IEnumTfLanguageProfiles_iface
;
91 WCHAR szwCurrentClsid
[39];
97 ITfCategoryMgr
*catmgr
;
98 } EnumTfLanguageProfiles
;
100 static HRESULT
ProfilesEnumGuid_Constructor(IEnumGUID
**ppOut
);
101 static HRESULT
EnumTfLanguageProfiles_Constructor(LANGID langid
, IEnumTfLanguageProfiles
**ppOut
);
103 static inline InputProcessorProfiles
*impl_from_ITfInputProcessorProfiles(ITfInputProcessorProfiles
*iface
)
105 return CONTAINING_RECORD(iface
, InputProcessorProfiles
, ITfInputProcessorProfiles_iface
);
108 static inline InputProcessorProfiles
*impl_from_ITfSource(ITfSource
*iface
)
110 return CONTAINING_RECORD(iface
, InputProcessorProfiles
, ITfSource_iface
);
113 static inline ProfilesEnumGuid
*impl_from_IEnumGUID(IEnumGUID
*iface
)
115 return CONTAINING_RECORD(iface
, ProfilesEnumGuid
, IEnumGUID_iface
);
118 static inline EnumTfLanguageProfiles
*impl_from_IEnumTfLanguageProfiles(IEnumTfLanguageProfiles
*iface
)
120 return CONTAINING_RECORD(iface
, EnumTfLanguageProfiles
, IEnumTfLanguageProfiles_iface
);
123 static void free_sink(InputProcessorProfilesSink
*sink
)
125 IUnknown_Release(sink
->interfaces
.pIUnknown
);
126 HeapFree(GetProcessHeap(),0,sink
);
129 static void InputProcessorProfiles_Destructor(InputProcessorProfiles
*This
)
131 struct list
*cursor
, *cursor2
;
132 TRACE("destroying %p\n", This
);
135 LIST_FOR_EACH_SAFE(cursor
, cursor2
, &This
->LanguageProfileNotifySink
)
137 InputProcessorProfilesSink
* sink
= LIST_ENTRY(cursor
,InputProcessorProfilesSink
,entry
);
142 HeapFree(GetProcessHeap(),0,This
);
145 static void add_userkey( REFCLSID rclsid
, LANGID langid
,
152 DWORD disposition
= 0;
157 StringFromGUID2(rclsid
, buf
, 39);
158 StringFromGUID2(guidProfile
, buf2
, 39);
159 sprintfW(fullkey
,szwFullLangfmt
,szwSystemTIPKey
,buf
,szwLngp
,langid
,buf2
);
161 res
= RegCreateKeyExW(HKEY_CURRENT_USER
,fullkey
, 0, NULL
, 0,
162 KEY_READ
| KEY_WRITE
, NULL
, &key
, &disposition
);
164 if (!res
&& disposition
== REG_CREATED_NEW_KEY
)
167 RegSetValueExW(key
, szwEnable
, 0, REG_DWORD
, (LPBYTE
)&zero
, sizeof(DWORD
));
174 static HRESULT WINAPI
InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles
*iface
, REFIID iid
, LPVOID
*ppvOut
)
176 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
179 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfInputProcessorProfiles
))
181 *ppvOut
= &This
->ITfInputProcessorProfiles_iface
;
183 else if (IsEqualIID(iid
, &IID_ITfSource
))
185 *ppvOut
= &This
->ITfSource_iface
;
190 ITfInputProcessorProfiles_AddRef(iface
);
194 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
195 return E_NOINTERFACE
;
198 static ULONG WINAPI
InputProcessorProfiles_AddRef(ITfInputProcessorProfiles
*iface
)
200 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
201 return InterlockedIncrement(&This
->refCount
);
204 static ULONG WINAPI
InputProcessorProfiles_Release(ITfInputProcessorProfiles
*iface
)
206 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
209 ret
= InterlockedDecrement(&This
->refCount
);
211 InputProcessorProfiles_Destructor(This
);
215 /*****************************************************
216 * ITfInputProcessorProfiles functions
217 *****************************************************/
218 static HRESULT WINAPI
InputProcessorProfiles_Register(
219 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
)
221 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
226 TRACE("(%p) %s\n",This
,debugstr_guid(rclsid
));
228 StringFromGUID2(rclsid
, buf
, 39);
229 sprintfW(fullkey
,szwTipfmt
,szwSystemTIPKey
,buf
);
231 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, NULL
, 0,
232 KEY_READ
| KEY_WRITE
, NULL
, &tipkey
, NULL
) != ERROR_SUCCESS
)
240 static HRESULT WINAPI
InputProcessorProfiles_Unregister(
241 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
)
243 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
247 TRACE("(%p) %s\n",This
,debugstr_guid(rclsid
));
249 StringFromGUID2(rclsid
, buf
, 39);
250 sprintfW(fullkey
,szwTipfmt
,szwSystemTIPKey
,buf
);
252 RegDeleteTreeW(HKEY_LOCAL_MACHINE
, fullkey
);
253 RegDeleteTreeW(HKEY_CURRENT_USER
, fullkey
);
258 static HRESULT WINAPI
InputProcessorProfiles_AddLanguageProfile(
259 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
,
260 LANGID langid
, REFGUID guidProfile
, const WCHAR
*pchDesc
,
261 ULONG cchDesc
, const WCHAR
*pchIconFile
, ULONG cchFile
,
264 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
269 DWORD disposition
= 0;
271 static const WCHAR fmt2
[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
272 static const WCHAR desc
[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
273 static const WCHAR icnf
[] = {'I','c','o','n','F','i','l','e',0};
274 static const WCHAR icni
[] = {'I','c','o','n','I','n','d','e','x',0};
276 TRACE("(%p) %s %x %s %s %s %i\n",This
,debugstr_guid(rclsid
), langid
,
277 debugstr_guid(guidProfile
), debugstr_wn(pchDesc
,cchDesc
),
278 debugstr_wn(pchIconFile
,cchFile
),uIconIndex
);
280 StringFromGUID2(rclsid
, buf
, 39);
281 sprintfW(fullkey
,szwTipfmt
,szwSystemTIPKey
,buf
);
283 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, KEY_READ
| KEY_WRITE
,
284 &tipkey
) != ERROR_SUCCESS
)
287 StringFromGUID2(guidProfile
, buf
, 39);
288 sprintfW(fullkey
,fmt2
,szwLngp
,langid
,buf
);
290 res
= RegCreateKeyExW(tipkey
,fullkey
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
291 NULL
, &fmtkey
, &disposition
);
296 RegSetValueExW(fmtkey
, desc
, 0, REG_SZ
, (const BYTE
*)pchDesc
, cchDesc
* sizeof(WCHAR
));
297 RegSetValueExW(fmtkey
, icnf
, 0, REG_SZ
, (const BYTE
*)pchIconFile
, cchFile
* sizeof(WCHAR
));
298 RegSetValueExW(fmtkey
, icni
, 0, REG_DWORD
, (LPBYTE
)&uIconIndex
, sizeof(DWORD
));
299 if (disposition
== REG_CREATED_NEW_KEY
)
300 RegSetValueExW(fmtkey
, szwEnable
, 0, REG_DWORD
, (LPBYTE
)&zero
, sizeof(DWORD
));
303 add_userkey(rclsid
, langid
, guidProfile
);
313 static HRESULT WINAPI
InputProcessorProfiles_RemoveLanguageProfile(
314 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID langid
,
317 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
318 FIXME("STUB:(%p)\n",This
);
322 static HRESULT WINAPI
InputProcessorProfiles_EnumInputProcessorInfo(
323 ITfInputProcessorProfiles
*iface
, IEnumGUID
**ppEnum
)
325 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
326 TRACE("(%p) %p\n",This
,ppEnum
);
327 return ProfilesEnumGuid_Constructor(ppEnum
);
330 static HRESULT WINAPI
InputProcessorProfiles_GetDefaultLanguageProfile(
331 ITfInputProcessorProfiles
*iface
, LANGID langid
, REFGUID catid
,
332 CLSID
*pclsid
, GUID
*pguidProfile
)
334 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
341 TRACE("%p) %x %s %p %p\n",This
, langid
, debugstr_guid(catid
),pclsid
,pguidProfile
);
343 if (!catid
|| !pclsid
|| !pguidProfile
)
346 StringFromGUID2(catid
, buf
, 39);
347 sprintfW(fullkey
, szwDefaultFmt
, szwSystemCTFKey
, szwAssemblies
, langid
, buf
);
349 if (RegOpenKeyExW(HKEY_CURRENT_USER
, fullkey
, 0, KEY_READ
| KEY_WRITE
,
350 &hkey
) != ERROR_SUCCESS
)
354 res
= RegQueryValueExW(hkey
, szwDefault
, 0, NULL
, (LPBYTE
)buf
, &count
);
355 if (res
!= ERROR_SUCCESS
)
360 CLSIDFromString(buf
,pclsid
);
362 res
= RegQueryValueExW(hkey
, szwProfile
, 0, NULL
, (LPBYTE
)buf
, &count
);
363 if (res
== ERROR_SUCCESS
)
364 CLSIDFromString(buf
,pguidProfile
);
371 static HRESULT WINAPI
InputProcessorProfiles_SetDefaultLanguageProfile(
372 ITfInputProcessorProfiles
*iface
, LANGID langid
, REFCLSID rclsid
,
373 REFGUID guidProfiles
)
375 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
381 ITfCategoryMgr
*catmgr
;
382 static const GUID
* tipcats
[3] = { &GUID_TFCAT_TIP_KEYBOARD
,
383 &GUID_TFCAT_TIP_SPEECH
,
384 &GUID_TFCAT_TIP_HANDWRITING
};
386 TRACE("%p) %x %s %s\n",This
, langid
, debugstr_guid(rclsid
),debugstr_guid(guidProfiles
));
388 if (!rclsid
|| !guidProfiles
)
391 hr
= CategoryMgr_Constructor(NULL
,(IUnknown
**)&catmgr
);
396 if (ITfCategoryMgr_FindClosestCategory(catmgr
, rclsid
,
397 &catid
, tipcats
, 3) != S_OK
)
398 hr
= ITfCategoryMgr_FindClosestCategory(catmgr
, rclsid
,
400 ITfCategoryMgr_Release(catmgr
);
405 StringFromGUID2(&catid
, buf
, 39);
406 sprintfW(fullkey
, szwDefaultFmt
, szwSystemCTFKey
, szwAssemblies
, langid
, buf
);
408 if (RegCreateKeyExW(HKEY_CURRENT_USER
, fullkey
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
409 NULL
, &hkey
, NULL
) != ERROR_SUCCESS
)
412 StringFromGUID2(rclsid
, buf
, 39);
413 RegSetValueExW(hkey
, szwDefault
, 0, REG_SZ
, (LPBYTE
)buf
, sizeof(buf
));
414 StringFromGUID2(guidProfiles
, buf
, 39);
415 RegSetValueExW(hkey
, szwProfile
, 0, REG_SZ
, (LPBYTE
)buf
, sizeof(buf
));
421 static HRESULT WINAPI
InputProcessorProfiles_ActivateLanguageProfile(
422 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID langid
,
423 REFGUID guidProfiles
)
425 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
428 TF_LANGUAGEPROFILE LanguageProfile
;
430 TRACE("(%p) %s %x %s\n",This
,debugstr_guid(rclsid
),langid
,debugstr_guid(guidProfiles
));
432 if (langid
!= This
->currentLanguage
) return E_INVALIDARG
;
434 if (get_active_textservice(rclsid
,NULL
))
436 TRACE("Already Active\n");
440 hr
= ITfInputProcessorProfiles_IsEnabledLanguageProfile(iface
, rclsid
,
441 langid
, guidProfiles
, &enabled
);
442 if (FAILED(hr
) || !enabled
)
444 TRACE("Not Enabled\n");
448 LanguageProfile
.clsid
= *rclsid
;
449 LanguageProfile
.langid
= langid
;
450 LanguageProfile
.guidProfile
= *guidProfiles
;
452 hr
= add_active_textservice(&LanguageProfile
);
457 static HRESULT WINAPI
InputProcessorProfiles_GetActiveLanguageProfile(
458 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID
*plangid
,
461 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
462 TF_LANGUAGEPROFILE profile
;
464 TRACE("(%p) %s %p %p\n",This
,debugstr_guid(rclsid
),plangid
,pguidProfile
);
466 if (!rclsid
|| !plangid
|| !pguidProfile
)
469 if (get_active_textservice(rclsid
, &profile
))
471 *plangid
= profile
.langid
;
472 *pguidProfile
= profile
.guidProfile
;
477 *pguidProfile
= GUID_NULL
;
482 static HRESULT WINAPI
InputProcessorProfiles_GetLanguageProfileDescription(
483 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID langid
,
484 REFGUID guidProfile
, BSTR
*pbstrProfile
)
486 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
487 FIXME("STUB:(%p)\n",This
);
491 static HRESULT WINAPI
InputProcessorProfiles_GetCurrentLanguage(
492 ITfInputProcessorProfiles
*iface
, LANGID
*plangid
)
494 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
495 TRACE("(%p) 0x%x\n",This
,This
->currentLanguage
);
500 *plangid
= This
->currentLanguage
;
505 static HRESULT WINAPI
InputProcessorProfiles_ChangeCurrentLanguage(
506 ITfInputProcessorProfiles
*iface
, LANGID langid
)
508 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
512 FIXME("STUB:(%p)\n",This
);
514 LIST_FOR_EACH(cursor
, &This
->LanguageProfileNotifySink
)
516 InputProcessorProfilesSink
* sink
= LIST_ENTRY(cursor
,InputProcessorProfilesSink
,entry
);
518 ITfLanguageProfileNotifySink_OnLanguageChange(sink
->interfaces
.pITfLanguageProfileNotifySink
, langid
, &accept
);
523 /* TODO: On successful language change call OnLanguageChanged sink */
527 static HRESULT WINAPI
InputProcessorProfiles_GetLanguageList(
528 ITfInputProcessorProfiles
*iface
, LANGID
**ppLangId
, ULONG
*pulCount
)
530 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
531 FIXME("Semi-STUB:(%p)\n",This
);
532 *ppLangId
= CoTaskMemAlloc(sizeof(LANGID
));
533 **ppLangId
= This
->currentLanguage
;
538 static HRESULT WINAPI
InputProcessorProfiles_EnumLanguageProfiles(
539 ITfInputProcessorProfiles
*iface
, LANGID langid
,
540 IEnumTfLanguageProfiles
**ppEnum
)
542 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
543 TRACE("(%p) %x %p\n",This
,langid
,ppEnum
);
544 return EnumTfLanguageProfiles_Constructor(langid
, ppEnum
);
547 static HRESULT WINAPI
InputProcessorProfiles_EnableLanguageProfile(
548 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID langid
,
549 REFGUID guidProfile
, BOOL fEnable
)
551 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
558 TRACE("(%p) %s %x %s %i\n",This
, debugstr_guid(rclsid
), langid
, debugstr_guid(guidProfile
), fEnable
);
560 StringFromGUID2(rclsid
, buf
, 39);
561 StringFromGUID2(guidProfile
, buf2
, 39);
562 sprintfW(fullkey
,szwFullLangfmt
,szwSystemTIPKey
,buf
,szwLngp
,langid
,buf2
);
564 res
= RegOpenKeyExW(HKEY_CURRENT_USER
, fullkey
, 0, KEY_READ
| KEY_WRITE
, &key
);
568 RegSetValueExW(key
, szwEnable
, 0, REG_DWORD
, (LPBYTE
)&fEnable
, sizeof(DWORD
));
577 static HRESULT WINAPI
InputProcessorProfiles_IsEnabledLanguageProfile(
578 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID langid
,
579 REFGUID guidProfile
, BOOL
*pfEnable
)
581 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
588 TRACE("(%p) %s, %i, %s, %p\n",This
,debugstr_guid(rclsid
),langid
,debugstr_guid(guidProfile
),pfEnable
);
593 StringFromGUID2(rclsid
, buf
, 39);
594 StringFromGUID2(guidProfile
, buf2
, 39);
595 sprintfW(fullkey
,szwFullLangfmt
,szwSystemTIPKey
,buf
,szwLngp
,langid
,buf2
);
597 res
= RegOpenKeyExW(HKEY_CURRENT_USER
, fullkey
, 0, KEY_READ
| KEY_WRITE
, &key
);
601 DWORD count
= sizeof(DWORD
);
602 res
= RegQueryValueExW(key
, szwEnable
, 0, NULL
, (LPBYTE
)pfEnable
, &count
);
606 if (res
) /* Try Default */
608 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, fullkey
, 0, KEY_READ
| KEY_WRITE
, &key
);
612 DWORD count
= sizeof(DWORD
);
613 res
= RegQueryValueExW(key
, szwEnable
, 0, NULL
, (LPBYTE
)pfEnable
, &count
);
624 static HRESULT WINAPI
InputProcessorProfiles_EnableLanguageProfileByDefault(
625 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID langid
,
626 REFGUID guidProfile
, BOOL fEnable
)
628 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
635 TRACE("(%p) %s %x %s %i\n",This
,debugstr_guid(rclsid
),langid
,debugstr_guid(guidProfile
),fEnable
);
637 StringFromGUID2(rclsid
, buf
, 39);
638 StringFromGUID2(guidProfile
, buf2
, 39);
639 sprintfW(fullkey
,szwFullLangfmt
,szwSystemTIPKey
,buf
,szwLngp
,langid
,buf2
);
641 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, fullkey
, 0, KEY_READ
| KEY_WRITE
, &key
);
645 RegSetValueExW(key
, szwEnable
, 0, REG_DWORD
, (LPBYTE
)&fEnable
, sizeof(DWORD
));
654 static HRESULT WINAPI
InputProcessorProfiles_SubstituteKeyboardLayout(
655 ITfInputProcessorProfiles
*iface
, REFCLSID rclsid
, LANGID langid
,
656 REFGUID guidProfile
, HKL hKL
)
658 InputProcessorProfiles
*This
= impl_from_ITfInputProcessorProfiles(iface
);
659 FIXME("STUB:(%p)\n",This
);
663 static const ITfInputProcessorProfilesVtbl InputProcessorProfilesVtbl
=
665 InputProcessorProfiles_QueryInterface
,
666 InputProcessorProfiles_AddRef
,
667 InputProcessorProfiles_Release
,
668 InputProcessorProfiles_Register
,
669 InputProcessorProfiles_Unregister
,
670 InputProcessorProfiles_AddLanguageProfile
,
671 InputProcessorProfiles_RemoveLanguageProfile
,
672 InputProcessorProfiles_EnumInputProcessorInfo
,
673 InputProcessorProfiles_GetDefaultLanguageProfile
,
674 InputProcessorProfiles_SetDefaultLanguageProfile
,
675 InputProcessorProfiles_ActivateLanguageProfile
,
676 InputProcessorProfiles_GetActiveLanguageProfile
,
677 InputProcessorProfiles_GetLanguageProfileDescription
,
678 InputProcessorProfiles_GetCurrentLanguage
,
679 InputProcessorProfiles_ChangeCurrentLanguage
,
680 InputProcessorProfiles_GetLanguageList
,
681 InputProcessorProfiles_EnumLanguageProfiles
,
682 InputProcessorProfiles_EnableLanguageProfile
,
683 InputProcessorProfiles_IsEnabledLanguageProfile
,
684 InputProcessorProfiles_EnableLanguageProfileByDefault
,
685 InputProcessorProfiles_SubstituteKeyboardLayout
688 /*****************************************************
689 * ITfSource functions
690 *****************************************************/
691 static HRESULT WINAPI
IPPSource_QueryInterface(ITfSource
*iface
, REFIID iid
, LPVOID
*ppvOut
)
693 InputProcessorProfiles
*This
= impl_from_ITfSource(iface
);
694 return ITfInputProcessorProfiles_QueryInterface(&This
->ITfInputProcessorProfiles_iface
, iid
, ppvOut
);
697 static ULONG WINAPI
IPPSource_AddRef(ITfSource
*iface
)
699 InputProcessorProfiles
*This
= impl_from_ITfSource(iface
);
700 return ITfInputProcessorProfiles_AddRef(&This
->ITfInputProcessorProfiles_iface
);
703 static ULONG WINAPI
IPPSource_Release(ITfSource
*iface
)
705 InputProcessorProfiles
*This
= impl_from_ITfSource(iface
);
706 return ITfInputProcessorProfiles_Release(&This
->ITfInputProcessorProfiles_iface
);
709 static HRESULT WINAPI
IPPSource_AdviseSink(ITfSource
*iface
,
710 REFIID riid
, IUnknown
*punk
, DWORD
*pdwCookie
)
712 InputProcessorProfiles
*This
= impl_from_ITfSource(iface
);
713 InputProcessorProfilesSink
*ipps
;
715 TRACE("(%p) %s %p %p\n",This
,debugstr_guid(riid
),punk
,pdwCookie
);
717 if (!riid
|| !punk
|| !pdwCookie
)
720 if (IsEqualIID(riid
, &IID_ITfLanguageProfileNotifySink
))
722 ipps
= HeapAlloc(GetProcessHeap(),0,sizeof(InputProcessorProfilesSink
));
724 return E_OUTOFMEMORY
;
725 if (FAILED(IUnknown_QueryInterface(punk
, riid
, (LPVOID
*)&ipps
->interfaces
.pITfLanguageProfileNotifySink
)))
727 HeapFree(GetProcessHeap(),0,ipps
);
728 return CONNECT_E_CANNOTCONNECT
;
730 list_add_head(&This
->LanguageProfileNotifySink
,&ipps
->entry
);
731 *pdwCookie
= generate_Cookie(COOKIE_MAGIC_IPPSINK
, ipps
);
735 FIXME("(%p) Unhandled Sink: %s\n",This
,debugstr_guid(riid
));
739 TRACE("cookie %x\n",*pdwCookie
);
744 static HRESULT WINAPI
IPPSource_UnadviseSink(ITfSource
*iface
, DWORD pdwCookie
)
746 InputProcessorProfiles
*This
= impl_from_ITfSource(iface
);
747 InputProcessorProfilesSink
*sink
;
749 TRACE("(%p) %x\n",This
,pdwCookie
);
751 if (get_Cookie_magic(pdwCookie
)!=COOKIE_MAGIC_IPPSINK
)
754 sink
= remove_Cookie(pdwCookie
);
756 return CONNECT_E_NOCONNECTION
;
758 list_remove(&sink
->entry
);
764 static const ITfSourceVtbl InputProcessorProfilesSourceVtbl
=
766 IPPSource_QueryInterface
,
769 IPPSource_AdviseSink
,
770 IPPSource_UnadviseSink
,
773 HRESULT
InputProcessorProfiles_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
775 InputProcessorProfiles
*This
;
777 return CLASS_E_NOAGGREGATION
;
779 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(InputProcessorProfiles
));
781 return E_OUTOFMEMORY
;
783 This
->ITfInputProcessorProfiles_iface
.lpVtbl
= &InputProcessorProfilesVtbl
;
784 This
->ITfSource_iface
.lpVtbl
= &InputProcessorProfilesSourceVtbl
;
786 This
->currentLanguage
= GetUserDefaultLCID();
788 list_init(&This
->LanguageProfileNotifySink
);
790 *ppOut
= (IUnknown
*)&This
->ITfInputProcessorProfiles_iface
;
791 TRACE("returning %p\n", *ppOut
);
795 /**************************************************
796 * IEnumGUID implementation for ITfInputProcessorProfiles::EnumInputProcessorInfo
797 **************************************************/
798 static void ProfilesEnumGuid_Destructor(ProfilesEnumGuid
*This
)
800 TRACE("destroying %p\n", This
);
801 RegCloseKey(This
->key
);
802 HeapFree(GetProcessHeap(),0,This
);
805 static HRESULT WINAPI
ProfilesEnumGuid_QueryInterface(IEnumGUID
*iface
, REFIID iid
, LPVOID
*ppvOut
)
807 ProfilesEnumGuid
*This
= impl_from_IEnumGUID(iface
);
810 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_IEnumGUID
))
812 *ppvOut
= &This
->IEnumGUID_iface
;
817 IEnumGUID_AddRef(iface
);
821 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
822 return E_NOINTERFACE
;
825 static ULONG WINAPI
ProfilesEnumGuid_AddRef(IEnumGUID
*iface
)
827 ProfilesEnumGuid
*This
= impl_from_IEnumGUID(iface
);
828 return InterlockedIncrement(&This
->refCount
);
831 static ULONG WINAPI
ProfilesEnumGuid_Release(IEnumGUID
*iface
)
833 ProfilesEnumGuid
*This
= impl_from_IEnumGUID(iface
);
836 ret
= InterlockedDecrement(&This
->refCount
);
838 ProfilesEnumGuid_Destructor(This
);
842 /*****************************************************
843 * IEnumGuid functions
844 *****************************************************/
845 static HRESULT WINAPI
ProfilesEnumGuid_Next( LPENUMGUID iface
,
846 ULONG celt
, GUID
*rgelt
, ULONG
*pceltFetched
)
848 ProfilesEnumGuid
*This
= impl_from_IEnumGUID(iface
);
851 TRACE("(%p)\n",This
);
853 if (rgelt
== NULL
) return E_POINTER
;
855 if (This
->key
) while (fetched
< celt
)
862 res
= RegEnumKeyExW(This
->key
, This
->next_index
, catid
, &cName
,
863 NULL
, NULL
, NULL
, NULL
);
864 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
865 ++(This
->next_index
);
867 hr
= CLSIDFromString(catid
, rgelt
);
868 if (FAILED(hr
)) continue;
874 if (pceltFetched
) *pceltFetched
= fetched
;
875 return fetched
== celt
? S_OK
: S_FALSE
;
878 static HRESULT WINAPI
ProfilesEnumGuid_Skip( LPENUMGUID iface
, ULONG celt
)
880 ProfilesEnumGuid
*This
= impl_from_IEnumGUID(iface
);
881 TRACE("(%p)\n",This
);
883 This
->next_index
+= celt
;
887 static HRESULT WINAPI
ProfilesEnumGuid_Reset( LPENUMGUID iface
)
889 ProfilesEnumGuid
*This
= impl_from_IEnumGUID(iface
);
890 TRACE("(%p)\n",This
);
891 This
->next_index
= 0;
895 static HRESULT WINAPI
ProfilesEnumGuid_Clone( LPENUMGUID iface
,
898 ProfilesEnumGuid
*This
= impl_from_IEnumGUID(iface
);
901 TRACE("(%p)\n",This
);
903 if (ppenum
== NULL
) return E_POINTER
;
905 res
= ProfilesEnumGuid_Constructor(ppenum
);
908 ProfilesEnumGuid
*new_This
= impl_from_IEnumGUID(*ppenum
);
909 new_This
->next_index
= This
->next_index
;
914 static const IEnumGUIDVtbl EnumGUIDVtbl
=
916 ProfilesEnumGuid_QueryInterface
,
917 ProfilesEnumGuid_AddRef
,
918 ProfilesEnumGuid_Release
,
919 ProfilesEnumGuid_Next
,
920 ProfilesEnumGuid_Skip
,
921 ProfilesEnumGuid_Reset
,
922 ProfilesEnumGuid_Clone
925 static HRESULT
ProfilesEnumGuid_Constructor(IEnumGUID
**ppOut
)
927 ProfilesEnumGuid
*This
;
929 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ProfilesEnumGuid
));
931 return E_OUTOFMEMORY
;
933 This
->IEnumGUID_iface
.lpVtbl
= &EnumGUIDVtbl
;
936 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, szwSystemTIPKey
, 0, NULL
, 0,
937 KEY_READ
| KEY_WRITE
, NULL
, &This
->key
, NULL
) != ERROR_SUCCESS
)
939 HeapFree(GetProcessHeap(), 0, This
);
943 *ppOut
= &This
->IEnumGUID_iface
;
944 TRACE("returning %p\n", *ppOut
);
948 /**************************************************
949 * IEnumTfLanguageProfiles implementation
950 **************************************************/
951 static void EnumTfLanguageProfiles_Destructor(EnumTfLanguageProfiles
*This
)
953 TRACE("destroying %p\n", This
);
954 RegCloseKey(This
->tipkey
);
956 RegCloseKey(This
->langkey
);
957 ITfCategoryMgr_Release(This
->catmgr
);
958 HeapFree(GetProcessHeap(),0,This
);
961 static HRESULT WINAPI
EnumTfLanguageProfiles_QueryInterface(IEnumTfLanguageProfiles
*iface
, REFIID iid
, LPVOID
*ppvOut
)
963 EnumTfLanguageProfiles
*This
= impl_from_IEnumTfLanguageProfiles(iface
);
967 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_IEnumTfLanguageProfiles
))
969 *ppvOut
= &This
->IEnumTfLanguageProfiles_iface
;
974 IEnumTfLanguageProfiles_AddRef(iface
);
978 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
979 return E_NOINTERFACE
;
982 static ULONG WINAPI
EnumTfLanguageProfiles_AddRef(IEnumTfLanguageProfiles
*iface
)
984 EnumTfLanguageProfiles
*This
= impl_from_IEnumTfLanguageProfiles(iface
);
985 return InterlockedIncrement(&This
->refCount
);
988 static ULONG WINAPI
EnumTfLanguageProfiles_Release(IEnumTfLanguageProfiles
*iface
)
990 EnumTfLanguageProfiles
*This
= impl_from_IEnumTfLanguageProfiles(iface
);
993 ret
= InterlockedDecrement(&This
->refCount
);
995 EnumTfLanguageProfiles_Destructor(This
);
999 /*****************************************************
1000 * IEnumGuid functions
1001 *****************************************************/
1002 static INT
next_LanguageProfile(EnumTfLanguageProfiles
*This
, CLSID clsid
, TF_LANGUAGEPROFILE
*tflp
)
1006 WCHAR profileid
[39];
1010 static const WCHAR fmt
[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1012 if (This
->langkey
== NULL
)
1014 sprintfW(fullkey
,fmt
,This
->szwCurrentClsid
,szwLngp
,This
->langid
);
1015 res
= RegOpenKeyExW(This
->tipkey
, fullkey
, 0, KEY_READ
| KEY_WRITE
, &This
->langkey
);
1018 This
->langkey
= NULL
;
1021 This
->lang_index
= 0;
1023 res
= RegEnumKeyExW(This
->langkey
, This
->lang_index
, profileid
, &cName
,
1024 NULL
, NULL
, NULL
, NULL
);
1025 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
1027 RegCloseKey(This
->langkey
);
1028 This
->langkey
= NULL
;
1031 ++(This
->lang_index
);
1035 static const GUID
* tipcats
[3] = { &GUID_TFCAT_TIP_KEYBOARD
,
1036 &GUID_TFCAT_TIP_SPEECH
,
1037 &GUID_TFCAT_TIP_HANDWRITING
};
1038 res
= CLSIDFromString(profileid
, &profile
);
1039 if (FAILED(res
)) return 0;
1041 tflp
->clsid
= clsid
;
1042 tflp
->langid
= This
->langid
;
1043 tflp
->fActive
= get_active_textservice(&clsid
, NULL
);
1044 tflp
->guidProfile
= profile
;
1045 if (ITfCategoryMgr_FindClosestCategory(This
->catmgr
, &clsid
,
1046 &tflp
->catid
, tipcats
, 3) != S_OK
)
1047 ITfCategoryMgr_FindClosestCategory(This
->catmgr
, &clsid
,
1048 &tflp
->catid
, NULL
, 0);
1054 static HRESULT WINAPI
EnumTfLanguageProfiles_Next(IEnumTfLanguageProfiles
*iface
,
1055 ULONG ulCount
, TF_LANGUAGEPROFILE
*pProfile
, ULONG
*pcFetch
)
1057 EnumTfLanguageProfiles
*This
= impl_from_IEnumTfLanguageProfiles(iface
);
1060 TRACE("(%p)\n",This
);
1062 if (pProfile
== NULL
) return E_POINTER
;
1064 if (This
->tipkey
) while (fetched
< ulCount
)
1071 res
= RegEnumKeyExW(This
->tipkey
, This
->tip_index
,
1072 This
->szwCurrentClsid
, &cName
, NULL
, NULL
, NULL
, NULL
);
1073 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
1074 ++(This
->tip_index
);
1075 hr
= CLSIDFromString(This
->szwCurrentClsid
, &clsid
);
1076 if (FAILED(hr
)) continue;
1078 while ( fetched
< ulCount
)
1080 INT res
= next_LanguageProfile(This
, clsid
, pProfile
);
1093 if (pcFetch
) *pcFetch
= fetched
;
1094 return fetched
== ulCount
? S_OK
: S_FALSE
;
1097 static HRESULT WINAPI
EnumTfLanguageProfiles_Skip( IEnumTfLanguageProfiles
* iface
, ULONG celt
)
1099 EnumTfLanguageProfiles
*This
= impl_from_IEnumTfLanguageProfiles(iface
);
1100 FIXME("STUB (%p)\n",This
);
1104 static HRESULT WINAPI
EnumTfLanguageProfiles_Reset( IEnumTfLanguageProfiles
* iface
)
1106 EnumTfLanguageProfiles
*This
= impl_from_IEnumTfLanguageProfiles(iface
);
1107 TRACE("(%p)\n",This
);
1108 This
->tip_index
= 0;
1110 RegCloseKey(This
->langkey
);
1111 This
->langkey
= NULL
;
1112 This
->lang_index
= 0;
1116 static HRESULT WINAPI
EnumTfLanguageProfiles_Clone( IEnumTfLanguageProfiles
*iface
,
1117 IEnumTfLanguageProfiles
**ppenum
)
1119 EnumTfLanguageProfiles
*This
= impl_from_IEnumTfLanguageProfiles(iface
);
1122 TRACE("(%p)\n",This
);
1124 if (ppenum
== NULL
) return E_POINTER
;
1126 res
= EnumTfLanguageProfiles_Constructor(This
->langid
, ppenum
);
1129 EnumTfLanguageProfiles
*new_This
= (EnumTfLanguageProfiles
*)*ppenum
;
1130 new_This
->tip_index
= This
->tip_index
;
1131 lstrcpynW(new_This
->szwCurrentClsid
,This
->szwCurrentClsid
,39);
1136 static const WCHAR fmt
[] = {'%','s','\\','%','s','\\','0','x','%','0','8','x',0};
1138 sprintfW(fullkey
,fmt
,This
->szwCurrentClsid
,szwLngp
,This
->langid
);
1139 res
= RegOpenKeyExW(new_This
->tipkey
, fullkey
, 0, KEY_READ
| KEY_WRITE
, &This
->langkey
);
1140 new_This
->lang_index
= This
->lang_index
;
1146 static const IEnumTfLanguageProfilesVtbl EnumTfLanguageProfilesVtbl
=
1148 EnumTfLanguageProfiles_QueryInterface
,
1149 EnumTfLanguageProfiles_AddRef
,
1150 EnumTfLanguageProfiles_Release
,
1151 EnumTfLanguageProfiles_Clone
,
1152 EnumTfLanguageProfiles_Next
,
1153 EnumTfLanguageProfiles_Reset
,
1154 EnumTfLanguageProfiles_Skip
1157 static HRESULT
EnumTfLanguageProfiles_Constructor(LANGID langid
, IEnumTfLanguageProfiles
**ppOut
)
1160 EnumTfLanguageProfiles
*This
;
1162 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(EnumTfLanguageProfiles
));
1164 return E_OUTOFMEMORY
;
1166 This
->IEnumTfLanguageProfiles_iface
.lpVtbl
= &EnumTfLanguageProfilesVtbl
;
1168 This
->langid
= langid
;
1170 hr
= CategoryMgr_Constructor(NULL
,(IUnknown
**)&This
->catmgr
);
1173 HeapFree(GetProcessHeap(),0,This
);
1177 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, szwSystemTIPKey
, 0, NULL
, 0,
1178 KEY_READ
| KEY_WRITE
, NULL
, &This
->tipkey
, NULL
) != ERROR_SUCCESS
)
1180 HeapFree(GetProcessHeap(), 0, This
);
1184 *ppOut
= &This
->IEnumTfLanguageProfiles_iface
;
1185 TRACE("returning %p\n", *ppOut
);