Different fix for GetBordersForSizer()

Try to determine the borders the same way GTK+ does it.
This seems to avoid incorrect results before widget is realized.
See #17239, #15872
This commit is contained in:
Paul Cornett
2017-01-02 08:31:35 -08:00
parent 5e906d80d8
commit c15d804197

View File

@@ -158,22 +158,30 @@ wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
{ {
GtkAllocation alloc, child_alloc; GtkWidget* label = gtk_frame_get_label_widget(GTK_FRAME(m_widget));
gtk_widget_get_allocation(m_widget, &alloc); #ifdef __WXGTK3__
const int w_save = alloc.width; *borderOther = 0;
const int h_save = alloc.height; *borderTop = 0;
if (alloc.width < 50) alloc.width = 50; if (label)
if (alloc.height < 50) alloc.height = 50; {
gtk_widget_set_allocation(m_widget, &alloc); int nat_width;
gtk_widget_get_preferred_width(label, NULL, &nat_width);
GTK_FRAME_GET_CLASS(m_widget)->compute_child_allocation(GTK_FRAME(m_widget), &child_alloc); gtk_widget_get_preferred_height_for_width(label, nat_width, borderTop, NULL);
}
alloc.width = w_save; #else
alloc.height = h_save; gtk_widget_ensure_style(m_widget);
gtk_widget_set_allocation(m_widget, &alloc); const int border_width = GTK_CONTAINER(m_widget)->border_width;
*borderOther = border_width + m_widget->style->xthickness;
*borderTop = child_alloc.y - alloc.y; *borderTop = border_width;
*borderOther = child_alloc.x - alloc.x; if (label)
{
GtkRequisition req;
gtk_widget_size_request(label, &req);
*borderTop += req.height;
}
else
*borderTop += m_widget->style->ythickness;
#endif
} }
#endif // wxUSE_STATBOX #endif // wxUSE_STATBOX