diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-07-26 10:47:01 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-07-27 12:49:46 +0200 |
commit | a905fed5ba72bc22098910d960e7a502365df9ef (patch) | |
tree | 2447f73f6fb58bcc1270f83987eab35ef29639de | |
parent | 7c84ce6960cbb9fccad20ad4d816b08b32e9567c (diff) |
factor out setting widget bg
Change-Id: I9f958e62df9efb00d5225ec485076fe8edbc2744
(cherry picked from commit e1252cc0bd300bf873325c598a7e5ad940061055)
Reviewed-on: https://gerrit.libreoffice.org/76448
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index a472537c2bfd..a846b16d6e17 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1388,6 +1388,7 @@ private: sal_uInt16 m_nLastMouseButton; sal_uInt16 m_nLastMouseClicks; ImplSVEvent* m_pFocusEvent; + GtkCssProvider* m_pBgCssProvider; gulong m_nFocusInSignalId; gulong m_nMnemonicActivateSignalId; gulong m_nFocusOutSignalId; @@ -1579,6 +1580,24 @@ private: } } + void set_background(const OUString* pColor) + { + GtkStyleContext *pWidgetContext = gtk_widget_get_style_context(GTK_WIDGET(m_pWidget)); + if (m_pBgCssProvider) + { + gtk_style_context_remove_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pBgCssProvider)); + m_pBgCssProvider = nullptr; + } + if (!pColor) + return; + m_pBgCssProvider = gtk_css_provider_new(); + OUString aBuffer = "* { background-color: #" + *pColor + "; }"; + OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8); + gtk_css_provider_load_from_data(m_pBgCssProvider, aResult.getStr(), aResult.getLength(), nullptr); + gtk_style_context_add_provider(pWidgetContext, GTK_STYLE_PROVIDER(m_pBgCssProvider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } + public: GtkInstanceWidget(GtkWidget* pWidget, GtkInstanceBuilder* pBuilder, bool bTakeOwnership) : m_pWidget(pWidget) @@ -1590,6 +1609,7 @@ public: , m_nLastMouseButton(0) , m_nLastMouseClicks(0) , m_pFocusEvent(nullptr) + , m_pBgCssProvider(nullptr) , m_nFocusInSignalId(0) , m_nMnemonicActivateSignalId(0) , m_nFocusOutSignalId(0) @@ -2081,13 +2101,8 @@ public: virtual void set_stack_background() override { - GtkStyleContext *pWidgetContext = gtk_widget_get_style_context(GTK_WIDGET(m_pWidget)); - GtkCssProvider *pProvider = gtk_css_provider_new(); - OUString aBuffer = "* { background-color: #" + Application::GetSettings().GetStyleSettings().GetWindowColor().AsRGBHexString() + "; }"; - OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8); - gtk_css_provider_load_from_data(pProvider, aResult.getStr(), aResult.getLength(), nullptr); - gtk_style_context_add_provider(pWidgetContext, GTK_STYLE_PROVIDER(pProvider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + OUString sColor = Application::GetSettings().GetStyleSettings().GetWindowColor().AsRGBHexString(); + set_background(&sColor); } virtual ~GtkInstanceWidget() override @@ -2121,6 +2136,8 @@ public: if (m_nSizeAllocateSignalId) g_signal_handler_disconnect(m_pWidget, m_nSizeAllocateSignalId); + set_background(nullptr); + if (m_pMouseEventBox && m_pMouseEventBox != m_pWidget) { // put things back they way we found them |