1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include "sal/config.h"
26 #include <comphelper/processfactory.hxx>
27 #include <tools/urlobj.hxx>
28 #include <tools/vcompat.hxx>
29 #include <unotools/streamwrap.hxx>
30 #include <unotools/ucbstreamhelper.hxx>
31 #include <unotools/tempfile.hxx>
32 #include <unotools/localfilehelper.hxx>
33 #include <ucbhelper/content.hxx>
34 #include <sot/storage.hxx>
35 #include <sot/formats.hxx>
36 #include <sot/filelist.hxx>
37 #include <vcl/virdev.hxx>
38 #include <vcl/cvtgrf.hxx>
39 #include <svl/itempool.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <avmedia/mediawindow.hxx>
42 #include <svx/svdograf.hxx>
43 #include <svx/fmpage.hxx>
45 #include <svx/unomodel.hxx>
46 #include <svx/fmmodel.hxx>
47 #include <svx/fmview.hxx>
48 #include "svx/galmisc.hxx"
49 #include "svx/galtheme.hxx"
50 #include <com/sun/star/sdbc/XResultSet.hpp>
51 #include <com/sun/star/ucb/XContentAccess.hpp>
52 #include <com/sun/star/io/XInputStream.hpp>
54 #include <svx/gallery1.hxx>
55 #include "galtheme.hrc"
56 #include <vcl/lstbox.hxx>
57 #include "gallerydrawmodel.hxx"
58 #include <boost/scoped_array.hpp>
59 #include <boost/scoped_ptr.hpp>
61 using namespace ::com::sun::star
;
66 GalleryTheme::GalleryTheme( Gallery
* pGallery
, GalleryThemeEntry
* pThemeEntry
)
67 : m_bDestDirRelative(false)
71 , mnBroadcasterLockCount(0)
74 , bAbortActualize(false)
76 ImplCreateSvDrawStorage();
79 GalleryTheme::~GalleryTheme()
83 for ( size_t i
= 0, n
= aObjectList
.size(); i
< n
; ++i
)
85 GalleryObject
* pEntry
= aObjectList
[ i
];
86 Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT
, GetName(), reinterpret_cast< sal_uIntPtr
>( pEntry
) ) );
87 Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED
, GetName(), reinterpret_cast< sal_uIntPtr
>( pEntry
) ) );
94 void GalleryTheme::ImplCreateSvDrawStorage()
98 aSvDrawStorageRef
= new SotStorage( false, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE
), pThm
->IsReadOnly() ? StreamMode::READ
: STREAM_STD_READWRITE
);
99 // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
100 if ( ( aSvDrawStorageRef
->GetError() != ERRCODE_NONE
) && !pThm
->IsReadOnly() )
101 aSvDrawStorageRef
= new SotStorage( false, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE
), StreamMode::READ
);
103 catch (const css::ucb::ContentCreationException
& e
)
105 SAL_WARN("svx", "failed to open: "
106 << GetSdvURL().GetMainURL(INetURLObject::NO_DECODE
)
107 << "due to : " << e
.Message
);
111 bool GalleryTheme::ImplWriteSgaObject( const SgaObject
& rObj
, size_t nPos
, GalleryObject
* pExistentEntry
)
113 boost::scoped_ptr
<SvStream
> pOStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE
), StreamMode::WRITE
));
118 const sal_uInt32 nOffset
= pOStm
->Seek( STREAM_SEEK_TO_END
);
120 rObj
.WriteData( *pOStm
, m_aDestDir
);
122 if( !pOStm
->GetError() )
124 GalleryObject
* pEntry
;
126 if( !pExistentEntry
)
128 pEntry
= new GalleryObject
;
129 if ( nPos
< aObjectList
.size() )
131 GalleryObjectList::iterator it
= aObjectList
.begin();
132 ::std::advance( it
, nPos
);
133 aObjectList
.insert( it
, pEntry
);
136 aObjectList
.push_back( pEntry
);
139 pEntry
= pExistentEntry
;
141 pEntry
->aURL
= rObj
.GetURL();
142 pEntry
->nOffset
= nOffset
;
143 pEntry
->eObjKind
= rObj
.GetObjKind();
151 SgaObject
* GalleryTheme::ImplReadSgaObject( GalleryObject
* pEntry
)
153 SgaObject
* pSgaObj
= NULL
;
157 boost::scoped_ptr
<SvStream
> pIStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE
), StreamMode::READ
));
161 sal_uInt32 nInventor
;
163 // Check to ensure that the file is a valid SGA file
164 pIStm
->Seek( pEntry
->nOffset
);
165 pIStm
->ReadUInt32( nInventor
);
167 if( nInventor
== COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
169 pIStm
->Seek( pEntry
->nOffset
);
171 switch( pEntry
->eObjKind
)
173 case( SGA_OBJ_BMP
): pSgaObj
= new SgaObjectBmp(); break;
174 case( SGA_OBJ_ANIM
): pSgaObj
= new SgaObjectAnim(); break;
175 case( SGA_OBJ_INET
): pSgaObj
= new SgaObjectINet(); break;
176 case( SGA_OBJ_SVDRAW
): pSgaObj
= new SgaObjectSvDraw(); break;
177 case( SGA_OBJ_SOUND
): pSgaObj
= new SgaObjectSound(); break;
185 ReadSgaObject( *pIStm
, *pSgaObj
);
186 pSgaObj
->ImplUpdateURL( pEntry
->aURL
);
195 void GalleryTheme::ImplWrite()
199 INetURLObject
aPathURL( GetThmURL() );
201 aPathURL
.removeSegment();
202 aPathURL
.removeFinalSlash();
204 DBG_ASSERT( aPathURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
206 if( FileExists( aPathURL
) || CreateDir( aPathURL
) )
209 boost::scoped_ptr
<SvStream
> pOStm(::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE
), StreamMode::WRITE
| StreamMode::COPY_ON_SYMLINK
| StreamMode::TRUNC
));
211 boost::scoped_ptr
<SvStream
> pOStm(::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE
), StreamMode::WRITE
| StreamMode::TRUNC
));
216 WriteGalleryTheme( *pOStm
, *this );
220 ImplSetModified( false );
225 const GalleryObject
* GalleryTheme::ImplGetGalleryObject( const INetURLObject
& rURL
)
227 for ( size_t i
= 0, n
= aObjectList
.size(); i
< n
; ++i
)
228 if ( aObjectList
[ i
]->aURL
== rURL
)
229 return aObjectList
[ i
];
233 INetURLObject
GalleryTheme::ImplGetURL( const GalleryObject
* pObject
) const
238 aURL
= pObject
->aURL
;
243 INetURLObject
GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind
, sal_uIntPtr nFormat
)
245 INetURLObject
aDir( GetParent()->GetUserURL() );
246 INetURLObject
aInfoFileURL( GetParent()->GetUserURL() );
247 INetURLObject aNewURL
;
248 sal_uInt32 nNextNumber
= 1999;
249 sal_Char
const* pExt
= NULL
;
252 aDir
.Append( OUString("dragdrop") );
255 aInfoFileURL
.Append( OUString("sdddndx1") );
257 // read next possible number
258 if( FileExists( aInfoFileURL
) )
260 boost::scoped_ptr
<SvStream
> pIStm(::utl::UcbStreamHelper::CreateStream( aInfoFileURL
.GetMainURL( INetURLObject::NO_DECODE
), StreamMode::READ
));
264 pIStm
->ReadUInt32( nNextNumber
);
273 case( CVT_BMP
): pExt
= ".bmp"; break;
274 case( CVT_GIF
): pExt
= ".gif"; break;
275 case( CVT_JPG
): pExt
= ".jpg"; break;
276 case( CVT_MET
): pExt
= ".met"; break;
277 case( CVT_PCT
): pExt
= ".pct"; break;
278 case( CVT_PNG
): pExt
= ".png"; break;
279 case( CVT_SVM
): pExt
= ".svm"; break;
280 case( CVT_TIF
): pExt
= ".tif"; break;
281 case( CVT_WMF
): pExt
= ".wmf"; break;
282 case( CVT_EMF
): pExt
= ".emf"; break;
293 if( SGA_OBJ_SVDRAW
== eObjKind
)
295 OUString
aFileName( "gallery/svdraw/dd" );
296 aNewURL
= INetURLObject( aFileName
+= OUString::number( ++nNextNumber
% 99999999 ), INetProtocol::PrivSoffice
);
300 for ( size_t i
= 0, n
= aObjectList
.size(); i
< n
; ++i
)
301 if ( aObjectList
[ i
]->aURL
== aNewURL
)
309 OUString
aFileName( "dd" );
311 aFileName
+= OUString::number( ++nNextNumber
% 999999 );
314 aFileName
+= OUString( pExt
, strlen(pExt
), RTL_TEXTENCODING_ASCII_US
);
317 aNewURL
.Append( aFileName
);
319 bExists
= FileExists( aNewURL
);
324 // write updated number
325 boost::scoped_ptr
<SvStream
> pOStm(::utl::UcbStreamHelper::CreateStream( aInfoFileURL
.GetMainURL( INetURLObject::NO_DECODE
), StreamMode::WRITE
));
329 pOStm
->WriteUInt32( nNextNumber
);
335 void GalleryTheme::ImplBroadcast( sal_uIntPtr nUpdatePos
)
337 if( !IsBroadcasterLocked() )
339 if( GetObjectCount() && ( nUpdatePos
>= GetObjectCount() ) )
340 nUpdatePos
= GetObjectCount() - 1;
342 Broadcast( GalleryHint( GalleryHintType::THEME_UPDATEVIEW
, GetName(), nUpdatePos
) );
346 bool GalleryTheme::UnlockTheme()
348 DBG_ASSERT( mnThemeLockCount
, "Theme is not locked" );
352 if( mnThemeLockCount
)
361 void GalleryTheme::UnlockBroadcaster( sal_uIntPtr nUpdatePos
)
363 DBG_ASSERT( mnBroadcasterLockCount
, "Broadcaster is not locked" );
365 if( mnBroadcasterLockCount
&& !--mnBroadcasterLockCount
)
366 ImplBroadcast( nUpdatePos
);
369 bool GalleryTheme::InsertObject( const SgaObject
& rObj
, sal_uIntPtr nInsertPos
)
374 GalleryObject
* pFoundEntry
= NULL
;
375 size_t iFoundPos
= 0;
376 for (size_t n
= aObjectList
.size(); iFoundPos
< n
; ++iFoundPos
)
378 if (aObjectList
[ iFoundPos
]->aURL
== rObj
.GetURL())
380 pFoundEntry
= aObjectList
[ iFoundPos
];
387 GalleryObject aNewEntry
;
389 // update title of new object if necessary
390 if (rObj
.GetTitle().isEmpty())
392 boost::scoped_ptr
<SgaObject
> pOldObj(ImplReadSgaObject(pFoundEntry
));
396 ((SgaObject
&) rObj
).SetTitle( pOldObj
->GetTitle() );
399 else if (rObj
.GetTitle() == "__<empty>__")
400 ((SgaObject
&) rObj
).SetTitle("");
402 ImplWriteSgaObject(rObj
, nInsertPos
, &aNewEntry
);
403 pFoundEntry
->nOffset
= aNewEntry
.nOffset
;
406 ImplWriteSgaObject(rObj
, nInsertPos
, NULL
);
408 ImplSetModified(true);
409 ImplBroadcast(pFoundEntry
? iFoundPos
: nInsertPos
);
414 SgaObject
* GalleryTheme::AcquireObject( size_t nPos
)
416 return ImplReadSgaObject( aObjectList
[ nPos
] );
419 void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uIntPtr nPos
, BitmapEx
& rBitmapEx
, Size
& rSize
, OUString
& rTitle
, OUString
& rPath
) const
421 const GalleryObject
* pGalleryObject
= nPos
< aObjectList
.size() ? aObjectList
[ nPos
] : NULL
;
425 rBitmapEx
= pGalleryObject
->maPreviewBitmapEx
;
426 rSize
= pGalleryObject
->maPreparedSize
;
427 rTitle
= pGalleryObject
->maTitle
;
428 rPath
= pGalleryObject
->maPath
;
432 OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
436 void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uIntPtr nPos
, const BitmapEx
& rBitmapEx
, const Size
& rSize
, const OUString
& rTitle
, const OUString
& rPath
)
438 GalleryObject
* pGalleryObject
= nPos
< aObjectList
.size() ? aObjectList
[ nPos
] : NULL
;
442 pGalleryObject
->maPreviewBitmapEx
= rBitmapEx
;
443 pGalleryObject
->maPreparedSize
= rSize
;
444 pGalleryObject
->maTitle
= rTitle
;
445 pGalleryObject
->maPath
= rPath
;
449 OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
453 void GalleryTheme::ReleaseObject( SgaObject
* pObject
)
458 bool GalleryTheme::RemoveObject( size_t nPos
)
460 GalleryObject
* pEntry
= NULL
;
461 if ( nPos
< aObjectList
.size() )
463 GalleryObjectList::iterator it
= aObjectList
.begin();
464 ::std::advance( it
, nPos
);
466 aObjectList
.erase( it
);
469 if( aObjectList
.empty() )
470 KillFile( GetSdgURL() );
474 if( SGA_OBJ_SVDRAW
== pEntry
->eObjKind
)
475 aSvDrawStorageRef
->Remove( pEntry
->aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
477 Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT
, GetName(), reinterpret_cast< sal_uIntPtr
>( pEntry
) ) );
478 Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED
, GetName(), reinterpret_cast< sal_uIntPtr
>( pEntry
) ) );
482 ImplSetModified( true );
483 ImplBroadcast( nPos
);
486 return( pEntry
!= NULL
);
489 bool GalleryTheme::ChangeObjectPos( size_t nOldPos
, size_t nNewPos
)
491 if (nOldPos
== nNewPos
|| nOldPos
>= aObjectList
.size())
494 GalleryObject
* pEntry
= aObjectList
[nOldPos
];
496 GalleryObjectList::iterator it
= aObjectList
.begin();
497 ::std::advance(it
, nNewPos
);
498 aObjectList
.insert(it
, pEntry
);
500 if (nNewPos
< nOldPos
)
503 it
= aObjectList
.begin();
504 ::std::advance(it
, nOldPos
);
505 aObjectList
.erase(it
);
507 ImplSetModified(true);
508 ImplBroadcast((nNewPos
< nOldPos
)? nNewPos
: (nNewPos
- 1));
513 void GalleryTheme::Actualize( const Link
<>& rActualizeLink
, GalleryProgress
* pProgress
)
519 GalleryObject
* pEntry
;
520 const size_t nCount
= aObjectList
.size();
523 bAbortActualize
= false;
526 for (size_t i
= 0; i
< nCount
; i
++)
527 aObjectList
[ i
]->mbDelete
= false;
529 for(size_t i
= 0; ( i
< nCount
) && !bAbortActualize
; i
++)
532 pProgress
->Update( i
, nCount
- 1 );
534 pEntry
= aObjectList
[ i
];
536 const INetURLObject
aURL( pEntry
->aURL
);
538 rActualizeLink
.Call( (void*) &aURL
);
540 // SvDraw objects will be updated later
541 if( pEntry
->eObjKind
!= SGA_OBJ_SVDRAW
)
543 // Still a function should be implemented,
544 // which assigns files to the relevant entry.
545 // insert graphics as graphic objects into the gallery
546 if( pEntry
->eObjKind
== SGA_OBJ_SOUND
)
548 SgaObjectSound
aObjSound( aURL
);
549 if( !InsertObject( aObjSound
) )
550 pEntry
->mbDelete
= true;
556 if ( GalleryGraphicImport( aURL
, aGraphic
, aFormat
) != GalleryGraphicImportRet::IMPORT_NONE
)
558 boost::scoped_ptr
<SgaObject
> pNewObj
;
560 if ( SGA_OBJ_INET
== pEntry
->eObjKind
)
561 pNewObj
.reset((SgaObject
*) new SgaObjectINet( aGraphic
, aURL
, aFormat
));
562 else if ( aGraphic
.IsAnimated() )
563 pNewObj
.reset((SgaObject
*) new SgaObjectAnim( aGraphic
, aURL
, aFormat
));
565 pNewObj
.reset((SgaObject
*) new SgaObjectBmp( aGraphic
, aURL
, aFormat
));
567 if( !InsertObject( *pNewObj
) )
568 pEntry
->mbDelete
= true;
571 pEntry
->mbDelete
= true; // set delete flag
576 if ( aSvDrawStorageRef
.Is() )
578 const OUString
aStmName( GetSvDrawStreamNameFromURL( pEntry
->aURL
) );
579 tools::SvRef
<SotStorageStream
> pIStm
= aSvDrawStorageRef
->OpenSotStream( aStmName
, StreamMode::READ
);
581 if( pIStm
&& !pIStm
->GetError() )
583 pIStm
->SetBufferSize( 16384 );
585 SgaObjectSvDraw
aNewObj( *pIStm
, pEntry
->aURL
);
587 if( !InsertObject( aNewObj
) )
588 pEntry
->mbDelete
= true;
590 pIStm
->SetBufferSize( 0L );
596 // remove all entries with set flag
597 for ( size_t i
= 0; i
< aObjectList
.size(); )
599 pEntry
= aObjectList
[ i
];
600 if( pEntry
->mbDelete
)
602 Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT
, GetName(), reinterpret_cast< sal_uIntPtr
>( pEntry
) ) );
603 Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED
, GetName(), reinterpret_cast< sal_uLong
>( pEntry
) ) );
604 GalleryObjectList::iterator it
= aObjectList
.begin();
605 ::std::advance( it
, i
);
606 aObjectList
.erase( it
);
613 ::utl::TempFile aTmp
;
614 INetURLObject
aInURL( GetSdgURL() );
615 INetURLObject
aTmpURL( aTmp
.GetURL() );
617 DBG_ASSERT( aInURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
618 DBG_ASSERT( aTmpURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
620 boost::scoped_ptr
<SvStream
> pIStm(::utl::UcbStreamHelper::CreateStream( aInURL
.GetMainURL( INetURLObject::NO_DECODE
), StreamMode::READ
));
621 boost::scoped_ptr
<SvStream
> pTmpStm(::utl::UcbStreamHelper::CreateStream( aTmpURL
.GetMainURL( INetURLObject::NO_DECODE
), StreamMode::WRITE
| StreamMode::TRUNC
));
623 if( pIStm
&& pTmpStm
)
625 for ( size_t i
= 0, n
= aObjectList
.size(); i
< n
; ++i
)
627 pEntry
= aObjectList
[ i
];
628 boost::scoped_ptr
<SgaObject
> pObj
;
630 switch( pEntry
->eObjKind
)
632 case( SGA_OBJ_BMP
): pObj
.reset(new SgaObjectBmp()); break;
633 case( SGA_OBJ_ANIM
): pObj
.reset(new SgaObjectAnim()); break;
634 case( SGA_OBJ_INET
): pObj
.reset(new SgaObjectINet()); break;
635 case( SGA_OBJ_SVDRAW
): pObj
.reset(new SgaObjectSvDraw()); break;
636 case (SGA_OBJ_SOUND
): pObj
.reset(new SgaObjectSound()); break;
644 pIStm
->Seek( pEntry
->nOffset
);
645 ReadSgaObject( *pIStm
, *pObj
);
646 pEntry
->nOffset
= pTmpStm
->Tell();
647 WriteSgaObject( *pTmpStm
, *pObj
);
653 OSL_FAIL( "File(s) could not be opened" );
659 CopyFile( aTmpURL
, aInURL
);
662 sal_uIntPtr nStorErr
= 0;
666 tools::SvRef
<SotStorage
> aTempStorageRef( new SotStorage( false, aTmpURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_STD_READWRITE
) );
667 aSvDrawStorageRef
->CopyTo( aTempStorageRef
);
668 nStorErr
= aSvDrawStorageRef
->GetError();
670 catch (const css::ucb::ContentCreationException
& e
)
672 SAL_WARN("svx", "failed to open: "
673 << aTmpURL
.GetMainURL(INetURLObject::NO_DECODE
)
674 << "due to : " << e
.Message
);
675 nStorErr
= ERRCODE_IO_GENERAL
;
680 aSvDrawStorageRef
.Clear();
681 CopyFile( aTmpURL
, GetSdvURL() );
682 ImplCreateSvDrawStorage();
686 ImplSetModified( true );
692 GalleryThemeEntry
* GalleryTheme::CreateThemeEntry( const INetURLObject
& rURL
, bool bReadOnly
)
694 DBG_ASSERT( rURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
696 GalleryThemeEntry
* pRet
= NULL
;
698 if( FileExists( rURL
) )
700 boost::scoped_ptr
<SvStream
> pIStm(::utl::UcbStreamHelper::CreateStream( rURL
.GetMainURL( INetURLObject::NO_DECODE
), StreamMode::READ
));
707 pIStm
->ReadUInt16( nVersion
);
709 if( nVersion
<= 0x00ff )
711 bool bThemeNameFromResource
= false;
712 sal_uInt32 nThemeId
= 0;
714 OString aTmpStr
= read_uInt16_lenPrefixed_uInt8s_ToOString(*pIStm
);
715 aThemeName
= OStringToOUString(aTmpStr
, RTL_TEXTENCODING_UTF8
);
717 // execute a charakter conversion
718 if( nVersion
>= 0x0004 )
723 pIStm
->ReadUInt32( nCount
).ReadUInt16( nTemp16
);
724 pIStm
->Seek( STREAM_SEEK_TO_END
);
726 // check whether there is a newer version;
727 // therefore jump back by 520Bytes (8 bytes ID + 512Bytes reserve buffer)
728 // if this is at all possible.
729 if( pIStm
->Tell() >= 520 )
731 sal_uInt32 nId1
, nId2
;
733 pIStm
->SeekRel( -520 );
734 pIStm
->ReadUInt32( nId1
).ReadUInt32( nId2
);
736 if( nId1
== COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
737 nId2
== COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
739 boost::scoped_ptr
<VersionCompat
> pCompat(new VersionCompat( *pIStm
, StreamMode::READ
));
741 pIStm
->ReadUInt32( nThemeId
);
743 if( pCompat
->GetVersion() >= 2 )
745 pIStm
->ReadCharAsBool( bThemeNameFromResource
);
751 INetURLObject
aPathURL( rURL
);
752 pRet
= new GalleryThemeEntry( false, aPathURL
, aThemeName
,
753 bReadOnly
, false, nThemeId
,
754 bThemeNameFromResource
);
762 bool GalleryTheme::GetThumb( sal_uIntPtr nPos
, BitmapEx
& rBmp
, bool )
764 SgaObject
* pObj
= AcquireObject( nPos
);
769 rBmp
= pObj
->GetThumbBmp();
770 ReleaseObject( pObj
);
777 bool GalleryTheme::GetGraphic( sal_uIntPtr nPos
, Graphic
& rGraphic
, bool bProgress
)
779 const GalleryObject
* pObject
= ImplGetGalleryObject( nPos
);
784 const INetURLObject
aURL( ImplGetURL( pObject
) );
786 switch( pObject
->eObjKind
)
789 case( SGA_OBJ_ANIM
):
790 case( SGA_OBJ_INET
):
792 OUString aFilterDummy
;
793 bRet
= ( GalleryGraphicImport( aURL
, rGraphic
, aFilterDummy
, bProgress
) != GalleryGraphicImportRet::IMPORT_NONE
);
797 case( SGA_OBJ_SVDRAW
):
799 SvxGalleryDrawModel aModel
;
801 if( aModel
.GetModel() )
803 if( GetModel( nPos
, *aModel
.GetModel(), bProgress
) )
807 if( CreateIMapGraphic( *aModel
.GetModel(), rGraphic
, aIMap
) )
811 ScopedVclPtrInstance
< VirtualDevice
> pVDev
;
812 pVDev
->SetMapMode( MapMode( MAP_100TH_MM
) );
813 FmFormView
aView( aModel
.GetModel(), pVDev
);
815 aView
.hideMarkHandles();
816 aView
.ShowSdrPage(aView
.GetModel()->GetPage(0));
818 rGraphic
= aView
.GetAllMarkedGraphic();
826 case( SGA_OBJ_SOUND
):
828 SgaObject
* pObj
= AcquireObject( nPos
);
832 rGraphic
= pObj
->GetThumbBmp();
833 //Bitmap aBmp( pObj->GetThumbBmp() );
834 //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
836 ReleaseObject( pObj
);
850 bool GalleryTheme::InsertGraphic( const Graphic
& rGraphic
, sal_uIntPtr nInsertPos
)
854 if( rGraphic
.GetType() != GRAPHIC_NONE
)
856 sal_uIntPtr nExportFormat
= CVT_UNKNOWN
;
857 const GfxLink
aGfxLink( ( (Graphic
&) rGraphic
).GetLink() );
859 if( aGfxLink
.GetDataSize() )
861 switch( aGfxLink
.GetType() )
863 case( GFX_LINK_TYPE_EPS_BUFFER
): nExportFormat
= CVT_SVM
; break;
864 case( GFX_LINK_TYPE_NATIVE_GIF
): nExportFormat
= CVT_GIF
; break;
866 // #i15508# added BMP type
867 // could not find/trigger a call to this, but should do no harm
868 case( GFX_LINK_TYPE_NATIVE_BMP
): nExportFormat
= CVT_BMP
; break;
870 case( GFX_LINK_TYPE_NATIVE_JPG
): nExportFormat
= CVT_JPG
; break;
871 case( GFX_LINK_TYPE_NATIVE_PNG
): nExportFormat
= CVT_PNG
; break;
872 case( GFX_LINK_TYPE_NATIVE_TIF
): nExportFormat
= CVT_TIF
; break;
873 case( GFX_LINK_TYPE_NATIVE_WMF
): nExportFormat
= CVT_WMF
; break;
874 case( GFX_LINK_TYPE_NATIVE_MET
): nExportFormat
= CVT_MET
; break;
875 case( GFX_LINK_TYPE_NATIVE_PCT
): nExportFormat
= CVT_PCT
; break;
876 case( GFX_LINK_TYPE_NATIVE_SVG
): nExportFormat
= CVT_SVG
; break;
883 if( rGraphic
.GetType() == GRAPHIC_BITMAP
)
885 if( rGraphic
.IsAnimated() )
886 nExportFormat
= CVT_GIF
;
888 nExportFormat
= CVT_PNG
;
891 nExportFormat
= CVT_SVM
;
894 const INetURLObject
aURL( ImplCreateUniqueURL( SGA_OBJ_BMP
, nExportFormat
) );
895 boost::scoped_ptr
<SvStream
> pOStm(::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), StreamMode::WRITE
| StreamMode::TRUNC
));
899 pOStm
->SetVersion( SOFFICE_FILEFORMAT_50
);
901 if( CVT_SVM
== nExportFormat
)
903 GDIMetaFile
aMtf( rGraphic
.GetGDIMetaFile() );
905 aMtf
.Write( *pOStm
);
906 bRet
= ( pOStm
->GetError() == ERRCODE_NONE
);
910 if( aGfxLink
.GetDataSize() && aGfxLink
.GetData() )
912 pOStm
->Write( aGfxLink
.GetData(), aGfxLink
.GetDataSize() );
913 bRet
= ( pOStm
->GetError() == ERRCODE_NONE
);
916 bRet
= ( GraphicConverter::Export( *pOStm
, rGraphic
, nExportFormat
) == ERRCODE_NONE
);
924 const SgaObjectBmp
aObjBmp( aURL
);
925 InsertObject( aObjBmp
, nInsertPos
);
932 bool GalleryTheme::GetModel( sal_uIntPtr nPos
, SdrModel
& rModel
, bool )
934 const GalleryObject
* pObject
= ImplGetGalleryObject( nPos
);
937 if( pObject
&& ( SGA_OBJ_SVDRAW
== pObject
->eObjKind
) )
939 const INetURLObject
aURL( ImplGetURL( pObject
) );
940 tools::SvRef
<SotStorage
> xStor( GetSvDrawStorage() );
944 const OUString
aStmName( GetSvDrawStreamNameFromURL( aURL
) );
945 tools::SvRef
<SotStorageStream
> xIStm( xStor
->OpenSotStream( aStmName
, StreamMode::READ
) );
947 if( xIStm
.Is() && !xIStm
->GetError() )
949 xIStm
->SetBufferSize( STREAMBUF_SIZE
);
950 bRet
= GallerySvDrawImport( *xIStm
, rModel
);
951 xIStm
->SetBufferSize( 0L );
959 bool GalleryTheme::InsertModel( const FmFormModel
& rModel
, sal_uIntPtr nInsertPos
)
961 INetURLObject
aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW
) );
962 tools::SvRef
<SotStorage
> xStor( GetSvDrawStorage() );
967 const OUString
aStmName( GetSvDrawStreamNameFromURL( aURL
) );
968 tools::SvRef
<SotStorageStream
> xOStm( xStor
->OpenSotStream( aStmName
, StreamMode::WRITE
| StreamMode::TRUNC
) );
970 if( xOStm
.Is() && !xOStm
->GetError() )
972 SvMemoryStream
aMemStm( 65535, 65535 );
973 FmFormModel
* pFormModel
= const_cast<FmFormModel
*>(&rModel
);
975 pFormModel
->BurnInStyleSheetAttributes();
978 uno::Reference
< io::XOutputStream
> xDocOut( new utl::OOutputStreamWrapper( aMemStm
) );
981 SvxDrawingLayerExport( pFormModel
, xDocOut
);
986 xOStm
->SetBufferSize( 16348 );
987 GalleryCodec
aCodec( *xOStm
);
988 aCodec
.Write( aMemStm
);
990 if( !xOStm
->GetError() )
992 SgaObjectSvDraw
aObjSvDraw( rModel
, aURL
);
993 bRet
= InsertObject( aObjSvDraw
, nInsertPos
);
996 xOStm
->SetBufferSize( 0L );
1004 bool GalleryTheme::GetModelStream( sal_uIntPtr nPos
, tools::SvRef
<SotStorageStream
>& rxModelStream
, bool )
1006 const GalleryObject
* pObject
= ImplGetGalleryObject( nPos
);
1009 if( pObject
&& ( SGA_OBJ_SVDRAW
== pObject
->eObjKind
) )
1011 const INetURLObject
aURL( ImplGetURL( pObject
) );
1012 tools::SvRef
<SotStorage
> xStor( GetSvDrawStorage() );
1016 const OUString
aStmName( GetSvDrawStreamNameFromURL( aURL
) );
1017 tools::SvRef
<SotStorageStream
> xIStm( xStor
->OpenSotStream( aStmName
, StreamMode::READ
) );
1019 if( xIStm
.Is() && !xIStm
->GetError() )
1021 sal_uInt32 nVersion
= 0;
1023 xIStm
->SetBufferSize( 16348 );
1025 if( GalleryCodec::IsCoded( *xIStm
, nVersion
) )
1027 SvxGalleryDrawModel aModel
;
1029 if( aModel
.GetModel() )
1031 if( GallerySvDrawImport( *xIStm
, *aModel
.GetModel() ) )
1033 aModel
.GetModel()->BurnInStyleSheetAttributes();
1036 uno::Reference
< io::XOutputStream
> xDocOut( new utl::OOutputStreamWrapper( *rxModelStream
) );
1038 if( SvxDrawingLayerExport( aModel
.GetModel(), xDocOut
) )
1039 rxModelStream
->Commit();
1043 bRet
= ( rxModelStream
->GetError() == ERRCODE_NONE
);
1047 xIStm
->SetBufferSize( 0 );
1055 bool GalleryTheme::InsertModelStream( const tools::SvRef
<SotStorageStream
>& rxModelStream
, sal_uIntPtr nInsertPos
)
1057 INetURLObject
aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW
) );
1058 tools::SvRef
<SotStorage
> xStor( GetSvDrawStorage() );
1063 const OUString
aStmName( GetSvDrawStreamNameFromURL( aURL
) );
1064 tools::SvRef
<SotStorageStream
> xOStm( xStor
->OpenSotStream( aStmName
, StreamMode::WRITE
| StreamMode::TRUNC
) );
1066 if( xOStm
.Is() && !xOStm
->GetError() )
1068 GalleryCodec
aCodec( *xOStm
);
1069 SvMemoryStream
aMemStm( 65535, 65535 );
1071 xOStm
->SetBufferSize( 16348 );
1072 aCodec
.Write( *rxModelStream
);
1074 if( !xOStm
->GetError() )
1077 SgaObjectSvDraw
aObjSvDraw( *xOStm
, aURL
);
1078 bRet
= InsertObject( aObjSvDraw
, nInsertPos
);
1081 xOStm
->SetBufferSize( 0L );
1089 bool GalleryTheme::GetURL( sal_uIntPtr nPos
, INetURLObject
& rURL
, bool )
1091 const GalleryObject
* pObject
= ImplGetGalleryObject( nPos
);
1096 rURL
= INetURLObject( ImplGetURL( pObject
) );
1103 bool GalleryTheme::InsertURL( const INetURLObject
& rURL
, sal_uIntPtr nInsertPos
)
1107 boost::scoped_ptr
<SgaObject
> pNewObj
;
1108 const GalleryGraphicImportRet nImportRet
= GalleryGraphicImport( rURL
, aGraphic
, aFormat
);
1111 if( nImportRet
!= GalleryGraphicImportRet::IMPORT_NONE
)
1113 if ( GalleryGraphicImportRet::IMPORT_INET
== nImportRet
)
1114 pNewObj
.reset((SgaObject
*) new SgaObjectINet( aGraphic
, rURL
, aFormat
));
1115 else if ( aGraphic
.IsAnimated() )
1116 pNewObj
.reset((SgaObject
*) new SgaObjectAnim( aGraphic
, rURL
, aFormat
));
1118 pNewObj
.reset((SgaObject
*) new SgaObjectBmp( aGraphic
, rURL
, aFormat
));
1120 #if HAVE_FEATURE_AVMEDIA
1121 else if( ::avmedia::MediaWindow::isMediaURL( rURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
), ""/*TODO?*/ ) )
1122 pNewObj
.reset((SgaObject
*) new SgaObjectSound( rURL
));
1124 if( pNewObj
&& InsertObject( *pNewObj
, nInsertPos
) )
1130 bool GalleryTheme::InsertFileOrDirURL( const INetURLObject
& rFileOrDirURL
, sal_uIntPtr nInsertPos
)
1133 ::std::vector
< INetURLObject
> aURLVector
;
1138 ::ucbhelper::Content
aCnt( rFileOrDirURL
.GetMainURL( INetURLObject::NO_DECODE
), uno::Reference
< ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
1139 bool bFolder
= false;
1141 aCnt
.getPropertyValue("IsFolder") >>= bFolder
;
1145 uno::Sequence
< OUString
> aProps( 1 );
1146 aProps
[ 0 ] = "Url";
1147 uno::Reference
< sdbc::XResultSet
> xResultSet( aCnt
.createCursor( aProps
, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY
) );
1148 uno::Reference
< ucb::XContentAccess
> xContentAccess( xResultSet
, uno::UNO_QUERY
);
1149 if( xContentAccess
.is() )
1151 while( xResultSet
->next() )
1153 aURL
.SetSmartURL( xContentAccess
->queryContentIdentifierString() );
1154 aURLVector
.push_back( aURL
);
1159 aURLVector
.push_back( rFileOrDirURL
);
1161 catch( const ucb::ContentCreationException
& )
1164 catch( const uno::RuntimeException
& )
1167 catch( const uno::Exception
& )
1171 ::std::vector
< INetURLObject
>::const_iterator
aIter( aURLVector
.begin() ), aEnd( aURLVector
.end() );
1173 while( aIter
!= aEnd
)
1174 bRet
= bRet
|| InsertURL( *aIter
++, nInsertPos
);
1179 bool GalleryTheme::InsertTransferable( const uno::Reference
< datatransfer::XTransferable
>& rxTransferable
, sal_uIntPtr nInsertPos
)
1183 if( rxTransferable
.is() )
1185 TransferableDataHelper
aDataHelper( rxTransferable
);
1186 boost::scoped_ptr
<Graphic
> pGraphic
;
1188 if( aDataHelper
.HasFormat( SotClipboardFormatId::DRAWING
) )
1190 tools::SvRef
<SotStorageStream
> xModelStm
;
1192 if( aDataHelper
.GetSotStorageStream( SotClipboardFormatId::DRAWING
, xModelStm
) )
1193 bRet
= InsertModelStream( xModelStm
, nInsertPos
);
1195 else if( aDataHelper
.HasFormat( SotClipboardFormatId::FILE_LIST
) ||
1196 aDataHelper
.HasFormat( SotClipboardFormatId::SIMPLE_FILE
) )
1200 if( aDataHelper
.HasFormat( SotClipboardFormatId::FILE_LIST
) )
1201 aDataHelper
.GetFileList( SotClipboardFormatId::FILE_LIST
, aFileList
);
1205 if (aDataHelper
.GetString(SotClipboardFormatId::SIMPLE_FILE
, aFile
) && !aFile
.isEmpty())
1206 aFileList
.AppendFile( aFile
);
1209 for( sal_uInt32 i
= 0, nCount
= aFileList
.Count(); i
< nCount
; ++i
)
1211 const OUString
aFile( aFileList
.GetFile( i
) );
1212 INetURLObject
aURL( aFile
);
1214 if( aURL
.GetProtocol() == INetProtocol::NotValid
)
1218 if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile
, aLocalURL
) )
1219 aURL
= INetURLObject( aLocalURL
);
1222 if( aURL
.GetProtocol() != INetProtocol::NotValid
)
1223 bRet
= InsertFileOrDirURL( aURL
, nInsertPos
);
1229 SotClipboardFormatId nFormat
= SotClipboardFormatId::NONE
;
1231 if( aDataHelper
.HasFormat( SotClipboardFormatId::SVXB
) )
1232 nFormat
= SotClipboardFormatId::SVXB
;
1233 else if( aDataHelper
.HasFormat( SotClipboardFormatId::GDIMETAFILE
) )
1234 nFormat
= SotClipboardFormatId::GDIMETAFILE
;
1235 else if( aDataHelper
.HasFormat( SotClipboardFormatId::BITMAP
) )
1236 nFormat
= SotClipboardFormatId::BITMAP
;
1238 if( nFormat
!= SotClipboardFormatId::NONE
&& aDataHelper
.GetGraphic( nFormat
, aGraphic
) )
1239 pGraphic
.reset(new Graphic( aGraphic
));
1246 if( aDataHelper
.HasFormat( SotClipboardFormatId::SVIM
) )
1251 // according to KA we don't need a BaseURL here
1252 if( aDataHelper
.GetImageMap( SotClipboardFormatId::SVIM
, aImageMap
) )
1254 SvxGalleryDrawModel aModel
;
1256 if( aModel
.GetModel() )
1258 SgaUserDataFactory aFactory
;
1260 SdrPage
* pPage
= aModel
.GetModel()->GetPage(0);
1261 SdrGrafObj
* pGrafObj
= new SdrGrafObj( *pGraphic
);
1263 pGrafObj
->AppendUserData( new SgaIMapInfo( aImageMap
) );
1264 pPage
->InsertObject( pGrafObj
);
1265 bRet
= InsertModel( *aModel
.GetModel(), nInsertPos
);
1271 bRet
= InsertGraphic( *pGraphic
, nInsertPos
);
1278 void GalleryTheme::CopyToClipboard( vcl::Window
* pWindow
, sal_uIntPtr nPos
)
1280 GalleryTransferable
* pTransferable
= new GalleryTransferable( this, nPos
, false );
1281 pTransferable
->CopyToClipboard( pWindow
);
1284 void GalleryTheme::StartDrag( vcl::Window
* pWindow
, sal_uIntPtr nPos
)
1286 GalleryTransferable
* pTransferable
= new GalleryTransferable( this, nPos
, true );
1287 pTransferable
->StartDrag( pWindow
, DND_ACTION_COPY
| DND_ACTION_LINK
);
1290 SvStream
& GalleryTheme::WriteData( SvStream
& rOStm
) const
1292 const INetURLObject
aRelURL1( GetParent()->GetRelativeURL() );
1293 const INetURLObject
aRelURL2( GetParent()->GetUserURL() );
1294 sal_uInt32 nCount
= GetObjectCount();
1297 rOStm
.WriteUInt16( 0x0004 );
1298 write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm
, GetRealName(), RTL_TEXTENCODING_UTF8
);
1299 rOStm
.WriteUInt32( nCount
).WriteUInt16( osl_getThreadTextEncoding() );
1301 for( sal_uInt32 i
= 0; i
< nCount
; i
++ )
1303 const GalleryObject
* pObj
= ImplGetGalleryObject( i
);
1306 if( SGA_OBJ_SVDRAW
== pObj
->eObjKind
)
1308 aPath
= GetSvDrawStreamNameFromURL( pObj
->aURL
);
1313 aPath
= pObj
->aURL
.GetMainURL( INetURLObject::NO_DECODE
);
1314 aPath
= aPath
.copy( 0, std::min(aRelURL1
.GetMainURL( INetURLObject::NO_DECODE
).getLength(), aPath
.getLength()) );
1315 bRel
= aPath
== aRelURL1
.GetMainURL( INetURLObject::NO_DECODE
);
1317 if( bRel
&& ( pObj
->aURL
.GetMainURL( INetURLObject::NO_DECODE
).getLength() > ( aRelURL1
.GetMainURL( INetURLObject::NO_DECODE
).getLength() + 1 ) ) )
1319 aPath
= pObj
->aURL
.GetMainURL( INetURLObject::NO_DECODE
);
1320 aPath
= aPath
.copy( std::min(aRelURL1
.GetMainURL( INetURLObject::NO_DECODE
).getLength(), aPath
.getLength()) );
1324 aPath
= pObj
->aURL
.GetMainURL( INetURLObject::NO_DECODE
);
1325 aPath
= aPath
.copy( 0, std::min(aRelURL2
.GetMainURL( INetURLObject::NO_DECODE
).getLength(), aPath
.getLength()) );
1326 bRel
= aPath
== aRelURL2
.GetMainURL( INetURLObject::NO_DECODE
);
1328 if( bRel
&& ( pObj
->aURL
.GetMainURL( INetURLObject::NO_DECODE
).getLength() > ( aRelURL2
.GetMainURL( INetURLObject::NO_DECODE
).getLength() + 1 ) ) )
1330 aPath
= pObj
->aURL
.GetMainURL( INetURLObject::NO_DECODE
);
1331 aPath
= aPath
.copy( std::min(aRelURL2
.GetMainURL( INetURLObject::NO_DECODE
).getLength(), aPath
.getLength()) );
1334 aPath
= pObj
->aURL
.GetMainURL( INetURLObject::NO_DECODE
);
1338 if ( !m_aDestDir
.isEmpty() )
1340 bool aFound
= aPath
.indexOf(m_aDestDir
) != -1;
1341 aPath
= aPath
.replaceFirst(m_aDestDir
, "");
1343 bRel
= m_bDestDirRelative
;
1345 SAL_WARN( "svx", "failed to replace destdir of '"
1346 << m_aDestDir
<< "' in '" << aPath
<< "'");
1349 rOStm
.WriteBool( bRel
);
1350 write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm
, aPath
, RTL_TEXTENCODING_UTF8
);
1351 rOStm
.WriteUInt32( pObj
->nOffset
).WriteUInt16( pObj
->eObjKind
);
1354 // more recently, a 512-byte reserve buffer is written,
1355 // to recognize them two sal_uIntPtr-Ids will be written.
1356 rOStm
.WriteUInt32( COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) ).WriteUInt32( COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) );
1358 const long nReservePos
= rOStm
.Tell();
1359 boost::scoped_ptr
<VersionCompat
> pCompat(new VersionCompat( rOStm
, StreamMode::WRITE
, 2 ));
1361 rOStm
.WriteUInt32( GetId() ).WriteBool( IsThemeNameFromResource() ); // From version 2 and up
1365 // Fill the rest of the buffer.
1366 const long nRest
= std::max( 512L - ( (long) rOStm
.Tell() - nReservePos
), 0L );
1370 boost::scoped_array
<char> pReserve(new char[ nRest
]);
1371 memset( pReserve
.get(), 0, nRest
);
1372 rOStm
.Write( pReserve
.get(), nRest
);
1378 SvStream
& GalleryTheme::ReadData( SvStream
& rIStm
)
1381 sal_uInt16 nVersion
;
1382 OUString aThemeName
;
1383 rtl_TextEncoding nTextEncoding
;
1385 rIStm
.ReadUInt16( nVersion
);
1386 OString aTmpStr
= read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm
);
1387 rIStm
.ReadUInt32( nCount
);
1389 if( nVersion
>= 0x0004 )
1392 rIStm
.ReadUInt16( nTmp16
);
1393 nTextEncoding
= (rtl_TextEncoding
) nTmp16
;
1396 nTextEncoding
= RTL_TEXTENCODING_UTF8
;
1398 aThemeName
= OStringToOUString(aTmpStr
, nTextEncoding
);
1400 if( nCount
<= ( 1L << 14 ) )
1402 GalleryObject
* pObj
;
1403 INetURLObject
aRelURL1( GetParent()->GetRelativeURL() );
1404 INetURLObject
aRelURL2( GetParent()->GetUserURL() );
1405 sal_uInt32 nId1
, nId2
;
1408 for( size_t i
= 0, n
= aObjectList
.size(); i
< n
; ++i
)
1410 pObj
= aObjectList
[ i
];
1411 Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT
, GetName(), reinterpret_cast< sal_uIntPtr
>( pObj
) ) );
1412 Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED
, GetName(), reinterpret_cast< sal_uIntPtr
>( pObj
) ) );
1415 aObjectList
.clear();
1417 for( sal_uInt32 i
= 0; i
< nCount
; i
++ )
1419 pObj
= new GalleryObject
;
1425 rIStm
.ReadCharAsBool( bRel
);
1426 OString aTempFileName
= read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm
);
1427 rIStm
.ReadUInt32( pObj
->nOffset
);
1428 rIStm
.ReadUInt16( nTemp
); pObj
->eObjKind
= (SgaObjKind
) nTemp
;
1430 aFileName
= OStringToOUString(aTempFileName
, osl_getThreadTextEncoding());
1434 aFileName
= aFileName
.replaceAll( "\\", "/" );
1435 aPath
= aRelURL1
.GetMainURL( INetURLObject::NO_DECODE
);
1437 if( aFileName
[ 0 ] != '/' )
1442 pObj
->aURL
= INetURLObject( aPath
);
1444 if( !FileExists( pObj
->aURL
) )
1446 aPath
= aRelURL2
.GetMainURL( INetURLObject::NO_DECODE
);
1448 if( aFileName
[0] != '/' )
1453 // assign this URL, even in the case it is not valid (#94482)
1454 pObj
->aURL
= INetURLObject( aPath
);
1459 if( SGA_OBJ_SVDRAW
== pObj
->eObjKind
)
1461 OUString
aDummyURL( "gallery/svdraw/" );
1462 pObj
->aURL
= INetURLObject( aDummyURL
+= aFileName
, INetProtocol::PrivSoffice
);
1468 pObj
->aURL
= INetURLObject( aFileName
);
1470 if( ( pObj
->aURL
.GetProtocol() == INetProtocol::NotValid
) &&
1471 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName
, aLocalURL
) )
1473 pObj
->aURL
= INetURLObject( aLocalURL
);
1477 aObjectList
.push_back( pObj
);
1480 rIStm
.ReadUInt32( nId1
).ReadUInt32( nId2
);
1482 // In newer versions a 512 byte reserve buffer is located at the end,
1483 // the data is located at the beginning of this buffer and are clamped
1484 // by a VersionCompat.
1485 if( !rIStm
.IsEof() &&
1486 nId1
== COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
1487 nId2
== COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
1489 boost::scoped_ptr
<VersionCompat
> pCompat(new VersionCompat( rIStm
, StreamMode::READ
));
1491 bool bThemeNameFromResource
= false;
1493 rIStm
.ReadUInt32( nTemp32
);
1495 if( pCompat
->GetVersion() >= 2 )
1497 rIStm
.ReadCharAsBool( bThemeNameFromResource
);
1500 SetId( nTemp32
, bThemeNameFromResource
);
1504 rIStm
.SetError( SVSTREAM_READ_ERROR
);
1506 ImplSetModified( false );
1511 SvStream
& WriteGalleryTheme( SvStream
& rOut
, const GalleryTheme
& rTheme
)
1513 return rTheme
.WriteData( rOut
);
1516 SvStream
& ReadGalleryTheme( SvStream
& rIn
, GalleryTheme
& rTheme
)
1518 return rTheme
.ReadData( rIn
);
1521 void GalleryTheme::ImplSetModified( bool bModified
)
1523 pThm
->SetModified(bModified
);
1526 const OUString
& GalleryTheme::GetRealName() const { return pThm
->GetThemeName(); }
1527 const INetURLObject
& GalleryTheme::GetThmURL() const { return pThm
->GetThmURL(); }
1528 const INetURLObject
& GalleryTheme::GetSdgURL() const { return pThm
->GetSdgURL(); }
1529 const INetURLObject
& GalleryTheme::GetSdvURL() const { return pThm
->GetSdvURL(); }
1530 sal_uInt32
GalleryTheme::GetId() const { return pThm
->GetId(); }
1531 void GalleryTheme::SetId( sal_uInt32 nNewId
, bool bResetThemeName
) { pThm
->SetId( nNewId
, bResetThemeName
); }
1532 bool GalleryTheme::IsThemeNameFromResource() const { return pThm
->IsNameFromResource(); }
1533 bool GalleryTheme::IsReadOnly() const { return pThm
->IsReadOnly(); }
1534 bool GalleryTheme::IsDefault() const { return pThm
->IsDefault(); }
1535 bool GalleryTheme::IsModified() const { return pThm
->IsModified(); }
1537 tools::SvRef
<SotStorage
> GalleryTheme::GetSvDrawStorage() const
1539 return aSvDrawStorageRef
;
1542 const OUString
& GalleryTheme::GetName() const { return pThm
->GetThemeName(); }
1544 void GalleryTheme::InsertAllThemes( ListBox
& rListBox
)
1546 for( sal_uInt16 i
= RID_GALLERYSTR_THEME_FIRST
; i
<= RID_GALLERYSTR_THEME_LAST
; i
++ )
1547 rListBox
.InsertEntry(GAL_RESSTR(i
));
1550 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */