X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d15694e8cad1d44087323bd568ca33ff5b354f2c..71a09c3579dd5cb4cd8fa7fdc143561cbff74e12:/src/osx/tglbtn_osx.cpp diff --git a/src/osx/tglbtn_osx.cpp b/src/osx/tglbtn_osx.cpp index c381cd4eda..f1ba9cd00e 100644 --- a/src/osx/tglbtn_osx.cpp +++ b/src/osx/tglbtn_osx.cpp @@ -5,7 +5,6 @@ // Author: Stefan Csomor // Modified by: // Created: 08.02.01 -// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -31,7 +30,7 @@ // ---------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) -wxDEFINE_EVENT( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEvent ); +wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent ); // ============================================================================ // implementation @@ -49,6 +48,21 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, { DontCreatePeer(); + m_marginX = + m_marginY = 0; + + // FIXME: this hack is needed because we're called from + // wxBitmapToggleButton::Create() with this style and we currently use a + // different wxWidgetImpl method (CreateBitmapToggleButton() rather than + // CreateToggleButton()) for creating bitmap buttons, but we really ought + // to unify the creation of buttons of all kinds and then remove + // this check + if ( style & wxBU_NOTEXT ) + { + return wxControl::Create(parent, id, pos, size, style, + validator, name); + } + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return false; @@ -61,18 +75,6 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, return TRUE; } -wxSize wxToggleButton::DoGetBestSize() const -{ - int wBtn = 70 ; - int hBtn = 20 ; - - int lBtn = m_label.Length() * 8 + 12 ; - if (lBtn > wBtn) - wBtn = lBtn; - - return wxSize ( wBtn , hBtn ) ; -} - void wxToggleButton::SetValue(bool val) { GetPeer()->SetValue( val ) ; @@ -91,7 +93,7 @@ void wxToggleButton::Command(wxCommandEvent & event) bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) { - wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); + wxCommandEvent event(wxEVT_TOGGLEBUTTON, m_windowId); event.SetInt(GetValue()); event.SetEventObject(this); ProcessCommand(event); @@ -102,7 +104,7 @@ bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) // wxBitmapToggleButton // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton) bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& label, @@ -113,13 +115,13 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, { DontCreatePeer(); - m_bitmap = label; + if ( !wxToggleButton::Create(parent, id, wxEmptyString, pos, size, style | wxBU_NOTEXT | wxBU_EXACTFIT, validator, name) ) + return false; m_marginX = m_marginY = wxDEFAULT_BUTTON_MARGIN; - if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) - return false; + m_bitmaps[State_Normal] = label; SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )); @@ -128,42 +130,5 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, return TRUE; } -wxSize wxBitmapToggleButton::DoGetBestSize() const -{ - if (!m_bitmap.IsOk()) - return wxSize(20,20); - - wxSize best; - best.x = m_bitmap.GetWidth() + 2 * m_marginX; - best.y = m_bitmap.GetHeight() + 2 * m_marginY; - - return best; -} - -void wxBitmapToggleButton::SetValue(bool val) -{ - GetPeer()->SetValue( val ) ; -} - -bool wxBitmapToggleButton::GetValue() const -{ - return GetPeer()->GetValue() ; -} - -void wxBitmapToggleButton::Command(wxCommandEvent & event) -{ - SetValue((event.GetInt() != 0)); - ProcessCommand(event); -} - -bool wxBitmapToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) -{ - wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); - event.SetInt(GetValue()); - event.SetEventObject(this); - ProcessCommand(event); - return noErr ; -} - #endif // wxUSE_TOGGLEBTN