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.

316 lines
8.2 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: ctrlbar.h
  7. //
  8. // Contents: IControlbar implementation, peer of IExtendControlbar
  9. //
  10. // Classes: CControlbar
  11. //
  12. // History:
  13. //____________________________________________________________________________
  14. //
  15. #ifndef _CTRLBAR_H_
  16. #define _CTRLBAR_H_
  17. class CControlbarsCache;
  18. class CMenuButton;
  19. class CNode;
  20. class CComponentPtrArray;
  21. class CToolbar;
  22. //+-------------------------------------------------------------------
  23. //
  24. // class: CControlbar
  25. //
  26. // Purpose: The IControlbar implementation that (equivalent
  27. // to IExtendControlbar). This allows manipulation
  28. // of toolbars & menu buttons.
  29. // The snapin and CSelData hold reference to this object.
  30. //
  31. // History: 10-12-1999 AnandhaG Created
  32. //
  33. //--------------------------------------------------------------------
  34. class CControlbar : public IControlbar,
  35. public CComObjectRoot
  36. {
  37. public:
  38. CControlbar();
  39. ~CControlbar();
  40. IMPLEMENTS_SNAPIN_NAME_FOR_DEBUG()
  41. private:
  42. CControlbar(const CControlbar& controlBar);
  43. public:
  44. // ATL COM map
  45. BEGIN_COM_MAP(CControlbar)
  46. COM_INTERFACE_ENTRY(IControlbar)
  47. END_COM_MAP()
  48. #ifdef DBG
  49. int dbg_cRef;
  50. ULONG InternalAddRef()
  51. {
  52. bool b = 1;
  53. if (b)
  54. ++dbg_cRef;
  55. return CComObjectRoot::InternalAddRef();
  56. }
  57. ULONG InternalRelease()
  58. {
  59. bool b = 1;
  60. if (b)
  61. --dbg_cRef;
  62. return CComObjectRoot::InternalRelease();
  63. }
  64. #endif // DBG
  65. // IControlbar members
  66. public:
  67. STDMETHOD(Create)(MMC_CONTROL_TYPE nType,
  68. LPEXTENDCONTROLBAR pExtendControlbar,
  69. LPUNKNOWN* ppUnknown);
  70. STDMETHOD(Attach)(MMC_CONTROL_TYPE nType, LPUNKNOWN lpUnknown);
  71. STDMETHOD(Detach)(LPUNKNOWN lpUnknown);
  72. public:
  73. HRESULT ControlbarNotify(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param);
  74. SC ScCleanup();
  75. SC ScShowToolbars(bool bShow);
  76. // Toolbar button & Menu button click handler.
  77. SC ScNotifySnapinOfMenuBtnClick(HNODE hNode, bool bScope, LPARAM lParam, LPMENUBUTTONDATA lpmenuButtonData);
  78. SC ScNotifySnapinOfToolBtnClick(HNODE hNode, bool bScope, LPARAM lParam, UINT nID);
  79. // The CToolbar object calls this when it is being destroyed.
  80. // It wants Controlbar to stop referencing it.
  81. void DeleteFromToolbarsList(CToolbar *pToolbar)
  82. {
  83. m_ToolbarsList.remove(pToolbar);
  84. }
  85. public:
  86. // Accessors.
  87. IExtendControlbar* GetExtendControlbar()
  88. {
  89. return m_spExtendControlbar;
  90. }
  91. void SetExtendControlbar(IExtendControlbar* pExtendControlbar,
  92. const CLSID& clsidSnapin)
  93. {
  94. ASSERT(pExtendControlbar != NULL);
  95. ASSERT(m_spExtendControlbar == NULL);
  96. m_spExtendControlbar = pExtendControlbar;
  97. m_clsidSnapin = clsidSnapin;
  98. }
  99. void SetExtendControlbar(IExtendControlbar* pExtendControlbar)
  100. {
  101. ASSERT(pExtendControlbar != NULL);
  102. ASSERT(m_spExtendControlbar == NULL);
  103. m_spExtendControlbar = pExtendControlbar;
  104. }
  105. BOOL IsSameSnapin(const CLSID& clsidSnapin)
  106. {
  107. return IsEqualCLSID(m_clsidSnapin, clsidSnapin);
  108. }
  109. void SetCache(CControlbarsCache* pCache)
  110. {
  111. ASSERT(pCache != NULL);
  112. m_pCache = pCache;
  113. }
  114. CMenuButtonsMgr* GetMenuButtonsMgr()
  115. {
  116. CViewData* pViewData = GetViewData();
  117. if (NULL != pViewData)
  118. {
  119. return pViewData->GetMenuButtonsMgr();
  120. }
  121. return NULL;
  122. }
  123. CAMCViewToolbarsMgr* GetAMCViewToolbarsMgr()
  124. {
  125. CViewData* pViewData = GetViewData();
  126. if (NULL != pViewData)
  127. {
  128. return pViewData->GetAMCViewToolbarsMgr();
  129. }
  130. return NULL;
  131. }
  132. private:
  133. // private methods
  134. CViewData* GetViewData();
  135. SC ScCreateToolbar(LPEXTENDCONTROLBAR pExtendControlbar, LPUNKNOWN* ppUnknown);
  136. SC ScCreateMenuButton(LPEXTENDCONTROLBAR pExtendControlbar, LPUNKNOWN* ppUnknown);
  137. SC ScAttachToolbar(LPUNKNOWN lpUnknown);
  138. SC ScAttachMenuButtons(LPUNKNOWN lpUnknown);
  139. SC ScDetachToolbars();
  140. SC ScDetachToolbar(LPTOOLBAR lpToolbar);
  141. SC ScDetachMenuButton(LPMENUBUTTON lpMenuButton);
  142. // Implementation
  143. private:
  144. IExtendControlbarPtr m_spExtendControlbar;
  145. CLSID m_clsidSnapin;
  146. CControlbarsCache* m_pCache;
  147. // List of IToolbar implementations (CToolbar) created.
  148. typedef std::list<CToolbar*> ToolbarsList;
  149. // Toolbars specific data
  150. ToolbarsList m_ToolbarsList;
  151. CMenuButton* m_pMenuButton; // One per IControlbar.
  152. }; // class CControlbar
  153. typedef CTypedPtrList<MMC::CPtrList, CControlbar*> CControlbarsList;
  154. class CSelData
  155. {
  156. public:
  157. CSelData(bool bScopeSel, bool bSelect)
  158. :
  159. m_bScopeSel(bScopeSel), m_bSelect(bSelect), m_pNodeScope(NULL),
  160. m_pMS(NULL), m_pCtrlbarPrimary(NULL), m_lCookie(-1),
  161. m_pCompPrimary(NULL)
  162. {
  163. DEBUG_INCREMENT_INSTANCE_COUNTER(CSelData);
  164. }
  165. ~CSelData()
  166. {
  167. DECLARE_SC(sc, _T("CSelData::~CSelData"));
  168. sc = ScReset();
  169. DEBUG_DECREMENT_INSTANCE_COUNTER(CSelData);
  170. }
  171. SC ScReset();
  172. SC ScDestroyPrimaryCtrlbar();
  173. SC ScDestroyExtensionCtrlbars();
  174. SC ScShowToolbars(bool bShow);
  175. bool operator==(CSelData& rhs)
  176. {
  177. if (m_bScopeSel != rhs.m_bScopeSel ||
  178. m_bSelect != rhs.m_bSelect)
  179. return false;
  180. if (m_bScopeSel)
  181. return (m_pNodeScope == rhs.m_pNodeScope);
  182. else
  183. return (m_pMS == rhs.m_pMS && m_lCookie == rhs.m_lCookie);
  184. }
  185. CControlbar* GetControlbar(const CLSID& clsidSnapin);
  186. CControlbarsList& GetControlbarsList()
  187. {
  188. return m_listExtCBs;
  189. }
  190. bool IsScope()
  191. {
  192. return m_bScopeSel;
  193. }
  194. bool IsSelect()
  195. {
  196. return m_bSelect;
  197. }
  198. // Implementation
  199. CComponent* m_pCompPrimary;
  200. CControlbar* m_pCtrlbarPrimary;
  201. CControlbarsList m_listExtCBs;
  202. IDataObjectPtr m_spDataObject;
  203. // data for scope sel
  204. CNode* m_pNodeScope;
  205. // data for result sel
  206. CMultiSelection* m_pMS;
  207. MMC_COOKIE m_lCookie;
  208. bool m_bScopeSel;
  209. bool m_bSelect;
  210. }; // class CSelData
  211. class CControlbarsCache : public IControlbarsCache,
  212. public CComObjectRoot
  213. {
  214. public:
  215. CControlbarsCache() : m_pViewData(NULL), m_SelData(false, false)
  216. {
  217. DEBUG_INCREMENT_INSTANCE_COUNTER(CControlbarsCache);
  218. }
  219. ~CControlbarsCache()
  220. {
  221. DEBUG_DECREMENT_INSTANCE_COUNTER(CControlbarsCache);
  222. }
  223. public:
  224. // ATL COM map
  225. BEGIN_COM_MAP(CControlbarsCache)
  226. COM_INTERFACE_ENTRY(IControlbarsCache)
  227. END_COM_MAP()
  228. // IControlbarsCache methods
  229. public:
  230. STDMETHOD(DetachControlbars)()
  231. {
  232. DECLARE_SC(sc, _T("CControlbarsCache::DetachControlbars"));
  233. sc = m_SelData.ScReset();
  234. if (sc)
  235. return sc.ToHr();
  236. return sc.ToHr();
  237. }
  238. public:
  239. HRESULT OnResultSelChange(CNode* pNode, MMC_COOKIE cookie, BOOL bSelected);
  240. HRESULT OnScopeSelChange(CNode* pNode, BOOL bSelected);
  241. HRESULT OnMultiSelect(CNode* pNodeScope, CMultiSelection* pMultiSelection,
  242. IDataObject* pDOMultiSel, BOOL bSelect);
  243. void SetViewData(CViewData* pViewData);
  244. CViewData* GetViewData();
  245. SC ScShowToolbars(bool bShow)
  246. {
  247. DECLARE_SC(sc, _T("CControlbarsCache::ScShowToolbars"));
  248. return (sc = m_SelData.ScShowToolbars(bShow));
  249. }
  250. private:
  251. CSelData m_SelData;
  252. CViewData* m_pViewData;
  253. // private methods
  254. HRESULT _OnDeSelect(CSelData& selData);
  255. CControlbar* CreateControlbar(IExtendControlbarPtr& spECB,
  256. const CLSID& clsidSnapin);
  257. HRESULT _ProcessSelection(CSelData& selData,
  258. CList<CLSID, CLSID&>& extnSnapins);
  259. }; // class CControlbarsCache
  260. #endif // _CTRLBAR_H_