X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9016f3ad7338e0e61ee30de5618302404bfca1ef..d9106ec5b679d5c9a5eb61b9633e5f3b1437b6a8:/src/msw/tglbtn.cpp diff --git a/src/msw/tglbtn.cpp b/src/msw/tglbtn.cpp index 358a3a0a20..f7380a3f66 100644 --- a/src/msw/tglbtn.cpp +++ b/src/msw/tglbtn.cpp @@ -6,9 +6,8 @@ // and William Gallafent. // Modified by: // Created: 08.02.01 -// RCS-ID: $Id$ // Copyright: (c) 2000 Johnny C. Norris II -// License: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -45,17 +44,52 @@ // macros // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) +wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent ); // ============================================================================ // implementation // ============================================================================ +//----------------------------------------------------------------------------- +// wxBitmapToggleButton +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton) + +bool wxBitmapToggleButton::Create( wxWindow *parent, wxWindowID id, + const wxBitmap& label,const wxPoint& pos, const wxSize& size, long style, + const wxValidator& validator, const wxString& name ) +{ + if (!wxToggleButton::Create( parent, id, wxEmptyString, pos, size, style, validator, name )) + return false; + + SetBitmap(label); + + if (size.x == -1 || size.y == -1) + { + wxSize new_size = GetBestSize(); + if (size.x != -1) + new_size.x = size.x; + if (size.y != -1) + new_size.y = size.y; + SetSize( new_size ); + } + + return true; +} + + // ---------------------------------------------------------------------------- // wxToggleButton // ---------------------------------------------------------------------------- +IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) + +void wxToggleButton::Init() +{ + m_state = false; +} + // Single check box item bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, @@ -65,6 +99,8 @@ bool wxToggleButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { + Init(); + if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; @@ -78,7 +114,7 @@ bool wxToggleButton::Create(wxWindow *parent, WXDWORD msStyle = MSWGetStyle(style, &exstyle); msStyle |= wxMSWButton::GetMultilineStyle(label); - return MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, exstyle); + return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, exstyle); } WXDWORD wxToggleButton::MSWGetStyle(long style, WXDWORD *exstyle) const @@ -99,26 +135,29 @@ WXDWORD wxToggleButton::MSWGetStyle(long style, WXDWORD *exstyle) const return msStyle; } -wxSize wxToggleButton::DoGetBestSize() const -{ - return wxMSWButton::ComputeBestSize(wx_const_cast(wxToggleButton *, this)); -} - -void wxToggleButton::SetLabel(const wxString& label) -{ - wxMSWButton::UpdateMultilineStyle(GetHwnd(), label); - - wxToggleButtonBase::SetLabel(label); -} - void wxToggleButton::SetValue(bool val) { - ::SendMessage(GetHwnd(), BM_SETCHECK, val, 0); + m_state = val; + if ( IsOwnerDrawn() ) + { + Refresh(); + } + else + { + ::SendMessage(GetHwnd(), BM_SETCHECK, val, 0); + } } bool wxToggleButton::GetValue() const { - return ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED; + if ( IsOwnerDrawn() ) + { + return m_state; + } + else + { + return ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED; + } } void wxToggleButton::Command(wxCommandEvent& event) @@ -127,13 +166,31 @@ void wxToggleButton::Command(wxCommandEvent& event) ProcessCommand(event); } -bool wxToggleButton::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) +bool wxToggleButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { - wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); + if ( param != BN_CLICKED && param != BN_DBLCLK ) + return false; + + // first update the value so that user event handler gets the new + // toggle button value + + // ownerdrawn buttons don't manage their state themselves unlike usual + // auto checkboxes so do it ourselves in any case + m_state = !m_state; + + wxCommandEvent event(wxEVT_TOGGLEBUTTON, m_windowId); event.SetInt(GetValue()); event.SetEventObject(this); ProcessCommand(event); return true; } +wxAnyButton::State wxToggleButton::GetNormalState() const +{ + if ( GetValue() ) + return State_Pressed; + else + return State_Normal; +} + #endif // wxUSE_TOGGLEBTN