ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

categorymgr.c
Go to the documentation of this file.
00001 /*
00002  *  ITfCategoryMgr implementation
00003  *
00004  *  Copyright 2009 Aric Stewart, CodeWeavers
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "config.h"
00022 
00023 #include <stdarg.h>
00024 
00025 #define COBJMACROS
00026 
00027 #include "wine/debug.h"
00028 #include "windef.h"
00029 #include "winbase.h"
00030 #include "winreg.h"
00031 #include "winuser.h"
00032 #include "shlwapi.h"
00033 #include "winerror.h"
00034 #include "objbase.h"
00035 
00036 #include "wine/unicode.h"
00037 
00038 #include "msctf.h"
00039 #include "msctf_internal.h"
00040 
00041 WINE_DEFAULT_DEBUG_CHANNEL(msctf);
00042 
00043 typedef struct tagCategoryMgr {
00044     ITfCategoryMgr ITfCategoryMgr_iface;
00045     LONG refCount;
00046 } CategoryMgr;
00047 
00048 static inline CategoryMgr *impl_from_ITfCategoryMgr(ITfCategoryMgr *iface)
00049 {
00050     return CONTAINING_RECORD(iface, CategoryMgr, ITfCategoryMgr_iface);
00051 }
00052 
00053 static void CategoryMgr_Destructor(CategoryMgr *This)
00054 {
00055     TRACE("destroying %p\n", This);
00056     HeapFree(GetProcessHeap(),0,This);
00057 }
00058 
00059 static HRESULT WINAPI CategoryMgr_QueryInterface(ITfCategoryMgr *iface, REFIID iid, LPVOID *ppvOut)
00060 {
00061     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00062     *ppvOut = NULL;
00063 
00064     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfCategoryMgr))
00065     {
00066         *ppvOut = This;
00067     }
00068 
00069     if (*ppvOut)
00070     {
00071         IUnknown_AddRef(iface);
00072         return S_OK;
00073     }
00074 
00075     WARN("unsupported interface: %s\n", debugstr_guid(iid));
00076     return E_NOINTERFACE;
00077 }
00078 
00079 static ULONG WINAPI CategoryMgr_AddRef(ITfCategoryMgr *iface)
00080 {
00081     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00082     return InterlockedIncrement(&This->refCount);
00083 }
00084 
00085 static ULONG WINAPI CategoryMgr_Release(ITfCategoryMgr *iface)
00086 {
00087     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00088     ULONG ret;
00089 
00090     ret = InterlockedDecrement(&This->refCount);
00091     if (ret == 0)
00092         CategoryMgr_Destructor(This);
00093     return ret;
00094 }
00095 
00096 /*****************************************************
00097  * ITfCategoryMgr functions
00098  *****************************************************/
00099 
00100 static HRESULT WINAPI CategoryMgr_RegisterCategory ( ITfCategoryMgr *iface,
00101         REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
00102 {
00103     WCHAR fullkey[110];
00104     WCHAR buf[39];
00105     WCHAR buf2[39];
00106     ULONG res;
00107     HKEY tipkey,catkey,itmkey;
00108     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00109 
00110     static const WCHAR ctg[] = {'C','a','t','e','g','o','r','y',0};
00111     static const WCHAR itm[] = {'I','t','e','m',0};
00112     static const WCHAR fmt[] = {'%','s','\\','%','s',0};
00113     static const WCHAR fmt2[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
00114 
00115     TRACE("(%p) %s %s %s\n",This,debugstr_guid(rclsid), debugstr_guid(rcatid), debugstr_guid(rguid));
00116 
00117     StringFromGUID2(rclsid, buf, 39);
00118     sprintfW(fullkey,fmt,szwSystemTIPKey,buf);
00119 
00120     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
00121                 &tipkey ) != ERROR_SUCCESS)
00122         return E_FAIL;
00123 
00124     StringFromGUID2(rcatid, buf, 39);
00125     StringFromGUID2(rguid, buf2, 39);
00126     sprintfW(fullkey,fmt2,ctg,ctg,buf,buf2);
00127 
00128     res = RegCreateKeyExW(tipkey, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
00129             NULL, &catkey, NULL);
00130     RegCloseKey(catkey);
00131 
00132     if (!res)
00133     {
00134         sprintfW(fullkey,fmt2,ctg,itm,buf2,buf);
00135         res = RegCreateKeyExW(tipkey, fullkey, 0, NULL, 0, KEY_READ | KEY_WRITE,
00136                 NULL, &itmkey, NULL);
00137 
00138         RegCloseKey(itmkey);
00139     }
00140 
00141     RegCloseKey(tipkey);
00142 
00143     if (!res)
00144         return S_OK;
00145     else
00146         return E_FAIL;
00147 }
00148 
00149 static HRESULT WINAPI CategoryMgr_UnregisterCategory ( ITfCategoryMgr *iface,
00150         REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
00151 {
00152     WCHAR fullkey[110];
00153     WCHAR buf[39];
00154     WCHAR buf2[39];
00155     HKEY tipkey;
00156     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00157 
00158     static const WCHAR ctg[] = {'C','a','t','e','g','o','r','y',0};
00159     static const WCHAR itm[] = {'I','t','e','m',0};
00160     static const WCHAR fmt[] = {'%','s','\\','%','s',0};
00161     static const WCHAR fmt2[] = {'%','s','\\','%','s','\\','%','s','\\','%','s',0};
00162 
00163     TRACE("(%p) %s %s %s\n",This,debugstr_guid(rclsid), debugstr_guid(rcatid), debugstr_guid(rguid));
00164 
00165     StringFromGUID2(rclsid, buf, 39);
00166     sprintfW(fullkey,fmt,szwSystemTIPKey,buf);
00167 
00168     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ | KEY_WRITE,
00169                 &tipkey ) != ERROR_SUCCESS)
00170         return E_FAIL;
00171 
00172     StringFromGUID2(rcatid, buf, 39);
00173     StringFromGUID2(rguid, buf2, 39);
00174     sprintfW(fullkey,fmt2,ctg,ctg,buf,buf2);
00175 
00176     sprintfW(fullkey,fmt2,ctg,itm,buf2,buf);
00177     RegDeleteTreeW(tipkey, fullkey);
00178     sprintfW(fullkey,fmt2,ctg,itm,buf2,buf);
00179     RegDeleteTreeW(tipkey, fullkey);
00180 
00181     RegCloseKey(tipkey);
00182     return S_OK;
00183 }
00184 
00185 static HRESULT WINAPI CategoryMgr_EnumCategoriesInItem ( ITfCategoryMgr *iface,
00186         REFGUID rguid, IEnumGUID **ppEnum)
00187 {
00188     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00189     FIXME("STUB:(%p)\n",This);
00190     return E_NOTIMPL;
00191 }
00192 
00193 static HRESULT WINAPI CategoryMgr_EnumItemsInCategory ( ITfCategoryMgr *iface,
00194         REFGUID rcatid, IEnumGUID **ppEnum)
00195 {
00196     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00197     FIXME("STUB:(%p)\n",This);
00198     return E_NOTIMPL;
00199 }
00200 
00201 static HRESULT WINAPI CategoryMgr_FindClosestCategory ( ITfCategoryMgr *iface,
00202         REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount)
00203 {
00204     static const WCHAR fmt[] = { '%','s','\\','%','s','\\','C','a','t','e','g','o','r','y','\\','I','t','e','m','\\','%','s',0};
00205 
00206     WCHAR fullkey[120];
00207     WCHAR buf[39];
00208     HKEY key;
00209     HRESULT hr = S_FALSE;
00210     INT index = 0;
00211     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00212 
00213     TRACE("(%p)\n",This);
00214 
00215     if (!pcatid || (ulCount && ppcatidList == NULL))
00216         return E_INVALIDARG;
00217 
00218     StringFromGUID2(rguid, buf, 39);
00219     sprintfW(fullkey,fmt,szwSystemTIPKey,buf,buf);
00220     *pcatid = GUID_NULL;
00221 
00222     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,fullkey, 0, KEY_READ, &key ) !=
00223             ERROR_SUCCESS)
00224         return S_FALSE;
00225 
00226     while (1)
00227     {
00228         HRESULT hr2;
00229         ULONG res;
00230         GUID guid;
00231         WCHAR catid[39];
00232         DWORD cName;
00233 
00234         cName = 39;
00235         res = RegEnumKeyExW(key, index, catid, &cName, NULL, NULL, NULL, NULL);
00236         if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
00237         index ++;
00238 
00239         hr2 = CLSIDFromString(catid, &guid);
00240         if (FAILED(hr2)) continue;
00241 
00242         if (ulCount)
00243         {
00244             int j;
00245             BOOL found = FALSE;
00246             for (j = 0; j < ulCount; j++)
00247                 if (IsEqualGUID(&guid, ppcatidList[j]))
00248                 {
00249                     found = TRUE;
00250                     *pcatid = guid;
00251                     hr = S_OK;
00252                     break;
00253                 }
00254             if (found) break;
00255         }
00256         else
00257         {
00258             *pcatid = guid;
00259             hr = S_OK;
00260             break;
00261         }
00262     }
00263 
00264     return hr;
00265 }
00266 
00267 static HRESULT WINAPI CategoryMgr_RegisterGUIDDescription (
00268         ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid,
00269         const WCHAR *pchDesc, ULONG cch)
00270 {
00271     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00272     FIXME("STUB:(%p)\n",This);
00273     return E_NOTIMPL;
00274 }
00275 
00276 static HRESULT WINAPI CategoryMgr_UnregisterGUIDDescription (
00277         ITfCategoryMgr *iface, REFCLSID rclsid, REFGUID rguid)
00278 {
00279     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00280     FIXME("STUB:(%p)\n",This);
00281     return E_NOTIMPL;
00282 }
00283 
00284 static HRESULT WINAPI CategoryMgr_GetGUIDDescription ( ITfCategoryMgr *iface,
00285         REFGUID rguid, BSTR *pbstrDesc)
00286 {
00287     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00288     FIXME("STUB:(%p)\n",This);
00289     return E_NOTIMPL;
00290 }
00291 
00292 static HRESULT WINAPI CategoryMgr_RegisterGUIDDWORD ( ITfCategoryMgr *iface,
00293         REFCLSID rclsid, REFGUID rguid, DWORD dw)
00294 {
00295     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00296     FIXME("STUB:(%p)\n",This);
00297     return E_NOTIMPL;
00298 }
00299 
00300 static HRESULT WINAPI CategoryMgr_UnregisterGUIDDWORD ( ITfCategoryMgr *iface,
00301         REFCLSID rclsid, REFGUID rguid)
00302 {
00303     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00304     FIXME("STUB:(%p)\n",This);
00305     return E_NOTIMPL;
00306 }
00307 
00308 static HRESULT WINAPI CategoryMgr_GetGUIDDWORD ( ITfCategoryMgr *iface,
00309         REFGUID rguid, DWORD *pdw)
00310 {
00311     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00312     FIXME("STUB:(%p)\n",This);
00313     return E_NOTIMPL;
00314 }
00315 
00316 static HRESULT WINAPI CategoryMgr_RegisterGUID ( ITfCategoryMgr *iface,
00317         REFGUID rguid, TfGuidAtom *pguidatom
00318 )
00319 {
00320     DWORD index;
00321     GUID *checkguid;
00322     DWORD id;
00323     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00324 
00325     TRACE("(%p) %s %p\n",This,debugstr_guid(rguid),pguidatom);
00326 
00327     if (!pguidatom)
00328         return E_INVALIDARG;
00329 
00330     index = 0;
00331     do {
00332         id = enumerate_Cookie(COOKIE_MAGIC_GUIDATOM,&index);
00333         if (id && IsEqualGUID(rguid,get_Cookie_data(id)))
00334         {
00335             *pguidatom = id;
00336             return S_OK;
00337         }
00338     } while(id);
00339 
00340     checkguid = HeapAlloc(GetProcessHeap(),0,sizeof(GUID));
00341     *checkguid = *rguid;
00342     id = generate_Cookie(COOKIE_MAGIC_GUIDATOM,checkguid);
00343 
00344     if (!id)
00345     {
00346         HeapFree(GetProcessHeap(),0,checkguid);
00347         return E_FAIL;
00348     }
00349 
00350     *pguidatom = id;
00351 
00352     return S_OK;
00353 }
00354 
00355 static HRESULT WINAPI CategoryMgr_GetGUID ( ITfCategoryMgr *iface,
00356         TfGuidAtom guidatom, GUID *pguid)
00357 {
00358     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00359 
00360     TRACE("(%p) %i\n",This,guidatom);
00361 
00362     if (!pguid)
00363         return E_INVALIDARG;
00364 
00365     *pguid = GUID_NULL;
00366 
00367     if (get_Cookie_magic(guidatom) == COOKIE_MAGIC_GUIDATOM)
00368         *pguid = *((REFGUID)get_Cookie_data(guidatom));
00369 
00370     return S_OK;
00371 }
00372 
00373 static HRESULT WINAPI CategoryMgr_IsEqualTfGuidAtom ( ITfCategoryMgr *iface,
00374         TfGuidAtom guidatom, REFGUID rguid, BOOL *pfEqual)
00375 {
00376     CategoryMgr *This = impl_from_ITfCategoryMgr(iface);
00377 
00378     TRACE("(%p) %i %s %p\n",This,guidatom,debugstr_guid(rguid),pfEqual);
00379 
00380     if (!pfEqual)
00381         return E_INVALIDARG;
00382 
00383     *pfEqual = FALSE;
00384     if (get_Cookie_magic(guidatom) == COOKIE_MAGIC_GUIDATOM)
00385     {
00386         if (IsEqualGUID(rguid,get_Cookie_data(guidatom)))
00387             *pfEqual = TRUE;
00388     }
00389 
00390     return S_OK;
00391 }
00392 
00393 
00394 static const ITfCategoryMgrVtbl CategoryMgr_CategoryMgrVtbl =
00395 {
00396     CategoryMgr_QueryInterface,
00397     CategoryMgr_AddRef,
00398     CategoryMgr_Release,
00399 
00400     CategoryMgr_RegisterCategory,
00401     CategoryMgr_UnregisterCategory,
00402     CategoryMgr_EnumCategoriesInItem,
00403     CategoryMgr_EnumItemsInCategory,
00404     CategoryMgr_FindClosestCategory,
00405     CategoryMgr_RegisterGUIDDescription,
00406     CategoryMgr_UnregisterGUIDDescription,
00407     CategoryMgr_GetGUIDDescription,
00408     CategoryMgr_RegisterGUIDDWORD,
00409     CategoryMgr_UnregisterGUIDDWORD,
00410     CategoryMgr_GetGUIDDWORD,
00411     CategoryMgr_RegisterGUID,
00412     CategoryMgr_GetGUID,
00413     CategoryMgr_IsEqualTfGuidAtom
00414 };
00415 
00416 HRESULT CategoryMgr_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
00417 {
00418     CategoryMgr *This;
00419     if (pUnkOuter)
00420         return CLASS_E_NOAGGREGATION;
00421 
00422     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CategoryMgr));
00423     if (This == NULL)
00424         return E_OUTOFMEMORY;
00425 
00426     This->ITfCategoryMgr_iface.lpVtbl = &CategoryMgr_CategoryMgrVtbl;
00427     This->refCount = 1;
00428 
00429     TRACE("returning %p\n", This);
00430     *ppOut = (IUnknown *)This;
00431     return S_OK;
00432 }

Generated on Sun May 27 2012 04:24:49 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.