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.

273 lines
7.1 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: menubtn.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 5/17/1997 WayneSc Created
  15. //____________________________________________________________________________
  16. //
  17. #include "stdafx.h"
  18. #include "menubtn.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. //////////////////////////////////////////////////////////////////////////////
  24. // IMenuButton implementation
  25. DEBUG_DECLARE_INSTANCE_COUNTER(CMenuButton);
  26. CMenuButton::CMenuButton()
  27. {
  28. m_pControlbar = NULL;
  29. m_pMenuButtonsMgr = NULL;
  30. DEBUG_INCREMENT_INSTANCE_COUNTER(CMenuButton);
  31. }
  32. CMenuButton::~CMenuButton()
  33. {
  34. m_pControlbar = NULL;
  35. m_pMenuButtonsMgr = NULL;
  36. DEBUG_DECREMENT_INSTANCE_COUNTER(CMenuButton);
  37. }
  38. void CMenuButton::SetControlbar(CControlbar* pControlbar)
  39. {
  40. m_pControlbar = pControlbar;
  41. }
  42. CControlbar* CMenuButton::GetControlbar()
  43. {
  44. return m_pControlbar;
  45. }
  46. CMenuButtonsMgr* CMenuButton::GetMenuButtonsMgr(void)
  47. {
  48. if ((NULL == m_pMenuButtonsMgr) && (NULL != m_pControlbar) )
  49. {
  50. m_pMenuButtonsMgr = m_pControlbar->GetMenuButtonsMgr();
  51. }
  52. return m_pMenuButtonsMgr;
  53. }
  54. //+-------------------------------------------------------------------
  55. //
  56. // Member: AddButton
  57. //
  58. // Synopsis: Add a menu button, called by snapin.
  59. //
  60. // Arguments: [idCommand] - Command ID for the menu button.
  61. // [lpButtonText] - The text for menu button.
  62. // [lpTooltipText] - Status / Tool tip text.
  63. //
  64. // Returns: HRESULT
  65. //
  66. //--------------------------------------------------------------------
  67. STDMETHODIMP CMenuButton::AddButton(int idCommand, LPOLESTR lpButtonText, LPOLESTR lpTooltipText)
  68. {
  69. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IMenuButton::AddButton"));
  70. if (lpButtonText == NULL || lpTooltipText == NULL)
  71. {
  72. sc = E_INVALIDARG;
  73. TraceSnapinError(_T("Invalid Args"), sc);
  74. return sc.ToHr();
  75. }
  76. CMenuButtonsMgr* pMenuButtonsMgr = GetMenuButtonsMgr();
  77. if (NULL == pMenuButtonsMgr)
  78. {
  79. sc = E_UNEXPECTED;
  80. return sc.ToHr();
  81. }
  82. sc = pMenuButtonsMgr->ScAddMenuButton(this, idCommand, lpButtonText, lpTooltipText);
  83. if (sc)
  84. return sc.ToHr();
  85. return sc.ToHr();
  86. }
  87. //+-------------------------------------------------------------------
  88. //
  89. // Member: SetButton
  90. //
  91. // Synopsis: Modify a menu button name or status text, called by snapin.
  92. //
  93. // Arguments: [idCommand] - Command ID for the menu button.
  94. // [lpButtonText] - The text for menu button.
  95. // [lpTooltipText] - Status / Tool tip text.
  96. //
  97. // Returns: HRESULT
  98. //
  99. //--------------------------------------------------------------------
  100. STDMETHODIMP CMenuButton::SetButton(int idCommand, LPOLESTR lpButtonText, LPOLESTR lpTooltipText)
  101. {
  102. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IMenuButton::SetButton"));
  103. if (lpButtonText == NULL || lpTooltipText == NULL)
  104. {
  105. sc = E_INVALIDARG;
  106. TraceSnapinError(_T("Invalid Args"), sc);
  107. return sc.ToHr();
  108. }
  109. CMenuButtonsMgr* pMenuButtonsMgr = GetMenuButtonsMgr();
  110. if (NULL == pMenuButtonsMgr)
  111. {
  112. sc = E_UNEXPECTED;
  113. return sc.ToHr();
  114. }
  115. sc = pMenuButtonsMgr->ScModifyMenuButton(this, idCommand, lpButtonText, lpTooltipText);
  116. if (sc)
  117. return sc.ToHr();
  118. return sc.ToHr();
  119. }
  120. //+-------------------------------------------------------------------
  121. //
  122. // Member: SetButtonState
  123. //
  124. // Synopsis: Modify a menu button state, called by snapin.
  125. //
  126. // Arguments: [idCommand] - Command ID for the menu button.
  127. // [nState] - The state to be modified.
  128. // [bState] - Set or Reset the state.
  129. //
  130. // Returns: HRESULT
  131. //
  132. //--------------------------------------------------------------------
  133. STDMETHODIMP CMenuButton::SetButtonState(int idCommand, MMC_BUTTON_STATE nState, BOOL bState)
  134. {
  135. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IMenuButton::SetButtonState"));
  136. if (nState == CHECKED || nState == INDETERMINATE)
  137. {
  138. sc = E_INVALIDARG;
  139. TraceSnapinError(_T("Invalid Button States"), sc);
  140. return sc.ToHr();
  141. }
  142. if (m_pControlbar == NULL)
  143. {
  144. sc = E_UNEXPECTED;
  145. return sc.ToHr();
  146. }
  147. // ENABLED, HIDDEN, BUTTONPRESSED
  148. CMenuButtonsMgr* pMenuButtonsMgr = GetMenuButtonsMgr();
  149. if (NULL == pMenuButtonsMgr)
  150. {
  151. sc = E_UNEXPECTED;
  152. return sc.ToHr();
  153. }
  154. sc = pMenuButtonsMgr->ScModifyMenuButtonState(this, idCommand, nState, bState);
  155. if (sc)
  156. return sc.ToHr();
  157. return sc.ToHr();
  158. }
  159. //+-------------------------------------------------------------------
  160. //
  161. // Member: ScAttach
  162. //
  163. // Synopsis: Attach this MenuButton object to the UI.
  164. //
  165. // Arguments: None
  166. //
  167. // Returns: SC
  168. //
  169. //--------------------------------------------------------------------
  170. SC CMenuButton::ScAttach(void)
  171. {
  172. DECLARE_SC(sc, _T("CMenuButton::ScAttach"));
  173. CMenuButtonsMgr* pMenuButtonsMgr = GetMenuButtonsMgr();
  174. if (NULL == pMenuButtonsMgr)
  175. return (sc = E_UNEXPECTED);
  176. sc = pMenuButtonsMgr->ScAttachMenuButton(this);
  177. if (sc)
  178. return sc.ToHr();
  179. return sc;
  180. }
  181. //+-------------------------------------------------------------------
  182. //
  183. // Member: ScDetach
  184. //
  185. // Synopsis: Detach this MenuButton object from the UI.
  186. //
  187. // Arguments: None
  188. //
  189. // Returns: SC
  190. //
  191. //--------------------------------------------------------------------
  192. SC CMenuButton::ScDetach(void)
  193. {
  194. DECLARE_SC(sc, _T("CMenuButton::ScDetach"));
  195. CMenuButtonsMgr* pMenuButtonsMgr = GetMenuButtonsMgr();
  196. if (NULL == pMenuButtonsMgr)
  197. return (sc = E_UNEXPECTED);
  198. sc = pMenuButtonsMgr->ScDetachMenuButton(this);
  199. if (sc)
  200. return sc;
  201. SetControlbar(NULL);
  202. return sc;
  203. }
  204. //+-------------------------------------------------------------------
  205. //
  206. // Member: ScNotifyMenuBtnClick
  207. //
  208. // Synopsis: Notify the Controbar (snapin) that menu button is clicked.
  209. //
  210. // Arguments: [hNode] - The node that owns the result pane.
  211. // [bScope] - Scope or Result.
  212. // [lParam] - If result (pane) lParam of result item.
  213. // [menuButtonData] - MENUBUTTONDATA
  214. //
  215. // Returns: SC
  216. //
  217. //--------------------------------------------------------------------
  218. SC CMenuButton:: ScNotifyMenuBtnClick(HNODE hNode, bool bScope,
  219. LPARAM lParam,
  220. MENUBUTTONDATA& menuButtonData)
  221. {
  222. DECLARE_SC(sc, _T("CMenuButton::ScNotifyMenuBtnClick"));
  223. if (NULL == m_pControlbar)
  224. return (sc = E_UNEXPECTED);
  225. sc = m_pControlbar->ScNotifySnapinOfMenuBtnClick(hNode, bScope, lParam, &menuButtonData);
  226. if (sc)
  227. return sc.ToHr();
  228. return sc;
  229. }