Allow wxSizer::Fit() to work properly when called from TLW ctor on GTK3
Style information affecting sizes may not be updated by GTK until TLW is shown See #16088
This commit is contained in:
@@ -968,10 +968,29 @@ wxSize wxSizer::ComputeFittingWindowSize(wxWindow *window)
|
|||||||
return window->ClientToWindowSize(ComputeFittingClientSize(window));
|
return window->ClientToWindowSize(ComputeFittingClientSize(window));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WXGTK3__
|
||||||
|
static void FitOnShow(wxShowEvent& event)
|
||||||
|
{
|
||||||
|
wxWindow* win = static_cast<wxWindow*>(event.GetEventObject());
|
||||||
|
wxSizer* sizer = win->GetSizer();
|
||||||
|
if (sizer)
|
||||||
|
sizer->Fit(win);
|
||||||
|
win->Unbind(wxEVT_SHOW, FitOnShow);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
wxSize wxSizer::Fit( wxWindow *window )
|
wxSize wxSizer::Fit( wxWindow *window )
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" );
|
wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" );
|
||||||
|
|
||||||
|
#ifdef __WXGTK3__
|
||||||
|
// GTK3 updates cached style information before showing a TLW,
|
||||||
|
// which may affect best size calculations, so add a handler to
|
||||||
|
// redo the calculations at that time
|
||||||
|
if (!window->IsShown() && window->IsTopLevel())
|
||||||
|
window->Bind(wxEVT_SHOW, FitOnShow);
|
||||||
|
#endif
|
||||||
|
|
||||||
// set client size
|
// set client size
|
||||||
window->SetClientSize(ComputeFittingClientSize(window));
|
window->SetClientSize(ComputeFittingClientSize(window));
|
||||||
|
|
||||||
@@ -1009,6 +1028,17 @@ void wxSizer::Layout()
|
|||||||
RepositionChildren(minSize);
|
RepositionChildren(minSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WXGTK3__
|
||||||
|
static void SetSizeHintsOnShow(wxShowEvent& event)
|
||||||
|
{
|
||||||
|
wxWindow* win = static_cast<wxWindow*>(event.GetEventObject());
|
||||||
|
wxSizer* sizer = win->GetSizer();
|
||||||
|
if (sizer)
|
||||||
|
sizer->SetSizeHints(win);
|
||||||
|
win->Unbind(wxEVT_SHOW, SetSizeHintsOnShow);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void wxSizer::SetSizeHints( wxWindow *window )
|
void wxSizer::SetSizeHints( wxWindow *window )
|
||||||
{
|
{
|
||||||
// Preserve the window's max size hints, but set the
|
// Preserve the window's max size hints, but set the
|
||||||
@@ -1020,6 +1050,12 @@ void wxSizer::SetSizeHints( wxWindow *window )
|
|||||||
// otherwise SetClientSize() could have no effect if there already are
|
// otherwise SetClientSize() could have no effect if there already are
|
||||||
// size hints in effect that forbid requested client size.
|
// size hints in effect that forbid requested client size.
|
||||||
|
|
||||||
|
#ifdef __WXGTK3__
|
||||||
|
// see comment in Fit()
|
||||||
|
if (!window->IsShown() && window->IsTopLevel())
|
||||||
|
window->Bind(wxEVT_SHOW, SetSizeHintsOnShow);
|
||||||
|
#endif
|
||||||
|
|
||||||
const wxSize clientSize = ComputeFittingClientSize(window);
|
const wxSize clientSize = ComputeFittingClientSize(window);
|
||||||
|
|
||||||
window->SetMinClientSize(clientSize);
|
window->SetMinClientSize(clientSize);
|
||||||
|
Reference in New Issue
Block a user