postprocess/CustomTarget_images.mk | 10 - solenv/bin/packimages.pl | 2 vcl/inc/impimagetree.hxx | 58 +++++--- vcl/source/gdi/impimagetree.cxx | 263 ++++++++++++++++++------------------- 4 files changed, 167 insertions(+), 166 deletions(-)
New commits: commit 96811dbda3c61115ead7837b19f664533b86f6b5 Author: Jan Holesovsky <[email protected]> Date: Sun Nov 23 03:14:51 2014 +0100 icons: Kill now irrelevant warning. Change-Id: I2ce348fe97cfc0fdaf1ad5e1063a28d069accdf5 diff --git a/solenv/bin/packimages.pl b/solenv/bin/packimages.pl index d6231b3..0e98566 100644 --- a/solenv/bin/packimages.pl +++ b/solenv/bin/packimages.pl @@ -381,8 +381,6 @@ sub create_zip_archive if ( !$member ) { print_error("can't add file '$path' to image zip archive: $!", 5); } - } else { - print_warning("file '$path' not found"); } } my $status = $zip->writeToFileNamed($tmp_out_file); commit b6bdc6771199b7b05d4f9840b66ebce3bb61d7db Author: Jan Holesovsky <[email protected]> Date: Sun Nov 23 03:07:44 2014 +0100 icons: Package only the icons that are in the theme. The fallback is now implemented directly in vcl, no need to waste space any more. Change-Id: Ia027fda5e92d2bac7369139f3277d73b0521bef2 diff --git a/postprocess/CustomTarget_images.mk b/postprocess/CustomTarget_images.mk index cbc9cef..5d995b7 100644 --- a/postprocess/CustomTarget_images.mk +++ b/postprocess/CustomTarget_images.mk @@ -13,10 +13,6 @@ $(eval $(call gb_CustomTarget_CustomTarget,postprocess/images)) packimages_DIR := $(call gb_CustomTarget_get_workdir,postprocess/images) helpimages_DIR := $(call gb_CustomTarget_get_workdir,helpcontent2/source/auxiliary) -# Custom sets, at 24x24 & 16x16 fall-back to Tango preferentially -# (Tango fallbacks to Industrial for the missing icons) -packimages_CUSTOM_FALLBACKS := -c $(SRCDIR)/icon-themes/tango -c $(SRCDIR)/icon-themes/industrial - $(eval $(call gb_CustomTarget_register_targets,postprocess/images,\ $(foreach theme,$(WITH_THEMES),images_$(theme).zip) \ commandimagelist.ilst \ @@ -36,11 +32,9 @@ $(packimages_DIR)/%.zip : \ $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),PRL,2) $(call gb_Helper_abbreviate_dirs, \ $(PERL) $(SRCDIR)/solenv/bin/packimages.pl \ - -g $(SRCDIR)/icon-themes/galaxy \ - -m $(SRCDIR)/icon-themes/galaxy \ $(if $(DEFAULT_THEME),\ - -c $(packimages_DIR),\ - -c $(SRCDIR)/icon-themes/$(subst images_,,$*) $(packimages_CUSTOM_FALLBACKS) \ + -g $(packimages_DIR) -m $(packimages_DIR) -c $(packimages_DIR),\ + -g $(SRCDIR)/icon-themes/$(subst images_,,$*) -m $(SRCDIR)/icon-themes/$(subst images_,,$*) -c $(SRCDIR)/icon-themes/$(subst images_,,$*) \ ) \ $(call gb_Helper_optional,HELP,-l $(helpimages_DIR) ) \ -l $(packimages_DIR) \ commit 78bf950a3e988f20bb5db61c966faa3b8de6d0e3 Author: Jan Holesovsky <[email protected]> Date: Sun Nov 23 03:06:27 2014 +0100 icons: Implement the fallback mechanism for icons. When an icon is not found in eg. images_sifr.zip, search it in images_tango.zip, etc. Change-Id: I8af952a1bd8e9e02531f84012e8ce39e75422313 diff --git a/vcl/inc/impimagetree.hxx b/vcl/inc/impimagetree.hxx index 7e8dda7..e66e754 100644 --- a/vcl/inc/impimagetree.hxx +++ b/vcl/inc/impimagetree.hxx @@ -95,8 +95,17 @@ private: bool findImage(std::vector< OUString > const & paths, BitmapEx & bitmap ); void loadImageLinks(); + void parseLinkFile(boost::shared_ptr< SvStream > stream); + + /// Return name of a real .png according to links.txt. OUString const & getRealImageName(OUString const & name); + + /** Rerurn name of the fallback style for the provided one. + + Must not be cyclic :-) The last theme in the chain returns an empty string. + */ + OUString fallbackStyle(const OUString &style); }; typedef salhelper::SingletonRef< ImplImageTree > ImplImageTreeSingletonRef; diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx index 9ce7fd2..8955902 100644 --- a/vcl/source/gdi/impimagetree.cxx +++ b/vcl/source/gdi/impimagetree.cxx @@ -101,21 +101,39 @@ ImplImageTree::~ImplImageTree() { } +OUString ImplImageTree::fallbackStyle(const OUString &style) +{ + if (style == "galaxy") + return OUString(); + else if (style == "industrial") + return OUString("galaxy"); + else if (style == "tango") + return OUString("industrial"); + else if (style == "breeze") + return OUString("sifr"); + + return OUString("tango"); +} + bool ImplImageTree::loadImage(OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized, bool loadMissing) { - bool found = false; - try { - found = doLoadImage(name, style, bitmap, localized); - } catch (css::uno::RuntimeException &) { - if (!loadMissing) - throw; + OUString aStyle(style); + while (!aStyle.isEmpty()) + { + try { + if (doLoadImage(name, aStyle, bitmap, localized)) + return true; + } + catch (css::uno::RuntimeException &) {} + + aStyle = fallbackStyle(aStyle); } - if (found || !loadMissing) - return found; - SAL_INFO("vcl", "ImplImageTree::loadImage exception couldn't load \"" - << name << "\", fetching default image"); + if (!loadMissing) + return false; + + SAL_INFO("vcl", "ImplImageTree::loadImage couldn't load \"" << name << "\", fetching default image"); return loadDefaultImage(style, bitmap); } commit 10c7500c46d33ee5d35c943322e2a0603ca72f18 Author: Jan Holesovsky <[email protected]> Date: Sun Nov 23 02:10:02 2014 +0100 icons: Even the cache and links are now stored per-style. Change-Id: I7d2bfd3e8aa102e88c107de445fa77c004867fe7 diff --git a/vcl/inc/impimagetree.hxx b/vcl/inc/impimagetree.hxx index 94a5469..7e8dda7 100644 --- a/vcl/inc/impimagetree.hxx +++ b/vcl/inc/impimagetree.hxx @@ -50,17 +50,22 @@ public: OUString const & style, BitmapEx& bitmap); -/** a crude form of life cycle control (called from DeInitVCL; otherwise, - * if the ImplImageTree singleton were destroyed during exit that would - * be too late for the destructors of the bitmaps in m_iconCache)*/ + /** a crude form of life cycle control (called from DeInitVCL; otherwise, + * if the ImplImageTree singleton were destroyed during exit that would + * be too late for the destructors of the bitmaps in maIconCache)*/ void shutDown(); css::uno::Reference< css::container::XNameAccess > getNameAccess(); private: + typedef boost::unordered_map<OUString, std::pair<bool, BitmapEx>, OUStringHash> IconCache; + typedef boost::unordered_map<OUString, OUString, OUStringHash> IconLinkHash; + struct IconSet { OUString maURL; css::uno::Reference<css::container::XNameAccess> maNameAccess; + IconCache maIconCache; + IconLinkHash maLinkHash; IconSet() {} IconSet(const OUString &aURL) : maURL(aURL) {} @@ -69,24 +74,21 @@ private: /// Map between the theme name(s) and the content. typedef boost::unordered_map<OUString, IconSet, OUStringHash> StyleIconSet; + /// Remember all the (used) icon styles and individual icons in them. StyleIconSet maIconSet; + /// Styly used for the current operations; switches switch several times during fallback search. + OUString maCurrentStyle; + bool doLoadImage( OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized); - typedef boost::unordered_map<OUString, std::pair<bool, BitmapEx>, OUStringHash> IconCache; - typedef boost::unordered_map<OUString, OUString, OUStringHash> IconLinkHash; - - OUString m_style; - IconCache m_iconCache; - IconLinkHash m_linkHash; - bool checkPathAccess(); void setStyle(OUString const & style ); - void resetPaths(); + void createStyle(); bool iconCacheLookup( OUString const & name, bool localized, BitmapEx & bitmap ); diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx index d76070d..9ce7fd2 100644 --- a/vcl/source/gdi/impimagetree.cxx +++ b/vcl/source/gdi/impimagetree.cxx @@ -165,57 +165,60 @@ bool ImplImageTree::doLoadImage(OUString const & name, OUString const & style, B } if (found) - m_iconCache[name.intern()] = std::make_pair(localized, bitmap); + maIconSet[maCurrentStyle].maIconCache[name.intern()] = std::make_pair(localized, bitmap); return found; } void ImplImageTree::shutDown() { - m_style.clear(); - // for safety; empty m_style means "not initialized" - m_iconCache.clear(); - m_linkHash.clear(); + maCurrentStyle.clear(); + for (StyleIconSet::iterator it = maIconSet.begin(); it != maIconSet.end(); ++it) + { + it->second.maIconCache.clear(); + it->second.maLinkHash.clear(); + } } void ImplImageTree::setStyle(OUString const & style) { - OSL_ASSERT(!style.isEmpty()); // empty m_style means "not initialized" - if (style != m_style) + assert(!style.isEmpty()); + if (style != maCurrentStyle) { - m_style = style; - resetPaths(); - m_iconCache.clear(); - m_linkHash.clear(); - loadImageLinks(); + maCurrentStyle = style; + createStyle(); } } -void ImplImageTree::resetPaths() +void ImplImageTree::createStyle() { - if (maIconSet.find(m_style) != maIconSet.end()) + if (maIconSet.find(maCurrentStyle) != maIconSet.end()) return; OUString url( "$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/config/" ); rtl::Bootstrap::expandMacros(url); - if ( m_style != "default" ) + if (maCurrentStyle != "default") { INetURLObject u(url); OSL_ASSERT(!u.HasError()); - bool ok = u.Append("images_" + m_style, INetURLObject::ENCODE_ALL); + bool ok = u.Append("images_" + maCurrentStyle, INetURLObject::ENCODE_ALL); OSL_ASSERT(ok); (void) ok; url = u.GetMainURL(INetURLObject::NO_DECODE); } else url += "images"; - maIconSet[m_style] = IconSet(url); + maIconSet[maCurrentStyle] = IconSet(url); + + loadImageLinks(); } bool ImplImageTree::iconCacheLookup(OUString const & name, bool localized, BitmapEx & bitmap) { - IconCache::iterator i(m_iconCache.find(getRealImageName(name))); - if (i != m_iconCache.end() && i->second.first == localized) + IconCache &rIconCache = maIconSet[maCurrentStyle].maIconCache; + + IconCache::iterator i(rIconCache.find(getRealImageName(name))); + if (i != rIconCache.end() && i->second.first == localized) { bitmap = i->second.second; return true; @@ -228,7 +231,7 @@ bool ImplImageTree::findImage(std::vector<OUString> const & paths, BitmapEx & bi if (!checkPathAccess()) return false; - const uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[m_style].maNameAccess; + const uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[maCurrentStyle].maNameAccess; for (std::vector<OUString>::const_reverse_iterator j(paths.rbegin()); j != paths.rend(); ++j) { @@ -252,7 +255,7 @@ void ImplImageTree::loadImageLinks() if (!checkPathAccess()) return; - const uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[m_style].maNameAccess; + const uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[maCurrentStyle].maNameAccess; if (rNameAccess->hasByName(aLinkFilename)) { @@ -288,32 +291,35 @@ void ImplImageTree::parseLinkFile(boost::shared_ptr< SvStream > pStream) continue; } - m_linkHash[aLink] = aOriginal; + maIconSet[maCurrentStyle].maLinkHash[aLink] = aOriginal; } } OUString const & ImplImageTree::getRealImageName(OUString const & name) { - IconLinkHash::iterator it(m_linkHash.find(name)); - if (it == m_linkHash.end()) + IconLinkHash &rLinkHash = maIconSet[maCurrentStyle].maLinkHash; + + IconLinkHash::iterator it(rLinkHash.find(name)); + if (it == rLinkHash.end()) return name; + return it->second; } bool ImplImageTree::checkPathAccess() { - uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[m_style].maNameAccess; + uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[maCurrentStyle].maNameAccess; if (rNameAccess.is()) return true; try { - rNameAccess = css::packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), maIconSet[m_style].maURL + ".zip"); + rNameAccess = css::packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), maIconSet[maCurrentStyle].maURL + ".zip"); } catch (const css::uno::RuntimeException &) { throw; } catch (const css::uno::Exception & e) { - SAL_INFO("vcl", "ImplImageTree::zip file location exception " << e.Message << " for " << maIconSet[m_style].maURL); + SAL_INFO("vcl", "ImplImageTree::zip file location exception " << e.Message << " for " << maIconSet[maCurrentStyle].maURL); return false; } return rNameAccess.is(); @@ -322,7 +328,7 @@ bool ImplImageTree::checkPathAccess() css::uno::Reference<css::container::XNameAccess> ImplImageTree::getNameAccess() { checkPathAccess(); - return maIconSet[m_style].maNameAccess; + return maIconSet[maCurrentStyle].maNameAccess; } /// Recursively dump all names ... commit 3820d954535b7b0b0e976ccd01251de848e3faea Author: Jan Holesovsky <[email protected]> Date: Sun Nov 23 01:36:24 2014 +0100 icons: Store paths of more styles at the same time. Change-Id: I9a13aa3ed928b989eaa2b2da8d1acfc5a37f506e diff --git a/vcl/inc/impimagetree.hxx b/vcl/inc/impimagetree.hxx index 22075862..94a5469 100644 --- a/vcl/inc/impimagetree.hxx +++ b/vcl/inc/impimagetree.hxx @@ -58,17 +58,27 @@ public: css::uno::Reference< css::container::XNameAccess > getNameAccess(); private: + struct IconSet { + OUString maURL; + css::uno::Reference<css::container::XNameAccess> maNameAccess; + + IconSet() {} + IconSet(const OUString &aURL) : maURL(aURL) {} + }; + + /// Map between the theme name(s) and the content. + typedef boost::unordered_map<OUString, IconSet, OUStringHash> StyleIconSet; + + StyleIconSet maIconSet; + bool doLoadImage( OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized); - typedef std::pair<OUString, css::uno::Reference<css::container::XNameAccess>> Path; - typedef boost::unordered_map<OUString, std::pair<bool, BitmapEx>, OUStringHash> IconCache; typedef boost::unordered_map<OUString, OUString, OUStringHash> IconLinkHash; OUString m_style; - Path m_path; IconCache m_iconCache; IconLinkHash m_linkHash; diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx index 63a5c56..d76070d 100644 --- a/vcl/source/gdi/impimagetree.cxx +++ b/vcl/source/gdi/impimagetree.cxx @@ -47,6 +47,8 @@ #include "impimagetree.hxx" #include <vcldemo-debug.hxx> +using namespace css; + namespace { static OUString createPath(OUString const & name, sal_Int32 pos, OUString const & locale) @@ -191,6 +193,9 @@ void ImplImageTree::setStyle(OUString const & style) void ImplImageTree::resetPaths() { + if (maIconSet.find(m_style) != maIconSet.end()) + return; + OUString url( "$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/config/" ); rtl::Bootstrap::expandMacros(url); if ( m_style != "default" ) @@ -203,8 +208,8 @@ void ImplImageTree::resetPaths() } else url += "images"; - m_path = std::make_pair( - url, css::uno::Reference< css::container::XNameAccess >()); + + maIconSet[m_style] = IconSet(url); } bool ImplImageTree::iconCacheLookup(OUString const & name, bool localized, BitmapEx & bitmap) @@ -223,14 +228,16 @@ bool ImplImageTree::findImage(std::vector<OUString> const & paths, BitmapEx & bi if (!checkPathAccess()) return false; - for (std::vector< OUString >::const_reverse_iterator j(paths.rbegin()); - j != paths.rend(); ++j) + const uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[m_style].maNameAccess; + + for (std::vector<OUString>::const_reverse_iterator j(paths.rbegin()); j != paths.rend(); ++j) { - if (m_path.second->hasByName(*j)) + if (rNameAccess->hasByName(*j)) { css::uno::Reference< css::io::XInputStream > s; - bool ok = m_path.second->getByName(*j) >>= s; - OSL_ASSERT(ok); (void) ok; + bool ok = rNameAccess->getByName(*j) >>= s; + assert(ok); + loadImageFromStream( wrapStream(s), *j, bitmap ); return true; } @@ -245,11 +252,13 @@ void ImplImageTree::loadImageLinks() if (!checkPathAccess()) return; - if ( m_path.second->hasByName(aLinkFilename) ) + const uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[m_style].maNameAccess; + + if (rNameAccess->hasByName(aLinkFilename)) { css::uno::Reference< css::io::XInputStream > s; - bool ok = m_path.second->getByName(aLinkFilename) >>= s; - OSL_ASSERT(ok); (void) ok; + bool ok = rNameAccess->getByName(aLinkFilename) >>= s; + assert(ok); parseLinkFile( wrapStream(s) ); return; @@ -293,25 +302,27 @@ OUString const & ImplImageTree::getRealImageName(OUString const & name) bool ImplImageTree::checkPathAccess() { - if (m_path.second.is()) + uno::Reference<container::XNameAccess> &rNameAccess = maIconSet[m_style].maNameAccess; + if (rNameAccess.is()) return true; try { - m_path.second = css::packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), m_path.first + ".zip"); - } catch (const css::uno::RuntimeException &) { + rNameAccess = css::packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), maIconSet[m_style].maURL + ".zip"); + } + catch (const css::uno::RuntimeException &) { throw; - } catch (const css::uno::Exception & e) { - SAL_INFO("vcl", "ImplImageTree::zip file location exception " - << e.Message << " for " << m_path.first); + } + catch (const css::uno::Exception & e) { + SAL_INFO("vcl", "ImplImageTree::zip file location exception " << e.Message << " for " << maIconSet[m_style].maURL); return false; } - return m_path.second.is(); + return rNameAccess.is(); } css::uno::Reference<css::container::XNameAccess> ImplImageTree::getNameAccess() { checkPathAccess(); - return m_path.second; + return maIconSet[m_style].maNameAccess; } /// Recursively dump all names ... @@ -319,8 +330,7 @@ css::uno::Sequence<OUString> ImageTree_getAllImageNames() { static ImplImageTreeSingletonRef aImageTree; - css::uno::Reference< css::container::XNameAccess > xRef( - aImageTree->getNameAccess() ); + css::uno::Reference<css::container::XNameAccess> xRef(aImageTree->getNameAccess()); return xRef->getElementNames(); } commit 9e4a1396d602b010f2dbdb0b7f1249dfe1abd01a Author: Jan Holesovsky <[email protected]> Date: Sun Nov 23 00:00:30 2014 +0100 icons: Kill an unused function + bring some consistency to the file. Change-Id: I346d751cef124b534784f0b3b335c9578c56e024 diff --git a/vcl/inc/impimagetree.hxx b/vcl/inc/impimagetree.hxx index 233893e..22075862 100644 --- a/vcl/inc/impimagetree.hxx +++ b/vcl/inc/impimagetree.hxx @@ -80,7 +80,7 @@ private: bool iconCacheLookup( OUString const & name, bool localized, BitmapEx & bitmap ); - bool find(std::vector< OUString > const & paths, BitmapEx & bitmap ); + bool findImage(std::vector< OUString > const & paths, BitmapEx & bitmap ); void loadImageLinks(); void parseLinkFile(boost::shared_ptr< SvStream > stream); diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx index ecfaf20..63a5c56 100644 --- a/vcl/source/gdi/impimagetree.cxx +++ b/vcl/source/gdi/impimagetree.cxx @@ -49,34 +49,12 @@ namespace { -static OUString createPath( - OUString const & name, sal_Int32 pos, OUString const & locale) +static OUString createPath(OUString const & name, sal_Int32 pos, OUString const & locale) { return name.copy(0, pos + 1) + locale + name.copy(pos); } -static boost::shared_ptr< SvStream > wrapFile(osl::File & file) -{ - // This could use SvInputStream instead if that did not have a broken - // SeekPos implementation for an XInputStream that is not also XSeekable - // (cf. "@@@" at tags/DEV300_m37/svtools/source/misc1/strmadpt.cxx@264807 - // l. 593): - boost::shared_ptr< SvStream > s(new SvMemoryStream); - for (;;) { - void *data[2048]; - sal_uInt64 n; - file.read(data, 2048, n); - s->Write(data, n); - if (n < 2048) { - break; - } - } - s->Seek(0); - return s; -} - -static boost::shared_ptr< SvStream > wrapStream( - css::uno::Reference< css::io::XInputStream > const & stream) +static boost::shared_ptr< SvStream > wrapStream(css::uno::Reference< css::io::XInputStream > const & stream) { // This could use SvInputStream instead if that did not have a broken // SeekPos implementation for an XInputStream that is not also XSeekable @@ -84,29 +62,29 @@ static boost::shared_ptr< SvStream > wrapStream( // l. 593): OSL_ASSERT(stream.is()); boost::shared_ptr< SvStream > s(new SvMemoryStream); - for (;;) { + for (;;) + { sal_Int32 const size = 2048; css::uno::Sequence< sal_Int8 > data(size); sal_Int32 n = stream->readBytes(data, size); s->Write(data.getConstArray(), n); - if (n < size) { + if (n < size) break; - } } s->Seek(0); return s; } -static void loadImageFromStream( - boost::shared_ptr< SvStream > pStream, - OUString const & rPath, BitmapEx & rBitmap) +static void loadImageFromStream(boost::shared_ptr< SvStream > pStream, OUString const & rPath, BitmapEx & rBitmap) { if (rPath.endsWith(".png")) { vcl::PNGReader aPNGReader( *pStream ); aPNGReader.SetIgnoreGammaChunk( true ); rBitmap = aPNGReader.Read(); - } else { + } + else + { ReadDIBBitmapEx(rBitmap, *pStream); } } @@ -121,9 +99,8 @@ ImplImageTree::~ImplImageTree() { } -bool ImplImageTree::loadImage( - OUString const & name, OUString const & style, BitmapEx & bitmap, - bool localized, bool loadMissing ) +bool ImplImageTree::loadImage(OUString const & name, OUString const & style, BitmapEx & bitmap, + bool localized, bool loadMissing) { bool found = false; try { @@ -141,17 +118,14 @@ bool ImplImageTree::loadImage( return loadDefaultImage(style, bitmap); } -bool ImplImageTree::loadDefaultImage( - OUString const & style, - BitmapEx& bitmap) +bool ImplImageTree::loadDefaultImage(OUString const & style, BitmapEx& bitmap) { return doLoadImage( OUString("res/grafikde.png"), style, bitmap, false); } -bool ImplImageTree::doLoadImage( - OUString const & name, OUString const & style, BitmapEx & bitmap, +bool ImplImageTree::doLoadImage(OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized) { setStyle(style); @@ -164,11 +138,12 @@ bool ImplImageTree::doLoadImage( std::vector< OUString > paths; paths.push_back(getRealImageName(name)); - if (localized) { + if (localized) + { sal_Int32 pos = name.lastIndexOf('/'); if (pos != -1) { - // find() uses a reverse iterator, so push in reverse order. + // findImage() uses a reverse iterator, so push in reverse order. std::vector< OUString > aFallbacks( Application::GetSettings().GetUILanguageTag().getFallbackStrings(true)); for (std::vector< OUString >::reverse_iterator it( aFallbacks.rbegin()); it != aFallbacks.rend(); ++it) @@ -177,9 +152,10 @@ bool ImplImageTree::doLoadImage( } } } + bool found = false; try { - found = find(paths, bitmap); + found = findImage(paths, bitmap); } catch (css::uno::RuntimeException &) { throw; } catch (const css::uno::Exception & e) { @@ -192,16 +168,19 @@ bool ImplImageTree::doLoadImage( return found; } -void ImplImageTree::shutDown() { +void ImplImageTree::shutDown() +{ m_style.clear(); // for safety; empty m_style means "not initialized" m_iconCache.clear(); m_linkHash.clear(); } -void ImplImageTree::setStyle(OUString const & style) { +void ImplImageTree::setStyle(OUString const & style) +{ OSL_ASSERT(!style.isEmpty()); // empty m_style means "not initialized" - if (style != m_style) { + if (style != m_style) + { m_style = style; resetPaths(); m_iconCache.clear(); @@ -210,7 +189,8 @@ void ImplImageTree::setStyle(OUString const & style) { } } -void ImplImageTree::resetPaths() { +void ImplImageTree::resetPaths() +{ OUString url( "$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/config/" ); rtl::Bootstrap::expandMacros(url); if ( m_style != "default" ) @@ -227,19 +207,18 @@ void ImplImageTree::resetPaths() { url, css::uno::Reference< css::container::XNameAccess >()); } -bool ImplImageTree::iconCacheLookup( - OUString const & name, bool localized, BitmapEx & bitmap) +bool ImplImageTree::iconCacheLookup(OUString const & name, bool localized, BitmapEx & bitmap) { IconCache::iterator i(m_iconCache.find(getRealImageName(name))); - if (i != m_iconCache.end() && i->second.first == localized) { + if (i != m_iconCache.end() && i->second.first == localized) + { bitmap = i->second.second; return true; } return false; } -bool ImplImageTree::find( - std::vector< OUString > const & paths, BitmapEx & bitmap) +bool ImplImageTree::findImage(std::vector<OUString> const & paths, BitmapEx & bitmap) { if (!checkPathAccess()) return false; @@ -247,7 +226,8 @@ bool ImplImageTree::find( for (std::vector< OUString >::const_reverse_iterator j(paths.rbegin()); j != paths.rend(); ++j) { - if (m_path.second->hasByName(*j)) { + if (m_path.second->hasByName(*j)) + { css::uno::Reference< css::io::XInputStream > s; bool ok = m_path.second->getByName(*j) >>= s; OSL_ASSERT(ok); (void) ok; @@ -328,14 +308,14 @@ bool ImplImageTree::checkPathAccess() return m_path.second.is(); } -css::uno::Reference< css::container::XNameAccess > ImplImageTree::getNameAccess() +css::uno::Reference<css::container::XNameAccess> ImplImageTree::getNameAccess() { checkPathAccess(); return m_path.second; } /// Recursively dump all names ... -css::uno::Sequence< OUString > ImageTree_getAllImageNames() +css::uno::Sequence<OUString> ImageTree_getAllImageNames() { static ImplImageTreeSingletonRef aImageTree; commit 44e02826bfc46cb5647d3805283b303bc964385f Author: Jan Holesovsky <[email protected]> Date: Sat Nov 22 22:23:04 2014 +0100 icons: m_cacheIcons is always true, kill it. Change-Id: Ie63f8780093a2605ecd4d1e80ccb05e16b486cf1 diff --git a/vcl/inc/impimagetree.hxx b/vcl/inc/impimagetree.hxx index c8c8fab..233893e 100644 --- a/vcl/inc/impimagetree.hxx +++ b/vcl/inc/impimagetree.hxx @@ -70,7 +70,6 @@ private: OUString m_style; Path m_path; IconCache m_iconCache; - bool m_cacheIcons; IconLinkHash m_linkHash; bool checkPathAccess(); diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx index fb07567..ecfaf20 100644 --- a/vcl/source/gdi/impimagetree.cxx +++ b/vcl/source/gdi/impimagetree.cxx @@ -113,9 +113,13 @@ static void loadImageFromStream( } -ImplImageTree::ImplImageTree() { m_cacheIcons = true; } +ImplImageTree::ImplImageTree() +{ +} -ImplImageTree::~ImplImageTree() {} +ImplImageTree::~ImplImageTree() +{ +} bool ImplImageTree::loadImage( OUString const & name, OUString const & style, BitmapEx & bitmap, @@ -151,18 +155,19 @@ bool ImplImageTree::doLoadImage( bool localized) { setStyle(style); - if (m_cacheIcons && iconCacheLookup(name, localized, bitmap)) { + if (iconCacheLookup(name, localized, bitmap)) return true; - } - if (!bitmap.IsEmpty()) { + + if (!bitmap.IsEmpty()) bitmap.SetEmpty(); - } + std::vector< OUString > paths; paths.push_back(getRealImageName(name)); if (localized) { sal_Int32 pos = name.lastIndexOf('/'); - if (pos != -1) { + if (pos != -1) + { // find() uses a reverse iterator, so push in reverse order. std::vector< OUString > aFallbacks( Application::GetSettings().GetUILanguageTag().getFallbackStrings(true)); for (std::vector< OUString >::reverse_iterator it( aFallbacks.rbegin()); @@ -180,9 +185,10 @@ bool ImplImageTree::doLoadImage( } catch (const css::uno::Exception & e) { SAL_INFO("vcl", "ImplImageTree::doLoadImage exception " << e.Message); } - if (m_cacheIcons && found) { + + if (found) m_iconCache[name.intern()] = std::make_pair(localized, bitmap); - } + return found; } @@ -235,20 +241,6 @@ bool ImplImageTree::iconCacheLookup( bool ImplImageTree::find( std::vector< OUString > const & paths, BitmapEx & bitmap) { - if (!m_cacheIcons) { - for (std::vector< OUString >::const_reverse_iterator j( - paths.rbegin()); - j != paths.rend(); ++j) - { - osl::File file(m_path.first + "/" + *j); - if (file.open(osl_File_OpenFlag_Read) == ::osl::FileBase::E_None) { - loadImageFromStream( wrapFile(file), *j, bitmap ); - file.close(); - return true; - } - } - } - if (!checkPathAccess()) return false; @@ -270,17 +262,6 @@ void ImplImageTree::loadImageLinks() { const OUString aLinkFilename("links.txt"); - if (!m_cacheIcons) - { - osl::File file(m_path.first + "/" + aLinkFilename); - if (file.open(osl_File_OpenFlag_Read) == ::osl::FileBase::E_None) - { - parseLinkFile( wrapFile(file) ); - file.close(); - return; - } - } - if (!checkPathAccess()) return; commit f09b39a65ddd60dabf4e47cb5e82acbd32305b31 Author: Jan Holesovsky <[email protected]> Date: Sat Nov 22 22:09:16 2014 +0100 icons: Unused CheckStyleCache. Change-Id: I9097b2704b7a961f448c58572f091f335847e951 diff --git a/vcl/inc/impimagetree.hxx b/vcl/inc/impimagetree.hxx index 9e4f579..c8c8fab 100644 --- a/vcl/inc/impimagetree.hxx +++ b/vcl/inc/impimagetree.hxx @@ -62,16 +62,10 @@ private: OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized); - typedef std::pair< - OUString, - css::uno::Reference< css::container::XNameAccess > > Path; - - typedef boost::unordered_map< - OUString, bool, OUStringHash > CheckStyleCache; - typedef boost::unordered_map< - OUString, std::pair< bool, BitmapEx >, OUStringHash > IconCache; - typedef boost::unordered_map< - OUString, OUString, OUStringHash > IconLinkHash; + typedef std::pair<OUString, css::uno::Reference<css::container::XNameAccess>> Path; + + typedef boost::unordered_map<OUString, std::pair<bool, BitmapEx>, OUStringHash> IconCache; + typedef boost::unordered_map<OUString, OUString, OUStringHash> IconLinkHash; OUString m_style; Path m_path; _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
