update dev300-m58
[ooovba.git] / svx / source / gallery2 / galtheme.cxx
blobc76cdce57613186106f14a8b9a40e9cacaca6a90
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: galtheme.cxx,v $
10 * $Revision: 1.50 $
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_svx.hxx"
34 #define ENABLE_BYTESTRING_STREAM_OPERATORS
36 #include <tools/urlobj.hxx>
37 #include <tools/vcompat.hxx>
38 #include <unotools/streamwrap.hxx>
39 #include <unotools/ucbstreamhelper.hxx>
40 #include <unotools/tempfile.hxx>
41 #include <unotools/localfilehelper.hxx>
42 #include <ucbhelper/content.hxx>
43 #include <sot/storage.hxx>
44 #include <sot/formats.hxx>
45 #include <sot/filelist.hxx>
46 #include <vcl/virdev.hxx>
47 #include <vcl/cvtgrf.hxx>
48 #include <svtools/itempool.hxx>
49 #include <sfx2/docfile.hxx>
50 #include <avmedia/mediawindow.hxx>
51 #include <svx/svdograf.hxx>
52 #include <svx/fmpage.hxx>
53 #include "codec.hxx"
54 #include <svx/unomodel.hxx>
55 #include <svx/fmmodel.hxx>
56 #include <svx/fmview.hxx>
57 #include "galmisc.hxx"
58 #include "galtheme.hxx"
59 #include <com/sun/star/sdbc/XResultSet.hpp>
60 #include <com/sun/star/ucb/XContentAccess.hpp>
61 #include <com/sun/star/io/XInputStream.hpp>
63 #include "gallerydrawmodel.hxx"
65 // --------------
66 // - Namespaces -
67 // --------------
69 using namespace ::rtl;
70 using namespace ::com::sun::star;
72 // ------------
73 // - SgaTheme -
74 // ------------
76 GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry ) :
77 pParent ( pGallery ),
78 pThm ( pThemeEntry ),
79 mnThemeLockCount ( 0 ),
80 mnBroadcasterLockCount( 0 ),
81 nDragPos ( 0 ),
82 bDragging ( FALSE )
84 ImplCreateSvDrawStorage();
86 if( pThm->IsImported() )
87 aImportName = pThm->GetThemeName();
90 // ------------------------------------------------------------------------
92 GalleryTheme::~GalleryTheme()
94 ImplWrite();
96 for( GalleryObject* pEntry = aObjectList.First(); pEntry; pEntry = aObjectList.Next() )
98 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< ULONG >( pEntry ) ) );
99 delete pEntry;
100 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< ULONG >( pEntry ) ) );
104 // ------------------------------------------------------------------------
106 void GalleryTheme::ImplCreateSvDrawStorage()
108 if( !pThm->IsImported() )
110 aSvDrawStorageRef = new SvStorage( FALSE, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), pThm->IsReadOnly() ? STREAM_READ : STREAM_STD_READWRITE );
111 // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
112 if ( ( aSvDrawStorageRef->GetError() != ERRCODE_NONE ) && !pThm->IsReadOnly() )
113 aSvDrawStorageRef = new SvStorage( FALSE, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
115 else
116 aSvDrawStorageRef.Clear();
119 // ------------------------------------------------------------------------
121 BOOL GalleryTheme::ImplWriteSgaObject( const SgaObject& rObj, ULONG nPos, GalleryObject* pExistentEntry )
123 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
124 BOOL bRet = FALSE;
126 if( pOStm )
128 const sal_uInt32 nOffset = pOStm->Seek( STREAM_SEEK_TO_END );
130 rObj.WriteData( *pOStm, m_aDestDir );
132 if( !pOStm->GetError() )
134 GalleryObject* pEntry;
136 if( !pExistentEntry )
138 pEntry = new GalleryObject;
139 aObjectList.Insert( pEntry, nPos );
141 else
142 pEntry = pExistentEntry;
144 pEntry->aURL = rObj.GetURL();
145 pEntry->nOffset = nOffset;
146 pEntry->eObjKind = rObj.GetObjKind();
147 bRet = TRUE;
150 delete pOStm;
153 return bRet;
156 // ------------------------------------------------------------------------
158 SgaObject* GalleryTheme::ImplReadSgaObject( GalleryObject* pEntry )
160 SgaObject* pSgaObj = NULL;
162 if( pEntry )
164 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
166 if( pIStm )
168 sal_uInt32 nInventor;
170 // Ueberpruefen, ob das File ein gueltiges SGA-File ist
171 pIStm->Seek( pEntry->nOffset );
172 *pIStm >> nInventor;
174 if( nInventor == COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
176 pIStm->Seek( pEntry->nOffset );
178 switch( pEntry->eObjKind )
180 case( SGA_OBJ_BMP ): pSgaObj = new SgaObjectBmp(); break;
181 case( SGA_OBJ_ANIM ): pSgaObj = new SgaObjectAnim(); break;
182 case( SGA_OBJ_INET ): pSgaObj = new SgaObjectINet(); break;
183 case( SGA_OBJ_SVDRAW ): pSgaObj = new SgaObjectSvDraw(); break;
184 case( SGA_OBJ_SOUND ): pSgaObj = new SgaObjectSound(); break;
186 default:
187 break;
190 if( pSgaObj )
192 *pIStm >> *pSgaObj;
193 pSgaObj->ImplUpdateURL( pEntry->aURL );
197 delete pIStm;
201 return pSgaObj;
204 // ------------------------------------------------------------------------
206 void GalleryTheme::ImplRead()
208 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
210 if( pIStm )
212 *pIStm >> *this;
213 delete pIStm;
217 // ------------------------------------------------------------------------
219 void GalleryTheme::ImplWrite()
221 if( IsModified() )
223 INetURLObject aPathURL( GetThmURL() );
225 aPathURL.removeSegment();
226 aPathURL.removeFinalSlash();
228 DBG_ASSERT( aPathURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
230 if( FileExists( aPathURL ) || CreateDir( aPathURL ) )
232 #ifdef UNX
233 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_COPY_ON_SYMLINK | STREAM_TRUNC );
234 #else
235 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
236 #endif
238 if( pOStm )
240 *pOStm << *this;
241 delete pOStm;
244 ImplSetModified( FALSE );
249 // ------------------------------------------------------------------------
251 const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
253 GalleryObject* pEntry = aObjectList.First();
254 GalleryObject* pFoundEntry = NULL;
256 for( ; pEntry && !pFoundEntry; pEntry = aObjectList.Next() )
257 if( pEntry->aURL == rURL )
258 pFoundEntry = pEntry;
260 return pFoundEntry;
263 // ------------------------------------------------------------------------
265 INetURLObject GalleryTheme::ImplGetURL( const GalleryObject* pObject ) const
267 INetURLObject aURL;
269 if( pObject )
271 if( IsImported() )
273 INetURLObject aPathURL( GetParent()->GetImportURL( GetName() ) );
275 aPathURL.removeSegment();
276 aPathURL.removeFinalSlash();
277 aPathURL.Append( pObject->aURL.GetName() );
278 aURL = aPathURL;
280 else
281 aURL = pObject->aURL;
284 return aURL;
287 // ------------------------------------------------------------------------
289 INetURLObject GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind, ULONG nFormat )
291 INetURLObject aDir( GetParent()->GetUserURL() );
292 INetURLObject aInfoFileURL( GetParent()->GetUserURL() );
293 INetURLObject aNewURL;
294 sal_uInt32 nNextNumber = 1999;
295 sal_Char const* pExt = NULL;
296 BOOL bExists;
298 aDir.Append( String( RTL_CONSTASCII_USTRINGPARAM( "dragdrop" ) ) );
299 CreateDir( aDir );
301 aInfoFileURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "sdddndx1" ) ) );
303 // read next possible number
304 if( FileExists( aInfoFileURL ) )
306 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
308 if( pIStm )
310 *pIStm >> nNextNumber;
311 delete pIStm;
315 // create extension
316 if( nFormat )
318 switch( nFormat )
320 case( CVT_BMP ): pExt = ".bmp"; break;
321 case( CVT_GIF ): pExt = ".gif"; break;
322 case( CVT_JPG ): pExt = ".jpg"; break;
323 case( CVT_MET ): pExt = ".met"; break;
324 case( CVT_PCT ): pExt = ".pct"; break;
325 case( CVT_PNG ): pExt = ".png"; break;
326 case( CVT_SVM ): pExt = ".svm"; break;
327 case( CVT_TIF ): pExt = ".tif"; break;
328 case( CVT_WMF ): pExt = ".wmf"; break;
329 case( CVT_EMF ): pExt = ".emf"; break;
331 default:
332 pExt = ".grf";
333 break;
339 // get URL
340 if( SGA_OBJ_SVDRAW == eObjKind )
342 String aFileName( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/dd" ) );
343 aNewURL = INetURLObject( aFileName += String::CreateFromInt32( ++nNextNumber % 99999999 ), INET_PROT_PRIV_SOFFICE );
345 bExists = FALSE;
347 for( GalleryObject* pEntry = aObjectList.First(); pEntry && !bExists; pEntry = aObjectList.Next() )
348 if( pEntry->aURL == aNewURL )
349 bExists = TRUE;
351 else
353 String aFileName( RTL_CONSTASCII_USTRINGPARAM( "dd" ) );
355 aFileName += String::CreateFromInt32( ++nNextNumber % 999999 );
356 aFileName += String( pExt, RTL_TEXTENCODING_ASCII_US );
358 aNewURL = aDir;
359 aNewURL.Append( aFileName );
361 bExists = FileExists( aNewURL );
364 while( bExists );
366 // write updated number
367 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
369 if( pOStm )
371 *pOStm << nNextNumber;
372 delete pOStm;
375 return aNewURL;
378 // ------------------------------------------------------------------------
380 void GalleryTheme::ImplBroadcast( ULONG nUpdatePos )
382 if( !IsBroadcasterLocked() )
384 if( GetObjectCount() && ( nUpdatePos >= GetObjectCount() ) )
385 nUpdatePos = GetObjectCount() - 1;
387 Broadcast( GalleryHint( GALLERY_HINT_THEME_UPDATEVIEW, GetName(), nUpdatePos ) );
391 // ------------------------------------------------------------------------
393 BOOL GalleryTheme::UnlockTheme()
395 DBG_ASSERT( mnThemeLockCount, "Theme is not locked" );
397 BOOL bRet = FALSE;
399 if( mnThemeLockCount )
401 --mnThemeLockCount;
402 bRet = TRUE;
405 return bRet;
408 // ------------------------------------------------------------------------
410 void GalleryTheme::UnlockBroadcaster( ULONG nUpdatePos )
412 DBG_ASSERT( mnBroadcasterLockCount, "Broadcaster is not locked" );
414 if( mnBroadcasterLockCount && !--mnBroadcasterLockCount )
415 ImplBroadcast( nUpdatePos );
418 // ------------------------------------------------------------------------
420 BOOL GalleryTheme::InsertObject( const SgaObject& rObj, ULONG nInsertPos )
422 BOOL bRet = FALSE;
424 if( rObj.IsValid() )
426 GalleryObject* pEntry = aObjectList.First();
427 GalleryObject* pFoundEntry = NULL;
429 for( ; pEntry && !pFoundEntry; pEntry = aObjectList.Next() )
430 if( pEntry->aURL == rObj.GetURL() )
431 pFoundEntry = pEntry;
433 if( pFoundEntry )
435 GalleryObject aNewEntry;
437 // update title of new object if neccessary
438 if( !rObj.GetTitle().Len() )
440 SgaObject* pOldObj = ImplReadSgaObject( pFoundEntry );
442 if( pOldObj )
444 ( (SgaObject&) rObj ).SetTitle( pOldObj->GetTitle() );
445 delete pOldObj;
448 else if( rObj.GetTitle() == String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) ) )
449 ( (SgaObject&) rObj ).SetTitle( String() );
451 ImplWriteSgaObject( rObj, nInsertPos, &aNewEntry );
452 pFoundEntry->nOffset = aNewEntry.nOffset;
454 else
455 ImplWriteSgaObject( rObj, nInsertPos, NULL );
457 ImplSetModified( bRet = TRUE );
458 ImplBroadcast( pFoundEntry ? aObjectList.GetPos( pFoundEntry ) : nInsertPos );
461 return bRet;
464 // ------------------------------------------------------------------------
466 SgaObject* GalleryTheme::AcquireObject( ULONG nPos )
468 return ImplReadSgaObject( aObjectList.GetObject( nPos ) );
471 // ------------------------------------------------------------------------
473 void GalleryTheme::ReleaseObject( SgaObject* pObject )
475 delete pObject;
478 // ------------------------------------------------------------------------
480 BOOL GalleryTheme::RemoveObject( ULONG nPos )
482 GalleryObject* pEntry = aObjectList.Remove( nPos );
484 if( !aObjectList.Count() )
485 KillFile( GetSdgURL() );
487 if( pEntry )
489 if( SGA_OBJ_SVDRAW == pEntry->eObjKind )
490 aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
492 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< ULONG >( pEntry ) ) );
493 delete pEntry;
494 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< ULONG >( pEntry ) ) );
496 ImplSetModified( TRUE );
497 ImplBroadcast( nPos );
500 return( pEntry != NULL );
503 // ------------------------------------------------------------------------
505 BOOL GalleryTheme::ChangeObjectPos( ULONG nOldPos, ULONG nNewPos )
507 BOOL bRet = FALSE;
509 if( nOldPos != nNewPos )
511 GalleryObject* pEntry = aObjectList.GetObject( nOldPos );
513 if( pEntry )
515 aObjectList.Insert( pEntry, nNewPos );
517 if( nNewPos < nOldPos )
518 nOldPos++;
520 aObjectList.Remove( nOldPos );
521 ImplSetModified( bRet = TRUE );
522 ImplBroadcast( ( nNewPos < nOldPos ) ? nNewPos : ( nNewPos - 1 ) );
526 return bRet;
529 // ------------------------------------------------------------------------
531 void GalleryTheme::Actualize( const Link& rActualizeLink, GalleryProgress* pProgress )
533 if( !IsReadOnly() && !IsImported() )
535 Graphic aGraphic;
536 String aFormat;
537 GalleryObject* pEntry;
538 const ULONG nCount = aObjectList.Count();
539 ULONG i;
541 LockBroadcaster();
542 bAbortActualize = FALSE;
544 // LoeschFlag zuruecksetzen
545 for ( i = 0; i < nCount; i++ )
546 aObjectList.GetObject( i )->bDummy = FALSE;
548 for( i = 0; ( i < nCount ) && !bAbortActualize; i++ )
550 if( pProgress )
551 pProgress->Update( i, nCount - 1 );
553 pEntry = aObjectList.GetObject( i );
555 const INetURLObject aURL( pEntry->aURL );
557 rActualizeLink.Call( (void*) &aURL );
559 // SvDraw-Objekte werden spaeter aktualisiert
560 if( pEntry->eObjKind != SGA_OBJ_SVDRAW )
562 // Hier muss noch etwas eingebaut werden,
563 // das Files auf den ensprechenden Eintrag matched
564 // Grafiken als Grafik-Objekte in die Gallery aufnehmen
565 if( pEntry->eObjKind == SGA_OBJ_SOUND )
567 SgaObjectSound aObjSound( aURL );
568 if( !InsertObject( aObjSound ) )
569 pEntry->bDummy = TRUE;
571 else
573 aGraphic.Clear();
575 if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) )
577 SgaObject* pNewObj;
579 if ( SGA_OBJ_INET == pEntry->eObjKind )
580 pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, aURL, aFormat );
581 else if ( aGraphic.IsAnimated() )
582 pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, aURL, aFormat );
583 else
584 pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, aURL, aFormat );
586 if( !InsertObject( *pNewObj ) )
587 pEntry->bDummy = TRUE;
589 delete pNewObj;
591 else
592 pEntry->bDummy = TRUE; // Loesch-Flag setzen
595 else
597 if ( aSvDrawStorageRef.Is() )
599 const String aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
600 SvStorageStreamRef pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, STREAM_READ );
602 if( pIStm && !pIStm->GetError() )
604 pIStm->SetBufferSize( 16384 );
606 SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL );
608 if( !InsertObject( aNewObj ) )
609 pEntry->bDummy = TRUE;
611 pIStm->SetBufferSize( 0L );
617 // remove all entries with set flag
618 pEntry = aObjectList.First();
619 while( pEntry )
621 if( pEntry->bDummy )
623 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< ULONG >( pEntry ) ) );
624 delete aObjectList.Remove( pEntry );
625 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< ULONG >( pEntry ) ) );
627 pEntry = aObjectList.GetCurObject();
629 else
630 pEntry = aObjectList.Next();
633 // update theme
634 ::utl::TempFile aTmp;
635 INetURLObject aInURL( GetSdgURL() );
636 INetURLObject aTmpURL( aTmp.GetURL() );
638 DBG_ASSERT( aInURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
639 DBG_ASSERT( aTmpURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
641 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
642 SvStream* pTmpStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
644 if( pIStm && pTmpStm )
646 pEntry = aObjectList.First();
648 while( pEntry )
650 SgaObject* pObj;
652 switch( pEntry->eObjKind )
654 case( SGA_OBJ_BMP ): pObj = new SgaObjectBmp(); break;
655 case( SGA_OBJ_ANIM ): pObj = new SgaObjectAnim(); break;
656 case( SGA_OBJ_INET ): pObj = new SgaObjectINet(); break;
657 case( SGA_OBJ_SVDRAW ): pObj = new SgaObjectSvDraw(); break;
658 case (SGA_OBJ_SOUND): pObj = new SgaObjectSound(); break;
660 default:
661 pObj = NULL;
662 break;
665 if( pObj )
667 pIStm->Seek( pEntry->nOffset );
668 *pIStm >> *pObj;
669 pEntry->nOffset = pTmpStm->Tell();
670 *pTmpStm << *pObj;
671 delete pObj;
674 pEntry = aObjectList.Next();
677 else
679 DBG_ERROR( "File(s) could not be opened" );
682 delete pIStm;
683 delete pTmpStm;
685 CopyFile( aTmpURL, aInURL );
686 KillFile( aTmpURL );
688 ULONG nStorErr = 0;
691 SvStorageRef aTempStorageRef( new SvStorage( FALSE, aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READWRITE ) );
692 aSvDrawStorageRef->CopyTo( aTempStorageRef );
693 nStorErr = aSvDrawStorageRef->GetError();
696 if( !nStorErr )
698 aSvDrawStorageRef.Clear();
699 CopyFile( aTmpURL, GetSdvURL() );
700 ImplCreateSvDrawStorage();
703 KillFile( aTmpURL );
704 ImplSetModified( TRUE );
705 ImplWrite();
706 UnlockBroadcaster();
710 // ------------------------------------------------------------------------
712 GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, BOOL bReadOnly )
714 DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
716 GalleryThemeEntry* pRet = NULL;
718 if( FileExists( rURL ) )
720 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
722 if( pIStm )
724 String aThemeName;
725 sal_uInt32 nThemeId = 0;
726 sal_uInt16 nVersion;
727 BOOL bThemeNameFromResource = FALSE;
729 *pIStm >> nVersion;
731 if( nVersion <= 0x00ff )
733 ByteString aTmpStr;
735 *pIStm >> aTmpStr; aThemeName = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
737 // Charakterkonvertierung durchfuehren
738 if( nVersion >= 0x0004 )
740 sal_uInt32 nCount;
741 sal_uInt16 nTemp16;
743 *pIStm >> nCount >> nTemp16;
744 pIStm->Seek( STREAM_SEEK_TO_END );
746 // pruefen, ob es sich um eine neuere Version handelt;
747 // daher um 520Bytes (8Bytes Kennung + 512Bytes Reserverpuffer ) zurueckspringen,
748 // falls dies ueberhaupt moeglich ist
749 if( pIStm->Tell() >= 520 )
751 sal_uInt32 nId1, nId2;
753 pIStm->SeekRel( -520 );
754 *pIStm >> nId1 >> nId2;
756 if( nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
757 nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
759 VersionCompat* pCompat = new VersionCompat( *pIStm, STREAM_READ );
761 *pIStm >> nThemeId;
763 if( pCompat->GetVersion() >= 2 )
765 *pIStm >> bThemeNameFromResource;
768 delete pCompat;
773 INetURLObject aPathURL( rURL );
775 aPathURL.removeSegment();
776 aPathURL.removeFinalSlash();
777 pRet = new GalleryThemeEntry( aPathURL, aThemeName,
778 String(rURL.GetBase()).Copy( 2, 6 ).ToInt32(),
779 bReadOnly, FALSE, FALSE, nThemeId,
780 bThemeNameFromResource );
783 delete pIStm;
787 return pRet;
790 // -----------------------------------------------------------------------------
792 BOOL GalleryTheme::GetThumb( ULONG nPos, Bitmap& rBmp, BOOL )
794 SgaObject* pObj = AcquireObject( nPos );
795 BOOL bRet = FALSE;
797 if( pObj )
799 rBmp = pObj->GetThumbBmp();
800 ReleaseObject( pObj );
801 bRet = TRUE;
804 return bRet;
807 // -----------------------------------------------------------------------------
809 BOOL GalleryTheme::GetGraphic( ULONG nPos, Graphic& rGraphic, BOOL bProgress )
811 const GalleryObject* pObject = ImplGetGalleryObject( nPos );
812 BOOL bRet = FALSE;
814 if( pObject )
816 const INetURLObject aURL( ImplGetURL( pObject ) );
818 switch( pObject->eObjKind )
820 case( SGA_OBJ_BMP ):
821 case( SGA_OBJ_ANIM ):
822 case( SGA_OBJ_INET ):
824 String aFilterDummy;
825 bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy, bProgress ) != SGA_IMPORT_NONE );
827 break;
829 case( SGA_OBJ_SVDRAW ):
831 SvxGalleryDrawModel aModel;
833 if( aModel.GetModel() )
835 if( GetModel( nPos, *aModel.GetModel(), bProgress ) )
837 ImageMap aIMap;
839 if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
840 bRet = TRUE;
841 else
843 VirtualDevice aVDev;
844 aVDev.SetMapMode( MapMode( MAP_100TH_MM ) );
845 FmFormView aView( aModel.GetModel(), &aVDev );
847 aView.hideMarkHandles();
848 aView.ShowSdrPage(aView.GetModel()->GetPage(0));
849 aView.MarkAll();
850 rGraphic = aView.GetAllMarkedGraphic();
851 bRet = TRUE;
856 break;
858 case( SGA_OBJ_SOUND ):
860 SgaObject* pObj = AcquireObject( nPos );
862 if( pObj )
864 Bitmap aBmp( pObj->GetThumbBmp() );
865 aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
866 rGraphic = aBmp;
867 ReleaseObject( pObj );
868 bRet = TRUE;
871 break;
873 default:
874 break;
878 return bRet;
881 // -----------------------------------------------------------------------------
883 BOOL GalleryTheme::InsertGraphic( const Graphic& rGraphic, ULONG nInsertPos )
885 BOOL bRet = FALSE;
887 if( rGraphic.GetType() != GRAPHIC_NONE )
889 ULONG nExportFormat = CVT_UNKNOWN;
890 const GfxLink aGfxLink( ( (Graphic&) rGraphic ).GetLink() );
892 if( aGfxLink.GetDataSize() )
894 switch( aGfxLink.GetType() )
896 case( GFX_LINK_TYPE_EPS_BUFFER ): nExportFormat = CVT_SVM; break;
897 case( GFX_LINK_TYPE_NATIVE_GIF ): nExportFormat = CVT_GIF; break;
898 case( GFX_LINK_TYPE_NATIVE_JPG ): nExportFormat = CVT_JPG; break;
899 case( GFX_LINK_TYPE_NATIVE_PNG ): nExportFormat = CVT_PNG; break;
900 case( GFX_LINK_TYPE_NATIVE_TIF ): nExportFormat = CVT_TIF; break;
901 case( GFX_LINK_TYPE_NATIVE_WMF ): nExportFormat = CVT_WMF; break;
902 case( GFX_LINK_TYPE_NATIVE_MET ): nExportFormat = CVT_MET; break;
903 case( GFX_LINK_TYPE_NATIVE_PCT ): nExportFormat = CVT_PCT; break;
904 default:
905 break;
908 else
910 if( rGraphic.GetType() == GRAPHIC_BITMAP )
912 if( rGraphic.IsAnimated() )
913 nExportFormat = CVT_GIF;
914 else
915 nExportFormat = CVT_PNG;
917 else
918 nExportFormat = CVT_SVM;
921 const INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_BMP, nExportFormat ) );
922 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
924 if( pOStm )
926 pOStm->SetVersion( SOFFICE_FILEFORMAT_50 );
928 if( CVT_SVM == nExportFormat )
930 GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
932 aMtf.Write( *pOStm );
933 bRet = ( pOStm->GetError() == ERRCODE_NONE );
935 else
937 if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
939 pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
940 bRet = ( pOStm->GetError() == ERRCODE_NONE );
942 else
943 bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE );
946 delete pOStm;
949 if( bRet )
951 const SgaObjectBmp aObjBmp( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
952 InsertObject( aObjBmp, nInsertPos );
956 return bRet;
959 // -----------------------------------------------------------------------------
961 BOOL GalleryTheme::GetModel( ULONG nPos, SdrModel& rModel, BOOL )
963 const GalleryObject* pObject = ImplGetGalleryObject( nPos );
964 BOOL bRet = FALSE;
966 if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
968 const INetURLObject aURL( ImplGetURL( pObject ) );
969 SvStorageRef xStor( GetSvDrawStorage() );
971 if( xStor.Is() )
973 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
974 SvStorageStreamRef xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
976 if( xIStm.Is() && !xIStm->GetError() )
978 xIStm->SetBufferSize( STREAMBUF_SIZE );
979 bRet = GallerySvDrawImport( *xIStm, rModel );
980 xIStm->SetBufferSize( 0L );
985 return bRet;
988 // -----------------------------------------------------------------------------
990 BOOL GalleryTheme::InsertModel( const FmFormModel& rModel, ULONG nInsertPos )
992 INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
993 SvStorageRef xStor( GetSvDrawStorage() );
994 BOOL bRet = FALSE;
996 if( xStor.Is() )
998 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
999 SvStorageStreamRef xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
1001 if( xOStm.Is() && !xOStm->GetError() )
1003 SvMemoryStream aMemStm( 65535, 65535 );
1004 FmFormModel* pFormModel = (FmFormModel*) &rModel;
1006 pFormModel->BurnInStyleSheetAttributes();
1009 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( aMemStm ) );
1011 if( xDocOut.is() )
1012 SvxDrawingLayerExport( pFormModel, xDocOut );
1015 aMemStm.Seek( 0 );
1017 xOStm->SetBufferSize( 16348 );
1018 GalleryCodec aCodec( *xOStm );
1019 aCodec.Write( aMemStm );
1021 if( !xOStm->GetError() )
1023 SgaObjectSvDraw aObjSvDraw( rModel, aURL );
1024 bRet = InsertObject( aObjSvDraw, nInsertPos );
1027 xOStm->SetBufferSize( 0L );
1028 xOStm->Commit();
1032 return bRet;
1035 // -----------------------------------------------------------------------------
1037 BOOL GalleryTheme::GetModelStream( ULONG nPos, SotStorageStreamRef& rxModelStream, BOOL )
1039 const GalleryObject* pObject = ImplGetGalleryObject( nPos );
1040 BOOL bRet = FALSE;
1042 if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
1044 const INetURLObject aURL( ImplGetURL( pObject ) );
1045 SvStorageRef xStor( GetSvDrawStorage() );
1047 if( xStor.Is() )
1049 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1050 SvStorageStreamRef xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
1052 if( xIStm.Is() && !xIStm->GetError() )
1054 UINT32 nVersion = 0;
1056 xIStm->SetBufferSize( 16348 );
1058 if( GalleryCodec::IsCoded( *xIStm, nVersion ) )
1060 SvxGalleryDrawModel aModel;
1062 if( aModel.GetModel() )
1064 if( GallerySvDrawImport( *xIStm, *aModel.GetModel() ) )
1066 aModel.GetModel()->BurnInStyleSheetAttributes();
1069 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) );
1071 if( SvxDrawingLayerExport( aModel.GetModel(), xDocOut ) )
1072 rxModelStream->Commit();
1076 bRet = ( rxModelStream->GetError() == ERRCODE_NONE );
1080 xIStm->SetBufferSize( 0 );
1085 return bRet;
1088 // -----------------------------------------------------------------------------
1090 BOOL GalleryTheme::InsertModelStream( const SotStorageStreamRef& rxModelStream, ULONG nInsertPos )
1092 INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
1093 SvStorageRef xStor( GetSvDrawStorage() );
1094 BOOL bRet = FALSE;
1096 if( xStor.Is() )
1098 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1099 SvStorageStreamRef xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
1101 if( xOStm.Is() && !xOStm->GetError() )
1103 GalleryCodec aCodec( *xOStm );
1104 SvMemoryStream aMemStm( 65535, 65535 );
1106 xOStm->SetBufferSize( 16348 );
1107 aCodec.Write( *rxModelStream );
1109 if( !xOStm->GetError() )
1111 xOStm->Seek( 0 );
1112 SgaObjectSvDraw aObjSvDraw( *xOStm, aURL );
1113 bRet = InsertObject( aObjSvDraw, nInsertPos );
1116 xOStm->SetBufferSize( 0L );
1117 xOStm->Commit();
1121 return bRet;
1124 // -----------------------------------------------------------------------------
1126 BOOL GalleryTheme::GetURL( ULONG nPos, INetURLObject& rURL, BOOL )
1128 const GalleryObject* pObject = ImplGetGalleryObject( nPos );
1129 BOOL bRet = FALSE;
1131 if( pObject )
1133 rURL = INetURLObject( ImplGetURL( pObject ) );
1134 bRet = TRUE;
1137 return bRet;
1140 // -----------------------------------------------------------------------------
1142 BOOL GalleryTheme::InsertURL( const INetURLObject& rURL, ULONG nInsertPos )
1144 Graphic aGraphic;
1145 String aFormat;
1146 SgaObject* pNewObj = NULL;
1147 const USHORT nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
1148 BOOL bRet = FALSE;
1150 if( nImportRet != SGA_IMPORT_NONE )
1152 if ( SGA_IMPORT_INET == nImportRet )
1153 pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, rURL, aFormat );
1154 else if ( aGraphic.IsAnimated() )
1155 pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, rURL, aFormat );
1156 else
1157 pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, rURL, aFormat );
1159 else if( ::avmedia::MediaWindow::isMediaURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
1160 pNewObj = (SgaObject*) new SgaObjectSound( rURL );
1162 if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
1163 bRet = TRUE;
1165 delete pNewObj;
1167 return bRet;
1170 // -----------------------------------------------------------------------------
1172 BOOL GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, ULONG nInsertPos )
1174 INetURLObject aURL;
1175 ::std::vector< INetURLObject > aURLVector;
1176 BOOL bRet = FALSE;
1180 ::ucbhelper::Content aCnt( rFileOrDirURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
1181 sal_Bool bFolder = false;
1183 aCnt.getPropertyValue( OUString::createFromAscii( "IsFolder" ) ) >>= bFolder;
1185 if( bFolder )
1187 uno::Sequence< OUString > aProps( 1 );
1188 aProps.getArray()[ 0 ] = OUString::createFromAscii( "Url" );
1189 uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
1191 if( xResultSet.is() )
1193 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1195 if( xContentAccess.is() )
1197 while( xResultSet->next() )
1199 aURL.SetSmartURL( xContentAccess->queryContentIdentifierString() );
1200 aURLVector.push_back( aURL );
1205 else
1206 aURLVector.push_back( rFileOrDirURL );
1208 catch( const ucb::ContentCreationException& )
1211 catch( const uno::RuntimeException& )
1214 catch( const uno::Exception& )
1218 ::std::vector< INetURLObject >::const_iterator aIter( aURLVector.begin() ), aEnd( aURLVector.end() );
1220 while( aIter != aEnd )
1221 bRet = bRet || InsertURL( *aIter++, nInsertPos );
1223 return bRet;
1226 // -----------------------------------------------------------------------------
1228 BOOL GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTransferable >& rxTransferable, ULONG nInsertPos )
1230 BOOL bRet = FALSE;
1232 if( rxTransferable.is() )
1234 TransferableDataHelper aDataHelper( rxTransferable );
1235 Graphic* pGraphic = NULL;
1237 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
1239 SotStorageStreamRef xModelStm;
1241 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) )
1242 bRet = InsertModelStream( xModelStm, nInsertPos );
1244 else if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
1245 aDataHelper.HasFormat( FORMAT_FILE ) )
1247 FileList aFileList;
1249 if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) )
1250 aDataHelper.GetFileList( SOT_FORMAT_FILE_LIST, aFileList );
1251 else
1253 String aFile;
1255 aDataHelper.GetString( FORMAT_FILE, aFile );
1257 if( aFile.Len() )
1258 aFileList.AppendFile( aFile );
1261 for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
1263 const String aFile( aFileList.GetFile( i ) );
1264 INetURLObject aURL( aFile );
1266 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
1268 String aLocalURL;
1270 if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aLocalURL ) )
1271 aURL = INetURLObject( aLocalURL );
1274 if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1275 bRet = InsertFileOrDirURL( aURL, nInsertPos );
1278 else
1280 Graphic aGraphic;
1281 ULONG nFormat = 0;
1283 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
1284 nFormat = SOT_FORMATSTR_ID_SVXB;
1285 else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1286 nFormat = FORMAT_GDIMETAFILE;
1287 else if( aDataHelper.HasFormat( FORMAT_BITMAP ) )
1288 nFormat = FORMAT_BITMAP;
1290 if( nFormat && aDataHelper.GetGraphic( nFormat, aGraphic ) )
1291 pGraphic = new Graphic( aGraphic );
1294 if( pGraphic )
1296 bRet = FALSE;
1298 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
1301 ImageMap aImageMap;
1303 // according to KA we don't need a BaseURL here
1304 if( aDataHelper.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) )
1306 SvxGalleryDrawModel aModel;
1308 if( aModel.GetModel() )
1310 SgaUserDataFactory aFactory;
1312 SdrPage* pPage = aModel.GetModel()->GetPage(0);
1313 SdrGrafObj* pGrafObj = new SdrGrafObj( *pGraphic );
1315 pGrafObj->InsertUserData( new SgaIMapInfo( aImageMap ) );
1316 pPage->InsertObject( pGrafObj );
1317 bRet = InsertModel( *aModel.GetModel(), nInsertPos );
1322 if( !bRet )
1323 bRet = InsertGraphic( *pGraphic, nInsertPos );
1325 delete pGraphic;
1329 return bRet;
1332 // -----------------------------------------------------------------------------
1334 void GalleryTheme::CopyToClipboard( Window* pWindow, ULONG nPos )
1336 GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
1337 pTransferable->CopyToClipboard( pWindow );
1340 // -----------------------------------------------------------------------------
1342 void GalleryTheme::StartDrag( Window* pWindow, ULONG nPos )
1344 GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true );
1345 pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK );
1348 // -----------------------------------------------------------------------------
1350 SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const
1352 const INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
1353 const INetURLObject aRelURL2( GetParent()->GetUserURL() );
1354 INetURLObject aNewURL, aTempURL;
1355 sal_uInt32 nCount = GetObjectCount();
1356 BOOL bRel;
1358 rOStm << (sal_uInt16) 0x0004;
1359 rOStm << ByteString( GetRealName(), RTL_TEXTENCODING_UTF8 );
1360 rOStm << nCount << (sal_uInt16) gsl_getSystemTextEncoding();
1362 for( sal_uInt32 i = 0; i < nCount; i++ )
1364 const GalleryObject* pObj = ImplGetGalleryObject( i );
1365 String aPath;
1367 if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1369 aPath = GetSvDrawStreamNameFromURL( pObj->aURL );
1370 bRel = FALSE;
1372 else
1374 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1375 bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL1.GetMainURL( INetURLObject::NO_DECODE ) ));
1377 if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
1379 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1380 aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
1382 else
1384 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1385 bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL2.GetMainURL( INetURLObject::NO_DECODE ) ));
1387 if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
1389 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1390 aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
1392 else
1393 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1397 aPath.SearchAndReplace(m_aDestDir, String());
1398 rOStm << bRel << ByteString( aPath, RTL_TEXTENCODING_UTF8 ) << pObj->nOffset << (sal_uInt16) pObj->eObjKind;
1401 // neuerdings wird ein 512-Byte-Reservepuffer gechrieben;
1402 // um diesen zu erkennen werden zwei ULONG-Ids geschrieben
1403 rOStm << COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) << COMPAT_FORMAT( 'E', 'S', 'R', 'V' );
1405 const long nReservePos = rOStm.Tell();
1406 VersionCompat* pCompat = new VersionCompat( rOStm, STREAM_WRITE, 2 );
1408 rOStm << (sal_uInt32) GetId() << IsThemeNameFromResource(); // ab Version 2
1410 delete pCompat;
1412 // Rest des Puffers auffuellen
1413 const long nRest = Max( 512L - ( (long) rOStm.Tell() - nReservePos ), 0L );
1415 if( nRest )
1417 char* pReserve = new char[ nRest ];
1418 memset( pReserve, 0, nRest );
1419 rOStm.Write( pReserve, nRest );
1420 delete[] pReserve;
1423 return rOStm;
1426 // ------------------------------------------------------------------------
1428 SvStream& GalleryTheme::ReadData( SvStream& rIStm )
1430 sal_uInt32 nCount;
1431 sal_uInt16 nVersion;
1432 ByteString aTmpStr;
1433 String aThemeName;
1434 rtl_TextEncoding nTextEncoding;
1436 aImportName = String();
1437 rIStm >> nVersion >> aTmpStr >> nCount;
1439 if( nVersion >= 0x0004 )
1441 UINT16 nTmp16;
1442 rIStm >> nTmp16;
1443 nTextEncoding = (rtl_TextEncoding) nTmp16;
1445 else
1446 nTextEncoding = RTL_TEXTENCODING_UTF8;
1448 aThemeName = String( aTmpStr.GetBuffer(), nTextEncoding );
1450 if( nCount <= ( 1L << 14 ) )
1452 GalleryObject* pObj;
1453 INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
1454 INetURLObject aRelURL2( GetParent()->GetUserURL() );
1455 sal_uInt32 nId1, nId2;
1456 BOOL bRel;
1458 for( pObj = aObjectList.First(); pObj; pObj = aObjectList.Next() )
1460 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< ULONG >( pObj ) ) );
1461 delete pObj;
1462 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< ULONG >( pObj ) ) );
1465 aObjectList.Clear();
1467 for( sal_uInt32 i = 0; i < nCount; i++ )
1469 pObj = new GalleryObject;
1471 ByteString aTempFileName;
1472 String aFileName;
1473 String aPath;
1474 sal_uInt16 nTemp;
1476 rIStm >> bRel >> aTempFileName >> pObj->nOffset;
1477 rIStm >> nTemp; pObj->eObjKind = (SgaObjKind) nTemp;
1479 aFileName = String( aTempFileName.GetBuffer(), gsl_getSystemTextEncoding() );
1481 if( bRel )
1483 aFileName.SearchAndReplaceAll( '\\', '/' );
1484 aPath = aRelURL1.GetMainURL( INetURLObject::NO_DECODE );
1486 if( aFileName.GetChar( 0 ) != '/' )
1487 aPath += '/';
1489 aPath += aFileName;
1491 pObj->aURL = INetURLObject( aPath );
1493 if( !FileExists( pObj->aURL ) )
1495 aPath = aRelURL2.GetMainURL( INetURLObject::NO_DECODE );
1497 if( aFileName.GetChar( 0 ) != '/' )
1498 aPath += '/';
1500 aPath += aFileName;
1502 // assign this URL, even in the case it is not valid (#94482)
1503 pObj->aURL = INetURLObject( aPath );
1506 else
1508 if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1510 const static String aBaseURLStr( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/" ) );
1512 String aDummyURL( aBaseURLStr );
1513 pObj->aURL = INetURLObject( aDummyURL += aFileName, INET_PROT_PRIV_SOFFICE );
1515 else
1517 String aLocalURL;
1519 pObj->aURL = INetURLObject( aFileName );
1521 if( ( pObj->aURL.GetProtocol() == INET_PROT_NOT_VALID ) &&
1522 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aLocalURL ) )
1524 pObj->aURL = INetURLObject( aLocalURL );
1529 aObjectList.Insert( pObj, LIST_APPEND );
1532 rIStm >> nId1 >> nId2;
1534 // in neueren Versionen befindet sich am Ende ein 512-Byte-Reservepuffer;
1535 // die Daten befinden sich am Anfang dieses Puffers und
1536 // sind durch eine VersionCompat geklammert
1537 if( !rIStm.IsEof() &&
1538 nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
1539 nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
1541 VersionCompat* pCompat = new VersionCompat( rIStm, STREAM_READ );
1542 sal_uInt32 nTemp32;
1543 BOOL bThemeNameFromResource = FALSE;
1545 rIStm >> nTemp32;
1547 if( pCompat->GetVersion() >= 2 )
1549 rIStm >> bThemeNameFromResource;
1552 SetId( nTemp32, bThemeNameFromResource );
1553 delete pCompat;
1556 else
1557 rIStm.SetError( SVSTREAM_READ_ERROR );
1559 ImplSetModified( FALSE );
1561 return rIStm;
1564 // ------------------------------------------------------------------------
1566 SvStream& operator<<( SvStream& rOut, const GalleryTheme& rTheme )
1568 return rTheme.WriteData( rOut );
1571 // ------------------------------------------------------------------------
1573 SvStream& operator>>( SvStream& rIn, GalleryTheme& rTheme )
1575 return rTheme.ReadData( rIn );