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. If parent argument is NULL, use GetParent() by default.
+ // Find the parent to use for modal dialog: try to use the specified parent
+ // but fall back to the current active window or main application window as
+ // last resort if it is unsuitable.
+ //
+ // This function always returns a valid top level window or NULL.
wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const;
#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
wxWindow *wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow *parent) const
{
- extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete;
+ if ( !parent )
+ return NULL;
+ extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete;
if ( wxPendingDelete.Member(parent) || parent->IsBeingDeleted() )
{
// this window is being deleted and we shouldn't create any children
if ( HasFlag(wxDIALOG_NO_PARENT) )
return NULL;
- // by default, use the parent specified in the ctor
- if ( !parent )
- parent = GetParent();
-
// first try the given parent
if ( parent )
parent = CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent));
// then the currently active window
if ( !parent )
- parent = CheckIfCanBeUsedAsParent(wxGetActiveWindow());
+ parent = CheckIfCanBeUsedAsParent(
+ wxGetTopLevelParent(wxGetActiveWindow()));
// and finally the application main window
if ( !parent )
if ( win )
win->GTKReleaseMouseAndNotify();
- wxWindow * const parent = GetParentForModalDialog();
+ wxWindow * const parent = GetParentForModalDialog(GetParent());
if ( parent )
{
gtk_window_set_transient_for( GTK_WINDOW(m_widget),
return CreateFrame(title, pos, size);
#else // !__WXMICROWIN__
// static cast is valid as we're only ever called for dialogs
- wxWindow * const
- parent = static_cast<wxDialog *>(this)->GetParentForModalDialog();
+ wxWindow * const
+ parent = static_cast<wxDialog *>(this)->
+ GetParentForModalDialog(GetParent());
m_hWnd = (WXHWND)::CreateDialogIndirect
(