From ce63f2e9eb49fb50a6dbd188f29116a670c9f922 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 Nov 2012 23:54:37 +0000 Subject: [PATCH] Make hack for button creation in wxOSX more robust. Don't crash when creating a plain wxButton with wxBU_NOTEXT style. This happened because we skipped creating the peer (real implementation) in this case entirely on the assumption that we were creating a wxBitmapButton, but this is not necessarily the case. So now test that the creation of the peer is really disabled before skipping it (this required adding ShouldCreatePeer() accessor). Merging wxWidgetImpl::CreateButton() and CreateBitmapButton() (and the same thing for toggle buttons) would still be a better solution but while it's trivial to do for Cocoa, it isn't for Carbon. And we can't use a single function for Cocoa but different functions for Carbon, so for now just continue to use this hack. Closes #13622. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72896 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/window.h | 5 ++++- src/osx/button_osx.cpp | 12 ++++++------ src/osx/window_osx.cpp | 5 +++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/wx/osx/window.h b/include/wx/osx/window.h index 757455f813..c97e979c8a 100644 --- a/include/wx/osx/window.h +++ b/include/wx/osx/window.h @@ -259,7 +259,10 @@ public: // optimization to avoid creating a user pane in wxWindow::Create if we already know // we will replace it with our own peer void DontCreatePeer(); - + + // return true unless DontCreatePeer() had been called + bool ShouldCreatePeer() const; + // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to // release existing peer void SetPeer(wxOSXWidgetImpl* peer); diff --git a/src/osx/button_osx.cpp b/src/osx/button_osx.cpp index 432f1f08af..32417fa88c 100644 --- a/src/osx/button_osx.cpp +++ b/src/osx/button_osx.cpp @@ -51,23 +51,23 @@ bool wxButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { - DontCreatePeer(); - - m_marginX = - m_marginY = 0; - // FIXME: this hack is needed because we're called from // wxBitmapButton::Create() with this style and we currently use a // different wxWidgetImpl method (CreateBitmapButton() rather than // CreateButton()) 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 ) + if ( style & wxBU_NOTEXT && !ShouldCreatePeer() ) { return wxControl::Create(parent, id, pos, size, style, validator, name); } + DontCreatePeer(); + + m_marginX = + m_marginY = 0; + wxString label; // Ignore the standard label for help buttons if possible, they use "?" diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index f09d216e64..bb67d1afb3 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -301,6 +301,11 @@ wxOSXWidgetImpl* wxWindowMac::GetPeer() const return m_peer == kOSXNoWidgetImpl ? NULL : m_peer ; } +bool wxWindowMac::ShouldCreatePeer() const +{ + return m_peer != kOSXNoWidgetImpl; +} + void wxWindowMac::DontCreatePeer() { m_peer = kOSXNoWidgetImpl; -- 2.45.2