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.

242 lines
6.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: srchq.hxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. const ULONG cMaxRowCache = 100; // can't have more visible rows than this
  15. const ULONG cwcMaxQuery = 200;
  16. enum ESearchType { srchNormal, srchClass, srchFunction };
  17. #define MAX_BOOKMARK_LENGTH 50 // should be big enough for 11 distributed rowsets
  18. class CBookMark
  19. {
  20. public:
  21. CBookMark () : cbBmk (0) {}
  22. CBookMark (DBBOOKMARK bmkSpecial) : cbBmk (1)
  23. {
  24. abBmk[0] = (BYTE)bmkSpecial;
  25. }
  26. BOOL IsValid() const { return cbBmk != 0; }
  27. void Invalidate () { cbBmk = 0; }
  28. BOOL IsEqual ( CBookMark& bmk)
  29. {
  30. if (cbBmk != bmk.cbBmk)
  31. return FALSE;
  32. else
  33. return memcmp ( abBmk, bmk.abBmk, cbBmk ) == 0;
  34. }
  35. void MakeFirst()
  36. {
  37. cbBmk = sizeof (BYTE);
  38. abBmk[0] = (BYTE) DBBMK_FIRST;
  39. }
  40. BOOL IsFirst()
  41. {
  42. return cbBmk == sizeof(BYTE) && abBmk[0] == (BYTE) DBBMK_FIRST;
  43. }
  44. DBLENGTH cbBmk;
  45. BYTE abBmk[MAX_BOOKMARK_LENGTH];
  46. };
  47. class CListView;
  48. enum FetchResult
  49. {
  50. fetchOk,
  51. fetchError,
  52. fetchBoundary
  53. };
  54. inline BOOL isFetchOK( FetchResult r )
  55. { return ( fetchOk == r || fetchBoundary == r ); }
  56. class CSearchQuery
  57. {
  58. friend class CWatchQuery;
  59. public:
  60. CSearchQuery( const XGrowable<WCHAR> & xCatList,
  61. WCHAR * pwcQuery,
  62. HWND hNotify,
  63. int cRowsDisp,
  64. LCID lcid,
  65. ESearchType srchType,
  66. IColumnMapper & columnMapper,
  67. CColumnList & columnList,
  68. CSortList & sort,
  69. ULONG ulDialect,
  70. ULONG ulLimit,
  71. ULONG ulFirstRows );
  72. ~CSearchQuery();
  73. void InitNotifications(HWND hwndList);
  74. BOOL WindowResized (ULONG& cRows);
  75. BOOL ListNotify (HWND hwnd, WPARAM action, long* pDist);
  76. BOOL GetSelectedRowData( WCHAR *&rpwc, HROW &hrow );
  77. void FreeSelectedRowData( HROW hrow );
  78. BOOL GetRow( DWORD iRow, unsigned &cCols, PROPVARIANT **pProps )
  79. {
  80. if (iRow >= _cHRows)
  81. return FALSE;
  82. HROW hRow = _aHRows[iRow];
  83. Win4Assert (hRow != 0);
  84. SCODE sc = _xRowset->GetData( hRow, _hAccessor, pProps );
  85. cCols = _columns.NumberOfColumns();
  86. return SUCCEEDED( sc );
  87. }
  88. void ProcessNotification (HWND hwndList, DBWATCHNOTIFY changeType, IRowset* pRowset);
  89. void ProcessNotificationComplete();
  90. void UpdateProgress (BOOL& fMore);
  91. DBCOUNTITEM RowCount() { return _cRowsTotal; }
  92. DBCOUNTITEM RowCurrent () { return _iRowCurrent;}
  93. BOOL MostlyDone() { return _fDone; }
  94. ULONG PctDone () { return _pctDone; }
  95. DWORD QueryStatus() { return _dwQueryStatus; }
  96. DWORD LastError() { return _scLastError; }
  97. void WriteResults();
  98. BOOL Browse( enumViewFile eViewType );
  99. void InvalidateCache ();
  100. BOOL IsSelected (UINT iRow);
  101. BOOL IsSelected () { return _bmkSelect.IsValid(); }
  102. void CreateScript (DBCOUNTITEM* pcChanges, DBROWWATCHCHANGE** paScript);
  103. inline double QueryTime()
  104. {
  105. if ( 0 == _dwEndTime )
  106. return 0.0;
  107. if ( _dwEndTime >= _dwStartTime )
  108. return ( (double) ( _dwEndTime - _dwStartTime ) ) / 1000;
  109. DWORD dw = ULONG_MAX - (DWORD) _dwStartTime + (DWORD) _dwEndTime;
  110. return ( (double) dw ) / 1000.0;
  111. }
  112. private:
  113. void Quiesce (BOOL fReally) { _fDone = fReally; }
  114. void InsertRowAfter (int iRow, HROW hrow);
  115. void DeleteRow (int iRow);
  116. void UpdateRow (int iRow, HROW hrow);
  117. void UpdateCount (long cTotal) { _cRowsTotal = cTotal; }
  118. void ParseCatList( WCHAR * * aScopes, WCHAR * * aCatalogs,
  119. WCHAR * * aMachines, DWORD * aDepths,
  120. ULONG & cScopes );
  121. SCODE InstantiateICommand( ICommand **ppQuery );
  122. void Exec(WCHAR *pwcCmdLine);
  123. long FindSelection();
  124. BOOL SelectUp( long * piNew );
  125. BOOL SelectDown( long * piNew );
  126. BOOL Select ( long* piRow );
  127. void ScrollLineUp (long* pdist);
  128. void ScrollPageUp (long* pdist);
  129. void ScrollLineDn (long* pdist);
  130. void ScrollPageDn (long* pdist);
  131. void ScrollTop (long* pdist);
  132. void ScrollBottom (long* pdist);
  133. void ScrollPos (long* pdist);
  134. void SetupColumnMappingsAndAccessors();
  135. BOOL InvokeBrowser(WCHAR *pwcPath);
  136. BOOL FetchApprox (LONG iFirstRow,
  137. LONG cToFetch, DBCOUNTITEM &rcFetched,
  138. HROW *pHRows, HWATCHREGION hRegion);
  139. FetchResult Fetch( CBookMark & bookMark, LONG iFirstRow,
  140. LONG cToFetch, DBCOUNTITEM &rcFetched,
  141. HROW *phRows, HWATCHREGION hRegion );
  142. BOOL GetBookMark( HROW hRow, CBookMark & bookMark )
  143. {
  144. Win4Assert( 0 != _hBmkAccessor );
  145. SCODE sc = _xRowset->GetData( hRow, _hBmkAccessor, &bookMark );
  146. return ( SUCCEEDED( sc ) && ( DB_S_ERRORSOCCURRED != sc ) );
  147. }
  148. // Query
  149. LCID _lcid;
  150. ESearchType _srchType;
  151. XGrowable<WCHAR, cwcMaxQuery> _xwcQuery;
  152. DBCOMMANDTREE * _prstQuery;
  153. //
  154. // Columns, Rowsets and accessors
  155. //
  156. XInterface<IRowsetScroll> _xRowset;
  157. XInterface<IRowsetQueryStatus> _xRowsetStatus;
  158. XInterface<IDBAsynchStatus> _xDBAsynchStatus;
  159. XInterface<IAccessor> _xIAccessor;
  160. HACCESSOR _hAccessor;
  161. HACCESSOR _hBmkAccessor;
  162. HACCESSOR _hBrowseAccessor;
  163. //
  164. // HROWs
  165. //
  166. HROW _aHRows[cMaxRowCache];
  167. ULONG _cHRows; // this many we have
  168. ULONG _cRowsDisp; // this many can be displayed
  169. HROW _aHRowsTmp[cMaxRowCache];
  170. CBookMark _bmkSelect;
  171. //
  172. // Notifications
  173. //
  174. HWND _hwndNotify; // where to send notifications
  175. HWND _hwndList;
  176. XPtr<CWatchQuery> _xWatch;
  177. HWATCHREGION _hRegion;
  178. DBCOUNTITEM _cRowsTotal;
  179. DBCOUNTITEM _iRowCurrent;
  180. ULONG_PTR _dwStartTime;
  181. ULONG_PTR _dwEndTime;
  182. CBookMark _bmkTop;
  183. BOOL _fDone;
  184. ULONG _pctDone;
  185. DWORD _dwQueryStatus;
  186. SCODE _scLastError;
  187. CColumnList &_columns;
  188. IColumnMapper &_columnMapper;
  189. XGrowable<WCHAR> _xCatList;
  190. };