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 "View.hxx"
21 : #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
22 : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
23 : #include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
24 : #include <com/sun/star/lang/XComponent.hpp>
25 : #include <sot/filelist.hxx>
26 : #include <unotools/pathoptions.hxx>
27 : #include <editeng/editdata.hxx>
28 : #include <svl/urlbmk.hxx>
29 : #include <svx/xexch.hxx>
30 : #include <svx/xflclit.hxx>
31 : #include <svx/xlnclit.hxx>
32 : #include <svx/svdpagv.hxx>
33 : #include <editeng/eeitem.hxx>
34 : #include <editeng/colritem.hxx>
35 : #include <sfx2/docfile.hxx>
36 : #include <svx/svditer.hxx>
37 : #include <svx/svdogrp.hxx>
38 : #include <svx/svdoole2.hxx>
39 : #include <svx/svdograf.hxx>
40 : #include <svx/svdetc.hxx>
41 : #include <svx/svdundo.hxx>
42 : #include <sfx2/app.hxx>
43 : #include <svl/itempool.hxx>
44 : #include <comphelper/classids.hxx>
45 : #include <svx/fmmodel.hxx>
46 : #include <sot/formats.hxx>
47 : #include <editeng/outliner.hxx>
48 : #include <editeng/editeng.hxx>
49 : #include <svx/obj3d.hxx>
50 : #include <svx/e3dundo.hxx>
51 : #include <svx/unomodel.hxx>
52 : #include <unotools/streamwrap.hxx>
53 : #include <vcl/metaact.hxx>
54 : #include <svx/svxids.hrc>
55 : #include <toolkit/helper/vclunohelper.hxx>
56 : #include "DrawDocShell.hxx"
57 : #include "fupoor.hxx"
58 : #include "Window.hxx"
59 : #include "sdxfer.hxx"
60 : #include "sdpage.hxx"
61 : #include "DrawViewShell.hxx"
62 : #include "drawdoc.hxx"
63 : #include "sdresid.hxx"
64 : #include "strings.hrc"
65 : #include "imapinfo.hxx"
66 : #include "SlideSorterViewShell.hxx"
67 : #include "strmname.h"
68 : #include "unomodel.hxx"
69 : #include "ViewClipboard.hxx"
70 : #include <sfx2/ipclient.hxx>
71 : #include <comphelper/storagehelper.hxx>
72 : #include <comphelper/processfactory.hxx>
73 : #include <tools/stream.hxx>
74 : #include <vcl/cvtgrf.hxx>
75 : #include <svx/sdrhittesthelper.hxx>
76 : #include <svx/xbtmpit.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 : namespace sd {
90 :
91 : #define CHECK_FORMAT_TRANS( _def_Type ) ( ( nFormat == (_def_Type) || !nFormat ) && aDataHelper.HasFormat( _def_Type ) )
92 :
93 : /*************************************************************************
94 : |*
95 : |* Paste
96 : |*
97 : \************************************************************************/
98 :
99 : struct ImpRememberOrigAndClone
100 : {
101 : SdrObject* pOrig;
102 : SdrObject* pClone;
103 : };
104 :
105 0 : SdrObject* ImpGetClone(std::vector<ImpRememberOrigAndClone*>& aConnectorContainer, SdrObject* pConnObj)
106 : {
107 0 : for(sal_uInt32 a(0); a < aConnectorContainer.size(); a++)
108 : {
109 0 : if(pConnObj == aConnectorContainer[a]->pOrig)
110 0 : return aConnectorContainer[a]->pClone;
111 : }
112 0 : return 0L;
113 : }
114 :
115 : // restrict movement to WorkArea
116 0 : void ImpCheckInsertPos(Point& rPos, const Size& rSize, const Rectangle& rWorkArea)
117 : {
118 0 : if(!rWorkArea.IsEmpty())
119 : {
120 0 : Rectangle aMarkRect(Point(rPos.X() - (rSize.Width() / 2), rPos.Y() - (rSize.Height() / 2)), rSize);
121 :
122 0 : if(!aMarkRect.IsInside(rWorkArea))
123 : {
124 0 : if(aMarkRect.Left() < rWorkArea.Left())
125 : {
126 0 : rPos.X() += rWorkArea.Left() - aMarkRect.Left();
127 : }
128 :
129 0 : if(aMarkRect.Right() > rWorkArea.Right())
130 : {
131 0 : rPos.X() -= aMarkRect.Right() - rWorkArea.Right();
132 : }
133 :
134 0 : if(aMarkRect.Top() < rWorkArea.Top())
135 : {
136 0 : rPos.Y() += rWorkArea.Top() - aMarkRect.Top();
137 : }
138 :
139 0 : if(aMarkRect.Bottom() > rWorkArea.Bottom())
140 : {
141 0 : rPos.Y() -= aMarkRect.Bottom() - rWorkArea.Bottom();
142 : }
143 : }
144 : }
145 0 : }
146 :
147 0 : bool View::InsertMetaFile( TransferableDataHelper& rDataHelper, const Point& rPos, ImageMap* pImageMap, bool bOptimize )
148 : {
149 0 : GDIMetaFile aMtf;
150 :
151 0 : if( !rDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
152 0 : return false;
153 :
154 0 : bool bVector = false;
155 0 : Graphic aGraphic;
156 :
157 : // check if metafile only contains a pixel image, if so insert a bitmap instead
158 0 : if( bOptimize )
159 : {
160 0 : MetaAction* pAction = aMtf.FirstAction();
161 0 : while( pAction && !bVector )
162 : {
163 0 : switch( pAction->GetType() )
164 : {
165 : case META_POINT_ACTION:
166 : case META_LINE_ACTION:
167 : case META_RECT_ACTION:
168 : case META_ROUNDRECT_ACTION:
169 : case META_ELLIPSE_ACTION:
170 : case META_ARC_ACTION:
171 : case META_PIE_ACTION:
172 : case META_CHORD_ACTION:
173 : case META_POLYLINE_ACTION:
174 : case META_POLYGON_ACTION:
175 : case META_POLYPOLYGON_ACTION:
176 : case META_TEXT_ACTION:
177 : case META_TEXTARRAY_ACTION:
178 : case META_STRETCHTEXT_ACTION:
179 : case META_TEXTRECT_ACTION:
180 : case META_GRADIENT_ACTION:
181 : case META_HATCH_ACTION:
182 : case META_WALLPAPER_ACTION:
183 : case META_EPS_ACTION:
184 : case META_TEXTLINE_ACTION:
185 : case META_FLOATTRANSPARENT_ACTION:
186 : case META_GRADIENTEX_ACTION:
187 : case META_BMPSCALEPART_ACTION:
188 : case META_BMPEXSCALEPART_ACTION:
189 0 : bVector = true;
190 0 : break;
191 : case META_BMP_ACTION:
192 : case META_BMPSCALE_ACTION:
193 : case META_BMPEX_ACTION:
194 : case META_BMPEXSCALE_ACTION:
195 0 : if( aGraphic.GetType() != GRAPHIC_NONE )
196 : {
197 0 : bVector = true;
198 : }
199 0 : else switch( pAction->GetType() )
200 : {
201 : case META_BMP_ACTION:
202 : {
203 0 : MetaBmpAction* pBmpAction = dynamic_cast< MetaBmpAction* >( pAction );
204 0 : if( pBmpAction )
205 0 : aGraphic = Graphic( pBmpAction->GetBitmap() );
206 : }
207 0 : break;
208 : case META_BMPSCALE_ACTION:
209 : {
210 0 : MetaBmpScaleAction* pBmpScaleAction = dynamic_cast< MetaBmpScaleAction* >( pAction );
211 0 : if( pBmpScaleAction )
212 0 : aGraphic = Graphic( pBmpScaleAction->GetBitmap() );
213 : }
214 0 : break;
215 : case META_BMPEX_ACTION:
216 : {
217 0 : MetaBmpExAction* pBmpExAction = dynamic_cast< MetaBmpExAction* >( pAction );
218 0 : if( pBmpExAction )
219 0 : aGraphic = Graphic( pBmpExAction->GetBitmapEx() );
220 : }
221 0 : break;
222 : case META_BMPEXSCALE_ACTION:
223 : {
224 0 : MetaBmpExScaleAction* pBmpExScaleAction = dynamic_cast< MetaBmpExScaleAction* >( pAction );
225 0 : if( pBmpExScaleAction )
226 0 : aGraphic = Graphic( pBmpExScaleAction->GetBitmapEx() );
227 : }
228 0 : break;
229 : }
230 : }
231 :
232 0 : pAction = aMtf.NextAction();
233 : }
234 : }
235 :
236 : // it is not a vector metafile but it also has no graphic?
237 0 : if( !bVector && (aGraphic.GetType() == GRAPHIC_NONE) )
238 0 : bVector = true;
239 :
240 : // restrict movement to WorkArea
241 0 : Point aInsertPos( rPos );
242 0 : Size aImageSize;
243 0 : aImageSize = bVector ? aMtf.GetPrefSize() : aGraphic.GetSizePixel();
244 0 : ImpCheckInsertPos(aInsertPos, aImageSize, GetWorkArea());
245 :
246 0 : if( bVector )
247 0 : aGraphic = Graphic( aMtf );
248 :
249 0 : aGraphic.SetPrefMapMode( aMtf.GetPrefMapMode() );
250 0 : aGraphic.SetPrefSize( aMtf.GetPrefSize() );
251 0 : InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap );
252 :
253 0 : return true;
254 : }
255 :
256 0 : sal_Bool View::InsertData( const TransferableDataHelper& rDataHelper,
257 : const Point& rPos, sal_Int8& rDnDAction, sal_Bool bDrag,
258 : sal_uLong nFormat, sal_uInt16 nPage, sal_uInt16 nLayer )
259 : {
260 0 : maDropPos = rPos;
261 0 : mnAction = rDnDAction;
262 0 : mbIsDropAllowed = false;
263 :
264 0 : TransferableDataHelper aDataHelper( rDataHelper );
265 0 : SdrObject* pPickObj = NULL;
266 0 : SdPage* pPage = NULL;
267 0 : ImageMap* pImageMap = NULL;
268 0 : bool bReturn = false;
269 0 : sal_Bool bLink = ( ( mnAction & DND_ACTION_LINK ) != 0 );
270 0 : sal_Bool bCopy = ( ( ( mnAction & DND_ACTION_COPY ) != 0 ) || bLink );
271 0 : sal_uLong nPasteOptions = SDRINSERT_SETDEFLAYER;
272 :
273 0 : if (mpViewSh != NULL)
274 : {
275 : OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
276 0 : SfxInPlaceClient* pIpClient = mpViewSh->GetViewShell()->GetIPClient();
277 0 : if( mpViewSh->ISA(::sd::slidesorter::SlideSorterViewShell)
278 0 : || (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive()))
279 0 : nPasteOptions |= SDRINSERT_DONTMARK;
280 : }
281 :
282 0 : if( bDrag )
283 : {
284 0 : SdrPageView* pPV = NULL;
285 0 : PickObj( rPos, getHitTolLog(), pPickObj, pPV );
286 : }
287 :
288 0 : if( nPage != SDRPAGE_NOTFOUND )
289 0 : pPage = (SdPage*) mrDoc.GetPage( nPage );
290 :
291 0 : SdTransferable* pOwnData = NULL;
292 0 : SdTransferable* pImplementation = SdTransferable::getImplementation( aDataHelper.GetTransferable() );
293 :
294 0 : if(pImplementation && (rDnDAction & DND_ACTION_LINK))
295 : {
296 : // suppress own data when it's intention is to use it as fill information
297 0 : pImplementation = 0;
298 : }
299 :
300 : // try to get own transfer data
301 0 : if( pImplementation )
302 : {
303 0 : if( SD_MOD()->pTransferClip == (SdTransferable*) pImplementation )
304 0 : pOwnData = SD_MOD()->pTransferClip;
305 0 : else if( SD_MOD()->pTransferDrag == (SdTransferable*) pImplementation )
306 0 : pOwnData = SD_MOD()->pTransferDrag;
307 0 : else if( SD_MOD()->pTransferSelection == (SdTransferable*) pImplementation )
308 0 : pOwnData = SD_MOD()->pTransferSelection;
309 : }
310 :
311 : // ImageMap?
312 0 : if( !pOwnData && aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
313 : {
314 0 : SotStorageStreamRef xStm;
315 :
316 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVIM, xStm ) )
317 : {
318 0 : pImageMap = new ImageMap;
319 : // mba: clipboard always must contain absolute URLs (could be from alien source)
320 0 : pImageMap->Read( *xStm, OUString() );
321 0 : }
322 : }
323 :
324 0 : bool bTable = false;
325 : // check special cases for pasting table formats as RTL
326 0 : if( !bLink && (!nFormat || (nFormat == SOT_FORMAT_RTF)) )
327 : {
328 : // if the objekt supports rtf and there is a table involved, default is to create a table
329 0 : if( aDataHelper.HasFormat( SOT_FORMAT_RTF ) && ! aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
330 : {
331 0 : SotStorageStreamRef xStm;
332 :
333 0 : if( aDataHelper.GetSotStorageStream( FORMAT_RTF, xStm ) )
334 : {
335 0 : xStm->Seek( 0 );
336 :
337 0 : OString aLine;
338 0 : while (xStm->ReadLine(aLine))
339 : {
340 0 : sal_Int32 x = aLine.indexOf( "\\trowd" );
341 0 : if (x != -1)
342 : {
343 0 : bTable = true;
344 0 : nFormat = FORMAT_RTF;
345 0 : break;
346 : }
347 0 : }
348 0 : }
349 : }
350 : }
351 :
352 : // Changed the whole decision tree to be dependent of bReturn as a flag that
353 : // the work was done; this allows to check multiple formats and not just fail
354 : // when a CHECK_FORMAT_TRANS(*format*) detected format does not work. This is
355 : // e.g. necessary for FORMAT_BITMAP
356 0 : if( pOwnData && !nFormat )
357 : {
358 0 : const View* pSourceView = pOwnData->GetView();
359 :
360 0 : if( pOwnData->GetDocShell() && pOwnData->IsPageTransferable() && ISA( View ) )
361 : {
362 0 : mpClipboard->HandlePageDrop (*pOwnData);
363 : }
364 0 : else if( pSourceView )
365 : {
366 0 : if( pSourceView == this )
367 : {
368 : // same view
369 0 : if( nLayer != SDRLAYER_NOTFOUND )
370 : {
371 : // drop on layer tab bar
372 0 : SdrLayerAdmin& rLayerAdmin = mrDoc.GetLayerAdmin();
373 0 : SdrLayer* pLayer = rLayerAdmin.GetLayerPerID( nLayer );
374 0 : SdrPageView* pPV = GetSdrPageView();
375 0 : OUString aLayer = pLayer->GetName();
376 :
377 0 : if( !pPV->IsLayerLocked( aLayer ) )
378 : {
379 0 : pOwnData->SetInternalMove( sal_True );
380 0 : SortMarkedObjects();
381 :
382 0 : for( sal_uLong nM = 0; nM < GetMarkedObjectCount(); nM++ )
383 : {
384 0 : SdrMark* pM = GetSdrMarkByIndex( nM );
385 0 : SdrObject* pO = pM->GetMarkedSdrObj();
386 :
387 0 : if( pO )
388 : {
389 : // #i11702#
390 0 : if( IsUndoEnabled() )
391 : {
392 0 : BegUndo(SD_RESSTR(STR_MODIFYLAYER));
393 0 : AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoObjectLayerChange(*pO, pO->GetLayer(), (SdrLayerID)nLayer));
394 0 : EndUndo();
395 : }
396 :
397 0 : pO->SetLayer( (SdrLayerID) nLayer );
398 : }
399 : }
400 :
401 0 : bReturn = true;
402 0 : }
403 : }
404 : else
405 : {
406 0 : SdrPageView* pPV = GetSdrPageView();
407 0 : sal_Bool bDropOnTabBar = sal_True;
408 :
409 0 : if( !pPage && pPV->GetPage()->GetPageNum() != mnDragSrcPgNum )
410 : {
411 0 : pPage = (SdPage*) pPV->GetPage();
412 0 : bDropOnTabBar = sal_False;
413 : }
414 :
415 0 : if( pPage )
416 : {
417 : // drop on other page
418 0 : OUString aActiveLayer = GetActiveLayer();
419 :
420 0 : if( !pPV->IsLayerLocked( aActiveLayer ) )
421 : {
422 0 : if( !IsPresObjSelected() )
423 : {
424 : SdrMarkList* pMarkList;
425 :
426 0 : if( (mnDragSrcPgNum != SDRPAGE_NOTFOUND) && (mnDragSrcPgNum != pPV->GetPage()->GetPageNum()) )
427 : {
428 0 : pMarkList = mpDragSrcMarkList;
429 : }
430 : else
431 : {
432 : // actual mark list is used
433 0 : pMarkList = new SdrMarkList( GetMarkedObjectList());
434 : }
435 :
436 0 : pMarkList->ForceSort();
437 :
438 : // stuff to remember originals and clones
439 0 : std::vector<ImpRememberOrigAndClone*> aConnectorContainer;
440 0 : sal_uInt32 a, nConnectorCount(0L);
441 0 : Point aCurPos;
442 :
443 : // calculate real position of current
444 : // source objects, if necessary (#103207)
445 0 : if( pOwnData == SD_MOD()->pTransferSelection )
446 : {
447 0 : Rectangle aCurBoundRect;
448 :
449 0 : if( pMarkList->TakeBoundRect( pPV, aCurBoundRect ) )
450 0 : aCurPos = aCurBoundRect.TopLeft();
451 : else
452 0 : aCurPos = pOwnData->GetStartPos();
453 : }
454 : else
455 0 : aCurPos = pOwnData->GetStartPos();
456 :
457 0 : const Size aVector( maDropPos.X() - aCurPos.X(), maDropPos.Y() - aCurPos.Y() );
458 :
459 0 : for(a = 0; a < pMarkList->GetMarkCount(); a++)
460 : {
461 0 : SdrMark* pM = pMarkList->GetMark(a);
462 0 : SdrObject* pObj = pM->GetMarkedSdrObj()->Clone();
463 :
464 0 : if(pObj)
465 : {
466 0 : if(!bDropOnTabBar)
467 : {
468 : // do a NbcMove(...) instead of setting SnapRects here
469 0 : pObj->NbcMove(aVector);
470 : }
471 :
472 0 : pPage->InsertObject(pObj);
473 :
474 0 : if( IsUndoEnabled() )
475 : {
476 0 : BegUndo(SD_RESSTR(STR_UNDO_DRAGDROP));
477 0 : AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
478 0 : EndUndo();
479 : }
480 :
481 0 : ImpRememberOrigAndClone* pRem = new ImpRememberOrigAndClone;
482 0 : pRem->pOrig = pM->GetMarkedSdrObj();
483 0 : pRem->pClone = pObj;
484 0 : aConnectorContainer.push_back(pRem);
485 :
486 0 : if(pObj->ISA(SdrEdgeObj))
487 0 : nConnectorCount++;
488 : }
489 : }
490 :
491 : // try to re-establish connections at clones
492 0 : if(nConnectorCount)
493 : {
494 0 : for(a = 0; a < aConnectorContainer.size(); a++)
495 : {
496 0 : ImpRememberOrigAndClone* pRem = aConnectorContainer[a];
497 :
498 0 : if(pRem->pClone->ISA(SdrEdgeObj))
499 : {
500 0 : SdrEdgeObj* pOrigEdge = (SdrEdgeObj*)pRem->pOrig;
501 0 : SdrEdgeObj* pCloneEdge = (SdrEdgeObj*)pRem->pClone;
502 :
503 : // test first connection
504 0 : SdrObjConnection& rConn0 = pOrigEdge->GetConnection(false);
505 0 : SdrObject* pConnObj = rConn0.GetObject();
506 0 : if(pConnObj)
507 : {
508 0 : SdrObject* pConnClone = ImpGetClone(aConnectorContainer, pConnObj);
509 0 : if(pConnClone)
510 : {
511 : // if dest obj was cloned, too, re-establish connection
512 0 : pCloneEdge->ConnectToNode(false, pConnClone);
513 0 : pCloneEdge->GetConnection(false).SetConnectorId(rConn0.GetConnectorId());
514 : }
515 : else
516 : {
517 : // set position of connection point of original connected object
518 0 : const SdrGluePointList* pGlueList = pConnObj->GetGluePointList();
519 0 : if(pGlueList)
520 : {
521 0 : sal_uInt16 nInd = pGlueList->FindGluePoint(rConn0.GetConnectorId());
522 :
523 0 : if(SDRGLUEPOINT_NOTFOUND != nInd)
524 : {
525 0 : const SdrGluePoint& rGluePoint = (*pGlueList)[nInd];
526 0 : Point aPosition = rGluePoint.GetAbsolutePos(*pConnObj);
527 0 : aPosition.X() += aVector.A();
528 0 : aPosition.Y() += aVector.B();
529 0 : pCloneEdge->SetTailPoint(false, aPosition);
530 : }
531 : }
532 : }
533 : }
534 :
535 : // test second connection
536 0 : SdrObjConnection& rConn1 = pOrigEdge->GetConnection(true);
537 0 : pConnObj = rConn1.GetObject();
538 0 : if(pConnObj)
539 : {
540 0 : SdrObject* pConnClone = ImpGetClone(aConnectorContainer, pConnObj);
541 0 : if(pConnClone)
542 : {
543 : // if dest obj was cloned, too, re-establish connection
544 0 : pCloneEdge->ConnectToNode(true, pConnClone);
545 0 : pCloneEdge->GetConnection(true).SetConnectorId(rConn1.GetConnectorId());
546 : }
547 : else
548 : {
549 : // set position of connection point of original connected object
550 0 : const SdrGluePointList* pGlueList = pConnObj->GetGluePointList();
551 0 : if(pGlueList)
552 : {
553 0 : sal_uInt16 nInd = pGlueList->FindGluePoint(rConn1.GetConnectorId());
554 :
555 0 : if(SDRGLUEPOINT_NOTFOUND != nInd)
556 : {
557 0 : const SdrGluePoint& rGluePoint = (*pGlueList)[nInd];
558 0 : Point aPosition = rGluePoint.GetAbsolutePos(*pConnObj);
559 0 : aPosition.X() += aVector.A();
560 0 : aPosition.Y() += aVector.B();
561 0 : pCloneEdge->SetTailPoint(true, aPosition);
562 : }
563 : }
564 : }
565 : }
566 : }
567 : }
568 : }
569 :
570 : // cleanup remember classes
571 0 : for(a = 0; a < aConnectorContainer.size(); a++)
572 0 : delete aConnectorContainer[a];
573 :
574 0 : if( pMarkList != mpDragSrcMarkList )
575 0 : delete pMarkList;
576 :
577 0 : bReturn = true;
578 : }
579 : else
580 : {
581 0 : maDropErrorTimer.Start();
582 0 : bReturn = false;
583 : }
584 0 : }
585 : }
586 : else
587 : {
588 0 : pOwnData->SetInternalMove( sal_True );
589 0 : MoveAllMarked( Size( maDropPos.X() - pOwnData->GetStartPos().X(),
590 0 : maDropPos.Y() - pOwnData->GetStartPos().Y() ), bCopy );
591 0 : bReturn = true;
592 : }
593 : }
594 : }
595 : else
596 : {
597 : // different views
598 0 : if( !pSourceView->IsPresObjSelected() )
599 : {
600 : // model is owned by from AllocModel() created DocShell
601 0 : SdDrawDocument* pSourceDoc = (SdDrawDocument*) pSourceView->GetModel();
602 0 : pSourceDoc->CreatingDataObj( pOwnData );
603 0 : SdDrawDocument* pModel = (SdDrawDocument*) pSourceView->GetMarkedObjModel();
604 0 : bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
605 :
606 0 : if( !pPage )
607 0 : pPage = (SdPage*) GetSdrPageView()->GetPage();
608 :
609 0 : OUString aLayout = pPage->GetLayoutName();
610 0 : sal_Int32 nPos = aLayout.indexOf(SD_LT_SEPARATOR);
611 0 : if (nPos != -1)
612 0 : aLayout = aLayout.copy(0, nPos);
613 0 : pPage->SetPresentationLayout( aLayout, sal_False, sal_False );
614 0 : pSourceDoc->CreatingDataObj( NULL );
615 : }
616 : else
617 : {
618 0 : maDropErrorTimer.Start();
619 0 : bReturn = false;
620 : }
621 : }
622 : }
623 : else
624 : {
625 0 : SdDrawDocument* pWorkModel = (SdDrawDocument*) pOwnData->GetWorkDocument();
626 0 : SdPage* pWorkPage = (SdPage*) pWorkModel->GetSdPage( 0, PK_STANDARD );
627 :
628 0 : pWorkPage->SetRectsDirty();
629 :
630 : // #i120393# Clipboard data uses full object geometry range
631 0 : const Size aSize( pWorkPage->GetAllObjBoundRect().GetSize() );
632 :
633 0 : maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
634 0 : maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
635 :
636 : // delete pages, that are not of any interest for us
637 0 : for( long i = ( pWorkModel->GetPageCount() - 1 ); i >= 0; i-- )
638 : {
639 0 : SdPage* pP = static_cast< SdPage* >( pWorkModel->GetPage( (sal_uInt16) i ) );
640 :
641 0 : if( pP->GetPageKind() != PK_STANDARD )
642 0 : pWorkModel->DeletePage( (sal_uInt16) i );
643 : }
644 :
645 0 : bReturn = Paste( *pWorkModel, maDropPos, pPage, nPasteOptions );
646 :
647 0 : if( !pPage )
648 0 : pPage = (SdPage*) GetSdrPageView()->GetPage();
649 :
650 0 : OUString aLayout = pPage->GetLayoutName();
651 0 : sal_Int32 nPos = aLayout.indexOf(SD_LT_SEPARATOR);
652 0 : if (nPos != -1)
653 0 : aLayout = aLayout.copy(0, nPos);
654 0 : pPage->SetPresentationLayout( aLayout, sal_False, sal_False );
655 : }
656 : }
657 :
658 0 : if(!bReturn && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_DRAWING ))
659 : {
660 0 : SotStorageStreamRef xStm;
661 :
662 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ) )
663 : {
664 0 : sal_Bool bChanged = sal_False;
665 :
666 0 : DrawDocShellRef xShell = new DrawDocShell(SFX_CREATE_MODE_INTERNAL);
667 0 : xShell->DoInitNew(0);
668 :
669 0 : SdDrawDocument* pModel = xShell->GetDoc();
670 0 : pModel->InsertPage(pModel->AllocPage(false));
671 :
672 0 : Reference< XComponent > xComponent( xShell->GetModel(), UNO_QUERY );
673 0 : xStm->Seek( 0 );
674 :
675 0 : com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
676 0 : bReturn = SvxDrawingLayerImport( pModel, xInputStream, xComponent, "com.sun.star.comp.Impress.XMLOasisImporter" );
677 :
678 0 : if( pModel->GetPageCount() == 0 )
679 : {
680 : OSL_FAIL("empty or invalid drawing xml document on clipboard!" );
681 : }
682 : else
683 : {
684 0 : if( bReturn )
685 : {
686 0 : if( pModel->GetSdPage( 0, PK_STANDARD )->GetObjCount() == 1 )
687 : {
688 : // only one object
689 0 : SdrObject* pObj = pModel->GetSdPage( 0, PK_STANDARD )->GetObj( 0 );
690 0 : SdrObject* pPickObj2 = NULL;
691 0 : SdrPageView* pPV = NULL;
692 0 : PickObj( rPos, getHitTolLog(), pPickObj2, pPV );
693 :
694 0 : if( ( mnAction & DND_ACTION_MOVE ) && pPickObj2 && pObj )
695 : {
696 : // replace object
697 0 : SdrObject* pNewObj = pObj->Clone();
698 0 : Rectangle aPickObjRect( pPickObj2->GetCurrentBoundRect() );
699 0 : Size aPickObjSize( aPickObjRect.GetSize() );
700 0 : Point aVec( aPickObjRect.TopLeft() );
701 0 : Rectangle aObjRect( pNewObj->GetCurrentBoundRect() );
702 0 : Size aObjSize( aObjRect.GetSize() );
703 :
704 0 : Fraction aScaleWidth( aPickObjSize.Width(), aObjSize.Width() );
705 0 : Fraction aScaleHeight( aPickObjSize.Height(), aObjSize.Height() );
706 0 : pNewObj->NbcResize( aObjRect.TopLeft(), aScaleWidth, aScaleHeight );
707 :
708 0 : aVec -= aObjRect.TopLeft();
709 0 : pNewObj->NbcMove( Size( aVec.X(), aVec.Y() ) );
710 :
711 0 : const bool bUndo = IsUndoEnabled();
712 :
713 0 : if( bUndo )
714 0 : BegUndo(SD_RESSTR(STR_UNDO_DRAGDROP));
715 0 : pNewObj->NbcSetLayer( pPickObj->GetLayer() );
716 0 : SdrPage* pWorkPage = GetSdrPageView()->GetPage();
717 0 : pWorkPage->InsertObject( pNewObj );
718 0 : if( bUndo )
719 : {
720 0 : AddUndo( mrDoc.GetSdrUndoFactory().CreateUndoNewObject( *pNewObj ) );
721 0 : AddUndo( mrDoc.GetSdrUndoFactory().CreateUndoDeleteObject( *pPickObj2 ) );
722 : }
723 0 : pWorkPage->RemoveObject( pPickObj2->GetOrdNum() );
724 :
725 0 : if( bUndo )
726 : {
727 0 : EndUndo();
728 : }
729 : else
730 : {
731 0 : SdrObject::Free(pPickObj2 );
732 : }
733 0 : bChanged = sal_True;
734 0 : mnAction = DND_ACTION_COPY;
735 : }
736 0 : else if( ( mnAction & DND_ACTION_LINK ) && pPickObj && pObj && !pPickObj->ISA( SdrGrafObj ) && !pPickObj->ISA( SdrOle2Obj ) )
737 : {
738 0 : SfxItemSet aSet( mrDoc.GetPool() );
739 :
740 : // set new attributes to object
741 0 : const bool bUndo = IsUndoEnabled();
742 0 : if( bUndo )
743 : {
744 0 : BegUndo( SD_RESSTR(STR_UNDO_DRAGDROP) );
745 0 : AddUndo( mrDoc.GetSdrUndoFactory().CreateUndoAttrObject( *pPickObj ) );
746 : }
747 :
748 0 : aSet.Put( pObj->GetMergedItemSet() );
749 :
750 : /* Do not take over corner radius. There are
751 : gradients (rectangles) in the gallery with corner
752 : radius of 0. We should not use that on the
753 : object. */
754 0 : aSet.ClearItem( SDRATTR_ECKENRADIUS );
755 :
756 0 : const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
757 :
758 0 : if(pSdrGrafObj)
759 : {
760 : // If we have a graphic as source object, use it's graphic
761 : // content as fill style
762 0 : aSet.Put(XFillStyleItem(XFILL_BITMAP));
763 0 : aSet.Put(XFillBitmapItem(&mrDoc.GetPool(), pSdrGrafObj->GetGraphic()));
764 : }
765 :
766 0 : pPickObj->SetMergedItemSetAndBroadcast( aSet );
767 :
768 0 : if( pPickObj->ISA( E3dObject ) && pObj->ISA( E3dObject ) )
769 : {
770 : // handle 3D attribute in addition
771 0 : SfxItemSet aNewSet( mrDoc.GetPool(), SID_ATTR_3D_START, SID_ATTR_3D_END, 0 );
772 0 : SfxItemSet aOldSet( mrDoc.GetPool(), SID_ATTR_3D_START, SID_ATTR_3D_END, 0 );
773 :
774 0 : aOldSet.Put(pPickObj->GetMergedItemSet());
775 0 : aNewSet.Put( pObj->GetMergedItemSet() );
776 :
777 0 : if( bUndo )
778 0 : AddUndo( new E3dAttributesUndoAction( mrDoc, (E3dObject*) pPickObj, aNewSet, aOldSet ) );
779 0 : pPickObj->SetMergedItemSetAndBroadcast( aNewSet );
780 : }
781 :
782 0 : if( bUndo )
783 0 : EndUndo();
784 0 : bChanged = sal_True;
785 : }
786 : }
787 : }
788 :
789 0 : if( !bChanged )
790 : {
791 0 : SdrPage* pWorkPage = pModel->GetSdPage( 0, PK_STANDARD );
792 :
793 0 : pWorkPage->SetRectsDirty();
794 :
795 0 : if( pOwnData )
796 : {
797 : // #i120393# Clipboard data uses full object geometry range
798 0 : const Size aSize( pWorkPage->GetAllObjBoundRect().GetSize() );
799 :
800 0 : maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
801 0 : maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
802 : }
803 :
804 0 : bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
805 : }
806 :
807 0 : xShell->DoClose();
808 0 : }
809 0 : }
810 : }
811 :
812 0 : if(!bReturn && CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE))
813 : {
814 0 : OUString aOUString;
815 :
816 0 : if( aDataHelper.GetString( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE, aOUString ) )
817 : {
818 0 : SdrObject* pObj = CreateFieldControl( aOUString );
819 :
820 0 : if( pObj )
821 : {
822 0 : Rectangle aRect( pObj->GetLogicRect() );
823 0 : Size aSize( aRect.GetSize() );
824 :
825 0 : maDropPos.X() -= ( aSize.Width() >> 1 );
826 0 : maDropPos.Y() -= ( aSize.Height() >> 1 );
827 :
828 0 : aRect.SetPos( maDropPos );
829 0 : pObj->SetLogicRect( aRect );
830 0 : InsertObjectAtView( pObj, *GetSdrPageView(), SDRINSERT_SETDEFLAYER );
831 0 : bReturn = true;
832 : }
833 0 : }
834 : }
835 :
836 0 : if(!bReturn &&
837 0 : !bLink &&
838 0 : (CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_EMBED_SOURCE) || CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_EMBEDDED_OBJ)) &&
839 0 : aDataHelper.HasFormat(SOT_FORMATSTR_ID_OBJECTDESCRIPTOR))
840 : {
841 : //TODO/LATER: is it possible that this format is binary?! (from old versions of SO)
842 0 : uno::Reference < io::XInputStream > xStm;
843 0 : TransferableObjectDescriptor aObjDesc;
844 :
845 0 : if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) &&
846 0 : ( aDataHelper.GetInputStream( nFormat ? nFormat : SOT_FORMATSTR_ID_EMBED_SOURCE, xStm ) ||
847 0 : aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ, xStm ) ) )
848 : {
849 0 : if( mrDoc.GetDocSh() && ( mrDoc.GetDocSh()->GetClassName() == aObjDesc.maClassName ) )
850 : {
851 0 : uno::Reference < embed::XStorage > xStore( ::comphelper::OStorageHelper::GetStorageFromInputStream( xStm ) );
852 0 : ::sd::DrawDocShellRef xDocShRef( new ::sd::DrawDocShell( SFX_CREATE_MODE_EMBEDDED, sal_True, mrDoc.GetDocumentType() ) );
853 :
854 : // mba: BaseURL doesn't make sense for clipboard functionality
855 0 : SfxMedium *pMedium = new SfxMedium( xStore, OUString() );
856 0 : if( xDocShRef->DoLoad( pMedium ) )
857 : {
858 0 : SdDrawDocument* pModel = (SdDrawDocument*) xDocShRef->GetDoc();
859 0 : SdPage* pWorkPage = (SdPage*) pModel->GetSdPage( 0, PK_STANDARD );
860 :
861 0 : pWorkPage->SetRectsDirty();
862 :
863 0 : if( pOwnData )
864 : {
865 : // #i120393# Clipboard data uses full object geometry range
866 0 : const Size aSize( pWorkPage->GetAllObjBoundRect().GetSize() );
867 :
868 0 : maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
869 0 : maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
870 : }
871 :
872 : // delete pages, that are not of any interest for us
873 0 : for( long i = ( pModel->GetPageCount() - 1 ); i >= 0; i-- )
874 : {
875 0 : SdPage* pP = static_cast< SdPage* >( pModel->GetPage( (sal_uInt16) i ) );
876 :
877 0 : if( pP->GetPageKind() != PK_STANDARD )
878 0 : pModel->DeletePage( (sal_uInt16) i );
879 : }
880 :
881 0 : bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
882 :
883 0 : if( !pPage )
884 0 : pPage = (SdPage*) GetSdrPageView()->GetPage();
885 :
886 0 : OUString aLayout = pPage->GetLayoutName();
887 0 : sal_Int32 nPos = aLayout.indexOf(SD_LT_SEPARATOR);
888 0 : if (nPos != -1)
889 0 : aLayout = aLayout.copy(0, nPos);
890 0 : pPage->SetPresentationLayout( aLayout, sal_False, sal_False );
891 : }
892 :
893 0 : xDocShRef->DoClose();
894 0 : xDocShRef.Clear();
895 :
896 : }
897 : else
898 : {
899 0 : OUString aName;
900 0 : uno::Reference < embed::XEmbeddedObject > xObj = mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
901 0 : if ( xObj.is() )
902 : {
903 0 : svt::EmbeddedObjectRef aObjRef( xObj, aObjDesc.mnViewAspect );
904 :
905 : // try to get the replacement image from the clipboard
906 0 : Graphic aGraphic;
907 0 : sal_uLong nGrFormat = 0;
908 :
909 :
910 : // insert replacement image ( if there is one ) into the object helper
911 0 : if ( nGrFormat )
912 : {
913 0 : datatransfer::DataFlavor aDataFlavor;
914 0 : SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
915 0 : aObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
916 : }
917 :
918 0 : Size aSize;
919 0 : if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
920 : {
921 0 : if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
922 0 : aSize = aObjDesc.maSize;
923 : else
924 : {
925 0 : MapMode aMapMode( MAP_100TH_MM );
926 0 : aSize = aObjRef.GetSize( &aMapMode );
927 : }
928 : }
929 : else
930 : {
931 0 : awt::Size aSz;
932 0 : MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
933 0 : if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
934 : {
935 0 : Size aTmp( OutputDevice::LogicToLogic( aObjDesc.maSize, MAP_100TH_MM, aMapUnit ) );
936 0 : aSz.Width = aTmp.Width();
937 0 : aSz.Height = aTmp.Height();
938 0 : xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
939 : }
940 :
941 : try
942 : {
943 0 : aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
944 : }
945 0 : catch( embed::NoVisualAreaSizeException& )
946 : {
947 : // if the size still was not set the default size will be set later
948 : }
949 :
950 0 : aSize = Size( aSz.Width, aSz.Height );
951 :
952 0 : if( !aSize.Width() || !aSize.Height() )
953 : {
954 0 : aSize.Width() = 14100;
955 0 : aSize.Height() = 10000;
956 0 : aSize = OutputDevice::LogicToLogic( Size(14100, 10000), MAP_100TH_MM, aMapUnit );
957 0 : aSz.Width = aSize.Width();
958 0 : aSz.Height = aSize.Height();
959 0 : xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
960 : }
961 :
962 0 : aSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
963 : }
964 :
965 0 : Size aMaxSize( mrDoc.GetMaxObjSize() );
966 :
967 0 : maDropPos.X() -= std::min( aSize.Width(), aMaxSize.Width() ) >> 1;
968 0 : maDropPos.Y() -= std::min( aSize.Height(), aMaxSize.Height() ) >> 1;
969 :
970 0 : Rectangle aRect( maDropPos, aSize );
971 0 : SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect );
972 0 : SdrPageView* pPV = GetSdrPageView();
973 0 : sal_uLong nOptions = SDRINSERT_SETDEFLAYER;
974 :
975 0 : if (mpViewSh!=NULL)
976 : {
977 : OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
978 : SfxInPlaceClient* pIpClient
979 0 : = mpViewSh->GetViewShell()->GetIPClient();
980 0 : if (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive())
981 0 : nOptions |= SDRINSERT_DONTMARK;
982 : }
983 :
984 0 : InsertObjectAtView( pObj, *pPV, nOptions );
985 :
986 0 : if( pImageMap )
987 0 : pObj->AppendUserData( new SdIMapInfo( *pImageMap ) );
988 :
989 0 : if ( pObj && pObj->IsChart() )
990 : {
991 0 : bool bDisableDataTableDialog = false;
992 0 : svt::EmbeddedObjectRef::TryRunningState( xObj );
993 0 : uno::Reference< beans::XPropertySet > xProps( xObj->getComponent(), uno::UNO_QUERY );
994 0 : if ( xProps.is() &&
995 0 : ( xProps->getPropertyValue( "DisableDataTableDialog" ) >>= bDisableDataTableDialog ) &&
996 : bDisableDataTableDialog )
997 : {
998 0 : xProps->setPropertyValue( "DisableDataTableDialog" , uno::makeAny( sal_False ) );
999 0 : xProps->setPropertyValue( "DisableComplexChartTypes" , uno::makeAny( sal_False ) );
1000 0 : uno::Reference< util::XModifiable > xModifiable( xProps, uno::UNO_QUERY );
1001 0 : if ( xModifiable.is() )
1002 : {
1003 0 : xModifiable->setModified( sal_True );
1004 0 : }
1005 0 : }
1006 : }
1007 :
1008 0 : bReturn = true;
1009 0 : }
1010 : }
1011 0 : }
1012 : }
1013 :
1014 0 : if(!bReturn &&
1015 0 : !bLink &&
1016 0 : (CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE) || CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_EMBED_SOURCE_OLE)) &&
1017 0 : aDataHelper.HasFormat(SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE))
1018 : {
1019 : // online insert ole if format is forced or no gdi metafile is available
1020 0 : if( (nFormat != 0) || !aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1021 : {
1022 0 : uno::Reference < io::XInputStream > xStm;
1023 0 : TransferableObjectDescriptor aObjDesc;
1024 :
1025 0 : if ( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aObjDesc ) )
1026 : {
1027 0 : uno::Reference < embed::XEmbeddedObject > xObj;
1028 0 : OUString aName;
1029 :
1030 0 : if ( aDataHelper.GetInputStream( nFormat ? nFormat : SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStm ) ||
1031 0 : aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStm ) )
1032 : {
1033 0 : xObj = mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
1034 : }
1035 : else
1036 : {
1037 : try
1038 : {
1039 0 : uno::Reference< embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1040 : uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator =
1041 0 : embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() );
1042 :
1043 0 : embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
1044 : xTmpStor,
1045 : "DummyName" ,
1046 0 : uno::Sequence< beans::PropertyValue >() );
1047 :
1048 : // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
1049 : // for example whether the object should be an iconified one
1050 0 : xObj = aInfo.Object;
1051 0 : if ( xObj.is() )
1052 0 : mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
1053 : }
1054 0 : catch( uno::Exception& )
1055 : {}
1056 : }
1057 :
1058 0 : if ( xObj.is() )
1059 : {
1060 0 : svt::EmbeddedObjectRef aObjRef( xObj, aObjDesc.mnViewAspect );
1061 :
1062 : // try to get the replacement image from the clipboard
1063 0 : Graphic aGraphic;
1064 0 : sal_uLong nGrFormat = 0;
1065 :
1066 : // (wg. Selection Manager bei Trustet Solaris)
1067 : #ifndef SOLARIS
1068 0 : if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
1069 0 : nGrFormat = SOT_FORMATSTR_ID_SVXB;
1070 0 : else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
1071 0 : nGrFormat = SOT_FORMAT_GDIMETAFILE;
1072 0 : else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) )
1073 0 : nGrFormat = SOT_FORMAT_BITMAP;
1074 : #endif
1075 :
1076 : // insert replacement image ( if there is one ) into the object helper
1077 0 : if ( nGrFormat )
1078 : {
1079 0 : datatransfer::DataFlavor aDataFlavor;
1080 0 : SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
1081 0 : aObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
1082 : }
1083 :
1084 0 : Size aSize;
1085 0 : if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
1086 : {
1087 0 : if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1088 0 : aSize = aObjDesc.maSize;
1089 : else
1090 : {
1091 0 : MapMode aMapMode( MAP_100TH_MM );
1092 0 : aSize = aObjRef.GetSize( &aMapMode );
1093 : }
1094 : }
1095 : else
1096 : {
1097 0 : MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
1098 :
1099 0 : awt::Size aSz;
1100 : try{
1101 0 : aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
1102 : }
1103 0 : catch( embed::NoVisualAreaSizeException& )
1104 : {
1105 : // the default size will be set later
1106 : }
1107 :
1108 0 : if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1109 : {
1110 0 : Size aTmp( OutputDevice::LogicToLogic( aObjDesc.maSize, MAP_100TH_MM, aMapUnit ) );
1111 0 : if ( aSz.Width != aTmp.Width() || aSz.Height != aTmp.Height() )
1112 : {
1113 0 : aSz.Width = aTmp.Width();
1114 0 : aSz.Height = aTmp.Height();
1115 0 : xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1116 : }
1117 : }
1118 :
1119 0 : aSize = Size( aSz.Width, aSz.Height );
1120 :
1121 0 : if( !aSize.Width() || !aSize.Height() )
1122 : {
1123 0 : aSize = OutputDevice::LogicToLogic( Size(14100, 10000), MAP_100TH_MM, aMapUnit );
1124 0 : aSz.Width = aSize.Width();
1125 0 : aSz.Height = aSize.Height();
1126 0 : xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1127 : }
1128 :
1129 0 : aSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
1130 : }
1131 :
1132 0 : Size aMaxSize( mrDoc.GetMaxObjSize() );
1133 :
1134 0 : maDropPos.X() -= std::min( aSize.Width(), aMaxSize.Width() ) >> 1;
1135 0 : maDropPos.Y() -= std::min( aSize.Height(), aMaxSize.Height() ) >> 1;
1136 :
1137 0 : Rectangle aRect( maDropPos, aSize );
1138 0 : SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect );
1139 0 : SdrPageView* pPV = GetSdrPageView();
1140 0 : sal_uLong nOptions = SDRINSERT_SETDEFLAYER;
1141 :
1142 0 : if (mpViewSh!=NULL)
1143 : {
1144 : OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
1145 : SfxInPlaceClient* pIpClient
1146 0 : = mpViewSh->GetViewShell()->GetIPClient();
1147 0 : if (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive())
1148 0 : nOptions |= SDRINSERT_DONTMARK;
1149 : }
1150 :
1151 0 : InsertObjectAtView( pObj, *pPV, nOptions );
1152 :
1153 0 : if( pImageMap )
1154 0 : pObj->AppendUserData( new SdIMapInfo( *pImageMap ) );
1155 :
1156 : // let the object stay in loaded state after insertion
1157 0 : pObj->Unload();
1158 0 : bReturn = true;
1159 0 : }
1160 0 : }
1161 : }
1162 :
1163 0 : if( !bReturn && aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1164 : {
1165 : // if no object was inserted, insert a picture
1166 0 : InsertMetaFile( aDataHelper, rPos, pImageMap, true );
1167 0 : bReturn = true;
1168 : }
1169 : }
1170 :
1171 0 : if(!bReturn && (!bLink || pPickObj) && CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_SVXB))
1172 : {
1173 0 : SotStorageStreamRef xStm;
1174 :
1175 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ) )
1176 : {
1177 0 : Point aInsertPos( rPos );
1178 0 : Graphic aGraphic;
1179 :
1180 0 : ReadGraphic( *xStm, aGraphic );
1181 :
1182 0 : if( pOwnData && pOwnData->GetWorkDocument() )
1183 : {
1184 0 : const SdDrawDocument* pWorkModel = pOwnData->GetWorkDocument();
1185 0 : SdrPage* pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1186 : pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1187 0 : pWorkModel->GetPage( 0 ) );
1188 :
1189 0 : pWorkPage->SetRectsDirty();
1190 :
1191 : // #i120393# Clipboard data uses full object geometry range
1192 0 : const Size aSize( pWorkPage->GetAllObjBoundRect().GetSize() );
1193 :
1194 0 : aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1195 0 : aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1196 : }
1197 :
1198 : // restrict movement to WorkArea
1199 : Size aImageMapSize = OutputDevice::LogicToLogic(aGraphic.GetPrefSize(),
1200 0 : aGraphic.GetPrefMapMode(), MapMode(MAP_100TH_MM));
1201 :
1202 0 : ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea());
1203 :
1204 0 : InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap );
1205 0 : bReturn = true;
1206 0 : }
1207 : }
1208 :
1209 0 : if(!bReturn && (!bLink || pPickObj) && CHECK_FORMAT_TRANS(FORMAT_GDIMETAFILE))
1210 : {
1211 0 : Point aInsertPos( rPos );
1212 :
1213 0 : if( pOwnData && pOwnData->GetWorkDocument() )
1214 :
1215 : {
1216 0 : const SdDrawDocument* pWorkModel = pOwnData->GetWorkDocument();
1217 0 : SdrPage* pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1218 : pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1219 0 : pWorkModel->GetPage( 0 ) );
1220 :
1221 0 : pWorkPage->SetRectsDirty();
1222 :
1223 : // #i120393# Clipboard data uses full object geometry range
1224 0 : const Size aSize( pWorkPage->GetAllObjBoundRect().GetSize() );
1225 :
1226 0 : aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1227 0 : aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1228 : }
1229 :
1230 0 : bReturn = InsertMetaFile( aDataHelper, aInsertPos, pImageMap, nFormat == 0 ? true : false ) ? sal_True : sal_False;
1231 : }
1232 :
1233 0 : if(!bReturn && (!bLink || pPickObj) && CHECK_FORMAT_TRANS(FORMAT_BITMAP))
1234 : {
1235 0 : BitmapEx aBmpEx;
1236 :
1237 : // get basic Bitmap data
1238 0 : aDataHelper.GetBitmapEx(FORMAT_BITMAP, aBmpEx);
1239 :
1240 0 : if(aBmpEx.IsEmpty())
1241 : {
1242 : // if this did not work, try to get graphic formats and convert these to bitmap
1243 0 : Graphic aGraphic;
1244 :
1245 0 : if(aDataHelper.GetGraphic(FORMAT_GDIMETAFILE, aGraphic))
1246 : {
1247 0 : aBmpEx = aGraphic.GetBitmapEx();
1248 : }
1249 0 : else if(aDataHelper.GetGraphic(SOT_FORMATSTR_ID_SVXB, aGraphic))
1250 : {
1251 0 : aBmpEx = aGraphic.GetBitmapEx();
1252 : }
1253 0 : else if(aDataHelper.GetGraphic(FORMAT_BITMAP, aGraphic))
1254 : {
1255 0 : aBmpEx = aGraphic.GetBitmapEx();
1256 0 : }
1257 : }
1258 :
1259 0 : if(!aBmpEx.IsEmpty())
1260 : {
1261 0 : Point aInsertPos( rPos );
1262 :
1263 0 : if( pOwnData && pOwnData->GetWorkDocument() )
1264 : {
1265 0 : const SdDrawDocument* pWorkModel = pOwnData->GetWorkDocument();
1266 0 : SdrPage* pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1267 : pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1268 0 : pWorkModel->GetPage( 0 ) );
1269 :
1270 0 : pWorkPage->SetRectsDirty();
1271 :
1272 : // #i120393# Clipboard data uses full object geometry range
1273 0 : const Size aSize( pWorkPage->GetAllObjBoundRect().GetSize() );
1274 :
1275 0 : aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1276 0 : aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1277 : }
1278 :
1279 : // restrict movement to WorkArea
1280 0 : Size aImageMapSize(aBmpEx.GetPrefSize());
1281 0 : ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea());
1282 :
1283 0 : InsertGraphic( aBmpEx, mnAction, aInsertPos, NULL, pImageMap );
1284 0 : bReturn = true;
1285 0 : }
1286 : }
1287 :
1288 0 : if(!bReturn && pPickObj && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_XFA ) )
1289 : {
1290 0 : SotStorageStreamRef xStm;
1291 :
1292 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_XFA, xStm ) )
1293 : {
1294 0 : XFillExchangeData aFillData( XFillAttrSetItem( &mrDoc.GetPool() ) );
1295 :
1296 0 : ReadXFillExchangeData( *xStm, aFillData );
1297 :
1298 0 : if( IsUndoEnabled() )
1299 : {
1300 0 : BegUndo( SD_RESSTR(STR_UNDO_DRAGDROP) );
1301 0 : AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoAttrObject( *pPickObj ) );
1302 0 : EndUndo();
1303 : }
1304 :
1305 0 : XFillAttrSetItem* pSetItem = aFillData.GetXFillAttrSetItem();
1306 0 : SfxItemSet rSet = pSetItem->GetItemSet();
1307 0 : XFillStyle eFill= ( (XFillStyleItem&) rSet.Get( XATTR_FILLSTYLE ) ).GetValue();
1308 :
1309 0 : if( eFill == XFILL_SOLID || eFill == XFILL_NONE )
1310 : {
1311 0 : const XFillColorItem& rColItem = (XFillColorItem&) rSet.Get( XATTR_FILLCOLOR );
1312 0 : Color aColor( rColItem.GetColorValue() );
1313 0 : OUString aName( rColItem.GetName() );
1314 0 : SfxItemSet aSet( mrDoc.GetPool() );
1315 0 : sal_Bool bClosed = pPickObj->IsClosedObj();
1316 0 : ::sd::Window* pWin = mpViewSh->GetActiveWindow();
1317 : sal_uInt16 nHitLog = (sal_uInt16) pWin->PixelToLogic(
1318 0 : Size(FuPoor::HITPIX, 0 ) ).Width();
1319 0 : const long n2HitLog = nHitLog << 1;
1320 0 : Point aHitPosR( rPos );
1321 0 : Point aHitPosL( rPos );
1322 0 : Point aHitPosT( rPos );
1323 0 : Point aHitPosB( rPos );
1324 0 : const SetOfByte* pVisiLayer = &GetSdrPageView()->GetVisibleLayers();
1325 :
1326 0 : aHitPosR.X() += n2HitLog;
1327 0 : aHitPosL.X() -= n2HitLog;
1328 0 : aHitPosT.Y() += n2HitLog;
1329 0 : aHitPosB.Y() -= n2HitLog;
1330 :
1331 0 : if( bClosed &&
1332 0 : SdrObjectPrimitiveHit(*pPickObj, aHitPosR, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1333 0 : SdrObjectPrimitiveHit(*pPickObj, aHitPosL, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1334 0 : SdrObjectPrimitiveHit(*pPickObj, aHitPosT, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1335 0 : SdrObjectPrimitiveHit(*pPickObj, aHitPosB, nHitLog, *GetSdrPageView(), pVisiLayer, false) )
1336 : {
1337 : // area fill
1338 0 : if(eFill == XFILL_SOLID )
1339 0 : aSet.Put(XFillColorItem(aName, aColor));
1340 :
1341 0 : aSet.Put( XFillStyleItem( eFill ) );
1342 : }
1343 : else
1344 0 : aSet.Put( XLineColorItem( aName, aColor ) );
1345 :
1346 : // add text color
1347 0 : pPickObj->SetMergedItemSetAndBroadcast( aSet );
1348 0 : }
1349 0 : }
1350 : }
1351 :
1352 0 : if(!bReturn && !bLink && CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_HTML))
1353 : {
1354 0 : SotStorageStreamRef xStm;
1355 :
1356 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_HTML, xStm ) )
1357 : {
1358 0 : xStm->Seek( 0 );
1359 : // mba: clipboard always must contain absolute URLs (could be from alien source)
1360 0 : bReturn = SdrView::Paste( *xStm, OUString(), EE_FORMAT_HTML, maDropPos, pPage, nPasteOptions );
1361 0 : }
1362 : }
1363 :
1364 0 : if(!bReturn && !bLink && CHECK_FORMAT_TRANS(SOT_FORMATSTR_ID_EDITENGINE))
1365 : {
1366 0 : SotStorageStreamRef xStm;
1367 :
1368 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_EDITENGINE, xStm ) )
1369 : {
1370 0 : OutlinerView* pOLV = GetTextEditOutlinerView();
1371 :
1372 0 : xStm->Seek( 0 );
1373 :
1374 0 : if( pOLV )
1375 : {
1376 0 : Rectangle aRect( pOLV->GetOutputArea() );
1377 0 : Point aPos( pOLV->GetWindow()->PixelToLogic( maDropPos ) );
1378 :
1379 0 : if( aRect.IsInside( aPos ) || ( !bDrag && IsTextEdit() ) )
1380 : {
1381 : // mba: clipboard always must contain absolute URLs (could be from alien source)
1382 0 : pOLV->Read( *xStm, OUString(), EE_FORMAT_BIN, false, mpDocSh->GetHeaderAttributes() );
1383 0 : bReturn = true;
1384 : }
1385 : }
1386 :
1387 0 : if( !bReturn )
1388 : // mba: clipboard always must contain absolute URLs (could be from alien source)
1389 0 : bReturn = SdrView::Paste( *xStm, OUString(), EE_FORMAT_BIN, maDropPos, pPage, nPasteOptions );
1390 0 : }
1391 : }
1392 :
1393 0 : if(!bReturn && !bLink && CHECK_FORMAT_TRANS(FORMAT_RTF))
1394 : {
1395 0 : SotStorageStreamRef xStm;
1396 :
1397 0 : if( aDataHelper.GetSotStorageStream( FORMAT_RTF, xStm ) )
1398 : {
1399 0 : xStm->Seek( 0 );
1400 :
1401 0 : if( bTable )
1402 : {
1403 0 : bReturn = PasteRTFTable( xStm, pPage, nPasteOptions );
1404 : }
1405 : else
1406 : {
1407 0 : OutlinerView* pOLV = GetTextEditOutlinerView();
1408 :
1409 0 : if( pOLV )
1410 : {
1411 0 : Rectangle aRect( pOLV->GetOutputArea() );
1412 0 : Point aPos( pOLV->GetWindow()->PixelToLogic( maDropPos ) );
1413 :
1414 0 : if( aRect.IsInside( aPos ) || ( !bDrag && IsTextEdit() ) )
1415 : {
1416 : // mba: clipboard always must contain absolute URLs (could be from alien source)
1417 0 : pOLV->Read( *xStm, OUString(), EE_FORMAT_RTF, false, mpDocSh->GetHeaderAttributes() );
1418 0 : bReturn = true;
1419 : }
1420 : }
1421 :
1422 0 : if( !bReturn )
1423 : // mba: clipboard always must contain absolute URLs (could be from alien source)
1424 0 : bReturn = SdrView::Paste( *xStm, OUString(), EE_FORMAT_RTF, maDropPos, pPage, nPasteOptions );
1425 : }
1426 0 : }
1427 : }
1428 :
1429 0 : if(!bReturn && CHECK_FORMAT_TRANS(FORMAT_FILE_LIST))
1430 : {
1431 0 : FileList aDropFileList;
1432 :
1433 0 : if( aDataHelper.GetFileList( FORMAT_FILE_LIST, aDropFileList ) )
1434 : {
1435 0 : maDropFileVector.clear();
1436 :
1437 0 : for( sal_uLong i = 0, nCount = aDropFileList.Count(); i < nCount; i++ )
1438 0 : maDropFileVector.push_back( aDropFileList.GetFile( i ) );
1439 :
1440 0 : maDropInsertFileTimer.Start();
1441 : }
1442 :
1443 0 : bReturn = true;
1444 : }
1445 :
1446 0 : if(!bReturn && CHECK_FORMAT_TRANS(FORMAT_FILE))
1447 : {
1448 0 : OUString aDropFile;
1449 :
1450 0 : if( aDataHelper.GetString( FORMAT_FILE, aDropFile ) )
1451 : {
1452 0 : maDropFileVector.clear();
1453 0 : maDropFileVector.push_back( aDropFile );
1454 0 : maDropInsertFileTimer.Start();
1455 : }
1456 :
1457 0 : bReturn = true;
1458 : }
1459 :
1460 0 : if(!bReturn && !bLink && CHECK_FORMAT_TRANS(FORMAT_STRING))
1461 : {
1462 0 : if( ( FORMAT_STRING == nFormat ) ||
1463 0 : ( !aDataHelper.HasFormat( SOT_FORMATSTR_ID_SOLK ) &&
1464 0 : !aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
1465 0 : !aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILENAME ) ) )
1466 : {
1467 0 : OUString aOUString;
1468 :
1469 0 : if( aDataHelper.GetString( FORMAT_STRING, aOUString ) )
1470 : {
1471 0 : OutlinerView* pOLV = GetTextEditOutlinerView();
1472 :
1473 0 : if( pOLV )
1474 : {
1475 0 : pOLV->InsertText( aOUString );
1476 0 : bReturn = true;
1477 : }
1478 :
1479 0 : if( !bReturn )
1480 0 : bReturn = SdrView::Paste( aOUString, maDropPos, pPage, nPasteOptions );
1481 0 : }
1482 : }
1483 : }
1484 :
1485 0 : MarkListHasChanged();
1486 0 : mbIsDropAllowed = true;
1487 0 : rDnDAction = mnAction;
1488 0 : delete pImageMap;
1489 :
1490 0 : return bReturn;
1491 : }
1492 :
1493 : extern void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel );
1494 :
1495 0 : bool View::PasteRTFTable( SotStorageStreamRef xStm, SdrPage* pPage, sal_uLong nPasteOptions )
1496 : {
1497 0 : SdDrawDocument* pModel = new SdDrawDocument( DOCUMENT_TYPE_IMPRESS, mpDocSh );
1498 0 : pModel->NewOrLoadCompleted(NEW_DOC);
1499 0 : pModel->GetItemPool().SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
1500 0 : pModel->InsertPage(pModel->AllocPage(false));
1501 :
1502 0 : Reference< XComponent > xComponent( new SdXImpressDocument( pModel, true ) );
1503 0 : pModel->setUnoModel( Reference< XInterface >::query( xComponent ) );
1504 :
1505 0 : CreateTableFromRTF( *xStm, pModel );
1506 0 : bool bRet = Paste( *pModel, maDropPos, pPage, nPasteOptions );
1507 :
1508 0 : xComponent->dispose();
1509 0 : xComponent.clear();
1510 :
1511 0 : delete pModel;
1512 :
1513 0 : return bRet;
1514 : }
1515 :
1516 0 : } // end of namespace sd
1517 :
1518 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|