X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/11a449ac9b11fbff75fb86e3bd487c762c92f962..08670ea85abf4b4946a9ce64971b591d7b1ee30b:/src/osx/tglbtn_osx.cpp diff --git a/src/osx/tglbtn_osx.cpp b/src/osx/tglbtn_osx.cpp index 09c9a7c9dc..5eb31a43bc 100644 --- a/src/osx/tglbtn_osx.cpp +++ b/src/osx/tglbtn_osx.cpp @@ -5,9 +5,9 @@ // Author: Stefan Csomor // Modified by: // Created: 08.02.01 -// RCS-ID: $Id: tglbtn.cpp 54129 2008-06-11 19:30:52Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// License: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -24,14 +24,14 @@ #include "wx/tglbtn.h" #include "wx/osx/private.h" -// Button +#include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) +wxDEFINE_EVENT( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEvent ); // ============================================================================ // implementation @@ -47,40 +47,43 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_macIsUserPane = FALSE ; + 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; - + m_labelOrig = m_label = label ; - m_peer = wxWidgetImpl::CreateToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ) ; + SetPeer(wxWidgetImpl::CreateToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )) ; MacPostControlCreate(pos,size) ; - - 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 ) ; + return TRUE; } void wxToggleButton::SetValue(bool val) { - m_peer->SetValue( val ) ; + GetPeer()->SetValue( val ) ; } bool wxToggleButton::GetValue() const { - return m_peer->GetValue() ; + return GetPeer()->GetValue() ; } void wxToggleButton::Command(wxCommandEvent & event) @@ -89,7 +92,7 @@ void wxToggleButton::Command(wxCommandEvent & event) ProcessCommand(event); } -bool wxToggleButton::HandleClicked( double timestampsec ) +bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) ) { wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); event.SetInt(GetValue()); @@ -102,7 +105,7 @@ bool wxToggleButton::HandleClicked( double timestampsec ) // wxBitmapToggleButton // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton) bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& label, @@ -111,58 +114,21 @@ bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_macIsUserPane = FALSE ; + DontCreatePeer(); - m_bitmap = label; - - m_marginX = - m_marginY = wxDEFAULT_BUTTON_MARGIN; - - if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) + if ( !wxToggleButton::Create(parent, id, wxEmptyString, pos, size, style | wxBU_NOTEXT | wxBU_EXACTFIT, validator, name) ) return false; - - m_peer = wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ) ; - - MacPostControlCreate(pos,size) ; - - return TRUE; -} -wxSize wxBitmapToggleButton::DoGetBestSize() const -{ - if (!m_bitmap.IsOk()) - return wxSize(20,20); + m_marginX = + m_marginY = wxDEFAULT_BUTTON_MARGIN; - wxSize best; - best.x = m_bitmap.GetWidth() + 2 * m_marginX; - best.y = m_bitmap.GetHeight() + 2 * m_marginY; + m_bitmaps[State_Normal] = label; - return best; -} + SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )); -void wxBitmapToggleButton::SetValue(bool val) -{ - m_peer->SetValue( val ) ; -} - -bool wxBitmapToggleButton::GetValue() const -{ - return m_peer->GetValue() ; -} - -void wxBitmapToggleButton::Command(wxCommandEvent & event) -{ - SetValue((event.GetInt() != 0)); - ProcessCommand(event); -} + MacPostControlCreate(pos,size) ; -bool wxBitmapToggleButton::HandleClicked( double timestampsec ) -{ - wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); - event.SetInt(GetValue()); - event.SetEventObject(this); - ProcessCommand(event); - return noErr ; + return TRUE; } #endif // wxUSE_TOGGLEBTN