Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

353 lines
9.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // File: catutil.cpp
  4. //
  5. //
  6. //----------------------------------------------------------------------------
  7. #include "private.h"
  8. #include "globals.h"
  9. #include "catutil.h"
  10. //+---------------------------------------------------------------------------
  11. //
  12. // GetUIMCat
  13. //
  14. //----------------------------------------------------------------------------
  15. ITfCategoryMgr *GetUIMCat(LIBTHREAD *plt)
  16. {
  17. if (!plt)
  18. return NULL;
  19. if (plt->_pcat)
  20. return plt->_pcat;
  21. if (SUCCEEDED(g_pfnCoCreate(CLSID_TF_CategoryMgr,
  22. NULL,
  23. CLSCTX_INPROC_SERVER,
  24. IID_ITfCategoryMgr,
  25. (void**)&plt->_pcat)))
  26. return plt->_pcat;
  27. return NULL;
  28. }
  29. //+---------------------------------------------------------------------------
  30. //
  31. // IsEqualTFGUIDATOM
  32. //
  33. //----------------------------------------------------------------------------
  34. BOOL IsEqualTFGUIDATOM(LIBTHREAD *plt, TfGuidAtom guidatom, REFGUID rguid)
  35. {
  36. BOOL fEqual = FALSE;
  37. ITfCategoryMgr *pcat = GetUIMCat(plt);
  38. if (pcat != NULL)
  39. {
  40. pcat->IsEqualTfGuidAtom(guidatom, rguid, &fEqual);
  41. }
  42. return fEqual;
  43. }
  44. //+---------------------------------------------------------------------------
  45. //
  46. // GetGUIDFromGUIDATOM
  47. //
  48. //----------------------------------------------------------------------------
  49. BOOL GetGUIDFromGUIDATOM(LIBTHREAD *plt, TfGuidAtom guidatom, GUID *pguid)
  50. {
  51. ITfCategoryMgr *pcat = GetUIMCat(plt);
  52. if (pcat == NULL)
  53. return FALSE;
  54. return (pcat->GetGUID(guidatom, pguid) == S_OK);
  55. }
  56. //+---------------------------------------------------------------------------
  57. //
  58. // GetGUIDATOMFromGUID
  59. //
  60. //----------------------------------------------------------------------------
  61. BOOL GetGUIDATOMFromGUID(LIBTHREAD *plt, REFGUID rguid, TfGuidAtom *pguidatom)
  62. {
  63. ITfCategoryMgr *pcat = GetUIMCat(plt);
  64. if (pcat == NULL)
  65. return FALSE;
  66. return (pcat->RegisterGUID(rguid, pguidatom) == S_OK);
  67. }
  68. //+---------------------------------------------------------------------------
  69. //
  70. // LibEnumCategoriesInItem
  71. //
  72. //----------------------------------------------------------------------------
  73. HRESULT LibEnumCategoriesInItem(LIBTHREAD *plt, REFGUID rguid, IEnumGUID **ppEnum)
  74. {
  75. ITfCategoryMgr *pcat = GetUIMCat(plt);
  76. if (pcat == NULL)
  77. return E_FAIL;
  78. return pcat->EnumCategoriesInItem(rguid, ppEnum);
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // LibEnumCategoriesInItem
  83. //
  84. //----------------------------------------------------------------------------
  85. HRESULT LibEnumItemsInCategory(LIBTHREAD *plt, REFGUID rcatid, IEnumGUID **ppEnum)
  86. {
  87. ITfCategoryMgr *pcat = GetUIMCat(plt);
  88. if (pcat == NULL)
  89. return E_FAIL;
  90. return pcat->EnumItemsInCategory(rcatid, ppEnum);
  91. }
  92. //+---------------------------------------------------------------------------
  93. //
  94. // RegisterGUIDDescription
  95. //
  96. //----------------------------------------------------------------------------
  97. HRESULT RegisterGUIDDescription(REFCLSID rclsid, REFGUID rcatid, WCHAR *pszDesc)
  98. {
  99. ITfCategoryMgr *pcat;
  100. HRESULT hr;
  101. if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  102. NULL,
  103. CLSCTX_INPROC_SERVER,
  104. IID_ITfCategoryMgr,
  105. (void**)&pcat)))
  106. {
  107. hr = pcat->RegisterGUIDDescription(rclsid, rcatid, pszDesc, wcslen(pszDesc));
  108. pcat->Release();
  109. }
  110. return hr;
  111. }
  112. //+---------------------------------------------------------------------------
  113. //
  114. // UnregisterGUIDDescription
  115. //
  116. //----------------------------------------------------------------------------
  117. HRESULT UnregisterGUIDDescription(REFCLSID rclsid, REFGUID rcatid)
  118. {
  119. ITfCategoryMgr *pcat;
  120. HRESULT hr;
  121. if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  122. NULL,
  123. CLSCTX_INPROC_SERVER,
  124. IID_ITfCategoryMgr,
  125. (void**)&pcat)))
  126. {
  127. hr = pcat->UnregisterGUIDDescription(rclsid, rcatid);
  128. pcat->Release();
  129. }
  130. return hr;
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // GetGUIDDescription
  135. //
  136. //----------------------------------------------------------------------------
  137. HRESULT GetGUIDDescription(LIBTHREAD *plt, REFCLSID rclsid, BSTR *pbstr)
  138. {
  139. ITfCategoryMgr *pcat = GetUIMCat(plt);
  140. HRESULT hr = E_FAIL;
  141. Assert(pcat);
  142. if (pcat)
  143. hr = pcat->GetGUIDDescription(rclsid, pbstr);
  144. return hr;
  145. }
  146. //+---------------------------------------------------------------------------
  147. //
  148. // RegisterGUIDDWORD
  149. //
  150. //----------------------------------------------------------------------------
  151. HRESULT RegisterGUIDDWORD(REFCLSID rclsid, REFGUID rcatid, DWORD dw)
  152. {
  153. ITfCategoryMgr *pcat;
  154. HRESULT hr;
  155. if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  156. NULL,
  157. CLSCTX_INPROC_SERVER,
  158. IID_ITfCategoryMgr,
  159. (void**)&pcat)))
  160. {
  161. hr = pcat->RegisterGUIDDWORD(rclsid, rcatid, dw);
  162. pcat->Release();
  163. }
  164. return hr;
  165. }
  166. //+---------------------------------------------------------------------------
  167. //
  168. // UnregisterGUIDDWORD
  169. //
  170. //----------------------------------------------------------------------------
  171. HRESULT UnregisterGUIDDWORD(REFCLSID rclsid, REFGUID rcatid)
  172. {
  173. ITfCategoryMgr *pcat;
  174. HRESULT hr;
  175. if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  176. NULL,
  177. CLSCTX_INPROC_SERVER,
  178. IID_ITfCategoryMgr,
  179. (void**)&pcat)))
  180. {
  181. hr = pcat->UnregisterGUIDDWORD(rclsid, rcatid);
  182. pcat->Release();
  183. }
  184. return hr;
  185. }
  186. //+---------------------------------------------------------------------------
  187. //
  188. // GetGUIDDWORD
  189. //
  190. //----------------------------------------------------------------------------
  191. HRESULT GetGUIDDWORD(LIBTHREAD *plt, REFCLSID rclsid, DWORD *pdw)
  192. {
  193. ITfCategoryMgr *pcat = GetUIMCat(plt);
  194. HRESULT hr = E_FAIL;
  195. Assert(pcat);
  196. if (pcat)
  197. hr = pcat->GetGUIDDWORD(rclsid, pdw);
  198. return hr;
  199. }
  200. //+---------------------------------------------------------------------------
  201. //
  202. // RegisterCategory
  203. //
  204. //----------------------------------------------------------------------------
  205. HRESULT RegisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
  206. {
  207. ITfCategoryMgr *pcat;
  208. HRESULT hr;
  209. if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  210. NULL,
  211. CLSCTX_INPROC_SERVER,
  212. IID_ITfCategoryMgr,
  213. (void**)&pcat)))
  214. {
  215. hr = pcat->RegisterCategory(rclsid, rcatid, rguid);
  216. pcat->Release();
  217. }
  218. return hr;
  219. }
  220. //+---------------------------------------------------------------------------
  221. //
  222. // UnregisterCategory
  223. //
  224. //----------------------------------------------------------------------------
  225. HRESULT UnregisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid)
  226. {
  227. ITfCategoryMgr *pcat;
  228. HRESULT hr;
  229. if (SUCCEEDED(hr = g_pfnCoCreate(CLSID_TF_CategoryMgr,
  230. NULL,
  231. CLSCTX_INPROC_SERVER,
  232. IID_ITfCategoryMgr,
  233. (void**)&pcat)))
  234. {
  235. hr = pcat->UnregisterCategory(rclsid, rcatid, rguid);
  236. pcat->Release();
  237. }
  238. return hr;
  239. }
  240. //+---------------------------------------------------------------------------
  241. //
  242. // UnregisterCategory
  243. //
  244. //----------------------------------------------------------------------------
  245. HRESULT RegisterCategories(REFCLSID rclsid, const REGISTERCAT *pregcat)
  246. {
  247. while (pregcat->pcatid)
  248. {
  249. if (FAILED(RegisterCategory(rclsid, *pregcat->pcatid, *pregcat->pguid)))
  250. return E_FAIL;
  251. pregcat++;
  252. }
  253. return S_OK;
  254. }
  255. //+---------------------------------------------------------------------------
  256. //
  257. // UnregisterCategory
  258. //
  259. //----------------------------------------------------------------------------
  260. HRESULT UnregisterCategories(REFCLSID rclsid, const REGISTERCAT *pregcat)
  261. {
  262. while (pregcat->pcatid)
  263. {
  264. if (FAILED(UnregisterCategory(rclsid, *pregcat->pcatid, *pregcat->pguid)))
  265. return E_FAIL;
  266. pregcat++;
  267. }
  268. return S_OK;
  269. }
  270. //+---------------------------------------------------------------------------
  271. //
  272. // GetKnownModeBias
  273. //
  274. //----------------------------------------------------------------------------
  275. HRESULT GetKnownModeBias(LIBTHREAD *plt, TfGuidAtom guidatom, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount)
  276. {
  277. *pcatid = GUID_MODEBIAS_NONE;
  278. GUID guid;
  279. ITfCategoryMgr *pcat = GetUIMCat(plt);
  280. if (!pcat)
  281. return E_FAIL;
  282. if (FAILED(pcat->GetGUID(guidatom, &guid)))
  283. return E_FAIL;
  284. return pcat->FindClosestCategory(guid, pcatid, ppcatidList, ulCount);
  285. }