diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-05-03 17:47:43 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-05-04 09:54:45 +0200 |
commit | 92d5cd31d93ca30f97fab09304a59aa41268431e (patch) | |
tree | bf5000b654d96e12cdf1a855db8dd16077966f57 /vcl | |
parent | a7dde8db81624c4f31c93b8611a4636d662f548e (diff) |
give icon data directly to gtk, skipping internal loaders
Change-Id: I4168b78d68a99e56105c49e1a1b6e1aa457609af
Reviewed-on: https://gerrit.libreoffice.org/53812
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/implimagetree.hxx | 3 | ||||
-rw-r--r-- | vcl/source/image/ImageTree.cxx | 5 | ||||
-rw-r--r-- | vcl/source/image/ImplImageTree.cxx | 40 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 32 |
4 files changed, 65 insertions, 15 deletions
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<SvMemoryStream> 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<SvMemoryStream> 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<SvMemoryStream> 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<css::container::XNameAccess>& rNameAccess = rIconSet.maNameAccess; + + LanguageTag aLanguageTag(rLang); + + for (OUString& rPath: getPaths(rName, aLanguageTag)) + { + if (rNameAccess->hasByName(rPath)) + { + css::uno::Reference<css::io::XInputStream> 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<SvMemoryStream>(); +} + 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 <tools/fract.hxx> #include <tools/stream.hxx> #include <unotools/resmgr.hxx> +#include <vcl/ImageTree.hxx> #include <vcl/mnemonic.hxx> -#include <vcl/pngwrite.hxx> #include <vcl/weld.hxx> 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); - - 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<const guchar*>(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); + 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<const guchar*>(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); + + 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); |