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"
36 #include "wine/unicode.h"
39 #include "msctf_internal.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
43 static const WCHAR szwLngp[] = {'L','a','n','g','u','a','g','e','P','r','o','f','i','l','e',0};
44 static const WCHAR szwEnabled[] = {'E','n','a','b','l','e','d',0};
45 static const WCHAR szwTipfmt[] = {'%','s','\\','%','s',0};
46 static const WCHAR szwFullLangfmt[] = {'%','s','\\','%','s','\\','%','s','\\','0','x','%','0','8','x','\\','%','s',0};
48 typedef struct tagInputProcessorProfiles {
49 const ITfInputProcessorProfilesVtbl *InputProcessorProfilesVtbl;
52 LANGID currentLanguage;
53 } InputProcessorProfiles;
55 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
57 TRACE("destroying %p\n", This);
58 HeapFree(GetProcessHeap(),0,This);
61 static void add_userkey( REFCLSID rclsid, LANGID langid,
68 DWORD disposition = 0;
73 StringFromGUID2(rclsid, buf, 39);
74 StringFromGUID2(guidProfile, buf2, 39);
75 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
77 res = RegCreateKeyExW(HKEY_CURRENT_USER,fullkey, 0, NULL, 0,
78 KEY_READ | KEY_WRITE, NULL, &key, &disposition);
80 if (!res && disposition == REG_CREATED_NEW_KEY)
83 RegSetValueExW(key, szwEnabled, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
90 static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, LPVOID *ppvOut)
92 InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
95 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
102 IUnknown_AddRef(iface);
106 WARN("unsupported interface: %s\n", debugstr_guid(iid));
107 return E_NOINTERFACE;
110 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
112 InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
113 return InterlockedIncrement(&This->refCount);
116 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
118 InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
121 ret = InterlockedDecrement(&This->refCount);
123 InputProcessorProfiles_Destructor(This);
127 /*****************************************************
128 * ITfInputProcessorProfiles functions
129 *****************************************************/
130 static HRESULT WINAPI InputProcessorProfiles_Register(
131 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
133 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
138 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
140 StringFromGUID2(rclsid, buf, 39);
141 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
143 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, NULL, 0,
144 KEY_READ | KEY_WRITE, NULL, &tipkey, NULL) != ERROR_SUCCESS)
152 static HRESULT WINAPI InputProcessorProfiles_Unregister(
153 ITfInputProcessorProfiles *iface, REFCLSID rclsid)
155 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
156 FIXME("STUB:(%p)\n",This);
160 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
161 ITfInputProcessorProfiles *iface, REFCLSID rclsid,
162 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
163 ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
170 DWORD disposition = 0;
172 static const WCHAR fmt2[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
173 static const WCHAR desc[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
174 static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
175 static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
177 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
179 TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
180 debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
181 debugstr_wn(pchIconFile,cchFile),uIconIndex);
183 StringFromGUID2(rclsid, buf, 39);
184 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
186 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
187 &tipkey ) != ERROR_SUCCESS)
190 StringFromGUID2(guidProfile, buf, 39);
191 sprintfW(fullkey,fmt2,szwLngp,langid,buf);
193 res = RegCreateKeyExW(tipkey,fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
194 NULL, &fmtkey, &disposition);
199 RegSetValueExW(fmtkey, desc, 0, REG_SZ, (LPBYTE)pchDesc, cchDesc * sizeof(WCHAR));
200 RegSetValueExW(fmtkey, icnf, 0, REG_SZ, (LPBYTE)pchIconFile, cchFile * sizeof(WCHAR));
201 RegSetValueExW(fmtkey, icni, 0, REG_DWORD, (LPBYTE)&uIconIndex, sizeof(DWORD));
202 if (disposition == REG_CREATED_NEW_KEY)
203 RegSetValueExW(fmtkey, szwEnabled, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
206 add_userkey(rclsid, langid, guidProfile);
216 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
217 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
220 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
221 FIXME("STUB:(%p)\n",This);
225 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
226 ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
228 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
229 FIXME("STUB:(%p)\n",This);
233 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
234 ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
235 CLSID *pclsid, GUID *pguidProfile)
237 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
238 FIXME("STUB:(%p)\n",This);
242 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
243 ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
244 REFGUID guidProfiles)
246 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
247 FIXME("STUB:(%p)\n",This);
251 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
252 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
253 REFGUID guidProfiles)
255 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
256 FIXME("STUB:(%p)\n",This);
260 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
261 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
264 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
265 FIXME("STUB:(%p)\n",This);
269 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
270 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
271 REFGUID guidProfile, BSTR *pbstrProfile)
273 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
274 FIXME("STUB:(%p)\n",This);
278 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
279 ITfInputProcessorProfiles *iface, LANGID *plangid)
281 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
282 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
287 *plangid = This->currentLanguage;
292 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
293 ITfInputProcessorProfiles *iface, LANGID langid)
295 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
296 FIXME("STUB:(%p)\n",This);
300 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
301 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
303 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
304 FIXME("STUB:(%p)\n",This);
308 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
309 ITfInputProcessorProfiles *iface, LANGID langid,
310 IEnumTfLanguageProfiles **ppEnum)
312 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
313 FIXME("STUB:(%p)\n",This);
317 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
318 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
319 REFGUID guidProfile, BOOL fEnable)
327 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
328 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
330 StringFromGUID2(rclsid, buf, 39);
331 StringFromGUID2(guidProfile, buf2, 39);
332 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
334 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
338 RegSetValueExW(key, szwEnabled, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
347 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
348 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
349 REFGUID guidProfile, BOOL *pfEnable)
357 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
358 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
363 StringFromGUID2(rclsid, buf, 39);
364 StringFromGUID2(guidProfile, buf2, 39);
365 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
367 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
371 DWORD count = sizeof(DWORD);
372 res = RegQueryValueExW(key, szwEnabled, 0, NULL, (LPBYTE)pfEnable, &count);
376 if (res) /* Try Default */
378 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
382 DWORD count = sizeof(DWORD);
383 res = RegQueryValueExW(key, szwEnabled, 0, NULL, (LPBYTE)pfEnable, &count);
394 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
395 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
396 REFGUID guidProfile, BOOL fEnable)
404 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
405 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
407 StringFromGUID2(rclsid, buf, 39);
408 StringFromGUID2(guidProfile, buf2, 39);
409 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
411 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
415 RegSetValueExW(key, szwEnabled, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
424 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
425 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
426 REFGUID guidProfile, HKL hKL)
428 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
429 FIXME("STUB:(%p)\n",This);
434 static const ITfInputProcessorProfilesVtbl InputProcessorProfiles_InputProcessorProfilesVtbl =
436 InputProcessorProfiles_QueryInterface,
437 InputProcessorProfiles_AddRef,
438 InputProcessorProfiles_Release,
440 InputProcessorProfiles_Register,
441 InputProcessorProfiles_Unregister,
442 InputProcessorProfiles_AddLanguageProfile,
443 InputProcessorProfiles_RemoveLanguageProfile,
444 InputProcessorProfiles_EnumInputProcessorInfo,
445 InputProcessorProfiles_GetDefaultLanguageProfile,
446 InputProcessorProfiles_SetDefaultLanguageProfile,
447 InputProcessorProfiles_ActivateLanguageProfile,
448 InputProcessorProfiles_GetActiveLanguageProfile,
449 InputProcessorProfiles_GetLanguageProfileDescription,
450 InputProcessorProfiles_GetCurrentLanguage,
451 InputProcessorProfiles_ChangeCurrentLanguage,
452 InputProcessorProfiles_GetLanguageList,
453 InputProcessorProfiles_EnumLanguageProfiles,
454 InputProcessorProfiles_EnableLanguageProfile,
455 InputProcessorProfiles_IsEnabledLanguageProfile,
456 InputProcessorProfiles_EnableLanguageProfileByDefault,
457 InputProcessorProfiles_SubstituteKeyboardLayout
460 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
462 InputProcessorProfiles *This;
464 return CLASS_E_NOAGGREGATION;
466 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
468 return E_OUTOFMEMORY;
470 This->InputProcessorProfilesVtbl= &InputProcessorProfiles_InputProcessorProfilesVtbl;
472 This->currentLanguage = GetUserDefaultLCID();
474 TRACE("returning %p\n", This);
475 *ppOut = (IUnknown *)This;