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
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
31 #include <wine/debug.h>
35 //#include "winuser.h"
36 //#include "shlwapi.h"
37 //#include "winerror.h"
40 #include <wine/unicode.h>
43 #include "msctf_internal.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msctf
);
47 typedef struct tagCategoryMgr
{
48 ITfCategoryMgr ITfCategoryMgr_iface
;
52 static inline CategoryMgr
*impl_from_ITfCategoryMgr(ITfCategoryMgr
*iface
)
54 return CONTAINING_RECORD(iface
, CategoryMgr
, ITfCategoryMgr_iface
);
57 static void CategoryMgr_Destructor(CategoryMgr
*This
)
59 TRACE("destroying %p\n", This
);
60 HeapFree(GetProcessHeap(),0,This
);
63 static HRESULT WINAPI
CategoryMgr_QueryInterface(ITfCategoryMgr
*iface
, REFIID iid
, LPVOID
*ppvOut
)
65 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
68 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfCategoryMgr
))
75 IUnknown_AddRef(iface
);
79 WARN("unsupported interface: %s\n", debugstr_guid(iid
));
83 static ULONG WINAPI
CategoryMgr_AddRef(ITfCategoryMgr
*iface
)
85 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
86 return InterlockedIncrement(&This
->refCount
);
89 static ULONG WINAPI
CategoryMgr_Release(ITfCategoryMgr
*iface
)
91 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
94 ret
= InterlockedDecrement(&This
->refCount
);
96 CategoryMgr_Destructor(This
);
100 /*****************************************************
101 * ITfCategoryMgr functions
102 *****************************************************/
104 static HRESULT WINAPI
CategoryMgr_RegisterCategory ( ITfCategoryMgr
*iface
,
105 REFCLSID rclsid
, REFGUID rcatid
, REFGUID rguid
)
111 HKEY tipkey
,catkey
,itmkey
;
112 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
114 static const WCHAR ctg
[] = {'C','a','t','e','g','o','r','y',0};
115 static const WCHAR itm
[] = {'I','t','e','m',0};
116 static const WCHAR fmt
[] = {'%','s','\\','%','s',0};
117 static const WCHAR fmt2
[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
119 TRACE("(%p) %s %s %s\n",This
,debugstr_guid(rclsid
), debugstr_guid(rcatid
), debugstr_guid(rguid
));
121 StringFromGUID2(rclsid
, buf
, 39);
122 sprintfW(fullkey
,fmt
,szwSystemTIPKey
,buf
);
124 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, KEY_READ
| KEY_WRITE
,
125 &tipkey
) != ERROR_SUCCESS
)
128 StringFromGUID2(rcatid
, buf
, 39);
129 StringFromGUID2(rguid
, buf2
, 39);
130 sprintfW(fullkey
,fmt2
,ctg
,ctg
,buf
,buf2
);
132 res
= RegCreateKeyExW(tipkey
, fullkey
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
133 NULL
, &catkey
, NULL
);
138 sprintfW(fullkey
,fmt2
,ctg
,itm
,buf2
,buf
);
139 res
= RegCreateKeyExW(tipkey
, fullkey
, 0, NULL
, 0, KEY_READ
| KEY_WRITE
,
140 NULL
, &itmkey
, NULL
);
153 static HRESULT WINAPI
CategoryMgr_UnregisterCategory ( ITfCategoryMgr
*iface
,
154 REFCLSID rclsid
, REFGUID rcatid
, REFGUID rguid
)
160 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
162 static const WCHAR ctg
[] = {'C','a','t','e','g','o','r','y',0};
163 static const WCHAR itm
[] = {'I','t','e','m',0};
164 static const WCHAR fmt
[] = {'%','s','\\','%','s',0};
165 static const WCHAR fmt2
[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
167 TRACE("(%p) %s %s %s\n",This
,debugstr_guid(rclsid
), debugstr_guid(rcatid
), debugstr_guid(rguid
));
169 StringFromGUID2(rclsid
, buf
, 39);
170 sprintfW(fullkey
,fmt
,szwSystemTIPKey
,buf
);
172 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, KEY_READ
| KEY_WRITE
,
173 &tipkey
) != ERROR_SUCCESS
)
176 StringFromGUID2(rcatid
, buf
, 39);
177 StringFromGUID2(rguid
, buf2
, 39);
178 sprintfW(fullkey
,fmt2
,ctg
,ctg
,buf
,buf2
);
180 sprintfW(fullkey
,fmt2
,ctg
,itm
,buf2
,buf
);
181 RegDeleteTreeW(tipkey
, fullkey
);
182 sprintfW(fullkey
,fmt2
,ctg
,itm
,buf2
,buf
);
183 RegDeleteTreeW(tipkey
, fullkey
);
189 static HRESULT WINAPI
CategoryMgr_EnumCategoriesInItem ( ITfCategoryMgr
*iface
,
190 REFGUID rguid
, IEnumGUID
**ppEnum
)
192 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
193 FIXME("STUB:(%p)\n",This
);
197 static HRESULT WINAPI
CategoryMgr_EnumItemsInCategory ( ITfCategoryMgr
*iface
,
198 REFGUID rcatid
, IEnumGUID
**ppEnum
)
200 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
201 FIXME("STUB:(%p)\n",This
);
205 static HRESULT WINAPI
CategoryMgr_FindClosestCategory ( ITfCategoryMgr
*iface
,
206 REFGUID rguid
, GUID
*pcatid
, const GUID
**ppcatidList
, ULONG ulCount
)
208 static const WCHAR fmt
[] = { '%','s','\\','%','s','\\','C','a','t','e','g','o','r','y','\\','I','t','e','m','\\','%','s',0};
213 HRESULT hr
= S_FALSE
;
215 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
217 TRACE("(%p)\n",This
);
219 if (!pcatid
|| (ulCount
&& ppcatidList
== NULL
))
222 StringFromGUID2(rguid
, buf
, 39);
223 sprintfW(fullkey
,fmt
,szwSystemTIPKey
,buf
,buf
);
226 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,fullkey
, 0, KEY_READ
, &key
) !=
239 res
= RegEnumKeyExW(key
, index
, catid
, &cName
, NULL
, NULL
, NULL
, NULL
);
240 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
243 hr2
= CLSIDFromString(catid
, &guid
);
244 if (FAILED(hr2
)) continue;
250 for (j
= 0; j
< ulCount
; j
++)
251 if (IsEqualGUID(&guid
, ppcatidList
[j
]))
271 static HRESULT WINAPI
CategoryMgr_RegisterGUIDDescription (
272 ITfCategoryMgr
*iface
, REFCLSID rclsid
, REFGUID rguid
,
273 const WCHAR
*pchDesc
, ULONG cch
)
275 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
276 FIXME("STUB:(%p)\n",This
);
280 static HRESULT WINAPI
CategoryMgr_UnregisterGUIDDescription (
281 ITfCategoryMgr
*iface
, REFCLSID rclsid
, REFGUID rguid
)
283 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
284 FIXME("STUB:(%p)\n",This
);
288 static HRESULT WINAPI
CategoryMgr_GetGUIDDescription ( ITfCategoryMgr
*iface
,
289 REFGUID rguid
, BSTR
*pbstrDesc
)
291 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
292 FIXME("STUB:(%p)\n",This
);
296 static HRESULT WINAPI
CategoryMgr_RegisterGUIDDWORD ( ITfCategoryMgr
*iface
,
297 REFCLSID rclsid
, REFGUID rguid
, DWORD dw
)
299 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
300 FIXME("STUB:(%p)\n",This
);
304 static HRESULT WINAPI
CategoryMgr_UnregisterGUIDDWORD ( ITfCategoryMgr
*iface
,
305 REFCLSID rclsid
, REFGUID rguid
)
307 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
308 FIXME("STUB:(%p)\n",This
);
312 static HRESULT WINAPI
CategoryMgr_GetGUIDDWORD ( ITfCategoryMgr
*iface
,
313 REFGUID rguid
, DWORD
*pdw
)
315 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
316 FIXME("STUB:(%p)\n",This
);
320 static HRESULT WINAPI
CategoryMgr_RegisterGUID ( ITfCategoryMgr
*iface
,
321 REFGUID rguid
, TfGuidAtom
*pguidatom
327 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
329 TRACE("(%p) %s %p\n",This
,debugstr_guid(rguid
),pguidatom
);
336 id
= enumerate_Cookie(COOKIE_MAGIC_GUIDATOM
,&index
);
337 if (id
&& IsEqualGUID(rguid
,get_Cookie_data(id
)))
344 checkguid
= HeapAlloc(GetProcessHeap(),0,sizeof(GUID
));
346 id
= generate_Cookie(COOKIE_MAGIC_GUIDATOM
,checkguid
);
350 HeapFree(GetProcessHeap(),0,checkguid
);
359 static HRESULT WINAPI
CategoryMgr_GetGUID ( ITfCategoryMgr
*iface
,
360 TfGuidAtom guidatom
, GUID
*pguid
)
362 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
364 TRACE("(%p) %i\n",This
,guidatom
);
371 if (get_Cookie_magic(guidatom
) == COOKIE_MAGIC_GUIDATOM
)
372 *pguid
= *((REFGUID
)get_Cookie_data(guidatom
));
377 static HRESULT WINAPI
CategoryMgr_IsEqualTfGuidAtom ( ITfCategoryMgr
*iface
,
378 TfGuidAtom guidatom
, REFGUID rguid
, BOOL
*pfEqual
)
380 CategoryMgr
*This
= impl_from_ITfCategoryMgr(iface
);
382 TRACE("(%p) %i %s %p\n",This
,guidatom
,debugstr_guid(rguid
),pfEqual
);
388 if (get_Cookie_magic(guidatom
) == COOKIE_MAGIC_GUIDATOM
)
390 if (IsEqualGUID(rguid
,get_Cookie_data(guidatom
)))
398 static const ITfCategoryMgrVtbl CategoryMgr_CategoryMgrVtbl
=
400 CategoryMgr_QueryInterface
,
404 CategoryMgr_RegisterCategory
,
405 CategoryMgr_UnregisterCategory
,
406 CategoryMgr_EnumCategoriesInItem
,
407 CategoryMgr_EnumItemsInCategory
,
408 CategoryMgr_FindClosestCategory
,
409 CategoryMgr_RegisterGUIDDescription
,
410 CategoryMgr_UnregisterGUIDDescription
,
411 CategoryMgr_GetGUIDDescription
,
412 CategoryMgr_RegisterGUIDDWORD
,
413 CategoryMgr_UnregisterGUIDDWORD
,
414 CategoryMgr_GetGUIDDWORD
,
415 CategoryMgr_RegisterGUID
,
417 CategoryMgr_IsEqualTfGuidAtom
420 HRESULT
CategoryMgr_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
424 return CLASS_E_NOAGGREGATION
;
426 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(CategoryMgr
));
428 return E_OUTOFMEMORY
;
430 This
->ITfCategoryMgr_iface
.lpVtbl
= &CategoryMgr_CategoryMgrVtbl
;
433 TRACE("returning %p\n", This
);
434 *ppOut
= (IUnknown
*)This
;