From 92d5cd31d93ca30f97fab09304a59aa41268431e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Thu, 3 May 2018 17:47:43 +0100 Subject: [PATCH] give icon data directly to gtk, skipping internal loaders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4168b78d68a99e56105c49e1a1b6e1aa457609af Reviewed-on: https://gerrit.libreoffice.org/53812 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- include/vcl/ImageTree.hxx | 4 +++ vcl/inc/implimagetree.hxx | 3 +++ vcl/source/image/ImageTree.cxx | 5 ++++ vcl/source/image/ImplImageTree.cxx | 40 ++++++++++++++++++++++++++++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 30 +++++++++++----------- 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/include/vcl/ImageTree.hxx b/include/vcl/ImageTree.hxx index a40905d863ef..66a82b000ebc 100644 --- a/include/vcl/ImageTree.hxx +++ b/include/vcl/ImageTree.hxx @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -55,6 +56,9 @@ public: VCL_DLLPUBLIC OUString getImageUrl( OUString const & name, OUString const & style, OUString const & lang); + VCL_DLLPUBLIC std::shared_ptr getImageStream( + OUString const & rName, OUString const & rStyle, OUString const & rLang); + VCL_DLLPUBLIC bool loadImage( OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized, diff --git a/vcl/inc/implimagetree.hxx b/vcl/inc/implimagetree.hxx index 92052e3c57e4..e35c9ac6ccfb 100644 --- a/vcl/inc/implimagetree.hxx +++ b/vcl/inc/implimagetree.hxx @@ -69,6 +69,9 @@ public: OUString getImageUrl( OUString const & name, OUString const & style, OUString const & lang); + std::shared_ptr getImageStream( + OUString const & rName, OUString const & rStyle, OUString const & rLang); + bool loadImage( OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized, diff --git a/vcl/source/image/ImageTree.cxx b/vcl/source/image/ImageTree.cxx index 941812925190..2e20183b0da5 100644 --- a/vcl/source/image/ImageTree.cxx +++ b/vcl/source/image/ImageTree.cxx @@ -30,6 +30,11 @@ OUString ImageTree::getImageUrl(OUString const & rName, OUString const & rStyle, return mpImplImageTree->getImageUrl(rName, rStyle, rLang); } +std::shared_ptr ImageTree::getImageStream(OUString const & rName, OUString const & rStyle, OUString const & rLang) +{ + return mpImplImageTree->getImageStream(rName, rStyle, rLang); +} + bool ImageTree::loadImage(OUString const & rName, OUString const & rStyle, BitmapEx & rBitmap, bool bLocalized, const ImageLoadFlags eFlags) diff --git a/vcl/source/image/ImplImageTree.cxx b/vcl/source/image/ImplImageTree.cxx index 296800681fa7..ba1f22155d27 100644 --- a/vcl/source/image/ImplImageTree.cxx +++ b/vcl/source/image/ImplImageTree.cxx @@ -256,6 +256,46 @@ OUString ImplImageTree::getImageUrl(OUString const & rName, OUString const & rSt return OUString(); } +std::shared_ptr ImplImageTree::getImageStream(OUString const & rName, OUString const & rStyle, OUString const & rLang) +{ + OUString aStyle(rStyle); + + while (!aStyle.isEmpty()) + { + try + { + setStyle(aStyle); + + if (checkPathAccess()) + { + IconSet& rIconSet = getCurrentIconSet(); + const css::uno::Reference& rNameAccess = rIconSet.maNameAccess; + + LanguageTag aLanguageTag(rLang); + + for (OUString& rPath: getPaths(rName, aLanguageTag)) + { + if (rNameAccess->hasByName(rPath)) + { + css::uno::Reference aStream; + bool ok = rNameAccess->getByName(rPath) >>= aStream; + assert(ok); + (void)ok; // prevent unused warning in release build + return wrapStream(aStream); + } + } + } + } + catch (const css::uno::Exception & e) + { + SAL_INFO("vcl", e); + } + + aStyle = fallbackStyle(aStyle); + } + return std::shared_ptr(); +} + OUString ImplImageTree::fallbackStyle(const OUString& rsStyle) { OUString sResult; diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index ed78e141b124..d88b8a5b9e95 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -32,8 +32,8 @@ #include #include #include +#include #include -#include #include using namespace com::sun::star; @@ -4226,6 +4226,8 @@ private: ResHookProc m_pStringReplace; OUString m_sHelpRoot; OString m_aUtf8HelpRoot; + OUString m_aIconTheme; + OUString m_aUILang; GtkBuilder* m_pBuilder; GSList* m_pObjectList; GtkWidget* m_pParentWidget; @@ -4251,20 +4253,18 @@ private: if (icon_name) { OUString aIconName(icon_name, strlen(icon_name), RTL_TEXTENCODING_UTF8); + auto xMemStm = ImageTree::get().getImageStream(aIconName, m_aIconTheme, m_aUILang); + if (xMemStm) + { + GdkPixbufLoader *pixbuf_loader = gdk_pixbuf_loader_new(); + gdk_pixbuf_loader_write(pixbuf_loader, static_cast(xMemStm->GetData()), + xMemStm->Seek(STREAM_SEEK_TO_END), nullptr); + gdk_pixbuf_loader_close(pixbuf_loader, nullptr); + GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader); - SvMemoryStream aMemStm; - BitmapEx aBitmap(aIconName); - vcl::PNGWriter aWriter(aBitmap); - aWriter.Write(aMemStm); - - GdkPixbufLoader *pixbuf_loader = gdk_pixbuf_loader_new(); - gdk_pixbuf_loader_write(pixbuf_loader, static_cast(aMemStm.GetData()), - aMemStm.Seek(STREAM_SEEK_TO_END), nullptr); - gdk_pixbuf_loader_close(pixbuf_loader, nullptr); - GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader); - - gtk_image_set_from_pixbuf(pImage, pixbuf); - g_object_unref(pixbuf_loader); + gtk_image_set_from_pixbuf(pImage, pixbuf); + g_object_unref(pixbuf_loader); + } } } //set helpids @@ -4343,6 +4343,8 @@ public: m_sHelpRoot = m_sHelpRoot.copy(0, nIdx); m_sHelpRoot = m_sHelpRoot + OUString('/'); m_aUtf8HelpRoot = OUStringToOString(m_sHelpRoot, RTL_TEXTENCODING_UTF8); + m_aIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme(); + m_aUILang = Application::GetSettings().GetUILanguageTag().getBcp47(); m_pObjectList = gtk_builder_get_objects(m_pBuilder); g_slist_foreach(m_pObjectList, postprocess, this);