A ToolBar is a collection of graphical buttons and/or controls which is attached to the edge of a Wx::Frame. It provides quick access to one-step application functions, such as opening or saving a file, or cutting and pasting text.
It has a native style on all platforms; note that on OS X, native toolbars may only be placed at the top of a Frame. Use Frame#set_tool_bar to set a toolbar to be managed by a Frame and ensure native appearance.
You may also create a toolbar that is managed by the frame, by calling Frame#create_tool_bar. Under Pocket PC, you should always use this function for creating the toolbar to be managed by the frame, so that Widgets can use a combined menubar and toolbar. Where you manage your own toolbars, create a ToolBar as usual.
The meaning of a “separator” is a vertical line under Windows and simple space under GTK+.
TB_FLAT |
Gives the toolbar a flat look (Windows and GTK only). |
TB_DOCKABLE |
Makes the toolbar floatable and dockable (GTK only). |
TB_HORIZONTAL |
Specifies horizontal layout (default). |
TB_VERTICAL |
Specifies vertical layout. |
TB_TEXT |
Shows the text in the toolbar buttons; by default only icons are shown. |
TB_NOICONS |
Specifies no icons in the toolbar buttons; by default they are shown. |
TB_NODIVIDER |
Specifies no divider (border) above the toolbar (Windows only). |
TB_NOALIGN |
Specifies no alignment with the parent window (Windows only, not very useful). |
TB_HORZ_LAYOUT |
Shows the text and the icons alongside, not vertically stacked (Windows and GTK2 only). This style must be used with TB_TEXT. |
TB_HORZ_TEXT |
Combination of TB_HORZ_LAYOUT and TB_TEXT. |
TB_NO_TOOLTIPS |
Don’t show the short help tooltips for the tools when the mouse hovers over them. |
TB_BOTTOM |
Align the toolbar at the bottom of parent window. |
TB_RIGHT |
Align the toolbar at the right side of parent window. |
See also window styles overview. Note that the Win32
native toolbar ignores TB_NOICONS style. Also, toggling the
TB_TEXT works only if the style was initially on.
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 CommandEvent 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 CommandEvent. 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) { | event | ... } | Process a EVT_COMMAND_TOOL_CLICKED event(a synonym for EVT_COMMAND_MENU_SELECTED). Pass the id of the tool. |
| evt_menu(id) { | event | ... } | The same as EVT_TOOL. |
| EVT_TOOL_RANGE(id1, id2, func) | Process a EVT_COMMAND_TOOL_CLICKED eventfor 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) { | event | ... } | Process a EVT_COMMAND_TOOL_RCLICKED event.Pass the id of the tool. |
| EVT_TOOL_RCLICKED_RANGE(id1, id2, func) | Process a EVT_COMMAND_TOOL_RCLICKED eventfor a range of ids. Pass the ids of the tools. |
| evt_tool_enter(id) { | event | ... } | Process a EVT_COMMAND_TOOL_ENTER event.Pass the id of the toolbar itself. The value of CommandEvent::GetSelection is the tool id, or -1 if the mouse cursor has moved off a tool. |
Toolbar overviewwxtoolbaroverview, ScrolledWindow
ToolBar.new(Window parent, Integer id,
Point pos = DEFAULT_POSITION,
Size size = DEFAULT_SIZE,
Integer style = TB_HORIZONTAL NO_BORDER,
String name = PanelNameStr)
Constructs a toolbar.
After a toolbar is created, you use ToolBar#add_tool and perhaps ToolBar#add_separator, and then you must call ToolBar#realize to construct and display the toolbar tools.
You may also create a toolbar that is managed by the frame, by calling Frame#create_tool_bar.
destructor()
Toolbar destructor.
Boolean add_control(Control control)
Adds any control to the toolbar, typically e.g. a combobox.
add_separator()
Adds a separator for spacing groups of tools.
ToolBar#add_tool, ToolBar#set_tool_separation
ToolBarTool add_item(Bitmap bitmap1,
Bitmap bitmap2 = NULL_BITMAP,
Integer position = -1,
Integer id = -1,
String label ='',
ItemKind kind = ITEM_NORMAL,
String short_help = '',
String long_help = '',
Object client_data = nil)
Adds or inserts a tool to the toolbar. Returns a ToolBarTool object with information about the newly added item. Optional parameters may also be specified by keywords in any order as following : tool = toolbar.add_item(a_bitmap, :position => 1, :label => “My Button”)
After you have added tools to a toolbar, you must call ToolBar#realize in order to have the tools appear.
ToolBar#add_separator, ToolBar#add_tool, ToolBar#add_check_tool, ToolBar#add_radio_tool, ToolBar#insert_tool, ToolBar#delete_tool, ToolBar#realize
ToolBarTool add_tool(Integer toolId,
String label,
Bitmap bitmap1,
String shortHelpString = "",
ItemKind kind = ITEM_NORMAL)
ToolBarTool add_tool(Integer toolId,
String label,
Bitmap bitmap1,
Bitmap bitmap2 = NullBitmap,
ItemKind kind = ITEM_NORMAL,
String shortHelpString = "",
String longHelpString = "",
Object clientData = nil)
Adds a tool to the toolbar. Returns a ToolBarTool object with information about the newly added item.
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.
After you have added tools to a toolbar, you must call ToolBar#realize in order to have the tools appear.
ToolBar#add_separator, ToolBar#add_check_tool, ToolBar#add_radio_tool, ToolBar#insert_tool, ToolBar#delete_tool, ToolBar#realize
ToolBarTool add_check_tool(Integer toolId,
String label,
Bitmap bitmap1,
Bitmap bitmap2,
String shortHelp = "",
String longHelp = "",
Object clientData = nil)
Adds a new check (or toggle) tool to the toolbar. The parameters are the same as in ToolBar#add_tool.
ToolBarTool add_radio_tool(Integer toolId,
String label,
Bitmap bitmap1,
Bitmap bitmap2,
String shortHelpString = "",
String longHelpString = "",
Object clientData = nil)
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.
clear_tools()
Deletes all the tools in the toolbar.
Boolean delete_tool(Integer 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 remove_tool 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.
Boolean delete_tool_by_pos(Integer pos)
This function behaves like delete_tool but it deletes the tool at the specified position and not the one with the given id.
enable_tool(Integer toolId, Boolean enable)
Enables or disables the tool.
NB: This function should only be called after Realize.
Some implementations will change the visible state of the tool to indicate that it is disabled.
ToolBar#get_tool_enabled, ToolBar#toggle_tool
ToolBarTool find_by_id(Integer id)
Returns information about the item with the passed-in id.
Control find_control(Integer id)
Returns a pointer to the Wx::Control identified by id or nil if no corresponding control is found.
Integer get_tools_count()
Returns the number of tools in the toolbar.
Size get_tool_size()
Returns the size of a whole button, which is usually larger than a tool bitmap because of added 3D effects.
ToolBar#set_tool_bitmap_size, ToolBar#get_tool_bitmap_size
Size get_tool_bitmap_size()
Returns the size of bitmap that the toolbar expects to have. The default bitmap size is 16 by 15 pixels.
Note that this is the size of the bitmap you pass to ToolBar#add_tool, and not the eventual size of the tool button.
ToolBar#set_tool_bitmap_size, ToolBar#get_tool_size
Size get_margins()
Returns the left/right and top/bottom margins, which are also used for inter-toolspacing.
Object get_tool_client_data(Integer toolId)
Get any client data associated with the tool.
Client data, or NULL if there is none.
Boolean get_tool_enabled(Integer toolId)
Called to determine whether a tool is enabled (responds to user input).
true if the tool is enabled, false otherwise.
String get_tool_long_help(Integer toolId)
Returns the long help for the given tool.
ToolBar#set_tool_long_help, ToolBar#set_tool_short_help
Integer get_tool_packing()
Returns the value used for packing tools.
Integer get_tool_pos(Integer toolId)
Returns the tool position in the toolbar, or NOT_FOUND if the tool is not found.
Integer get_tool_separation()
Returns the default separator size.
String get_tool_short_help(Integer toolId)
Returns the short help for the given tool.
Boolean get_tool_state(Integer toolId)
Gets the on/off state of a toggle tool.
true if the tool is toggled on, false otherwise.
ToolBarTool insert_control(Integer pos,
Control control)
Inserts the control into the toolbar at the given position.
You must call Realize for the change to take place.
ToolBarTool insert_separator(Integer pos)
Inserts the separator into the toolbar at the given position.
You must call Realize for the change to take place.
ToolBarTool insert_tool(Integer pos,
Integer toolId,
String label,
Bitmap bitmap1,
Bitmap bitmap2 = NullBitmap,
Integer type = Wx::ITEM_NORMAL,
String shortHelp = "",
String longHelp = "",
Object clientData = nil)
Inserts the tool with the specified attributes into the toolbar at the given position. Returns a ToolBarTool object with information about the newly inserted item.
You must call Realize for the change to take place.
Boolean on_left_click(Integer toolId, Boolean 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.
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.
ToolBar#on_mouse_enter, ToolBar#on_right_click
on_mouse_enter(Integer 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.
With some derived toolbar classes, if the mouse moves quickly out of the toolbar, Widgets may not be able to detect it. Therefore this function may not always be called when expected.
on_right_click(Integer 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.
A typical use of this member might be to pop up a menu.
ToolBar#on_mouse_enter, ToolBar#on_left_click
Boolean realize()
This function should be called after you have added tools.
ToolBarTool remove_tool(Integer 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.
set_bitmap_resource(Integer resourceId)
Sets the bitmap resource identifier for specifying tool bitmaps as indices into a custom bitmap. Windows CE only.
set_margins(Size size)
set_margins(Integer x, Integer y)
Set the values to be used as margins for the toolbar.
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.
set_tool_bitmap_size(Size size)
Sets the default size of each tool bitmap. The default bitmap size is 16 by 15 pixels.
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 ToolBar#add_tool, and not the eventual size of the tool button.
ToolBar#get_tool_bitmap_size, ToolBar#get_tool_size
set_tool_client_data(Integer id, Object clientData)
Sets the client data associated with the tool.
set_tool_disabled_bitmap(Integer id, Bitmap 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.
set_tool_long_help(Integer toolId, String helpString)
Sets the long help for the given tool.
You might use the long help for displaying the tool purpose on the status line.
set_tool_normal_bitmap(Integer id, Bitmap bitmap)
Sets the bitmap to be used by the tool with the given ID. This can only be used on Button tools, not controls.
set_tool_packing(Integer packing)
Sets the value used for spacing tools. The default value is 1.
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.
set_tool_short_help(Integer toolId, String helpString)
Sets the short help for the given tool.
An application might use short help for identifying the tool purpose in a tooltip.
ToolBar#get_tool_short_help, ToolBar#set_tool_long_help
set_tool_separation(Integer separation)
Sets the default separator size. The default value is 5.
toggle_tool(Integer toolId, Boolean toggle)
Toggles a tool on or off. This does not cause any event to get emitted.
Only applies to a tool that has been specified as a toggle tool.
[This page automatically generated from the Textile source at Wed Sep 09 02:21:28 +0100 2009]