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 const ITfCategoryMgrVtbl
*CategoryMgrVtbl
;
48 static void CategoryMgr_Destructor(CategoryMgr
*This
)
50 TRACE("destroying %p\n", This
);
51 HeapFree(GetProcessHeap(),0,This
);
54 static HRESULT WINAPI
CategoryMgr_QueryInterface(ITfCategoryMgr
*iface
, REFIID iid
, LPVOID
*ppvOut
)
56 CategoryMgr
*This
= (CategoryMgr
*)iface
;
59 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfCategoryMgr
))
66 IUnknown_AddRef(iface
);
70 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
74 static ULONG WINAPI
CategoryMgr_AddRef(ITfCategoryMgr
*iface
)
76 CategoryMgr
*This
= (CategoryMgr
*)iface
;
77 return InterlockedIncrement(&This
->refCount
);
80 static ULONG WINAPI
CategoryMgr_Release(ITfCategoryMgr
*iface
)
82 CategoryMgr
*This
= (CategoryMgr
*)iface
;
85 ret
= InterlockedDecrement(&This
->refCount
);
87 CategoryMgr_Destructor(This
);
91 /*****************************************************
92 * ITfCategoryMgr functions
93 *****************************************************/
95 static HRESULT WINAPI
CategoryMgr_RegisterCategory ( ITfCategoryMgr
*iface
,
96 REFCLSID rclsid
, REFGUID rcatid
, REFGUID rguid
)
102 HKEY tipkey
,catkey
,itmkey
;
103 CategoryMgr
*This
= (CategoryMgr
*)iface
;
105 static const WCHAR ctg
[] = {'C','a','t','e','g','o','r','y',0};
106 static const WCHAR itm
[] = {'I','t','e','m',0};
107 static const WCHAR fmt
[] = {'%','s','\\','%','s',0};
108 static const WCHAR fmt2
[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
110 TRACE("(%p) %s %s %s\n",This
,debugstr_guid(rclsid
), debugstr_guid(rcatid
), debugstr_guid(rguid
));
112 StringFromGUID2(rclsid
, buf
, 39);
113 sprintfW(fullkey
,fmt
,szwSystemTIPKey
,buf
);
115 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, KEY_READ
| KEY_WRITE
,
116 &tipkey
) != ERROR_SUCCESS
)
119 StringFromGUID2(rcatid
, buf
, 39);
120 StringFromGUID2(rguid
, buf2
, 39);
121 sprintfW(fullkey
,fmt2
,ctg
,ctg
,buf
,buf2
);
123 res
= RegCreateKeyExW(tipkey
, fullkey
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
124 NULL
, &catkey
, NULL
);
129 sprintfW(fullkey
,fmt2
,ctg
,itm
,buf2
,buf
);
130 res
= RegCreateKeyExW(tipkey
, fullkey
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
131 NULL
, &itmkey
, NULL
);
144 static HRESULT WINAPI
CategoryMgr_UnregisterCategory ( ITfCategoryMgr
*iface
,
145 REFCLSID rclsid
, REFGUID rcatid
, REFGUID rguid
)
151 CategoryMgr
*This
= (CategoryMgr
*)iface
;
153 static const WCHAR ctg
[] = {'C','a','t','e','g','o','r','y',0};
154 static const WCHAR itm
[] = {'I','t','e','m',0};
155 static const WCHAR fmt
[] = {'%','s','\\','%','s',0};
156 static const WCHAR fmt2
[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
158 TRACE("(%p) %s %s %s\n",This
,debugstr_guid(rclsid
), debugstr_guid(rcatid
), debugstr_guid(rguid
));
160 StringFromGUID2(rclsid
, buf
, 39);
161 sprintfW(fullkey
,fmt
,szwSystemTIPKey
,buf
);
163 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, KEY_READ
| KEY_WRITE
,
164 &tipkey
) != ERROR_SUCCESS
)
167 StringFromGUID2(rcatid
, buf
, 39);
168 StringFromGUID2(rguid
, buf2
, 39);
169 sprintfW(fullkey
,fmt2
,ctg
,ctg
,buf
,buf2
);
171 sprintfW(fullkey
,fmt2
,ctg
,itm
,buf2
,buf
);
172 RegDeleteTreeW(tipkey
, fullkey
);
173 sprintfW(fullkey
,fmt2
,ctg
,itm
,buf2
,buf
);
174 RegDeleteTreeW(tipkey
, fullkey
);
180 static HRESULT WINAPI
CategoryMgr_EnumCategoriesInItem ( ITfCategoryMgr
*iface
,
181 REFGUID rguid
, IEnumGUID
**ppEnum
)
183 CategoryMgr
*This
= (CategoryMgr
*)iface
;
184 FIXME("STUB:(%p)\n",This
);
188 static HRESULT WINAPI
CategoryMgr_EnumItemsInCategory ( ITfCategoryMgr
*iface
,
189 REFGUID rcatid
, IEnumGUID
**ppEnum
)
191 CategoryMgr
*This
= (CategoryMgr
*)iface
;
192 FIXME("STUB:(%p)\n",This
);
196 static HRESULT WINAPI
CategoryMgr_FindClosestCategory ( ITfCategoryMgr
*iface
,
197 REFGUID rguid
, GUID
*pcatid
, const GUID
**ppcatidList
, ULONG ulCount
)
199 static const WCHAR fmt
[] = { '%','s','\\','%','s','\\','C','a','t','e','g','o','r','y','\\','I','t','e','m','\\','%','s',0};
204 HRESULT hr
= S_FALSE
;
206 CategoryMgr
*This
= (CategoryMgr
*)iface
;
208 TRACE("(%p)\n",This
);
210 if (!pcatid
|| (ulCount
&& ppcatidList
== NULL
))
213 StringFromGUID2(rguid
, buf
, 39);
214 sprintfW(fullkey
,fmt
,szwSystemTIPKey
,buf
,buf
);
217 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, KEY_READ
, &key
) !=
230 res
= RegEnumKeyExW(key
, index
, catid
, &cName
, NULL
, NULL
, NULL
, NULL
);
231 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
234 hr2
= CLSIDFromString(catid
, &guid
);
235 if (FAILED(hr2
)) continue;
241 for (j
= 0; j
< ulCount
; j
++)
242 if (IsEqualGUID(&guid
, ppcatidList
[j
]))
262 static HRESULT WINAPI
CategoryMgr_RegisterGUIDDescription (
263 ITfCategoryMgr
*iface
, REFCLSID rclsid
, REFGUID rguid
,
264 const WCHAR
*pchDesc
, ULONG cch
)
266 CategoryMgr
*This
= (CategoryMgr
*)iface
;
267 FIXME("STUB:(%p)\n",This
);
271 static HRESULT WINAPI
CategoryMgr_UnregisterGUIDDescription (
272 ITfCategoryMgr
*iface
, REFCLSID rclsid
, REFGUID rguid
)
274 CategoryMgr
*This
= (CategoryMgr
*)iface
;
275 FIXME("STUB:(%p)\n",This
);
279 static HRESULT WINAPI
CategoryMgr_GetGUIDDescription ( ITfCategoryMgr
*iface
,
280 REFGUID rguid
, BSTR
*pbstrDesc
)
282 CategoryMgr
*This
= (CategoryMgr
*)iface
;
283 FIXME("STUB:(%p)\n",This
);
287 static HRESULT WINAPI
CategoryMgr_RegisterGUIDDWORD ( ITfCategoryMgr
*iface
,
288 REFCLSID rclsid
, REFGUID rguid
, DWORD dw
)
290 CategoryMgr
*This
= (CategoryMgr
*)iface
;
291 FIXME("STUB:(%p)\n",This
);
295 static HRESULT WINAPI
CategoryMgr_UnregisterGUIDDWORD ( ITfCategoryMgr
*iface
,
296 REFCLSID rclsid
, REFGUID rguid
)
298 CategoryMgr
*This
= (CategoryMgr
*)iface
;
299 FIXME("STUB:(%p)\n",This
);
303 static HRESULT WINAPI
CategoryMgr_GetGUIDDWORD ( ITfCategoryMgr
*iface
,
304 REFGUID rguid
, DWORD
*pdw
)
306 CategoryMgr
*This
= (CategoryMgr
*)iface
;
307 FIXME("STUB:(%p)\n",This
);
311 static HRESULT WINAPI
CategoryMgr_RegisterGUID ( ITfCategoryMgr
*iface
,
312 REFGUID rguid
, TfGuidAtom
*pguidatom
318 CategoryMgr
*This
= (CategoryMgr
*)iface
;
320 TRACE("(%p) %s %p\n",This
,debugstr_guid(rguid
),pguidatom
);
327 id
= enumerate_Cookie(COOKIE_MAGIC_GUIDATOM
,&index
);
328 if (id
&& IsEqualGUID(rguid
,get_Cookie_data(id
)))
335 checkguid
= HeapAlloc(GetProcessHeap(),0,sizeof(GUID
));
337 id
= generate_Cookie(COOKIE_MAGIC_GUIDATOM
,checkguid
);
341 HeapFree(GetProcessHeap(),0,checkguid
);
350 static HRESULT WINAPI
CategoryMgr_GetGUID ( ITfCategoryMgr
*iface
,
351 TfGuidAtom guidatom
, GUID
*pguid
)
353 CategoryMgr
*This
= (CategoryMgr
*)iface
;
355 TRACE("(%p) %i\n",This
,guidatom
);
362 if (get_Cookie_magic(guidatom
) == COOKIE_MAGIC_GUIDATOM
)
363 *pguid
= *((REFGUID
)get_Cookie_data(guidatom
));
368 static HRESULT WINAPI
CategoryMgr_IsEqualTfGuidAtom ( ITfCategoryMgr
*iface
,
369 TfGuidAtom guidatom
, REFGUID rguid
, BOOL
*pfEqual
)
371 CategoryMgr
*This
= (CategoryMgr
*)iface
;
373 TRACE("(%p) %i %s %p\n",This
,guidatom
,debugstr_guid(rguid
),pfEqual
);
379 if (get_Cookie_magic(guidatom
) == COOKIE_MAGIC_GUIDATOM
)
381 if (IsEqualGUID(rguid
,get_Cookie_data(guidatom
)))
389 static const ITfCategoryMgrVtbl CategoryMgr_CategoryMgrVtbl
=
391 CategoryMgr_QueryInterface
,
395 CategoryMgr_RegisterCategory
,
396 CategoryMgr_UnregisterCategory
,
397 CategoryMgr_EnumCategoriesInItem
,
398 CategoryMgr_EnumItemsInCategory
,
399 CategoryMgr_FindClosestCategory
,
400 CategoryMgr_RegisterGUIDDescription
,
401 CategoryMgr_UnregisterGUIDDescription
,
402 CategoryMgr_GetGUIDDescription
,
403 CategoryMgr_RegisterGUIDDWORD
,
404 CategoryMgr_UnregisterGUIDDWORD
,
405 CategoryMgr_GetGUIDDWORD
,
406 CategoryMgr_RegisterGUID
,
408 CategoryMgr_IsEqualTfGuidAtom
411 HRESULT
CategoryMgr_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
415 return CLASS_E_NOAGGREGATION
;
417 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(CategoryMgr
));
419 return E_OUTOFMEMORY
;
421 This
->CategoryMgrVtbl
= &CategoryMgr_CategoryMgrVtbl
;
424 TRACE("returning %p\n", This
);
425 *ppOut
= (IUnknown
*)This
;