2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: button.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxButton
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-02 21:39:02 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxButton
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-16 20:47:38 -04:00
|
|
|
A button is a control that contains a text string, and is one of the most
|
|
|
|
common elements of a GUI.
|
|
|
|
|
|
|
|
It may be placed on a @ref wxDialog "dialog box" or on a @ref wxPanel panel,
|
|
|
|
or indeed on almost any other window.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-06-15 19:18:06 -04:00
|
|
|
By default, i.e. if none of the alignment styles are specified, the label
|
|
|
|
is centered both horizontally and vertically. If the button has both a
|
|
|
|
label and a bitmap, the alignment styles above specify the location of the
|
|
|
|
rectangle combining both the label and the bitmap and the bitmap position
|
|
|
|
set with wxButton::SetBitmapPosition() defines the relative position of the
|
|
|
|
bitmap with respect to the label (however currently non-default alignment
|
|
|
|
combinations are not implemented on all platforms).
|
|
|
|
|
2009-06-20 23:01:53 -04:00
|
|
|
Since version 2.9.1 wxButton supports showing both text and an image
|
|
|
|
(currently only when using wxMSW, wxGTK or wxOSX/Cocoa ports), see
|
2009-06-14 18:55:24 -04:00
|
|
|
SetBitmap() and SetBitmapLabel(), SetBitmapDisabled() &c methods. In the
|
|
|
|
previous wxWidgets versions this functionality was only available in (the
|
|
|
|
now trivial) wxBitmapButton class which was only capable of showing an
|
|
|
|
image without text.
|
|
|
|
|
|
|
|
A button may have either a single image for all states or different images
|
2009-06-20 23:01:53 -04:00
|
|
|
for the following states (different images are not currently supported
|
|
|
|
under OS X where the normal image is used for all states):
|
2009-06-14 18:55:24 -04:00
|
|
|
@li @b normal: the default state
|
|
|
|
@li @b disabled: bitmap shown when the button is disabled.
|
|
|
|
@li @b pressed: bitmap shown when the button is pushed (e.g. while the user
|
|
|
|
keeps the mouse button pressed on it)
|
|
|
|
@li @b focus: bitmap shown when the button has keyboard focus (but is not
|
|
|
|
pressed as in this case the button is in the pressed state)
|
|
|
|
@li @b current: bitmap shown when the mouse is over the button (but it is
|
|
|
|
not pressed although it may have focus). Notice that if current bitmap
|
|
|
|
is not specified but the current platform UI uses hover images for the
|
|
|
|
buttons (such as Windows XP or GTK+), then the focus bitmap is used for
|
|
|
|
hover state as well. This makes it possible to set focus bitmap only to
|
|
|
|
get reasonably good behaviour on all platforms.
|
|
|
|
|
|
|
|
All of the bitmaps must be of the same size and the normal bitmap must be
|
2011-03-14 07:54:39 -04:00
|
|
|
set first (to a valid bitmap), before setting any other ones. Also, if the
|
|
|
|
size of the bitmaps is changed later, you need to change the size of the
|
|
|
|
normal bitmap before setting any other bitmaps with the new size (and you
|
|
|
|
do need to reset all of them as their original values can be lost when the
|
|
|
|
normal bitmap size changes).
|
2009-06-14 18:55:24 -04:00
|
|
|
|
|
|
|
The position of the image inside the button be configured using
|
|
|
|
SetBitmapPosition(). By default the image is on the left of the text.
|
|
|
|
|
2011-11-05 07:55:42 -04:00
|
|
|
Please also notice that GTK+ uses a global setting called @c gtk-button-images
|
|
|
|
to determine if the images should be shown in the buttons
|
2010-03-02 20:08:19 -05:00
|
|
|
at all. If it is off (which is the case in e.g. Gnome 2.28 by default), no
|
|
|
|
images will be shown, consistently with the native behaviour.
|
|
|
|
|
2011-11-05 07:55:42 -04:00
|
|
|
@beginStyleTable
|
|
|
|
@style{wxBU_LEFT}
|
|
|
|
Left-justifies the label. Windows and GTK+ only.
|
|
|
|
@style{wxBU_TOP}
|
|
|
|
Aligns the label to the top of the button. Windows and GTK+ only.
|
|
|
|
@style{wxBU_RIGHT}
|
|
|
|
Right-justifies the bitmap label. Windows and GTK+ only.
|
|
|
|
@style{wxBU_BOTTOM}
|
|
|
|
Aligns the label to the bottom of the button. Windows and GTK+ only.
|
|
|
|
@style{wxBU_EXACTFIT}
|
2013-02-05 15:46:10 -05:00
|
|
|
By default, all buttons are made of at least the standard button size,
|
|
|
|
even if their contents is small enough to fit into a smaller size. This
|
|
|
|
is done for consistency as most platforms use buttons of the same size
|
|
|
|
in the native dialogs, but can be overridden by specifying this flag.
|
|
|
|
If it is given, the button will be made just big enough for its
|
|
|
|
contents. Notice that under MSW the button will still have at least the
|
|
|
|
standard height, even with this style, if it has a non-empty label.
|
2011-11-05 07:55:42 -04:00
|
|
|
@style{wxBU_NOTEXT}
|
|
|
|
Disables the display of the text label in the button even if it has one
|
|
|
|
or its id is one of the standard stock ids with an associated label:
|
|
|
|
without using this style a button which is only supposed to show a
|
|
|
|
bitmap but uses a standard id would display a label too.
|
|
|
|
@style{wxBORDER_NONE}
|
|
|
|
Creates a button without border. This is currently implemented in MSW,
|
2016-01-22 09:40:58 -05:00
|
|
|
GTK2 and OSX/Cocoa.
|
2011-11-05 07:55:42 -04:00
|
|
|
@endStyleTable
|
|
|
|
|
|
|
|
@beginEventEmissionTable{wxCommandEvent}
|
|
|
|
@event{EVT_BUTTON(id, func)}
|
2013-04-25 06:11:03 -04:00
|
|
|
Process a @c wxEVT_BUTTON event, when the button is clicked.
|
2011-11-05 07:55:42 -04:00
|
|
|
@endEventTable
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{ctrl}
|
2012-11-03 14:32:50 -04:00
|
|
|
@appearance{button}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxBitmapButton
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2011-11-03 23:38:09 -04:00
|
|
|
class wxButton : public wxAnyButton
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-03-16 20:47:38 -04:00
|
|
|
/**
|
|
|
|
Default ctor.
|
|
|
|
*/
|
|
|
|
wxButton();
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Constructor, creating and showing a button.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The preferred way to create standard buttons is to use default value of
|
2008-03-16 20:47:38 -04:00
|
|
|
@a label. If no label is supplied and @a id is one of standard IDs from
|
2010-08-11 12:03:46 -04:00
|
|
|
@ref page_stockitems "this list", a standard label will be used. In
|
|
|
|
other words, if you use a predefined @c wxID_XXX constant, just omit
|
|
|
|
the label completely rather than specifying it. In particular, help
|
|
|
|
buttons (the ones with @a id of @c wxID_HELP) under Mac OS X can't
|
|
|
|
display any label at all and while wxButton will detect if the standard
|
|
|
|
"Help" label is used and ignore it, using any other label will prevent
|
|
|
|
the button from correctly appearing as a help button and so should be
|
|
|
|
avoided.
|
|
|
|
|
2008-03-16 20:47:38 -04:00
|
|
|
|
|
|
|
In addition to that, the button will be decorated with stock icons under GTK+ 2.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param parent
|
2008-03-09 08:33:59 -04:00
|
|
|
Parent window. Must not be @NULL.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param id
|
2011-11-05 07:55:42 -04:00
|
|
|
Button identifier. A value of @c wxID_ANY indicates a default value.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param label
|
2008-03-09 08:33:59 -04:00
|
|
|
Text to be displayed on the button.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pos
|
2008-03-09 08:33:59 -04:00
|
|
|
Button position.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param size
|
2008-03-09 08:33:59 -04:00
|
|
|
Button size. If the default size is specified then the button is sized
|
|
|
|
appropriately for the text.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param style
|
2008-03-16 20:47:38 -04:00
|
|
|
Window style. See wxButton class description.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param validator
|
2008-03-09 08:33:59 -04:00
|
|
|
Window validator.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param name
|
2008-03-09 08:33:59 -04:00
|
|
|
Window name.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see Create(), wxValidator
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxButton(wxWindow* parent, wxWindowID id,
|
|
|
|
const wxString& label = wxEmptyString,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2008-03-25 08:22:08 -04:00
|
|
|
const wxString& name = wxButtonNameStr);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-16 20:47:38 -04:00
|
|
|
Button creation function for two-step creation.
|
|
|
|
For more details, see wxButton().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Create(wxWindow* parent, wxWindowID id,
|
|
|
|
const wxString& label = wxEmptyString,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
2008-03-25 08:22:08 -04:00
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxButtonNameStr);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2010-02-08 14:52:00 -05:00
|
|
|
/**
|
|
|
|
Returns @true if an authentication needed symbol is displayed on the
|
|
|
|
button.
|
|
|
|
|
|
|
|
@remarks This method always returns @false if the platform is not
|
|
|
|
Windows Vista or newer.
|
|
|
|
|
|
|
|
@see SetAuthNeeded()
|
|
|
|
|
|
|
|
@since 2.9.1
|
|
|
|
*/
|
|
|
|
bool GetAuthNeeded() const;
|
|
|
|
|
2010-03-01 19:23:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns the default size for the buttons. It is advised to make all the dialog
|
|
|
|
buttons of the same size and this function allows to retrieve the (platform and
|
|
|
|
current font dependent size) which should be the best suited for this.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
static wxSize GetDefaultSize();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the string label for the button.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SetLabel()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetLabel() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2010-02-08 14:52:00 -05:00
|
|
|
/**
|
|
|
|
Sets whether an authentication needed symbol should be displayed on the
|
|
|
|
button.
|
|
|
|
|
|
|
|
@remarks This method doesn't do anything if the platform is not Windows
|
|
|
|
Vista or newer.
|
|
|
|
|
|
|
|
@see GetAuthNeeded()
|
|
|
|
|
|
|
|
@since 2.9.1
|
|
|
|
*/
|
|
|
|
void SetAuthNeeded(bool needed = true);
|
|
|
|
|
2009-06-14 18:55:24 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-27 17:14:31 -04:00
|
|
|
This sets the button to be the default item in its top-level window
|
|
|
|
(e.g. the panel or the dialog box containing it).
|
2008-03-16 20:47:38 -04:00
|
|
|
|
|
|
|
As normal, pressing return causes the default button to be depressed when
|
|
|
|
the return key is pressed.
|
|
|
|
|
|
|
|
See also wxWindow::SetFocus() which sets the keyboard focus for windows
|
|
|
|
and text panel items, and wxTopLevelWindow::SetDefaultItem().
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@remarks Under Windows, only dialog box buttons respond to this function.
|
2008-03-27 17:14:31 -04:00
|
|
|
|
2011-11-05 07:55:42 -04:00
|
|
|
@return the old default item (possibly @NULL)
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-27 17:14:31 -04:00
|
|
|
virtual wxWindow* SetDefault();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the string label for the button.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param label
|
2008-03-09 08:33:59 -04:00
|
|
|
The label to set.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetLabel(const wxString& label);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|