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:
		| @@ -116,6 +116,10 @@ wxGTK: | |||||||
| - fixed wrong colour of tooltips under some themes | - fixed wrong colour of tooltips under some themes | ||||||
| - implemented wxColourDialog as native dialog | - implemented wxColourDialog as native dialog | ||||||
|  |  | ||||||
|  | wxMotif: | ||||||
|  |  | ||||||
|  | - added 3 state checkbox | ||||||
|  |  | ||||||
|  |  | ||||||
| 2.5.2 | 2.5.2 | ||||||
| ----- | ----- | ||||||
|   | |||||||
| @@ -16,8 +16,6 @@ | |||||||
| #pragma interface "checkbox.h" | #pragma interface "checkbox.h" | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #include "wx/control.h" |  | ||||||
|  |  | ||||||
| // Checkbox item (single checkbox) | // Checkbox item (single checkbox) | ||||||
| class WXDLLEXPORT wxCheckBox: public wxCheckBoxBase | class WXDLLEXPORT wxCheckBox: public wxCheckBoxBase | ||||||
| { | { | ||||||
| @@ -54,6 +52,10 @@ private: | |||||||
|         m_evtType = wxEVT_COMMAND_CHECKBOX_CLICKED; |         m_evtType = wxEVT_COMMAND_CHECKBOX_CLICKED; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     virtual void DoSet3StateValue(wxCheckBoxState state); | ||||||
|  |  | ||||||
|  |     virtual wxCheckBoxState DoGet3StateValue() const; | ||||||
|  |  | ||||||
|     // public for the callback |     // public for the callback | ||||||
| public: | public: | ||||||
|     // either exEVT_COMMAND_CHECKBOX_CLICKED or ..._TOGGLEBUTTON_CLICKED |     // either exEVT_COMMAND_CHECKBOX_CLICKED or ..._TOGGLEBUTTON_CLICKED | ||||||
|   | |||||||
| @@ -65,6 +65,9 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |||||||
|         wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)), |         wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)), | ||||||
|         XmNlabelString, text(), |         XmNlabelString, text(), | ||||||
|         XmNrecomputeSize, False, |         XmNrecomputeSize, False, | ||||||
|  |         // XmNindicatorOn, XmINDICATOR_CHECK_BOX, | ||||||
|  |         // XmNfillOnSelect, False, | ||||||
|  |         XmNtoggleMode, Is3State() ? XmTOGGLE_INDETERMINATE : XmTOGGLE_BOOLEAN, | ||||||
|         NULL); |         NULL); | ||||||
|      |      | ||||||
|     XtAddCallback( (Widget)m_mainWidget, |     XtAddCallback( (Widget)m_mainWidget, | ||||||
| @@ -82,20 +85,30 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |||||||
|  |  | ||||||
| void wxCheckBox::SetValue(bool val) | void wxCheckBox::SetValue(bool val) | ||||||
| { | { | ||||||
|     m_inSetValue = TRUE; |     if (val) | ||||||
|     XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE); |     { | ||||||
|     m_inSetValue = FALSE; |         Set3StateValue(wxCHK_CHECKED); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         Set3StateValue(wxCHK_UNCHECKED); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| bool wxCheckBox::GetValue() const | bool wxCheckBox::GetValue() const | ||||||
| { | { | ||||||
|     return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0); |     return (Get3StateValue() != 0); | ||||||
| } | } | ||||||
|  |  | ||||||
| void wxCheckBox::Command (wxCommandEvent & event) | void wxCheckBox::Command (wxCommandEvent & event) | ||||||
| { | { | ||||||
|     SetValue ((event.GetInt() != 0)); |     int state = event.GetInt(); | ||||||
|     ProcessCommand (event); |     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, | void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData, | ||||||
| @@ -106,10 +119,18 @@ void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData, | |||||||
|     if (item->InSetValue()) |     if (item->InSetValue()) | ||||||
|         return; |         return; | ||||||
|  |  | ||||||
|     wxCommandEvent event (item->m_evtType, item->GetId()); |     wxCheckBoxState state = item->Get3StateValue(); | ||||||
|     event.SetInt((int) item->GetValue ()); |  | ||||||
|     event.SetEventObject(item); |     if( !item->Is3rdStateAllowedForUser() && state == wxCHK_UNDETERMINED ) | ||||||
|     item->ProcessCommand (event); |     { | ||||||
|  |         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() | void wxCheckBox::ChangeBackgroundColour() | ||||||
| @@ -133,6 +154,45 @@ void wxCheckBox::ChangeBackgroundColour() | |||||||
|         NULL); |         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 | // wxToggleButton | ||||||
| /////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user