msctf: Implement ITfInputProcessorProfiles::Register.
[wine] / dlls / msctf / inputprocessor.c
1 /*
2  *  ITfInputProcessorProfiles implementation
3  *
4  *  Copyright 2009 Aric Stewart, CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #define COBJMACROS
26
27 #include "wine/debug.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winuser.h"
32 #include "shlwapi.h"
33 #include "winerror.h"
34 #include "objbase.h"
35
36 #include "wine/unicode.h"
37
38 #include "msctf.h"
39 #include "msctf_internal.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
42
43 typedef struct tagInputProcessorProfiles {
44     const ITfInputProcessorProfilesVtbl *InputProcessorProfilesVtbl;
45     LONG refCount;
46
47     LANGID  currentLanguage;
48 } InputProcessorProfiles;
49
50 static void InputProcessorProfiles_Destructor(InputProcessorProfiles *This)
51 {
52     TRACE("destroying %p\n", This);
53     HeapFree(GetProcessHeap(),0,This);
54 }
55
56 static HRESULT WINAPI InputProcessorProfiles_QueryInterface(ITfInputProcessorProfiles *iface, REFIID iid, LPVOID *ppvOut)
57 {
58     InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
59     *ppvOut = NULL;
60
61     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfInputProcessorProfiles))
62     {
63         *ppvOut = This;
64     }
65
66     if (*ppvOut)
67     {
68         IUnknown_AddRef(iface);
69         return S_OK;
70     }
71
72     WARN("unsupported interface: %s\n", debugstr_guid(iid));
73     return E_NOINTERFACE;
74 }
75
76 static ULONG WINAPI InputProcessorProfiles_AddRef(ITfInputProcessorProfiles *iface)
77 {
78     InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
79     return InterlockedIncrement(&This->refCount);
80 }
81
82 static ULONG WINAPI InputProcessorProfiles_Release(ITfInputProcessorProfiles *iface)
83 {
84     InputProcessorProfiles *This = (InputProcessorProfiles *)iface;
85     ULONG ret;
86
87     ret = InterlockedDecrement(&This->refCount);
88     if (ret == 0)
89         InputProcessorProfiles_Destructor(This);
90     return ret;
91 }
92
93 /*****************************************************
94  * ITfInputProcessorProfiles functions
95  *****************************************************/
96 static HRESULT WINAPI InputProcessorProfiles_Register(
97         ITfInputProcessorProfiles *iface, REFCLSID rclsid)
98 {
99     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
100     HKEY tipkey;
101     WCHAR buf[39];
102     static const WCHAR fmt[] = {'%','s','\\','%','s',0};
103     WCHAR fullkey[68];
104
105     TRACE("(%p) %s\n",This,debugstr_guid(rclsid));
106
107     StringFromGUID2(rclsid, buf, 39);
108     sprintfW(fullkey,fmt,szwSystemTIPKey,buf);
109
110     if (RegCreateKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, NULL, 0,
111                     KEY_READ | KEY_WRITE, NULL, &tipkey, NULL) != ERROR_SUCCESS)
112         return E_FAIL;
113
114     RegCloseKey(tipkey);
115
116     return S_OK;
117 }
118
119 static HRESULT WINAPI InputProcessorProfiles_Unregister(
120         ITfInputProcessorProfiles *iface, REFCLSID rclsid)
121 {
122     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
123     FIXME("STUB:(%p)\n",This);
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI InputProcessorProfiles_AddLanguageProfile(
128         ITfInputProcessorProfiles *iface, REFCLSID rclsid,
129         LANGID langid, REFGUID guidProfile, const WCHAR *pchDesc,
130         ULONG cchDesc, const WCHAR *pchIconFile, ULONG cchFile,
131         ULONG uIconIndex)
132 {
133     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
134     FIXME("STUB:(%p)\n",This);
135     return E_NOTIMPL;
136 }
137
138 static HRESULT WINAPI InputProcessorProfiles_RemoveLanguageProfile(
139         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
140         REFGUID guidProfile)
141 {
142     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
143     FIXME("STUB:(%p)\n",This);
144     return E_NOTIMPL;
145 }
146
147 static HRESULT WINAPI InputProcessorProfiles_EnumInputProcessorInfo(
148         ITfInputProcessorProfiles *iface, IEnumGUID **ppEnum)
149 {
150     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
151     FIXME("STUB:(%p)\n",This);
152     return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI InputProcessorProfiles_GetDefaultLanguageProfile(
156         ITfInputProcessorProfiles *iface, LANGID langid, REFGUID catid,
157         CLSID *pclsid, GUID *pguidProfile)
158 {
159     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
160     FIXME("STUB:(%p)\n",This);
161     return E_NOTIMPL;
162 }
163
164 static HRESULT WINAPI InputProcessorProfiles_SetDefaultLanguageProfile(
165         ITfInputProcessorProfiles *iface, LANGID langid, REFCLSID rclsid,
166         REFGUID guidProfiles)
167 {
168     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
169     FIXME("STUB:(%p)\n",This);
170     return E_NOTIMPL;
171 }
172
173 static HRESULT WINAPI InputProcessorProfiles_ActivateLanguageProfile(
174         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
175         REFGUID guidProfiles)
176 {
177     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
178     FIXME("STUB:(%p)\n",This);
179     return E_NOTIMPL;
180 }
181
182 static HRESULT WINAPI InputProcessorProfiles_GetActiveLanguageProfile(
183         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID *plangid,
184         GUID *pguidProfile)
185 {
186     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
187     FIXME("STUB:(%p)\n",This);
188     return E_NOTIMPL;
189 }
190
191 static HRESULT WINAPI InputProcessorProfiles_GetLanguageProfileDescription(
192         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
193         REFGUID guidProfile, BSTR *pbstrProfile)
194 {
195     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
196     FIXME("STUB:(%p)\n",This);
197     return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI InputProcessorProfiles_GetCurrentLanguage(
201         ITfInputProcessorProfiles *iface, LANGID *plangid)
202 {
203     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
204     TRACE("(%p) 0x%x\n",This,This->currentLanguage);
205
206     if (!plangid)
207         return E_INVALIDARG;
208
209     *plangid = This->currentLanguage;
210
211     return S_OK;
212 }
213
214 static HRESULT WINAPI InputProcessorProfiles_ChangeCurrentLanguage(
215         ITfInputProcessorProfiles *iface, LANGID langid)
216 {
217     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
218     FIXME("STUB:(%p)\n",This);
219     return E_NOTIMPL;
220 }
221
222 static HRESULT WINAPI InputProcessorProfiles_GetLanguageList(
223         ITfInputProcessorProfiles *iface, LANGID **ppLangId, ULONG *pulCount)
224 {
225     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
226     FIXME("STUB:(%p)\n",This);
227     return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI InputProcessorProfiles_EnumLanguageProfiles(
231         ITfInputProcessorProfiles *iface, LANGID langid,
232         IEnumTfLanguageProfiles **ppEnum)
233 {
234     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
235     FIXME("STUB:(%p)\n",This);
236     return E_NOTIMPL;
237 }
238
239 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfile(
240         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
241         REFGUID guidProfile, BOOL fEnable)
242 {
243     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
244     FIXME("STUB:(%p)\n",This);
245     return E_NOTIMPL;
246 }
247
248 static HRESULT WINAPI InputProcessorProfiles_IsEnabledLanguageProfile(
249         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
250         REFGUID guidProfile, BOOL *pfEnable)
251 {
252     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
253     FIXME("STUB:(%p)\n",This);
254     return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI InputProcessorProfiles_EnableLanguageProfileByDefault(
258         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
259         REFGUID guidProfile, BOOL fEnable)
260 {
261     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
262     FIXME("STUB:(%p)\n",This);
263     return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI InputProcessorProfiles_SubstituteKeyboardLayout(
267         ITfInputProcessorProfiles *iface, REFCLSID rclsid, LANGID langid,
268         REFGUID guidProfile, HKL hKL)
269 {
270     InputProcessorProfiles *This = (InputProcessorProfiles*)iface;
271     FIXME("STUB:(%p)\n",This);
272     return E_NOTIMPL;
273 }
274
275
276 static const ITfInputProcessorProfilesVtbl InputProcessorProfiles_InputProcessorProfilesVtbl =
277 {
278     InputProcessorProfiles_QueryInterface,
279     InputProcessorProfiles_AddRef,
280     InputProcessorProfiles_Release,
281
282     InputProcessorProfiles_Register,
283     InputProcessorProfiles_Unregister,
284     InputProcessorProfiles_AddLanguageProfile,
285     InputProcessorProfiles_RemoveLanguageProfile,
286     InputProcessorProfiles_EnumInputProcessorInfo,
287     InputProcessorProfiles_GetDefaultLanguageProfile,
288     InputProcessorProfiles_SetDefaultLanguageProfile,
289     InputProcessorProfiles_ActivateLanguageProfile,
290     InputProcessorProfiles_GetActiveLanguageProfile,
291     InputProcessorProfiles_GetLanguageProfileDescription,
292     InputProcessorProfiles_GetCurrentLanguage,
293     InputProcessorProfiles_ChangeCurrentLanguage,
294     InputProcessorProfiles_GetLanguageList,
295     InputProcessorProfiles_EnumLanguageProfiles,
296     InputProcessorProfiles_EnableLanguageProfile,
297     InputProcessorProfiles_IsEnabledLanguageProfile,
298     InputProcessorProfiles_EnableLanguageProfileByDefault,
299     InputProcessorProfiles_SubstituteKeyboardLayout
300 };
301
302 HRESULT InputProcessorProfiles_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
303 {
304     InputProcessorProfiles *This;
305     if (pUnkOuter)
306         return CLASS_E_NOAGGREGATION;
307
308     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(InputProcessorProfiles));
309     if (This == NULL)
310         return E_OUTOFMEMORY;
311
312     This->InputProcessorProfilesVtbl= &InputProcessorProfiles_InputProcessorProfilesVtbl;
313     This->refCount = 1;
314     This->currentLanguage = GetUserDefaultLCID();
315
316     TRACE("returning %p\n", This);
317     *ppOut = (IUnknown *)This;
318     return S_OK;
319 }