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.

400 lines
9.5 KiB

  1. /*
  2. * t a b l e . c p p
  3. *
  4. * Purpose:
  5. * Implements the OE-MOM DataBinding Table object
  6. *
  7. * History
  8. *
  9. * Copyright (C) Microsoft Corp. 1995, 1996.
  10. */
  11. #include <pch.hxx>
  12. #include "msoeobj.h"
  13. #include "mshtmdid.h"
  14. #include "table.h"
  15. #include "instance.h"
  16. COEMsgTable::COEMsgTable() : CBaseDisp()
  17. {
  18. m_pTable=0;
  19. m_pDSListen=0;
  20. m_fAsc=TRUE;
  21. m_col=COLUMN_RECEIVED;
  22. m_pDataSrcListener=0;
  23. CoIncrementInit("COEMsgTable::COEMsgTable", MSOEAPI_START_SHOWERRORS, NULL, NULL);
  24. }
  25. COEMsgTable::~COEMsgTable()
  26. {
  27. ReleaseObj(m_pTable);
  28. ReleaseObj(m_pDSListen);
  29. ReleaseObj(m_pDataSrcListener);
  30. CoDecrementInit("COEMsgTable::COEMsgTable", NULL);
  31. }
  32. HRESULT COEMsgTable::PrivateQueryInterface(REFIID riid, LPVOID *lplpObj)
  33. {
  34. if(!lplpObj)
  35. return E_INVALIDARG;
  36. *lplpObj = NULL;
  37. if (IsEqualIID(riid, IID_IUnknown))
  38. *lplpObj = (LPVOID)(OLEDBSimpleProvider *)this;
  39. else if (IsEqualIID(riid, IID_OLEDBSimpleProvider))
  40. *lplpObj = (LPVOID)(OLEDBSimpleProvider *)this;
  41. else if (IsEqualIID(riid, IID_IDispatch))
  42. *lplpObj = (LPVOID)(IDispatch *)(CBaseDisp *)this;
  43. else if (IsEqualIID(riid, IID_IDispatchEx))
  44. *lplpObj = (LPVOID)(IDispatchEx *)this;
  45. else if (IsEqualIID(riid, IID_IOEMsgList))
  46. *lplpObj = (LPVOID)(IOEMsgList *)this;
  47. else
  48. {
  49. return E_NOINTERFACE;
  50. }
  51. AddRef();
  52. return NOERROR;
  53. }
  54. HRESULT COEMsgTable::Init()
  55. {
  56. FOLDERINFO fi;
  57. HRESULT hr;
  58. g_pStore->GetSpecialFolderInfo(FOLDERID_LOCAL_STORE, FOLDER_INBOX, &fi);
  59. hr = CoCreateInstance(CLSID_MessageTable, NULL, CLSCTX_INPROC_SERVER,
  60. IID_IMessageTable, (LPVOID *)&m_pTable);
  61. if (FAILED(hr))
  62. goto error;
  63. // Tell the table which folder to look at
  64. hr = m_pTable->Initialize(fi.idFolder, NULL, FALSE, NULL);
  65. if (FAILED(hr))
  66. goto error;
  67. hr = CBaseDisp::EnsureTypeLibrary((LPVOID *)(IOEMsgList *)this, IID_IOEMsgList);
  68. if (FAILED(hr))
  69. goto error;
  70. error:
  71. return hr;
  72. }
  73. HRESULT COEMsgTable::getRowCount(long *pcRows)
  74. {
  75. *pcRows = 0;
  76. if (m_pTable)
  77. m_pTable->GetCount(MESSAGE_COUNT_VISIBLE, (ULONG *)pcRows);
  78. return S_OK;
  79. }
  80. HRESULT COEMsgTable::getColumnCount(long *pcColumns)
  81. {
  82. *pcColumns=COLUMN_MAX;
  83. return S_OK;
  84. }
  85. HRESULT COEMsgTable::getRWStatus(long iRow, long iColumn, OSPRW *prwStatus)
  86. {
  87. *prwStatus = OSPRW_READONLY;
  88. return S_OK;
  89. }
  90. HRESULT COEMsgTable::getVariant(long iRow, long iColumn, OSPFORMAT format, VARIANT __RPC_FAR *pVar)
  91. {
  92. LPMESSAGEINFO pmsginfo;
  93. LPSTR pszData = NULL;
  94. TCHAR rgch[MAX_PATH];
  95. pVar->vt = VT_NULL;
  96. if (iRow == 0)
  97. {
  98. // return headings if row==0
  99. pVar->vt = VT_BSTR;
  100. pVar->bstrVal = SysAllocString(_PszFromColIndex(iColumn-1));
  101. return S_OK;
  102. }
  103. if (m_pTable->GetRow(iRow-1, &pmsginfo)==S_OK)
  104. {
  105. switch (iColumn-1)
  106. {
  107. case COLUMN_MSGID:
  108. wnsprintf(rgch,ARRAYSIZE(rgch), "%d", pmsginfo->idMessage);
  109. pszData = rgch;
  110. break;
  111. case COLUMN_SUBJECT:
  112. pszData = pmsginfo->pszSubject;
  113. break;
  114. case COLUMN_TO:
  115. pszData = pmsginfo->pszDisplayTo;
  116. break;
  117. case COLUMN_FROM:
  118. pszData = pmsginfo->pszDisplayFrom;
  119. break;
  120. case COLUMN_RECEIVED:
  121. pszData = rgch;
  122. *rgch=0;
  123. CchFileTimeToDateTimeSz(&pmsginfo->ftReceived, rgch, sizeof(rgch)/sizeof(TCHAR), DTM_NOSECONDS);
  124. break;
  125. default:
  126. pVar->vt = VT_NULL;
  127. pVar->lVal = NULL;
  128. return S_OK;
  129. }
  130. }
  131. if (pszData)
  132. {
  133. pVar->vt = VT_BSTR;
  134. HrLPSZToBSTR(pszData, &pVar->bstrVal);
  135. }
  136. else
  137. AssertSz(0, "bad");
  138. return S_OK;
  139. }
  140. HRESULT COEMsgTable::setVariant(long iRow, long iColumn, OSPFORMAT format, VARIANT Var)
  141. {
  142. AssertSz(0, "READONLY Table");
  143. return E_NOTIMPL;
  144. }
  145. HRESULT COEMsgTable::getLocale(BSTR *pbstrLocale)
  146. {
  147. nyi("DATABINDING::getLocale");
  148. return E_NOTIMPL;
  149. }
  150. HRESULT COEMsgTable::deleteRows(long iRow, long cRows, long *pcRowsDeleted)
  151. {
  152. AssertSz(0, "READONLY Table");
  153. return E_NOTIMPL;
  154. }
  155. HRESULT COEMsgTable::insertRows(long iRow, long cRows, long *pcRowsInserted)
  156. {
  157. AssertSz(0, "READONLY Table");
  158. return E_NOTIMPL;
  159. }
  160. HRESULT COEMsgTable::find(long iRowStart, long iColumn, VARIANT val, OSPFIND findFlags, OSPCOMP compType, long *piRowFound)
  161. {
  162. nyi("DATABINDING::find");
  163. return E_NOTIMPL;
  164. }
  165. HRESULT COEMsgTable::addOLEDBSimpleProviderListener(OLEDBSimpleProviderListener *pospIListener)
  166. {
  167. ReplaceInterface(m_pDSListen, pospIListener);
  168. if (pospIListener)
  169. pospIListener->transferComplete(OSPXFER_COMPLETE);
  170. return S_OK;
  171. }
  172. HRESULT COEMsgTable::removeOLEDBSimpleProviderListener(OLEDBSimpleProviderListener *pospIListener)
  173. {
  174. SafeRelease(m_pDSListen);
  175. return S_OK;
  176. }
  177. HRESULT COEMsgTable::isAsync(BOOL *pbAsynch)
  178. {
  179. *pbAsynch = FALSE;
  180. return S_OK;
  181. }
  182. HRESULT COEMsgTable::getEstimatedRows(long *piRows)
  183. {
  184. return getRowCount(piRows);
  185. }
  186. HRESULT COEMsgTable::stopTransfer()
  187. {
  188. return S_OK;
  189. }
  190. HRESULT CreateInstance_OEMsgTable(IUnknown *pUnkOuter, IUnknown **ppUnknown)
  191. {
  192. // Locals
  193. COEMsgTable *pMsgTable=NULL;
  194. HRESULT hr;
  195. if (NULL != pUnkOuter)
  196. return CLASS_E_NOAGGREGATION;
  197. pMsgTable = new COEMsgTable();
  198. if (!pMsgTable)
  199. return E_OUTOFMEMORY;
  200. hr = pMsgTable->Init();
  201. if (FAILED(hr))
  202. goto error;
  203. hr = pMsgTable->QueryInterface(IID_IUnknown, (LPVOID *)ppUnknown);
  204. error:
  205. ReleaseObj(pMsgTable);
  206. return hr;
  207. }
  208. HRESULT COEMsgTable::GetDispID(BSTR bstrName, DWORD grfdex, DISPID *pid)
  209. {
  210. return DispGetIDsOfNames(m_pTypeInfo, &bstrName, 1, pid);
  211. }
  212. HRESULT COEMsgTable::InvokeEx(DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
  213. {
  214. switch (id)
  215. {
  216. case DISPID_MSDATASRCINTERFACE:
  217. pvarRes->vt = VT_UNKNOWN;
  218. pvarRes->punkVal = (OLEDBSimpleProvider *)this;
  219. AddRef();
  220. return S_OK;
  221. case DISPID_ADVISEDATASRCCHANGEEVENT:
  222. if (pdp->cArgs == 1 && pdp->rgvarg[0].vt == VT_UNKNOWN)
  223. {
  224. ReplaceInterface(m_pDataSrcListener, (DataSourceListener *)pdp->rgvarg[0].punkVal);
  225. return S_OK;
  226. }
  227. else
  228. return E_INVALIDARG;
  229. default:
  230. return DispInvoke(m_pUnkInvoke, m_pTypeInfo, id, wFlags, pdp, pvarRes, pei, NULL);
  231. }
  232. return E_NOTIMPL;
  233. }
  234. HRESULT COEMsgTable::DeleteMemberByName(BSTR bstrName, DWORD grfdex)
  235. {
  236. return E_NOTIMPL;
  237. }
  238. HRESULT COEMsgTable::DeleteMemberByDispID(DISPID id)
  239. {
  240. return E_NOTIMPL;
  241. }
  242. HRESULT COEMsgTable::GetMemberProperties(DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
  243. {
  244. return E_NOTIMPL;
  245. }
  246. HRESULT COEMsgTable::GetMemberName(DISPID id, BSTR *pbstrName)
  247. {
  248. return E_NOTIMPL;
  249. }
  250. HRESULT COEMsgTable::GetNextDispID(DWORD grfdex, DISPID id, DISPID *pid)
  251. {
  252. return E_NOTIMPL;
  253. }
  254. HRESULT COEMsgTable::GetNameSpaceParent(IUnknown **ppunk)
  255. {
  256. return E_NOTIMPL;
  257. }
  258. HRESULT COEMsgTable::put_sortColumn(BSTR bstr)
  259. {
  260. return S_OK;
  261. }
  262. HRESULT COEMsgTable::get_sortColumn(BSTR *pbstr)
  263. {
  264. *pbstr = SysAllocString(_PszFromColIndex(m_col));
  265. return S_OK;
  266. }
  267. HRESULT COEMsgTable::put_sortDirection(VARIANT_BOOL v)
  268. {
  269. return S_OK;
  270. }
  271. HRESULT COEMsgTable::get_sortDirection(VARIANT_BOOL *pv)
  272. {
  273. *pv = m_fAsc ? VARIANT_TRUE : VARIANT_FALSE;
  274. return S_OK;
  275. }
  276. HRESULT COEMsgTable::test()
  277. {
  278. if (m_pDataSrcListener)
  279. m_pDataSrcListener->dataMemberChanged(NULL);
  280. return S_OK;
  281. }
  282. static const WCHAR c_szOESubjW[] = L"oeSubj",
  283. c_szOEToW[] = L"oeTo",
  284. c_szOEFromW[] = L"oeFrom",
  285. c_szOEMsgIdW[] = L"oeMsgId",
  286. c_szOEReceivedW[] = L"oeDate";
  287. DWORD COEMsgTable::_colIndexFromString(LPWSTR pszW)
  288. {
  289. if (StrCmpIW(c_szOESubjW, pszW)==0)
  290. return COLUMN_SUBJECT;
  291. else
  292. if (StrCmpIW(c_szOEToW, pszW)==0)
  293. return COLUMN_TO;
  294. else
  295. if (StrCmpIW(c_szOEReceivedW, pszW)==0)
  296. return COLUMN_RECEIVED;
  297. else
  298. if (StrCmpIW(c_szOEFromW, pszW)==0)
  299. return COLUMN_FROM;
  300. else
  301. if (StrCmpIW(c_szOEMsgIdW, pszW)==0)
  302. return COLUMN_MSGID;
  303. return (DWORD)-1;
  304. }
  305. LPWSTR COEMsgTable::_PszFromColIndex(DWORD dw)
  306. {
  307. switch (dw)
  308. {
  309. case COLUMN_MSGID:
  310. return (LPWSTR)c_szOEMsgIdW;
  311. case COLUMN_SUBJECT:
  312. return (LPWSTR)c_szOESubjW;
  313. case COLUMN_TO:
  314. return (LPWSTR)c_szOEToW;
  315. case COLUMN_FROM:
  316. return (LPWSTR)c_szOEFromW;
  317. case COLUMN_RECEIVED:
  318. return (LPWSTR)c_szOEReceivedW;
  319. }
  320. return NULL;
  321. }