1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_svx.hxx"
32 #define ENABLE_BYTESTRING_STREAM_OPERATORS
34 #include <tools/vcompat.hxx>
35 #include <ucbhelper/content.hxx>
36 #include <unotools/ucbstreamhelper.hxx>
37 #include <unotools/pathoptions.hxx>
38 #include <sfx2/docfile.hxx>
39 #include "svx/gallery.hxx"
40 #include "gallery.hrc"
41 #include "svx/galmisc.hxx"
42 #include "svx/galtheme.hxx"
43 #include "svx/gallery1.hxx"
44 #include <com/sun/star/sdbc/XResultSet.hpp>
45 #include <com/sun/star/ucb/XContentAccess.hpp>
47 #define ENABLE_BYTESTRING_STREAM_OPERATORS
53 using namespace ::rtl
;
54 using namespace ::com::sun::star
;
56 // ---------------------
57 // - GalleryThemeEntry -
58 // ---------------------
60 GalleryThemeEntry::GalleryThemeEntry( const INetURLObject
& rBaseURL
, const String
& rName
,
61 sal_uInt32 _nFileNumber
, sal_Bool _bReadOnly
, sal_Bool _bImported
,
62 sal_Bool _bNewFile
, sal_uInt32 _nId
, sal_Bool _bThemeNameFromResource
) :
63 nFileNumber ( _nFileNumber
),
65 bReadOnly ( _bReadOnly
|| _bImported
),
66 bImported ( _bImported
),
67 bThemeNameFromResource ( _bThemeNameFromResource
)
69 INetURLObject
aURL( rBaseURL
);
70 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
71 String
aFileName( String( RTL_CONSTASCII_USTRINGPARAM( "sg" ) ) );
73 aURL
.Append( ( aFileName
+= String::CreateFromInt32( nFileNumber
) ) += String( RTL_CONSTASCII_USTRINGPARAM( ".thm" ) ) );
74 aThmURL
= ImplGetURLIgnoreCase( aURL
);
76 aURL
.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "sdg" ) ) );
77 aSdgURL
= ImplGetURLIgnoreCase( aURL
);
79 aURL
.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "sdv" ) ) );
80 aSdvURL
= ImplGetURLIgnoreCase( aURL
);
82 SetModified( _bNewFile
);
84 if( nId
&& bThemeNameFromResource
)
85 aName
= String( GAL_RESID( RID_GALLERYSTR_THEME_START
+ (sal_uInt16
) nId
) );
91 // -----------------------------------------------------------------------------
93 INetURLObject
GalleryThemeEntry::ImplGetURLIgnoreCase( const INetURLObject
& rURL
) const
95 INetURLObject
aURL( rURL
);
98 // check original file name
99 if( !FileExists( aURL
) )
101 // check upper case file name
102 aURL
.setName( aURL
.getName().toAsciiUpperCase() );
104 if(!FileExists( aURL
) )
106 // check lower case file name
107 aURL
.setName( aURL
.getName().toAsciiLowerCase() );
114 // -----------------------------------------------------------------------------
116 void GalleryThemeEntry::SetName( const String
& rNewName
)
118 if( aName
!= rNewName
)
121 SetModified( sal_True
);
122 bThemeNameFromResource
= sal_False
;
126 // -----------------------------------------------------------------------------
128 void GalleryThemeEntry::SetId( sal_uInt32 nNewId
, sal_Bool bResetThemeName
)
131 SetModified( sal_True
);
132 bThemeNameFromResource
= ( nId
&& bResetThemeName
);
135 // ---------------------------
136 // - GalleryImportThemeEntry -
137 // ---------------------------
139 SvStream
& operator<<( SvStream
& rOut
, const GalleryImportThemeEntry
& rEntry
)
143 rOut
<< ByteString( rEntry
.aThemeName
, RTL_TEXTENCODING_UTF8
) <<
144 ByteString( rEntry
.aUIName
, RTL_TEXTENCODING_UTF8
) <<
145 ByteString( String(rEntry
.aURL
.GetMainURL( INetURLObject::NO_DECODE
)), RTL_TEXTENCODING_UTF8
) <<
146 ByteString( rEntry
.aImportName
, RTL_TEXTENCODING_UTF8
) <<
152 // ------------------------------------------------------------------------
154 SvStream
& operator>>( SvStream
& rIn
, GalleryImportThemeEntry
& rEntry
)
158 rIn
>> aTmpStr
; rEntry
.aThemeName
= String( aTmpStr
, RTL_TEXTENCODING_UTF8
);
159 rIn
>> aTmpStr
; rEntry
.aUIName
= String( aTmpStr
, RTL_TEXTENCODING_UTF8
);
160 rIn
>> aTmpStr
; rEntry
.aURL
= INetURLObject( String( aTmpStr
, RTL_TEXTENCODING_UTF8
) );
161 rIn
>> aTmpStr
; rEntry
.aImportName
= String( aTmpStr
, RTL_TEXTENCODING_UTF8
);
167 // --------------------------
168 // - GalleryThemeCacheEntry -
169 // --------------------------
171 class GalleryThemeCacheEntry
175 const GalleryThemeEntry
* mpThemeEntry
;
176 GalleryTheme
* mpTheme
;
180 GalleryThemeCacheEntry( const GalleryThemeEntry
* pThemeEntry
, GalleryTheme
* pTheme
) :
181 mpThemeEntry( pThemeEntry
), mpTheme( pTheme
) {}
182 ~GalleryThemeCacheEntry() { delete mpTheme
; }
184 const GalleryThemeEntry
* GetThemeEntry() const { return mpThemeEntry
; }
185 GalleryTheme
* GetTheme() const { return mpTheme
; }
192 Gallery::Gallery( const String
& rMultiPath
)
193 : nReadTextEncoding ( gsl_getSystemTextEncoding() )
194 , nLastFileNumber ( 0 )
195 , bMultiPath ( sal_False
)
197 ImplLoad( rMultiPath
);
200 // ------------------------------------------------------------------------
204 // Themen-Liste loeschen
205 for ( size_t i
= 0, n
= aThemeList
.size(); i
< n
; ++i
)
206 delete aThemeList
[ i
];
209 // Import-Liste loeschen
210 for ( size_t i
= 0, n
= aImportList
.size(); i
< n
; ++i
)
211 delete aImportList
[ i
];
215 // ------------------------------------------------------------------------
217 Gallery
* Gallery::GetGalleryInstance()
219 static Gallery
* pGallery
= NULL
;
223 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
226 pGallery
= new Gallery( SvtPathOptions().GetGalleryPath() );
233 // ------------------------------------------------------------------------
235 void Gallery::ImplLoad( const String
& rMultiPath
)
237 const sal_uInt16 nTokenCount
= rMultiPath
.GetTokenCount( ';' );
238 sal_Bool bIsReadOnlyDir
;
240 bMultiPath
= ( nTokenCount
> 0 );
242 INetURLObject
aCurURL(SvtPathOptions().GetConfigPath());
243 ImplLoadSubDirs( aCurURL
, bIsReadOnlyDir
);
245 if( !bIsReadOnlyDir
)
250 aRelURL
= INetURLObject( rMultiPath
.GetToken( 0, ';' ) );
252 for( sal_uInt16 i
= 0UL; i
< nTokenCount
; i
++ )
254 aCurURL
= INetURLObject(rMultiPath
.GetToken( i
, ';' ));
256 ImplLoadSubDirs( aCurURL
, bIsReadOnlyDir
);
258 if( !bIsReadOnlyDir
)
263 aRelURL
= INetURLObject( rMultiPath
);
265 DBG_ASSERT( aUserURL
.GetProtocol() != INET_PROT_NOT_VALID
, "no writable Gallery user directory available" );
266 DBG_ASSERT( aRelURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
271 // ------------------------------------------------------------------------
273 void Gallery::ImplLoadSubDirs( const INetURLObject
& rBaseURL
, sal_Bool
& rbDirIsReadOnly
)
275 rbDirIsReadOnly
= sal_False
;
279 uno::Reference
< ucb::XCommandEnvironment
> xEnv
;
280 ::ucbhelper::Content
aCnt( rBaseURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
282 uno::Sequence
< OUString
> aProps( 1 );
283 aProps
.getArray()[ 0 ] = OUString(RTL_CONSTASCII_USTRINGPARAM("Url"));
285 uno::Reference
< sdbc::XResultSet
> xResultSet( aCnt
.createCursor( aProps
, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY
) );
289 // check readonlyness the very hard way
290 INetURLObject
aTestURL( rBaseURL
);
291 String
aTestFile( RTL_CONSTASCII_USTRINGPARAM( "cdefghij.klm" ) );
293 aTestURL
.Append( aTestFile
);
294 SvStream
* pTestStm
= ::utl::UcbStreamHelper::CreateStream( aTestURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_WRITE
);
300 if( pTestStm
->GetError() )
301 rbDirIsReadOnly
= sal_True
;
304 KillFile( aTestURL
);
307 rbDirIsReadOnly
= sal_True
;
309 catch( const ucb::ContentCreationException
& )
312 catch( const uno::RuntimeException
& )
315 catch( const uno::Exception
& )
319 if( xResultSet
.is() )
321 uno::Reference
< ucb::XContentAccess
> xContentAccess( xResultSet
, uno::UNO_QUERY
);
323 if( xContentAccess
.is() )
325 while( xResultSet
->next() )
327 INetURLObject
aThmURL( xContentAccess
->queryContentIdentifierString() );
329 if(aThmURL
.GetExtension().equalsIgnoreAsciiCaseAscii("thm"))
331 INetURLObject
aSdgURL( aThmURL
); aSdgURL
.SetExtension( OUString(RTL_CONSTASCII_USTRINGPARAM("sdg")) );
332 INetURLObject
aSdvURL( aThmURL
); aSdvURL
.SetExtension( OUString(RTL_CONSTASCII_USTRINGPARAM("sdv")) );
333 const OUString
aTitleProp( RTL_CONSTASCII_USTRINGPARAM("Title") );
334 const OUString
aReadOnlyProp( RTL_CONSTASCII_USTRINGPARAM("IsReadOnly") );
336 sal_Bool bReadOnly
= sal_False
;
340 ::ucbhelper::Content
aThmCnt( aThmURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
341 ::ucbhelper::Content
aSdgCnt( aSdgURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
342 ::ucbhelper::Content
aSdvCnt( aSdvURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
346 aThmCnt
.getPropertyValue( aTitleProp
) >>= aTitle
;
348 catch( const uno::RuntimeException
& )
351 catch( const uno::Exception
& )
355 if( aTitle
.getLength() )
359 aThmCnt
.getPropertyValue( aReadOnlyProp
) >>= bReadOnly
;
361 catch( const uno::RuntimeException
& )
364 catch( const uno::Exception
& )
372 aSdgCnt
.getPropertyValue( aTitleProp
) >>= aTitle
;
374 catch( const ::com::sun::star::uno::RuntimeException
& )
377 catch( const ::com::sun::star::uno::Exception
& )
381 if( aTitle
.getLength() )
385 aSdgCnt
.getPropertyValue( aReadOnlyProp
) >>= bReadOnly
;
387 catch( const uno::RuntimeException
& )
390 catch( const uno::Exception
& )
400 aSdvCnt
.getPropertyValue( aTitleProp
) >>= aTitle
;
402 catch( const ::com::sun::star::uno::RuntimeException
& )
405 catch( const ::com::sun::star::uno::Exception
& )
409 if( aTitle
.getLength() )
413 aSdvCnt
.getPropertyValue( aReadOnlyProp
) >>= bReadOnly
;
415 catch( const uno::RuntimeException
& )
418 catch( const uno::Exception
& )
424 GalleryThemeEntry
* pEntry
= GalleryTheme::CreateThemeEntry( aThmURL
, rbDirIsReadOnly
|| bReadOnly
);
428 const sal_uIntPtr nFileNumber
= (sal_uIntPtr
) String(aThmURL
.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32();
430 aThemeList
.push_back( pEntry
);
432 if( nFileNumber
> nLastFileNumber
)
433 nLastFileNumber
= nFileNumber
;
437 catch( const ucb::ContentCreationException
& )
440 catch( const uno::RuntimeException
& )
443 catch( const uno::Exception
& )
451 catch( const ucb::ContentCreationException
& )
454 catch( const uno::RuntimeException
& )
457 catch( const uno::Exception
& )
462 // ------------------------------------------------------------------------
464 void Gallery::ImplLoadImports()
466 INetURLObject
aURL( GetUserURL() );
468 aURL
.Append( String( RTL_CONSTASCII_USTRINGPARAM( "gallery.sdi" ) ) );
470 if( FileExists( aURL
) )
472 SvStream
* pIStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_READ
);
476 GalleryThemeEntry
* pThemeEntry
;
477 GalleryImportThemeEntry
* pImportEntry
;
479 sal_uInt32 nInventor
;
483 sal_uInt16 nTempCharSet
;
485 for ( size_t j
= 0, n
= aImportList
.size(); j
< n
; ++j
)
486 delete aImportList
[ j
];
491 if( nInventor
== COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
493 *pIStm
>> nId
>> nCount
>> nTempCharSet
;
495 for( i
= 0; i
< nCount
; i
++ )
497 pImportEntry
= new GalleryImportThemeEntry
;
499 *pIStm
>> *pImportEntry
;
500 aImportList
.push_back( pImportEntry
);
501 aFile
= INetURLObject( pImportEntry
->aURL
);
502 pThemeEntry
= new GalleryThemeEntry( aFile
,
503 pImportEntry
->aUIName
,
504 String(aFile
.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32(),
505 sal_True
, sal_True
, sal_False
, 0, sal_False
);
507 aThemeList
.push_back( pThemeEntry
);
516 // ------------------------------------------------------------------------
518 void Gallery::ImplWriteImportList()
520 INetURLObject
aURL( GetUserURL() );
521 aURL
.Append( ( String( "gallery.sdi", RTL_TEXTENCODING_UTF8
) ) );
522 SvStream
* pOStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_WRITE
| STREAM_TRUNC
);
526 const sal_uInt32 nInventor
= (sal_uInt32
) COMPAT_FORMAT( 'S', 'G', 'A', '3' );
527 const sal_uInt16 nId
= 0x0004;
529 *pOStm
<< nInventor
<< nId
<< (sal_uInt32
) aImportList
.size() << (sal_uInt16
) gsl_getSystemTextEncoding();
531 for ( size_t i
= 0, n
= aImportList
.size(); i
< n
; ++i
)
532 *pOStm
<< *aImportList
[ i
];
534 if( pOStm
->GetError() )
535 ErrorHandler::HandleError( ERRCODE_IO_GENERAL
);
541 // ------------------------------------------------------------------------
543 GalleryThemeEntry
* Gallery::ImplGetThemeEntry( const String
& rThemeName
)
545 GalleryThemeEntry
* pFound
= NULL
;
547 if( rThemeName
.Len() )
548 for ( size_t i
= 0, n
= aThemeList
.size(); i
< n
&& !pFound
; ++i
)
549 if( rThemeName
== aThemeList
[ i
]->GetThemeName() )
550 pFound
= aThemeList
[ i
];
555 // ------------------------------------------------------------------------
557 GalleryImportThemeEntry
* Gallery::ImplGetImportThemeEntry( const String
& rImportName
)
559 for ( size_t i
= 0, n
= aImportList
.size(); i
< n
; ++i
)
560 if ( rImportName
== aImportList
[ i
]->aUIName
)
561 return aImportList
[ i
];
565 // ------------------------------------------------------------------------
567 String
Gallery::GetThemeName( sal_uIntPtr nThemeId
) const
569 GalleryThemeEntry
* pFound
= NULL
;
571 for ( size_t i
= 0, n
= aThemeList
.size(); i
< n
&& !pFound
; ++i
)
573 GalleryThemeEntry
* pEntry
= aThemeList
[ i
];
574 if( nThemeId
== pEntry
->GetId() )
578 // try fallback, if no entry was found
581 ByteString aFallback
;
585 case( GALLERY_THEME_3D
): aFallback
= "3D"; break;
586 case( GALLERY_THEME_BULLETS
): aFallback
= "Bullets"; break;
587 case( GALLERY_THEME_HOMEPAGE
): aFallback
= "Homepage"; break;
588 case( GALLERY_THEME_HTMLBUTTONS
): aFallback
= "private://gallery/hidden/HtmlExportButtons"; break;
589 case( GALLERY_THEME_POWERPOINT
): aFallback
= "private://gallery/hidden/imgppt"; break;
590 case( GALLERY_THEME_FONTWORK
): aFallback
= "private://gallery/hidden/fontwork"; break;
591 case( GALLERY_THEME_FONTWORK_VERTICAL
): aFallback
= "private://gallery/hidden/fontworkvertical"; break;
592 case( GALLERY_THEME_RULERS
): aFallback
= "Rulers"; break;
593 case( GALLERY_THEME_SOUNDS
): aFallback
= "Sounds"; break;
599 pFound
= ( (Gallery
*) this )->ImplGetThemeEntry( String::CreateFromAscii( aFallback
.GetBuffer() ) );
602 return( pFound
? pFound
->GetThemeName() : String() );
605 // ------------------------------------------------------------------------
607 sal_Bool
Gallery::HasTheme( const String
& rThemeName
)
609 return( ImplGetThemeEntry( rThemeName
) != NULL
);
612 // ------------------------------------------------------------------------
614 sal_Bool
Gallery::CreateTheme( const String
& rThemeName
, sal_uInt32 nNumFrom
)
616 sal_Bool bRet
= sal_False
;
618 if( !HasTheme( rThemeName
) && ( GetUserURL().GetProtocol() != INET_PROT_NOT_VALID
) )
620 nLastFileNumber
= nNumFrom
> nLastFileNumber
? nNumFrom
: nLastFileNumber
+ 1;
621 GalleryThemeEntry
* pNewEntry
= new GalleryThemeEntry( GetUserURL(), rThemeName
,
623 sal_False
, sal_False
, sal_True
, 0, sal_False
);
625 aThemeList
.push_back( pNewEntry
);
626 delete( new GalleryTheme( this, pNewEntry
) );
627 Broadcast( GalleryHint( GALLERY_HINT_THEME_CREATED
, rThemeName
) );
634 // ------------------------------------------------------------------------
636 sal_Bool
Gallery::RenameTheme( const String
& rOldName
, const String
& rNewName
)
638 GalleryThemeEntry
* pThemeEntry
= ImplGetThemeEntry( rOldName
);
639 sal_Bool bRet
= sal_False
;
641 // Ueberpruefen, ob neuer Themenname schon vorhanden ist
642 if( pThemeEntry
&& !HasTheme( rNewName
) && ( !pThemeEntry
->IsReadOnly() || pThemeEntry
->IsImported() ) )
644 SfxListener aListener
;
645 GalleryTheme
* pThm
= AcquireTheme( rOldName
, aListener
);
649 const String
aOldName( rOldName
);
651 pThemeEntry
->SetName( rNewName
);
654 if( pThemeEntry
->IsImported() )
656 pThm
->SetImportName( rNewName
);
658 GalleryImportThemeEntry
* pImportEntry
= ImplGetImportThemeEntry( rOldName
);
662 pImportEntry
->aUIName
= rNewName
;
663 ImplWriteImportList();
667 Broadcast( GalleryHint( GALLERY_HINT_THEME_RENAMED
, aOldName
, pThm
->GetName() ) );
668 ReleaseTheme( pThm
, aListener
);
676 // ------------------------------------------------------------------------
678 sal_Bool
Gallery::RemoveTheme( const String
& rThemeName
)
680 GalleryThemeEntry
* pThemeEntry
= ImplGetThemeEntry( rThemeName
);
681 sal_Bool bRet
= sal_False
;
683 if( pThemeEntry
&& ( !pThemeEntry
->IsReadOnly() || pThemeEntry
->IsImported() ) )
685 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_THEME
, rThemeName
) );
687 if( pThemeEntry
->IsImported() )
689 GalleryImportThemeEntry
* pImportEntry
= ImplGetImportThemeEntry( rThemeName
);
693 for ( GalleryImportThemeList::iterator it
= aImportList
.begin(); it
< aImportList
.end(); ++it
)
695 if ( *it
== pImportEntry
)
698 aImportList
.erase( it
);
706 SfxListener aListener
;
707 GalleryTheme
* pThm
= AcquireTheme( rThemeName
, aListener
);
711 INetURLObject
aThmURL( pThm
->GetThmURL() );
712 INetURLObject
aSdgURL( pThm
->GetSdgURL() );
713 INetURLObject
aSdvURL( pThm
->GetSdvURL() );
715 ReleaseTheme( pThm
, aListener
);
723 for ( GalleryThemeList::iterator it
= aThemeList
.begin(); it
< aThemeList
.end(); ++it
)
725 if ( pThemeEntry
== *it
) {
727 aThemeList
.erase( it
);
732 Broadcast( GalleryHint( GALLERY_HINT_THEME_REMOVED
, rThemeName
) );
740 // ------------------------------------------------------------------------
742 INetURLObject
Gallery::GetImportURL( const String
& rThemeName
)
745 GalleryImportThemeEntry
* pImportEntry
= ImplGetImportThemeEntry( rThemeName
);
749 aURL
= pImportEntry
->aURL
;
750 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
756 // ------------------------------------------------------------------------
758 GalleryTheme
* Gallery::ImplGetCachedTheme( const GalleryThemeEntry
* pThemeEntry
)
760 GalleryTheme
* pTheme
= NULL
;
764 for (GalleryCacheThemeList::const_iterator it
= aThemeCache
.begin(); it
!= aThemeCache
.end(); ++it
)
766 if (pThemeEntry
== (*it
)->GetThemeEntry())
768 pTheme
= (*it
)->GetTheme();
777 if( !pThemeEntry
->IsImported() )
778 aURL
= pThemeEntry
->GetThmURL();
780 aURL
= GetImportURL( pThemeEntry
->GetThemeName() );
782 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
784 if( FileExists( aURL
) )
786 SvStream
* pIStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_READ
);
790 pTheme
= new GalleryTheme( this, (GalleryThemeEntry
*) pThemeEntry
);
793 if( pIStm
->GetError() )
794 delete pTheme
, pTheme
= NULL
;
795 else if( pThemeEntry
->IsImported() )
796 pTheme
->SetImportName( pThemeEntry
->GetThemeName() );
803 aThemeCache
.push_back( new GalleryThemeCacheEntry( pThemeEntry
, pTheme
));
810 // ------------------------------------------------------------------------
812 void Gallery::ImplDeleteCachedTheme( GalleryTheme
* pTheme
)
814 for (GalleryCacheThemeList::iterator it
= aThemeCache
.begin(); it
!= aThemeCache
.end(); ++it
)
816 if (pTheme
== (*it
)->GetTheme())
819 aThemeCache
.erase(it
);
825 // ------------------------------------------------------------------------
827 GalleryTheme
* Gallery::AcquireTheme( const String
& rThemeName
, SfxListener
& rListener
)
829 GalleryTheme
* pTheme
= NULL
;
830 GalleryThemeEntry
* pThemeEntry
= ImplGetThemeEntry( rThemeName
);
832 if( pThemeEntry
&& ( ( pTheme
= ImplGetCachedTheme( pThemeEntry
) ) != NULL
) )
833 rListener
.StartListening( *pTheme
);
838 // ------------------------------------------------------------------------
840 void Gallery::ReleaseTheme( GalleryTheme
* pTheme
, SfxListener
& rListener
)
844 rListener
.EndListening( *pTheme
);
846 if( !pTheme
->HasListeners() )
847 ImplDeleteCachedTheme( pTheme
);
851 sal_Bool
GalleryThemeEntry::IsDefault() const
852 { return( ( nId
> 0 ) && ( nId
!= ( RID_GALLERYSTR_THEME_MYTHEME
- RID_GALLERYSTR_THEME_START
) ) ); }
854 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */