]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix bug with using uninitialized flags in GetParentForModalDialog().
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 18 Apr 2010 00:05:37 +0000 (00:05 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 18 Apr 2010 00:05:37 +0000 (00:05 +0000)
GetParentForModalDialog() was called from the ctor initialized list before
m_windowStyle could be initialized by the base class ctor in several different
places, meaning that the check for wxDIALOG_NO_PARENT in this function was
using uninitialized variable.

Fix this by passing the style parameter explicitly to this function to allow
using it from derived class ctors. Still keep an overload which uses the
actual window parent and flags which is simpler to use for later calls to this
function.

Thanks valgrind for finding this one.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64019 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

24 files changed:
include/wx/dialog.h
src/common/dlgcmn.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/dialog.cpp
src/gtk/dirdlg.cpp
src/gtk/filedlg.cpp
src/gtk/fontdlg.cpp
src/gtk/msgdlg.cpp
src/gtk1/dialog.cpp
src/msw/msgdlg.cpp
src/msw/toplevel.cpp
src/univ/dialog.cpp

index 71c80a0fc461ec19de94df714c6f7a5927c375fc..bcdbeecaee700e42d208f458857c93b55d56d23a 100644 (file)
@@ -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
index 345d01a2d84d52d86854ee40729353520aef904c..0ba3bc7d3308ca6cfe5f267c57aa93e2a8a64bcf 100644 (file)
@@ -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
index 03c93c5e8bb3465b0c6f230affd2d4a3441a834b..83f9bc004924b170d672c857ce7d82183d10433f 100644 (file)
@@ -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;
index f3a8fd5a5cd50aa576d50f8ff722b30a2877dc40..1222695adda9826b5ff0dbf72b3a9494ef5ecc15 100644 (file)
@@ -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;
index f9dd9b24d6a08598926544a2cb20ca4774106b65..87a9ee5380da36bd66fa887f8fa1ca7fb1352840 100644 (file)
@@ -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,
index dc2719db4bc6bbff746210668b01935abb1eb35c..f34ff0a9ed28f850e5e8891a9230421e5fdb6796 100644 (file)
@@ -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))
index 12125d5c16c0d01345b9caee278fdbe71a0c93db..b0cc8c996af959a196c11d4a5f4179064279fe6a 100644 (file)
@@ -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,
index bded8f883fd67929afa054fb22d2fb3790cd3e65..d908ebb47f08d0e03efe6bf3e9bda05fb2a6365c 100644 (file)
@@ -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),
index 16a056b257390724a0cab83823fbf8e062fb9044..0fc0424ff58401b60a5f18c0a602e4a2c6219cd7 100644 (file)
@@ -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)
 {
index eb6a6fb8f1e2ed8cabe71872a4267e5d3560bf76..6a940febfa3c8bb2141be2884be98477c8755e65 100644 (file)
@@ -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 |
index 77af0c76aaae6a6a850b186d6b759646368e15ca..443d354104bc5e929e0e16c8c18660617a800d2d 100644 (file)
@@ -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),
index 54a49b5dfad8ed6803ac5d47bd86df99cebcaacd..20b01263c927916ec7919b8c06ca1ef3edf2ef0e 100644 (file)
@@ -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;
index d1f96ebfe5368c861519c1042c28b3b1f4a45036..d6e402bd1f0e592c452740debe0e3d80dffc9b8f 100644 (file)
@@ -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)
index feee0ac4b62f9b323bf31ee645c9e7a5e52c6ef3..9de9692a5fcba1717f9defbe2ad165fb24676270 100644 (file)
@@ -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
                       )
index 893311f989be2ef1b0f129de66da1e585c767640..0c606ca0186cc6241413b53fbfa55cf97196bf5e 100644 (file)
@@ -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;
 
index bb3fbd15861debc507680e88d388b7060126c23c..0d05469ff809c0b3a4ba0f12fd1d2b86bf24efad 100644 (file)
@@ -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),
index a1d32a3e8b04070648f719ba64e3daff452ee162..7f06ed819aaf512807515c7935ad49b246f11451 100644 (file)
@@ -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,
index 3e63c532434a725617a0d6d6dd037cd9d57f6fac..278950e6ab332db825c52ab3ba05e2909888b9f8 100644 (file)
@@ -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))
index 83b7c23ff15d382a16eeb191758853c8257fc21a..8ad18f9eca3caac7d23df7ca2c261f8905d04a4f 100644 (file)
@@ -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,
index eee220b449bf566d9fcbfeddaa3fdebe03b28eab..dc24565e391852c931f817fb7ccb43a1a40c77e7 100644 (file)
@@ -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
+                 )
 {
 }
 
index 540910d9dc035f9b00b5cb016fad385a4464b07b..54bac5264ff20430f3fb380cb12375da5227cafd 100644 (file)
@@ -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
index feddca75214a8eba9c69b9d419456d73ad06be27..b25e7b84e0c6d0544df7a864ea917f7805478813 100644 (file)
@@ -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
index d5b115495e7b8d9988796b8407ca07bef2237cdc..cfcf7f783601d950a1701e7b24b5453fbe7c7965 100644 (file)
@@ -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<wxDialog *>(this)->
-                    GetParentForModalDialog(GetParent());
+        parent = static_cast<wxDialog *>(this)->GetParentForModalDialog();
 
     m_hWnd = (WXHWND)::CreateDialogIndirect
                        (
index f0f3d659c228c50bff92c392ada6356fce8a08e4..c0f69439b7b74faa65cd23ac9a276c5c224b39d3 100644 (file)
@@ -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);