Use two step creation of wxListHeaderWindow to avoid reentrancy under OSX.

This improves the solution of the problem already solved in r74197 by
separating setting of m_headerWin variable from the window creation instead of
using an explicit recursion check.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74231 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-06-13 13:57:28 +00:00
parent cc33ae725d
commit 1c25a4c2ae
2 changed files with 29 additions and 28 deletions

View File

@@ -336,7 +336,10 @@ protected:
public: public:
wxListHeaderWindow(); wxListHeaderWindow();
wxListHeaderWindow( wxWindow *win, // We provide only Create(), not the ctor, because we need to create the
// C++ object before creating the window, see the explanations in
// CreateOrDestroyHeaderWindowAsNeeded()
bool Create( wxWindow *win,
wxWindowID id, wxWindowID id,
wxListMainWindow *owner, wxListMainWindow *owner,
const wxPoint &pos = wxDefaultPosition, const wxPoint &pos = wxDefaultPosition,

View File

@@ -952,15 +952,17 @@ wxListHeaderWindow::wxListHeaderWindow()
m_resizeCursor = NULL; m_resizeCursor = NULL;
} }
wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, bool wxListHeaderWindow::Create( wxWindow *win,
wxWindowID id, wxWindowID id,
wxListMainWindow *owner, wxListMainWindow *owner,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
const wxString &name ) const wxString &name )
: wxWindow( win, id, pos, size, style, name )
{ {
if ( !wxWindow::Create(win, id, pos, size, style, name) )
return false;
Init(); Init();
m_owner = owner; m_owner = owner;
@@ -978,6 +980,8 @@ wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,
if (!m_hasFont) if (!m_hasFont)
SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT ));
#endif #endif
return true;
} }
wxListHeaderWindow::~wxListHeaderWindow() wxListHeaderWindow::~wxListHeaderWindow()
@@ -4509,18 +4513,13 @@ void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
if (needs_header) if (needs_header)
{ {
// since there is no separate Create method for the wxListHeaderWindow // Notice that we must initialize m_headerWin first, and create the
// we have to guard against reentrancy which happens via new wxListHeaderWindow -> // real window only later, so that the test in the beginning of the
// wxNavigationEnabled::AddChild -> ToggleWindowStyle -> SetWindowStyleFlag // function blocks repeated creation of the header as it could happen
// since has_header is still false then // before via wxNavigationEnabled::AddChild() -> ToggleWindowStyle() ->
static bool blockreentrancy = false; // SetWindowStyleFlag().
m_headerWin = new wxListHeaderWindow();
if ( blockreentrancy ) m_headerWin->Create
return;
blockreentrancy = true;
m_headerWin = new wxListHeaderWindow
( (
this, wxID_ANY, m_mainWin, this, wxID_ANY, m_mainWin,
wxPoint(0,0), wxPoint(0,0),
@@ -4531,7 +4530,6 @@ void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
), ),
wxTAB_TRAVERSAL wxTAB_TRAVERSAL
); );
blockreentrancy = false;
#if defined( __WXMAC__ ) #if defined( __WXMAC__ )
static wxFont font( wxOSX_SYSTEM_FONT_SMALL ); static wxFont font( wxOSX_SYSTEM_FONT_SMALL );