]>
git.saurik.com Git - wxWidgets.git/blob - interface/toolbar.h
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 classes:
15 @b wxToolBar95 The native Windows 95 toolbar. Used on Windows 95, NT 4 and
17 @b wxToolBarMSW A Windows implementation. Used on 16-bit Windows.
18 @b wxToolBarGTK The GTK toolbar.
23 Gives the toolbar a flat look (Windows and GTK only).
25 Makes the toolbar floatable and dockable (GTK only).
26 @style{wxTB_HORIZONTAL}
27 Specifies horizontal layout (default).
29 Specifies vertical layout.
31 Shows the text in the toolbar buttons; by default only icons are
34 Specifies no icons in the toolbar buttons; by default they are
36 @style{wxTB_NODIVIDER}
37 Specifies no divider (border) above the toolbar (Windows only).
39 Specifies no alignment with the parent window (Windows only, not
41 @style{wxTB_HORZ_LAYOUT}
42 Shows the text and the icons alongside, not vertically stacked
43 (Windows and GTK 2 only). This style must be used with wxTB_TEXT.
44 @style{wxTB_HORZ_TEXT}
45 Combination of wxTB_HORZ_LAYOUT and wxTB_TEXT.
46 @style{wxTB_NO_TOOLTIPS}
47 Don't show the short help tooltips for the tools when the mouse
50 Align the toolbar at the bottom of parent window.
52 Align the toolbar at the right side of parent window.
58 @see @ref overview_toolbar
60 class wxToolBar
: public wxControl
68 Pointer to a parent window.
70 Window identifier. If -1, will automatically create an identifier.
72 Window position. wxDefaultPosition is (-1, -1) which indicates that
74 should generate a default position for the window. If using the wxWindow
75 class directly, supply
78 Window size. wxDefaultSize is (-1, -1) which indicates that wxWidgets
79 should generate a default size for the window.
81 Window style. See wxToolBar for details.
85 @remarks After a toolbar is created, you use AddTool() and
86 perhaps AddSeparator(), and then you must call
87 Realize() to construct and display the toolbar
91 wxToolBar(wxWindow
* parent
, wxWindowID id
,
92 const wxPoint
& pos
= wxDefaultPosition
,
93 const wxSize
& size
= wxDefaultSize
,
94 long style
= wxTB_HORIZONTAL
| wxBORDER_NONE
,
95 const wxString
& name
= wxPanelNameStr
);
104 Adds a new check (or toggle) tool to the toolbar. The parameters are the same
109 wxToolBarToolBase
* AddCheckTool(int toolId
,
110 const wxString
& label
,
111 const wxBitmap
& bitmap1
,
112 const wxBitmap
& bitmap2
,
113 const wxString
& shortHelpString
= "",
114 const wxString
& longHelpString
= "",
115 wxObject
* clientData
= NULL
);
118 Adds any control to the toolbar, typically e.g. a combobox.
121 The control to be added.
123 Text to be displayed near the control.
125 @remarks wxMSW: the label is only displayed if there is enough space
126 available below the embedded control.
128 bool AddControl(wxControl
* control
, const wxString label
= "");
131 Adds a new radio tool to the toolbar. Consecutive radio tools form a radio
132 group such that exactly one button in the group is pressed at any moment, in
133 other words whenever a button in the group is pressed the previously pressed
134 button is automatically released. You should avoid having the radio groups of
135 only one element as it would be impossible for the user to use such button.
136 By default, the first button in the radio group is initially pressed, the
141 wxToolBarToolBase
* AddRadioTool(int toolId
,
142 const wxString
& label
,
143 const wxBitmap
& bitmap1
,
144 const wxBitmap
& bitmap2
,
145 const wxString
& shortHelpString
= "",
146 const wxString
& longHelpString
= "",
147 wxObject
* clientData
= NULL
);
150 Adds a separator for spacing groups of tools.
152 @see AddTool(), SetToolSeparation()
158 Adds a tool to the toolbar. The first (short and most commonly used) version
159 has fewer parameters than the full version at the price of not being able to
160 specify some of the more rarely used button features. The last version allows
161 you to add an existing tool.
165 the tool may be identified in subsequent operations.
167 May be wxITEM_NORMAL for a normal button (default),
168 wxITEM_CHECK for a checkable tool (such tool stays pressed after it had been
169 toggled) or wxITEM_RADIO for a checkable tool which makes part of a radio
170 group of tools each of which is automatically unchecked whenever another
172 in the group is checked
174 The primary tool bitmap.
176 The bitmap used when the tool is disabled. If it is equal to
177 wxNullBitmap, the disabled bitmap is automatically generated by greing the
179 @param shortHelpString
180 This string is used for the tools tooltip
181 @param longHelpString
182 This string is shown in the statusbar (if any) of the
183 parent frame when the mouse pointer is inside the tool
185 An optional pointer to client data which can be
186 retrieved later using GetToolClientData().
188 The tool to be added.
190 @remarks After you have added tools to a toolbar, you must call
191 Realize() in order to have the tools appear.
193 @see AddSeparator(), AddCheckTool(), AddRadioTool(),
194 InsertTool(), DeleteTool(), Realize()
196 wxToolBarToolBase
* AddTool(int toolId
, const wxString
& label
,
197 const wxBitmap
& bitmap1
,
198 const wxString
& shortHelpString
= "",
199 wxItemKind kind
= wxITEM_NORMAL
);
200 wxToolBarToolBase
* AddTool(int toolId
, const wxString
& label
,
201 const wxBitmap
& bitmap1
,
202 const wxBitmap
& bitmap2
= wxNullBitmap
,
203 wxItemKind kind
= wxITEM_NORMAL
,
204 const wxString
& shortHelpString
= "",
205 const wxString
& longHelpString
= "",
206 wxObject
* clientData
= NULL
);
207 wxToolBarToolBase
* AddTool(wxToolBarToolBase
* tool
);
211 Deletes all the tools in the toolbar.
216 Removes the specified tool from the toolbar and deletes it. If you don't want
217 to delete the tool, but just to remove it from the toolbar (to possibly add it
218 back later), you may use RemoveTool() instead.
219 Note that it is unnecessary to call Realize() for the
220 change to take place, it will happen immediately.
221 Returns @true if the tool was deleted, @false otherwise.
223 @see DeleteToolByPos()
225 bool DeleteTool(int toolId
);
228 This function behaves like DeleteTool() but it
229 deletes the tool at the specified position and not the one with the given id.
231 bool DeleteToolByPos(size_t pos
);
234 Enables or disables the tool.
237 Tool to enable or disable.
239 If @true, enables the tool, otherwise disables it.
241 @remarks Some implementations will change the visible state of the tool
242 to indicate that it is disabled.
244 @see GetToolEnabled(), ToggleTool()
246 void EnableTool(int toolId
, bool enable
);
249 Returns a pointer to the tool identified by @a id or
250 @NULL if no corresponding tool is found.
252 wxToolBarToolBase
* FindById(int id
);
255 Returns a pointer to the control identified by @a id or
256 @NULL if no corresponding control is found.
258 wxControl
* FindControl(int id
);
261 Finds a tool for the given mouse position.
268 @returns A pointer to a tool if a tool is found, or @NULL otherwise.
270 @remarks Currently not implemented in wxGTK (always returns @NULL there).
272 wxToolBarToolBase
* FindToolForPosition(wxCoord x
, wxCoord y
) const;
275 Returns the left/right and top/bottom margins, which are also used for
280 wxSize
GetMargins() const;
283 Returns the size of bitmap that the toolbar expects to have. The default bitmap
284 size is 16 by 15 pixels.
286 @remarks Note that this is the size of the bitmap you pass to
287 AddTool(), and not the eventual size of the
290 @see SetToolBitmapSize(), GetToolSize()
292 wxSize
GetToolBitmapSize();
295 Get any client data associated with the tool.
298 Id of the tool, as passed to AddTool().
300 @returns Client data, or @NULL if there is none.
302 wxObject
* GetToolClientData(int toolId
) const;
305 Called to determine whether a tool is enabled (responds to user input).
308 Id of the tool in question.
310 @returns @true if the tool is enabled, @false otherwise.
314 bool GetToolEnabled(int toolId
) const;
317 Returns the long help for the given tool.
320 The tool in question.
322 @see SetToolLongHelp(), SetToolShortHelp()
324 wxString
GetToolLongHelp(int toolId
) const;
327 Returns the value used for packing tools.
329 @see SetToolPacking()
331 int GetToolPacking() const;
334 Returns the tool position in the toolbar, or @c wxNOT_FOUND if the tool is not
337 int GetToolPos(int toolId
) const;
340 Returns the default separator size.
342 @see SetToolSeparation()
344 int GetToolSeparation() const;
347 Returns the short help for the given tool.
350 The tool in question.
352 @see GetToolLongHelp(), SetToolShortHelp()
354 wxString
GetToolShortHelp(int toolId
) const;
357 Returns the size of a whole button, which is usually larger than a tool bitmap
361 @see SetToolBitmapSize(), GetToolBitmapSize()
363 wxSize
GetToolSize();
366 Gets the on/off state of a toggle tool.
369 The tool in question.
371 @returns @true if the tool is toggled on, @false otherwise.
375 bool GetToolState(int toolId
) const;
378 Returns the number of tools in the toolbar.
380 int GetToolsCount() const;
383 Inserts the control into the toolbar at the given position.
384 You must call Realize() for the change to take place.
386 @see AddControl(), InsertTool()
388 wxToolBarToolBase
* InsertControl(size_t pos
, wxControl
* control
);
391 Inserts the separator into the toolbar at the given position.
392 You must call Realize() for the change to take place.
394 @see AddSeparator(), InsertTool()
396 wxToolBarToolBase
* InsertSeparator(size_t pos
);
400 Inserts the tool with the specified attributes into the toolbar at the given
402 You must call Realize() for the change to take place.
404 @see AddTool(), InsertControl(), InsertSeparator()
406 wxToolBarToolBase
* InsertTool(size_t pos
, int toolId
,
407 const wxBitmap
& bitmap1
,
408 const wxBitmap
& bitmap2
= wxNullBitmap
,
409 bool isToggle
= false,
410 wxObject
* clientData
= NULL
,
411 const wxString
& shortHelpString
= "",
412 const wxString
& longHelpString
= "");
413 wxToolBarToolBase
* InsertTool(size_t pos
,
414 wxToolBarToolBase
* tool
);
418 Called when the user clicks on a tool with the left mouse button.
419 This is the old way of detecting tool clicks; although it will still work,
420 you should use the EVT_MENU or EVT_TOOL macro instead.
423 The identifier passed to AddTool().
425 @true if the tool is a toggle and the toggle is down, otherwise is @false.
427 @returns If the tool is a toggle and this function returns @false, the
428 toggle toggle state (internal and visual) will not be
429 changed. This provides a way of specifying that toggle
430 operations are not permitted in some circumstances.
432 @see OnMouseEnter(), OnRightClick()
434 bool OnLeftClick(int toolId
, bool toggleDown
);
437 This is called when the mouse cursor moves into a tool or out of
439 This is the old way of detecting mouse enter events; although it will still
441 you should use the EVT_TOOL_ENTER macro instead.
444 Greater than -1 if the mouse cursor has moved into the tool,
445 or -1 if the mouse cursor has moved. The
446 programmer can override this to provide extra information about the tool,
447 such as a short description on the status line.
449 @remarks With some derived toolbar classes, if the mouse moves quickly
450 out of the toolbar, wxWidgets may not be able to detect
451 it. Therefore this function may not always be called
454 void OnMouseEnter(int toolId
);
457 Called when the user clicks on a tool with the right mouse button. The
458 programmer should override this function to detect right tool clicks.
459 This is the old way of detecting tool right clicks; although it will still work,
460 you should use the EVT_TOOL_RCLICKED macro instead.
463 The identifier passed to AddTool().
465 The x position of the mouse cursor.
467 The y position of the mouse cursor.
469 @remarks A typical use of this member might be to pop up a menu.
471 @see OnMouseEnter(), OnLeftClick()
473 void OnRightClick(int toolId
, float x
, float y
);
476 This function should be called after you have added tools.
481 Removes the given tool from the toolbar but doesn't delete it. This allows to
482 insert/add this tool back to this (or another) toolbar later.
483 Note that it is unnecessary to call Realize() for the
484 change to take place, it will happen immediately.
488 wxToolBarToolBase
* RemoveTool(int id
);
491 Sets the bitmap resource identifier for specifying tool bitmaps as indices
492 into a custom bitmap. Windows CE only.
494 void SetBitmapResource(int resourceId
);
497 Sets the dropdown menu for the tool given by its @e id. The tool itself will
498 delete the menu when it's no longer needed.
499 If you define a EVT_TOOL_DROPDOWN handler in your program, you must call
500 wxEvent::Skip from it or the menu won't be displayed.
502 bool SetDropdownMenu(int id
, wxMenu
* menu
);
506 Set the values to be used as margins for the toolbar.
511 Left margin, right margin and inter-tool separation value.
513 Top margin, bottom margin and inter-tool separation value.
515 @remarks This must be called before the tools are added if absolute
516 positioning is to be used, and the default (zero-size)
517 margins are to be overridden.
519 @see GetMargins(), wxSize
521 void SetMargins(const wxSize
& size
);
522 void SetMargins(int x
, int y
);
526 Sets the default size of each tool bitmap. The default bitmap size is 16 by 15
530 The size of the bitmaps in the toolbar.
532 @remarks This should be called to tell the toolbar what the tool bitmap
533 size is. Call it before you add tools.
535 @see GetToolBitmapSize(), GetToolSize()
537 void SetToolBitmapSize(const wxSize
& size
);
540 Sets the client data associated with the tool.
542 void SetToolClientData(int id
, wxObject
* clientData
);
545 Sets the bitmap to be used by the tool with the given ID when the tool
546 is in a disabled state. This can only be used on Button tools, not
547 controls. NOTE: The native toolbar classes on the main platforms all
548 synthesize the disabled bitmap from the normal bitmap, so this
549 function will have no effect on those platforms.
551 void SetToolDisabledBitmap(int id
, const wxBitmap
& bitmap
);
554 Sets the long help for the given tool.
557 The tool in question.
559 A string for the long help.
561 @remarks You might use the long help for displaying the tool purpose on
564 @see GetToolLongHelp(), SetToolShortHelp(),
566 void SetToolLongHelp(int toolId
, const wxString
& helpString
);
569 Sets the bitmap to be used by the tool with the given ID. This can
570 only be used on Button tools, not controls.
572 void SetToolNormalBitmap(int id
, const wxBitmap
& bitmap
);
575 Sets the value used for spacing tools. The default value is 1.
578 The value for packing.
580 @remarks The packing is used for spacing in the vertical direction if the
581 toolbar is horizontal, and for spacing in the
582 horizontal direction if the toolbar is vertical.
584 @see GetToolPacking()
586 void SetToolPacking(int packing
);
589 Sets the default separator size. The default value is 5.
596 void SetToolSeparation(int separation
);
599 Sets the short help for the given tool.
602 The tool in question.
604 The string for the short help.
606 @remarks An application might use short help for identifying the tool
607 purpose in a tooltip.
609 @see GetToolShortHelp(), SetToolLongHelp()
611 void SetToolShortHelp(int toolId
, const wxString
& helpString
);
614 Toggles a tool on or off. This does not cause any event to get emitted.
619 If @true, toggles the tool on, otherwise toggles it off.
621 @remarks Only applies to a tool that has been specified as a toggle tool.
623 void ToggleTool(int toolId
, bool toggle
);