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.

312 lines
8.6 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. //
  6. //
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. // PURPOSE.
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //
  17. //==============================================================;
  18. #include "Comp.h"
  19. #include "DataObj.h"
  20. #include <commctrl.h> // Needed for button styles...
  21. #include <crtdbg.h>
  22. #include "globals.h"
  23. #include "resource.h"
  24. #include "DeleBase.h"
  25. #include "CompData.h"
  26. CComponent::CComponent(CComponentData *parent)
  27. : m_pComponentData(parent), m_cref(0), m_ipConsole(NULL)
  28. {
  29. OBJECT_CREATED
  30. m_ipDisplayHelp = NULL;
  31. m_ipControlBar = NULL;
  32. m_ipMenuButton = NULL;
  33. }
  34. CComponent::~CComponent()
  35. {
  36. OBJECT_DESTROYED
  37. }
  38. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  39. {
  40. if (!ppv)
  41. return E_FAIL;
  42. *ppv = NULL;
  43. if (IsEqualIID(riid, IID_IUnknown))
  44. *ppv = static_cast<IComponent *>(this);
  45. else if (IsEqualIID(riid, IID_IComponent))
  46. *ppv = static_cast<IComponent *>(this);
  47. else if (IsEqualIID(riid, IID_IExtendControlbar))
  48. *ppv = static_cast<IExtendControlbar *>(this);
  49. if (*ppv)
  50. {
  51. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  52. return S_OK;
  53. }
  54. return E_NOINTERFACE;
  55. }
  56. STDMETHODIMP_(ULONG) CComponent::AddRef()
  57. {
  58. return InterlockedIncrement((LONG *)&m_cref);
  59. }
  60. STDMETHODIMP_(ULONG) CComponent::Release()
  61. {
  62. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  63. {
  64. delete this;
  65. return 0;
  66. }
  67. return m_cref;
  68. }
  69. ///////////////////////////////
  70. // Interface IComponent
  71. ///////////////////////////////
  72. STDMETHODIMP CComponent::Initialize(
  73. /* [in] */ LPCONSOLE lpConsole)
  74. {
  75. HRESULT hr = S_OK;
  76. // Save away all the interfaces we'll need.
  77. // Fail if we can't QI the required interfaces.
  78. m_ipConsole = lpConsole;
  79. m_ipConsole->AddRef();
  80. hr = m_ipConsole->QueryInterface(IID_IDisplayHelp, (void **)&m_ipDisplayHelp);
  81. return hr;
  82. }
  83. STDMETHODIMP CComponent::Notify(
  84. /* [in] */ LPDATAOBJECT lpDataObject,
  85. /* [in] */ MMC_NOTIFY_TYPE event,
  86. /* [in] */ LPARAM arg,
  87. /* [in] */ LPARAM param)
  88. {
  89. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  90. HRESULT hr = S_FALSE;
  91. //Get our data object. If it is NULL, we return with S_FALSE.
  92. //See implementation of GetOurDataObject() to see how to
  93. //handle special data objects.
  94. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  95. if (NULL == pDataObject)
  96. return S_FALSE;
  97. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  98. switch (event) {
  99. case MMCN_ADD_IMAGES:
  100. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  101. break;
  102. case MMCN_SELECT:
  103. hr = base->OnSelect(m_ipConsole, (BOOL) LOWORD(arg), (BOOL) HIWORD(arg));
  104. break;
  105. case MMCN_SHOW:
  106. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  107. break;
  108. case MMCN_CONTEXTHELP:
  109. hr = base->OnShowContextHelp(m_ipDisplayHelp, m_pComponentData->m_HelpFile);
  110. break;
  111. }
  112. return hr;
  113. }
  114. STDMETHODIMP CComponent::Destroy(
  115. /* [in] */ MMC_COOKIE cookie)
  116. {
  117. if (m_ipConsole) {
  118. m_ipConsole->Release();
  119. m_ipConsole = NULL;
  120. }
  121. if (m_ipDisplayHelp) {
  122. m_ipDisplayHelp->Release();
  123. m_ipDisplayHelp = NULL;
  124. }
  125. if (m_ipControlBar) {
  126. m_ipControlBar->Release();
  127. m_ipControlBar = NULL;
  128. }
  129. if (m_ipMenuButton) {
  130. m_ipMenuButton->Release();
  131. m_ipMenuButton = NULL;
  132. }
  133. return S_OK;
  134. }
  135. STDMETHODIMP CComponent::QueryDataObject(
  136. /* [in] */ MMC_COOKIE cookie,
  137. /* [in] */ DATA_OBJECT_TYPES type,
  138. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  139. {
  140. CDataObject *pObj = NULL;
  141. if (cookie == 0)
  142. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  143. else
  144. pObj = new CDataObject(cookie, type);
  145. if (!pObj)
  146. return E_OUTOFMEMORY;
  147. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  148. return S_OK;
  149. }
  150. STDMETHODIMP CComponent::GetResultViewType(
  151. /* [in] */ MMC_COOKIE cookie,
  152. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  153. /* [out] */ long __RPC_FAR *pViewOptions)
  154. {
  155. CDelegationBase *base = (CDelegationBase *)cookie;
  156. //
  157. // Ask for default listview.
  158. //
  159. if (base == NULL)
  160. {
  161. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  162. *ppViewType = NULL;
  163. }
  164. else
  165. return base->GetResultViewType(ppViewType, pViewOptions);
  166. return S_OK;
  167. }
  168. STDMETHODIMP CComponent::GetDisplayInfo(
  169. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  170. {
  171. HRESULT hr = S_OK;
  172. CDelegationBase *base = NULL;
  173. // if they are asking for the RDI_STR we have one of those to give
  174. if (pResultDataItem->lParam) {
  175. base = (CDelegationBase *)pResultDataItem->lParam;
  176. if (pResultDataItem->mask & RDI_STR) {
  177. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  178. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  179. pResultDataItem->str = pszW;
  180. }
  181. if (pResultDataItem->mask & RDI_IMAGE) {
  182. pResultDataItem->nImage = base->GetBitmapIndex();
  183. }
  184. }
  185. return hr;
  186. }
  187. STDMETHODIMP CComponent::CompareObjects(
  188. /* [in] */ LPDATAOBJECT lpDataObjectA,
  189. /* [in] */ LPDATAOBJECT lpDataObjectB)
  190. {
  191. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  192. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  193. // compare the object pointers
  194. if (baseA->GetCookie() == baseB->GetCookie())
  195. return S_OK;
  196. return S_FALSE;
  197. }
  198. ///////////////////////////////
  199. // Interface IExtendControlBar
  200. ///////////////////////////////
  201. HRESULT CComponent::SetControlbar(
  202. /* [in] */ LPCONTROLBAR pControlbar)
  203. {
  204. HRESULT hr = S_OK;
  205. //
  206. // Clean up
  207. //
  208. // if we've got a cached control bar, release it
  209. if (m_ipControlBar) {
  210. m_ipControlBar->Release();
  211. m_ipControlBar = NULL;
  212. }
  213. // if we've got a cached menubutton, release it
  214. if (m_ipMenuButton) {
  215. m_ipMenuButton->Release();
  216. m_ipMenuButton = NULL;
  217. }
  218. //
  219. // Install new pieces if necessary
  220. //
  221. // if a new one came in, cache and AddRef
  222. if (pControlbar) {
  223. m_ipControlBar = pControlbar;
  224. m_ipControlBar->AddRef();
  225. // add our menu button
  226. hr = m_ipControlBar->Create(MENUBUTTON, // type of control to be created
  227. dynamic_cast<IExtendControlbar *>(this),
  228. reinterpret_cast<IUnknown **>(&m_ipMenuButton));
  229. _ASSERT(SUCCEEDED(hr));
  230. m_ipMenuButton->AddRef();
  231. hr = m_ipMenuButton->AddButton(IDR_STATE_MENU, L"Vehicle &Status", L"Change vehicle state");
  232. _ASSERT(SUCCEEDED(hr));
  233. }
  234. return hr;
  235. }
  236. HRESULT CComponent::ControlbarNotify(
  237. /* [in] */ MMC_NOTIFY_TYPE event,
  238. /* [in] */ LPARAM arg,
  239. /* [in] */ LPARAM param)
  240. {
  241. HRESULT hr = S_OK;
  242. if (event == MMCN_SELECT) {
  243. CDelegationBase *base = GetOurDataObject(reinterpret_cast<IDataObject *>(param))->GetBaseNodeObject();
  244. hr = base->SetMenuState(m_ipControlBar, m_ipMenuButton, (BOOL) LOWORD(arg), (BOOL) HIWORD(arg));
  245. } else if (event == MMCN_MENU_BTNCLICK) {
  246. CDelegationBase *base = GetOurDataObject(reinterpret_cast<IDataObject *>(arg))->GetBaseNodeObject();
  247. hr = base->OnSetMenuButton(m_ipConsole, (MENUBUTTONDATA *)param);
  248. }
  249. return hr;
  250. }