From 37bb10790847bb2088e7f29211a31b1118fed2ad Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 27 Apr 2015 13:15:17 +0100 Subject: gtk3: hive the borders and padding calc off into a standalone Change-Id: I0890a7d8c50b8646782bfc4358aa7c2f106dc22d --- vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx | 41 +++++++++++++++------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'vcl') diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx index abab9e131e13..355e2b2bcb21 100644 --- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx +++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx @@ -979,6 +979,28 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co return true; } +Rectangle AdjustRectForTextBordersPadding(GtkStyleContext* pStyle, long nTextHeight, const Rectangle& rControlRegion) +{ + gtk_style_context_save(pStyle); + gtk_style_context_add_class(pStyle, GTK_STYLE_CLASS_ENTRY); + + GtkBorder border; + gtk_style_context_get_border(pStyle, GTK_STATE_FLAG_NORMAL, &border); + + GtkBorder padding; + gtk_style_context_get_padding(pStyle, GTK_STATE_FLAG_NORMAL, &padding); + + gint nWidgetHeight = nTextHeight + padding.top + padding.bottom + border.top + border.bottom; + + nWidgetHeight = std::max(nWidgetHeight, rControlRegion.GetHeight()); + + Rectangle aEditRect(rControlRegion.TopLeft(), Size(rControlRegion.GetWidth(), nWidgetHeight)); + + gtk_style_context_restore(pStyle); + + return aEditRect; +} + bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState, const ImplControlValue& rValue, const OUString&, Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion ) @@ -1071,24 +1093,7 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar } else if ((nType == CTRL_EDITBOX || nType == CTRL_LISTBOX || nType == CTRL_COMBOBOX) && nPart == PART_ENTIRE_CONTROL) { - gtk_style_context_save(mpEntryStyle); - gtk_style_context_add_class(mpEntryStyle, GTK_STYLE_CLASS_ENTRY); - - GtkBorder border; - gtk_style_context_get_border(mpEntryStyle, GTK_STATE_FLAG_NORMAL, &border); - - GtkBorder padding; - gtk_style_context_get_padding(mpEntryStyle, GTK_STATE_FLAG_NORMAL, &padding); - - auto nTextHeight = rValue.getNumericVal(); - - gint nWidgetHeight = nTextHeight + padding.top + padding.bottom + border.top + border.bottom; - - nWidgetHeight = std::max(nWidgetHeight, rControlRegion.GetHeight()); - - aEditRect = Rectangle(rControlRegion.TopLeft(), Size(rControlRegion.GetWidth(), nWidgetHeight)); - - gtk_style_context_restore(mpEntryStyle); + aEditRect = AdjustRectForTextBordersPadding(mpEntryStyle, rValue.getNumericVal(), rControlRegion); } else { -- cgit v1.2.3