xref: /aoo42x/main/svx/source/gallery2/galtheme.cxx (revision 86e1cf34)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/urlobj.hxx>
30cdf0e10cSrcweir #include <tools/vcompat.hxx>
31cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
32cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
33cdf0e10cSrcweir #include <unotools/tempfile.hxx>
34cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
35cdf0e10cSrcweir #include <ucbhelper/content.hxx>
36cdf0e10cSrcweir #include <sot/storage.hxx>
37cdf0e10cSrcweir #include <sot/formats.hxx>
38cdf0e10cSrcweir #include <sot/filelist.hxx>
39cdf0e10cSrcweir #include <vcl/virdev.hxx>
40cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
41cdf0e10cSrcweir #include <svl/itempool.hxx>
42cdf0e10cSrcweir #include <sfx2/docfile.hxx>
43cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
44cdf0e10cSrcweir #include <svx/svdograf.hxx>
45cdf0e10cSrcweir #include <svx/fmpage.hxx>
46cdf0e10cSrcweir #include "codec.hxx"
47cdf0e10cSrcweir #include <svx/unomodel.hxx>
48cdf0e10cSrcweir #include <svx/fmmodel.hxx>
49cdf0e10cSrcweir #include <svx/fmview.hxx>
50cdf0e10cSrcweir #include "svx/galmisc.hxx"
51cdf0e10cSrcweir #include "svx/galtheme.hxx"
52cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
54cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
55cdf0e10cSrcweir #include "galobj.hxx"
56cdf0e10cSrcweir #include <svx/gallery1.hxx>
57cdf0e10cSrcweir #include "galtheme.hrc"
58cdf0e10cSrcweir #include <vcl/lstbox.hxx>
59cdf0e10cSrcweir #include "gallerydrawmodel.hxx"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // --------------
62cdf0e10cSrcweir // - Namespaces -
63cdf0e10cSrcweir // --------------
64cdf0e10cSrcweir 
65cdf0e10cSrcweir using namespace ::rtl;
66cdf0e10cSrcweir using namespace ::com::sun::star;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // ------------
69cdf0e10cSrcweir // - SgaTheme -
70cdf0e10cSrcweir // ------------
DBG_NAME(GalleryTheme)71cdf0e10cSrcweir DBG_NAME(GalleryTheme)
72cdf0e10cSrcweir 
73cdf0e10cSrcweir GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry ) :
74cdf0e10cSrcweir 		pParent               ( pGallery ),
75cdf0e10cSrcweir 		pThm		          ( pThemeEntry ),
76cdf0e10cSrcweir         mnThemeLockCount      ( 0 ),
77cdf0e10cSrcweir 		mnBroadcasterLockCount( 0 ),
78cdf0e10cSrcweir 		nDragPos	          ( 0 ),
79cdf0e10cSrcweir 		bDragging	          ( sal_False )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     DBG_CTOR(GalleryTheme,NULL);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	ImplCreateSvDrawStorage();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	if( pThm->IsImported() )
86cdf0e10cSrcweir 		aImportName = pThm->GetThemeName();
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // ------------------------------------------------------------------------
90cdf0e10cSrcweir 
~GalleryTheme()91cdf0e10cSrcweir GalleryTheme::~GalleryTheme()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	ImplWrite();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	for( GalleryObject* pEntry = aObjectList.First(); pEntry; pEntry = aObjectList.Next() )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
98cdf0e10cSrcweir 		delete pEntry;
99cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     DBG_DTOR(GalleryTheme,NULL);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir // ------------------------------------------------------------------------
106cdf0e10cSrcweir 
ImplCreateSvDrawStorage()107cdf0e10cSrcweir void GalleryTheme::ImplCreateSvDrawStorage()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	if( !pThm->IsImported() )
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		aSvDrawStorageRef = new SvStorage( sal_False, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), pThm->IsReadOnly() ? STREAM_READ : STREAM_STD_READWRITE );
112cdf0e10cSrcweir 		// #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
113cdf0e10cSrcweir 		if ( ( aSvDrawStorageRef->GetError() != ERRCODE_NONE ) && !pThm->IsReadOnly() )
114cdf0e10cSrcweir 			aSvDrawStorageRef = new SvStorage( sal_False, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 	else
117cdf0e10cSrcweir 		aSvDrawStorageRef.Clear();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // ------------------------------------------------------------------------
121cdf0e10cSrcweir 
ImplWriteSgaObject(const SgaObject & rObj,sal_uIntPtr nPos,GalleryObject * pExistentEntry)122cdf0e10cSrcweir sal_Bool GalleryTheme::ImplWriteSgaObject( const SgaObject& rObj, sal_uIntPtr nPos, GalleryObject* pExistentEntry )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	SvStream*	pOStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
125cdf0e10cSrcweir 	sal_Bool		bRet = sal_False;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	if( pOStm )
128cdf0e10cSrcweir 	{
129cdf0e10cSrcweir 		const sal_uInt32 nOffset = pOStm->Seek( STREAM_SEEK_TO_END );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 		rObj.WriteData( *pOStm, m_aDestDir );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		if( !pOStm->GetError() )
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			GalleryObject* pEntry;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 			if( !pExistentEntry )
138cdf0e10cSrcweir 			{
139cdf0e10cSrcweir 				pEntry = new GalleryObject;
140cdf0e10cSrcweir 				aObjectList.Insert( pEntry, nPos );
141cdf0e10cSrcweir 			}
142cdf0e10cSrcweir 			else
143cdf0e10cSrcweir 				pEntry = pExistentEntry;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			pEntry->aURL = rObj.GetURL();
146cdf0e10cSrcweir 			pEntry->nOffset = nOffset;
147cdf0e10cSrcweir 			pEntry->eObjKind = rObj.GetObjKind();
148cdf0e10cSrcweir 			bRet = sal_True;
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		delete pOStm;
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	return bRet;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // ------------------------------------------------------------------------
158cdf0e10cSrcweir 
ImplReadSgaObject(GalleryObject * pEntry)159cdf0e10cSrcweir SgaObject* GalleryTheme::ImplReadSgaObject( GalleryObject* pEntry )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	SgaObject* pSgaObj = NULL;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	if( pEntry )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		if( pIStm )
168cdf0e10cSrcweir 		{
169cdf0e10cSrcweir 			sal_uInt32 nInventor;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 			// Ueberpruefen, ob das File ein gueltiges SGA-File ist
172cdf0e10cSrcweir 			pIStm->Seek( pEntry->nOffset );
173cdf0e10cSrcweir 			*pIStm >> nInventor;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 			if( nInventor == COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
176cdf0e10cSrcweir 			{
177cdf0e10cSrcweir 				pIStm->Seek( pEntry->nOffset );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 				switch( pEntry->eObjKind )
180cdf0e10cSrcweir 				{
181cdf0e10cSrcweir 					case( SGA_OBJ_BMP ):	pSgaObj = new SgaObjectBmp(); break;
182cdf0e10cSrcweir 					case( SGA_OBJ_ANIM ):	pSgaObj = new SgaObjectAnim(); break;
183cdf0e10cSrcweir 					case( SGA_OBJ_INET ):	pSgaObj = new SgaObjectINet(); break;
184cdf0e10cSrcweir 					case( SGA_OBJ_SVDRAW ):	pSgaObj = new SgaObjectSvDraw(); break;
185cdf0e10cSrcweir 					case( SGA_OBJ_SOUND ):	pSgaObj = new SgaObjectSound(); break;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 					default:
188cdf0e10cSrcweir 					break;
189cdf0e10cSrcweir 				}
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 				if( pSgaObj )
192cdf0e10cSrcweir 				{
193cdf0e10cSrcweir 					*pIStm >> *pSgaObj;
194cdf0e10cSrcweir 					pSgaObj->ImplUpdateURL( pEntry->aURL );
195cdf0e10cSrcweir 				}
196cdf0e10cSrcweir 			}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 			delete pIStm;
199cdf0e10cSrcweir 		}
200cdf0e10cSrcweir 	}
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	return pSgaObj;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir // ------------------------------------------------------------------------
206cdf0e10cSrcweir 
ImplRead()207cdf0e10cSrcweir void GalleryTheme::ImplRead()
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	SvStream* pIStm	= ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	if( pIStm )
212cdf0e10cSrcweir 	{
213cdf0e10cSrcweir 		*pIStm >> *this;
214cdf0e10cSrcweir 		delete pIStm;
215cdf0e10cSrcweir 	}
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir // ------------------------------------------------------------------------
219cdf0e10cSrcweir 
ImplWrite()220cdf0e10cSrcweir void GalleryTheme::ImplWrite()
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	if( IsModified() )
223cdf0e10cSrcweir 	{
224cdf0e10cSrcweir 		INetURLObject aPathURL( GetThmURL() );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 		aPathURL.removeSegment();
227cdf0e10cSrcweir 		aPathURL.removeFinalSlash();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 		DBG_ASSERT( aPathURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 		if( FileExists( aPathURL ) || CreateDir( aPathURL ) )
232cdf0e10cSrcweir 		{
233cdf0e10cSrcweir #ifdef UNX
234cdf0e10cSrcweir 			SvStream* pOStm	= ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_COPY_ON_SYMLINK | STREAM_TRUNC );
235cdf0e10cSrcweir #else
236cdf0e10cSrcweir 			SvStream* pOStm	= ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
237cdf0e10cSrcweir #endif
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 			if( pOStm )
240cdf0e10cSrcweir 			{
241cdf0e10cSrcweir 				*pOStm << *this;
242cdf0e10cSrcweir 				delete pOStm;
243cdf0e10cSrcweir 			}
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 			ImplSetModified( sal_False );
246cdf0e10cSrcweir 		}
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir // ------------------------------------------------------------------------
251cdf0e10cSrcweir 
ImplGetGalleryObject(const INetURLObject & rURL)252cdf0e10cSrcweir const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	GalleryObject*	pEntry = aObjectList.First();
255cdf0e10cSrcweir 	GalleryObject*	pFoundEntry = NULL;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	for( ; pEntry && !pFoundEntry; pEntry = aObjectList.Next() )
258cdf0e10cSrcweir 		if( pEntry->aURL == rURL )
259cdf0e10cSrcweir 			pFoundEntry = pEntry;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	return pFoundEntry;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir // ------------------------------------------------------------------------
265cdf0e10cSrcweir 
ImplGetURL(const GalleryObject * pObject) const266cdf0e10cSrcweir INetURLObject GalleryTheme::ImplGetURL( const GalleryObject* pObject ) const
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	INetURLObject aURL;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	if( pObject )
271cdf0e10cSrcweir 	{
272cdf0e10cSrcweir 		if( IsImported() )
273cdf0e10cSrcweir 		{
274cdf0e10cSrcweir 			INetURLObject aPathURL( GetParent()->GetImportURL( GetName() ) );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 			aPathURL.removeSegment();
277cdf0e10cSrcweir 			aPathURL.removeFinalSlash();
278cdf0e10cSrcweir 			aPathURL.Append( pObject->aURL.GetName() );
279cdf0e10cSrcweir 			aURL = aPathURL;
280cdf0e10cSrcweir 		}
281cdf0e10cSrcweir 		else
282cdf0e10cSrcweir 			aURL = pObject->aURL;
283cdf0e10cSrcweir 	}
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	return aURL;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // ------------------------------------------------------------------------
289cdf0e10cSrcweir 
ImplCreateUniqueURL(SgaObjKind eObjKind,sal_uIntPtr nFormat)290cdf0e10cSrcweir INetURLObject GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind, sal_uIntPtr nFormat )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir     INetURLObject   aDir( GetParent()->GetUserURL() );
293cdf0e10cSrcweir     INetURLObject   aInfoFileURL( GetParent()->GetUserURL() );
294cdf0e10cSrcweir     INetURLObject   aNewURL;
295cdf0e10cSrcweir 	sal_uInt32		nNextNumber = 1999;
296cdf0e10cSrcweir     sal_Char const* pExt = NULL;
297cdf0e10cSrcweir     sal_Bool            bExists;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir     aDir.Append( String( RTL_CONSTASCII_USTRINGPARAM( "dragdrop" ) ) );
300cdf0e10cSrcweir     CreateDir( aDir );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	aInfoFileURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "sdddndx1" ) ) );
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 	// read next possible number
305cdf0e10cSrcweir     if( FileExists( aInfoFileURL ) )
306cdf0e10cSrcweir 	{
307cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		if( pIStm )
310cdf0e10cSrcweir 		{
311cdf0e10cSrcweir 			*pIStm >> nNextNumber;
312cdf0e10cSrcweir 			delete pIStm;
313cdf0e10cSrcweir 		}
314cdf0e10cSrcweir 	}
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     // create extension
317cdf0e10cSrcweir     if( nFormat )
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         switch( nFormat )
320cdf0e10cSrcweir         {
321cdf0e10cSrcweir             case( CVT_BMP ): pExt = ".bmp"; break;
322cdf0e10cSrcweir             case( CVT_GIF ): pExt = ".gif"; break;
323cdf0e10cSrcweir             case( CVT_JPG ): pExt = ".jpg"; break;
324cdf0e10cSrcweir             case( CVT_MET ): pExt = ".met"; break;
325cdf0e10cSrcweir             case( CVT_PCT ): pExt = ".pct"; break;
326cdf0e10cSrcweir             case( CVT_PNG ): pExt = ".png"; break;
327cdf0e10cSrcweir             case( CVT_SVM ): pExt = ".svm"; break;
328cdf0e10cSrcweir             case( CVT_TIF ): pExt = ".tif"; break;
329cdf0e10cSrcweir             case( CVT_WMF ): pExt = ".wmf"; break;
330cdf0e10cSrcweir             case( CVT_EMF ): pExt = ".emf"; break;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir             default:
333cdf0e10cSrcweir                 pExt = ".grf";
334cdf0e10cSrcweir             break;
335cdf0e10cSrcweir         }
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     do
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         // get URL
341cdf0e10cSrcweir 	    if( SGA_OBJ_SVDRAW == eObjKind )
342cdf0e10cSrcweir 	    {
343cdf0e10cSrcweir             String aFileName( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/dd" ) );
344cdf0e10cSrcweir 		    aNewURL = INetURLObject( aFileName += String::CreateFromInt32( ++nNextNumber % 99999999 ), INET_PROT_PRIV_SOFFICE );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir             bExists = sal_False;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 		    for( GalleryObject* pEntry = aObjectList.First(); pEntry && !bExists; pEntry = aObjectList.Next() )
349cdf0e10cSrcweir 			    if( pEntry->aURL == aNewURL )
350cdf0e10cSrcweir                     bExists = sal_True;
351cdf0e10cSrcweir 	    }
352cdf0e10cSrcweir 	    else
353cdf0e10cSrcweir 	    {
354cdf0e10cSrcweir             String aFileName( RTL_CONSTASCII_USTRINGPARAM( "dd" ) );
355cdf0e10cSrcweir 
356cdf0e10cSrcweir             aFileName += String::CreateFromInt32( ++nNextNumber % 999999 );
357cdf0e10cSrcweir             aFileName += String( pExt, RTL_TEXTENCODING_ASCII_US );
358cdf0e10cSrcweir 
359cdf0e10cSrcweir             aNewURL = aDir;
360cdf0e10cSrcweir 		    aNewURL.Append( aFileName );
361cdf0e10cSrcweir 
362cdf0e10cSrcweir             bExists = FileExists( aNewURL );
363cdf0e10cSrcweir 	    }
364cdf0e10cSrcweir     }
365cdf0e10cSrcweir     while( bExists );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 	// write updated number
368cdf0e10cSrcweir     SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	if( pOStm )
371cdf0e10cSrcweir 	{
372cdf0e10cSrcweir 		*pOStm << nNextNumber;
373cdf0e10cSrcweir 		delete pOStm;
374cdf0e10cSrcweir 	}
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 	return aNewURL;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir // ------------------------------------------------------------------------
380cdf0e10cSrcweir 
ImplBroadcast(sal_uIntPtr nUpdatePos)381cdf0e10cSrcweir void GalleryTheme::ImplBroadcast( sal_uIntPtr nUpdatePos )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir 	if( !IsBroadcasterLocked() )
384cdf0e10cSrcweir 	{
385cdf0e10cSrcweir 		if( GetObjectCount() && ( nUpdatePos >= GetObjectCount() ) )
386cdf0e10cSrcweir 			nUpdatePos = GetObjectCount() - 1;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_THEME_UPDATEVIEW, GetName(), nUpdatePos ) );
389cdf0e10cSrcweir 	}
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir // ------------------------------------------------------------------------
393cdf0e10cSrcweir 
UnlockTheme()394cdf0e10cSrcweir sal_Bool GalleryTheme::UnlockTheme()
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     DBG_ASSERT( mnThemeLockCount, "Theme is not locked" );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     sal_Bool bRet = sal_False;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     if( mnThemeLockCount )
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         --mnThemeLockCount;
403cdf0e10cSrcweir         bRet = sal_True;
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     return bRet;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir // ------------------------------------------------------------------------
410cdf0e10cSrcweir 
UnlockBroadcaster(sal_uIntPtr nUpdatePos)411cdf0e10cSrcweir void GalleryTheme::UnlockBroadcaster( sal_uIntPtr nUpdatePos )
412cdf0e10cSrcweir {
413cdf0e10cSrcweir 	DBG_ASSERT( mnBroadcasterLockCount, "Broadcaster is not locked" );
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	if( mnBroadcasterLockCount && !--mnBroadcasterLockCount )
416cdf0e10cSrcweir 		ImplBroadcast( nUpdatePos );
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir // ------------------------------------------------------------------------
420cdf0e10cSrcweir 
InsertObject(const SgaObject & rObj,sal_uIntPtr nInsertPos)421cdf0e10cSrcweir sal_Bool GalleryTheme::InsertObject( const SgaObject& rObj, sal_uIntPtr nInsertPos )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	if( rObj.IsValid() )
426cdf0e10cSrcweir 	{
427cdf0e10cSrcweir 		GalleryObject*	pEntry = aObjectList.First();
428cdf0e10cSrcweir 		GalleryObject*	pFoundEntry = NULL;
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 		for( ; pEntry && !pFoundEntry; pEntry = aObjectList.Next() )
431cdf0e10cSrcweir 			if( pEntry->aURL == rObj.GetURL() )
432cdf0e10cSrcweir 				pFoundEntry = pEntry;
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 		if( pFoundEntry )
435cdf0e10cSrcweir         {
436cdf0e10cSrcweir     		GalleryObject aNewEntry;
437cdf0e10cSrcweir 
438*86e1cf34SPedro Giffuni             // update title of new object if necessary
439cdf0e10cSrcweir             if( !rObj.GetTitle().Len() )
440cdf0e10cSrcweir             {
441cdf0e10cSrcweir                 SgaObject* pOldObj = ImplReadSgaObject( pFoundEntry );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir                 if( pOldObj )
444cdf0e10cSrcweir                 {
445cdf0e10cSrcweir                     ( (SgaObject&) rObj ).SetTitle( pOldObj->GetTitle() );
446cdf0e10cSrcweir                     delete pOldObj;
447cdf0e10cSrcweir                 }
448cdf0e10cSrcweir             }
449cdf0e10cSrcweir             else if( rObj.GetTitle() == String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) ) )
450cdf0e10cSrcweir                 ( (SgaObject&) rObj ).SetTitle( String() );
451cdf0e10cSrcweir 
452cdf0e10cSrcweir             ImplWriteSgaObject( rObj, nInsertPos, &aNewEntry );
453cdf0e10cSrcweir 			pFoundEntry->nOffset = aNewEntry.nOffset;
454cdf0e10cSrcweir         }
455cdf0e10cSrcweir 		else
456cdf0e10cSrcweir 			ImplWriteSgaObject( rObj, nInsertPos, NULL );
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 		ImplSetModified( bRet = sal_True );
459cdf0e10cSrcweir 		ImplBroadcast( pFoundEntry ? aObjectList.GetPos( pFoundEntry ) : nInsertPos );
460cdf0e10cSrcweir 	}
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 	return bRet;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir // ------------------------------------------------------------------------
466cdf0e10cSrcweir 
AcquireObject(sal_uIntPtr nPos)467cdf0e10cSrcweir SgaObject* GalleryTheme::AcquireObject( sal_uIntPtr nPos )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	return ImplReadSgaObject( aObjectList.GetObject( nPos ) );
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir // ------------------------------------------------------------------------
473cdf0e10cSrcweir 
GetPreviewBitmapExAndStrings(sal_uIntPtr nPos,BitmapEx & rBitmapEx,Size & rSize,String & rTitle,String & rPath) const47421b36550SArmin Le Grand void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uIntPtr nPos, BitmapEx& rBitmapEx, Size& rSize, String& rTitle, String& rPath) const
47521b36550SArmin Le Grand {
47621b36550SArmin Le Grand     const GalleryObject* pGalleryObject = aObjectList.GetObject(nPos);
47721b36550SArmin Le Grand 
47821b36550SArmin Le Grand     if(pGalleryObject)
47921b36550SArmin Le Grand     {
48021b36550SArmin Le Grand         rBitmapEx = pGalleryObject->maPreviewBitmapEx;
48121b36550SArmin Le Grand         rSize = pGalleryObject->maPreparedSize;
48221b36550SArmin Le Grand         rTitle = pGalleryObject->maTitle;
48321b36550SArmin Le Grand         rPath = pGalleryObject->maPath;
48421b36550SArmin Le Grand     }
48521b36550SArmin Le Grand     else
48621b36550SArmin Le Grand     {
48721b36550SArmin Le Grand         OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
48821b36550SArmin Le Grand     }
48921b36550SArmin Le Grand }
49021b36550SArmin Le Grand 
49121b36550SArmin Le Grand // ------------------------------------------------------------------------
49221b36550SArmin Le Grand 
SetPreviewBitmapExAndStrings(sal_uIntPtr nPos,const BitmapEx & rBitmapEx,const Size & rSize,const String & rTitle,const String & rPath)49321b36550SArmin Le Grand void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uIntPtr nPos, const BitmapEx& rBitmapEx, const Size& rSize, const String& rTitle, const String& rPath)
49421b36550SArmin Le Grand {
49521b36550SArmin Le Grand     GalleryObject* pGalleryObject = aObjectList.GetObject(nPos);
49621b36550SArmin Le Grand 
49721b36550SArmin Le Grand     if(pGalleryObject)
49821b36550SArmin Le Grand     {
49921b36550SArmin Le Grand         pGalleryObject->maPreviewBitmapEx = rBitmapEx;
50021b36550SArmin Le Grand         pGalleryObject->maPreparedSize = rSize;
50121b36550SArmin Le Grand         pGalleryObject->maTitle = rTitle;
50221b36550SArmin Le Grand         pGalleryObject->maPath = rPath;
50321b36550SArmin Le Grand     }
50421b36550SArmin Le Grand     else
50521b36550SArmin Le Grand     {
50621b36550SArmin Le Grand         OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
50721b36550SArmin Le Grand     }
50821b36550SArmin Le Grand }
50921b36550SArmin Le Grand 
51021b36550SArmin Le Grand // ------------------------------------------------------------------------
51121b36550SArmin Le Grand 
ReleaseObject(SgaObject * pObject)512cdf0e10cSrcweir void GalleryTheme::ReleaseObject( SgaObject* pObject )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir 	delete pObject;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir // ------------------------------------------------------------------------
518cdf0e10cSrcweir 
RemoveObject(sal_uIntPtr nPos)519cdf0e10cSrcweir sal_Bool GalleryTheme::RemoveObject( sal_uIntPtr nPos )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir 	GalleryObject* pEntry = aObjectList.Remove( nPos );
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 	if( !aObjectList.Count() )
524cdf0e10cSrcweir 		KillFile( GetSdgURL() );
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 	if( pEntry )
527cdf0e10cSrcweir 	{
528cdf0e10cSrcweir 		if( SGA_OBJ_SVDRAW == pEntry->eObjKind )
529cdf0e10cSrcweir 			aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
532cdf0e10cSrcweir 		delete pEntry;
533cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 		ImplSetModified( sal_True );
536cdf0e10cSrcweir 		ImplBroadcast( nPos );
537cdf0e10cSrcweir 	}
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 	return( pEntry != NULL );
540cdf0e10cSrcweir }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir // ------------------------------------------------------------------------
543cdf0e10cSrcweir 
ChangeObjectPos(sal_uIntPtr nOldPos,sal_uIntPtr nNewPos)544cdf0e10cSrcweir sal_Bool GalleryTheme::ChangeObjectPos( sal_uIntPtr nOldPos, sal_uIntPtr nNewPos )
545cdf0e10cSrcweir {
546cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 	if( nOldPos != nNewPos )
549cdf0e10cSrcweir 	{
550cdf0e10cSrcweir 		GalleryObject* pEntry = aObjectList.GetObject( nOldPos );
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 		if( pEntry )
553cdf0e10cSrcweir 		{
554cdf0e10cSrcweir 			aObjectList.Insert( pEntry, nNewPos );
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 			if( nNewPos < nOldPos )
557cdf0e10cSrcweir 				nOldPos++;
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 			aObjectList.Remove( nOldPos );
560cdf0e10cSrcweir 			ImplSetModified( bRet = sal_True );
561cdf0e10cSrcweir 			ImplBroadcast( ( nNewPos < nOldPos ) ? nNewPos : ( nNewPos - 1 ) );
562cdf0e10cSrcweir 		}
563cdf0e10cSrcweir 	}
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 	return bRet;
566cdf0e10cSrcweir }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir // ------------------------------------------------------------------------
569cdf0e10cSrcweir 
Actualize(const Link & rActualizeLink,GalleryProgress * pProgress)570cdf0e10cSrcweir void GalleryTheme::Actualize( const Link& rActualizeLink, GalleryProgress* pProgress )
571cdf0e10cSrcweir {
572cdf0e10cSrcweir 	if( !IsReadOnly() && !IsImported() )
573cdf0e10cSrcweir 	{
574cdf0e10cSrcweir 		Graphic			aGraphic;
575cdf0e10cSrcweir 		String			aFormat;
576cdf0e10cSrcweir 		GalleryObject*	pEntry;
577cdf0e10cSrcweir 		const sal_uIntPtr		nCount = aObjectList.Count();
578cdf0e10cSrcweir 		sal_uIntPtr			i;
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 		LockBroadcaster();
581cdf0e10cSrcweir 		bAbortActualize = sal_False;
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 		// LoeschFlag zuruecksetzen
584cdf0e10cSrcweir 		for ( i = 0; i < nCount; i++ )
58521b36550SArmin Le Grand 			aObjectList.GetObject( i )->mbDelete = false;
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 		for( i = 0; ( i < nCount ) && !bAbortActualize; i++ )
588cdf0e10cSrcweir 		{
589cdf0e10cSrcweir 			if( pProgress )
590cdf0e10cSrcweir 				pProgress->Update( i, nCount - 1 );
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 			pEntry = aObjectList.GetObject( i );
593cdf0e10cSrcweir 
594cdf0e10cSrcweir             const INetURLObject aURL( pEntry->aURL );
595cdf0e10cSrcweir 
596cdf0e10cSrcweir             rActualizeLink.Call( (void*) &aURL );
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 			// SvDraw-Objekte werden spaeter aktualisiert
599cdf0e10cSrcweir 			if( pEntry->eObjKind != SGA_OBJ_SVDRAW )
600cdf0e10cSrcweir 			{
601cdf0e10cSrcweir 				// Hier muss noch etwas eingebaut werden,
602cdf0e10cSrcweir 				// das Files auf den ensprechenden Eintrag matched
603cdf0e10cSrcweir 				// Grafiken als Grafik-Objekte in die Gallery aufnehmen
604cdf0e10cSrcweir 				if( pEntry->eObjKind == SGA_OBJ_SOUND )
605cdf0e10cSrcweir 				{
606cdf0e10cSrcweir 					SgaObjectSound aObjSound( aURL );
607cdf0e10cSrcweir 					if( !InsertObject( aObjSound ) )
60821b36550SArmin Le Grand 						pEntry->mbDelete = true;
609cdf0e10cSrcweir 				}
610cdf0e10cSrcweir 				else
611cdf0e10cSrcweir 				{
612cdf0e10cSrcweir 					aGraphic.Clear();
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 					if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) )
615cdf0e10cSrcweir 					{
616cdf0e10cSrcweir 						SgaObject* pNewObj;
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 						if ( SGA_OBJ_INET == pEntry->eObjKind )
619cdf0e10cSrcweir 							pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, aURL, aFormat );
620cdf0e10cSrcweir 						else if ( aGraphic.IsAnimated() )
621cdf0e10cSrcweir 							pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, aURL, aFormat );
622cdf0e10cSrcweir 						else
623cdf0e10cSrcweir 							pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, aURL, aFormat );
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 						if( !InsertObject( *pNewObj ) )
62621b36550SArmin Le Grand 							pEntry->mbDelete = true;
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 						delete pNewObj;
629cdf0e10cSrcweir 					}
630cdf0e10cSrcweir 					else
63121b36550SArmin Le Grand 						pEntry->mbDelete = true; // Loesch-Flag setzen
632cdf0e10cSrcweir 				}
633cdf0e10cSrcweir 			}
634cdf0e10cSrcweir 			else
635cdf0e10cSrcweir 			{
636cdf0e10cSrcweir 				if ( aSvDrawStorageRef.Is() )
637cdf0e10cSrcweir 				{
638cdf0e10cSrcweir 					const String		aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
639cdf0e10cSrcweir 					SvStorageStreamRef	pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, STREAM_READ );
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 					if( pIStm && !pIStm->GetError() )
642cdf0e10cSrcweir 					{
643cdf0e10cSrcweir 						pIStm->SetBufferSize( 16384 );
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 						SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL );
646cdf0e10cSrcweir 
647cdf0e10cSrcweir                         if( !InsertObject( aNewObj ) )
64821b36550SArmin Le Grand 							pEntry->mbDelete = true;
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 						pIStm->SetBufferSize( 0L );
651cdf0e10cSrcweir 					}
652cdf0e10cSrcweir 				}
653cdf0e10cSrcweir 			}
654cdf0e10cSrcweir 		}
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 		// remove all entries with set flag
657cdf0e10cSrcweir 		pEntry = aObjectList.First();
658cdf0e10cSrcweir 		while( pEntry )
659cdf0e10cSrcweir 		{
66021b36550SArmin Le Grand 			if( pEntry->mbDelete )
661cdf0e10cSrcweir 			{
662cdf0e10cSrcweir 				Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
663cdf0e10cSrcweir 				delete aObjectList.Remove( pEntry );
664cdf0e10cSrcweir 				Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 				pEntry = aObjectList.GetCurObject();
667cdf0e10cSrcweir 			}
668cdf0e10cSrcweir 			else
669cdf0e10cSrcweir 				pEntry = aObjectList.Next();
670cdf0e10cSrcweir 		}
671cdf0e10cSrcweir 
672cdf0e10cSrcweir 		// update theme
673cdf0e10cSrcweir 		::utl::TempFile	aTmp;
674cdf0e10cSrcweir 		INetURLObject	aInURL( GetSdgURL() );
675cdf0e10cSrcweir 		INetURLObject	aTmpURL( aTmp.GetURL() );
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 		DBG_ASSERT( aInURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
678cdf0e10cSrcweir 		DBG_ASSERT( aTmpURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
681cdf0e10cSrcweir 		SvStream* pTmpStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 		if( pIStm && pTmpStm )
684cdf0e10cSrcweir 		{
685cdf0e10cSrcweir 			pEntry = aObjectList.First();
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 			while( pEntry )
688cdf0e10cSrcweir 			{
689cdf0e10cSrcweir 				SgaObject* pObj;
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 				switch( pEntry->eObjKind )
692cdf0e10cSrcweir 				{
693cdf0e10cSrcweir 					case( SGA_OBJ_BMP ):	pObj = new SgaObjectBmp(); break;
694cdf0e10cSrcweir 					case( SGA_OBJ_ANIM ):	pObj = new SgaObjectAnim(); break;
695cdf0e10cSrcweir 					case( SGA_OBJ_INET ):	pObj = new SgaObjectINet(); break;
696cdf0e10cSrcweir 					case( SGA_OBJ_SVDRAW ):	pObj = new SgaObjectSvDraw(); break;
697cdf0e10cSrcweir 					case (SGA_OBJ_SOUND):	pObj = new SgaObjectSound(); break;
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 					default:
700cdf0e10cSrcweir 						pObj = NULL;
701cdf0e10cSrcweir 					break;
702cdf0e10cSrcweir 				}
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 				if( pObj )
705cdf0e10cSrcweir 				{
706cdf0e10cSrcweir 					pIStm->Seek( pEntry->nOffset );
707cdf0e10cSrcweir 					*pIStm >> *pObj;
708cdf0e10cSrcweir 					pEntry->nOffset = pTmpStm->Tell();
709cdf0e10cSrcweir 					*pTmpStm << *pObj;
710cdf0e10cSrcweir 					delete pObj;
711cdf0e10cSrcweir 				}
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 				pEntry = aObjectList.Next();
714cdf0e10cSrcweir 			}
715cdf0e10cSrcweir 		}
716cdf0e10cSrcweir 		else
717cdf0e10cSrcweir 		{
718cdf0e10cSrcweir 			DBG_ERROR( "File(s) could not be opened" );
719cdf0e10cSrcweir 		}
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 		delete pIStm;
722cdf0e10cSrcweir 		delete pTmpStm;
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 		CopyFile( aTmpURL, aInURL );
725cdf0e10cSrcweir 		KillFile( aTmpURL );
726cdf0e10cSrcweir 
727cdf0e10cSrcweir 		sal_uIntPtr nStorErr = 0;
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 		{
730cdf0e10cSrcweir 			SvStorageRef aTempStorageRef( new SvStorage( sal_False, aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READWRITE ) );
731cdf0e10cSrcweir 			aSvDrawStorageRef->CopyTo( aTempStorageRef );
732cdf0e10cSrcweir 			nStorErr = aSvDrawStorageRef->GetError();
733cdf0e10cSrcweir 		}
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 		if( !nStorErr )
736cdf0e10cSrcweir 		{
737cdf0e10cSrcweir 			aSvDrawStorageRef.Clear();
738cdf0e10cSrcweir 			CopyFile( aTmpURL, GetSdvURL() );
739cdf0e10cSrcweir 			ImplCreateSvDrawStorage();
740cdf0e10cSrcweir 		}
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 		KillFile( aTmpURL );
743cdf0e10cSrcweir 		ImplSetModified( sal_True );
744cdf0e10cSrcweir 		ImplWrite();
745cdf0e10cSrcweir 		UnlockBroadcaster();
746cdf0e10cSrcweir 	}
747cdf0e10cSrcweir }
748cdf0e10cSrcweir 
749cdf0e10cSrcweir // ------------------------------------------------------------------------
750cdf0e10cSrcweir 
CreateThemeEntry(const INetURLObject & rURL,sal_Bool bReadOnly)751cdf0e10cSrcweir GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sal_Bool bReadOnly )
752cdf0e10cSrcweir {
753cdf0e10cSrcweir 	DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
754cdf0e10cSrcweir 
755cdf0e10cSrcweir 	GalleryThemeEntry*	pRet = NULL;
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 	if( FileExists( rURL ) )
758cdf0e10cSrcweir 	{
759cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 		if( pIStm )
762cdf0e10cSrcweir 		{
763cdf0e10cSrcweir 			String			aThemeName;
764cdf0e10cSrcweir 			sal_uInt32		nThemeId = 0;
765cdf0e10cSrcweir 			sal_uInt16		nVersion;
766cdf0e10cSrcweir 			sal_Bool			bThemeNameFromResource = sal_False;
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 			*pIStm >> nVersion;
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 			if( nVersion <= 0x00ff )
771cdf0e10cSrcweir 			{
772cdf0e10cSrcweir 				ByteString aTmpStr;
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 				*pIStm >> aTmpStr; aThemeName = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 				// Charakterkonvertierung durchfuehren
777cdf0e10cSrcweir 				if( nVersion >= 0x0004 )
778cdf0e10cSrcweir 				{
779cdf0e10cSrcweir 					sal_uInt32	nCount;
780cdf0e10cSrcweir 					sal_uInt16	nTemp16;
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 					*pIStm >> nCount >> nTemp16;
783cdf0e10cSrcweir 					pIStm->Seek( STREAM_SEEK_TO_END );
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 					// pruefen, ob es sich um eine neuere Version handelt;
786cdf0e10cSrcweir 					// daher um 520Bytes (8Bytes Kennung + 512Bytes Reserverpuffer ) zurueckspringen,
787cdf0e10cSrcweir 					// falls dies ueberhaupt moeglich ist
788cdf0e10cSrcweir 					if( pIStm->Tell() >= 520 )
789cdf0e10cSrcweir 					{
790cdf0e10cSrcweir 						sal_uInt32 nId1, nId2;
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 						pIStm->SeekRel( -520 );
793cdf0e10cSrcweir 						*pIStm >> nId1 >> nId2;
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 						if( nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
796cdf0e10cSrcweir 							nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
797cdf0e10cSrcweir 						{
798cdf0e10cSrcweir 							VersionCompat* pCompat = new VersionCompat( *pIStm, STREAM_READ );
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 							*pIStm >> nThemeId;
801cdf0e10cSrcweir 
802cdf0e10cSrcweir 							if( pCompat->GetVersion() >= 2 )
803cdf0e10cSrcweir 							{
804cdf0e10cSrcweir 								*pIStm >> bThemeNameFromResource;
805cdf0e10cSrcweir 							}
806cdf0e10cSrcweir 
807cdf0e10cSrcweir 							delete pCompat;
808cdf0e10cSrcweir 						}
809cdf0e10cSrcweir 					}
810cdf0e10cSrcweir 				}
811cdf0e10cSrcweir 
812cdf0e10cSrcweir 				INetURLObject aPathURL( rURL );
813cdf0e10cSrcweir 
814cdf0e10cSrcweir 				aPathURL.removeSegment();
815cdf0e10cSrcweir 				aPathURL.removeFinalSlash();
816cdf0e10cSrcweir 				pRet = new GalleryThemeEntry( aPathURL, aThemeName,
817cdf0e10cSrcweir 											  String(rURL.GetBase()).Copy( 2, 6 ).ToInt32(),
818cdf0e10cSrcweir 											  bReadOnly, sal_False, sal_False, nThemeId,
819cdf0e10cSrcweir 											  bThemeNameFromResource );
820cdf0e10cSrcweir 			}
821cdf0e10cSrcweir 
822cdf0e10cSrcweir 			delete pIStm;
823cdf0e10cSrcweir 		}
824cdf0e10cSrcweir 	}
825cdf0e10cSrcweir 
826cdf0e10cSrcweir 	return pRet;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir 
829cdf0e10cSrcweir // -----------------------------------------------------------------------------
830cdf0e10cSrcweir 
GetThumb(sal_uIntPtr nPos,BitmapEx & rBmp,sal_Bool)8316dd94783SArmin Le Grand sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, BitmapEx& rBmp, sal_Bool )
832cdf0e10cSrcweir {
833cdf0e10cSrcweir 	SgaObject*	pObj = AcquireObject( nPos );
834cdf0e10cSrcweir 	sal_Bool		bRet = sal_False;
835cdf0e10cSrcweir 
836cdf0e10cSrcweir 	if( pObj )
837cdf0e10cSrcweir 	{
838cdf0e10cSrcweir 		rBmp = pObj->GetThumbBmp();
839cdf0e10cSrcweir 		ReleaseObject( pObj );
840cdf0e10cSrcweir 		bRet = sal_True;
841cdf0e10cSrcweir 	}
842cdf0e10cSrcweir 
843cdf0e10cSrcweir 	return bRet;
844cdf0e10cSrcweir }
845cdf0e10cSrcweir 
846cdf0e10cSrcweir // -----------------------------------------------------------------------------
847cdf0e10cSrcweir 
GetGraphic(sal_uIntPtr nPos,Graphic & rGraphic,sal_Bool bProgress)848cdf0e10cSrcweir sal_Bool GalleryTheme::GetGraphic( sal_uIntPtr nPos, Graphic& rGraphic, sal_Bool bProgress )
849cdf0e10cSrcweir {
850cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
851cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
852cdf0e10cSrcweir 
853cdf0e10cSrcweir 	if( pObject )
854cdf0e10cSrcweir 	{
855cdf0e10cSrcweir 		const INetURLObject aURL( ImplGetURL( pObject ) );
856cdf0e10cSrcweir 
857cdf0e10cSrcweir 		switch( pObject->eObjKind )
858cdf0e10cSrcweir 		{
859cdf0e10cSrcweir 			case( SGA_OBJ_BMP ):
860cdf0e10cSrcweir 			case( SGA_OBJ_ANIM ):
861cdf0e10cSrcweir 			case( SGA_OBJ_INET ):
862cdf0e10cSrcweir 			{
863cdf0e10cSrcweir 				String aFilterDummy;
864cdf0e10cSrcweir 				bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy, bProgress ) != SGA_IMPORT_NONE );
865cdf0e10cSrcweir 			}
866cdf0e10cSrcweir 			break;
867cdf0e10cSrcweir 
868cdf0e10cSrcweir 			case( SGA_OBJ_SVDRAW ):
869cdf0e10cSrcweir 			{
870cdf0e10cSrcweir                 SvxGalleryDrawModel aModel;
871cdf0e10cSrcweir 
872cdf0e10cSrcweir                 if( aModel.GetModel() )
873cdf0e10cSrcweir                 {
874cdf0e10cSrcweir 				    if( GetModel( nPos, *aModel.GetModel(), bProgress ) )
875cdf0e10cSrcweir 				    {
876cdf0e10cSrcweir 					    ImageMap aIMap;
877cdf0e10cSrcweir 
878cdf0e10cSrcweir 					    if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
879cdf0e10cSrcweir 						    bRet = sal_True;
880cdf0e10cSrcweir 					    else
881cdf0e10cSrcweir 					    {
882cdf0e10cSrcweir 						    VirtualDevice aVDev;
883cdf0e10cSrcweir 						    aVDev.SetMapMode( MapMode( MAP_100TH_MM ) );
884cdf0e10cSrcweir 						    FmFormView aView( aModel.GetModel(), &aVDev );
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 						    aView.hideMarkHandles();
887cdf0e10cSrcweir 						    aView.ShowSdrPage(aView.GetModel()->GetPage(0));
888cdf0e10cSrcweir 						    aView.MarkAll();
889cdf0e10cSrcweir 						    rGraphic = aView.GetAllMarkedGraphic();
890cdf0e10cSrcweir 						    bRet = sal_True;
891cdf0e10cSrcweir 					    }
892cdf0e10cSrcweir 				    }
893cdf0e10cSrcweir                 }
894cdf0e10cSrcweir 			}
895cdf0e10cSrcweir 			break;
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 			case( SGA_OBJ_SOUND ):
898cdf0e10cSrcweir 			{
899cdf0e10cSrcweir 				SgaObject* pObj = AcquireObject( nPos );
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 				if( pObj )
902cdf0e10cSrcweir 				{
9036dd94783SArmin Le Grand                     rGraphic = pObj->GetThumbBmp();
9046dd94783SArmin Le Grand 					//Bitmap aBmp( pObj->GetThumbBmp() );
9056dd94783SArmin Le Grand 					//aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
9066dd94783SArmin Le Grand 					//rGraphic = aBmp;
907cdf0e10cSrcweir 					ReleaseObject( pObj );
908cdf0e10cSrcweir 					bRet = sal_True;
909cdf0e10cSrcweir 				}
910cdf0e10cSrcweir 			}
911cdf0e10cSrcweir 			break;
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 			default:
914cdf0e10cSrcweir 			break;
915cdf0e10cSrcweir 		}
916cdf0e10cSrcweir 	}
917cdf0e10cSrcweir 
918cdf0e10cSrcweir 	return bRet;
919cdf0e10cSrcweir }
920cdf0e10cSrcweir 
921cdf0e10cSrcweir // -----------------------------------------------------------------------------
922cdf0e10cSrcweir 
InsertGraphic(const Graphic & rGraphic,sal_uIntPtr nInsertPos)923cdf0e10cSrcweir sal_Bool GalleryTheme::InsertGraphic( const Graphic& rGraphic, sal_uIntPtr nInsertPos )
924cdf0e10cSrcweir {
925cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
926cdf0e10cSrcweir 
927cdf0e10cSrcweir 	if( rGraphic.GetType() != GRAPHIC_NONE )
928cdf0e10cSrcweir     {
929cdf0e10cSrcweir 		sal_uIntPtr           nExportFormat = CVT_UNKNOWN;
930cdf0e10cSrcweir 		const GfxLink	aGfxLink( ( (Graphic&) rGraphic ).GetLink() );
931cdf0e10cSrcweir 
932cdf0e10cSrcweir 		if( aGfxLink.GetDataSize() )
933cdf0e10cSrcweir 		{
934cdf0e10cSrcweir 			switch( aGfxLink.GetType() )
935cdf0e10cSrcweir 			{
936cdf0e10cSrcweir 				case( GFX_LINK_TYPE_EPS_BUFFER ): nExportFormat = CVT_SVM; break;
937cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_GIF ): nExportFormat = CVT_GIF; break;
93872583341SArmin Le Grand 
93972583341SArmin Le Grand                 // #15508# added BMP type
94072583341SArmin Le Grand                 // could not find/trigger a call to this, but should do no harm
94172583341SArmin Le Grand                 case( GFX_LINK_TYPE_NATIVE_BMP ): nExportFormat = CVT_BMP; break;
94272583341SArmin Le Grand 
943cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_JPG ): nExportFormat = CVT_JPG; break;
944cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_PNG ): nExportFormat = CVT_PNG; break;
945cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_TIF ): nExportFormat = CVT_TIF; break;
946cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_WMF ): nExportFormat = CVT_WMF; break;
947cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_MET ): nExportFormat = CVT_MET; break;
948cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_PCT ): nExportFormat = CVT_PCT; break;
949cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_SVG ): nExportFormat = CVT_SVG; break;
950cdf0e10cSrcweir 				default:
951cdf0e10cSrcweir 					break;
952cdf0e10cSrcweir 			}
953cdf0e10cSrcweir 		}
954cdf0e10cSrcweir 		else
955cdf0e10cSrcweir 		{
956cdf0e10cSrcweir 		    if( rGraphic.GetType() == GRAPHIC_BITMAP )
957cdf0e10cSrcweir 		    {
958cdf0e10cSrcweir 			    if( rGraphic.IsAnimated() )
959cdf0e10cSrcweir 				    nExportFormat = CVT_GIF;
960cdf0e10cSrcweir 			    else
961cdf0e10cSrcweir 				    nExportFormat = CVT_PNG;
962cdf0e10cSrcweir 		    }
963cdf0e10cSrcweir 		    else
964cdf0e10cSrcweir                 nExportFormat = CVT_SVM;
965cdf0e10cSrcweir 		}
966cdf0e10cSrcweir 
967cdf0e10cSrcweir         const INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_BMP, nExportFormat ) );
968cdf0e10cSrcweir 		SvStream*           pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
969cdf0e10cSrcweir 
970cdf0e10cSrcweir         if( pOStm )
971cdf0e10cSrcweir         {
972cdf0e10cSrcweir 		    pOStm->SetVersion( SOFFICE_FILEFORMAT_50 );
973cdf0e10cSrcweir 
974cdf0e10cSrcweir             if( CVT_SVM == nExportFormat )
975cdf0e10cSrcweir             {
976cdf0e10cSrcweir                 GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
977cdf0e10cSrcweir 
978cdf0e10cSrcweir 			    aMtf.Write( *pOStm );
979cdf0e10cSrcweir 			    bRet = ( pOStm->GetError() == ERRCODE_NONE );
980cdf0e10cSrcweir             }
981cdf0e10cSrcweir             else
982cdf0e10cSrcweir             {
983cdf0e10cSrcweir                 if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
984cdf0e10cSrcweir                 {
985cdf0e10cSrcweir                     pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
986cdf0e10cSrcweir                     bRet = ( pOStm->GetError() == ERRCODE_NONE );
987cdf0e10cSrcweir                 }
988cdf0e10cSrcweir                 else
989cdf0e10cSrcweir                     bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE );
990cdf0e10cSrcweir             }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir             delete pOStm;
993cdf0e10cSrcweir         }
994cdf0e10cSrcweir 
995cdf0e10cSrcweir 		if( bRet )
996cdf0e10cSrcweir 		{
997cdf0e10cSrcweir 			const SgaObjectBmp aObjBmp( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
998cdf0e10cSrcweir 			InsertObject( aObjBmp, nInsertPos );
999cdf0e10cSrcweir 		}
1000cdf0e10cSrcweir 	}
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 	return bRet;
1003cdf0e10cSrcweir }
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir // -----------------------------------------------------------------------------
1006cdf0e10cSrcweir 
GetModel(sal_uIntPtr nPos,SdrModel & rModel,sal_Bool)1007cdf0e10cSrcweir sal_Bool GalleryTheme::GetModel( sal_uIntPtr nPos, SdrModel& rModel, sal_Bool )
1008cdf0e10cSrcweir {
1009cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
1010cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 	if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
1013cdf0e10cSrcweir 	{
1014cdf0e10cSrcweir 		const INetURLObject aURL( ImplGetURL( pObject ) );
1015cdf0e10cSrcweir 		SvStorageRef		xStor( GetSvDrawStorage() );
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 		if( xStor.Is() )
1018cdf0e10cSrcweir 		{
1019cdf0e10cSrcweir 			const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1020cdf0e10cSrcweir 			SvStorageStreamRef	xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir 			if( xIStm.Is() && !xIStm->GetError() )
1023cdf0e10cSrcweir 			{
1024cdf0e10cSrcweir 				xIStm->SetBufferSize( STREAMBUF_SIZE );
1025cdf0e10cSrcweir 				bRet = GallerySvDrawImport( *xIStm, rModel );
1026cdf0e10cSrcweir 				xIStm->SetBufferSize( 0L );
1027cdf0e10cSrcweir 			}
1028cdf0e10cSrcweir 		}
1029cdf0e10cSrcweir 	}
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir 	return bRet;
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir // -----------------------------------------------------------------------------
1035cdf0e10cSrcweir 
InsertModel(const FmFormModel & rModel,sal_uIntPtr nInsertPos)1036cdf0e10cSrcweir sal_Bool GalleryTheme::InsertModel( const FmFormModel& rModel, sal_uIntPtr nInsertPos )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir 	INetURLObject	aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
1039cdf0e10cSrcweir 	SvStorageRef	xStor( GetSvDrawStorage() );
1040cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir 	if( xStor.Is() )
1043cdf0e10cSrcweir 	{
1044cdf0e10cSrcweir 		const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1045cdf0e10cSrcweir 		SvStorageStreamRef	xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir 		if( xOStm.Is() && !xOStm->GetError() )
1048cdf0e10cSrcweir 		{
1049cdf0e10cSrcweir 			SvMemoryStream	aMemStm( 65535, 65535 );
1050cdf0e10cSrcweir 			FmFormModel*	pFormModel = (FmFormModel*) &rModel;
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 		    pFormModel->BurnInStyleSheetAttributes();
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir             {
1055cdf0e10cSrcweir 			    uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( aMemStm ) );
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir         	    if( xDocOut.is() )
1058cdf0e10cSrcweir                     SvxDrawingLayerExport( pFormModel, xDocOut );
1059cdf0e10cSrcweir 		    }
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir             aMemStm.Seek( 0 );
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir 		    xOStm->SetBufferSize( 16348 );
1064cdf0e10cSrcweir 			GalleryCodec aCodec( *xOStm );
1065cdf0e10cSrcweir 		    aCodec.Write( aMemStm );
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir 		    if( !xOStm->GetError() )
1068cdf0e10cSrcweir 		    {
1069cdf0e10cSrcweir 			    SgaObjectSvDraw	aObjSvDraw( rModel, aURL );
1070cdf0e10cSrcweir 			    bRet = InsertObject( aObjSvDraw, nInsertPos );
1071cdf0e10cSrcweir 		    }
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir 		    xOStm->SetBufferSize( 0L );
1074cdf0e10cSrcweir             xOStm->Commit();
1075cdf0e10cSrcweir         }
1076cdf0e10cSrcweir 	}
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir 	return bRet;
1079cdf0e10cSrcweir }
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir // -----------------------------------------------------------------------------
1082cdf0e10cSrcweir 
GetModelStream(sal_uIntPtr nPos,SotStorageStreamRef & rxModelStream,sal_Bool)1083cdf0e10cSrcweir sal_Bool GalleryTheme::GetModelStream( sal_uIntPtr nPos, SotStorageStreamRef& rxModelStream, sal_Bool )
1084cdf0e10cSrcweir {
1085cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
1086cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 	if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
1089cdf0e10cSrcweir 	{
1090cdf0e10cSrcweir 		const INetURLObject aURL( ImplGetURL( pObject ) );
1091cdf0e10cSrcweir 		SvStorageRef		xStor( GetSvDrawStorage() );
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir 		if( xStor.Is() )
1094cdf0e10cSrcweir 		{
1095cdf0e10cSrcweir 			const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1096cdf0e10cSrcweir 			SvStorageStreamRef	xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 			if( xIStm.Is() && !xIStm->GetError() )
1099cdf0e10cSrcweir 			{
1100cdf0e10cSrcweir             	sal_uInt32 nVersion = 0;
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir                 xIStm->SetBufferSize( 16348 );
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 	            if( GalleryCodec::IsCoded( *xIStm, nVersion ) )
1105cdf0e10cSrcweir                 {
1106cdf0e10cSrcweir                     SvxGalleryDrawModel aModel;
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir                     if( aModel.GetModel() )
1109cdf0e10cSrcweir                     {
1110cdf0e10cSrcweir                         if( GallerySvDrawImport( *xIStm, *aModel.GetModel() ) )
1111cdf0e10cSrcweir                         {
1112cdf0e10cSrcweir                             aModel.GetModel()->BurnInStyleSheetAttributes();
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir                             {
1115cdf0e10cSrcweir                                 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) );
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir                                 if( SvxDrawingLayerExport( aModel.GetModel(), xDocOut ) )
1118cdf0e10cSrcweir                                     rxModelStream->Commit();
1119cdf0e10cSrcweir                             }
1120cdf0e10cSrcweir                         }
1121cdf0e10cSrcweir 
1122cdf0e10cSrcweir                         bRet = ( rxModelStream->GetError() == ERRCODE_NONE );
1123cdf0e10cSrcweir                     }
1124cdf0e10cSrcweir                 }
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir                 xIStm->SetBufferSize( 0 );
1127cdf0e10cSrcweir 			}
1128cdf0e10cSrcweir 		}
1129cdf0e10cSrcweir 	}
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir 	return bRet;
1132cdf0e10cSrcweir }
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir // -----------------------------------------------------------------------------
1135cdf0e10cSrcweir 
InsertModelStream(const SotStorageStreamRef & rxModelStream,sal_uIntPtr nInsertPos)1136cdf0e10cSrcweir sal_Bool GalleryTheme::InsertModelStream( const SotStorageStreamRef& rxModelStream, sal_uIntPtr nInsertPos )
1137cdf0e10cSrcweir {
1138cdf0e10cSrcweir 	INetURLObject	aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
1139cdf0e10cSrcweir 	SvStorageRef	xStor( GetSvDrawStorage() );
1140cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir 	if( xStor.Is() )
1143cdf0e10cSrcweir 	{
1144cdf0e10cSrcweir 		const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1145cdf0e10cSrcweir 		SvStorageStreamRef	xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir 		if( xOStm.Is() && !xOStm->GetError() )
1148cdf0e10cSrcweir 		{
1149cdf0e10cSrcweir             GalleryCodec    aCodec( *xOStm );
1150cdf0e10cSrcweir             SvMemoryStream  aMemStm( 65535, 65535 );
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir 		    xOStm->SetBufferSize( 16348 );
1153cdf0e10cSrcweir             aCodec.Write( *rxModelStream );
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir 		    if( !xOStm->GetError() )
1156cdf0e10cSrcweir 		    {
1157cdf0e10cSrcweir 			    xOStm->Seek( 0 );
1158cdf0e10cSrcweir                 SgaObjectSvDraw	aObjSvDraw( *xOStm, aURL );
1159cdf0e10cSrcweir 			    bRet = InsertObject( aObjSvDraw, nInsertPos );
1160cdf0e10cSrcweir 		    }
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 		    xOStm->SetBufferSize( 0L );
1163cdf0e10cSrcweir             xOStm->Commit();
1164cdf0e10cSrcweir         }
1165cdf0e10cSrcweir 	}
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir 	return bRet;
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir // -----------------------------------------------------------------------------
1171cdf0e10cSrcweir 
GetURL(sal_uIntPtr nPos,INetURLObject & rURL,sal_Bool)1172cdf0e10cSrcweir sal_Bool GalleryTheme::GetURL( sal_uIntPtr nPos, INetURLObject& rURL, sal_Bool )
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
1175cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir 	if( pObject )
1178cdf0e10cSrcweir 	{
1179cdf0e10cSrcweir 		rURL = INetURLObject( ImplGetURL( pObject ) );
1180cdf0e10cSrcweir 		bRet = sal_True;
1181cdf0e10cSrcweir 	}
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 	return bRet;
1184cdf0e10cSrcweir }
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir // -----------------------------------------------------------------------------
1187cdf0e10cSrcweir 
InsertURL(const INetURLObject & rURL,sal_uIntPtr nInsertPos)1188cdf0e10cSrcweir sal_Bool GalleryTheme::InsertURL( const INetURLObject& rURL, sal_uIntPtr nInsertPos )
1189cdf0e10cSrcweir {
1190cdf0e10cSrcweir 	Graphic			aGraphic;
1191cdf0e10cSrcweir 	String			aFormat;
1192cdf0e10cSrcweir 	SgaObject*		pNewObj = NULL;
1193cdf0e10cSrcweir 	const sal_uInt16	nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
1194cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir 	if( nImportRet != SGA_IMPORT_NONE )
1197cdf0e10cSrcweir 	{
1198cdf0e10cSrcweir 		if ( SGA_IMPORT_INET == nImportRet )
1199cdf0e10cSrcweir 			pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, rURL, aFormat );
1200cdf0e10cSrcweir 		else if ( aGraphic.IsAnimated() )
1201cdf0e10cSrcweir 			pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, rURL, aFormat );
1202cdf0e10cSrcweir 		else
1203cdf0e10cSrcweir 			pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, rURL, aFormat );
1204cdf0e10cSrcweir 	}
1205cdf0e10cSrcweir 	else if( ::avmedia::MediaWindow::isMediaURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
1206cdf0e10cSrcweir 		pNewObj = (SgaObject*) new SgaObjectSound( rURL );
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir 	if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
1209cdf0e10cSrcweir 		bRet = sal_True;
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir 	delete pNewObj;
1212cdf0e10cSrcweir 
1213cdf0e10cSrcweir 	return bRet;
1214cdf0e10cSrcweir }
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir // -----------------------------------------------------------------------------
1217cdf0e10cSrcweir 
InsertFileOrDirURL(const INetURLObject & rFileOrDirURL,sal_uIntPtr nInsertPos)1218cdf0e10cSrcweir sal_Bool GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, sal_uIntPtr nInsertPos )
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir     INetURLObject                   aURL;
1221cdf0e10cSrcweir     ::std::vector< INetURLObject >  aURLVector;
1222cdf0e10cSrcweir 	sal_Bool                            bRet = sal_False;
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir 	try
1225cdf0e10cSrcweir 	{
1226cdf0e10cSrcweir 		::ucbhelper::Content         aCnt( rFileOrDirURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
1227cdf0e10cSrcweir 		sal_Bool        bFolder = false;
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 		aCnt.getPropertyValue( OUString::createFromAscii( "IsFolder" ) ) >>= bFolder;
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 		if( bFolder )
1232cdf0e10cSrcweir 		{
1233cdf0e10cSrcweir 			uno::Sequence< OUString > aProps( 1 );
1234cdf0e10cSrcweir 			aProps.getArray()[ 0 ] = OUString::createFromAscii( "Url" );
1235cdf0e10cSrcweir 			uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
1236cdf0e10cSrcweir             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1237cdf0e10cSrcweir 			if( xContentAccess.is() )
1238cdf0e10cSrcweir 			{
1239cdf0e10cSrcweir 				while( xResultSet->next() )
1240cdf0e10cSrcweir 				{
1241cdf0e10cSrcweir 					aURL.SetSmartURL( xContentAccess->queryContentIdentifierString() );
1242cdf0e10cSrcweir                     aURLVector.push_back( aURL );
1243cdf0e10cSrcweir 				}
1244cdf0e10cSrcweir 			}
1245cdf0e10cSrcweir 		}
1246cdf0e10cSrcweir 		else
1247cdf0e10cSrcweir             aURLVector.push_back( rFileOrDirURL );
1248cdf0e10cSrcweir 	}
1249cdf0e10cSrcweir 	catch( const ucb::ContentCreationException& )
1250cdf0e10cSrcweir 	{
1251cdf0e10cSrcweir 	}
1252cdf0e10cSrcweir 	catch( const uno::RuntimeException& )
1253cdf0e10cSrcweir 	{
1254cdf0e10cSrcweir 	}
1255cdf0e10cSrcweir 	catch( const uno::Exception& )
1256cdf0e10cSrcweir 	{
1257cdf0e10cSrcweir 	}
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir     ::std::vector< INetURLObject >::const_iterator aIter( aURLVector.begin() ), aEnd( aURLVector.end() );
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir     while( aIter != aEnd )
1262cdf0e10cSrcweir         bRet = bRet || InsertURL( *aIter++, nInsertPos );
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir     return bRet;
1265cdf0e10cSrcweir }
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir // -----------------------------------------------------------------------------
1268cdf0e10cSrcweir 
InsertTransferable(const uno::Reference<datatransfer::XTransferable> & rxTransferable,sal_uIntPtr nInsertPos)1269cdf0e10cSrcweir sal_Bool GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uIntPtr nInsertPos )
1270cdf0e10cSrcweir {
1271cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir 	if( rxTransferable.is() )
1274cdf0e10cSrcweir 	{
1275cdf0e10cSrcweir 		TransferableDataHelper	aDataHelper( rxTransferable );
1276cdf0e10cSrcweir 		Graphic*				pGraphic = NULL;
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir 		if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
1279cdf0e10cSrcweir 		{
1280cdf0e10cSrcweir 			SotStorageStreamRef xModelStm;
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir 			if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) )
1283cdf0e10cSrcweir 				bRet = InsertModelStream( xModelStm, nInsertPos );
1284cdf0e10cSrcweir 		}
1285cdf0e10cSrcweir 		else if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
1286cdf0e10cSrcweir                  aDataHelper.HasFormat( FORMAT_FILE ) )
1287cdf0e10cSrcweir 		{
1288cdf0e10cSrcweir             FileList aFileList;
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir             if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) )
1291cdf0e10cSrcweir                 aDataHelper.GetFileList( SOT_FORMAT_FILE_LIST, aFileList );
1292cdf0e10cSrcweir             else
1293cdf0e10cSrcweir             {
1294cdf0e10cSrcweir                 String aFile;
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir                 aDataHelper.GetString( FORMAT_FILE, aFile );
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir                 if( aFile.Len() )
1299cdf0e10cSrcweir                     aFileList.AppendFile( aFile );
1300cdf0e10cSrcweir             }
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir             for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
1303cdf0e10cSrcweir             {
1304cdf0e10cSrcweir                 const String    aFile( aFileList.GetFile( i ) );
1305cdf0e10cSrcweir                 INetURLObject   aURL( aFile );
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir                 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
1308cdf0e10cSrcweir                 {
1309cdf0e10cSrcweir                     String aLocalURL;
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir                     if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aLocalURL ) )
1312cdf0e10cSrcweir                         aURL = INetURLObject( aLocalURL );
1313cdf0e10cSrcweir                 }
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir                 if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1316cdf0e10cSrcweir                     bRet = InsertFileOrDirURL( aURL, nInsertPos );
1317cdf0e10cSrcweir 			}
1318cdf0e10cSrcweir 		}
1319cdf0e10cSrcweir 		else
1320cdf0e10cSrcweir 		{
1321cdf0e10cSrcweir 			Graphic	aGraphic;
1322cdf0e10cSrcweir 			sal_uIntPtr	nFormat = 0;
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir 			if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
1325cdf0e10cSrcweir 				nFormat = SOT_FORMATSTR_ID_SVXB;
1326cdf0e10cSrcweir 			else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1327cdf0e10cSrcweir 				nFormat = FORMAT_GDIMETAFILE;
1328cdf0e10cSrcweir 			else if( aDataHelper.HasFormat( FORMAT_BITMAP ) )
1329cdf0e10cSrcweir 				nFormat = FORMAT_BITMAP;
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir 			if( nFormat && aDataHelper.GetGraphic( nFormat, aGraphic ) )
1332cdf0e10cSrcweir 				pGraphic = new Graphic( aGraphic );
1333cdf0e10cSrcweir 		}
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir 		if( pGraphic )
1336cdf0e10cSrcweir 		{
1337cdf0e10cSrcweir 			bRet = sal_False;
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir 			if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
1340cdf0e10cSrcweir 			{
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir 				ImageMap aImageMap;
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir                 // according to KA we don't need a BaseURL here
1345cdf0e10cSrcweir                 if( aDataHelper.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) )
1346cdf0e10cSrcweir 				{
1347cdf0e10cSrcweir                     SvxGalleryDrawModel aModel;
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir                     if( aModel.GetModel() )
1350cdf0e10cSrcweir                     {
1351cdf0e10cSrcweir 					    SgaUserDataFactory	aFactory;
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir 					    SdrPage*	pPage = aModel.GetModel()->GetPage(0);
1354cdf0e10cSrcweir 					    SdrGrafObj*	pGrafObj = new SdrGrafObj( *pGraphic );
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir 					    pGrafObj->InsertUserData( new SgaIMapInfo( aImageMap ) );
1357cdf0e10cSrcweir 					    pPage->InsertObject( pGrafObj );
1358cdf0e10cSrcweir 					    bRet = InsertModel( *aModel.GetModel(), nInsertPos );
1359cdf0e10cSrcweir                     }
1360cdf0e10cSrcweir 				}
1361cdf0e10cSrcweir 			}
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir 			if( !bRet )
1364cdf0e10cSrcweir 				bRet = InsertGraphic( *pGraphic, nInsertPos );
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir 			delete pGraphic;
1367cdf0e10cSrcweir 		}
1368cdf0e10cSrcweir 	}
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir 	return bRet;
1371cdf0e10cSrcweir }
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir // -----------------------------------------------------------------------------
1374cdf0e10cSrcweir 
CopyToClipboard(Window * pWindow,sal_uIntPtr nPos)1375cdf0e10cSrcweir void GalleryTheme::CopyToClipboard( Window* pWindow, sal_uIntPtr nPos )
1376cdf0e10cSrcweir {
1377cdf0e10cSrcweir 	GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
1378cdf0e10cSrcweir 	pTransferable->CopyToClipboard( pWindow );
1379cdf0e10cSrcweir }
1380cdf0e10cSrcweir 
1381cdf0e10cSrcweir // -----------------------------------------------------------------------------
1382cdf0e10cSrcweir 
StartDrag(Window * pWindow,sal_uIntPtr nPos)1383cdf0e10cSrcweir void GalleryTheme::StartDrag( Window* pWindow, sal_uIntPtr nPos )
1384cdf0e10cSrcweir {
1385cdf0e10cSrcweir 	GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true );
1386cdf0e10cSrcweir 	pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK );
1387cdf0e10cSrcweir }
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir // -----------------------------------------------------------------------------
1390cdf0e10cSrcweir 
WriteData(SvStream & rOStm) const1391cdf0e10cSrcweir SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const
1392cdf0e10cSrcweir {
1393cdf0e10cSrcweir 	const INetURLObject	aRelURL1( GetParent()->GetRelativeURL() );
1394cdf0e10cSrcweir 	const INetURLObject	aRelURL2( GetParent()->GetUserURL() );
1395cdf0e10cSrcweir 	INetURLObject		aNewURL, aTempURL;
1396cdf0e10cSrcweir 	sal_uInt32			nCount = GetObjectCount();
1397cdf0e10cSrcweir 	sal_Bool				bRel;
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir 	rOStm << (sal_uInt16) 0x0004;
1400cdf0e10cSrcweir 	rOStm << ByteString( GetRealName(), RTL_TEXTENCODING_UTF8 );
1401cdf0e10cSrcweir 	rOStm << nCount << (sal_uInt16) gsl_getSystemTextEncoding();
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir 	for( sal_uInt32 i = 0; i < nCount; i++ )
1404cdf0e10cSrcweir 	{
1405cdf0e10cSrcweir 		const GalleryObject* pObj = ImplGetGalleryObject( i );
1406cdf0e10cSrcweir 		String				 aPath;
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir 		if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1409cdf0e10cSrcweir 		{
1410cdf0e10cSrcweir 			aPath = GetSvDrawStreamNameFromURL( pObj->aURL );
1411cdf0e10cSrcweir 			bRel = sal_False;
1412cdf0e10cSrcweir 		}
1413cdf0e10cSrcweir 		else
1414cdf0e10cSrcweir 		{
1415cdf0e10cSrcweir 			aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1416cdf0e10cSrcweir 			bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL1.GetMainURL( INetURLObject::NO_DECODE ) ));
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir 			if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
1419cdf0e10cSrcweir 			{
1420cdf0e10cSrcweir 				aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1421cdf0e10cSrcweir 				aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
1422cdf0e10cSrcweir 			}
1423cdf0e10cSrcweir 			else
1424cdf0e10cSrcweir 			{
1425cdf0e10cSrcweir 				aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1426cdf0e10cSrcweir 				bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL2.GetMainURL( INetURLObject::NO_DECODE ) ));
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir 				if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
1429cdf0e10cSrcweir 				{
1430cdf0e10cSrcweir 					aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1431cdf0e10cSrcweir 					aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
1432cdf0e10cSrcweir 				}
1433cdf0e10cSrcweir 				else
1434cdf0e10cSrcweir 					aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1435cdf0e10cSrcweir 			}
1436cdf0e10cSrcweir 		}
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir 		aPath.SearchAndReplace(m_aDestDir, String());
1439cdf0e10cSrcweir 		rOStm << bRel << ByteString( aPath, RTL_TEXTENCODING_UTF8 ) << pObj->nOffset << (sal_uInt16) pObj->eObjKind;
1440cdf0e10cSrcweir 	}
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir 	// neuerdings wird ein 512-Byte-Reservepuffer gechrieben;
1443cdf0e10cSrcweir 	// um diesen zu erkennen werden zwei sal_uIntPtr-Ids geschrieben
1444cdf0e10cSrcweir 	rOStm << COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) << COMPAT_FORMAT( 'E', 'S', 'R', 'V' );
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 	const long		nReservePos = rOStm.Tell();
1447cdf0e10cSrcweir 	VersionCompat*	pCompat = new VersionCompat( rOStm, STREAM_WRITE, 2 );
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir 	rOStm << (sal_uInt32) GetId() << IsThemeNameFromResource(); // ab Version 2
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir 	delete pCompat;
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir 	// Rest des Puffers auffuellen
1454cdf0e10cSrcweir 	const long	nRest = Max( 512L - ( (long) rOStm.Tell() - nReservePos ), 0L );
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir 	if( nRest )
1457cdf0e10cSrcweir 	{
1458cdf0e10cSrcweir 		char* pReserve = new char[ nRest ];
1459cdf0e10cSrcweir 		memset( pReserve, 0, nRest );
1460cdf0e10cSrcweir 		rOStm.Write( pReserve, nRest );
1461cdf0e10cSrcweir 		delete[] pReserve;
1462cdf0e10cSrcweir 	}
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir 	return rOStm;
1465cdf0e10cSrcweir }
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir // ------------------------------------------------------------------------
1468cdf0e10cSrcweir 
ReadData(SvStream & rIStm)1469cdf0e10cSrcweir SvStream& GalleryTheme::ReadData( SvStream& rIStm )
1470cdf0e10cSrcweir {
1471cdf0e10cSrcweir 	sal_uInt32			nCount;
1472cdf0e10cSrcweir 	sal_uInt16			nVersion;
1473cdf0e10cSrcweir 	ByteString			aTmpStr;
1474cdf0e10cSrcweir 	String				aThemeName;
1475cdf0e10cSrcweir 	rtl_TextEncoding	nTextEncoding;
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir 	aImportName = String();
1478cdf0e10cSrcweir 	rIStm >> nVersion >> aTmpStr >> nCount;
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir 	if( nVersion >= 0x0004 )
1481cdf0e10cSrcweir 	{
1482cdf0e10cSrcweir 		sal_uInt16 nTmp16;
1483cdf0e10cSrcweir 		rIStm >> nTmp16;
1484cdf0e10cSrcweir 		nTextEncoding = (rtl_TextEncoding) nTmp16;
1485cdf0e10cSrcweir 	}
1486cdf0e10cSrcweir 	else
1487cdf0e10cSrcweir 		nTextEncoding = RTL_TEXTENCODING_UTF8;
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir 	aThemeName = String( aTmpStr.GetBuffer(), nTextEncoding );
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir 	if( nCount <= ( 1L << 14 ) )
1492cdf0e10cSrcweir 	{
1493cdf0e10cSrcweir 		GalleryObject*	pObj;
1494cdf0e10cSrcweir 		INetURLObject	aRelURL1( GetParent()->GetRelativeURL() );
1495cdf0e10cSrcweir 		INetURLObject	aRelURL2( GetParent()->GetUserURL() );
1496cdf0e10cSrcweir 		sal_uInt32		nId1, nId2;
1497cdf0e10cSrcweir 		sal_Bool			bRel;
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir 		for( pObj = aObjectList.First(); pObj; pObj = aObjectList.Next() )
1500cdf0e10cSrcweir 		{
1501cdf0e10cSrcweir 			Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
1502cdf0e10cSrcweir 			delete pObj;
1503cdf0e10cSrcweir 			Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
1504cdf0e10cSrcweir 		}
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir 		aObjectList.Clear();
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir 		for( sal_uInt32 i = 0; i < nCount; i++ )
1509cdf0e10cSrcweir 		{
1510cdf0e10cSrcweir 			pObj = new GalleryObject;
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir 			ByteString	aTempFileName;
1513cdf0e10cSrcweir 			String		aFileName;
1514cdf0e10cSrcweir 			String		aPath;
1515cdf0e10cSrcweir 			sal_uInt16	nTemp;
1516cdf0e10cSrcweir 
1517cdf0e10cSrcweir 			rIStm >> bRel >> aTempFileName >> pObj->nOffset;
1518cdf0e10cSrcweir 			rIStm >> nTemp; pObj->eObjKind = (SgaObjKind) nTemp;
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir 			aFileName = String( aTempFileName.GetBuffer(), gsl_getSystemTextEncoding() );
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir 			if( bRel )
1523cdf0e10cSrcweir 			{
1524cdf0e10cSrcweir 				aFileName.SearchAndReplaceAll( '\\', '/' );
1525cdf0e10cSrcweir 				aPath = aRelURL1.GetMainURL( INetURLObject::NO_DECODE );
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 				if( aFileName.GetChar( 0 ) != '/' )
1528cdf0e10cSrcweir 			    		aPath += '/';
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir 				aPath += aFileName;
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir 				pObj->aURL = INetURLObject( aPath );
1533cdf0e10cSrcweir 
1534cdf0e10cSrcweir 				if( !FileExists( pObj->aURL ) )
1535cdf0e10cSrcweir 				{
1536cdf0e10cSrcweir 					aPath = aRelURL2.GetMainURL( INetURLObject::NO_DECODE );
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir 					if( aFileName.GetChar( 0 ) != '/' )
1539cdf0e10cSrcweir 						aPath += '/';
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir 					aPath += aFileName;
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir 					// assign this URL, even in the case it is not valid (#94482)
1544cdf0e10cSrcweir                     pObj->aURL = INetURLObject( aPath );
1545cdf0e10cSrcweir 				}
1546cdf0e10cSrcweir 			}
1547cdf0e10cSrcweir 			else
1548cdf0e10cSrcweir 			{
1549cdf0e10cSrcweir 				if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1550cdf0e10cSrcweir 				{
1551cdf0e10cSrcweir 					const static String aBaseURLStr( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/" ) );
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir 					String aDummyURL( aBaseURLStr );
1554cdf0e10cSrcweir 					pObj->aURL = INetURLObject( aDummyURL += aFileName, INET_PROT_PRIV_SOFFICE );
1555cdf0e10cSrcweir 				}
1556cdf0e10cSrcweir 				else
1557cdf0e10cSrcweir 				{
1558cdf0e10cSrcweir                     String aLocalURL;
1559cdf0e10cSrcweir 
1560cdf0e10cSrcweir 					pObj->aURL = INetURLObject( aFileName );
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir 					if( ( pObj->aURL.GetProtocol() == INET_PROT_NOT_VALID ) &&
1563cdf0e10cSrcweir 						::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aLocalURL ) )
1564cdf0e10cSrcweir 					{
1565cdf0e10cSrcweir 						pObj->aURL = INetURLObject( aLocalURL );
1566cdf0e10cSrcweir 					}
1567cdf0e10cSrcweir 				}
1568cdf0e10cSrcweir 			}
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir 			aObjectList.Insert( pObj, LIST_APPEND );
1571cdf0e10cSrcweir 		}
1572cdf0e10cSrcweir 
1573cdf0e10cSrcweir 		rIStm >> nId1 >> nId2;
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir 		// in neueren Versionen befindet sich am Ende ein 512-Byte-Reservepuffer;
1576cdf0e10cSrcweir 		// die Daten befinden sich am Anfang dieses Puffers und
1577cdf0e10cSrcweir 		// sind durch eine VersionCompat geklammert
1578cdf0e10cSrcweir 		if( !rIStm.IsEof() &&
1579cdf0e10cSrcweir 			nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
1580cdf0e10cSrcweir 			nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
1581cdf0e10cSrcweir 		{
1582cdf0e10cSrcweir 			VersionCompat*	pCompat = new VersionCompat( rIStm, STREAM_READ );
1583cdf0e10cSrcweir 			sal_uInt32		nTemp32;
1584cdf0e10cSrcweir 			sal_Bool			bThemeNameFromResource = sal_False;
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir 			rIStm >> nTemp32;
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir 			if( pCompat->GetVersion() >= 2 )
1589cdf0e10cSrcweir 			{
1590cdf0e10cSrcweir 				rIStm >> bThemeNameFromResource;
1591cdf0e10cSrcweir 			}
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir 			SetId( nTemp32, bThemeNameFromResource );
1594cdf0e10cSrcweir 			delete pCompat;
1595cdf0e10cSrcweir 		}
1596cdf0e10cSrcweir 	}
1597cdf0e10cSrcweir 	else
1598cdf0e10cSrcweir 		rIStm.SetError( SVSTREAM_READ_ERROR );
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir 	ImplSetModified( sal_False );
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir 	return rIStm;
1603cdf0e10cSrcweir }
1604cdf0e10cSrcweir 
1605cdf0e10cSrcweir // ------------------------------------------------------------------------
1606cdf0e10cSrcweir 
operator <<(SvStream & rOut,const GalleryTheme & rTheme)1607cdf0e10cSrcweir SvStream& operator<<( SvStream& rOut, const GalleryTheme& rTheme )
1608cdf0e10cSrcweir {
1609cdf0e10cSrcweir 	return rTheme.WriteData( rOut );
1610cdf0e10cSrcweir }
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir // ------------------------------------------------------------------------
1613cdf0e10cSrcweir 
operator >>(SvStream & rIn,GalleryTheme & rTheme)1614cdf0e10cSrcweir SvStream& operator>>( SvStream& rIn, GalleryTheme& rTheme )
1615cdf0e10cSrcweir {
1616cdf0e10cSrcweir 	return rTheme.ReadData( rIn );
1617cdf0e10cSrcweir }
1618cdf0e10cSrcweir 
ImplSetModified(sal_Bool bModified)1619cdf0e10cSrcweir void GalleryTheme::ImplSetModified( sal_Bool bModified )
1620cdf0e10cSrcweir { pThm->SetModified( bModified ); }
1621cdf0e10cSrcweir 
GetRealName() const1622cdf0e10cSrcweir const String& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); }
GetThmURL() const1623cdf0e10cSrcweir const INetURLObject& GalleryTheme::GetThmURL() const { return pThm->GetThmURL(); }
GetSdgURL() const1624cdf0e10cSrcweir const INetURLObject& GalleryTheme::GetSdgURL() const { return pThm->GetSdgURL(); }
GetSdvURL() const1625cdf0e10cSrcweir const INetURLObject& GalleryTheme::GetSdvURL() const { return pThm->GetSdvURL(); }
GetId() const1626cdf0e10cSrcweir sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); }
SetId(sal_uInt32 nNewId,sal_Bool bResetThemeName)1627cdf0e10cSrcweir void GalleryTheme::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); }
IsThemeNameFromResource() const1628cdf0e10cSrcweir sal_Bool GalleryTheme::IsThemeNameFromResource() const { return pThm->IsNameFromResource(); }
IsImported() const1629cdf0e10cSrcweir sal_Bool GalleryTheme::IsImported() const { return pThm->IsImported(); }
IsReadOnly() const1630cdf0e10cSrcweir sal_Bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); }
IsDefault() const1631cdf0e10cSrcweir sal_Bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); }
IsModified() const1632cdf0e10cSrcweir sal_Bool GalleryTheme::IsModified() const { return pThm->IsModified(); }
GetName() const1633cdf0e10cSrcweir const String& GalleryTheme::GetName() const	{ return IsImported() ? aImportName : pThm->GetThemeName(); }
1634cdf0e10cSrcweir 
InsertAllThemes(ListBox & rListBox)1635cdf0e10cSrcweir void GalleryTheme::InsertAllThemes( ListBox& rListBox )
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir 	for( sal_uInt16 i = RID_GALLERYSTR_THEME_FIRST; i <= RID_GALLERYSTR_THEME_LAST; i++ )
1638cdf0e10cSrcweir 		rListBox.InsertEntry( String( GAL_RESID( i ) ) );
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir 
1641