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