Source code of Windows XP (NT5)
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.

197 lines
5.3 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // File: vwadvhld.cxx
  4. //
  5. // Contents: Miscellaneous OLE helper routines
  6. //
  7. //------------------------------------------------------------------------
  8. #include "headers.hxx"
  9. #pragma hdrstop
  10. //+---------------------------------------------------------------
  11. //
  12. // Member: ViewAdviseHolder::ViewAdviseHolder, protected
  13. //
  14. // Synopsis: Constructor for ViewAdviseHolder class
  15. //
  16. //----------------------------------------------------------------
  17. ViewAdviseHolder::ViewAdviseHolder()
  18. {
  19. _refs = 1;
  20. _pAdvSink = NULL;
  21. _dwAdviseAspects = 0;
  22. _dwAdviseFlags = 0;
  23. }
  24. //+---------------------------------------------------------------
  25. //
  26. // Member: ViewAdviseHolder::~ViewAdviseHolder, protected
  27. //
  28. // Synopsis: Destructor for ViewAdviseHolder class
  29. //
  30. //----------------------------------------------------------------
  31. ViewAdviseHolder::~ViewAdviseHolder()
  32. {
  33. if (_pAdvSink != NULL)
  34. _pAdvSink->Release();
  35. }
  36. //+---------------------------------------------------------------
  37. //
  38. // Member: ViewAdviseHolder::QueryInterface, public
  39. //
  40. // Synopsis: Method of IUnknown interface
  41. //
  42. //----------------------------------------------------------------
  43. STDMETHODIMP
  44. ViewAdviseHolder::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  45. {
  46. if (IsEqualIID(riid,IID_IUnknown))
  47. {
  48. *ppvObj = this;
  49. AddRef();
  50. return NOERROR;
  51. }
  52. DOUT(TEXT("ViewAdviseHolder::QueryInterface E_NOINTERFACE\r\n"));
  53. *ppvObj = NULL;
  54. return E_NOINTERFACE;
  55. }
  56. //+---------------------------------------------------------------
  57. //
  58. // Member: ViewAdviseHolder:AddRef, public
  59. //
  60. // Synopsis: Method of IUnknown interface
  61. //
  62. //----------------------------------------------------------------
  63. STDMETHODIMP_(ULONG)
  64. ViewAdviseHolder::AddRef(void)
  65. {
  66. return _refs++;
  67. }
  68. //+---------------------------------------------------------------
  69. //
  70. // Member: ViewAdviseHolder::Release, public
  71. //
  72. // Synopsis: Method of IUnknown interface
  73. //
  74. //----------------------------------------------------------------
  75. STDMETHODIMP_(ULONG)
  76. ViewAdviseHolder::Release(void)
  77. {
  78. if (--_refs == 0)
  79. delete this;
  80. return (_refs);
  81. }
  82. //+---------------------------------------------------------------
  83. //
  84. // Member: ViewAdviseHolder::SetAdvise, public
  85. //
  86. // Synopsis: Places an advise in the advise holder
  87. //
  88. // Arguments: The arguments are the same as to IViewObject::SetAdvise
  89. //
  90. // Notes: IViewObject objects using this advise holder delegate
  91. // their IViewObject::SetAdvise methods to this method.
  92. //
  93. //----------------------------------------------------------------
  94. STDMETHODIMP
  95. ViewAdviseHolder::SetAdvise(DWORD aspects, DWORD advf, LPADVISESINK pAdvSink)
  96. {
  97. if (_pAdvSink != NULL)
  98. _pAdvSink->Release();
  99. _pAdvSink = pAdvSink;
  100. if (_pAdvSink != NULL)
  101. _pAdvSink->AddRef();
  102. _dwAdviseAspects = aspects;
  103. _dwAdviseFlags = advf;
  104. return NOERROR;
  105. }
  106. //+---------------------------------------------------------------
  107. //
  108. // Member: ViewAdviseHolder::GetAdvise, public
  109. //
  110. // Synopsis: Reports on an advise in the advise holder
  111. //
  112. // Arguments: The arguments are the same as to IViewObject::GetAdvise
  113. //
  114. // Notes: IViewObject objects using this advise holder delegate
  115. // their IViewObject::GetAdvise methods to this method.
  116. //
  117. //----------------------------------------------------------------
  118. STDMETHODIMP
  119. ViewAdviseHolder::GetAdvise(DWORD FAR* pAspects,
  120. DWORD FAR* pAdvf,
  121. LPADVISESINK FAR* ppAdvSink)
  122. {
  123. *ppAdvSink = _pAdvSink;
  124. *pAspects = _dwAdviseAspects;
  125. *pAdvf = _dwAdviseFlags;
  126. return NOERROR;
  127. // review: is this the right return code if no advise has been set?
  128. }
  129. //+---------------------------------------------------------------
  130. //
  131. // Member: ViewAdviseHolder::SendOnViewChange, public
  132. //
  133. // Synopsis: Sends an OnViewChange notification to the registered advise.
  134. //
  135. // Arguments: [dwAspect] -- the display aspect that has changed
  136. //
  137. // Notes: The client IViewObject should call this method whenever
  138. // its view has changed.
  139. //
  140. //----------------------------------------------------------------
  141. void ViewAdviseHolder::SendOnViewChange(DWORD dwAspect)
  142. {
  143. if (_pAdvSink != NULL && (dwAspect&_dwAdviseAspects) != 0)
  144. _pAdvSink->OnViewChange(dwAspect, -1);
  145. }
  146. //+---------------------------------------------------------------
  147. //
  148. // Function: CreateViewAdviseHolder
  149. //
  150. // Synopsis: Creates a ViewAdviseHolder object
  151. //
  152. // Arguments: [ppViewHolder] -- place where the view holder is returned
  153. //
  154. // Returns: Success if the advise holder was created
  155. //
  156. // Notes: This function is directly analogous to the OLE provided
  157. // CreateDataAdviseHolder
  158. //
  159. //----------------------------------------------------------------
  160. HRESULT
  161. CreateViewAdviseHolder(LPVIEWADVISEHOLDER FAR* ppViewHolder)
  162. {
  163. //LPVIEWADVISEHOLDER pViewAdvHolder = new (NullOnFail) ViewAdviseHolder;
  164. LPVIEWADVISEHOLDER pViewAdvHolder = new ViewAdviseHolder;
  165. *ppViewHolder = pViewAdvHolder;
  166. if (pViewAdvHolder == NULL)
  167. {
  168. DOUT(TEXT("o2base/vwadvhld/CreateViewAdviseHolder failed\r\n"));
  169. return E_OUTOFMEMORY;
  170. }
  171. else
  172. return NOERROR;
  173. }