X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a290fa5a7deebe9d96c0c0089d18e27d4bd9b624..bc0289bf5e29def4ba504807e45d6b7daf917fad:/src/univ/checkbox.cpp?ds=sidebyside diff --git a/src/univ/checkbox.cpp b/src/univ/checkbox.cpp index 450d303dc1..520a2edf05 100644 --- a/src/univ/checkbox.cpp +++ b/src/univ/checkbox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: univ/checkbox.cpp +// Name: src/univ/checkbox.cpp // Purpose: wxCheckBox implementation // Author: Vadim Zeitlin // Modified by: @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "univcheckbox.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -29,9 +25,10 @@ #if wxUSE_CHECKBOX +#include "wx/checkbox.h" + #ifndef WX_PRECOMP #include "wx/dcclient.h" - #include "wx/checkbox.h" #include "wx/validate.h" #include "wx/button.h" // for wxACTION_BUTTON_XXX @@ -42,6 +39,22 @@ #include "wx/univ/inphand.h" #include "wx/univ/colschem.h" +// ---------------------------------------------------------------------------- +// wxStdCheckboxInputHandler: handles the mouse events for the check and radio +// boxes (handling the keyboard input is simple, but its handling differs a +// lot between GTK and MSW, so a new class should be derived for this) +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxStdCheckboxInputHandler : public wxStdInputHandler +{ +public: + wxStdCheckboxInputHandler(wxInputHandler *inphand); + + // we have to override this one as wxStdButtonInputHandler version works + // only with the buttons + virtual bool HandleActivation(wxInputConsumer *consumer, bool activated); +}; + // ============================================================================ // implementation // ============================================================================ @@ -71,7 +84,7 @@ bool wxCheckBox::Create(wxWindow *parent, return false; SetLabel(label); - SetBestSize(size); + SetInitialSize(size); CreateInputHandler(wxINP_HANDLER_CHECKBOX); @@ -84,24 +97,12 @@ bool wxCheckBox::Create(wxWindow *parent, bool wxCheckBox::GetValue() const { - return m_status == Status_Checked; + return (Get3StateValue() != wxCHK_UNCHECKED); } void wxCheckBox::SetValue(bool value) { - Status status = value ? Status_Checked : Status_Unchecked; - if ( status != m_status ) - { - m_status = status; - - if ( m_status == Status_Checked ) - { - // invoke the hook - OnCheck(); - } - - Refresh(); - } + Set3StateValue( value ? wxCHK_CHECKED : wxCHK_UNCHECKED ); } void wxCheckBox::OnCheck() @@ -151,8 +152,12 @@ void wxCheckBox::DoDraw(wxControlRenderer *renderer) dc.SetFont(GetFont()); dc.SetTextForeground(GetForegroundColour()); - if ( m_status == Status_Checked ) - flags |= wxCONTROL_CHECKED; + switch ( Get3StateValue() ) + { + case wxCHK_CHECKED: flags |= wxCONTROL_CHECKED; break; + case wxCHK_UNDETERMINED: flags |= wxCONTROL_UNDETERMINED; break; + default: /* do nothing */ break; + } wxBitmap bitmap(GetBitmap(GetState(flags), m_status)); @@ -189,7 +194,9 @@ wxSize wxCheckBox::DoGetBestClientSize() const if ( height < sizeBmp.y ) height = sizeBmp.y; -#if wxUNIV_COMPATIBLE_MSW +#if defined(wxUNIV_COMPATIBLE_MSW) && wxUNIV_COMPATIBLE_MSW + // FIXME: flag nowhere defined so perhaps should be removed? + // this looks better but is different from what wxMSW does height += GetCharHeight()/2; #endif // wxUNIV_COMPATIBLE_MSW @@ -203,6 +210,41 @@ wxSize wxCheckBox::DoGetBestClientSize() const // checkbox actions // ---------------------------------------------------------------------------- +void wxCheckBox::DoSet3StateValue(wxCheckBoxState state) +{ + Status status; + switch ( state ) + { + case wxCHK_UNCHECKED: status = Status_Unchecked; break; + case wxCHK_CHECKED: status = Status_Checked; break; + default: wxFAIL_MSG(_T("Unknown checkbox state")); + case wxCHK_UNDETERMINED: status = Status_3rdState; break; + } + if ( status != m_status ) + { + m_status = status; + + if ( m_status == Status_Checked ) + { + // invoke the hook + OnCheck(); + } + + Refresh(); + } +} + +wxCheckBoxState wxCheckBox::DoGet3StateValue() const +{ + switch ( m_status ) + { + case Status_Checked: return wxCHK_CHECKED; + case Status_Unchecked: return wxCHK_UNCHECKED; + default: /* go further */ break; + } + return wxCHK_UNDETERMINED; +} + void wxCheckBox::Press() { if ( !m_isPressed ) @@ -227,7 +269,25 @@ void wxCheckBox::Toggle() { m_isPressed = false; - ChangeValue(!GetValue()); + Status status = m_status; + + switch ( Get3StateValue() ) + { + case wxCHK_CHECKED: + Set3StateValue(Is3rdStateAllowedForUser() ? wxCHK_UNDETERMINED : wxCHK_UNCHECKED); + break; + + case wxCHK_UNCHECKED: + Set3StateValue(wxCHK_CHECKED); + break; + + case wxCHK_UNDETERMINED: + Set3StateValue(wxCHK_UNCHECKED); + break; + } + + if( status != m_status ) + SendEvent(); } void wxCheckBox::ChangeValue(bool value) @@ -241,7 +301,17 @@ void wxCheckBox::SendEvent() { wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId()); InitCommandEvent(event); - event.SetInt(IsChecked()); + wxCheckBoxState state = Get3StateValue(); + + // If the style flag to allow the user setting the undetermined state + // is not set, then skip the undetermined state and set it to unchecked. + if ( state == wxCHK_UNDETERMINED && !Is3rdStateAllowedForUser() ) + { + state = wxCHK_UNCHECKED; + Set3StateValue(state); + } + + event.SetInt(state); Command(event); } @@ -269,12 +339,20 @@ bool wxCheckBox::PerformAction(const wxControlAction& action, return true; } +/* static */ +wxInputHandler *wxCheckBox::CreateStdInputHandler(wxInputHandler *handlerDef) +{ + static wxStdCheckboxInputHandler s_handler(handlerDef); + + return &s_handler; +} + // ---------------------------------------------------------------------------- // wxStdCheckboxInputHandler // ---------------------------------------------------------------------------- -wxStdCheckboxInputHandler::wxStdCheckboxInputHandler(wxInputHandler *inphand) - : wxStdButtonInputHandler(inphand) +wxStdCheckboxInputHandler::wxStdCheckboxInputHandler(wxInputHandler *def) + : wxStdInputHandler(wxButton::GetStdInputHandler(def)) { }