]>
git.saurik.com Git - wxWidgets.git/blob - interface/toolbar.h
c7deafc8bc4c10841cfece5f2d065c5bf9d7fd2c
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxToolBar
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 The name wxToolBar is defined to be a synonym for one of the following
16 - @b wxToolBar95 - The native Windows 95 toolbar. Used on Windows 95, NT 4
18 - @b wxToolBarMSW - A Windows implementation. Used on 16-bit Windows.
19 - @b wxToolBarGTK - The GTK toolbar.
21 You may also create a toolbar that is managed by the frame, by calling
22 wxFrame::CreateToolBar(). Under Pocket PC, you should always use this
23 function for creating the toolbar to be managed by the frame, so that
24 wxWidgets can use a combined menubar and toolbar. Where you manage your
25 own toolbars, create a wxToolBar as usual.
27 The meaning of a "separator" is a vertical line under Windows and simple
30 @b wxToolBar95: Note that this toolbar paints tools to reflect
31 system-wide colours. If you use more than 16 colours in your tool
32 bitmaps, you may wish to suppress this behaviour, otherwise system
33 colours in your bitmaps will inadvertently be mapped to system colours.
34 To do this, set the msw.remap system option before creating the toolbar:
37 wxSystemOptions::SetOption(wxT("msw.remap"), 0);
40 If you wish to use 32-bit images (which include an alpha channel for
44 wxSystemOptions::SetOption(wxT("msw.remap"), 2);
47 Then colour remapping is switched off, and a transparent background
48 used. But only use this option under Windows XP with true colour:
51 if (wxTheApp->GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32)
54 There are several different types of tools you can add to a toolbar. These
55 types are controlled by the ::wxItemKind enumeration.
59 Gives the toolbar a flat look (Windows and GTK only).
61 Makes the toolbar floatable and dockable (GTK only).
62 @style{wxTB_HORIZONTAL}
63 Specifies horizontal layout (default).
65 Specifies vertical layout.
67 Shows the text in the toolbar buttons; by default only icons are shown.
69 Specifies no icons in the toolbar buttons; by default they are shown.
70 @style{wxTB_NODIVIDER}
71 Specifies no divider (border) above the toolbar (Windows only)
73 Specifies no alignment with the parent window (Windows only, not very
75 @style{wxTB_HORZ_LAYOUT}
76 Shows the text and the icons alongside, not vertically stacked (Windows
77 and GTK 2 only). This style must be used with @c wxTB_TEXT.
78 @style{wxTB_HORZ_TEXT}
79 Combination of @c wxTB_HORZ_LAYOUT and @c wxTB_TEXT.
80 @style{wxTB_NO_TOOLTIPS}
81 Don't show the short help tooltips for the tools when the mouse hovers
84 Align the toolbar at the bottom of parent window.
86 Align the toolbar at the right side of parent window.
89 See also @ref overview_windowstyles. Note that the Win32 native toolbar
90 ignores @c wxTB_NOICONS style. Also, toggling the @c wxTB_TEXT works only
91 if the style was initially on.
93 @beginEventTable{wxCommandEvent}
94 @event{EVT_TOOL(id, func)}
95 Process a @c wxEVT_COMMAND_TOOL_CLICKED event (a synonym for @c
96 wxEVT_COMMAND_MENU_SELECTED). Pass the id of the tool.
97 @event{EVT_MENU(id, func)}
98 The same as EVT_TOOL().
99 @event{EVT_TOOL_RANGE(id1, id2, func)}
100 Process a @c wxEVT_COMMAND_TOOL_CLICKED event for a range of
101 identifiers. Pass the ids of the tools.
102 @event{EVT_MENU_RANGE(id1, id2, func)}
103 The same as EVT_TOOL_RANGE().
104 @event{EVT_TOOL_RCLICKED(id, func)}
105 Process a @c wxEVT_COMMAND_TOOL_RCLICKED event. Pass the id of the
107 @event{EVT_TOOL_RCLICKED_RANGE(id1, id2, func)}
108 Process a @c wxEVT_COMMAND_TOOL_RCLICKED event for a range of ids. Pass
109 the ids of the tools.
110 @event{EVT_TOOL_ENTER(id, func)}
111 Process a @c wxEVT_COMMAND_TOOL_ENTER event. Pass the id of the toolbar
112 itself. The value of wxCommandEvent::GetSelection() is the tool id, or
113 -1 if the mouse cursor has moved off a tool.
114 @event{EVT_TOOL_DROPDOWN(id, func)}
115 Process a @c wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED event. If unhandled,
116 displays the default dropdown menu set using
117 wxToolBar::SetDropdownMenu().
120 The toolbar class emits menu commands in the same way that a frame menubar
121 does, so you can use one EVT_MENU() macro for both a menu item and a toolbar
122 button. The event handler functions take a wxCommandEvent argument. For most
123 event macros, the identifier of the tool is passed, but for EVT_TOOL_ENTER()
124 the toolbar window identifier is passed and the tool identifier is retrieved
125 from the wxCommandEvent. This is because the identifier may be -1 when the
126 mouse moves off a tool, and -1 is not allowed as an identifier in the event
132 @see @ref overview_toolbar
134 class wxToolBar
: public wxControl
143 Constructs a toolbar.
146 Pointer to a parent window.
148 Window identifier. If -1, will automatically create an identifier.
150 Window position. ::wxDefaultPosition is (-1, -1) which indicates that
151 wxWidgets should generate a default position for the window. If
152 using the wxWindow class directly, supply an actual position.
154 Window size. ::wxDefaultSize is (-1, -1) which indicates that
155 wxWidgets should generate a default size for the window.
157 Window style. See wxToolBar for details.
161 @remarks After a toolbar is created, you use AddTool() and perhaps
162 AddSeparator(), and then you must call Realize() to construct and
163 display the toolbar tools.
165 wxToolBar(wxWindow
* parent
, wxWindowID id
,
166 const wxPoint
& pos
= wxDefaultPosition
,
167 const wxSize
& size
= wxDefaultSize
,
168 long style
= wxTB_HORIZONTAL
| wxBORDER_NONE
,
169 const wxString
& name
= wxPanelNameStr
);
177 Adds a new check (or toggle) tool to the toolbar. The parameters are the
178 same as in AddTool().
182 wxToolBarToolBase
* AddCheckTool(int toolId
,
183 const wxString
& label
,
184 const wxBitmap
& bitmap1
,
185 const wxBitmap
& bitmap2
,
186 const wxString
& shortHelpString
= "",
187 const wxString
& longHelpString
= "",
188 wxObject
* clientData
= NULL
);
191 Adds any control to the toolbar, typically e.g. a wxComboBox.
194 The control to be added.
196 Text to be displayed near the control.
199 wxMSW: the label is only displayed if there is enough space
200 available below the embedded control.
203 wxMac: labels are only displayed if wxWidgets is built with @c
204 wxMAC_USE_NATIVE_TOOLBAR set to 1
206 bool AddControl(wxControl
* control
, const wxString label
= "");
209 Adds a new radio tool to the toolbar. Consecutive radio tools form a
210 radio group such that exactly one button in the group is pressed at any
211 moment, in other words whenever a button in the group is pressed the
212 previously pressed button is automatically released. You should avoid
213 having the radio groups of only one element as it would be impossible
214 for the user to use such button.
216 By default, the first button in the radio group is initially pressed,
222 wxToolBarToolBase
* AddRadioTool(int toolId
,
223 const wxString
& label
,
224 const wxBitmap
& bitmap1
,
225 const wxBitmap
& bitmap2
,
226 const wxString
& shortHelpString
= "",
227 const wxString
& longHelpString
= "",
228 wxObject
* clientData
= NULL
);
231 Adds a separator for spacing groups of tools.
233 @see AddTool(), SetToolSeparation()
238 Adds a tool to the toolbar.
241 The tool to be added.
243 @remarks After you have added tools to a toolbar, you must call
244 Realize() in order to have the tools appear.
246 @see AddSeparator(), AddCheckTool(), AddRadioTool(),
247 InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
249 wxToolBarToolBase
* AddTool(wxToolBarToolBase
* tool
);
252 Adds a tool to the toolbar. This most commonly used version has fewer
253 parameters than the full version below which specifies the more rarely
254 used button features.
257 An integer by which the tool may be identified in subsequent
260 The string to be displayed with the tool.
262 The primary tool bitmap.
264 This string is used for the tools tooltip.
266 May be ::wxITEM_NORMAL for a normal button (default), ::wxITEM_CHECK
267 for a checkable tool (such tool stays pressed after it had been
268 toggled) or ::wxITEM_RADIO for a checkable tool which makes part of
269 a radio group of tools each of which is automatically unchecked
270 whenever another button in the group is checked. ::wxITEM_DROPDOWN
271 specifies that a drop-down menu button will appear next to the
272 tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
274 @remarks After you have added tools to a toolbar, you must call
275 Realize() in order to have the tools appear.
277 @see AddSeparator(), AddCheckTool(), AddRadioTool(),
278 InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
280 wxToolBarToolBase
* AddTool(int toolId
, const wxString
& label
,
281 const wxBitmap
& bitmap
,
282 const wxString
& shortHelp
= wxEmptyString
,
283 wxItemKind kind
= wxITEM_NORMAL
);
286 Adds a tool to the toolbar.
289 An integer by which the tool may be identified in subsequent
292 The string to be displayed with the tool.
294 The primary tool bitmap.
296 The bitmap used when the tool is disabled. If it is equal to
297 ::wxNullBitmap (default), the disabled bitmap is automatically
298 generated by greying the normal one.
299 @param shortHelpString
300 This string is used for the tools tooltip.
301 @param longHelpString
302 This string is shown in the statusbar (if any) of the parent frame
303 when the mouse pointer is inside the tool.
305 May be ::wxITEM_NORMAL for a normal button (default), ::wxITEM_CHECK
306 for a checkable tool (such tool stays pressed after it had been
307 toggled) or ::wxITEM_RADIO for a checkable tool which makes part of
308 a radio group of tools each of which is automatically unchecked
309 whenever another button in the group is checked. ::wxITEM_DROPDOWN
310 specifies that a drop-down menu button will appear next to the
311 tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
313 An optional pointer to client data which can be retrieved later
314 using GetToolClientData().
316 @remarks After you have added tools to a toolbar, you must call
317 Realize() in order to have the tools appear.
319 @see AddSeparator(), AddCheckTool(), AddRadioTool(),
320 InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()
322 wxToolBarToolBase
* AddTool(int toolId
, const wxString
& label
,
323 const wxBitmap
& bitmap
,
324 const wxBitmap
& bmpDisabled
= wxNullBitmap
,
325 wxItemKind kind
= wxITEM_NORMAL
,
326 const wxString
& shortHelpString
= wxEmptyString
,
327 const wxString
& longHelpString
= wxEmptyString
,
328 wxObject
* clientData
= NULL
);
331 Deletes all the tools in the toolbar.
336 Removes the specified tool from the toolbar and deletes it. If you don't
337 want to delete the tool, but just to remove it from the toolbar (to
338 possibly add it back later), you may use RemoveTool() instead.
340 @note It is unnecessary to call Realize() for the change to take
341 place, it will happen immediately.
343 @returns @true if the tool was deleted, @false otherwise.
345 @see DeleteToolByPos()
347 bool DeleteTool(int toolId
);
350 This function behaves like DeleteTool() but it deletes the tool at the
351 specified position and not the one with the given id.
353 bool DeleteToolByPos(size_t pos
);
356 Enables or disables the tool.
359 Tool to enable or disable.
361 If @true, enables the tool, otherwise disables it.
363 @remarks Some implementations will change the visible state of the tool
364 to indicate that it is disabled.
367 @see GetToolEnabled(), ToggleTool()
369 void EnableTool(int toolId
, bool enable
);
372 Returns a pointer to the tool identified by @a id or @NULL if no
373 corresponding tool is found.
375 wxToolBarToolBase
* FindById(int id
);
378 Returns a pointer to the control identified by @a id or @NULL if no
379 corresponding control is found.
381 wxControl
* FindControl(int id
);
384 Finds a tool for the given mouse position.
391 @return A pointer to a tool if a tool is found, or @NULL otherwise.
393 @remarks Currently not implemented in wxGTK (always returns @NULL
396 wxToolBarToolBase
* FindToolForPosition(wxCoord x
, wxCoord y
) const;
399 Returns the left/right and top/bottom margins, which are also used for
404 wxSize
GetMargins() const;
407 Returns the size of bitmap that the toolbar expects to have. The default
408 bitmap size is 16 by 15 pixels.
410 @remarks Note that this is the size of the bitmap you pass to AddTool(),
411 and not the eventual size of the tool button.
413 @see SetToolBitmapSize(), GetToolSize()
415 wxSize
GetToolBitmapSize();
418 Get any client data associated with the tool.
421 Id of the tool, as passed to AddTool().
423 @return Client data, or @NULL if there is none.
425 wxObject
* GetToolClientData(int toolId
) const;
428 Called to determine whether a tool is enabled (responds to user input).
431 Id of the tool in question.
433 @return @true if the tool is enabled, @false otherwise.
437 bool GetToolEnabled(int toolId
) const;
440 Returns the long help for the given tool.
443 The tool in question.
445 @see SetToolLongHelp(), SetToolShortHelp()
447 wxString
GetToolLongHelp(int toolId
) const;
450 Returns the value used for packing tools.
452 @see SetToolPacking()
454 int GetToolPacking() const;
457 Returns the tool position in the toolbar, or @c wxNOT_FOUND if the tool
460 int GetToolPos(int toolId
) const;
463 Returns the default separator size.
465 @see SetToolSeparation()
467 int GetToolSeparation() const;
470 Returns the short help for the given tool.
473 The tool in question.
475 @see GetToolLongHelp(), SetToolShortHelp()
477 wxString
GetToolShortHelp(int toolId
) const;
480 Returns the size of a whole button, which is usually larger than a tool
481 bitmap because of added 3D effects.
483 @see SetToolBitmapSize(), GetToolBitmapSize()
485 wxSize
GetToolSize();
488 Gets the on/off state of a toggle tool.
491 The tool in question.
493 @return @true if the tool is toggled on, @false otherwise.
497 bool GetToolState(int toolId
) const;
500 Returns the number of tools in the toolbar.
502 int GetToolsCount() const;
505 Inserts the control into the toolbar at the given position. You must
506 call Realize() for the change to take place.
508 @see AddControl(), InsertTool()
510 wxToolBarToolBase
* InsertControl(size_t pos
, wxControl
* control
);
513 Inserts the separator into the toolbar at the given position. You must
514 call Realize() for the change to take place.
516 @see AddSeparator(), InsertTool()
518 wxToolBarToolBase
* InsertSeparator(size_t pos
);
522 Inserts the tool with the specified attributes into the toolbar at the
525 You must call Realize() for the change to take place.
527 @see AddTool(), InsertControl(), InsertSeparator()
529 wxToolBarToolBase
* InsertTool(size_t pos
, int toolId
,
530 const wxBitmap
& bitmap1
,
531 const wxBitmap
& bitmap2
= wxNullBitmap
,
532 bool isToggle
= false,
533 wxObject
* clientData
= NULL
,
534 const wxString
& shortHelpString
= "",
535 const wxString
& longHelpString
= "");
536 wxToolBarToolBase
* InsertTool(size_t pos
,
537 wxToolBarToolBase
* tool
);
541 Called when the user clicks on a tool with the left mouse button. This
542 is the old way of detecting tool clicks; although it will still work,
543 you should use the EVT_MENU() or EVT_TOOL() macro instead.
546 The identifier passed to AddTool().
548 @true if the tool is a toggle and the toggle is down, otherwise is
551 @return If the tool is a toggle and this function returns @false, the
552 toggle state (internal and visual) will not be changed. This
553 provides a way of specifying that toggle operations are not
554 permitted in some circumstances.
556 @see OnMouseEnter(), OnRightClick()
558 bool OnLeftClick(int toolId
, bool toggleDown
);
561 This is called when the mouse cursor moves into a tool or out of the
562 toolbar. This is the old way of detecting mouse enter events;
563 although it will still work, you should use the EVT_TOOL_ENTER()
567 Greater than -1 if the mouse cursor has moved into the tool, or -1
568 if the mouse cursor has moved. The programmer can override this to
569 provide extra information about the tool, such as a short
570 description on the status line.
572 @remarks With some derived toolbar classes, if the mouse moves quickly
573 out of the toolbar, wxWidgets may not be able to detect it.
574 Therefore this function may not always be called when expected.
576 void OnMouseEnter(int toolId
);
579 @deprecated This is the old way of detecting tool right clicks;
580 although it will still work, you should use the
581 EVT_TOOL_RCLICKED() macro instead.
583 Called when the user clicks on a tool with the right mouse button. The
584 programmer should override this function to detect right tool clicks.
587 The identifier passed to AddTool().
589 The x position of the mouse cursor.
591 The y position of the mouse cursor.
593 @remarks A typical use of this member might be to pop up a menu.
595 @see OnMouseEnter(), OnLeftClick()
597 void OnRightClick(int toolId
, float x
, float y
);
600 This function should be called after you have added tools.
605 Removes the given tool from the toolbar but doesn't delete it. This
606 allows to insert/add this tool back to this (or another) toolbar later.
608 @note It is unnecessary to call Realize() for the change to take place,
609 it will happen immediately.
614 wxToolBarToolBase
* RemoveTool(int id
);
617 Sets the bitmap resource identifier for specifying tool bitmaps as
618 indices into a custom bitmap. Windows CE only.
620 void SetBitmapResource(int resourceId
);
623 Sets the dropdown menu for the tool given by its @e id. The tool itself
624 will delete the menu when it's no longer needed. Only supported under
627 If you define a EVT_TOOL_DROPDOWN() handler in your program, you must
628 call wxEvent::Skip() from it or the menu won't be displayed.
630 bool SetDropdownMenu(int id
, wxMenu
* menu
);
633 Set the values to be used as margins for the toolbar.
636 Left margin, right margin and inter-tool separation value.
638 Top margin, bottom margin and inter-tool separation value.
640 @remarks This must be called before the tools are added if absolute
641 positioning is to be used, and the default (zero-size) margins are
646 void SetMargins(int x
, int y
);
649 Set the margins for the toolbar.
654 @remarks This must be called before the tools are added if absolute
655 positioning is to be used, and the default (zero-size) margins are
658 @see GetMargins(), wxSize
660 void SetMargins(const wxSize
& size
);
663 Sets the default size of each tool bitmap. The default bitmap size is 16
667 The size of the bitmaps in the toolbar.
669 @remarks This should be called to tell the toolbar what the tool bitmap
670 size is. Call it before you add tools.
672 @see GetToolBitmapSize(), GetToolSize()
674 void SetToolBitmapSize(const wxSize
& size
);
677 Sets the client data associated with the tool.
679 void SetToolClientData(int id
, wxObject
* clientData
);
682 Sets the bitmap to be used by the tool with the given ID when the tool
683 is in a disabled state. This can only be used on Button tools, not
686 @note The native toolbar classes on the main platforms all synthesize
687 the disabled bitmap from the normal bitmap, so this function will
688 have no effect on those platforms.
691 void SetToolDisabledBitmap(int id
, const wxBitmap
& bitmap
);
694 Sets the long help for the given tool.
697 The tool in question.
699 A string for the long help.
701 @remarks You might use the long help for displaying the tool purpose on
704 @see GetToolLongHelp(), SetToolShortHelp(),
706 void SetToolLongHelp(int toolId
, const wxString
& helpString
);
709 Sets the bitmap to be used by the tool with the given ID. This can only
710 be used on Button tools, not controls.
712 void SetToolNormalBitmap(int id
, const wxBitmap
& bitmap
);
715 Sets the value used for spacing tools. The default value is 1.
718 The value for packing.
720 @remarks The packing is used for spacing in the vertical direction if
721 the toolbar is horizontal, and for spacing in the horizontal
722 direction if the toolbar is vertical.
724 @see GetToolPacking()
726 void SetToolPacking(int packing
);
729 Sets the default separator size. The default value is 5.
736 void SetToolSeparation(int separation
);
739 Sets the short help for the given tool.
742 The tool in question.
744 The string for the short help.
746 @remarks An application might use short help for identifying the tool
747 purpose in a tooltip.
750 @see GetToolShortHelp(), SetToolLongHelp()
752 void SetToolShortHelp(int toolId
, const wxString
& helpString
);
755 Toggles a tool on or off. This does not cause any event to get emitted.
760 If @true, toggles the tool on, otherwise toggles it off.
762 @remarks Only applies to a tool that has been specified as a toggle
765 void ToggleTool(int toolId
, bool toggle
);