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.

456 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: toolbar.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. //////////////////////////////////////////////////////////////////////////////
  16. // IToolbar implementation
  17. DEBUG_DECLARE_INSTANCE_COUNTER(CToolbar);
  18. CToolbar::CToolbar()
  19. {
  20. m_pControlbar = NULL;
  21. m_pToolbarIntf = NULL;
  22. DEBUG_INCREMENT_INSTANCE_COUNTER(CToolbar);
  23. }
  24. CToolbar::~CToolbar()
  25. {
  26. DECLARE_SC(sc, _T("CToolbar::~CToolbar"));
  27. // Destroy the toolbar UI.
  28. if (m_pToolbarIntf)
  29. {
  30. sc = m_pToolbarIntf->ScDelete(this);
  31. if (sc)
  32. sc.TraceAndClear();
  33. m_pToolbarIntf = NULL;
  34. }
  35. // Controlbar has a reference to this object, ask it
  36. // to stop referencing this object.
  37. if (m_pControlbar)
  38. {
  39. m_pControlbar->DeleteFromToolbarsList(this);
  40. m_pControlbar = NULL;
  41. }
  42. DEBUG_DECREMENT_INSTANCE_COUNTER(CToolbar);
  43. }
  44. //+-------------------------------------------------------------------
  45. //
  46. // Member: AddBitmap
  47. //
  48. // Synopsis: Add bitmaps for given toolbar.
  49. //
  50. // Arguments:
  51. // [nImages] - Number of bitmap images.
  52. // [hbmp] - Handle to the bitmap.
  53. // [cxSize] - Size of the bitmap.
  54. // [cySize] - Size of the bitmap.
  55. // [crMask] - color mask.
  56. //
  57. // Returns: HRESULT
  58. //
  59. // Note: We support only 16x16 bitmaps for toolbars.
  60. //
  61. //--------------------------------------------------------------------
  62. STDMETHODIMP CToolbar::AddBitmap(int nImages, HBITMAP hbmp, int cxSize,
  63. int cySize, COLORREF crMask)
  64. {
  65. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IToolbar::AddBitmap"));
  66. if (hbmp == NULL || nImages < 1 || cxSize < 1 || cySize < 1)
  67. {
  68. sc = E_INVALIDARG;
  69. TraceSnapinError(_T("Invalid Arguments"), sc);
  70. return sc.ToHr();
  71. }
  72. // Note: We support only 16x16 bitmaps for toolbars.
  73. if (cxSize != BUTTON_BITMAP_SIZE || cySize != BUTTON_BITMAP_SIZE)
  74. {
  75. sc = E_INVALIDARG;
  76. TraceSnapinError(_T("Invalid Bitmap size"), sc);
  77. return sc.ToHr();
  78. }
  79. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  80. if (sc)
  81. return sc.ToHr();
  82. sc = m_pToolbarIntf->ScAddBitmap(this, nImages, hbmp, crMask);
  83. if (sc)
  84. return sc.ToHr();
  85. return sc.ToHr();
  86. }
  87. //+-------------------------------------------------------------------
  88. //
  89. // Member: AddButtons
  90. //
  91. // Synopsis: Add buttons for given toolbar.
  92. //
  93. // Arguments:
  94. // [nButtons] - Number of buttons.
  95. // [lpButtons] - Array of MMCBUTTONS to be added.
  96. //
  97. // Returns: HRESULT
  98. //
  99. //--------------------------------------------------------------------
  100. STDMETHODIMP CToolbar::AddButtons(int nButtons, LPMMCBUTTON lpButtons)
  101. {
  102. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IToolbar::AddButtons"));
  103. if ( (lpButtons == NULL) || (nButtons < 1) )
  104. {
  105. sc = E_INVALIDARG;
  106. TraceSnapinError(_T("Invalid Args"), sc);
  107. return sc.ToHr();
  108. }
  109. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  110. if (sc)
  111. return sc.ToHr();
  112. sc = m_pToolbarIntf->ScAddButtons(this, nButtons, lpButtons);
  113. if (sc)
  114. return sc.ToHr();
  115. return sc.ToHr();
  116. }
  117. //+-------------------------------------------------------------------
  118. //
  119. // Member: InsertButton
  120. //
  121. // Synopsis: Add buttons for given toolbar at given index.
  122. //
  123. // Arguments:
  124. // [nButtons] - Index at which this button is to be added.
  125. // [lpButton] - Ptr to MMCBUTTON to be added.
  126. //
  127. // Returns: HRESULT
  128. //
  129. //--------------------------------------------------------------------
  130. STDMETHODIMP CToolbar::InsertButton(int nIndex, LPMMCBUTTON lpButton)
  131. {
  132. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IToolbar::InsertButton"));
  133. if ( (lpButton == NULL) || (nIndex < 0) )
  134. {
  135. sc = E_INVALIDARG;
  136. TraceSnapinError(_T("Invalid Args"), sc);
  137. return sc.ToHr();
  138. }
  139. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  140. if (sc)
  141. return sc.ToHr();
  142. sc = m_pToolbarIntf->ScInsertButton(this, nIndex, lpButton);
  143. if (sc)
  144. return sc.ToHr();
  145. return sc.ToHr();
  146. }
  147. //+-------------------------------------------------------------------
  148. //
  149. // Member: DeleteButton
  150. //
  151. // Synopsis: Delete the button at given index.
  152. //
  153. // Arguments:
  154. // [nIndex] - Index of the button to be deleted.
  155. //
  156. // Returns: HRESULT
  157. //
  158. //--------------------------------------------------------------------
  159. STDMETHODIMP CToolbar::DeleteButton(int nIndex)
  160. {
  161. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IToolbar::DeleteButton"));
  162. if (nIndex < 0)
  163. {
  164. sc = E_INVALIDARG;
  165. TraceSnapinError(_T("Invalid index"), sc);
  166. return sc.ToHr();
  167. }
  168. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  169. if (sc)
  170. return sc.ToHr();
  171. sc = m_pToolbarIntf->ScDeleteButton(this, nIndex);
  172. if (sc)
  173. return sc.ToHr();
  174. return sc.ToHr();
  175. }
  176. //+-------------------------------------------------------------------
  177. //
  178. // Member: GetTBStateFromMMCButtonState
  179. //
  180. // Synopsis: We use MMC_BUTTON_STATE for Set/Get Button States &
  181. // use TBSTATE for Insert/Add Buttons.
  182. // This method helps Get/Set ButtonState methods to translate
  183. // the MMC_BUTTON_STATEs to TBSTATE so that conui deals only
  184. // with TBSTATE.
  185. //
  186. // Arguments: [nState] - MMC_BUTTON_STATE to be transformed.
  187. //
  188. // Returns: TBSTATE value.
  189. //
  190. //--------------------------------------------------------------------
  191. BYTE CToolbar::GetTBStateFromMMCButtonState(MMC_BUTTON_STATE nState)
  192. {
  193. switch (nState)
  194. {
  195. case ENABLED:
  196. return TBSTATE_ENABLED;
  197. break;
  198. case CHECKED:
  199. return TBSTATE_CHECKED;
  200. break;
  201. case HIDDEN:
  202. return TBSTATE_HIDDEN;
  203. break;
  204. case INDETERMINATE:
  205. return TBSTATE_INDETERMINATE;
  206. break;
  207. case BUTTONPRESSED:
  208. return TBSTATE_PRESSED;
  209. break;
  210. default:
  211. ASSERT(FALSE); // Invalid option
  212. return 0;
  213. }
  214. }
  215. //+-------------------------------------------------------------------
  216. //
  217. // Member: GetButtonState
  218. //
  219. // Synopsis: Is the given state of a button set or not.
  220. //
  221. // Arguments:
  222. // [idCommand] - Command id of the button.
  223. // [nState] - State needed.
  224. // [pbState] - Is the above state set or reset.
  225. //
  226. // Returns: HRESULT
  227. //
  228. //--------------------------------------------------------------------
  229. STDMETHODIMP CToolbar::GetButtonState(int idCommand, MMC_BUTTON_STATE nState,
  230. BOOL* pbState)
  231. {
  232. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IToolbar::GetButtonState"));
  233. if (pbState == NULL)
  234. {
  235. sc = E_INVALIDARG;
  236. TraceSnapinError(_T("NULL pointer"), sc);
  237. return sc.ToHr();
  238. }
  239. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  240. if (sc)
  241. return sc.ToHr();
  242. sc = m_pToolbarIntf->ScGetButtonState(this, idCommand,
  243. GetTBStateFromMMCButtonState(nState),
  244. pbState);
  245. if (sc)
  246. return sc.ToHr();
  247. return sc.ToHr();
  248. }
  249. //+-------------------------------------------------------------------
  250. //
  251. // Member: SetButtonState
  252. //
  253. // Synopsis: Modify the given state of a button.
  254. //
  255. // Arguments:
  256. // [idCommand] - Command id of the button.
  257. // [nState] - State to be modified.
  258. // [bState] - Set or Reset the state.
  259. //
  260. // Returns: HRESULT
  261. //
  262. //--------------------------------------------------------------------
  263. STDMETHODIMP CToolbar::SetButtonState(int idCommand, MMC_BUTTON_STATE nState,
  264. BOOL bState)
  265. {
  266. DECLARE_SC_FOR_PUBLIC_INTERFACE(sc, _T("IToolbar::SetButtonState"));
  267. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  268. if (sc)
  269. return sc.ToHr();
  270. sc = m_pToolbarIntf->ScSetButtonState(this, idCommand,
  271. GetTBStateFromMMCButtonState(nState),
  272. bState);
  273. if (sc)
  274. return sc.ToHr();
  275. return (sc.ToHr());
  276. }
  277. //+-------------------------------------------------------------------
  278. //
  279. // Member: ScAttach
  280. //
  281. // Synopsis: Attach this toolbar to UI.
  282. //
  283. // Arguments: None.
  284. //
  285. // Returns: SC
  286. //
  287. //--------------------------------------------------------------------
  288. SC CToolbar::ScAttach()
  289. {
  290. DECLARE_SC(sc, _T("CToolbar::ScAttach"));
  291. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  292. if (sc)
  293. return sc.ToHr();
  294. sc = m_pToolbarIntf->ScAttach(this);
  295. if (sc)
  296. return sc.ToHr();
  297. return (sc);
  298. }
  299. //+-------------------------------------------------------------------
  300. //
  301. // Member: ScDetach
  302. //
  303. // Synopsis: Detach this toolbar from the UI.
  304. //
  305. // Arguments: None.
  306. //
  307. // Returns: SC
  308. //
  309. //--------------------------------------------------------------------
  310. SC CToolbar::ScDetach()
  311. {
  312. DECLARE_SC(sc, _T("CToolbar::ScDetach"));
  313. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  314. if (sc)
  315. return sc.ToHr();
  316. sc = m_pToolbarIntf->ScDetach(this);
  317. if (sc)
  318. return sc.ToHr();
  319. return (sc);
  320. }
  321. //+-------------------------------------------------------------------
  322. //
  323. // Member: ScShow
  324. //
  325. // Synopsis: Show/Hide this toolbar.
  326. //
  327. // Arguments:
  328. // [bShow] - Show or Hide.
  329. //
  330. // Returns: SC
  331. //
  332. //--------------------------------------------------------------------
  333. SC CToolbar::ScShow(BOOL bShow)
  334. {
  335. DECLARE_SC(sc, _T("CToolbar::ScShow"));
  336. sc = ScCheckPointers(m_pToolbarIntf, E_UNEXPECTED);
  337. if (sc)
  338. return sc.ToHr();
  339. sc = (bShow ? m_pToolbarIntf->ScAttach(this) : m_pToolbarIntf->ScDetach(this));
  340. if (sc)
  341. return sc.ToHr();
  342. return (sc);
  343. }
  344. //+-------------------------------------------------------------------
  345. //
  346. // Member: ScNotifyToolBarClick
  347. //
  348. // Synopsis: Notify the snapin about a tool button is click.
  349. //
  350. // Arguments: [pNode] - CNode* that owns result pane.
  351. // [bScope] - Scope or Result.
  352. // [lResultItemCookie] - If Result pane is selected the item param.
  353. // [nID] - Command ID of the tool button clicked.
  354. //
  355. // Returns: SC
  356. //
  357. //--------------------------------------------------------------------
  358. SC CToolbar::ScNotifyToolBarClick(HNODE hNode, bool bScope,
  359. LPARAM lResultItemCookie, UINT nID)
  360. {
  361. DECLARE_SC(sc, _T("CToolbar::ScNotifyToolbarClick"));
  362. if (NULL == m_pControlbar)
  363. return (sc = E_UNEXPECTED);
  364. sc = m_pControlbar->ScNotifySnapinOfToolBtnClick(hNode, bScope, lResultItemCookie, nID);
  365. if (sc)
  366. return sc;
  367. return(sc);
  368. }
  369. //+-------------------------------------------------------------------
  370. //
  371. // Member: CToolbar::ScAMCViewToolbarsBeingDestroyed
  372. //
  373. // Synopsis: The CAMCViewToolbars object is going away, do not
  374. // reference that object anymore.
  375. //
  376. // Arguments:
  377. //
  378. // Returns: SC
  379. //
  380. //--------------------------------------------------------------------
  381. SC CToolbar::ScAMCViewToolbarsBeingDestroyed ()
  382. {
  383. DECLARE_SC(sc, _T("CToolbar::ScAMCViewToolbarsBeingDestroyed"));
  384. m_pToolbarIntf = NULL;
  385. return (sc);
  386. }