2 * ITfCategoryMgr 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 typedef struct tagCategoryMgr {
44 ITfCategoryMgr ITfCategoryMgr_iface;
48 static inline CategoryMgr *impl_from_ITfCategoryMgr(ITfCategoryMgr *iface)
50 return CONTAINING_RECORD(iface, CategoryMgr, ITfCategoryMgr_iface);
53 static void CategoryMgr_Destructor(CategoryMgr *This)
55 TRACE("destroying %p\n", This);
56 HeapFree(GetProcessHeap(),0,This);
59 static HRESULT WINAPI CategoryMgr_QueryInterface(ITfCategoryMgr *iface, REFIID iid, LPVOID *ppvOut)
61 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
64 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfCategoryMgr))
71 IUnknown_AddRef(iface);
75 WARN("unsupported interface: %s\n", debugstr_guid(iid));
79 static ULONG WINAPI CategoryMgr_AddRef(ITfCategoryMgr *iface)
81 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
82 return InterlockedIncrement(&This->refCount);
85 static ULONG WINAPI CategoryMgr_Release(ITfCategoryMgr *iface)
87 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
90 ret = InterlockedDecrement(&This->refCount);
92 CategoryMgr_Destructor(This);
96 /*****************************************************
97 * ITfCategoryMgr functions
98 *****************************************************/
100 static HRESULT WINAPI CategoryMgr_RegisterCategory ( ITfCategoryMgr *iface,
101 REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
107 HKEY tipkey,catkey,itmkey;
108 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
110 static const WCHAR ctg[] = {'C','a','t','e','g','o','r','y',0};
111 static const WCHAR itm[] = {'I','t','e','m',0};
112 static const WCHAR fmt[] = {'%','s','\\','%','s',0};
113 static const WCHAR fmt2[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
115 TRACE("(%p) %s %s %s\n",This,debugstr_guid(rclsid), debugstr_guid(rcatid), debugstr_guid(rguid));
117 StringFromGUID2(rclsid, buf, 39);
118 sprintfW(fullkey,fmt,szwSystemTIPKey,buf);
120 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
121 &tipkey ) != ERROR_SUCCESS)
124 StringFromGUID2(rcatid, buf, 39);
125 StringFromGUID2(rguid, buf2, 39);
126 sprintfW(fullkey,fmt2,ctg,ctg,buf,buf2);
128 res = RegCreateKeyExW(tipkey, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
129 NULL, &catkey, NULL);
134 sprintfW(fullkey,fmt2,ctg,itm,buf2,buf);
135 res = RegCreateKeyExW(tipkey, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
136 NULL, &itmkey, NULL);
149 static HRESULT WINAPI CategoryMgr_UnregisterCategory ( ITfCategoryMgr *iface,
150 REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
156 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
158 static const WCHAR ctg[] = {'C','a','t','e','g','o','r','y',0};
159 static const WCHAR itm[] = {'I','t','e','m',0};
160 static const WCHAR fmt[] = {'%','s','\\','%','s',0};
161 static const WCHAR fmt2[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
163 TRACE("(%p) %s %s %s\n",This,debugstr_guid(rclsid), debugstr_guid(rcatid), debugstr_guid(rguid));
165 StringFromGUID2(rclsid, buf, 39);
166 sprintfW(fullkey,fmt,szwSystemTIPKey,buf);
168 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
169 &tipkey ) != ERROR_SUCCESS)
172 StringFromGUID2(rcatid, buf, 39);
173 StringFromGUID2(rguid, buf2, 39);
174 sprintfW(fullkey,fmt2,ctg,ctg,buf,buf2);
176 sprintfW(fullkey,fmt2,ctg,itm,buf2,buf);
177 RegDeleteTreeW(tipkey, fullkey);
178 sprintfW(fullkey,fmt2,ctg,itm,buf2,buf);
179 RegDeleteTreeW(tipkey, fullkey);
185 static HRESULT WINAPI CategoryMgr_EnumCategoriesInItem ( ITfCategoryMgr *iface,
186 REFGUID rguid, IEnumGUID **ppEnum)
188 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
189 FIXME("STUB:(%p)\n",This);
193 static HRESULT WINAPI CategoryMgr_EnumItemsInCategory ( ITfCategoryMgr *iface,
194 REFGUID rcatid, IEnumGUID **ppEnum)
196 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
197 FIXME("STUB:(%p)\n",This);
201 static HRESULT WINAPI CategoryMgr_FindClosestCategory ( ITfCategoryMgr *iface,
202 REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount)
204 static const WCHAR fmt[] = { '%','s','\\','%','s','\\','C','a','t','e','g','o','r','y','\\','I','t','e','m','\\','%','s',0};
209 HRESULT hr = S_FALSE;
211 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
213 TRACE("(%p)\n",This);
215 if (!pcatid || (ulCount && ppcatidList == NULL))
218 StringFromGUID2(rguid, buf, 39);
219 sprintfW(fullkey,fmt,szwSystemTIPKey,buf,buf);
222 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ, &key ) !=
235 res = RegEnumKeyExW(key, index, catid, &cName, NULL, NULL, NULL, NULL);
236 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
239 hr2 = CLSIDFromString(catid, &guid);
240 if (FAILED(hr2)) continue;
246 for (j = 0; j < ulCount; j++)
247 if (IsEqualGUID(&guid, ppcatidList[j]))
267 static HRESULT WINAPI CategoryMgr_RegisterGUIDDescription (
268 ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid,
269 const WCHAR *pchDesc, ULONG cch)
271 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
272 FIXME("STUB:(%p)\n",This);
276 static HRESULT WINAPI CategoryMgr_UnregisterGUIDDescription (
277 ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid)
279 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
280 FIXME("STUB:(%p)\n",This);
284 static HRESULT WINAPI CategoryMgr_GetGUIDDescription ( ITfCategoryMgr *iface,
285 REFGUID rguid, BSTR *pbstrDesc)
287 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
288 FIXME("STUB:(%p)\n",This);
292 static HRESULT WINAPI CategoryMgr_RegisterGUIDDWORD ( ITfCategoryMgr *iface,
293 REFCLSID rclsid, REFGUID rguid, DWORD dw)
295 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
296 FIXME("STUB:(%p)\n",This);
300 static HRESULT WINAPI CategoryMgr_UnregisterGUIDDWORD ( ITfCategoryMgr *iface,
301 REFCLSID rclsid, REFGUID rguid)
303 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
304 FIXME("STUB:(%p)\n",This);
308 static HRESULT WINAPI CategoryMgr_GetGUIDDWORD ( ITfCategoryMgr *iface,
309 REFGUID rguid, DWORD *pdw)
311 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
312 FIXME("STUB:(%p)\n",This);
316 static HRESULT WINAPI CategoryMgr_RegisterGUID ( ITfCategoryMgr *iface,
317 REFGUID rguid, TfGuidAtom *pguidatom
323 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
325 TRACE("(%p) %s %p\n",This,debugstr_guid(rguid),pguidatom);
332 id = enumerate_Cookie(COOKIE_MAGIC_GUIDATOM,&index);
333 if (id && IsEqualGUID(rguid,get_Cookie_data(id)))
340 checkguid = HeapAlloc(GetProcessHeap(),0,sizeof(GUID));
342 id = generate_Cookie(COOKIE_MAGIC_GUIDATOM,checkguid);
346 HeapFree(GetProcessHeap(),0,checkguid);
355 static HRESULT WINAPI CategoryMgr_GetGUID ( ITfCategoryMgr *iface,
356 TfGuidAtom guidatom, GUID *pguid)
358 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
360 TRACE("(%p) %i\n",This,guidatom);
367 if (get_Cookie_magic(guidatom) == COOKIE_MAGIC_GUIDATOM)
368 *pguid = *((REFGUID)get_Cookie_data(guidatom));
373 static HRESULT WINAPI CategoryMgr_IsEqualTfGuidAtom ( ITfCategoryMgr *iface,
374 TfGuidAtom guidatom, REFGUID rguid, BOOL *pfEqual)
376 CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
378 TRACE("(%p) %i %s %p\n",This,guidatom,debugstr_guid(rguid),pfEqual);
384 if (get_Cookie_magic(guidatom) == COOKIE_MAGIC_GUIDATOM)
386 if (IsEqualGUID(rguid,get_Cookie_data(guidatom)))
394 static const ITfCategoryMgrVtbl CategoryMgr_CategoryMgrVtbl =
396 CategoryMgr_QueryInterface,
400 CategoryMgr_RegisterCategory,
401 CategoryMgr_UnregisterCategory,
402 CategoryMgr_EnumCategoriesInItem,
403 CategoryMgr_EnumItemsInCategory,
404 CategoryMgr_FindClosestCategory,
405 CategoryMgr_RegisterGUIDDescription,
406 CategoryMgr_UnregisterGUIDDescription,
407 CategoryMgr_GetGUIDDescription,
408 CategoryMgr_RegisterGUIDDWORD,
409 CategoryMgr_UnregisterGUIDDWORD,
410 CategoryMgr_GetGUIDDWORD,
411 CategoryMgr_RegisterGUID,
413 CategoryMgr_IsEqualTfGuidAtom
416 HRESULT CategoryMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
420 return CLASS_E_NOAGGREGATION;
422 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CategoryMgr));
424 return E_OUTOFMEMORY;
426 This->ITfCategoryMgr_iface.lpVtbl = &CategoryMgr_CategoryMgrVtbl;
429 TRACE("returning %p\n", This);
430 *ppOut = (IUnknown *)This;