Added code for 3 state checkbox.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27656 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon 2004-06-05 21:01:06 +00:00
parent dd12575372
commit f8ab089a49
3 changed files with 78 additions and 12 deletions

View File

@ -116,6 +116,10 @@ wxGTK:
- fixed wrong colour of tooltips under some themes
- implemented wxColourDialog as native dialog
wxMotif:
- added 3 state checkbox
2.5.2
-----

View File

@ -16,8 +16,6 @@
#pragma interface "checkbox.h"
#endif
#include "wx/control.h"
// Checkbox item (single checkbox)
class WXDLLEXPORT wxCheckBox: public wxCheckBoxBase
{
@ -54,6 +52,10 @@ private:
m_evtType = wxEVT_COMMAND_CHECKBOX_CLICKED;
}
virtual void DoSet3StateValue(wxCheckBoxState state);
virtual wxCheckBoxState DoGet3StateValue() const;
// public for the callback
public:
// either exEVT_COMMAND_CHECKBOX_CLICKED or ..._TOGGLEBUTTON_CLICKED

View File

@ -65,6 +65,9 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)),
XmNlabelString, text(),
XmNrecomputeSize, False,
// XmNindicatorOn, XmINDICATOR_CHECK_BOX,
// XmNfillOnSelect, False,
XmNtoggleMode, Is3State() ? XmTOGGLE_INDETERMINATE : XmTOGGLE_BOOLEAN,
NULL);
XtAddCallback( (Widget)m_mainWidget,
@ -82,20 +85,30 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
void wxCheckBox::SetValue(bool val)
{
m_inSetValue = TRUE;
XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
m_inSetValue = FALSE;
if (val)
{
Set3StateValue(wxCHK_CHECKED);
}
else
{
Set3StateValue(wxCHK_UNCHECKED);
}
}
bool wxCheckBox::GetValue() const
{
return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
return (Get3StateValue() != 0);
}
void wxCheckBox::Command (wxCommandEvent & event)
{
SetValue ((event.GetInt() != 0));
ProcessCommand (event);
int state = event.GetInt();
wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
|| (state == wxCHK_UNDETERMINED),
wxT("event.GetInt() returned an invalid checkbox state") );
Set3StateValue((wxCheckBoxState) state);
ProcessCommand(event);
}
void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
@ -106,10 +119,18 @@ void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
if (item->InSetValue())
return;
wxCommandEvent event (item->m_evtType, item->GetId());
event.SetInt((int) item->GetValue ());
event.SetEventObject(item);
item->ProcessCommand (event);
wxCheckBoxState state = item->Get3StateValue();
if( !item->Is3rdStateAllowedForUser() && state == wxCHK_UNDETERMINED )
{
state = wxCHK_UNCHECKED;
item->Set3StateValue( state );
}
wxCommandEvent event( item->m_evtType, item->GetId() );
event.SetInt( (int)state );
event.SetEventObject( item );
item->ProcessCommand( event );
}
void wxCheckBox::ChangeBackgroundColour()
@ -133,6 +154,45 @@ void wxCheckBox::ChangeBackgroundColour()
NULL);
}
void wxCheckBox::DoSet3StateValue(wxCheckBoxState state)
{
m_inSetValue = true;
unsigned char value;
switch (state)
{
case wxCHK_UNCHECKED: value = XmUNSET; break;
case wxCHK_CHECKED: value = XmSET; break;
case wxCHK_UNDETERMINED: value = XmINDETERMINATE; break;
}
XtVaSetValues( (Widget) m_mainWidget,
XmNset, value,
NULL );
m_inSetValue = false;
}
wxCheckBoxState wxCheckBox::DoGet3StateValue() const
{
unsigned char value = 0;
XtVaGetValues( (Widget) m_mainWidget,
XmNset, &value,
NULL );
switch (value)
{
case XmUNSET: return wxCHK_UNCHECKED;
case XmSET: return wxCHK_CHECKED;
case XmINDETERMINATE: return wxCHK_UNDETERMINED;
}
// impossible...
return wxCHK_UNDETERMINED;
}
///////////////////////////////////////////////////////////////////////////////
// wxToggleButton
///////////////////////////////////////////////////////////////////////////////