Source code of Windows XP (NT5)
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.

317 lines
10 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. Toolbar.cpp
  5. Abstract:
  6. This module contains the support code for toolbar
  7. --*/
  8. #include "precomp.hxx"
  9. #pragma hdrstop
  10. // Handle to main toolbar window
  11. HWND g_Toolbar;
  12. // See docs for TBBUTTON
  13. TBBUTTON g_TbButtons[] =
  14. {
  15. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  16. { 0, IDM_FILE_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  17. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  18. { 2, IDM_EDIT_CUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  19. { 3, IDM_EDIT_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  20. { 4, IDM_EDIT_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  21. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  22. { 5, IDM_DEBUG_GO, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  23. { 6, IDM_DEBUG_RESTART, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  24. { 7, IDM_DEBUG_STOPDEBUGGING, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  25. { 8, IDM_DEBUG_BREAK, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  26. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  27. { 9, IDM_DEBUG_STEPINTO, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  28. { 10, IDM_DEBUG_STEPOVER, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  29. { 11, IDM_DEBUG_STEPOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  30. { 12, IDM_DEBUG_RUNTOCURSOR, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  31. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  32. { 13, IDM_EDIT_TOGGLEBREAKPOINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  33. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  34. { 15, IDM_VIEW_COMMAND, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  35. { 16, IDM_VIEW_WATCH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  36. { 17, IDM_VIEW_LOCALS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  37. { 18, IDM_VIEW_REGISTERS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  38. { 19, IDM_VIEW_MEMORY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  39. { 20, IDM_VIEW_CALLSTACK, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  40. { 21, IDM_VIEW_DISASM, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  41. { 22, IDM_VIEW_SCRATCH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  42. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  43. { 23, IDM_DEBUG_SOURCE_MODE_ON, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0},
  44. { 24, IDM_DEBUG_SOURCE_MODE_OFF, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0},
  45. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  46. { 25, IDM_EDIT_PROPERTIES, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  47. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  48. { 26, IDM_VIEW_FONT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  49. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  50. { 27, IDM_VIEW_OPTIONS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  51. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  52. { 28, IDM_WINDOW_ARRANGE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  53. };
  54. // Toolbar constants.
  55. #define NUM_BMPS_IN_TOOLBAR ( sizeof(g_TbButtons) / sizeof(g_TbButtons[0]) )
  56. // Used to retrieve the tooltip text
  57. typedef struct
  58. {
  59. UINT uCmdId; // TBBUTTON command
  60. int nStrId; // String resource ID
  61. } TB_STR_MAP;
  62. // Map the command id to resource string identifier.
  63. TB_STR_MAP g_TbStrMap[] =
  64. {
  65. { IDM_FILE_OPEN, TBR_FILE_OPEN },
  66. { IDM_EDIT_CUT, TBR_EDIT_CUT },
  67. { IDM_EDIT_COPY, TBR_EDIT_COPY },
  68. { IDM_EDIT_PASTE, TBR_EDIT_PASTE },
  69. { IDM_DEBUG_GO, TBR_DEBUG_GO },
  70. { IDM_DEBUG_RESTART, TBR_DEBUG_RESTART },
  71. { IDM_DEBUG_STOPDEBUGGING, TBR_DEBUG_STOPDEBUGGING },
  72. { IDM_DEBUG_BREAK, TBR_DEBUG_BREAK },
  73. { IDM_DEBUG_STEPINTO, TBR_DEBUG_STEPINTO },
  74. { IDM_DEBUG_STEPOVER, TBR_DEBUG_STEPOVER },
  75. { IDM_DEBUG_STEPOUT, TBR_DEBUG_STEPOUT },
  76. { IDM_DEBUG_RUNTOCURSOR, TBR_DEBUG_RUNTOCURSOR },
  77. { IDM_EDIT_TOGGLEBREAKPOINT, TBR_EDIT_BREAKPOINTS },
  78. { IDM_VIEW_COMMAND, TBR_VIEW_COMMAND },
  79. { IDM_VIEW_WATCH, TBR_VIEW_WATCH },
  80. { IDM_VIEW_LOCALS, TBR_VIEW_LOCALS },
  81. { IDM_VIEW_REGISTERS, TBR_VIEW_REGISTERS },
  82. { IDM_VIEW_MEMORY, TBR_VIEW_MEMORY },
  83. { IDM_VIEW_CALLSTACK, TBR_VIEW_CALLSTACK },
  84. { IDM_VIEW_DISASM, TBR_VIEW_DISASM },
  85. { IDM_VIEW_SCRATCH, TBR_VIEW_SCRATCH },
  86. { IDM_DEBUG_SOURCE_MODE_ON, TBR_DEBUG_SOURCE_MODE_ON },
  87. { IDM_DEBUG_SOURCE_MODE_OFF, TBR_DEBUG_SOURCE_MODE_OFF },
  88. { IDM_EDIT_PROPERTIES, TBR_EDIT_PROPERTIES },
  89. { IDM_VIEW_FONT, TBR_VIEW_FONT },
  90. { IDM_VIEW_OPTIONS, TBR_VIEW_OPTIONS },
  91. { IDM_WINDOW_ARRANGE, TBR_WINDOW_ARRANGE },
  92. };
  93. #define NUM_TOOLBAR_BUTTONS (sizeof(g_TbButtons) / sizeof(TBBUTTON))
  94. #define NUM_TOOLBAR_STRINGS (sizeof(g_TbStrMap) / sizeof(TB_STR_MAP))
  95. PTSTR
  96. GetToolTipTextFor_Toolbar(UINT uToolbarId)
  97. /*++
  98. Routine Description:
  99. Given the id of the toolbar button, we retrieve the
  100. corresponding tooltip text from the resources.
  101. Arguments:
  102. uToolbarId - The command id for the toolbar button. This is the
  103. value contained in the WM_COMMAND msg.
  104. Returns:
  105. Returns a pointer to a static buffer that contains the tooltip text.
  106. --*/
  107. {
  108. // Display tool tip text.
  109. static TCHAR sz[MAX_MSG_TXT];
  110. int nStrId = 0, i;
  111. // Get the str id given the cmd id
  112. for (i = 0; i < NUM_TOOLBAR_STRINGS; i++)
  113. {
  114. if (g_TbStrMap[i].uCmdId == uToolbarId)
  115. {
  116. nStrId = g_TbStrMap[i].nStrId;
  117. break;
  118. }
  119. }
  120. Assert(nStrId);
  121. // Now that we have the string id ....
  122. Dbg(LoadString(g_hInst, nStrId, sz, _tsizeof(sz) ));
  123. return sz;
  124. }
  125. BOOL
  126. CreateToolbar(HWND hwndParent)
  127. /*++
  128. Routine Description:
  129. Creates the toolbar.
  130. Arguments:
  131. hwndParent - The parent window of the toolbar.
  132. --*/
  133. {
  134. g_Toolbar = CreateToolbarEx(hwndParent, // parent
  135. WS_CHILD | WS_BORDER
  136. | WS_VISIBLE
  137. | TBSTYLE_TOOLTIPS
  138. | TBSTYLE_WRAPABLE
  139. | CCS_TOP, // style
  140. ID_TOOLBAR, // toolbar id
  141. NUM_BMPS_IN_TOOLBAR, // number of bitmaps
  142. g_hInst, // mod instance
  143. IDB_BMP_TOOLBAR, // resource id for the bitmap
  144. g_TbButtons, // address of buttons
  145. NUM_TOOLBAR_BUTTONS, // number of buttons
  146. 16,15, // width & height of the buttons
  147. 16,15, // width & height of the bitmaps
  148. sizeof(TBBUTTON) // structure size
  149. );
  150. return g_Toolbar != NULL;
  151. }
  152. void
  153. Show_Toolbar(BOOL bShow)
  154. /*++
  155. Routine Description:
  156. Shows/hides the toolbar.
  157. Arguments:
  158. bShow - TRUE - Show the toolbar.
  159. FALSE - Hide the toolbar.
  160. Autmatically resizes the MDI Client
  161. --*/
  162. {
  163. RECT rect;
  164. // Show/Hide the toolbar
  165. ShowWindow(g_Toolbar, bShow ? SW_SHOW : SW_HIDE);
  166. //Ask the frame to resize, so that everything will be correctly positioned.
  167. GetWindowRect(g_hwndFrame, &rect);
  168. EnableToolbarControls();
  169. SendMessage(g_hwndFrame,
  170. WM_SIZE,
  171. SIZE_RESTORED,
  172. MAKELPARAM(rect.right - rect.left, rect.bottom - rect.top)
  173. );
  174. // Ask the MDIClient to redraw itself and its children.
  175. // This is done in order to fix a redraw problem where some of the
  176. // MDIChild window are not correctly redrawn.
  177. RedrawWindow(g_hwndMDIClient,
  178. NULL,
  179. NULL,
  180. RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_FRAME
  181. );
  182. } /* UpdateToolbar() */
  183. HWND
  184. GetHwnd_Toolbar()
  185. {
  186. return g_Toolbar;
  187. }
  188. /*** EnableToolbarControls
  189. **
  190. ** Description:
  191. ** Enables/disables the controls in the toolbar according
  192. ** to the current state of the system.
  193. **
  194. */
  195. void
  196. EnableToolbarControls()
  197. {
  198. int i;
  199. for (i = 0; i < NUM_TOOLBAR_BUTTONS; i++)
  200. {
  201. // This will enable disable the toolbar
  202. if (g_TbButtons[i].idCommand)
  203. {
  204. CommandIdEnabled(g_TbButtons[i].idCommand);
  205. }
  206. }
  207. }
  208. void
  209. ToolbarIdEnabled(
  210. IN UINT uMenuID,
  211. IN BOOL fEnabled
  212. )
  213. /*++
  214. Routine Description:
  215. Enables/disables a ToolBar item based.
  216. Arguments:
  217. uMenuID - Supplies a menu id whose state is to be determined.
  218. fEnabled - enable or disable a toolbar item.
  219. Return Value:
  220. None
  221. --*/
  222. {
  223. switch (uMenuID)
  224. {
  225. case IDM_FILE_OPEN:
  226. case IDM_EDIT_CUT:
  227. case IDM_EDIT_COPY:
  228. case IDM_EDIT_PASTE:
  229. case IDM_DEBUG_GO:
  230. case IDM_DEBUG_RESTART:
  231. case IDM_DEBUG_STOPDEBUGGING:
  232. case IDM_DEBUG_BREAK:
  233. case IDM_DEBUG_STEPINTO:
  234. case IDM_DEBUG_STEPOVER:
  235. case IDM_DEBUG_STEPOUT:
  236. case IDM_DEBUG_RUNTOCURSOR:
  237. case IDM_EDIT_TOGGLEBREAKPOINT:
  238. case IDM_VIEW_COMMAND:
  239. case IDM_VIEW_WATCH:
  240. case IDM_VIEW_LOCALS:
  241. case IDM_VIEW_REGISTERS:
  242. case IDM_VIEW_MEMORY:
  243. case IDM_VIEW_CALLSTACK:
  244. case IDM_VIEW_DISASM:
  245. case IDM_EDIT_PROPERTIES:
  246. // Nothing special to do here, except change the state
  247. SendMessage(GetHwnd_Toolbar(),
  248. TB_ENABLEBUTTON,
  249. uMenuID,
  250. MAKELONG(fEnabled, 0));
  251. break;
  252. case IDM_DEBUG_SOURCE_MODE_ON:
  253. case IDM_DEBUG_SOURCE_MODE_OFF:
  254. // Toggle the state between the two items
  255. SendMessage(GetHwnd_Toolbar(),
  256. TB_CHECKBUTTON,
  257. IDM_DEBUG_SOURCE_MODE_ON,
  258. MAKELONG(GetSrcMode_StatusBar(), 0));
  259. SendMessage(GetHwnd_Toolbar(),
  260. TB_CHECKBUTTON,
  261. IDM_DEBUG_SOURCE_MODE_OFF,
  262. MAKELONG(!GetSrcMode_StatusBar(), 0));
  263. break;
  264. }
  265. }