merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / view / sdview3.cxx
blob84dbf3d0fc2347685351221773b1d147648a3b1c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdview3.cxx,v $
10 * $Revision: 1.76 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "View.hxx"
35 #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
36 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <sot/filelist.hxx>
39 #include <svtools/pathoptions.hxx>
40 #ifndef _EDITDATA_HXX
41 #include <svx/editdata.hxx>
42 #endif
43 #include <svtools/urlbmk.hxx>
44 #include <svx/xexch.hxx>
45 #include <svx/xflclit.hxx>
46 #include <svx/xlnclit.hxx>
47 #include <svx/svdpagv.hxx>
48 #include <svx/eeitem.hxx>
49 #include <svx/colritem.hxx>
50 #include <sfx2/docfile.hxx>
51 #include <svx/svditer.hxx>
52 #include <svx/svdogrp.hxx>
53 #include <svx/svdoole2.hxx>
54 #include <svx/svdograf.hxx>
55 #include <svx/svdetc.hxx>
56 #include <svx/svdundo.hxx>
57 #include <sfx2/app.hxx>
58 #include <svtools/itempool.hxx>
59 #include <sot/clsids.hxx>
60 #ifndef _FM_FMMODEL_HXX
61 #include <svx/fmmodel.hxx>
62 #endif
63 #include <sot/formats.hxx>
64 #include <svx/outliner.hxx>
65 #ifndef _EDITENG_HXX //autogen
66 #include <svx/editeng.hxx>
67 #endif
68 #include <svx/obj3d.hxx>
69 #include <svx/e3dundo.hxx>
70 #include <svx/dbexch.hrc>
71 #include <svx/unomodel.hxx>
72 #include <unotools/streamwrap.hxx>
73 #include <vcl/metaact.hxx>
75 #include <toolkit/helper/vclunohelper.hxx>
77 #include "DrawDocShell.hxx"
78 #include "fupoor.hxx"
79 #include "Window.hxx"
80 #include "sdxfer.hxx"
81 #include "sdpage.hxx"
82 #include "DrawViewShell.hxx"
83 #include "drawdoc.hxx"
84 #include "sdresid.hxx"
85 #include "strings.hrc"
86 #include "imapinfo.hxx"
87 #include "SlideSorterViewShell.hxx"
88 #include "strmname.h"
89 #include "unomodel.hxx"
90 #include "ViewClipboard.hxx"
92 #include <sfx2/ipclient.hxx>
93 #include <comphelper/storagehelper.hxx>
94 #include <comphelper/processfactory.hxx>
95 #include <tools/stream.hxx>
96 #include <vcl/cvtgrf.hxx>
97 #include <svx/sdrhittesthelper.hxx>
99 // --------------
100 // - Namespaces -
101 // --------------
103 using namespace ::com::sun::star;
104 using namespace ::com::sun::star::lang;
105 using namespace ::com::sun::star::uno;
106 using namespace ::com::sun::star::io;
107 using namespace ::com::sun::star::datatransfer;
108 using namespace ::com::sun::star::datatransfer::clipboard;
110 namespace sd {
112 #define CHECK_FORMAT_TRANS( _def_Type ) ( ( nFormat == (_def_Type) || !nFormat ) && aDataHelper.HasFormat( _def_Type ) )
114 /*************************************************************************
116 |* Paste
118 \************************************************************************/
120 // #83525#
121 struct ImpRememberOrigAndClone
123 SdrObject* pOrig;
124 SdrObject* pClone;
127 SdrObject* ImpGetClone(Container& aConnectorContainer, SdrObject* pConnObj)
129 for(sal_uInt32 a(0); a < aConnectorContainer.Count(); a++)
131 if(pConnObj == ((ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a))->pOrig)
132 return ((ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a))->pClone;
134 return 0L;
137 // #90129# restrict movement to WorkArea
138 void ImpCheckInsertPos(Point& rPos, const Size& rSize, const Rectangle& rWorkArea)
140 if(!rWorkArea.IsEmpty())
142 Rectangle aMarkRect(Point(rPos.X() - (rSize.Width() / 2), rPos.Y() - (rSize.Height() / 2)), rSize);
144 if(!aMarkRect.IsInside(rWorkArea))
146 if(aMarkRect.Left() < rWorkArea.Left())
148 rPos.X() += rWorkArea.Left() - aMarkRect.Left();
151 if(aMarkRect.Right() > rWorkArea.Right())
153 rPos.X() -= aMarkRect.Right() - rWorkArea.Right();
156 if(aMarkRect.Top() < rWorkArea.Top())
158 rPos.Y() += rWorkArea.Top() - aMarkRect.Top();
161 if(aMarkRect.Bottom() > rWorkArea.Bottom())
163 rPos.Y() -= aMarkRect.Bottom() - rWorkArea.Bottom();
169 bool View::InsertMetaFile( TransferableDataHelper& rDataHelper, const Point& rPos, ImageMap* pImageMap, bool bOptimize )
171 GDIMetaFile aMtf;
173 if( !rDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
174 return false;
177 SvFileStream aSvOutputStream( String( RTL_CONSTASCII_USTRINGPARAM( "/tmp/test.png" ) ), STREAM_WRITE | STREAM_TRUNC );
178 Graphic aMtfGraphic( aMtf );
179 Size aPreviewSizePixel( OutputDevice::LogicToLogic( aMtf.GetPrefSize(), aMtf.GetPrefMapMode(), MAP_PIXEL ) );
181 if( aPreviewSizePixel.Width() && aPreviewSizePixel.Height() )
183 const double fWH = static_cast< double >( aPreviewSizePixel.Width() ) / static_cast< double >( aPreviewSizePixel.Height() );
185 if( fWH <= 1.0 )
186 aPreviewSizePixel.Width() = static_cast< long >( 128.0 * fWH ), aPreviewSizePixel.Height() = 128;
187 else
188 aPreviewSizePixel.Width() = 128, aPreviewSizePixel.Height() = static_cast< long >( 128.0 / fWH );
190 if( GraphicConverter::Export( aSvOutputStream, aMtfGraphic.GetBitmapEx( &aPreviewSizePixel ), CVT_PNG ) )
192 // handle errror case here
194 else
196 // Success
200 bool bVector = false;
201 Graphic aGraphic;
203 // check if metafile only contains a pixel image, if so insert a bitmap instead
204 if( bOptimize )
206 MetaAction* pAction = aMtf.FirstAction();
207 while( pAction && !bVector )
209 switch( pAction->GetType() )
211 case META_POINT_ACTION:
212 case META_LINE_ACTION:
213 case META_RECT_ACTION:
214 case META_ROUNDRECT_ACTION:
215 case META_ELLIPSE_ACTION:
216 case META_ARC_ACTION:
217 case META_PIE_ACTION:
218 case META_CHORD_ACTION:
219 case META_POLYLINE_ACTION:
220 case META_POLYGON_ACTION:
221 case META_POLYPOLYGON_ACTION:
222 case META_TEXT_ACTION:
223 case META_TEXTARRAY_ACTION:
224 case META_STRETCHTEXT_ACTION:
225 case META_TEXTRECT_ACTION:
226 case META_GRADIENT_ACTION:
227 case META_HATCH_ACTION:
228 case META_WALLPAPER_ACTION:
229 case META_EPS_ACTION:
230 case META_TEXTLINE_ACTION:
231 case META_FLOATTRANSPARENT_ACTION:
232 case META_GRADIENTEX_ACTION:
233 case META_BMPSCALEPART_ACTION:
234 case META_BMPEXSCALEPART_ACTION:
235 bVector = true;
236 break;
237 case META_BMP_ACTION:
238 case META_BMPSCALE_ACTION:
239 case META_BMPEX_ACTION:
240 case META_BMPEXSCALE_ACTION:
241 if( aGraphic.GetType() != GRAPHIC_NONE )
243 bVector = true;
245 else switch( pAction->GetType() )
247 case META_BMP_ACTION:
249 MetaBmpAction* pBmpAction = dynamic_cast< MetaBmpAction* >( pAction );
250 if( pBmpAction )
251 aGraphic = Graphic( pBmpAction->GetBitmap() );
253 break;
254 case META_BMPSCALE_ACTION:
256 MetaBmpScaleAction* pBmpScaleAction = dynamic_cast< MetaBmpScaleAction* >( pAction );
257 if( pBmpScaleAction )
258 aGraphic = Graphic( pBmpScaleAction->GetBitmap() );
260 break;
261 case META_BMPEX_ACTION:
263 MetaBmpExAction* pBmpExAction = dynamic_cast< MetaBmpExAction* >( pAction );
264 if( pBmpExAction )
265 aGraphic = Graphic( pBmpExAction->GetBitmapEx() );
267 break;
268 case META_BMPEXSCALE_ACTION:
270 MetaBmpExScaleAction* pBmpExScaleAction = dynamic_cast< MetaBmpExScaleAction* >( pAction );
271 if( pBmpExScaleAction )
272 aGraphic = Graphic( pBmpExScaleAction->GetBitmapEx() );
274 break;
278 pAction = aMtf.NextAction();
282 // it is not a vector metafile but it also has no graphic?
283 if( !bVector && (aGraphic.GetType() == GRAPHIC_NONE) )
284 bVector = true;
286 // #90129# restrict movement to WorkArea
287 Point aInsertPos( rPos );
288 Size aImageSize;
289 aImageSize = bVector ? aMtf.GetPrefSize() : aGraphic.GetSizePixel();
290 ImpCheckInsertPos(aInsertPos, aImageSize, GetWorkArea());
292 if( bVector )
293 aGraphic = Graphic( aMtf );
295 aGraphic.SetPrefMapMode( aMtf.GetPrefMapMode() );
296 aGraphic.SetPrefSize( aMtf.GetPrefSize() );
297 InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap );
299 return true;
302 BOOL View::InsertData( const TransferableDataHelper& rDataHelper,
303 const Point& rPos, sal_Int8& rDnDAction, BOOL bDrag,
304 ULONG nFormat, USHORT nPage, USHORT nLayer )
306 maDropPos = rPos;
307 mnAction = rDnDAction;
308 mbIsDropAllowed = FALSE;
310 TransferableDataHelper aDataHelper( rDataHelper );
311 SdrObject* pPickObj = NULL;
312 SdPage* pPage = NULL;
313 ImageMap* pImageMap = NULL;
314 BOOL bReturn = FALSE;
315 BOOL bLink = ( ( mnAction & DND_ACTION_LINK ) != 0 );
316 BOOL bCopy = ( ( ( mnAction & DND_ACTION_COPY ) != 0 ) || bLink );
317 ULONG nPasteOptions = SDRINSERT_SETDEFLAYER;
319 if (mpViewSh != NULL)
321 OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
322 SfxInPlaceClient* pIpClient = mpViewSh->GetViewShell()->GetIPClient();
323 if( mpViewSh->ISA(::sd::slidesorter::SlideSorterViewShell)
324 || (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive()))
325 nPasteOptions |= SDRINSERT_DONTMARK;
328 if( bDrag )
330 SdrPageView* pPV = NULL;
331 PickObj( rPos, getHitTolLog(), pPickObj, pPV );
334 if( nPage != SDRPAGE_NOTFOUND )
335 pPage = (SdPage*) mpDoc->GetPage( nPage );
337 SdTransferable* pOwnData = NULL;
338 SdTransferable* pImplementation = SdTransferable::getImplementation( aDataHelper.GetTransferable() );
340 // try to get own transfer data
341 if( pImplementation )
343 if( SD_MOD()->pTransferClip == (SdTransferable*) pImplementation )
344 pOwnData = SD_MOD()->pTransferClip;
345 else if( SD_MOD()->pTransferDrag == (SdTransferable*) pImplementation )
346 pOwnData = SD_MOD()->pTransferDrag;
347 else if( SD_MOD()->pTransferSelection == (SdTransferable*) pImplementation )
348 pOwnData = SD_MOD()->pTransferSelection;
351 // ImageMap?
352 if( !pOwnData && aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
354 SotStorageStreamRef xStm;
356 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVIM, xStm ) )
358 pImageMap = new ImageMap;
359 // mba: clipboard always must contain absolute URLs (could be from alien source)
360 pImageMap->Read( *xStm, String() );
364 bool bTable = false;
365 // check special cases for pasting table formats as RTL
366 if( !bLink && (!nFormat || (nFormat == SOT_FORMAT_RTF)) )
368 // if the objekt supports rtf and there is a table involved, default is to create a table
369 if( aDataHelper.HasFormat( SOT_FORMAT_RTF ) && ! aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
371 SotStorageStreamRef xStm;
373 if( aDataHelper.GetSotStorageStream( FORMAT_RTF, xStm ) )
375 xStm->Seek( 0 );
377 ByteString aLine;
378 while( xStm->ReadLine(aLine) )
380 xub_StrLen x = aLine.Search( "\\trowd" );
381 if( x != STRING_NOTFOUND )
383 bTable = true;
384 nFormat = FORMAT_RTF;
385 break;
392 if( pOwnData && !nFormat )
394 const View* pSourceView = pOwnData->GetView();
397 if( pOwnData->GetDocShell() && pOwnData->IsPageTransferable() && ISA( View ) )
399 mpClipboard->HandlePageDrop (*pOwnData);
401 else if( pSourceView )
403 if( pSourceView == this )
405 // same view
406 if( nLayer != SDRLAYER_NOTFOUND )
408 // drop on layer tab bar
409 SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
410 SdrLayer* pLayer = rLayerAdmin.GetLayerPerID( nLayer );
411 SdrPageView* pPV = GetSdrPageView();
412 String aLayer( pLayer->GetName() );
414 if( !pPV->IsLayerLocked( aLayer ) )
416 pOwnData->SetInternalMove( TRUE );
417 SortMarkedObjects();
419 for( ULONG nM = 0; nM < GetMarkedObjectCount(); nM++ )
421 SdrMark* pM = GetSdrMarkByIndex( nM );
422 SdrObject* pO = pM->GetMarkedSdrObj();
424 if( pO )
426 // #i11702#
427 if( IsUndoEnabled() )
429 BegUndo(String(SdResId(STR_MODIFYLAYER)));
430 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoObjectLayerChange(*pO, pO->GetLayer(), (SdrLayerID)nLayer));
431 EndUndo();
434 pO->SetLayer( (SdrLayerID) nLayer );
438 bReturn = TRUE;
441 else
443 SdrPageView* pPV = GetSdrPageView();
444 BOOL bDropOnTabBar = TRUE;
446 if( !pPage && pPV->GetPage()->GetPageNum() != mnDragSrcPgNum )
448 pPage = (SdPage*) pPV->GetPage();
449 bDropOnTabBar = FALSE;
452 if( pPage )
454 // drop on other page
455 String aActiveLayer( GetActiveLayer() );
457 if( !pPV->IsLayerLocked( aActiveLayer ) )
459 if( !IsPresObjSelected() )
461 SdrMarkList* pMarkList;
463 if( (mnDragSrcPgNum != SDRPAGE_NOTFOUND) && (mnDragSrcPgNum != pPV->GetPage()->GetPageNum()) )
465 pMarkList = mpDragSrcMarkList;
467 else
469 // actual mark list is used
470 pMarkList = new SdrMarkList( GetMarkedObjectList());
473 pMarkList->ForceSort();
475 // #83525# stuff to remember originals and clones
476 Container aConnectorContainer(0);
477 sal_uInt32 a, nConnectorCount(0L);
478 Point aCurPos;
480 // calculate real position of current
481 // source objects, if necessary (#103207)
482 if( pOwnData == SD_MOD()->pTransferSelection )
484 Rectangle aCurBoundRect;
486 if( pMarkList->TakeBoundRect( pPV, aCurBoundRect ) )
487 aCurPos = aCurBoundRect.TopLeft();
488 else
489 aCurPos = pOwnData->GetStartPos();
491 else
492 aCurPos = pOwnData->GetStartPos();
494 const Size aVector( maDropPos.X() - aCurPos.X(), maDropPos.Y() - aCurPos.Y() );
496 for(a = 0; a < pMarkList->GetMarkCount(); a++)
498 SdrMark* pM = pMarkList->GetMark(a);
499 SdrObject* pObj = pM->GetMarkedSdrObj()->Clone();
501 if(pObj)
503 if(!bDropOnTabBar)
505 // #83525# do a NbcMove(...) instead of setting SnapRects here
506 pObj->NbcMove(aVector);
509 pPage->InsertObject(pObj);
511 if( IsUndoEnabled() )
513 BegUndo(String(SdResId(STR_UNDO_DRAGDROP)));
514 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
515 EndUndo();
518 // #83525#
519 ImpRememberOrigAndClone* pRem = new ImpRememberOrigAndClone;
520 pRem->pOrig = pM->GetMarkedSdrObj();
521 pRem->pClone = pObj;
522 aConnectorContainer.Insert(pRem, CONTAINER_APPEND);
524 if(pObj->ISA(SdrEdgeObj))
525 nConnectorCount++;
529 // #83525# try to re-establish connections at clones
530 if(nConnectorCount)
532 for(a = 0; a < aConnectorContainer.Count(); a++)
534 ImpRememberOrigAndClone* pRem = (ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a);
536 if(pRem->pClone->ISA(SdrEdgeObj))
538 SdrEdgeObj* pOrigEdge = (SdrEdgeObj*)pRem->pOrig;
539 SdrEdgeObj* pCloneEdge = (SdrEdgeObj*)pRem->pClone;
541 // test first connection
542 SdrObjConnection& rConn0 = pOrigEdge->GetConnection(FALSE);
543 SdrObject* pConnObj = rConn0.GetObject();
544 if(pConnObj)
546 SdrObject* pConnClone = ImpGetClone(aConnectorContainer, pConnObj);
547 if(pConnClone)
549 // if dest obj was cloned, too, re-establish connection
550 pCloneEdge->ConnectToNode(FALSE, pConnClone);
551 pCloneEdge->GetConnection(FALSE).SetConnectorId(rConn0.GetConnectorId());
553 else
555 // set position of connection point of original connected object
556 const SdrGluePointList* pGlueList = pConnObj->GetGluePointList();
557 if(pGlueList)
559 sal_uInt16 nInd = pGlueList->FindGluePoint(rConn0.GetConnectorId());
561 if(SDRGLUEPOINT_NOTFOUND != nInd)
563 const SdrGluePoint& rGluePoint = (*pGlueList)[nInd];
564 Point aPosition = rGluePoint.GetAbsolutePos(*pConnObj);
565 aPosition.X() += aVector.A();
566 aPosition.Y() += aVector.B();
567 pCloneEdge->SetTailPoint(FALSE, aPosition);
573 // test second connection
574 SdrObjConnection& rConn1 = pOrigEdge->GetConnection(TRUE);
575 pConnObj = rConn1.GetObject();
576 if(pConnObj)
578 SdrObject* pConnClone = ImpGetClone(aConnectorContainer, pConnObj);
579 if(pConnClone)
581 // if dest obj was cloned, too, re-establish connection
582 pCloneEdge->ConnectToNode(TRUE, pConnClone);
583 pCloneEdge->GetConnection(TRUE).SetConnectorId(rConn1.GetConnectorId());
585 else
587 // set position of connection point of original connected object
588 const SdrGluePointList* pGlueList = pConnObj->GetGluePointList();
589 if(pGlueList)
591 sal_uInt16 nInd = pGlueList->FindGluePoint(rConn1.GetConnectorId());
593 if(SDRGLUEPOINT_NOTFOUND != nInd)
595 const SdrGluePoint& rGluePoint = (*pGlueList)[nInd];
596 Point aPosition = rGluePoint.GetAbsolutePos(*pConnObj);
597 aPosition.X() += aVector.A();
598 aPosition.Y() += aVector.B();
599 pCloneEdge->SetTailPoint(TRUE, aPosition);
608 // #83525# cleanup remember classes
609 for(a = 0; a < aConnectorContainer.Count(); a++)
610 delete (ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a);
612 if( pMarkList != mpDragSrcMarkList )
613 delete pMarkList;
615 bReturn = TRUE;
617 else
619 maDropErrorTimer.Start();
620 bReturn = FALSE;
624 else
626 pOwnData->SetInternalMove( TRUE );
627 MoveAllMarked( Size( maDropPos.X() - pOwnData->GetStartPos().X(),
628 maDropPos.Y() - pOwnData->GetStartPos().Y() ), bCopy );
629 bReturn = TRUE;
633 else
635 // different views
636 if( !pSourceView->IsPresObjSelected() )
638 // model is owned by from AllocModel() created DocShell
639 SdDrawDocument* pSourceDoc = (SdDrawDocument*) pSourceView->GetModel();
640 pSourceDoc->CreatingDataObj( pOwnData );
641 SdDrawDocument* pModel = (SdDrawDocument*) pSourceView->GetAllMarkedModel();
642 bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
644 if( !pPage )
645 pPage = (SdPage*) GetSdrPageView()->GetPage();
647 String aLayout( pPage->GetLayoutName() );
648 aLayout.Erase( aLayout.SearchAscii( SD_LT_SEPARATOR ) );
649 pPage->SetPresentationLayout( aLayout, FALSE, FALSE );
650 pSourceDoc->CreatingDataObj( NULL );
652 else
654 maDropErrorTimer.Start();
655 bReturn = FALSE;
659 else
661 SdDrawDocument* pWorkModel = (SdDrawDocument*) pOwnData->GetWorkDocument();
662 SdPage* pWorkPage = (SdPage*) pWorkModel->GetSdPage( 0, PK_STANDARD );
664 pWorkPage->SetRectsDirty();
666 // #104148# Use SnapRect, not BoundRect
667 Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
669 maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
670 maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
672 // delete pages, that are not of any interest for us
673 for( long i = ( pWorkModel->GetPageCount() - 1 ); i >= 0; i-- )
675 SdPage* pP = static_cast< SdPage* >( pWorkModel->GetPage( (USHORT) i ) );
677 if( pP->GetPageKind() != PK_STANDARD )
678 pWorkModel->DeletePage( (USHORT) i );
681 bReturn = Paste( *pWorkModel, maDropPos, pPage, nPasteOptions );
683 if( !pPage )
684 pPage = (SdPage*) GetSdrPageView()->GetPage();
686 String aLayout(pPage->GetLayoutName());
687 aLayout.Erase(aLayout.SearchAscii(SD_LT_SEPARATOR));
688 pPage->SetPresentationLayout( aLayout, FALSE, FALSE );
691 else if( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_DRAWING ) )
693 SotStorageStreamRef xStm;
695 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ) )
697 BOOL bChanged = FALSE;
699 DrawDocShellRef xShell = new DrawDocShell(SFX_CREATE_MODE_INTERNAL);
700 xShell->DoInitNew(0);
702 SdDrawDocument* pModel = xShell->GetDoc();
703 pModel->InsertPage(pModel->AllocPage(false));
705 Reference< XComponent > xComponent( xShell->GetModel(), UNO_QUERY );
706 xStm->Seek( 0 );
708 com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
709 bReturn = SvxDrawingLayerImport( pModel, xInputStream, xComponent, "com.sun.star.comp.Impress.XMLOasisImporter" );
711 if( pModel->GetPageCount() == 0 )
713 DBG_ERROR("empty or invalid drawing xml document on clipboard!" );
715 else
717 if( bReturn )
719 if( pModel->GetSdPage( 0, PK_STANDARD )->GetObjCount() == 1 )
721 // only one object
722 SdrObject* pObj = pModel->GetSdPage( 0, PK_STANDARD )->GetObj( 0 );
723 SdrObject* pPickObj2 = NULL;
724 SdrPageView* pPV = NULL;
725 PickObj( rPos, getHitTolLog(), pPickObj2, pPV );
727 if( ( mnAction & DND_ACTION_MOVE ) && pPickObj2 && pObj )
729 // replace object
730 SdrObject* pNewObj = pObj->Clone();
731 Rectangle aPickObjRect( pPickObj2->GetCurrentBoundRect() );
732 Size aPickObjSize( aPickObjRect.GetSize() );
733 Point aVec( aPickObjRect.TopLeft() );
734 Rectangle aObjRect( pNewObj->GetCurrentBoundRect() );
735 Size aObjSize( aObjRect.GetSize() );
737 Fraction aScaleWidth( aPickObjSize.Width(), aObjSize.Width() );
738 Fraction aScaleHeight( aPickObjSize.Height(), aObjSize.Height() );
739 pNewObj->NbcResize( aObjRect.TopLeft(), aScaleWidth, aScaleHeight );
741 aVec -= aObjRect.TopLeft();
742 pNewObj->NbcMove( Size( aVec.X(), aVec.Y() ) );
744 const bool bUndo = IsUndoEnabled();
746 if( bUndo )
747 BegUndo( String( SdResId(STR_UNDO_DRAGDROP ) ) );
748 pNewObj->NbcSetLayer( pPickObj->GetLayer() );
749 SdrPage* pWorkPage = GetSdrPageView()->GetPage();
750 pWorkPage->InsertObject( pNewObj );
751 if( bUndo )
753 AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoNewObject( *pNewObj ) );
754 AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoDeleteObject( *pPickObj2 ) );
756 pWorkPage->RemoveObject( pPickObj2->GetOrdNum() );
758 if( bUndo )
760 EndUndo();
762 else
764 SdrObject::Free(pPickObj2 );
766 bChanged = TRUE;
767 mnAction = DND_ACTION_COPY;
769 else if( ( mnAction & DND_ACTION_LINK ) && pPickObj && pObj && !pPickObj->ISA( SdrGrafObj ) && !pPickObj->ISA( SdrOle2Obj ) )
771 SfxItemSet aSet( mpDoc->GetPool() );
773 // set new attributes to object
774 const bool bUndo = IsUndoEnabled();
775 if( bUndo )
777 BegUndo( String( SdResId( STR_UNDO_DRAGDROP ) ) );
778 AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoAttrObject( *pPickObj ) );
780 aSet.Put( pObj->GetMergedItemSet() );
782 // Eckenradius soll nicht uebernommen werden.
783 // In der Gallery stehen Farbverlauefe (Rechtecke)
784 // welche den Eckenradius == 0 haben. Dieser soll
785 // nicht auf das Objekt uebertragen werden.
786 aSet.ClearItem( SDRATTR_ECKENRADIUS );
788 pPickObj->SetMergedItemSetAndBroadcast( aSet );
790 if( pPickObj->ISA( E3dObject ) && pObj->ISA( E3dObject ) )
792 // Zusaetzlich 3D Attribute handeln
793 SfxItemSet aNewSet( mpDoc->GetPool(), SID_ATTR_3D_START, SID_ATTR_3D_END, 0 );
794 SfxItemSet aOldSet( mpDoc->GetPool(), SID_ATTR_3D_START, SID_ATTR_3D_END, 0 );
796 aOldSet.Put(pPickObj->GetMergedItemSet());
797 aNewSet.Put( pObj->GetMergedItemSet() );
799 if( bUndo )
800 AddUndo( new E3dAttributesUndoAction( *mpDoc, this, (E3dObject*) pPickObj, aNewSet, aOldSet, FALSE ) );
801 pPickObj->SetMergedItemSetAndBroadcast( aNewSet );
804 if( bUndo )
805 EndUndo();
806 bChanged = TRUE;
811 if( !bChanged )
813 SdrPage* pWorkPage = pModel->GetSdPage( 0, PK_STANDARD );
815 pWorkPage->SetRectsDirty();
817 if( pOwnData )
819 // #104148# Use SnapRect, not BoundRect
820 Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
822 maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
823 maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
826 bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
829 xShell->DoClose();
833 else if( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE ) )
835 ::rtl::OUString aOUString;
837 if( aDataHelper.GetString( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE, aOUString ) )
839 SdrObject* pObj = CreateFieldControl( aOUString );
841 if( pObj )
843 Rectangle aRect( pObj->GetLogicRect() );
844 Size aSize( aRect.GetSize() );
846 maDropPos.X() -= ( aSize.Width() >> 1 );
847 maDropPos.Y() -= ( aSize.Height() >> 1 );
849 aRect.SetPos( maDropPos );
850 pObj->SetLogicRect( aRect );
851 InsertObjectAtView( pObj, *GetSdrPageView(), SDRINSERT_SETDEFLAYER );
852 bReturn = TRUE;
856 else if( !bLink &&
857 ( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBED_SOURCE ) ||
858 CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ) &&
859 aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
861 //TODO/LATER: is it possible that this format is binary?! (from old versions of SO)
862 uno::Reference < io::XInputStream > xStm;
863 TransferableObjectDescriptor aObjDesc;
865 if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) &&
866 ( aDataHelper.GetInputStream( nFormat ? nFormat : SOT_FORMATSTR_ID_EMBED_SOURCE, xStm ) ||
867 aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ, xStm ) ) )
869 if( mpDoc->GetDocSh() && ( mpDoc->GetDocSh()->GetClassName() == aObjDesc.maClassName ) )
871 uno::Reference < embed::XStorage > xStore( ::comphelper::OStorageHelper::GetStorageFromInputStream( xStm ) );
872 ::sd::DrawDocShellRef xDocShRef( new ::sd::DrawDocShell( SFX_CREATE_MODE_EMBEDDED, TRUE, mpDoc->GetDocumentType() ) );
874 // mba: BaseURL doesn't make sense for clipboard functionality
875 SfxMedium *pMedium = new SfxMedium( xStore, String() );
876 if( xDocShRef->DoLoad( pMedium ) )
878 SdDrawDocument* pModel = (SdDrawDocument*) xDocShRef->GetDoc();
879 SdPage* pWorkPage = (SdPage*) pModel->GetSdPage( 0, PK_STANDARD );
881 pWorkPage->SetRectsDirty();
883 if( pOwnData )
885 // #104148# Use SnapRect, not BoundRect
886 Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
888 maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
889 maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
892 // delete pages, that are not of any interest for us
893 for( long i = ( pModel->GetPageCount() - 1 ); i >= 0; i-- )
895 SdPage* pP = static_cast< SdPage* >( pModel->GetPage( (USHORT) i ) );
897 if( pP->GetPageKind() != PK_STANDARD )
898 pModel->DeletePage( (USHORT) i );
901 bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
903 if( !pPage )
904 pPage = (SdPage*) GetSdrPageView()->GetPage();
906 String aLayout(pPage->GetLayoutName());
907 aLayout.Erase(aLayout.SearchAscii(SD_LT_SEPARATOR));
908 pPage->SetPresentationLayout( aLayout, FALSE, FALSE );
911 xDocShRef->DoClose();
912 xDocShRef.Clear();
915 else
917 ::rtl::OUString aName;
918 uno::Reference < embed::XEmbeddedObject > xObj = mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
919 if ( xObj.is() )
921 svt::EmbeddedObjectRef aObjRef( xObj, aObjDesc.mnViewAspect );
923 // try to get the replacement image from the clipboard
924 Graphic aGraphic;
925 ULONG nGrFormat = 0;
927 // (wg. Selection Manager bei Trustet Solaris)
928 #ifndef SOLARIS
930 if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
931 nGrFormat = SOT_FORMATSTR_ID_SVXB;
932 else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
933 nGrFormat = SOT_FORMAT_GDIMETAFILE;
934 else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) )
935 nGrFormat = SOT_FORMAT_BITMAP;
937 #endif
939 // insert replacement image ( if there is one ) into the object helper
940 if ( nGrFormat )
942 datatransfer::DataFlavor aDataFlavor;
943 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
944 aObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
947 Size aSize;
948 if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
950 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
951 aSize = aObjDesc.maSize;
952 else
954 MapMode aMapMode( MAP_100TH_MM );
955 aSize = aObjRef.GetSize( &aMapMode );
958 else
960 awt::Size aSz;
961 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
962 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
964 Size aTmp( OutputDevice::LogicToLogic( aObjDesc.maSize, MAP_100TH_MM, aMapUnit ) );
965 aSz.Width = aTmp.Width();
966 aSz.Height = aTmp.Height();
967 xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
972 aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
974 catch( embed::NoVisualAreaSizeException& )
976 // if the size still was not set the default size will be set later
979 aSize = Size( aSz.Width, aSz.Height );
981 if( !aSize.Width() || !aSize.Height() )
983 aSize.Width() = 14100;
984 aSize.Height() = 10000;
985 aSize = OutputDevice::LogicToLogic( Size(14100, 10000), MAP_100TH_MM, aMapUnit );
986 aSz.Width = aSize.Width();
987 aSz.Height = aSize.Height();
988 xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
991 aSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
994 Size aMaxSize( mpDoc->GetMaxObjSize() );
996 maDropPos.X() -= Min( aSize.Width(), aMaxSize.Width() ) >> 1;
997 maDropPos.Y() -= Min( aSize.Height(), aMaxSize.Height() ) >> 1;
999 Rectangle aRect( maDropPos, aSize );
1000 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect );
1001 SdrPageView* pPV = GetSdrPageView();
1002 ULONG nOptions = SDRINSERT_SETDEFLAYER;
1004 if (mpViewSh!=NULL)
1006 OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
1007 SfxInPlaceClient* pIpClient
1008 = mpViewSh->GetViewShell()->GetIPClient();
1009 if (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive())
1010 nOptions |= SDRINSERT_DONTMARK;
1013 InsertObjectAtView( pObj, *pPV, nOptions );
1015 if( pImageMap )
1016 pObj->InsertUserData( new SdIMapInfo( *pImageMap ) );
1018 bReturn = TRUE;
1023 else if( !bLink &&
1024 ( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) ||
1025 CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) ) &&
1026 aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE ) )
1028 // online insert ole if format is forced or no gdi metafile is available
1029 if( (nFormat != 0) || !aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1031 uno::Reference < io::XInputStream > xStm;
1032 TransferableObjectDescriptor aObjDesc;
1034 if ( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aObjDesc ) )
1036 uno::Reference < embed::XEmbeddedObject > xObj;
1037 ::rtl::OUString aName;
1039 if ( aDataHelper.GetInputStream( nFormat ? nFormat : SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStm ) ||
1040 aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStm ) )
1042 xObj = mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
1044 else
1048 uno::Reference< embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1049 uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator(
1050 ::comphelper::getProcessServiceFactory()->createInstance(
1051 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ),
1052 uno::UNO_QUERY_THROW );
1054 embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
1055 xTmpStor,
1056 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DummyName" ) ),
1057 uno::Sequence< beans::PropertyValue >() );
1059 // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
1060 // for example whether the object should be an iconified one
1061 xObj = aInfo.Object;
1062 if ( xObj.is() )
1063 mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
1065 catch( uno::Exception& )
1069 if ( xObj.is() )
1071 svt::EmbeddedObjectRef aObjRef( xObj, aObjDesc.mnViewAspect );
1073 // try to get the replacement image from the clipboard
1074 Graphic aGraphic;
1075 ULONG nGrFormat = 0;
1077 // (wg. Selection Manager bei Trustet Solaris)
1078 #ifndef SOLARIS
1079 if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
1080 nGrFormat = SOT_FORMATSTR_ID_SVXB;
1081 else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
1082 nGrFormat = SOT_FORMAT_GDIMETAFILE;
1083 else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) )
1084 nGrFormat = SOT_FORMAT_BITMAP;
1085 #endif
1087 // insert replacement image ( if there is one ) into the object helper
1088 if ( nGrFormat )
1090 datatransfer::DataFlavor aDataFlavor;
1091 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
1092 aObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
1095 Size aSize;
1096 if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
1098 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1099 aSize = aObjDesc.maSize;
1100 else
1102 MapMode aMapMode( MAP_100TH_MM );
1103 aSize = aObjRef.GetSize( &aMapMode );
1106 else
1108 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
1110 awt::Size aSz;
1111 try{
1112 aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
1114 catch( embed::NoVisualAreaSizeException& )
1116 // the default size will be set later
1119 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1121 Size aTmp( OutputDevice::LogicToLogic( aObjDesc.maSize, MAP_100TH_MM, aMapUnit ) );
1122 if ( aSz.Width != aTmp.Width() || aSz.Height != aTmp.Height() )
1124 aSz.Width = aTmp.Width();
1125 aSz.Height = aTmp.Height();
1126 xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1130 aSize = Size( aSz.Width, aSz.Height );
1132 if( !aSize.Width() || !aSize.Height() )
1134 aSize = OutputDevice::LogicToLogic( Size(14100, 10000), MAP_100TH_MM, aMapUnit );
1135 aSz.Width = aSize.Width();
1136 aSz.Height = aSize.Height();
1137 xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1140 aSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
1143 Size aMaxSize( mpDoc->GetMaxObjSize() );
1145 maDropPos.X() -= Min( aSize.Width(), aMaxSize.Width() ) >> 1;
1146 maDropPos.Y() -= Min( aSize.Height(), aMaxSize.Height() ) >> 1;
1148 Rectangle aRect( maDropPos, aSize );
1149 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect );
1150 SdrPageView* pPV = GetSdrPageView();
1151 ULONG nOptions = SDRINSERT_SETDEFLAYER;
1153 if (mpViewSh!=NULL)
1155 OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
1156 SfxInPlaceClient* pIpClient
1157 = mpViewSh->GetViewShell()->GetIPClient();
1158 if (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive())
1159 nOptions |= SDRINSERT_DONTMARK;
1162 InsertObjectAtView( pObj, *pPV, nOptions );
1164 if( pImageMap )
1165 pObj->InsertUserData( new SdIMapInfo( *pImageMap ) );
1167 // let the object stay in loaded state after insertion
1168 pObj->Unload();
1169 bReturn = TRUE;
1174 if( !bReturn && aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1176 // if no object was inserted, insert a picture
1177 InsertMetaFile( aDataHelper, rPos, pImageMap, true );
1180 else if( ( !bLink || pPickObj ) && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_SVXB ) )
1182 SotStorageStreamRef xStm;
1184 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ) )
1186 Point aInsertPos( rPos );
1187 Graphic aGraphic;
1189 *xStm >> aGraphic;
1191 if( pOwnData && pOwnData->GetWorkDocument() )
1193 const SdDrawDocument* pWorkModel = pOwnData->GetWorkDocument();
1194 SdrPage* pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1195 pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1196 pWorkModel->GetPage( 0 ) );
1198 pWorkPage->SetRectsDirty();
1200 // #104148# Use SnapRect, not BoundRect
1201 Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
1203 aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1204 aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1207 // #90129# restrict movement to WorkArea
1208 Size aImageMapSize = OutputDevice::LogicToLogic(aGraphic.GetPrefSize(),
1209 aGraphic.GetPrefMapMode(), MapMode(MAP_100TH_MM));
1211 ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea());
1213 InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap );
1214 bReturn = TRUE;
1217 else if( ( !bLink || pPickObj ) && CHECK_FORMAT_TRANS( FORMAT_GDIMETAFILE ) )
1219 Point aInsertPos( rPos );
1221 if( pOwnData && pOwnData->GetWorkDocument() )
1224 const SdDrawDocument* pWorkModel = pOwnData->GetWorkDocument();
1225 SdrPage* pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1226 pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1227 pWorkModel->GetPage( 0 ) );
1229 pWorkPage->SetRectsDirty();
1231 // #104148# Use SnapRect, not BoundRect
1232 Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
1234 aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1235 aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1238 bReturn = InsertMetaFile( aDataHelper, aInsertPos, pImageMap, nFormat == 0 ? true : false ) ? TRUE : FALSE;
1240 else if( ( !bLink || pPickObj ) && CHECK_FORMAT_TRANS( FORMAT_BITMAP ) )
1242 Bitmap aBmp;
1244 if( aDataHelper.GetBitmap( FORMAT_BITMAP, aBmp ) )
1246 Point aInsertPos( rPos );
1248 if( pOwnData && pOwnData->GetWorkDocument() )
1250 const SdDrawDocument* pWorkModel = pOwnData->GetWorkDocument();
1251 SdrPage* pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1252 pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1253 pWorkModel->GetPage( 0 ) );
1255 pWorkPage->SetRectsDirty();
1257 // #104148# Use SnapRect, not BoundRect
1258 Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
1260 aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1261 aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1264 // #90129# restrict movement to WorkArea
1265 Size aImageMapSize(aBmp.GetPrefSize());
1266 ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea());
1268 InsertGraphic( aBmp, mnAction, aInsertPos, NULL, pImageMap );
1269 bReturn = TRUE;
1272 else if( pPickObj && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_XFA ) )
1274 SotStorageStreamRef xStm;
1276 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_XFA, xStm ) )
1278 XFillExchangeData aFillData( XFillAttrSetItem( &mpDoc->GetPool() ) );
1280 *xStm >> aFillData;
1282 if( IsUndoEnabled() )
1284 BegUndo( String( SdResId( STR_UNDO_DRAGDROP ) ) );
1285 AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoAttrObject( *pPickObj ) );
1286 EndUndo();
1289 XFillAttrSetItem* pSetItem = aFillData.GetXFillAttrSetItem();
1290 SfxItemSet rSet = pSetItem->GetItemSet();
1291 XFillStyle eFill= ( (XFillStyleItem&) rSet.Get( XATTR_FILLSTYLE ) ).GetValue();
1293 if( eFill == XFILL_SOLID || eFill == XFILL_NONE )
1295 const XFillColorItem& rColItem = (XFillColorItem&) rSet.Get( XATTR_FILLCOLOR );
1296 Color aColor( rColItem.GetColorValue() );
1297 String aName( rColItem.GetName() );
1298 SfxItemSet aSet( mpDoc->GetPool() );
1299 BOOL bClosed = pPickObj->IsClosedObj();
1300 ::sd::Window* pWin = mpViewSh->GetActiveWindow();
1301 USHORT nHitLog = (USHORT) pWin->PixelToLogic(
1302 Size(FuPoor::HITPIX, 0 ) ).Width();
1303 const long n2HitLog = nHitLog << 1;
1304 Point aHitPosR( rPos );
1305 Point aHitPosL( rPos );
1306 Point aHitPosT( rPos );
1307 Point aHitPosB( rPos );
1308 const SetOfByte* pVisiLayer = &GetSdrPageView()->GetVisibleLayers();
1310 aHitPosR.X() += n2HitLog;
1311 aHitPosL.X() -= n2HitLog;
1312 aHitPosT.Y() += n2HitLog;
1313 aHitPosB.Y() -= n2HitLog;
1315 if( bClosed &&
1316 SdrObjectPrimitiveHit(*pPickObj, aHitPosR, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1317 SdrObjectPrimitiveHit(*pPickObj, aHitPosL, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1318 SdrObjectPrimitiveHit(*pPickObj, aHitPosT, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1319 SdrObjectPrimitiveHit(*pPickObj, aHitPosB, nHitLog, *GetSdrPageView(), pVisiLayer, false) )
1321 // area fill
1322 if(eFill == XFILL_SOLID )
1323 aSet.Put(XFillColorItem(aName, aColor));
1325 aSet.Put( XFillStyleItem( eFill ) );
1327 else
1328 aSet.Put( XLineColorItem( aName, aColor ) );
1330 // Textfarbe hinzufuegen
1331 pPickObj->SetMergedItemSetAndBroadcast( aSet );
1335 else if( !bLink && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_HTML ) )
1337 SotStorageStreamRef xStm;
1339 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_HTML, xStm ) )
1341 xStm->Seek( 0 );
1342 // mba: clipboard always must contain absolute URLs (could be from alien source)
1343 bReturn = SdrView::Paste( *xStm, String(), EE_FORMAT_HTML, maDropPos, pPage, nPasteOptions );
1346 else if( !bLink && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EDITENGINE ) )
1348 SotStorageStreamRef xStm;
1350 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_EDITENGINE, xStm ) )
1352 OutlinerView* pOLV = GetTextEditOutlinerView();
1354 xStm->Seek( 0 );
1356 if( pOLV )
1358 Rectangle aRect( pOLV->GetOutputArea() );
1359 Point aPos( pOLV->GetWindow()->PixelToLogic( maDropPos ) );
1361 if( aRect.IsInside( aPos ) || ( !bDrag && IsTextEdit() ) )
1363 // mba: clipboard always must contain absolute URLs (could be from alien source)
1364 pOLV->Read( *xStm, String(), EE_FORMAT_BIN, FALSE, mpDocSh->GetHeaderAttributes() );
1365 bReturn = TRUE;
1369 if( !bReturn )
1370 // mba: clipboard always must contain absolute URLs (could be from alien source)
1371 bReturn = SdrView::Paste( *xStm, String(), EE_FORMAT_BIN, maDropPos, pPage, nPasteOptions );
1374 else if( !bLink && CHECK_FORMAT_TRANS( FORMAT_RTF ) )
1376 SotStorageStreamRef xStm;
1378 if( aDataHelper.GetSotStorageStream( FORMAT_RTF, xStm ) )
1380 xStm->Seek( 0 );
1382 if( bTable )
1384 bReturn = PasteRTFTable( xStm, pPage, nPasteOptions );
1386 else
1388 OutlinerView* pOLV = GetTextEditOutlinerView();
1390 if( pOLV )
1392 Rectangle aRect( pOLV->GetOutputArea() );
1393 Point aPos( pOLV->GetWindow()->PixelToLogic( maDropPos ) );
1395 if( aRect.IsInside( aPos ) || ( !bDrag && IsTextEdit() ) )
1397 // mba: clipboard always must contain absolute URLs (could be from alien source)
1398 pOLV->Read( *xStm, String(), EE_FORMAT_RTF, FALSE, mpDocSh->GetHeaderAttributes() );
1399 bReturn = TRUE;
1403 if( !bReturn )
1404 // mba: clipboard always must contain absolute URLs (could be from alien source)
1405 bReturn = SdrView::Paste( *xStm, String(), EE_FORMAT_RTF, maDropPos, pPage, nPasteOptions );
1409 else if( CHECK_FORMAT_TRANS( FORMAT_FILE_LIST ) )
1411 FileList aDropFileList;
1413 if( aDataHelper.GetFileList( FORMAT_FILE_LIST, aDropFileList ) )
1415 maDropFileVector.clear();
1417 for( ULONG i = 0, nCount = aDropFileList.Count(); i < nCount; i++ )
1418 maDropFileVector.push_back( aDropFileList.GetFile( i ) );
1420 maDropInsertFileTimer.Start();
1423 bReturn = TRUE;
1425 else if( CHECK_FORMAT_TRANS( FORMAT_FILE ) )
1427 String aDropFile;
1429 if( aDataHelper.GetString( FORMAT_FILE, aDropFile ) )
1431 maDropFileVector.clear();
1432 maDropFileVector.push_back( aDropFile );
1433 maDropInsertFileTimer.Start();
1436 bReturn = TRUE;
1438 else if( !bLink && CHECK_FORMAT_TRANS( FORMAT_STRING ) )
1440 if( ( FORMAT_STRING == nFormat ) ||
1441 ( !aDataHelper.HasFormat( SOT_FORMATSTR_ID_SOLK ) &&
1442 !aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
1443 !aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILENAME ) ) )
1445 ::rtl::OUString aOUString;
1447 if( aDataHelper.GetString( FORMAT_STRING, aOUString ) )
1449 OutlinerView* pOLV = GetTextEditOutlinerView();
1451 if( pOLV )
1453 pOLV->InsertText( aOUString );
1454 bReturn = TRUE;
1457 if( !bReturn )
1458 bReturn = SdrView::Paste( aOUString, maDropPos, pPage, nPasteOptions );
1463 MarkListHasChanged();
1464 mbIsDropAllowed = TRUE;
1465 rDnDAction = mnAction;
1466 delete pImageMap;
1468 return bReturn;
1471 extern void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel );
1473 bool View::PasteRTFTable( SotStorageStreamRef xStm, SdrPage* pPage, ULONG nPasteOptions )
1475 SdDrawDocument* pModel = new SdDrawDocument( DOCUMENT_TYPE_IMPRESS, mpDocSh );
1476 pModel->NewOrLoadCompleted(NEW_DOC);
1477 pModel->GetItemPool().SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
1478 pModel->InsertPage(pModel->AllocPage(false));
1480 Reference< XComponent > xComponent( new SdXImpressDocument( pModel, sal_True ) );
1481 pModel->setUnoModel( Reference< XInterface >::query( xComponent ) );
1483 CreateTableFromRTF( *xStm, pModel );
1484 bool bRet = Paste( *pModel, maDropPos, pPage, nPasteOptions );
1486 xComponent->dispose();
1487 xComponent.clear();
1489 delete pModel;
1491 return bRet;
1494 } // end of namespace sd