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.

210 lines
6.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: watch.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. //#define USE_WATCH_REGIONS // last tried 10/7/96
  16. //
  17. // CWatchQuery
  18. //
  19. CWatchQuery::CWatchQuery (CSearchQuery* pClient, IRowsetScroll* pRowset)
  20. : _pClient (pClient),
  21. _pContainer (0),
  22. _pNotifyWatch (0),
  23. _pPoint (0),
  24. _pRowsetWatch (0),
  25. _hRegion (0),
  26. _fEverGotARowsChanged(FALSE),
  27. _wnLast( 0 )
  28. {
  29. if (!pRowset)
  30. THROW (CException(E_FAIL));
  31. _pNotifyWatch = new CRowsetNotifyWatch( pClient->_hwndNotify );
  32. SCODE sc = pRowset->QueryInterface( IID_IConnectionPointContainer,
  33. (void **) &_pContainer );
  34. if (SUCCEEDED(sc))
  35. {
  36. sc = _pContainer->FindConnectionPoint( IID_IRowsetWatchNotify,
  37. &_pPoint );
  38. if (SUCCEEDED(sc))
  39. {
  40. sc = _pPoint->Advise( (IUnknown *) _pNotifyWatch,
  41. &_dwAdviseID );
  42. if (SUCCEEDED(sc))
  43. {
  44. sc = pRowset->QueryInterface( IID_IRowsetWatchRegion,
  45. (void**) &_pRowsetWatch );
  46. }
  47. }
  48. }
  49. #ifdef USE_WATCH_REGIONS
  50. if (_pRowsetWatch)
  51. {
  52. sc = _pRowsetWatch->CreateWatchRegion (DBWATCHMODE_MOVE, &_hRegion);
  53. }
  54. #endif
  55. _mode = DBWATCHMODE_MOVE;
  56. } //CWatchNotify
  57. CWatchQuery::~CWatchQuery ()
  58. {
  59. srchDebugOut(( DEB_ITRACE,
  60. "~CWatchQuery, ever got a rc: %d, _wnLast: %d\n",
  61. _fEverGotARowsChanged, _wnLast ));
  62. if (_pPoint)
  63. {
  64. _pPoint->Unadvise(_dwAdviseID);
  65. _pPoint->Release();
  66. }
  67. if (_pContainer)
  68. _pContainer->Release();
  69. if (_pRowsetWatch)
  70. _pRowsetWatch->Release();
  71. if (_pNotifyWatch)
  72. _pNotifyWatch->Release();
  73. } //~CWatchQuery
  74. void CWatchQuery::Notify (HWND hwndList, DBWATCHNOTIFY changeType)
  75. {
  76. // don't post more notifications while we're busy
  77. _pNotifyWatch->HoldNotifications( TRUE );
  78. _wnLast = changeType;
  79. switch (changeType)
  80. {
  81. case DBWATCHNOTIFY_QUERYDONE:
  82. _pClient->Quiesce(TRUE);
  83. srchDebugOut(( DEB_ITRACE, "CWatchQuery::Notify - Query DONE\n"));
  84. break;
  85. case DBWATCHNOTIFY_QUERYREEXECUTED:
  86. _pClient->Quiesce(FALSE);
  87. break;
  88. case DBWATCHNOTIFY_ROWSCHANGED:
  89. RowsChanged (hwndList);
  90. break;
  91. default :
  92. Win4Assert( !"unexpected notification!" );
  93. break;
  94. }
  95. } //Notify
  96. void CWatchQuery::NotifyComplete()
  97. {
  98. _pNotifyWatch->HoldNotifications( FALSE );
  99. } //NotifyComplete
  100. void CWatchQuery::RowsChanged (HWND hwnd)
  101. {
  102. DBCOUNTITEM cChanges = 0;
  103. DBROWWATCHCHANGE* aChange = 0;
  104. _fEverGotARowsChanged = TRUE;
  105. SCODE sc = _pRowsetWatch->Refresh( &cChanges, &aChange );
  106. Win4Assert ((sc == STATUS_UNEXPECTED_NETWORK_ERROR ||
  107. sc == DB_S_TOOMANYCHANGES || sc == E_FAIL)
  108. && cChanges == 0);
  109. if ( sc == STATUS_UNEXPECTED_NETWORK_ERROR )
  110. sc = DB_S_TOOMANYCHANGES;
  111. if (sc == DB_S_TOOMANYCHANGES)
  112. {
  113. _pClient->CreateScript (&cChanges, &aChange);
  114. }
  115. srchDebugOut(( DEB_ITRACE, "CWatchQuery::RowsChanged Changes = %d\n", cChanges));
  116. if (cChanges != 0)
  117. {
  118. ExecuteScript (hwnd, (ULONG) cChanges, aChange);
  119. CoTaskMemFree (aChange);
  120. }
  121. } //RowsChanged
  122. void CWatchQuery::ExecuteScript (HWND hwndList, ULONG cChanges, DBROWWATCHCHANGE* aScript)
  123. {
  124. for (ULONG i = 0; i < cChanges; i++)
  125. {
  126. switch (aScript[i].eChangeKind)
  127. {
  128. case DBROWCHANGEKIND_INSERT:
  129. _pClient->InsertRowAfter((int) aScript[i].iRow, aScript[i].hRow);
  130. SendMessage (hwndList, wmInsertItem, 0, aScript[i].iRow );
  131. srchDebugOut(( DEB_ITRACE, "CWatchQuery::ExecuteScript - Row INS: %d\n", aScript[i].iRow));
  132. break;
  133. case DBROWCHANGEKIND_DELETE:
  134. _pClient->DeleteRow ((int) aScript[i].iRow);
  135. SendMessage (hwndList, wmDeleteItem, 0, aScript[i].iRow );
  136. srchDebugOut(( DEB_ITRACE, "CWatchQuery::ExecuteScript - Row DEL: %d\n", aScript[i].iRow));
  137. break;
  138. case DBROWCHANGEKIND_UPDATE:
  139. _pClient->UpdateRow ((int) aScript[i].iRow, aScript[i].hRow);
  140. SendMessage (hwndList, wmUpdateItem, 0, aScript[i].iRow );
  141. srchDebugOut(( DEB_ITRACE, "CWatchQuery::ExecuteScript - Row UPD\n"));
  142. break;
  143. case DBROWCHANGEKIND_COUNT:
  144. _pClient->UpdateCount ((int) aScript[i].iRow);
  145. srchDebugOut(( DEB_ITRACE, "CWatchQuery::ExecuteScript - Row CNT\n"));
  146. default:
  147. Win4Assert (!"unknown change kind");
  148. }
  149. }
  150. } //ExecuteScript
  151. void CWatchQuery::Extend (HWATCHREGION hRegion)
  152. {
  153. #ifdef USE_WATCH_REGIONS
  154. if ((_mode & DBWATCHMODE_EXTEND) == 0)
  155. {
  156. _mode |= DBWATCHMODE_EXTEND;
  157. _mode &= ~DBWATCHMODE_MOVE;
  158. _pRowsetWatch->ChangeWatchMode ( hRegion, _mode);
  159. }
  160. #endif
  161. }
  162. void CWatchQuery::Move (HWATCHREGION hRegion)
  163. {
  164. #ifdef USE_WATCH_REGIONS
  165. if ((_mode & DBWATCHMODE_MOVE) == 0)
  166. {
  167. _mode |= DBWATCHMODE_MOVE;
  168. _mode &= ~DBWATCHMODE_EXTEND;
  169. _pRowsetWatch->ChangeWatchMode ( hRegion, _mode);
  170. }
  171. #endif
  172. }
  173. void CWatchQuery::Shrink (HWATCHREGION hRegion, CBookMark& bmk, ULONG cRows)
  174. {
  175. #ifdef USE_WATCH_REGIONS
  176. _pRowsetWatch->ShrinkWatchRegion (hRegion,
  177. 0, // no chapter
  178. bmk.cbBmk, bmk.abBmk,
  179. cRows //_mode
  180. );
  181. #endif
  182. }