From 4f73f25cc81a95cbfff4f1afa850aae5976a423c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 9 May 2009 16:55:37 +0000 Subject: [PATCH] don't use GetParent() in GetParentForModalDialog() itself as it can be called before m_parent is initialized git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60573 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dialog.h | 7 +++++-- src/common/dlgcmn.cpp | 11 +++++------ src/gtk/dialog.cpp | 2 +- src/msw/toplevel.cpp | 5 +++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/wx/dialog.h b/include/wx/dialog.h index 4951bc72b2..a791d83c55 100644 --- a/include/wx/dialog.h +++ b/include/wx/dialog.h @@ -90,8 +90,11 @@ public: void SetEscapeId(int escapeId); int GetEscapeId() const { return m_escapeId; } - // Returns the parent to use for modal dialogs if the user did not specify it - // explicitly. If parent argument is NULL, use GetParent() by default. + // Find the parent to use for modal dialog: try to use the specified parent + // but fall back to the current active window or main application window as + // last resort if it is unsuitable. + // + // This function always returns a valid top level window or NULL. wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const; #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index 18288235be..08e2282d8f 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -80,8 +80,10 @@ void wxDialogBase::Init() wxWindow *wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow *parent) const { - extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete; + if ( !parent ) + return NULL; + extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete; if ( wxPendingDelete.Member(parent) || parent->IsBeingDeleted() ) { // this window is being deleted and we shouldn't create any children @@ -120,17 +122,14 @@ wxWindow *wxDialogBase::GetParentForModalDialog(wxWindow *parent) const if ( HasFlag(wxDIALOG_NO_PARENT) ) return NULL; - // by default, use the parent specified in the ctor - if ( !parent ) - parent = GetParent(); - // first try the given parent if ( parent ) parent = CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent)); // then the currently active window if ( !parent ) - parent = CheckIfCanBeUsedAsParent(wxGetActiveWindow()); + parent = CheckIfCanBeUsedAsParent( + wxGetTopLevelParent(wxGetActiveWindow())); // and finally the application main window if ( !parent ) diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index 0d05469ff8..bb3fbd1586 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -111,7 +111,7 @@ int wxDialog::ShowModal() if ( win ) win->GTKReleaseMouseAndNotify(); - wxWindow * const parent = GetParentForModalDialog(); + wxWindow * const parent = GetParentForModalDialog(GetParent()); if ( parent ) { gtk_window_set_transient_for( GTK_WINDOW(m_widget), diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index a803576060..cafb0cd710 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -374,8 +374,9 @@ bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, return CreateFrame(title, pos, size); #else // !__WXMICROWIN__ // static cast is valid as we're only ever called for dialogs - wxWindow * const - parent = static_cast(this)->GetParentForModalDialog(); + wxWindow * const + parent = static_cast(this)-> + GetParentForModalDialog(GetParent()); m_hWnd = (WXHWND)::CreateDialogIndirect ( -- 2.45.2