added wxDialog::GetParentForModalDialog() and use it to try to always create modal dialogs with a parent (slightly modified patch 1702962)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45588 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -64,6 +64,10 @@ public:
|
|||||||
void SetEscapeId(int escapeId);
|
void SetEscapeId(int escapeId);
|
||||||
int GetEscapeId() const { return m_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
|
#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
|
||||||
// splits text up at newlines and places the
|
// splits text up at newlines and places the
|
||||||
// lines into a vertical wxBoxSizer
|
// lines into a vertical wxBoxSizer
|
||||||
|
@@ -71,6 +71,25 @@ void wxDialogBase::Init()
|
|||||||
WX_INIT_CONTROL_CONTAINER();
|
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
|
#if wxUSE_STATTEXT
|
||||||
|
|
||||||
class wxTextSizerWrapper : public wxTextWrapper
|
class wxTextSizerWrapper : public wxTextWrapper
|
||||||
|
@@ -102,8 +102,8 @@ wxIcon wxAboutDialogInfo::GetIcon() const
|
|||||||
|
|
||||||
bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
|
bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
|
||||||
{
|
{
|
||||||
// TODO: should we use main frame as parent by default here?
|
// this is a modal dialog thus we'll use GetParentForModalDialog:
|
||||||
if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName(),
|
if ( !wxDialog::Create(GetParentForModalDialog(), wxID_ANY, _("About ") + info.GetName(),
|
||||||
wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
|
wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -140,8 +140,9 @@ void wxGenericColourDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
bool wxGenericColourDialog::Create(wxWindow *parent, wxColourData *data)
|
bool wxGenericColourDialog::Create(wxWindow *parent, wxColourData *data)
|
||||||
{
|
{
|
||||||
if ( !wxDialog::Create(parent, wxID_ANY, _("Choose colour"),
|
if ( !wxDialog::Create(GetParentForModalDialog(parent), wxID_ANY,
|
||||||
wxPoint(0,0), wxSize(900, 900)) )
|
_("Choose colour"),
|
||||||
|
wxPoint(0, 0), wxSize(900, 900)) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
|
@@ -78,6 +78,8 @@ bool wxGenericDirDialog::Create(wxWindow* parent,
|
|||||||
{
|
{
|
||||||
wxBusyCursor cursor;
|
wxBusyCursor cursor;
|
||||||
|
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
|
if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -87,6 +87,8 @@ bool wxGenericFindReplaceDialog::Create(wxWindow *parent,
|
|||||||
const wxString& title,
|
const wxString& title,
|
||||||
int style)
|
int style)
|
||||||
{
|
{
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
if ( !wxDialog::Create(parent, wxID_ANY, title,
|
if ( !wxDialog::Create(parent, wxID_ANY, title,
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
|
||||||
|
@@ -996,6 +996,8 @@ bool wxGenericFileDialog::Create( wxWindow *parent,
|
|||||||
{
|
{
|
||||||
m_bypassGenericImpl = bypassGenericImpl;
|
m_bypassGenericImpl = bypassGenericImpl;
|
||||||
|
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
|
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
|
||||||
wildCard, style, pos, sz, name))
|
wildCard, style, pos, sz, name))
|
||||||
{
|
{
|
||||||
|
@@ -190,7 +190,10 @@ void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
bool wxGenericFontDialog::DoCreate(wxWindow *parent)
|
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") ) )
|
_T("fontdialog") ) )
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("wxFontDialog creation failed") );
|
wxFAIL_MSG( wxT("wxFontDialog creation failed") );
|
||||||
|
@@ -64,6 +64,8 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
|
|||||||
{
|
{
|
||||||
SetMessageDialogStyle(style);
|
SetMessageDialogStyle(style);
|
||||||
|
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
|
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
|
||||||
|
|
||||||
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
@@ -77,7 +77,8 @@ wxNumberEntryDialog::wxNumberEntryDialog(wxWindow *parent,
|
|||||||
long min,
|
long min,
|
||||||
long max,
|
long max,
|
||||||
const wxPoint& pos)
|
const wxPoint& pos)
|
||||||
: wxDialog(parent, wxID_ANY, caption,
|
: wxDialog(GetParentForModalDialog(parent),
|
||||||
|
wxID_ANY, caption,
|
||||||
pos, wxDefaultSize)
|
pos, wxDefaultSize)
|
||||||
{
|
{
|
||||||
m_value = value;
|
m_value = value;
|
||||||
|
@@ -136,7 +136,8 @@ END_EVENT_TABLE()
|
|||||||
|
|
||||||
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
|
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
|
||||||
wxPrintDialogData* data)
|
wxPrintDialogData* data)
|
||||||
: wxPrintDialogBase(parent, wxID_ANY, _("Print"),
|
: wxPrintDialogBase(GetParentForModalDialog(parent),
|
||||||
|
wxID_ANY, _("Print"),
|
||||||
wxPoint(0,0), wxSize(600, 600),
|
wxPoint(0,0), wxSize(600, 600),
|
||||||
wxDEFAULT_DIALOG_STYLE |
|
wxDEFAULT_DIALOG_STYLE |
|
||||||
wxTAB_TRAVERSAL)
|
wxTAB_TRAVERSAL)
|
||||||
@@ -149,7 +150,8 @@ wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
|
|||||||
|
|
||||||
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
|
wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
|
||||||
wxPrintData* data)
|
wxPrintData* data)
|
||||||
: wxPrintDialogBase(parent, wxID_ANY, _("Print"),
|
: wxPrintDialogBase(GetParentForModalDialog(parent),
|
||||||
|
wxID_ANY, _("Print"),
|
||||||
wxPoint(0,0), wxSize(600, 600),
|
wxPoint(0,0), wxSize(600, 600),
|
||||||
wxDEFAULT_DIALOG_STYLE |
|
wxDEFAULT_DIALOG_STYLE |
|
||||||
wxTAB_TRAVERSAL)
|
wxTAB_TRAVERSAL)
|
||||||
|
@@ -97,7 +97,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
|
|||||||
int maximum,
|
int maximum,
|
||||||
wxWindow *parent,
|
wxWindow *parent,
|
||||||
int style)
|
int style)
|
||||||
: wxDialog(parent, wxID_ANY, title),
|
: wxDialog(GetParentForModalDialog(parent), wxID_ANY, title),
|
||||||
m_skip(false),
|
m_skip(false),
|
||||||
m_delay(3),
|
m_delay(3),
|
||||||
m_hasAbortButton(false),
|
m_hasAbortButton(false),
|
||||||
|
@@ -62,6 +62,8 @@ bool wxPropertySheetDialog::Create(wxWindow* parent, wxWindowID id, const wxStri
|
|||||||
const wxPoint& pos, const wxSize& sz, long style,
|
const wxPoint& pos, const wxSize& sz, long style,
|
||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
|
if (!wxDialog::Create(parent, id, title, pos, sz, style|wxCLIP_CHILDREN, name))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -71,7 +71,8 @@ wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent,
|
|||||||
const wxString& value,
|
const wxString& value,
|
||||||
long style,
|
long style,
|
||||||
const wxPoint& pos)
|
const wxPoint& pos)
|
||||||
: wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
|
: wxDialog(GetParentForModalDialog(parent),
|
||||||
|
wxID_ANY, caption, pos, wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE),
|
wxDEFAULT_DIALOG_STYLE),
|
||||||
m_value(value)
|
m_value(value)
|
||||||
{
|
{
|
||||||
|
@@ -215,7 +215,7 @@ END_EVENT_TABLE()
|
|||||||
wxTipDialog::wxTipDialog(wxWindow *parent,
|
wxTipDialog::wxTipDialog(wxWindow *parent,
|
||||||
wxTipProvider *tipProvider,
|
wxTipProvider *tipProvider,
|
||||||
bool showAtStartup)
|
bool showAtStartup)
|
||||||
: wxDialog(parent, wxID_ANY, _("Tip of the Day"),
|
: wxDialog(GetParentForModalDialog(parent), wxID_ANY, _("Tip of the Day"),
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
|
||||||
)
|
)
|
||||||
|
@@ -41,9 +41,10 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
|
|||||||
wxString title(_("Choose colour"));
|
wxString title(_("Choose colour"));
|
||||||
m_widget = gtk_color_selection_dialog_new(wxGTK_CONV(title));
|
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_window_set_transient_for(GTK_WINDOW(m_widget),
|
||||||
gtk_parent);
|
gtk_parent);
|
||||||
}
|
}
|
||||||
|
@@ -99,6 +99,8 @@ wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
|
|||||||
m_message = title;
|
m_message = title;
|
||||||
m_needParent = false;
|
m_needParent = false;
|
||||||
|
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
if (!PreCreation(parent, pos, wxDefaultSize) ||
|
if (!PreCreation(parent, pos, wxDefaultSize) ||
|
||||||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
|
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
|
||||||
wxDefaultValidator, wxT("dirdialog")))
|
wxDefaultValidator, wxT("dirdialog")))
|
||||||
|
@@ -154,6 +154,8 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
|
|||||||
|
|
||||||
m_needParent = false;
|
m_needParent = false;
|
||||||
|
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
if (!PreCreation(parent, pos, wxDefaultSize) ||
|
if (!PreCreation(parent, pos, wxDefaultSize) ||
|
||||||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
|
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
|
||||||
wxDefaultValidator, wxT("filedialog")))
|
wxDefaultValidator, wxT("filedialog")))
|
||||||
|
@@ -88,6 +88,8 @@ bool wxFontDialog::DoCreate(wxWindow *parent)
|
|||||||
{
|
{
|
||||||
m_needParent = false;
|
m_needParent = false;
|
||||||
|
|
||||||
|
parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
|
if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
|
||||||
!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
|
!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
|
||||||
wxDefaultValidator, wxT("fontdialog") ))
|
wxDefaultValidator, wxT("fontdialog") ))
|
||||||
|
@@ -38,7 +38,8 @@ wxMessageDialog::wxMessageDialog(wxWindow *parent,
|
|||||||
m_caption = caption;
|
m_caption = caption;
|
||||||
m_message = message;
|
m_message = message;
|
||||||
SetMessageDialogStyle(style);
|
SetMessageDialogStyle(style);
|
||||||
m_parent = wxGetTopLevelParent(parent);
|
|
||||||
|
m_parent = GetParentForModalDialog(parent);
|
||||||
|
|
||||||
GtkMessageType type = GTK_MESSAGE_ERROR;
|
GtkMessageType type = GTK_MESSAGE_ERROR;
|
||||||
GtkButtonsType buttons = GTK_BUTTONS_OK;
|
GtkButtonsType buttons = GTK_BUTTONS_OK;
|
||||||
|
Reference in New Issue
Block a user