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_sw.hxx" 26 #ifdef PRECOMPILED 27 #include "ui_pch.hxx" 28 #endif 29 30 31 #include <com/sun/star/embed/XVisualObject.hpp> 32 #include <com/sun/star/embed/XTransactedObject.hpp> 33 #include <com/sun/star/embed/Aspects.hpp> 34 #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp> 35 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 36 37 #include <svtools/embedtransfer.hxx> 38 #include <svtools/insdlg.hxx> 39 #include <unotools/tempfile.hxx> 40 #include <comphelper/storagehelper.hxx> 41 #include <comphelper/processfactory.hxx> 42 #include <unotools/ucbstreamhelper.hxx> 43 #include <sot/filelist.hxx> 44 #include <svx/svxdlg.hxx> 45 #include <toolkit/helper/vclunohelper.hxx> 46 #include <osl/endian.h> 47 #include <sfx2/linkmgr.hxx> 48 #include <tools/urlobj.hxx> 49 #include <vcl/wrkwin.hxx> 50 #include <vcl/msgbox.hxx> 51 #include <sfx2/dispatch.hxx> 52 #include <svl/stritem.hxx> 53 #include <svtools/imap.hxx> 54 #include <sot/storage.hxx> 55 #include <vcl/graph.hxx> 56 #include <svl/urihelper.hxx> 57 #include <svx/svdmodel.hxx> 58 #include <svx/xexch.hxx> 59 #include <svx/xmlexchg.hxx> 60 #include <svx/dbaexchange.hxx> 61 #include <svx/clipfmtitem.hxx> 62 #include <sfx2/mieclip.hxx> 63 #include <svx/svdetc.hxx> 64 #include <svx/xoutbmp.hxx> 65 #include <svl/urlbmk.hxx> 66 #include <svtools/htmlout.hxx> 67 #include <svx/hlnkitem.hxx> 68 #include <svtools/inetimg.hxx> 69 #include <editeng/paperinf.hxx> 70 #include <svx/fmview.hxx> 71 #include <editeng/scripttypeitem.hxx> 72 #include <sfx2/docfilt.hxx> 73 #include <svtools/imapobj.hxx> 74 #include <sfx2/docfile.hxx> 75 #include <unotools/transliterationwrapper.hxx> 76 #include <unotools/streamwrap.hxx> 77 #include <svtools/filter.hxx> 78 79 #include <svx/unomodel.hxx> 80 #include <fmturl.hxx> 81 #include <fmtinfmt.hxx> 82 #include <fmtfsize.hxx> 83 #include <swdtflvr.hxx> 84 #include <shellio.hxx> 85 #include <ddefld.hxx> 86 #include <doc.hxx> 87 #include <IDocumentUndoRedo.hxx> 88 #include <pagedesc.hxx> 89 #include <IMark.hxx> 90 #include <bookmrk.hxx> 91 #include <docary.hxx> 92 #include <section.hxx> 93 #include <ndtxt.hxx> 94 #include <edtwin.hxx> 95 #include <navicont.hxx> 96 #include <swcont.hxx> 97 #include <wrtsh.hxx> 98 #include <swmodule.hxx> 99 #include <view.hxx> 100 #include <docsh.hxx> 101 #include <wdocsh.hxx> 102 #include <fldbas.hxx> //DDE 103 #include <swundo.hxx> // fuer Undo-Ids 104 #include <pam.hxx> 105 #include <ndole.hxx> 106 #include <swwait.hxx> 107 #include <viewopt.hxx> 108 #include <swunodef.hxx> 109 #include <vcl/sound.hxx> 110 #include <swerror.h> 111 #include <SwCapObjType.hxx> 112 #include <cmdid.h> 113 #include <dochdl.hrc> 114 #include <comcore.hrc> // #111827# 115 #include <sot/stg.hxx> 116 #include <svx/svditer.hxx> 117 #include <editeng/eeitem.hxx> 118 #include <editeng/fhgtitem.hxx> 119 #include <svx/svdpage.hxx> 120 #include <avmedia/mediawindow.hxx> 121 #include <swcrsr.hxx> 122 #include <SwRewriter.hxx> 123 #include <globals.hrc> 124 #include <vos/mutex.hxx> 125 #include <vcl/svapp.hxx> 126 #include <swserv.hxx> 127 #include <switerator.hxx> 128 129 extern sal_Bool bFrmDrag; 130 extern sal_Bool bDDINetAttr; 131 extern sal_Bool bExecuteDrag; 132 133 134 #define OLESIZE 11905 - 2 * lMinBorder, 6 * MM50 135 136 #define SWTRANSFER_OBJECTTYPE_DRAWMODEL 0x00000001 137 #define SWTRANSFER_OBJECTTYPE_HTML 0x00000002 138 #define SWTRANSFER_OBJECTTYPE_RTF 0x00000004 139 #define SWTRANSFER_OBJECTTYPE_STRING 0x00000008 140 #define SWTRANSFER_OBJECTTYPE_SWOLE 0x00000010 141 #define SWTRANSFER_OBJECTTYPE_DDE 0x00000020 142 143 #define SWTRANSFER_GRAPHIC_INSERTED 0x00000040 144 145 using namespace ::svx; 146 using ::rtl::OUString; 147 using namespace ::com::sun::star; 148 using namespace ::com::sun::star::uno; 149 using namespace ::com::sun::star::datatransfer; 150 using namespace nsTransferBufferType; 151 152 #define DDE_TXT_ENCODING gsl_getSystemTextEncoding() 153 154 class SwTrnsfrDdeLink : public ::sfx2::SvBaseLink 155 { 156 String sName; 157 ::sfx2::SvLinkSourceRef refObj; 158 SwTransferable& rTrnsfr; 159 SwDocShell* pDocShell; 160 sal_uLong nOldTimeOut; 161 sal_Bool bDelBookmrk : 1; 162 sal_Bool bInDisconnect : 1; 163 164 sal_Bool FindDocShell(); 165 166 using sfx2::SvBaseLink::Disconnect; 167 168 protected: 169 virtual ~SwTrnsfrDdeLink(); 170 171 public: 172 SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh ); 173 174 virtual void DataChanged( const String& rMimeType, 175 const uno::Any & rValue ); 176 virtual void Closed(); 177 178 sal_Bool WriteData( SvStream& rStrm ); 179 180 void Disconnect( sal_Bool bRemoveDataAdvise ); 181 }; 182 183 // helper class for Action and Undo enclosing 184 class SwTrnsfrActionAndUndo 185 { 186 SwWrtShell *pSh; 187 SwUndoId eUndoId; 188 public: 189 SwTrnsfrActionAndUndo( SwWrtShell *pS, SwUndoId nId, 190 const SwRewriter * pRewriter = 0, 191 sal_Bool bDelSel = sal_False) 192 : pSh( pS ), eUndoId( nId ) 193 { 194 pSh->StartUndo( eUndoId, pRewriter ); 195 if( bDelSel ) 196 pSh->DelRight(); 197 pSh->StartAllAction(); 198 } 199 ~SwTrnsfrActionAndUndo() 200 { 201 pSh->EndUndo(); 202 pSh->EndAllAction(); 203 } 204 }; 205 206 207 // ----------------------------------------------------------------------- 208 209 SwTransferable::SwTransferable( SwWrtShell& rSh ) 210 : pWrtShell( &rSh ), 211 pCreatorView( 0 ), 212 pClpDocFac( 0 ), 213 pClpGraphic( 0 ), 214 pClpBitmap( 0 ), 215 pOrigGrf( 0 ), 216 pBkmk( 0 ), 217 pImageMap( 0 ), 218 pTargetURL( 0 ), 219 eBufferType( TRNSFR_NONE ) 220 { 221 rSh.GetView().AddTransferable(*this); 222 SwDocShell* pDShell = rSh.GetDoc()->GetDocShell(); 223 if( pDShell ) 224 { 225 pDShell->FillTransferableObjectDescriptor( aObjDesc ); 226 if( pDShell->GetMedium() ) 227 { 228 const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject(); 229 aObjDesc.maDisplayName = URIHelper::removePassword( 230 rURLObj.GetMainURL( INetURLObject::NO_DECODE ), 231 INetURLObject::WAS_ENCODED, 232 INetURLObject::DECODE_UNAMBIGUOUS ); 233 } 234 235 PrepareOLE( aObjDesc ); 236 } 237 } 238 239 // ----------------------------------------------------------------------- 240 241 SwTransferable::~SwTransferable() 242 { 243 Application::GetSolarMutex().acquire(); 244 245 // der DDELink braucht noch die WrtShell! 246 if( refDdeLink.Is() ) 247 { 248 ((SwTrnsfrDdeLink*)&refDdeLink)->Disconnect( sal_True ); 249 refDdeLink.Clear(); 250 } 251 252 pWrtShell = 0; 253 254 // dvo 2002-05-30, #99239#: release reference to the document so that 255 // aDocShellRef will delete it (if aDocShellRef is set). Otherwise, the OLE 256 // nodes keep references to their sub-storage when the storage is already 257 // dead. 258 delete pClpDocFac; 259 260 //JP 22.04.95: erst schliessen, dann kann die Ref. auch gecleared werden, 261 // so das die DocShell auch tatsaechlich geloescht wird! 262 if( aDocShellRef.Is() ) 263 { 264 SfxObjectShell * pObj = aDocShellRef; 265 SwDocShell* pDocSh = (SwDocShell*)pObj; 266 pDocSh->DoClose(); 267 } 268 aDocShellRef.Clear(); 269 270 SwModule* pMod = SW_MOD(); 271 if(pMod) 272 { 273 if ( pMod->pDragDrop == this ) 274 pMod->pDragDrop = 0; 275 else if ( pMod->pXSelection == this ) 276 pMod->pXSelection = 0; 277 } 278 279 delete pClpGraphic; 280 delete pClpBitmap; 281 delete pImageMap; 282 delete pTargetURL; 283 delete pBkmk; 284 285 286 eBufferType = TRNSFR_NONE; 287 288 Application::GetSolarMutex().release(); 289 } 290 291 // ----------------------------------------------------------------------- 292 293 static SwDoc * lcl_GetDoc(SwDocFac & rDocFac) 294 { 295 SwDoc *const pDoc = rDocFac.GetDoc(); 296 ASSERT( pDoc, "Document not found" ); 297 if (pDoc) 298 { 299 pDoc->SetClipBoard( true ); 300 } 301 return pDoc; 302 } 303 304 // ----------------------------------------------------------------------- 305 306 void SwTransferable::ObjectReleased() 307 { 308 SwModule *pMod = SW_MOD(); 309 if( this == pMod->pDragDrop ) 310 pMod->pDragDrop = 0; 311 else if( this == pMod->pXSelection ) 312 pMod->pXSelection = 0; 313 } 314 315 // ----------------------------------------------------------------------- 316 317 void SwTransferable::AddSupportedFormats() 318 { 319 // only need if we are the current XSelection Object 320 SwModule *pMod = SW_MOD(); 321 if( this == pMod->pXSelection ) 322 { 323 SetDataForDragAndDrop( Point( 0,0) ); 324 } 325 } 326 327 // ----------------------------------------------------------------------- 328 329 void SwTransferable::InitOle( SfxObjectShell* pDoc, SwDoc& rDoc ) 330 { 331 //OleVisArea einstellen. Linke obere Ecke der Seite und Groesse 332 //der RealSize in Twips. 333 const Size aSz( OLESIZE ); 334 SwRect aVis( Point( DOCUMENTBORDER, DOCUMENTBORDER ), aSz ); 335 pDoc->SetVisArea( aVis.SVRect() ); 336 rDoc.set(IDocumentSettingAccess::BROWSE_MODE, true ); 337 } 338 339 // ----------------------------------------------------------------------- 340 341 uno::Reference < embed::XEmbeddedObject > SwTransferable::FindOLEObj( sal_Int64& nAspect ) const 342 { 343 uno::Reference < embed::XEmbeddedObject > xObj; 344 if( pClpDocFac ) 345 { 346 SwIterator<SwCntntNode,SwFmtColl> aIter( *pClpDocFac->GetDoc()->GetDfltGrfFmtColl() ); 347 for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() ) 348 if( ND_OLENODE == pNd->GetNodeType() ) 349 { 350 xObj = ((SwOLENode*)pNd)->GetOLEObj().GetOleRef(); 351 nAspect = ((SwOLENode*)pNd)->GetAspect(); 352 break; 353 } 354 } 355 return xObj; 356 } 357 358 // ----------------------------------------------------------------------- 359 360 Graphic* SwTransferable::FindOLEReplacementGraphic() const 361 { 362 if( pClpDocFac ) 363 { 364 SwIterator<SwCntntNode,SwFmtColl> aIter( *pClpDocFac->GetDoc()->GetDfltGrfFmtColl() ); 365 for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() ) 366 if( ND_OLENODE == pNd->GetNodeType() ) 367 { 368 return ((SwOLENode*)pNd)->GetGraphic(); 369 } 370 } 371 372 return NULL; 373 } 374 375 376 // ----------------------------------------------------------------------- 377 378 void SwTransferable::RemoveDDELinkFormat( const Window& rWin ) 379 { 380 RemoveFormat( SOT_FORMATSTR_ID_LINK ); 381 CopyToClipboard( (Window*)&rWin ); 382 } 383 384 // ----------------------------------------------------------------------- 385 386 sal_Bool SwTransferable::GetData( const DATA_FLAVOR& rFlavor ) 387 { 388 sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor ); 389 390 // we can only fullfil the request if 391 // 1) we have data for this format 392 // 2) we have either a clipboard document (pClpDocFac), or 393 // we have a SwWrtShell (so we can generate a new clipboard document) 394 if( !HasFormat( nFormat ) || ( pClpDocFac == NULL && pWrtShell == NULL ) ) 395 return sal_False; 396 397 if( !pClpDocFac ) 398 { 399 SelectionType nSelectionType = pWrtShell->GetSelectionType(); 400 401 // when pending we will not get the correct type, but nsSelectionType::SEL_TXT 402 // as fallback. This *happens* durning D&D, so we need to check if we are in 403 // the fallback and just try to get a graphic 404 const bool bPending(pWrtShell->BasicActionPend()); 405 406 // SEL_GRF kommt vom ContentType der editsh 407 if(bPending || ((nsSelectionType::SEL_GRF | nsSelectionType::SEL_DRW_FORM) & nSelectionType)) 408 { 409 pClpGraphic = new Graphic; 410 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic )) 411 pOrigGrf = pClpGraphic; 412 pClpBitmap = new Graphic; 413 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap )) 414 pOrigGrf = pClpBitmap; 415 416 // ist es ein URL-Button ? 417 String sURL, sDesc; 418 if( pWrtShell->GetURLFromButton( sURL, sDesc ) ) 419 { 420 pBkmk = new INetBookmark( sURL, sDesc ); 421 eBufferType = TRNSFR_INETFLD; 422 } 423 } 424 425 pClpDocFac = new SwDocFac; 426 SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac); 427 428 pTmpDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen 429 pWrtShell->Copy( pTmpDoc ); 430 431 // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!) 432 aDocShellRef = pTmpDoc->GetTmpDocShell(); 433 if( aDocShellRef.Is() ) 434 SwTransferable::InitOle( aDocShellRef, *pTmpDoc ); 435 pTmpDoc->SetTmpDocShell( (SfxObjectShell*)NULL ); 436 437 if( nSelectionType & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() ) 438 { 439 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR ); 440 441 Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY()); 442 443 sal_Bool bSelect = bExecuteDrag && 444 pWrtShell->GetView().GetDocShell() && 445 !pWrtShell->GetView().GetDocShell()->IsReadOnly(); 446 if( pWrtShell->GetContentAtPos( aPos, aCntntAtPos, bSelect ) ) 447 { 448 pBkmk = new INetBookmark( 449 ((SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr)->GetValue(), 450 aCntntAtPos.sStr ); 451 eBufferType = TRNSFR_INETFLD; 452 if( bSelect ) 453 pWrtShell->SelectTxtAttr( RES_TXTATR_INETFMT ); 454 } 455 } 456 if( pWrtShell->IsFrmSelected() ) 457 { 458 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL ); 459 pWrtShell->GetFlyFrmAttr( aSet ); 460 const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL ); 461 if( rURL.GetMap() ) 462 pImageMap = new ImageMap( *rURL.GetMap() ); 463 else if( rURL.GetURL().Len() ) 464 pTargetURL = new INetImage( aEmptyStr, rURL.GetURL(), 465 rURL.GetTargetFrameName(), 466 aEmptyStr, Size() ); 467 } 468 } 469 470 sal_Bool bOK = sal_False; 471 if( TRNSFR_OLE == eBufferType ) 472 { 473 //TODO/MBA: testing - is this the "single OLE object" case?! 474 // aus dem ClipDoc das OLE-Object besorgen und von dem die Daten 475 // besorgen. 476 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; // will be set in the next statement 477 uno::Reference < embed::XEmbeddedObject > xObj = FindOLEObj( nAspect ); 478 Graphic* pOLEGraph = FindOLEReplacementGraphic(); 479 if( xObj.is() ) 480 { 481 TransferableDataHelper aD( new SvEmbedTransferHelper( xObj, pOLEGraph, nAspect ) ); 482 uno::Any aAny( aD.GetAny( rFlavor )); 483 if( aAny.hasValue() ) 484 bOK = SetAny( aAny, rFlavor ); 485 } 486 487 // the following solution will be used in the case when the object can not generate the image 488 // TODO/LATER: in future the transferhelper must probably be created based on object and the replacement stream 489 if ( nFormat == SOT_FORMAT_GDIMETAFILE ) 490 { 491 pOLEGraph = FindOLEReplacementGraphic(); 492 if ( pOLEGraph ) 493 bOK = SetGDIMetaFile( pOLEGraph->GetGDIMetaFile(), rFlavor ); 494 } 495 } 496 else 497 { 498 switch( nFormat ) 499 { 500 case SOT_FORMATSTR_ID_LINK: 501 if( refDdeLink.Is() ) 502 bOK = SetObject( &refDdeLink, 503 SWTRANSFER_OBJECTTYPE_DDE, rFlavor ); 504 break; 505 506 case SOT_FORMATSTR_ID_OBJECTDESCRIPTOR: 507 case SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR: 508 bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor ); 509 break; 510 511 case SOT_FORMATSTR_ID_DRAWING: 512 { 513 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 514 bOK = SetObject( pDoc->GetDrawModel(), 515 SWTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor ); 516 } 517 break; 518 519 case SOT_FORMAT_STRING: 520 { 521 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 522 bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_STRING, rFlavor ); 523 } 524 break; 525 case SOT_FORMAT_RTF: 526 { 527 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 528 bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_RTF, rFlavor ); 529 } 530 break; 531 532 case SOT_FORMATSTR_ID_HTML: 533 { 534 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 535 bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_HTML, rFlavor ); 536 } 537 break; 538 539 case SOT_FORMATSTR_ID_SVXB: 540 if( eBufferType & TRNSFR_GRAPHIC && pOrigGrf ) 541 bOK = SetGraphic( *pOrigGrf, rFlavor ); 542 break; 543 544 case SOT_FORMAT_GDIMETAFILE: 545 if( eBufferType & TRNSFR_GRAPHIC ) 546 bOK = SetGDIMetaFile( pClpGraphic->GetGDIMetaFile(), rFlavor ); 547 break; 548 case SOT_FORMAT_BITMAP: 549 case SOT_FORMATSTR_ID_PNG: 550 // #126398# Neither pClpBitmap nor pClpGraphic are necessarily set 551 if( (eBufferType & TRNSFR_GRAPHIC) && (pClpBitmap != 0 || pClpGraphic != 0)) 552 bOK = SetBitmapEx( (pClpBitmap ? pClpBitmap : pClpGraphic)->GetBitmapEx(), rFlavor ); 553 break; 554 555 case SOT_FORMATSTR_ID_SVIM: 556 if( pImageMap ) 557 bOK = SetImageMap( *pImageMap, rFlavor ); 558 break; 559 560 case SOT_FORMATSTR_ID_INET_IMAGE: 561 if( pTargetURL ) 562 bOK = SetINetImage( *pTargetURL, rFlavor ); 563 break; 564 565 case SOT_FORMATSTR_ID_SOLK: 566 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: 567 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 568 case SOT_FORMATSTR_ID_FILECONTENT: 569 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR: 570 case SOT_FORMAT_FILE: 571 if( (TRNSFR_INETFLD & eBufferType) && pBkmk ) 572 bOK = SetINetBookmark( *pBkmk, rFlavor ); 573 break; 574 575 case SOT_FORMATSTR_ID_EMBED_SOURCE: 576 // default: 577 if( !aDocShellRef.Is() ) 578 { 579 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 580 SwDocShell* pNewDocSh = new SwDocShell( pDoc, 581 SFX_CREATE_MODE_EMBEDDED ); 582 aDocShellRef = pNewDocSh; 583 aDocShellRef->DoInitNew( NULL ); 584 SwTransferable::InitOle( aDocShellRef, *pDoc ); 585 } 586 bOK = SetObject( &aDocShellRef, SWTRANSFER_OBJECTTYPE_SWOLE, 587 rFlavor ); 588 break; 589 } 590 } 591 return bOK; 592 } 593 594 // ----------------------------------------------------------------------- 595 596 sal_Bool SwTransferable::WriteObject( SotStorageStreamRef& xStream, 597 void* pObject, sal_uInt32 nObjectType, 598 const DATA_FLAVOR& /*rFlavor*/ ) 599 { 600 sal_Bool bRet = sal_False; 601 WriterRef xWrt; 602 603 switch( nObjectType ) 604 { 605 case SWTRANSFER_OBJECTTYPE_DRAWMODEL: 606 { 607 //JP 28.02.2001: dont change the sequence of commands - Bug 8 608 SdrModel *pModel = (SdrModel*)pObject; 609 xStream->SetBufferSize( 16348 ); 610 611 // #108584# 612 // for the changed pool defaults from drawing layer pool set those 613 // attributes as hard attributes to preserve them for saving 614 const SfxItemPool& rItemPool = pModel->GetItemPool(); 615 const SvxFontHeightItem& rDefaultFontHeight = (const SvxFontHeightItem&)rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT); 616 617 // SW should have no MasterPages 618 DBG_ASSERT(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)"); 619 620 for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++) 621 { 622 const SdrPage* pPage = pModel->GetPage(a); 623 SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS); 624 625 while(aIter.IsMore()) 626 { 627 SdrObject* pObj = aIter.Next(); 628 const SvxFontHeightItem& rItem = (const SvxFontHeightItem&)pObj->GetMergedItem(EE_CHAR_FONTHEIGHT); 629 630 if(rItem.GetHeight() == rDefaultFontHeight.GetHeight()) 631 { 632 pObj->SetMergedItem(rDefaultFontHeight); 633 } 634 } 635 } 636 637 { 638 uno::Reference<io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *xStream ) ); 639 if( SvxDrawingLayerExport( pModel, xDocOut ) ) 640 xStream->Commit(); 641 } 642 643 bRet = ERRCODE_NONE == xStream->GetError(); 644 } 645 break; 646 647 case SWTRANSFER_OBJECTTYPE_SWOLE: 648 { 649 SfxObjectShell* pEmbObj = (SfxObjectShell*) pObject; 650 try 651 { 652 ::utl::TempFile aTempFile; 653 aTempFile.EnableKillingFile(); 654 uno::Reference< embed::XStorage > xWorkStore = 655 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE ); 656 657 // write document storage 658 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False ); 659 // mba: no BaseURL for clipboard 660 SfxMedium aMedium( xWorkStore, String() ); 661 bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False ); 662 pEmbObj->DoSaveCompleted(); 663 664 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY ); 665 if ( xTransact.is() ) 666 xTransact->commit(); 667 668 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ ); 669 if( pSrcStm ) 670 { 671 xStream->SetBufferSize( 0xff00 ); 672 *xStream << *pSrcStm; 673 delete pSrcStm; 674 } 675 676 bRet = sal_True; 677 678 xWorkStore->dispose(); 679 xWorkStore = uno::Reference < embed::XStorage >(); 680 xStream->Commit(); 681 } 682 catch ( uno::Exception& ) 683 {} 684 685 bRet = ( xStream->GetError() == ERRCODE_NONE ); 686 } 687 break; 688 689 690 case SWTRANSFER_OBJECTTYPE_DDE: 691 { 692 xStream->SetBufferSize( 1024 ); 693 SwTrnsfrDdeLink* pDdeLnk = (SwTrnsfrDdeLink*)pObject; 694 if( pDdeLnk->WriteData( *xStream ) ) 695 { 696 xStream->Commit(); 697 bRet = ERRCODE_NONE == xStream->GetError(); 698 } 699 } 700 break; 701 702 case SWTRANSFER_OBJECTTYPE_HTML: 703 GetHTMLWriter( aEmptyStr, String(), xWrt ); 704 break; 705 706 case SWTRANSFER_OBJECTTYPE_RTF: 707 GetRTFWriter( aEmptyStr, String(), xWrt ); 708 break; 709 710 case SWTRANSFER_OBJECTTYPE_STRING: 711 GetASCWriter( aEmptyStr, String(), xWrt ); 712 if( xWrt.Is() ) 713 { 714 SwAsciiOptions aAOpt; 715 aAOpt.SetCharSet( RTL_TEXTENCODING_UTF8 ); 716 xWrt->SetAsciiOptions( aAOpt ); 717 718 // #102841# no start char for clipboard 719 xWrt->bUCS2_WithStartChar = sal_False; 720 } 721 break; 722 } 723 724 if( xWrt.Is() ) 725 { 726 SwDoc* pDoc = (SwDoc*)pObject; 727 xWrt->bWriteClipboardDoc = sal_True; 728 xWrt->bWriteOnlyFirstTable = 0 != (TRNSFR_TABELLE & eBufferType); 729 xWrt->SetShowProgress( sal_False ); 730 SwWriter aWrt( *xStream, *pDoc ); 731 if( !IsError( aWrt.Write( xWrt )) ) 732 { 733 *xStream << '\0'; // terminate with a zero 734 xStream->Commit(); 735 bRet = sal_True; 736 } 737 } 738 739 return bRet; 740 } 741 742 // ----------------------------------------------------------------------- 743 744 int SwTransferable::Cut() 745 { 746 int nRet = Copy( sal_True ); 747 if( nRet ) 748 DeleteSelection(); 749 return nRet; 750 } 751 752 // ----------------------------------------------------------------------- 753 754 void SwTransferable::DeleteSelection() 755 { 756 if(!pWrtShell) 757 return; 758 // Selektionsart vor Action-Klammerung erfragen 759 const int nSelection = pWrtShell->GetSelectionType(); 760 pWrtShell->StartUndo( UNDO_DELETE ); 761 if( ( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL ) & nSelection ) 762 pWrtShell->IntelligentCut( nSelection ); 763 pWrtShell->DelRight(); 764 pWrtShell->EndUndo( UNDO_DELETE ); 765 } 766 767 // ----------------------------------------------------------------------- 768 769 int SwTransferable::PrepareForCopy( sal_Bool bIsCut ) 770 { 771 int nRet = 1; 772 if(!pWrtShell) 773 return 0;; 774 775 String sGrfNm; 776 const int nSelection = pWrtShell->GetSelectionType(); 777 if( nSelection == nsSelectionType::SEL_GRF ) 778 { 779 pClpGraphic = new Graphic; 780 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic )) 781 pOrigGrf = pClpGraphic; 782 pClpBitmap = new Graphic; 783 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap )) 784 pOrigGrf = pClpBitmap; 785 786 pClpDocFac = new SwDocFac; 787 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 788 pWrtShell->Copy( pDoc ); 789 790 if (pOrigGrf && !pOrigGrf->GetBitmap().IsEmpty()) 791 AddFormat( SOT_FORMATSTR_ID_SVXB ); 792 793 PrepareOLE( aObjDesc ); 794 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 795 796 // --> OD 2005-02-09 #119353# - robust 797 const Graphic* pGrf = pWrtShell->GetGraphic(); 798 if( pGrf && pGrf->IsSupportedGraphic() ) 799 // <-- 800 { 801 AddFormat( FORMAT_GDIMETAFILE ); 802 AddFormat( SOT_FORMATSTR_ID_PNG ); 803 AddFormat( FORMAT_BITMAP ); 804 } 805 eBufferType = TRNSFR_GRAPHIC; 806 pWrtShell->GetGrfNms( &sGrfNm, 0 ); 807 } 808 else if ( nSelection == nsSelectionType::SEL_OLE ) 809 { 810 pClpDocFac = new SwDocFac; 811 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 812 aDocShellRef = new SwDocShell( pDoc, SFX_CREATE_MODE_EMBEDDED); 813 aDocShellRef->DoInitNew( NULL ); 814 pWrtShell->Copy( pDoc ); 815 816 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 817 818 // --> OD #i98753# 819 // set size of embedded object at the object description structure 820 aObjDesc.maSize = OutputDevice::LogicToLogic( pWrtShell->GetObjSize(), MAP_TWIP, MAP_100TH_MM ); 821 // <-- 822 PrepareOLE( aObjDesc ); 823 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 824 825 AddFormat( FORMAT_GDIMETAFILE ); 826 eBufferType = TRNSFR_OLE; 827 } 828 //Gibt es ueberhaupt etwas zum bereitstellen? 829 else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() || 830 pWrtShell->IsObjSelected() ) 831 { 832 SwWait *pWait = 0; 833 if( pWrtShell->ShouldWait() ) 834 pWait = new SwWait( *pWrtShell->GetView().GetDocShell(), sal_True ); 835 836 pClpDocFac = new SwDocFac; 837 838 // zusaetzlichen Cursor erzeugen, damit eine Gleichbehandlung 839 // von Tastatur- und Mausselektion moeglich ist. 840 // Im AddMode wird bei Tastaturselektion der neue Cursor erst 841 // beim Bewegen des Cursors nach Selektionsende erzeugt. 842 if( pWrtShell->IsAddMode() && pWrtShell->SwCrsrShell::HasSelection() ) 843 pWrtShell->CreateCrsr(); 844 845 SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac); 846 847 pTmpDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen 848 pWrtShell->Copy( pTmpDoc ); 849 850 { 851 IDocumentMarkAccess* const pMarkAccess = pTmpDoc->getIDocumentMarkAccess(); 852 ::std::vector< ::sw::mark::IMark* > vDdeMarks; 853 // find all DDE-Bookmarks 854 for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin(); 855 ppMark != pMarkAccess->getAllMarksEnd(); 856 ppMark++) 857 { 858 if(IDocumentMarkAccess::DDE_BOOKMARK == IDocumentMarkAccess::GetType(**ppMark)) 859 vDdeMarks.push_back(ppMark->get()); 860 } 861 // remove all DDE-Bookmarks, they are invalid inside the clipdoc! 862 for(::std::vector< ::sw::mark::IMark* >::iterator ppMark = vDdeMarks.begin(); 863 ppMark != vDdeMarks.end(); 864 ppMark++) 865 pMarkAccess->deleteMark(*ppMark); 866 } 867 868 // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!) 869 aDocShellRef = pTmpDoc->GetTmpDocShell(); 870 if( aDocShellRef.Is() ) 871 SwTransferable::InitOle( aDocShellRef, *pTmpDoc ); 872 pTmpDoc->SetTmpDocShell( (SfxObjectShell*)NULL ); 873 874 if( pWrtShell->IsObjSelected() ) 875 eBufferType = TRNSFR_DRAWING; 876 else 877 { 878 eBufferType = TRNSFR_DOCUMENT; 879 if (pWrtShell->IntelligentCut(nSelection, sal_False) != SwWrtShell::NO_WORD) 880 eBufferType = (TransferBufferType)(TRNSFR_DOCUMENT_WORD | eBufferType); 881 } 882 883 int bDDELink = pWrtShell->IsSelection(); 884 if( nSelection & nsSelectionType::SEL_TBL_CELLS ) 885 { 886 eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType); 887 bDDELink = pWrtShell->HasWholeTabSelection(); 888 } 889 890 //Wenn's einer braucht OLE'n wir ihm was. 891 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 892 893 //RTF vor das Metafile von OLE stellen, weil mit weniger verlusten 894 //behaftet. 895 if( !pWrtShell->IsObjSelected() ) 896 { 897 AddFormat( FORMAT_RTF ); 898 AddFormat( SOT_FORMATSTR_ID_HTML ); 899 } 900 if( pWrtShell->IsSelection() ) 901 AddFormat( FORMAT_STRING ); 902 903 if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM )) 904 { 905 AddFormat( SOT_FORMATSTR_ID_DRAWING ); 906 if ( nSelection & nsSelectionType::SEL_DRW ) 907 { 908 AddFormat( FORMAT_GDIMETAFILE ); 909 AddFormat( SOT_FORMATSTR_ID_PNG ); 910 AddFormat( FORMAT_BITMAP ); 911 } 912 eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType ); 913 914 pClpGraphic = new Graphic; 915 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic )) 916 pOrigGrf = pClpGraphic; 917 pClpBitmap = new Graphic; 918 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap )) 919 pOrigGrf = pClpBitmap; 920 921 // ist es ein URL-Button ? 922 String sURL, sDesc; 923 if( pWrtShell->GetURLFromButton( sURL, sDesc ) ) 924 { 925 AddFormat( FORMAT_STRING ); 926 AddFormat( SOT_FORMATSTR_ID_SOLK ); 927 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ); 928 AddFormat( SOT_FORMATSTR_ID_FILECONTENT ); 929 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ); 930 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ); 931 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType ); 932 nRet = sal_True; 933 } 934 } 935 936 // beim Cut hat DDE-Link keinen Sinn!! 937 SwDocShell* pDShell; 938 if( !bIsCut && bDDELink && 939 0 != ( pDShell = pWrtShell->GetDoc()->GetDocShell()) && 940 SFX_CREATE_MODE_STANDARD == pDShell->GetCreateMode() ) 941 { 942 AddFormat( SOT_FORMATSTR_ID_LINK ); 943 refDdeLink = new SwTrnsfrDdeLink( *this, *pWrtShell ); 944 } 945 946 //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt. 947 //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage 948 //auch noch mit delayed rendering beantwortet werden. 949 aObjDesc.mbCanLink = sal_False; 950 Size aSz( OLESIZE ); 951 aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM ); 952 953 PrepareOLE( aObjDesc ); 954 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 955 956 delete pWait; 957 } 958 else 959 nRet = 0; 960 961 if( pWrtShell->IsFrmSelected() ) 962 { 963 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL ); 964 pWrtShell->GetFlyFrmAttr( aSet ); 965 const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL ); 966 if( rURL.GetMap() ) 967 { 968 pImageMap = new ImageMap( *rURL.GetMap() ); 969 AddFormat( SOT_FORMATSTR_ID_SVIM ); 970 } 971 else if( rURL.GetURL().Len() ) 972 { 973 pTargetURL = new INetImage( sGrfNm, rURL.GetURL(), 974 rURL.GetTargetFrameName(), 975 aEmptyStr, Size() ); 976 AddFormat( SOT_FORMATSTR_ID_INET_IMAGE ); 977 } 978 } 979 980 return nRet; 981 } 982 983 int SwTransferable::Copy( sal_Bool bIsCut ) 984 { 985 int nRet = PrepareForCopy( bIsCut ); 986 if ( nRet ) 987 { 988 CopyToClipboard( &pWrtShell->GetView().GetEditWin() ); 989 } 990 return nRet; 991 } 992 993 // ----------------------------------------------------------------------- 994 995 int SwTransferable::CalculateAndCopy() 996 { 997 if(!pWrtShell) 998 return 0; 999 SwWait aWait( *pWrtShell->GetView().GetDocShell(), sal_True ); 1000 1001 String aStr( pWrtShell->Calculate() ); 1002 1003 pClpDocFac = new SwDocFac; 1004 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac); 1005 pWrtShell->Copy(pDoc, & aStr); 1006 eBufferType = TRNSFR_DOCUMENT; 1007 AddFormat( FORMAT_STRING ); 1008 1009 CopyToClipboard( &pWrtShell->GetView().GetEditWin() ); 1010 1011 return 1; 1012 } 1013 1014 // ----------------------------------------------------------------------- 1015 1016 int SwTransferable::CopyGlossary( SwTextBlocks& rGlossary, 1017 const String& rStr ) 1018 { 1019 if(!pWrtShell) 1020 return 0; 1021 SwWait aWait( *pWrtShell->GetView().GetDocShell(), sal_True ); 1022 1023 pClpDocFac = new SwDocFac; 1024 SwDoc *const pCDoc = lcl_GetDoc(*pClpDocFac); 1025 1026 SwNodes& rNds = pCDoc->GetNodes(); 1027 SwNodeIndex aNodeIdx( *rNds.GetEndOfContent().StartOfSectionNode() ); 1028 SwCntntNode* pCNd = rNds.GoNext( &aNodeIdx ); // gehe zum 1. ContentNode 1029 SwPaM aPam( *pCNd ); 1030 1031 pCDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen 1032 1033 pCDoc->InsertGlossary( rGlossary, rStr, aPam, 0 ); 1034 1035 // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!) 1036 aDocShellRef = pCDoc->GetTmpDocShell(); 1037 if( aDocShellRef.Is() ) 1038 SwTransferable::InitOle( aDocShellRef, *pCDoc ); 1039 pCDoc->SetTmpDocShell( (SfxObjectShell*)NULL ); 1040 1041 eBufferType = TRNSFR_DOCUMENT; 1042 1043 //Wenn's einer braucht OLE'n wir ihm was. 1044 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 1045 AddFormat( FORMAT_RTF ); 1046 AddFormat( SOT_FORMATSTR_ID_HTML ); 1047 AddFormat( FORMAT_STRING ); 1048 1049 //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt. 1050 //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage 1051 //auch noch mit delayed rendering beantwortet werden. 1052 aObjDesc.mbCanLink = sal_False; 1053 Size aSz( OLESIZE ); 1054 aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM ); 1055 1056 PrepareOLE( aObjDesc ); 1057 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 1058 1059 CopyToClipboard( &pWrtShell->GetView().GetEditWin() ); 1060 1061 return 1; 1062 } 1063 1064 static inline uno::Reference < XTransferable > * lcl_getTransferPointer ( uno::Reference < XTransferable > &xRef ) 1065 { 1066 return &xRef; 1067 } 1068 // ----------------------------------------------------------------------- 1069 1070 sal_Bool SwTransferable::IsPaste( const SwWrtShell& rSh, 1071 const TransferableDataHelper& rData ) 1072 { 1073 // Check the common case first: We can always paste our own data! 1074 // #106503#: If _only_ the internal format can be pasted, this check will 1075 // yield 'true', while the one below would give a (wrong) result 'false'. 1076 1077 bool bIsPaste = ( GetSwTransferable( rData ) != NULL ); 1078 1079 // if it's not our own data, we need to have a closer look: 1080 if( ! bIsPaste ) 1081 { 1082 // determine the proper paste action, and return true if we find one 1083 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() ); 1084 1085 sal_uInt16 nDestination = SwTransferable::GetSotDestination( rSh ); 1086 sal_uInt16 nSourceOptions = 1087 (( EXCHG_DEST_DOC_TEXTFRAME == nDestination || 1088 EXCHG_DEST_SWDOC_FREE_AREA == nDestination || 1089 EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination || 1090 EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination ) 1091 ? EXCHG_IN_ACTION_COPY 1092 : EXCHG_IN_ACTION_MOVE); 1093 1094 sal_uLong nFormat; // output param for GetExchangeAction 1095 sal_uInt16 nEventAction; // output param for GetExchangeAction 1096 sal_uInt16 nAction = SotExchange::GetExchangeAction( 1097 rData.GetDataFlavorExVector(), 1098 nDestination, 1099 nSourceOptions, /* ?? */ 1100 EXCHG_IN_ACTION_DEFAULT, /* ?? */ 1101 nFormat, nEventAction, 0, 1102 lcl_getTransferPointer ( xTransferable ) ); 1103 1104 // if we find a suitable action, we can paste! 1105 bIsPaste = (EXCHG_INOUT_ACTION_NONE != nAction); 1106 } 1107 1108 return bIsPaste; 1109 } 1110 1111 // ----------------------------------------------------------------------- 1112 1113 int SwTransferable::Paste( SwWrtShell& rSh, TransferableDataHelper& rData ) 1114 { 1115 sal_uInt16 nEventAction, nAction=0, 1116 nDestination = SwTransferable::GetSotDestination( rSh ); 1117 sal_uLong nFormat = 0; 1118 1119 if( GetSwTransferable( rData ) ) 1120 { 1121 nAction = EXCHG_OUT_ACTION_INSERT_PRIVATE; 1122 } 1123 else 1124 { 1125 sal_uInt16 nSourceOptions = 1126 (( EXCHG_DEST_DOC_TEXTFRAME == nDestination || 1127 EXCHG_DEST_SWDOC_FREE_AREA == nDestination || 1128 EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination || 1129 EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination ) 1130 ? EXCHG_IN_ACTION_COPY 1131 : EXCHG_IN_ACTION_MOVE); 1132 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() ); 1133 nAction = SotExchange::GetExchangeAction( 1134 rData.GetDataFlavorExVector(), 1135 nDestination, 1136 nSourceOptions, /* ?? */ 1137 EXCHG_IN_ACTION_DEFAULT, /* ?? */ 1138 nFormat, nEventAction, 0, 1139 lcl_getTransferPointer ( xTransferable ) ); 1140 } 1141 1142 // special case for tables from draw application 1143 if( EXCHG_OUT_ACTION_INSERT_DRAWOBJ == (nAction & EXCHG_ACTION_MASK) ) 1144 { 1145 if( rData.HasFormat( SOT_FORMAT_RTF ) ) 1146 { 1147 nAction = EXCHG_OUT_ACTION_INSERT_STRING | (nAction & !EXCHG_ACTION_MASK); 1148 nFormat = SOT_FORMAT_RTF; 1149 } 1150 } 1151 1152 return EXCHG_INOUT_ACTION_NONE != nAction && 1153 SwTransferable::PasteData( rData, rSh, nAction, nFormat, 1154 nDestination, sal_False, sal_False ); 1155 } 1156 1157 // ----------------------------------------------------------------------- 1158 1159 int SwTransferable::PasteData( TransferableDataHelper& rData, 1160 SwWrtShell& rSh, sal_uInt16 nAction, sal_uLong nFormat, 1161 sal_uInt16 nDestination, sal_Bool bIsPasteFmt, 1162 sal_Bool bIsDefault, 1163 const Point* pPt, sal_Int8 nDropAction, 1164 sal_Bool bPasteSelection ) 1165 { 1166 SwWait aWait( *rSh.GetView(). 1167 GetDocShell(), sal_False ); 1168 SwTrnsfrActionAndUndo* pAction = 0; 1169 SwModule* pMod = SW_MOD(); 1170 1171 int nRet = 0; 1172 bool bCallAutoCaption = false; 1173 1174 if( pPt ) 1175 { 1176 // external Drop 1177 if( bPasteSelection ? !pMod->pXSelection : !pMod->pDragDrop ) 1178 { 1179 switch( nDestination ) 1180 { 1181 case EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP: 1182 case EXCHG_DEST_DOC_LNKD_GRAPHOBJ: 1183 case EXCHG_DEST_DOC_GRAPH_W_IMAP: 1184 case EXCHG_DEST_DOC_GRAPHOBJ: 1185 case EXCHG_DEST_DOC_OLEOBJ: 1186 case EXCHG_DEST_DOC_DRAWOBJ: 1187 case EXCHG_DEST_DOC_URLBUTTON: 1188 case EXCHG_DEST_DOC_GROUPOBJ: 1189 // Rahmen/Objecte selektieren 1190 SwTransferable::SetSelInShell( rSh, sal_True, pPt ); 1191 break; 1192 1193 // case EXCHG_DEST_DOC_TEXTFRAME: 1194 // case EXCHG_DEST_SWDOC_FREE_AREA: 1195 // case EXCHG_DEST_DOC_URLFIELD: 1196 default: 1197 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 1198 break; 1199 } 1200 } 1201 } 1202 else if( ( !GetSwTransferable( rData ) || bIsPasteFmt ) && 1203 !rSh.IsTableMode() && rSh.HasSelection() ) 1204 { 1205 // dann die Selektionen loeschen 1206 1207 //Selektierten Inhalt loeschen, 1208 // - nicht bei Tabellen-Selektion 1209 // - nicht bei ReRead einer Grafik/DDEDaten 1210 // - nicht bei D&D, fuer die richtige Selektion wurde im 1211 // Drop-Handler gesorgt 1212 sal_Bool bDelSel = sal_False; 1213 switch( nDestination ) 1214 { 1215 case EXCHG_DEST_DOC_TEXTFRAME: 1216 case EXCHG_DEST_SWDOC_FREE_AREA: 1217 case EXCHG_DEST_DOC_TEXTFRAME_WEB: 1218 case EXCHG_DEST_SWDOC_FREE_AREA_WEB: 1219 bDelSel = sal_True; 1220 break; 1221 } 1222 1223 if( bDelSel ) 1224 // --> FME 2004-10-19 #i34830# 1225 pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD, NULL, 1226 sal_True ); 1227 // <-- 1228 } 1229 1230 SwTransferable *pTrans=0, *pTunneledTrans=GetSwTransferable( rData ); 1231 // uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY ); 1232 // if ( xTunnel.is() ) 1233 // { 1234 // sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() ); 1235 // if ( nHandle ) 1236 // pTunneledTrans = (SwTransferable*) (sal_IntPtr) nHandle; 1237 // } 1238 1239 // check for private drop 1240 bool bPrivateDrop(pPt && (bPasteSelection ? 0 != (pTrans = pMod->pXSelection) : 0 != (pTrans = pMod->pDragDrop))); 1241 bool bNeedToSelectBeforePaste(false); 1242 1243 if(bPrivateDrop && DND_ACTION_LINK == nDropAction) 1244 { 1245 // internal drop on object, suppress bPrivateDrop to change internal fill 1246 bPrivateDrop = false; 1247 bNeedToSelectBeforePaste = true; 1248 } 1249 1250 if(bPrivateDrop && pPt && DND_ACTION_MOVE == nDropAction) 1251 { 1252 // check if dragged over a useful target. If yes, use as content exchange 1253 // drop as if from external 1254 const SwFrmFmt* pSwFrmFmt = rSh.GetFmtFromObj(*pPt); 1255 1256 if(pSwFrmFmt && 0 != dynamic_cast< const SwDrawFrmFmt* >(pSwFrmFmt)) 1257 { 1258 bPrivateDrop = false; 1259 bNeedToSelectBeforePaste = true; 1260 } 1261 } 1262 1263 if(bPrivateDrop) 1264 { 1265 // then internal Drag & Drop or XSelection 1266 nRet = pTrans->PrivateDrop( rSh, *pPt, DND_ACTION_MOVE == nDropAction, 1267 bPasteSelection ); 1268 } 1269 else if( !pPt && pTunneledTrans && 1270 EXCHG_OUT_ACTION_INSERT_PRIVATE == nAction ) 1271 { 1272 // then internal paste 1273 nRet = pTunneledTrans->PrivatePaste( rSh ); 1274 } 1275 else if( EXCHG_INOUT_ACTION_NONE != nAction ) 1276 { 1277 if( !pAction ) 1278 { 1279 // #111827# 1280 pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD); 1281 } 1282 1283 // im Drag&Drop duerfen keine MessageBoxen angezeigt werden 1284 sal_Bool bMsg = 0 == pPt; 1285 sal_uInt8 nActionFlags = static_cast< sal_uInt8 >(( nAction >> 8 ) & 0xFF); 1286 1287 sal_uInt16 nClearedAction = ( nAction & EXCHG_ACTION_MASK ); 1288 // Selektionen loeschen 1289 1290 switch( nClearedAction ) 1291 { 1292 case EXCHG_OUT_ACTION_INSERT_PRIVATE: 1293 ASSERT( pPt, "EXCHG_OUT_ACTION_INSERT_PRIVATE: was soll hier passieren?" ); 1294 break; 1295 1296 case EXCHG_OUT_ACTION_MOVE_PRIVATE: 1297 ASSERT( pPt, "EXCHG_OUT_ACTION_MOVE_PRIVATE: was soll hier passieren?" ); 1298 break; 1299 1300 1301 case EXCHG_IN_ACTION_MOVE: 1302 case EXCHG_IN_ACTION_COPY: 1303 case EXCHG_IN_ACTION_LINK: 1304 case EXCHG_OUT_ACTION_INSERT_HTML: 1305 case EXCHG_OUT_ACTION_INSERT_STRING: 1306 case EXCHG_OUT_ACTION_INSERT_IMAGEMAP: 1307 case EXCHG_OUT_ACTION_REPLACE_IMAGEMAP: 1308 1309 // dann muss ueber das Format gegangen werden 1310 switch( nFormat ) 1311 { 1312 case SOT_FORMATSTR_ID_DRAWING: 1313 nRet = SwTransferable::_PasteSdrFormat( rData, rSh, 1314 SW_PASTESDR_INSERT, pPt, 1315 nActionFlags, bNeedToSelectBeforePaste); 1316 break; 1317 1318 case SOT_FORMATSTR_ID_HTML: 1319 case SOT_FORMATSTR_ID_HTML_SIMPLE: 1320 case SOT_FORMATSTR_ID_HTML_NO_COMMENT: 1321 case SOT_FORMAT_RTF: 1322 case SOT_FORMAT_STRING: 1323 nRet = SwTransferable::_PasteFileContent( rData, rSh, 1324 nFormat, bMsg ); 1325 break; 1326 1327 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: 1328 { 1329 INetBookmark aBkmk; 1330 if( rData.GetINetBookmark( nFormat, aBkmk ) ) 1331 { 1332 SwFmtINetFmt aFmt( aBkmk.GetURL(), aEmptyStr ); 1333 rSh.InsertURL( aFmt, aBkmk.GetDescription() ); 1334 nRet = 1; 1335 } 1336 } 1337 break; 1338 1339 case SOT_FORMATSTR_ID_SD_OLE: 1340 nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat, 1341 nActionFlags, bMsg ); 1342 break; 1343 1344 case SOT_FORMATSTR_ID_SVIM: 1345 nRet = SwTransferable::_PasteImageMap( rData, rSh ); 1346 break; 1347 1348 case SOT_FORMATSTR_ID_SVXB: 1349 case SOT_FORMAT_BITMAP: 1350 case SOT_FORMATSTR_ID_PNG: 1351 case SOT_FORMAT_GDIMETAFILE: 1352 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1353 SW_PASTESDR_INSERT,pPt, 1354 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1355 break; 1356 1357 case SOT_FORMATSTR_ID_XFORMS: 1358 case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE: 1359 case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE: 1360 case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE: 1361 nRet = SwTransferable::_PasteDBData( rData, rSh, nFormat, 1362 EXCHG_IN_ACTION_LINK == nClearedAction, 1363 pPt, bMsg ); 1364 break; 1365 1366 case SOT_FORMAT_FILE: 1367 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat, 1368 ( EXCHG_IN_ACTION_MOVE == nClearedAction 1369 ? SW_PASTESDR_REPLACE 1370 : EXCHG_IN_ACTION_LINK == nClearedAction 1371 ? SW_PASTESDR_SETATTR 1372 : SW_PASTESDR_INSERT), 1373 pPt, nActionFlags, bMsg ); 1374 break; 1375 1376 case SOT_FORMAT_FILE_LIST: 1377 // dann nur als Grafiken einfuegen 1378 nRet = SwTransferable::_PasteFileList( rData, rSh, 1379 EXCHG_IN_ACTION_LINK == nClearedAction, 1380 pPt, bMsg ); 1381 break; 1382 1383 case SOT_FORMATSTR_ID_SONLK: 1384 if( pPt ) 1385 { 1386 NaviContentBookmark aBkmk; 1387 if( aBkmk.Paste( rData ) ) 1388 { 1389 if(bIsDefault) 1390 { 1391 switch(aBkmk.GetDefaultDragType()) 1392 { 1393 case REGION_MODE_NONE: nClearedAction = EXCHG_IN_ACTION_COPY; break; 1394 case REGION_MODE_EMBEDDED: nClearedAction = EXCHG_IN_ACTION_MOVE; break; 1395 case REGION_MODE_LINK: nClearedAction = EXCHG_IN_ACTION_LINK; break; 1396 } 1397 } 1398 rSh.NavigatorPaste( aBkmk, nClearedAction ); 1399 nRet = 1; 1400 } 1401 } 1402 break; 1403 1404 case SOT_FORMATSTR_ID_INET_IMAGE: 1405 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE: 1406 nRet = SwTransferable::_PasteTargetURL( rData, rSh, 1407 SW_PASTESDR_INSERT, 1408 pPt, sal_True ); 1409 break; 1410 1411 default: 1412 ASSERT( pPt, "unbekanntes Format" ); 1413 } 1414 break; 1415 1416 case EXCHG_OUT_ACTION_INSERT_FILE: 1417 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat, 1418 SW_PASTESDR_INSERT, pPt, 1419 nActionFlags, bMsg ); 1420 if( nRet & SWTRANSFER_GRAPHIC_INSERTED ) 1421 bCallAutoCaption = true; 1422 break; 1423 1424 case EXCHG_OUT_ACTION_INSERT_OLE: 1425 nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat, 1426 nActionFlags,bMsg ); 1427 break; 1428 1429 case EXCHG_OUT_ACTION_INSERT_DDE: 1430 { 1431 sal_Bool bReRead = 0 != CNT_HasGrf( rSh.GetCntType() ); 1432 nRet = SwTransferable::_PasteDDE( rData, rSh, bReRead, bMsg ); 1433 } 1434 break; 1435 1436 case EXCHG_OUT_ACTION_INSERT_HYPERLINK: 1437 { 1438 String sURL, sDesc; 1439 if( SOT_FORMAT_FILE == nFormat ) 1440 { 1441 if( rData.GetString( nFormat, sURL ) && sURL.Len() ) 1442 { 1443 SwTransferable::_CheckForURLOrLNKFile( rData, sURL, &sDesc ); 1444 if( !sDesc.Len() ) 1445 sDesc = sURL; 1446 nRet = 1; 1447 } 1448 } 1449 else 1450 { 1451 INetBookmark aBkmk; 1452 if( rData.GetINetBookmark( nFormat, aBkmk ) ) 1453 { 1454 sURL = aBkmk.GetURL(); 1455 sDesc = aBkmk.GetDescription(); 1456 nRet = 1; 1457 } 1458 } 1459 1460 if( nRet ) 1461 { 1462 SwFmtINetFmt aFmt( sURL, aEmptyStr ); 1463 rSh.InsertURL( aFmt, sDesc ); 1464 } 1465 } 1466 break; 1467 1468 case EXCHG_OUT_ACTION_GET_ATTRIBUTES: 1469 switch( nFormat ) 1470 { 1471 case SOT_FORMATSTR_ID_DRAWING: 1472 nRet = SwTransferable::_PasteSdrFormat( rData, rSh, 1473 SW_PASTESDR_SETATTR, pPt, 1474 nActionFlags, bNeedToSelectBeforePaste); 1475 break; 1476 case SOT_FORMATSTR_ID_SVXB: 1477 case SOT_FORMAT_GDIMETAFILE: 1478 case SOT_FORMAT_BITMAP: 1479 case SOT_FORMATSTR_ID_PNG: 1480 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: 1481 case SOT_FORMAT_FILE: 1482 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 1483 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR: 1484 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1485 SW_PASTESDR_SETATTR, pPt, 1486 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1487 break; 1488 default: 1489 ASSERT( sal_False, "unbekanntes Format" ); 1490 } 1491 1492 break; 1493 1494 case EXCHG_OUT_ACTION_INSERT_DRAWOBJ: 1495 nRet = SwTransferable::_PasteSdrFormat( rData, rSh, 1496 SW_PASTESDR_INSERT, pPt, 1497 nActionFlags, bNeedToSelectBeforePaste); 1498 break; 1499 case EXCHG_OUT_ACTION_INSERT_SVXB: 1500 case EXCHG_OUT_ACTION_INSERT_GDIMETAFILE: 1501 case EXCHG_OUT_ACTION_INSERT_BITMAP: 1502 case EXCHG_OUT_ACTION_INSERT_GRAPH: 1503 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1504 SW_PASTESDR_INSERT, pPt, 1505 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1506 break; 1507 1508 case EXCHG_OUT_ACTION_REPLACE_DRAWOBJ: 1509 nRet = SwTransferable::_PasteSdrFormat( rData, rSh, 1510 SW_PASTESDR_REPLACE, pPt, 1511 nActionFlags, bNeedToSelectBeforePaste); 1512 break; 1513 1514 case EXCHG_OUT_ACTION_REPLACE_SVXB: 1515 case EXCHG_OUT_ACTION_REPLACE_GDIMETAFILE: 1516 case EXCHG_OUT_ACTION_REPLACE_BITMAP: 1517 case EXCHG_OUT_ACTION_REPLACE_GRAPH: 1518 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1519 SW_PASTESDR_REPLACE,pPt, 1520 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1521 break; 1522 1523 case EXCHG_OUT_ACTION_INSERT_INTERACTIVE: 1524 nRet = SwTransferable::_PasteAsHyperlink( rData, rSh, nFormat ); 1525 break; 1526 1527 default: 1528 ASSERT( sal_False, "unbekannte Action" ); 1529 } 1530 } 1531 1532 if( !bPasteSelection && rSh.IsFrmSelected() ) 1533 { 1534 rSh.EnterSelFrmMode(); 1535 //force ::SelectShell 1536 rSh.GetView().StopShellTimer(); 1537 } 1538 1539 if( pAction ) 1540 delete pAction; 1541 if( bCallAutoCaption ) 1542 rSh.GetView().AutoCaption( GRAPHIC_CAP ); 1543 1544 return nRet; 1545 } 1546 1547 // ----------------------------------------------------------------------- 1548 1549 sal_uInt16 SwTransferable::GetSotDestination( const SwWrtShell& rSh, 1550 const Point* pPt ) 1551 { 1552 sal_uInt16 nRet = EXCHG_INOUT_ACTION_NONE; 1553 1554 ObjCntType eOType; 1555 if( pPt ) 1556 { 1557 SdrObject *pObj = 0; 1558 eOType = rSh.GetObjCntType( *pPt, pObj ); 1559 } 1560 else 1561 eOType = rSh.GetObjCntTypeOfSelection(); 1562 1563 switch( eOType ) 1564 { 1565 case OBJCNT_GRF: 1566 { 1567 sal_Bool bIMap, bLink; 1568 if( pPt ) 1569 { 1570 bIMap = 0 != rSh.GetFmtFromObj( *pPt )->GetURL().GetMap(); 1571 String aDummy; 1572 rSh.GetGrfAtPos( *pPt, aDummy, bLink ); 1573 } 1574 else 1575 { 1576 bIMap = 0 != rSh.GetFlyFrmFmt()->GetURL().GetMap(); 1577 String aDummy; 1578 rSh.GetGrfNms( &aDummy, 0 ); 1579 bLink = 0 != aDummy.Len(); 1580 } 1581 1582 if( bLink && bIMap ) 1583 nRet = EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP; 1584 else if( bLink ) 1585 nRet = EXCHG_DEST_DOC_LNKD_GRAPHOBJ; 1586 else if( bIMap ) 1587 nRet = EXCHG_DEST_DOC_GRAPH_W_IMAP; 1588 else 1589 nRet = EXCHG_DEST_DOC_GRAPHOBJ; 1590 } 1591 break; 1592 1593 case OBJCNT_FLY: 1594 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) 1595 nRet = EXCHG_DEST_DOC_TEXTFRAME_WEB; 1596 else 1597 nRet = EXCHG_DEST_DOC_TEXTFRAME; 1598 break; 1599 case OBJCNT_OLE: nRet = EXCHG_DEST_DOC_OLEOBJ; break; 1600 1601 case OBJCNT_CONTROL: /* no Action avail */ 1602 case OBJCNT_SIMPLE: nRet = EXCHG_DEST_DOC_DRAWOBJ; break; 1603 case OBJCNT_URLBUTTON: nRet = EXCHG_DEST_DOC_URLBUTTON; break; 1604 case OBJCNT_GROUPOBJ: nRet = EXCHG_DEST_DOC_GROUPOBJ; break; 1605 1606 // was mmchen wir bei Mehrfachselektion??? 1607 // case OBJCNT_DONTCARE: 1608 default: 1609 { 1610 /* 1611 JP 13.07.98: Bug 52637: es wird ein URL-Feld erkannt also werden nur die 1612 Inhalte zugelassen. Das ist aber bestimmt nicht das 1613 gewollte. 1614 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR ); 1615 SfxItemSet aSet( (SfxItemPool&)rSh.GetAttrPool(), 1616 RES_TXTATR_INETFMT, RES_TXTATR_INETFMT ); 1617 if( pPt ? ((SwWrtShell&)rSh).GetContentAtPos( *pPt, aCntntAtPos, sal_False ) 1618 : (rSh.GetAttr( aSet ) && aSet.Count()) ) 1619 nRet = EXCHG_DEST_DOC_URLFIELD; 1620 else 1621 */ 1622 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) 1623 nRet = EXCHG_DEST_SWDOC_FREE_AREA_WEB; 1624 else 1625 nRet = EXCHG_DEST_SWDOC_FREE_AREA; 1626 } 1627 } 1628 1629 return nRet; 1630 } 1631 1632 // ----------------------------------------------------------------------- 1633 1634 int SwTransferable::_PasteFileContent( TransferableDataHelper& rData, 1635 SwWrtShell& rSh, sal_uLong nFmt, sal_Bool bMsg ) 1636 { 1637 sal_uInt16 nResId = MSG_CLPBRD_FORMAT_ERROR; 1638 int nRet = 0; 1639 1640 MSE40HTMLClipFormatObj aMSE40ClpObj; 1641 1642 SotStorageStreamRef xStrm; 1643 SvStream* pStream = 0; 1644 SwRead pRead = 0; 1645 rtl::OUString sData; 1646 switch( nFmt ) 1647 { 1648 case SOT_FORMAT_STRING: 1649 { 1650 pRead = ReadAscii; 1651 if( rData.GetString( nFmt, sData ) ) 1652 { 1653 pStream = new SvMemoryStream( (void*)sData.getStr(), 1654 sData.getLength() * sizeof( sal_Unicode ), 1655 STREAM_READ ); 1656 #ifdef OSL_BIGENDIAN 1657 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); 1658 #else 1659 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 1660 #endif 1661 1662 SwAsciiOptions aAOpt; 1663 aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 ); 1664 pRead->GetReaderOpt().SetASCIIOpts( aAOpt ); 1665 break; 1666 } 1667 } 1668 // no break - because then test if we get a stream 1669 1670 default: 1671 if( rData.GetSotStorageStream( nFmt, xStrm ) ) 1672 { 1673 if( ( SOT_FORMATSTR_ID_HTML_SIMPLE == nFmt ) || 1674 ( SOT_FORMATSTR_ID_HTML_NO_COMMENT == nFmt ) ) 1675 { 1676 pStream = aMSE40ClpObj.IsValid( *xStrm ); 1677 pRead = ReadHTML; 1678 pRead->SetReadUTF8( sal_True ); 1679 //pRead->SetBaseURL( aMSE40ClpObj.GetBaseURL() ); 1680 1681 sal_Bool bNoComments = 1682 ( nFmt == SOT_FORMATSTR_ID_HTML_NO_COMMENT ); 1683 pRead->SetIgnoreHTMLComments( bNoComments ); 1684 } 1685 else 1686 { 1687 pStream = &xStrm; 1688 if( SOT_FORMAT_RTF == nFmt ) 1689 pRead = SwReaderWriter::GetReader( READER_WRITER_RTF ); 1690 else if( !pRead ) 1691 { 1692 pRead = ReadHTML; 1693 pRead->SetReadUTF8( sal_True ); 1694 } 1695 } 1696 } 1697 break; 1698 } 1699 1700 if( pStream && pRead ) 1701 { 1702 Link aOldLink( rSh.GetChgLnk() ); 1703 rSh.SetChgLnk( Link() ); 1704 1705 const SwPosition& rInsPos = *rSh.GetCrsr()->Start(); 1706 SwReader aReader( *pStream, aEmptyStr, String(), *rSh.GetCrsr() ); 1707 rSh.SaveTblBoxCntnt( &rInsPos ); 1708 if( IsError( aReader.Read( *pRead )) ) 1709 nResId = ERR_CLPBRD_READ; 1710 else 1711 nResId = 0, nRet = 1; 1712 1713 rSh.SetChgLnk( aOldLink ); 1714 if( nRet ) 1715 rSh.CallChgLnk(); 1716 } 1717 else 1718 nResId = MSG_CLPBRD_FORMAT_ERROR; 1719 1720 // Exist a SvMemoryStream? (data in the OUString and xStrm is empty) 1721 if( pStream && !xStrm.Is() ) 1722 delete pStream; 1723 1724 if( bMsg && nResId ) 1725 { 1726 InfoBox( 0, SW_RES( nResId )).Execute(); 1727 } 1728 return nRet; 1729 } 1730 1731 // ----------------------------------------------------------------------- 1732 1733 int SwTransferable::_PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh, 1734 sal_uLong nFmt, sal_uInt8 nActionFlags, sal_Bool bMsg ) 1735 { 1736 int nRet = 0; 1737 TransferableObjectDescriptor aObjDesc; 1738 uno::Reference < io::XInputStream > xStrm; 1739 uno::Reference < embed::XStorage > xStore; 1740 Reader* pRead = 0; 1741 1742 // Get the preferred format 1743 SotFormatStringId nId; 1744 if( rData.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ) 1745 nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ; 1746 else if( rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ) && 1747 rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )) 1748 nId = SOT_FORMATSTR_ID_EMBED_SOURCE; 1749 else 1750 nId = 0; 1751 1752 if( nId && rData.GetInputStream( nId, xStrm ) && xStrm.is() ) 1753 { 1754 // if there is an embedded object, first try if it's a writer object 1755 // this will be inserted into the document by using a Reader 1756 try 1757 { 1758 xStore = comphelper::OStorageHelper::GetStorageFromInputStream( xStrm ); 1759 switch( SotStorage::GetFormatID( xStore ) ) 1760 { 1761 case SOT_FORMATSTR_ID_STARWRITER_60: 1762 case SOT_FORMATSTR_ID_STARWRITERWEB_60: 1763 case SOT_FORMATSTR_ID_STARWRITERGLOB_60: 1764 case SOT_FORMATSTR_ID_STARWRITER_8: 1765 case SOT_FORMATSTR_ID_STARWRITERWEB_8: 1766 case SOT_FORMATSTR_ID_STARWRITERGLOB_8: 1767 pRead = ReadXML; 1768 break; 1769 default: 1770 try 1771 { 1772 uno::Reference < lang::XComponent > xComp( xStore, uno::UNO_QUERY ); 1773 xComp->dispose(); 1774 xStore = 0; 1775 } 1776 catch ( uno::Exception& ) 1777 { 1778 } 1779 1780 break; 1781 } 1782 } 1783 catch ( uno::Exception& ) 1784 { 1785 // it wasn't a storage, but maybe it's a useful stream 1786 } 1787 1788 nFmt = nId; 1789 } 1790 1791 if( pRead ) 1792 { 1793 SwPaM &rPAM = *rSh.GetCrsr(); 1794 SwReader aReader( xStore, aEmptyStr, rPAM ); 1795 if( !IsError( aReader.Read( *pRead )) ) 1796 nRet = 1; 1797 else if( bMsg ) 1798 InfoBox( 0, SW_RES(ERR_CLPBRD_READ) ).Execute(); 1799 } 1800 else 1801 { 1802 // temporary storage until the object is inserted 1803 uno::Reference< embed::XStorage > xTmpStor; 1804 uno::Reference < embed::XEmbeddedObject > xObj; 1805 ::rtl::OUString aName; 1806 comphelper::EmbeddedObjectContainer aCnt; 1807 1808 if ( xStrm.is() ) 1809 { 1810 if ( !rData.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) ) 1811 { 1812 DBG_ASSERT( !xStrm.is(), "An object without descriptor in clipboard!"); 1813 } 1814 } 1815 else 1816 { 1817 if( rData.HasFormat( nFmt = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE ) && rData.GetTransferableObjectDescriptor( nFmt, aObjDesc ) ) 1818 { 1819 if ( !rData.GetInputStream( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStrm ) ) 1820 rData.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStrm ); 1821 1822 if ( !xStrm.is() ) 1823 { 1824 // This is MSOLE object that should be created by direct using of system clipboard 1825 try 1826 { 1827 xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage(); 1828 uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator( 1829 ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString( 1830 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ), 1831 uno::UNO_QUERY_THROW ); 1832 1833 embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard( 1834 xTmpStor, 1835 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DummyName" ) ), 1836 uno::Sequence< beans::PropertyValue >() ); 1837 1838 // TODO/LATER: in future InsertedObjectInfo will be used to get container related information 1839 // for example whether the object should be an iconified one 1840 xObj = aInfo.Object; 1841 } 1842 catch( uno::Exception& ) 1843 {} 1844 } 1845 } 1846 } 1847 1848 if ( xStrm.is() && !xObj.is() ) 1849 xObj = aCnt.InsertEmbeddedObject( xStrm, aName ); 1850 1851 if( xObj.is() ) 1852 { 1853 svt::EmbeddedObjectRef xObjRef( xObj, aObjDesc.mnViewAspect ); 1854 1855 // try to get the replacement image from the clipboard 1856 Graphic aGraphic; 1857 sal_uLong nGrFormat = 0; 1858 1859 // (wg. Selection Manager bei Trustet Solaris) 1860 #ifndef SOLARIS 1861 /* 1862 if( rData.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) ) 1863 nGrFormat = SOT_FORMATSTR_ID_SVXB; 1864 else if( rData.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) ) 1865 nGrFormat = SOT_FORMAT_GDIMETAFILE; 1866 else if( rData.GetGraphic( FORMAT_BITMAP, aGraphic ) ) 1867 nGrFormat = SOT_FORMAT_BITMAP; 1868 */ 1869 #endif 1870 1871 // insert replacement image ( if there is one ) into the object helper 1872 if ( nGrFormat ) 1873 { 1874 datatransfer::DataFlavor aDataFlavor; 1875 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor ); 1876 xObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType ); 1877 } 1878 else if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON ) 1879 { 1880 // it is important to have an icon, let an empty graphic be used 1881 // if no other graphic is provided 1882 // TODO/LATER: in future a default bitmap could be used 1883 ::rtl::OUString aMimeType; 1884 MapMode aMapMode( MAP_100TH_MM ); 1885 aGraphic.SetPrefSize( Size( 2500, 2500 ) ); 1886 aGraphic.SetPrefMapMode( aMapMode ); 1887 xObjRef.SetGraphic( aGraphic, aMimeType ); 1888 } 1889 1890 //Size einstellen. Ist ein Hack wg. Auslieferung, die Size sollte 1891 //an das InsertOle uebergeben werden!!!!!!!!!! 1892 Size aSize; 1893 if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON ) 1894 { 1895 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() ) 1896 aSize = aObjDesc.maSize; 1897 else 1898 { 1899 MapMode aMapMode( MAP_100TH_MM ); 1900 aSize = xObjRef.GetSize( &aMapMode ); 1901 } 1902 } 1903 else if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() ) 1904 { 1905 aSize = Size( aObjDesc.maSize ); //immer 100TH_MM 1906 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) ); 1907 aSize = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit ); 1908 awt::Size aSz; 1909 try 1910 { 1911 aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect ); 1912 } 1913 catch( embed::NoVisualAreaSizeException& ) 1914 { 1915 // in this case the provided size is used 1916 } 1917 1918 if ( aSz.Width != aSize.Width() || aSz.Height != aSize.Height() ) 1919 { 1920 aSz.Width = aSize.Width(); 1921 aSz.Height = aSize.Height(); 1922 xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz ); 1923 } 1924 } 1925 else 1926 { 1927 // the descriptor contains the wrong object size 1928 // the following call will let the MSOLE objects cache the size if it is possible 1929 // it should be done while the object is running 1930 try 1931 { 1932 xObj->getVisualAreaSize( aObjDesc.mnViewAspect ); 1933 } 1934 catch( uno::Exception& ) 1935 { 1936 } 1937 } 1938 //Ende mit Hack! 1939 1940 rSh.InsertOleObject( xObjRef ); 1941 nRet = 1; 1942 1943 if( nRet && ( nActionFlags & 1944 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) )) 1945 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False ); 1946 1947 // let the object be unloaded if possible 1948 SwOLEObj::UnloadObject( xObj, rSh.GetDoc(), embed::Aspects::MSOLE_CONTENT ); 1949 } 1950 } 1951 return nRet; 1952 } 1953 1954 // ----------------------------------------------------------------------- 1955 1956 1957 // ----------------------------------------------------------------------- 1958 1959 int SwTransferable::_PasteTargetURL( TransferableDataHelper& rData, 1960 SwWrtShell& rSh, sal_uInt16 nAction, 1961 const Point* pPt, sal_Bool bInsertGRF ) 1962 { 1963 int nRet = 0; 1964 INetImage aINetImg; 1965 if( ( rData.HasFormat( SOT_FORMATSTR_ID_INET_IMAGE ) && 1966 rData.GetINetImage( SOT_FORMATSTR_ID_INET_IMAGE, aINetImg )) || 1967 ( rData.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_IMAGE ) && 1968 rData.GetINetImage( SOT_FORMATSTR_ID_NETSCAPE_IMAGE, aINetImg )) ) 1969 { 1970 if( aINetImg.GetImageURL().Len() && bInsertGRF ) 1971 { 1972 String sURL( aINetImg.GetImageURL() ); 1973 SwTransferable::_CheckForURLOrLNKFile( rData, sURL ); 1974 1975 //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die 1976 // Grafiken zu testen !!!! 1977 Graphic aGrf; 1978 GraphicFilter *pFlt = GraphicFilter::GetGraphicFilter(); 1979 nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( sURL, aEmptyStr, aGrf, pFlt ); 1980 if( nRet ) 1981 { 1982 switch( nAction ) 1983 { 1984 case SW_PASTESDR_INSERT: 1985 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 1986 rSh.Insert( sURL, aEmptyStr, aGrf ); 1987 break; 1988 1989 case SW_PASTESDR_REPLACE: 1990 if( rSh.IsObjSelected() ) 1991 { 1992 rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf ); 1993 Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() ); 1994 SwTransferable::SetSelInShell( rSh, sal_True, &aPt ); 1995 } 1996 else 1997 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 1998 break; 1999 2000 case SW_PASTESDR_SETATTR: 2001 if( rSh.IsObjSelected() ) 2002 rSh.Paste( aGrf ); 2003 else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() ) 2004 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 2005 else 2006 { 2007 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2008 rSh.Insert( sURL, aEmptyStr, aGrf ); 2009 } 2010 break; 2011 default: 2012 nRet = 0; 2013 } 2014 } 2015 } 2016 else 2017 nRet = 1; 2018 } 2019 2020 if( nRet ) 2021 { 2022 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2023 rSh.GetFlyFrmAttr( aSet ); 2024 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2025 2026 if( aURL.GetURL() != aINetImg.GetTargetURL() || 2027 aURL.GetTargetFrameName() != aINetImg.GetTargetFrame() ) 2028 { 2029 aURL.SetURL( aINetImg.GetTargetURL(), sal_False ); 2030 aURL.SetTargetFrameName( aINetImg.GetTargetFrame() ); 2031 aSet.Put( aURL ); 2032 rSh.SetFlyFrmAttr( aSet ); 2033 } 2034 } 2035 return nRet; 2036 } 2037 2038 2039 // ----------------------------------------------------------------------- 2040 2041 void SwTransferable::SetSelInShell( SwWrtShell& rSh, sal_Bool bSelectFrm, 2042 const Point* pPt ) 2043 { 2044 if( bSelectFrm ) 2045 { 2046 // Rahmen/Objecte selektieren 2047 if( pPt && !rSh.GetView().GetViewFrame()->GetDispatcher()->IsLocked() ) 2048 { 2049 rSh.GetView().NoRotate(); 2050 if( rSh.SelectObj( *pPt )) 2051 { 2052 rSh.HideCrsr(); 2053 rSh.EnterSelFrmMode( pPt ); 2054 bFrmDrag = sal_True; 2055 } 2056 } 2057 } 2058 else 2059 { 2060 if( rSh.IsFrmSelected() || rSh.IsObjSelected() ) 2061 { 2062 rSh.UnSelectFrm(); 2063 rSh.LeaveSelFrmMode(); 2064 rSh.GetView().GetEditWin().StopInsFrm(); 2065 bFrmDrag = sal_False; 2066 } 2067 else if( rSh.GetView().GetDrawFuncPtr() ) 2068 rSh.GetView().GetEditWin().StopInsFrm(); 2069 2070 rSh.EnterStdMode(); 2071 if( pPt ) 2072 rSh.SwCrsrShell::SetCrsr( *pPt, sal_True ); 2073 } 2074 } 2075 2076 // ----------------------------------------------------------------------- 2077 2078 int SwTransferable::_PasteDDE( TransferableDataHelper& rData, 2079 SwWrtShell& rWrtShell, sal_Bool bReReadGrf, 2080 sal_Bool bMsg ) 2081 { 2082 // Daten aus dem Clipboardformat 2083 String aApp, aTopic, aItem; 2084 2085 { 2086 SotStorageStreamRef xStrm; 2087 if( !rData.GetSotStorageStream( SOT_FORMATSTR_ID_LINK, xStrm )) 2088 { 2089 ASSERT( !&rWrtShell, "DDE Data not found." ); 2090 return 0; 2091 } //sinnvollen Fehler melden!! 2092 2093 rtl_TextEncoding eEncoding = DDE_TXT_ENCODING; 2094 xStrm->ReadCString( aApp, eEncoding ); 2095 xStrm->ReadCString( aTopic, eEncoding ); 2096 xStrm->ReadCString( aItem, eEncoding ); 2097 } 2098 2099 String aCmd; 2100 sfx2::MakeLnkName( aCmd, &aApp, aTopic, aItem ); 2101 2102 // wollen wir jetzt eine Grafik einlesen ? 2103 sal_uLong nFormat; 2104 if( !rData.HasFormat( FORMAT_RTF ) && 2105 !rData.HasFormat( SOT_FORMATSTR_ID_HTML ) && 2106 !rData.HasFormat( FORMAT_STRING ) && 2107 (rData.HasFormat( nFormat = FORMAT_GDIMETAFILE ) || 2108 rData.HasFormat( nFormat = FORMAT_BITMAP )) ) 2109 { 2110 Graphic aGrf; 2111 int nRet = rData.GetGraphic( nFormat, aGrf ); 2112 if( nRet ) 2113 { 2114 String sLnkTyp( String::CreateFromAscii( 2115 RTL_CONSTASCII_STRINGPARAM( "DDE" ))); 2116 if ( bReReadGrf ) 2117 rWrtShell.ReRead( aCmd, sLnkTyp, &aGrf ); 2118 else 2119 rWrtShell.Insert( aCmd, sLnkTyp, aGrf ); 2120 } 2121 return nRet; 2122 } 2123 2124 SwFieldType* pTyp = 0; 2125 sal_uInt16 i = 1,j; 2126 String aName; 2127 sal_Bool bAlreadyThere = sal_False, bDoublePaste = sal_False; 2128 sal_uInt16 nSize = rWrtShell.GetFldTypeCount(); 2129 const ::utl::TransliterationWrapper& rColl = ::GetAppCmpStrIgnore(); 2130 2131 do { 2132 aName = aApp; 2133 aName += String::CreateFromInt32( i ); 2134 for( j = INIT_FLDTYPES; j < nSize; j++ ) 2135 { 2136 pTyp = rWrtShell.GetFldType( j ); 2137 if( RES_DDEFLD == pTyp->Which() ) 2138 { 2139 String sTmp( ((SwDDEFieldType*)pTyp)->GetCmd() ); 2140 if( rColl.isEqual( sTmp, aCmd ) && 2141 sfx2::LINKUPDATE_ALWAYS == ((SwDDEFieldType*)pTyp)->GetType() ) 2142 { 2143 aName = pTyp->GetName(); 2144 bDoublePaste = sal_True; 2145 break; 2146 } 2147 else if( rColl.isEqual( aName, pTyp->GetName() ) ) 2148 break; 2149 } 2150 } 2151 if( j == nSize ) 2152 bAlreadyThere = sal_False; 2153 else 2154 { 2155 bAlreadyThere = sal_True; 2156 i++; 2157 } 2158 } 2159 while( bAlreadyThere && !bDoublePaste ); 2160 2161 if( !bDoublePaste ) 2162 { 2163 SwDDEFieldType aType( aName, aCmd, sfx2::LINKUPDATE_ALWAYS ); 2164 pTyp = rWrtShell.InsertFldType( aType ); 2165 } 2166 2167 2168 SwDDEFieldType* pDDETyp = (SwDDEFieldType*)pTyp; 2169 2170 String aExpand; 2171 if( rData.GetString( FORMAT_STRING, aExpand )) 2172 { 2173 do { // middle checked loop 2174 2175 // Wenn die Daten von einer Tabellenkalkulation kommen 2176 // fuegen wir eine DDE-Tabelle ein 2177 if( ( rData.HasFormat( SOT_FORMATSTR_ID_SYLK ) || 2178 rData.HasFormat( SOT_FORMATSTR_ID_SYLK_BIGCAPS ) ) && 2179 aExpand.Len() && 2180 ( 1 < aExpand.GetTokenCount( '\n' ) || 2181 aExpand.GetTokenCount( '\t' )) ) 2182 { 2183 String sTmp( aExpand ); 2184 xub_StrLen nRows = sTmp.GetTokenCount( '\n' ); 2185 if( nRows ) 2186 --nRows; 2187 sTmp = sTmp.GetToken( 0, '\n' ); 2188 xub_StrLen nCols = sTmp.GetTokenCount( '\t' ); 2189 2190 // mindestens eine Spalte & Zeile muss vorhanden sein 2191 if( !nRows || !nCols ) 2192 { 2193 if( bMsg ) 2194 InfoBox(0, SW_RESSTR(STR_NO_TABLE)).Execute(); 2195 pDDETyp = 0; 2196 break; 2197 } 2198 2199 rWrtShell.InsertDDETable( 2200 SwInsertTableOptions( tabopts::HEADLINE_NO_BORDER, 1 ), // TODO MULTIHEADER 2201 pDDETyp, nRows, nCols ); 2202 } 2203 else if( 1 < aExpand.GetTokenCount( '\n' ) ) 2204 { 2205 // mehrere Absaetze -> eine geschuetzte Section einfuegen 2206 if( rWrtShell.HasSelection() ) 2207 rWrtShell.DelRight(); 2208 2209 SwSectionData aSect( DDE_LINK_SECTION, aName ); 2210 aSect.SetLinkFileName( aCmd ); 2211 aSect.SetProtectFlag(true); 2212 rWrtShell.InsertSection( aSect ); 2213 2214 pDDETyp = 0; // FeldTypen wieder entfernen 2215 } 2216 else 2217 { 2218 // Einfuegen 2219 SwDDEField aSwDDEField( pDDETyp ); 2220 rWrtShell.Insert( aSwDDEField ); 2221 } 2222 2223 } while( sal_False ); 2224 } 2225 else 2226 pDDETyp = 0; // FeldTypen wieder entfernen 2227 2228 if( !pDDETyp && !bDoublePaste ) 2229 { 2230 // FeldTyp wieder entfernen - Fehler aufgetreten! 2231 for( j = nSize; j >= INIT_FLDTYPES; --j ) 2232 if( pTyp == rWrtShell.GetFldType( j ) ) 2233 { 2234 rWrtShell.RemoveFldType( j ); 2235 break; 2236 } 2237 } 2238 2239 return 1; 2240 } 2241 2242 // ----------------------------------------------------------------------- 2243 2244 int SwTransferable::_PasteSdrFormat( TransferableDataHelper& rData, 2245 SwWrtShell& rSh, sal_uInt16 nAction, 2246 const Point* pPt, sal_uInt8 nActionFlags, bool bNeedToSelectBeforePaste) 2247 { 2248 int nRet = 0; 2249 SotStorageStreamRef xStrm; 2250 if( rData.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStrm )) 2251 { 2252 xStrm->SetVersion( SOFFICE_FILEFORMAT_50 ); 2253 2254 if(bNeedToSelectBeforePaste && pPt) 2255 { 2256 // if this is an internal drag, need to set the target right (select it), else 2257 // still the source will be selected 2258 SwTransferable::SetSelInShell( rSh, sal_True, pPt ); 2259 } 2260 2261 rSh.Paste( *xStrm, nAction, pPt ); 2262 nRet = 1; 2263 2264 if( nRet && ( nActionFlags & 2265 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) )) 2266 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False ); 2267 } 2268 return nRet; 2269 } 2270 2271 // ----------------------------------------------------------------------- 2272 2273 int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, 2274 sal_uLong nFmt, sal_uInt16 nAction, const Point* pPt, 2275 sal_uInt8 nActionFlags, sal_Int8 /* nDropAction */, bool bNeedToSelectBeforePaste) 2276 { 2277 int nRet = 0; 2278 2279 Graphic aGrf; 2280 INetBookmark aBkmk; 2281 sal_Bool bCheckForGrf = sal_False, bCheckForImageMap = sal_False; 2282 2283 switch( nFmt ) 2284 { 2285 case SOT_FORMAT_BITMAP: 2286 case SOT_FORMATSTR_ID_PNG: 2287 case SOT_FORMAT_GDIMETAFILE: 2288 nRet = rData.GetGraphic( nFmt, aGrf ); 2289 break; 2290 2291 case SOT_FORMATSTR_ID_SVXB: 2292 { 2293 SotStorageStreamRef xStm; 2294 2295 if(rData.GetSotStorageStream(SOT_FORMATSTR_ID_SVXB, xStm)) 2296 { 2297 *xStm >> aGrf; 2298 nRet = (GRAPHIC_NONE != aGrf.GetType() && GRAPHIC_DEFAULT != aGrf.GetType()); 2299 } 2300 2301 break; 2302 } 2303 2304 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: 2305 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 2306 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR: 2307 if( 0 != ( nRet = rData.GetINetBookmark( nFmt, aBkmk ) )) 2308 { 2309 /* if( SW_PASTESDR_SETATTR != nAction ) 2310 { 2311 INetURLObject aURL( aBkmk.GetURL() ); 2312 bCheckForGrf = INET_PROT_FILE == aURL.GetProtocol(); 2313 nRet = 0 != bCheckForGrf; 2314 } 2315 */ 2316 if( SW_PASTESDR_SETATTR == nAction ) 2317 nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK; 2318 else 2319 bCheckForGrf = sal_True; 2320 } 2321 break; 2322 2323 case SOT_FORMAT_FILE: 2324 { 2325 String sTxt; 2326 if( 0 != ( nRet = rData.GetString( nFmt, sTxt ) ) ) 2327 { 2328 String sDesc; 2329 SwTransferable::_CheckForURLOrLNKFile( rData, sTxt, &sDesc ); 2330 2331 aBkmk = INetBookmark( 2332 URIHelper::SmartRel2Abs(INetURLObject(), sTxt, Link(), false ), 2333 sDesc ); 2334 bCheckForGrf = sal_True; 2335 bCheckForImageMap = SW_PASTESDR_REPLACE == nAction; 2336 } 2337 } 2338 break; 2339 2340 default: 2341 nRet = rData.GetGraphic( nFmt, aGrf ); 2342 break; 2343 } 2344 2345 if( bCheckForGrf ) 2346 { 2347 //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die 2348 // Grafiken zu testen !!!! 2349 GraphicFilter *pFlt = GraphicFilter::GetGraphicFilter(); 2350 nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( aBkmk.GetURL(), aEmptyStr, 2351 aGrf, pFlt ); 2352 if( !nRet && SW_PASTESDR_SETATTR == nAction && 2353 SOT_FORMAT_FILE == nFmt && 2354 // Bug 63031 - nur bei Rahmenselektion 2355 rSh.IsFrmSelected() ) 2356 { 2357 // dann als Hyperlink hinter die Grafik setzen 2358 nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK; 2359 nRet = sal_True; 2360 } 2361 } 2362 2363 if(pPt && bNeedToSelectBeforePaste) 2364 { 2365 // when using internal D&Ds, still the source object is selected and 2366 // this is necessary to get the correct source data which is also 2367 // dependent from selection. After receiving the drag data it is 2368 // now tiime to select the correct target object 2369 SwTransferable::SetSelInShell( rSh, sal_True, pPt ); 2370 } 2371 2372 if( nRet ) 2373 { 2374 String sURL; 2375 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) 2376 sURL = aBkmk.GetURL(); 2377 2378 switch( nAction ) 2379 { 2380 case SW_PASTESDR_INSERT: 2381 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2382 rSh.Insert( sURL, aEmptyStr, aGrf ); 2383 break; 2384 2385 case SW_PASTESDR_REPLACE: 2386 if( rSh.IsObjSelected() ) 2387 { 2388 rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf ); 2389 Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() ); 2390 SwTransferable::SetSelInShell( rSh, sal_True, &aPt ); 2391 } 2392 else 2393 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 2394 break; 2395 2396 case SW_PASTESDR_SETATTR: 2397 if( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK == nFmt ) 2398 { 2399 if( rSh.IsFrmSelected() ) 2400 { 2401 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2402 rSh.GetFlyFrmAttr( aSet ); 2403 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2404 aURL.SetURL( aBkmk.GetURL(), sal_False ); 2405 aSet.Put( aURL ); 2406 rSh.SetFlyFrmAttr( aSet ); 2407 } 2408 } 2409 else if( rSh.IsObjSelected() ) 2410 rSh.Paste( aGrf ); 2411 else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() ) 2412 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 2413 else 2414 { 2415 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2416 rSh.Insert( aBkmk.GetURL(), aEmptyStr, aGrf ); 2417 } 2418 break; 2419 default: 2420 nRet = 0; 2421 } 2422 } 2423 2424 if( nRet ) 2425 { 2426 2427 if( nActionFlags & 2428 (( EXCHG_OUT_ACTION_FLAG_INSERT_IMAGEMAP | 2429 EXCHG_OUT_ACTION_FLAG_REPLACE_IMAGEMAP ) >> 8) ) 2430 SwTransferable::_PasteImageMap( rData, rSh ); 2431 2432 if( nActionFlags & 2433 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ) 2434 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False ); 2435 } 2436 else if( bCheckForImageMap ) 2437 { 2438 // oder sollte das File ein ImageMap-File sein? 2439 ImageMap aMap; 2440 SfxMedium aMed( INetURLObject(aBkmk.GetURL()).GetFull(), 2441 STREAM_STD_READ, sal_False ); 2442 SvStream* pStream = aMed.GetInStream(); 2443 if( pStream != NULL && 2444 !pStream->GetError() && 2445 // mba: no BaseURL for clipboard functionality 2446 aMap.Read( *pStream, IMAP_FORMAT_DETECT, String() ) == IMAP_ERR_OK && 2447 aMap.GetIMapObjectCount() ) 2448 { 2449 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2450 rSh.GetFlyFrmAttr( aSet ); 2451 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2452 aURL.SetMap( &aMap ); 2453 aSet.Put( aURL ); 2454 rSh.SetFlyFrmAttr( aSet ); 2455 nRet = 1; 2456 } 2457 } 2458 2459 return nRet; 2460 } 2461 2462 // ----------------------------------------------------------------------- 2463 2464 int SwTransferable::_PasteImageMap( TransferableDataHelper& rData, 2465 SwWrtShell& rSh ) 2466 { 2467 int nRet = 0; 2468 if( rData.HasFormat( SOT_FORMATSTR_ID_SVIM )) 2469 { 2470 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2471 rSh.GetFlyFrmAttr( aSet ); 2472 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2473 const ImageMap* pOld = aURL.GetMap(); 2474 2475 // setzen oder ersetzen ist hier die Frage 2476 ImageMap aImageMap; 2477 if( rData.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) && 2478 ( !pOld || aImageMap != *pOld )) 2479 { 2480 aURL.SetMap( &aImageMap ); 2481 aSet.Put( aURL ); 2482 rSh.SetFlyFrmAttr( aSet ); 2483 } 2484 nRet = 1; 2485 } 2486 return nRet; 2487 } 2488 2489 // ----------------------------------------------------------------------- 2490 2491 int SwTransferable::_PasteAsHyperlink( TransferableDataHelper& rData, 2492 SwWrtShell& rSh, sal_uLong nFmt ) 2493 { 2494 int nRet = 0; 2495 String sFile; 2496 if( rData.GetString( nFmt, sFile ) && sFile.Len() ) 2497 { 2498 String sDesc; 2499 SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc ); 2500 2501 //#41801# ersteinmal die URL absolut machen 2502 INetURLObject aURL; 2503 aURL.SetSmartProtocol( INET_PROT_FILE ); 2504 aURL.SetSmartURL( sFile ); 2505 sFile = aURL.GetMainURL( INetURLObject::NO_DECODE ); 2506 2507 switch( rSh.GetObjCntTypeOfSelection() ) 2508 { 2509 case OBJCNT_FLY: 2510 case OBJCNT_GRF: 2511 case OBJCNT_OLE: 2512 { 2513 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2514 rSh.GetFlyFrmAttr( aSet ); 2515 SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) ); 2516 aURL2.SetURL( sFile, sal_False ); 2517 if( !aURL2.GetName().Len() ) 2518 aURL2.SetName( sFile ); 2519 aSet.Put( aURL2 ); 2520 rSh.SetFlyFrmAttr( aSet ); 2521 } 2522 break; 2523 2524 default: 2525 { 2526 rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ), 2527 sDesc.Len() ? sDesc : sFile ); 2528 } 2529 } 2530 nRet = sal_True; 2531 } 2532 return nRet; 2533 } 2534 2535 // ----------------------------------------------------------------------- 2536 2537 int SwTransferable::_PasteFileName( TransferableDataHelper& rData, 2538 SwWrtShell& rSh, sal_uLong nFmt, 2539 sal_uInt16 nAction, const Point* pPt, 2540 sal_uInt8 nActionFlags, sal_Bool /* bMsg */) 2541 { 2542 int nRet = SwTransferable::_PasteGrf( rData, rSh, nFmt, nAction, 2543 pPt, nActionFlags, 0, false); 2544 if( nRet ) 2545 nRet |= SWTRANSFER_GRAPHIC_INSERTED; 2546 if( !nRet ) 2547 { 2548 String sFile, sDesc; 2549 if( rData.GetString( nFmt, sFile ) && sFile.Len() ) 2550 { 2551 INetURLObject aMediaURL; 2552 2553 aMediaURL.SetSmartURL( sFile ); 2554 const String aMediaURLStr( aMediaURL.GetMainURL( INetURLObject::NO_DECODE ) ); 2555 2556 if( ::avmedia::MediaWindow::isMediaURL( aMediaURLStr ) ) 2557 { 2558 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aMediaURLStr ); 2559 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( 2560 SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON, 2561 &aMediaURLItem, 0L ); 2562 } 2563 else 2564 { 2565 sal_Bool bIsURLFile = SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc ); 2566 2567 //Eigenes FileFormat? -->Einfuegen, nicht fuer StarWriter/Web 2568 String sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link(), false ); 2569 const SfxFilter* pFlt = SW_PASTESDR_SETATTR == nAction 2570 ? 0 : SwIoSystem::GetFileFilter( 2571 sFileURL, aEmptyStr ); 2572 if( pFlt && !rSh.GetView().GetDocShell()->ISA(SwWebDocShell) 2573 /* 2574 JP 02.07.98: warum nur fuer die Formate ?? 2575 && ( pFlt->GetUserData() == FILTER_SW5 || 2576 pFlt->GetUserData() == FILTER_SW4 || 2577 pFlt->GetUserData() == FILTER_SW3 || 2578 pFlt->GetUserData() == FILTER_SWG ) 2579 */ 2580 ) 2581 { 2582 // und dann per PostUser Event den Bereich-Einfuegen-Dialog hochreissen 2583 SwSectionData * pSect = new SwSectionData( 2584 FILE_LINK_SECTION, 2585 rSh.GetDoc()->GetUniqueSectionName() ); 2586 pSect->SetLinkFileName( sFileURL ); 2587 pSect->SetProtectFlag( true ); 2588 2589 Application::PostUserEvent( STATIC_LINK( &rSh, SwWrtShell, 2590 InsertRegionDialog ), pSect ); 2591 nRet = 1; 2592 } 2593 else if( SW_PASTESDR_SETATTR == nAction || 2594 ( bIsURLFile && SW_PASTESDR_INSERT == nAction )) 2595 { 2596 //Fremde Files koennen wir immerhin noch als Links 2597 //Einfuegen. 2598 2599 //#41801# ersteinmal die URL absolut machen 2600 INetURLObject aURL; 2601 aURL.SetSmartProtocol( INET_PROT_FILE ); 2602 aURL.SetSmartURL( sFile ); 2603 sFile = aURL.GetMainURL( INetURLObject::NO_DECODE ); 2604 2605 switch( rSh.GetObjCntTypeOfSelection() ) 2606 { 2607 case OBJCNT_FLY: 2608 case OBJCNT_GRF: 2609 case OBJCNT_OLE: 2610 { 2611 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2612 rSh.GetFlyFrmAttr( aSet ); 2613 SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) ); 2614 aURL2.SetURL( sFile, sal_False ); 2615 if( !aURL2.GetName().Len() ) 2616 aURL2.SetName( sFile ); 2617 aSet.Put( aURL2 ); 2618 rSh.SetFlyFrmAttr( aSet ); 2619 } 2620 break; 2621 2622 default: 2623 { 2624 rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ), 2625 sDesc.Len() ? sDesc : sFile ); 2626 } 2627 } 2628 nRet = sal_True; 2629 } 2630 } 2631 } 2632 } 2633 return nRet; 2634 } 2635 2636 // ----------------------------------------------------------------------- 2637 2638 int SwTransferable::_PasteDBData( TransferableDataHelper& rData, 2639 SwWrtShell& rSh, sal_uLong nFmt, sal_Bool bLink, 2640 const Point* pDragPt, sal_Bool bMsg ) 2641 { 2642 int nRet = 0; 2643 String sTxt; 2644 if( rData.GetString( nFmt, sTxt ) && sTxt.Len() ) 2645 { 2646 sal_uInt16 nWh = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == nFmt 2647 ? 0 2648 : SOT_FORMATSTR_ID_SBA_DATAEXCHANGE == nFmt 2649 ? (bLink 2650 ? FN_QRY_MERGE_FIELD 2651 : FN_QRY_INSERT) 2652 : (bLink 2653 ? 0 2654 : FN_QRY_INSERT_FIELD ); 2655 DataFlavorExVector& rVector = rData.GetDataFlavorExVector(); 2656 sal_Bool bHaveColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(rVector, CTF_COLUMN_DESCRIPTOR | CTF_CONTROL_EXCHANGE); 2657 if ( SOT_FORMATSTR_ID_XFORMS == nFmt ) 2658 { 2659 SdrObject* pObj; 2660 rSh.MakeDrawView(); 2661 FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() ); 2662 if(pFmView) { 2663 const OXFormsDescriptor &rDesc = OXFormsTransferable::extractDescriptor(rData); 2664 if(0 != (pObj = pFmView->CreateXFormsControl(rDesc))) 2665 { 2666 rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt ); 2667 } 2668 } 2669 } 2670 else if( nWh ) 2671 { 2672 SfxUsrAnyItem* pConnectionItem = 0; 2673 SfxUsrAnyItem* pCursorItem = 0; 2674 SfxUsrAnyItem* pColumnItem = 0; 2675 SfxUsrAnyItem* pSourceItem = 0; 2676 SfxUsrAnyItem* pCommandItem = 0; 2677 SfxUsrAnyItem* pCommandTypeItem = 0; 2678 SfxUsrAnyItem* pColumnNameItem = 0; 2679 SfxUsrAnyItem* pSelectionItem = 0; 2680 2681 sal_Bool bDataAvailable = sal_True; 2682 ODataAccessDescriptor aDesc; 2683 if(bHaveColumnDescriptor) 2684 aDesc = OColumnTransferable::extractColumnDescriptor(rData); 2685 else if(ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) ) 2686 aDesc = ODataAccessObjectTransferable::extractObjectDescriptor(rData); 2687 else 2688 bDataAvailable = sal_False; 2689 2690 if ( bDataAvailable ) 2691 { 2692 pConnectionItem = new SfxUsrAnyItem(FN_DB_CONNECTION_ANY, aDesc[daConnection]); 2693 pColumnItem = new SfxUsrAnyItem(FN_DB_COLUMN_ANY, aDesc[daColumnObject]); 2694 pSourceItem = new SfxUsrAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource())); 2695 pCommandItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[daCommand]); 2696 pCommandTypeItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[daCommandType]); 2697 pColumnNameItem = new SfxUsrAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[daColumnName]); 2698 pSelectionItem = new SfxUsrAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[daSelection]); 2699 pCursorItem = new SfxUsrAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[daCursor]); 2700 } 2701 2702 SwView& rView = rSh.GetView(); 2703 //force ::SelectShell 2704 rView.StopShellTimer(); 2705 2706 SfxStringItem aDataDesc( nWh, sTxt ); 2707 rView.GetViewFrame()->GetDispatcher()->Execute( 2708 nWh, SFX_CALLMODE_ASYNCHRON, &aDataDesc, 2709 pConnectionItem, pColumnItem, 2710 pSourceItem, pCommandItem, pCommandTypeItem, 2711 pColumnNameItem, pSelectionItem, pCursorItem,0L); 2712 delete pConnectionItem; 2713 delete pColumnItem; 2714 delete pSourceItem; 2715 delete pCommandItem; 2716 delete pCommandTypeItem; 2717 delete pColumnNameItem; 2718 delete pCursorItem; 2719 } 2720 else 2721 { 2722 SdrObject* pObj; 2723 rSh.MakeDrawView(); 2724 FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() ); 2725 if (pFmView && bHaveColumnDescriptor) 2726 { 2727 if ( 0 != (pObj = pFmView->CreateFieldControl( OColumnTransferable::extractColumnDescriptor(rData) ) ) ) 2728 rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt ); 2729 } 2730 } 2731 nRet = 1; 2732 } 2733 else if( bMsg ) 2734 { 2735 InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute(); 2736 } 2737 return nRet; 2738 } 2739 2740 // ----------------------------------------------------------------------- 2741 2742 int SwTransferable::_PasteFileList( TransferableDataHelper& rData, 2743 SwWrtShell& rSh, sal_Bool bLink, 2744 const Point* pPt, sal_Bool bMsg ) 2745 { 2746 int nRet = 0; 2747 FileList aFileList; 2748 if( rData.GetFileList( SOT_FORMAT_FILE_LIST, aFileList ) && 2749 aFileList.Count() ) 2750 { 2751 sal_uInt16 nAct = bLink ? SW_PASTESDR_SETATTR : SW_PASTESDR_INSERT; 2752 String sFlyNm; 2753 // iterate over the filelist 2754 for( sal_uLong n = 0, nEnd = aFileList.Count(); n < nEnd; ++n ) 2755 { 2756 TransferDataContainer* pHlp = new TransferDataContainer; 2757 pHlp->CopyString( FORMAT_FILE, aFileList.GetFile( n )); 2758 TransferableDataHelper aData( pHlp ); 2759 2760 if( SwTransferable::_PasteFileName( aData, rSh, SOT_FORMAT_FILE, nAct, 2761 pPt, sal_False, bMsg )) 2762 { 2763 if( bLink ) 2764 { 2765 sFlyNm = rSh.GetFlyName(); 2766 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2767 } 2768 nRet = 1; 2769 } 2770 } 2771 if( sFlyNm.Len() ) 2772 rSh.GotoFly( sFlyNm ); 2773 } 2774 else if( bMsg ) 2775 { 2776 InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute(); 2777 } 2778 return nRet; 2779 } 2780 2781 // ----------------------------------------------------------------------- 2782 2783 sal_Bool SwTransferable::_CheckForURLOrLNKFile( TransferableDataHelper& rData, 2784 String& rFileName, String* pTitle ) 2785 { 2786 sal_Bool bIsURLFile = sal_False; 2787 INetBookmark aBkmk; 2788 if( rData.GetINetBookmark( SOT_FORMATSTR_ID_SOLK, aBkmk ) ) 2789 { 2790 rFileName = aBkmk.GetURL(); 2791 if( pTitle ) 2792 *pTitle = aBkmk.GetDescription(); 2793 bIsURLFile = sal_True; 2794 } 2795 else 2796 { 2797 xub_StrLen nLen = rFileName.Len(); 2798 if( 4 < nLen && '.' == rFileName.GetChar( nLen - 4 )) 2799 { 2800 String sExt( rFileName.Copy( nLen - 3 )); 2801 if( sExt.EqualsIgnoreCaseAscii( "url" )) 2802 { 2803 ASSERT( !&rFileName, "how do we read today .URL - Files?" ); 2804 } 2805 } 2806 } 2807 return bIsURLFile; 2808 } 2809 2810 // ----------------------------------------------------------------------- 2811 2812 sal_Bool SwTransferable::IsPasteSpecial( const SwWrtShell& rWrtShell, 2813 const TransferableDataHelper& rData ) 2814 { 2815 // we can paste-special if there's an entry in the paste-special-format list 2816 SvxClipboardFmtItem aClipboardFmtItem(0); 2817 FillClipFmtItem( rWrtShell, rData, aClipboardFmtItem); 2818 return aClipboardFmtItem.Count() > 0; 2819 } 2820 2821 // ----------------------------------------------------------------------- 2822 2823 int SwTransferable::PasteFormat( SwWrtShell& rSh, 2824 TransferableDataHelper& rData, 2825 sal_uLong nFormat ) 2826 { 2827 SwWait aWait( *rSh.GetView().GetDocShell(), sal_False ); 2828 int nRet = 0; 2829 2830 sal_uLong nPrivateFmt = FORMAT_PRIVATE; 2831 SwTransferable *pClipboard = GetSwTransferable( rData ); 2832 if( pClipboard && 2833 ((TRNSFR_DOCUMENT|TRNSFR_GRAPHIC|TRNSFR_OLE) & pClipboard->eBufferType )) 2834 nPrivateFmt = SOT_FORMATSTR_ID_EMBED_SOURCE; 2835 2836 if( pClipboard && nPrivateFmt == nFormat ) 2837 nRet = pClipboard->PrivatePaste( rSh ); 2838 else if( rData.HasFormat( nFormat ) ) 2839 { 2840 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() ); 2841 sal_uInt16 nEventAction, 2842 nDestination = SwTransferable::GetSotDestination( rSh ), 2843 nSourceOptions = 2844 (( EXCHG_DEST_DOC_TEXTFRAME == nDestination || 2845 EXCHG_DEST_SWDOC_FREE_AREA == nDestination || 2846 EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination || 2847 EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination ) 2848 ? EXCHG_IN_ACTION_COPY 2849 : EXCHG_IN_ACTION_MOVE), 2850 nAction = SotExchange::GetExchangeAction( 2851 rData.GetDataFlavorExVector(), 2852 nDestination, 2853 nSourceOptions, /* ?? */ 2854 EXCHG_IN_ACTION_DEFAULT, /* ?? */ 2855 nFormat, nEventAction, nFormat, 2856 lcl_getTransferPointer ( xTransferable ) ); 2857 2858 if( EXCHG_INOUT_ACTION_NONE != nAction ) 2859 nRet = SwTransferable::PasteData( rData, rSh, nAction, nFormat, 2860 nDestination, sal_True, sal_False ); 2861 } 2862 return nRet; 2863 } 2864 2865 // ----------------------------------------------------------------------- 2866 2867 int SwTransferable::_TestAllowedFormat( const TransferableDataHelper& rData, 2868 sal_uLong nFormat, sal_uInt16 nDestination ) 2869 { 2870 sal_uInt16 nAction = EXCHG_INOUT_ACTION_NONE, nEventAction; 2871 if( rData.HasFormat( nFormat )) { 2872 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() ); 2873 nAction = SotExchange::GetExchangeAction( 2874 rData.GetDataFlavorExVector(), 2875 nDestination, EXCHG_IN_ACTION_COPY, 2876 EXCHG_IN_ACTION_COPY, nFormat, 2877 nEventAction, nFormat, 2878 lcl_getTransferPointer ( xTransferable ) ); 2879 } 2880 return EXCHG_INOUT_ACTION_NONE != nAction; 2881 } 2882 2883 // ----------------------------------------------------------------------- 2884 2885 /** 2886 * the list of formats which will be offered to the user in the 'Paste 2887 * Special...' dialog and the paste button menu 2888 */ 2889 static sal_uInt16 aPasteSpecialIds[] = 2890 { 2891 SOT_FORMATSTR_ID_HTML, 2892 SOT_FORMATSTR_ID_HTML_SIMPLE, 2893 SOT_FORMATSTR_ID_HTML_NO_COMMENT, 2894 FORMAT_RTF, 2895 FORMAT_STRING, 2896 SOT_FORMATSTR_ID_SONLK, 2897 SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, 2898 SOT_FORMATSTR_ID_DRAWING, 2899 SOT_FORMATSTR_ID_SVXB, 2900 FORMAT_GDIMETAFILE, 2901 FORMAT_BITMAP, 2902 SOT_FORMATSTR_ID_SVIM, 2903 SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, 2904 0 2905 }; 2906 2907 2908 int SwTransferable::PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper& rData ) 2909 { 2910 // Plain text == unformatted 2911 return SwTransferable::PasteFormat( rSh, rData, SOT_FORMAT_STRING ); 2912 } 2913 2914 // ----------------------------------------------------------------------- 2915 2916 int SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, sal_uLong& rFormatUsed ) 2917 { 2918 int nRet = 0; 2919 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 2920 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rSh.GetView().GetEditWin() ); 2921 2922 DataFlavorExVector aFormats( rData.GetDataFlavorExVector() ); 2923 TransferableObjectDescriptor aDesc; 2924 2925 sal_uInt16 nDest = SwTransferable::GetSotDestination( rSh ); 2926 2927 SwTransferable *pClipboard = GetSwTransferable( rData ); 2928 if( pClipboard ) 2929 { 2930 aDesc = pClipboard->aObjDesc; 2931 sal_uInt16 nResId; 2932 if( pClipboard->eBufferType & TRNSFR_DOCUMENT ) 2933 nResId = STR_PRIVATETEXT; 2934 else if( pClipboard->eBufferType & TRNSFR_GRAPHIC ) 2935 nResId = STR_PRIVATEGRAPHIC; 2936 else if( pClipboard->eBufferType == TRNSFR_OLE ) 2937 nResId = STR_PRIVATEOLE; 2938 else 2939 nResId = 0; 2940 2941 if( nResId ) 2942 { 2943 if( STR_PRIVATEOLE == nResId || STR_PRIVATEGRAPHIC == nResId ) 2944 { 2945 // add SOT_FORMATSTR_ID_EMBED_SOURCE to the formats. This 2946 // format display then the private format name. 2947 DataFlavorEx aFlavorEx; 2948 aFlavorEx.mnSotId = SOT_FORMATSTR_ID_EMBED_SOURCE; 2949 aFormats.insert( aFormats.begin(), aFlavorEx ); 2950 } 2951 pDlg->SetObjName( pClipboard->aObjDesc.maClassName, 2952 SW_RES( nResId ) ); 2953 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr ); 2954 } 2955 } 2956 else 2957 { 2958 if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) ) 2959 rData.GetTransferableObjectDescriptor( 2960 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc ); 2961 2962 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest )) 2963 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr ); 2964 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest )) 2965 pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyStr ); 2966 } 2967 2968 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest )) 2969 pDlg->Insert( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) ); 2970 2971 for( sal_uInt16* pIds = aPasteSpecialIds; *pIds; ++pIds ) 2972 if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest )) 2973 pDlg->Insert( *pIds, aEmptyStr ); 2974 2975 sal_uLong nFormat = pDlg->GetFormat( rData.GetTransferable() ); 2976 2977 if( nFormat ) 2978 nRet = SwTransferable::PasteFormat( rSh, rData, nFormat ); 2979 2980 if ( nRet ) 2981 rFormatUsed = nFormat; 2982 2983 delete pDlg; 2984 return nRet; 2985 } 2986 2987 2988 void SwTransferable::FillClipFmtItem( const SwWrtShell& rSh, 2989 const TransferableDataHelper& rData, 2990 SvxClipboardFmtItem & rToFill ) 2991 { 2992 sal_uInt16 nDest = SwTransferable::GetSotDestination( rSh ); 2993 2994 SwTransferable *pClipboard = GetSwTransferable( rData ); 2995 if( pClipboard ) 2996 { 2997 sal_uInt16 nResId; 2998 if( pClipboard->eBufferType & TRNSFR_DOCUMENT ) 2999 nResId = STR_PRIVATETEXT; 3000 else if( pClipboard->eBufferType & TRNSFR_GRAPHIC ) 3001 nResId = STR_PRIVATEGRAPHIC; 3002 else if( pClipboard->eBufferType == TRNSFR_OLE ) 3003 nResId = STR_PRIVATEOLE; 3004 else 3005 nResId = 0; 3006 3007 if( nResId ) 3008 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE, 3009 SW_RES( nResId ) ); 3010 } 3011 else 3012 { 3013 TransferableObjectDescriptor aDesc; 3014 if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) ) 3015 ((TransferableDataHelper&)rData).GetTransferableObjectDescriptor( 3016 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc ); 3017 3018 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest )) 3019 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE, 3020 aDesc.maTypeName ); 3021 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest )) 3022 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK_SOURCE ); 3023 3024 SotFormatStringId nFormat; 3025 if ( rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE) || rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE) ) 3026 { 3027 String sName,sSource; 3028 if ( SvPasteObjectHelper::GetEmbeddedName(rData,sName,sSource,nFormat) ) 3029 rToFill.AddClipbrdFormat( nFormat, sName ); 3030 } 3031 } 3032 3033 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest )) 3034 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) ); 3035 3036 for( sal_uInt16* pIds = aPasteSpecialIds; *pIds; ++pIds ) 3037 if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest )) 3038 rToFill.AddClipbrdFormat( *pIds, aEmptyStr ); 3039 } 3040 3041 void SwTransferable::SetDataForDragAndDrop( const Point& rSttPos ) 3042 { 3043 if(!pWrtShell) 3044 return; 3045 String sGrfNm; 3046 const int nSelection = pWrtShell->GetSelectionType(); 3047 if( nsSelectionType::SEL_GRF == nSelection) 3048 { 3049 AddFormat( SOT_FORMATSTR_ID_SVXB ); 3050 // --> OD 2005-02-09 #119353# - robust 3051 const Graphic* pGrf = pWrtShell->GetGraphic(); 3052 if ( pGrf && pGrf->IsSupportedGraphic() ) 3053 // <-- 3054 { 3055 AddFormat( FORMAT_GDIMETAFILE ); 3056 AddFormat( SOT_FORMATSTR_ID_PNG ); 3057 AddFormat( FORMAT_BITMAP ); 3058 } 3059 eBufferType = TRNSFR_GRAPHIC; 3060 pWrtShell->GetGrfNms( &sGrfNm, 0 ); 3061 } 3062 else if( nsSelectionType::SEL_OLE == nSelection ) 3063 { 3064 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 3065 PrepareOLE( aObjDesc ); 3066 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 3067 AddFormat( FORMAT_GDIMETAFILE ); 3068 eBufferType = TRNSFR_OLE; 3069 } 3070 //Gibt es ueberhaupt etwas zum bereitstellen? 3071 else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() || 3072 pWrtShell->IsObjSelected() ) 3073 { 3074 if( pWrtShell->IsObjSelected() ) 3075 eBufferType = TRNSFR_DRAWING; 3076 else 3077 { 3078 eBufferType = TRNSFR_DOCUMENT; 3079 if( SwWrtShell::NO_WORD != 3080 pWrtShell->IntelligentCut( nSelection, sal_False )) 3081 eBufferType = TransferBufferType( TRNSFR_DOCUMENT_WORD 3082 | eBufferType); 3083 } 3084 3085 if( nSelection & nsSelectionType::SEL_TBL_CELLS ) 3086 eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType); 3087 3088 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 3089 3090 //RTF vor das Metafile von OLE stellen, weil mit weniger verlusten 3091 //behaftet. 3092 if( !pWrtShell->IsObjSelected() ) 3093 { 3094 AddFormat( FORMAT_RTF ); 3095 AddFormat( SOT_FORMATSTR_ID_HTML ); 3096 } 3097 if( pWrtShell->IsSelection() ) 3098 AddFormat( FORMAT_STRING ); 3099 3100 if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM )) 3101 { 3102 AddFormat( SOT_FORMATSTR_ID_DRAWING ); 3103 if ( nSelection & nsSelectionType::SEL_DRW ) 3104 { 3105 AddFormat( FORMAT_GDIMETAFILE ); 3106 AddFormat( SOT_FORMATSTR_ID_PNG ); 3107 AddFormat( FORMAT_BITMAP ); 3108 } 3109 eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType ); 3110 3111 pClpGraphic = new Graphic; 3112 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic )) 3113 pOrigGrf = pClpGraphic; 3114 pClpBitmap = new Graphic; 3115 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap )) 3116 pOrigGrf = pClpBitmap; 3117 3118 // ist es ein URL-Button ? 3119 String sURL, sDesc; 3120 if( pWrtShell->GetURLFromButton( sURL, sDesc ) ) 3121 { 3122 AddFormat( FORMAT_STRING ); 3123 AddFormat( SOT_FORMATSTR_ID_SOLK ); 3124 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ); 3125 AddFormat( SOT_FORMATSTR_ID_FILECONTENT ); 3126 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ); 3127 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ); 3128 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType ); 3129 } 3130 } 3131 3132 //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt. 3133 //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage 3134 //auch noch mit delayed rendering beantwortet werden. 3135 aObjDesc.mbCanLink = sal_False; 3136 aObjDesc.maDragStartPos = rSttPos; 3137 aObjDesc.maSize = OutputDevice::LogicToLogic( Size( OLESIZE ), 3138 MAP_TWIP, MAP_100TH_MM ); 3139 PrepareOLE( aObjDesc ); 3140 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 3141 } 3142 else if( nSelection & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() ) 3143 { 3144 // ist nur ein Feld - Selektiert? 3145 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR ); 3146 Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY()); 3147 3148 if( pWrtShell->GetContentAtPos( aPos, aCntntAtPos ) ) 3149 { 3150 AddFormat( FORMAT_STRING ); 3151 AddFormat( SOT_FORMATSTR_ID_SOLK ); 3152 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ); 3153 AddFormat( SOT_FORMATSTR_ID_FILECONTENT ); 3154 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ); 3155 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ); 3156 eBufferType = TRNSFR_INETFLD; 3157 } 3158 } 3159 3160 if( pWrtShell->IsFrmSelected() ) 3161 { 3162 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL ); 3163 pWrtShell->GetFlyFrmAttr( aSet ); 3164 const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL ); 3165 if( rURL.GetMap() ) 3166 { 3167 pImageMap = new ImageMap( *rURL.GetMap() ); 3168 AddFormat( SOT_FORMATSTR_ID_SVIM ); 3169 } 3170 else if( rURL.GetURL().Len() ) 3171 { 3172 pTargetURL = new INetImage( sGrfNm, rURL.GetURL(), 3173 rURL.GetTargetFrameName(), 3174 aEmptyStr, Size() ); 3175 AddFormat( SOT_FORMATSTR_ID_INET_IMAGE ); 3176 } 3177 } 3178 } 3179 3180 void SwTransferable::StartDrag( Window* pWin, const Point& rPos ) 3181 { 3182 if(!pWrtShell) 3183 return; 3184 bOldIdle = pWrtShell->GetViewOptions()->IsIdle(); 3185 bCleanUp = sal_True; 3186 3187 ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( sal_False ); 3188 3189 if( pWrtShell->IsSelFrmMode() ) 3190 pWrtShell->ShowCrsr(); 3191 3192 SW_MOD()->pDragDrop = this; 3193 3194 SetDataForDragAndDrop( rPos ); 3195 3196 sal_Int8 nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK; 3197 SwDocShell* pDShell = pWrtShell->GetView().GetDocShell(); 3198 if( ( pDShell && pDShell->IsReadOnly() ) || pWrtShell->HasReadonlySel() ) 3199 nDragOptions &= ~DND_ACTION_MOVE; 3200 3201 TransferableHelper::StartDrag( pWin, nDragOptions ); 3202 } 3203 3204 void SwTransferable::DragFinished( sal_Int8 nAction ) 3205 { 3206 //Und noch die letzten Nacharbeiten damit alle Stati stimmen. 3207 if( DND_ACTION_MOVE == nAction ) 3208 { 3209 if( bCleanUp ) 3210 { 3211 //Es wurde auserhalb des Writers gedroped. Wir muessen noch 3212 //loeschen. 3213 3214 pWrtShell->StartAllAction(); 3215 pWrtShell->StartUndo( UNDO_UI_DRAG_AND_MOVE ); 3216 if ( pWrtShell->IsTableMode() ) 3217 pWrtShell->DeleteTblSel(); 3218 else 3219 { 3220 if ( !(pWrtShell->IsSelFrmMode() || pWrtShell->IsObjSelected()) ) 3221 //SmartCut, eines der Blanks mitnehmen. 3222 pWrtShell->IntelligentCut( pWrtShell->GetSelectionType(), sal_True ); 3223 pWrtShell->DelRight(); 3224 } 3225 pWrtShell->EndUndo( UNDO_UI_DRAG_AND_MOVE ); 3226 pWrtShell->EndAllAction(); 3227 } 3228 else 3229 { 3230 const int nSelection = pWrtShell->GetSelectionType(); 3231 if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF | 3232 nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW ) & nSelection ) 3233 { 3234 pWrtShell->EnterSelFrmMode(); 3235 } 3236 } 3237 } 3238 pWrtShell->GetView().GetEditWin().DragFinished(); 3239 3240 if( pWrtShell->IsSelFrmMode() ) 3241 pWrtShell->HideCrsr(); 3242 else 3243 pWrtShell->ShowCrsr(); 3244 //!! else if( DND_ACTION_NONE != nAction ) 3245 //!! pWrtShell->ShowCrsr(); 3246 //!! else 3247 //!! { 3248 //!! //Muss wohl sein weil gescrollt wurde und ?...? 3249 //!! pWrtShell->StartAction(); 3250 //!! pWrtShell->EndAction(); 3251 //!! } 3252 3253 ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( bOldIdle ); 3254 } 3255 3256 3257 /* */ 3258 3259 int SwTransferable::PrivatePaste( SwWrtShell& rShell ) 3260 { 3261 // erst den SelectionType erfragen, dann Action-Klammerung !!!! 3262 // (sonst wird nicht in eine TabellenSelektion gepastet!!!) 3263 ASSERT( !rShell.ActionPend(), "Paste darf nie eine Actionklammerung haben" ); 3264 if ( !pClpDocFac ) 3265 return sal_False; // the return value of the SwFEShell::Paste also is sal_Bool! 3266 3267 const int nSelection = rShell.GetSelectionType(); 3268 3269 // #111827# 3270 SwRewriter aRewriter; 3271 3272 SwTrnsfrActionAndUndo aAction( &rShell, UNDO_PASTE_CLIPBOARD); 3273 3274 bool bKillPaMs = false; 3275 3276 //Selektierten Inhalt loeschen, nicht bei Tabellen-Selektion und 3277 //Tabelle im Clipboard 3278 if( rShell.HasSelection() && !( nSelection & nsSelectionType::SEL_TBL_CELLS)) 3279 { 3280 bKillPaMs = true; 3281 rShell.SetRetainSelection( true ); 3282 rShell.DelRight(); 3283 // war ein Fly selektiert, so muss jetzt fuer eine gueltige 3284 // Cursor-Position gesorgt werden! (geparkter Cursor!) 3285 if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF | 3286 nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW | 3287 nsSelectionType::SEL_DRW_FORM ) & nSelection ) 3288 { 3289 // den Cursor wieder positionieren 3290 Point aPt( rShell.GetCharRect().Pos() ); 3291 rShell.SwCrsrShell::SetCrsr( aPt, sal_True ); 3292 } 3293 rShell.SetRetainSelection( false ); 3294 } 3295 3296 sal_Bool bInWrd = sal_False, bEndWrd = sal_False, bSttWrd = sal_False, 3297 bSmart = 0 != (TRNSFR_DOCUMENT_WORD & eBufferType); 3298 if( bSmart ) 3299 { 3300 // #108491# Why not for other Scripts? If TRNSFR_DOCUMENT_WORD is set, we have 3301 // a word in the buffer, word in this context means 'something with spaces at 3302 // beginning and end'. In this case we definitely want these spaces to be inserted 3303 // here. 3304 // if( SCRIPTTYPE_LATIN != rShell.GetScriptType() ) 3305 // bSmart = sal_False; 3306 // else 3307 // { 3308 bInWrd = rShell.IsInWrd(); 3309 bEndWrd = rShell.IsEndWrd(); 3310 bSmart = bInWrd || bEndWrd; 3311 if( bSmart ) 3312 { 3313 bSttWrd = rShell.IsSttWrd(); 3314 if( bSmart && !bSttWrd && (bInWrd || bEndWrd) ) 3315 rShell.SwEditShell::Insert(' '); 3316 } 3317 // } 3318 } 3319 3320 int nRet = rShell.Paste( pClpDocFac->GetDoc() ); 3321 3322 if( bKillPaMs ) 3323 rShell.KillPams(); 3324 3325 // Wenn Smart Paste dann Leerzeichen einfuegen 3326 if( nRet && bSmart && ((bInWrd && !bEndWrd )|| bSttWrd) ) 3327 rShell.SwEditShell::Insert(' '); 3328 3329 return nRet; 3330 } 3331 3332 int SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt, 3333 sal_Bool bMove, sal_Bool bIsXSelection ) 3334 { 3335 int cWord = 0; 3336 sal_Bool bInWrd = sal_False; 3337 sal_Bool bEndWrd = sal_False; 3338 sal_Bool bSttWrd = sal_False; 3339 sal_Bool bSttPara= sal_False; 3340 sal_Bool bTblSel = sal_False; 3341 sal_Bool bFrmSel = sal_False; 3342 3343 SwWrtShell& rSrcSh = *GetShell(); 3344 3345 rSh.UnSetVisCrsr(); 3346 3347 if( TRNSFR_INETFLD == eBufferType ) 3348 { 3349 if( rSh.GetFmtFromObj( rDragPt ) ) 3350 { 3351 INetBookmark aTmp; 3352 if( (TRNSFR_INETFLD & eBufferType) && pBkmk ) 3353 aTmp = *pBkmk; 3354 3355 // Zielgrafik selektieren 3356 if( rSh.SelectObj( rDragPt ) ) 3357 { 3358 rSh.HideCrsr(); 3359 rSh.EnterSelFrmMode( &rDragPt ); 3360 bFrmDrag = sal_True; 3361 } 3362 3363 const int nSelection = rSh.GetSelectionType(); 3364 3365 // Draw-Objekte erstmal noch nicht beruecksichtigen 3366 if( nsSelectionType::SEL_GRF & nSelection ) 3367 { 3368 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 3369 rSh.GetFlyFrmAttr( aSet ); 3370 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 3371 aURL.SetURL( aTmp.GetURL(), sal_False ); 3372 aSet.Put( aURL ); 3373 rSh.SetFlyFrmAttr( aSet ); 3374 return 1; 3375 } 3376 3377 if( nsSelectionType::SEL_DRW & nSelection ) 3378 { 3379 rSh.LeaveSelFrmMode(); 3380 rSh.UnSelectFrm(); 3381 rSh.ShowCrsr(); 3382 bFrmDrag = sal_False; 3383 } 3384 } 3385 } 3386 3387 if( &rSh != &rSrcSh && (nsSelectionType::SEL_GRF & rSh.GetSelectionType()) && 3388 TRNSFR_GRAPHIC == eBufferType ) 3389 { 3390 // ReRead auf die Grafik 3391 String sGrfNm, sFltNm; 3392 rSrcSh.GetGrfNms( &sGrfNm, &sFltNm ); 3393 rSh.ReRead( sGrfNm, sFltNm, rSrcSh.GetGraphic() ); 3394 return 1; 3395 } 3396 3397 //Nicht in Selektionen oder selektierten Rahmen 3398 if( rSh.ChgCurrPam( rDragPt ) || 3399 ( rSh.IsSelFrmMode() && rSh.IsInsideSelectedObj( rDragPt )) ) 3400 return 0; 3401 3402 if( rSrcSh.IsTableMode() ) 3403 bTblSel = sal_True; 3404 else if( rSrcSh.IsSelFrmMode() || rSrcSh.IsObjSelected() ) 3405 { 3406 // keine positionsgeschuetzten Objecte verschieben! 3407 if( bMove && rSrcSh.IsSelObjProtected( FLYPROTECT_POS ) ) 3408 return 0; 3409 3410 bFrmSel = sal_True; 3411 } 3412 3413 const int nSel = rSrcSh.GetSelectionType(); 3414 3415 SwUndoId eUndoId = bMove ? UNDO_UI_DRAG_AND_MOVE : UNDO_UI_DRAG_AND_COPY; 3416 3417 // #111827# 3418 SwRewriter aRewriter; 3419 3420 aRewriter.AddRule(UNDO_ARG1, rSrcSh.GetSelDescr()); 3421 3422 if(rSrcSh.GetDoc() != rSh.GetDoc()) 3423 rSrcSh.StartUndo( eUndoId, &aRewriter ); 3424 rSh.StartUndo( eUndoId, &aRewriter ); 3425 3426 rSh.StartAction(); 3427 rSrcSh.StartAction(); 3428 3429 if( &rSrcSh != &rSh ) 3430 { 3431 rSh.EnterStdMode(); 3432 rSh.SwCrsrShell::SetCrsr( rDragPt, sal_True ); 3433 cWord = rSrcSh.IntelligentCut( nSel, sal_False ); 3434 } 3435 else if( !bTblSel && !bFrmSel ) 3436 { 3437 if( !rSh.IsAddMode() ) 3438 { 3439 // --> OD 2008-03-19 #i87233# 3440 if ( rSh.IsBlockMode() ) 3441 { 3442 // preserve order of cursors for block mode 3443 rSh.GoPrevCrsr(); 3444 } 3445 // <-- 3446 rSh.SwCrsrShell::CreateCrsr(); 3447 } 3448 rSh.SwCrsrShell::SetCrsr( rDragPt, sal_True, false ); 3449 rSh.GoPrevCrsr(); 3450 cWord = rSh.IntelligentCut( rSh.GetSelectionType(), sal_False ); 3451 rSh.GoNextCrsr(); 3452 } 3453 3454 bInWrd = rSh.IsInWrd(); 3455 bEndWrd = rSh.IsEndWrd(); 3456 bSttWrd = !bEndWrd && rSh.IsSttWrd(); 3457 bSttPara= rSh.IsSttPara(); 3458 3459 Point aSttPt( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY() ); 3460 3461 //JP 05.03.96: INetFelder erstmal selektieren ! 3462 if( TRNSFR_INETFLD == eBufferType ) 3463 { 3464 if( &rSrcSh == &rSh ) 3465 { 3466 rSh.GoPrevCrsr(); 3467 rSh.SwCrsrShell::SetCrsr( aSttPt, sal_True ); 3468 rSh.SelectTxtAttr( RES_TXTATR_INETFMT ); 3469 if( rSh.ChgCurrPam( rDragPt ) ) 3470 { 3471 // nicht in sich selbst kopieren/verschieben 3472 rSh.DestroyCrsr(); 3473 rSh.EndUndo(); 3474 rSh.EndAction(); 3475 rSh.EndAction(); 3476 return 0; 3477 } 3478 rSh.GoNextCrsr(); 3479 } 3480 else 3481 { 3482 rSrcSh.SwCrsrShell::SetCrsr( aSttPt, sal_True ); 3483 rSrcSh.SelectTxtAttr( RES_TXTATR_INETFMT ); 3484 } 3485 3486 // ist am Einfuege Punkt ein URL-Attribut? Dann das ersetzen, 3487 // also einfach eine Selektion aufspannen? 3488 rSh.DelINetAttrWithText(); 3489 bDDINetAttr = sal_True; 3490 } 3491 3492 if ( rSrcSh.IsSelFrmMode() ) 3493 { 3494 //Hack: Spezialbehandlung austricksen 3495 aSttPt -= aSttPt - rSrcSh.GetObjRect().Pos(); 3496 } 3497 3498 sal_Bool bRet = rSrcSh.SwFEShell::Copy( &rSh, aSttPt, rDragPt, bMove, 3499 !bIsXSelection ); 3500 3501 if( !bIsXSelection ) 3502 { 3503 rSrcSh.Push(); 3504 if ( bRet && bMove && !bFrmSel ) 3505 { 3506 if ( bTblSel ) 3507 { 3508 /* #109590# delete table contents not cells */ 3509 rSrcSh.Delete(); 3510 } 3511 else 3512 { 3513 //SmartCut, eines der Blank mitnehmen. 3514 rSh.SwCrsrShell::DestroyCrsr(); 3515 if ( cWord == SwWrtShell::WORD_SPACE_BEFORE ) 3516 rSh.ExtendSelection( sal_False ); 3517 else if ( cWord == SwWrtShell::WORD_SPACE_AFTER ) 3518 rSh.ExtendSelection(); 3519 rSrcSh.DelRight(); 3520 } 3521 } 3522 rSrcSh.KillPams(); 3523 rSrcSh.Pop( sal_False ); 3524 3525 /* #109590# after dragging a table selection inside one shell 3526 set cursor to the drop position. */ 3527 if( &rSh == &rSrcSh && ( bTblSel || rSh.IsBlockMode() ) ) 3528 { 3529 rSrcSh.SwCrsrShell::SetCrsr(rDragPt); 3530 rSrcSh.GetSwCrsr()->SetMark(); 3531 } 3532 } 3533 3534 if( bRet && !bTblSel && !bFrmSel ) 3535 { 3536 if( (bInWrd || bEndWrd) && 3537 (cWord == SwWrtShell::WORD_SPACE_AFTER || 3538 cWord == SwWrtShell::WORD_SPACE_BEFORE) ) 3539 { 3540 if ( bSttWrd || (bInWrd && !bEndWrd)) 3541 rSh.SwEditShell::Insert(' ', bIsXSelection); 3542 if ( !bSttWrd || (bInWrd && !bSttPara) ) 3543 { 3544 rSh.SwapPam(); 3545 if ( !bSttWrd ) 3546 rSh.SwEditShell::Insert(' ', bIsXSelection); 3547 rSh.SwapPam(); 3548 } 3549 } 3550 3551 if( bIsXSelection ) 3552 { 3553 if( &rSrcSh == &rSh && !rSh.IsAddMode() ) 3554 { 3555 rSh.SwCrsrShell::DestroyCrsr(); 3556 rSh.GoPrevCrsr(); 3557 } 3558 else 3559 { 3560 rSh.SwapPam(); 3561 rSh.SwCrsrShell::ClearMark(); 3562 } 3563 } 3564 else 3565 { 3566 if( rSh.IsAddMode() ) 3567 rSh.SwCrsrShell::CreateCrsr(); 3568 else 3569 { 3570 // Selektionsmodus einschalten 3571 rSh.SttSelect(); 3572 rSh.EndSelect(); 3573 } 3574 } 3575 } 3576 3577 if( bRet && bMove && bFrmSel ) 3578 rSrcSh.LeaveSelFrmMode(); 3579 3580 if( rSrcSh.GetDoc() != rSh.GetDoc() ) 3581 rSrcSh.EndUndo(); 3582 rSh.EndUndo(); 3583 3584 // Shell in den richtigen Status versetzen 3585 if( &rSrcSh != &rSh && ( rSh.IsFrmSelected() || rSh.IsObjSelected() )) 3586 rSh.EnterSelFrmMode(); 3587 3588 rSrcSh.EndAction(); 3589 rSh.EndAction(); 3590 return 1; 3591 } 3592 3593 // Interfaces for Selection 3594 void SwTransferable::CreateSelection( SwWrtShell& rSh, 3595 const ViewShell * _pCreatorView ) 3596 { 3597 SwModule *pMod = SW_MOD(); 3598 SwTransferable* pNew = new SwTransferable( rSh ); 3599 3600 /* #96392#*/ 3601 pNew->pCreatorView = _pCreatorView; 3602 3603 uno::Reference< 3604 datatransfer::XTransferable > xRef( pNew ); 3605 pMod->pXSelection = pNew; 3606 pNew->CopyToSelection( rSh.GetWin() ); 3607 } 3608 3609 void SwTransferable::ClearSelection( SwWrtShell& rSh, 3610 const ViewShell * _pCreatorView) 3611 { 3612 SwModule *pMod = SW_MOD(); 3613 if( pMod->pXSelection && 3614 ((!pMod->pXSelection->pWrtShell) || (pMod->pXSelection->pWrtShell == &rSh)) && 3615 /* #96392# */ 3616 (!_pCreatorView || (pMod->pXSelection->pCreatorView == _pCreatorView)) ) 3617 { 3618 TransferableHelper::ClearSelection( rSh.GetWin() ); 3619 } 3620 } 3621 /* -----------------3/31/2003 11:46AM---------------- 3622 3623 --------------------------------------------------*/ 3624 const Sequence< sal_Int8 >& SwTransferable::getUnoTunnelId() 3625 { 3626 static Sequence< sal_Int8 > aSeq; 3627 if( !aSeq.getLength() ) 3628 { 3629 static osl::Mutex aCreateMutex; 3630 osl::Guard< osl::Mutex > aGuard( aCreateMutex ); 3631 aSeq.realloc( 16 ); 3632 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True ); 3633 } 3634 return aSeq; 3635 } 3636 /* -----------------3/31/2003 11:46AM---------------- 3637 3638 --------------------------------------------------*/ 3639 sal_Int64 SwTransferable::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException ) 3640 { 3641 sal_Int64 nRet; 3642 if( ( rId.getLength() == 16 ) && 3643 ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ) 3644 { 3645 nRet = sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) ); 3646 } 3647 else 3648 nRet = TransferableHelper::getSomething(rId); 3649 return nRet; 3650 } 3651 3652 SwTransferable* SwTransferable::GetSwTransferable( const TransferableDataHelper& rData ) 3653 { 3654 SwTransferable* pSwTransferable = NULL; 3655 3656 uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY ); 3657 if ( xTunnel.is() ) 3658 { 3659 sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() ); 3660 if ( nHandle ) 3661 pSwTransferable = (SwTransferable*) (sal_IntPtr) nHandle; 3662 } 3663 3664 return pSwTransferable; 3665 3666 } 3667 3668 /* */ 3669 3670 // ----------------------------------------------------------------------- 3671 3672 SwTrnsfrDdeLink::SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh ) 3673 : rTrnsfr( rTrans ), pDocShell( 0 ), 3674 bDelBookmrk( sal_False ), bInDisconnect( sal_False ) 3675 { 3676 // hier kommen wir nur bei Tabellen- oder Text-Selection an 3677 const int nSelection = rSh.GetSelectionType(); 3678 if( nsSelectionType::SEL_TBL_CELLS & nSelection ) 3679 { 3680 SwFrmFmt* pFmt = rSh.GetTableFmt(); 3681 if( pFmt ) 3682 sName = pFmt->GetName(); 3683 } 3684 else 3685 { 3686 // creating a temp. bookmark without undo 3687 sal_Bool bUndo = rSh.DoesUndo(); 3688 rSh.DoUndo( sal_False ); 3689 sal_Bool bIsModified = rSh.IsModified(); 3690 3691 ::sw::mark::IMark* pMark = rSh.SetBookmark( 3692 KeyCode(), 3693 ::rtl::OUString(), 3694 ::rtl::OUString(), 3695 IDocumentMarkAccess::DDE_BOOKMARK); 3696 if(pMark) 3697 { 3698 sName = pMark->GetName(); 3699 bDelBookmrk = sal_True; 3700 if( !bIsModified ) 3701 rSh.ResetModified(); 3702 } 3703 else 3704 sName.Erase(); 3705 rSh.DoUndo( bUndo ); 3706 } 3707 3708 if( sName.Len() && 3709 0 != ( pDocShell = rSh.GetDoc()->GetDocShell() ) ) 3710 { 3711 // dann erzeugen wir uns mal unseren "Server" und connecten uns 3712 // zu diesem 3713 refObj = pDocShell->DdeCreateLinkSource( sName ); 3714 if( refObj.Is() ) 3715 { 3716 refObj->AddConnectAdvise( this ); 3717 refObj->AddDataAdvise( this, 3718 // SotExchange::GetFormatMimeType( FORMAT_RTF ), 3719 aEmptyStr, 3720 ADVISEMODE_NODATA | ADVISEMODE_ONLYONCE ); 3721 nOldTimeOut = refObj->GetUpdateTimeout(); 3722 refObj->SetUpdateTimeout( 0 ); 3723 } 3724 } 3725 } 3726 3727 // ----------------------------------------------------------------------- 3728 3729 SwTrnsfrDdeLink::~SwTrnsfrDdeLink() 3730 { 3731 if( refObj.Is() ) 3732 Disconnect( sal_True ); 3733 } 3734 3735 // ----------------------------------------------------------------------- 3736 3737 void SwTrnsfrDdeLink::DataChanged( const String& , 3738 const uno::Any& ) 3739 { 3740 // tja das wars dann mit dem Link 3741 if( !bInDisconnect ) 3742 { 3743 if( FindDocShell() && pDocShell->GetView() ) 3744 rTrnsfr.RemoveDDELinkFormat( pDocShell->GetView()->GetEditWin() ); 3745 Disconnect( sal_False ); 3746 } 3747 } 3748 3749 // ----------------------------------------------------------------------- 3750 3751 sal_Bool SwTrnsfrDdeLink::WriteData( SvStream& rStrm ) 3752 { 3753 if( !refObj.Is() || !FindDocShell() ) 3754 return sal_False; 3755 3756 rtl_TextEncoding eEncoding = DDE_TXT_ENCODING; 3757 const ByteString aAppNm( GetpApp()->GetAppName(), eEncoding ); 3758 const ByteString aTopic( pDocShell->GetTitle( SFX_TITLE_FULLNAME ), 3759 eEncoding ); 3760 const ByteString aName( sName, eEncoding ); 3761 3762 sal_Char* pMem = new char[ aAppNm.Len() + aTopic.Len() + aName.Len() + 4 ]; 3763 3764 xub_StrLen nLen = aAppNm.Len(); 3765 memcpy( pMem, aAppNm.GetBuffer(), nLen ); 3766 pMem[ nLen++ ] = 0; 3767 memcpy( pMem + nLen, aTopic.GetBuffer(), aTopic.Len() ); 3768 nLen = nLen + aTopic.Len(); 3769 pMem[ nLen++ ] = 0; 3770 memcpy( pMem + nLen, aName.GetBuffer(), aName.Len() ); 3771 nLen = nLen + aName.Len(); 3772 pMem[ nLen++ ] = 0; 3773 pMem[ nLen++ ] = 0; 3774 3775 rStrm.Write( pMem, nLen ); 3776 delete[] pMem; 3777 3778 IDocumentMarkAccess* const pMarkAccess = pDocShell->GetDoc()->getIDocumentMarkAccess(); 3779 IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName); 3780 if(ppMark != pMarkAccess->getAllMarksEnd() 3781 && IDocumentMarkAccess::GetType(**ppMark) != IDocumentMarkAccess::BOOKMARK) 3782 { 3783 // the mark is still a DdeBookmark 3784 // we replace it with a Bookmark, so it will get saved etc. 3785 ::sw::mark::IMark* const pMark = ppMark->get(); 3786 SwServerObject* const pServerObject = dynamic_cast<SwServerObject *>(&refObj); 3787 3788 // collecting state of old mark 3789 SwPaM aPaM(pMark->GetMarkStart()); 3790 *aPaM.GetPoint() = pMark->GetMarkStart(); 3791 if(pMark->IsExpanded()) 3792 { 3793 aPaM.SetMark(); 3794 *aPaM.GetMark() = pMark->GetMarkEnd(); 3795 } 3796 ::rtl::OUString sMarkName = pMark->GetName(); 3797 3798 // remove mark 3799 pServerObject->SetNoServer(); // this removes the connection between SwServerObject and mark 3800 // N.B. ppMark was not loaded from file and cannot have xml:id 3801 pMarkAccess->deleteMark(ppMark); 3802 3803 // recreate as Bookmark 3804 ::sw::mark::IMark* const pNewMark = pMarkAccess->makeMark( 3805 aPaM, 3806 sMarkName, 3807 IDocumentMarkAccess::BOOKMARK); 3808 pServerObject->SetDdeBookmark(*pNewMark); 3809 } 3810 3811 bDelBookmrk = false; 3812 return true; 3813 } 3814 3815 // ----------------------------------------------------------------------- 3816 3817 void SwTrnsfrDdeLink::Disconnect( sal_Bool bRemoveDataAdvise ) 3818 { 3819 //JP 29.01.96 Bug 24432: 3820 // kein DataChanged mehr entgegen nehmen, wenn man 3821 // sich schon im Disconnet befindet! 3822 // (DTOR vom Bookmark verschickt einen DataChanged!) 3823 const sal_Bool bOldDisconnect = bInDisconnect; 3824 bInDisconnect = sal_True; 3825 3826 // den nicht verwendeten Bookmark wieder zerstoeren (ohne Undo!)? 3827 if( bDelBookmrk && refObj.Is() && FindDocShell() ) 3828 { 3829 SwDoc* pDoc = pDocShell->GetDoc(); 3830 ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo()); 3831 3832 // --> OD, CD, OS 2005-11-25 #i58448# 3833 Link aSavedOle2Link( pDoc->GetOle2Link() ); 3834 pDoc->SetOle2Link( Link() ); 3835 // <-- 3836 sal_Bool bIsModified = pDoc->IsModified(); 3837 3838 IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess(); 3839 // check, if DdeBookmark is already in its desctruction 3840 IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName); 3841 if ( ppMark != pMarkAccess->getAllMarksEnd() ) 3842 { 3843 ::sw::mark::DdeBookmark* const pDdeBookmark = dynamic_cast< ::sw::mark::DdeBookmark* >(ppMark->get()); 3844 if ( pDdeBookmark && !pDdeBookmark->IsInDestruction() ) 3845 { 3846 pMarkAccess->deleteMark(ppMark); 3847 } 3848 } 3849 3850 if( !bIsModified ) 3851 pDoc->ResetModified(); 3852 pDoc->SetOle2Link( aSavedOle2Link ); 3853 3854 bDelBookmrk = sal_False; 3855 } 3856 3857 if( refObj.Is() ) 3858 { 3859 refObj->SetUpdateTimeout( nOldTimeOut ); 3860 refObj->RemoveConnectAdvise( this ); 3861 if( bRemoveDataAdvise ) 3862 // in einem DataChanged darf das SelectionObject NIE geloescht 3863 // werden; wird schon von der Basisklasse erledigt 3864 // (ADVISEMODE_ONLYONCE!!!!) 3865 // Im normalen Disconnet aber schon! 3866 refObj->RemoveAllDataAdvise( this ); 3867 refObj.Clear(); 3868 } 3869 bInDisconnect = bOldDisconnect; 3870 } 3871 3872 // ----------------------------------------------------------------------- 3873 3874 sal_Bool SwTrnsfrDdeLink::FindDocShell() 3875 { 3876 TypeId aType( TYPE( SwDocShell ) ); 3877 SfxObjectShell* pTmpSh = SfxObjectShell::GetFirst( &aType ); 3878 while( pTmpSh ) 3879 { 3880 if( pTmpSh == pDocShell ) // die wollen wir haben 3881 { 3882 if( pDocShell->GetDoc() ) 3883 return sal_True; 3884 break; // das Doc ist nicht mehr vorhanden, also raus! 3885 } 3886 pTmpSh = SfxObjectShell::GetNext( *pTmpSh, &aType ); 3887 } 3888 3889 pDocShell = 0; 3890 return sal_False; 3891 } 3892 3893 // ----------------------------------------------------------------------- 3894 3895 void SwTrnsfrDdeLink::Closed() 3896 { 3897 if( !bInDisconnect && refObj.Is() ) 3898 { 3899 refObj->RemoveAllDataAdvise( this ); 3900 refObj->RemoveConnectAdvise( this ); 3901 refObj.Clear(); 3902 } 3903 } 3904