toolbar.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: ribbon/toolbar.h
  3. // Purpose: interface of wxRibbonToolBar
  4. // Author: Peter Cawley
  5. // Licence: wxWindows licence
  6. ///////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxRibbonToolBar
  9. A ribbon tool bar is similar to a traditional toolbar which has no labels.
  10. It contains one or more tool groups, each of which contains one or more
  11. tools. Each tool is represented by a (generally small, i.e. 16x15) bitmap.
  12. @beginEventEmissionTable{wxRibbonToolBarEvent}
  13. @event{EVT_RIBBONTOOLBAR_CLICKED(id, func)}
  14. Triggered when the normal (non-dropdown) region of a tool on the tool
  15. bar is clicked.
  16. @event{EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(id, func)}
  17. Triggered when the dropdown region of a tool on the tool bar is
  18. clicked. wxRibbonToolBarEvent::PopupMenu() should be called by the
  19. event handler if it wants to display a popup menu (which is what most
  20. dropdown tools should be doing).
  21. @endEventTable
  22. @library{wxribbon}
  23. @category{ribbon}
  24. */
  25. class wxRibbonToolBar : public wxRibbonControl
  26. {
  27. public:
  28. /**
  29. Default constructor.
  30. With this constructor, Create() should be called in order to create
  31. the tool bar.
  32. */
  33. wxRibbonToolBar();
  34. /**
  35. Construct a ribbon tool bar with the given parameters.
  36. @param parent
  37. Parent window for the tool bar (typically a wxRibbonPanel).
  38. @param id
  39. An identifier for the toolbar. @c wxID_ANY is taken to mean a default.
  40. @param pos
  41. Initial position of the tool bar.
  42. @param size
  43. Initial size of the tool bar.
  44. @param style
  45. Tool bar style, currently unused.
  46. */
  47. wxRibbonToolBar(wxWindow* parent,
  48. wxWindowID id = wxID_ANY,
  49. const wxPoint& pos = wxDefaultPosition,
  50. const wxSize& size = wxDefaultSize,
  51. long style = 0);
  52. /**
  53. Destructor.
  54. */
  55. virtual ~wxRibbonToolBar();
  56. /**
  57. Create a tool bar in two-step tool bar construction.
  58. Should only be called when the default constructor is used, and
  59. arguments have the same meaning as in the full constructor.
  60. */
  61. bool Create(wxWindow* parent,
  62. wxWindowID id = wxID_ANY,
  63. const wxPoint& pos = wxDefaultPosition,
  64. const wxSize& size = wxDefaultSize,
  65. long style = 0);
  66. /**
  67. Add a tool to the tool bar (simple version).
  68. */
  69. virtual wxRibbonToolBarToolBase* AddTool(
  70. int tool_id,
  71. const wxBitmap& bitmap,
  72. const wxString& help_string,
  73. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
  74. /**
  75. Add a dropdown tool to the tool bar (simple version).
  76. @see AddTool()
  77. */
  78. virtual wxRibbonToolBarToolBase* AddDropdownTool(
  79. int tool_id,
  80. const wxBitmap& bitmap,
  81. const wxString& help_string = wxEmptyString);
  82. /**
  83. Add a hybrid tool to the tool bar (simple version).
  84. @see AddTool()
  85. */
  86. virtual wxRibbonToolBarToolBase* AddHybridTool(
  87. int tool_id,
  88. const wxBitmap& bitmap,
  89. const wxString& help_string = wxEmptyString);
  90. /**
  91. Add a toggle tool to the tool bar (simple version).
  92. @since 2.9.4
  93. @see AddTool()
  94. */
  95. virtual wxRibbonToolBarToolBase* AddToggleTool(
  96. int tool_id,
  97. const wxBitmap& bitmap,
  98. const wxString& help_string);
  99. /**
  100. Add a tool to the tool bar.
  101. @param tool_id
  102. ID of the new tool (used for event callbacks).
  103. @param bitmap
  104. Bitmap to use as the foreground for the new tool. Does not have
  105. to be the same size as other tool bitmaps, but should be similar
  106. as otherwise it will look visually odd.
  107. @param bitmap_disabled
  108. Bitmap to use when the tool is disabled. If left as wxNullBitmap,
  109. then a bitmap will be automatically generated from @a bitmap.
  110. @param help_string
  111. The UI help string to associate with the new tool.
  112. @param kind
  113. The kind of tool to add.
  114. @param client_data
  115. Client data to associate with the new tool.
  116. @return An opaque pointer which can be used only with other tool bar
  117. methods.
  118. @see AddDropdownTool(), AddHybridTool(), AddSeparator(), InsertTool()
  119. */
  120. virtual wxRibbonToolBarToolBase* AddTool(
  121. int tool_id,
  122. const wxBitmap& bitmap,
  123. const wxBitmap& bitmap_disabled = wxNullBitmap,
  124. const wxString& help_string = wxEmptyString,
  125. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
  126. wxObject* client_data = NULL);
  127. /**
  128. Add a separator to the tool bar.
  129. Separators are used to separate tools into groups. As such, a separator
  130. is not explicitly drawn, but is visually seen as the gap between tool
  131. groups.
  132. */
  133. virtual wxRibbonToolBarToolBase* AddSeparator();
  134. /**
  135. Insert a tool to the tool bar (simple version) as the specified
  136. position.
  137. @since 2.9.4
  138. @see InsertTool()
  139. */
  140. virtual wxRibbonToolBarToolBase* InsertTool(
  141. size_t pos,
  142. int tool_id,
  143. const wxBitmap& bitmap,
  144. const wxString& help_string,
  145. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
  146. /**
  147. Insert a dropdown tool to the tool bar (simple version) as the specified
  148. position.
  149. @since 2.9.4
  150. @see AddDropdownTool(), InsertTool()
  151. */
  152. virtual wxRibbonToolBarToolBase* InsertDropdownTool(
  153. size_t pos,
  154. int tool_id,
  155. const wxBitmap& bitmap,
  156. const wxString& help_string = wxEmptyString);
  157. /**
  158. Insert a hybrid tool to the tool bar (simple version) as the specified
  159. position.
  160. @since 2.9.4
  161. @see AddHybridTool(), InsertTool()
  162. */
  163. virtual wxRibbonToolBarToolBase* InsertHybridTool(
  164. size_t pos,
  165. int tool_id,
  166. const wxBitmap& bitmap,
  167. const wxString& help_string = wxEmptyString);
  168. /**
  169. Insert a toggle tool to the tool bar (simple version) as the specified
  170. position.
  171. @since 2.9.4
  172. @see AddToggleTool(), InsertTool()
  173. */
  174. virtual wxRibbonToolBarToolBase* InsertToggleTool(
  175. size_t pos,
  176. int tool_id,
  177. const wxBitmap& bitmap,
  178. const wxString& help_string = wxEmptyString);
  179. /**
  180. Insert a tool to the tool bar at the specified position.
  181. @param pos
  182. Position of the new tool (number of tools and separators from the
  183. beginning of the toolbar).
  184. @param tool_id
  185. ID of the new tool (used for event callbacks).
  186. @param bitmap
  187. Bitmap to use as the foreground for the new tool. Does not have
  188. to be the same size as other tool bitmaps, but should be similar
  189. as otherwise it will look visually odd.
  190. @param bitmap_disabled
  191. Bitmap to use when the tool is disabled. If left as wxNullBitmap,
  192. then a bitmap will be automatically generated from @a bitmap.
  193. @param help_string
  194. The UI help string to associate with the new tool.
  195. @param kind
  196. The kind of tool to add.
  197. @param client_data
  198. Client data to associate with the new tool.
  199. @return An opaque pointer which can be used only with other tool bar
  200. methods.
  201. @since 2.9.4
  202. @see InsertDropdownTool(), InsertHybridTool(), InsertSeparator()
  203. */
  204. virtual wxRibbonToolBarToolBase* InsertTool(
  205. size_t pos,
  206. int tool_id,
  207. const wxBitmap& bitmap,
  208. const wxBitmap& bitmap_disabled = wxNullBitmap,
  209. const wxString& help_string = wxEmptyString,
  210. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
  211. wxObject* client_data = NULL);
  212. /**
  213. Insert a separator to the tool bar at the specified position.
  214. @since 2.9.4
  215. @see AddSeparator(), InsertTool()
  216. */
  217. virtual wxRibbonToolBarToolBase* InsertSeparator(size_t pos);
  218. /**
  219. Deletes all the tools in the toolbar.
  220. @since 2.9.4
  221. */
  222. virtual void ClearTools();
  223. /**
  224. Removes the specified tool from the toolbar and deletes it.
  225. @param tool_id
  226. ID of the tool to delete.
  227. @returns @true if the tool was deleted, @false otherwise.
  228. @since 2.9.4
  229. @see DeleteToolByPos()
  230. */
  231. virtual bool DeleteTool(int tool_id);
  232. /**
  233. This function behaves like DeleteTool() but it deletes the tool at the
  234. specified position and not the one with the given id.
  235. Useful to delete separators.
  236. @since 2.9.4
  237. */
  238. virtual bool DeleteToolByPos(size_t pos);
  239. /**
  240. Returns a pointer to the tool opaque structure by @a id or @NULL if no
  241. corresponding tool is found.
  242. @since 2.9.4
  243. */
  244. virtual wxRibbonToolBarToolBase* FindById(int tool_id)const;
  245. /**
  246. Return the opaque pointer corresponding to the given tool.
  247. @return an opaque pointer, NULL if is a separator or not found.
  248. @since 2.9.4
  249. */
  250. wxRibbonToolBarToolBase* GetToolByPos(size_t pos)const
  251. /**
  252. Returns the number of tools in the toolbar.
  253. @since 2.9.4
  254. */
  255. virtual size_t GetToolCount() const;
  256. /**
  257. Return the id assciated to the tool opaque structure.
  258. The structure pointer must not be @NULL.
  259. @since 2.9.4
  260. */
  261. virtual int GetToolId(const wxRibbonToolBarToolBase* tool)const;
  262. /**
  263. Get any client data associated with the tool.
  264. @param tool_id
  265. ID of the tool in question, as passed to AddTool().
  266. @return Client data, or @NULL if there is none.
  267. @since 2.9.4
  268. */
  269. virtual wxObject* GetToolClientData(int tool_id)const;
  270. /**
  271. Called to determine whether a tool is enabled (responds to user input).
  272. @param tool_id
  273. ID of the tool in question, as passed to AddTool().
  274. @return @true if the tool is enabled, @false otherwise.
  275. @since 2.9.4
  276. @see EnableTool()
  277. */
  278. virtual bool GetToolEnabled(int tool_id)const;
  279. /**
  280. Returns the help string for the given tool.
  281. @param tool_id
  282. ID of the tool in question, as passed to AddTool().
  283. @since 2.9.4
  284. */
  285. virtual wxString GetToolHelpString(int tool_id)const;
  286. /**
  287. Return the kind of the given tool.
  288. @param tool_id
  289. ID of the tool in question, as passed to AddTool().
  290. @since 2.9.4
  291. */
  292. virtual wxRibbonButtonKind GetToolKind(int tool_id)const;
  293. /**
  294. Returns the tool position in the toolbar, or @c wxNOT_FOUND if the tool
  295. is not found.
  296. @param tool_id
  297. ID of the tool in question, as passed to AddTool().
  298. @since 2.9.4
  299. */
  300. virtual int GetToolPos(int tool_id)const;
  301. /**
  302. Gets the on/off state of a toggle tool.
  303. @param tool_id
  304. ID of the tool in question, as passed to AddTool().
  305. @return @true if the tool is toggled on, @false otherwise.
  306. @see ToggleTool()
  307. @since 2.9.4
  308. */
  309. virtual bool GetToolState(int tool_id)const;
  310. /**
  311. Calculate tool layouts and positions.
  312. Must be called after tools are added to the tool bar, as otherwise
  313. the newly added tools will not be displayed.
  314. */
  315. virtual bool Realize();
  316. /**
  317. Set the number of rows to distribute tool groups over.
  318. Tool groups can be distributed over a variable number of rows. The way
  319. in which groups are assigned to rows is not specified, and the order
  320. of groups may change, but they will be distributed in such a way as to
  321. minimise the overall size of the tool bar.
  322. @param nMin
  323. The minimum number of rows to use.
  324. @param nMax
  325. The maximum number of rows to use (defaults to nMin).
  326. */
  327. virtual void SetRows(int nMin, int nMax = -1);
  328. /**
  329. Sets the client data associated with the tool.
  330. @param tool_id
  331. ID of the tool in question, as passed to AddTool().
  332. @param clientData
  333. The client data to use.
  334. @since 2.9.4
  335. */
  336. virtual void SetToolClientData(int tool_id, wxObject* clientData);
  337. /**
  338. Sets the bitmap to be used by the tool with the given ID when the tool
  339. is in a disabled state.
  340. @param tool_id
  341. ID of the tool in question, as passed to AddTool().
  342. @param bitmap
  343. Bitmap to use for disabled tools.
  344. @since 2.9.4
  345. */
  346. virtual void SetToolDisabledBitmap(int tool_id, const wxBitmap &bitmap);
  347. /**
  348. Sets the help string shown in tooltip for the given tool.
  349. @param tool_id
  350. ID of the tool in question, as passed to AddTool().
  351. @param helpString
  352. A string for the help.
  353. @see GetToolHelpString()
  354. @since 2.9.4
  355. */
  356. virtual void SetToolHelpString(int tool_id, const wxString& helpString);
  357. /**
  358. Sets the bitmap to be used by the tool with the given ID.
  359. @param tool_id
  360. ID of the tool in question, as passed to AddTool().
  361. @param bitmap
  362. Bitmap to use for normals tools.
  363. @since 2.9.4
  364. */
  365. virtual void SetToolNormalBitmap(int tool_id, const wxBitmap &bitmap);
  366. /**
  367. Enable or disable a single tool on the bar.
  368. @param tool_id
  369. ID of the tool to enable or disable.
  370. @param enable
  371. @true to enable the tool, @false to disable it.
  372. @since 2.9.4
  373. */
  374. virtual void EnableTool(int tool_id, bool enable = true);
  375. /**
  376. Set a toggle tool to the checked or unchecked state.
  377. @param tool_id
  378. ID of the toggle tool to manipulate.
  379. @param checked
  380. @true to set the tool to the toggled/pressed/checked state,
  381. @false to set it to the untoggled/unpressed/unchecked state.
  382. @since 2.9.4
  383. */
  384. virtual void ToggleTool(int tool_id, bool checked);
  385. };