Merge branch 'find-dialog-parent'
Use correct parent for the generic "Find" dialog, even when it is not shown yet. See https://github.com/wxWidgets/wxWidgets/pull/2486
This commit is contained in:
@@ -105,7 +105,10 @@ public:
|
|||||||
// check whether it contains wxDIALOG_NO_PARENT bit.
|
// check whether it contains wxDIALOG_NO_PARENT bit.
|
||||||
//
|
//
|
||||||
// This function always returns a valid top level window or NULL.
|
// This function always returns a valid top level window or NULL.
|
||||||
wxWindow *GetParentForModalDialog(wxWindow *parent, long style) const;
|
wxWindow *GetParentForModalDialog(wxWindow *parent, long style) const
|
||||||
|
{
|
||||||
|
return DoGetParentForDialog(wxDIALOG_MODALITY_APP_MODAL, parent, style);
|
||||||
|
}
|
||||||
|
|
||||||
// This overload can only be used for already initialized windows, i.e. not
|
// This overload can only be used for already initialized windows, i.e. not
|
||||||
// from the ctor. It uses the current window parent and style.
|
// from the ctor. It uses the current window parent and style.
|
||||||
@@ -114,6 +117,16 @@ public:
|
|||||||
return GetParentForModalDialog(GetParent(), GetWindowStyle());
|
return GetParentForModalDialog(GetParent(), GetWindowStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is similar to GetParentForModalDialog() but should be used
|
||||||
|
// for modeless dialogs and skips the checks irrelevant for them (currently
|
||||||
|
// just the one checking that the candidate parent window is visible, as it
|
||||||
|
// is possible to create a modeless dialog before its parent is shown if it
|
||||||
|
// is only shown later, after showing the parent).
|
||||||
|
wxWindow *GetParentForModelessDialog(wxWindow *parent, long style) const
|
||||||
|
{
|
||||||
|
return DoGetParentForDialog(wxDIALOG_MODALITY_NONE, parent, style);
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
|
#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
|
||||||
// splits text up at newlines and places the lines into a vertical
|
// splits text up at newlines and places the lines into a vertical
|
||||||
// wxBoxSizer, with the given maximum width, lines will not be wrapped
|
// wxBoxSizer, with the given maximum width, lines will not be wrapped
|
||||||
@@ -243,9 +256,15 @@ protected:
|
|||||||
static bool sm_layoutAdaptation;
|
static bool sm_layoutAdaptation;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// helper of GetParentForModalDialog(): returns the passed in window if it
|
// Common implementation of GetParentFor{Modal,Modeless}Dialog().
|
||||||
// can be used as our parent or NULL if it can't
|
wxWindow *DoGetParentForDialog(wxDialogModality modality,
|
||||||
wxWindow *CheckIfCanBeUsedAsParent(wxWindow *parent) const;
|
wxWindow *parent,
|
||||||
|
long style) const;
|
||||||
|
|
||||||
|
// helper of DoGetParentForDialog(): returns the passed in window if it
|
||||||
|
// can be used as parent for this kind of dialog or NULL if it can't
|
||||||
|
wxWindow *CheckIfCanBeUsedAsParent(wxDialogModality modality,
|
||||||
|
wxWindow *parent) const;
|
||||||
|
|
||||||
// Helper of OnCharHook() and OnCloseWindow(): find the appropriate button
|
// Helper of OnCharHook() and OnCloseWindow(): find the appropriate button
|
||||||
// for closing the dialog and send a click event for it.
|
// for closing the dialog and send a click event for it.
|
||||||
|
@@ -128,7 +128,9 @@ wxDialogBase::wxDialogBase()
|
|||||||
SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
|
SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWindow *wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow *parent) const
|
wxWindow *
|
||||||
|
wxDialogBase::CheckIfCanBeUsedAsParent(wxDialogModality modality,
|
||||||
|
wxWindow *parent) const
|
||||||
{
|
{
|
||||||
if ( !parent )
|
if ( !parent )
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -148,11 +150,22 @@ wxWindow *wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow *parent) const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This check is done for modal dialogs only because modeless dialogs can
|
||||||
|
// be created before their parent is shown and only shown later.
|
||||||
|
switch ( modality )
|
||||||
|
{
|
||||||
|
case wxDIALOG_MODALITY_NONE:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxDIALOG_MODALITY_APP_MODAL:
|
||||||
|
case wxDIALOG_MODALITY_WINDOW_MODAL:
|
||||||
if ( !parent->IsShownOnScreen() )
|
if ( !parent->IsShownOnScreen() )
|
||||||
{
|
{
|
||||||
// using hidden parent won't work correctly neither
|
// using hidden parent won't work correctly neither
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ( parent == this )
|
if ( parent == this )
|
||||||
{
|
{
|
||||||
@@ -165,7 +178,9 @@ wxWindow *wxDialogBase::CheckIfCanBeUsedAsParent(wxWindow *parent) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxWindow *
|
wxWindow *
|
||||||
wxDialogBase::GetParentForModalDialog(wxWindow *parent, long style) const
|
wxDialogBase::DoGetParentForDialog(wxDialogModality modality,
|
||||||
|
wxWindow *parent,
|
||||||
|
long style) const
|
||||||
{
|
{
|
||||||
// creating a parent-less modal dialog will result (under e.g. wxGTK2)
|
// 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
|
// in an unfocused dialog, so try to find a valid parent for it unless we
|
||||||
@@ -175,16 +190,16 @@ wxDialogBase::GetParentForModalDialog(wxWindow *parent, long style) const
|
|||||||
|
|
||||||
// first try the given parent
|
// first try the given parent
|
||||||
if ( parent )
|
if ( parent )
|
||||||
parent = CheckIfCanBeUsedAsParent(wxGetTopLevelParent(parent));
|
parent = CheckIfCanBeUsedAsParent(modality, wxGetTopLevelParent(parent));
|
||||||
|
|
||||||
// then the currently active window
|
// then the currently active window
|
||||||
if ( !parent )
|
if ( !parent )
|
||||||
parent = CheckIfCanBeUsedAsParent(
|
parent = CheckIfCanBeUsedAsParent(modality,
|
||||||
wxGetTopLevelParent(wxGetActiveWindow()));
|
wxGetTopLevelParent(wxGetActiveWindow()));
|
||||||
|
|
||||||
// and finally the application main window
|
// and finally the application main window
|
||||||
if ( !parent )
|
if ( !parent )
|
||||||
parent = CheckIfCanBeUsedAsParent(wxApp::GetMainTopWindow());
|
parent = CheckIfCanBeUsedAsParent(modality, wxApp::GetMainTopWindow());
|
||||||
|
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
@@ -84,13 +84,14 @@ void wxFindReplaceDialogBase::Send(wxFindDialogEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !GetEventHandler()->ProcessEvent(event) )
|
if ( !ProcessWindowEvent(event) )
|
||||||
{
|
{
|
||||||
// the event is not propagated upwards to the parent automatically
|
// the event is not propagated upwards to the parent automatically
|
||||||
// because the dialog is a top level window, so do it manually as
|
// because the dialog is a top level window, so do it manually as
|
||||||
// in 9 cases of 10 the message must be processed by the dialog
|
// in 9 cases out of 10 the message must be processed by the dialog
|
||||||
// owner and not the dialog itself
|
// owner and not the dialog itself
|
||||||
(void)GetParent()->GetEventHandler()->ProcessEvent(event);
|
if ( GetParent() )
|
||||||
|
(void)GetParent()->ProcessWindowEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -83,7 +83,7 @@ bool wxGenericFindReplaceDialog::Create(wxWindow *parent,
|
|||||||
const wxString& title,
|
const wxString& title,
|
||||||
int style)
|
int style)
|
||||||
{
|
{
|
||||||
parent = GetParentForModalDialog(parent, style);
|
parent = GetParentForModelessDialog(parent, style);
|
||||||
|
|
||||||
if ( !wxDialog::Create(parent, wxID_ANY, title,
|
if ( !wxDialog::Create(parent, wxID_ANY, title,
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
Reference in New Issue
Block a user