ReactOS  0.4.14-dev-552-g2fad488
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 
43 typedef struct tagCategoryMgr {
46 } CategoryMgr;
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);
118  swprintf(fullkey,fmt,szwSystemTIPKey,buf);
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);
166  swprintf(fullkey,fmt,szwSystemTIPKey,buf);
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;
207  HRESULT hr = S_FALSE;
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;
340  id = generate_Cookie(COOKIE_MAGIC_GUIDATOM,checkguid);
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 
365  if (get_Cookie_magic(guidatom) == COOKIE_MAGIC_GUIDATOM)
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;
382  if (get_Cookie_magic(guidatom) == COOKIE_MAGIC_GUIDATOM)
383  {
384  if (IsEqualGUID(rguid,get_Cookie_data(guidatom)))
385  *pfEqual = TRUE;
386  }
387 
388  return S_OK;
389 }
390 
391 
392 static const ITfCategoryMgrVtbl CategoryMgrVtbl =
393 {
411 };
412 
414 {
415  CategoryMgr *This;
416  if (pUnkOuter)
417  return CLASS_E_NOAGGREGATION;
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 REFGUID
Definition: guiddef.h:116
static HRESULT WINAPI CategoryMgr_GetGUIDDescription(ITfCategoryMgr *iface, REFGUID rguid, BSTR *pbstrDesc)
Definition: categorymgr.c:282
const WCHAR szwSystemTIPKey[]
Definition: msctf.c:76
WINE_DEFAULT_DEBUG_CHANNEL(msctf)
LPVOID get_Cookie_data(DWORD id)
Definition: msctf.c:246
static void CategoryMgr_Destructor(CategoryMgr *This)
Definition: categorymgr.c:53
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
DWORD enumerate_Cookie(DWORD magic, DWORD *index)
Definition: msctf.c:273
#define E_NOINTERFACE
Definition: winerror.h:2364
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
Definition: scsiwmi.h:51
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define KEY_READ
Definition: nt_native.h:1023
#define REFCLSID
Definition: guiddef.h:117
static HRESULT WINAPI CategoryMgr_EnumItemsInCategory(ITfCategoryMgr *iface, REFGUID rcatid, IEnumGUID **ppEnum)
Definition: categorymgr.c:191
#define WARN(fmt,...)
Definition: debug.h:111
static HRESULT WINAPI CategoryMgr_GetGUIDDWORD(ITfCategoryMgr *iface, REFGUID rguid, DWORD *pdw)
Definition: categorymgr.c:306
static HRESULT WINAPI CategoryMgr_IsEqualTfGuidAtom(ITfCategoryMgr *iface, TfGuidAtom guidatom, REFGUID rguid, BOOL *pfEqual)
Definition: categorymgr.c:371
OLECHAR * BSTR
Definition: compat.h:1942
DWORD get_Cookie_magic(DWORD id)
Definition: msctf.c:233
#define E_FAIL
Definition: ddrawi.h:102
static HRESULT WINAPI CategoryMgr_QueryInterface(ITfCategoryMgr *iface, REFIID iid, LPVOID *ppvOut)
Definition: categorymgr.c:59
int32_t INT
Definition: typedefs.h:56
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:1091
static HRESULT WINAPI CategoryMgr_RegisterGUIDDescription(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid, const WCHAR *pchDesc, ULONG cch)
Definition: categorymgr.c:265
const GUID * guid
#define COOKIE_MAGIC_GUIDATOM
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static HRESULT WINAPI CategoryMgr_GetGUID(ITfCategoryMgr *iface, TfGuidAtom guidatom, GUID *pguid)
Definition: categorymgr.c:353
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define FIXME(fmt,...)
Definition: debug.h:110
static HRESULT WINAPI CategoryMgr_UnregisterGUIDDescription(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid)
Definition: categorymgr.c:274
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:201
smooth NULL
Definition: ftsmooth.c:416
struct tagCategoryMgr CategoryMgr
GUID catid
Definition: msctf.idl:608
GLuint index
Definition: glext.h:6031
static ULONG WINAPI CategoryMgr_Release(ITfCategoryMgr *iface)
Definition: categorymgr.c:85
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
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
#define KEY_WRITE
Definition: nt_native.h:1031
HRESULT CategoryMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
Definition: categorymgr.c:413
#define TRACE(s)
Definition: solgame.cpp:4
static HRESULT WINAPI CategoryMgr_FindClosestCategory(ITfCategoryMgr *iface, REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount)
Definition: categorymgr.c:199
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
static HRESULT WINAPI CategoryMgr_RegisterCategory(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
Definition: categorymgr.c:100
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WINAPI
Definition: msvc.h:8
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
unsigned long DWORD
Definition: ntddk_ex.h:95
REFIID LPVOID DWORD dw
Definition: atlbase.h:40
static HRESULT WINAPI CategoryMgr_RegisterGUID(ITfCategoryMgr *iface, REFGUID rguid, TfGuidAtom *pguidatom)
Definition: categorymgr.c:314
static HRESULT WINAPI CategoryMgr_UnregisterGUIDDWORD(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid)
Definition: categorymgr.c:298
int ret
#define index(s, c)
Definition: various.h:29
#define InterlockedDecrement
Definition: armddk.h:52
HKEY key
Definition: reg.c:42
#define GUID_NULL
Definition: ks.h:106
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
#define ERROR_MORE_DATA
Definition: dderror.h:13
DWORD TfGuidAtom
Definition: msctf.idl:69
LSTATUS WINAPI RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
Definition: reg.c:1746
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
static HRESULT WINAPI CategoryMgr_EnumCategoriesInItem(ITfCategoryMgr *iface, REFGUID rguid, IEnumGUID **ppEnum)
Definition: categorymgr.c:183
#define E_NOTIMPL
Definition: ddrawi.h:99
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
static CategoryMgr * impl_from_ITfCategoryMgr(ITfCategoryMgr *iface)
Definition: categorymgr.c:48
static HRESULT WINAPI CategoryMgr_RegisterGUIDDWORD(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid, DWORD dw)
Definition: categorymgr.c:290
GLuint res
Definition: glext.h:9613
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
unsigned int ULONG
Definition: retypes.h:1
GLenum GLuint id
Definition: glext.h:5579
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
static ULONG WINAPI CategoryMgr_AddRef(ITfCategoryMgr *iface)
Definition: categorymgr.c:79
static const ITfCategoryMgrVtbl CategoryMgrVtbl
Definition: categorymgr.c:392
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:2527
ITfCategoryMgr ITfCategoryMgr_iface
Definition: categorymgr.c:44
Definition: dsound.c:943
#define HeapFree(x, y, z)
Definition: compat.h:402
static HRESULT WINAPI CategoryMgr_UnregisterCategory(ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
Definition: categorymgr.c:149
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
DWORD generate_Cookie(DWORD magic, LPVOID data)
Definition: msctf.c:189
Definition: path.c:42
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12