xref: /AOO41X/main/svx/source/gallery2/galmisc.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
32*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
33*cdf0e10cSrcweir #include <unotools/processfactory.hxx>
34*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
35*cdf0e10cSrcweir #include <tools/resmgr.hxx>
36*cdf0e10cSrcweir #include <tools/urlobj.hxx>
37*cdf0e10cSrcweir #include <svl/solar.hrc>
38*cdf0e10cSrcweir #include <svl/urihelper.hxx>
39*cdf0e10cSrcweir #include <svtools/filter.hxx>
40*cdf0e10cSrcweir #include <svl/itempool.hxx>
41*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
42*cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
43*cdf0e10cSrcweir #include <vcl/svapp.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "svtools/filter.hxx"
46*cdf0e10cSrcweir #include <svx/svdpage.hxx>
47*cdf0e10cSrcweir #include <svx/svdograf.hxx>
48*cdf0e10cSrcweir #include <svx/fmmodel.hxx>
49*cdf0e10cSrcweir #include <svx/fmview.hxx>
50*cdf0e10cSrcweir #include <svx/unomodel.hxx>
51*cdf0e10cSrcweir #include "codec.hxx"
52*cdf0e10cSrcweir #include "gallery.hrc"
53*cdf0e10cSrcweir #include "svx/gallery1.hxx"
54*cdf0e10cSrcweir #include "svx/galtheme.hxx"
55*cdf0e10cSrcweir #include "svx/galmisc.hxx"
56*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir // --------------
62*cdf0e10cSrcweir // - Namespaces -
63*cdf0e10cSrcweir // --------------
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir using namespace ::rtl;
66*cdf0e10cSrcweir using namespace ::com::sun::star;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir // ----------
69*cdf0e10cSrcweir // - ResMgr -
70*cdf0e10cSrcweir // ----------
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir ResMgr* GetGalleryResMgr()
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	static ResMgr* pGalleryResMgr = NULL;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	if( !pGalleryResMgr )
77*cdf0e10cSrcweir 	{
78*cdf0e10cSrcweir 		ByteString aResMgrName( "gal" );
79*cdf0e10cSrcweir 		pGalleryResMgr = ResMgr::CreateResMgr(
80*cdf0e10cSrcweir 			aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
81*cdf0e10cSrcweir 	}
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	return pGalleryResMgr;
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir // -------------------------
87*cdf0e10cSrcweir // - GalleryResGetBitmapEx -
88*cdf0e10cSrcweir // -------------------------
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir BitmapEx GalleryResGetBitmapEx( sal_uInt32 nId )
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     BitmapEx aBmpEx( GAL_RESID( nId ) );
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     if( !aBmpEx.IsTransparent() )
95*cdf0e10cSrcweir             aBmpEx = BitmapEx( aBmpEx.GetBitmap(), COL_LIGHTMAGENTA );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     return aBmpEx;
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir // ----------------------
101*cdf0e10cSrcweir // - SgaUserDataFactory -
102*cdf0e10cSrcweir // ----------------------
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir IMPL_LINK( SgaUserDataFactory, MakeUserData, SdrObjFactory*, pObjFactory )
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	if ( pObjFactory->nInventor == IV_IMAPINFO && pObjFactory->nIdentifier == ID_IMAPINFO )
107*cdf0e10cSrcweir 		pObjFactory->pNewData = new SgaIMapInfo;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	return 0L;
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir // ------------------------
113*cdf0e10cSrcweir // - GalleryGraphicImport -
114*cdf0e10cSrcweir // ------------------------
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir sal_uInt16 GalleryGraphicImport( const INetURLObject& rURL, Graphic& rGraphic,
117*cdf0e10cSrcweir 				             String& rFilterName, sal_Bool bShowProgress )
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	sal_uInt16		nRet = SGA_IMPORT_NONE;
120*cdf0e10cSrcweir 	SfxMedium	aMedium( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ, sal_True );
121*cdf0e10cSrcweir 	String		aFilterName;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 	aMedium.DownLoad();
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	SvStream* pIStm = aMedium.GetInStream();
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	if( pIStm )
128*cdf0e10cSrcweir 	{
129*cdf0e10cSrcweir 		GraphicFilter*		pGraphicFilter = GraphicFilter::GetGraphicFilter();
130*cdf0e10cSrcweir 		GalleryProgress*	pProgress = bShowProgress ? new GalleryProgress( pGraphicFilter ) : NULL;
131*cdf0e10cSrcweir 		sal_uInt16				nFormat;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 		if( !pGraphicFilter->ImportGraphic( rGraphic, rURL.GetMainURL( INetURLObject::NO_DECODE ), *pIStm, GRFILTER_FORMAT_DONTKNOW, &nFormat ) )
134*cdf0e10cSrcweir 		{
135*cdf0e10cSrcweir 			rFilterName = pGraphicFilter->GetImportFormatName( nFormat );
136*cdf0e10cSrcweir 			nRet = SGA_IMPORT_FILE;
137*cdf0e10cSrcweir 		}
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 		delete pProgress;
140*cdf0e10cSrcweir 	}
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	return nRet;
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir // -----------------------
146*cdf0e10cSrcweir // - GallerySvDrawImport -
147*cdf0e10cSrcweir // -----------------------
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir sal_Bool GallerySvDrawImport( SvStream& rIStm, SdrModel& rModel )
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir 	sal_uInt32  nVersion;
152*cdf0e10cSrcweir     sal_Bool    bRet = sal_False;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	if( GalleryCodec::IsCoded( rIStm, nVersion ) )
155*cdf0e10cSrcweir 	{
156*cdf0e10cSrcweir 		SvMemoryStream	aMemStm( 65535, 65535 );
157*cdf0e10cSrcweir 		GalleryCodec	aCodec( rIStm );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 		aCodec.Read( aMemStm );
160*cdf0e10cSrcweir 		aMemStm.Seek( 0UL );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         if( 1 == nVersion )
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir 			DBG_ERROR( "staroffice binary file formats are no longer supported inside the gallery!" );
165*cdf0e10cSrcweir 		    bRet = false;
166*cdf0e10cSrcweir         }
167*cdf0e10cSrcweir         else if( 2 == nVersion )
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             // recall to read as XML
170*cdf0e10cSrcweir             bRet = GallerySvDrawImport( aMemStm, rModel );
171*cdf0e10cSrcweir         }
172*cdf0e10cSrcweir  	}
173*cdf0e10cSrcweir 	else
174*cdf0e10cSrcweir 	{
175*cdf0e10cSrcweir         // read as XML
176*cdf0e10cSrcweir     	uno::Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( rIStm ) );
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 		rModel.GetItemPool().SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
179*cdf0e10cSrcweir 		uno::Reference< lang::XComponent > xComponent;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 		bRet = SvxDrawingLayerImport( &rModel, xInputStream, xComponent, "com.sun.star.comp.Draw.XMLOasisImporter" );
182*cdf0e10cSrcweir 		if( !bRet || (rModel.GetPageCount() == 0) )
183*cdf0e10cSrcweir 		{
184*cdf0e10cSrcweir 			rIStm.Seek(0);
185*cdf0e10cSrcweir 			bRet = SvxDrawingLayerImport( &rModel, xInputStream, xComponent, "com.sun.star.comp.Draw.XMLImporter" );
186*cdf0e10cSrcweir 		}
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	return bRet;
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir // ---------------------
194*cdf0e10cSrcweir // - CreateIMapGraphic -
195*cdf0e10cSrcweir // ---------------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir sal_Bool CreateIMapGraphic( const FmFormModel& rModel, Graphic& rGraphic, ImageMap& rImageMap )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	if ( rModel.GetPageCount() )
202*cdf0e10cSrcweir 	{
203*cdf0e10cSrcweir 		const SdrPage*		pPage = rModel.GetPage( 0 );
204*cdf0e10cSrcweir 		const SdrObject*	pObj = pPage->GetObj( 0 );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 		if ( pPage->GetObjCount() == 1 && pObj->ISA( SdrGrafObj ) )
207*cdf0e10cSrcweir 		{
208*cdf0e10cSrcweir 			const sal_uInt16 nCount = pObj->GetUserDataCount();
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 			// gibt es in den User-Daten eine IMap-Information?
211*cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < nCount; i++ )
212*cdf0e10cSrcweir 			{
213*cdf0e10cSrcweir 				const SdrObjUserData* pUserData = pObj->GetUserData( i );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 				if ( ( pUserData->GetInventor() == IV_IMAPINFO ) && ( pUserData->GetId() == ID_IMAPINFO ) )
216*cdf0e10cSrcweir 				{
217*cdf0e10cSrcweir 					rGraphic = ( (SdrGrafObj*) pObj )->GetGraphic();
218*cdf0e10cSrcweir 					rImageMap = ( (SgaIMapInfo*) pUserData )->GetImageMap();
219*cdf0e10cSrcweir 					bRet = sal_True;
220*cdf0e10cSrcweir 					break;
221*cdf0e10cSrcweir 				}
222*cdf0e10cSrcweir 			}
223*cdf0e10cSrcweir 		}
224*cdf0e10cSrcweir 	}
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	return bRet;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir // --------------------
230*cdf0e10cSrcweir // - GetReducedString -
231*cdf0e10cSrcweir // --------------------
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir String GetReducedString( const INetURLObject& rURL, sal_uIntPtr nMaxLen )
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     String aReduced( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir     aReduced = aReduced.GetToken( aReduced.GetTokenCount( '/' ) - 1, '/' );
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     if( INET_PROT_PRIV_SOFFICE != rURL.GetProtocol() )
240*cdf0e10cSrcweir     {
241*cdf0e10cSrcweir         sal_Unicode     aDelimiter;
242*cdf0e10cSrcweir    	    const String    aPath( rURL.getFSysPath( INetURLObject::FSYS_DETECT, &aDelimiter ) );
243*cdf0e10cSrcweir         const String    aName( aReduced );
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir         if( aPath.Len() > nMaxLen )
246*cdf0e10cSrcweir         {
247*cdf0e10cSrcweir             aReduced = aPath.Copy( 0, (sal_uInt16)( nMaxLen - aName.Len() - 4 ) );
248*cdf0e10cSrcweir     	    aReduced += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
249*cdf0e10cSrcweir             aReduced += aDelimiter;
250*cdf0e10cSrcweir 		    aReduced += aName;
251*cdf0e10cSrcweir         }
252*cdf0e10cSrcweir         else
253*cdf0e10cSrcweir             aReduced = aPath;
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     return aReduced;
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir // -----------------------------------------------------------------------------
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir String GetSvDrawStreamNameFromURL( const INetURLObject& rSvDrawObjURL )
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir 	String aRet;
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	if( rSvDrawObjURL.GetProtocol() == INET_PROT_PRIV_SOFFICE &&
266*cdf0e10cSrcweir 		String(rSvDrawObjURL.GetMainURL( INetURLObject::NO_DECODE )).GetTokenCount( '/' ) == 3 )
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 		aRet = String(rSvDrawObjURL.GetMainURL( INetURLObject::NO_DECODE )).GetToken( 2, '/' );
269*cdf0e10cSrcweir 	}
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 	return aRet;
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir // -----------------------------------------------------------------------------
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir sal_Bool FileExists( const INetURLObject& rURL )
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	if( rURL.GetProtocol() != INET_PROT_NOT_VALID )
281*cdf0e10cSrcweir 	{
282*cdf0e10cSrcweir 		try
283*cdf0e10cSrcweir 		{
284*cdf0e10cSrcweir 			::ucbhelper::Content		aCnt( rURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
285*cdf0e10cSrcweir 			OUString	aTitle;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 			aCnt.getPropertyValue( OUString::createFromAscii( "Title" ) ) >>= aTitle;
288*cdf0e10cSrcweir 			bRet = ( aTitle.getLength() > 0 );
289*cdf0e10cSrcweir 		}
290*cdf0e10cSrcweir 		catch( const ucb::ContentCreationException& )
291*cdf0e10cSrcweir 		{
292*cdf0e10cSrcweir 		}
293*cdf0e10cSrcweir 		catch( const uno::RuntimeException& )
294*cdf0e10cSrcweir 		{
295*cdf0e10cSrcweir 		}
296*cdf0e10cSrcweir 	    catch( const uno::Exception& )
297*cdf0e10cSrcweir 	    {
298*cdf0e10cSrcweir 	    }
299*cdf0e10cSrcweir 	}
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 	return bRet;
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir // -----------------------------------------------------------------------------
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir sal_Bool CreateDir( const INetURLObject& rURL )
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir 	sal_Bool bRet = FileExists( rURL );
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 	if( !bRet )
311*cdf0e10cSrcweir 	{
312*cdf0e10cSrcweir 		try
313*cdf0e10cSrcweir 		{
314*cdf0e10cSrcweir 			uno::Reference< ucb::XCommandEnvironment >	aCmdEnv;
315*cdf0e10cSrcweir 			INetURLObject							aNewFolderURL( rURL );
316*cdf0e10cSrcweir 			INetURLObject							aParentURL( aNewFolderURL ); aParentURL.removeSegment();
317*cdf0e10cSrcweir 			::ucbhelper::Content					aParent( aParentURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
318*cdf0e10cSrcweir 			uno::Sequence< OUString >				aProps( 1 );
319*cdf0e10cSrcweir 			uno::Sequence< uno::Any >				aValues( 1 );
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 			aProps.getArray()[ 0 ] = OUString::createFromAscii( "Title" );
322*cdf0e10cSrcweir 			aValues.getArray()[ 0 ] = uno::makeAny( OUString( aNewFolderURL.GetName() ) );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir         ::ucbhelper::Content aContent( aNewFolderURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
325*cdf0e10cSrcweir         bRet = aParent.insertNewContent( OUString::createFromAscii( "application/vnd.sun.staroffice.fsys-folder" ), aProps, aValues, aContent );
326*cdf0e10cSrcweir 		}
327*cdf0e10cSrcweir 		catch( const ucb::ContentCreationException& )
328*cdf0e10cSrcweir 		{
329*cdf0e10cSrcweir 		}
330*cdf0e10cSrcweir 		catch( const uno::RuntimeException& )
331*cdf0e10cSrcweir 		{
332*cdf0e10cSrcweir 		}
333*cdf0e10cSrcweir 	    catch( const uno::Exception& )
334*cdf0e10cSrcweir 	    {
335*cdf0e10cSrcweir 	    }
336*cdf0e10cSrcweir 	}
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 	return bRet;
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir // -----------------------------------------------------------------------------
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir sal_Bool CopyFile(  const INetURLObject& rSrcURL, const INetURLObject& rDstURL )
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 	try
348*cdf0e10cSrcweir 	{
349*cdf0e10cSrcweir 		::ucbhelper::Content aDestPath( rDstURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 		aDestPath.executeCommand( OUString::createFromAscii( "transfer" ),
352*cdf0e10cSrcweir 								  uno::makeAny( ucb::TransferInfo( sal_False, rSrcURL.GetMainURL( INetURLObject::NO_DECODE ),
353*cdf0e10cSrcweir 												rDstURL.GetName(), ucb::NameClash::OVERWRITE ) ) );
354*cdf0e10cSrcweir 		bRet = sal_True;
355*cdf0e10cSrcweir 	}
356*cdf0e10cSrcweir 	catch( const ucb::ContentCreationException& )
357*cdf0e10cSrcweir 	{
358*cdf0e10cSrcweir 	}
359*cdf0e10cSrcweir 	catch( const uno::RuntimeException& )
360*cdf0e10cSrcweir 	{
361*cdf0e10cSrcweir 	}
362*cdf0e10cSrcweir 	catch( const uno::Exception& )
363*cdf0e10cSrcweir 	{
364*cdf0e10cSrcweir 	}
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir 	return bRet;
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir // -----------------------------------------------------------------------------
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir sal_Bool KillFile( const INetURLObject& rURL )
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir 	sal_Bool bRet = FileExists( rURL );
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 	if( bRet )
376*cdf0e10cSrcweir 	{
377*cdf0e10cSrcweir 		try
378*cdf0e10cSrcweir 		{
379*cdf0e10cSrcweir 			::ucbhelper::Content aCnt( rURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
380*cdf0e10cSrcweir 			aCnt.executeCommand( OUString::createFromAscii( "delete" ), uno::makeAny( sal_Bool( sal_True ) ) );
381*cdf0e10cSrcweir 		}
382*cdf0e10cSrcweir 		catch( const ucb::ContentCreationException& )
383*cdf0e10cSrcweir 		{
384*cdf0e10cSrcweir 			bRet = sal_False;
385*cdf0e10cSrcweir 		}
386*cdf0e10cSrcweir 		catch( const uno::RuntimeException& )
387*cdf0e10cSrcweir 		{
388*cdf0e10cSrcweir 			bRet = sal_False;
389*cdf0e10cSrcweir 		}
390*cdf0e10cSrcweir 	    catch( const uno::Exception& )
391*cdf0e10cSrcweir 	    {
392*cdf0e10cSrcweir             bRet = sal_False;
393*cdf0e10cSrcweir 	    }
394*cdf0e10cSrcweir 	}
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 	return bRet;
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir // -------------------
400*cdf0e10cSrcweir // - GalleryProgress -
401*cdf0e10cSrcweir // -------------------
402*cdf0e10cSrcweir DBG_NAME(GalleryProgress)
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir GalleryProgress::GalleryProgress( GraphicFilter* pFilter ) :
405*cdf0e10cSrcweir 	mpFilter( pFilter )
406*cdf0e10cSrcweir {
407*cdf0e10cSrcweir     DBG_CTOR(GalleryProgress,NULL);
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory > xMgr( ::utl::getProcessServiceFactory() );
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 	if( xMgr.is() )
412*cdf0e10cSrcweir 	{
413*cdf0e10cSrcweir 		uno::Reference< awt::XProgressMonitor >	xMonitor( xMgr->createInstance(
414*cdf0e10cSrcweir 													  ::rtl::OUString::createFromAscii( "com.sun.star.awt.XProgressMonitor" ) ),
415*cdf0e10cSrcweir 													  uno::UNO_QUERY );
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 		if ( xMonitor.is() )
418*cdf0e10cSrcweir 		{
419*cdf0e10cSrcweir 			mxProgressBar = uno::Reference< awt::XProgressBar >( xMonitor, uno::UNO_QUERY );
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 			if( mxProgressBar.is() )
422*cdf0e10cSrcweir 			{
423*cdf0e10cSrcweir 				String aProgressText;
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 				if( mpFilter )
426*cdf0e10cSrcweir 				{
427*cdf0e10cSrcweir 					aProgressText = String( GAL_RESID( RID_SVXSTR_GALLERY_FILTER ) );
428*cdf0e10cSrcweir //					mpFilter->SetUpdatePercentHdl( LINK( this, GalleryProgress, Update ) );		// sj: progress wasn't working up from SO7 at all
429*cdf0e10cSrcweir //																								// so I am removing this. The gallery progress should
430*cdf0e10cSrcweir //																								// be changed to use the XStatusIndicator instead of XProgressMonitor
431*cdf0e10cSrcweir 				}
432*cdf0e10cSrcweir 				else
433*cdf0e10cSrcweir 					aProgressText = String( RTL_CONSTASCII_USTRINGPARAM( "Gallery" ) );
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 				xMonitor->addText( String( RTL_CONSTASCII_USTRINGPARAM( "Gallery" ) ), aProgressText, sal_False ) ;
436*cdf0e10cSrcweir 				mxProgressBar->setRange( 0, GALLERY_PROGRESS_RANGE );
437*cdf0e10cSrcweir 			}
438*cdf0e10cSrcweir 		}
439*cdf0e10cSrcweir 	}
440*cdf0e10cSrcweir }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir // ------------------------------------------------------------------------
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir GalleryProgress::~GalleryProgress()
445*cdf0e10cSrcweir {
446*cdf0e10cSrcweir //	if( mpFilter )
447*cdf0e10cSrcweir //		mpFilter->SetUpdatePercentHdl( Link() );
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     DBG_DTOR(GalleryProgress,NULL);
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir // ------------------------------------------------------------------------
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir void GalleryProgress::Update( sal_uIntPtr nVal, sal_uIntPtr nMaxVal )
455*cdf0e10cSrcweir {
456*cdf0e10cSrcweir 	if( mxProgressBar.is() && nMaxVal )
457*cdf0e10cSrcweir 		mxProgressBar->setValue( Min( (sal_uIntPtr)( (double) nVal / nMaxVal * GALLERY_PROGRESS_RANGE ), (sal_uIntPtr) GALLERY_PROGRESS_RANGE ) );
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir // -----------------------
461*cdf0e10cSrcweir // - GalleryTransferable -
462*cdf0e10cSrcweir // -----------------------
463*cdf0e10cSrcweir DBG_NAME(GalleryTransferable)
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir GalleryTransferable::GalleryTransferable( GalleryTheme* pTheme, sal_uIntPtr nObjectPos, bool bLazy ) :
466*cdf0e10cSrcweir 	mpTheme( pTheme ),
467*cdf0e10cSrcweir 	meObjectKind( mpTheme->GetObjectKind( nObjectPos ) ),
468*cdf0e10cSrcweir 	mnObjectPos( nObjectPos ),
469*cdf0e10cSrcweir 	mpGraphicObject( NULL ),
470*cdf0e10cSrcweir 	mpImageMap( NULL ),
471*cdf0e10cSrcweir 	mpURL( NULL )
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir     DBG_CTOR(GalleryTransferable,NULL);
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir     InitData( bLazy );
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir // ------------------------------------------------------------------------
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir GalleryTransferable::~GalleryTransferable()
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir     DBG_DTOR(GalleryTransferable,NULL);
484*cdf0e10cSrcweir }
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir // ------------------------------------------------------------------------
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir void GalleryTransferable::InitData( bool bLazy )
489*cdf0e10cSrcweir {
490*cdf0e10cSrcweir     switch( meObjectKind )
491*cdf0e10cSrcweir     {
492*cdf0e10cSrcweir         case( SGA_OBJ_SVDRAW ):
493*cdf0e10cSrcweir         {
494*cdf0e10cSrcweir             if( !bLazy )
495*cdf0e10cSrcweir             {
496*cdf0e10cSrcweir                 if( !mpGraphicObject )
497*cdf0e10cSrcweir                 {
498*cdf0e10cSrcweir                     Graphic aGraphic;
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir                     if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
501*cdf0e10cSrcweir                         mpGraphicObject = new GraphicObject( aGraphic );
502*cdf0e10cSrcweir                 }
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir                 if( !mxModelStream.Is() )
505*cdf0e10cSrcweir                 {
506*cdf0e10cSrcweir                     mxModelStream = new SotStorageStream( String() );
507*cdf0e10cSrcweir                     mxModelStream->SetBufferSize( 16348 );
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir                     if( !mpTheme->GetModelStream( mnObjectPos, mxModelStream ) )
510*cdf0e10cSrcweir                         mxModelStream.Clear();
511*cdf0e10cSrcweir                     else
512*cdf0e10cSrcweir                         mxModelStream->Seek( 0 );
513*cdf0e10cSrcweir                 }
514*cdf0e10cSrcweir             }
515*cdf0e10cSrcweir         }
516*cdf0e10cSrcweir         break;
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir         case( SGA_OBJ_ANIM ):
519*cdf0e10cSrcweir         case( SGA_OBJ_BMP ):
520*cdf0e10cSrcweir         case( SGA_OBJ_INET ):
521*cdf0e10cSrcweir         case( SGA_OBJ_SOUND ):
522*cdf0e10cSrcweir         {
523*cdf0e10cSrcweir             if( !mpURL )
524*cdf0e10cSrcweir             {
525*cdf0e10cSrcweir                 mpURL = new INetURLObject;
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir                 if( !mpTheme->GetURL( mnObjectPos, *mpURL ) )
528*cdf0e10cSrcweir                     delete mpURL, mpURL = NULL;
529*cdf0e10cSrcweir             }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir             if( ( SGA_OBJ_SOUND != meObjectKind ) && !mpGraphicObject )
532*cdf0e10cSrcweir             {
533*cdf0e10cSrcweir                 Graphic aGraphic;
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir                 if( mpTheme->GetGraphic( mnObjectPos, aGraphic ) )
536*cdf0e10cSrcweir                     mpGraphicObject = new GraphicObject( aGraphic );
537*cdf0e10cSrcweir             }
538*cdf0e10cSrcweir         }
539*cdf0e10cSrcweir         break;
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir     	default:
542*cdf0e10cSrcweir             DBG_ERROR( "GalleryTransferable::GalleryTransferable: invalid object type" );
543*cdf0e10cSrcweir         break;
544*cdf0e10cSrcweir 	}
545*cdf0e10cSrcweir }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir // ------------------------------------------------------------------------
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir void GalleryTransferable::AddSupportedFormats()
550*cdf0e10cSrcweir {
551*cdf0e10cSrcweir     if( SGA_OBJ_SVDRAW == meObjectKind )
552*cdf0e10cSrcweir     {
553*cdf0e10cSrcweir         AddFormat( SOT_FORMATSTR_ID_DRAWING );
554*cdf0e10cSrcweir         AddFormat( SOT_FORMATSTR_ID_SVXB );
555*cdf0e10cSrcweir         AddFormat( FORMAT_GDIMETAFILE );
556*cdf0e10cSrcweir         AddFormat( FORMAT_BITMAP );
557*cdf0e10cSrcweir     }
558*cdf0e10cSrcweir     else
559*cdf0e10cSrcweir     {
560*cdf0e10cSrcweir         if( mpURL )
561*cdf0e10cSrcweir             AddFormat( FORMAT_FILE );
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir         if( mpGraphicObject )
564*cdf0e10cSrcweir         {
565*cdf0e10cSrcweir             AddFormat( SOT_FORMATSTR_ID_SVXB );
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir             if( mpGraphicObject->GetType() == GRAPHIC_GDIMETAFILE )
568*cdf0e10cSrcweir             {
569*cdf0e10cSrcweir                 AddFormat( FORMAT_GDIMETAFILE );
570*cdf0e10cSrcweir                 AddFormat( FORMAT_BITMAP );
571*cdf0e10cSrcweir             }
572*cdf0e10cSrcweir             else
573*cdf0e10cSrcweir             {
574*cdf0e10cSrcweir                 AddFormat( FORMAT_BITMAP );
575*cdf0e10cSrcweir                 AddFormat( FORMAT_GDIMETAFILE );
576*cdf0e10cSrcweir             }
577*cdf0e10cSrcweir         }
578*cdf0e10cSrcweir     }
579*cdf0e10cSrcweir }
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir // ------------------------------------------------------------------------
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir sal_Bool GalleryTransferable::GetData( const datatransfer::DataFlavor& rFlavor )
584*cdf0e10cSrcweir {
585*cdf0e10cSrcweir 	sal_uInt32	nFormat = SotExchange::GetFormat( rFlavor );
586*cdf0e10cSrcweir 	sal_Bool	bRet = sal_False;
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 	InitData( false );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 	if( ( SOT_FORMATSTR_ID_DRAWING == nFormat ) && ( SGA_OBJ_SVDRAW == meObjectKind ) )
591*cdf0e10cSrcweir 	{
592*cdf0e10cSrcweir         bRet = ( mxModelStream.Is() && SetObject( &mxModelStream, 0, rFlavor ) );
593*cdf0e10cSrcweir 	}
594*cdf0e10cSrcweir 	else if( ( SOT_FORMATSTR_ID_SVIM == nFormat ) && mpImageMap )
595*cdf0e10cSrcweir 	{
596*cdf0e10cSrcweir         // TODO/MBA: do we need a BaseURL here?!
597*cdf0e10cSrcweir         bRet = SetImageMap( *mpImageMap, rFlavor );
598*cdf0e10cSrcweir 	}
599*cdf0e10cSrcweir 	else if( ( FORMAT_FILE == nFormat ) && mpURL )
600*cdf0e10cSrcweir 	{
601*cdf0e10cSrcweir 		bRet = SetString( mpURL->GetMainURL( INetURLObject::NO_DECODE ), rFlavor );
602*cdf0e10cSrcweir 	}
603*cdf0e10cSrcweir 	else if( ( SOT_FORMATSTR_ID_SVXB == nFormat ) && mpGraphicObject )
604*cdf0e10cSrcweir 	{
605*cdf0e10cSrcweir 		bRet = SetGraphic( mpGraphicObject->GetGraphic(), rFlavor );
606*cdf0e10cSrcweir 	}
607*cdf0e10cSrcweir 	else if( ( FORMAT_GDIMETAFILE == nFormat ) && mpGraphicObject )
608*cdf0e10cSrcweir 	{
609*cdf0e10cSrcweir 		bRet = SetGDIMetaFile( mpGraphicObject->GetGraphic().GetGDIMetaFile(), rFlavor );
610*cdf0e10cSrcweir 	}
611*cdf0e10cSrcweir 	else if( ( FORMAT_BITMAP == nFormat ) && mpGraphicObject )
612*cdf0e10cSrcweir 	{
613*cdf0e10cSrcweir 		bRet = SetBitmap( mpGraphicObject->GetGraphic().GetBitmap(), rFlavor );
614*cdf0e10cSrcweir 	}
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir 	return bRet;
617*cdf0e10cSrcweir }
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir // ------------------------------------------------------------------------
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir sal_Bool GalleryTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject,
622*cdf0e10cSrcweir 										   sal_uInt32, const datatransfer::DataFlavor& )
623*cdf0e10cSrcweir {
624*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir 	if( pUserObject )
627*cdf0e10cSrcweir 	{
628*cdf0e10cSrcweir         *rxOStm << *static_cast< SotStorageStream* >( pUserObject );
629*cdf0e10cSrcweir 		bRet = ( rxOStm->GetError() == ERRCODE_NONE );
630*cdf0e10cSrcweir 	}
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 	return bRet;
633*cdf0e10cSrcweir }
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir // ------------------------------------------------------------------------
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir void GalleryTransferable::DragFinished( sal_Int8 nDropAction )
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir 	mpTheme->SetDragging( sal_False );
640*cdf0e10cSrcweir 	mpTheme->SetDragPos( 0 );
641*cdf0e10cSrcweir 	if ( nDropAction )
642*cdf0e10cSrcweir 	{
643*cdf0e10cSrcweir 		Window *pFocusWindow = Application::GetFocusWindow();
644*cdf0e10cSrcweir 		if ( pFocusWindow )
645*cdf0e10cSrcweir 			pFocusWindow->GrabFocusToDocument();
646*cdf0e10cSrcweir 	}
647*cdf0e10cSrcweir }
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir // ------------------------------------------------------------------------
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir void GalleryTransferable::ObjectReleased()
652*cdf0e10cSrcweir {
653*cdf0e10cSrcweir     mxModelStream.Clear();
654*cdf0e10cSrcweir 	delete mpGraphicObject, mpGraphicObject = NULL;
655*cdf0e10cSrcweir 	delete mpImageMap, mpImageMap = NULL;
656*cdf0e10cSrcweir 	delete mpURL, mpURL = NULL;
657*cdf0e10cSrcweir }
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir // ------------------------------------------------------------------------
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir void GalleryTransferable::CopyToClipboard( Window* pWindow )
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir 	TransferableHelper::CopyToClipboard( pWindow );
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir // ------------------------------------------------------------------------
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir void GalleryTransferable::StartDrag( Window* pWindow, sal_Int8 nDragSourceActions,
669*cdf0e10cSrcweir 									 sal_Int32 nDragPointer, sal_Int32 nDragImage )
670*cdf0e10cSrcweir {
671*cdf0e10cSrcweir     INetURLObject aURL;
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir     if( mpTheme->GetURL( mnObjectPos, aURL ) && ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) )
674*cdf0e10cSrcweir     {
675*cdf0e10cSrcweir     	mpTheme->SetDragging( sal_True );
676*cdf0e10cSrcweir 	    mpTheme->SetDragPos( mnObjectPos );
677*cdf0e10cSrcweir 		TransferableHelper::StartDrag( pWindow, nDragSourceActions, nDragPointer, nDragImage );
678*cdf0e10cSrcweir     }
679*cdf0e10cSrcweir }
680