+}
+
+// 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;
+ }