## 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.

Derived from

wxToolBarBase
wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/toolbar.h> (to allow wxWidgets to select an appropriate toolbar class)
<wx/tbarbase.h> (the base class)

Remarks

You may also create a toolbar that is managed by the frame, by calling wxFrame::CreateToolBar. Under Pocket PC, you should always use this function for creating the toolbar to be managed by the frame, so that wxWidgets can use a combined menubar and toolbar. Where you manage your own toolbars, create a wxToolBar as usual.

The meaning of a "separator" is a vertical line under Windows and simple space under GTK+.

wxToolBar95: Note that this toolbar paints tools to reflect system-wide colours. If you use more than 16 colours in your tool bitmaps, you may wish to suppress this behaviour, otherwise system colours in your bitmaps will inadvertently be mapped to system colours. To do this, set the `msw.remap` system option before creating the toolbar:

      wxSystemOptions::SetOption(wxT("msw.remap"), 0);

If you wish to use 32-bit images (which include an alpha channel for transparency) use:

      wxSystemOptions::SetOption(wxT("msw.remap"), 2);

then colour remapping is switched off, and a transparent background used. But only use this option under Windows XP with true colour:

      (wxTheApp->GetComCtl32Version() >= 600 && ::wxDisplayDepth() >= 32)

Window styles

wxTB_FLAT | Gives the toolbar a flat look (Windows and GTK only).
wxTB_DOCKABLE | Makes the toolbar floatable and dockable (GTK only).
wxTB_HORIZONTAL | Specifies horizontal layout (default).
wxTB_VERTICAL | Specifies vertical layout.
wxTB_TEXT | Shows 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 (border) above the toolbar (Windows only).
wxTB_NOALIGN | Specifies no alignment with the parent window (Windows only, not very useful).
wxTB_HORZ_LAYOUT | Shows the text and the icons alongside, not vertically stacked (Windows and GTK 2 only). This style must be used with wxTB_TEXT.
wxTB_HORZ_TEXT | Combination of wxTB_HORZ_LAYOUT and wxTB_TEXT.
wxTB_NO_TOOLTIPS | Don't show the short help tooltips for the tools when the mouse hovers over them.
wxTB_BOTTOM | Align the toolbar at the bottom of parent window.
wxTB_RIGHT | Align the toolbar at the right side of parent window.

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 way 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 identifier is passed and the tool identifier is retrieved from the wxCommandEvent. This is because the identifier may be -1 when the mouse moves off a tool, and -1 is not allowed as an identifier in the event system.

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 of 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::ClearTools
wxToolBar::DeleteTool
wxToolBar::DeleteToolByPos
wxToolBar::EnableTool
wxToolBar::FindById
wxToolBar::FindControl
wxToolBar::FindToolForPosition
wxToolBar::GetToolsCount
wxToolBar::GetToolSize
wxToolBar::GetToolBitmapSize
wxToolBar::GetMargins
wxToolBar::GetToolClientData
wxToolBar::GetToolEnabled
wxToolBar::GetToolLongHelp
wxToolBar::GetToolPacking
wxToolBar::GetToolPos
wxToolBar::GetToolSeparation
wxToolBar::GetToolShortHelp
wxToolBar::GetToolState
wxToolBar::InsertControl
wxToolBar::InsertSeparator
wxToolBar::InsertTool
wxToolBar::OnLeftClick
wxToolBar::OnMouseEnter
wxToolBar::OnRightClick
wxToolBar::Realize
wxToolBar::RemoveTool
wxToolBar::SetBitmapResource
wxToolBar::SetMargins
wxToolBar::SetToolBitmapSize
wxToolBar::SetToolClientData
wxToolBar::SetToolDisabledBitmap
wxToolBar::SetToolLongHelp
wxToolBar::SetToolPacking
wxToolBar::SetToolShortHelp
wxToolBar::SetToolNormalBitmap
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 wxWidgets 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 wxWidgets 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

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

wxToolBarToolBase* 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`)

wxToolBarToolBase* AddTool(wxToolBarToolBase* tool)

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. The last version allows you to add an existing tool.

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.

bitmap2

The bitmap used when the tool is disabled. If it is equal to wxNullBitmap, the disabled bitmap is automatically generated by greing the normal one.

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.

tool

The tool to be added.

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

wxToolBarToolBase* 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

wxToolBarToolBase* 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::ClearTools

void ClearTools()

Deletes all the tools in the toolbar.

### 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

Some implementations will change the visible state of the tool to indicate that it is disabled.

See also

wxToolBar::GetToolEnabled, wxToolBar::ToggleTool

### wxToolBar::FindById

wxToolBarToolBase* FindById(int id)

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

### 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

wxToolBarToolBase* FindToolForPosition(wxCoord x, wxCoord 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

Currently not implemented in wxGTK (always returns `NULL` there).

### wxToolBar::GetToolsCount

int GetToolsCount() const

Returns the number of tools in the toolbar.

### 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::GetToolPos

int GetToolPos(int toolId) const

Returns the tool position in the toolbar, or `wxNOT_FOUND` if the tool is not found.

### 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

wxToolBarToolBase * 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

wxToolBarToolBase * 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

wxToolBarToolBase * 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 = "")

wxToolBarToolBase * InsertTool(size_t pos, wxToolBarToolBase* tool)

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, wxWidgets 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.

### wxToolBar::RemoveTool

wxToolBarToolBase * 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::SetBitmapResource

void SetBitmapResource(int resourceId)

Sets the bitmap resource identifier for specifying tool bitmaps as indices into a custom bitmap. Windows CE only.

### 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::SetToolDisabledBitmap

void SetToolDisabledBitmap(int id, const wxBitmap& bitmap)

Sets the bitmap to be used by the tool with the given ID when the tool is in a disabled state. This can only be used on Button tools, not controls. NOTE: The native toolbar classes on the main platforms all synthesize the disabled bitmap from the normal bitmap, so this function will have no effect on those platforms.

### 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::SetToolNormalBitmap

void SetToolNormalBitmap(int id, const wxBitmap& bitmap)

Sets the bitmap to be used by the tool with the given ID. This can only be used on Button tools, not controls.

### 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