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.

519 lines
13 KiB

  1. //
  2. // readrng.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "rngsink.h"
  7. #include "immxutil.h"
  8. #include "catmgr.h"
  9. #include "rprop.h"
  10. #include "proputil.h"
  11. /* f66ee5c0-fe8c-11d2-8ded-00105a2799b5 */
  12. static const IID IID_CGeneralPropStore = {
  13. 0xf66ee5c0,
  14. 0xfe8c,
  15. 0x11d2,
  16. {0x8d, 0xed, 0x00, 0x10, 0x5a, 0x27, 0x99, 0xb5}
  17. };
  18. DBG_ID_INSTANCE(CGeneralPropStore);
  19. DBG_ID_INSTANCE(CStaticPropStore);
  20. //////////////////////////////////////////////////////////////////////////////
  21. //
  22. // CGeneralPropStore
  23. //
  24. //////////////////////////////////////////////////////////////////////////////
  25. //+---------------------------------------------------------------------------
  26. //
  27. // _Init
  28. //
  29. //----------------------------------------------------------------------------
  30. BOOL CGeneralPropStore::_Init(TfGuidAtom guidatom, const VARIANT *pvarValue, DWORD dwPropFlags)
  31. {
  32. _guidatom = guidatom;
  33. _dwPropFlags = dwPropFlags;
  34. return (VariantToTfProp(&_prop,
  35. pvarValue,
  36. ADDREF,
  37. (dwPropFlags & PROPF_VTI4TOGUIDATOM))
  38. == S_OK);
  39. }
  40. BOOL CGeneralPropStore::_Init(TfGuidAtom guidatom, TFPROPERTY *ptfp, DWORD dwPropFlags)
  41. {
  42. _guidatom = guidatom;
  43. _dwPropFlags = dwPropFlags;
  44. _prop = *ptfp;
  45. switch (_prop.type)
  46. {
  47. case TF_PT_UNKNOWN:
  48. _prop.punk->AddRef();
  49. break;
  50. case TF_PT_BSTR:
  51. if ((_prop.bstr = SysAllocString(ptfp->bstr)) == NULL)
  52. return FALSE;
  53. break;
  54. case TF_PT_PROXY:
  55. if ((_prop.blob = PROXY_BLOB::Clone(ptfp->blob)) == NULL)
  56. return FALSE;
  57. break;
  58. }
  59. return TRUE;
  60. }
  61. BOOL CGeneralPropStore::_Init(TfGuidAtom guidatom, int iDataSize, TfPropertyType proptype, IStream *pStream, DWORD dwPropFlags)
  62. {
  63. GUID guid;
  64. TfGuidAtom gaTmp;
  65. BOOL fRet;
  66. _guidatom = guidatom;
  67. _dwPropFlags = dwPropFlags;
  68. _prop.type = proptype;
  69. fRet = FALSE; // failure
  70. switch (proptype)
  71. {
  72. case TF_PT_DWORD:
  73. if (iDataSize != sizeof(DWORD))
  74. break;
  75. fRet = SUCCEEDED(pStream->Read((void *)&_prop.dw, iDataSize, NULL));
  76. break;
  77. case TF_PT_GUID:
  78. if (iDataSize != sizeof(GUID))
  79. break;
  80. if (FAILED(pStream->Read((void *)&guid, iDataSize, NULL)))
  81. break;
  82. CCategoryMgr::s_RegisterGUID(guid, &gaTmp);
  83. _prop.guidatom = gaTmp;
  84. fRet = TRUE;
  85. break;
  86. case TF_PT_BSTR:
  87. _prop.bstr = SysAllocStringLen(NULL, iDataSize / sizeof(WCHAR));
  88. if (_prop.bstr == NULL)
  89. break;
  90. if (FAILED(pStream->Read((void *)_prop.bstr, iDataSize, NULL)))
  91. {
  92. SysFreeString(_prop.bstr);
  93. _prop.bstr = NULL;
  94. break;
  95. }
  96. fRet = TRUE;
  97. break;
  98. case TF_PT_PROXY:
  99. // just copy the bytes blindly, we won't do anything with them
  100. if ((_prop.blob = PROXY_BLOB::Alloc(iDataSize)) == NULL)
  101. break;
  102. if (FAILED(pStream->Read(_prop.blob->rgBytes, iDataSize, NULL)))
  103. {
  104. cicMemFree(_prop.blob);
  105. _prop.blob = NULL;
  106. }
  107. _prop.blob->cb = iDataSize;
  108. fRet = TRUE;
  109. break;
  110. case TF_PT_NONE:
  111. Assert(0);
  112. break;
  113. }
  114. return fRet;
  115. }
  116. //+---------------------------------------------------------------------------
  117. //
  118. // dtor
  119. //
  120. //----------------------------------------------------------------------------
  121. CGeneralPropStore::~CGeneralPropStore()
  122. {
  123. switch (_prop.type)
  124. {
  125. case TF_PT_UNKNOWN:
  126. SafeRelease(_prop.punk);
  127. break;
  128. case TF_PT_BSTR:
  129. SysFreeString(_prop.bstr);
  130. break;
  131. case TF_PT_PROXY:
  132. PROXY_BLOB::Free(_prop.blob);
  133. break;
  134. }
  135. }
  136. //+---------------------------------------------------------------------------
  137. //
  138. // GetType
  139. //
  140. //----------------------------------------------------------------------------
  141. STDAPI CGeneralPropStore::GetType(GUID *pguid)
  142. {
  143. return MyGetGUID(_guidatom, pguid);
  144. }
  145. //+---------------------------------------------------------------------------
  146. //
  147. // GetDataType
  148. //
  149. //----------------------------------------------------------------------------
  150. STDAPI CGeneralPropStore::GetDataType(DWORD *pdwReserved)
  151. {
  152. if (pdwReserved == NULL)
  153. return E_INVALIDARG;
  154. *pdwReserved = _prop.type;
  155. return S_OK;
  156. }
  157. //+---------------------------------------------------------------------------
  158. //
  159. // GetData
  160. //
  161. //----------------------------------------------------------------------------
  162. STDAPI CGeneralPropStore::GetData(VARIANT *pvarValue)
  163. {
  164. if (pvarValue == NULL)
  165. return E_INVALIDARG;
  166. return TfPropToVariant(pvarValue, &_prop, ADDREF);
  167. }
  168. //+---------------------------------------------------------------------------
  169. //
  170. // OnTextUpdated
  171. //
  172. //----------------------------------------------------------------------------
  173. STDAPI CGeneralPropStore::OnTextUpdated(DWORD dwFlags, ITfRange *pRange, BOOL *pfAccept)
  174. {
  175. // This PropStore does not support TextUpdate.
  176. // leave the ink alone if it's a correction
  177. if (_dwPropFlags & PROPF_ACCEPTCORRECTION)
  178. *pfAccept = (dwFlags & TF_TU_CORRECTION);
  179. else
  180. *pfAccept = FALSE;
  181. return S_OK;
  182. }
  183. //+---------------------------------------------------------------------------
  184. //
  185. // Shrink
  186. //
  187. //----------------------------------------------------------------------------
  188. STDAPI CGeneralPropStore::Shrink(ITfRange *pRange, BOOL *pfFree)
  189. {
  190. // This PropStore does not support Shrink.
  191. *pfFree = TRUE;
  192. return S_OK;
  193. }
  194. //+---------------------------------------------------------------------------
  195. //
  196. // Divide
  197. //
  198. //----------------------------------------------------------------------------
  199. STDAPI CGeneralPropStore::Divide(ITfRange *pRangeThis, ITfRange *pRangeNew, ITfPropertyStore **ppPropStore)
  200. {
  201. //
  202. // This PropStore does not support Divide.
  203. //
  204. *ppPropStore = NULL;
  205. return S_OK;
  206. }
  207. //+---------------------------------------------------------------------------
  208. //
  209. // Clone
  210. //
  211. //----------------------------------------------------------------------------
  212. STDAPI CGeneralPropStore::Clone(ITfPropertyStore **ppPropStore)
  213. {
  214. CGeneralPropStore *pStore;
  215. if (ppPropStore == NULL)
  216. return E_INVALIDARG;
  217. *ppPropStore = NULL;
  218. //
  219. // we can't clone a Unknown prop.
  220. //
  221. if (_prop.type == TF_PT_UNKNOWN)
  222. return E_FAIL;
  223. if ((pStore = new CGeneralPropStore) == NULL)
  224. return E_OUTOFMEMORY;
  225. if (!pStore->_Init(_guidatom, &_prop, _dwPropFlags))
  226. return E_FAIL;
  227. *ppPropStore = pStore;
  228. return S_OK;
  229. }
  230. //+---------------------------------------------------------------------------
  231. //
  232. // GetpropertyRangeCreator
  233. //
  234. //----------------------------------------------------------------------------
  235. STDAPI CGeneralPropStore::GetPropertyRangeCreator(CLSID *pclsid)
  236. {
  237. memset(pclsid, 0, sizeof(*pclsid));
  238. return TF_S_GENERALPROPSTORE;
  239. }
  240. //+---------------------------------------------------------------------------
  241. //
  242. // Serialize
  243. //
  244. //----------------------------------------------------------------------------
  245. STDAPI CGeneralPropStore::Serialize(IStream *pStream, ULONG *pcb)
  246. {
  247. GUID guid;
  248. ULONG ulSize;
  249. HRESULT hr = E_FAIL;
  250. if (!pcb)
  251. return E_INVALIDARG;
  252. *pcb = 0;
  253. if (!pStream)
  254. return E_INVALIDARG;
  255. switch (_prop.type)
  256. {
  257. case TF_PT_DWORD:
  258. if (SUCCEEDED(hr = pStream->Write(&_prop.dw, sizeof(DWORD), NULL)))
  259. *pcb = sizeof(DWORD);
  260. break;
  261. case TF_PT_GUID:
  262. if (SUCCEEDED(MyGetGUID(_prop.guidatom, &guid)) &&
  263. SUCCEEDED(hr = pStream->Write(&guid, sizeof(GUID), NULL)))
  264. {
  265. *pcb = sizeof(GUID);
  266. }
  267. break;
  268. case TF_PT_BSTR:
  269. ulSize = SysStringLen(_prop.bstr) * sizeof(WCHAR);
  270. if (SUCCEEDED(pStream->Write(_prop.bstr, ulSize, NULL)))
  271. {
  272. *pcb = ulSize;
  273. }
  274. hr = *pcb ? S_OK : S_FALSE;
  275. break;
  276. case TF_PT_PROXY:
  277. if (SUCCEEDED(pStream->Write(_prop.blob->rgBytes, _prop.blob->cb, pcb)))
  278. {
  279. hr = (*pcb == _prop.blob->cb) ? S_OK : E_FAIL;
  280. }
  281. break;
  282. case TF_PT_UNKNOWN:
  283. hr = S_FALSE;
  284. break;
  285. }
  286. return hr;
  287. }
  288. //////////////////////////////////////////////////////////////////////////////
  289. //
  290. // CPropStoreProxy
  291. //
  292. // CPropStore is for keeping the persistent data when the owner TFE
  293. // is not available.
  294. //
  295. // GetPropertyRangeCreator() returns the real owner TFE of this data.
  296. // So next time the application may be able to find the real owner if it is
  297. // available.
  298. //
  299. //////////////////////////////////////////////////////////////////////////////
  300. //+---------------------------------------------------------------------------
  301. //
  302. // _Init
  303. //
  304. //----------------------------------------------------------------------------
  305. BOOL CPropStoreProxy::_Init(const CLSID *pclsidTIP, TfGuidAtom guidatom, int iDataSize, IStream *pStream, DWORD dwPropFlags)
  306. {
  307. if (!CGeneralPropStore::_Init(guidatom, iDataSize, TF_PT_PROXY, pStream, dwPropFlags))
  308. return FALSE;
  309. _clsidTIP = *pclsidTIP;
  310. return TRUE;
  311. }
  312. BOOL CPropStoreProxy::_Init(const CLSID *pclsidTIP, TfGuidAtom guidatom, TFPROPERTY *ptfp, DWORD dwPropFlags)
  313. {
  314. if (!CGeneralPropStore::_Init(guidatom, ptfp, dwPropFlags))
  315. return FALSE;
  316. _clsidTIP = *pclsidTIP;
  317. return TRUE;
  318. }
  319. //+---------------------------------------------------------------------------
  320. //
  321. // GetpropertyRangeCreator
  322. //
  323. //----------------------------------------------------------------------------
  324. STDAPI CPropStoreProxy::GetPropertyRangeCreator(CLSID *pclsid)
  325. {
  326. *pclsid = _clsidTIP;
  327. return TF_S_PROPSTOREPROXY;
  328. }
  329. //+---------------------------------------------------------------------------
  330. //
  331. // Clone
  332. //
  333. //----------------------------------------------------------------------------
  334. STDAPI CPropStoreProxy::Clone(ITfPropertyStore **ppPropStore)
  335. {
  336. CPropStoreProxy *pStore;
  337. if (ppPropStore == NULL)
  338. return E_INVALIDARG;
  339. *ppPropStore = NULL;
  340. //
  341. // we can't clone a Unknown prop.
  342. //
  343. if (_prop.type == TF_PT_UNKNOWN)
  344. return E_FAIL;
  345. if ((pStore = new CPropStoreProxy) == NULL)
  346. return E_OUTOFMEMORY;
  347. if (!pStore->_Init(&_clsidTIP, _guidatom, &_prop, _dwPropFlags))
  348. return E_FAIL;
  349. *ppPropStore = pStore;
  350. return S_OK;
  351. }
  352. //////////////////////////////////////////////////////////////////////////////
  353. //
  354. // CStaticPropStore
  355. //
  356. // CStaticPropStore works like character property. We keep same raw data
  357. // even if the range is devided or changed.
  358. //
  359. // So the range data should not contain the information that is associated
  360. // with cch.
  361. //
  362. //////////////////////////////////////////////////////////////////////////////
  363. //+---------------------------------------------------------------------------
  364. //
  365. // Shrink
  366. //
  367. //----------------------------------------------------------------------------
  368. STDAPI CStaticPropStore::Shrink(ITfRange *pRange, BOOL *pfFree)
  369. {
  370. // we don't change any raw data.
  371. *pfFree = FALSE;
  372. return S_OK;
  373. }
  374. //+---------------------------------------------------------------------------
  375. //
  376. // Divide
  377. //
  378. //----------------------------------------------------------------------------
  379. STDAPI CStaticPropStore::Divide(ITfRange *pRangeThis, ITfRange *pRangeNew, ITfPropertyStore **ppPropStore)
  380. {
  381. CStaticPropStore *pss;
  382. *ppPropStore = NULL;
  383. if ((pss = new CStaticPropStore) == NULL)
  384. return E_OUTOFMEMORY;
  385. if (!pss->_Init(_guidatom, &_prop, _dwPropFlags))
  386. return E_FAIL;
  387. *ppPropStore = pss;
  388. return S_OK;
  389. }
  390. //+---------------------------------------------------------------------------
  391. //
  392. // Clone
  393. //
  394. //----------------------------------------------------------------------------
  395. STDAPI CStaticPropStore::Clone(ITfPropertyStore **ppPropStore)
  396. {
  397. CStaticPropStore *pStore;
  398. if (ppPropStore == NULL)
  399. return E_INVALIDARG;
  400. *ppPropStore = NULL;
  401. //
  402. // we can't clone a Unknown prop.
  403. //
  404. if (_prop.type == TF_PT_UNKNOWN)
  405. return E_FAIL;
  406. if ((pStore = new CStaticPropStore) == NULL)
  407. return E_OUTOFMEMORY;
  408. if (!pStore->_Init(_guidatom, &_prop, _dwPropFlags))
  409. return E_FAIL;
  410. *ppPropStore = pStore;
  411. return S_OK;
  412. }