wxToolBar Class Reference
[Miscellaneous Windows]

#include <wx/toolbar.h>

Inheritance diagram for wxToolBar:

wxControl wxWindow wxEvtHandler wxObject

List of all members.


Detailed Description

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

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:

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

There are several different types of tools you can add to a toolbar. These types are controlled by the wxItemKind enumeration.

Styles:

See also Window Styles. Note that the Win32 native toolbar ignores wxTB_NOICONS style. Also, toggling the wxTB_TEXT works only if the style was initially on.

Events:

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxCommandEvent& event)

Event macros:
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.

Library:  wxCore

Category:  Miscellaneous Windows

See also:
Toolbar Overview

Public Member Functions

 wxToolBar ()
 wxToolBar (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTB_HORIZONTAL|wxBORDER_NONE, const wxString &name=wxPanelNameStr)
virtual ~wxToolBar ()
wxToolBarToolBase * AddCheckTool (int toolId, const wxString &label, const wxBitmap &bitmap1, const wxBitmap &bitmap2, const wxString &shortHelpString="", const wxString &longHelpString="", wxObject *clientData=NULL)
bool AddControl (wxControl *control, const wxString label="")
wxToolBarToolBase * AddRadioTool (int toolId, const wxString &label, const wxBitmap &bitmap1, const wxBitmap &bitmap2, const wxString &shortHelpString="", const wxString &longHelpString="", wxObject *clientData=NULL)
void AddSeparator ()
virtual wxToolBarToolBase * AddTool (wxToolBarToolBase *tool)
wxToolBarToolBase * AddTool (int toolId, const wxString &label, const wxBitmap &bitmap, const wxString &shortHelp=wxEmptyString, wxItemKind kind=wxITEM_NORMAL)
wxToolBarToolBase * AddTool (int toolId, const wxString &label, const wxBitmap &bitmap, const wxBitmap &bmpDisabled=wxNullBitmap, wxItemKind kind=wxITEM_NORMAL, const wxString &shortHelpString=wxEmptyString, const wxString &longHelpString=wxEmptyString, wxObject *clientData=NULL)
virtual void ClearTools ()
virtual bool DeleteTool (int toolId)
virtual bool DeleteToolByPos (size_t pos)
virtual void EnableTool (int toolId, bool enable)
wxToolBarToolBase * FindById (int id) const
virtual wxControlFindControl (int id)
virtual wxToolBarToolBase * FindToolForPosition (wxCoord x, wxCoord y) const
wxSize GetMargins () const
virtual wxSize GetToolBitmapSize () const
virtual wxObjectGetToolClientData (int toolId) const
virtual bool GetToolEnabled (int toolId) const
virtual wxString GetToolLongHelp (int toolId) const
virtual int GetToolPacking () const
virtual int GetToolPos (int toolId) const
virtual int GetToolSeparation () const
virtual wxString GetToolShortHelp (int toolId) const
virtual wxSize GetToolSize () const
virtual bool GetToolState (int toolId) const
int GetToolsCount () const
wxToolBarToolBase * InsertControl (size_t pos, wxControl *control)
virtual wxToolBarToolBase * InsertSeparator (size_t pos)
virtual bool OnLeftClick (int toolId, bool toggleDown)
virtual void OnMouseEnter (int toolId)
void OnRightClick (int toolId, float x, float y)
virtual bool Realize ()
virtual wxToolBarToolBase * RemoveTool (int id)
void SetBitmapResource (int resourceId)
bool SetDropdownMenu (int id, wxMenu *menu)
virtual void SetMargins (int x, int y)
void SetMargins (const wxSize &size)
virtual void SetToolBitmapSize (const wxSize &size)
virtual void SetToolClientData (int id, wxObject *clientData)
virtual void SetToolDisabledBitmap (int id, const wxBitmap &bitmap)
virtual void SetToolLongHelp (int toolId, const wxString &helpString)
virtual void SetToolNormalBitmap (int id, const wxBitmap &bitmap)
virtual void SetToolPacking (int packing)
virtual void SetToolSeparation (int separation)
virtual void SetToolShortHelp (int toolId, const wxString &helpString)
virtual void ToggleTool (int toolId, bool toggle)
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)

Constructor & Destructor Documentation

wxToolBar::wxToolBar (  ) 

Default constructor.

wxToolBar::wxToolBar ( wxWindow parent,
wxWindowID  id,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
long  style = wxTB_HORIZONTAL|wxBORDER_NONE,
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 AddTool() and perhaps AddSeparator(), and then you must call Realize() to construct and display the toolbar tools.

virtual wxToolBar::~wxToolBar (  )  [virtual]

Toolbar destructor.


Member Function Documentation

wxToolBarToolBase* wxToolBar::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 AddTool().

See also:
AddTool()

bool wxToolBar::AddControl ( wxControl control,
const wxString  label = "" 
)

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

Parameters:
control The control to be added.
label Text to be displayed near the control.
Remarks:
wxMSW: the label is only displayed if there is enough space available below the embedded control.

wxMac: labels are only displayed if wxWidgets is built with wxMAC_USE_NATIVE_TOOLBAR set to 1

wxToolBarToolBase* wxToolBar::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:
AddTool()

void wxToolBar::AddSeparator (  ) 

Adds a separator for spacing groups of tools.

See also:
AddTool(), SetToolSeparation()

virtual wxToolBarToolBase* wxToolBar::AddTool ( wxToolBarToolBase *  tool  )  [virtual]

Adds a tool to the toolbar.

Parameters:
tool The tool to be added.
Remarks:
After you have added tools to a toolbar, you must call Realize() in order to have the tools appear.
See also:
AddSeparator(), AddCheckTool(), AddRadioTool(), InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()

wxToolBarToolBase* wxToolBar::AddTool ( int  toolId,
const wxString label,
const wxBitmap bitmap,
const wxString shortHelp = wxEmptyString,
wxItemKind  kind = wxITEM_NORMAL 
)

Adds a tool to the toolbar. This most commonly used version has fewer parameters than the full version below which specifies the more rarely used button features.

Parameters:
toolId An integer by which the tool may be identified in subsequent operations.
label The string to be displayed with the tool.
bitmap The primary tool bitmap.
shortHelp This string is used for the tools tooltip.
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. wxITEM_DROPDOWN specifies that a drop-down menu button will appear next to the tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
Remarks:
After you have added tools to a toolbar, you must call Realize() in order to have the tools appear.
See also:
AddSeparator(), AddCheckTool(), AddRadioTool(), InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()

wxToolBarToolBase* wxToolBar::AddTool ( int  toolId,
const wxString label,
const wxBitmap bitmap,
const wxBitmap bmpDisabled = wxNullBitmap,
wxItemKind  kind = wxITEM_NORMAL,
const wxString shortHelpString = wxEmptyString,
const wxString longHelpString = wxEmptyString,
wxObject clientData = NULL 
)

Adds a tool to the toolbar.

Parameters:
toolId An integer by which the tool may be identified in subsequent operations.
label The string to be displayed with the tool.
bitmap The primary tool bitmap.
bmpDisabled The bitmap used when the tool is disabled. If it is equal to wxNullBitmap (default), the disabled bitmap is automatically generated by greying 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.
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. wxITEM_DROPDOWN specifies that a drop-down menu button will appear next to the tool button (only GTK+ and MSW). Call SetDropdownMenu() afterwards.
clientData An optional pointer to client data which can be retrieved later using GetToolClientData().
Remarks:
After you have added tools to a toolbar, you must call Realize() in order to have the tools appear.
See also:
AddSeparator(), AddCheckTool(), AddRadioTool(), InsertTool(), DeleteTool(), Realize(), SetDropdownMenu()

virtual void wxToolBar::ClearTools (  )  [virtual]

Deletes all the tools in the toolbar.

virtual bool wxToolBar::DeleteTool ( int  toolId  )  [virtual]

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:
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()

virtual bool wxToolBar::DeleteToolByPos ( size_t  pos  )  [virtual]

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

virtual void wxToolBar::EnableTool ( int  toolId,
bool  enable 
) [virtual]

Enables or disables the tool.

Parameters:
toolId Tool to enable or disable.
enable If true, enables the tool, otherwise disables it.
Remarks:
Some implementations will change the visible state of the tool to indicate that it is disabled.
See also:
GetToolEnabled(), ToggleTool()

wxToolBarToolBase* wxToolBar::FindById ( int  id  )  const

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

virtual wxControl* wxToolBar::FindControl ( int  id  )  [virtual]

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

virtual wxToolBarToolBase* wxToolBar::FindToolForPosition ( wxCoord  x,
wxCoord  y 
) const [virtual]

Finds a tool for the given mouse position.

Parameters:
x X position.
y Y position.
Returns:
A pointer to a tool if a tool is found, or NULL otherwise.
Remarks:
Currently not implemented in wxGTK (always returns NULL there).

wxSize wxToolBar::GetMargins (  )  const

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

See also:
SetMargins()

virtual wxSize wxToolBar::GetToolBitmapSize (  )  const [virtual]

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 AddTool(), and not the eventual size of the tool button.
See also:
SetToolBitmapSize(), GetToolSize()

virtual wxObject* wxToolBar::GetToolClientData ( int  toolId  )  const [virtual]

Get any client data associated with the tool.

Parameters:
toolId Id of the tool, as passed to AddTool().
Returns:
Client data, or NULL if there is none.

virtual bool wxToolBar::GetToolEnabled ( int  toolId  )  const [virtual]

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

Parameters:
toolId Id of the tool in question.
Returns:
true if the tool is enabled, false otherwise.
See also:
EnableTool()

virtual wxString wxToolBar::GetToolLongHelp ( int  toolId  )  const [virtual]

Returns the long help for the given tool.

Parameters:
toolId The tool in question.
See also:
SetToolLongHelp(), SetToolShortHelp()

virtual int wxToolBar::GetToolPacking (  )  const [virtual]

Returns the value used for packing tools.

See also:
SetToolPacking()

virtual int wxToolBar::GetToolPos ( int  toolId  )  const [virtual]

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

virtual int wxToolBar::GetToolSeparation (  )  const [virtual]

Returns the default separator size.

See also:
SetToolSeparation()

virtual wxString wxToolBar::GetToolShortHelp ( int  toolId  )  const [virtual]

Returns the short help for the given tool.

Parameters:
toolId The tool in question.
See also:
GetToolLongHelp(), SetToolShortHelp()

virtual wxSize wxToolBar::GetToolSize (  )  const [virtual]

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

See also:
SetToolBitmapSize(), GetToolBitmapSize()

virtual bool wxToolBar::GetToolState ( int  toolId  )  const [virtual]

Gets the on/off state of a toggle tool.

Parameters:
toolId The tool in question.
Returns:
true if the tool is toggled on, false otherwise.
See also:
ToggleTool()

int wxToolBar::GetToolsCount (  )  const

Returns the number of tools in the toolbar.

wxToolBarToolBase* wxToolBar::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()

virtual wxToolBarToolBase* wxToolBar::InsertSeparator ( size_t  pos  )  [virtual]

Inserts the separator into the toolbar at the given position. You must call Realize() for the change to take place.

See also:
AddSeparator(), InsertTool()

wxToolBarToolBase* wxToolBar::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()

wxToolBarToolBase* wxToolBar::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()

virtual bool wxToolBar::OnLeftClick ( int  toolId,
bool  toggleDown 
) [virtual]

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 AddTool().
toggleDown true if the tool is a toggle and the toggle is down, otherwise is false.
Returns:
If the tool is a toggle and this function returns false, the 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:
OnMouseEnter(), OnRightClick()

virtual void wxToolBar::OnMouseEnter ( int  toolId  )  [virtual]

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.

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

Deprecated:
This is the old way of detecting tool right clicks; although it will still work, you should use the EVT_TOOL_RCLICKED() macro instead.
Called when the user clicks on a tool with the right mouse button. The programmer should override this function to detect right tool clicks.

Parameters:
toolId The identifier passed to 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:
OnMouseEnter(), OnLeftClick()

virtual bool wxToolBar::Realize (  )  [virtual]

This function should be called after you have added tools.

virtual wxToolBarToolBase* wxToolBar::RemoveTool ( int  id  )  [virtual]

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:
It is unnecessary to call Realize() for the change to take place, it will happen immediately.
See also:
DeleteTool()

void wxToolBar::SetBitmapResource ( int  resourceId  ) 

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

bool wxToolBar::SetDropdownMenu ( int  id,
wxMenu menu 
)

Sets the dropdown menu for the tool given by its id. The tool itself will delete the menu when it's no longer needed. Only supported under GTK+ und MSW.

If you define a EVT_TOOL_DROPDOWN() handler in your program, you must call wxEvent::Skip() from it or the menu won't be displayed.

virtual void wxToolBar::SetMargins ( int  x,
int  y 
) [virtual]

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

Parameters:
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:
GetMargins()

void wxToolBar::SetMargins ( const wxSize size  ) 

Set the margins for the toolbar.

Parameters:
size Margin size.
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:
GetMargins(), wxSize

virtual void wxToolBar::SetToolBitmapSize ( const wxSize size  )  [virtual]

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.
See also:
GetToolBitmapSize(), GetToolSize()

virtual void wxToolBar::SetToolClientData ( int  id,
wxObject clientData 
) [virtual]

Sets the client data associated with the tool.

virtual void wxToolBar::SetToolDisabledBitmap ( int  id,
const wxBitmap bitmap 
) [virtual]

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.

virtual void wxToolBar::SetToolLongHelp ( int  toolId,
const wxString helpString 
) [virtual]

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:
GetToolLongHelp(), SetToolShortHelp(),

virtual void wxToolBar::SetToolNormalBitmap ( int  id,
const wxBitmap bitmap 
) [virtual]

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

virtual void wxToolBar::SetToolPacking ( int  packing  )  [virtual]

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:
GetToolPacking()

virtual void wxToolBar::SetToolSeparation ( int  separation  )  [virtual]

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

Parameters:
separation The separator size.
See also:
AddSeparator()

virtual void wxToolBar::SetToolShortHelp ( int  toolId,
const wxString helpString 
) [virtual]

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:
GetToolShortHelp(), SetToolLongHelp()

virtual void wxToolBar::ToggleTool ( int  toolId,
bool  toggle 
) [virtual]

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.



wxWidgets logo

[ top ]