2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: statbox.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxStaticBox
|
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
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxStaticBox
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-04-19 15:46:36 -04:00
|
|
|
A static box is a rectangle drawn around other windows to denote
|
2008-03-08 08:52:38 -05:00
|
|
|
a logical grouping of items.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-08-07 08:39:41 -04:00
|
|
|
Note that while the previous versions required that windows appearing
|
|
|
|
inside a static box be created as its siblings (i.e. use the same parent as
|
|
|
|
the static box itself), since wxWidgets 2.9.1 it is also possible to create
|
|
|
|
them as children of wxStaticBox itself and you are actually encouraged to
|
|
|
|
do it like this if compatibility with the previous versions is not
|
|
|
|
important.
|
|
|
|
|
|
|
|
So the new recommended way to create static box is:
|
|
|
|
@code
|
|
|
|
void MyFrame::CreateControls()
|
|
|
|
{
|
|
|
|
wxPanel *panel = new wxPanel(this);
|
|
|
|
wxStaticBox *box = new wxStaticBox(panel, wxID_ANY, "StaticBox");
|
|
|
|
|
2019-10-25 13:39:47 -04:00
|
|
|
new wxStaticText(box, wxID_ANY, "This window is a child of the staticbox");
|
2009-08-07 08:39:41 -04:00
|
|
|
...
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
While the compatible -- and now deprecated -- way is
|
2009-04-25 06:49:36 -04:00
|
|
|
@code
|
2009-08-07 08:39:41 -04:00
|
|
|
wxStaticBox *box = new wxStaticBox(panel, wxID_ANY, "StaticBox");
|
2009-04-25 06:49:36 -04:00
|
|
|
|
2019-10-25 13:39:47 -04:00
|
|
|
new wxStaticText(panel, wxID_ANY, "This window is a child of the panel");
|
2009-08-07 08:39:41 -04:00
|
|
|
...
|
2009-04-25 06:49:36 -04:00
|
|
|
@endcode
|
2009-08-07 08:39:41 -04:00
|
|
|
|
2009-04-25 06:49:36 -04:00
|
|
|
Also note that there is a specialized wxSizer class (wxStaticBoxSizer) which can
|
|
|
|
be used as an easier way to pack items into a static box.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{ctrl}
|
2012-11-03 14:32:50 -04:00
|
|
|
@appearance{staticbox}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-04-19 15:46:36 -04:00
|
|
|
@see wxStaticText, wxStaticBoxSizer
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxStaticBox : public wxControl
|
|
|
|
{
|
|
|
|
public:
|
2008-05-29 10:10:52 -04:00
|
|
|
/**
|
|
|
|
Default constructor
|
|
|
|
*/
|
|
|
|
wxStaticBox();
|
2008-10-07 12:57:34 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Constructor, creating and showing a static box.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
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
|
2008-03-09 08:33:59 -04:00
|
|
|
Window identifier. The value 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 in the static box, the empty string for no label.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pos
|
2008-10-07 12:57:34 -04:00
|
|
|
Window position.
|
2009-04-19 15:46:36 -04:00
|
|
|
If ::wxDefaultPosition is specified then a default position is chosen.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param size
|
2008-10-07 12:57:34 -04:00
|
|
|
Checkbox size.
|
2009-04-19 15:46:36 -04:00
|
|
|
If ::wxDefaultSize is specified then a default size is chosen.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param style
|
2017-12-21 13:03:12 -05:00
|
|
|
Window style. There are no wxStaticBox-specific styles, but generic
|
|
|
|
::wxALIGN_LEFT, ::wxALIGN_CENTRE_HORIZONTAL and ::wxALIGN_RIGHT can
|
|
|
|
be used here to change the position of the static box label when
|
|
|
|
using wxGTK (these styles are ignored under the other platforms
|
|
|
|
currently).
|
2008-03-08 09:43:31 -05:00
|
|
|
@param name
|
2008-03-09 08:33:59 -04:00
|
|
|
Window name.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see Create()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxStaticBox(wxWindow* parent, wxWindowID id,
|
|
|
|
const wxString& label,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
2008-11-13 16:32:53 -05:00
|
|
|
const wxString& name = wxStaticBoxNameStr);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2017-12-19 15:29:32 -05:00
|
|
|
/**
|
|
|
|
Constructor for a static box using the given window as label.
|
|
|
|
|
|
|
|
This constructor takes a pointer to an arbitrary window (although
|
|
|
|
usually a wxCheckBox or a wxRadioButton) instead of just the usual text
|
|
|
|
label and puts this window at the top of the box at the place where the
|
|
|
|
label would be shown.
|
|
|
|
|
|
|
|
The @a label window must be a non-null, fully created window and will
|
|
|
|
become a child of this wxStaticBox, i.e. it will be owned by this
|
|
|
|
control and will be deleted when the wxStaticBox itself is deleted.
|
|
|
|
|
|
|
|
An example of creating a wxStaticBox with window as a label:
|
|
|
|
@code
|
|
|
|
void MyFrame::CreateControls()
|
|
|
|
{
|
|
|
|
wxPanel* panel = new wxPanel(this);
|
|
|
|
wxCheckBox* checkbox = new wxCheckBox(panel, wxID_ANY, "Box checkbox");
|
|
|
|
wxStaticBox* box = new wxStaticBox(panel, wxID_ANY, checkbox);
|
|
|
|
...
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
2017-12-24 14:07:05 -05:00
|
|
|
Currently this constructor is only available in wxGTK and wxMSW, use
|
2017-12-19 15:29:32 -05:00
|
|
|
@c wxHAS_WINDOW_LABEL_IN_STATIC_BOX to check whether it can be used at
|
|
|
|
compile-time.
|
|
|
|
|
|
|
|
@since 3.1.1
|
|
|
|
*/
|
|
|
|
wxStaticBox(wxWindow* parent, wxWindowID id,
|
|
|
|
wxWindow* label,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxString& name = wxStaticBoxNameStr);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Destructor, destroying the group box.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxStaticBox();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-10-07 12:57:34 -04:00
|
|
|
Creates the static box for two-step construction.
|
|
|
|
See wxStaticBox() for further details.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-29 11:34:31 -04:00
|
|
|
bool Create(wxWindow* parent, wxWindowID id, const wxString& label,
|
2008-03-08 08:52:38 -05:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
2008-10-29 11:34:31 -04:00
|
|
|
const wxSize& size = wxDefaultSize, long style = 0,
|
|
|
|
const wxString& name = wxStaticBoxNameStr);
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2017-12-19 15:29:32 -05:00
|
|
|
/**
|
|
|
|
Creates the static box with the window as a label.
|
|
|
|
|
|
|
|
This method can only be called for an object created using its default
|
|
|
|
constructor.
|
|
|
|
|
|
|
|
See the constructor documentation for more details.
|
|
|
|
|
2018-01-13 16:26:07 -05:00
|
|
|
Currently this overload is only available in wxGTK and wxMSW, use
|
2017-12-19 15:29:32 -05:00
|
|
|
@c wxHAS_WINDOW_LABEL_IN_STATIC_BOX to check whether it can be used at
|
|
|
|
compile-time.
|
|
|
|
|
|
|
|
@since 3.1.1
|
|
|
|
*/
|
2018-01-13 16:26:07 -05:00
|
|
|
bool Create(wxWindow* parent, wxWindowID id,
|
2017-12-19 15:29:32 -05:00
|
|
|
wxWindow* label,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxString& name = wxStaticBoxNameStr);
|
2018-01-06 19:14:17 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Enables or disables the box without affecting its label window, if any.
|
|
|
|
|
|
|
|
wxStaticBox overrides wxWindow::Enable() in order to avoid disabling
|
|
|
|
the control used as a label, if this box is using one. This is done in
|
|
|
|
order to allow using a wxCheckBox, for example, label and enable or
|
|
|
|
disable the box according to the state of the checkbox: if disabling
|
|
|
|
the box also disabled the checkbox in this situation, it would make it
|
|
|
|
impossible for the user to re-enable the box after disabling it, so the
|
|
|
|
checkbox stays enabled even if @c box->Enable(false) is called.
|
|
|
|
|
|
|
|
However with the actual behaviour, implemented in this overridden
|
|
|
|
method, the following code (shown using C++11 only for convenience,
|
|
|
|
this behaviour is not C++11-specific):
|
|
|
|
@code
|
|
|
|
auto check = new wxCheckBox(parent, wxID_ANY, "Use the box");
|
|
|
|
auto box = new wxStaticBox(parent, wxID_ANY, check);
|
|
|
|
check->Bind(wxEVT_CHECKBOX,
|
|
|
|
[box](wxCommandEvent& event) {
|
|
|
|
box->Enable(event.IsChecked());
|
|
|
|
});
|
|
|
|
@endcode
|
|
|
|
does work as expected.
|
Don't pretend static box with enabled label is disabled
Trying to be smart by setting m_isEnabled to false in
wxStaticBox::Enable() without actually disabling the box itself (because
it can't be done if its label window is to remain enabled) didn't really
work. For example, it was impossible to TAB to a checkbox label of the
box when it was disabled, because keyboard navigation (correctly)
doesn't recurse into disabled windows and there could be similar
problems with any other code iterating over windows and skipping over
the disabled ones.
So, finally, simplify things and keep m_isEnabled in sync with the real
box state, even if this, counter-intuitively, means that IsEnabled() on
the box returns true after calling Enable(false) on it.
This also reverts 4ee35cf5ee569b6ee6c7d0d5702484d4d2a20f96 ("Don't
disable wxStaticBox children at wx level when disabling it") as we can't
avoid really disabling the children any more now that their parent is
not disabled: without this, their IsEnabled() would return true, i.e.
they wouldn't be disabled at all, from the program point of view. This
is unfortunate for the reasons that originally motivated that commit,
i.e. if some wxStaticBox child is disabled, disabling and re-enabling
the box will now re-enable this child, even if it shouldn't, but seems
impossible to avoid. The only possible alternative is to modify
IsEnabled() to add some wxStaticBox-specific hook to it, e.g. instead of
calling GetParent()->IsEnabled() there, we could call some now
AreChildrenEnable() method, which would delegate to IsEnabled() by
default but overridden in wxStaticBox. However this seems complicated,
and will add an extra virtual function call to all (frequently
happening) IsEnabled() calls.
2018-01-18 17:14:36 -05:00
|
|
|
|
|
|
|
Please note that overriding Enable() to not actually disable this
|
|
|
|
window itself has two possibly unexpected consequences:
|
|
|
|
|
|
|
|
- The box retains its enabled status, i.e. IsEnabled() still returns
|
|
|
|
@true, after calling @c Enable(false).
|
|
|
|
- The box children are enabled or disabled when the box is, which can
|
|
|
|
result in the loss of their original state. E.g. if a box child is
|
|
|
|
initially disabled, then the box itself is disabled and, finally, the
|
|
|
|
box is enabled again, this child will end up being enabled too (this
|
|
|
|
wouldn't happen with any other parent window as its children would
|
|
|
|
inherit the disabled state from the parent instead of being really
|
|
|
|
disabled themselves when it is disabled). To avoid this problem,
|
|
|
|
consider using ::wxEVT_UPDATE_UI to ensure that the child state is
|
|
|
|
always correct or restoring it manually after re-enabling the box.
|
2018-01-06 19:14:17 -05:00
|
|
|
*/
|
|
|
|
virtual bool Enable(bool enable = true);
|
2017-12-19 15:29:32 -05:00
|
|
|
};
|