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.

321 lines
11 KiB

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