]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/toolbar.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxToolBar
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 The name wxToolBar is defined to be a synonym for one of the following
15 - @b wxToolBar95 - The native Windows 95 toolbar. Used on Windows 95, NT 4
17 - @b wxToolBarMSW - A Windows implementation. Used on 16-bit Windows.
18 - @b wxToolBarGTK - The GTK toolbar.
20 You may also create a toolbar that is managed by the frame, by calling
21 wxFrame::CreateToolBar(). Under Pocket PC, you should always use this
22 function for creating the toolbar to be managed by the frame, so that
23 wxWidgets can use a combined menubar and toolbar. Where you manage your
24 own toolbars, create a wxToolBar as usual.
26 The meaning of a "separator" is a vertical line under Windows and simple
29 @b wxToolBar95: Note that this toolbar paints tools to reflect
30 system-wide colours. If you use more than 16 colours in your tool
31 bitmaps, you may wish to suppress this behaviour, otherwise system
32 colours in your bitmaps will inadvertently be mapped to system colours.
33 To do this, set the msw.remap system option before creating the toolbar:
36 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
39 If you wish to use 32-bit images (which include an alpha channel for
43 wxSystemOptions::SetOption(wxT("msw.remap"), 2);
46 Then colour remapping is switched off, and a transparent background
47 used. But only use this option under Windows XP with true colour:
50 if (wxTheApp->GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32)
53 There are several different types of tools you can add to a toolbar. These
54 types are controlled by the ::wxItemKind enumeration.
58 Gives the toolbar a flat look (Windows and GTK only).
60 Makes the toolbar floatable and dockable (GTK only).
61 @style{wxTB_HORIZONTAL}
62 Specifies horizontal layout (default).
64 Specifies vertical layout.
66 Shows the text in the toolbar buttons; by default only icons are shown.
68 Specifies no icons in the toolbar buttons; by default they are shown.
69 @style{wxTB_NODIVIDER}
70 Specifies no divider (border) above the toolbar (Windows only)
72 Specifies no alignment with the parent window (Windows only, not very
74 @style{wxTB_HORZ_LAYOUT}
75 Shows the text and the icons alongside, not vertically stacked (Windows
76 and GTK 2 only). This style must be used with @c wxTB_TEXT.
77 @style{wxTB_HORZ_TEXT}
78 Combination of @c wxTB_HORZ_LAYOUT and @c wxTB_TEXT.
79 @style{wxTB_NO_TOOLTIPS}
80 Don't show the short help tooltips for the tools when the mouse hovers
83 Align the toolbar at the bottom of parent window.
85 Align the toolbar at the right side of parent window.
88 See also @ref overview_windowstyles. Note that the Win32 native toolbar
89 ignores @c wxTB_NOICONS style. Also, toggling the @c wxTB_TEXT works only
90 if the style was initially on.
92 @beginEventTable{wxCommandEvent}
93 @event{EVT_TOOL(id, func)}
94 Process a @c wxEVT_COMMAND_TOOL_CLICKED event (a synonym for @c
95 wxEVT_COMMAND_MENU_SELECTED). Pass the id of the tool.
96 @event{EVT_MENU(id, func)}
97 The same as EVT_TOOL().
98 @event{EVT_TOOL_RANGE(id1, id2, func)}
99 Process a @c wxEVT_COMMAND_TOOL_CLICKED event for a range of
100 identifiers. Pass the ids of the tools.
101 @event{EVT_MENU_RANGE(id1, id2, func)}
102 The same as EVT_TOOL_RANGE().
103 @event{EVT_TOOL_RCLICKED(id, func)}
104 Process a @c wxEVT_COMMAND_TOOL_RCLICKED event. Pass the id of the
106 @event{EVT_TOOL_RCLICKED_RANGE(id1, id2, func)}
107 Process a @c wxEVT_COMMAND_TOOL_RCLICKED event for a range of ids. Pass
108 the ids of the tools.
109 @event{EVT_TOOL_ENTER(id, func)}
110 Process a @c wxEVT_COMMAND_TOOL_ENTER event. Pass the id of the toolbar
111 itself. The value of wxCommandEvent::GetSelection() is the tool id, or
112 -1 if the mouse cursor has moved off a tool.
113 @event{EVT_TOOL_DROPDOWN(id, func)}
114 Process a @c wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED event. If unhandled,
115 displays the default dropdown menu set using
116 wxToolBar::SetDropdownMenu().
119 The toolbar class emits menu commands in the same way that a frame menubar
120 does, so you can use one EVT_MENU() macro for both a menu item and a toolbar
121 button. The event handler functions take a wxCommandEvent argument. For most
122 event macros, the identifier of the tool is passed, but for EVT_TOOL_ENTER()
123 the toolbar window identifier is passed and the tool identifier is retrieved
124 from the wxCommandEvent. This is because the identifier may be -1 when the
125 mouse moves off a tool, and -1 is not allowed as an identifier in the event
131 @see @ref overview_toolbar
133 class wxToolBar
: public wxControl
142 Constructs a toolbar.
145 Pointer to a parent window.
147 Window identifier. If -1, will automatically create an identifier.
149 Window position. ::wxDefaultPosition is (-1, -1) which indicates that
150 wxWidgets should generate a default position for the window. If
151 using the wxWindow class directly, supply an actual position.
153 Window size. ::wxDefaultSize is (-1, -1) which indicates that
154 wxWidgets should generate a default size for the window.
156 Window style. See wxToolBar for details.
160 @remarks After a toolbar is created, you use AddTool() and perhaps
161 AddSeparator(), and then you must call Realize() to construct and
162 display the toolbar tools.
164 wxToolBar(wxWindow
* parent
, wxWindowID id
,
165 const wxPoint
& pos
= wxDefaultPosition
,
166 const wxSize
& size
= wxDefaultSize
,
167 long style
= wxTB_HORIZONTAL
| wxBORDER_NONE
,
168 const wxString
& name
= wxPanelNameStr
);
173 virtual ~wxToolBar();
176 Adds a new check (or toggle) tool to the toolbar. The parameters are the
177 same as in AddTool().
181 wxToolBarToolBase
* AddCheckTool(int toolId
,
182 const wxString
& label
,
183 const wxBitmap
& bitmap1
,
184 const wxBitmap
& bitmap2
,
185 const wxString
& shortHelpString
= "",
186 const wxString
& longHelpString
= "",
187 wxObject
* clientData
= NULL
);
190 Adds any control to the toolbar, typically e.g. a wxComboBox.
193 The control to be added.
195 Text to be displayed near the control.
198 wxMSW: the label is only displayed if there is enough space
199 available below the embedded control.
202 wxMac: labels are only displayed if wxWidgets is built with @c
203 wxMAC_USE_NATIVE_TOOLBAR set to 1
205 bool AddControl(wxControl
* control
, const wxString label
= "");
208 Adds a new radio tool to the toolbar. Consecutive radio tools form a
209 radio group such that exactly one button in the group is pressed at any
210 moment, in other words whenever a button in the group is pressed the
211 previously pressed button is automatically released. You should avoid
212 having the radio groups of only one element as it would be impossible
213 for the user to use such button.
215 By default, the first button in the radio group is initially pressed,
221 wxToolBarToolBase
* AddRadioTool(int toolId
,
222 const wxString
& label
,
223 const wxBitmap
& bitmap1
,
224 const wxBitmap
& bitmap2
,
225 const wxString
& shortHelpString
= "",
226 const wxString
& longHelpString
= "",
227 wxObject
* clientData
= NULL
);
230 Adds a separator for spacing groups of tools.
232 @see AddTool(), SetToolSeparation()
237 Adds a tool to the toolbar.
240 The tool to be added.
242 @remarks After you have added tools to a toolbar, you must call
243 Realize() in order to have the tools appear.
245 @see AddSeparator(), AddCheckTool(), AddRadioTool(),
246 InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
248 virtual wxToolBarToolBase
* AddTool(wxToolBarToolBase
* tool
);
251 Adds a tool to the toolbar. This most commonly used version has fewer
252 parameters than the full version below which specifies the more rarely
253 used button features.
256 An integer by which the tool may be identified in subsequent
259 The string to be displayed with the tool.
261 The primary tool bitmap.
263 This string is used for the tools tooltip.
265 May be ::wxITEM_NORMAL for a normal button (default), ::wxITEM_CHECK
266 for a checkable tool (such tool stays pressed after it had been
267 toggled) or ::wxITEM_RADIO for a checkable tool which makes part of
268 a radio group of tools each of which is automatically unchecked
269 whenever another button in the group is checked. ::wxITEM_DROPDOWN
270 specifies that a drop-down menu button will appear next to the
271 tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
273 @remarks After you have added tools to a toolbar, you must call
274 Realize() in order to have the tools appear.
276 @see AddSeparator(), AddCheckTool(), AddRadioTool(),
277 InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
279 wxToolBarToolBase
* AddTool(int toolId
, const wxString
& label
,
280 const wxBitmap
& bitmap
,
281 const wxString
& shortHelp
= wxEmptyString
,
282 wxItemKind kind
= wxITEM_NORMAL
);
285 Adds a tool to the toolbar.
288 An integer by which the tool may be identified in subsequent
291 The string to be displayed with the tool.
293 The primary tool bitmap.
295 The bitmap used when the tool is disabled. If it is equal to
296 ::wxNullBitmap (default), the disabled bitmap is automatically
297 generated by greying the normal one.
298 @param shortHelpString
299 This string is used for the tools tooltip.
300 @param longHelpString
301 This string is shown in the statusbar (if any) of the parent frame
302 when the mouse pointer is inside the tool.
304 May be ::wxITEM_NORMAL for a normal button (default), ::wxITEM_CHECK
305 for a checkable tool (such tool stays pressed after it had been
306 toggled) or ::wxITEM_RADIO for a checkable tool which makes part of
307 a radio group of tools each of which is automatically unchecked
308 whenever another button in the group is checked. ::wxITEM_DROPDOWN
309 specifies that a drop-down menu button will appear next to the
310 tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
312 An optional pointer to client data which can be retrieved later
313 using GetToolClientData().
315 @remarks After you have added tools to a toolbar, you must call
316 Realize() in order to have the tools appear.
318 @see AddSeparator(), AddCheckTool(), AddRadioTool(),
319 InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
321 wxToolBarToolBase
* AddTool(int toolId
, const wxString
& label
,
322 const wxBitmap
& bitmap
,
323 const wxBitmap
& bmpDisabled
= wxNullBitmap
,
324 wxItemKind kind
= wxITEM_NORMAL
,
325 const wxString
& shortHelpString
= wxEmptyString
,
326 const wxString
& longHelpString
= wxEmptyString
,
327 wxObject
* clientData
= NULL
);
330 Deletes all the tools in the toolbar.
332 virtual void ClearTools();
335 Removes the specified tool from the toolbar and deletes it. If you don't
336 want to delete the tool, but just to remove it from the toolbar (to
337 possibly add it back later), you may use RemoveTool() instead.
339 @note It is unnecessary to call Realize() for the change to take
340 place, it will happen immediately.
342 @returns @true if the tool was deleted, @false otherwise.
344 @see DeleteToolByPos()
346 virtual bool DeleteTool(int toolId
);
349 This function behaves like DeleteTool() but it deletes the tool at the
350 specified position and not the one with the given id.
352 virtual bool DeleteToolByPos(size_t pos
);
355 Enables or disables the tool.
358 Tool to enable or disable.
360 If @true, enables the tool, otherwise disables it.
362 @remarks Some implementations will change the visible state of the tool
363 to indicate that it is disabled.
366 @see GetToolEnabled(), ToggleTool()
368 virtual void EnableTool(int toolId
, bool enable
);
371 Returns a pointer to the tool identified by @a id or @NULL if no
372 corresponding tool is found.
374 wxToolBarToolBase
* FindById(int id
) const;
377 Returns a pointer to the control identified by @a id or @NULL if no
378 corresponding control is found.
380 virtual wxControl
* FindControl(int id
);
383 Finds a tool for the given mouse position.
390 @return A pointer to a tool if a tool is found, or @NULL otherwise.
392 @remarks Currently not implemented in wxGTK (always returns @NULL
395 virtual wxToolBarToolBase
* FindToolForPosition(wxCoord x
, wxCoord y
) const;
398 Returns the left/right and top/bottom margins, which are also used for
403 wxSize
GetMargins() const;
406 Returns the size of bitmap that the toolbar expects to have. The default
407 bitmap size is 16 by 15 pixels.
409 @remarks Note that this is the size of the bitmap you pass to AddTool(),
410 and not the eventual size of the tool button.
412 @see SetToolBitmapSize(), GetToolSize()
414 virtual wxSize
GetToolBitmapSize() const;
417 Get any client data associated with the tool.
420 Id of the tool, as passed to AddTool().
422 @return Client data, or @NULL if there is none.
424 virtual wxObject
* GetToolClientData(int toolId
) const;
427 Called to determine whether a tool is enabled (responds to user input).
430 Id of the tool in question.
432 @return @true if the tool is enabled, @false otherwise.
436 virtual bool GetToolEnabled(int toolId
) const;
439 Returns the long help for the given tool.
442 The tool in question.
444 @see SetToolLongHelp(), SetToolShortHelp()
446 virtual wxString
GetToolLongHelp(int toolId
) const;
449 Returns the value used for packing tools.
451 @see SetToolPacking()
453 virtual int GetToolPacking() const;
456 Returns the tool position in the toolbar, or @c wxNOT_FOUND if the tool
459 virtual int GetToolPos(int toolId
) const;
462 Returns the default separator size.
464 @see SetToolSeparation()
466 virtual int GetToolSeparation() const;
469 Returns the short help for the given tool.
472 The tool in question.
474 @see GetToolLongHelp(), SetToolShortHelp()
476 virtual wxString
GetToolShortHelp(int toolId
) const;
479 Returns the size of a whole button, which is usually larger than a tool
480 bitmap because of added 3D effects.
482 @see SetToolBitmapSize(), GetToolBitmapSize()
484 virtual wxSize
GetToolSize() const;
487 Gets the on/off state of a toggle tool.
490 The tool in question.
492 @return @true if the tool is toggled on, @false otherwise.
496 virtual bool GetToolState(int toolId
) const;
499 Returns the number of tools in the toolbar.
501 int GetToolsCount() const;
504 Inserts the control into the toolbar at the given position. You must
505 call Realize() for the change to take place.
507 @see AddControl(), InsertTool()
509 wxToolBarToolBase
* InsertControl(size_t pos
, wxControl
* control
);
512 Inserts the separator into the toolbar at the given position. You must
513 call Realize() for the change to take place.
515 @see AddSeparator(), InsertTool()
517 virtual wxToolBarToolBase
* InsertSeparator(size_t pos
);
521 Inserts the tool with the specified attributes into the toolbar at the
524 You must call Realize() for the change to take place.
526 @see AddTool(), InsertControl(), InsertSeparator()
528 wxToolBarToolBase
* InsertTool(size_t pos
, int toolId
,
529 const wxBitmap
& bitmap1
,
530 const wxBitmap
& bitmap2
= wxNullBitmap
,
531 bool isToggle
= false,
532 wxObject
* clientData
= NULL
,
533 const wxString
& shortHelpString
= "",
534 const wxString
& longHelpString
= "");
535 wxToolBarToolBase
* InsertTool(size_t pos
,
536 wxToolBarToolBase
* tool
);
540 Called when the user clicks on a tool with the left mouse button. This
541 is the old way of detecting tool clicks; although it will still work,
542 you should use the EVT_MENU() or EVT_TOOL() macro instead.
545 The identifier passed to AddTool().
547 @true if the tool is a toggle and the toggle is down, otherwise is
550 @return If the tool is a toggle and this function returns @false, the
551 toggle state (internal and visual) will not be changed. This
552 provides a way of specifying that toggle operations are not
553 permitted in some circumstances.
555 @see OnMouseEnter(), OnRightClick()
557 virtual bool OnLeftClick(int toolId
, bool toggleDown
);
560 This is called when the mouse cursor moves into a tool or out of the
561 toolbar. This is the old way of detecting mouse enter events;
562 although it will still work, you should use the EVT_TOOL_ENTER()
566 Greater than -1 if the mouse cursor has moved into the tool, or -1
567 if the mouse cursor has moved. The programmer can override this to
568 provide extra information about the tool, such as a short
569 description on the status line.
571 @remarks With some derived toolbar classes, if the mouse moves quickly
572 out of the toolbar, wxWidgets may not be able to detect it.
573 Therefore this function may not always be called when expected.
575 virtual void OnMouseEnter(int toolId
);
578 @deprecated This is the old way of detecting tool right clicks;
579 although it will still work, you should use the
580 EVT_TOOL_RCLICKED() macro instead.
582 Called when the user clicks on a tool with the right mouse button. The
583 programmer should override this function to detect right tool clicks.
586 The identifier passed to AddTool().
588 The x position of the mouse cursor.
590 The y position of the mouse cursor.
592 @remarks A typical use of this member might be to pop up a menu.
594 @see OnMouseEnter(), OnLeftClick()
596 void OnRightClick(int toolId
, float x
, float y
);
599 This function should be called after you have added tools.
601 virtual bool Realize();
604 Removes the given tool from the toolbar but doesn't delete it. This
605 allows to insert/add this tool back to this (or another) toolbar later.
607 @note It is unnecessary to call Realize() for the change to take place,
608 it will happen immediately.
613 virtual wxToolBarToolBase
* RemoveTool(int id
);
616 Sets the bitmap resource identifier for specifying tool bitmaps as
617 indices into a custom bitmap. Windows CE only.
619 void SetBitmapResource(int resourceId
);
622 Sets the dropdown menu for the tool given by its @e id. The tool itself
623 will delete the menu when it's no longer needed. Only supported under
626 If you define a EVT_TOOL_DROPDOWN() handler in your program, you must
627 call wxEvent::Skip() from it or the menu won't be displayed.
629 bool SetDropdownMenu(int id
, wxMenu
* menu
);
632 Set the values to be used as margins for the toolbar.
635 Left margin, right margin and inter-tool separation value.
637 Top margin, bottom margin and inter-tool separation value.
639 @remarks This must be called before the tools are added if absolute
640 positioning is to be used, and the default (zero-size) margins are
645 virtual void SetMargins(int x
, int y
);
648 Set the margins for the toolbar.
653 @remarks This must be called before the tools are added if absolute
654 positioning is to be used, and the default (zero-size) margins are
657 @see GetMargins(), wxSize
659 void SetMargins(const wxSize
& size
);
662 Sets the default size of each tool bitmap. The default bitmap size is 16
666 The size of the bitmaps in the toolbar.
668 @remarks This should be called to tell the toolbar what the tool bitmap
669 size is. Call it before you add tools.
671 @see GetToolBitmapSize(), GetToolSize()
673 virtual void SetToolBitmapSize(const wxSize
& size
);
676 Sets the client data associated with the tool.
678 virtual void SetToolClientData(int id
, wxObject
* clientData
);
681 Sets the bitmap to be used by the tool with the given ID when the tool
682 is in a disabled state. This can only be used on Button tools, not
685 @note The native toolbar classes on the main platforms all synthesize
686 the disabled bitmap from the normal bitmap, so this function will
687 have no effect on those platforms.
690 virtual void SetToolDisabledBitmap(int id
, const wxBitmap
& bitmap
);
693 Sets the long help for the given tool.
696 The tool in question.
698 A string for the long help.
700 @remarks You might use the long help for displaying the tool purpose on
703 @see GetToolLongHelp(), SetToolShortHelp(),
705 virtual void SetToolLongHelp(int toolId
, const wxString
& helpString
);
708 Sets the bitmap to be used by the tool with the given ID. This can only
709 be used on Button tools, not controls.
711 virtual void SetToolNormalBitmap(int id
, const wxBitmap
& bitmap
);
714 Sets the value used for spacing tools. The default value is 1.
717 The value for packing.
719 @remarks The packing is used for spacing in the vertical direction if
720 the toolbar is horizontal, and for spacing in the horizontal
721 direction if the toolbar is vertical.
723 @see GetToolPacking()
725 virtual void SetToolPacking(int packing
);
728 Sets the default separator size. The default value is 5.
735 virtual void SetToolSeparation(int separation
);
738 Sets the short help for the given tool.
741 The tool in question.
743 The string for the short help.
745 @remarks An application might use short help for identifying the tool
746 purpose in a tooltip.
749 @see GetToolShortHelp(), SetToolLongHelp()
751 virtual void SetToolShortHelp(int toolId
, const wxString
& helpString
);
754 Toggles a tool on or off. This does not cause any event to get emitted.
759 If @true, toggles the tool on, otherwise toggles it off.
761 @remarks Only applies to a tool that has been specified as a toggle
764 virtual void ToggleTool(int toolId
, bool toggle
);