toolbar.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: toolbar.h
  3. // Purpose: interface of wxToolBar
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. enum wxToolBarToolStyle
  8. {
  9. wxTOOL_STYLE_BUTTON = 1,
  10. wxTOOL_STYLE_SEPARATOR = 2,
  11. wxTOOL_STYLE_CONTROL
  12. };
  13. /** wxToolBar style flags */
  14. enum
  15. {
  16. /** lay out the toolbar horizontally */
  17. wxTB_HORIZONTAL = wxHORIZONTAL,
  18. wxTB_TOP = wxTB_HORIZONTAL,
  19. /** lay out the toolbar vertically */
  20. wxTB_VERTICAL = wxVERTICAL,
  21. wxTB_LEFT = wxTB_VERTICAL,
  22. /** show 3D buttons (wxToolBarSimple only) */
  23. wxTB_3DBUTTONS,
  24. /** "flat" buttons (Win32/GTK only) */
  25. wxTB_FLAT,
  26. /** dockable toolbar (GTK only) */
  27. wxTB_DOCKABLE,
  28. /** don't show the icons (they're shown by default) */
  29. wxTB_NOICONS,
  30. /** show the text (not shown by default) */
  31. wxTB_TEXT,
  32. /** don't show the divider between toolbar and the window (Win32 only) */
  33. wxTB_NODIVIDER,
  34. /** no automatic alignment (Win32 only, useless) */
  35. wxTB_NOALIGN,
  36. /** show the text and the icons alongside, not vertically stacked (Win32/GTK) */
  37. wxTB_HORZ_LAYOUT,
  38. wxTB_HORZ_TEXT = wxTB_HORZ_LAYOUT | wxTB_TEXT,
  39. /** don't show the toolbar short help tooltips */
  40. wxTB_NO_TOOLTIPS,
  41. /** lay out toolbar at the bottom of the window */
  42. wxTB_BOTTOM,
  43. /** lay out toolbar at the right edge of the window */
  44. wxTB_RIGHT,
  45. /** flags that are closest to the native look*/
  46. wxTB_DEFAULT_STYLE = wxTB_HORIZONTAL | wxTB_FLAT
  47. };
  48. /**
  49. @class wxToolBarToolBase
  50. A toolbar tool represents one item on the toolbar.
  51. It has a unique id (except for the separators), the style (telling whether
  52. it is a normal button, separator or a control), the state (toggled or not,
  53. enabled or not) and short and long help strings. The default
  54. implementations use the short help string for the tooltip text which is
  55. popped up when the mouse pointer enters the tool and the long help string
  56. for the applications status bar.
  57. */
  58. class wxToolBarToolBase : public wxObject
  59. {
  60. public:
  61. wxToolBarToolBase(wxToolBarBase *tbar = NULL,
  62. int toolid = wxID_SEPARATOR,
  63. const wxString& label = wxEmptyString,
  64. const wxBitmap& bmpNormal = wxNullBitmap,
  65. const wxBitmap& bmpDisabled = wxNullBitmap,
  66. wxItemKind kind = wxITEM_NORMAL,
  67. wxObject *clientData = NULL,
  68. const wxString& shortHelpString = wxEmptyString,
  69. const wxString& longHelpString = wxEmptyString);
  70. wxToolBarToolBase(wxToolBarBase *tbar,
  71. wxControl *control,
  72. const wxString& label);
  73. virtual ~wxToolBarToolBase();
  74. int GetId() const;
  75. wxControl *GetControl() const;
  76. wxToolBarBase *GetToolBar() const;
  77. bool IsStretchable() const;
  78. bool IsButton() const;
  79. bool IsControl() const;
  80. bool IsSeparator() const;
  81. bool IsStretchableSpace() const;
  82. int GetStyle() const;
  83. wxItemKind GetKind() const;
  84. void MakeStretchable();
  85. bool IsEnabled() const;
  86. bool IsToggled() const;
  87. bool CanBeToggled() const;
  88. const wxBitmap& GetNormalBitmap() const;
  89. const wxBitmap& GetDisabledBitmap() const;
  90. const wxBitmap& GetBitmap() const;
  91. const wxString& GetLabel() const;
  92. const wxString& GetShortHelp() const;
  93. const wxString& GetLongHelp() const;
  94. wxObject *GetClientData() const;
  95. virtual bool Enable(bool enable);
  96. virtual bool Toggle(bool toggle);
  97. virtual bool SetToggle(bool toggle);
  98. virtual bool SetShortHelp(const wxString& help);
  99. virtual bool SetLongHelp(const wxString& help);
  100. void Toggle();
  101. virtual void SetNormalBitmap(const wxBitmap& bmp);
  102. virtual void SetDisabledBitmap(const wxBitmap& bmp);
  103. virtual void SetLabel(const wxString& label);
  104. void SetClientData(wxObject *clientData);
  105. virtual void Detach();
  106. virtual void Attach(wxToolBarBase *tbar);
  107. virtual void SetDropdownMenu(wxMenu *menu);
  108. wxMenu *GetDropdownMenu() const;
  109. };
  110. /**
  111. @class wxToolBar
  112. A toolbar is a bar of buttons and/or other controls usually placed below
  113. the menu bar in a wxFrame.
  114. You may create a toolbar that is managed by a frame calling
  115. wxFrame::CreateToolBar(). Under Pocket PC, you should always use this
  116. function for creating the toolbar to be managed by the frame, so that
  117. wxWidgets can use a combined menubar and toolbar. Where you manage your
  118. own toolbars, create wxToolBar as usual.
  119. There are several different types of tools you can add to a toolbar.
  120. These types are controlled by the ::wxItemKind enumeration.
  121. Note that many methods in wxToolBar such as wxToolBar::AddTool return a
  122. @c wxToolBarToolBase* object.
  123. This should be regarded as an opaque handle representing the newly added
  124. toolbar item, providing access to its id and position within the toolbar.
  125. Changes to the item's state should be made through calls to wxToolBar methods,
  126. for example wxToolBar::EnableTool.
  127. Calls to @c wxToolBarToolBase methods (undocumented by purpose) will not change
  128. the visible state of the item within the tool bar.
  129. <b>wxMSW note</b>: Note that under wxMSW toolbar paints tools to reflect
  130. system-wide colours. If you use more than 16 colours in your tool bitmaps,
  131. you may wish to suppress this behaviour, otherwise system colours in your
  132. bitmaps will inadvertently be mapped to system colours.
  133. To do this, set the msw.remap system option before creating the toolbar:
  134. @code
  135. wxSystemOptions::SetOption("msw.remap", 0);
  136. @endcode
  137. If you wish to use 32-bit images (which include an alpha channel for
  138. transparency) use:
  139. @code
  140. wxSystemOptions::SetOption("msw.remap", 2);
  141. @endcode
  142. Then colour remapping is switched off, and a transparent background
  143. used. But only use this option under Windows XP with true colour:
  144. @code
  145. if (wxTheApp->GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32)
  146. @endcode
  147. @beginStyleTable
  148. @style{wxTB_FLAT}
  149. Gives the toolbar a flat look (Windows and GTK only).
  150. @style{wxTB_DOCKABLE}
  151. Makes the toolbar floatable and dockable (GTK only).
  152. @style{wxTB_HORIZONTAL}
  153. Specifies horizontal layout (default).
  154. @style{wxTB_VERTICAL}
  155. Specifies vertical layout.
  156. @style{wxTB_TEXT}
  157. Shows the text in the toolbar buttons; by default only icons are shown.
  158. @style{wxTB_NOICONS}
  159. Specifies no icons in the toolbar buttons; by default they are shown.
  160. @style{wxTB_NODIVIDER}
  161. Specifies no divider (border) above the toolbar (Windows only)
  162. @style{wxTB_NOALIGN}
  163. Specifies no alignment with the parent window (Windows only, not very
  164. useful).
  165. @style{wxTB_HORZ_LAYOUT}
  166. Shows the text and the icons alongside, not vertically stacked (Windows
  167. and GTK 2 only). This style must be used with @c wxTB_TEXT.
  168. @style{wxTB_HORZ_TEXT}
  169. Combination of @c wxTB_HORZ_LAYOUT and @c wxTB_TEXT.
  170. @style{wxTB_NO_TOOLTIPS}
  171. Don't show the short help tooltips for the tools when the mouse hovers
  172. over them.
  173. @style{wxTB_BOTTOM}
  174. Align the toolbar at the bottom of parent window.
  175. @style{wxTB_RIGHT}
  176. Align the toolbar at the right side of parent window.
  177. @style{wxTB_DEFAULT_STYLE}
  178. Combination of @c wxTB_HORIZONTAL and @c wxTB_FLAT. This style is new
  179. since wxWidgets 2.9.5.
  180. @endStyleTable
  181. See also @ref overview_windowstyles. Note that the wxMSW native toolbar
  182. ignores @c wxTB_NOICONS style. Also, toggling the @c wxTB_TEXT works only
  183. if the style was initially on.
  184. @beginEventEmissionTable{wxCommandEvent}
  185. @event{EVT_TOOL(id, func)}
  186. Process a @c wxEVT_TOOL event (a synonym for @c
  187. wxEVT_MENU). Pass the id of the tool.
  188. @event{EVT_MENU(id, func)}
  189. The same as EVT_TOOL().
  190. @event{EVT_TOOL_RANGE(id1, id2, func)}
  191. Process a @c wxEVT_TOOL event for a range of
  192. identifiers. Pass the ids of the tools.
  193. @event{EVT_MENU_RANGE(id1, id2, func)}
  194. The same as EVT_TOOL_RANGE().
  195. @event{EVT_TOOL_RCLICKED(id, func)}
  196. Process a @c wxEVT_TOOL_RCLICKED event. Pass the id of the
  197. tool. (Not available on wxOSX.)
  198. @event{EVT_TOOL_RCLICKED_RANGE(id1, id2, func)}
  199. Process a @c wxEVT_TOOL_RCLICKED event for a range of ids. Pass
  200. the ids of the tools. (Not available on wxOSX.)
  201. @event{EVT_TOOL_ENTER(id, func)}
  202. Process a @c wxEVT_TOOL_ENTER event. Pass the id of the toolbar
  203. itself. The value of wxCommandEvent::GetSelection() is the tool id, or
  204. -1 if the mouse cursor has moved off a tool. (Not available on wxOSX.)
  205. @event{EVT_TOOL_DROPDOWN(id, func)}
  206. Process a @c wxEVT_TOOL_DROPDOWN event. If unhandled,
  207. displays the default dropdown menu set using
  208. wxToolBar::SetDropdownMenu().
  209. @endEventTable
  210. The toolbar class emits menu commands in the same way that a frame menubar
  211. does, so you can use one EVT_MENU() macro for both a menu item and a toolbar
  212. button. The event handler functions take a wxCommandEvent argument. For most
  213. event macros, the identifier of the tool is passed, but for EVT_TOOL_ENTER()
  214. the toolbar window identifier is passed and the tool identifier is retrieved
  215. from the wxCommandEvent. This is because the identifier may be @c wxID_ANY when the
  216. mouse moves off a tool, and @c wxID_ANY is not allowed as an identifier in the event
  217. system.
  218. @library{wxcore}
  219. @category{miscwnd}
  220. @see @ref overview_toolbar
  221. */
  222. class wxToolBar : public wxControl
  223. {
  224. public:
  225. /**
  226. Default constructor.
  227. */
  228. wxToolBar();
  229. /**
  230. Constructs a toolbar.
  231. @param parent
  232. Pointer to a parent window.
  233. @param id
  234. Window identifier. If -1, will automatically create an identifier.
  235. @param pos
  236. Window position. ::wxDefaultPosition indicates that wxWidgets should
  237. generate a default position for the window.
  238. If using the wxWindow class directly, supply an actual position.
  239. @param size
  240. Window size. ::wxDefaultSize indicates that wxWidgets should generate
  241. a default size for the window.
  242. @param style
  243. Window style. See wxToolBar initial description for details.
  244. @param name
  245. Window name.
  246. @remarks After a toolbar is created, you use AddTool() and perhaps
  247. AddSeparator(), and then you must call Realize() to construct
  248. and display the toolbar tools.
  249. */
  250. wxToolBar(wxWindow* parent, wxWindowID id,
  251. const wxPoint& pos = wxDefaultPosition,
  252. const wxSize& size = wxDefaultSize,
  253. long style = wxTB_HORIZONTAL,
  254. const wxString& name = wxToolBarNameStr);
  255. /**
  256. Toolbar destructor.
  257. */
  258. virtual ~wxToolBar();
  259. /**
  260. Adds a new check (or toggle) tool to the toolbar. The parameters are the
  261. same as in AddTool().
  262. @see AddTool()
  263. */
  264. wxToolBarToolBase* AddCheckTool(int toolId, const wxString& label,
  265. const wxBitmap& bitmap1,
  266. const wxBitmap& bmpDisabled = wxNullBitmap,
  267. const wxString& shortHelp = wxEmptyString,
  268. const wxString& longHelp = wxEmptyString,
  269. wxObject* clientData = NULL);
  270. /**
  271. Adds any control to the toolbar, typically e.g.\ a wxComboBox.
  272. @param control
  273. The control to be added.
  274. @param label
  275. Text to be displayed near the control.
  276. @remarks
  277. wxMSW: the label is only displayed if there is enough space
  278. available below the embedded control.
  279. @remarks
  280. wxMac: labels are only displayed if wxWidgets is built with @c
  281. wxMAC_USE_NATIVE_TOOLBAR set to 1
  282. */
  283. virtual wxToolBarToolBase* AddControl(wxControl* control,
  284. const wxString& label = wxEmptyString);
  285. /**
  286. Adds a new radio tool to the toolbar. Consecutive radio tools form a
  287. radio group such that exactly one button in the group is pressed at any
  288. moment, in other words whenever a button in the group is pressed the
  289. previously pressed button is automatically released. You should avoid
  290. having the radio groups of only one element as it would be impossible
  291. for the user to use such button.
  292. By default, the first button in the radio group is initially pressed,
  293. the others are not.
  294. @see AddTool()
  295. */
  296. wxToolBarToolBase* AddRadioTool(int toolId, const wxString& label,
  297. const wxBitmap& bitmap1,
  298. const wxBitmap& bmpDisabled = wxNullBitmap,
  299. const wxString& shortHelp = wxEmptyString,
  300. const wxString& longHelp = wxEmptyString,
  301. wxObject* clientData = NULL);
  302. /**
  303. Adds a separator for spacing groups of tools.
  304. Notice that the separator uses the look appropriate for the current
  305. platform so it can be a vertical line (MSW, some versions of GTK) or
  306. just an empty space or something else.
  307. @see AddTool(), SetToolSeparation(), AddStretchableSpace()
  308. */
  309. virtual wxToolBarToolBase* AddSeparator();
  310. /**
  311. Adds a stretchable space to the toolbar.
  312. Any space not taken up by the fixed items (all items except for
  313. stretchable spaces) is distributed in equal measure between the
  314. stretchable spaces in the toolbar. The most common use for this method
  315. is to add a single stretchable space before the items which should be
  316. right-aligned in the toolbar, but more exotic possibilities are
  317. possible, e.g. a stretchable space may be added in the beginning and
  318. the end of the toolbar to centre all toolbar items.
  319. @see AddTool(), AddSeparator(), InsertStretchableSpace()
  320. @since 2.9.1
  321. */
  322. wxToolBarToolBase *AddStretchableSpace();
  323. //@{
  324. /**
  325. Adds a tool to the toolbar.
  326. @param tool
  327. The tool to be added.
  328. @remarks After you have added tools to a toolbar, you must call
  329. Realize() in order to have the tools appear.
  330. @see AddSeparator(), AddCheckTool(), AddRadioTool(),
  331. InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
  332. */
  333. virtual wxToolBarToolBase* AddTool(wxToolBarToolBase* tool);
  334. /**
  335. Adds a tool to the toolbar. This most commonly used version has fewer
  336. parameters than the full version below which specifies the more rarely
  337. used button features.
  338. @param toolId
  339. An integer by which the tool may be identified in subsequent
  340. operations.
  341. @param label
  342. The string to be displayed with the tool.
  343. @param bitmap
  344. The primary tool bitmap.
  345. @param shortHelp
  346. This string is used for the tools tooltip.
  347. @param kind
  348. May be ::wxITEM_NORMAL for a normal button (default), ::wxITEM_CHECK
  349. for a checkable tool (such tool stays pressed after it had been
  350. toggled) or ::wxITEM_RADIO for a checkable tool which makes part of
  351. a radio group of tools each of which is automatically unchecked
  352. whenever another button in the group is checked. ::wxITEM_DROPDOWN
  353. specifies that a drop-down menu button will appear next to the
  354. tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
  355. @remarks After you have added tools to a toolbar, you must call
  356. Realize() in order to have the tools appear.
  357. @see AddSeparator(), AddCheckTool(), AddRadioTool(),
  358. InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
  359. */
  360. wxToolBarToolBase* AddTool(int toolId, const wxString& label,
  361. const wxBitmap& bitmap,
  362. const wxString& shortHelp = wxEmptyString,
  363. wxItemKind kind = wxITEM_NORMAL);
  364. /**
  365. Adds a tool to the toolbar.
  366. @param toolId
  367. An integer by which the tool may be identified in subsequent
  368. operations.
  369. @param label
  370. The string to be displayed with the tool.
  371. @param bitmap
  372. The primary tool bitmap.
  373. @param bmpDisabled
  374. The bitmap used when the tool is disabled. If it is equal to
  375. ::wxNullBitmap (default), the disabled bitmap is automatically
  376. generated by greying the normal one.
  377. @param kind
  378. May be ::wxITEM_NORMAL for a normal button (default), ::wxITEM_CHECK
  379. for a checkable tool (such tool stays pressed after it had been
  380. toggled) or ::wxITEM_RADIO for a checkable tool which makes part of
  381. a radio group of tools each of which is automatically unchecked
  382. whenever another button in the group is checked. ::wxITEM_DROPDOWN
  383. specifies that a drop-down menu button will appear next to the
  384. tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
  385. @param shortHelpString
  386. This string is used for the tools tooltip.
  387. @param longHelpString
  388. This string is shown in the statusbar (if any) of the parent frame
  389. when the mouse pointer is inside the tool.
  390. @param clientData
  391. An optional pointer to client data which can be retrieved later
  392. using GetToolClientData().
  393. @remarks After you have added tools to a toolbar, you must call
  394. Realize() in order to have the tools appear.
  395. @see AddSeparator(), AddCheckTool(), AddRadioTool(),
  396. InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
  397. */
  398. wxToolBarToolBase* AddTool(int toolId, const wxString& label,
  399. const wxBitmap& bitmap,
  400. const wxBitmap& bmpDisabled,
  401. wxItemKind kind = wxITEM_NORMAL,
  402. const wxString& shortHelpString = wxEmptyString,
  403. const wxString& longHelpString = wxEmptyString,
  404. wxObject* clientData = NULL);
  405. //@}
  406. /**
  407. Deletes all the tools in the toolbar.
  408. */
  409. virtual void ClearTools();
  410. /**
  411. Removes the specified tool from the toolbar and deletes it. If you don't
  412. want to delete the tool, but just to remove it from the toolbar (to
  413. possibly add it back later), you may use RemoveTool() instead.
  414. @note It is unnecessary to call Realize() for the change to take
  415. place, it will happen immediately.
  416. @returns @true if the tool was deleted, @false otherwise.
  417. @see DeleteToolByPos()
  418. */
  419. virtual bool DeleteTool(int toolId);
  420. /**
  421. This function behaves like DeleteTool() but it deletes the tool at the
  422. specified position and not the one with the given id.
  423. */
  424. virtual bool DeleteToolByPos(size_t pos);
  425. /**
  426. Enables or disables the tool.
  427. @param toolId
  428. ID of the tool to enable or disable, as passed to AddTool().
  429. @param enable
  430. If @true, enables the tool, otherwise disables it.
  431. @remarks Some implementations will change the visible state of the tool
  432. to indicate that it is disabled.
  433. @see GetToolEnabled(), ToggleTool()
  434. */
  435. virtual void EnableTool(int toolId, bool enable);
  436. /**
  437. Returns a pointer to the tool identified by @a id or @NULL if no
  438. corresponding tool is found.
  439. */
  440. wxToolBarToolBase* FindById(int id) const;
  441. /**
  442. Returns a pointer to the control identified by @a id or @NULL if no
  443. corresponding control is found.
  444. */
  445. virtual wxControl* FindControl(int id);
  446. /**
  447. Finds a tool for the given mouse position.
  448. @param x
  449. X position.
  450. @param y
  451. Y position.
  452. @return A pointer to a tool if a tool is found, or @NULL otherwise.
  453. @remarks Currently not implemented in wxGTK (always returns @NULL
  454. there).
  455. */
  456. virtual wxToolBarToolBase* FindToolForPosition(wxCoord x, wxCoord y) const;
  457. /**
  458. Returns the left/right and top/bottom margins, which are also used for
  459. inter-toolspacing.
  460. @see SetMargins()
  461. */
  462. wxSize GetMargins() const;
  463. /**
  464. Returns the size of bitmap that the toolbar expects to have.
  465. The default bitmap size is platform-dependent: for example, it is 16*15
  466. for MSW and 24*24 for GTK. This size does @em not necessarily indicate
  467. the best size to use for the toolbars on the given platform, for this
  468. you should use @c wxArtProvider::GetNativeSizeHint(wxART_TOOLBAR) but
  469. in any case, as the bitmap size is deduced automatically from the size
  470. of the bitmaps associated with the tools added to the toolbar, it is
  471. usually unnecessary to call SetToolBitmapSize() explicitly.
  472. @remarks Note that this is the size of the bitmap you pass to AddTool(),
  473. and not the eventual size of the tool button.
  474. @see SetToolBitmapSize(), GetToolSize()
  475. */
  476. virtual wxSize GetToolBitmapSize() const;
  477. /**
  478. Returns a pointer to the tool at ordinal position @a pos.
  479. Don't confuse this with FindToolForPosition().
  480. @since 2.9.1
  481. @see GetToolsCount()
  482. */
  483. const wxToolBarToolBase *GetToolByPos(int pos) const;
  484. /**
  485. Get any client data associated with the tool.
  486. @param toolId
  487. ID of the tool in question, as passed to AddTool().
  488. @return Client data, or @NULL if there is none.
  489. */
  490. virtual wxObject* GetToolClientData(int toolId) const;
  491. /**
  492. Called to determine whether a tool is enabled (responds to user input).
  493. @param toolId
  494. ID of the tool in question, as passed to AddTool().
  495. @return @true if the tool is enabled, @false otherwise.
  496. @see EnableTool()
  497. */
  498. virtual bool GetToolEnabled(int toolId) const;
  499. /**
  500. Returns the long help for the given tool.
  501. @param toolId
  502. ID of the tool in question, as passed to AddTool().
  503. @see SetToolLongHelp(), SetToolShortHelp()
  504. */
  505. virtual wxString GetToolLongHelp(int toolId) const;
  506. /**
  507. Returns the value used for packing tools.
  508. @see SetToolPacking()
  509. */
  510. virtual int GetToolPacking() const;
  511. /**
  512. Returns the tool position in the toolbar, or @c wxNOT_FOUND if the tool
  513. is not found.
  514. @param toolId
  515. ID of the tool in question, as passed to AddTool().
  516. */
  517. virtual int GetToolPos(int toolId) const;
  518. /**
  519. Returns the default separator size.
  520. @see SetToolSeparation()
  521. */
  522. virtual int GetToolSeparation() const;
  523. /**
  524. Returns the short help for the given tool.
  525. @param toolId
  526. ID of the tool in question, as passed to AddTool().
  527. @see GetToolLongHelp(), SetToolShortHelp()
  528. */
  529. virtual wxString GetToolShortHelp(int toolId) const;
  530. /**
  531. Returns the size of a whole button, which is usually larger than a tool
  532. bitmap because of added 3D effects.
  533. @see SetToolBitmapSize(), GetToolBitmapSize()
  534. */
  535. virtual wxSize GetToolSize() const;
  536. /**
  537. Gets the on/off state of a toggle tool.
  538. @param toolId
  539. ID of the tool in question, as passed to AddTool().
  540. @return @true if the tool is toggled on, @false otherwise.
  541. @see ToggleTool()
  542. */
  543. virtual bool GetToolState(int toolId) const;
  544. /**
  545. Returns the number of tools in the toolbar.
  546. */
  547. size_t GetToolsCount() const;
  548. /**
  549. Inserts the control into the toolbar at the given position. You must
  550. call Realize() for the change to take place.
  551. @see AddControl(), InsertTool()
  552. */
  553. virtual wxToolBarToolBase* InsertControl(size_t pos, wxControl* control,
  554. const wxString& label = wxEmptyString);
  555. /**
  556. Inserts the separator into the toolbar at the given position. You must
  557. call Realize() for the change to take place.
  558. @see AddSeparator(), InsertTool()
  559. */
  560. virtual wxToolBarToolBase* InsertSeparator(size_t pos);
  561. /**
  562. Inserts a stretchable space at the given position.
  563. See AddStretchableSpace() for details about stretchable spaces.
  564. @see InsertTool(), InsertSeparator()
  565. @since 2.9.1
  566. */
  567. wxToolBarToolBase *InsertStretchableSpace(size_t pos);
  568. //@{
  569. /**
  570. Inserts the tool with the specified attributes into the toolbar at the
  571. given position.
  572. You must call Realize() for the change to take place.
  573. @see AddTool(), InsertControl(), InsertSeparator()
  574. @return The newly inserted tool or @NULL on failure. Notice that with
  575. the overload taking @a tool parameter the caller is responsible for
  576. deleting the tool in the latter case.
  577. */
  578. wxToolBarToolBase* InsertTool( size_t pos,
  579. int toolId,
  580. const wxString& label,
  581. const wxBitmap& bitmap,
  582. const wxBitmap& bmpDisabled = wxNullBitmap,
  583. wxItemKind kind = wxITEM_NORMAL,
  584. const wxString& shortHelp = wxEmptyString,
  585. const wxString& longHelp = wxEmptyString,
  586. wxObject *clientData = NULL);
  587. wxToolBarToolBase* InsertTool(size_t pos,
  588. wxToolBarToolBase* tool);
  589. //@}
  590. /**
  591. Called when the user clicks on a tool with the left mouse button. This
  592. is the old way of detecting tool clicks; although it will still work,
  593. you should use the EVT_MENU() or EVT_TOOL() macro instead.
  594. @param toolId
  595. The identifier passed to AddTool().
  596. @param toggleDown
  597. @true if the tool is a toggle and the toggle is down, otherwise is
  598. @false.
  599. @return If the tool is a toggle and this function returns @false, the
  600. toggle state (internal and visual) will not be changed. This
  601. provides a way of specifying that toggle operations are not
  602. permitted in some circumstances.
  603. @see OnMouseEnter(), OnRightClick()
  604. */
  605. virtual bool OnLeftClick(int toolId, bool toggleDown);
  606. /**
  607. This is called when the mouse cursor moves into a tool or out of the
  608. toolbar. This is the old way of detecting mouse enter events;
  609. although it will still work, you should use the EVT_TOOL_ENTER()
  610. macro instead.
  611. @param toolId
  612. Greater than -1 if the mouse cursor has moved into the tool, or -1
  613. if the mouse cursor has moved. The programmer can override this to
  614. provide extra information about the tool, such as a short
  615. description on the status line.
  616. @remarks With some derived toolbar classes, if the mouse moves quickly
  617. out of the toolbar, wxWidgets may not be able to detect it.
  618. Therefore this function may not always be called when expected.
  619. */
  620. virtual void OnMouseEnter(int toolId);
  621. /**
  622. @deprecated This is the old way of detecting tool right clicks;
  623. although it will still work, you should use the
  624. EVT_TOOL_RCLICKED() macro instead.
  625. Called when the user clicks on a tool with the right mouse button. The
  626. programmer should override this function to detect right tool clicks.
  627. @param toolId
  628. The identifier passed to AddTool().
  629. @param x
  630. The x position of the mouse cursor.
  631. @param y
  632. The y position of the mouse cursor.
  633. @remarks A typical use of this member might be to pop up a menu.
  634. @see OnMouseEnter(), OnLeftClick()
  635. */
  636. virtual void OnRightClick(int toolId, long x, long y);
  637. /**
  638. This function should be called after you have added tools.
  639. */
  640. virtual bool Realize();
  641. /**
  642. Removes the given tool from the toolbar but doesn't delete it. This
  643. allows to insert/add this tool back to this (or another) toolbar later.
  644. @note It is unnecessary to call Realize() for the change to take place,
  645. it will happen immediately.
  646. @see DeleteTool()
  647. */
  648. virtual wxToolBarToolBase* RemoveTool(int id);
  649. /**
  650. Sets the bitmap resource identifier for specifying tool bitmaps as
  651. indices into a custom bitmap.
  652. This is a Windows CE-specific method not available in the other ports.
  653. @onlyfor{wxmsw_wince}
  654. */
  655. void SetBitmapResource(int resourceId);
  656. /**
  657. Sets the dropdown menu for the tool given by its @e id. The tool itself
  658. will delete the menu when it's no longer needed. Only supported under
  659. GTK+ und MSW.
  660. If you define a EVT_TOOL_DROPDOWN() handler in your program, you must
  661. call wxEvent::Skip() from it or the menu won't be displayed.
  662. */
  663. bool SetDropdownMenu(int id, wxMenu* menu);
  664. //@{
  665. /**
  666. Set the values to be used as margins for the toolbar.
  667. @param x
  668. Left margin, right margin and inter-tool separation value.
  669. @param y
  670. Top margin, bottom margin and inter-tool separation value.
  671. @remarks This must be called before the tools are added if absolute
  672. positioning is to be used, and the default (zero-size) margins are
  673. to be overridden.
  674. @see GetMargins()
  675. */
  676. virtual void SetMargins(int x, int y);
  677. /**
  678. Set the margins for the toolbar.
  679. @param size
  680. Margin size.
  681. @remarks This must be called before the tools are added if absolute
  682. positioning is to be used, and the default (zero-size) margins are
  683. to be overridden.
  684. @see GetMargins(), wxSize
  685. */
  686. void SetMargins(const wxSize& size);
  687. //@}
  688. /**
  689. Sets the default size of each tool bitmap. The default bitmap size is 16
  690. by 15 pixels.
  691. @param size
  692. The size of the bitmaps in the toolbar.
  693. @remarks This should be called to tell the toolbar what the tool bitmap
  694. size is. Call it before you add tools.
  695. @see GetToolBitmapSize(), GetToolSize()
  696. */
  697. virtual void SetToolBitmapSize(const wxSize& size);
  698. /**
  699. Sets the client data associated with the tool.
  700. @param id
  701. ID of the tool in question, as passed to AddTool().
  702. @param clientData
  703. The client data to use.
  704. */
  705. virtual void SetToolClientData(int id, wxObject* clientData);
  706. /**
  707. Sets the bitmap to be used by the tool with the given ID when the tool
  708. is in a disabled state. This can only be used on Button tools, not
  709. controls.
  710. @param id
  711. ID of the tool in question, as passed to AddTool().
  712. @param bitmap
  713. Bitmap to use for disabled tools.
  714. @note The native toolbar classes on the main platforms all synthesize
  715. the disabled bitmap from the normal bitmap, so this function will
  716. have no effect on those platforms.
  717. */
  718. virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap);
  719. /**
  720. Sets the long help for the given tool.
  721. @param toolId
  722. ID of the tool in question, as passed to AddTool().
  723. @param helpString
  724. A string for the long help.
  725. @remarks You might use the long help for displaying the tool purpose on
  726. the status line.
  727. @see GetToolLongHelp(), SetToolShortHelp(),
  728. */
  729. virtual void SetToolLongHelp(int toolId, const wxString& helpString);
  730. /**
  731. Sets the bitmap to be used by the tool with the given ID. This can only
  732. be used on Button tools, not controls.
  733. @param id
  734. ID of the tool in question, as passed to AddTool().
  735. @param bitmap
  736. Bitmap to use for normals tools.
  737. */
  738. virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap);
  739. /**
  740. Sets the value used for spacing tools. The default value is 1.
  741. @param packing
  742. The value for packing.
  743. @remarks The packing is used for spacing in the vertical direction if
  744. the toolbar is horizontal, and for spacing in the horizontal
  745. direction if the toolbar is vertical.
  746. @see GetToolPacking()
  747. */
  748. virtual void SetToolPacking(int packing);
  749. /**
  750. Sets the default separator size. The default value is 5.
  751. @param separation
  752. The separator size.
  753. @see AddSeparator()
  754. */
  755. virtual void SetToolSeparation(int separation);
  756. /**
  757. Sets the short help for the given tool.
  758. @param toolId
  759. ID of the tool in question, as passed to AddTool().
  760. @param helpString
  761. The string for the short help.
  762. @remarks An application might use short help for identifying the tool
  763. purpose in a tooltip.
  764. @see GetToolShortHelp(), SetToolLongHelp()
  765. */
  766. virtual void SetToolShortHelp(int toolId, const wxString& helpString);
  767. /**
  768. Toggles a tool on or off. This does not cause any event to get emitted.
  769. @param toolId
  770. ID of the tool in question, as passed to AddTool().
  771. @param toggle
  772. If @true, toggles the tool on, otherwise toggles it off.
  773. @remarks Only applies to a tool that has been specified as a toggle
  774. tool.
  775. */
  776. virtual void ToggleTool(int toolId, bool toggle);
  777. /**
  778. Factory function to create a new toolbar tool.
  779. */
  780. virtual wxToolBarToolBase *CreateTool(int toolId,
  781. const wxString& label,
  782. const wxBitmap& bmpNormal,
  783. const wxBitmap& bmpDisabled = wxNullBitmap,
  784. wxItemKind kind = wxITEM_NORMAL,
  785. wxObject *clientData = NULL,
  786. const wxString& shortHelp = wxEmptyString,
  787. const wxString& longHelp = wxEmptyString);
  788. /**
  789. Factory function to create a new control toolbar tool.
  790. */
  791. virtual wxToolBarToolBase *CreateTool(wxControl *control,
  792. const wxString& label);
  793. /**
  794. Factory function to create a new separator toolbar tool.
  795. */
  796. wxToolBarToolBase *CreateSeparator()
  797. };