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