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.

691 lines
19 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // TDC / STD Notifications
  4. // Copyright (C) Microsoft Corporation, 1996, 1997
  5. //
  6. // File: Notify.cpp
  7. //
  8. // Contents: Implementation of the CEventBroker class.
  9. // This class translates internal TDC / STD events into
  10. // appropriate notifications for the external world.
  11. //
  12. //------------------------------------------------------------------------
  13. #include "stdafx.h"
  14. #include <simpdata.h>
  15. #include "TDC.h"
  16. #include <MLang.h>
  17. #include "Notify.h"
  18. #include "TDCParse.h"
  19. #include "TDCArr.h"
  20. #include "SimpData.h"
  21. #include "TDCIds.h"
  22. #include "TDCCtl.h"
  23. //------------------------------------------------------------------------
  24. //
  25. // Method: CEventBroker()
  26. //
  27. // Synopsis: Class constructor
  28. //
  29. // Arguments: None
  30. //
  31. //------------------------------------------------------------------------
  32. CEventBroker::CEventBroker(CTDCCtl *pReadyStateControl)
  33. {
  34. m_cRef = 1;
  35. m_pSTDEvents = NULL;
  36. // ;begin_internal
  37. m_pDATASRCListener = NULL;
  38. // ;end_internal
  39. m_pDataSourceListener = NULL;
  40. m_pBSC = NULL;
  41. // Can't AddRef this control, since it has a ref on this object;
  42. // would lead to circular refs & zombie objects.
  43. //
  44. m_pReadyStateControl = pReadyStateControl;
  45. // When we're born, we'd better be born READYSTATE_COMPLETE.
  46. // If and when a query starts, we can go READYSTATE_LOADED.
  47. m_lReadyState = READYSTATE_COMPLETE;
  48. }
  49. CEventBroker::~CEventBroker()
  50. {
  51. SetDataSourceListener(NULL);
  52. // ;begin_internal
  53. SetDATASRCListener(NULL);
  54. // ;end_internal
  55. SetSTDEvents(NULL);
  56. }
  57. //+-----------------------------------------------------------------------
  58. //
  59. // Method: AddRef()
  60. //
  61. // Synopsis: Implements part of the standard IUnknown COM interface.
  62. // (Adds a reference to this COM object)
  63. //
  64. // Arguments: None
  65. //
  66. // Returns: Number of references to this COM object.
  67. //
  68. //+-----------------------------------------------------------------------
  69. STDMETHODIMP_(ULONG)
  70. CEventBroker::AddRef ()
  71. {
  72. return ++m_cRef;
  73. }
  74. //+-----------------------------------------------------------------------
  75. //
  76. // Method: Release()
  77. //
  78. // Synopsis: Implements part of the standard IUnknown COM interface.
  79. // (Removes a reference to this COM object)
  80. //
  81. // Arguments: None
  82. //
  83. // Returns: Number of remaining references to this COM object.
  84. // 0 if the COM object is no longer referenced.
  85. //
  86. //+-----------------------------------------------------------------------
  87. STDMETHODIMP_(ULONG)
  88. CEventBroker::Release ()
  89. {
  90. ULONG retval;
  91. retval = --m_cRef;
  92. if (m_cRef == 0)
  93. {
  94. m_cRef = 0xffff;
  95. delete this;
  96. }
  97. return retval;
  98. }
  99. //------------------------------------------------------------------------
  100. //
  101. // Method: GetReadyState()
  102. //
  103. // Synopsis: Returns the current ReadyState in the supplied pointer.
  104. //
  105. // Arguments: plReadyState Pointer to space to hold ReadyState result
  106. //
  107. // Returns: S_OK indicating success.
  108. //
  109. //------------------------------------------------------------------------
  110. STDMETHODIMP
  111. CEventBroker::GetReadyState(LONG *plReadyState)
  112. {
  113. *plReadyState = m_lReadyState;
  114. return S_OK;
  115. }
  116. //------------------------------------------------------------------------
  117. //
  118. // Method: UpdateReadySTate()
  119. //
  120. // Synopsis: Update our ReadyState and FireOnChanged iif it changed
  121. //
  122. // Arguments: lReadyState new ReadyState
  123. //
  124. // Returns: S_OK indicating success.
  125. //
  126. //------------------------------------------------------------------------
  127. STDMETHODIMP
  128. CEventBroker::UpdateReadyState(LONG lReadyState)
  129. {
  130. // If we're actually stopping something, then fire READYSTATE_COMPLETE
  131. if (m_lReadyState != lReadyState)
  132. {
  133. m_lReadyState = lReadyState;
  134. if (m_pReadyStateControl != NULL)
  135. {
  136. m_pReadyStateControl->FireOnChanged(DISPID_READYSTATE);
  137. m_pReadyStateControl->FireOnReadyStateChanged();
  138. }
  139. }
  140. return S_OK;
  141. }
  142. //------------------------------------------------------------------------
  143. //
  144. // Method: SetDataSourceListener()
  145. //
  146. // Synopsis: Sets the COM object which should receive DATASRC
  147. // notification events.
  148. //
  149. // Arguments: pDataSourceLIstener Pointer to COM object to receive notification
  150. // events, or NULL if no notifications to be sent.
  151. //
  152. // Returns: S_OK indicating success.
  153. //
  154. //------------------------------------------------------------------------
  155. STDMETHODIMP
  156. CEventBroker::SetDataSourceListener(DataSourceListener *pDataSourceListener)
  157. {
  158. // If we've changed/reset the data source listener, make sure we don't
  159. // think we've fired dataMemberChanged on it yet.
  160. ClearInterface(&m_pDataSourceListener);
  161. if (pDataSourceListener != NULL)
  162. {
  163. m_pDataSourceListener = pDataSourceListener;
  164. m_pDataSourceListener->AddRef();
  165. }
  166. return S_OK;
  167. }
  168. // ;begin_internal
  169. //------------------------------------------------------------------------
  170. //
  171. // Method: SetDATASRCListener()
  172. //
  173. // Synopsis: Sets the COM object which should receive DATASRC
  174. // notification events.
  175. //
  176. // Arguments: pDATASRCLIstener Pointer to COM object to receive notification
  177. // events, or NULL if no notifications to be sent.
  178. //
  179. // Returns: S_OK indicating success.
  180. //
  181. //------------------------------------------------------------------------
  182. STDMETHODIMP
  183. CEventBroker::SetDATASRCListener(DATASRCListener *pDATASRCListener)
  184. {
  185. // If we've changed/reset the data source listener, make sure we don't
  186. // think we've fired dataMemberChanged on it yet.
  187. ClearInterface(&m_pDATASRCListener);
  188. if (pDATASRCListener != NULL)
  189. {
  190. m_pDATASRCListener = pDATASRCListener;
  191. m_pDATASRCListener->AddRef();
  192. }
  193. return S_OK;
  194. }
  195. // ;end_internal
  196. //------------------------------------------------------------------------
  197. //
  198. // Method: SetSTDEvents()
  199. //
  200. // Synopsis: Sets the COM object which should receive DATASRC
  201. // notification events.
  202. //
  203. // Arguments: pSTDEvents Pointer to COM object to receive notification
  204. // events, or NULL if no notifications to be sent.
  205. //
  206. // Returns: S_OK indicating success.
  207. //
  208. //------------------------------------------------------------------------
  209. STDMETHODIMP
  210. CEventBroker::SetSTDEvents(OLEDBSimpleProviderListener *pSTDEvents)
  211. {
  212. ClearInterface(&m_pSTDEvents);
  213. if (pSTDEvents != NULL)
  214. {
  215. m_pSTDEvents = pSTDEvents;
  216. m_pSTDEvents->AddRef();
  217. }
  218. return S_OK;
  219. }
  220. //------------------------------------------------------------------------
  221. //
  222. // Method: aboutToChangeCell()
  223. //
  224. // Synopsis: Notifies anyone who wants to know that a particular cell
  225. // is about to change.
  226. //
  227. // Arguments: iRow Row number of the cell that has changed.
  228. // iCol Column number of the cell that has changed.
  229. //
  230. // Returns: S_OK upon success.
  231. // Error code upon failure.
  232. //
  233. //------------------------------------------------------------------------
  234. STDMETHODIMP
  235. CEventBroker::aboutToChangeCell(LONG iRow, LONG iCol)
  236. {
  237. HRESULT hr = S_OK;
  238. _ASSERT(iRow >= 0);
  239. _ASSERT(iCol >= 1);
  240. if (m_pSTDEvents != NULL)
  241. hr = m_pSTDEvents->aboutToChangeCell(iRow, iCol);
  242. return hr;
  243. }
  244. //------------------------------------------------------------------------
  245. //
  246. // Method: CellChanged()
  247. //
  248. // Synopsis: Notifies anyone who wants to know that a particular cell
  249. // has changed.
  250. //
  251. // Arguments: iRow Row number of the cell that has changed.
  252. // iCol Column number of the cell that has changed.
  253. //
  254. // Returns: S_OK upon success.
  255. // Error code upon failure.
  256. //
  257. //------------------------------------------------------------------------
  258. STDMETHODIMP
  259. CEventBroker::cellChanged(LONG iRow, LONG iCol)
  260. {
  261. HRESULT hr = S_OK;
  262. _ASSERT(iRow >= 0);
  263. _ASSERT(iCol >= 1);
  264. if (m_pSTDEvents != NULL)
  265. hr = m_pSTDEvents->cellChanged(iRow, iCol);
  266. return hr;
  267. }
  268. //------------------------------------------------------------------------
  269. //
  270. // Method: RowChanged()
  271. //
  272. // Synopsis: Notifies anyone who wants to know that a particular row
  273. // has changed.
  274. //
  275. // Arguments: iRow Number of the row that has changed.
  276. //
  277. // Returns: S_OK upon success.
  278. // Error code upon failure.
  279. //
  280. //------------------------------------------------------------------------
  281. STDMETHODIMP
  282. CEventBroker::RowChanged(LONG iRow)
  283. {
  284. HRESULT hr = S_OK;
  285. _ASSERT(iRow >= 0);
  286. if (m_pSTDEvents != NULL)
  287. hr = m_pSTDEvents->cellChanged(iRow, -1);
  288. return hr;
  289. }
  290. //------------------------------------------------------------------------
  291. //
  292. // Method: ColChanged()
  293. //
  294. // Synopsis: Notifies anyone who wants to know that a particular column
  295. // has changed.
  296. //
  297. // Arguments: iCol Number of the column that has changed.
  298. //
  299. // Returns: S_OK upon success.
  300. // Error code upon failure.
  301. //
  302. //------------------------------------------------------------------------
  303. STDMETHODIMP
  304. CEventBroker::ColChanged(LONG iCol)
  305. {
  306. HRESULT hr = S_OK;
  307. _ASSERT(iCol > 0);
  308. if (m_pSTDEvents != NULL)
  309. hr = m_pSTDEvents->cellChanged(-1, iCol);
  310. return hr;
  311. }
  312. //------------------------------------------------------------------------
  313. //
  314. // Method: aboutToDeleteRows()
  315. //
  316. // Synopsis: Notifies anyone who wants to know that a some rows
  317. // have been deleted.
  318. //
  319. // Arguments: iRowStart Number of row on which deletion started.
  320. // iRowCount Number of rows deleted.
  321. //
  322. // Returns: S_OK upon success.
  323. // Error code upon failure.
  324. //
  325. //------------------------------------------------------------------------
  326. STDMETHODIMP
  327. CEventBroker::aboutToDeleteRows(LONG iRowStart, LONG iRowCount)
  328. {
  329. HRESULT hr = S_OK;
  330. _ASSERT(iRowStart >= 0);
  331. _ASSERT(iRowCount > 0);
  332. if (m_pSTDEvents != NULL)
  333. hr = m_pSTDEvents->aboutToDeleteRows(iRowStart, iRowCount);
  334. return hr;
  335. }
  336. //------------------------------------------------------------------------
  337. //
  338. // Method: deletedRows()
  339. //
  340. // Synopsis: Notifies anyone who wants to know that a some rows
  341. // have been deleted.
  342. //
  343. // Arguments: iRowStart Number of row on which deletion started.
  344. // iRowCount Number of rows deleted.
  345. //
  346. // Returns: S_OK upon success.
  347. // Error code upon failure.
  348. //
  349. //------------------------------------------------------------------------
  350. STDMETHODIMP
  351. CEventBroker::deletedRows(LONG iRowStart, LONG iRowCount)
  352. {
  353. HRESULT hr = S_OK;
  354. _ASSERT(iRowStart >= 0);
  355. _ASSERT(iRowCount > 0);
  356. if (m_pSTDEvents != NULL)
  357. hr = m_pSTDEvents->deletedRows(iRowStart, iRowCount);
  358. return hr;
  359. }
  360. //------------------------------------------------------------------------
  361. //
  362. // Method: aboutToInsertRows()
  363. //
  364. // Synopsis: Notifies anyone who wants to know that a some rows
  365. // have been inserted.
  366. //
  367. // Arguments: iRowStart Number of row on which insertion started.
  368. // iRowCount Number of rows inserted.
  369. //
  370. // Returns: S_OK upon success.
  371. // Error code upon failure.
  372. //
  373. //------------------------------------------------------------------------
  374. STDMETHODIMP
  375. CEventBroker::aboutToInsertRows(LONG iRowStart, LONG iRowCount)
  376. {
  377. HRESULT hr = S_OK;
  378. _ASSERT(iRowStart >= 0);
  379. _ASSERT(iRowCount > 0);
  380. if (m_pSTDEvents != NULL)
  381. m_pSTDEvents->aboutToInsertRows(iRowStart, iRowCount);
  382. return hr;
  383. }
  384. //------------------------------------------------------------------------
  385. //
  386. // Method: insertedRows()
  387. //
  388. // Synopsis: Notifies anyone who wants to know that a some rows
  389. // have been inserted.
  390. //
  391. // Arguments: iRowStart Number of row on which insertion started.
  392. // iRowCount Number of rows inserted.
  393. //
  394. // Returns: S_OK upon success.
  395. // Error code upon failure.
  396. //
  397. //------------------------------------------------------------------------
  398. STDMETHODIMP
  399. CEventBroker::insertedRows(LONG iRowStart, LONG iRowCount)
  400. {
  401. HRESULT hr = S_OK;
  402. _ASSERT(iRowStart >= 0);
  403. _ASSERT(iRowCount > 0);
  404. if (m_pSTDEvents != NULL)
  405. m_pSTDEvents->insertedRows(iRowStart, iRowCount);
  406. return hr;
  407. }
  408. //------------------------------------------------------------------------
  409. //
  410. // Method: rowsAvailable()
  411. //
  412. // Synopsis: Notifies anyone who wants to know that a some rows
  413. // have arrived. Although this is very similar to insertedRows
  414. // we want to preserve the distinction between rows that
  415. // arrive on the wire and an insert operation that might be
  416. // performed while some data is still downloading.
  417. //
  418. // Arguments: iRowStart Number of row on which insertion started.
  419. // iRowCount Number of rows inserted.
  420. //
  421. // Returns: S_OK upon success.
  422. // Error code upon failure.
  423. //
  424. //------------------------------------------------------------------------
  425. STDMETHODIMP
  426. CEventBroker::rowsAvailable(LONG iRowStart, LONG iRowCount)
  427. {
  428. HRESULT hr = S_OK;
  429. _ASSERT(iRowStart >= 0);
  430. _ASSERT(iRowCount > 0);
  431. if (m_pSTDEvents != NULL)
  432. hr = m_pSTDEvents->rowsAvailable(iRowStart, iRowCount);
  433. return hr;
  434. }
  435. // ;begin_internal
  436. #ifdef NEVER
  437. //------------------------------------------------------------------------
  438. //
  439. // Method: DeletedCols()
  440. //
  441. // Synopsis: Notifies anyone who wants to know that a some columns
  442. // have been deleted.
  443. //
  444. // Arguments: iColStart Number of column on which deletion started.
  445. // iColCount Number of columns deleted.
  446. //
  447. // Returns: S_OK upon success.
  448. // Error code upon failure.
  449. //
  450. //------------------------------------------------------------------------
  451. STDMETHODIMP
  452. CEventBroker::DeletedCols(LONG iColStart, LONG iColCount)
  453. {
  454. HRESULT hr = S_OK;
  455. _ASSERT(iColStart > 0);
  456. _ASSERT(iColCount > 0);
  457. if (m_pSTDEvents != NULL)
  458. hr = m_pSTDEvents->DeletedColumns(iColStart, iColCount);
  459. return hr;
  460. }
  461. //------------------------------------------------------------------------
  462. //
  463. // Method: InsertedCols()
  464. //
  465. // Synopsis: Notifies anyone who wants to know that a some columns
  466. // have been inserted.
  467. //
  468. // Arguments: iColStart Number of column on which insertion started.
  469. // iColCount Number of columns inserted.
  470. //
  471. // Returns: S_OK upon success.
  472. // Error code upon failure.
  473. //
  474. //------------------------------------------------------------------------
  475. STDMETHODIMP
  476. CEventBroker::InsertedCols(LONG iColStart, LONG iColCount)
  477. {
  478. HRESULT hr = S_OK;
  479. _ASSERT(iColStart > 0);
  480. _ASSERT(iColCount > 0);
  481. if (m_pSTDEvents != NULL)
  482. hr = m_pSTDEvents->InsertedColumns(iColStart, iColCount);
  483. return hr;
  484. }
  485. #endif
  486. // ;end_internal
  487. //------------------------------------------------------------------------
  488. //
  489. // Method: STDLoadStarted()
  490. //
  491. // Synopsis: Notifies anyone who wants to know that the STD control
  492. // has begun loading its data.
  493. //
  494. // Arguments: pBSC Pointer to data-retrieval object.
  495. //
  496. // Returns: S_OK upon success.
  497. // Error code upon failure.
  498. //
  499. //------------------------------------------------------------------------
  500. STDMETHODIMP
  501. CEventBroker::STDLoadStarted(CComObject<CMyBindStatusCallback<CTDCCtl> > *pBSC, boolean fAppending)
  502. {
  503. HRESULT hr = S_OK;
  504. m_pBSC = pBSC;
  505. return hr;
  506. }
  507. //------------------------------------------------------------------------
  508. //
  509. // Method: STDLoadCompleted()
  510. //
  511. // Synopsis: Notifies anyone who wants to know that the STD control
  512. // has loaded all of its data.
  513. // Note this function should be idempotent -- i.e. it may be
  514. // called more than once in synchronous cases, once when the
  515. // transfer actually completes, and again as soon as the event
  516. // sink is actually hooked up in order to fire the transferComplete
  517. // event.
  518. //
  519. // Arguments: None.
  520. //
  521. // Returns: S_OK upon success.
  522. // Error code upon failure.
  523. //
  524. //------------------------------------------------------------------------
  525. STDMETHODIMP
  526. CEventBroker::STDLoadCompleted()
  527. {
  528. HRESULT hr = S_OK;
  529. m_pBSC = NULL;
  530. if (m_pSTDEvents != NULL)
  531. hr = m_pSTDEvents->transferComplete(OSPXFER_COMPLETE);
  532. UpdateReadyState(READYSTATE_COMPLETE);
  533. return hr;
  534. }
  535. //------------------------------------------------------------------------
  536. //
  537. // Method: STDLoadStopped()
  538. //
  539. // Synopsis: Notifies anyone who wants to know that the STD control
  540. // has aborted the data load operation.
  541. //
  542. // Arguments: OSPXFER giving reason for stop
  543. //
  544. // Returns: S_OK upon success.
  545. // Error code upon failure.
  546. //
  547. //------------------------------------------------------------------------
  548. STDMETHODIMP
  549. CEventBroker::STDLoadStopped()
  550. {
  551. HRESULT hr = S_OK;
  552. if (m_pBSC && m_pBSC->m_spBinding)
  553. {
  554. hr = m_pBSC->m_spBinding->Abort();
  555. m_pBSC = NULL;
  556. }
  557. // Right now, any error results in not returning an STD object,
  558. // therefore we should not fire transfer complete.
  559. if (m_pSTDEvents)
  560. hr = m_pSTDEvents->transferComplete(OSPXFER_ABORT);
  561. UpdateReadyState(READYSTATE_COMPLETE);
  562. return hr;
  563. }
  564. //------------------------------------------------------------------------
  565. //
  566. // Method: STDLoadedHeader()
  567. //
  568. // Synopsis: Notifies anyone who wants to know that the STD control
  569. // has loaded its header row.
  570. //
  571. // Arguments: None.
  572. //
  573. // Returns: S_OK upon success.
  574. // Error code upon failure.
  575. //
  576. //------------------------------------------------------------------------
  577. STDMETHODIMP
  578. CEventBroker::STDLoadedHeader()
  579. {
  580. HRESULT hr = S_OK;
  581. hr = STDDataSetChanged();
  582. UpdateReadyState(READYSTATE_INTERACTIVE);
  583. return hr;
  584. }
  585. //------------------------------------------------------------------------
  586. //
  587. // Method: STDSortFilterCompleted()
  588. //
  589. // Synopsis: Notifies anyone who wants to know that the STD control
  590. // has refiltered / resorted its data.
  591. //
  592. // Returns: S_OK upon success.
  593. // Error code upon failure.
  594. //
  595. //------------------------------------------------------------------------
  596. STDMETHODIMP
  597. CEventBroker::STDDataSetChanged()
  598. {
  599. HRESULT hr = S_OK;
  600. if (m_pDataSourceListener != NULL)
  601. hr = m_pDataSourceListener->dataMemberChanged(NULL);
  602. // ;begin_internal
  603. if (m_pDATASRCListener != NULL)
  604. hr = m_pDATASRCListener->datasrcChanged(NULL, TRUE);
  605. // ;end_internal
  606. return hr;
  607. }