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->getMarksBegin(); 855 ppMark != pMarkAccess->getMarksEnd(); 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_FORMAT_GDIMETAFILE: 1351 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1352 SW_PASTESDR_INSERT,pPt, 1353 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1354 break; 1355 1356 case SOT_FORMATSTR_ID_XFORMS: 1357 case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE: 1358 case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE: 1359 case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE: 1360 nRet = SwTransferable::_PasteDBData( rData, rSh, nFormat, 1361 EXCHG_IN_ACTION_LINK == nClearedAction, 1362 pPt, bMsg ); 1363 break; 1364 1365 case SOT_FORMAT_FILE: 1366 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat, 1367 ( EXCHG_IN_ACTION_MOVE == nClearedAction 1368 ? SW_PASTESDR_REPLACE 1369 : EXCHG_IN_ACTION_LINK == nClearedAction 1370 ? SW_PASTESDR_SETATTR 1371 : SW_PASTESDR_INSERT), 1372 pPt, nActionFlags, bMsg ); 1373 break; 1374 1375 case SOT_FORMAT_FILE_LIST: 1376 // dann nur als Grafiken einfuegen 1377 nRet = SwTransferable::_PasteFileList( rData, rSh, 1378 EXCHG_IN_ACTION_LINK == nClearedAction, 1379 pPt, bMsg ); 1380 break; 1381 1382 case SOT_FORMATSTR_ID_SONLK: 1383 if( pPt ) 1384 { 1385 NaviContentBookmark aBkmk; 1386 if( aBkmk.Paste( rData ) ) 1387 { 1388 if(bIsDefault) 1389 { 1390 switch(aBkmk.GetDefaultDragType()) 1391 { 1392 case REGION_MODE_NONE: nClearedAction = EXCHG_IN_ACTION_COPY; break; 1393 case REGION_MODE_EMBEDDED: nClearedAction = EXCHG_IN_ACTION_MOVE; break; 1394 case REGION_MODE_LINK: nClearedAction = EXCHG_IN_ACTION_LINK; break; 1395 } 1396 } 1397 rSh.NavigatorPaste( aBkmk, nClearedAction ); 1398 nRet = 1; 1399 } 1400 } 1401 break; 1402 1403 case SOT_FORMATSTR_ID_INET_IMAGE: 1404 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE: 1405 nRet = SwTransferable::_PasteTargetURL( rData, rSh, 1406 SW_PASTESDR_INSERT, 1407 pPt, sal_True ); 1408 break; 1409 1410 default: 1411 ASSERT( pPt, "unbekanntes Format" ); 1412 } 1413 break; 1414 1415 case EXCHG_OUT_ACTION_INSERT_FILE: 1416 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat, 1417 SW_PASTESDR_INSERT, pPt, 1418 nActionFlags, bMsg ); 1419 if( nRet & SWTRANSFER_GRAPHIC_INSERTED ) 1420 bCallAutoCaption = true; 1421 break; 1422 1423 case EXCHG_OUT_ACTION_INSERT_OLE: 1424 nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat, 1425 nActionFlags,bMsg ); 1426 break; 1427 1428 case EXCHG_OUT_ACTION_INSERT_DDE: 1429 { 1430 sal_Bool bReRead = 0 != CNT_HasGrf( rSh.GetCntType() ); 1431 nRet = SwTransferable::_PasteDDE( rData, rSh, bReRead, bMsg ); 1432 } 1433 break; 1434 1435 case EXCHG_OUT_ACTION_INSERT_HYPERLINK: 1436 { 1437 String sURL, sDesc; 1438 if( SOT_FORMAT_FILE == nFormat ) 1439 { 1440 if( rData.GetString( nFormat, sURL ) && sURL.Len() ) 1441 { 1442 SwTransferable::_CheckForURLOrLNKFile( rData, sURL, &sDesc ); 1443 if( !sDesc.Len() ) 1444 sDesc = sURL; 1445 nRet = 1; 1446 } 1447 } 1448 else 1449 { 1450 INetBookmark aBkmk; 1451 if( rData.GetINetBookmark( nFormat, aBkmk ) ) 1452 { 1453 sURL = aBkmk.GetURL(); 1454 sDesc = aBkmk.GetDescription(); 1455 nRet = 1; 1456 } 1457 } 1458 1459 if( nRet ) 1460 { 1461 SwFmtINetFmt aFmt( sURL, aEmptyStr ); 1462 rSh.InsertURL( aFmt, sDesc ); 1463 } 1464 } 1465 break; 1466 1467 case EXCHG_OUT_ACTION_GET_ATTRIBUTES: 1468 switch( nFormat ) 1469 { 1470 case SOT_FORMATSTR_ID_DRAWING: 1471 nRet = SwTransferable::_PasteSdrFormat( rData, rSh, 1472 SW_PASTESDR_SETATTR, pPt, 1473 nActionFlags, bNeedToSelectBeforePaste); 1474 break; 1475 case SOT_FORMATSTR_ID_SVXB: 1476 case SOT_FORMAT_GDIMETAFILE: 1477 case SOT_FORMAT_BITMAP: 1478 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: 1479 case SOT_FORMAT_FILE: 1480 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 1481 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR: 1482 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1483 SW_PASTESDR_SETATTR, pPt, 1484 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1485 break; 1486 default: 1487 ASSERT( sal_False, "unbekanntes Format" ); 1488 } 1489 1490 break; 1491 1492 case EXCHG_OUT_ACTION_INSERT_DRAWOBJ: 1493 nRet = SwTransferable::_PasteSdrFormat( rData, rSh, 1494 SW_PASTESDR_INSERT, pPt, 1495 nActionFlags, bNeedToSelectBeforePaste); 1496 break; 1497 case EXCHG_OUT_ACTION_INSERT_SVXB: 1498 case EXCHG_OUT_ACTION_INSERT_GDIMETAFILE: 1499 case EXCHG_OUT_ACTION_INSERT_BITMAP: 1500 case EXCHG_OUT_ACTION_INSERT_GRAPH: 1501 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1502 SW_PASTESDR_INSERT, pPt, 1503 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1504 break; 1505 1506 case EXCHG_OUT_ACTION_REPLACE_DRAWOBJ: 1507 nRet = SwTransferable::_PasteSdrFormat( rData, rSh, 1508 SW_PASTESDR_REPLACE, pPt, 1509 nActionFlags, bNeedToSelectBeforePaste); 1510 break; 1511 1512 case EXCHG_OUT_ACTION_REPLACE_SVXB: 1513 case EXCHG_OUT_ACTION_REPLACE_GDIMETAFILE: 1514 case EXCHG_OUT_ACTION_REPLACE_BITMAP: 1515 case EXCHG_OUT_ACTION_REPLACE_GRAPH: 1516 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat, 1517 SW_PASTESDR_REPLACE,pPt, 1518 nActionFlags, nDropAction, bNeedToSelectBeforePaste); 1519 break; 1520 1521 case EXCHG_OUT_ACTION_INSERT_INTERACTIVE: 1522 nRet = SwTransferable::_PasteAsHyperlink( rData, rSh, nFormat ); 1523 break; 1524 1525 default: 1526 ASSERT( sal_False, "unbekannte Action" ); 1527 } 1528 } 1529 1530 if( !bPasteSelection && rSh.IsFrmSelected() ) 1531 { 1532 rSh.EnterSelFrmMode(); 1533 //force ::SelectShell 1534 rSh.GetView().StopShellTimer(); 1535 } 1536 1537 if( pAction ) 1538 delete pAction; 1539 if( bCallAutoCaption ) 1540 rSh.GetView().AutoCaption( GRAPHIC_CAP ); 1541 1542 return nRet; 1543 } 1544 1545 // ----------------------------------------------------------------------- 1546 1547 sal_uInt16 SwTransferable::GetSotDestination( const SwWrtShell& rSh, 1548 const Point* pPt ) 1549 { 1550 sal_uInt16 nRet = EXCHG_INOUT_ACTION_NONE; 1551 1552 ObjCntType eOType; 1553 if( pPt ) 1554 { 1555 SdrObject *pObj = 0; 1556 eOType = rSh.GetObjCntType( *pPt, pObj ); 1557 } 1558 else 1559 eOType = rSh.GetObjCntTypeOfSelection(); 1560 1561 switch( eOType ) 1562 { 1563 case OBJCNT_GRF: 1564 { 1565 sal_Bool bIMap, bLink; 1566 if( pPt ) 1567 { 1568 bIMap = 0 != rSh.GetFmtFromObj( *pPt )->GetURL().GetMap(); 1569 String aDummy; 1570 rSh.GetGrfAtPos( *pPt, aDummy, bLink ); 1571 } 1572 else 1573 { 1574 bIMap = 0 != rSh.GetFlyFrmFmt()->GetURL().GetMap(); 1575 String aDummy; 1576 rSh.GetGrfNms( &aDummy, 0 ); 1577 bLink = 0 != aDummy.Len(); 1578 } 1579 1580 if( bLink && bIMap ) 1581 nRet = EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP; 1582 else if( bLink ) 1583 nRet = EXCHG_DEST_DOC_LNKD_GRAPHOBJ; 1584 else if( bIMap ) 1585 nRet = EXCHG_DEST_DOC_GRAPH_W_IMAP; 1586 else 1587 nRet = EXCHG_DEST_DOC_GRAPHOBJ; 1588 } 1589 break; 1590 1591 case OBJCNT_FLY: 1592 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) 1593 nRet = EXCHG_DEST_DOC_TEXTFRAME_WEB; 1594 else 1595 nRet = EXCHG_DEST_DOC_TEXTFRAME; 1596 break; 1597 case OBJCNT_OLE: nRet = EXCHG_DEST_DOC_OLEOBJ; break; 1598 1599 case OBJCNT_CONTROL: /* no Action avail */ 1600 case OBJCNT_SIMPLE: nRet = EXCHG_DEST_DOC_DRAWOBJ; break; 1601 case OBJCNT_URLBUTTON: nRet = EXCHG_DEST_DOC_URLBUTTON; break; 1602 case OBJCNT_GROUPOBJ: nRet = EXCHG_DEST_DOC_GROUPOBJ; break; 1603 1604 // was mmchen wir bei Mehrfachselektion??? 1605 // case OBJCNT_DONTCARE: 1606 default: 1607 { 1608 /* 1609 JP 13.07.98: Bug 52637: es wird ein URL-Feld erkannt also werden nur die 1610 Inhalte zugelassen. Das ist aber bestimmt nicht das 1611 gewollte. 1612 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR ); 1613 SfxItemSet aSet( (SfxItemPool&)rSh.GetAttrPool(), 1614 RES_TXTATR_INETFMT, RES_TXTATR_INETFMT ); 1615 if( pPt ? ((SwWrtShell&)rSh).GetContentAtPos( *pPt, aCntntAtPos, sal_False ) 1616 : (rSh.GetAttr( aSet ) && aSet.Count()) ) 1617 nRet = EXCHG_DEST_DOC_URLFIELD; 1618 else 1619 */ 1620 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) 1621 nRet = EXCHG_DEST_SWDOC_FREE_AREA_WEB; 1622 else 1623 nRet = EXCHG_DEST_SWDOC_FREE_AREA; 1624 } 1625 } 1626 1627 return nRet; 1628 } 1629 1630 // ----------------------------------------------------------------------- 1631 1632 int SwTransferable::_PasteFileContent( TransferableDataHelper& rData, 1633 SwWrtShell& rSh, sal_uLong nFmt, sal_Bool bMsg ) 1634 { 1635 sal_uInt16 nResId = MSG_CLPBRD_FORMAT_ERROR; 1636 int nRet = 0; 1637 1638 MSE40HTMLClipFormatObj aMSE40ClpObj; 1639 1640 SotStorageStreamRef xStrm; 1641 SvStream* pStream = 0; 1642 SwRead pRead = 0; 1643 rtl::OUString sData; 1644 switch( nFmt ) 1645 { 1646 case SOT_FORMAT_STRING: 1647 { 1648 pRead = ReadAscii; 1649 if( rData.GetString( nFmt, sData ) ) 1650 { 1651 pStream = new SvMemoryStream( (void*)sData.getStr(), 1652 sData.getLength() * sizeof( sal_Unicode ), 1653 STREAM_READ ); 1654 #ifdef OSL_BIGENDIAN 1655 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); 1656 #else 1657 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 1658 #endif 1659 1660 SwAsciiOptions aAOpt; 1661 aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 ); 1662 pRead->GetReaderOpt().SetASCIIOpts( aAOpt ); 1663 break; 1664 } 1665 } 1666 // no break - because then test if we get a stream 1667 1668 default: 1669 if( rData.GetSotStorageStream( nFmt, xStrm ) ) 1670 { 1671 if( ( SOT_FORMATSTR_ID_HTML_SIMPLE == nFmt ) || 1672 ( SOT_FORMATSTR_ID_HTML_NO_COMMENT == nFmt ) ) 1673 { 1674 pStream = aMSE40ClpObj.IsValid( *xStrm ); 1675 pRead = ReadHTML; 1676 pRead->SetReadUTF8( sal_True ); 1677 //pRead->SetBaseURL( aMSE40ClpObj.GetBaseURL() ); 1678 1679 sal_Bool bNoComments = 1680 ( nFmt == SOT_FORMATSTR_ID_HTML_NO_COMMENT ); 1681 pRead->SetIgnoreHTMLComments( bNoComments ); 1682 } 1683 else 1684 { 1685 pStream = &xStrm; 1686 if( SOT_FORMAT_RTF == nFmt ) 1687 pRead = SwReaderWriter::GetReader( READER_WRITER_RTF ); 1688 else if( !pRead ) 1689 { 1690 pRead = ReadHTML; 1691 pRead->SetReadUTF8( sal_True ); 1692 } 1693 } 1694 } 1695 break; 1696 } 1697 1698 if( pStream && pRead ) 1699 { 1700 Link aOldLink( rSh.GetChgLnk() ); 1701 rSh.SetChgLnk( Link() ); 1702 1703 const SwPosition& rInsPos = *rSh.GetCrsr()->Start(); 1704 SwReader aReader( *pStream, aEmptyStr, String(), *rSh.GetCrsr() ); 1705 rSh.SaveTblBoxCntnt( &rInsPos ); 1706 if( IsError( aReader.Read( *pRead )) ) 1707 nResId = ERR_CLPBRD_READ; 1708 else 1709 nResId = 0, nRet = 1; 1710 1711 rSh.SetChgLnk( aOldLink ); 1712 if( nRet ) 1713 rSh.CallChgLnk(); 1714 } 1715 else 1716 nResId = MSG_CLPBRD_FORMAT_ERROR; 1717 1718 // Exist a SvMemoryStream? (data in the OUString and xStrm is empty) 1719 if( pStream && !xStrm.Is() ) 1720 delete pStream; 1721 1722 if( bMsg && nResId ) 1723 { 1724 InfoBox( 0, SW_RES( nResId )).Execute(); 1725 } 1726 return nRet; 1727 } 1728 1729 // ----------------------------------------------------------------------- 1730 1731 int SwTransferable::_PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh, 1732 sal_uLong nFmt, sal_uInt8 nActionFlags, sal_Bool bMsg ) 1733 { 1734 int nRet = 0; 1735 TransferableObjectDescriptor aObjDesc; 1736 uno::Reference < io::XInputStream > xStrm; 1737 uno::Reference < embed::XStorage > xStore; 1738 Reader* pRead = 0; 1739 1740 // Get the preferred format 1741 SotFormatStringId nId; 1742 if( rData.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) ) 1743 nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ; 1744 else if( rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ) && 1745 rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )) 1746 nId = SOT_FORMATSTR_ID_EMBED_SOURCE; 1747 else 1748 nId = 0; 1749 1750 if( nId && rData.GetInputStream( nId, xStrm ) && xStrm.is() ) 1751 { 1752 // if there is an embedded object, first try if it's a writer object 1753 // this will be inserted into the document by using a Reader 1754 try 1755 { 1756 xStore = comphelper::OStorageHelper::GetStorageFromInputStream( xStrm ); 1757 switch( SotStorage::GetFormatID( xStore ) ) 1758 { 1759 case SOT_FORMATSTR_ID_STARWRITER_60: 1760 case SOT_FORMATSTR_ID_STARWRITERWEB_60: 1761 case SOT_FORMATSTR_ID_STARWRITERGLOB_60: 1762 case SOT_FORMATSTR_ID_STARWRITER_8: 1763 case SOT_FORMATSTR_ID_STARWRITERWEB_8: 1764 case SOT_FORMATSTR_ID_STARWRITERGLOB_8: 1765 pRead = ReadXML; 1766 break; 1767 default: 1768 try 1769 { 1770 uno::Reference < lang::XComponent > xComp( xStore, uno::UNO_QUERY ); 1771 xComp->dispose(); 1772 xStore = 0; 1773 } 1774 catch ( uno::Exception& ) 1775 { 1776 } 1777 1778 break; 1779 } 1780 } 1781 catch ( uno::Exception& ) 1782 { 1783 // it wasn't a storage, but maybe it's a useful stream 1784 } 1785 1786 nFmt = nId; 1787 } 1788 1789 if( pRead ) 1790 { 1791 SwPaM &rPAM = *rSh.GetCrsr(); 1792 SwReader aReader( xStore, aEmptyStr, rPAM ); 1793 if( !IsError( aReader.Read( *pRead )) ) 1794 nRet = 1; 1795 else if( bMsg ) 1796 InfoBox( 0, SW_RES(ERR_CLPBRD_READ) ).Execute(); 1797 } 1798 else 1799 { 1800 // temporary storage until the object is inserted 1801 uno::Reference< embed::XStorage > xTmpStor; 1802 uno::Reference < embed::XEmbeddedObject > xObj; 1803 ::rtl::OUString aName; 1804 comphelper::EmbeddedObjectContainer aCnt; 1805 1806 if ( xStrm.is() ) 1807 { 1808 if ( !rData.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) ) 1809 { 1810 DBG_ASSERT( !xStrm.is(), "An object without descriptor in clipboard!"); 1811 } 1812 } 1813 else 1814 { 1815 if( rData.HasFormat( nFmt = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE ) && rData.GetTransferableObjectDescriptor( nFmt, aObjDesc ) ) 1816 { 1817 if ( !rData.GetInputStream( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStrm ) ) 1818 rData.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStrm ); 1819 1820 if ( !xStrm.is() ) 1821 { 1822 // This is MSOLE object that should be created by direct using of system clipboard 1823 try 1824 { 1825 xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage(); 1826 uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator( 1827 ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString( 1828 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ), 1829 uno::UNO_QUERY_THROW ); 1830 1831 embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard( 1832 xTmpStor, 1833 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DummyName" ) ), 1834 uno::Sequence< beans::PropertyValue >() ); 1835 1836 // TODO/LATER: in future InsertedObjectInfo will be used to get container related information 1837 // for example whether the object should be an iconified one 1838 xObj = aInfo.Object; 1839 } 1840 catch( uno::Exception& ) 1841 {} 1842 } 1843 } 1844 } 1845 1846 if ( xStrm.is() && !xObj.is() ) 1847 xObj = aCnt.InsertEmbeddedObject( xStrm, aName ); 1848 1849 if( xObj.is() ) 1850 { 1851 svt::EmbeddedObjectRef xObjRef( xObj, aObjDesc.mnViewAspect ); 1852 1853 // try to get the replacement image from the clipboard 1854 Graphic aGraphic; 1855 sal_uLong nGrFormat = 0; 1856 1857 // (wg. Selection Manager bei Trustet Solaris) 1858 #ifndef SOLARIS 1859 /* 1860 if( rData.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) ) 1861 nGrFormat = SOT_FORMATSTR_ID_SVXB; 1862 else if( rData.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) ) 1863 nGrFormat = SOT_FORMAT_GDIMETAFILE; 1864 else if( rData.GetGraphic( FORMAT_BITMAP, aGraphic ) ) 1865 nGrFormat = SOT_FORMAT_BITMAP; 1866 */ 1867 #endif 1868 1869 // insert replacement image ( if there is one ) into the object helper 1870 if ( nGrFormat ) 1871 { 1872 datatransfer::DataFlavor aDataFlavor; 1873 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor ); 1874 xObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType ); 1875 } 1876 else if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON ) 1877 { 1878 // it is important to have an icon, let an empty graphic be used 1879 // if no other graphic is provided 1880 // TODO/LATER: in future a default bitmap could be used 1881 ::rtl::OUString aMimeType; 1882 MapMode aMapMode( MAP_100TH_MM ); 1883 aGraphic.SetPrefSize( Size( 2500, 2500 ) ); 1884 aGraphic.SetPrefMapMode( aMapMode ); 1885 xObjRef.SetGraphic( aGraphic, aMimeType ); 1886 } 1887 1888 //Size einstellen. Ist ein Hack wg. Auslieferung, die Size sollte 1889 //an das InsertOle uebergeben werden!!!!!!!!!! 1890 Size aSize; 1891 if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON ) 1892 { 1893 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() ) 1894 aSize = aObjDesc.maSize; 1895 else 1896 { 1897 MapMode aMapMode( MAP_100TH_MM ); 1898 aSize = xObjRef.GetSize( &aMapMode ); 1899 } 1900 } 1901 else if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() ) 1902 { 1903 aSize = Size( aObjDesc.maSize ); //immer 100TH_MM 1904 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) ); 1905 aSize = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit ); 1906 awt::Size aSz; 1907 try 1908 { 1909 aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect ); 1910 } 1911 catch( embed::NoVisualAreaSizeException& ) 1912 { 1913 // in this case the provided size is used 1914 } 1915 1916 if ( aSz.Width != aSize.Width() || aSz.Height != aSize.Height() ) 1917 { 1918 aSz.Width = aSize.Width(); 1919 aSz.Height = aSize.Height(); 1920 xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz ); 1921 } 1922 } 1923 else 1924 { 1925 // the descriptor contains the wrong object size 1926 // the following call will let the MSOLE objects cache the size if it is possible 1927 // it should be done while the object is running 1928 try 1929 { 1930 xObj->getVisualAreaSize( aObjDesc.mnViewAspect ); 1931 } 1932 catch( uno::Exception& ) 1933 { 1934 } 1935 } 1936 //Ende mit Hack! 1937 1938 rSh.InsertOleObject( xObjRef ); 1939 nRet = 1; 1940 1941 if( nRet && ( nActionFlags & 1942 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) )) 1943 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False ); 1944 1945 // let the object be unloaded if possible 1946 SwOLEObj::UnloadObject( xObj, rSh.GetDoc(), embed::Aspects::MSOLE_CONTENT ); 1947 } 1948 } 1949 return nRet; 1950 } 1951 1952 // ----------------------------------------------------------------------- 1953 1954 1955 // ----------------------------------------------------------------------- 1956 1957 int SwTransferable::_PasteTargetURL( TransferableDataHelper& rData, 1958 SwWrtShell& rSh, sal_uInt16 nAction, 1959 const Point* pPt, sal_Bool bInsertGRF ) 1960 { 1961 int nRet = 0; 1962 INetImage aINetImg; 1963 if( ( rData.HasFormat( SOT_FORMATSTR_ID_INET_IMAGE ) && 1964 rData.GetINetImage( SOT_FORMATSTR_ID_INET_IMAGE, aINetImg )) || 1965 ( rData.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_IMAGE ) && 1966 rData.GetINetImage( SOT_FORMATSTR_ID_NETSCAPE_IMAGE, aINetImg )) ) 1967 { 1968 if( aINetImg.GetImageURL().Len() && bInsertGRF ) 1969 { 1970 String sURL( aINetImg.GetImageURL() ); 1971 SwTransferable::_CheckForURLOrLNKFile( rData, sURL ); 1972 1973 //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die 1974 // Grafiken zu testen !!!! 1975 Graphic aGrf; 1976 GraphicFilter *pFlt = GraphicFilter::GetGraphicFilter(); 1977 nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( sURL, aEmptyStr, aGrf, pFlt ); 1978 if( nRet ) 1979 { 1980 switch( nAction ) 1981 { 1982 case SW_PASTESDR_INSERT: 1983 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 1984 rSh.Insert( sURL, aEmptyStr, aGrf ); 1985 break; 1986 1987 case SW_PASTESDR_REPLACE: 1988 if( rSh.IsObjSelected() ) 1989 { 1990 rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf ); 1991 Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() ); 1992 SwTransferable::SetSelInShell( rSh, sal_True, &aPt ); 1993 } 1994 else 1995 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 1996 break; 1997 1998 case SW_PASTESDR_SETATTR: 1999 if( rSh.IsObjSelected() ) 2000 rSh.Paste( aGrf ); 2001 else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() ) 2002 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 2003 else 2004 { 2005 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2006 rSh.Insert( sURL, aEmptyStr, aGrf ); 2007 } 2008 break; 2009 default: 2010 nRet = 0; 2011 } 2012 } 2013 } 2014 else 2015 nRet = 1; 2016 } 2017 2018 if( nRet ) 2019 { 2020 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2021 rSh.GetFlyFrmAttr( aSet ); 2022 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2023 2024 if( aURL.GetURL() != aINetImg.GetTargetURL() || 2025 aURL.GetTargetFrameName() != aINetImg.GetTargetFrame() ) 2026 { 2027 aURL.SetURL( aINetImg.GetTargetURL(), sal_False ); 2028 aURL.SetTargetFrameName( aINetImg.GetTargetFrame() ); 2029 aSet.Put( aURL ); 2030 rSh.SetFlyFrmAttr( aSet ); 2031 } 2032 } 2033 return nRet; 2034 } 2035 2036 2037 // ----------------------------------------------------------------------- 2038 2039 void SwTransferable::SetSelInShell( SwWrtShell& rSh, sal_Bool bSelectFrm, 2040 const Point* pPt ) 2041 { 2042 if( bSelectFrm ) 2043 { 2044 // Rahmen/Objecte selektieren 2045 if( pPt && !rSh.GetView().GetViewFrame()->GetDispatcher()->IsLocked() ) 2046 { 2047 rSh.GetView().NoRotate(); 2048 if( rSh.SelectObj( *pPt )) 2049 { 2050 rSh.HideCrsr(); 2051 rSh.EnterSelFrmMode( pPt ); 2052 bFrmDrag = sal_True; 2053 } 2054 } 2055 } 2056 else 2057 { 2058 if( rSh.IsFrmSelected() || rSh.IsObjSelected() ) 2059 { 2060 rSh.UnSelectFrm(); 2061 rSh.LeaveSelFrmMode(); 2062 rSh.GetView().GetEditWin().StopInsFrm(); 2063 bFrmDrag = sal_False; 2064 } 2065 else if( rSh.GetView().GetDrawFuncPtr() ) 2066 rSh.GetView().GetEditWin().StopInsFrm(); 2067 2068 rSh.EnterStdMode(); 2069 if( pPt ) 2070 rSh.SwCrsrShell::SetCrsr( *pPt, sal_True ); 2071 } 2072 } 2073 2074 // ----------------------------------------------------------------------- 2075 2076 int SwTransferable::_PasteDDE( TransferableDataHelper& rData, 2077 SwWrtShell& rWrtShell, sal_Bool bReReadGrf, 2078 sal_Bool bMsg ) 2079 { 2080 // Daten aus dem Clipboardformat 2081 String aApp, aTopic, aItem; 2082 2083 { 2084 SotStorageStreamRef xStrm; 2085 if( !rData.GetSotStorageStream( SOT_FORMATSTR_ID_LINK, xStrm )) 2086 { 2087 ASSERT( !&rWrtShell, "DDE Data not found." ); 2088 return 0; 2089 } //sinnvollen Fehler melden!! 2090 2091 rtl_TextEncoding eEncoding = DDE_TXT_ENCODING; 2092 xStrm->ReadCString( aApp, eEncoding ); 2093 xStrm->ReadCString( aTopic, eEncoding ); 2094 xStrm->ReadCString( aItem, eEncoding ); 2095 } 2096 2097 String aCmd; 2098 sfx2::MakeLnkName( aCmd, &aApp, aTopic, aItem ); 2099 2100 // wollen wir jetzt eine Grafik einlesen ? 2101 sal_uLong nFormat; 2102 if( !rData.HasFormat( FORMAT_RTF ) && 2103 !rData.HasFormat( SOT_FORMATSTR_ID_HTML ) && 2104 !rData.HasFormat( FORMAT_STRING ) && 2105 (rData.HasFormat( nFormat = FORMAT_GDIMETAFILE ) || 2106 rData.HasFormat( nFormat = FORMAT_BITMAP )) ) 2107 { 2108 Graphic aGrf; 2109 int nRet = rData.GetGraphic( nFormat, aGrf ); 2110 if( nRet ) 2111 { 2112 String sLnkTyp( String::CreateFromAscii( 2113 RTL_CONSTASCII_STRINGPARAM( "DDE" ))); 2114 if ( bReReadGrf ) 2115 rWrtShell.ReRead( aCmd, sLnkTyp, &aGrf ); 2116 else 2117 rWrtShell.Insert( aCmd, sLnkTyp, aGrf ); 2118 } 2119 return nRet; 2120 } 2121 2122 SwFieldType* pTyp = 0; 2123 sal_uInt16 i = 1,j; 2124 String aName; 2125 sal_Bool bAlreadyThere = sal_False, bDoublePaste = sal_False; 2126 sal_uInt16 nSize = rWrtShell.GetFldTypeCount(); 2127 const ::utl::TransliterationWrapper& rColl = ::GetAppCmpStrIgnore(); 2128 2129 do { 2130 aName = aApp; 2131 aName += String::CreateFromInt32( i ); 2132 for( j = INIT_FLDTYPES; j < nSize; j++ ) 2133 { 2134 pTyp = rWrtShell.GetFldType( j ); 2135 if( RES_DDEFLD == pTyp->Which() ) 2136 { 2137 String sTmp( ((SwDDEFieldType*)pTyp)->GetCmd() ); 2138 if( rColl.isEqual( sTmp, aCmd ) && 2139 sfx2::LINKUPDATE_ALWAYS == ((SwDDEFieldType*)pTyp)->GetType() ) 2140 { 2141 aName = pTyp->GetName(); 2142 bDoublePaste = sal_True; 2143 break; 2144 } 2145 else if( rColl.isEqual( aName, pTyp->GetName() ) ) 2146 break; 2147 } 2148 } 2149 if( j == nSize ) 2150 bAlreadyThere = sal_False; 2151 else 2152 { 2153 bAlreadyThere = sal_True; 2154 i++; 2155 } 2156 } 2157 while( bAlreadyThere && !bDoublePaste ); 2158 2159 if( !bDoublePaste ) 2160 { 2161 SwDDEFieldType aType( aName, aCmd, sfx2::LINKUPDATE_ALWAYS ); 2162 pTyp = rWrtShell.InsertFldType( aType ); 2163 } 2164 2165 2166 SwDDEFieldType* pDDETyp = (SwDDEFieldType*)pTyp; 2167 2168 String aExpand; 2169 if( rData.GetString( FORMAT_STRING, aExpand )) 2170 { 2171 do { // middle checked loop 2172 2173 // Wenn die Daten von einer Tabellenkalkulation kommen 2174 // fuegen wir eine DDE-Tabelle ein 2175 if( ( rData.HasFormat( SOT_FORMATSTR_ID_SYLK ) || 2176 rData.HasFormat( SOT_FORMATSTR_ID_SYLK_BIGCAPS ) ) && 2177 aExpand.Len() && 2178 ( 1 < aExpand.GetTokenCount( '\n' ) || 2179 aExpand.GetTokenCount( '\t' )) ) 2180 { 2181 String sTmp( aExpand ); 2182 xub_StrLen nRows = sTmp.GetTokenCount( '\n' ); 2183 if( nRows ) 2184 --nRows; 2185 sTmp = sTmp.GetToken( 0, '\n' ); 2186 xub_StrLen nCols = sTmp.GetTokenCount( '\t' ); 2187 2188 // mindestens eine Spalte & Zeile muss vorhanden sein 2189 if( !nRows || !nCols ) 2190 { 2191 if( bMsg ) 2192 InfoBox(0, SW_RESSTR(STR_NO_TABLE)).Execute(); 2193 pDDETyp = 0; 2194 break; 2195 } 2196 2197 rWrtShell.InsertDDETable( 2198 SwInsertTableOptions( tabopts::HEADLINE_NO_BORDER, 1 ), // TODO MULTIHEADER 2199 pDDETyp, nRows, nCols ); 2200 } 2201 else if( 1 < aExpand.GetTokenCount( '\n' ) ) 2202 { 2203 // mehrere Absaetze -> eine geschuetzte Section einfuegen 2204 if( rWrtShell.HasSelection() ) 2205 rWrtShell.DelRight(); 2206 2207 SwSectionData aSect( DDE_LINK_SECTION, aName ); 2208 aSect.SetLinkFileName( aCmd ); 2209 aSect.SetProtectFlag(true); 2210 rWrtShell.InsertSection( aSect ); 2211 2212 pDDETyp = 0; // FeldTypen wieder entfernen 2213 } 2214 else 2215 { 2216 // Einfuegen 2217 SwDDEField aSwDDEField( pDDETyp ); 2218 rWrtShell.Insert( aSwDDEField ); 2219 } 2220 2221 } while( sal_False ); 2222 } 2223 else 2224 pDDETyp = 0; // FeldTypen wieder entfernen 2225 2226 if( !pDDETyp && !bDoublePaste ) 2227 { 2228 // FeldTyp wieder entfernen - Fehler aufgetreten! 2229 for( j = nSize; j >= INIT_FLDTYPES; --j ) 2230 if( pTyp == rWrtShell.GetFldType( j ) ) 2231 { 2232 rWrtShell.RemoveFldType( j ); 2233 break; 2234 } 2235 } 2236 2237 return 1; 2238 } 2239 2240 // ----------------------------------------------------------------------- 2241 2242 int SwTransferable::_PasteSdrFormat( TransferableDataHelper& rData, 2243 SwWrtShell& rSh, sal_uInt16 nAction, 2244 const Point* pPt, sal_uInt8 nActionFlags, bool bNeedToSelectBeforePaste) 2245 { 2246 int nRet = 0; 2247 SotStorageStreamRef xStrm; 2248 if( rData.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStrm )) 2249 { 2250 xStrm->SetVersion( SOFFICE_FILEFORMAT_50 ); 2251 2252 if(bNeedToSelectBeforePaste && pPt) 2253 { 2254 // if this is an internal drag, need to set the target right (select it), else 2255 // still the source will be selected 2256 SwTransferable::SetSelInShell( rSh, sal_True, pPt ); 2257 } 2258 2259 rSh.Paste( *xStrm, nAction, pPt ); 2260 nRet = 1; 2261 2262 if( nRet && ( nActionFlags & 2263 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) )) 2264 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False ); 2265 } 2266 return nRet; 2267 } 2268 2269 // ----------------------------------------------------------------------- 2270 2271 int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, 2272 sal_uLong nFmt, sal_uInt16 nAction, const Point* pPt, 2273 sal_uInt8 nActionFlags, sal_Int8 /* nDropAction */, bool bNeedToSelectBeforePaste) 2274 { 2275 int nRet = 0; 2276 2277 Graphic aGrf; 2278 INetBookmark aBkmk; 2279 sal_Bool bCheckForGrf = sal_False, bCheckForImageMap = sal_False; 2280 2281 switch( nFmt ) 2282 { 2283 case SOT_FORMAT_BITMAP: 2284 case SOT_FORMAT_GDIMETAFILE: 2285 nRet = rData.GetGraphic( nFmt, aGrf ); 2286 break; 2287 2288 case SOT_FORMATSTR_ID_SVXB: 2289 { 2290 SotStorageStreamRef xStm; 2291 2292 if(rData.GetSotStorageStream(SOT_FORMATSTR_ID_SVXB, xStm)) 2293 { 2294 *xStm >> aGrf; 2295 nRet = (GRAPHIC_NONE != aGrf.GetType() && GRAPHIC_DEFAULT != aGrf.GetType()); 2296 } 2297 2298 break; 2299 } 2300 2301 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: 2302 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 2303 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR: 2304 if( 0 != ( nRet = rData.GetINetBookmark( nFmt, aBkmk ) )) 2305 { 2306 /* if( SW_PASTESDR_SETATTR != nAction ) 2307 { 2308 INetURLObject aURL( aBkmk.GetURL() ); 2309 bCheckForGrf = INET_PROT_FILE == aURL.GetProtocol(); 2310 nRet = 0 != bCheckForGrf; 2311 } 2312 */ 2313 if( SW_PASTESDR_SETATTR == nAction ) 2314 nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK; 2315 else 2316 bCheckForGrf = sal_True; 2317 } 2318 break; 2319 2320 case SOT_FORMAT_FILE: 2321 { 2322 String sTxt; 2323 if( 0 != ( nRet = rData.GetString( nFmt, sTxt ) ) ) 2324 { 2325 String sDesc; 2326 SwTransferable::_CheckForURLOrLNKFile( rData, sTxt, &sDesc ); 2327 2328 aBkmk = INetBookmark( 2329 URIHelper::SmartRel2Abs(INetURLObject(), sTxt, Link(), false ), 2330 sDesc ); 2331 bCheckForGrf = sal_True; 2332 bCheckForImageMap = SW_PASTESDR_REPLACE == nAction; 2333 } 2334 } 2335 break; 2336 2337 default: 2338 nRet = rData.GetGraphic( nFmt, aGrf ); 2339 break; 2340 } 2341 2342 if( bCheckForGrf ) 2343 { 2344 //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die 2345 // Grafiken zu testen !!!! 2346 GraphicFilter *pFlt = GraphicFilter::GetGraphicFilter(); 2347 nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( aBkmk.GetURL(), aEmptyStr, 2348 aGrf, pFlt ); 2349 if( !nRet && SW_PASTESDR_SETATTR == nAction && 2350 SOT_FORMAT_FILE == nFmt && 2351 // Bug 63031 - nur bei Rahmenselektion 2352 rSh.IsFrmSelected() ) 2353 { 2354 // dann als Hyperlink hinter die Grafik setzen 2355 nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK; 2356 nRet = sal_True; 2357 } 2358 } 2359 2360 if(pPt && bNeedToSelectBeforePaste) 2361 { 2362 // when using internal D&Ds, still the source object is selected and 2363 // this is necessary to get the correct source data which is also 2364 // dependent from selection. After receiving the drag data it is 2365 // now tiime to select the correct target object 2366 SwTransferable::SetSelInShell( rSh, sal_True, pPt ); 2367 } 2368 2369 if( nRet ) 2370 { 2371 String sURL; 2372 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) 2373 sURL = aBkmk.GetURL(); 2374 2375 switch( nAction ) 2376 { 2377 case SW_PASTESDR_INSERT: 2378 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2379 rSh.Insert( sURL, aEmptyStr, aGrf ); 2380 break; 2381 2382 case SW_PASTESDR_REPLACE: 2383 if( rSh.IsObjSelected() ) 2384 { 2385 rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf ); 2386 Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() ); 2387 SwTransferable::SetSelInShell( rSh, sal_True, &aPt ); 2388 } 2389 else 2390 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 2391 break; 2392 2393 case SW_PASTESDR_SETATTR: 2394 if( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK == nFmt ) 2395 { 2396 if( rSh.IsFrmSelected() ) 2397 { 2398 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2399 rSh.GetFlyFrmAttr( aSet ); 2400 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2401 aURL.SetURL( aBkmk.GetURL(), sal_False ); 2402 aSet.Put( aURL ); 2403 rSh.SetFlyFrmAttr( aSet ); 2404 } 2405 } 2406 else if( rSh.IsObjSelected() ) 2407 rSh.Paste( aGrf ); 2408 else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() ) 2409 rSh.ReRead( sURL, aEmptyStr, &aGrf ); 2410 else 2411 { 2412 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2413 rSh.Insert( aBkmk.GetURL(), aEmptyStr, aGrf ); 2414 } 2415 break; 2416 default: 2417 nRet = 0; 2418 } 2419 } 2420 2421 if( nRet ) 2422 { 2423 2424 if( nActionFlags & 2425 (( EXCHG_OUT_ACTION_FLAG_INSERT_IMAGEMAP | 2426 EXCHG_OUT_ACTION_FLAG_REPLACE_IMAGEMAP ) >> 8) ) 2427 SwTransferable::_PasteImageMap( rData, rSh ); 2428 2429 if( nActionFlags & 2430 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ) 2431 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False ); 2432 } 2433 else if( bCheckForImageMap ) 2434 { 2435 // oder sollte das File ein ImageMap-File sein? 2436 ImageMap aMap; 2437 SfxMedium aMed( INetURLObject(aBkmk.GetURL()).GetFull(), 2438 STREAM_STD_READ, sal_False ); 2439 SvStream* pStream = aMed.GetInStream(); 2440 if( pStream != NULL && 2441 !pStream->GetError() && 2442 // mba: no BaseURL for clipboard functionality 2443 aMap.Read( *pStream, IMAP_FORMAT_DETECT, String() ) == IMAP_ERR_OK && 2444 aMap.GetIMapObjectCount() ) 2445 { 2446 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2447 rSh.GetFlyFrmAttr( aSet ); 2448 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2449 aURL.SetMap( &aMap ); 2450 aSet.Put( aURL ); 2451 rSh.SetFlyFrmAttr( aSet ); 2452 nRet = 1; 2453 } 2454 } 2455 2456 return nRet; 2457 } 2458 2459 // ----------------------------------------------------------------------- 2460 2461 int SwTransferable::_PasteImageMap( TransferableDataHelper& rData, 2462 SwWrtShell& rSh ) 2463 { 2464 int nRet = 0; 2465 if( rData.HasFormat( SOT_FORMATSTR_ID_SVIM )) 2466 { 2467 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2468 rSh.GetFlyFrmAttr( aSet ); 2469 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 2470 const ImageMap* pOld = aURL.GetMap(); 2471 2472 // setzen oder ersetzen ist hier die Frage 2473 ImageMap aImageMap; 2474 if( rData.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) && 2475 ( !pOld || aImageMap != *pOld )) 2476 { 2477 aURL.SetMap( &aImageMap ); 2478 aSet.Put( aURL ); 2479 rSh.SetFlyFrmAttr( aSet ); 2480 } 2481 nRet = 1; 2482 } 2483 return nRet; 2484 } 2485 2486 // ----------------------------------------------------------------------- 2487 2488 int SwTransferable::_PasteAsHyperlink( TransferableDataHelper& rData, 2489 SwWrtShell& rSh, sal_uLong nFmt ) 2490 { 2491 int nRet = 0; 2492 String sFile; 2493 if( rData.GetString( nFmt, sFile ) && sFile.Len() ) 2494 { 2495 String sDesc; 2496 SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc ); 2497 2498 //#41801# ersteinmal die URL absolut machen 2499 INetURLObject aURL; 2500 aURL.SetSmartProtocol( INET_PROT_FILE ); 2501 aURL.SetSmartURL( sFile ); 2502 sFile = aURL.GetMainURL( INetURLObject::NO_DECODE ); 2503 2504 switch( rSh.GetObjCntTypeOfSelection() ) 2505 { 2506 case OBJCNT_FLY: 2507 case OBJCNT_GRF: 2508 case OBJCNT_OLE: 2509 { 2510 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2511 rSh.GetFlyFrmAttr( aSet ); 2512 SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) ); 2513 aURL2.SetURL( sFile, sal_False ); 2514 if( !aURL2.GetName().Len() ) 2515 aURL2.SetName( sFile ); 2516 aSet.Put( aURL2 ); 2517 rSh.SetFlyFrmAttr( aSet ); 2518 } 2519 break; 2520 2521 default: 2522 { 2523 rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ), 2524 sDesc.Len() ? sDesc : sFile ); 2525 } 2526 } 2527 nRet = sal_True; 2528 } 2529 return nRet; 2530 } 2531 2532 // ----------------------------------------------------------------------- 2533 2534 int SwTransferable::_PasteFileName( TransferableDataHelper& rData, 2535 SwWrtShell& rSh, sal_uLong nFmt, 2536 sal_uInt16 nAction, const Point* pPt, 2537 sal_uInt8 nActionFlags, sal_Bool /* bMsg */) 2538 { 2539 int nRet = SwTransferable::_PasteGrf( rData, rSh, nFmt, nAction, 2540 pPt, nActionFlags, 0, false); 2541 if( nRet ) 2542 nRet |= SWTRANSFER_GRAPHIC_INSERTED; 2543 if( !nRet ) 2544 { 2545 String sFile, sDesc; 2546 if( rData.GetString( nFmt, sFile ) && sFile.Len() ) 2547 { 2548 INetURLObject aMediaURL; 2549 2550 aMediaURL.SetSmartURL( sFile ); 2551 const String aMediaURLStr( aMediaURL.GetMainURL( INetURLObject::NO_DECODE ) ); 2552 2553 if( ::avmedia::MediaWindow::isMediaURL( aMediaURLStr ) ) 2554 { 2555 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aMediaURLStr ); 2556 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( 2557 SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON, 2558 &aMediaURLItem, 0L ); 2559 } 2560 else 2561 { 2562 sal_Bool bIsURLFile = SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc ); 2563 2564 //Eigenes FileFormat? -->Einfuegen, nicht fuer StarWriter/Web 2565 String sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link(), false ); 2566 const SfxFilter* pFlt = SW_PASTESDR_SETATTR == nAction 2567 ? 0 : SwIoSystem::GetFileFilter( 2568 sFileURL, aEmptyStr ); 2569 if( pFlt && !rSh.GetView().GetDocShell()->ISA(SwWebDocShell) 2570 /* 2571 JP 02.07.98: warum nur fuer die Formate ?? 2572 && ( pFlt->GetUserData() == FILTER_SW5 || 2573 pFlt->GetUserData() == FILTER_SW4 || 2574 pFlt->GetUserData() == FILTER_SW3 || 2575 pFlt->GetUserData() == FILTER_SWG ) 2576 */ 2577 ) 2578 { 2579 // und dann per PostUser Event den Bereich-Einfuegen-Dialog hochreissen 2580 SwSectionData * pSect = new SwSectionData( 2581 FILE_LINK_SECTION, 2582 rSh.GetDoc()->GetUniqueSectionName() ); 2583 pSect->SetLinkFileName( sFileURL ); 2584 pSect->SetProtectFlag( true ); 2585 2586 Application::PostUserEvent( STATIC_LINK( &rSh, SwWrtShell, 2587 InsertRegionDialog ), pSect ); 2588 nRet = 1; 2589 } 2590 else if( SW_PASTESDR_SETATTR == nAction || 2591 ( bIsURLFile && SW_PASTESDR_INSERT == nAction )) 2592 { 2593 //Fremde Files koennen wir immerhin noch als Links 2594 //Einfuegen. 2595 2596 //#41801# ersteinmal die URL absolut machen 2597 INetURLObject aURL; 2598 aURL.SetSmartProtocol( INET_PROT_FILE ); 2599 aURL.SetSmartURL( sFile ); 2600 sFile = aURL.GetMainURL( INetURLObject::NO_DECODE ); 2601 2602 switch( rSh.GetObjCntTypeOfSelection() ) 2603 { 2604 case OBJCNT_FLY: 2605 case OBJCNT_GRF: 2606 case OBJCNT_OLE: 2607 { 2608 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 2609 rSh.GetFlyFrmAttr( aSet ); 2610 SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) ); 2611 aURL2.SetURL( sFile, sal_False ); 2612 if( !aURL2.GetName().Len() ) 2613 aURL2.SetName( sFile ); 2614 aSet.Put( aURL2 ); 2615 rSh.SetFlyFrmAttr( aSet ); 2616 } 2617 break; 2618 2619 default: 2620 { 2621 rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ), 2622 sDesc.Len() ? sDesc : sFile ); 2623 } 2624 } 2625 nRet = sal_True; 2626 } 2627 } 2628 } 2629 } 2630 return nRet; 2631 } 2632 2633 // ----------------------------------------------------------------------- 2634 2635 int SwTransferable::_PasteDBData( TransferableDataHelper& rData, 2636 SwWrtShell& rSh, sal_uLong nFmt, sal_Bool bLink, 2637 const Point* pDragPt, sal_Bool bMsg ) 2638 { 2639 int nRet = 0; 2640 String sTxt; 2641 if( rData.GetString( nFmt, sTxt ) && sTxt.Len() ) 2642 { 2643 sal_uInt16 nWh = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == nFmt 2644 ? 0 2645 : SOT_FORMATSTR_ID_SBA_DATAEXCHANGE == nFmt 2646 ? (bLink 2647 ? FN_QRY_MERGE_FIELD 2648 : FN_QRY_INSERT) 2649 : (bLink 2650 ? 0 2651 : FN_QRY_INSERT_FIELD ); 2652 DataFlavorExVector& rVector = rData.GetDataFlavorExVector(); 2653 sal_Bool bHaveColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(rVector, CTF_COLUMN_DESCRIPTOR | CTF_CONTROL_EXCHANGE); 2654 if ( SOT_FORMATSTR_ID_XFORMS == nFmt ) 2655 { 2656 SdrObject* pObj; 2657 rSh.MakeDrawView(); 2658 FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() ); 2659 if(pFmView) { 2660 const OXFormsDescriptor &rDesc = OXFormsTransferable::extractDescriptor(rData); 2661 if(0 != (pObj = pFmView->CreateXFormsControl(rDesc))) 2662 { 2663 rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt ); 2664 } 2665 } 2666 } 2667 else if( nWh ) 2668 { 2669 SfxUsrAnyItem* pConnectionItem = 0; 2670 SfxUsrAnyItem* pCursorItem = 0; 2671 SfxUsrAnyItem* pColumnItem = 0; 2672 SfxUsrAnyItem* pSourceItem = 0; 2673 SfxUsrAnyItem* pCommandItem = 0; 2674 SfxUsrAnyItem* pCommandTypeItem = 0; 2675 SfxUsrAnyItem* pColumnNameItem = 0; 2676 SfxUsrAnyItem* pSelectionItem = 0; 2677 2678 sal_Bool bDataAvailable = sal_True; 2679 ODataAccessDescriptor aDesc; 2680 if(bHaveColumnDescriptor) 2681 aDesc = OColumnTransferable::extractColumnDescriptor(rData); 2682 else if(ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) ) 2683 aDesc = ODataAccessObjectTransferable::extractObjectDescriptor(rData); 2684 else 2685 bDataAvailable = sal_False; 2686 2687 if ( bDataAvailable ) 2688 { 2689 pConnectionItem = new SfxUsrAnyItem(FN_DB_CONNECTION_ANY, aDesc[daConnection]); 2690 pColumnItem = new SfxUsrAnyItem(FN_DB_COLUMN_ANY, aDesc[daColumnObject]); 2691 pSourceItem = new SfxUsrAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource())); 2692 pCommandItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[daCommand]); 2693 pCommandTypeItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[daCommandType]); 2694 pColumnNameItem = new SfxUsrAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[daColumnName]); 2695 pSelectionItem = new SfxUsrAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[daSelection]); 2696 pCursorItem = new SfxUsrAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[daCursor]); 2697 } 2698 2699 SwView& rView = rSh.GetView(); 2700 //force ::SelectShell 2701 rView.StopShellTimer(); 2702 2703 SfxStringItem aDataDesc( nWh, sTxt ); 2704 rView.GetViewFrame()->GetDispatcher()->Execute( 2705 nWh, SFX_CALLMODE_ASYNCHRON, &aDataDesc, 2706 pConnectionItem, pColumnItem, 2707 pSourceItem, pCommandItem, pCommandTypeItem, 2708 pColumnNameItem, pSelectionItem, pCursorItem,0L); 2709 delete pConnectionItem; 2710 delete pColumnItem; 2711 delete pSourceItem; 2712 delete pCommandItem; 2713 delete pCommandTypeItem; 2714 delete pColumnNameItem; 2715 delete pCursorItem; 2716 } 2717 else 2718 { 2719 SdrObject* pObj; 2720 rSh.MakeDrawView(); 2721 FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() ); 2722 if (pFmView && bHaveColumnDescriptor) 2723 { 2724 if ( 0 != (pObj = pFmView->CreateFieldControl( OColumnTransferable::extractColumnDescriptor(rData) ) ) ) 2725 rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt ); 2726 } 2727 } 2728 nRet = 1; 2729 } 2730 else if( bMsg ) 2731 { 2732 InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute(); 2733 } 2734 return nRet; 2735 } 2736 2737 // ----------------------------------------------------------------------- 2738 2739 int SwTransferable::_PasteFileList( TransferableDataHelper& rData, 2740 SwWrtShell& rSh, sal_Bool bLink, 2741 const Point* pPt, sal_Bool bMsg ) 2742 { 2743 int nRet = 0; 2744 FileList aFileList; 2745 if( rData.GetFileList( SOT_FORMAT_FILE_LIST, aFileList ) && 2746 aFileList.Count() ) 2747 { 2748 sal_uInt16 nAct = bLink ? SW_PASTESDR_SETATTR : SW_PASTESDR_INSERT; 2749 String sFlyNm; 2750 // iterate over the filelist 2751 for( sal_uLong n = 0, nEnd = aFileList.Count(); n < nEnd; ++n ) 2752 { 2753 TransferDataContainer* pHlp = new TransferDataContainer; 2754 pHlp->CopyString( FORMAT_FILE, aFileList.GetFile( n )); 2755 TransferableDataHelper aData( pHlp ); 2756 2757 if( SwTransferable::_PasteFileName( aData, rSh, SOT_FORMAT_FILE, nAct, 2758 pPt, sal_False, bMsg )) 2759 { 2760 if( bLink ) 2761 { 2762 sFlyNm = rSh.GetFlyName(); 2763 SwTransferable::SetSelInShell( rSh, sal_False, pPt ); 2764 } 2765 nRet = 1; 2766 } 2767 } 2768 if( sFlyNm.Len() ) 2769 rSh.GotoFly( sFlyNm ); 2770 } 2771 else if( bMsg ) 2772 { 2773 InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute(); 2774 } 2775 return nRet; 2776 } 2777 2778 // ----------------------------------------------------------------------- 2779 2780 sal_Bool SwTransferable::_CheckForURLOrLNKFile( TransferableDataHelper& rData, 2781 String& rFileName, String* pTitle ) 2782 { 2783 sal_Bool bIsURLFile = sal_False; 2784 INetBookmark aBkmk; 2785 if( rData.GetINetBookmark( SOT_FORMATSTR_ID_SOLK, aBkmk ) ) 2786 { 2787 rFileName = aBkmk.GetURL(); 2788 if( pTitle ) 2789 *pTitle = aBkmk.GetDescription(); 2790 bIsURLFile = sal_True; 2791 } 2792 else 2793 { 2794 xub_StrLen nLen = rFileName.Len(); 2795 if( 4 < nLen && '.' == rFileName.GetChar( nLen - 4 )) 2796 { 2797 String sExt( rFileName.Copy( nLen - 3 )); 2798 if( sExt.EqualsIgnoreCaseAscii( "url" )) 2799 { 2800 ASSERT( !&rFileName, "how do we read today .URL - Files?" ); 2801 } 2802 } 2803 } 2804 return bIsURLFile; 2805 } 2806 2807 // ----------------------------------------------------------------------- 2808 2809 sal_Bool SwTransferable::IsPasteSpecial( const SwWrtShell& rWrtShell, 2810 const TransferableDataHelper& rData ) 2811 { 2812 // we can paste-special if there's an entry in the paste-special-format list 2813 SvxClipboardFmtItem aClipboardFmtItem(0); 2814 FillClipFmtItem( rWrtShell, rData, aClipboardFmtItem); 2815 return aClipboardFmtItem.Count() > 0; 2816 } 2817 2818 // ----------------------------------------------------------------------- 2819 2820 int SwTransferable::PasteFormat( SwWrtShell& rSh, 2821 TransferableDataHelper& rData, 2822 sal_uLong nFormat ) 2823 { 2824 SwWait aWait( *rSh.GetView().GetDocShell(), sal_False ); 2825 int nRet = 0; 2826 2827 sal_uLong nPrivateFmt = FORMAT_PRIVATE; 2828 SwTransferable *pClipboard = GetSwTransferable( rData ); 2829 if( pClipboard && 2830 ((TRNSFR_DOCUMENT|TRNSFR_GRAPHIC|TRNSFR_OLE) & pClipboard->eBufferType )) 2831 nPrivateFmt = SOT_FORMATSTR_ID_EMBED_SOURCE; 2832 2833 if( pClipboard && nPrivateFmt == nFormat ) 2834 nRet = pClipboard->PrivatePaste( rSh ); 2835 else if( rData.HasFormat( nFormat ) ) 2836 { 2837 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() ); 2838 sal_uInt16 nEventAction, 2839 nDestination = SwTransferable::GetSotDestination( rSh ), 2840 nSourceOptions = 2841 (( EXCHG_DEST_DOC_TEXTFRAME == nDestination || 2842 EXCHG_DEST_SWDOC_FREE_AREA == nDestination || 2843 EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination || 2844 EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination ) 2845 ? EXCHG_IN_ACTION_COPY 2846 : EXCHG_IN_ACTION_MOVE), 2847 nAction = SotExchange::GetExchangeAction( 2848 rData.GetDataFlavorExVector(), 2849 nDestination, 2850 nSourceOptions, /* ?? */ 2851 EXCHG_IN_ACTION_DEFAULT, /* ?? */ 2852 nFormat, nEventAction, nFormat, 2853 lcl_getTransferPointer ( xTransferable ) ); 2854 2855 if( EXCHG_INOUT_ACTION_NONE != nAction ) 2856 nRet = SwTransferable::PasteData( rData, rSh, nAction, nFormat, 2857 nDestination, sal_True, sal_False ); 2858 } 2859 return nRet; 2860 } 2861 2862 // ----------------------------------------------------------------------- 2863 2864 int SwTransferable::_TestAllowedFormat( const TransferableDataHelper& rData, 2865 sal_uLong nFormat, sal_uInt16 nDestination ) 2866 { 2867 sal_uInt16 nAction = EXCHG_INOUT_ACTION_NONE, nEventAction; 2868 if( rData.HasFormat( nFormat )) { 2869 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() ); 2870 nAction = SotExchange::GetExchangeAction( 2871 rData.GetDataFlavorExVector(), 2872 nDestination, EXCHG_IN_ACTION_COPY, 2873 EXCHG_IN_ACTION_COPY, nFormat, 2874 nEventAction, nFormat, 2875 lcl_getTransferPointer ( xTransferable ) ); 2876 } 2877 return EXCHG_INOUT_ACTION_NONE != nAction; 2878 } 2879 2880 // ----------------------------------------------------------------------- 2881 2882 /** 2883 * the list of formats which will be offered to the user in the 'Paste 2884 * Special...' dialog and the paste button menu 2885 */ 2886 static sal_uInt16 aPasteSpecialIds[] = 2887 { 2888 SOT_FORMATSTR_ID_HTML, 2889 SOT_FORMATSTR_ID_HTML_SIMPLE, 2890 SOT_FORMATSTR_ID_HTML_NO_COMMENT, 2891 FORMAT_RTF, 2892 FORMAT_STRING, 2893 SOT_FORMATSTR_ID_SONLK, 2894 SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, 2895 SOT_FORMATSTR_ID_DRAWING, 2896 SOT_FORMATSTR_ID_SVXB, 2897 FORMAT_GDIMETAFILE, 2898 FORMAT_BITMAP, 2899 SOT_FORMATSTR_ID_SVIM, 2900 SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, 2901 0 2902 }; 2903 2904 2905 int SwTransferable::PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper& rData ) 2906 { 2907 // Plain text == unformatted 2908 return SwTransferable::PasteFormat( rSh, rData, SOT_FORMAT_STRING ); 2909 } 2910 2911 // ----------------------------------------------------------------------- 2912 2913 int SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, sal_uLong& rFormatUsed ) 2914 { 2915 int nRet = 0; 2916 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 2917 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rSh.GetView().GetEditWin() ); 2918 2919 DataFlavorExVector aFormats( rData.GetDataFlavorExVector() ); 2920 TransferableObjectDescriptor aDesc; 2921 2922 sal_uInt16 nDest = SwTransferable::GetSotDestination( rSh ); 2923 2924 SwTransferable *pClipboard = GetSwTransferable( rData ); 2925 if( pClipboard ) 2926 { 2927 aDesc = pClipboard->aObjDesc; 2928 sal_uInt16 nResId; 2929 if( pClipboard->eBufferType & TRNSFR_DOCUMENT ) 2930 nResId = STR_PRIVATETEXT; 2931 else if( pClipboard->eBufferType & TRNSFR_GRAPHIC ) 2932 nResId = STR_PRIVATEGRAPHIC; 2933 else if( pClipboard->eBufferType == TRNSFR_OLE ) 2934 nResId = STR_PRIVATEOLE; 2935 else 2936 nResId = 0; 2937 2938 if( nResId ) 2939 { 2940 if( STR_PRIVATEOLE == nResId || STR_PRIVATEGRAPHIC == nResId ) 2941 { 2942 // add SOT_FORMATSTR_ID_EMBED_SOURCE to the formats. This 2943 // format display then the private format name. 2944 DataFlavorEx aFlavorEx; 2945 aFlavorEx.mnSotId = SOT_FORMATSTR_ID_EMBED_SOURCE; 2946 aFormats.insert( aFormats.begin(), aFlavorEx ); 2947 } 2948 pDlg->SetObjName( pClipboard->aObjDesc.maClassName, 2949 SW_RES( nResId ) ); 2950 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr ); 2951 } 2952 } 2953 else 2954 { 2955 if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) ) 2956 rData.GetTransferableObjectDescriptor( 2957 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc ); 2958 2959 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest )) 2960 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr ); 2961 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest )) 2962 pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyStr ); 2963 } 2964 2965 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest )) 2966 pDlg->Insert( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) ); 2967 2968 for( sal_uInt16* pIds = aPasteSpecialIds; *pIds; ++pIds ) 2969 if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest )) 2970 pDlg->Insert( *pIds, aEmptyStr ); 2971 2972 sal_uLong nFormat = pDlg->GetFormat( rData.GetTransferable() ); 2973 2974 if( nFormat ) 2975 nRet = SwTransferable::PasteFormat( rSh, rData, nFormat ); 2976 2977 if ( nRet ) 2978 rFormatUsed = nFormat; 2979 2980 delete pDlg; 2981 return nRet; 2982 } 2983 2984 2985 void SwTransferable::FillClipFmtItem( const SwWrtShell& rSh, 2986 const TransferableDataHelper& rData, 2987 SvxClipboardFmtItem & rToFill ) 2988 { 2989 sal_uInt16 nDest = SwTransferable::GetSotDestination( rSh ); 2990 2991 SwTransferable *pClipboard = GetSwTransferable( rData ); 2992 if( pClipboard ) 2993 { 2994 sal_uInt16 nResId; 2995 if( pClipboard->eBufferType & TRNSFR_DOCUMENT ) 2996 nResId = STR_PRIVATETEXT; 2997 else if( pClipboard->eBufferType & TRNSFR_GRAPHIC ) 2998 nResId = STR_PRIVATEGRAPHIC; 2999 else if( pClipboard->eBufferType == TRNSFR_OLE ) 3000 nResId = STR_PRIVATEOLE; 3001 else 3002 nResId = 0; 3003 3004 if( nResId ) 3005 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE, 3006 SW_RES( nResId ) ); 3007 } 3008 else 3009 { 3010 TransferableObjectDescriptor aDesc; 3011 if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) ) 3012 ((TransferableDataHelper&)rData).GetTransferableObjectDescriptor( 3013 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc ); 3014 3015 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest )) 3016 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE, 3017 aDesc.maTypeName ); 3018 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest )) 3019 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK_SOURCE ); 3020 3021 SotFormatStringId nFormat; 3022 if ( rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE) || rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE) ) 3023 { 3024 String sName,sSource; 3025 if ( SvPasteObjectHelper::GetEmbeddedName(rData,sName,sSource,nFormat) ) 3026 rToFill.AddClipbrdFormat( nFormat, sName ); 3027 } 3028 } 3029 3030 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest )) 3031 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) ); 3032 3033 for( sal_uInt16* pIds = aPasteSpecialIds; *pIds; ++pIds ) 3034 if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest )) 3035 rToFill.AddClipbrdFormat( *pIds, aEmptyStr ); 3036 } 3037 3038 void SwTransferable::SetDataForDragAndDrop( const Point& rSttPos ) 3039 { 3040 if(!pWrtShell) 3041 return; 3042 String sGrfNm; 3043 const int nSelection = pWrtShell->GetSelectionType(); 3044 if( nsSelectionType::SEL_GRF == nSelection) 3045 { 3046 AddFormat( SOT_FORMATSTR_ID_SVXB ); 3047 // --> OD 2005-02-09 #119353# - robust 3048 const Graphic* pGrf = pWrtShell->GetGraphic(); 3049 if ( pGrf && pGrf->IsSupportedGraphic() ) 3050 // <-- 3051 { 3052 AddFormat( FORMAT_GDIMETAFILE ); 3053 AddFormat( SOT_FORMATSTR_ID_PNG ); 3054 AddFormat( FORMAT_BITMAP ); 3055 } 3056 eBufferType = TRNSFR_GRAPHIC; 3057 pWrtShell->GetGrfNms( &sGrfNm, 0 ); 3058 } 3059 else if( nsSelectionType::SEL_OLE == nSelection ) 3060 { 3061 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 3062 PrepareOLE( aObjDesc ); 3063 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 3064 AddFormat( FORMAT_GDIMETAFILE ); 3065 eBufferType = TRNSFR_OLE; 3066 } 3067 //Gibt es ueberhaupt etwas zum bereitstellen? 3068 else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() || 3069 pWrtShell->IsObjSelected() ) 3070 { 3071 if( pWrtShell->IsObjSelected() ) 3072 eBufferType = TRNSFR_DRAWING; 3073 else 3074 { 3075 eBufferType = TRNSFR_DOCUMENT; 3076 if( SwWrtShell::NO_WORD != 3077 pWrtShell->IntelligentCut( nSelection, sal_False )) 3078 eBufferType = TransferBufferType( TRNSFR_DOCUMENT_WORD 3079 | eBufferType); 3080 } 3081 3082 if( nSelection & nsSelectionType::SEL_TBL_CELLS ) 3083 eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType); 3084 3085 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 3086 3087 //RTF vor das Metafile von OLE stellen, weil mit weniger verlusten 3088 //behaftet. 3089 if( !pWrtShell->IsObjSelected() ) 3090 { 3091 AddFormat( FORMAT_RTF ); 3092 AddFormat( SOT_FORMATSTR_ID_HTML ); 3093 } 3094 if( pWrtShell->IsSelection() ) 3095 AddFormat( FORMAT_STRING ); 3096 3097 if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM )) 3098 { 3099 AddFormat( SOT_FORMATSTR_ID_DRAWING ); 3100 if ( nSelection & nsSelectionType::SEL_DRW ) 3101 { 3102 AddFormat( FORMAT_GDIMETAFILE ); 3103 AddFormat( SOT_FORMATSTR_ID_PNG ); 3104 AddFormat( FORMAT_BITMAP ); 3105 } 3106 eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType ); 3107 3108 pClpGraphic = new Graphic; 3109 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic )) 3110 pOrigGrf = pClpGraphic; 3111 pClpBitmap = new Graphic; 3112 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap )) 3113 pOrigGrf = pClpBitmap; 3114 3115 // ist es ein URL-Button ? 3116 String sURL, sDesc; 3117 if( pWrtShell->GetURLFromButton( sURL, sDesc ) ) 3118 { 3119 AddFormat( FORMAT_STRING ); 3120 AddFormat( SOT_FORMATSTR_ID_SOLK ); 3121 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ); 3122 AddFormat( SOT_FORMATSTR_ID_FILECONTENT ); 3123 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ); 3124 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ); 3125 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType ); 3126 } 3127 } 3128 3129 //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt. 3130 //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage 3131 //auch noch mit delayed rendering beantwortet werden. 3132 aObjDesc.mbCanLink = sal_False; 3133 aObjDesc.maDragStartPos = rSttPos; 3134 aObjDesc.maSize = OutputDevice::LogicToLogic( Size( OLESIZE ), 3135 MAP_TWIP, MAP_100TH_MM ); 3136 PrepareOLE( aObjDesc ); 3137 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 3138 } 3139 else if( nSelection & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() ) 3140 { 3141 // ist nur ein Feld - Selektiert? 3142 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR ); 3143 Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY()); 3144 3145 if( pWrtShell->GetContentAtPos( aPos, aCntntAtPos ) ) 3146 { 3147 AddFormat( FORMAT_STRING ); 3148 AddFormat( SOT_FORMATSTR_ID_SOLK ); 3149 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ); 3150 AddFormat( SOT_FORMATSTR_ID_FILECONTENT ); 3151 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ); 3152 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ); 3153 eBufferType = TRNSFR_INETFLD; 3154 } 3155 } 3156 3157 if( pWrtShell->IsFrmSelected() ) 3158 { 3159 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL ); 3160 pWrtShell->GetFlyFrmAttr( aSet ); 3161 const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL ); 3162 if( rURL.GetMap() ) 3163 { 3164 pImageMap = new ImageMap( *rURL.GetMap() ); 3165 AddFormat( SOT_FORMATSTR_ID_SVIM ); 3166 } 3167 else if( rURL.GetURL().Len() ) 3168 { 3169 pTargetURL = new INetImage( sGrfNm, rURL.GetURL(), 3170 rURL.GetTargetFrameName(), 3171 aEmptyStr, Size() ); 3172 AddFormat( SOT_FORMATSTR_ID_INET_IMAGE ); 3173 } 3174 } 3175 } 3176 3177 void SwTransferable::StartDrag( Window* pWin, const Point& rPos ) 3178 { 3179 if(!pWrtShell) 3180 return; 3181 bOldIdle = pWrtShell->GetViewOptions()->IsIdle(); 3182 bCleanUp = sal_True; 3183 3184 ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( sal_False ); 3185 3186 if( pWrtShell->IsSelFrmMode() ) 3187 pWrtShell->ShowCrsr(); 3188 3189 SW_MOD()->pDragDrop = this; 3190 3191 SetDataForDragAndDrop( rPos ); 3192 3193 sal_Int8 nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK; 3194 SwDocShell* pDShell = pWrtShell->GetView().GetDocShell(); 3195 if( ( pDShell && pDShell->IsReadOnly() ) || pWrtShell->HasReadonlySel() ) 3196 nDragOptions &= ~DND_ACTION_MOVE; 3197 3198 TransferableHelper::StartDrag( pWin, nDragOptions ); 3199 } 3200 3201 void SwTransferable::DragFinished( sal_Int8 nAction ) 3202 { 3203 //Und noch die letzten Nacharbeiten damit alle Stati stimmen. 3204 if( DND_ACTION_MOVE == nAction ) 3205 { 3206 if( bCleanUp ) 3207 { 3208 //Es wurde auserhalb des Writers gedroped. Wir muessen noch 3209 //loeschen. 3210 3211 pWrtShell->StartAllAction(); 3212 pWrtShell->StartUndo( UNDO_UI_DRAG_AND_MOVE ); 3213 if ( pWrtShell->IsTableMode() ) 3214 pWrtShell->DeleteTblSel(); 3215 else 3216 { 3217 if ( !(pWrtShell->IsSelFrmMode() || pWrtShell->IsObjSelected()) ) 3218 //SmartCut, eines der Blanks mitnehmen. 3219 pWrtShell->IntelligentCut( pWrtShell->GetSelectionType(), sal_True ); 3220 pWrtShell->DelRight(); 3221 } 3222 pWrtShell->EndUndo( UNDO_UI_DRAG_AND_MOVE ); 3223 pWrtShell->EndAllAction(); 3224 } 3225 else 3226 { 3227 const int nSelection = pWrtShell->GetSelectionType(); 3228 if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF | 3229 nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW ) & nSelection ) 3230 { 3231 pWrtShell->EnterSelFrmMode(); 3232 } 3233 } 3234 } 3235 pWrtShell->GetView().GetEditWin().DragFinished(); 3236 3237 if( pWrtShell->IsSelFrmMode() ) 3238 pWrtShell->HideCrsr(); 3239 else 3240 pWrtShell->ShowCrsr(); 3241 //!! else if( DND_ACTION_NONE != nAction ) 3242 //!! pWrtShell->ShowCrsr(); 3243 //!! else 3244 //!! { 3245 //!! //Muss wohl sein weil gescrollt wurde und ?...? 3246 //!! pWrtShell->StartAction(); 3247 //!! pWrtShell->EndAction(); 3248 //!! } 3249 3250 ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( bOldIdle ); 3251 } 3252 3253 3254 /* */ 3255 3256 int SwTransferable::PrivatePaste( SwWrtShell& rShell ) 3257 { 3258 // erst den SelectionType erfragen, dann Action-Klammerung !!!! 3259 // (sonst wird nicht in eine TabellenSelektion gepastet!!!) 3260 ASSERT( !rShell.ActionPend(), "Paste darf nie eine Actionklammerung haben" ); 3261 if ( !pClpDocFac ) 3262 return sal_False; // the return value of the SwFEShell::Paste also is sal_Bool! 3263 3264 const int nSelection = rShell.GetSelectionType(); 3265 3266 // #111827# 3267 SwRewriter aRewriter; 3268 3269 SwTrnsfrActionAndUndo aAction( &rShell, UNDO_PASTE_CLIPBOARD); 3270 3271 bool bKillPaMs = false; 3272 3273 //Selektierten Inhalt loeschen, nicht bei Tabellen-Selektion und 3274 //Tabelle im Clipboard 3275 if( rShell.HasSelection() && !( nSelection & nsSelectionType::SEL_TBL_CELLS)) 3276 { 3277 bKillPaMs = true; 3278 rShell.SetRetainSelection( true ); 3279 rShell.DelRight(); 3280 // war ein Fly selektiert, so muss jetzt fuer eine gueltige 3281 // Cursor-Position gesorgt werden! (geparkter Cursor!) 3282 if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF | 3283 nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW | 3284 nsSelectionType::SEL_DRW_FORM ) & nSelection ) 3285 { 3286 // den Cursor wieder positionieren 3287 Point aPt( rShell.GetCharRect().Pos() ); 3288 rShell.SwCrsrShell::SetCrsr( aPt, sal_True ); 3289 } 3290 rShell.SetRetainSelection( false ); 3291 } 3292 3293 sal_Bool bInWrd = sal_False, bEndWrd = sal_False, bSttWrd = sal_False, 3294 bSmart = 0 != (TRNSFR_DOCUMENT_WORD & eBufferType); 3295 if( bSmart ) 3296 { 3297 // #108491# Why not for other Scripts? If TRNSFR_DOCUMENT_WORD is set, we have 3298 // a word in the buffer, word in this context means 'something with spaces at 3299 // beginning and end'. In this case we definitely want these spaces to be inserted 3300 // here. 3301 // if( SCRIPTTYPE_LATIN != rShell.GetScriptType() ) 3302 // bSmart = sal_False; 3303 // else 3304 // { 3305 bInWrd = rShell.IsInWrd(); 3306 bEndWrd = rShell.IsEndWrd(); 3307 bSmart = bInWrd || bEndWrd; 3308 if( bSmart ) 3309 { 3310 bSttWrd = rShell.IsSttWrd(); 3311 if( bSmart && !bSttWrd && (bInWrd || bEndWrd) ) 3312 rShell.SwEditShell::Insert(' '); 3313 } 3314 // } 3315 } 3316 3317 int nRet = rShell.Paste( pClpDocFac->GetDoc() ); 3318 3319 if( bKillPaMs ) 3320 rShell.KillPams(); 3321 3322 // Wenn Smart Paste dann Leerzeichen einfuegen 3323 if( nRet && bSmart && ((bInWrd && !bEndWrd )|| bSttWrd) ) 3324 rShell.SwEditShell::Insert(' '); 3325 3326 return nRet; 3327 } 3328 3329 int SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt, 3330 sal_Bool bMove, sal_Bool bIsXSelection ) 3331 { 3332 int cWord = 0; 3333 sal_Bool bInWrd = sal_False; 3334 sal_Bool bEndWrd = sal_False; 3335 sal_Bool bSttWrd = sal_False; 3336 sal_Bool bSttPara= sal_False; 3337 sal_Bool bTblSel = sal_False; 3338 sal_Bool bFrmSel = sal_False; 3339 3340 SwWrtShell& rSrcSh = *GetShell(); 3341 3342 rSh.UnSetVisCrsr(); 3343 3344 if( TRNSFR_INETFLD == eBufferType ) 3345 { 3346 if( rSh.GetFmtFromObj( rDragPt ) ) 3347 { 3348 INetBookmark aTmp; 3349 if( (TRNSFR_INETFLD & eBufferType) && pBkmk ) 3350 aTmp = *pBkmk; 3351 3352 // Zielgrafik selektieren 3353 if( rSh.SelectObj( rDragPt ) ) 3354 { 3355 rSh.HideCrsr(); 3356 rSh.EnterSelFrmMode( &rDragPt ); 3357 bFrmDrag = sal_True; 3358 } 3359 3360 const int nSelection = rSh.GetSelectionType(); 3361 3362 // Draw-Objekte erstmal noch nicht beruecksichtigen 3363 if( nsSelectionType::SEL_GRF & nSelection ) 3364 { 3365 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL ); 3366 rSh.GetFlyFrmAttr( aSet ); 3367 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) ); 3368 aURL.SetURL( aTmp.GetURL(), sal_False ); 3369 aSet.Put( aURL ); 3370 rSh.SetFlyFrmAttr( aSet ); 3371 return 1; 3372 } 3373 3374 if( nsSelectionType::SEL_DRW & nSelection ) 3375 { 3376 rSh.LeaveSelFrmMode(); 3377 rSh.UnSelectFrm(); 3378 rSh.ShowCrsr(); 3379 bFrmDrag = sal_False; 3380 } 3381 } 3382 } 3383 3384 if( &rSh != &rSrcSh && (nsSelectionType::SEL_GRF & rSh.GetSelectionType()) && 3385 TRNSFR_GRAPHIC == eBufferType ) 3386 { 3387 // ReRead auf die Grafik 3388 String sGrfNm, sFltNm; 3389 rSrcSh.GetGrfNms( &sGrfNm, &sFltNm ); 3390 rSh.ReRead( sGrfNm, sFltNm, rSrcSh.GetGraphic() ); 3391 return 1; 3392 } 3393 3394 //Nicht in Selektionen oder selektierten Rahmen 3395 if( rSh.ChgCurrPam( rDragPt ) || 3396 ( rSh.IsSelFrmMode() && rSh.IsInsideSelectedObj( rDragPt )) ) 3397 return 0; 3398 3399 if( rSrcSh.IsTableMode() ) 3400 bTblSel = sal_True; 3401 else if( rSrcSh.IsSelFrmMode() || rSrcSh.IsObjSelected() ) 3402 { 3403 // keine positionsgeschuetzten Objecte verschieben! 3404 if( bMove && rSrcSh.IsSelObjProtected( FLYPROTECT_POS ) ) 3405 return 0; 3406 3407 bFrmSel = sal_True; 3408 } 3409 3410 const int nSel = rSrcSh.GetSelectionType(); 3411 3412 SwUndoId eUndoId = bMove ? UNDO_UI_DRAG_AND_MOVE : UNDO_UI_DRAG_AND_COPY; 3413 3414 // #111827# 3415 SwRewriter aRewriter; 3416 3417 aRewriter.AddRule(UNDO_ARG1, rSrcSh.GetSelDescr()); 3418 3419 if(rSrcSh.GetDoc() != rSh.GetDoc()) 3420 rSrcSh.StartUndo( eUndoId, &aRewriter ); 3421 rSh.StartUndo( eUndoId, &aRewriter ); 3422 3423 rSh.StartAction(); 3424 rSrcSh.StartAction(); 3425 3426 if( &rSrcSh != &rSh ) 3427 { 3428 rSh.EnterStdMode(); 3429 rSh.SwCrsrShell::SetCrsr( rDragPt, sal_True ); 3430 cWord = rSrcSh.IntelligentCut( nSel, sal_False ); 3431 } 3432 else if( !bTblSel && !bFrmSel ) 3433 { 3434 if( !rSh.IsAddMode() ) 3435 { 3436 // --> OD 2008-03-19 #i87233# 3437 if ( rSh.IsBlockMode() ) 3438 { 3439 // preserve order of cursors for block mode 3440 rSh.GoPrevCrsr(); 3441 } 3442 // <-- 3443 rSh.SwCrsrShell::CreateCrsr(); 3444 } 3445 rSh.SwCrsrShell::SetCrsr( rDragPt, sal_True, false ); 3446 rSh.GoPrevCrsr(); 3447 cWord = rSh.IntelligentCut( rSh.GetSelectionType(), sal_False ); 3448 rSh.GoNextCrsr(); 3449 } 3450 3451 bInWrd = rSh.IsInWrd(); 3452 bEndWrd = rSh.IsEndWrd(); 3453 bSttWrd = !bEndWrd && rSh.IsSttWrd(); 3454 bSttPara= rSh.IsSttPara(); 3455 3456 Point aSttPt( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY() ); 3457 3458 //JP 05.03.96: INetFelder erstmal selektieren ! 3459 if( TRNSFR_INETFLD == eBufferType ) 3460 { 3461 if( &rSrcSh == &rSh ) 3462 { 3463 rSh.GoPrevCrsr(); 3464 rSh.SwCrsrShell::SetCrsr( aSttPt, sal_True ); 3465 rSh.SelectTxtAttr( RES_TXTATR_INETFMT ); 3466 if( rSh.ChgCurrPam( rDragPt ) ) 3467 { 3468 // nicht in sich selbst kopieren/verschieben 3469 rSh.DestroyCrsr(); 3470 rSh.EndUndo(); 3471 rSh.EndAction(); 3472 rSh.EndAction(); 3473 return 0; 3474 } 3475 rSh.GoNextCrsr(); 3476 } 3477 else 3478 { 3479 rSrcSh.SwCrsrShell::SetCrsr( aSttPt, sal_True ); 3480 rSrcSh.SelectTxtAttr( RES_TXTATR_INETFMT ); 3481 } 3482 3483 // ist am Einfuege Punkt ein URL-Attribut? Dann das ersetzen, 3484 // also einfach eine Selektion aufspannen? 3485 rSh.DelINetAttrWithText(); 3486 bDDINetAttr = sal_True; 3487 } 3488 3489 if ( rSrcSh.IsSelFrmMode() ) 3490 { 3491 //Hack: Spezialbehandlung austricksen 3492 aSttPt -= aSttPt - rSrcSh.GetObjRect().Pos(); 3493 } 3494 3495 sal_Bool bRet = rSrcSh.SwFEShell::Copy( &rSh, aSttPt, rDragPt, bMove, 3496 !bIsXSelection ); 3497 3498 if( !bIsXSelection ) 3499 { 3500 rSrcSh.Push(); 3501 if ( bRet && bMove && !bFrmSel ) 3502 { 3503 if ( bTblSel ) 3504 { 3505 /* #109590# delete table contents not cells */ 3506 rSrcSh.Delete(); 3507 } 3508 else 3509 { 3510 //SmartCut, eines der Blank mitnehmen. 3511 rSh.SwCrsrShell::DestroyCrsr(); 3512 if ( cWord == SwWrtShell::WORD_SPACE_BEFORE ) 3513 rSh.ExtendSelection( sal_False ); 3514 else if ( cWord == SwWrtShell::WORD_SPACE_AFTER ) 3515 rSh.ExtendSelection(); 3516 rSrcSh.DelRight(); 3517 } 3518 } 3519 rSrcSh.KillPams(); 3520 rSrcSh.Pop( sal_False ); 3521 3522 /* #109590# after dragging a table selection inside one shell 3523 set cursor to the drop position. */ 3524 if( &rSh == &rSrcSh && ( bTblSel || rSh.IsBlockMode() ) ) 3525 { 3526 rSrcSh.SwCrsrShell::SetCrsr(rDragPt); 3527 rSrcSh.GetSwCrsr()->SetMark(); 3528 } 3529 } 3530 3531 if( bRet && !bTblSel && !bFrmSel ) 3532 { 3533 if( (bInWrd || bEndWrd) && 3534 (cWord == SwWrtShell::WORD_SPACE_AFTER || 3535 cWord == SwWrtShell::WORD_SPACE_BEFORE) ) 3536 { 3537 if ( bSttWrd || (bInWrd && !bEndWrd)) 3538 rSh.SwEditShell::Insert(' ', bIsXSelection); 3539 if ( !bSttWrd || (bInWrd && !bSttPara) ) 3540 { 3541 rSh.SwapPam(); 3542 if ( !bSttWrd ) 3543 rSh.SwEditShell::Insert(' ', bIsXSelection); 3544 rSh.SwapPam(); 3545 } 3546 } 3547 3548 if( bIsXSelection ) 3549 { 3550 if( &rSrcSh == &rSh && !rSh.IsAddMode() ) 3551 { 3552 rSh.SwCrsrShell::DestroyCrsr(); 3553 rSh.GoPrevCrsr(); 3554 } 3555 else 3556 { 3557 rSh.SwapPam(); 3558 rSh.SwCrsrShell::ClearMark(); 3559 } 3560 } 3561 else 3562 { 3563 if( rSh.IsAddMode() ) 3564 rSh.SwCrsrShell::CreateCrsr(); 3565 else 3566 { 3567 // Selektionsmodus einschalten 3568 rSh.SttSelect(); 3569 rSh.EndSelect(); 3570 } 3571 } 3572 } 3573 3574 if( bRet && bMove && bFrmSel ) 3575 rSrcSh.LeaveSelFrmMode(); 3576 3577 if( rSrcSh.GetDoc() != rSh.GetDoc() ) 3578 rSrcSh.EndUndo(); 3579 rSh.EndUndo(); 3580 3581 // Shell in den richtigen Status versetzen 3582 if( &rSrcSh != &rSh && ( rSh.IsFrmSelected() || rSh.IsObjSelected() )) 3583 rSh.EnterSelFrmMode(); 3584 3585 rSrcSh.EndAction(); 3586 rSh.EndAction(); 3587 return 1; 3588 } 3589 3590 // Interfaces for Selection 3591 void SwTransferable::CreateSelection( SwWrtShell& rSh, 3592 const ViewShell * _pCreatorView ) 3593 { 3594 SwModule *pMod = SW_MOD(); 3595 SwTransferable* pNew = new SwTransferable( rSh ); 3596 3597 /* #96392#*/ 3598 pNew->pCreatorView = _pCreatorView; 3599 3600 uno::Reference< 3601 datatransfer::XTransferable > xRef( pNew ); 3602 pMod->pXSelection = pNew; 3603 pNew->CopyToSelection( rSh.GetWin() ); 3604 } 3605 3606 void SwTransferable::ClearSelection( SwWrtShell& rSh, 3607 const ViewShell * _pCreatorView) 3608 { 3609 SwModule *pMod = SW_MOD(); 3610 if( pMod->pXSelection && 3611 ((!pMod->pXSelection->pWrtShell) || (pMod->pXSelection->pWrtShell == &rSh)) && 3612 /* #96392# */ 3613 (!_pCreatorView || (pMod->pXSelection->pCreatorView == _pCreatorView)) ) 3614 { 3615 TransferableHelper::ClearSelection( rSh.GetWin() ); 3616 } 3617 } 3618 /* -----------------3/31/2003 11:46AM---------------- 3619 3620 --------------------------------------------------*/ 3621 const Sequence< sal_Int8 >& SwTransferable::getUnoTunnelId() 3622 { 3623 static Sequence< sal_Int8 > aSeq; 3624 if( !aSeq.getLength() ) 3625 { 3626 static osl::Mutex aCreateMutex; 3627 osl::Guard< osl::Mutex > aGuard( aCreateMutex ); 3628 aSeq.realloc( 16 ); 3629 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True ); 3630 } 3631 return aSeq; 3632 } 3633 /* -----------------3/31/2003 11:46AM---------------- 3634 3635 --------------------------------------------------*/ 3636 sal_Int64 SwTransferable::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException ) 3637 { 3638 sal_Int64 nRet; 3639 if( ( rId.getLength() == 16 ) && 3640 ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ) 3641 { 3642 nRet = sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) ); 3643 } 3644 else 3645 nRet = TransferableHelper::getSomething(rId); 3646 return nRet; 3647 } 3648 3649 SwTransferable* SwTransferable::GetSwTransferable( const TransferableDataHelper& rData ) 3650 { 3651 SwTransferable* pSwTransferable = NULL; 3652 3653 uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY ); 3654 if ( xTunnel.is() ) 3655 { 3656 sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() ); 3657 if ( nHandle ) 3658 pSwTransferable = (SwTransferable*) (sal_IntPtr) nHandle; 3659 } 3660 3661 return pSwTransferable; 3662 3663 } 3664 3665 /* */ 3666 3667 // ----------------------------------------------------------------------- 3668 3669 SwTrnsfrDdeLink::SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh ) 3670 : rTrnsfr( rTrans ), pDocShell( 0 ), 3671 bDelBookmrk( sal_False ), bInDisconnect( sal_False ) 3672 { 3673 // hier kommen wir nur bei Tabellen- oder Text-Selection an 3674 const int nSelection = rSh.GetSelectionType(); 3675 if( nsSelectionType::SEL_TBL_CELLS & nSelection ) 3676 { 3677 SwFrmFmt* pFmt = rSh.GetTableFmt(); 3678 if( pFmt ) 3679 sName = pFmt->GetName(); 3680 } 3681 else 3682 { 3683 // creating a temp. bookmark without undo 3684 sal_Bool bUndo = rSh.DoesUndo(); 3685 rSh.DoUndo( sal_False ); 3686 sal_Bool bIsModified = rSh.IsModified(); 3687 3688 ::sw::mark::IMark* pMark = rSh.SetBookmark( 3689 KeyCode(), 3690 ::rtl::OUString(), 3691 ::rtl::OUString(), 3692 IDocumentMarkAccess::DDE_BOOKMARK); 3693 if(pMark) 3694 { 3695 sName = pMark->GetName(); 3696 bDelBookmrk = sal_True; 3697 if( !bIsModified ) 3698 rSh.ResetModified(); 3699 } 3700 else 3701 sName.Erase(); 3702 rSh.DoUndo( bUndo ); 3703 } 3704 3705 if( sName.Len() && 3706 0 != ( pDocShell = rSh.GetDoc()->GetDocShell() ) ) 3707 { 3708 // dann erzeugen wir uns mal unseren "Server" und connecten uns 3709 // zu diesem 3710 refObj = pDocShell->DdeCreateLinkSource( sName ); 3711 if( refObj.Is() ) 3712 { 3713 refObj->AddConnectAdvise( this ); 3714 refObj->AddDataAdvise( this, 3715 // SotExchange::GetFormatMimeType( FORMAT_RTF ), 3716 aEmptyStr, 3717 ADVISEMODE_NODATA | ADVISEMODE_ONLYONCE ); 3718 nOldTimeOut = refObj->GetUpdateTimeout(); 3719 refObj->SetUpdateTimeout( 0 ); 3720 } 3721 } 3722 } 3723 3724 // ----------------------------------------------------------------------- 3725 3726 SwTrnsfrDdeLink::~SwTrnsfrDdeLink() 3727 { 3728 if( refObj.Is() ) 3729 Disconnect( sal_True ); 3730 } 3731 3732 // ----------------------------------------------------------------------- 3733 3734 void SwTrnsfrDdeLink::DataChanged( const String& , 3735 const uno::Any& ) 3736 { 3737 // tja das wars dann mit dem Link 3738 if( !bInDisconnect ) 3739 { 3740 if( FindDocShell() && pDocShell->GetView() ) 3741 rTrnsfr.RemoveDDELinkFormat( pDocShell->GetView()->GetEditWin() ); 3742 Disconnect( sal_False ); 3743 } 3744 } 3745 3746 // ----------------------------------------------------------------------- 3747 3748 sal_Bool SwTrnsfrDdeLink::WriteData( SvStream& rStrm ) 3749 { 3750 if( !refObj.Is() || !FindDocShell() ) 3751 return sal_False; 3752 3753 rtl_TextEncoding eEncoding = DDE_TXT_ENCODING; 3754 const ByteString aAppNm( GetpApp()->GetAppName(), eEncoding ); 3755 const ByteString aTopic( pDocShell->GetTitle( SFX_TITLE_FULLNAME ), 3756 eEncoding ); 3757 const ByteString aName( sName, eEncoding ); 3758 3759 sal_Char* pMem = new char[ aAppNm.Len() + aTopic.Len() + aName.Len() + 4 ]; 3760 3761 xub_StrLen nLen = aAppNm.Len(); 3762 memcpy( pMem, aAppNm.GetBuffer(), nLen ); 3763 pMem[ nLen++ ] = 0; 3764 memcpy( pMem + nLen, aTopic.GetBuffer(), aTopic.Len() ); 3765 nLen = nLen + aTopic.Len(); 3766 pMem[ nLen++ ] = 0; 3767 memcpy( pMem + nLen, aName.GetBuffer(), aName.Len() ); 3768 nLen = nLen + aName.Len(); 3769 pMem[ nLen++ ] = 0; 3770 pMem[ nLen++ ] = 0; 3771 3772 rStrm.Write( pMem, nLen ); 3773 delete[] pMem; 3774 3775 IDocumentMarkAccess* const pMarkAccess = pDocShell->GetDoc()->getIDocumentMarkAccess(); 3776 IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName); 3777 if(ppMark != pMarkAccess->getMarksEnd() 3778 && IDocumentMarkAccess::GetType(**ppMark) != IDocumentMarkAccess::BOOKMARK) 3779 { 3780 // the mark is still a DdeBookmark 3781 // we replace it with a Bookmark, so it will get saved etc. 3782 ::sw::mark::IMark* const pMark = ppMark->get(); 3783 SwServerObject* const pServerObject = dynamic_cast<SwServerObject *>(&refObj); 3784 3785 // collecting state of old mark 3786 SwPaM aPaM(pMark->GetMarkStart()); 3787 *aPaM.GetPoint() = pMark->GetMarkStart(); 3788 if(pMark->IsExpanded()) 3789 { 3790 aPaM.SetMark(); 3791 *aPaM.GetMark() = pMark->GetMarkEnd(); 3792 } 3793 ::rtl::OUString sMarkName = pMark->GetName(); 3794 3795 // remove mark 3796 pServerObject->SetNoServer(); // this removes the connection between SwServerObject and mark 3797 // N.B. ppMark was not loaded from file and cannot have xml:id 3798 pMarkAccess->deleteMark(ppMark); 3799 3800 // recreate as Bookmark 3801 ::sw::mark::IMark* const pNewMark = pMarkAccess->makeMark( 3802 aPaM, 3803 sMarkName, 3804 IDocumentMarkAccess::BOOKMARK); 3805 pServerObject->SetDdeBookmark(*pNewMark); 3806 } 3807 3808 bDelBookmrk = false; 3809 return true; 3810 } 3811 3812 // ----------------------------------------------------------------------- 3813 3814 void SwTrnsfrDdeLink::Disconnect( sal_Bool bRemoveDataAdvise ) 3815 { 3816 //JP 29.01.96 Bug 24432: 3817 // kein DataChanged mehr entgegen nehmen, wenn man 3818 // sich schon im Disconnet befindet! 3819 // (DTOR vom Bookmark verschickt einen DataChanged!) 3820 const sal_Bool bOldDisconnect = bInDisconnect; 3821 bInDisconnect = sal_True; 3822 3823 // den nicht verwendeten Bookmark wieder zerstoeren (ohne Undo!)? 3824 if( bDelBookmrk && refObj.Is() && FindDocShell() ) 3825 { 3826 SwDoc* pDoc = pDocShell->GetDoc(); 3827 ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo()); 3828 3829 // --> OD, CD, OS 2005-11-25 #i58448# 3830 Link aSavedOle2Link( pDoc->GetOle2Link() ); 3831 pDoc->SetOle2Link( Link() ); 3832 // <-- 3833 sal_Bool bIsModified = pDoc->IsModified(); 3834 3835 IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess(); 3836 // check, if DdeBookmark is already in its desctruction 3837 IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName); 3838 if ( ppMark != pMarkAccess->getMarksEnd() ) 3839 { 3840 ::sw::mark::DdeBookmark* const pDdeBookmark = dynamic_cast< ::sw::mark::DdeBookmark* >(ppMark->get()); 3841 if ( pDdeBookmark && !pDdeBookmark->IsInDestruction() ) 3842 { 3843 pMarkAccess->deleteMark(ppMark); 3844 } 3845 } 3846 3847 if( !bIsModified ) 3848 pDoc->ResetModified(); 3849 pDoc->SetOle2Link( aSavedOle2Link ); 3850 3851 bDelBookmrk = sal_False; 3852 } 3853 3854 if( refObj.Is() ) 3855 { 3856 refObj->SetUpdateTimeout( nOldTimeOut ); 3857 refObj->RemoveConnectAdvise( this ); 3858 if( bRemoveDataAdvise ) 3859 // in einem DataChanged darf das SelectionObject NIE geloescht 3860 // werden; wird schon von der Basisklasse erledigt 3861 // (ADVISEMODE_ONLYONCE!!!!) 3862 // Im normalen Disconnet aber schon! 3863 refObj->RemoveAllDataAdvise( this ); 3864 refObj.Clear(); 3865 } 3866 bInDisconnect = bOldDisconnect; 3867 } 3868 3869 // ----------------------------------------------------------------------- 3870 3871 sal_Bool SwTrnsfrDdeLink::FindDocShell() 3872 { 3873 TypeId aType( TYPE( SwDocShell ) ); 3874 SfxObjectShell* pTmpSh = SfxObjectShell::GetFirst( &aType ); 3875 while( pTmpSh ) 3876 { 3877 if( pTmpSh == pDocShell ) // die wollen wir haben 3878 { 3879 if( pDocShell->GetDoc() ) 3880 return sal_True; 3881 break; // das Doc ist nicht mehr vorhanden, also raus! 3882 } 3883 pTmpSh = SfxObjectShell::GetNext( *pTmpSh, &aType ); 3884 } 3885 3886 pDocShell = 0; 3887 return sal_False; 3888 } 3889 3890 // ----------------------------------------------------------------------- 3891 3892 void SwTrnsfrDdeLink::Closed() 3893 { 3894 if( !bInDisconnect && refObj.Is() ) 3895 { 3896 refObj->RemoveAllDataAdvise( this ); 3897 refObj->RemoveConnectAdvise( this ); 3898 refObj.Clear(); 3899 } 3900 } 3901