X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5c33522fca7cddc441a316f5b9fb50d7685435ba..779e28da630ef9fba6441fb0bab01cd538a7e7bb:/src/msw/tglbtn.cpp?ds=sidebyside diff --git a/src/msw/tglbtn.cpp b/src/msw/tglbtn.cpp index 1c6c6a8a07..e4effb9ff0 100644 --- a/src/msw/tglbtn.cpp +++ b/src/msw/tglbtn.cpp @@ -8,7 +8,7 @@ // Created: 08.02.01 // RCS-ID: $Id$ // Copyright: (c) 2000 Johnny C. Norris II -// License: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -45,17 +45,52 @@ // macros // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) +wxDEFINE_EVENT( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, 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 +100,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 +115,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 +136,29 @@ WXDWORD wxToggleButton::MSWGetStyle(long style, WXDWORD *exstyle) const return msStyle; } -wxSize wxToggleButton::DoGetBestSize() const -{ - return wxMSWButton::ComputeBestSize(const_cast(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,8 +167,18 @@ void wxToggleButton::Command(wxCommandEvent& event) ProcessCommand(event); } -bool wxToggleButton::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) +bool wxToggleButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { + 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_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); event.SetInt(GetValue()); event.SetEventObject(this); @@ -136,4 +186,12 @@ bool wxToggleButton::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) return true; } +wxAnyButton::State wxToggleButton::GetNormalState() const +{ + if ( GetValue() ) + return State_Pressed; + else + return State_Normal; +} + #endif // wxUSE_TOGGLEBTN