Make wxTopLevelWindow::Layout() do the expected thing

It makes sense for explicit calls to Layout() to use the same logic as
is implicitly used when a TLW is resized, so override it to use
TLW-specific logic instead of using a separate DoLayout() for this.

Note that DoLayout() still has to be preserved because Debian code
search finds at least a couple of examples of its use outside the
library, meaning that there are probably quite a few more of them in the
wild.

Also, wxTopLevelWindow still needs its own wxEVT_SIZE handler because
the base class only calls Layout() if GetAutoLayout() is true, while we
want it to be always called. This might be worked around by just calling
SetAutoLayout(true) in wxTopLevelWindow ctor, but it seems safer, from
compatibility point of view, to keep wxTopLevelWindow::OnSize() instead.

See #18472.
This commit is contained in:
Vadim Zeitlin 2019-08-22 13:46:53 +02:00
parent 8dc3c38fad
commit 3241e7a850
2 changed files with 15 additions and 8 deletions

View File

@ -276,9 +276,13 @@ public:
virtual bool IsTopNavigationDomain(NavigationKind kind) const wxOVERRIDE;
virtual bool IsVisible() const { return IsShown(); }
// override to do TLW-specific layout: we resize our unique child to fill
// the entire client area
virtual bool Layout() wxOVERRIDE;
// event handlers
void OnCloseWindow(wxCloseEvent& event);
void OnSize(wxSizeEvent& WXUNUSED(event)) { DoLayout(); }
void OnSize(wxSizeEvent& WXUNUSED(event)) { Layout(); }
// Get rect to be used to center top-level children
virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h);
@ -326,9 +330,8 @@ protected:
// send the iconize event, return true if processed
bool SendIconizeEvent(bool iconized = true);
// do TLW-specific layout: we resize our unique child to fill the entire
// client area
void DoLayout();
// this method is only kept for compatibility, call Layout() instead.
void DoLayout() { Layout(); }
static int WidthDefault(int w) { return w == wxDefaultCoord ? GetDefaultSize().x : w; }
static int HeightDefault(int h) { return h == wxDefaultCoord ? GetDefaultSize().y : h; }

View File

@ -411,20 +411,20 @@ bool wxTopLevelWindowBase::IsTopNavigationDomain(NavigationKind kind) const
// default resizing behaviour - if only ONE subwindow, resize to fill the
// whole client area
void wxTopLevelWindowBase::DoLayout()
bool wxTopLevelWindowBase::Layout()
{
// We are called during the window destruction several times, e.g. as
// wxFrame tries to adjust to its tool/status bars disappearing. But
// actually doing the layout is pretty useless in this case as the window
// will disappear anyhow -- so just don't bother.
if ( IsBeingDeleted() )
return;
return false;
// if we're using constraints or sizers - do use them
if ( GetAutoLayout() )
{
Layout();
return wxNonOwnedWindow::Layout();
}
else
{
@ -443,7 +443,7 @@ void wxTopLevelWindowBase::DoLayout()
{
if ( child )
{
return; // it's our second subwindow - nothing to do
return false; // it's our second subwindow - nothing to do
}
child = win;
@ -458,8 +458,12 @@ void wxTopLevelWindowBase::DoLayout()
DoGetClientSize(&clientW, &clientH);
child->SetSize(0, 0, clientW, clientH);
return true;
}
}
return false;
}
// The default implementation for the close window event.