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