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