xref: /aoo42x/main/svx/source/gallery2/galtheme.cxx (revision 6dd94783)
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 // ------------
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 
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 
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 
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 
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 
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 
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 
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 
266cdf0e10cSrcweir 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 
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 
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 
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 
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 
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 
438cdf0e10cSrcweir             // update title of new object if neccessary
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 
467cdf0e10cSrcweir SgaObject* GalleryTheme::AcquireObject( sal_uIntPtr nPos )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	return ImplReadSgaObject( aObjectList.GetObject( nPos ) );
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir // ------------------------------------------------------------------------
473cdf0e10cSrcweir 
474cdf0e10cSrcweir void GalleryTheme::ReleaseObject( SgaObject* pObject )
475cdf0e10cSrcweir {
476cdf0e10cSrcweir 	delete pObject;
477cdf0e10cSrcweir }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir // ------------------------------------------------------------------------
480cdf0e10cSrcweir 
481cdf0e10cSrcweir sal_Bool GalleryTheme::RemoveObject( sal_uIntPtr nPos )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir 	GalleryObject* pEntry = aObjectList.Remove( nPos );
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 	if( !aObjectList.Count() )
486cdf0e10cSrcweir 		KillFile( GetSdgURL() );
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 	if( pEntry )
489cdf0e10cSrcweir 	{
490cdf0e10cSrcweir 		if( SGA_OBJ_SVDRAW == pEntry->eObjKind )
491cdf0e10cSrcweir 			aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
494cdf0e10cSrcweir 		delete pEntry;
495cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 		ImplSetModified( sal_True );
498cdf0e10cSrcweir 		ImplBroadcast( nPos );
499cdf0e10cSrcweir 	}
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 	return( pEntry != NULL );
502cdf0e10cSrcweir }
503cdf0e10cSrcweir 
504cdf0e10cSrcweir // ------------------------------------------------------------------------
505cdf0e10cSrcweir 
506cdf0e10cSrcweir sal_Bool GalleryTheme::ChangeObjectPos( sal_uIntPtr nOldPos, sal_uIntPtr nNewPos )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 	if( nOldPos != nNewPos )
511cdf0e10cSrcweir 	{
512cdf0e10cSrcweir 		GalleryObject* pEntry = aObjectList.GetObject( nOldPos );
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 		if( pEntry )
515cdf0e10cSrcweir 		{
516cdf0e10cSrcweir 			aObjectList.Insert( pEntry, nNewPos );
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 			if( nNewPos < nOldPos )
519cdf0e10cSrcweir 				nOldPos++;
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 			aObjectList.Remove( nOldPos );
522cdf0e10cSrcweir 			ImplSetModified( bRet = sal_True );
523cdf0e10cSrcweir 			ImplBroadcast( ( nNewPos < nOldPos ) ? nNewPos : ( nNewPos - 1 ) );
524cdf0e10cSrcweir 		}
525cdf0e10cSrcweir 	}
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 	return bRet;
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir // ------------------------------------------------------------------------
531cdf0e10cSrcweir 
532cdf0e10cSrcweir void GalleryTheme::Actualize( const Link& rActualizeLink, GalleryProgress* pProgress )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir 	if( !IsReadOnly() && !IsImported() )
535cdf0e10cSrcweir 	{
536cdf0e10cSrcweir 		Graphic			aGraphic;
537cdf0e10cSrcweir 		String			aFormat;
538cdf0e10cSrcweir 		GalleryObject*	pEntry;
539cdf0e10cSrcweir 		const sal_uIntPtr		nCount = aObjectList.Count();
540cdf0e10cSrcweir 		sal_uIntPtr			i;
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 		LockBroadcaster();
543cdf0e10cSrcweir 		bAbortActualize = sal_False;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 		// LoeschFlag zuruecksetzen
546cdf0e10cSrcweir 		for ( i = 0; i < nCount; i++ )
547cdf0e10cSrcweir 			aObjectList.GetObject( i )->bDummy = sal_False;
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 		for( i = 0; ( i < nCount ) && !bAbortActualize; i++ )
550cdf0e10cSrcweir 		{
551cdf0e10cSrcweir 			if( pProgress )
552cdf0e10cSrcweir 				pProgress->Update( i, nCount - 1 );
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 			pEntry = aObjectList.GetObject( i );
555cdf0e10cSrcweir 
556cdf0e10cSrcweir             const INetURLObject aURL( pEntry->aURL );
557cdf0e10cSrcweir 
558cdf0e10cSrcweir             rActualizeLink.Call( (void*) &aURL );
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 			// SvDraw-Objekte werden spaeter aktualisiert
561cdf0e10cSrcweir 			if( pEntry->eObjKind != SGA_OBJ_SVDRAW )
562cdf0e10cSrcweir 			{
563cdf0e10cSrcweir 				// Hier muss noch etwas eingebaut werden,
564cdf0e10cSrcweir 				// das Files auf den ensprechenden Eintrag matched
565cdf0e10cSrcweir 				// Grafiken als Grafik-Objekte in die Gallery aufnehmen
566cdf0e10cSrcweir 				if( pEntry->eObjKind == SGA_OBJ_SOUND )
567cdf0e10cSrcweir 				{
568cdf0e10cSrcweir 					SgaObjectSound aObjSound( aURL );
569cdf0e10cSrcweir 					if( !InsertObject( aObjSound ) )
570cdf0e10cSrcweir 						pEntry->bDummy = sal_True;
571cdf0e10cSrcweir 				}
572cdf0e10cSrcweir 				else
573cdf0e10cSrcweir 				{
574cdf0e10cSrcweir 					aGraphic.Clear();
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 					if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) )
577cdf0e10cSrcweir 					{
578cdf0e10cSrcweir 						SgaObject* pNewObj;
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 						if ( SGA_OBJ_INET == pEntry->eObjKind )
581cdf0e10cSrcweir 							pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, aURL, aFormat );
582cdf0e10cSrcweir 						else if ( aGraphic.IsAnimated() )
583cdf0e10cSrcweir 							pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, aURL, aFormat );
584cdf0e10cSrcweir 						else
585cdf0e10cSrcweir 							pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, aURL, aFormat );
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 						if( !InsertObject( *pNewObj ) )
588cdf0e10cSrcweir 							pEntry->bDummy = sal_True;
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 						delete pNewObj;
591cdf0e10cSrcweir 					}
592cdf0e10cSrcweir 					else
593cdf0e10cSrcweir 						pEntry->bDummy = sal_True; // Loesch-Flag setzen
594cdf0e10cSrcweir 				}
595cdf0e10cSrcweir 			}
596cdf0e10cSrcweir 			else
597cdf0e10cSrcweir 			{
598cdf0e10cSrcweir 				if ( aSvDrawStorageRef.Is() )
599cdf0e10cSrcweir 				{
600cdf0e10cSrcweir 					const String		aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
601cdf0e10cSrcweir 					SvStorageStreamRef	pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, STREAM_READ );
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 					if( pIStm && !pIStm->GetError() )
604cdf0e10cSrcweir 					{
605cdf0e10cSrcweir 						pIStm->SetBufferSize( 16384 );
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 						SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL );
608cdf0e10cSrcweir 
609cdf0e10cSrcweir                         if( !InsertObject( aNewObj ) )
610cdf0e10cSrcweir 							pEntry->bDummy = sal_True;
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 						pIStm->SetBufferSize( 0L );
613cdf0e10cSrcweir 					}
614cdf0e10cSrcweir 				}
615cdf0e10cSrcweir 			}
616cdf0e10cSrcweir 		}
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 		// remove all entries with set flag
619cdf0e10cSrcweir 		pEntry = aObjectList.First();
620cdf0e10cSrcweir 		while( pEntry )
621cdf0e10cSrcweir 		{
622cdf0e10cSrcweir 			if( pEntry->bDummy )
623cdf0e10cSrcweir 			{
624cdf0e10cSrcweir 				Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
625cdf0e10cSrcweir 				delete aObjectList.Remove( pEntry );
626cdf0e10cSrcweir 				Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 				pEntry = aObjectList.GetCurObject();
629cdf0e10cSrcweir 			}
630cdf0e10cSrcweir 			else
631cdf0e10cSrcweir 				pEntry = aObjectList.Next();
632cdf0e10cSrcweir 		}
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 		// update theme
635cdf0e10cSrcweir 		::utl::TempFile	aTmp;
636cdf0e10cSrcweir 		INetURLObject	aInURL( GetSdgURL() );
637cdf0e10cSrcweir 		INetURLObject	aTmpURL( aTmp.GetURL() );
638cdf0e10cSrcweir 
639cdf0e10cSrcweir 		DBG_ASSERT( aInURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
640cdf0e10cSrcweir 		DBG_ASSERT( aTmpURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
643cdf0e10cSrcweir 		SvStream* pTmpStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 		if( pIStm && pTmpStm )
646cdf0e10cSrcweir 		{
647cdf0e10cSrcweir 			pEntry = aObjectList.First();
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 			while( pEntry )
650cdf0e10cSrcweir 			{
651cdf0e10cSrcweir 				SgaObject* pObj;
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 				switch( pEntry->eObjKind )
654cdf0e10cSrcweir 				{
655cdf0e10cSrcweir 					case( SGA_OBJ_BMP ):	pObj = new SgaObjectBmp(); break;
656cdf0e10cSrcweir 					case( SGA_OBJ_ANIM ):	pObj = new SgaObjectAnim(); break;
657cdf0e10cSrcweir 					case( SGA_OBJ_INET ):	pObj = new SgaObjectINet(); break;
658cdf0e10cSrcweir 					case( SGA_OBJ_SVDRAW ):	pObj = new SgaObjectSvDraw(); break;
659cdf0e10cSrcweir 					case (SGA_OBJ_SOUND):	pObj = new SgaObjectSound(); break;
660cdf0e10cSrcweir 
661cdf0e10cSrcweir 					default:
662cdf0e10cSrcweir 						pObj = NULL;
663cdf0e10cSrcweir 					break;
664cdf0e10cSrcweir 				}
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 				if( pObj )
667cdf0e10cSrcweir 				{
668cdf0e10cSrcweir 					pIStm->Seek( pEntry->nOffset );
669cdf0e10cSrcweir 					*pIStm >> *pObj;
670cdf0e10cSrcweir 					pEntry->nOffset = pTmpStm->Tell();
671cdf0e10cSrcweir 					*pTmpStm << *pObj;
672cdf0e10cSrcweir 					delete pObj;
673cdf0e10cSrcweir 				}
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 				pEntry = aObjectList.Next();
676cdf0e10cSrcweir 			}
677cdf0e10cSrcweir 		}
678cdf0e10cSrcweir 		else
679cdf0e10cSrcweir 		{
680cdf0e10cSrcweir 			DBG_ERROR( "File(s) could not be opened" );
681cdf0e10cSrcweir 		}
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 		delete pIStm;
684cdf0e10cSrcweir 		delete pTmpStm;
685cdf0e10cSrcweir 
686cdf0e10cSrcweir 		CopyFile( aTmpURL, aInURL );
687cdf0e10cSrcweir 		KillFile( aTmpURL );
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 		sal_uIntPtr nStorErr = 0;
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 		{
692cdf0e10cSrcweir 			SvStorageRef aTempStorageRef( new SvStorage( sal_False, aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READWRITE ) );
693cdf0e10cSrcweir 			aSvDrawStorageRef->CopyTo( aTempStorageRef );
694cdf0e10cSrcweir 			nStorErr = aSvDrawStorageRef->GetError();
695cdf0e10cSrcweir 		}
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 		if( !nStorErr )
698cdf0e10cSrcweir 		{
699cdf0e10cSrcweir 			aSvDrawStorageRef.Clear();
700cdf0e10cSrcweir 			CopyFile( aTmpURL, GetSdvURL() );
701cdf0e10cSrcweir 			ImplCreateSvDrawStorage();
702cdf0e10cSrcweir 		}
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 		KillFile( aTmpURL );
705cdf0e10cSrcweir 		ImplSetModified( sal_True );
706cdf0e10cSrcweir 		ImplWrite();
707cdf0e10cSrcweir 		UnlockBroadcaster();
708cdf0e10cSrcweir 	}
709cdf0e10cSrcweir }
710cdf0e10cSrcweir 
711cdf0e10cSrcweir // ------------------------------------------------------------------------
712cdf0e10cSrcweir 
713cdf0e10cSrcweir GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sal_Bool bReadOnly )
714cdf0e10cSrcweir {
715cdf0e10cSrcweir 	DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 	GalleryThemeEntry*	pRet = NULL;
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 	if( FileExists( rURL ) )
720cdf0e10cSrcweir 	{
721cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 		if( pIStm )
724cdf0e10cSrcweir 		{
725cdf0e10cSrcweir 			String			aThemeName;
726cdf0e10cSrcweir 			sal_uInt32		nThemeId = 0;
727cdf0e10cSrcweir 			sal_uInt16		nVersion;
728cdf0e10cSrcweir 			sal_Bool			bThemeNameFromResource = sal_False;
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 			*pIStm >> nVersion;
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 			if( nVersion <= 0x00ff )
733cdf0e10cSrcweir 			{
734cdf0e10cSrcweir 				ByteString aTmpStr;
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 				*pIStm >> aTmpStr; aThemeName = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 				// Charakterkonvertierung durchfuehren
739cdf0e10cSrcweir 				if( nVersion >= 0x0004 )
740cdf0e10cSrcweir 				{
741cdf0e10cSrcweir 					sal_uInt32	nCount;
742cdf0e10cSrcweir 					sal_uInt16	nTemp16;
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 					*pIStm >> nCount >> nTemp16;
745cdf0e10cSrcweir 					pIStm->Seek( STREAM_SEEK_TO_END );
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 					// pruefen, ob es sich um eine neuere Version handelt;
748cdf0e10cSrcweir 					// daher um 520Bytes (8Bytes Kennung + 512Bytes Reserverpuffer ) zurueckspringen,
749cdf0e10cSrcweir 					// falls dies ueberhaupt moeglich ist
750cdf0e10cSrcweir 					if( pIStm->Tell() >= 520 )
751cdf0e10cSrcweir 					{
752cdf0e10cSrcweir 						sal_uInt32 nId1, nId2;
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 						pIStm->SeekRel( -520 );
755cdf0e10cSrcweir 						*pIStm >> nId1 >> nId2;
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 						if( nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
758cdf0e10cSrcweir 							nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
759cdf0e10cSrcweir 						{
760cdf0e10cSrcweir 							VersionCompat* pCompat = new VersionCompat( *pIStm, STREAM_READ );
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 							*pIStm >> nThemeId;
763cdf0e10cSrcweir 
764cdf0e10cSrcweir 							if( pCompat->GetVersion() >= 2 )
765cdf0e10cSrcweir 							{
766cdf0e10cSrcweir 								*pIStm >> bThemeNameFromResource;
767cdf0e10cSrcweir 							}
768cdf0e10cSrcweir 
769cdf0e10cSrcweir 							delete pCompat;
770cdf0e10cSrcweir 						}
771cdf0e10cSrcweir 					}
772cdf0e10cSrcweir 				}
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 				INetURLObject aPathURL( rURL );
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 				aPathURL.removeSegment();
777cdf0e10cSrcweir 				aPathURL.removeFinalSlash();
778cdf0e10cSrcweir 				pRet = new GalleryThemeEntry( aPathURL, aThemeName,
779cdf0e10cSrcweir 											  String(rURL.GetBase()).Copy( 2, 6 ).ToInt32(),
780cdf0e10cSrcweir 											  bReadOnly, sal_False, sal_False, nThemeId,
781cdf0e10cSrcweir 											  bThemeNameFromResource );
782cdf0e10cSrcweir 			}
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 			delete pIStm;
785cdf0e10cSrcweir 		}
786cdf0e10cSrcweir 	}
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 	return pRet;
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir // -----------------------------------------------------------------------------
792cdf0e10cSrcweir 
793*6dd94783SArmin Le Grand sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, BitmapEx& rBmp, sal_Bool )
794cdf0e10cSrcweir {
795cdf0e10cSrcweir 	SgaObject*	pObj = AcquireObject( nPos );
796cdf0e10cSrcweir 	sal_Bool		bRet = sal_False;
797cdf0e10cSrcweir 
798cdf0e10cSrcweir 	if( pObj )
799cdf0e10cSrcweir 	{
800cdf0e10cSrcweir 		rBmp = pObj->GetThumbBmp();
801cdf0e10cSrcweir 		ReleaseObject( pObj );
802cdf0e10cSrcweir 		bRet = sal_True;
803cdf0e10cSrcweir 	}
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 	return bRet;
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir // -----------------------------------------------------------------------------
809cdf0e10cSrcweir 
810cdf0e10cSrcweir sal_Bool GalleryTheme::GetGraphic( sal_uIntPtr nPos, Graphic& rGraphic, sal_Bool bProgress )
811cdf0e10cSrcweir {
812cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
813cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
814cdf0e10cSrcweir 
815cdf0e10cSrcweir 	if( pObject )
816cdf0e10cSrcweir 	{
817cdf0e10cSrcweir 		const INetURLObject aURL( ImplGetURL( pObject ) );
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 		switch( pObject->eObjKind )
820cdf0e10cSrcweir 		{
821cdf0e10cSrcweir 			case( SGA_OBJ_BMP ):
822cdf0e10cSrcweir 			case( SGA_OBJ_ANIM ):
823cdf0e10cSrcweir 			case( SGA_OBJ_INET ):
824cdf0e10cSrcweir 			{
825cdf0e10cSrcweir 				String aFilterDummy;
826cdf0e10cSrcweir 				bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy, bProgress ) != SGA_IMPORT_NONE );
827cdf0e10cSrcweir 			}
828cdf0e10cSrcweir 			break;
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 			case( SGA_OBJ_SVDRAW ):
831cdf0e10cSrcweir 			{
832cdf0e10cSrcweir                 SvxGalleryDrawModel aModel;
833cdf0e10cSrcweir 
834cdf0e10cSrcweir                 if( aModel.GetModel() )
835cdf0e10cSrcweir                 {
836cdf0e10cSrcweir 				    if( GetModel( nPos, *aModel.GetModel(), bProgress ) )
837cdf0e10cSrcweir 				    {
838cdf0e10cSrcweir 					    ImageMap aIMap;
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 					    if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
841cdf0e10cSrcweir 						    bRet = sal_True;
842cdf0e10cSrcweir 					    else
843cdf0e10cSrcweir 					    {
844cdf0e10cSrcweir 						    VirtualDevice aVDev;
845cdf0e10cSrcweir 						    aVDev.SetMapMode( MapMode( MAP_100TH_MM ) );
846cdf0e10cSrcweir 						    FmFormView aView( aModel.GetModel(), &aVDev );
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 						    aView.hideMarkHandles();
849cdf0e10cSrcweir 						    aView.ShowSdrPage(aView.GetModel()->GetPage(0));
850cdf0e10cSrcweir 						    aView.MarkAll();
851cdf0e10cSrcweir 						    rGraphic = aView.GetAllMarkedGraphic();
852cdf0e10cSrcweir 						    bRet = sal_True;
853cdf0e10cSrcweir 					    }
854cdf0e10cSrcweir 				    }
855cdf0e10cSrcweir                 }
856cdf0e10cSrcweir 			}
857cdf0e10cSrcweir 			break;
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 			case( SGA_OBJ_SOUND ):
860cdf0e10cSrcweir 			{
861cdf0e10cSrcweir 				SgaObject* pObj = AcquireObject( nPos );
862cdf0e10cSrcweir 
863cdf0e10cSrcweir 				if( pObj )
864cdf0e10cSrcweir 				{
865*6dd94783SArmin Le Grand                     rGraphic = pObj->GetThumbBmp();
866*6dd94783SArmin Le Grand 					//Bitmap aBmp( pObj->GetThumbBmp() );
867*6dd94783SArmin Le Grand 					//aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
868*6dd94783SArmin Le Grand 					//rGraphic = aBmp;
869cdf0e10cSrcweir 					ReleaseObject( pObj );
870cdf0e10cSrcweir 					bRet = sal_True;
871cdf0e10cSrcweir 				}
872cdf0e10cSrcweir 			}
873cdf0e10cSrcweir 			break;
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 			default:
876cdf0e10cSrcweir 			break;
877cdf0e10cSrcweir 		}
878cdf0e10cSrcweir 	}
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 	return bRet;
881cdf0e10cSrcweir }
882cdf0e10cSrcweir 
883cdf0e10cSrcweir // -----------------------------------------------------------------------------
884cdf0e10cSrcweir 
885cdf0e10cSrcweir sal_Bool GalleryTheme::InsertGraphic( const Graphic& rGraphic, sal_uIntPtr nInsertPos )
886cdf0e10cSrcweir {
887cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 	if( rGraphic.GetType() != GRAPHIC_NONE )
890cdf0e10cSrcweir     {
891cdf0e10cSrcweir 		sal_uIntPtr           nExportFormat = CVT_UNKNOWN;
892cdf0e10cSrcweir 		const GfxLink	aGfxLink( ( (Graphic&) rGraphic ).GetLink() );
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 		if( aGfxLink.GetDataSize() )
895cdf0e10cSrcweir 		{
896cdf0e10cSrcweir 			switch( aGfxLink.GetType() )
897cdf0e10cSrcweir 			{
898cdf0e10cSrcweir 				case( GFX_LINK_TYPE_EPS_BUFFER ): nExportFormat = CVT_SVM; break;
899cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_GIF ): nExportFormat = CVT_GIF; break;
900cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_JPG ): nExportFormat = CVT_JPG; break;
901cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_PNG ): nExportFormat = CVT_PNG; break;
902cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_TIF ): nExportFormat = CVT_TIF; break;
903cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_WMF ): nExportFormat = CVT_WMF; break;
904cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_MET ): nExportFormat = CVT_MET; break;
905cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_PCT ): nExportFormat = CVT_PCT; break;
906cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_SVG ): nExportFormat = CVT_SVG; break;
907cdf0e10cSrcweir 				default:
908cdf0e10cSrcweir 					break;
909cdf0e10cSrcweir 			}
910cdf0e10cSrcweir 		}
911cdf0e10cSrcweir 		else
912cdf0e10cSrcweir 		{
913cdf0e10cSrcweir 		    if( rGraphic.GetType() == GRAPHIC_BITMAP )
914cdf0e10cSrcweir 		    {
915cdf0e10cSrcweir 			    if( rGraphic.IsAnimated() )
916cdf0e10cSrcweir 				    nExportFormat = CVT_GIF;
917cdf0e10cSrcweir 			    else
918cdf0e10cSrcweir 				    nExportFormat = CVT_PNG;
919cdf0e10cSrcweir 		    }
920cdf0e10cSrcweir 		    else
921cdf0e10cSrcweir                 nExportFormat = CVT_SVM;
922cdf0e10cSrcweir 		}
923cdf0e10cSrcweir 
924cdf0e10cSrcweir         const INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_BMP, nExportFormat ) );
925cdf0e10cSrcweir 		SvStream*           pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
926cdf0e10cSrcweir 
927cdf0e10cSrcweir         if( pOStm )
928cdf0e10cSrcweir         {
929cdf0e10cSrcweir 		    pOStm->SetVersion( SOFFICE_FILEFORMAT_50 );
930cdf0e10cSrcweir 
931cdf0e10cSrcweir             if( CVT_SVM == nExportFormat )
932cdf0e10cSrcweir             {
933cdf0e10cSrcweir                 GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 			    aMtf.Write( *pOStm );
936cdf0e10cSrcweir 			    bRet = ( pOStm->GetError() == ERRCODE_NONE );
937cdf0e10cSrcweir             }
938cdf0e10cSrcweir             else
939cdf0e10cSrcweir             {
940cdf0e10cSrcweir                 if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
941cdf0e10cSrcweir                 {
942cdf0e10cSrcweir                     pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
943cdf0e10cSrcweir                     bRet = ( pOStm->GetError() == ERRCODE_NONE );
944cdf0e10cSrcweir                 }
945cdf0e10cSrcweir                 else
946cdf0e10cSrcweir                     bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE );
947cdf0e10cSrcweir             }
948cdf0e10cSrcweir 
949cdf0e10cSrcweir             delete pOStm;
950cdf0e10cSrcweir         }
951cdf0e10cSrcweir 
952cdf0e10cSrcweir 		if( bRet )
953cdf0e10cSrcweir 		{
954cdf0e10cSrcweir 			const SgaObjectBmp aObjBmp( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
955cdf0e10cSrcweir 			InsertObject( aObjBmp, nInsertPos );
956cdf0e10cSrcweir 		}
957cdf0e10cSrcweir 	}
958cdf0e10cSrcweir 
959cdf0e10cSrcweir 	return bRet;
960cdf0e10cSrcweir }
961cdf0e10cSrcweir 
962cdf0e10cSrcweir // -----------------------------------------------------------------------------
963cdf0e10cSrcweir 
964cdf0e10cSrcweir sal_Bool GalleryTheme::GetModel( sal_uIntPtr nPos, SdrModel& rModel, sal_Bool )
965cdf0e10cSrcweir {
966cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
967cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 	if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
970cdf0e10cSrcweir 	{
971cdf0e10cSrcweir 		const INetURLObject aURL( ImplGetURL( pObject ) );
972cdf0e10cSrcweir 		SvStorageRef		xStor( GetSvDrawStorage() );
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 		if( xStor.Is() )
975cdf0e10cSrcweir 		{
976cdf0e10cSrcweir 			const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
977cdf0e10cSrcweir 			SvStorageStreamRef	xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 			if( xIStm.Is() && !xIStm->GetError() )
980cdf0e10cSrcweir 			{
981cdf0e10cSrcweir 				xIStm->SetBufferSize( STREAMBUF_SIZE );
982cdf0e10cSrcweir 				bRet = GallerySvDrawImport( *xIStm, rModel );
983cdf0e10cSrcweir 				xIStm->SetBufferSize( 0L );
984cdf0e10cSrcweir 			}
985cdf0e10cSrcweir 		}
986cdf0e10cSrcweir 	}
987cdf0e10cSrcweir 
988cdf0e10cSrcweir 	return bRet;
989cdf0e10cSrcweir }
990cdf0e10cSrcweir 
991cdf0e10cSrcweir // -----------------------------------------------------------------------------
992cdf0e10cSrcweir 
993cdf0e10cSrcweir sal_Bool GalleryTheme::InsertModel( const FmFormModel& rModel, sal_uIntPtr nInsertPos )
994cdf0e10cSrcweir {
995cdf0e10cSrcweir 	INetURLObject	aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
996cdf0e10cSrcweir 	SvStorageRef	xStor( GetSvDrawStorage() );
997cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
998cdf0e10cSrcweir 
999cdf0e10cSrcweir 	if( xStor.Is() )
1000cdf0e10cSrcweir 	{
1001cdf0e10cSrcweir 		const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1002cdf0e10cSrcweir 		SvStorageStreamRef	xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir 		if( xOStm.Is() && !xOStm->GetError() )
1005cdf0e10cSrcweir 		{
1006cdf0e10cSrcweir 			SvMemoryStream	aMemStm( 65535, 65535 );
1007cdf0e10cSrcweir 			FmFormModel*	pFormModel = (FmFormModel*) &rModel;
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 		    pFormModel->BurnInStyleSheetAttributes();
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir             {
1012cdf0e10cSrcweir 			    uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( aMemStm ) );
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir         	    if( xDocOut.is() )
1015cdf0e10cSrcweir                     SvxDrawingLayerExport( pFormModel, xDocOut );
1016cdf0e10cSrcweir 		    }
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir             aMemStm.Seek( 0 );
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 		    xOStm->SetBufferSize( 16348 );
1021cdf0e10cSrcweir 			GalleryCodec aCodec( *xOStm );
1022cdf0e10cSrcweir 		    aCodec.Write( aMemStm );
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 		    if( !xOStm->GetError() )
1025cdf0e10cSrcweir 		    {
1026cdf0e10cSrcweir 			    SgaObjectSvDraw	aObjSvDraw( rModel, aURL );
1027cdf0e10cSrcweir 			    bRet = InsertObject( aObjSvDraw, nInsertPos );
1028cdf0e10cSrcweir 		    }
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 		    xOStm->SetBufferSize( 0L );
1031cdf0e10cSrcweir             xOStm->Commit();
1032cdf0e10cSrcweir         }
1033cdf0e10cSrcweir 	}
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 	return bRet;
1036cdf0e10cSrcweir }
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir // -----------------------------------------------------------------------------
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir sal_Bool GalleryTheme::GetModelStream( sal_uIntPtr nPos, SotStorageStreamRef& rxModelStream, sal_Bool )
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
1043cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir 	if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
1046cdf0e10cSrcweir 	{
1047cdf0e10cSrcweir 		const INetURLObject aURL( ImplGetURL( pObject ) );
1048cdf0e10cSrcweir 		SvStorageRef		xStor( GetSvDrawStorage() );
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 		if( xStor.Is() )
1051cdf0e10cSrcweir 		{
1052cdf0e10cSrcweir 			const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1053cdf0e10cSrcweir 			SvStorageStreamRef	xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir 			if( xIStm.Is() && !xIStm->GetError() )
1056cdf0e10cSrcweir 			{
1057cdf0e10cSrcweir             	sal_uInt32 nVersion = 0;
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir                 xIStm->SetBufferSize( 16348 );
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 	            if( GalleryCodec::IsCoded( *xIStm, nVersion ) )
1062cdf0e10cSrcweir                 {
1063cdf0e10cSrcweir                     SvxGalleryDrawModel aModel;
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir                     if( aModel.GetModel() )
1066cdf0e10cSrcweir                     {
1067cdf0e10cSrcweir                         if( GallerySvDrawImport( *xIStm, *aModel.GetModel() ) )
1068cdf0e10cSrcweir                         {
1069cdf0e10cSrcweir                             aModel.GetModel()->BurnInStyleSheetAttributes();
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir                             {
1072cdf0e10cSrcweir                                 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) );
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir                                 if( SvxDrawingLayerExport( aModel.GetModel(), xDocOut ) )
1075cdf0e10cSrcweir                                     rxModelStream->Commit();
1076cdf0e10cSrcweir                             }
1077cdf0e10cSrcweir                         }
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir                         bRet = ( rxModelStream->GetError() == ERRCODE_NONE );
1080cdf0e10cSrcweir                     }
1081cdf0e10cSrcweir                 }
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir                 xIStm->SetBufferSize( 0 );
1084cdf0e10cSrcweir 			}
1085cdf0e10cSrcweir 		}
1086cdf0e10cSrcweir 	}
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 	return bRet;
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir // -----------------------------------------------------------------------------
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir sal_Bool GalleryTheme::InsertModelStream( const SotStorageStreamRef& rxModelStream, sal_uIntPtr nInsertPos )
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir 	INetURLObject	aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
1096cdf0e10cSrcweir 	SvStorageRef	xStor( GetSvDrawStorage() );
1097cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir 	if( xStor.Is() )
1100cdf0e10cSrcweir 	{
1101cdf0e10cSrcweir 		const String		aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1102cdf0e10cSrcweir 		SvStorageStreamRef	xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 		if( xOStm.Is() && !xOStm->GetError() )
1105cdf0e10cSrcweir 		{
1106cdf0e10cSrcweir             GalleryCodec    aCodec( *xOStm );
1107cdf0e10cSrcweir             SvMemoryStream  aMemStm( 65535, 65535 );
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir 		    xOStm->SetBufferSize( 16348 );
1110cdf0e10cSrcweir             aCodec.Write( *rxModelStream );
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir 		    if( !xOStm->GetError() )
1113cdf0e10cSrcweir 		    {
1114cdf0e10cSrcweir 			    xOStm->Seek( 0 );
1115cdf0e10cSrcweir                 SgaObjectSvDraw	aObjSvDraw( *xOStm, aURL );
1116cdf0e10cSrcweir 			    bRet = InsertObject( aObjSvDraw, nInsertPos );
1117cdf0e10cSrcweir 		    }
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir 		    xOStm->SetBufferSize( 0L );
1120cdf0e10cSrcweir             xOStm->Commit();
1121cdf0e10cSrcweir         }
1122cdf0e10cSrcweir 	}
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir 	return bRet;
1125cdf0e10cSrcweir }
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir // -----------------------------------------------------------------------------
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir sal_Bool GalleryTheme::GetURL( sal_uIntPtr nPos, INetURLObject& rURL, sal_Bool )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir 	const GalleryObject*	pObject = ImplGetGalleryObject( nPos );
1132cdf0e10cSrcweir 	sal_Bool					bRet = sal_False;
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir 	if( pObject )
1135cdf0e10cSrcweir 	{
1136cdf0e10cSrcweir 		rURL = INetURLObject( ImplGetURL( pObject ) );
1137cdf0e10cSrcweir 		bRet = sal_True;
1138cdf0e10cSrcweir 	}
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir 	return bRet;
1141cdf0e10cSrcweir }
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir // -----------------------------------------------------------------------------
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir sal_Bool GalleryTheme::InsertURL( const INetURLObject& rURL, sal_uIntPtr nInsertPos )
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir 	Graphic			aGraphic;
1148cdf0e10cSrcweir 	String			aFormat;
1149cdf0e10cSrcweir 	SgaObject*		pNewObj = NULL;
1150cdf0e10cSrcweir 	const sal_uInt16	nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
1151cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir 	if( nImportRet != SGA_IMPORT_NONE )
1154cdf0e10cSrcweir 	{
1155cdf0e10cSrcweir 		if ( SGA_IMPORT_INET == nImportRet )
1156cdf0e10cSrcweir 			pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, rURL, aFormat );
1157cdf0e10cSrcweir 		else if ( aGraphic.IsAnimated() )
1158cdf0e10cSrcweir 			pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, rURL, aFormat );
1159cdf0e10cSrcweir 		else
1160cdf0e10cSrcweir 			pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, rURL, aFormat );
1161cdf0e10cSrcweir 	}
1162cdf0e10cSrcweir 	else if( ::avmedia::MediaWindow::isMediaURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
1163cdf0e10cSrcweir 		pNewObj = (SgaObject*) new SgaObjectSound( rURL );
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 	if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
1166cdf0e10cSrcweir 		bRet = sal_True;
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir 	delete pNewObj;
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir 	return bRet;
1171cdf0e10cSrcweir }
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir // -----------------------------------------------------------------------------
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir sal_Bool GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, sal_uIntPtr nInsertPos )
1176cdf0e10cSrcweir {
1177cdf0e10cSrcweir     INetURLObject                   aURL;
1178cdf0e10cSrcweir     ::std::vector< INetURLObject >  aURLVector;
1179cdf0e10cSrcweir 	sal_Bool                            bRet = sal_False;
1180cdf0e10cSrcweir 
1181cdf0e10cSrcweir 	try
1182cdf0e10cSrcweir 	{
1183cdf0e10cSrcweir 		::ucbhelper::Content         aCnt( rFileOrDirURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
1184cdf0e10cSrcweir 		sal_Bool        bFolder = false;
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir 		aCnt.getPropertyValue( OUString::createFromAscii( "IsFolder" ) ) >>= bFolder;
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir 		if( bFolder )
1189cdf0e10cSrcweir 		{
1190cdf0e10cSrcweir 			uno::Sequence< OUString > aProps( 1 );
1191cdf0e10cSrcweir 			aProps.getArray()[ 0 ] = OUString::createFromAscii( "Url" );
1192cdf0e10cSrcweir 			uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
1193cdf0e10cSrcweir             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1194cdf0e10cSrcweir 			if( xContentAccess.is() )
1195cdf0e10cSrcweir 			{
1196cdf0e10cSrcweir 				while( xResultSet->next() )
1197cdf0e10cSrcweir 				{
1198cdf0e10cSrcweir 					aURL.SetSmartURL( xContentAccess->queryContentIdentifierString() );
1199cdf0e10cSrcweir                     aURLVector.push_back( aURL );
1200cdf0e10cSrcweir 				}
1201cdf0e10cSrcweir 			}
1202cdf0e10cSrcweir 		}
1203cdf0e10cSrcweir 		else
1204cdf0e10cSrcweir             aURLVector.push_back( rFileOrDirURL );
1205cdf0e10cSrcweir 	}
1206cdf0e10cSrcweir 	catch( const ucb::ContentCreationException& )
1207cdf0e10cSrcweir 	{
1208cdf0e10cSrcweir 	}
1209cdf0e10cSrcweir 	catch( const uno::RuntimeException& )
1210cdf0e10cSrcweir 	{
1211cdf0e10cSrcweir 	}
1212cdf0e10cSrcweir 	catch( const uno::Exception& )
1213cdf0e10cSrcweir 	{
1214cdf0e10cSrcweir 	}
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir     ::std::vector< INetURLObject >::const_iterator aIter( aURLVector.begin() ), aEnd( aURLVector.end() );
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir     while( aIter != aEnd )
1219cdf0e10cSrcweir         bRet = bRet || InsertURL( *aIter++, nInsertPos );
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir     return bRet;
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir // -----------------------------------------------------------------------------
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir sal_Bool GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uIntPtr nInsertPos )
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir 	if( rxTransferable.is() )
1231cdf0e10cSrcweir 	{
1232cdf0e10cSrcweir 		TransferableDataHelper	aDataHelper( rxTransferable );
1233cdf0e10cSrcweir 		Graphic*				pGraphic = NULL;
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir 		if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
1236cdf0e10cSrcweir 		{
1237cdf0e10cSrcweir 			SotStorageStreamRef xModelStm;
1238cdf0e10cSrcweir 
1239cdf0e10cSrcweir 			if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) )
1240cdf0e10cSrcweir 				bRet = InsertModelStream( xModelStm, nInsertPos );
1241cdf0e10cSrcweir 		}
1242cdf0e10cSrcweir 		else if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
1243cdf0e10cSrcweir                  aDataHelper.HasFormat( FORMAT_FILE ) )
1244cdf0e10cSrcweir 		{
1245cdf0e10cSrcweir             FileList aFileList;
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir             if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) )
1248cdf0e10cSrcweir                 aDataHelper.GetFileList( SOT_FORMAT_FILE_LIST, aFileList );
1249cdf0e10cSrcweir             else
1250cdf0e10cSrcweir             {
1251cdf0e10cSrcweir                 String aFile;
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir                 aDataHelper.GetString( FORMAT_FILE, aFile );
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir                 if( aFile.Len() )
1256cdf0e10cSrcweir                     aFileList.AppendFile( aFile );
1257cdf0e10cSrcweir             }
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir             for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
1260cdf0e10cSrcweir             {
1261cdf0e10cSrcweir                 const String    aFile( aFileList.GetFile( i ) );
1262cdf0e10cSrcweir                 INetURLObject   aURL( aFile );
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir                 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
1265cdf0e10cSrcweir                 {
1266cdf0e10cSrcweir                     String aLocalURL;
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir                     if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aLocalURL ) )
1269cdf0e10cSrcweir                         aURL = INetURLObject( aLocalURL );
1270cdf0e10cSrcweir                 }
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir                 if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1273cdf0e10cSrcweir                     bRet = InsertFileOrDirURL( aURL, nInsertPos );
1274cdf0e10cSrcweir 			}
1275cdf0e10cSrcweir 		}
1276cdf0e10cSrcweir 		else
1277cdf0e10cSrcweir 		{
1278cdf0e10cSrcweir 			Graphic	aGraphic;
1279cdf0e10cSrcweir 			sal_uIntPtr	nFormat = 0;
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir 			if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
1282cdf0e10cSrcweir 				nFormat = SOT_FORMATSTR_ID_SVXB;
1283cdf0e10cSrcweir 			else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1284cdf0e10cSrcweir 				nFormat = FORMAT_GDIMETAFILE;
1285cdf0e10cSrcweir 			else if( aDataHelper.HasFormat( FORMAT_BITMAP ) )
1286cdf0e10cSrcweir 				nFormat = FORMAT_BITMAP;
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir 			if( nFormat && aDataHelper.GetGraphic( nFormat, aGraphic ) )
1289cdf0e10cSrcweir 				pGraphic = new Graphic( aGraphic );
1290cdf0e10cSrcweir 		}
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir 		if( pGraphic )
1293cdf0e10cSrcweir 		{
1294cdf0e10cSrcweir 			bRet = sal_False;
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir 			if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
1297cdf0e10cSrcweir 			{
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir 				ImageMap aImageMap;
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir                 // according to KA we don't need a BaseURL here
1302cdf0e10cSrcweir                 if( aDataHelper.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) )
1303cdf0e10cSrcweir 				{
1304cdf0e10cSrcweir                     SvxGalleryDrawModel aModel;
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir                     if( aModel.GetModel() )
1307cdf0e10cSrcweir                     {
1308cdf0e10cSrcweir 					    SgaUserDataFactory	aFactory;
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir 					    SdrPage*	pPage = aModel.GetModel()->GetPage(0);
1311cdf0e10cSrcweir 					    SdrGrafObj*	pGrafObj = new SdrGrafObj( *pGraphic );
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir 					    pGrafObj->InsertUserData( new SgaIMapInfo( aImageMap ) );
1314cdf0e10cSrcweir 					    pPage->InsertObject( pGrafObj );
1315cdf0e10cSrcweir 					    bRet = InsertModel( *aModel.GetModel(), nInsertPos );
1316cdf0e10cSrcweir                     }
1317cdf0e10cSrcweir 				}
1318cdf0e10cSrcweir 			}
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir 			if( !bRet )
1321cdf0e10cSrcweir 				bRet = InsertGraphic( *pGraphic, nInsertPos );
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir 			delete pGraphic;
1324cdf0e10cSrcweir 		}
1325cdf0e10cSrcweir 	}
1326cdf0e10cSrcweir 
1327cdf0e10cSrcweir 	return bRet;
1328cdf0e10cSrcweir }
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir // -----------------------------------------------------------------------------
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir void GalleryTheme::CopyToClipboard( Window* pWindow, sal_uIntPtr nPos )
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir 	GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
1335cdf0e10cSrcweir 	pTransferable->CopyToClipboard( pWindow );
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir // -----------------------------------------------------------------------------
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir void GalleryTheme::StartDrag( Window* pWindow, sal_uIntPtr nPos )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir 	GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true );
1343cdf0e10cSrcweir 	pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK );
1344cdf0e10cSrcweir }
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir // -----------------------------------------------------------------------------
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const
1349cdf0e10cSrcweir {
1350cdf0e10cSrcweir 	const INetURLObject	aRelURL1( GetParent()->GetRelativeURL() );
1351cdf0e10cSrcweir 	const INetURLObject	aRelURL2( GetParent()->GetUserURL() );
1352cdf0e10cSrcweir 	INetURLObject		aNewURL, aTempURL;
1353cdf0e10cSrcweir 	sal_uInt32			nCount = GetObjectCount();
1354cdf0e10cSrcweir 	sal_Bool				bRel;
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir 	rOStm << (sal_uInt16) 0x0004;
1357cdf0e10cSrcweir 	rOStm << ByteString( GetRealName(), RTL_TEXTENCODING_UTF8 );
1358cdf0e10cSrcweir 	rOStm << nCount << (sal_uInt16) gsl_getSystemTextEncoding();
1359cdf0e10cSrcweir 
1360cdf0e10cSrcweir 	for( sal_uInt32 i = 0; i < nCount; i++ )
1361cdf0e10cSrcweir 	{
1362cdf0e10cSrcweir 		const GalleryObject* pObj = ImplGetGalleryObject( i );
1363cdf0e10cSrcweir 		String				 aPath;
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir 		if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1366cdf0e10cSrcweir 		{
1367cdf0e10cSrcweir 			aPath = GetSvDrawStreamNameFromURL( pObj->aURL );
1368cdf0e10cSrcweir 			bRel = sal_False;
1369cdf0e10cSrcweir 		}
1370cdf0e10cSrcweir 		else
1371cdf0e10cSrcweir 		{
1372cdf0e10cSrcweir 			aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1373cdf0e10cSrcweir 			bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL1.GetMainURL( INetURLObject::NO_DECODE ) ));
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir 			if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
1376cdf0e10cSrcweir 			{
1377cdf0e10cSrcweir 				aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1378cdf0e10cSrcweir 				aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
1379cdf0e10cSrcweir 			}
1380cdf0e10cSrcweir 			else
1381cdf0e10cSrcweir 			{
1382cdf0e10cSrcweir 				aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1383cdf0e10cSrcweir 				bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL2.GetMainURL( INetURLObject::NO_DECODE ) ));
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir 				if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
1386cdf0e10cSrcweir 				{
1387cdf0e10cSrcweir 					aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1388cdf0e10cSrcweir 					aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
1389cdf0e10cSrcweir 				}
1390cdf0e10cSrcweir 				else
1391cdf0e10cSrcweir 					aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1392cdf0e10cSrcweir 			}
1393cdf0e10cSrcweir 		}
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir 		aPath.SearchAndReplace(m_aDestDir, String());
1396cdf0e10cSrcweir 		rOStm << bRel << ByteString( aPath, RTL_TEXTENCODING_UTF8 ) << pObj->nOffset << (sal_uInt16) pObj->eObjKind;
1397cdf0e10cSrcweir 	}
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir 	// neuerdings wird ein 512-Byte-Reservepuffer gechrieben;
1400cdf0e10cSrcweir 	// um diesen zu erkennen werden zwei sal_uIntPtr-Ids geschrieben
1401cdf0e10cSrcweir 	rOStm << COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) << COMPAT_FORMAT( 'E', 'S', 'R', 'V' );
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir 	const long		nReservePos = rOStm.Tell();
1404cdf0e10cSrcweir 	VersionCompat*	pCompat = new VersionCompat( rOStm, STREAM_WRITE, 2 );
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir 	rOStm << (sal_uInt32) GetId() << IsThemeNameFromResource(); // ab Version 2
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir 	delete pCompat;
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir 	// Rest des Puffers auffuellen
1411cdf0e10cSrcweir 	const long	nRest = Max( 512L - ( (long) rOStm.Tell() - nReservePos ), 0L );
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir 	if( nRest )
1414cdf0e10cSrcweir 	{
1415cdf0e10cSrcweir 		char* pReserve = new char[ nRest ];
1416cdf0e10cSrcweir 		memset( pReserve, 0, nRest );
1417cdf0e10cSrcweir 		rOStm.Write( pReserve, nRest );
1418cdf0e10cSrcweir 		delete[] pReserve;
1419cdf0e10cSrcweir 	}
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir 	return rOStm;
1422cdf0e10cSrcweir }
1423cdf0e10cSrcweir 
1424cdf0e10cSrcweir // ------------------------------------------------------------------------
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir SvStream& GalleryTheme::ReadData( SvStream& rIStm )
1427cdf0e10cSrcweir {
1428cdf0e10cSrcweir 	sal_uInt32			nCount;
1429cdf0e10cSrcweir 	sal_uInt16			nVersion;
1430cdf0e10cSrcweir 	ByteString			aTmpStr;
1431cdf0e10cSrcweir 	String				aThemeName;
1432cdf0e10cSrcweir 	rtl_TextEncoding	nTextEncoding;
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	aImportName = String();
1435cdf0e10cSrcweir 	rIStm >> nVersion >> aTmpStr >> nCount;
1436cdf0e10cSrcweir 
1437cdf0e10cSrcweir 	if( nVersion >= 0x0004 )
1438cdf0e10cSrcweir 	{
1439cdf0e10cSrcweir 		sal_uInt16 nTmp16;
1440cdf0e10cSrcweir 		rIStm >> nTmp16;
1441cdf0e10cSrcweir 		nTextEncoding = (rtl_TextEncoding) nTmp16;
1442cdf0e10cSrcweir 	}
1443cdf0e10cSrcweir 	else
1444cdf0e10cSrcweir 		nTextEncoding = RTL_TEXTENCODING_UTF8;
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 	aThemeName = String( aTmpStr.GetBuffer(), nTextEncoding );
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir 	if( nCount <= ( 1L << 14 ) )
1449cdf0e10cSrcweir 	{
1450cdf0e10cSrcweir 		GalleryObject*	pObj;
1451cdf0e10cSrcweir 		INetURLObject	aRelURL1( GetParent()->GetRelativeURL() );
1452cdf0e10cSrcweir 		INetURLObject	aRelURL2( GetParent()->GetUserURL() );
1453cdf0e10cSrcweir 		sal_uInt32		nId1, nId2;
1454cdf0e10cSrcweir 		sal_Bool			bRel;
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir 		for( pObj = aObjectList.First(); pObj; pObj = aObjectList.Next() )
1457cdf0e10cSrcweir 		{
1458cdf0e10cSrcweir 			Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
1459cdf0e10cSrcweir 			delete pObj;
1460cdf0e10cSrcweir 			Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
1461cdf0e10cSrcweir 		}
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir 		aObjectList.Clear();
1464cdf0e10cSrcweir 
1465cdf0e10cSrcweir 		for( sal_uInt32 i = 0; i < nCount; i++ )
1466cdf0e10cSrcweir 		{
1467cdf0e10cSrcweir 			pObj = new GalleryObject;
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir 			ByteString	aTempFileName;
1470cdf0e10cSrcweir 			String		aFileName;
1471cdf0e10cSrcweir 			String		aPath;
1472cdf0e10cSrcweir 			sal_uInt16	nTemp;
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir 			rIStm >> bRel >> aTempFileName >> pObj->nOffset;
1475cdf0e10cSrcweir 			rIStm >> nTemp; pObj->eObjKind = (SgaObjKind) nTemp;
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir 			aFileName = String( aTempFileName.GetBuffer(), gsl_getSystemTextEncoding() );
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir 			if( bRel )
1480cdf0e10cSrcweir 			{
1481cdf0e10cSrcweir 				aFileName.SearchAndReplaceAll( '\\', '/' );
1482cdf0e10cSrcweir 				aPath = aRelURL1.GetMainURL( INetURLObject::NO_DECODE );
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir 				if( aFileName.GetChar( 0 ) != '/' )
1485cdf0e10cSrcweir 			    		aPath += '/';
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir 				aPath += aFileName;
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir 				pObj->aURL = INetURLObject( aPath );
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir 				if( !FileExists( pObj->aURL ) )
1492cdf0e10cSrcweir 				{
1493cdf0e10cSrcweir 					aPath = aRelURL2.GetMainURL( INetURLObject::NO_DECODE );
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir 					if( aFileName.GetChar( 0 ) != '/' )
1496cdf0e10cSrcweir 						aPath += '/';
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir 					aPath += aFileName;
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir 					// assign this URL, even in the case it is not valid (#94482)
1501cdf0e10cSrcweir                     pObj->aURL = INetURLObject( aPath );
1502cdf0e10cSrcweir 				}
1503cdf0e10cSrcweir 			}
1504cdf0e10cSrcweir 			else
1505cdf0e10cSrcweir 			{
1506cdf0e10cSrcweir 				if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1507cdf0e10cSrcweir 				{
1508cdf0e10cSrcweir 					const static String aBaseURLStr( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/" ) );
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir 					String aDummyURL( aBaseURLStr );
1511cdf0e10cSrcweir 					pObj->aURL = INetURLObject( aDummyURL += aFileName, INET_PROT_PRIV_SOFFICE );
1512cdf0e10cSrcweir 				}
1513cdf0e10cSrcweir 				else
1514cdf0e10cSrcweir 				{
1515cdf0e10cSrcweir                     String aLocalURL;
1516cdf0e10cSrcweir 
1517cdf0e10cSrcweir 					pObj->aURL = INetURLObject( aFileName );
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir 					if( ( pObj->aURL.GetProtocol() == INET_PROT_NOT_VALID ) &&
1520cdf0e10cSrcweir 						::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aLocalURL ) )
1521cdf0e10cSrcweir 					{
1522cdf0e10cSrcweir 						pObj->aURL = INetURLObject( aLocalURL );
1523cdf0e10cSrcweir 					}
1524cdf0e10cSrcweir 				}
1525cdf0e10cSrcweir 			}
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 			aObjectList.Insert( pObj, LIST_APPEND );
1528cdf0e10cSrcweir 		}
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir 		rIStm >> nId1 >> nId2;
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir 		// in neueren Versionen befindet sich am Ende ein 512-Byte-Reservepuffer;
1533cdf0e10cSrcweir 		// die Daten befinden sich am Anfang dieses Puffers und
1534cdf0e10cSrcweir 		// sind durch eine VersionCompat geklammert
1535cdf0e10cSrcweir 		if( !rIStm.IsEof() &&
1536cdf0e10cSrcweir 			nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
1537cdf0e10cSrcweir 			nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
1538cdf0e10cSrcweir 		{
1539cdf0e10cSrcweir 			VersionCompat*	pCompat = new VersionCompat( rIStm, STREAM_READ );
1540cdf0e10cSrcweir 			sal_uInt32		nTemp32;
1541cdf0e10cSrcweir 			sal_Bool			bThemeNameFromResource = sal_False;
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir 			rIStm >> nTemp32;
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 			if( pCompat->GetVersion() >= 2 )
1546cdf0e10cSrcweir 			{
1547cdf0e10cSrcweir 				rIStm >> bThemeNameFromResource;
1548cdf0e10cSrcweir 			}
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir 			SetId( nTemp32, bThemeNameFromResource );
1551cdf0e10cSrcweir 			delete pCompat;
1552cdf0e10cSrcweir 		}
1553cdf0e10cSrcweir 	}
1554cdf0e10cSrcweir 	else
1555cdf0e10cSrcweir 		rIStm.SetError( SVSTREAM_READ_ERROR );
1556cdf0e10cSrcweir 
1557cdf0e10cSrcweir 	ImplSetModified( sal_False );
1558cdf0e10cSrcweir 
1559cdf0e10cSrcweir 	return rIStm;
1560cdf0e10cSrcweir }
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir // ------------------------------------------------------------------------
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir SvStream& operator<<( SvStream& rOut, const GalleryTheme& rTheme )
1565cdf0e10cSrcweir {
1566cdf0e10cSrcweir 	return rTheme.WriteData( rOut );
1567cdf0e10cSrcweir }
1568cdf0e10cSrcweir 
1569cdf0e10cSrcweir // ------------------------------------------------------------------------
1570cdf0e10cSrcweir 
1571cdf0e10cSrcweir SvStream& operator>>( SvStream& rIn, GalleryTheme& rTheme )
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir 	return rTheme.ReadData( rIn );
1574cdf0e10cSrcweir }
1575cdf0e10cSrcweir 
1576cdf0e10cSrcweir void GalleryTheme::ImplSetModified( sal_Bool bModified )
1577cdf0e10cSrcweir { pThm->SetModified( bModified ); }
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir const String& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); }
1580cdf0e10cSrcweir const INetURLObject& GalleryTheme::GetThmURL() const { return pThm->GetThmURL(); }
1581cdf0e10cSrcweir const INetURLObject& GalleryTheme::GetSdgURL() const { return pThm->GetSdgURL(); }
1582cdf0e10cSrcweir const INetURLObject& GalleryTheme::GetSdvURL() const { return pThm->GetSdvURL(); }
1583cdf0e10cSrcweir sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); }
1584cdf0e10cSrcweir void GalleryTheme::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); }
1585cdf0e10cSrcweir sal_Bool GalleryTheme::IsThemeNameFromResource() const { return pThm->IsNameFromResource(); }
1586cdf0e10cSrcweir sal_Bool GalleryTheme::IsImported() const { return pThm->IsImported(); }
1587cdf0e10cSrcweir sal_Bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); }
1588cdf0e10cSrcweir sal_Bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); }
1589cdf0e10cSrcweir sal_Bool GalleryTheme::IsModified() const { return pThm->IsModified(); }
1590cdf0e10cSrcweir const String& GalleryTheme::GetName() const	{ return IsImported() ? aImportName : pThm->GetThemeName(); }
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir void GalleryTheme::InsertAllThemes( ListBox& rListBox )
1593cdf0e10cSrcweir {
1594cdf0e10cSrcweir 	for( sal_uInt16 i = RID_GALLERYSTR_THEME_FIRST; i <= RID_GALLERYSTR_THEME_LAST; i++ )
1595cdf0e10cSrcweir 		rListBox.InsertEntry( String( GAL_RESID( i ) ) );
1596cdf0e10cSrcweir }
1597cdf0e10cSrcweir 
1598