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:
Vadim Zeitlin
2007-04-22 20:34:41 +00:00
parent a2979ead8d
commit 2229243bdf
20 changed files with 63 additions and 14 deletions

View 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

View 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

View 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;

View 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)

View 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;

View 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

View 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))
{

View 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") );

View 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 );

View 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;

View 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)

View 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),

View 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;

View 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)
{

View 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
)

View 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);
}

View 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")))

View 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")))

View 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") ))

View 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;