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.

331 lines
9.3 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. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  27. CComponent::CComponent(CComponentData *parent)
  28. : m_pComponentData(parent), m_cref(0), m_ipConsole(NULL)
  29. {
  30. OBJECT_CREATED
  31. m_ipDisplayHelp = NULL;
  32. m_ipControlBar = NULL;
  33. m_ipToolbar = NULL;
  34. }
  35. CComponent::~CComponent()
  36. {
  37. OBJECT_DESTROYED
  38. }
  39. STDMETHODIMP CComponent::QueryInterface(REFIID riid, LPVOID *ppv)
  40. {
  41. if (!ppv)
  42. return E_FAIL;
  43. *ppv = NULL;
  44. if (IsEqualIID(riid, IID_IUnknown))
  45. *ppv = static_cast<IComponent *>(this);
  46. else if (IsEqualIID(riid, IID_IComponent))
  47. *ppv = static_cast<IComponent *>(this);
  48. else if (IsEqualIID(riid, IID_IExtendControlbar))
  49. *ppv = static_cast<IExtendControlbar *>(this);
  50. if (*ppv)
  51. {
  52. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  53. return S_OK;
  54. }
  55. return E_NOINTERFACE;
  56. }
  57. STDMETHODIMP_(ULONG) CComponent::AddRef()
  58. {
  59. return InterlockedIncrement((LONG *)&m_cref);
  60. }
  61. STDMETHODIMP_(ULONG) CComponent::Release()
  62. {
  63. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  64. {
  65. delete this;
  66. return 0;
  67. }
  68. return m_cref;
  69. }
  70. ///////////////////////////////
  71. // Interface IComponent
  72. ///////////////////////////////
  73. STDMETHODIMP CComponent::Initialize(
  74. /* [in] */ LPCONSOLE lpConsole)
  75. {
  76. HRESULT hr = S_OK;
  77. // Save away all the interfaces we'll need.
  78. // Fail if we can't QI the required interfaces.
  79. m_ipConsole = lpConsole;
  80. m_ipConsole->AddRef();
  81. hr = m_ipConsole->QueryInterface(IID_IDisplayHelp, (void **)&m_ipDisplayHelp);
  82. return hr;
  83. }
  84. STDMETHODIMP CComponent::Notify(
  85. /* [in] */ LPDATAOBJECT lpDataObject,
  86. /* [in] */ MMC_NOTIFY_TYPE event,
  87. /* [in] */ LPARAM arg,
  88. /* [in] */ LPARAM param)
  89. {
  90. MMCN_Crack(FALSE, lpDataObject, NULL, this, event, arg, param);
  91. HRESULT hr = S_FALSE;
  92. //Get our data object. If it is NULL, we return with S_FALSE.
  93. //See implementation of GetOurDataObject() to see how to
  94. //handle special data objects.
  95. CDataObject *pDataObject = GetOurDataObject(lpDataObject);
  96. if (NULL == pDataObject)
  97. return S_FALSE;
  98. CDelegationBase *base = pDataObject->GetBaseNodeObject();
  99. switch (event) {
  100. case MMCN_ADD_IMAGES:
  101. hr = base->OnAddImages((IImageList *)arg, (HSCOPEITEM)param);
  102. break;
  103. case MMCN_SELECT:
  104. // We do not set any standard verbs now.
  105. break;
  106. case MMCN_SHOW:
  107. hr = base->OnShow(m_ipConsole, (BOOL)arg, (HSCOPEITEM)param);
  108. break;
  109. case MMCN_CONTEXTHELP:
  110. hr = base->OnShowContextHelp(m_ipDisplayHelp, m_pComponentData->m_HelpFile);
  111. break;
  112. }
  113. return hr;
  114. }
  115. STDMETHODIMP CComponent::Destroy(
  116. /* [in] */ MMC_COOKIE cookie)
  117. {
  118. if (m_ipConsole) {
  119. m_ipConsole->Release();
  120. m_ipConsole = NULL;
  121. }
  122. if (m_ipDisplayHelp) {
  123. m_ipDisplayHelp->Release();
  124. m_ipDisplayHelp = NULL;
  125. }
  126. if (m_ipToolbar) {
  127. m_ipToolbar->Release();
  128. m_ipToolbar = NULL;
  129. }
  130. if (m_ipControlBar) {
  131. m_ipControlBar->Release();
  132. m_ipControlBar = NULL;
  133. }
  134. return S_OK;
  135. }
  136. STDMETHODIMP CComponent::QueryDataObject(
  137. /* [in] */ MMC_COOKIE cookie,
  138. /* [in] */ DATA_OBJECT_TYPES type,
  139. /* [out] */ LPDATAOBJECT __RPC_FAR *ppDataObject)
  140. {
  141. CDataObject *pObj = NULL;
  142. if (cookie == 0)
  143. pObj = new CDataObject((MMC_COOKIE)m_pComponentData->m_pStaticNode, type);
  144. else
  145. pObj = new CDataObject(cookie, type);
  146. if (!pObj)
  147. return E_OUTOFMEMORY;
  148. pObj->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  149. return S_OK;
  150. }
  151. STDMETHODIMP CComponent::GetResultViewType(
  152. /* [in] */ MMC_COOKIE cookie,
  153. /* [out] */ LPOLESTR __RPC_FAR *ppViewType,
  154. /* [out] */ long __RPC_FAR *pViewOptions)
  155. {
  156. CDelegationBase *base = (CDelegationBase *)cookie;
  157. //
  158. // Ask for default listview.
  159. //
  160. if (base == NULL)
  161. {
  162. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  163. *ppViewType = NULL;
  164. }
  165. else
  166. return base->GetResultViewType(ppViewType, pViewOptions);
  167. return S_OK;
  168. }
  169. STDMETHODIMP CComponent::GetDisplayInfo(
  170. /* [out][in] */ RESULTDATAITEM __RPC_FAR *pResultDataItem)
  171. {
  172. HRESULT hr = S_OK;
  173. CDelegationBase *base = NULL;
  174. // if they are asking for the RDI_STR we have one of those to give
  175. if (pResultDataItem->lParam) {
  176. base = (CDelegationBase *)pResultDataItem->lParam;
  177. if (pResultDataItem->mask & RDI_STR) {
  178. LPCTSTR pszT = base->GetDisplayName(pResultDataItem->nCol);
  179. MAKE_WIDEPTR_FROMTSTR_ALLOC(pszW, pszT);
  180. pResultDataItem->str = pszW;
  181. }
  182. if (pResultDataItem->mask & RDI_IMAGE) {
  183. pResultDataItem->nImage = base->GetBitmapIndex();
  184. }
  185. }
  186. return hr;
  187. }
  188. STDMETHODIMP CComponent::CompareObjects(
  189. /* [in] */ LPDATAOBJECT lpDataObjectA,
  190. /* [in] */ LPDATAOBJECT lpDataObjectB)
  191. {
  192. CDelegationBase *baseA = GetOurDataObject(lpDataObjectA)->GetBaseNodeObject();
  193. CDelegationBase *baseB = GetOurDataObject(lpDataObjectB)->GetBaseNodeObject();
  194. // compare the object pointers
  195. if (baseA->GetCookie() == baseB->GetCookie())
  196. return S_OK;
  197. return S_FALSE;
  198. }
  199. ///////////////////////////////
  200. // Interface IExtendControlBar
  201. ///////////////////////////////
  202. static MMCBUTTON SnapinButtons1[] =
  203. {
  204. { 0, ID_BUTTONSTART, TBSTATE_ENABLED, TBSTYLE_GROUP, L"Start Vehicle", L"Start Vehicle" },
  205. { 1, ID_BUTTONPAUSE, TBSTATE_ENABLED, TBSTYLE_GROUP, L"Pause Vehicle", L"Pause Vehicle"},
  206. { 2, ID_BUTTONSTOP, TBSTATE_ENABLED, TBSTYLE_GROUP, L"Stop Vehicle", L"Stop Vehicle" },
  207. };
  208. HRESULT CComponent::SetControlbar(
  209. /* [in] */ LPCONTROLBAR pControlbar)
  210. {
  211. HRESULT hr = S_OK;
  212. //
  213. // Clean up
  214. //
  215. // if we've got a cached toolbar, release it
  216. if (m_ipToolbar) {
  217. m_ipToolbar->Release();
  218. m_ipToolbar = NULL;
  219. }
  220. // if we've got a cached control bar, release it
  221. if (m_ipControlBar) {
  222. m_ipControlBar->Release();
  223. m_ipControlBar = NULL;
  224. }
  225. //
  226. // Install new pieces if necessary
  227. //
  228. // if a new one came in, cache and AddRef
  229. if (pControlbar) {
  230. m_ipControlBar = pControlbar;
  231. m_ipControlBar->AddRef();
  232. hr = m_ipControlBar->Create(TOOLBAR, // type of control to be created
  233. dynamic_cast<IExtendControlbar *>(this),
  234. reinterpret_cast<IUnknown **>(&m_ipToolbar));
  235. _ASSERT(SUCCEEDED(hr));
  236. // The IControlbar::Create AddRefs the toolbar object it created
  237. // so no need to do any addref on the interface.
  238. // add the bitmap to the toolbar
  239. HBITMAP hbmp = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDR_TOOLBAR1));
  240. hr = m_ipToolbar->AddBitmap(3, hbmp, 16, 16, RGB(0, 128, 128)); // NOTE, hardcoded value 3
  241. _ASSERT(SUCCEEDED(hr));
  242. // Add the buttons to the toolbar
  243. hr = m_ipToolbar->AddButtons(ARRAYLEN(SnapinButtons1), SnapinButtons1);
  244. _ASSERT(SUCCEEDED(hr));
  245. }
  246. return hr;
  247. }
  248. HRESULT CComponent::ControlbarNotify(
  249. /* [in] */ MMC_NOTIFY_TYPE event,
  250. /* [in] */ LPARAM arg,
  251. /* [in] */ LPARAM param)
  252. {
  253. HRESULT hr = S_OK;
  254. if (event == MMCN_SELECT) {
  255. BOOL bScope = (BOOL) LOWORD(arg);
  256. BOOL bSelect = (BOOL) HIWORD(arg);
  257. CDelegationBase *base = GetOurDataObject(reinterpret_cast<IDataObject *>(param))->GetBaseNodeObject();
  258. hr = base->OnSetToolbar(this, m_ipControlBar, m_ipToolbar, bScope, bSelect);
  259. } else if (event == MMCN_BTN_CLICK) {
  260. CDelegationBase *base = GetOurDataObject(reinterpret_cast<IDataObject *>(arg))->GetBaseNodeObject();
  261. hr = base->OnToolbarCommand(this, m_ipConsole, (MMC_CONSOLE_VERB)param);
  262. }
  263. return hr;
  264. }