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:
// but fall back to the current active window or main application window as
// last resort if it is unsuitable.
//
// 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.
// 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
#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
// splits text up at newlines and places the
-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
{
// 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
return NULL;
// first try the given parent
bool wxGenericColourDialog::Create(wxWindow *parent, wxColourData *data)
{
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;
_("Choose colour"),
wxPoint(0, 0), wxSize(900, 900)) )
return false;
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
return false;
if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
return false;
const wxString& title,
int style)
{
const wxString& title,
int style)
{
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if ( !wxDialog::Create(parent, wxID_ANY, title,
wxDefaultPosition, wxDefaultSize,
if ( !wxDialog::Create(parent, wxID_ANY, title,
wxDefaultPosition, wxDefaultSize,
{
m_bypassGenericImpl = bypassGenericImpl;
{
m_bypassGenericImpl = bypassGenericImpl;
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
wildCard, style, pos, sz, name))
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
wildCard, style, pos, sz, name))
bool wxGenericFontDialog::DoCreate(wxWindow *parent)
{
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,
if ( !wxDialog::Create( parent , wxID_ANY , wxT("Choose Font") ,
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
const wxString& caption,
long style,
const wxPoint& pos)
const wxString& caption,
long style,
const wxPoint& pos)
- : wxMessageDialogBase(GetParentForModalDialog(parent),
+ : wxMessageDialogBase(GetParentForModalDialog(parent, style),
message,
caption,
style),
message,
caption,
style),
long min,
long max,
const wxPoint& pos)
long min,
long max,
const wxPoint& pos)
- : wxDialog(GetParentForModalDialog(parent),
+ : wxDialog(GetParentForModalDialog(parent, 0),
wxID_ANY, caption,
pos, wxDefaultSize)
{
wxID_ANY, caption,
pos, wxDefaultSize)
{
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
wxPrintDialogData* data)
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 |
wxID_ANY, _("Print"),
wxPoint(0,0), wxSize(600, 600),
wxDEFAULT_DIALOG_STYLE |
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
wxPrintData* data)
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 |
wxID_ANY, _("Print"),
wxPoint(0,0), wxSize(600, 600),
wxDEFAULT_DIALOG_STYLE |
int maximum,
wxWindow *parent,
int style)
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),
m_skip(false),
m_delay(3),
m_hasAbortButton(false),
const wxPoint& pos, const wxSize& sz, long style,
const wxString& name)
{
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;
if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
return false;
const wxString& value,
long style,
const wxPoint& pos)
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)
wxID_ANY, caption, pos, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE),
m_value(value)
wxTipDialog::wxTipDialog(wxWindow *parent,
wxTipProvider *tipProvider,
bool showAtStartup)
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
)
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
)
if (data)
m_data = *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;
GtkWindow * const parentGTK = m_parent ? GTK_WINDOW(m_parent->m_widget)
: NULL;
if ( win )
win->GTKReleaseMouseAndNotify();
if ( win )
win->GTKReleaseMouseAndNotify();
- wxWindow * const parent = GetParentForModalDialog(GetParent());
+ wxWindow * const parent = GetParentForModalDialog();
if ( parent )
{
gtk_window_set_transient_for( GTK_WINDOW(m_widget),
if ( parent )
{
gtk_window_set_transient_for( GTK_WINDOW(m_widget),
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!PreCreation(parent, pos, wxDefaultSize) ||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
if (!PreCreation(parent, pos, wxDefaultSize) ||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
const wxString& name)
: wxFileDialogBase()
{
const wxString& name)
: wxFileDialogBase()
{
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName,
wildCard, style, pos, sz, name))
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName,
wildCard, style, pos, sz, name))
bool wxFontDialog::DoCreate(wxWindow *parent)
{
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,
if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
const wxString& caption,
long style,
const wxPoint& WXUNUSED(pos))
const wxString& caption,
long style,
const wxPoint& WXUNUSED(pos))
- : wxMessageDialogWithCustomLabels(GetParentForModalDialog(parent),
- message,
- caption,
- style)
+ : wxMessageDialogWithCustomLabels
+ (
+ GetParentForModalDialog(parent, style),
+ message,
+ caption,
+ style
+ )
// use the apps top level window as parent if none given unless explicitly
// forbidden
// 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
}
wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
}
// use the top level window as parent if none specified
}
// 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
HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
#if wxUSE_INTL
#else // !__WXMICROWIN__
// static cast is valid as we're only ever called for dialogs
wxWindow * const
#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
(
m_hWnd = (WXHWND)::CreateDialogIndirect
(
// use the apps top level window as parent if none given unless explicitly
// forbidden
// 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;
- }