merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / misc / imagemgr.cxx
blob56a9980cd8e9cfa9ef008169fcb137ecdf830238
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imagemgr.cxx,v $
10 * $Revision: 1.52 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 // includes --------------------------------------------------------------
36 #include "imagemgr.hxx"
37 #include <tools/urlobj.hxx>
38 #include <tools/debug.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/wrkwin.hxx>
41 #include "vcl/image.hxx"
42 #include <sot/storage.hxx>
43 #include <sot/clsids.hxx>
44 #include <unotools/ucbhelper.hxx>
45 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
46 #include <comphelper/processfactory.hxx>
47 #endif
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #include <com/sun/star/container/XNameContainer.hpp>
50 #include <com/sun/star/document/XTypeDetection.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
53 #include <ucbhelper/content.hxx>
54 #include <tools/rcid.h>
55 #include <rtl/logfile.hxx>
56 #include <unotools/configmgr.hxx>
58 #include <svtools/svtools.hrc>
59 #include "imagemgr.hrc"
60 #include <svtools/svtdata.hxx>
62 // globals *******************************************************************
64 #define NO_INDEX ((USHORT)0xFFFF)
65 #define CONTENT_HELPER ::utl::UCBContentHelper
66 #define ASCII_STRING(s) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
68 struct SvtExtensionResIdMapping_Impl
70 const char* _pExt;
71 BOOL _bExt;
72 USHORT _nStrId;
73 USHORT _nImgId;
76 static SvtExtensionResIdMapping_Impl __READONLY_DATA ExtensionMap_Impl[] =
78 { "awk", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
79 { "bas", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
80 { "bat", TRUE, STR_DESCRIPTION_BATCHFILE, IMG_APP },
81 { "bmk", FALSE, STR_DESCRIPTION_BOOKMARKFILE, 0 },
82 { "bmp", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_BITMAP },
83 { "c", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
84 { "cfg", FALSE, STR_DESCRIPTION_CFGFILE, 0 },
85 { "cmd", TRUE, STR_DESCRIPTION_BATCHFILE, IMG_APP },
86 { "cob", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
87 { "com", TRUE, STR_DESCRIPTION_APPLICATION, IMG_APP },
88 { "cxx", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
89 { "dbf", TRUE, STR_DESCRIPTION_DATABASE_TABLE, IMG_TABLE },
90 { "def", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
91 { "dll", TRUE, STR_DESCRIPTION_SYSFILE, 0 },
92 { "doc", FALSE, STR_DESCRIPTION_WORD_DOC, IMG_WORD },
93 { "dxf", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_DXF },
94 { "exe", TRUE, STR_DESCRIPTION_APPLICATION, IMG_APP },
95 { "gif", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_GIF },
96 { "h", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
97 { "hlp", FALSE, STR_DESCRIPTION_HELP_DOC, IMG_HELP },
98 { "hrc", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
99 { "htm", FALSE, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
100 { "html", FALSE, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
101 { "asp", FALSE, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
102 { "hxx", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
103 { "ini", FALSE, STR_DESCRIPTION_CFGFILE, 0 },
104 { "java", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
105 { "jpeg", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG },
106 { "jpg", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG },
107 { "lha", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
108 #ifdef WNT
109 { "lnk", FALSE, 0, 0 },
110 #endif
111 { "log", TRUE, STR_DESCRIPTION_LOGFILE, 0 },
112 { "lst", TRUE, STR_DESCRIPTION_LOGFILE, 0 },
113 { "met", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_MET },
114 { "mml", FALSE, STR_DESCRIPTION_MATHML_DOC, IMG_MATH },
115 { "mod", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
116 { "odb", FALSE, STR_DESCRIPTION_OO_DATABASE_DOC, IMG_OO_DATABASE_DOC },
117 { "odg", FALSE, STR_DESCRIPTION_OO_DRAW_DOC, IMG_OO_DRAW_DOC },
118 { "odf", FALSE, STR_DESCRIPTION_OO_MATH_DOC, IMG_OO_MATH_DOC },
119 { "odm", FALSE, STR_DESCRIPTION_OO_GLOBAL_DOC, IMG_OO_GLOBAL_DOC },
120 { "odp", FALSE, STR_DESCRIPTION_OO_IMPRESS_DOC, IMG_OO_IMPRESS_DOC },
121 { "ods", FALSE, STR_DESCRIPTION_OO_CALC_DOC, IMG_OO_CALC_DOC },
122 { "odt", FALSE, STR_DESCRIPTION_OO_WRITER_DOC, IMG_OO_WRITER_DOC },
123 { "otg", FALSE, STR_DESCRIPTION_OO_DRAW_TEMPLATE, IMG_OO_DRAW_TEMPLATE },
124 { "otp", FALSE, STR_DESCRIPTION_OO_IMPRESS_TEMPLATE, IMG_OO_IMPRESS_TEMPLATE },
125 { "ots", FALSE, STR_DESCRIPTION_OO_CALC_TEMPLATE, IMG_OO_CALC_TEMPLATE },
126 { "ott", FALSE, STR_DESCRIPTION_OO_WRITER_TEMPLATE, IMG_OO_WRITER_TEMPLATE },
127 { "pas", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
128 { "pcd", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCD },
129 { "pct", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT },
130 { "pcx", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCX },
131 { "pl", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
132 { "png", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PNG },
133 { "rar", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
134 { "sbl", FALSE, 0, IMG_MACROLIB },
135 { "sch", FALSE, 0, 0 },
136 { "sda", FALSE, STR_DESCRIPTION_SDRAW_DOC, IMG_DRAW },
137 { "sdb", FALSE, STR_DESCRIPTION_SDATABASE_DOC, IMG_DATABASE },
138 { "sdc", FALSE, STR_DESCRIPTION_SCALC_DOC, IMG_CALC },
139 { "sdd", FALSE, STR_DESCRIPTION_SIMPRESS_DOC, IMG_IMPRESS },
140 { "sdp", FALSE, STR_DESCRIPTION_SIMPRESS_DOC, IMG_IMPRESSPACKED },
141 { "sds", FALSE, STR_DESCRIPTION_SCHART_DOC, IMG_CHART },
142 { "sdw", FALSE, STR_DESCRIPTION_SWRITER_DOC, IMG_WRITER },
143 { "sga", FALSE, 0, IMG_GALLERY },
144 { "sgf", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SGF },
145 { "sgl", FALSE, STR_DESCRIPTION_GLOBALDOC, IMG_GLOBAL_DOC },
146 { "sgv", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SGV },
147 { "shtml", FALSE, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
148 { "sim", FALSE, STR_DESCRIPTION_SIMAGE_DOC, IMG_SIM },
149 { "smf", FALSE, STR_DESCRIPTION_SMATH_DOC, IMG_MATH },
150 { "src", TRUE, STR_DESCRIPTION_SOURCEFILE, IMG_TEXTFILE },
151 { "svh", FALSE, STR_DESCRIPTION_HELP_DOC, IMG_SVHELP },
152 { "svm", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SVM },
153 { "stc", FALSE, STR_DESCRIPTION_CALC_TEMPLATE, IMG_CALCTEMPLATE },
154 { "std", FALSE, STR_DESCRIPTION_DRAW_TEMPLATE, IMG_DRAWTEMPLATE },
155 { "sti", FALSE, STR_DESCRIPTION_IMPRESS_TEMPLATE, IMG_IMPRESSTEMPLATE },
156 { "stw", FALSE, STR_DESCRIPTION_WRITER_TEMPLATE, IMG_WRITERTEMPLATE },
157 { "sxc", FALSE, STR_DESCRIPTION_SXCALC_DOC, IMG_CALC },
158 { "sxd", FALSE, STR_DESCRIPTION_SXDRAW_DOC, IMG_DRAW },
159 { "sxg", FALSE, STR_DESCRIPTION_SXGLOBAL_DOC, IMG_GLOBAL_DOC },
160 { "sxi", FALSE, STR_DESCRIPTION_SXIMPRESS_DOC, IMG_IMPRESS },
161 { "sxm", FALSE, STR_DESCRIPTION_SXMATH_DOC, IMG_MATH },
162 { "sxs", FALSE, STR_DESCRIPTION_SXCHART_DOC, IMG_CHART },
163 { "sxw", FALSE, STR_DESCRIPTION_SXWRITER_DOC, IMG_WRITER },
164 { "sys", TRUE, STR_DESCRIPTION_SYSFILE, 0 },
165 { "tif", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF },
166 { "tiff", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF },
167 { "txt", FALSE, STR_DESCRIPTION_TEXTFILE, IMG_TEXTFILE },
168 { "url", FALSE, STR_DESCRIPTION_LINK, IMG_HTML },
169 { "vor", FALSE, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC, IMG_WRITERTEMPLATE },
170 { "vxd", TRUE, STR_DESCRIPTION_SYSFILE, 0 },
171 { "wmf", TRUE, STR_DESCRIPTION_GRAPHIC_DOC, IMG_WMF },
172 { "xls", FALSE, STR_DESCRIPTION_EXCEL_DOC, IMG_EXCEL },
173 { "xlt", FALSE, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC, IMG_EXCELTEMPLATE },
174 { "uu", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
175 { "uue", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
176 { "z", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
177 { "zip", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
178 { "zoo", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
179 { "gz", TRUE, STR_DESCRIPTION_ARCHIVFILE, 0 },
180 { "ppt", FALSE, STR_DESCRIPTION_POWERPOINT, IMG_POWERPOINT },
181 { "pot", FALSE, STR_DESCRIPTION_POWERPOINT_TEMPLATE, IMG_POWERPOINTTEMPLATE },
182 { "pps", FALSE, STR_DESCRIPTION_POWERPOINT_SHOW, IMG_POWERPOINT },
183 { "oxt", FALSE, STR_DESCRIPTION_EXTENSION, IMG_EXTENSION },
184 { 0, FALSE, 0, 0 }
187 #ifdef OS2
188 SvtExtensionResIdMapping_Impl Mappings[] =
190 {"StarWriter 4.0", FALSE,STR_DESCRIPTION_SWRITER_DOC, IMG_WRITER},
191 {"StarWriter 3.0", FALSE,STR_DESCRIPTION_SWRITER_DOC, IMG_WRITER},
192 {"StarCalc 4.0", FALSE,STR_DESCRIPTION_SCALC_DOC, IMG_CALC},
193 {"StarCalc 3.0", FALSE,STR_DESCRIPTION_SCALC_DOC, IMG_CALC},
194 {"StarImpress 4.0", FALSE,STR_DESCRIPTION_SIMPRESS_DOC,IMG_IMPRESS},
195 {"StarDraw 4.0", FALSE,STR_DESCRIPTION_SDRAW_DOC, IMG_DRAW},
196 {"StarDraw 3.0", FALSE,STR_DESCRIPTION_SDRAW_DOC, IMG_DRAW},
197 {"StarChart 3.0", FALSE,STR_DESCRIPTION_SCHART_DOC, IMG_CHART},
198 {"StarChart 4.0", FALSE,STR_DESCRIPTION_SCHART_DOC, IMG_CHART},
199 {"Bitmap", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_BITMAP},
200 {"AutoCAD", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM},
201 {"Gif-File", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_GIF},
202 {"JPEG-File", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG},
203 {"Metafile ", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM},
204 {"Photo-CD ", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCD},
205 {"Mac Pict", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT},
206 {"PCX-File ", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCX},
207 {"PNG-File", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM},
208 {"SV-Metafile", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM},
209 {"TIFF-File", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF},
210 {"MS-Metafile", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_WMF},
211 {"XBM-File", FALSE,STR_DESCRIPTION_GRAPHIC_DOC, IMG_BITMAP},
212 {"UniformResourceLocator", FALSE,STR_DESCRIPTION_LINK, IMG_URL},
213 {NULL, 0}
215 #endif
217 struct SvtFactory2ExtensionMapping_Impl
219 const char* _pFactory;
220 const char* _pExtension;
223 // mapping from "private:factory" url to extension
225 static SvtFactory2ExtensionMapping_Impl __READONLY_DATA Fac2ExtMap_Impl[] =
227 { "swriter", "odt" },
228 { "swriter/web", "html" },
229 { "swriter/GlobalDocument", "odm" },
230 { "scalc", "ods" },
231 { "simpress", "odp" },
232 { "sdraw", "odg" },
233 { "smath", "odf" },
234 { "sdatabase", "odb" },
235 { NULL, NULL }
238 //****************************************************************************
240 static String GetImageExtensionByFactory_Impl( const String& rURL )
242 INetURLObject aObj( rURL );
243 String aPath = aObj.GetURLPath( INetURLObject::NO_DECODE );
244 String aExtension;
246 if ( aPath.Len() )
248 USHORT nIndex = 0;
249 while ( Fac2ExtMap_Impl[ nIndex ]._pFactory )
251 if ( aPath.EqualsAscii( Fac2ExtMap_Impl[ nIndex ]._pFactory ) )
253 // extension found
254 aExtension = String::CreateFromAscii( Fac2ExtMap_Impl[ nIndex ]._pExtension );
255 // and return it
256 return aExtension;
258 ++nIndex;
262 // no extension found, so use the type detection (performance brake)
266 // get the TypeDetection service to access all registered types
267 ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory > xFac = ::comphelper::getProcessServiceFactory();
268 ::com::sun::star::uno::Reference < ::com::sun::star::document::XTypeDetection > xTypeDetector(
269 xFac->createInstance( ASCII_STRING("com.sun.star.document.TypeDetection") ), ::com::sun::star::uno::UNO_QUERY );
271 ::rtl::OUString aInternalType = xTypeDetector->queryTypeByURL( rURL );
272 ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > xAccess( xTypeDetector, ::com::sun::star::uno::UNO_QUERY );
273 ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aTypeProps;
274 if ( aInternalType.getLength() > 0 && xAccess->hasByName( aInternalType ) )
276 xAccess->getByName( aInternalType ) >>= aTypeProps;
277 sal_Int32 nProps = aTypeProps.getLength();
278 for ( sal_Int32 i = 0; i < nProps; ++i )
280 const ::com::sun::star::beans::PropertyValue& rProp = aTypeProps[i];
281 if ( rProp.Name.compareToAscii("Extensions") == COMPARE_EQUAL )
283 ::com::sun::star::uno::Sequence < ::rtl::OUString > aExtensions;
284 if ( ( rProp.Value >>= aExtensions ) && aExtensions.getLength() > 0 )
286 const ::rtl::OUString* pExtensions = aExtensions.getConstArray();
287 aExtension = String( pExtensions[0] );
288 break;
294 catch( const ::com::sun::star::uno::RuntimeException& )
296 throw; // dont hide it!
298 catch( const ::com::sun::star::uno::Exception& )
300 // type detection failed -> no extension
303 return aExtension;
306 static USHORT GetIndexOfExtension_Impl( const String& rExtension )
308 USHORT nRet = NO_INDEX;
309 if ( rExtension.Len() )
311 USHORT nIndex = 0;
312 String aExt = rExtension;
313 aExt.ToLowerAscii();
314 while ( ExtensionMap_Impl[ nIndex ]._pExt )
316 if ( aExt.EqualsAscii( ExtensionMap_Impl[ nIndex ]._pExt ) )
318 nRet = nIndex;
319 break;
321 ++nIndex;
325 return nRet;
328 static USHORT GetImageId_Impl( const String& rExtension )
330 USHORT nImage = IMG_FILE;
331 if ( rExtension.Len() != NO_INDEX )
333 USHORT nIndex = GetIndexOfExtension_Impl( rExtension );
334 if ( nIndex != NO_INDEX )
336 nImage = ExtensionMap_Impl[ nIndex ]._nImgId;
337 if ( !nImage )
338 nImage = IMG_FILE;
342 return nImage;
345 static sal_Bool GetVolumeProperties_Impl( ::ucbhelper::Content& rContent, svtools::VolumeInfo& rVolumeInfo )
347 sal_Bool bRet = sal_False;
351 bRet = ( ( rContent.getPropertyValue( ASCII_STRING("IsVolume") ) >>= rVolumeInfo.m_bIsVolume ) &&
352 ( rContent.getPropertyValue( ASCII_STRING("IsRemote") ) >>= rVolumeInfo.m_bIsRemote ) &&
353 ( rContent.getPropertyValue( ASCII_STRING("IsRemoveable") ) >>= rVolumeInfo.m_bIsRemoveable ) &&
354 ( rContent.getPropertyValue( ASCII_STRING("IsFloppy") ) >>= rVolumeInfo.m_bIsFloppy ) &&
355 ( rContent.getPropertyValue( ASCII_STRING("IsCompactDisc") ) >>= rVolumeInfo.m_bIsCompactDisc ) );
357 catch( const ::com::sun::star::uno::RuntimeException& )
359 throw; // dont hide it!
361 catch( const ::com::sun::star::uno::Exception& )
363 // type detection failed -> no extension
366 return bRet;
369 static USHORT GetFolderImageId_Impl( const String& rURL )
371 USHORT nRet = IMG_FOLDER;
372 ::svtools::VolumeInfo aVolumeInfo;
375 ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
376 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
378 if ( aVolumeInfo.m_bIsRemote )
379 nRet = IMG_NETWORKDEV;
380 else if ( aVolumeInfo.m_bIsCompactDisc )
381 nRet = IMG_CDROMDEV;
382 else if ( aVolumeInfo.m_bIsRemoveable )
383 nRet = IMG_REMOVEABLEDEV;
384 else if ( aVolumeInfo.m_bIsVolume )
385 nRet = IMG_FIXEDDEV;
388 catch( const ::com::sun::star::uno::RuntimeException& )
390 throw; // dont hide it!
392 catch( const ::com::sun::star::uno::Exception& )
394 // ...
396 return nRet;
399 static USHORT GetImageId_Impl( const INetURLObject& rObject, sal_Bool bDetectFolder )
401 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog, "svtools", "hb93813", "SvFileInformationManager::GetImageId_Impl()" );
403 String aExt, sURL = rObject.GetMainURL( INetURLObject::NO_DECODE );
404 USHORT nImage = IMG_FILE;
406 if ( rObject.GetProtocol() == INET_PROT_PRIVATE )
408 String aURLPath = sURL.Copy( URL_PREFIX_PRIV_SOFFICE_LEN );
409 String aType = aURLPath.GetToken( 0, INET_PATH_TOKEN );
410 if ( aType == String( RTL_CONSTASCII_STRINGPARAM("factory") ) )
412 // detect an image id for our "private:factory" urls
413 aExt = GetImageExtensionByFactory_Impl( sURL );
414 if ( aExt.Len() > 0 )
415 nImage = GetImageId_Impl( aExt );
416 return nImage;
418 else if ( aType == String( RTL_CONSTASCII_STRINGPARAM("image") ) )
419 nImage = (USHORT)aURLPath.GetToken( 1, INET_PATH_TOKEN ).ToInt32();
421 else
423 aExt = rObject.getExtension();
424 if ( aExt.EqualsAscii( "vor" ) )
426 SotStorageRef aStorage = new SotStorage( sURL, STREAM_STD_READ );
427 USHORT nId = IMG_WRITERTEMPLATE;
428 if ( !aStorage->GetError() )
430 SvGlobalName aGlobalName = aStorage->GetClassName();
431 if ( aGlobalName == SvGlobalName(SO3_SC_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_30) )
432 nId = IMG_CALCTEMPLATE;
433 else if ( aGlobalName == SvGlobalName(SO3_SDRAW_CLASSID_50) )
434 nId = IMG_DRAWTEMPLATE;
435 else if ( aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_50) ||
436 aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_30) )
437 nId = IMG_IMPRESSTEMPLATE;
438 else if ( aGlobalName == SvGlobalName(SO3_SM_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_30) )
439 nId = IMG_MATHTEMPLATE;
442 return nId;
446 if ( nImage == IMG_FILE && sURL.Len() )
448 if ( bDetectFolder && CONTENT_HELPER::IsFolder( sURL ) )
449 nImage = GetFolderImageId_Impl( sURL );
450 else if ( aExt.Len() > 0 )
451 nImage = GetImageId_Impl( aExt );
453 return nImage;
456 static USHORT GetDescriptionId_Impl( const String& rExtension, sal_Bool& rbShowExt )
458 USHORT nId = 0;
460 if ( rExtension.Len() != NO_INDEX )
462 USHORT nIndex = GetIndexOfExtension_Impl( rExtension );
463 if ( nIndex != NO_INDEX )
465 nId = ExtensionMap_Impl[ nIndex ]._nStrId;
466 rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt;
470 return nId;
473 static String GetDescriptionByFactory_Impl( const String& rFactory )
475 USHORT nResId = 0;
476 if ( rFactory.EqualsIgnoreCaseAscii( "swriter", 0, 7 ) )
477 nResId = STR_DESCRIPTION_FACTORY_WRITER;
478 else if ( rFactory.EqualsIgnoreCaseAscii( "scalc", 0, 5 ) )
479 nResId = STR_DESCRIPTION_FACTORY_CALC;
480 else if ( rFactory.EqualsIgnoreCaseAscii( "simpress", 0, 8 ) )
481 nResId = STR_DESCRIPTION_FACTORY_IMPRESS;
482 else if ( rFactory.EqualsIgnoreCaseAscii( "sdraw", 0, 5 ) )
483 nResId = STR_DESCRIPTION_FACTORY_DRAW;
484 else if ( rFactory.EqualsIgnoreCaseAscii( "swriter/web", 0, 11 ) )
485 nResId = STR_DESCRIPTION_FACTORY_WRITERWEB;
486 else if ( rFactory.EqualsIgnoreCaseAscii( "swriter/globaldocument", 0, 22 ) )
487 nResId = STR_DESCRIPTION_FACTORY_GLOBALDOC;
488 else if ( rFactory.EqualsIgnoreCaseAscii( "smath", 0, 5 ) )
489 nResId = STR_DESCRIPTION_FACTORY_MATH;
490 else if ( rFactory.EqualsIgnoreCaseAscii( "sdatabase", 0, 9 ) )
491 nResId = STR_DESCRIPTION_FACTORY_DATABASE;
493 String aRet;
494 if ( nResId )
496 ::vos::OGuard aGuard( Application::GetSolarMutex() );
497 aRet = String( SvtResId( nResId ) );
499 return aRet;
502 static USHORT GetFolderDescriptionId_Impl( const String& rURL )
504 USHORT nRet = STR_DESCRIPTION_FOLDER;
505 svtools::VolumeInfo aVolumeInfo;
508 ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
509 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
511 if ( aVolumeInfo.m_bIsRemote )
512 nRet = STR_DESCRIPTION_REMOTE_VOLUME;
513 else if ( aVolumeInfo.m_bIsFloppy )
514 nRet = STR_DESCRIPTION_FLOPPY_VOLUME;
515 else if ( aVolumeInfo.m_bIsCompactDisc )
516 nRet = STR_DESCRIPTION_CDROM_VOLUME;
517 else if ( aVolumeInfo.m_bIsRemoveable || aVolumeInfo.m_bIsVolume )
518 nRet = STR_DESCRIPTION_LOCALE_VOLUME;
521 catch( const ::com::sun::star::uno::RuntimeException& )
523 throw; // dont hide it!
525 catch( const ::com::sun::star::uno::Exception& )
527 // ...
529 return nRet;
532 static ResMgr* GetIsoResMgr_Impl()
534 static ResMgr* pIsoResMgr = NULL;
536 if ( !pIsoResMgr )
538 ByteString aResMgrName( "iso" );
539 pIsoResMgr = ResMgr::CreateResMgr(
540 aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
541 if ( !pIsoResMgr )
543 // no "iso" resource -> search for "ooo" resource
544 aResMgrName = ByteString( "ooo" );
545 pIsoResMgr = ResMgr::CreateResMgr(
546 aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
550 return pIsoResMgr;
553 static ImageList* CreateImageList_Impl( USHORT nResId )
555 ImageList* pList = NULL;
556 ResMgr* pResMgr = GetIsoResMgr_Impl();
557 DBG_ASSERT( pResMgr, "SvFileInformationManager::CreateImageList_Impl(): no resmgr" );
558 ResId aResId( nResId, *pResMgr );
559 aResId.SetRT( RSC_IMAGELIST );
560 if ( pResMgr->IsAvailable( aResId ) )
561 pList = new ImageList( aResId );
562 else
563 pList = new ImageList();
564 return pList;
567 static Image GetOfficeImageFromList_Impl( USHORT nImageId, BOOL bBig, BOOL bHighContrast )
569 ImageList* pList = NULL;
571 static ImageList* _pSmallOfficeImgList = NULL;
572 static ImageList* _pBigOfficeImgList = NULL;
573 static ImageList* _pSmallHCOfficeImgList = NULL;
574 static ImageList* _pBigHCOfficeImgList = NULL;
575 static ULONG nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
577 // If the style has been changed, throw away our cache of the older images
578 if ( nStyle != Application::GetSettings().GetStyleSettings().GetSymbolsStyle() )
580 delete _pSmallOfficeImgList, _pSmallOfficeImgList = NULL;
581 delete _pBigOfficeImgList, _pBigOfficeImgList = NULL;
582 delete _pSmallHCOfficeImgList, _pSmallHCOfficeImgList = NULL;
583 delete _pBigHCOfficeImgList, _pBigHCOfficeImgList = NULL;
584 nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
587 // #i21242# MT: For B&W we need the HC Image and must transform.
588 // bHiContrast is TRUE for all dark backgrounds, but we need HC Images for HC White also,
589 // so we can't rely on bHighContrast.
590 BOOL bBlackAndWhite = Application::GetSettings().GetStyleSettings().IsHighContrastBlackAndWhite();
591 if ( bBlackAndWhite )
592 bHighContrast = TRUE;
595 if ( bBig )
597 if ( bHighContrast )
599 if ( !_pBigHCOfficeImgList )
600 _pBigHCOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_BIG_HIGHCONTRAST );
601 pList = _pBigHCOfficeImgList;
603 else
605 if ( !_pBigOfficeImgList )
606 _pBigOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_BIG );
607 pList = _pBigOfficeImgList;
610 else
612 if ( bHighContrast )
614 if ( !_pSmallHCOfficeImgList )
615 _pSmallHCOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_SMALL_HIGHCONTRAST );
616 pList = _pSmallHCOfficeImgList;
618 else
620 if ( !_pSmallOfficeImgList )
621 _pSmallOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_SMALL );
622 pList = _pSmallOfficeImgList;
626 Image aImage = pList->GetImage( nImageId );
628 if ( bBlackAndWhite )
630 // First invert the Image, because it's designed for black background, structures are bright
631 aImage.Invert();
632 // Now make monochrome...
633 ImageColorTransform eTrans = IMAGECOLORTRANSFORM_MONOCHROME_WHITE;
634 if ( Application::GetSettings().GetStyleSettings().GetFaceColor().GetColor() == COL_WHITE )
635 eTrans = IMAGECOLORTRANSFORM_MONOCHROME_BLACK;
636 aImage = aImage.GetColorTransformedImage( eTrans );
639 return aImage;
642 static Image GetImageFromList_Impl( USHORT nImageId, BOOL bBig, BOOL bHighContrast )
644 if ( !bBig && IMG_FOLDER == nImageId && !bHighContrast )
645 // return our new small folder image (256 colors)
646 return Image( SvtResId( IMG_SVT_FOLDER ) );
648 ImageList* pList = NULL;
650 static ImageList* _pSmallImageList = NULL;
651 static ImageList* _pBigImageList = NULL;
652 static ImageList* _pSmallHCImageList = NULL;
653 static ImageList* _pBigHCImageList = NULL;
654 static ULONG nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
656 // If the style has been changed, throw away our cache of the older images
657 if ( nStyle != Application::GetSettings().GetStyleSettings().GetSymbolsStyle() )
659 delete _pSmallImageList, _pSmallImageList = NULL;
660 delete _pBigImageList, _pBigImageList = NULL;
661 delete _pSmallHCImageList, _pSmallHCImageList = NULL;
662 delete _pBigHCImageList, _pBigHCImageList = NULL;
663 nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
666 if ( bBig )
668 if ( bHighContrast )
670 if ( !_pBigHCImageList )
671 _pBigHCImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_BIG_HIGHCONTRAST ) );
672 pList = _pBigHCImageList;
674 else
676 if ( !_pBigImageList )
677 _pBigImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_BIG ) );
678 pList = _pBigImageList;
681 else
683 if ( bHighContrast )
685 if ( !_pSmallHCImageList )
686 _pSmallHCImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_SMALL_HIGHCONTRAST ) );
687 pList = _pSmallHCImageList;
689 else
691 if ( !_pSmallImageList )
692 _pSmallImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_SMALL ) );
693 pList = _pSmallImageList;
697 if ( pList->HasImageAtPos( nImageId ) )
698 return pList->GetImage( nImageId );
699 else
700 return GetOfficeImageFromList_Impl( nImageId, bBig, bHighContrast );
703 //****************************************************************************
705 void ReplaceStarOfficeVar( String& _rDescription )
707 static String sVariable( RTL_CONSTASCII_STRINGPARAM( "%STAROFFICE" ) );
708 static String sProductName;
709 if ( sProductName.Len() == 0 )
711 ::rtl::OUString sTemp;
712 ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ) >>= sTemp;
713 if ( sTemp.equalsAscii( "StarSuite" ) == sal_False )
714 sProductName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarOffice" ) );
715 else
716 sProductName = String( sTemp );
718 _rDescription.SearchAndReplace( sVariable, sProductName );
721 String SvFileInformationManager::GetDescription_Impl( const INetURLObject& rObject, sal_Bool bDetectFolder )
723 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog, "svtools", "hb93813", "SvFileInformationManager::GetDescription_Impl()" );
725 String sDescription;
726 String sExtension( rObject.getExtension() ), sURL( rObject.GetMainURL( INetURLObject::NO_DECODE ) );
727 USHORT nResId = 0;
728 sal_Bool bShowExt = sal_False, bDetected = sal_False, bOnlyFile = sal_False;
729 sal_Bool bFolder = bDetectFolder ? CONTENT_HELPER::IsFolder( sURL ) : sal_False;
730 if ( !bFolder )
732 if ( !bDetected )
734 if ( rObject.GetProtocol() == INET_PROT_PRIVATE )
736 String aURLPath = sURL.Copy( URL_PREFIX_PRIV_SOFFICE_LEN );
737 String aType = aURLPath.GetToken( 0, INET_PATH_TOKEN );
738 if ( aType == String( RTL_CONSTASCII_STRINGPARAM("factory") ) )
740 sDescription = GetDescriptionByFactory_Impl( aURLPath.Copy( aURLPath.Search( INET_PATH_TOKEN ) + 1 ) );
741 bDetected = sal_True;
745 if ( !bDetected )
747 // search a description by extension
748 sal_Bool bExt = ( sExtension.Len() > 0 );
749 if ( bExt )
751 sExtension.ToLowerAscii();
752 nResId = GetDescriptionId_Impl( sExtension, bShowExt );
754 if ( !nResId )
756 nResId = STR_DESCRIPTION_FILE;
757 bOnlyFile = bExt;
762 else
763 nResId = GetFolderDescriptionId_Impl( sURL );
765 if ( nResId > 0 )
767 if ( bOnlyFile )
769 bShowExt = sal_False;
770 sExtension.ToUpperAscii();
771 sDescription = sExtension;
772 sDescription += '-';
774 ::vos::OGuard aGuard( Application::GetSolarMutex() );
775 sDescription += String( SvtResId( nResId ) );
778 DBG_ASSERT( sDescription.Len() > 0, "file without description" );
780 if ( bShowExt )
782 sDescription += String( RTL_CONSTASCII_STRINGPARAM(" (") );
783 sDescription += sExtension;
784 sDescription += ')';
787 ReplaceStarOfficeVar( sDescription );
788 return sDescription;
791 Image SvFileInformationManager::GetImage( const INetURLObject& rObject, sal_Bool bBig )
793 return GetImage( rObject, bBig, FALSE );
796 Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject, sal_Bool bBig )
798 return GetFileImage( rObject, bBig, FALSE );
801 Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, sal_Bool bBig )
803 return GetImageNoDefault( rObject, bBig, FALSE );
806 Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo, sal_Bool bBig )
808 return GetFolderImage( rInfo, bBig, FALSE );
811 Image SvFileInformationManager::GetImage( const INetURLObject& rObject, sal_Bool bBig, sal_Bool bHighContrast )
813 USHORT nImage = GetImageId_Impl( rObject, sal_True );
814 DBG_ASSERT( nImage, "invalid ImageId" );
815 return GetImageFromList_Impl( nImage, bBig, bHighContrast );
818 Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject, sal_Bool bBig, sal_Bool bHighContrast )
820 USHORT nImage = GetImageId_Impl( rObject, sal_False );
821 DBG_ASSERT( nImage, "invalid ImageId" );
822 return GetImageFromList_Impl( nImage, bBig, bHighContrast );
825 Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, sal_Bool bBig, sal_Bool bHighContrast )
827 USHORT nImage = GetImageId_Impl( rObject, sal_True );
828 DBG_ASSERT( nImage, "invalid ImageId" );
830 if ( nImage == IMG_FILE )
831 return Image();
833 return GetImageFromList_Impl( nImage, bBig, bHighContrast );
836 Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo, sal_Bool bBig, sal_Bool bHighContrast )
838 USHORT nImage = IMG_FOLDER;
839 DBG_ASSERT( nImage, "invalid ImageId" );
841 if ( rInfo.m_bIsRemote )
842 nImage = IMG_NETWORKDEV;
843 else if ( rInfo.m_bIsCompactDisc )
844 nImage = IMG_CDROMDEV;
845 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsFloppy )
846 nImage = IMG_REMOVEABLEDEV;
847 else if ( rInfo.m_bIsVolume )
848 nImage = IMG_FIXEDDEV;
850 return GetImageFromList_Impl( nImage, bBig, bHighContrast );
853 String SvFileInformationManager::GetDescription( const INetURLObject& rObject )
855 return SvFileInformationManager::GetDescription_Impl( rObject, sal_True );
858 String SvFileInformationManager::GetFileDescription( const INetURLObject& rObject )
860 return SvFileInformationManager::GetDescription_Impl( rObject, sal_False );
863 String SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo& rInfo )
865 USHORT nResId = STR_DESCRIPTION_FOLDER;
866 if ( rInfo.m_bIsRemote )
867 nResId = STR_DESCRIPTION_REMOTE_VOLUME;
868 else if ( rInfo.m_bIsFloppy )
869 nResId = STR_DESCRIPTION_FLOPPY_VOLUME;
870 else if ( rInfo.m_bIsCompactDisc )
871 nResId = STR_DESCRIPTION_CDROM_VOLUME;
872 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsVolume )
873 nResId = STR_DESCRIPTION_LOCALE_VOLUME;
875 String sDescription = String( SvtResId( nResId ) );
876 return sDescription;