Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/embed/XTransactedObject.hpp>
21 : #include <com/sun/star/embed/XEmbedPersist.hpp>
22 : #include <com/sun/star/uno/Exception.hpp>
23 :
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
26 : #include <com/sun/star/form/FormButtonType.hpp>
27 : #include <toolkit/helper/vclunohelper.hxx>
28 : #include <unotools/streamwrap.hxx>
29 :
30 : #include <svx/unomodel.hxx>
31 : #include <unotools/tempfile.hxx>
32 : #include <unotools/ucbstreamhelper.hxx>
33 : #include <comphelper/storagehelper.hxx>
34 : #include <comphelper/servicehelper.hxx>
35 :
36 : #include <svtools/embedtransfer.hxx>
37 : #include <sot/storage.hxx>
38 : #include <vcl/virdev.hxx>
39 : #include <svx/fmglob.hxx>
40 : #include <svx/svditer.hxx>
41 : #include <svx/svdograf.hxx>
42 : #include <svx/svdoole2.hxx>
43 : #include <svx/svdouno.hxx>
44 : #include <svx/svdpage.hxx>
45 : #include <svx/svdxcgv.hxx>
46 : #include <sfx2/docfile.hxx>
47 : #include <svl/itempool.hxx>
48 : #include <svl/urlbmk.hxx>
49 : #include <tools/urlobj.hxx>
50 : #include <osl/mutex.hxx>
51 :
52 : #include "drwtrans.hxx"
53 : #include "docsh.hxx"
54 : #include "drwlayer.hxx"
55 : #include "drawview.hxx"
56 : #include "viewdata.hxx"
57 : #include "scmod.hxx"
58 : #include "chartlis.hxx"
59 : #include "rangeutl.hxx"
60 : #include "formula/grammar.hxx"
61 : #include "dragdata.hxx"
62 : #include "clipdata.hxx"
63 :
64 : // #108584#
65 : #include "scitems.hxx"
66 :
67 : // #108584#
68 : #include <editeng/eeitem.hxx>
69 :
70 : // #108584#
71 : #include <editeng/fhgtitem.hxx>
72 : #include <vcl/svapp.hxx>
73 :
74 :
75 : using namespace com::sun::star;
76 :
77 : // -----------------------------------------------------------------------
78 :
79 : #define SCDRAWTRANS_TYPE_EMBOBJ 1
80 : #define SCDRAWTRANS_TYPE_DRAWMODEL 2
81 : #define SCDRAWTRANS_TYPE_DOCUMENT 3
82 :
83 : // -----------------------------------------------------------------------
84 :
85 : // -----------------------------------------------------------------------
86 :
87 0 : ScDrawTransferObj::ScDrawTransferObj( SdrModel* pClipModel, ScDocShell* pContainerShell,
88 : const TransferableObjectDescriptor& rDesc ) :
89 : pModel( pClipModel ),
90 : aObjDesc( rDesc ),
91 : pBookmark( NULL ),
92 : bGraphic( false ),
93 : bGrIsBit( false ),
94 : bOleObj( false ),
95 : pDragSourceView( NULL ),
96 : nDragSourceFlags( 0 ),
97 : bDragWasInternal( false ),
98 0 : nSourceDocID( 0 )
99 : {
100 : //
101 : // check what kind of objects are contained
102 : //
103 :
104 0 : SdrPage* pPage = pModel->GetPage(0);
105 0 : if (pPage)
106 : {
107 0 : SdrObjListIter aIter( *pPage, IM_FLAT );
108 0 : SdrObject* pObject = aIter.Next();
109 0 : if (pObject && !aIter.Next()) // exactly one object?
110 : {
111 : //
112 : // OLE object
113 : //
114 :
115 0 : sal_uInt16 nSdrObjKind = pObject->GetObjIdentifier();
116 0 : if (nSdrObjKind == OBJ_OLE2)
117 : {
118 : // if object has no persistence it must be copied as a part of document
119 : try
120 : {
121 0 : uno::Reference< embed::XEmbedPersist > xPersObj( ((SdrOle2Obj*)pObject)->GetObjRef(), uno::UNO_QUERY );
122 0 : if ( xPersObj.is() && xPersObj->hasEntry() )
123 0 : bOleObj = sal_True;
124 : }
125 0 : catch( uno::Exception& )
126 : {}
127 : // aOleData is initialized later
128 : }
129 :
130 : //
131 : // Graphic object
132 : //
133 :
134 0 : if (nSdrObjKind == OBJ_GRAF)
135 : {
136 0 : bGraphic = sal_True;
137 0 : if ( ((SdrGrafObj*)pObject)->GetGraphic().GetType() == GRAPHIC_BITMAP )
138 0 : bGrIsBit = sal_True;
139 : }
140 :
141 : //
142 : // URL button
143 : //
144 :
145 0 : SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObject);
146 0 : if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
147 : {
148 0 : uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
149 : OSL_ENSURE( xControlModel.is(), "uno control without model" );
150 0 : if ( xControlModel.is() )
151 : {
152 0 : uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
153 0 : uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
154 :
155 0 : rtl::OUString sPropButtonType(RTL_CONSTASCII_USTRINGPARAM( "ButtonType" ));
156 0 : rtl::OUString sPropTargetURL(RTL_CONSTASCII_USTRINGPARAM( "TargetURL" ));
157 0 : rtl::OUString sPropLabel(RTL_CONSTASCII_USTRINGPARAM( "Label" ));
158 :
159 0 : if(xInfo->hasPropertyByName( sPropButtonType ))
160 : {
161 0 : uno::Any aAny = xPropSet->getPropertyValue( sPropButtonType );
162 : form::FormButtonType eTmp;
163 0 : if ( (aAny >>= eTmp) && eTmp == form::FormButtonType_URL )
164 : {
165 : // URL
166 0 : if(xInfo->hasPropertyByName( sPropTargetURL ))
167 : {
168 0 : aAny = xPropSet->getPropertyValue( sPropTargetURL );
169 0 : rtl::OUString sTmp;
170 0 : if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
171 : {
172 0 : String aUrl = sTmp;
173 0 : String aAbs;
174 : const SfxMedium* pMedium;
175 0 : if (pContainerShell && (pMedium = pContainerShell->GetMedium()) != NULL)
176 : {
177 0 : bool bWasAbs = true;
178 0 : aAbs = pMedium->GetURLObject().smartRel2Abs( aUrl, bWasAbs ).
179 0 : GetMainURL(INetURLObject::NO_DECODE);
180 : // full path as stored INetBookmark must be encoded
181 : }
182 : else
183 0 : aAbs = aUrl;
184 :
185 : // Label
186 0 : String aLabel;
187 0 : if(xInfo->hasPropertyByName( sPropLabel ))
188 : {
189 0 : aAny = xPropSet->getPropertyValue( sPropLabel );
190 0 : if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
191 : {
192 0 : aLabel = String(sTmp);
193 : }
194 : }
195 0 : pBookmark = new INetBookmark( aAbs, aLabel );
196 0 : }
197 : }
198 0 : }
199 0 : }
200 0 : }
201 : }
202 0 : }
203 : }
204 :
205 : //
206 : // get size for object descriptor
207 : //
208 :
209 : // #i71538# use complete SdrViews
210 : // SdrExchangeView aView(pModel);
211 0 : SdrView aView(pModel);
212 0 : SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
213 0 : aView.MarkAllObj(pPv);
214 0 : aSrcSize = aView.GetAllMarkedRect().GetSize();
215 :
216 0 : if ( bOleObj ) // single OLE object
217 : {
218 0 : SdrOle2Obj* pObj = GetSingleObject();
219 0 : if ( pObj && pObj->GetObjRef().is() )
220 0 : SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() );
221 : }
222 :
223 0 : aObjDesc.maSize = aSrcSize;
224 0 : PrepareOLE( aObjDesc );
225 :
226 : //
227 : // remember a unique ID of the source document
228 : //
229 0 : if ( pContainerShell )
230 : {
231 0 : ScDocument* pDoc = pContainerShell->GetDocument();
232 0 : if ( pDoc )
233 : {
234 0 : nSourceDocID = pDoc->GetDocumentID();
235 0 : if ( pPage )
236 : {
237 0 : ScChartHelper::FillProtectedChartRangesVector( m_aProtectedChartRangesVector, pDoc, pPage );
238 : }
239 : }
240 0 : }
241 0 : }
242 :
243 0 : ScDrawTransferObj::~ScDrawTransferObj()
244 : {
245 0 : SolarMutexGuard aSolarGuard;
246 :
247 0 : ScModule* pScMod = SC_MOD();
248 0 : if ( pScMod->GetClipData().pDrawClipboard == this )
249 : {
250 : OSL_FAIL("ScDrawTransferObj wasn't released");
251 0 : pScMod->SetClipObject( NULL, NULL );
252 : }
253 0 : if ( pScMod->GetDragData().pDrawTransfer == this )
254 : {
255 : OSL_FAIL("ScDrawTransferObj wasn't released");
256 0 : pScMod->ResetDragObject();
257 : }
258 :
259 0 : aOleData = TransferableDataHelper(); // clear before releasing the mutex
260 0 : aDocShellRef.Clear();
261 :
262 0 : delete pModel;
263 0 : aDrawPersistRef.Clear(); // after the model
264 :
265 0 : delete pBookmark;
266 0 : delete pDragSourceView;
267 0 : }
268 :
269 0 : ScDrawTransferObj* ScDrawTransferObj::GetOwnClipboard( Window* )
270 : {
271 0 : ScDrawTransferObj* pObj = SC_MOD()->GetClipData().pDrawClipboard;
272 0 : return pObj;
273 : }
274 :
275 0 : static sal_Bool lcl_HasOnlyControls( SdrModel* pModel )
276 : {
277 0 : sal_Bool bOnlyControls = false; // default if there are no objects
278 :
279 0 : if ( pModel )
280 : {
281 0 : SdrPage* pPage = pModel->GetPage(0);
282 0 : if (pPage)
283 : {
284 0 : SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
285 0 : SdrObject* pObj = aIter.Next();
286 0 : if ( pObj )
287 : {
288 0 : bOnlyControls = sal_True; // only set if there are any objects at all
289 0 : while ( pObj )
290 : {
291 0 : if (!pObj->ISA(SdrUnoObj))
292 : {
293 0 : bOnlyControls = false;
294 0 : break;
295 : }
296 0 : pObj = aIter.Next();
297 : }
298 0 : }
299 : }
300 : }
301 :
302 0 : return bOnlyControls;
303 : }
304 :
305 0 : void ScDrawTransferObj::AddSupportedFormats()
306 : {
307 0 : if ( bGrIsBit ) // single bitmap graphic
308 : {
309 0 : AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
310 0 : AddFormat( SOT_FORMATSTR_ID_SVXB );
311 0 : AddFormat( SOT_FORMAT_BITMAP );
312 0 : AddFormat( SOT_FORMAT_GDIMETAFILE );
313 : }
314 0 : else if ( bGraphic ) // other graphic
315 : {
316 : // #i25616#
317 0 : AddFormat( SOT_FORMATSTR_ID_DRAWING );
318 :
319 0 : AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
320 0 : AddFormat( SOT_FORMATSTR_ID_SVXB );
321 0 : AddFormat( SOT_FORMAT_GDIMETAFILE );
322 0 : AddFormat( SOT_FORMAT_BITMAP );
323 : }
324 0 : else if ( pBookmark ) // url button
325 : {
326 : // AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
327 0 : AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
328 0 : AddFormat( SOT_FORMATSTR_ID_SOLK );
329 0 : AddFormat( SOT_FORMAT_STRING );
330 0 : AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
331 0 : AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
332 0 : AddFormat( SOT_FORMATSTR_ID_DRAWING );
333 : }
334 0 : else if ( bOleObj ) // single OLE object
335 : {
336 0 : AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
337 0 : AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
338 0 : AddFormat( SOT_FORMAT_GDIMETAFILE );
339 :
340 0 : if ( !aOleData.GetTransferable().is() )
341 : {
342 0 : SdrOle2Obj* pObj = GetSingleObject();
343 0 : if ( pObj && pObj->GetObjRef().is() )
344 0 : aOleData = TransferableDataHelper( new SvEmbedTransferHelper( pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() ) ) ;
345 : }
346 0 : if ( aOleData.GetTransferable().is() )
347 : {
348 : // get format list from object snapshot
349 : // (this must be after inserting the default formats!)
350 :
351 0 : DataFlavorExVector aVector( aOleData.GetDataFlavorExVector() );
352 0 : DataFlavorExVector::iterator aIter( aVector.begin() ), aEnd( aVector.end() );
353 :
354 0 : while( aIter != aEnd )
355 0 : AddFormat( *aIter++ );
356 : }
357 : }
358 : else // any drawing objects
359 : {
360 0 : AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
361 0 : AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
362 0 : AddFormat( SOT_FORMATSTR_ID_DRAWING );
363 :
364 : // leave out bitmap and metafile if there are only controls
365 0 : if ( !lcl_HasOnlyControls( pModel ) )
366 : {
367 0 : AddFormat( SOT_FORMAT_BITMAP );
368 0 : AddFormat( SOT_FORMAT_GDIMETAFILE );
369 : }
370 : }
371 :
372 : // if( pImageMap )
373 : // AddFormat( SOT_FORMATSTR_ID_SVIM );
374 0 : }
375 :
376 0 : sal_Bool ScDrawTransferObj::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
377 : {
378 0 : sal_Bool bOK = false;
379 0 : sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
380 :
381 0 : if ( bOleObj && nFormat != SOT_FORMAT_GDIMETAFILE )
382 : {
383 0 : if ( !aOleData.GetTransferable().is() )
384 : {
385 0 : SdrOle2Obj* pObj = GetSingleObject();
386 0 : if ( pObj && pObj->GetObjRef().is() )
387 0 : aOleData = TransferableDataHelper( new SvEmbedTransferHelper( pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() ) ) ;
388 : }
389 :
390 0 : if( aOleData.GetTransferable().is() && aOleData.HasFormat( rFlavor ) )
391 : {
392 0 : sal_uLong nOldSwapMode = 0;
393 :
394 0 : if( pModel )
395 : {
396 0 : nOldSwapMode = pModel->GetSwapGraphicsMode();
397 0 : pModel->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
398 : }
399 :
400 0 : bOK = SetAny( aOleData.GetAny( rFlavor ), rFlavor );
401 :
402 0 : if( pModel )
403 0 : pModel->SetSwapGraphicsMode( nOldSwapMode );
404 :
405 0 : return bOK;
406 : }
407 : }
408 :
409 0 : if( HasFormat( nFormat ) )
410 : {
411 0 : if ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
412 : {
413 0 : bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor );
414 : }
415 0 : else if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
416 : {
417 0 : bOK = SetObject( pModel, SCDRAWTRANS_TYPE_DRAWMODEL, rFlavor );
418 : }
419 0 : else if ( nFormat == SOT_FORMAT_BITMAP || nFormat == SOT_FORMAT_GDIMETAFILE )
420 : {
421 : // #i71538# use complete SdrViews
422 : // SdrExchangeView aView( pModel );
423 0 : SdrView aView( pModel );
424 0 : SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
425 : OSL_ENSURE( pPv, "pPv not there..." );
426 0 : aView.MarkAllObj( pPv );
427 0 : if ( nFormat == SOT_FORMAT_GDIMETAFILE )
428 0 : bOK = SetGDIMetaFile( aView.GetMarkedObjMetaFile(true), rFlavor );
429 : else
430 0 : bOK = SetBitmap( aView.GetMarkedObjBitmapEx(true).GetBitmap(), rFlavor );
431 : }
432 0 : else if ( nFormat == SOT_FORMATSTR_ID_SVXB )
433 : {
434 : // only enabled for single graphics object
435 :
436 0 : SdrPage* pPage = pModel->GetPage(0);
437 0 : if (pPage)
438 : {
439 0 : SdrObjListIter aIter( *pPage, IM_FLAT );
440 0 : SdrObject* pObject = aIter.Next();
441 0 : if (pObject && pObject->GetObjIdentifier() == OBJ_GRAF)
442 : {
443 0 : SdrGrafObj* pGraphObj = (SdrGrafObj*) pObject;
444 0 : bOK = SetGraphic( pGraphObj->GetGraphic(), rFlavor );
445 0 : }
446 : }
447 : }
448 0 : else if ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
449 : {
450 0 : if ( bOleObj ) // single OLE object
451 : {
452 0 : SdrOle2Obj* pObj = GetSingleObject();
453 0 : if ( pObj && pObj->GetObjRef().is() )
454 : {
455 0 : bOK = SetObject( pObj->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ, rFlavor );
456 : }
457 : }
458 : else // create object from contents
459 : {
460 : //TODO/LATER: needs new Format, because now single OLE and "this" are different
461 0 : InitDocShell(); // set aDocShellRef
462 :
463 0 : SfxObjectShell* pEmbObj = aDocShellRef;
464 0 : bOK = SetObject( pEmbObj, SCDRAWTRANS_TYPE_DOCUMENT, rFlavor );
465 : }
466 : }
467 0 : else if( pBookmark )
468 : {
469 0 : bOK = SetINetBookmark( *pBookmark, rFlavor );
470 : }
471 : }
472 0 : return bOK;
473 : }
474 :
475 0 : sal_Bool ScDrawTransferObj::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
476 : const ::com::sun::star::datatransfer::DataFlavor& /* rFlavor */ )
477 : {
478 : // called from SetObject, put data into stream
479 :
480 0 : sal_Bool bRet = false;
481 0 : switch (nUserObjectId)
482 : {
483 : case SCDRAWTRANS_TYPE_DRAWMODEL:
484 : {
485 0 : SdrModel* pDrawModel = (SdrModel*)pUserObject;
486 0 : rxOStm->SetBufferSize( 0xff00 );
487 :
488 : // #108584#
489 : // for the changed pool defaults from drawing layer pool set those
490 : // attributes as hard attributes to preserve them for saving
491 0 : const SfxItemPool& rItemPool = pModel->GetItemPool();
492 0 : const SvxFontHeightItem& rDefaultFontHeight = (const SvxFontHeightItem&)rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
493 :
494 : // SW should have no MasterPages
495 : OSL_ENSURE(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
496 :
497 0 : for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
498 : {
499 0 : const SdrPage* pPage = pModel->GetPage(a);
500 0 : SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS);
501 :
502 0 : while(aIter.IsMore())
503 : {
504 0 : SdrObject* pObj = aIter.Next();
505 0 : const SvxFontHeightItem& rItem = (const SvxFontHeightItem&)pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
506 :
507 0 : if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
508 : {
509 0 : pObj->SetMergedItem(rDefaultFontHeight);
510 : }
511 : }
512 0 : }
513 :
514 : {
515 0 : com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
516 0 : if( SvxDrawingLayerExport( pDrawModel, xDocOut ) )
517 0 : rxOStm->Commit();
518 : }
519 :
520 0 : bRet = ( rxOStm->GetError() == ERRCODE_NONE );
521 : }
522 0 : break;
523 :
524 : case SCDRAWTRANS_TYPE_EMBOBJ:
525 : {
526 : // impl. for "single OLE"
527 0 : embed::XEmbeddedObject* pEmbObj = (embed::XEmbeddedObject*) pUserObject;
528 :
529 0 : ::utl::TempFile aTempFile;
530 0 : aTempFile.EnableKillingFile();
531 : uno::Reference< embed::XStorage > xWorkStore =
532 0 : ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
533 :
534 0 : uno::Reference < embed::XEmbedPersist > xPers( (embed::XVisualObject*)pEmbObj, uno::UNO_QUERY );
535 0 : if ( xPers.is() )
536 : {
537 : try
538 : {
539 0 : uno::Sequence < beans::PropertyValue > aSeq;
540 0 : ::rtl::OUString aDummyName(RTL_CONSTASCII_USTRINGPARAM("Dummy"));
541 0 : xPers->storeToEntry( xWorkStore, aDummyName, aSeq, aSeq );
542 0 : if ( xWorkStore->isStreamElement( aDummyName ) )
543 : {
544 0 : uno::Reference < io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
545 0 : uno::Reference < io::XStream > xNewStream = xWorkStore->openStreamElement( aDummyName, embed::ElementModes::READ );
546 0 : ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream->getInputStream(), xDocOut );
547 : }
548 : else
549 : {
550 0 : uno::Reference < io::XStream > xDocStr( new utl::OStreamWrapper( *rxOStm ) );
551 0 : uno::Reference< embed::XStorage > xDocStg = ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr );
552 0 : uno::Reference < embed::XStorage > xNewStg = xWorkStore->openStorageElement( aDummyName, embed::ElementModes::READ );
553 0 : xNewStg->copyToStorage( xDocStg );
554 0 : uno::Reference < embed::XTransactedObject > xTrans( xDocStg, uno::UNO_QUERY );
555 0 : if ( xTrans.is() )
556 0 : xTrans->commit();
557 : }
558 :
559 0 : rxOStm->Commit();
560 : }
561 0 : catch ( uno::Exception& )
562 : {
563 : }
564 : }
565 :
566 0 : break;
567 : }
568 : case SCDRAWTRANS_TYPE_DOCUMENT:
569 : {
570 : // impl. for "DocShell"
571 0 : SfxObjectShell* pEmbObj = (SfxObjectShell*) pUserObject;
572 :
573 : try
574 : {
575 0 : ::utl::TempFile aTempFile;
576 0 : aTempFile.EnableKillingFile();
577 : uno::Reference< embed::XStorage > xWorkStore =
578 0 : ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
579 :
580 : // write document storage
581 0 : pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
582 :
583 : // mba: no relative ULRs for clipboard!
584 0 : SfxMedium aMedium( xWorkStore, String() );
585 0 : bRet = pEmbObj->DoSaveObjectAs( aMedium, false );
586 0 : pEmbObj->DoSaveCompleted();
587 :
588 0 : uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
589 0 : if ( xTransact.is() )
590 0 : xTransact->commit();
591 :
592 0 : SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
593 0 : if( pSrcStm )
594 : {
595 0 : rxOStm->SetBufferSize( 0xff00 );
596 0 : *rxOStm << *pSrcStm;
597 0 : delete pSrcStm;
598 : }
599 :
600 0 : bRet = sal_True;
601 :
602 0 : xWorkStore->dispose();
603 0 : xWorkStore = uno::Reference < embed::XStorage >();
604 0 : rxOStm->Commit();
605 : }
606 0 : catch ( uno::Exception& )
607 : {}
608 :
609 0 : bRet = ( rxOStm->GetError() == ERRCODE_NONE );
610 : }
611 0 : break;
612 :
613 : default:
614 : OSL_FAIL("unknown object id");
615 : }
616 0 : return bRet;
617 : }
618 :
619 0 : void ScDrawTransferObj::ObjectReleased()
620 : {
621 0 : ScModule* pScMod = SC_MOD();
622 0 : if ( pScMod->GetClipData().pDrawClipboard == this )
623 0 : pScMod->SetClipObject( NULL, NULL );
624 :
625 0 : TransferableHelper::ObjectReleased();
626 0 : }
627 :
628 0 : void ScDrawTransferObj::DragFinished( sal_Int8 nDropAction )
629 : {
630 0 : if ( nDropAction == DND_ACTION_MOVE && !bDragWasInternal && !(nDragSourceFlags & SC_DROP_NAVIGATOR) )
631 : {
632 : // move: delete source objects
633 :
634 0 : if ( pDragSourceView )
635 0 : pDragSourceView->DeleteMarked();
636 : }
637 :
638 0 : ScModule* pScMod = SC_MOD();
639 0 : if ( pScMod->GetDragData().pDrawTransfer == this )
640 0 : pScMod->ResetDragObject();
641 :
642 0 : DELETEZ( pDragSourceView );
643 :
644 0 : TransferableHelper::DragFinished( nDropAction );
645 0 : }
646 :
647 0 : void ScDrawTransferObj::SetDrawPersist( const SfxObjectShellRef& rRef )
648 : {
649 0 : aDrawPersistRef = rRef;
650 0 : }
651 :
652 0 : static void lcl_InitMarks( SdrMarkView& rDest, const SdrMarkView& rSource, SCTAB nTab )
653 : {
654 0 : rDest.ShowSdrPage(rDest.GetModel()->GetPage(nTab));
655 0 : SdrPageView* pDestPV = rDest.GetSdrPageView();
656 : OSL_ENSURE(pDestPV,"PageView ?");
657 :
658 0 : const SdrMarkList& rMarkList = rSource.GetMarkedObjectList();
659 0 : sal_uLong nCount = rMarkList.GetMarkCount();
660 0 : for (sal_uLong i=0; i<nCount; i++)
661 : {
662 0 : SdrMark* pMark = rMarkList.GetMark(i);
663 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
664 :
665 0 : rDest.MarkObj(pObj, pDestPV);
666 : }
667 0 : }
668 :
669 0 : void ScDrawTransferObj::SetDragSource( ScDrawView* pView )
670 : {
671 0 : DELETEZ( pDragSourceView );
672 0 : pDragSourceView = new SdrView( pView->GetModel() );
673 0 : lcl_InitMarks( *pDragSourceView, *pView, pView->GetTab() );
674 :
675 : //! add as listener with document, delete pDragSourceView if document gone
676 0 : }
677 :
678 0 : void ScDrawTransferObj::SetDragSourceObj( SdrObject* pObj, SCTAB nTab )
679 : {
680 0 : DELETEZ( pDragSourceView );
681 0 : pDragSourceView = new SdrView( pObj->GetModel() );
682 0 : pDragSourceView->ShowSdrPage(pDragSourceView->GetModel()->GetPage(nTab));
683 0 : SdrPageView* pPV = pDragSourceView->GetSdrPageView();
684 0 : pDragSourceView->MarkObj(pObj, pPV);
685 :
686 : //! add as listener with document, delete pDragSourceView if document gone
687 0 : }
688 :
689 0 : void ScDrawTransferObj::SetDragSourceFlags( sal_uInt16 nFlags )
690 : {
691 0 : nDragSourceFlags = nFlags;
692 0 : }
693 :
694 0 : void ScDrawTransferObj::SetDragWasInternal()
695 : {
696 0 : bDragWasInternal = sal_True;
697 0 : }
698 :
699 0 : SdrOle2Obj* ScDrawTransferObj::GetSingleObject()
700 : {
701 : // if single OLE object was copied, get its object
702 :
703 0 : SdrPage* pPage = pModel->GetPage(0);
704 0 : if (pPage)
705 : {
706 0 : SdrObjListIter aIter( *pPage, IM_FLAT );
707 0 : SdrObject* pObject = aIter.Next();
708 0 : if (pObject && pObject->GetObjIdentifier() == OBJ_OLE2)
709 : {
710 0 : return (SdrOle2Obj*) pObject;
711 0 : }
712 : }
713 :
714 0 : return NULL;
715 : }
716 :
717 : //
718 : // initialize aDocShellRef with a live document from the ClipDoc
719 : //
720 :
721 0 : void ScDrawTransferObj::InitDocShell()
722 : {
723 0 : if ( !aDocShellRef.Is() )
724 : {
725 0 : ScDocShell* pDocSh = new ScDocShell;
726 0 : aDocShellRef = pDocSh; // ref must be there before InitNew
727 :
728 0 : pDocSh->DoInitNew(NULL);
729 :
730 0 : ScDocument* pDestDoc = pDocSh->GetDocument();
731 0 : pDestDoc->InitDrawLayer( pDocSh );
732 :
733 0 : SdrModel* pDestModel = pDestDoc->GetDrawLayer();
734 : // #i71538# use complete SdrViews
735 : // SdrExchangeView aDestView( pDestModel );
736 0 : SdrView aDestView( pDestModel );
737 0 : aDestView.ShowSdrPage(aDestView.GetModel()->GetPage(0));
738 0 : aDestView.Paste( *pModel, Point( aSrcSize.Width()/2, aSrcSize.Height()/2 ) );
739 :
740 : // put objects to right layer (see ScViewFunc::PasteDataFormat for SOT_FORMATSTR_ID_DRAWING)
741 :
742 0 : SdrPage* pPage = pDestModel->GetPage(0);
743 0 : if (pPage)
744 : {
745 0 : SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
746 0 : SdrObject* pObject = aIter.Next();
747 0 : while (pObject)
748 : {
749 0 : if ( pObject->ISA(SdrUnoObj) )
750 0 : pObject->NbcSetLayer(SC_LAYER_CONTROLS);
751 : else
752 0 : pObject->NbcSetLayer(SC_LAYER_FRONT);
753 0 : pObject = aIter.Next();
754 0 : }
755 : }
756 :
757 0 : Point aTmpPoint;
758 0 : Rectangle aDestArea( aTmpPoint, aSrcSize );
759 0 : pDocSh->SetVisArea( aDestArea );
760 :
761 0 : ScViewOptions aViewOpt( pDestDoc->GetViewOptions() );
762 0 : aViewOpt.SetOption( VOPT_GRID, false );
763 0 : pDestDoc->SetViewOptions( aViewOpt );
764 :
765 0 : ScViewData aViewData( pDocSh, NULL );
766 0 : aViewData.SetTabNo( 0 );
767 0 : aViewData.SetScreen( aDestArea );
768 0 : aViewData.SetCurX( 0 );
769 0 : aViewData.SetCurY( 0 );
770 0 : pDocSh->UpdateOle(&aViewData, sal_True);
771 : }
772 0 : }
773 :
774 : namespace
775 : {
776 : class theScDrawTransferObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScDrawTransferObjUnoTunnelId > {};
777 : }
778 :
779 0 : const com::sun::star::uno::Sequence< sal_Int8 >& ScDrawTransferObj::getUnoTunnelId()
780 : {
781 0 : return theScDrawTransferObjUnoTunnelId::get().getSeq();
782 : }
783 :
784 0 : sal_Int64 SAL_CALL ScDrawTransferObj::getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException )
785 : {
786 : sal_Int64 nRet;
787 0 : if( ( rId.getLength() == 16 ) &&
788 0 : ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
789 : {
790 0 : nRet = reinterpret_cast< sal_Int64 >( this );
791 : }
792 : else
793 0 : nRet = TransferableHelper::getSomething(rId);
794 0 : return nRet;
795 15 : }
796 :
797 :
798 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|