// 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
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
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;
{
wxBusyCursor cursor;
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
return false;
const wxString& title,
int style)
{
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if ( !wxDialog::Create(parent, wxID_ANY, title,
wxDefaultPosition, wxDefaultSize,
{
m_bypassGenericImpl = bypassGenericImpl;
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
wildCard, style, pos, sz, name))
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,
const wxString& caption,
long style,
const wxPoint& pos)
- : wxMessageDialogBase(GetParentForModalDialog(parent),
+ : wxMessageDialogBase(GetParentForModalDialog(parent, style),
message,
caption,
style),
long min,
long max,
const wxPoint& pos)
- : wxDialog(GetParentForModalDialog(parent),
+ : wxDialog(GetParentForModalDialog(parent, 0),
wxID_ANY, caption,
pos, wxDefaultSize)
{
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 |
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 |
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),
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;
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)
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
)
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;
if ( win )
win->GTKReleaseMouseAndNotify();
- wxWindow * const parent = GetParentForModalDialog(GetParent());
+ wxWindow * const parent = GetParentForModalDialog();
if ( parent )
{
gtk_window_set_transient_for( GTK_WINDOW(m_widget),
{
m_message = title;
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!PreCreation(parent, pos, wxDefaultSize) ||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
const wxString& name)
: wxFileDialogBase()
{
- parent = GetParentForModalDialog(parent);
+ parent = GetParentForModalDialog(parent, style);
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName,
wildCard, style, pos, sz, name))
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,
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
- 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
}
// 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
#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
(
// 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);