## wxToolBar

The name wxToolBar is defined to be a synonym for one of the following classes:

- wxToolBar95 The native Windows 95 toolbar. Used on Windows 95, NT 4 and above.
- wxToolBarMSW A Windows implementation. Used on 16-bit Windows.
- wxToolBarGTK The GTK toolbar.
- wxToolBarSimple A simple implementation, with scrolling. Used on platforms with no native toolbar control, or where scrolling is required.

Note that the base class wxToolBarBase defines automatic scrolling management functionality which is similar to wxScrolledWindow, so please refer to this class also. Not all toolbars support scrolling, but wxToolBarSimple does.

Derived from

wxToolBarBase
wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/toolbar.h> (to allow wxWindows to select an appropriate toolbar class)
<wx/tbarbase.h> (the base class)
<wx/tbarmsw.h> (the non-Windows 95 Windows toolbar class)
<wx/tbar95.h> (the Windows 95/98 toolbar class)
<wx/tbarsmpl.h> (the generic simple toolbar class)

Remarks

You may also create a toolbar that is managed by the frame, by calling wxFrame::CreateToolBar.

Due to the use of native toolbars on the various platforms, certain adaptions will often have to be made in order to get optimal look on all platforms as some platforms ignore the values for explicit placement and use their own layout and the meaning of a "separator" is a vertical line under Windows95 vs. simple space under GTK etc.

wxToolBar95: Note that this toolbar paints tools to reflect user-selected colours.

Window styles

wxTB_FLAT | Gives the toolbar a flat look ('coolbar' or 'flatbar' style). Windows 95 and GTK 1.2 only.
wxTB_DOCKABLE | Makes the toolbar floatable and dockable. GTK only.
wxTB_HORIZONTAL | Specifies horizontal layout.
wxTB_VERTICAL | Specifies vertical layout (not available for the GTK and Windows 95 toolbar).
wxTB_3DBUTTONS | Gives wxToolBarSimple a mild 3D look to its buttons.
wxTB_TEXT | Show the text in the toolbar buttons; by default only icons are shown.
wxTB_NOICONS | Specifies no icons in the toolbar buttons; by default they are shown.
wxTB_NODIVIDER | Specifies no divider above the toolbar; by default it is shown. Windows only.
wxTB_NOALIGN | Specifies no alignment with the parent window. Windows only.

See also window styles overview. Note that the Win32 native toolbar ignores `wxTB_NOICONS` style. Also, toggling the `wxTB_TEXT` works only if the style was initially on.

Event handling

The toolbar class emits menu commands in the same was that a frame menubar does, so you can use one EVT_MENU macro for both a menu item and a toolbar button. The event handler functions take a wxCommandEvent argument. For most event macros, the identifier of the tool is passed, but for EVT_TOOL_ENTER the toolbar window is passed and the tool id is retrieved from the wxCommandEvent. This is because the id may be -1 when the mouse moves off a tool, and -1 is not allowed as an identifier in the event system.

Note that tool commands (and UI update events for tools) are first sent to the focus window within the frame that contains the toolbar. If no window within the frame has the focus, then the events are sent directly to the toolbar (and up the hierarchy to the frame, depending on where the application has put its event handlers). This allows command and UI update handling to be processed by specific windows and controls, and not necessarily by the application frame.

EVT_TOOL(id, func) | Process a wxEVT_COMMAND_TOOL_CLICKED event (a synonym for wxEVT_COMMAND_MENU_SELECTED). Pass the id of the tool.
EVT_MENU(id, func) | The same as EVT_TOOL.
EVT_TOOL_RANGE(id1, id2, func) | Process a wxEVT_COMMAND_TOOL_CLICKED event for a range id identifiers. Pass the ids of the tools.
EVT_MENU_RANGE(id1, id2, func) | The same as EVT_TOOL_RANGE.

EVT_TOOL_RCLICKED(id, func) | Process a wxEVT_COMMAND_TOOL_RCLICKED event. Pass the id of the tool.
EVT_TOOL_RCLICKED_RANGE(id1, id2, func) | Process a wxEVT_COMMAND_TOOL_RCLICKED event for a range of ids. Pass the ids of the tools.
EVT_TOOL_ENTER(id, func) | Process a wxEVT_COMMAND_TOOL_ENTER event. Pass the id of the toolbar itself. The value of wxCommandEvent::GetSelection is the tool id, or -1 if the mouse cursor has moved off a tool.

See also

Toolbar overview, wxScrolledWindow

Members

wxToolBar::wxToolBar
wxToolBar::~wxToolBar
wxToolBar::AddControl
wxToolBar::AddSeparator
wxToolBar::AddTool
wxToolBar::AddCheckTool
wxToolBar::AddRadioTool
wxToolBar::DeleteTool
wxToolBar::DeleteToolByPos
wxToolBar::EnableTool
wxToolBar::FindControl
wxToolBar::FindToolForPosition
wxToolBar::GetToolSize
wxToolBar::GetToolBitmapSize
wxToolBar::GetMargins
wxToolBar::GetToolClientData
wxToolBar::GetToolEnabled
wxToolBar::GetToolLongHelp
wxToolBar::GetToolPacking
wxToolBar::GetToolSeparation
wxToolBar::GetToolShortHelp
wxToolBar::GetToolState
wxToolBar::InsertControl
wxToolBar::InsertSeparator
wxToolBar::InsertTool
wxToolBar::OnLeftClick
wxToolBar::OnMouseEnter
wxToolBar::OnRightClick
wxToolBar::Realize
wxToolBar::RemoveTool
wxToolBar::SetMargins
wxToolBar::SetToolBitmapSize
wxToolBar::SetToolClientData
wxToolBar::SetToolLongHelp
wxToolBar::SetToolPacking
wxToolBar::SetToolShortHelp
wxToolBar::SetToolSeparation
wxToolBar::ToggleTool

### wxToolBar::wxToolBar

wxToolBar()

Default constructor.

wxToolBar(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTB_HORIZONTAL | wxNO_BORDER, const wxString& name = wxPanelNameStr)

Constructs a toolbar.

Parameters

parent

Pointer to a parent window.

id

Window identifier. If -1, will automatically create an identifier.

pos

Window position. wxDefaultPosition is (-1, -1) which indicates that wxWindows should generate a default position for the window. If using the wxWindow class directly, supply an actual position.

size

Window size. wxDefaultSize is (-1, -1) which indicates that wxWindows should generate a default size for the window.

style

Window style. See wxToolBar for details.

name

Window name.

Remarks

After a toolbar is created, you use wxToolBar::AddTool and perhaps wxToolBar::AddSeparator, and then you must call wxToolBar::Realize to construct and display the toolbar tools.

You may also create a toolbar that is managed by the frame, by calling wxFrame::CreateToolBar.

### wxToolBar::~wxToolBar

void ~wxToolBar()

Toolbar destructor.

### wxToolBar::AddControl

bool AddControl(wxControl* control)

Adds any control to the toolbar, typically e.g. a combobox.

control

The control to be added.

### wxToolBar::AddSeparator

void AddSeparator()

Adds a separator for spacing groups of tools.

See also

wxToolBar::AddTool, wxToolBar::SetToolSeparation

### wxToolBar::AddTool

wxToolBarTool* AddTool(int toolId, const wxString& label, const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)

wxToolBarTool* AddTool(int toolId, const wxString& label, const wxBitmap& bitmap1, const wxBitmap& bitmap2 = wxNullBitmap, wxItemKind kind = wxITEM_NORMAL, const wxString& shortHelpString = "", const wxString& longHelpString = "", wxObject* clientData = NULL)

Adds a tool to the toolbar. The first (short and most commonly used) version has fewer parameters than the full version at the price of not being able to specify some of the more rarely used button features.

Parameters

toolId

An integer by which the tool may be identified in subsequent operations.

kind

May be wxITEM_NORMAL for a normal button (default), wxITEM_CHECK for a checkable tool (such tool stays pressed after it had been toggled) or wxITEM_RADIO for a checkable tool which makes part of a radio group of tools each of which is automatically unchecked whenever another button in the group is checked

bitmap1

The primary tool bitmap for toggle and button tools.

bitmap2

The second bitmap specifies the on-state bitmap for a toggle tool. If this is wxNullBitmap, either an inverted version of the primary bitmap is used for the on-state of a toggle tool (monochrome displays) or a black border is drawn around the tool (colour displays) or the pixmap is shown as a pressed button (GTK).

shortHelpString

This string is used for the tools tooltip

longHelpString

This string is shown in the statusbar (if any) of the parent frame when the mouse pointer is inside the tool

clientData

An optional pointer to client data which can be retrieved later using wxToolBar::GetToolClientData.

Remarks

After you have added tools to a toolbar, you must call wxToolBar::Realize in order to have the tools appear.

See also

wxToolBar::AddSeparator, wxToolBar::AddCheckTool, wxToolBar::AddRadioTool, wxToolBar::InsertTool, wxToolBar::DeleteTool, wxToolBar::Realize

### wxToolBar::AddCheckTool

wxToolBarTool* AddCheckTool(int toolId, const wxString& label, const wxBitmap& bitmap1, const wxBitmap& bitmap2, const wxString& shortHelpString = "", const wxString& longHelpString = "", wxObject* clientData = NULL)

Adds a new check (or toggle) tool to the toolbar. The parameters are the same as in wxToolBar::AddTool.

See also

wxToolBar::AddTool

### wxToolBar::AddRadioTool

wxToolBarTool* AddRadioTool(int toolId, const wxString& label, const wxBitmap& bitmap1, const wxBitmap& bitmap2, const wxString& shortHelpString = "", const wxString& longHelpString = "", wxObject* clientData = NULL)

Adds a new radio tool to the toolbar. Consecutive radio tools form a radio group such that exactly one button in the group is pressed at any moment, in other words whenever a button in the group is pressed the previously pressed button is automatically released. You should avoid having the radio groups of only one element as it would be impossible for the user to use such button.

By default, the first button in the radio group is initially pressed, the others are not.

See also

wxToolBar::AddTool

### wxToolBar::DeleteTool

bool DeleteTool(int toolId)

Removes the specified tool from the toolbar and deletes it. If you don't want to delete the tool, but just to remove it from the toolbar (to possibly add it back later), you may use RemoveTool instead.

Note that it is unnecessary to call Realize for the change to take place, it will happen immediately.

Returns TRUE if the tool was deleted, FALSE otherwise.

See also

DeleteToolByPos

### wxToolBar::DeleteToolByPos

bool DeleteToolByPos(size_t pos)

This function behaves like DeleteTool but it deletes the tool at the specified position and not the one with the given id.

### wxToolBar::EnableTool

void EnableTool(int toolId, const bool enable)

Enables or disables the tool.

Parameters

toolId

Tool to enable or disable.

enable

If TRUE, enables the tool, otherwise disables it.

NB: This function should only be called after Realize.

Remarks

For wxToolBarSimple, does nothing. Some other implementations will change the visible state of the tool to indicate that it is disabled.

See also

wxToolBar::GetToolEnabled, wxToolBar::ToggleTool

### wxToolBar::FindControl

wxControl* FindControl(int id)

Returns a pointer to the control identified by id or NULL if no corresponding control is found.

### wxToolBar::FindToolForPosition

wxToolBarTool* FindToolForPosition(const float x, const float y) const

Finds a tool for the given mouse position.

Parameters

x

X position.

y

Y position.

Return value

A pointer to a tool if a tool is found, or NULL otherwise.

Remarks

Used internally, and should not need to be used by the programmer.

### wxToolBar::GetToolSize

wxSize GetToolSize()

Returns the size of a whole button, which is usually larger than a tool bitmap because of added 3D effects.

See also

wxToolBar::SetToolBitmapSize, wxToolBar::GetToolBitmapSize

### wxToolBar::GetToolBitmapSize

wxSize GetToolBitmapSize()

Returns the size of bitmap that the toolbar expects to have. The default bitmap size is 16 by 15 pixels.

Remarks

Note that this is the size of the bitmap you pass to wxToolBar::AddTool, and not the eventual size of the tool button.

See also

wxToolBar::SetToolBitmapSize, wxToolBar::GetToolSize

### wxToolBar::GetMargins

wxSize GetMargins() const

Returns the left/right and top/bottom margins, which are also used for inter-toolspacing.

See also

wxToolBar::SetMargins

### wxToolBar::GetToolClientData

wxObject* GetToolClientData(int toolId) const

Get any client data associated with the tool.

Parameters

toolId

Id of the tool, as passed to wxToolBar::AddTool.

Return value

Client data, or NULL if there is none.

### wxToolBar::GetToolEnabled

bool GetToolEnabled(int toolId) const

Called to determine whether a tool is enabled (responds to user input).

Parameters

toolId

Id of the tool in question.

Return value

TRUE if the tool is enabled, FALSE otherwise.

See also

wxToolBar::EnableTool

### wxToolBar::GetToolLongHelp

wxString GetToolLongHelp(int toolId) const

Returns the long help for the given tool.

Parameters

toolId

The tool in question.

See also

wxToolBar::SetToolLongHelp, wxToolBar::SetToolShortHelp

### wxToolBar::GetToolPacking

int GetToolPacking() const

Returns the value used for packing tools.

See also

wxToolBar::SetToolPacking

### wxToolBar::GetToolSeparation

int GetToolSeparation() const

Returns the default separator size.

See also

wxToolBar::SetToolSeparation

### wxToolBar::GetToolShortHelp

wxString GetToolShortHelp(int toolId) const

Returns the short help for the given tool.

Parameters

toolId

The tool in question.

See also

wxToolBar::GetToolLongHelp, wxToolBar::SetToolShortHelp

### wxToolBar::GetToolState

bool GetToolState(int toolId) const

Gets the on/off state of a toggle tool.

Parameters

toolId

The tool in question.

Return value

TRUE if the tool is toggled on, FALSE otherwise.

See also

wxToolBar::ToggleTool

### wxToolBar::InsertControl

wxToolBarTool * InsertControl(size_t pos, wxControl *control)

Inserts the control into the toolbar at the given position.

You must call Realize for the change to take place.

See also

AddControl,
InsertTool

### wxToolBar::InsertSeparator

wxToolBarTool * InsertSeparator(size_t pos)

Inserts the separator into the toolbar at the given position.

You must call Realize for the change to take place.

See also

AddSeparator,
InsertTool

### wxToolBar::InsertTool

wxToolBarTool * InsertTool(size_t pos, int toolId, const wxBitmap& bitmap1, const wxBitmap& bitmap2 = wxNullBitmap, bool isToggle = FALSE, wxObject* clientData = NULL, const wxString& shortHelpString = "", const wxString& longHelpString = "")

Inserts the tool with the specified attributes into the toolbar at the given position.

You must call Realize for the change to take place.

See also

AddTool,
InsertControl,
InsertSeparator

### wxToolBar::OnLeftClick

bool OnLeftClick(int toolId, bool toggleDown)

Called when the user clicks on a tool with the left mouse button.

This is the old way of detecting tool clicks; although it will still work, you should use the EVT_MENU or EVT_TOOL macro instead.

Parameters

toolId

The identifier passed to wxToolBar::AddTool.

toggleDown

TRUE if the tool is a toggle and the toggle is down, otherwise is FALSE.

Return value

If the tool is a toggle and this function returns FALSE, the toggle toggle state (internal and visual) will not be changed. This provides a way of specifying that toggle operations are not permitted in some circumstances.

See also

wxToolBar::OnMouseEnter, wxToolBar::OnRightClick

### wxToolBar::OnMouseEnter

void OnMouseEnter(int toolId)

This is called when the mouse cursor moves into a tool or out of the toolbar.

This is the old way of detecting mouse enter events; although it will still work, you should use the EVT_TOOL_ENTER macro instead.

Parameters

toolId

Greater than -1 if the mouse cursor has moved into the tool, or -1 if the mouse cursor has moved. The programmer can override this to provide extra information about the tool, such as a short description on the status line.

Remarks

With some derived toolbar classes, if the mouse moves quickly out of the toolbar, wxWindows may not be able to detect it. Therefore this function may not always be called when expected.

### wxToolBar::OnRightClick

void OnRightClick(int toolId, float x, float y)

Called when the user clicks on a tool with the right mouse button. The programmer should override this function to detect right tool clicks.

This is the old way of detecting tool right clicks; although it will still work, you should use the EVT_TOOL_RCLICKED macro instead.

Parameters

toolId

The identifier passed to wxToolBar::AddTool.

x

The x position of the mouse cursor.

y

The y position of the mouse cursor.

Remarks

A typical use of this member might be to pop up a menu.

See also

wxToolBar::OnMouseEnter, wxToolBar::OnLeftClick

### wxToolBar::Realize

bool Realize()

This function should be called after you have added tools.

If you are using absolute positions for your tools when using a wxToolBarSimple object, do not call this function. You must call it at all other times.

### wxToolBar::RemoveTool

wxToolBarTool * RemoveTool(int id)

Removes the given tool from the toolbar but doesn't delete it. This allows to insert/add this tool back to this (or another) toolbar later.

Note that it is unnecessary to call Realize for the change to take place, it will happen immediately.

See also

DeleteTool

### wxToolBar::SetMargins

void SetMargins(const wxSize& size)

void SetMargins(int x, int y)

Set the values to be used as margins for the toolbar.

Parameters

size

Margin size.

x

Left margin, right margin and inter-tool separation value.

y

Top margin, bottom margin and inter-tool separation value.

Remarks

This must be called before the tools are added if absolute positioning is to be used, and the default (zero-size) margins are to be overridden.

See also

wxToolBar::GetMargins, wxSize

### wxToolBar::SetToolBitmapSize

void SetToolBitmapSize(const wxSize& size)

Sets the default size of each tool bitmap. The default bitmap size is 16 by 15 pixels.

Parameters

size

The size of the bitmaps in the toolbar.

Remarks

This should be called to tell the toolbar what the tool bitmap size is. Call it before you add tools.

Note that this is the size of the bitmap you pass to wxToolBar::AddTool, and not the eventual size of the tool button.

See also

wxToolBar::GetToolBitmapSize, wxToolBar::GetToolSize

### wxToolBar::SetToolClientData

void SetToolClientData(int id, wxObject* clientData)

Sets the client data associated with the tool.

### wxToolBar::SetToolLongHelp

void SetToolLongHelp(int toolId, const wxString& helpString)

Sets the long help for the given tool.

Parameters

toolId

The tool in question.

helpString

A string for the long help.

Remarks

You might use the long help for displaying the tool purpose on the status line.

See also

wxToolBar::GetToolLongHelp, wxToolBar::SetToolShortHelp,

### wxToolBar::SetToolPacking

void SetToolPacking(int packing)

Sets the value used for spacing tools. The default value is 1.

Parameters

packing

The value for packing.

Remarks

The packing is used for spacing in the vertical direction if the toolbar is horizontal, and for spacing in the horizontal direction if the toolbar is vertical.

See also

wxToolBar::GetToolPacking

### wxToolBar::SetToolShortHelp

void SetToolShortHelp(int toolId, const wxString& helpString)

Sets the short help for the given tool.

Parameters

toolId

The tool in question.

helpString

The string for the short help.

Remarks

An application might use short help for identifying the tool purpose in a tooltip.

See also

wxToolBar::GetToolShortHelp, wxToolBar::SetToolLongHelp

### wxToolBar::SetToolSeparation

void SetToolSeparation(int separation)

Sets the default separator size. The default value is 5.

Parameters

separation

The separator size.

See also

wxToolBar::AddSeparator

### wxToolBar::ToggleTool

void ToggleTool(int toolId, const bool toggle)

Toggles a tool on or off. This does not cause any event to get emitted.

Parameters

toolId

Tool in question.

toggle

If TRUE, toggles the tool on, otherwise toggles it off.

Remarks

Only applies to a tool that has been specified as a toggle tool.

See also

wxToolBar::GetToolState