diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2020-08-24 17:18:03 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-09-03 17:41:48 +0200 |
commit | e944b2d62b499f4d9392cf5ce067b905bc2d67ab (patch) | |
tree | 440632ff87cde9b32c5152fcaef92fe7d7bfd345 /vcl/unx | |
parent | ba86d4e1345276c5fa76a5e4b00e1f04de8cc166 (diff) |
tdf#136094 Handle background color in drawNativeControl
Make gtk3's 'GtkSalGraphics::drawNativeControl'
take into account a control's background color,
if any is explicitly set:
Set background/fill color (in 'Edit::ApplySettings')
also for the case where the control is drawn "natively",
but don't draw the background in the generic 'Window::Erase'
method for the case of native drawing; instead handle it when
drawing the control itself.
This adds an additional parameter to pass the background color to the
relevant '{d,D}rawNativeControl' methods (defaulting to 'COL_AUTO')
and implements the required handling to apply the background color
for the gtk3 case.
qt5/kf5 will probably be handled in an upcoming commit as well.
Windows as well as the "gen" VCL plugin were not affected by the
issue, so remain unchanged and just ignore the new parameter.
In a quick test on on macOS, the rendering of the controls
in the sample doc was broken beyond just the missing background
colors (s. screenshot attached to tdf#136094); the behavior there
also remains unchanged by this patch, the new parameter is ignored
for now.
Change-Id: I01923a504fea2367ae96032104f09099e35f410e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101284
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Michael Weghorn <m.weghorn@posteo.de>
(cherry picked from commit 2c9052802ea411dffbf5906c4914611fcbfbc6a5)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101165
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx index 5a853b436609..50e894f40443 100644 --- a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx +++ b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx @@ -2317,7 +2317,7 @@ void GtkSalGraphics::handleDamage(const tools::Rectangle& rDamagedRegion) bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, const tools::Rectangle& rControlRegion, ControlState nState, const ImplControlValue& rValue, - const OUString&) + const OUString&, const Color& rBackgroundColor) { RenderType renderType = nPart == ControlPart::Focus ? RenderType::Focus : RenderType::BackgroundAndFrame; GtkStyleContext *context = nullptr; @@ -2568,6 +2568,20 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co gtk_style_context_add_class(context, styleClass); } + // apply background in style, if explicitly set + // note: for more complex controls that use multiple styles for their elements, + // background may have to be applied for more of those as well (s. case RenderType::Combobox below) + GtkCssProvider* pBgCssProvider = nullptr; + if (rBackgroundColor != COL_AUTO) + { + const OUString sColorCss = "* { background-color: #" + rBackgroundColor.AsRGBHexString() + "; }"; + const OString aResult = OUStringToOString(sColorCss, RTL_TEXTENCODING_UTF8); + pBgCssProvider = gtk_css_provider_new(); + gtk_css_provider_load_from_data(pBgCssProvider, aResult.getStr(), aResult.getLength(), nullptr); + gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(pBgCssProvider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } + switch(renderType) { case RenderType::Background: @@ -2619,7 +2633,16 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co PaintSpinButton(flags, cr, rControlRegion, nPart, rValue); break; case RenderType::Combobox: + if (pBgCssProvider) + { + gtk_style_context_add_provider(mpComboboxEntryStyle, GTK_STYLE_PROVIDER(pBgCssProvider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } PaintCombobox(flags, cr, rControlRegion, nType, nPart); + if (pBgCssProvider) + { + gtk_style_context_remove_provider(mpComboboxEntryStyle, GTK_STYLE_PROVIDER(pBgCssProvider)); + } break; case RenderType::Icon: gtk_style_context_save (context); @@ -2698,6 +2721,10 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co { gtk_style_context_remove_class(context, styleClass); } + if (pBgCssProvider) + { + gtk_style_context_remove_provider(context, GTK_STYLE_PROVIDER(pBgCssProvider)); + } aContextState.restore(); cairo_destroy(cr); // unref |