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.

361 lines
10 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // TDC Array
  4. // Copyright (C) Microsoft Corporation, 1996, 1997
  5. //
  6. // File: TDCArr.h
  7. //
  8. // Contents: Declaration of the CTDCArr class.
  9. // This class forms the heart of the Tabular Data Control.
  10. // It provides the core 2D array of variant values, plus
  11. // a (possibly filtered/sorted) view of this data for
  12. // presentation through an ISimpleTabularData interface.
  13. //
  14. //------------------------------------------------------------------------
  15. // ;begin_internal
  16. #ifndef TDC_SKEL
  17. // ;end_internal
  18. #include "tarray.h"
  19. //------------------------------------------------------------------------
  20. //
  21. // CTDCCell
  22. //
  23. // This class represents a cell value within the 2D TDC control
  24. //
  25. //------------------------------------------------------------------------
  26. class CTDCCell : public VARIANT
  27. {
  28. public:
  29. CTDCCell()
  30. {
  31. VariantInit(this);
  32. }
  33. ~CTDCCell()
  34. {
  35. clear();
  36. }
  37. void clear()
  38. {
  39. VariantClear(this);
  40. }
  41. };
  42. //------------------------------------------------------------------------
  43. //
  44. // TDCDateFmt
  45. //
  46. // This enum represents the 6 meaningful ways to format dates
  47. //
  48. //------------------------------------------------------------------------
  49. typedef enum
  50. {
  51. TDCDF_NULL,
  52. TDCDF_DMY,
  53. TDCDF_DYM,
  54. TDCDF_MDY,
  55. TDCDF_MYD,
  56. TDCDF_YMD,
  57. TDCDF_YDM,
  58. }
  59. TDCDateFmt;
  60. //------------------------------------------------------------------------
  61. //
  62. // CTDCColInfo
  63. //
  64. // This class represents type/formatting information for a column
  65. //
  66. //------------------------------------------------------------------------
  67. class CTDCColInfo
  68. {
  69. public:
  70. VARTYPE vtType;
  71. TDCDateFmt datefmt; // Format string for dates
  72. CTDCColInfo()
  73. {
  74. vtType = VT_EMPTY;
  75. }
  76. };
  77. // ;begin_internal
  78. #endif // TDC_SKEL
  79. // ;end_internal
  80. //------------------------------------------------------------------------
  81. //
  82. // CTDCSortCriterion
  83. //
  84. // This class represents a sorting criterion (sort column and direction)
  85. //
  86. //------------------------------------------------------------------------
  87. class CTDCSortCriterion
  88. {
  89. public:
  90. LONG m_iSortCol;
  91. boolean m_fSortAscending;
  92. CTDCSortCriterion *m_pNext;
  93. CTDCSortCriterion()
  94. {
  95. m_pNext = NULL;
  96. }
  97. ~CTDCSortCriterion()
  98. {
  99. if (m_pNext != NULL)
  100. delete m_pNext;
  101. }
  102. };
  103. //------------------------------------------------------------------------
  104. //
  105. // CTDCFilterNode
  106. //
  107. // This class represents a tree node in a filter query.
  108. //
  109. //------------------------------------------------------------------------
  110. class CTDCFilterNode
  111. {
  112. public:
  113. enum NODE_OP
  114. {
  115. NT_AND,
  116. NT_OR,
  117. NT_EQ,
  118. NT_NE,
  119. NT_LT,
  120. NT_GT,
  121. NT_LE,
  122. NT_GE,
  123. NT_ATOM,
  124. NT_NULL,
  125. };
  126. NODE_OP m_type;
  127. CTDCFilterNode *m_pLeft; // NT_AND ... NT_GE
  128. CTDCFilterNode *m_pRight; // NT_AND ... NT_GE
  129. LONG m_iCol; // NT_ATOM, +ve column #, 0 means fixed value
  130. VARIANT m_value; // NT_ATOM, m_iCol == 0: optional fixed value
  131. VARTYPE m_vt; // NT_EQ ... NT_ATOM - type of comparison/atom
  132. boolean m_fWildcard; // True for string literals with '*' wildcard
  133. CTDCFilterNode()
  134. {
  135. m_type = NT_NULL;
  136. m_pLeft = NULL;
  137. m_pRight = NULL;
  138. m_iCol = 0;
  139. m_vt = VT_EMPTY;
  140. VariantInit(&m_value);
  141. }
  142. ~CTDCFilterNode()
  143. {
  144. if (m_pLeft != NULL)
  145. delete m_pLeft;
  146. if (m_pRight != NULL)
  147. delete m_pRight;
  148. VariantClear(&m_value);
  149. }
  150. };
  151. class CEventBroker;
  152. //------------------------------------------------------------------------
  153. //
  154. // CTDCArr
  155. //
  156. //------------------------------------------------------------------------
  157. class CTDCArr : public OLEDBSimpleProvider,
  158. public CTDCFieldSink
  159. {
  160. public:
  161. STDMETHOD(QueryInterface) (REFIID, LPVOID FAR*);
  162. STDMETHOD_(ULONG,AddRef) (THIS);
  163. STDMETHOD_(ULONG,Release) (THIS);
  164. CTDCArr();
  165. STDMETHOD(Init)(CEventBroker *pEventBroker, IMultiLanguage *pML);
  166. // CTDCFieldSink methods
  167. //
  168. STDMETHOD(AddField)(LPWCH pwch, DWORD dwSize);
  169. STDMETHOD(EOLN)();
  170. STDMETHOD(EOF)();
  171. // TDC control methods
  172. //
  173. STDMETHOD(StartDataLoad)(boolean fUseHeader,
  174. BSTR bstrSortExpr, BSTR bstrFilterExpr, LCID lcid,
  175. CComObject<CMyBindStatusCallback<CTDCCtl> > *pBSC,
  176. boolean fAppend, boolean fCaseSensitive);
  177. STDMETHOD(SetSortFilterCriteria)(BSTR bstrSortExpr, BSTR bstrFilterExpr,
  178. boolean fCaseSensitive);
  179. // OLEDBSimpleProvider methods
  180. //
  181. STDMETHOD(getRowCount)(DBROWCOUNT *pcRows);
  182. STDMETHOD(getColumnCount)(DB_LORDINAL *pcCols);
  183. STDMETHOD(getRWStatus)(DBROWCOUNT iRow, DB_LORDINAL iCol, OSPRW *prwStatus);
  184. STDMETHOD(getVariant)(DBROWCOUNT iRow, DB_LORDINAL iCol, OSPFORMAT format, VARIANT *pVar);
  185. STDMETHOD(setVariant)(DBROWCOUNT iRow, DB_LORDINAL iCol, OSPFORMAT format, VARIANT Var);
  186. STDMETHOD(getLocale)(BSTR *pbstrLocale);
  187. STDMETHOD(deleteRows)(DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsDeleted);
  188. STDMETHOD(insertRows)(DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsInserted);
  189. STDMETHOD(find) (DBROWCOUNT iRowStart, DB_LORDINAL iCol, VARIANT val,
  190. OSPFIND findFlags, OSPCOMP compType, DBROWCOUNT *piRowFound);
  191. STDMETHOD(addOLEDBSimpleProviderListener)(OLEDBSimpleProviderListener *pospIListener);
  192. STDMETHOD(removeOLEDBSimpleProviderListener)(OLEDBSimpleProviderListener *pospIListener);
  193. STDMETHOD(getEstimatedRows)(DBROWCOUNT *pcRows);
  194. STDMETHOD(isAsync)(BOOL *pbAsync);
  195. STDMETHOD(stopTransfer)();
  196. // ;begin_internal
  197. STDMETHOD(DeleteColumns)(DB_LORDINAL iCol, DB_LORDINAL cCols, DB_LORDINAL *pcColsDeleted);
  198. STDMETHOD(InsertColumns)(DB_LORDINAL iCol, DB_LORDINAL cCols, DB_LORDINAL *pcColsInserted);
  199. // ;end_internal
  200. // This member is used during a sort operation
  201. //
  202. int SortComp(LONG iRow1, LONG iRow2);
  203. enum LOAD_STATE
  204. {
  205. LS_UNINITIALISED,
  206. LS_LOADING_HEADER_UNAVAILABLE,
  207. LS_LOADING_HEADER_AVAILABLE,
  208. LS_LOADED,
  209. };
  210. LOAD_STATE GetLoadState() { return m_state; }
  211. void SetIsAsync(BOOL fAsync) { m_fAsync = fAsync; }
  212. CEventBroker *m_pEventBroker;
  213. IMultiLanguage *m_pML;
  214. private:
  215. ULONG m_cRef; // interface reference count
  216. LOAD_STATE m_state;
  217. LCID m_lcid; // Default user LCID
  218. LCID m_lcidRead; // User LCID corresponding to LANGUAGE property
  219. ~CTDCArr();
  220. // ;begin_internal
  221. #ifndef TDC_SKEL
  222. // ;end_internal
  223. boolean m_fSortFilterDisrupted;
  224. STDMETHOD(ApplySortFilterCriteria)();
  225. // These members are used during a sort operation
  226. //
  227. CTDCSortCriterion *m_pSortList;
  228. BSTR m_bstrSortExpr;
  229. HRESULT CreateSortList(BSTR bstrSortCols);
  230. // These members are used during a filter operation
  231. //
  232. CTDCFilterNode *m_pFilterTree;
  233. BSTR m_bstrFilterExpr;
  234. boolean EvalDataRow(LONG iRow, CTDCFilterNode *pNode);
  235. CTDCFilterNode *FilterParseComplex(LPWCH *ppwch, HRESULT *phr);
  236. CTDCFilterNode *FilterParseSimple(LPWCH *ppwch, HRESULT *phr);
  237. CTDCFilterNode *FilterParseAtom(LPWCH *ppwch, HRESULT *phr);
  238. LONG m_fLastFilter;
  239. // ;begin_internal
  240. #endif // TDC_SKEL
  241. // ;end_internal
  242. // These members are used during a load
  243. //
  244. boolean m_fUseHeader;
  245. boolean m_fSkipRow;
  246. LONG m_iCurrRow;
  247. LONG m_iCurrCol;
  248. LONG m_iDataRows;
  249. LONG m_iFilterRows;
  250. LONG m_iCols;
  251. boolean m_fCaseSensitive;
  252. BOOL m_fAsync; // TRUE iff Async
  253. // These methods and members form the internal array implementation
  254. //
  255. inline boolean fValidDataRow(LONG iRow);
  256. inline boolean fValidFilterRow(LONG iRow);
  257. inline boolean fValidCol(LONG iCol);
  258. inline boolean fValidDataCell(LONG iRow, LONG iCol);
  259. inline boolean fValidFilterCell(LONG iRow, LONG iCol);
  260. inline CTDCCell *GetDataCell(LONG iRow, LONG iCol);
  261. inline CTDCCell *GetFilterCell(LONG iRow, LONG iCol);
  262. inline CTDCColInfo *GetColInfo(LONG iCol);
  263. LONG CalcDataRows();
  264. LONG CalcFilterRows();
  265. LONG CalcCols();
  266. TSTDArray<TSTDArray<CTDCCell> *> m_arrparrCells;
  267. TSTDArray<TSTDArray<CTDCCell> *> m_arrparrFilter;
  268. TSTDArray<CTDCColInfo> m_arrColInfo;
  269. // Misc internal methods
  270. //
  271. LONG FindCol(BSTR bstrColName);
  272. HRESULT GetVariantBSTR(VARIANT *pv, BSTR *pbstr, boolean *pfAllocated);
  273. void RenumberColumnHeadings();
  274. HRESULT CreateNumberedColumnHeadings();
  275. HRESULT ParseColumnHeadings();
  276. HRESULT VariantFromBSTR(VARIANT *pv, BSTR bstr, CTDCColInfo *pColInfo, LCID);
  277. int VariantComp(VARIANT *pVar1, VARIANT *pVar2, VARTYPE type,
  278. boolean fCaseSensitive);
  279. int InsertionSortHelper(int iRow);
  280. };
  281. inline boolean CTDCArr::fValidDataRow(LONG iRow)
  282. {
  283. return iRow >= 0 && iRow <= m_iDataRows;
  284. }
  285. inline boolean CTDCArr::fValidFilterRow(LONG iRow)
  286. {
  287. return iRow >= 0 && iRow <= m_iFilterRows;
  288. }
  289. inline boolean CTDCArr::fValidCol(LONG iCol)
  290. {
  291. return iCol >= 1 && iCol <= m_iCols;
  292. }
  293. inline boolean CTDCArr::fValidDataCell(LONG iRow, LONG iCol)
  294. {
  295. return fValidDataRow(iRow) && fValidCol(iCol);
  296. }
  297. inline boolean CTDCArr::fValidFilterCell(LONG iRow, LONG iCol)
  298. {
  299. return fValidFilterRow(iRow) && fValidCol(iCol);
  300. }
  301. // ;begin_internal
  302. #ifndef TDC_SKEL
  303. // ;end_internal
  304. inline CTDCCell *CTDCArr::GetDataCell(LONG iRow, LONG iCol)
  305. {
  306. return &((*m_arrparrCells[iRow])[iCol - 1]);
  307. }
  308. inline CTDCColInfo *CTDCArr::GetColInfo(LONG iCol)
  309. {
  310. return &m_arrColInfo[iCol - 1];
  311. }
  312. inline CTDCCell *CTDCArr::GetFilterCell(LONG iRow, LONG iCol)
  313. {
  314. return &((*m_arrparrFilter[iRow])[iCol - 1]);
  315. }
  316. // ;begin_internal
  317. #endif // TDC_SKEL
  318. // ;end_internal