]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxDialog::GetParentForModalDialog() and use it to try to always create modal...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 22 Apr 2007 20:34:41 +0000 (20:34 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 22 Apr 2007 20:34:41 +0000 (20:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45588 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

20 files changed:
include/wx/dialog.h
src/common/dlgcmn.cpp
src/generic/aboutdlgg.cpp
src/generic/colrdlgg.cpp
src/generic/dirdlgg.cpp
src/generic/fdrepdlg.cpp
src/generic/filedlgg.cpp
src/generic/fontdlgg.cpp
src/generic/msgdlgg.cpp
src/generic/numdlgg.cpp
src/generic/prntdlgg.cpp
src/generic/progdlgg.cpp
src/generic/propdlg.cpp
src/generic/textdlgg.cpp
src/generic/tipdlg.cpp
src/gtk/colordlg.cpp
src/gtk/dirdlg.cpp
src/gtk/filedlg.cpp
src/gtk/fontdlg.cpp
src/gtk/msgdlg.cpp

index 766771c42d538c2b5f5cf2b7dc07b89bb7a2f38d..58a30e2d0c1247fea384a2e0425cbc8dd9ae44de 100644 (file)
@@ -64,6 +64,10 @@ 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
+    wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const;
+
 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
     // splits text up at newlines and places the
     // lines into a vertical wxBoxSizer
index be6afab98ef04c4ee740d089feb6914e895e00f6..ec5a528ad43d8e6cf87d8598771ae927f6e2fd14 100644 (file)
@@ -71,6 +71,25 @@ void wxDialogBase::Init()
     WX_INIT_CONTROL_CONTAINER();
 }
 
+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 || parent->HasExtraStyle(wxWS_EX_TRANSIENT) )
+        parent = wxTheApp->GetTopWindow();
+
+    if ( parent && parent->HasExtraStyle(wxWS_EX_TRANSIENT) )
+    {
+        // can't use this one, it's going to disappear
+        parent = NULL;
+    }
+
+    return parent;
+}
+
 #if wxUSE_STATTEXT
 
 class wxTextSizerWrapper : public wxTextWrapper
index 33cd027719517c027d47860398bc70e120e0440d..77e5d513c2f81e7e78bf0e0932f1b0c00720fa4f 100644 (file)
@@ -102,8 +102,8 @@ wxIcon wxAboutDialogInfo::GetIcon() const
 
 bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
 {
-    // TODO: should we use main frame as parent by default here?
-    if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName(),
+    // this is a modal dialog thus we'll use GetParentForModalDialog:
+    if ( !wxDialog::Create(GetParentForModalDialog(), wxID_ANY, _("About ") + info.GetName(),
                            wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
         return false;
 
index ec97500ac8cd9942828e1278995df74e6edd61c0..0f4bfd6bab9c5c1ab43226172f525daf58e763f8 100644 (file)
@@ -140,8 +140,9 @@ void wxGenericColourDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 
 bool wxGenericColourDialog::Create(wxWindow *parent, wxColourData *data)
 {
-    if ( !wxDialog::Create(parent, wxID_ANY, _("Choose colour"),
-                           wxPoint(0,0), wxSize(900, 900)) )
+    if ( !wxDialog::Create(GetParentForModalDialog(parent), wxID_ANY,
+                           _("Choose colour"),
+                           wxPoint(0, 0), wxSize(900, 900)) )
         return false;
 
     if (data)
index 5b7b50b2c3ef981aa122e033f21e0c6190f7fabc..bfe97a9cf94babd4a96b19fc1109bfbfea618f30 100644 (file)
@@ -78,6 +78,8 @@ bool wxGenericDirDialog::Create(wxWindow* parent,
 {
     wxBusyCursor cursor;
 
+    parent = GetParentForModalDialog(parent);
+
     if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
         return false;
 
index 797ac68cbb8d039b900daa8bf2003de22b066784..976ade0dec51b119d592e102c02b69b538938d16 100644 (file)
@@ -87,6 +87,8 @@ bool wxGenericFindReplaceDialog::Create(wxWindow *parent,
                                         const wxString& title,
                                         int style)
 {
+    parent = GetParentForModalDialog(parent);
+
     if ( !wxDialog::Create(parent, wxID_ANY, title,
                            wxDefaultPosition, wxDefaultSize,
                            wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
index 2f493b2e322b56a54eb81a9e246623a360e83bea..90c086fd97e4a40c1b74242806aead8cbe5eeb69 100644 (file)
@@ -996,6 +996,8 @@ bool wxGenericFileDialog::Create( wxWindow *parent,
 {
     m_bypassGenericImpl = bypassGenericImpl;
 
+    parent = GetParentForModalDialog(parent);
+
     if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
                                   wildCard, style, pos, sz, name))
     {
index 06a23703c63994399ca7c0a94c3739f9238d09af..175954049b4b98afb8fb0d78eb887145d56611b0 100644 (file)
@@ -190,7 +190,10 @@ void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 
 bool wxGenericFontDialog::DoCreate(wxWindow *parent)
 {
-    if ( !wxDialog::Create( parent , wxID_ANY , _T("Choose Font") , wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
+    parent = GetParentForModalDialog(parent);
+
+    if ( !wxDialog::Create( parent , wxID_ANY , _T("Choose Font") ,
+                            wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
         _T("fontdialog") ) )
     {
         wxFAIL_MSG( wxT("wxFontDialog creation failed") );
index e17387ba58737dedce377200a176583393eca50f..1565d88e4f81af2c4c7c1909678f924de0c063e3 100644 (file)
@@ -64,6 +64,8 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
 {
     SetMessageDialogStyle(style);
 
+    parent = GetParentForModalDialog(parent);
+
     bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
 
     wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
index 615b64ba0f2c4b82b652316b99a6a127a966c0a4..a7099e1c19aae8b677809b1a6098406a81fe190d 100644 (file)
@@ -77,7 +77,8 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
                                          long min,
                                          long max,
                                          const wxPoint& pos)
-                   : wxDialog(parent, wxID_ANY, caption,
+                   : wxDialog(GetParentForModalDialog(parent),
+                              wxID_ANY, caption,
                               pos, wxDefaultSize)
 {
     m_value = value;
index 3b0fb9a59ab7a482be8f16d8fc6419ac80ae05ce..18e5c56675af9546594ac1f97751a5ce91862066 100644 (file)
@@ -136,7 +136,8 @@ END_EVENT_TABLE()
 
 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
                                            wxPrintDialogData* data)
-                    : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
+                    : wxPrintDialogBase(GetParentForModalDialog(parent), 
+                               wxID_ANY, _("Print"),
                                wxPoint(0,0), wxSize(600, 600),
                                wxDEFAULT_DIALOG_STYLE |
                                wxTAB_TRAVERSAL)
@@ -149,7 +150,8 @@ wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
 
 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
                                            wxPrintData* data)
-                    : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
+                    : wxPrintDialogBase(GetParentForModalDialog(parent), 
+                                wxID_ANY, _("Print"),
                                wxPoint(0,0), wxSize(600, 600),
                                wxDEFAULT_DIALOG_STYLE |
                                wxTAB_TRAVERSAL)
index ec7f57c95133ee0f03cdefd27483915cb3f98b70..f230c3745803bc6b0944b3391b882684b1dd6afc 100644 (file)
@@ -97,7 +97,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
                                    int maximum,
                                    wxWindow *parent,
                                    int style)
-                : wxDialog(parent, wxID_ANY, title),
+                : wxDialog(GetParentForModalDialog(parent), wxID_ANY, title),
                   m_skip(false),
                   m_delay(3),
                   m_hasAbortButton(false),
index 15cd495c34befd10b5853f3564a5a952addcfae0..fa41bed4a8ed12c335546734d98d2cac10b33f36 100644 (file)
@@ -62,6 +62,8 @@ bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxStri
                                        const wxPoint& pos, const wxSize& sz, long style,
                                        const wxString& name)
 {
+    parent = GetParentForModalDialog(parent);
+
     if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
         return false;
 
index de16dbbd5c8d42f483ac862b7d556c9740611811..e7b809eb60ea504dcbdde8adf828965e3b57f53c 100644 (file)
@@ -71,7 +71,8 @@ wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
                                      const wxString& value,
                                      long style,
                                      const wxPoint& pos)
-                 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
+                 : wxDialog(GetParentForModalDialog(parent),
+                            wxID_ANY, caption, pos, wxDefaultSize,
                             wxDEFAULT_DIALOG_STYLE),
                    m_value(value)
 {
index e8fbb90d0c137a41c123033c64fa4b2007fd840d..491a0ba700156bc8c85ca03bff9fa451d75abb63 100644 (file)
@@ -215,7 +215,7 @@ END_EVENT_TABLE()
 wxTipDialog::wxTipDialog(wxWindow *parent,
                          wxTipProvider *tipProvider,
                          bool showAtStartup)
-           : wxDialog(parent, wxID_ANY, _("Tip of the Day"),
+           : wxDialog(GetParentForModalDialog(parent), wxID_ANY, _("Tip of the Day"),
                       wxDefaultPosition, wxDefaultSize,
                       wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
                       )
index 34e9c118fea275d20cd3f43b18d11bee17fbbf99..20bacbb9e29e9658261ac3b1bf63122f060a5856 100644 (file)
@@ -41,9 +41,10 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
     wxString title(_("Choose colour"));
     m_widget = gtk_color_selection_dialog_new(wxGTK_CONV(title));
 
-    if (parent)
+    m_parent = GetParentForModalDialog(parent);
+    if ( m_parent )
     {
-        GtkWindow* gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) );
+        GtkWindow* gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(m_parent->m_widget) );
         gtk_window_set_transient_for(GTK_WINDOW(m_widget),
                                      gtk_parent);
     }
index 699f568fcb0596f37a379f7859f5a683dd4990da..f555dcdf17141de04ed15a20ced61e1bb3bf2ecd 100644 (file)
@@ -99,6 +99,8 @@ wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
         m_message = title;
         m_needParent = false;
 
+        parent = GetParentForModalDialog(parent);
+
         if (!PreCreation(parent, pos, wxDefaultSize) ||
             !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
                     wxDefaultValidator, wxT("dirdialog")))
index 65e530ab25d0b344c52485d624eae8517daa894f..60fc46cdb8bbf9dbd1b00ec1102eec3607b0752d 100644 (file)
@@ -154,6 +154,8 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
 
     m_needParent = false;
 
+    parent = GetParentForModalDialog(parent);
+
     if (!PreCreation(parent, pos, wxDefaultSize) ||
         !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
                 wxDefaultValidator, wxT("filedialog")))
index c95411e3709b872ffd81097169b0e3e7dbb38b28..c20b8b55ab6f617572b029c9498ced2c854c551d 100644 (file)
@@ -88,6 +88,8 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
 {
     m_needParent = false;
 
+    parent = GetParentForModalDialog(parent);
+
     if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
         !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
                      wxDefaultValidator, wxT("fontdialog") ))
index e2b0a4ef26421f0d7cda8f5c7cc0db9aeabb433e..ddbecfa54a02620f999e38cd308c1e4e79f045ad 100644 (file)
@@ -38,7 +38,8 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent,
     m_caption = caption;
     m_message = message;
     SetMessageDialogStyle(style);
-    m_parent = wxGetTopLevelParent(parent);
+
+    m_parent = GetParentForModalDialog(parent);
 
     GtkMessageType type = GTK_MESSAGE_ERROR;
     GtkButtonsType buttons = GTK_BUTTONS_OK;