diff --git a/include/wx/dialog.h b/include/wx/dialog.h index 71c80a0fc4..bcdbeecaee 100644 --- a/include/wx/dialog.h +++ b/include/wx/dialog.h @@ -98,8 +98,19 @@ public: // but fall back to the current active window or main application window as // last resort if it is unsuitable. // + // As this function is often called from the ctor, the window style may be + // not set yet and hence must be passed explicitly to it so that we could + // check whether it contains wxDIALOG_NO_PARENT bit. + // // This function always returns a valid top level window or NULL. - wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const; + wxWindow *GetParentForModalDialog(wxWindow *parent, long style) const; + + // This overload can only be used for already initialized windows, i.e. not + // from the ctor. It uses the current window parent and style. + wxWindow *GetParentForModalDialog() const + { + return GetParentForModalDialog(GetParent(), GetWindowStyle()); + } #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL // splits text up at newlines and places the diff --git a/src/common/dlgcmn.cpp b/src/common/dlgcmn.cpp index 345d01a2d8..0ba3bc7d33 100644 --- a/src/common/dlgcmn.cpp +++ b/src/common/dlgcmn.cpp @@ -116,12 +116,13 @@ wxWindow *wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow *parent) const return parent; } -wxWindow *wxDialogBase::GetParentForModalDialog(wxWindow *parent) const +wxWindow * +wxDialogBase::GetParentForModalDialog(wxWindow *parent, long style) 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 unless we // were explicitly asked not to - if ( HasFlag(wxDIALOG_NO_PARENT) ) + if ( style & wxDIALOG_NO_PARENT ) return NULL; // first try the given parent diff --git a/src/generic/colrdlgg.cpp b/src/generic/colrdlgg.cpp index 03c93c5e8b..83f9bc0049 100644 --- a/src/generic/colrdlgg.cpp +++ b/src/generic/colrdlgg.cpp @@ -140,7 +140,7 @@ void wxGenericColourDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) bool wxGenericColourDialog::Create(wxWindow *parent, wxColourData *data) { - if ( !wxDialog::Create(GetParentForModalDialog(parent), wxID_ANY, + if ( !wxDialog::Create(GetParentForModalDialog(parent, 0), wxID_ANY, _("Choose colour"), wxPoint(0, 0), wxSize(900, 900)) ) return false; diff --git a/src/generic/dirdlgg.cpp b/src/generic/dirdlgg.cpp index f3a8fd5a5c..1222695add 100644 --- a/src/generic/dirdlgg.cpp +++ b/src/generic/dirdlgg.cpp @@ -79,7 +79,7 @@ bool wxGenericDirDialog::Create(wxWindow* parent, { wxBusyCursor cursor; - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, style); if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name)) return false; diff --git a/src/generic/fdrepdlg.cpp b/src/generic/fdrepdlg.cpp index f9dd9b24d6..87a9ee5380 100644 --- a/src/generic/fdrepdlg.cpp +++ b/src/generic/fdrepdlg.cpp @@ -87,7 +87,7 @@ bool wxGenericFindReplaceDialog::Create(wxWindow *parent, const wxString& title, int style) { - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, style); if ( !wxDialog::Create(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index dc2719db4b..f34ff0a9ed 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -164,7 +164,7 @@ bool wxGenericFileDialog::Create( wxWindow *parent, { m_bypassGenericImpl = bypassGenericImpl; - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, style); if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile, wildCard, style, pos, sz, name)) diff --git a/src/generic/fontdlgg.cpp b/src/generic/fontdlgg.cpp index 12125d5c16..b0cc8c996a 100644 --- a/src/generic/fontdlgg.cpp +++ b/src/generic/fontdlgg.cpp @@ -282,7 +282,7 @@ void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) bool wxGenericFontDialog::DoCreate(wxWindow *parent) { - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, 0); if ( !wxDialog::Create( parent , wxID_ANY , wxT("Choose Font") , wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, diff --git a/src/generic/msgdlgg.cpp b/src/generic/msgdlgg.cpp index bded8f883f..d908ebb47f 100644 --- a/src/generic/msgdlgg.cpp +++ b/src/generic/msgdlgg.cpp @@ -60,7 +60,7 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString& caption, long style, const wxPoint& pos) - : wxMessageDialogBase(GetParentForModalDialog(parent), + : wxMessageDialogBase(GetParentForModalDialog(parent, style), message, caption, style), diff --git a/src/generic/numdlgg.cpp b/src/generic/numdlgg.cpp index 16a056b257..0fc0424ff5 100644 --- a/src/generic/numdlgg.cpp +++ b/src/generic/numdlgg.cpp @@ -77,7 +77,7 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent, long min, long max, const wxPoint& pos) - : wxDialog(GetParentForModalDialog(parent), + : wxDialog(GetParentForModalDialog(parent, 0), wxID_ANY, caption, pos, wxDefaultSize) { diff --git a/src/generic/prntdlgg.cpp b/src/generic/prntdlgg.cpp index eb6a6fb8f1..6a940febfa 100644 --- a/src/generic/prntdlgg.cpp +++ b/src/generic/prntdlgg.cpp @@ -145,7 +145,7 @@ END_EVENT_TABLE() wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintDialogData* data) - : wxPrintDialogBase(GetParentForModalDialog(parent), + : wxPrintDialogBase(GetParentForModalDialog(parent, 0), wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE | @@ -159,7 +159,7 @@ wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintData* data) - : wxPrintDialogBase(GetParentForModalDialog(parent), + : wxPrintDialogBase(GetParentForModalDialog(parent, 0), wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE | diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp index 77af0c76aa..443d354104 100644 --- a/src/generic/progdlgg.cpp +++ b/src/generic/progdlgg.cpp @@ -99,7 +99,7 @@ wxProgressDialog::wxProgressDialog(const wxString& title, int maximum, wxWindow *parent, int style) - : wxDialog(GetParentForModalDialog(parent), wxID_ANY, title), + : wxDialog(GetParentForModalDialog(parent, style), wxID_ANY, title), m_skip(false), m_delay(3), m_hasAbortButton(false), diff --git a/src/generic/propdlg.cpp b/src/generic/propdlg.cpp index 54a49b5dfa..20b01263c9 100644 --- a/src/generic/propdlg.cpp +++ b/src/generic/propdlg.cpp @@ -62,7 +62,7 @@ bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxStri const wxPoint& pos, const wxSize& sz, long style, const wxString& name) { - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, style); if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name)) return false; diff --git a/src/generic/textdlgg.cpp b/src/generic/textdlgg.cpp index d1f96ebfe5..d6e402bd1f 100644 --- a/src/generic/textdlgg.cpp +++ b/src/generic/textdlgg.cpp @@ -71,7 +71,7 @@ wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& value, long style, const wxPoint& pos) - : wxDialog(GetParentForModalDialog(parent), + : wxDialog(GetParentForModalDialog(parent, style), wxID_ANY, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE), m_value(value) diff --git a/src/generic/tipdlg.cpp b/src/generic/tipdlg.cpp index feee0ac4b6..9de9692a5f 100644 --- a/src/generic/tipdlg.cpp +++ b/src/generic/tipdlg.cpp @@ -218,7 +218,7 @@ END_EVENT_TABLE() wxTipDialog::wxTipDialog(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup) - : wxDialog(GetParentForModalDialog(parent), wxID_ANY, _("Tip of the Day"), + : wxDialog(GetParentForModalDialog(parent, 0), wxID_ANY, _("Tip of the Day"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ) diff --git a/src/gtk/colordlg.cpp b/src/gtk/colordlg.cpp index 893311f989..0c606ca018 100644 --- a/src/gtk/colordlg.cpp +++ b/src/gtk/colordlg.cpp @@ -48,7 +48,7 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) if (data) m_data = *data; - m_parent = GetParentForModalDialog(parent); + m_parent = GetParentForModalDialog(parent, 0); GtkWindow * const parentGTK = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL; diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index bb3fbd1586..0d05469ff8 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(GetParent()); + wxWindow * const parent = GetParentForModalDialog(); if ( parent ) { gtk_window_set_transient_for( GTK_WINDOW(m_widget), diff --git a/src/gtk/dirdlg.cpp b/src/gtk/dirdlg.cpp index a1d32a3e8b..7f06ed819a 100644 --- a/src/gtk/dirdlg.cpp +++ b/src/gtk/dirdlg.cpp @@ -99,7 +99,7 @@ wxDirDialog::wxDirDialog(wxWindow* parent, { m_message = title; - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, style); if (!PreCreation(parent, pos, wxDefaultSize) || !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style, diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index 3e63c53243..278950e6ab 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -173,7 +173,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& name) : wxFileDialogBase() { - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, style); if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name)) diff --git a/src/gtk/fontdlg.cpp b/src/gtk/fontdlg.cpp index 83b7c23ff1..8ad18f9eca 100644 --- a/src/gtk/fontdlg.cpp +++ b/src/gtk/fontdlg.cpp @@ -86,7 +86,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) bool wxFontDialog::DoCreate(wxWindow *parent) { - parent = GetParentForModalDialog(parent); + parent = GetParentForModalDialog(parent, 0); if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, diff --git a/src/gtk/msgdlg.cpp b/src/gtk/msgdlg.cpp index eee220b449..dc24565e39 100644 --- a/src/gtk/msgdlg.cpp +++ b/src/gtk/msgdlg.cpp @@ -44,10 +44,13 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& caption, long style, const wxPoint& WXUNUSED(pos)) - : wxMessageDialogWithCustomLabels(GetParentForModalDialog(parent), - message, - caption, - style) + : wxMessageDialogWithCustomLabels + ( + GetParentForModalDialog(parent, style), + message, + caption, + style + ) { } diff --git a/src/gtk1/dialog.cpp b/src/gtk1/dialog.cpp index 540910d9dc..54bac5264f 100644 --- a/src/gtk1/dialog.cpp +++ b/src/gtk1/dialog.cpp @@ -192,14 +192,11 @@ int wxDialog::ShowModal() // use the apps top level window as parent if none given unless explicitly // forbidden - if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) + wxWindow * const parent = GetParentForModalDialog(); + if ( parent ) { - wxWindow * const parent = GetParentForModalDialog(); - if ( parent ) - { - m_parent = parent; - gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget) ); - } + m_parent = parent; + gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget) ); } wxBusyCursorSuspender cs; // temporarily suppress the busy cursor diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index feddca7521..b25e7b84e0 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -443,8 +443,7 @@ int wxMessageDialog::ShowModal() } // use the top level window as parent if none specified - if ( !m_parent ) - m_parent = GetParentForModalDialog(); + m_parent = GetParentForModalDialog(); HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL; #if wxUSE_INTL diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index d5b115495e..cfcf7f7836 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -375,8 +375,7 @@ bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, #else // !__WXMICROWIN__ // static cast is valid as we're only ever called for dialogs wxWindow * const - parent = static_cast(this)-> - GetParentForModalDialog(GetParent()); + parent = static_cast(this)->GetParentForModalDialog(); m_hWnd = (WXHWND)::CreateDialogIndirect ( diff --git a/src/univ/dialog.cpp b/src/univ/dialog.cpp index f0f3d659c2..c0f69439b7 100644 --- a/src/univ/dialog.cpp +++ b/src/univ/dialog.cpp @@ -179,13 +179,10 @@ int wxDialog::ShowModal() // use the apps top level window as parent if none given unless explicitly // forbidden - if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) + wxWindow * const parent = GetParentForModalDialog(); + if ( parent && parent != this ) { - wxWindow * const parent = GetParentForModalDialog(); - if ( parent && parent != this ) - { - m_parent = parent; - } + m_parent = parent; } Show(true);