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)
157 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
159 TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
161 StringFromGUID2(rclsid, buf, 39);
162 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
164 RegDeleteTreeW(HKEY_LOCAL_MACHINE, fullkey);
165 RegDeleteTreeW(HKEY_CURRENT_USER, fullkey);
170 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
171 ITfInputProcessorProfiles *iface, REFCLSID rclsid,
172 LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
173 ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
180 DWORD disposition = 0;
182 static const WCHAR fmt2[] = {'%','s','\\','0','x','%','0','8','x','\\','%','s',0};
183 static const WCHAR desc[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
184 static const WCHAR icnf[] = {'I','c','o','n','F','i','l','e',0};
185 static const WCHAR icni[] = {'I','c','o','n','I','n','d','e','x',0};
187 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
189 TRACE("(%p) %s %x %s %s %s %i\n",This,debugstr_guid(rclsid), langid,
190 debugstr_guid(guidProfile), debugstr_wn(pchDesc,cchDesc),
191 debugstr_wn(pchIconFile,cchFile),uIconIndex);
193 StringFromGUID2(rclsid, buf, 39);
194 sprintfW(fullkey,szwTipfmt,szwSystemTIPKey,buf);
196 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
197 &tipkey ) != ERROR_SUCCESS)
200 StringFromGUID2(guidProfile, buf, 39);
201 sprintfW(fullkey,fmt2,szwLngp,langid,buf);
203 res = RegCreateKeyExW(tipkey,fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
204 NULL, &fmtkey, &disposition);
209 RegSetValueExW(fmtkey, desc, 0, REG_SZ, (LPBYTE)pchDesc, cchDesc * sizeof(WCHAR));
210 RegSetValueExW(fmtkey, icnf, 0, REG_SZ, (LPBYTE)pchIconFile, cchFile * sizeof(WCHAR));
211 RegSetValueExW(fmtkey, icni, 0, REG_DWORD, (LPBYTE)&uIconIndex, sizeof(DWORD));
212 if (disposition == REG_CREATED_NEW_KEY)
213 RegSetValueExW(fmtkey, szwEnabled, 0, REG_DWORD, (LPBYTE)&zero, sizeof(DWORD));
216 add_userkey(rclsid, langid, guidProfile);
226 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
227 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
230 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
231 FIXME("STUB:(%p)\n",This);
235 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
236 ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
238 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
239 FIXME("STUB:(%p)\n",This);
243 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
244 ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
245 CLSID *pclsid, GUID *pguidProfile)
247 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
248 FIXME("STUB:(%p)\n",This);
252 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
253 ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
254 REFGUID guidProfiles)
256 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
257 FIXME("STUB:(%p)\n",This);
261 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
262 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
263 REFGUID guidProfiles)
265 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
266 FIXME("STUB:(%p)\n",This);
270 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
271 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
274 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
275 FIXME("STUB:(%p)\n",This);
279 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
280 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
281 REFGUID guidProfile, BSTR *pbstrProfile)
283 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
284 FIXME("STUB:(%p)\n",This);
288 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
289 ITfInputProcessorProfiles *iface, LANGID *plangid)
291 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
292 TRACE("(%p) 0x%x\n",This,This->currentLanguage);
297 *plangid = This->currentLanguage;
302 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
303 ITfInputProcessorProfiles *iface, LANGID langid)
305 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
306 FIXME("STUB:(%p)\n",This);
310 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
311 ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
313 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
314 FIXME("STUB:(%p)\n",This);
318 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
319 ITfInputProcessorProfiles *iface, LANGID langid,
320 IEnumTfLanguageProfiles **ppEnum)
322 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
323 FIXME("STUB:(%p)\n",This);
327 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
328 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
329 REFGUID guidProfile, BOOL fEnable)
337 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
338 TRACE("(%p) %s %x %s %i\n",This, debugstr_guid(rclsid), langid, debugstr_guid(guidProfile), fEnable);
340 StringFromGUID2(rclsid, buf, 39);
341 StringFromGUID2(guidProfile, buf2, 39);
342 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
344 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
348 RegSetValueExW(key, szwEnabled, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
357 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
358 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
359 REFGUID guidProfile, BOOL *pfEnable)
367 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
368 TRACE("(%p) %s, %i, %s, %p\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),pfEnable);
373 StringFromGUID2(rclsid, buf, 39);
374 StringFromGUID2(guidProfile, buf2, 39);
375 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
377 res = RegOpenKeyExW(HKEY_CURRENT_USER, fullkey, 0, KEY_READ | KEY_WRITE, &key);
381 DWORD count = sizeof(DWORD);
382 res = RegQueryValueExW(key, szwEnabled, 0, NULL, (LPBYTE)pfEnable, &count);
386 if (res) /* Try Default */
388 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
392 DWORD count = sizeof(DWORD);
393 res = RegQueryValueExW(key, szwEnabled, 0, NULL, (LPBYTE)pfEnable, &count);
404 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
405 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
406 REFGUID guidProfile, BOOL fEnable)
414 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
415 TRACE("(%p) %s %x %s %i\n",This,debugstr_guid(rclsid),langid,debugstr_guid(guidProfile),fEnable);
417 StringFromGUID2(rclsid, buf, 39);
418 StringFromGUID2(guidProfile, buf2, 39);
419 sprintfW(fullkey,szwFullLangfmt,szwSystemTIPKey,buf,szwLngp,langid,buf2);
421 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, fullkey, 0, KEY_READ | KEY_WRITE, &key);
425 RegSetValueExW(key, szwEnabled, 0, REG_DWORD, (LPBYTE)&fEnable, sizeof(DWORD));
434 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
435 ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
436 REFGUID guidProfile, HKL hKL)
438 InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
439 FIXME("STUB:(%p)\n",This);
444 static const ITfInputProcessorProfilesVtbl InputProcessorProfiles_InputProcessorProfilesVtbl =
446 InputProcessorProfiles_QueryInterface,
447 InputProcessorProfiles_AddRef,
448 InputProcessorProfiles_Release,
450 InputProcessorProfiles_Register,
451 InputProcessorProfiles_Unregister,
452 InputProcessorProfiles_AddLanguageProfile,
453 InputProcessorProfiles_RemoveLanguageProfile,
454 InputProcessorProfiles_EnumInputProcessorInfo,
455 InputProcessorProfiles_GetDefaultLanguageProfile,
456 InputProcessorProfiles_SetDefaultLanguageProfile,
457 InputProcessorProfiles_ActivateLanguageProfile,
458 InputProcessorProfiles_GetActiveLanguageProfile,
459 InputProcessorProfiles_GetLanguageProfileDescription,
460 InputProcessorProfiles_GetCurrentLanguage,
461 InputProcessorProfiles_ChangeCurrentLanguage,
462 InputProcessorProfiles_GetLanguageList,
463 InputProcessorProfiles_EnumLanguageProfiles,
464 InputProcessorProfiles_EnableLanguageProfile,
465 InputProcessorProfiles_IsEnabledLanguageProfile,
466 InputProcessorProfiles_EnableLanguageProfileByDefault,
467 InputProcessorProfiles_SubstituteKeyboardLayout
470 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
472 InputProcessorProfiles *This;
474 return CLASS_E_NOAGGREGATION;
476 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
478 return E_OUTOFMEMORY;
480 This->InputProcessorProfilesVtbl= &InputProcessorProfiles_InputProcessorProfilesVtbl;
482 This->currentLanguage = GetUserDefaultLCID();
484 TRACE("returning %p\n", This);
485 *ppOut = (IUnknown *)This;