]> git.saurik.com Git - wxWidgets.git/commitdiff
don't use GetParent() in GetParentForModalDialog() itself as it can be called before...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 May 2009 16:55:37 +0000 (16:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 May 2009 16:55:37 +0000 (16:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60573 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dialog.h
src/common/dlgcmn.cpp
src/gtk/dialog.cpp
src/msw/toplevel.cpp

index 4951bc72b26644d15cd9b1fa811895c0792533ce..a791d83c55e17835d56debd278a0501caf477fe8 100644 (file)
@@ -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
index 18288235be8c8d342596e2a9269b357d355c55eb..08e2282d8ff250b00746ffb29e4e078cb3c4b036 100644 (file)
@@ -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 )
index 0d05469ff809c0b3a4ba0f12fd1d2b86bf24efad..bb3fbd15861debc507680e88d388b7060126c23c 100644 (file)
@@ -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),
index a803576060e38d2117e6d896666b0acba61213ae..cafb0cd7103294edc935d37bd36b078a2a2d4069 100644 (file)
@@ -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<wxDialog *>(this)->GetParentForModalDialog();
+    wxWindow * const
+        parent = static_cast<wxDialog *>(this)->
+                    GetParentForModalDialog(GetParent());
 
     m_hWnd = (WXHWND)::CreateDialogIndirect
                        (