summaryrefslogtreecommitdiff
path: root/vcl/source/gdi/impimagetree.cxx
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2009-02-12 09:18:09 +0000
committerOliver Bolte <obo@openoffice.org>2009-02-12 09:18:09 +0000
commit68f3a7e1ecb8c3585507f857604ec8e9b1874166 (patch)
tree3588f03c967e2241a9b4ee5970b26603688962d4 /vcl/source/gdi/impimagetree.cxx
parentf53e1b5c40e9a4674b035d11313c0ce77362fe07 (diff)
CWS-TOOLING: integrate CWS sb103
2009-01-15 15:28:08 +0100 sb r266375 : #i97629# set UNO_PATH in python start program and use it in bootstrap function in officehelper.py (and do not erroneously encode a vnd.sun.star.pathname URE_BOOTSTRAP value in tools::extendApplicationEnvironment) 2009-01-15 10:40:17 +0100 sb r266338 : #i97424# explicit shut down of ImplImageTree singleton in DeInitVCL still required 2009-01-14 12:07:15 +0100 sb r266276 : CWS-TOOLING: rebase CWS sb103 to trunk@265758 (milestone: DEV300:m38) 2009-01-14 08:53:02 +0100 sb r266266 : #i96284# remove implementation of unused (but expensive) link feature; plus some general cleanup 2009-01-08 14:42:59 +0100 sb r266010 : #i96683# enable dlclose for GCC 3 (based on a patch by cmc) 2009-01-06 14:18:23 +0100 sb r265920 : #i97424# spurious unreferenced local variables 2008-12-19 15:33:39 +0100 sb r265727 : #i57359# no need for a special glibc 2.2.4 based libgcc_s.so.1 for URE any more as the general one used for OOo is guaranteed to be based on at least glibc 2.2.4, anyway 2008-12-19 13:54:37 +0100 sb r265724 : #i97424# clean up and speed up vcl ImplImageTree 2008-12-18 14:28:10 +0100 sb r265690 : #i97132# spread usage of the rtl::Static pattern (patch by cmc) 2008-12-15 14:33:00 +0100 sb r265499 : #i90492# generate UTF-8 encoded output (patch by tora) 2008-12-15 11:45:05 +0100 sb r265469 : #i95593# -Djava.library.path to find libtest_javauno_any.so 2008-12-15 11:23:14 +0100 sb r265468 : #i93769# it appears that Java nowadays expects file URIs in UTF-8, so ExternalUriReferenceTranslator.toExternal must not be called 2008-12-10 12:02:50 +0100 sb r265164 : #i93219# use (corrected) signal handling instead of forking again (to avoid unintended generation of core files)
Diffstat (limited to 'vcl/source/gdi/impimagetree.cxx')
-rw-r--r--vcl/source/gdi/impimagetree.cxx872
1 files changed, 235 insertions, 637 deletions
diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx
index 00cba849de43..64cddece1199 100644
--- a/vcl/source/gdi/impimagetree.cxx
+++ b/vcl/source/gdi/impimagetree.cxx
@@ -1,696 +1,294 @@
/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: impimagetree.cxx,v $
- * $Revision: 1.19 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: code,v $
+*
+* $Revision: 1.4 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
-// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_vcl.hxx"
+#include "sal/config.h"
-#include <cstdio>
-#include <ctype.h>
-#include <tools/debug.hxx>
-#include <tools/datetime.hxx>
-#include <tools/urlobj.hxx>
-#include <vcl/svapp.hxx>
-#include <vcl/bitmapex.hxx>
-#include <vcl/pngread.hxx>
-#include <unotools/ucbstreamhelper.hxx>
-#ifndef _UNTOOLS_LOCALFILEHELPER_HXX
-#include <unotools/localfilehelper.hxx>
-#endif
-#include <unotools/datetime.hxx>
-#include <comphelper/processfactory.hxx>
-#include <rtl/bootstrap.hxx>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/packages/zip/XZipFileAccess.hpp>
-#include <com/sun/star/container/XNameAccess.hpp>
-#include <com/sun/star/lang/XInitialization.hpp>
-#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
-
-#include "vcl/impimagetree.hxx"
-
+#include <list>
+#include <memory>
+#include <utility>
#include <vector>
-#include <hash_map>
-#define DEFAULT_PROJECTNAME "res"
-#define IMAGES_ZIPFILENAME_PREFIX "images"
-#define IMAGES_ZIPFILENAME_BRAND "_brand"
-#define IMAGES_ZIPFILENAME_SUFFIX ".zip"
-#define IMAGES_CACHEDIR "imagecache"
-
-using namespace ::com::sun::star;
+#include <hash_map>
-ImplZipAccessor::ImplZipAccessor()
-{
- uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
+#include "com/sun/star/container/XNameAccess.hpp"
+#include "com/sun/star/io/XInputStream.hpp"
+#include "com/sun/star/lang/Locale.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "comphelper/processfactory.hxx"
+#include "osl/diagnose.h"
+#include "rtl/bootstrap.hxx"
+#include "rtl/string.h"
+#include "rtl/textenc.h"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+#include "tools/stream.hxx"
+#include "tools/urlobj.hxx"
+#include "vcl/bitmapex.hxx"
+#include "vcl/impimagetree.hxx"
+#include "vcl/pngread.hxx"
+#include "vcl/settings.hxx"
+#include "vcl/svapp.hxx"
- if( xFactory.is() )
- {
- mxFileAccess.set( xFactory->createInstance(
- ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
- uno::UNO_QUERY );
- }
-}
+namespace {
-// -----------------------------------------------------------------------
+namespace css = com::sun::star;
-ImplZipAccessor::~ImplZipAccessor()
+rtl::OUString createPath(
+ rtl::OUString const & name, sal_Int32 pos, rtl::OUString const & locale)
{
- Clear();
+ rtl::OUStringBuffer b(name.copy(0, pos + 1));
+ b.append(locale);
+ b.append(name.copy(pos));
+ return b.makeStringAndClear();
}
-// -----------------------------------------------------------------------
-
-void ImplZipAccessor::Update( const ::rtl::OUString& rSymbolsStyle )
+std::auto_ptr< SvStream > wrapStream(
+ css::uno::Reference< css::io::XInputStream > const & stream)
{
-#ifdef DEBUG
- std::fprintf( stderr, "\nUpdating symbols for style: %s\n", ByteString( String( rSymbolsStyle ), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
-#endif
-
- Clear();
-
- uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
-
- const ::rtl::OUString aZipFileName( ::rtl::OUString::createFromAscii( IMAGES_ZIPFILENAME_PREFIX ) );
- rtl::OUString aBrandPath( RTL_CONSTASCII_USTRINGPARAM( "$BRAND_BASE_DIR/share/config" ) );
- rtl::OUString aOOOPath( RTL_CONSTASCII_USTRINGPARAM( "$OOO_BASE_DIR/share/config" ) );
- ::std::vector< ::rtl::OUString > aTmpURLVector;
-
- rtl::Bootstrap::expandMacros( aBrandPath );
- rtl::Bootstrap::expandMacros( aOOOPath );
-
- // Theme Branding Zip
- if( rSymbolsStyle.getLength() )
- {
- INetURLObject aThemeBrandURL( aBrandPath );
- ::rtl::OUString aThemeBrandZip( aZipFileName );
-
- ( aThemeBrandZip += ::rtl::OUString::createFromAscii( "_" ) ) += rSymbolsStyle;
- aThemeBrandZip += ::rtl::OUString::createFromAscii( IMAGES_ZIPFILENAME_BRAND );
- aThemeBrandZip += ::rtl::OUString::createFromAscii( IMAGES_ZIPFILENAME_SUFFIX );
- aThemeBrandURL.Append( aThemeBrandZip );
-
- if( mxFileAccess->exists( aThemeBrandURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
- aTmpURLVector.push_back( aThemeBrandURL.GetMainURL( INetURLObject::NO_DECODE ) );
- }
-
- // Branding Zip
- INetURLObject aBrandURL( aBrandPath );
- ::rtl::OUString aBrandZip( aZipFileName );
-
- aBrandZip += ::rtl::OUString::createFromAscii( IMAGES_ZIPFILENAME_BRAND );
- aBrandZip += ::rtl::OUString::createFromAscii( IMAGES_ZIPFILENAME_SUFFIX );
- aBrandURL.Append( aBrandZip );
-
- if( mxFileAccess->exists( aBrandURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
- aTmpURLVector.push_back( aBrandURL.GetMainURL( INetURLObject::NO_DECODE ) );
-
- // Theme Zip
- if( rSymbolsStyle.getLength() )
- {
- INetURLObject aThemeURL( aOOOPath );
- ::rtl::OUString aThemeZip( aZipFileName );
-
- ( aThemeZip += ::rtl::OUString::createFromAscii( "_" ) ) += rSymbolsStyle;
- aThemeZip += ::rtl::OUString::createFromAscii( IMAGES_ZIPFILENAME_SUFFIX );
- aThemeURL.Append( aThemeZip );
-
- if( mxFileAccess->exists( aThemeURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
- aTmpURLVector.push_back( aThemeURL.GetMainURL( INetURLObject::NO_DECODE ) );
- }
-
- // Default Zip
- if( rSymbolsStyle.getLength() )
- {
- INetURLObject aDefaultURL( aOOOPath );
- ::rtl::OUString aDefaultZip( aZipFileName );
-
- aDefaultZip += ::rtl::OUString::createFromAscii( IMAGES_ZIPFILENAME_SUFFIX );
- aDefaultURL.Append( aDefaultZip );
-
- if( mxFileAccess->exists( aDefaultURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
- aTmpURLVector.push_back( aDefaultURL.GetMainURL( INetURLObject::NO_DECODE ) );
- }
-
- if( xFactory.is() )
- {
- for( unsigned int i = 0; i < aTmpURLVector.size(); ++i )
- {
- try
- {
- uno::Reference< packages::zip::XZipFileAccess > xZipAcc( xFactory->createInstance(
- ::rtl::OUString::createFromAscii( "com.sun.star.packages.zip.ZipFileAccess" ) ),
- uno::UNO_QUERY );
-
- if( xZipAcc.is() )
- {
- uno::Reference< lang::XInitialization > xInit( xZipAcc, uno::UNO_QUERY );
-
- if( xInit.is() )
- {
- uno::Sequence< uno::Any > aInitSeq( 1 );
- const ::rtl::OUString& rZipURL = aTmpURLVector[ i ];
-
- if( rZipURL.getLength() )
- {
- uno::Reference< container::XNameAccess > xNameAcc;
-
- aInitSeq[ 0 ] <<= rZipURL;
- xInit->initialize( aInitSeq );
- xNameAcc.set( xZipAcc, uno::UNO_QUERY );
-
- if( xNameAcc.is() && xNameAcc->getElementNames().getLength() )
- {
- maURLVector.push_back( rZipURL );
- maZipAccVector.push_back( xZipAcc );
- maNameAccVector.push_back( xNameAcc );
-#ifdef DEBUG
- std::fprintf( stderr, "Current set has symbols from archive: %s\n", ByteString( String( rZipURL ), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
-#endif
- }
- }
- }
- }
- }
- catch( const uno::Exception& )
- {
- }
+ // 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):
+ OSL_ASSERT(stream.is());
+ std::auto_ptr< SvStream > s(new SvMemoryStream);
+ for (;;) {
+ css::uno::Sequence< sal_Int8 > data;
+ sal_Int32 const size = 30000;
+ sal_Int32 n = stream->readBytes(data, size);
+ s->Write(data.getConstArray(), n);
+ if (n < size) {
+ break;
}
}
+ s->Seek(0);
+ return s;
}
-// -----------------------------------------------------------------------
-
-void ImplZipAccessor::Clear()
-{
- maURLVector.clear();
- maZipAccVector.clear();
- maNameAccVector.clear();
-}
-
-// -----------------------------------------------------------------------
-
-bool ImplZipAccessor::HasEntries() const
+void loadFromStream(
+ css::uno::Reference< css::io::XInputStream > const & stream,
+ rtl::OUString const & path, BitmapEx & bitmap)
{
- return( maNameAccVector.size() > 0 );
-}
-
-// -----------------------------------------------------------------------
-
-uno::Reference< io::XInputStream > ImplZipAccessor::GetByName( const ::rtl::OUString& rName ) const
-{
- uno::Reference< io::XInputStream > xRet;
-
-#ifdef DEBUG
- std::fprintf( stderr, "Looking for file: %s\n", ByteString( String( rName ), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
-#endif
-
- for( unsigned int i = 0; ( i < maNameAccVector.size() ) && !xRet.is(); ++i )
- {
- if( maNameAccVector[ i ]->hasByName( rName ) )
- {
- try
- {
- if( maNameAccVector[ i ]->getByName( rName ) >>= xRet )
- {
-#ifdef DEBUG
- std::fprintf( stderr, "Found in archive: %s\n\n", ByteString( String( maURLVector[ i ] ), RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
-#endif
-
-
- break;
- }
- }
- catch( const uno::Exception & )
- {
- }
- }
+ std::auto_ptr< SvStream > s(wrapStream(stream));
+ if (path.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".png"))) {
+ bitmap = vcl::PNGReader(*s).Read();
+ } else {
+ *s >> bitmap;
}
-
- return( xRet );
-}
-
-
-// -----------------
-// - ImplImageTree -
-// -----------------
-
-typedef ::std::hash_map< ::rtl::OUString, BitmapEx, ::rtl::OUStringHash > BmpExHashMap;
-static BmpExHashMap aBmpExHashMap;
-
-// -----------------------------------------------------------------------
-
-ImplImageTree::ImplImageTree() :
- mbInit( false ),
- maSymbolsStyle( Application::GetSettings().GetStyleSettings().GetCurrentSymbolsStyleName() )
-{
}
-// -----------------------------------------------------------------------
-
-ImplImageTree::~ImplImageTree()
-{
}
-// -----------------------------------------------------------------------
-
-void ImplImageTree::cleanup()
-{
- ImplImageTreeSingletonRef aCleaner;
-
- aCleaner->maZipAcc.Clear();
- aCleaner->mxFileAccess.clear();
- aCleaner->mxPathSettings.clear();
-
- BmpExHashMap aTmp;
- aBmpExHashMap.swap( aTmp );
-}
+ImplImageTree::ImplImageTree() {}
-// -----------------------------------------------------------------------
+ImplImageTree::~ImplImageTree() {}
-bool ImplImageTree::implInit()
+bool ImplImageTree::loadImage(
+ rtl::OUString const & name, rtl::OUString const & style, BitmapEx & bitmap,
+ bool localized)
{
- if( !mbInit )
- {
- uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
-
- if( xFactory.is() )
- {
- // #137795# protect against exceptions in service instantiation
- try
- {
- mxPathSettings.set( xFactory->createInstance(
- ::rtl::OUString::createFromAscii( "com.sun.star.util.PathSettings" ) ),
- uno::UNO_QUERY );
- mxFileAccess.set( xFactory->createInstance(
- ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
- uno::UNO_QUERY );
-
- if( mxPathSettings.is() && mxFileAccess.is() )
- {
- maZipAcc.Update( maSymbolsStyle );
- // implCheckUserCache();
+ setStyle(style);
+ if (cacheLookup(name, localized, bitmap)) {
+ return true;
+ }
+ if (!bitmap.IsEmpty()) {
+ bitmap.SetEmpty();
+ }
+ std::vector< rtl::OUString > paths;
+ paths.push_back(name);
+ if (localized) {
+ sal_Int32 pos = name.lastIndexOf('/');
+ if (pos != -1) {
+ css::lang::Locale const & loc =
+ Application::GetSettings().GetUILocale();
+ paths.push_back(createPath(name, pos, loc.Language));
+ if (loc.Country.getLength() != 0) {
+ rtl::OUStringBuffer b(loc.Language);
+ b.append(sal_Unicode('-'));
+ b.append(loc.Country);
+ rtl::OUString p(createPath(name, pos, b.makeStringAndClear()));
+ paths.push_back(p);
+ if (loc.Variant.getLength() != 0) {
+ b.append(p);
+ b.append(sal_Unicode('-'));
+ b.append(loc.Variant);
+ paths.push_back(
+ createPath(name, pos, b.makeStringAndClear()));
}
}
- catch( const uno::Exception& )
- {
- maZipAcc.Clear();
- mxPathSettings.clear();
- mxFileAccess.clear();
- }
}
}
-
- return( mbInit = maZipAcc.HasEntries() );
-}
-
-// -----------------------------------------------------------------------
-
-const ::rtl::OUString& ImplImageTree::implGetUserDirURL() const
-{
- static ::rtl::OUString aRet;
-
- if( !aRet.getLength() && mxPathSettings.is() && mxFileAccess.is() )
- {
- const ::rtl::OUString aImagesCacheDir( ::rtl::OUString::createFromAscii( IMAGES_CACHEDIR ) );
- uno::Any aAny( mxPathSettings->getPropertyValue( ::rtl::OUString::createFromAscii( "UserConfig" ) ) );
-
- if( ( aAny >>= aRet ) && aRet.getLength() )
- {
- INetURLObject aCacheURL( aRet );
-
- aCacheURL.Append( aImagesCacheDir );
-
- try
- {
- mxFileAccess->createFolder( aRet = aCacheURL.GetMainURL( INetURLObject::NO_DECODE ) );
- }
- catch( const ucb::CommandAbortedException& )
- {
- }
- catch( const uno::Exception& )
- {
- }
- }
+ bool found = false;
+ try {
+ found = find(paths, bitmap);
+ } catch (css::uno::RuntimeException &) {
+ throw;
+ } catch (css::uno::Exception & e) {
+ OSL_TRACE(
+ "ImplImageTree::loadImage exception \"%s\"",
+ rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
}
-
- return aRet;
+ if (found) {
+ m_cache[name.intern()] = std::make_pair(localized, bitmap);
+ }
+ return found;
}
-// -----------------------------------------------------------------------
-
-::rtl::OUString ImplImageTree::implGetUserFileURL( const ::rtl::OUString& rName ) const
-{
- INetURLObject aFileURL( implGetUserDirURL() );
-
- aFileURL.Append( rName );
-
- return( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
+void ImplImageTree::shutDown() {
+ m_style = rtl::OUString();
+ // for safety; empty m_style means "not initialized"
+ m_zips.clear();
+ m_cache.clear();
}
-// -----------------------------------------------------------------------
-
-void ImplImageTree::implCheckUserCache()
-{
-/*
- const ::rtl::OUString& rZipURL = implGetZipFileURL();
- const ::rtl::OUString& rUserDirURL = implGetUserDirURL();
-
- if( rZipURL.getLength() && rUserDirURL.getLength() )
- {
- try
- {
- ::DateTime aZipDateTime, aCacheFileDateTime;
- const uno::Sequence< ::rtl::OUString > aCacheFiles( mxFileAccess->getFolderContents( rUserDirURL, false ) );
-
- ::utl::typeConvert( mxFileAccess->getDateTimeModified( rZipURL ), aZipDateTime );
-
- for( sal_Int32 i = 0; i < aCacheFiles.getLength(); ++i )
- {
- const ::rtl::OUString aCacheFile( aCacheFiles[ i ] );
-
- try
- {
- ::utl::typeConvert( mxFileAccess->getDateTimeModified( aCacheFile ), aCacheFileDateTime );
-
- if( aZipDateTime > aCacheFileDateTime )
- mxFileAccess->kill( aCacheFile );
- }
- catch( const ucb::CommandAbortedException& )
- {
- }
- catch( const uno::Exception& )
- {
- }
- }
- }
- catch( const ucb::CommandAbortedException& )
- {
- }
- catch( const uno::Exception& )
- {
- }
+void ImplImageTree::setStyle(rtl::OUString const & style) {
+ OSL_ASSERT(style.getLength() != 0); // empty m_style means "not initialized"
+ if (style != m_style) {
+ m_style = style;
+ resetZips();
+ m_cache.clear();
}
-*/
}
-// ------------------------------------------------------------------------------
-
-bool ImplImageTree::implLoadFromStream( SvStream& rIStm,
- const ::rtl::OUString& rFileName,
- BitmapEx& rReturn )
-{
- static const ::rtl::OUString aPNGExtension( ::rtl::OUString::createFromAscii( "png" ) );
- const sal_Int32 nDotPos = rFileName.lastIndexOf( '.' );
- const sal_uInt32 nStmPos = rIStm.Tell();
-
- if( ( -1 != nDotPos ) && ( rFileName.lastIndexOf( aPNGExtension ) == ( nDotPos + 1 ) ) )
+void ImplImageTree::resetZips() {
+ m_zips.clear();
{
- ::vcl::PNGReader aPNGReader( rIStm );
- rReturn = aPNGReader.Read();
+ rtl::OUString url(
+ RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR/share/config"));
+ rtl::Bootstrap::expandMacros(url);
+ INetURLObject u(url);
+ OSL_ASSERT(!u.HasError());
+ rtl::OUStringBuffer b;
+ b.appendAscii(RTL_CONSTASCII_STRINGPARAM("images_"));
+ b.append(m_style);
+ b.appendAscii(RTL_CONSTASCII_STRINGPARAM("_brand.zip"));
+ bool ok = u.Append(b.makeStringAndClear(), INetURLObject::ENCODE_ALL);
+ OSL_ASSERT(ok); (void) ok;
+ m_zips.push_back(
+ std::make_pair(
+ u.GetMainURL(INetURLObject::NO_DECODE),
+ css::uno::Reference< css::container::XNameAccess >()));
}
-
- if( rReturn.IsEmpty() )
{
- rIStm.Seek( nStmPos );
- rIStm.ResetError();
- rIStm >> rReturn;
+ rtl::OUString url(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "$BRAND_BASE_DIR/share/config/images_brand.zip"));
+ rtl::Bootstrap::expandMacros(url);
+ m_zips.push_back(
+ std::make_pair(
+ url, css::uno::Reference< css::container::XNameAccess >()));
}
-
- return( !rReturn.IsEmpty() );
-}
-
-// ------------------------------------------------------------------------------
-
-::std::auto_ptr< SvStream > ImplImageTree::implGetStream( const uno::Reference< io::XInputStream >& rxIStm ) const
-{
- ::std::auto_ptr< SvStream > apRet;
-
- // create a seekable memory stream from the non-seekable XInputStream
- if( rxIStm.is() )
{
- const sal_Int32 nBufferSize = 32768;
- sal_Int32 nRead;
- uno::Sequence < sal_Int8 > aReadSeq( nBufferSize );
-
- apRet.reset( new SvMemoryStream( nBufferSize, nBufferSize ) );
-
- do
- {
- nRead = rxIStm->readBytes ( aReadSeq, nBufferSize );
- apRet->Write( aReadSeq.getConstArray(), nRead );
- }
- while ( nRead == nBufferSize );
-
- if( apRet->Tell() > 0 )
- apRet->Seek( 0 );
- else
- apRet.reset();
+ rtl::OUString url(
+ RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/share/config"));
+ rtl::Bootstrap::expandMacros(url);
+ INetURLObject u(url);
+ OSL_ASSERT(!u.HasError());
+ rtl::OUStringBuffer b;
+ b.appendAscii(RTL_CONSTASCII_STRINGPARAM("images_"));
+ b.append(m_style);
+ b.appendAscii(RTL_CONSTASCII_STRINGPARAM(".zip"));
+ bool ok = u.Append(b.makeStringAndClear(), INetURLObject::ENCODE_ALL);
+ OSL_ASSERT(ok); (void) ok;
+ m_zips.push_back(
+ std::make_pair(
+ u.GetMainURL(INetURLObject::NO_DECODE),
+ css::uno::Reference< css::container::XNameAccess >()));
+ }
+ {
+ rtl::OUString url(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "$OOO_BASE_DIR/share/config/images.zip"));
+ rtl::Bootstrap::expandMacros(url);
+ m_zips.push_back(
+ std::make_pair(
+ url, css::uno::Reference< css::container::XNameAccess >()));
}
-
- return apRet;
}
-// ------------------------------------------------------------------------------
-
-void ImplImageTree::implUpdateSymbolsStyle( const ::rtl::OUString& rSymbolsStyle )
+bool ImplImageTree::cacheLookup(
+ rtl::OUString const & name, bool localized, BitmapEx & bitmap)
{
- if ( rSymbolsStyle != maSymbolsStyle )
- {
- maSymbolsStyle = rSymbolsStyle;
- if ( mbInit )
- {
- maZipAcc.Clear();
- mxFileAccess.clear();
- mxPathSettings.clear();
-
- BmpExHashMap aTmp;
- aBmpExHashMap.swap( aTmp );
-
- mbInit = false;
- }
+ Cache::iterator i(m_cache.find(name));
+ if (i != m_cache.end() && i->second.first == localized) {
+ bitmap = i->second.second;
+ return true;
+ } else {
+ return false;
}
}
-// ------------------------------------------------------------------------------
-
-bool ImplImageTree::loadImage( const ::rtl::OUString& rName,
- const ::rtl::OUString& rSymbolsStyle,
- BitmapEx& rReturn,
- bool bSearchLanguageDependent )
+bool ImplImageTree::find(
+ std::vector< rtl::OUString > const & paths, BitmapEx & bitmap)
{
- implUpdateSymbolsStyle( rSymbolsStyle );
-
- const BmpExHashMap::const_iterator aBmpExFindIter( aBmpExHashMap.find( rName ) );
-
- if( aBmpExFindIter != aBmpExHashMap.end() )
- rReturn = (*aBmpExFindIter).second;
- else
- {
- if( !rReturn.IsEmpty() )
- rReturn.SetEmpty();
-
- if( maZipAcc.HasEntries() || ( implInit() && maZipAcc.HasEntries() ) )
- {
- if( bSearchLanguageDependent )
- {
- // try to get image from local subdirectory
- const ::rtl::OUString aDash( ::rtl::OUString::createFromAscii( "-" ) );
- const lang::Locale& rLocale = Application::GetSettings().GetUILocale();
- ::rtl::OUString aSubDir[3]; // array must be expanded if more locale variants are checked!
- int nSubDirs=0;
- ::rtl::OUString aLocaleStr( rLocale.Language );
-
- aSubDir[nSubDirs++] = aLocaleStr;
- if( rLocale.Country.getLength() )
- {
- ( aLocaleStr += aDash ) += rLocale.Country;
- aSubDir[nSubDirs++] = aLocaleStr;
-
- if( rLocale.Variant.getLength() )
- {
- ( aLocaleStr += aDash ) += rLocale.Variant;
- aSubDir[nSubDirs++] = aLocaleStr;
- }
- }
-
- for( --nSubDirs; nSubDirs >= 0; nSubDirs-- )
- {
- // check all locale variants, starting with the most detailed one
- if( aSubDir[nSubDirs].getLength() )
- {
- const sal_Int32 nPos = rName.lastIndexOf( '/' );
-
- if( -1 != nPos )
- {
- ::rtl::OUString aLocaleName( rName.copy( 0, nPos + 1 ) );
-
- aLocaleName += aSubDir[nSubDirs];
- aLocaleName += ::rtl::OUString::createFromAscii( "/" );
- aLocaleName += rName.copy( nPos + 1 );
-
- try
- {
- uno::Reference< io::XInputStream > xIStm( maZipAcc.GetByName( aLocaleName ) );
-
- if( xIStm.is() )
- {
- ::std::auto_ptr< SvStream > apRet( implGetStream( xIStm ) );
-
- if( apRet.get() )
- implLoadFromStream( *apRet, aLocaleName, rReturn );
- }
- }
- catch( const uno::Exception & )
- {
- }
- }
- }
- }
- }
-
- if( rReturn.IsEmpty() )
- {
- try
- {
- uno::Reference< io::XInputStream > xIStm( maZipAcc.GetByName( rName ) );
-
- if( xIStm.is() )
- {
- ::std::auto_ptr< SvStream > apRet( implGetStream( xIStm ) );
-
- if( apRet.get() )
- implLoadFromStream( *apRet, rName, rReturn );
- }
- }
- catch( const uno::Exception & )
- {
- }
- }
-
- if( rReturn.IsEmpty() )
- {
- ::std::auto_ptr< SvStream > apIStm( ::utl::UcbStreamHelper::CreateStream( implGetUserFileURL( rName ), STREAM_READ ));
-
- if( apIStm.get() )
- *apIStm >> rReturn;
+ for (Zips::iterator i(m_zips.begin()); i != m_zips.end();) {
+ if (!i->second.is()) {
+ css::uno::Sequence< css::uno::Any > args(1);
+ args[0] <<= i->first;
+ try {
+ i->second.set(
+ comphelper::createProcessComponentWithArguments(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.packages.zip.ZipFileAccess")),
+ args),
+ css::uno::UNO_QUERY_THROW);
+ } catch (css::uno::RuntimeException &) {
+ throw;
+ } catch (css::uno::Exception & e) {
+ OSL_TRACE(
+ "ImplImageTree::find exception \"%s\"",
+ rtl::OUStringToOString(
+ e.Message, RTL_TEXTENCODING_UTF8).getStr());
+ i = m_zips.erase(i);
+ continue;
}
}
- else
+ for (std::vector< rtl::OUString >::const_reverse_iterator j(
+ paths.rbegin());
+ j != paths.rend(); ++j)
{
- // HACK for old setup!!! search in filesystem relative to application root
- ::rtl::OUString aAppDir( Application::GetAppFileName() );
- sal_Int32 nPos = aAppDir.lastIndexOf( '/' );
-
- if( -1 == nPos )
- nPos = aAppDir.lastIndexOf( '\\' );
-
- if( -1 != nPos )
- {
- String aURLStr;
-
- aAppDir = aAppDir.copy( 0, nPos );
-
- if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aAppDir, aURLStr ) )
- {
- INetURLObject aURL( aURLStr );
- sal_Int32 nIndex = 0;
-
- do
- {
- aURL.Append( rName.getToken( 0, '/', nIndex ) );
- }
- while( nIndex >= 0 );
-
- aURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE );
-
- ::std::auto_ptr< SvStream > apIStm( ::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_READ ) );
-
- if( apIStm.get() )
- {
- implLoadFromStream( *apIStm, aURLStr, rReturn );
- apIStm.reset();
- }
-
- if( rReturn.IsEmpty() )
- {
- // HACK for old setup!!! try to look in ../share/config
- nPos = aAppDir.lastIndexOf( '/' );
-
- if( -1 == nPos )
- nPos = aAppDir.lastIndexOf( '\\' );
-
- aAppDir = aAppDir.copy( 0, nPos );
-
- if( ( -1 != nPos ) && ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aAppDir, aURLStr ) )
- {
- aURL = INetURLObject( aURLStr );
- aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "share" ) ) );
- aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "config" ) ) );
- nIndex = 0;
-
- do
- {
- aURL.Append( rName.getToken( 0, '/', nIndex ) );
- }
- while( nIndex >= 0 );
-
- aURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE );
-
- apIStm.reset( ::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_READ ) );
-
- if( apIStm.get() )
- implLoadFromStream( *apIStm, aURLStr, rReturn );
- }
- }
- }
+ if (i->second->hasByName(*j)) {
+ css::uno::Reference< css::io::XInputStream > s;
+ bool ok = i->second->getByName(*j) >>= s;
+ OSL_ASSERT(ok); (void) ok;
+ loadFromStream(s, *j, bitmap);
+ return true;
}
}
+ ++i;
}
-
- if( !rReturn.IsEmpty() )
- aBmpExHashMap[ rName.intern() ] = rReturn;
-
- return( !rReturn.IsEmpty() );
-}
-
-// ------------------------------------------------------------------------------
-
-void ImplImageTree::addUserImage( const ::rtl::OUString& rName, const BitmapEx& rBmpEx )
-{
- const ::rtl::OUString aFileName( implGetUserFileURL( rName ) );
-
- if( aFileName.getLength() )
- {
- ::std::auto_ptr< SvStream > apOStm( ::utl::UcbStreamHelper::CreateStream( aFileName, STREAM_WRITE | STREAM_TRUNC ) );
-
- if( apOStm.get() )
- *apOStm << rBmpEx;
- }
+ return false;
}