Improve our estimate of GtkEntry margins

For GTK2, get the "inner border" the same way GTK does it. And for GTK3,
provide an actual implementation. Also, don't return a wxPoint for a size.
See #18567
This commit is contained in:
Paul Cornett
2019-11-11 08:29:28 -08:00
parent 46a94c2b48
commit df9f4af357
2 changed files with 30 additions and 23 deletions

View File

@@ -84,7 +84,7 @@ protected:
wxSize GTKGetPreferredSize(GtkWidget* widget) const; wxSize GTKGetPreferredSize(GtkWidget* widget) const;
// Inner margins in a GtkEntry // Inner margins in a GtkEntry
wxPoint GTKGetEntryMargins(GtkEntry* entry) const; wxSize GTKGetEntryMargins(GtkEntry* entry) const;
private: private:
wxDECLARE_DYNAMIC_CLASS(wxControl); wxDECLARE_DYNAMIC_CLASS(wxControl);

View File

@@ -363,37 +363,44 @@ wxSize wxControl::GTKGetPreferredSize(GtkWidget* widget) const
return wxSize(req.width, req.height); return wxSize(req.width, req.height);
} }
wxPoint wxControl::GTKGetEntryMargins(GtkEntry* entry) const wxSize wxControl::GTKGetEntryMargins(GtkEntry* entry) const
{ {
wxPoint marg(0, 0); wxSize size;
gtk_entry_get_layout_offsets(entry, &size.x, &size.y);
#ifdef __WXGTK3__
GtkBorder border;
GtkStyleContext* sc = gtk_widget_get_style_context(GTK_WIDGET(entry));
gtk_style_context_get_padding(sc, gtk_style_context_get_state(sc), &border);
#else
// Equivalent to the GTK2 private function _gtk_entry_effective_inner_border()
GtkBorder border = { 2, 2, 2, 2 };
#ifndef __WXGTK3__
#if GTK_CHECK_VERSION(2,10,0) #if GTK_CHECK_VERSION(2,10,0)
// The margins we have previously set
const GtkBorder* border = NULL;
if (wx_is_at_least_gtk2(10)) if (wx_is_at_least_gtk2(10))
border = gtk_entry_get_inner_border(entry);
if ( border )
{ {
marg.x = border->left + border->right; const GtkBorder* innerBorder1 = gtk_entry_get_inner_border(entry);
marg.y = border->top + border->bottom; if (innerBorder1)
border = *innerBorder1;
else
{
GtkBorder* innerBorder2;
gtk_widget_style_get(GTK_WIDGET(entry), "inner-border", &innerBorder2, NULL);
if (innerBorder2)
{
border = *innerBorder2;
gtk_border_free(innerBorder2);
}
}
} }
#endif // GTK+ 2.10+ #endif // GTK+ 2.10+
#else // GTK+ 3 #endif
// Gtk3 does not use inner border, but StyleContext and CSS
// TODO: implement it, starting with wxTextEntry::DoSetMargins()
#endif // GTK+ 2/3
int x, y; size.x += border.left + border.right;
gtk_entry_get_layout_offsets(entry, &x, &y); size.y += border.top + border.bottom;
// inner borders are included. Substract them so we can get other margins
x -= marg.x;
y -= marg.y;
marg.x += 2 * x + 2;
marg.y += 2 * y + 2;
return marg; return size;
} }