ReactOS 0.4.15-dev-7934-g1dc8d80
categorymgr.c
Go to the documentation of this file.
1/*
2 * ITfCategoryMgr 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 <stdarg.h>
22#ifdef __REACTOS__
23#include <wchar.h>
24#endif
25
26#define COBJMACROS
27
28#include "wine/debug.h"
29#include "windef.h"
30#include "winbase.h"
31#include "winreg.h"
32#include "winuser.h"
33#include "shlwapi.h"
34#include "winerror.h"
35#include "objbase.h"
36
37
38#include "msctf.h"
39#include "msctf_internal.h"
40
42
43typedef struct tagCategoryMgr {
47
49{
50 return CONTAINING_RECORD(iface, CategoryMgr, ITfCategoryMgr_iface);
51}
52
54{
55 TRACE("destroying %p\n", This);
57}
58
60{
62 *ppvOut = NULL;
63
64 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfCategoryMgr))
65 {
66 *ppvOut = &This->ITfCategoryMgr_iface;
67 }
68
69 if (*ppvOut)
70 {
71 ITfCategoryMgr_AddRef(iface);
72 return S_OK;
73 }
74
75 WARN("unsupported interface: %s\n", debugstr_guid(iid));
76 return E_NOINTERFACE;
77}
78
80{
82 return InterlockedIncrement(&This->refCount);
83}
84
86{
88 ULONG ret;
89
90 ret = InterlockedDecrement(&This->refCount);
91 if (ret == 0)
93 return ret;
94}
95
96/*****************************************************
97 * ITfCategoryMgr functions
98 *****************************************************/
99
101 REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
102{
103 WCHAR fullkey[110];
104 WCHAR buf[39];
105 WCHAR buf2[39];
106 ULONG res;
107 HKEY tipkey,catkey,itmkey;
109
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};
114
115 TRACE("(%p) %s %s %s\n",This,debugstr_guid(rclsid), debugstr_guid(rcatid), debugstr_guid(rguid));
116
117 StringFromGUID2(rclsid, buf, 39);
119
121 &tipkey ) != ERROR_SUCCESS)
122 return E_FAIL;
123
124 StringFromGUID2(rcatid, buf, 39);
125 StringFromGUID2(rguid, buf2, 39);
126 swprintf(fullkey,fmt2,ctg,ctg,buf,buf2);
127
128 res = RegCreateKeyExW(tipkey, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
129 NULL, &catkey, NULL);
130 RegCloseKey(catkey);
131
132 if (!res)
133 {
134 swprintf(fullkey,fmt2,ctg,itm,buf2,buf);
135 res = RegCreateKeyExW(tipkey, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
136 NULL, &itmkey, NULL);
137
138 RegCloseKey(itmkey);
139 }
140
141 RegCloseKey(tipkey);
142
143 if (!res)
144 return S_OK;
145 else
146 return E_FAIL;
147}
148
150 REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
151{
152 WCHAR fullkey[110];
153 WCHAR buf[39];
154 WCHAR buf2[39];
155 HKEY tipkey;
157
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};
162
163 TRACE("(%p) %s %s %s\n",This,debugstr_guid(rclsid), debugstr_guid(rcatid), debugstr_guid(rguid));
164
165 StringFromGUID2(rclsid, buf, 39);
167
169 &tipkey ) != ERROR_SUCCESS)
170 return E_FAIL;
171
172 StringFromGUID2(rcatid, buf, 39);
173 StringFromGUID2(rguid, buf2, 39);
174 swprintf(fullkey,fmt2,ctg,ctg,buf,buf2);
175 RegDeleteTreeW(tipkey, fullkey);
176 swprintf(fullkey,fmt2,ctg,itm,buf2,buf);
177 RegDeleteTreeW(tipkey, fullkey);
178
179 RegCloseKey(tipkey);
180 return S_OK;
181}
182
184 REFGUID rguid, IEnumGUID **ppEnum)
185{
187 FIXME("STUB:(%p)\n",This);
188 return E_NOTIMPL;
189}
190
192 REFGUID rcatid, IEnumGUID **ppEnum)
193{
195 FIXME("STUB:(%p)\n",This);
196 return E_NOTIMPL;
197}
198
200 REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount)
201{
202 static const WCHAR fmt[] = { '%','s','\\','%','s','\\','C','a','t','e','g','o','r','y','\\','I','t','e','m','\\','%','s',0};
203
204 WCHAR fullkey[120];
205 WCHAR buf[39];
206 HKEY key;
208 INT index = 0;
210
211 TRACE("(%p)\n",This);
212
213 if (!pcatid || (ulCount && ppcatidList == NULL))
214 return E_INVALIDARG;
215
216 StringFromGUID2(rguid, buf, 39);
218 *pcatid = GUID_NULL;
219
220 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ, &key ) !=
222 return S_FALSE;
223
224 while (1)
225 {
226 HRESULT hr2;
227 ULONG res;
228 GUID guid;
229 WCHAR catid[39];
230 DWORD cName;
231
232 cName = 39;
233 res = RegEnumKeyExW(key, index, catid, &cName, NULL, NULL, NULL, NULL);
234 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
235 index ++;
236
237 hr2 = CLSIDFromString(catid, &guid);
238 if (FAILED(hr2)) continue;
239
240 if (ulCount)
241 {
242 ULONG j;
243 BOOL found = FALSE;
244 for (j = 0; j < ulCount; j++)
245 if (IsEqualGUID(&guid, ppcatidList[j]))
246 {
247 found = TRUE;
248 *pcatid = guid;
249 hr = S_OK;
250 break;
251 }
252 if (found) break;
253 }
254 else
255 {
256 *pcatid = guid;
257 hr = S_OK;
258 break;
259 }
260 }
261
262 return hr;
263}
264
266 ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid,
267 const WCHAR *pchDesc, ULONG cch)
268{
270 FIXME("STUB:(%p)\n",This);
271 return E_NOTIMPL;
272}
273
275 ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid)
276{
278 FIXME("STUB:(%p)\n",This);
279 return E_NOTIMPL;
280}
281
283 REFGUID rguid, BSTR *pbstrDesc)
284{
286 FIXME("STUB:(%p)\n",This);
287 return E_NOTIMPL;
288}
289
291 REFCLSID rclsid, REFGUID rguid, DWORD dw)
292{
294 FIXME("STUB:(%p)\n",This);
295 return E_NOTIMPL;
296}
297
299 REFCLSID rclsid, REFGUID rguid)
300{
302 FIXME("STUB:(%p)\n",This);
303 return E_NOTIMPL;
304}
305
307 REFGUID rguid, DWORD *pdw)
308{
310 FIXME("STUB:(%p)\n",This);
311 return E_NOTIMPL;
312}
313
315 REFGUID rguid, TfGuidAtom *pguidatom
316)
317{
318 DWORD index;
319 GUID *checkguid;
320 DWORD id;
322
323 TRACE("(%p) %s %p\n",This,debugstr_guid(rguid),pguidatom);
324
325 if (!pguidatom)
326 return E_INVALIDARG;
327
328 index = 0;
329 do {
331 if (id && IsEqualGUID(rguid,get_Cookie_data(id)))
332 {
333 *pguidatom = id;
334 return S_OK;
335 }
336 } while(id);
337
338 checkguid = HeapAlloc(GetProcessHeap(),0,sizeof(GUID));
339 *checkguid = *rguid;
341
342 if (!id)
343 {
344 HeapFree(GetProcessHeap(),0,checkguid);
345 return E_FAIL;
346 }
347
348 *pguidatom = id;
349
350 return S_OK;
351}
352
354 TfGuidAtom guidatom, GUID *pguid)
355{
357
358 TRACE("(%p) %i\n",This,guidatom);
359
360 if (!pguid)
361 return E_INVALIDARG;
362
363 *pguid = GUID_NULL;
364
366 *pguid = *((REFGUID)get_Cookie_data(guidatom));
367
368 return S_OK;
369}
370
372 TfGuidAtom guidatom, REFGUID rguid, BOOL *pfEqual)
373{
375
376 TRACE("(%p) %i %s %p\n",This,guidatom,debugstr_guid(rguid),pfEqual);
377
378 if (!pfEqual)
379 return E_INVALIDARG;
380
381 *pfEqual = FALSE;
383 {
384 if (IsEqualGUID(rguid,get_Cookie_data(guidatom)))
385 *pfEqual = TRUE;
386 }
387
388 return S_OK;
389}
390
391
392static const ITfCategoryMgrVtbl CategoryMgrVtbl =
393{
411};
412
414{
416 if (pUnkOuter)
418
420 if (This == NULL)
421 return E_OUTOFMEMORY;
422
423 This->ITfCategoryMgr_iface.lpVtbl = &CategoryMgrVtbl;
424 This->refCount = 1;
425
426 *ppOut = (IUnknown *)&This->ITfCategoryMgr_iface;
427 TRACE("returning %p\n", *ppOut);
428 return S_OK;
429}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define index(s, c)
Definition: various.h:29
const GUID IID_IUnknown
#define FIXME(fmt,...)
Definition: debug.h:111
#define WARN(fmt,...)
Definition: debug.h:112
#define RegCloseKey(hKey)
Definition: registry.h:49
static HRESULT WINAPI CategoryMgr_QueryInterface(ITfCategoryMgr *iface, REFIID iid, LPVOID *ppvOut)
Definition: categorymgr.c:59
static HRESULT WINAPI CategoryMgr_FindClosestCategory(ITfCategoryMgr *iface, REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount)
Definition: categorymgr.c:199
static HRESULT WINAPI CategoryMgr_IsEqualTfGuidAtom(ITfCategoryMgr *iface, TfGuidAtom guidatom, REFGUID rguid, BOOL *pfEqual)
Definition: categorymgr.c:371
static HRESULT WINAPI CategoryMgr_UnregisterCategory(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
Definition: categorymgr.c:149
static HRESULT WINAPI CategoryMgr_UnregisterGUIDDWORD(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid)
Definition: categorymgr.c:298
static HRESULT WINAPI CategoryMgr_RegisterGUIDDescription(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid, const WCHAR *pchDesc, ULONG cch)
Definition: categorymgr.c:265
HRESULT CategoryMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
Definition: categorymgr.c:413
static ULONG WINAPI CategoryMgr_AddRef(ITfCategoryMgr *iface)
Definition: categorymgr.c:79
static HRESULT WINAPI CategoryMgr_RegisterCategory(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
Definition: categorymgr.c:100
static HRESULT WINAPI CategoryMgr_EnumItemsInCategory(ITfCategoryMgr *iface, REFGUID rcatid, IEnumGUID **ppEnum)
Definition: categorymgr.c:191
static HRESULT WINAPI CategoryMgr_RegisterGUIDDWORD(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid, DWORD dw)
Definition: categorymgr.c:290
static HRESULT WINAPI CategoryMgr_GetGUIDDescription(ITfCategoryMgr *iface, REFGUID rguid, BSTR *pbstrDesc)
Definition: categorymgr.c:282
static HRESULT WINAPI CategoryMgr_GetGUID(ITfCategoryMgr *iface, TfGuidAtom guidatom, GUID *pguid)
Definition: categorymgr.c:353
static const ITfCategoryMgrVtbl CategoryMgrVtbl
Definition: categorymgr.c:392
static HRESULT WINAPI CategoryMgr_GetGUIDDWORD(ITfCategoryMgr *iface, REFGUID rguid, DWORD *pdw)
Definition: categorymgr.c:306
static ULONG WINAPI CategoryMgr_Release(ITfCategoryMgr *iface)
Definition: categorymgr.c:85
static HRESULT WINAPI CategoryMgr_RegisterGUID(ITfCategoryMgr *iface, REFGUID rguid, TfGuidAtom *pguidatom)
Definition: categorymgr.c:314
static HRESULT WINAPI CategoryMgr_EnumCategoriesInItem(ITfCategoryMgr *iface, REFGUID rguid, IEnumGUID **ppEnum)
Definition: categorymgr.c:183
static void CategoryMgr_Destructor(CategoryMgr *This)
Definition: categorymgr.c:53
struct tagCategoryMgr CategoryMgr
static HRESULT WINAPI CategoryMgr_UnregisterGUIDDescription(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid)
Definition: categorymgr.c:274
static CategoryMgr * impl_from_ITfCategoryMgr(ITfCategoryMgr *iface)
Definition: categorymgr.c:48
LSTATUS WINAPI RegDeleteTreeW(_In_ HKEY, _In_opt_ LPCWSTR)
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
OLECHAR * BSTR
Definition: compat.h:2293
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
GLuint index
Definition: glext.h:6031
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint id
Definition: glext.h:5910
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
#define GUID_NULL
Definition: ks.h:106
const GUID * guid
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
DWORD get_Cookie_magic(DWORD id)
Definition: msctf.c:233
DWORD enumerate_Cookie(DWORD magic, DWORD *index)
Definition: msctf.c:273
const WCHAR szwSystemTIPKey[]
Definition: msctf.c:76
DWORD generate_Cookie(DWORD magic, LPVOID data)
Definition: msctf.c:189
LPVOID get_Cookie_data(DWORD id)
Definition: msctf.c:246
GUID catid
Definition: msctf.idl:647
DWORD TfGuidAtom
Definition: msctf.idl:106
#define COOKIE_MAGIC_GUIDATOM
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_WRITE
Definition: nt_native.h:1031
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFGUID
Definition: guiddef.h:116
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
Definition: scsiwmi.h:51
Definition: dsound.c:943
Definition: copy.c:22
ITfCategoryMgr ITfCategoryMgr_iface
Definition: categorymgr.c:44
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
int ret
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define E_NOINTERFACE
Definition: winerror.h:2364
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
__wchar_t WCHAR
Definition: xmlstorage.h:180