2001-06-26 20:59:19 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/checkbox.h
|
|
|
|
// Purpose: wxCheckBox class interface
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 07.09.00
|
2004-05-23 14:56:36 +00:00
|
|
|
// Copyright: (c) wxWidgets team
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
2001-06-26 20:59:19 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-15 00:23:28 +00:00
|
|
|
#ifndef _WX_CHECKBOX_H_BASE_
|
|
|
|
#define _WX_CHECKBOX_H_BASE_
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2003-07-09 21:48:53 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#if wxUSE_CHECKBOX
|
|
|
|
|
|
|
|
#include "wx/control.h"
|
|
|
|
|
2003-09-28 00:23:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* wxCheckBox style flags
|
|
|
|
* (Using wxCHK_* because wxCB_* is used by wxComboBox).
|
|
|
|
* Determine whether to use a 3-state or 2-state
|
|
|
|
* checkbox. 3-state enables to differentiate
|
|
|
|
* between 'unchecked', 'checked' and 'undetermined'.
|
2010-10-16 18:10:42 +00:00
|
|
|
*
|
|
|
|
* In addition to the styles here it is also possible to specify just 0 which
|
|
|
|
* is treated the same as wxCHK_2STATE for compatibility (but using explicit
|
|
|
|
* flag is preferred).
|
2003-09-28 00:23:08 +00:00
|
|
|
*/
|
2010-10-16 18:10:42 +00:00
|
|
|
#define wxCHK_2STATE 0x4000
|
2003-09-28 00:23:08 +00:00
|
|
|
#define wxCHK_3STATE 0x1000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this style is set the user can set the checkbox to the
|
|
|
|
* undetermined state. If not set the undetermined set can only
|
|
|
|
* be set programmatically.
|
|
|
|
* This style can only be used with 3 state checkboxes.
|
|
|
|
*/
|
|
|
|
#define wxCHK_ALLOW_3RD_STATE_FOR_USER 0x2000
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[];
|
2001-06-26 20:59:19 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxCheckBox: a control which shows a label and a box which may be checked
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxCheckBoxBase : public wxControl
|
2001-06-26 20:59:19 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-01-15 13:49:22 +00:00
|
|
|
wxCheckBoxBase() { }
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
// set/get the checked status of the listbox
|
2003-09-28 18:01:42 +00:00
|
|
|
virtual void SetValue(bool value) = 0;
|
2001-06-26 20:59:19 +00:00
|
|
|
virtual bool GetValue() const = 0;
|
|
|
|
|
2003-09-28 00:23:08 +00:00
|
|
|
bool IsChecked() const
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( !Is3State(), wxT("Calling IsChecked() doesn't make sense for")
|
|
|
|
wxT(" a three state checkbox, Use Get3StateValue() instead") );
|
|
|
|
|
|
|
|
return GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxCheckBoxState Get3StateValue() const
|
|
|
|
{
|
|
|
|
wxCheckBoxState state = DoGet3StateValue();
|
|
|
|
|
|
|
|
if ( state == wxCHK_UNDETERMINED && !Is3State() )
|
|
|
|
{
|
|
|
|
// Undetermined state with a 2-state checkbox??
|
|
|
|
wxFAIL_MSG( wxT("DoGet3StateValue() says the 2-state checkbox is ")
|
|
|
|
wxT("in an undetermined/third state") );
|
|
|
|
|
|
|
|
state = wxCHK_UNCHECKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set3StateValue(wxCheckBoxState state)
|
|
|
|
{
|
|
|
|
if ( state == wxCHK_UNDETERMINED && !Is3State() )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("Setting a 2-state checkbox to undetermined state"));
|
|
|
|
state = wxCHK_UNCHECKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DoSet3StateValue(state);
|
|
|
|
}
|
|
|
|
|
2003-10-15 22:45:23 +00:00
|
|
|
bool Is3State() const { return HasFlag(wxCHK_3STATE); }
|
2003-09-28 00:23:08 +00:00
|
|
|
|
|
|
|
bool Is3rdStateAllowedForUser() const
|
|
|
|
{
|
2003-10-15 22:45:23 +00:00
|
|
|
return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER);
|
2003-09-28 00:23:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool HasTransparentBackground() wxOVERRIDE { return true; }
|
2004-03-04 17:03:55 +00:00
|
|
|
|
2006-02-12 16:32:50 +00:00
|
|
|
// wxCheckBox-specific processing after processing the update event
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) wxOVERRIDE
|
2006-02-12 16:32:50 +00:00
|
|
|
{
|
2006-06-30 10:51:44 +00:00
|
|
|
wxControl::DoUpdateWindowUI(event);
|
|
|
|
|
2006-02-12 16:32:50 +00:00
|
|
|
if ( event.GetSetChecked() )
|
|
|
|
SetValue(event.GetChecked());
|
|
|
|
}
|
|
|
|
|
2003-09-28 00:23:08 +00:00
|
|
|
protected:
|
2007-11-13 12:10:34 +00:00
|
|
|
// choose the default border for this window
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxBorder GetDefaultBorder() const wxOVERRIDE { return wxBORDER_NONE; }
|
2007-11-13 12:10:34 +00:00
|
|
|
|
2003-09-28 00:23:08 +00:00
|
|
|
virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; }
|
|
|
|
|
|
|
|
virtual wxCheckBoxState DoGet3StateValue() const
|
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
return wxCHK_UNCHECKED;
|
|
|
|
}
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2010-10-16 18:10:42 +00:00
|
|
|
// Helper function to be called from derived classes Create()
|
|
|
|
// implementations: it checks that the style doesn't contain any
|
|
|
|
// incompatible bits and modifies it to be sane if it does.
|
|
|
|
static void WXValidateStyle(long *stylePtr)
|
|
|
|
{
|
|
|
|
long& style = *stylePtr;
|
|
|
|
|
2010-10-28 14:23:09 +00:00
|
|
|
if ( !(style & (wxCHK_2STATE | wxCHK_3STATE)) )
|
2010-10-16 18:10:42 +00:00
|
|
|
{
|
|
|
|
// For compatibility we use absence of style flags as wxCHK_2STATE
|
|
|
|
// because wxCHK_2STATE used to have the value of 0 and some
|
2010-10-28 14:23:09 +00:00
|
|
|
// existing code uses 0 instead of it. Moreover, some code even
|
|
|
|
// uses some non-0 style, e.g. wxBORDER_XXX, but doesn't specify
|
|
|
|
// neither wxCHK_2STATE nor wxCHK_3STATE -- to avoid breaking it,
|
|
|
|
// assume (much more common) 2 state checkbox by default.
|
|
|
|
style |= wxCHK_2STATE;
|
2010-10-16 18:10:42 +00:00
|
|
|
}
|
2010-10-28 14:23:09 +00:00
|
|
|
|
|
|
|
if ( style & wxCHK_3STATE )
|
2010-10-16 18:10:42 +00:00
|
|
|
{
|
|
|
|
if ( style & wxCHK_2STATE )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( "wxCHK_2STATE and wxCHK_3STATE can't be used "
|
|
|
|
"together" );
|
|
|
|
style &= ~wxCHK_3STATE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // No wxCHK_3STATE
|
|
|
|
{
|
|
|
|
if ( style & wxCHK_ALLOW_3RD_STATE_FOR_USER )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( "wxCHK_ALLOW_3RD_STATE_FOR_USER doesn't make sense "
|
|
|
|
"without wxCHK_3STATE" );
|
|
|
|
style &= ~wxCHK_ALLOW_3RD_STATE_FOR_USER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-22 00:24:07 +00:00
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase);
|
2001-06-26 20:59:19 +00:00
|
|
|
};
|
|
|
|
|
2010-10-16 18:10:51 +00:00
|
|
|
// Most ports support 3 state checkboxes so define this by default.
|
|
|
|
#define wxHAS_3STATE_CHECKBOX
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#include "wx/univ/checkbox.h"
|
|
|
|
#elif defined(__WXMSW__)
|
|
|
|
#include "wx/msw/checkbox.h"
|
1998-07-10 14:15:17 +00:00
|
|
|
#elif defined(__WXMOTIF__)
|
2001-06-26 20:59:19 +00:00
|
|
|
#include "wx/motif/checkbox.h"
|
2006-01-23 03:27:34 +00:00
|
|
|
#elif defined(__WXGTK20__)
|
2001-06-26 20:59:19 +00:00
|
|
|
#include "wx/gtk/checkbox.h"
|
2006-01-23 03:27:34 +00:00
|
|
|
#elif defined(__WXGTK__)
|
2010-10-16 18:10:51 +00:00
|
|
|
#undef wxHAS_3STATE_CHECKBOX
|
2006-01-23 03:27:34 +00:00
|
|
|
#include "wx/gtk1/checkbox.h"
|
1998-08-15 00:23:28 +00:00
|
|
|
#elif defined(__WXMAC__)
|
2008-06-11 19:17:41 +00:00
|
|
|
#include "wx/osx/checkbox.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#endif // wxUSE_CHECKBOX
|
|
|
|
|
2010-10-16 18:10:51 +00:00
|
|
|
#endif // _WX_CHECKBOX_H_BASE_
|