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
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
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;
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)
{
wxBusyCursor cursor;
+ parent = GetParentForModalDialog(parent);
+
if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
return false;
const wxString& title,
int style)
{
+ parent = GetParentForModalDialog(parent);
+
if ( !wxDialog::Create(parent, wxID_ANY, title,
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
{
m_bypassGenericImpl = bypassGenericImpl;
+ parent = GetParentForModalDialog(parent);
+
if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile,
wildCard, style, pos, sz, name))
{
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") );
{
SetMessageDialogStyle(style);
+ parent = GetParentForModalDialog(parent);
+
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
long min,
long max,
const wxPoint& pos)
- : wxDialog(parent, wxID_ANY, caption,
+ : wxDialog(GetParentForModalDialog(parent),
+ wxID_ANY, caption,
pos, wxDefaultSize)
{
m_value = value;
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)
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)
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),
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;
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)
{
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
)
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);
}
m_message = title;
m_needParent = false;
+ parent = GetParentForModalDialog(parent);
+
if (!PreCreation(parent, pos, wxDefaultSize) ||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
wxDefaultValidator, wxT("dirdialog")))
m_needParent = false;
+ parent = GetParentForModalDialog(parent);
+
if (!PreCreation(parent, pos, wxDefaultSize) ||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
wxDefaultValidator, wxT("filedialog")))
{
m_needParent = false;
+ parent = GetParentForModalDialog(parent);
+
if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) ||
!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
wxDefaultValidator, wxT("fontdialog") ))
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;