2001-06-26 16:59:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/checkbox.h
|
|
|
|
// Purpose: wxCheckBox class interface
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 07.09.00
|
|
|
|
// RCS-ID: $Id$
|
2004-05-23 10:56:36 -04:00
|
|
|
// Copyright: (c) wxWidgets team
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2001-06-26 16:59:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _WX_CHECKBOX_H_BASE_
|
|
|
|
#define _WX_CHECKBOX_H_BASE_
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2003-07-09 17:48:53 -04:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if wxUSE_CHECKBOX
|
|
|
|
|
|
|
|
#include "wx/control.h"
|
|
|
|
|
2003-09-27 20:23:08 -04: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 14:10:42 -04: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-27 20:23:08 -04:00
|
|
|
*/
|
2010-10-16 14:10:42 -04:00
|
|
|
#define wxCHK_2STATE 0x4000
|
2003-09-27 20:23:08 -04: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 11:06:00 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxCheckBoxNameStr[];
|
2001-06-26 16:59:19 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxCheckBox: a control which shows a label and a box which may be checked
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxCheckBoxBase : public wxControl
|
2001-06-26 16:59:19 -04:00
|
|
|
{
|
|
|
|
public:
|
2004-01-15 08:49:22 -05:00
|
|
|
wxCheckBoxBase() { }
|
2003-07-21 20:24:07 -04:00
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
// set/get the checked status of the listbox
|
2003-09-28 14:01:42 -04:00
|
|
|
virtual void SetValue(bool value) = 0;
|
2001-06-26 16:59:19 -04:00
|
|
|
virtual bool GetValue() const = 0;
|
|
|
|
|
2003-09-27 20:23:08 -04: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 18:45:23 -04:00
|
|
|
bool Is3State() const { return HasFlag(wxCHK_3STATE); }
|
2003-09-27 20:23:08 -04:00
|
|
|
|
|
|
|
bool Is3rdStateAllowedForUser() const
|
|
|
|
{
|
2003-10-15 18:45:23 -04:00
|
|
|
return HasFlag(wxCHK_ALLOW_3RD_STATE_FOR_USER);
|
2003-09-27 20:23:08 -04:00
|
|
|
}
|
|
|
|
|
2005-01-07 11:54:09 -05:00
|
|
|
virtual bool HasTransparentBackground() { return true; }
|
2004-03-04 12:03:55 -05:00
|
|
|
|
2006-02-12 11:32:50 -05:00
|
|
|
// wxCheckBox-specific processing after processing the update event
|
|
|
|
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event)
|
|
|
|
{
|
2006-06-30 06:51:44 -04:00
|
|
|
wxControl::DoUpdateWindowUI(event);
|
|
|
|
|
2006-02-12 11:32:50 -05:00
|
|
|
if ( event.GetSetChecked() )
|
|
|
|
SetValue(event.GetChecked());
|
|
|
|
}
|
|
|
|
|
2003-09-27 20:23:08 -04:00
|
|
|
protected:
|
2007-11-13 07:10:34 -05:00
|
|
|
// choose the default border for this window
|
|
|
|
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
|
|
|
|
|
2003-09-27 20:23:08 -04:00
|
|
|
virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; }
|
|
|
|
|
|
|
|
virtual wxCheckBoxState DoGet3StateValue() const
|
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
return wxCHK_UNCHECKED;
|
|
|
|
}
|
2003-07-21 20:24:07 -04:00
|
|
|
|
2010-10-16 14:10:42 -04: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 10:23:09 -04:00
|
|
|
if ( !(style & (wxCHK_2STATE | wxCHK_3STATE)) )
|
2010-10-16 14:10:42 -04: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 10:23:09 -04: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 14:10:42 -04:00
|
|
|
}
|
2010-10-28 10:23:09 -04:00
|
|
|
|
|
|
|
if ( style & wxCHK_3STATE )
|
2010-10-16 14:10:42 -04: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-21 20:24:07 -04:00
|
|
|
private:
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxCheckBoxBase);
|
2001-06-26 16:59:19 -04:00
|
|
|
};
|
|
|
|
|
2010-10-16 14:10:51 -04:00
|
|
|
// Most ports support 3 state checkboxes so define this by default.
|
|
|
|
#define wxHAS_3STATE_CHECKBOX
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#include "wx/univ/checkbox.h"
|
|
|
|
#elif defined(__WXMSW__)
|
|
|
|
#include "wx/msw/checkbox.h"
|
1998-07-10 10:15:17 -04:00
|
|
|
#elif defined(__WXMOTIF__)
|
2001-06-26 16:59:19 -04:00
|
|
|
#include "wx/motif/checkbox.h"
|
2006-01-22 22:27:34 -05:00
|
|
|
#elif defined(__WXGTK20__)
|
2001-06-26 16:59:19 -04:00
|
|
|
#include "wx/gtk/checkbox.h"
|
2006-01-22 22:27:34 -05:00
|
|
|
#elif defined(__WXGTK__)
|
2010-10-16 14:10:51 -04:00
|
|
|
#undef wxHAS_3STATE_CHECKBOX
|
2006-01-22 22:27:34 -05:00
|
|
|
#include "wx/gtk1/checkbox.h"
|
1998-08-14 20:23:28 -04:00
|
|
|
#elif defined(__WXMAC__)
|
2008-06-11 15:17:41 -04:00
|
|
|
#include "wx/osx/checkbox.h"
|
2003-03-22 01:18:36 -05:00
|
|
|
#elif defined(__WXCOCOA__)
|
|
|
|
#include "wx/cocoa/checkbox.h"
|
1999-07-27 23:38:12 -04:00
|
|
|
#elif defined(__WXPM__)
|
2010-10-16 14:10:51 -04:00
|
|
|
#undef wxHAS_3STATE_CHECKBOX
|
2001-06-26 16:59:19 -04:00
|
|
|
#include "wx/os2/checkbox.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#endif // wxUSE_CHECKBOX
|
|
|
|
|
2010-10-16 14:10:51 -04:00
|
|
|
#endif // _WX_CHECKBOX_H_BASE_
|