X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/57d7f9888e18d350fb023fdccd39e0ab7a3bb8dd..a0477b5a2b864a164a1012b3cfea03dc42e869ba:/src/common/dlgcmn.cpp

diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp
index be6afab98e..8430081563 100644
--- a/src/common/dlgcmn.cpp
+++ b/src/common/dlgcmn.cpp
@@ -27,6 +27,7 @@
 #include "wx/dialog.h"
 
 #ifndef WX_PRECOMP
+    #include "wx/app.h"
     #include "wx/button.h"
     #include "wx/dcclient.h"
     #include "wx/intl.h"
@@ -71,6 +72,36 @@ void wxDialogBase::Init()
     WX_INIT_CONTROL_CONTAINER();
 }
 
+// helper of GetParentForModalDialog()
+static bool CanBeUsedAsParent(wxWindow *parent)
+{
+    extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete;
+
+    return !parent->HasExtraStyle(wxWS_EX_TRANSIENT) &&
+                parent->IsShownOnScreen() &&
+                    !wxPendingDelete.Member(parent) &&
+                        parent->IsBeingDeleted();
+}
+
+wxWindow *wxDialogBase::GetParentForModalDialog(wxWindow *parent) const
+{
+    // creating a parent-less modal dialog will result (under e.g. wxGTK2)
+    // in an unfocused dialog, so try to find a valid parent for it:
+    if ( parent )
+        parent = wxGetTopLevelParent(parent);
+
+    if ( !parent || !CanBeUsedAsParent(parent) )
+        parent = wxTheApp->GetTopWindow();
+
+    if ( parent && !CanBeUsedAsParent(parent) )
+    {
+        // can't use this one, it's going to disappear
+        parent = NULL;
+    }
+
+    return parent;
+}
+
 #if wxUSE_STATTEXT
 
 class wxTextSizerWrapper : public wxTextWrapper