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.

364 lines
11 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: verbs.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 4/9/1997 RaviR Created
  15. //____________________________________________________________________________
  16. //
  17. #ifndef _VERBS_H_
  18. #define _VERBS_H_
  19. class CNode;
  20. class CVerbSet;
  21. /*+-------------------------------------------------------------------------*
  22. * class CConsoleVerbState
  23. *
  24. *
  25. * PURPOSE: Button state for console commands.
  26. *
  27. *+-------------------------------------------------------------------------*/
  28. class CConsoleVerbState
  29. {
  30. public:
  31. CConsoleVerbState() {m_state = m_stateDisabled = TBSTATE_HIDDEN; m_bHiddenBySnapIn = false;}
  32. void Init(BYTE stateDisabled) {m_stateDisabled = m_state;}
  33. void Disable() {m_state = m_stateDisabled; m_bHiddenBySnapIn = false;}
  34. BYTE GetState() {return m_state;}
  35. void SetState(BYTE state) {m_state = state;}
  36. void SetHiddenBySnapin(BOOL b) {m_bHiddenBySnapIn = b;}
  37. bool IsHiddenBySnapin() {return m_bHiddenBySnapIn;}
  38. private:
  39. BYTE m_state; // State
  40. bool m_bHiddenBySnapIn;
  41. BYTE m_stateDisabled; // what "Disabled" means for this verb.
  42. };
  43. typedef CConsoleVerbState *LPCONSOLE_VERB_STATE;
  44. /*+-------------------------------------------------------------------------*
  45. * class CConsoleVerbImpl
  46. *
  47. *
  48. * PURPOSE: This is the object that the snapins' IConsoleVerb points to.
  49. * This object has a pointer to an implementation of CVerbSet.
  50. * The CVerbSet object can be switched to allow a temporary
  51. * selection, for instance. This allows a view to have its toolbars
  52. * to get their verb settings from a different CVerbSet object than
  53. * the right click context menu does - just set the CVerbSet
  54. * pointer on the CConsoleVerbImpl to the CVerbSet that the
  55. * changes should be routed to, and send the snapin an MMCN_SELECT
  56. * notification.
  57. *
  58. * What might be confusing at first is that both CConsoleVerbImpl
  59. * as well as CVerbSet keep a set of states. 1) The CConsoleVerbImpl
  60. * needs to have its own set because the
  61. * set of states needs to look consistent to the snapin regardless
  62. * of where the CVerbSet pointer is pointing to. 2) At the same time,
  63. * the CVerbSet needs its own set of states so that its client
  64. * consistently reads this set.
  65. *+-------------------------------------------------------------------------*/
  66. class CConsoleVerbImpl : public IConsoleVerb, public CComObjectRoot
  67. {
  68. public:
  69. CConsoleVerbImpl();
  70. ~CConsoleVerbImpl();
  71. // ATL COM maps
  72. BEGIN_COM_MAP(CConsoleVerbImpl)
  73. COM_INTERFACE_ENTRY(IConsoleVerb)
  74. END_COM_MAP()
  75. // IConsoleVerb methods
  76. public:
  77. STDMETHOD(GetVerbState)(MMC_CONSOLE_VERB eCmdID, MMC_BUTTON_STATE nState, BOOL* pbState);
  78. STDMETHOD(SetVerbState)(MMC_CONSOLE_VERB eCmdID, MMC_BUTTON_STATE nState, BOOL bState);
  79. STDMETHOD(SetDefaultVerb)(MMC_CONSOLE_VERB eCmdID);
  80. STDMETHOD(GetDefaultVerb)(MMC_CONSOLE_VERB* peCmdID)
  81. {
  82. *peCmdID = m_DefaultVerb;
  83. return S_OK;
  84. }
  85. BYTE GetVerbState(MMC_CONSOLE_VERB verb);
  86. HRESULT SetDisabledAll(void);
  87. void SetVerbSet(IConsoleVerb* pVerbSet);
  88. private:
  89. CVerbSet* GetVerbSet()
  90. {
  91. ASSERT(m_pVerbSet != NULL);
  92. return m_pVerbSet;
  93. }
  94. public:
  95. #ifdef DBG
  96. int dbg_cRef_CConsoleVerbImpl;
  97. ULONG InternalAddRef();
  98. ULONG InternalRelease();
  99. #endif // DBG
  100. // Internal functions
  101. private:
  102. LPCONSOLE_VERB_STATE GetConsoleVerbState(MMC_CONSOLE_VERB m_eCmdID);
  103. // Implementation
  104. private:
  105. CVerbSet* m_pVerbSet;
  106. MMC_CONSOLE_VERB m_DefaultVerb;
  107. CConsoleVerbState m_rgConsoleVerbStates[evMax];
  108. bool m_bCutVerbDisabledBySnapin;
  109. }; // class CConsoleVerbImpl
  110. HRESULT _GetConsoleVerb(CNode* pNode, LPCONSOLEVERB* ppConsoleVerb);
  111. /*+-------------------------------------------------------------------------*
  112. * class CVerbSetBase
  113. *
  114. *
  115. * PURPOSE: This class retains the state of all the verbs corresponding
  116. * to a particular object. See the note in CConsoleVerbImpl above.
  117. *
  118. * This also forms base class for CVerbSet as well as CTemporaryVerbSet
  119. * objects.
  120. *
  121. * Do not instantiate this object directly you should create either
  122. * CVerbSet or CTemporaryVerbSet object.
  123. *
  124. *+-------------------------------------------------------------------------*/
  125. class CVerbSetBase : public IConsoleVerb, public CComObjectRoot
  126. {
  127. public:
  128. CVerbSetBase();
  129. ~CVerbSetBase();
  130. // ATL COM maps
  131. BEGIN_COM_MAP(CVerbSetBase)
  132. COM_INTERFACE_ENTRY(IConsoleVerb)
  133. END_COM_MAP()
  134. // IConsoleVerb methods
  135. public:
  136. STDMETHOD(GetVerbState)(MMC_CONSOLE_VERB m_eCmdID, MMC_BUTTON_STATE nState, BOOL* pbState);
  137. STDMETHOD(GetDefaultVerb)(MMC_CONSOLE_VERB* peCmdID);
  138. STDMETHOD(SetVerbState)(MMC_CONSOLE_VERB m_eCmdID, MMC_BUTTON_STATE nState, BOOL bState)
  139. {
  140. ASSERT(0 && "Should never come here!!!");
  141. return E_FAIL;
  142. }
  143. STDMETHOD(SetDefaultVerb)(MMC_CONSOLE_VERB m_eCmdID)
  144. {
  145. ASSERT(0 && "Should never come here!!!");
  146. return E_FAIL;
  147. }
  148. SC ScInitializeForMultiSelection(CNode *pNode, bool bSelect);
  149. void SetMultiSelection(CMultiSelection* pMS);
  150. SC ScComputeVerbStates();
  151. IConsoleVerb* GetConsoleVerb(void) const;
  152. // Implementation
  153. protected:
  154. void Reset();
  155. BYTE _GetVerbState(EVerb ev);
  156. private:
  157. void _EnableVerb(EVerb eVerb, bool fEnable);
  158. void _EnableVerb(EVerb eVerb);
  159. void _HideVerb(EVerb eVerb);
  160. void _AskSnapin(EVerb eVerb);
  161. protected:
  162. CNode* m_pNode;
  163. bool m_bScopePaneSelected;
  164. LPARAM m_lResultCookie;
  165. bool m_bVerbContextDataValid;
  166. CMultiSelection* m_pMultiSelection;
  167. IConsoleVerbPtr m_spConsoleVerbCurr;
  168. struct SVerbState
  169. {
  170. BYTE bAskSnapin; // 0 => don't ask, 1 => ask, 2 => asked and answered.
  171. BYTE nState;
  172. };
  173. SVerbState m_rbVerbState[evMax];
  174. };
  175. /*+-------------------------------------------------------------------------*
  176. * class CVerbSet
  177. *
  178. *
  179. * PURPOSE: This object stores verb state information for currently (non-temporarily)
  180. * selected item if there is one and is created by CViewData per view.
  181. *
  182. *+-------------------------------------------------------------------------*/
  183. class CVerbSet : public CVerbSetBase
  184. {
  185. public:
  186. CVerbSet() { Reset(); }
  187. SC ScInitialize (CNode *pNode, bool bScope, bool bSelect,
  188. bool bLVBackgroundSelected, LPARAM lResultCookie);
  189. void Notify(IConsoleVerb* pCVIn, MMC_CONSOLE_VERB m_eCmdID);
  190. SC ScGetVerbSetContext(CNode*& pNode, bool& bScope, LPARAM& lResultCookie, bool& bSelected);
  191. void DisableChangesToStdbar() { m_bChangesToStdbarEnabled = false;}
  192. void EnableChangesToStdbar() { m_bChangesToStdbarEnabled = true;}
  193. private:
  194. bool IsChangesToStdbarEnabled() { return m_bChangesToStdbarEnabled;}
  195. void Reset();
  196. private:
  197. bool m_bChangesToStdbarEnabled;
  198. };
  199. /*+-------------------------------------------------------------------------*
  200. * class CTemporaryVerbSet
  201. *
  202. *
  203. * PURPOSE: This object provides methods to initialize temporary verbset state
  204. * infomation. This de-selects any item that is currently selected, then
  205. * selects temp item computes verbs, de-selects temp item and selects
  206. * original item.
  207. *
  208. * Here selection or de-selection means sending (MMCN_SELECT, true) or
  209. * (MMCN_SELECT, false).
  210. *
  211. *+-------------------------------------------------------------------------*/
  212. class CTemporaryVerbSet : public CVerbSetBase
  213. {
  214. public:
  215. STDMETHOD(GetDefaultVerb)(MMC_CONSOLE_VERB* peCmdID);
  216. SC ScInitialize(CNode *pNode, LPARAM lResultCookie, bool bScopePaneSel);
  217. SC ScInitialize(LPDATAOBJECT lpDataObject, CNode *pNode, bool bScopePaneSel, LPARAM lResultCookie);
  218. SC ScComputeVerbStates();
  219. private:
  220. SC ScInitializePermanentVerbSet(CNode *pNode, bool bSelect);
  221. private:
  222. MMC_CONSOLE_VERB m_DefaultVerb;
  223. };
  224. inline CVerbSetBase::CVerbSetBase()
  225. {
  226. Reset();
  227. DEBUG_INCREMENT_INSTANCE_COUNTER(CVerbSetBase);
  228. }
  229. inline CVerbSetBase::~CVerbSetBase()
  230. {
  231. DEBUG_DECREMENT_INSTANCE_COUNTER(CVerbSetBase);
  232. }
  233. inline void CVerbSetBase::SetMultiSelection(CMultiSelection* pMS)
  234. {
  235. m_pMultiSelection = pMS;
  236. }
  237. inline void CVerbSetBase::Reset()
  238. {
  239. m_bScopePaneSelected = false;
  240. m_bVerbContextDataValid = false;
  241. m_lResultCookie = NULL;
  242. m_pNode = NULL;
  243. m_pMultiSelection = NULL;
  244. m_spConsoleVerbCurr = NULL;
  245. }
  246. inline IConsoleVerb* CVerbSetBase::GetConsoleVerb(void) const
  247. {
  248. return m_spConsoleVerbCurr;
  249. }
  250. inline void CVerbSetBase::_EnableVerb(EVerb eVerb, bool fEnable)
  251. {
  252. if (fEnable)
  253. _EnableVerb(eVerb);
  254. else
  255. _HideVerb(eVerb);
  256. }
  257. inline void CVerbSetBase::_EnableVerb(EVerb eVerb)
  258. {
  259. m_rbVerbState[eVerb].bAskSnapin = 0;
  260. m_rbVerbState[eVerb].nState = TBSTATE_ENABLED;
  261. }
  262. inline void CVerbSetBase::_HideVerb(EVerb eVerb)
  263. {
  264. m_rbVerbState[eVerb].bAskSnapin = 0;
  265. m_rbVerbState[eVerb].nState = TBSTATE_HIDDEN;
  266. }
  267. inline void CVerbSetBase::_AskSnapin(EVerb eVerb)
  268. {
  269. m_rbVerbState[eVerb].bAskSnapin = 1;
  270. m_rbVerbState[eVerb].nState = 0;
  271. }
  272. inline void CConsoleVerbImpl::SetVerbSet(IConsoleVerb* pVerbSet)
  273. {
  274. m_pVerbSet = dynamic_cast<CVerbSet*>(pVerbSet);
  275. ASSERT(m_pVerbSet != NULL);
  276. }
  277. inline void CVerbSet::Reset()
  278. {
  279. CVerbSetBase::Reset();
  280. m_bChangesToStdbarEnabled = true;
  281. }
  282. inline SC CVerbSet::ScGetVerbSetContext(CNode*& pNode,
  283. bool& bScopePaneSel,
  284. LPARAM& lResultCookie,
  285. bool& bDataValid)
  286. {
  287. pNode = m_pNode;
  288. bScopePaneSel = m_bScopePaneSelected;
  289. lResultCookie = m_lResultCookie;
  290. bDataValid = m_bVerbContextDataValid;
  291. if (! pNode)
  292. return E_FAIL;
  293. return S_OK;
  294. }
  295. #endif // _VERBS_H_