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 : : #include <com/sun/star/embed/XTransactedObject.hpp>
30 : : #include <com/sun/star/embed/XEmbedPersist.hpp>
31 : : #include <com/sun/star/embed/ElementModes.hpp>
32 : : #include <com/sun/star/lang/XComponent.hpp>
33 : : #include <osl/mutex.hxx>
34 : : #include <unotools/ucbstreamhelper.hxx>
35 : : #include <unotools/tempfile.hxx>
36 : : #include <editeng/eeitem.hxx>
37 : : #include <editeng/flditem.hxx>
38 : : #include <svx/svdpagv.hxx>
39 : : #include <sfx2/app.hxx>
40 : : #include <vcl/msgbox.hxx>
41 : : #include <svx/svdoole2.hxx>
42 : : #include <svx/svdograf.hxx>
43 : : #include <svx/svdotext.hxx>
44 : : #include <editeng/outlobj.hxx>
45 : : #include <sot/storage.hxx>
46 : : #include <svl/itempool.hxx>
47 : : #include <editeng/editobj.hxx>
48 : : #include <svx/fmglob.hxx>
49 : : #include <svx/svdouno.hxx>
50 : : #include <sot/formats.hxx>
51 : : #include <svl/urlbmk.hxx>
52 : : #include <editeng/outliner.hxx>
53 : :
54 : : #include <com/sun/star/form/FormButtonType.hpp>
55 : : #include <com/sun/star/beans/XPropertySet.hpp>
56 : : #include <unotools/streamwrap.hxx>
57 : :
58 : : #include <svx/svdotable.hxx>
59 : : #include <svx/unomodel.hxx>
60 : : #include <svx/svditer.hxx>
61 : : #include <sfx2/docfile.hxx>
62 : : #include <comphelper/storagehelper.hxx>
63 : : #include <comphelper/servicehelper.hxx>
64 : : #include <svtools/embedtransfer.hxx>
65 : : #include "DrawDocShell.hxx"
66 : : #include "View.hxx"
67 : : #include "sdpage.hxx"
68 : : #include "drawview.hxx"
69 : : #include "drawdoc.hxx"
70 : : #include "stlpool.hxx"
71 : : #include "strings.hrc"
72 : : #include "sdresid.hxx"
73 : : #include "imapinfo.hxx"
74 : : #include "sdxfer.hxx"
75 : : #include "unomodel.hxx"
76 : : #include <vcl/virdev.hxx>
77 : :
78 : : // --------------
79 : : // - Namespaces -
80 : : // --------------
81 : :
82 : : using namespace ::com::sun::star;
83 : : using namespace ::com::sun::star::lang;
84 : : using namespace ::com::sun::star::uno;
85 : : using namespace ::com::sun::star::io;
86 : : using namespace ::com::sun::star::datatransfer;
87 : : using namespace ::com::sun::star::datatransfer::clipboard;
88 : :
89 : : // -----------
90 : : // - Defines -
91 : : // -----------
92 : :
93 : : #define SDTRANSFER_OBJECTTYPE_DRAWMODEL 0x00000001
94 : : #define SDTRANSFER_OBJECTTYPE_DRAWOLE 0x00000002
95 : :
96 : : // ------------------
97 : : // - SdTransferable -
98 : : // ------------------
99 : :
100 : 2 : SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, sal_Bool bInitOnGetData )
101 : : : mpPageDocShell( NULL )
102 : : , mpOLEDataHelper( NULL )
103 : : , mpObjDesc( NULL )
104 : : , mpSdView( pWorkView )
105 : : , mpSdViewIntern( pWorkView )
106 : : , mpSdDrawDocument( NULL )
107 : : , mpSdDrawDocumentIntern( NULL )
108 : : , mpSourceDoc( pSrcDoc )
109 : : , mpVDev( NULL )
110 : : , mpBookmark( NULL )
111 : : , mpGraphic( NULL )
112 : : , mpImageMap( NULL )
113 : : , mbInternalMove( sal_False )
114 : : , mbOwnDocument( sal_False )
115 : : , mbOwnView( sal_False )
116 : : , mbLateInit( bInitOnGetData )
117 : : , mbPageTransferable( sal_False )
118 : : , mbPageTransferablePersistent( sal_False )
119 [ + - ][ + - ]: 2 : , mbIsUnoObj( false )
[ + - ]
120 : : {
121 [ + - ]: 2 : if( mpSourceDoc )
122 [ + - ]: 2 : StartListening( *mpSourceDoc );
123 : :
124 [ + - ]: 2 : if( pWorkView )
125 [ + - ]: 2 : StartListening( *pWorkView );
126 : :
127 [ - + ]: 2 : if( !mbLateInit )
128 [ # # ]: 0 : CreateData();
129 : 2 : }
130 : :
131 : : // -----------------------------------------------------------------------------
132 : :
133 [ + - ][ + - ]: 2 : SdTransferable::~SdTransferable()
134 : : {
135 [ + - ]: 2 : if( mpSourceDoc )
136 [ + - ]: 2 : EndListening( *mpSourceDoc );
137 : :
138 [ + - ]: 2 : if( mpSdView )
139 [ + - ]: 2 : EndListening( *const_cast< sd::View *>( mpSdView) );
140 : :
141 [ + - ]: 2 : SolarMutexGuard aSolarGuard;
142 : :
143 [ + - ]: 2 : ObjectReleased();
144 : :
145 [ - + ]: 2 : if( mbOwnView )
146 [ # # ][ # # ]: 0 : delete mpSdViewIntern;
147 : :
148 [ - + ][ # # ]: 2 : delete mpOLEDataHelper;
149 : :
150 [ - + ]: 2 : if( maDocShellRef.Is() )
151 : : {
152 : 0 : SfxObjectShell* pObj = maDocShellRef;
153 : 0 : ::sd::DrawDocShell* pDocSh = static_cast< ::sd::DrawDocShell*>(pObj);
154 [ # # ]: 0 : pDocSh->DoClose();
155 : : }
156 : :
157 [ + - ]: 2 : maDocShellRef.Clear();
158 : :
159 [ - + ]: 2 : if( mbOwnDocument )
160 [ # # ][ # # ]: 0 : delete mpSdDrawDocumentIntern;
161 : :
162 [ - + ][ # # ]: 2 : delete mpGraphic;
163 [ - + ][ # # ]: 2 : delete mpBookmark;
164 [ - + ][ # # ]: 2 : delete mpImageMap;
165 : :
166 [ - + ][ # # ]: 2 : delete mpVDev;
167 [ + - ][ + - ]: 2 : delete mpObjDesc;
[ + - ]
168 : :
169 [ - + ]: 4 : }
170 : :
171 : : // -----------------------------------------------------------------------------
172 : :
173 : 0 : void SdTransferable::CreateObjectReplacement( SdrObject* pObj )
174 : : {
175 [ # # ]: 0 : if( pObj )
176 : : {
177 [ # # ]: 0 : delete mpOLEDataHelper, mpOLEDataHelper = NULL;
178 [ # # ]: 0 : delete mpGraphic, mpGraphic = NULL;
179 [ # # ]: 0 : delete mpBookmark, mpBookmark = NULL;
180 [ # # ]: 0 : delete mpImageMap, mpImageMap = NULL;
181 : :
182 [ # # ]: 0 : if( pObj->ISA( SdrOle2Obj ) )
183 : : {
184 : : try
185 : : {
186 [ # # ]: 0 : uno::Reference < embed::XEmbeddedObject > xObj = static_cast< SdrOle2Obj* >( pObj )->GetObjRef();
187 [ # # ]: 0 : uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
188 [ # # ][ # # ]: 0 : if( xObj.is() && xPersist.is() && xPersist->hasEntry() )
[ # # ][ # # ]
[ # # ][ # # ]
189 : : {
190 [ # # ][ # # ]: 0 : mpOLEDataHelper = new TransferableDataHelper( new SvEmbedTransferHelper( xObj, static_cast< SdrOle2Obj* >( pObj )->GetGraphic(), static_cast< SdrOle2Obj* >( pObj )->GetAspect() ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
191 : :
192 : : // TODO/LATER: the standalone handling of the graphic should not be used any more in future
193 : : // The EmbedDataHelper should bring the graphic in future
194 [ # # ]: 0 : Graphic* pObjGr = static_cast< SdrOle2Obj* >( pObj )->GetGraphic();
195 [ # # ]: 0 : if ( pObjGr )
196 [ # # ][ # # ]: 0 : mpGraphic = new Graphic( *pObjGr );
197 [ # # ]: 0 : }
198 : : }
199 : 0 : catch( uno::Exception& )
200 : : {}
201 : : }
202 [ # # ][ # # ]: 0 : else if( pObj->ISA( SdrGrafObj ) && (mpSourceDoc && !mpSourceDoc->GetAnimationInfo( pObj )) )
[ # # ][ # # ]
203 : : {
204 [ # # ]: 0 : mpGraphic = new Graphic( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() );
205 : : }
206 [ # # ][ # # ]: 0 : else if( pObj->IsUnoObj() && FmFormInventor == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == (sal_uInt16) OBJ_FM_BUTTON ) )
[ # # ][ # # ]
207 : : {
208 : 0 : SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( pObj );
209 : :
210 [ # # ][ # # ]: 0 : if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
[ # # ]
211 : : {
212 [ # # ]: 0 : Reference< ::com::sun::star::awt::XControlModel > xControlModel( pUnoCtrl->GetUnoControlModel() );
213 : :
214 [ # # ]: 0 : if( !xControlModel.is() )
215 : : return;
216 : :
217 [ # # ]: 0 : Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xControlModel, UNO_QUERY );
218 : :
219 [ # # ]: 0 : if( !xPropSet.is() )
220 : : return;
221 : :
222 : : ::com::sun::star::form::FormButtonType eButtonType;
223 [ # # ][ # # ]: 0 : Any aTmp( xPropSet->getPropertyValue( "ButtonType" ) );
224 : :
225 [ # # ][ # # ]: 0 : if( aTmp >>= eButtonType )
226 : : {
227 : 0 : ::rtl::OUString aLabel, aURL;
228 : :
229 [ # # ][ # # ]: 0 : xPropSet->getPropertyValue( "Label" ) >>= aLabel;
230 [ # # ][ # # ]: 0 : xPropSet->getPropertyValue( "TargetURL" ) >>= aURL;
231 : :
232 [ # # ][ # # ]: 0 : mpBookmark = new INetBookmark( String( aURL ), String( aLabel ) );
[ # # ][ # # ]
[ # # ][ # # ]
233 [ # # ][ # # ]: 0 : }
234 : : }
235 : : }
236 [ # # ]: 0 : else if( pObj->ISA( SdrTextObj ) )
237 : : {
238 : : const OutlinerParaObject* pPara;
239 : :
240 [ # # ]: 0 : if( (pPara = static_cast< SdrTextObj* >( pObj )->GetOutlinerParaObject()) != 0 )
241 : : {
242 : : const SvxFieldItem* pField;
243 : :
244 [ # # ]: 0 : if( (pField = pPara->GetTextObject().GetField()) != 0 )
245 : : {
246 : 0 : const SvxFieldData* pData = pField->GetField();
247 : :
248 [ # # ][ # # ]: 0 : if( pData && pData->ISA( SvxURLField ) )
[ # # ]
249 : : {
250 : 0 : const SvxURLField* pURL = (SvxURLField*) pData;
251 : :
252 [ # # ][ # # ]: 0 : mpBookmark = new INetBookmark( pURL->GetURL(), pURL->GetRepresentation() );
[ # # ][ # # ]
253 : : }
254 : : }
255 : : }
256 : : }
257 : :
258 : 0 : SdIMapInfo* pInfo = static_cast< SdDrawDocument* >( pObj->GetModel() )->GetIMapInfo( static_cast< SdrObject* >( pObj ) );
259 : :
260 [ # # ]: 0 : if( pInfo )
261 [ # # ]: 0 : mpImageMap = new ImageMap( pInfo->GetImageMap() );
262 : :
263 [ # # ][ # # ]: 0 : mbIsUnoObj = pObj && pObj->IsUnoObj();
264 : : }
265 : : }
266 : :
267 : : // -----------------------------------------------------------------------------
268 : :
269 : 0 : void SdTransferable::CreateData()
270 : : {
271 [ # # ][ # # ]: 0 : if( mpSdDrawDocument && !mpSdViewIntern )
272 : : {
273 : 0 : mbOwnView = sal_True;
274 : :
275 : 0 : SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PK_STANDARD);
276 : :
277 [ # # ]: 0 : if( 1 == pPage->GetObjCount() )
278 : 0 : CreateObjectReplacement( pPage->GetObj( 0 ) );
279 : :
280 [ # # ]: 0 : mpVDev = new VirtualDevice( *Application::GetDefaultDevice() );
281 [ # # ][ # # ]: 0 : mpVDev->SetMapMode( MapMode( mpSdDrawDocumentIntern->GetScaleUnit(), Point(), mpSdDrawDocumentIntern->GetScaleFraction(), mpSdDrawDocumentIntern->GetScaleFraction() ) );
[ # # ]
282 [ # # ]: 0 : mpSdViewIntern = new ::sd::View( *mpSdDrawDocumentIntern, mpVDev );
283 : 0 : mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern );
284 : 0 : mpSdViewIntern->hideMarkHandles();
285 : 0 : SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage);
286 : 0 : ((SdrMarkView*)mpSdViewIntern)->MarkAllObj(pPageView);
287 : : }
288 [ # # ][ # # ]: 0 : else if( mpSdView && !mpSdDrawDocumentIntern )
289 : : {
290 : 0 : const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList();
291 : :
292 [ # # ]: 0 : if( rMarkList.GetMarkCount() == 1 )
293 [ # # ][ # # ]: 0 : CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
[ # # ]
294 : :
295 [ # # ]: 0 : if( mpSourceDoc )
296 : 0 : mpSourceDoc->CreatingDataObj(this);
297 [ # # ]: 0 : mpSdDrawDocumentIntern = (SdDrawDocument*) mpSdView->GetAllMarkedModel();
298 [ # # ]: 0 : if( mpSourceDoc )
299 : 0 : mpSourceDoc->CreatingDataObj(0);
300 : :
301 [ # # ][ # # ]: 0 : if( !maDocShellRef.Is() && mpSdDrawDocumentIntern->GetDocSh() )
[ # # ]
302 [ # # ]: 0 : maDocShellRef = mpSdDrawDocumentIntern->GetDocSh();
303 : :
304 [ # # ]: 0 : if( !maDocShellRef.Is() )
305 : : {
306 : : OSL_FAIL( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
307 : 0 : mbOwnDocument = sal_True;
308 : : }
309 : :
310 : : // Groesse der Source-Seite uebernehmen
311 : 0 : SdrPageView* pPgView = mpSdView->GetSdrPageView();
312 : 0 : SdPage* pOldPage = (SdPage*) pPgView->GetPage();
313 : 0 : SdrModel* pOldModel = mpSdView->GetModel();
314 [ # # ]: 0 : SdStyleSheetPool* pOldStylePool = (SdStyleSheetPool*) pOldModel->GetStyleSheetPool();
315 [ # # ]: 0 : SdStyleSheetPool* pNewStylePool = (SdStyleSheetPool*) mpSdDrawDocumentIntern->GetStyleSheetPool();
316 [ # # ]: 0 : SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
317 [ # # ]: 0 : String aOldLayoutName( pOldPage->GetLayoutName() );
318 : :
319 [ # # ][ # # ]: 0 : pPage->SetSize( pOldPage->GetSize() );
320 [ # # ][ # # ]: 0 : pPage->SetLayoutName( aOldLayoutName );
[ # # ]
321 [ # # ]: 0 : pNewStylePool->CopyGraphicSheets( *pOldStylePool );
322 [ # # ]: 0 : pNewStylePool->CopyCellSheets( *pOldStylePool );
323 [ # # ]: 0 : pNewStylePool->CopyTableStyles( *pOldStylePool );
324 [ # # ][ # # ]: 0 : aOldLayoutName.Erase( aOldLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
325 [ # # ]: 0 : SdStyleSheetVector aCreatedSheets;
326 [ # # ][ # # ]: 0 : pNewStylePool->CopyLayoutSheets( aOldLayoutName, *pOldStylePool, aCreatedSheets );
327 : : }
328 : :
329 : : // set VisArea and adjust objects if neccessary
330 [ # # ][ # # ]: 0 : if( maVisArea.IsEmpty() &&
[ # # # # ]
[ # # ]
331 : : mpSdDrawDocumentIntern && mpSdViewIntern &&
332 : 0 : mpSdDrawDocumentIntern->GetPageCount() )
333 : : {
334 : 0 : SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
335 : :
336 [ # # ]: 0 : if( 1 == mpSdDrawDocumentIntern->GetPageCount() )
337 : : {
338 : : // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
339 : : // fat lines correctly
340 [ # # ]: 0 : Point aOrigin( ( maVisArea = mpSdViewIntern->GetAllMarkedBoundRect() ).TopLeft() );
341 : 0 : Size aVector( -aOrigin.X(), -aOrigin.Y() );
342 : :
343 [ # # ][ # # ]: 0 : for( sal_uLong nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; nObj++ )
344 : : {
345 [ # # ]: 0 : SdrObject* pObj = pPage->GetObj( nObj );
346 [ # # ]: 0 : pObj->NbcMove( aVector );
347 : : }
348 : : }
349 : : else
350 [ # # ]: 0 : maVisArea.SetSize( pPage->GetSize() );
351 : :
352 : : // Die Ausgabe soll am Nullpunkt erfolgen
353 : 0 : maVisArea.SetPos( Point() );
354 : : }
355 : 0 : }
356 : :
357 : : // -----------------------------------------------------------------------------
358 : :
359 : 0 : sal_Bool lcl_HasOnlyControls( SdrModel* pModel )
360 : : {
361 : 0 : sal_Bool bOnlyControls = sal_False; // default if there are no objects
362 : :
363 [ # # ]: 0 : if ( pModel )
364 : : {
365 : 0 : SdrPage* pPage = pModel->GetPage(0);
366 [ # # ]: 0 : if (pPage)
367 : : {
368 [ # # ]: 0 : SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
369 [ # # ]: 0 : SdrObject* pObj = aIter.Next();
370 [ # # ]: 0 : if ( pObj )
371 : : {
372 : 0 : bOnlyControls = sal_True; // only set if there are any objects at all
373 [ # # ]: 0 : while ( pObj )
374 : : {
375 [ # # ][ # # ]: 0 : if (!pObj->ISA(SdrUnoObj))
[ # # ]
376 : : {
377 : 0 : bOnlyControls = sal_False;
378 : 0 : break;
379 : : }
380 [ # # ]: 0 : pObj = aIter.Next();
381 : : }
382 : 0 : }
383 : : }
384 : : }
385 : :
386 : 0 : return bOnlyControls;
387 : : }
388 : :
389 : : // -----------------------------------------------------------------------------
390 : :
391 : 0 : bool lcl_HasOnlyOneTable( SdrModel* pModel )
392 : : {
393 [ # # ]: 0 : if ( pModel )
394 : : {
395 : 0 : SdrPage* pPage = pModel->GetPage(0);
396 [ # # ][ # # ]: 0 : if (pPage && pPage->GetObjCount() == 1 )
[ # # ]
397 : : {
398 [ # # ][ # # ]: 0 : if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != 0 )
[ # # ]
399 : 0 : return true;
400 : : }
401 : : }
402 : 0 : return false;
403 : : }
404 : :
405 : : // -----------------------------------------------------------------------------
406 : :
407 : 0 : void SdTransferable::AddSupportedFormats()
408 : : {
409 [ # # ][ # # ]: 0 : if( !mbPageTransferable || mbPageTransferablePersistent )
410 : : {
411 [ # # ]: 0 : if( !mbLateInit )
412 : 0 : CreateData();
413 : :
414 [ # # ]: 0 : if( mpObjDesc )
415 : 0 : AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
416 : :
417 [ # # ]: 0 : if( mpOLEDataHelper )
418 : : {
419 [ # # ]: 0 : AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
420 : :
421 [ # # ]: 0 : DataFlavorExVector aVector( mpOLEDataHelper->GetDataFlavorExVector() );
422 : 0 : DataFlavorExVector::iterator aIter( aVector.begin() ), aEnd( aVector.end() );
423 : :
424 [ # # ][ # # ]: 0 : while( aIter != aEnd )
425 [ # # ][ # # ]: 0 : AddFormat( *aIter++ );
426 : : }
427 [ # # ]: 0 : else if( mpGraphic )
428 : : {
429 : : // #i25616#
430 : 0 : AddFormat( SOT_FORMATSTR_ID_DRAWING );
431 : :
432 : 0 : AddFormat( SOT_FORMATSTR_ID_SVXB );
433 : :
434 [ # # ]: 0 : if( mpGraphic->GetType() == GRAPHIC_BITMAP )
435 : : {
436 : 0 : AddFormat( SOT_FORMAT_BITMAP );
437 : 0 : AddFormat( SOT_FORMAT_GDIMETAFILE );
438 : : }
439 : : else
440 : : {
441 : 0 : AddFormat( SOT_FORMAT_GDIMETAFILE );
442 : 0 : AddFormat( SOT_FORMAT_BITMAP );
443 : : }
444 : : }
445 [ # # ]: 0 : else if( mpBookmark )
446 : : {
447 : 0 : AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
448 : 0 : AddFormat( FORMAT_STRING );
449 : : }
450 : : else
451 : : {
452 : 0 : AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
453 : 0 : AddFormat( SOT_FORMATSTR_ID_DRAWING );
454 [ # # ][ # # ]: 0 : if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
[ # # ]
455 : : {
456 : 0 : AddFormat( SOT_FORMAT_GDIMETAFILE );
457 : 0 : AddFormat( SOT_FORMAT_BITMAP );
458 : : }
459 : :
460 [ # # ]: 0 : if( lcl_HasOnlyOneTable( mpSdDrawDocument ) )
461 : 0 : AddFormat( SOT_FORMAT_RTF );
462 : : }
463 : :
464 [ # # ]: 0 : if( mpImageMap )
465 : 0 : AddFormat( SOT_FORMATSTR_ID_SVIM );
466 : : }
467 : 0 : }
468 : :
469 : : // -----------------------------------------------------------------------------
470 : :
471 : 0 : sal_Bool SdTransferable::GetData( const DataFlavor& rFlavor )
472 : : {
473 [ # # ]: 0 : if (SD_MOD()==NULL)
474 : 0 : return sal_False;
475 : :
476 : 0 : sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
477 : 0 : sal_Bool bOK = sal_False;
478 : :
479 : 0 : CreateData();
480 : :
481 [ # # ][ # # ]: 0 : if( nFormat == SOT_FORMAT_RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
[ # # ]
482 : : {
483 : 0 : bOK = SetTableRTF( mpSdDrawDocument, rFlavor );
484 : : }
485 [ # # ][ # # ]: 0 : else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
[ # # ]
486 : : {
487 : 0 : sal_uLong nOldSwapMode = 0;
488 : :
489 [ # # ]: 0 : if( mpSdDrawDocumentIntern )
490 : : {
491 : 0 : nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
492 : 0 : mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
493 : : }
494 : :
495 : : // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
496 [ # # ][ # # ]: 0 : if( nFormat == FORMAT_GDIMETAFILE && mpGraphic )
497 : 0 : bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile(), rFlavor );
498 : : else
499 [ # # ]: 0 : bOK = SetAny( mpOLEDataHelper->GetAny( rFlavor ), rFlavor );
500 : :
501 [ # # ]: 0 : if( mpSdDrawDocumentIntern )
502 : 0 : mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
503 : : }
504 [ # # ]: 0 : else if( HasFormat( nFormat ) )
505 : : {
506 [ # # ][ # # ]: 0 : if( ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) && mpObjDesc )
[ # # ]
507 : : {
508 : 0 : bOK = SetTransferableObjectDescriptor( *mpObjDesc, rFlavor );
509 : : }
510 [ # # ]: 0 : else if( nFormat == SOT_FORMATSTR_ID_DRAWING )
511 : : {
512 : 0 : SfxObjectShellRef aOldRef( maDocShellRef );
513 : :
514 [ # # ]: 0 : maDocShellRef.Clear();
515 : :
516 [ # # ]: 0 : if( mpSdViewIntern )
517 : : {
518 : 0 : SdDrawDocument& rInternDoc = mpSdViewIntern->GetDoc();
519 : 0 : rInternDoc.CreatingDataObj(this);
520 [ # # ][ # # ]: 0 : SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->GetAllMarkedModel() );
521 : 0 : rInternDoc.CreatingDataObj(0);
522 : :
523 [ # # ]: 0 : bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
524 : :
525 [ # # ]: 0 : if( maDocShellRef.Is() )
526 : : {
527 [ # # ]: 0 : maDocShellRef->DoClose();
528 : : }
529 : : else
530 : : {
531 [ # # ][ # # ]: 0 : delete pDoc;
532 : : }
533 : : }
534 : :
535 [ # # ][ # # ]: 0 : maDocShellRef = aOldRef;
536 : : }
537 [ # # ]: 0 : else if( nFormat == FORMAT_GDIMETAFILE )
538 : : {
539 [ # # ]: 0 : if( mpSdViewIntern )
540 [ # # ]: 0 : bOK = SetGDIMetaFile( mpSdViewIntern->GetAllMarkedMetaFile( sal_True ), rFlavor );
541 : : }
542 [ # # ]: 0 : else if( nFormat == FORMAT_BITMAP )
543 : : {
544 [ # # ]: 0 : if( mpSdViewIntern )
545 [ # # ]: 0 : bOK = SetBitmap( mpSdViewIntern->GetAllMarkedBitmap( sal_True ), rFlavor );
546 : : }
547 [ # # ][ # # ]: 0 : else if( ( nFormat == FORMAT_STRING ) && mpBookmark )
548 : : {
549 [ # # ]: 0 : bOK = SetString( mpBookmark->GetURL(), rFlavor );
550 : : }
551 [ # # ][ # # ]: 0 : else if( ( nFormat == SOT_FORMATSTR_ID_SVXB ) && mpGraphic )
552 : : {
553 : 0 : bOK = SetGraphic( *mpGraphic, rFlavor );
554 : : }
555 [ # # ][ # # ]: 0 : else if( ( nFormat == SOT_FORMATSTR_ID_SVIM ) && mpImageMap )
556 : : {
557 : 0 : bOK = SetImageMap( *mpImageMap, rFlavor );
558 : : }
559 [ # # ]: 0 : else if( mpBookmark )
560 : : {
561 : 0 : bOK = SetINetBookmark( *mpBookmark, rFlavor );
562 : : }
563 [ # # ]: 0 : else if( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
564 : : {
565 : 0 : sal_uLong nOldSwapMode = 0;
566 : :
567 [ # # ]: 0 : if( mpSdDrawDocumentIntern )
568 : : {
569 : 0 : nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
570 : 0 : mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
571 : : }
572 : :
573 [ # # ]: 0 : if( !maDocShellRef.Is() )
574 : : {
575 : : maDocShellRef = new ::sd::DrawDocShell(
576 : : mpSdDrawDocumentIntern,
577 : : SFX_CREATE_MODE_EMBEDDED,
578 : : sal_True,
579 [ # # ]: 0 : mpSdDrawDocumentIntern->GetDocumentType());
580 : 0 : mbOwnDocument = sal_False;
581 : 0 : maDocShellRef->DoInitNew( NULL );
582 : : }
583 : :
584 : 0 : maDocShellRef->SetVisArea( maVisArea );
585 : 0 : bOK = SetObject( &maDocShellRef, SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
586 : :
587 [ # # ]: 0 : if( mpSdDrawDocumentIntern )
588 : 0 : mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
589 : : }
590 : : }
591 : :
592 : 0 : return bOK;
593 : : }
594 : :
595 : : // -----------------------------------------------------------------------------
596 : :
597 : 0 : sal_Bool SdTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& )
598 : : {
599 : 0 : sal_Bool bRet = sal_False;
600 : :
601 [ # # # ]: 0 : switch( nObjectType )
602 : : {
603 : : case( SDTRANSFER_OBJECTTYPE_DRAWMODEL ):
604 : : {
605 : : try
606 : : {
607 [ # # ][ # # ]: 0 : static const sal_Bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL );
608 : 0 : SdDrawDocument* pDoc = (SdDrawDocument*) pObject;
609 [ # # ]: 0 : if ( !bDontBurnInStyleSheet )
610 [ # # ]: 0 : pDoc->BurnInStyleSheetAttributes();
611 [ # # ]: 0 : rxOStm->SetBufferSize( 16348 );
612 : :
613 [ # # ][ # # ]: 0 : Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, sal_True ) );
614 [ # # ][ # # ]: 0 : pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
615 : :
616 : : {
617 [ # # ][ # # ]: 0 : com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
[ # # ]
618 [ # # ][ # # ]: 0 : if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
[ # # ]
619 [ # # ]: 0 : rxOStm->Commit();
620 : : }
621 : :
622 [ # # ][ # # ]: 0 : xComponent->dispose();
623 [ # # ]: 0 : bRet = ( rxOStm->GetError() == ERRCODE_NONE );
624 : : }
625 : 0 : catch( Exception& )
626 : : {
627 : : OSL_FAIL( "sd::SdTransferable::WriteObject(), exception catched!" );
628 : 0 : bRet = sal_False;
629 : : }
630 : : }
631 : 0 : break;
632 : :
633 : : case( SDTRANSFER_OBJECTTYPE_DRAWOLE ):
634 : : {
635 : 0 : SfxObjectShell* pEmbObj = (SfxObjectShell*) pObject;
636 [ # # ]: 0 : ::utl::TempFile aTempFile;
637 : 0 : aTempFile.EnableKillingFile();
638 : :
639 : : try
640 : : {
641 : : uno::Reference< embed::XStorage > xWorkStore =
642 [ # # ][ # # ]: 0 : ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
[ # # ][ # # ]
643 : :
644 : : // write document storage
645 [ # # ]: 0 : pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
646 : : // mba: no relative ULRs for clipboard!
647 [ # # ][ # # ]: 0 : SfxMedium aMedium( xWorkStore, String() );
[ # # ]
648 [ # # ]: 0 : bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False );
649 [ # # ]: 0 : pEmbObj->DoSaveCompleted();
650 : :
651 [ # # ]: 0 : uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
652 [ # # ]: 0 : if ( xTransact.is() )
653 [ # # ][ # # ]: 0 : xTransact->commit();
654 : :
655 [ # # ][ # # ]: 0 : SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
[ # # ]
656 [ # # ]: 0 : if( pSrcStm )
657 : : {
658 [ # # ]: 0 : rxOStm->SetBufferSize( 0xff00 );
659 [ # # ]: 0 : *rxOStm << *pSrcStm;
660 [ # # ][ # # ]: 0 : delete pSrcStm;
661 : : }
662 : :
663 : 0 : bRet = sal_True;
664 [ # # ][ # # ]: 0 : rxOStm->Commit();
[ # # ]
665 : : }
666 [ # # ]: 0 : catch ( Exception& )
667 [ # # ]: 0 : {}
668 : : }
669 : :
670 : 0 : break;
671 : :
672 : : default:
673 : 0 : break;
674 : : }
675 : :
676 : 0 : return bRet;
677 : : }
678 : :
679 : : // -----------------------------------------------------------------------------
680 : :
681 : 0 : void SdTransferable::DragFinished( sal_Int8 nDropAction )
682 : : {
683 [ # # ]: 0 : if( mpSdView )
684 : 0 : ( (::sd::View*) mpSdView )->DragFinished( nDropAction );
685 : 0 : }
686 : :
687 : : // -----------------------------------------------------------------------------
688 : :
689 : 4 : void SdTransferable::ObjectReleased()
690 : : {
691 [ - + ]: 4 : if( this == SD_MOD()->pTransferClip )
692 : 0 : SD_MOD()->pTransferClip = NULL;
693 : :
694 [ - + ]: 4 : if( this == SD_MOD()->pTransferDrag )
695 : 0 : SD_MOD()->pTransferDrag = NULL;
696 : :
697 [ + + ]: 4 : if( this == SD_MOD()->pTransferSelection )
698 : 2 : SD_MOD()->pTransferSelection = NULL;
699 : 4 : }
700 : :
701 : : // -----------------------------------------------------------------------------
702 : :
703 : 2 : void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor& rObjDesc )
704 : : {
705 [ - + ]: 2 : delete mpObjDesc;
706 [ + - ]: 2 : mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
707 : 2 : PrepareOLE( rObjDesc );
708 : 2 : }
709 : :
710 : : // -----------------------------------------------------------------------------
711 : :
712 : 0 : void SdTransferable::SetPageBookmarks( const std::vector<rtl::OUString> &rPageBookmarks, sal_Bool bPersistent )
713 : : {
714 [ # # ]: 0 : if( mpSourceDoc )
715 : : {
716 [ # # ]: 0 : if( mpSdViewIntern )
717 : 0 : mpSdViewIntern->HideSdrPage();
718 : :
719 : 0 : mpSdDrawDocument->ClearModel(sal_False);
720 : :
721 : 0 : mpPageDocShell = NULL;
722 : :
723 : 0 : maPageBookmarks.clear();
724 : :
725 [ # # ]: 0 : if( bPersistent )
726 : : {
727 : 0 : mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
728 : : mpSdDrawDocument->InsertBookmarkAsPage( rPageBookmarks, NULL, sal_False, sal_True, 1, sal_True,
729 : 0 : mpSourceDoc->GetDocSh(), sal_True, sal_True, sal_False );
730 : : }
731 : : else
732 : : {
733 : 0 : mpPageDocShell = mpSourceDoc->GetDocSh();
734 : 0 : maPageBookmarks = rPageBookmarks;
735 : : }
736 : :
737 [ # # ][ # # ]: 0 : if( mpSdViewIntern && mpSdDrawDocument )
738 : : {
739 : 0 : SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PK_STANDARD );
740 : :
741 [ # # ]: 0 : if( pPage )
742 : : {
743 : 0 : ( (SdrMarkView*) mpSdViewIntern )->MarkAllObj( (SdrPageView*) mpSdViewIntern->ShowSdrPage( pPage ) );
744 : : }
745 : : }
746 : :
747 : : // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
748 : : // don't offer any formats => it's just for internal puposes
749 : 0 : mbPageTransferable = sal_True;
750 : 0 : mbPageTransferablePersistent = bPersistent;
751 : : }
752 : 0 : }
753 : :
754 : : // -----------------------------------------------------------------------------
755 : :
756 : 0 : sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException )
757 : : {
758 : : sal_Int64 nRet;
759 : :
760 [ # # # # ]: 0 : if( ( rId.getLength() == 16 ) &&
[ # # ]
761 : 0 : ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
762 : : {
763 : 0 : nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
764 : : }
765 : : else
766 : : {
767 : 0 : nRet = 0;
768 : : }
769 : :
770 : 0 : return nRet;
771 : : }
772 : :
773 : : namespace
774 : : {
775 : : class theSdTransferableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSdTransferableUnoTunnelId > {};
776 : : }
777 : :
778 : 0 : const ::com::sun::star::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId()
779 : : {
780 : 0 : return theSdTransferableUnoTunnelId::get().getSeq();
781 : : }
782 : :
783 : : // -----------------------------------------------------------------------------
784 : :
785 : 0 : SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw()
786 : : {
787 : : try
788 : : {
789 [ # # ]: 0 : Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
790 [ # # ][ # # ]: 0 : return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
[ # # ][ # # ]
791 : : }
792 : 0 : catch( const ::com::sun::star::uno::Exception& )
793 : : {
794 : : }
795 : 0 : return NULL;
796 : : }
797 : :
798 : : // -----------------------------------------------------------------------------
799 : :
800 : : // SfxListener
801 : 0 : void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
802 : : {
803 [ # # ]: 0 : const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
804 [ # # ]: 0 : if( pSdrHint )
805 : : {
806 [ # # ]: 0 : if( HINT_MODELCLEARED == pSdrHint->GetKind() )
807 : : {
808 : 0 : EndListening(*mpSourceDoc);
809 : 0 : mpSourceDoc = 0;
810 : : }
811 : : }
812 : : else
813 : : {
814 [ # # ]: 0 : const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint * >(&rHint);
815 [ # # ][ # # ]: 0 : if(pSimpleHint && (pSimpleHint->GetId() == SFX_HINT_DYING) )
[ # # ]
816 : : {
817 [ # # ]: 0 : if( &rBC == mpSourceDoc )
818 : 0 : mpSourceDoc = 0;
819 [ # # ][ # # ]: 0 : if( &rBC == mpSdViewIntern )
820 : 0 : mpSdViewIntern = 0;
821 [ # # ][ # # ]: 0 : if( &rBC == mpSdView )
822 : 0 : mpSdView = 0;
823 : : }
824 : : }
825 : 0 : }
826 : :
827 : 0 : sal_Bool SdTransferable::SetTableRTF( SdDrawDocument* pModel, const DataFlavor& rFlavor)
828 : : {
829 [ # # ]: 0 : if ( pModel )
830 : : {
831 : 0 : SdrPage* pPage = pModel->GetPage(0);
832 [ # # ][ # # ]: 0 : if (pPage && pPage->GetObjCount() == 1 )
[ # # ]
833 : : {
834 [ # # ]: 0 : sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
835 [ # # ]: 0 : if( pTableObj )
836 : : {
837 [ # # ]: 0 : SvMemoryStream aMemStm( 65535, 65535 );
838 [ # # ]: 0 : sdr::table::SdrTableObj::ExportAsRTF( aMemStm, *pTableObj );
839 [ # # ][ # # ]: 0 : return SetAny( Any( Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ) ), rFlavor );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
840 : : }
841 : : }
842 : : }
843 : :
844 : 0 : return sal_False;
845 : : }
846 : :
847 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|