1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp> 31 #include <com/sun/star/embed/Aspects.hpp> 32 33 34 #include <svx/unomodel.hxx> 35 #include <unotools/streamwrap.hxx> 36 37 //------------------------------------------------------------------ 38 39 #include <svx/dbexch.hrc> 40 #include <svx/fmmodel.hxx> 41 #include <svx/svdetc.hxx> 42 #include <svx/svditer.hxx> 43 #include <svx/svdobj.hxx> 44 #include <svx/svdogrp.hxx> 45 #include <svx/svdouno.hxx> 46 #include <svx/svdoole2.hxx> 47 #include <svx/svdpage.hxx> 48 #include <sfx2/dispatch.hxx> 49 #include <sfx2/docfile.hxx> 50 #include <sot/clsids.hxx> 51 #include <sot/formats.hxx> 52 #include <sot/filelist.hxx> 53 #include <unotools/pathoptions.hxx> 54 #include <svl/ptitem.hxx> 55 #include <svl/stritem.hxx> 56 #include <svtools/transfer.hxx> 57 #include <vcl/graph.hxx> 58 59 #include <comphelper/storagehelper.hxx> 60 #include <comphelper/processfactory.hxx> 61 62 #include <sot/formats.hxx> 63 #define SOT_FORMATSTR_ID_STARCALC_CURRENT SOT_FORMATSTR_ID_STARCALC_50 64 65 #include "viewfunc.hxx" 66 #include "docsh.hxx" 67 #include "drawview.hxx" 68 #include "impex.hxx" 69 #include "dbfunc.hxx" 70 #include "dbcolect.hxx" 71 #include "sc.hrc" 72 #include "filter.hxx" 73 #include "scextopt.hxx" 74 #include "tabvwsh.hxx" // wegen GetViewFrame 75 #include "compiler.hxx" 76 77 #include "asciiopt.hxx" 78 #include "scabstdlg.hxx" 79 #include "clipparam.hxx" 80 #include <vcl/msgbox.hxx> 81 #include <sfx2/viewfrm.hxx> 82 #include <svx/dbaexchange.hxx> 83 84 using namespace com::sun::star; 85 86 //------------------------------------------------------------------ 87 88 sal_Bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, 89 const uno::Reference<datatransfer::XTransferable>& rxTransferable, 90 SCCOL nPosX, SCROW nPosY, Point* pLogicPos, sal_Bool bLink, sal_Bool bAllowDialogs ) 91 { 92 ScDocument* pDoc = GetViewData()->GetDocument(); 93 pDoc->SetPastingDrawFromOtherDoc( sal_True ); 94 95 Point aPos; // inserting position (1/100 mm) 96 if (pLogicPos) 97 aPos = *pLogicPos; 98 else 99 { 100 // inserting position isn't needed for text formats 101 sal_Bool bIsTextFormat = ( ScImportExport::IsFormatSupported( nFormatId ) || 102 nFormatId == FORMAT_RTF ); 103 if ( !bIsTextFormat ) 104 { 105 // Window MapMode isn't drawing MapMode if DrawingLayer hasn't been created yet 106 107 SCTAB nTab = GetViewData()->GetTabNo(); 108 long nXT = 0; 109 for (SCCOL i=0; i<nPosX; i++) 110 nXT += pDoc->GetColWidth(i,nTab); 111 if (pDoc->IsNegativePage(nTab)) 112 nXT = -nXT; 113 sal_uLong nYT = pDoc->GetRowHeight( 0, nPosY-1, nTab); 114 aPos = Point( (long)(nXT * HMM_PER_TWIPS), (long)(nYT * HMM_PER_TWIPS) ); 115 } 116 } 117 118 TransferableDataHelper aDataHelper( rxTransferable ); 119 sal_Bool bRet = sal_False; 120 121 // 122 // handle individual formats 123 // 124 125 if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE || 126 nFormatId == SOT_FORMATSTR_ID_LINK_SOURCE || 127 nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE || 128 nFormatId == SOT_FORMATSTR_ID_LINK_SOURCE_OLE || 129 nFormatId == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) 130 { 131 uno::Reference < io::XInputStream > xStm; 132 TransferableObjectDescriptor aObjDesc; 133 134 if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) && 135 aDataHelper.GetInputStream( nFormatId, xStm ) ) 136 { 137 if ( aObjDesc.maClassName == SvGlobalName( SO3_SC_CLASSID_60 ) ) 138 { 139 uno::Reference < embed::XStorage > xStore = ::comphelper::OStorageHelper::GetStorageFromInputStream( xStm ); 140 141 // mba: BaseURL doesn't make sense for clipboard 142 // #i43716# Medium must be allocated with "new". 143 // DoLoad stores the pointer and deletes it with the SfxObjectShell. 144 SfxMedium* pMedium = new SfxMedium( xStore, String() ); 145 146 // TODO/LATER: is it a problem that we don't support binary formats here? 147 ScDocShellRef xDocShRef = new ScDocShell(SFX_CREATE_MODE_EMBEDDED); 148 if (xDocShRef->DoLoad(pMedium)) 149 { 150 ScDocument* pSrcDoc = xDocShRef->GetDocument(); 151 SCTAB nSrcTab = pSrcDoc->GetVisibleTab(); 152 if (!pSrcDoc->HasTable(nSrcTab)) 153 nSrcTab = 0; 154 155 ScMarkData aSrcMark; 156 aSrcMark.SelectOneTable( nSrcTab ); // for CopyToClip 157 ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); 158 159 SCCOL nFirstCol, nLastCol; 160 SCROW nFirstRow, nLastRow; 161 if ( pSrcDoc->GetDataStart( nSrcTab, nFirstCol, nFirstRow ) ) 162 pSrcDoc->GetCellArea( nSrcTab, nLastCol, nLastRow ); 163 else 164 { 165 nFirstCol = nLastCol = 0; 166 nFirstRow = nLastRow = 0; 167 } 168 ScClipParam aClipParam(ScRange(nFirstCol, nFirstRow, nSrcTab, nLastCol, nLastRow, nSrcTab), false); 169 pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aSrcMark); 170 ScGlobal::SetClipDocName( xDocShRef->GetTitle( SFX_TITLE_FULLNAME ) ); 171 172 SetCursor( nPosX, nPosY ); 173 Unmark(); 174 PasteFromClip( IDF_ALL, pClipDoc, 175 PASTE_NOFUNC, sal_False, sal_False, sal_False, INS_NONE, IDF_NONE, 176 bAllowDialogs ); 177 delete pClipDoc; 178 bRet = sal_True; 179 } 180 181 xDocShRef->DoClose(); 182 xDocShRef.Clear(); 183 } 184 else 185 { 186 ::rtl::OUString aName; 187 uno::Reference < embed::XEmbeddedObject > xObj = GetViewData()->GetViewShell()->GetObjectShell()-> 188 GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName ); 189 if ( xObj.is() ) 190 { 191 // try to get the replacement image from the clipboard 192 Graphic aGraphic; 193 sal_uLong nGrFormat = 0; 194 // (wg. Selection Manager bei Trustet Solaris) 195 #ifndef SOLARIS 196 /* 197 if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) ) 198 nGrFormat = SOT_FORMATSTR_ID_SVXB; 199 else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) ) 200 nGrFormat = SOT_FORMAT_GDIMETAFILE; 201 else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) ) 202 nGrFormat = SOT_FORMAT_BITMAP; 203 */ 204 #endif 205 206 // insert replacement image ( if there is one ) into the object helper 207 if ( nGrFormat ) 208 { 209 datatransfer::DataFlavor aDataFlavor; 210 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor ); 211 PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect ); 212 } 213 else 214 PasteObject( aPos, xObj, &aObjDesc.maSize ); 215 216 bRet = sal_True; 217 } 218 else 219 { 220 DBG_ERROR("Error in CreateAndLoad"); 221 } 222 } 223 } 224 else 225 { 226 // uno::Reference < io::XInputStream > xStm; 227 // TransferableObjectDescriptor aObjDesc; 228 229 if ( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aObjDesc ) ) 230 { 231 ::rtl::OUString aName; 232 uno::Reference < embed::XEmbeddedObject > xObj; 233 234 if ( aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStm ) 235 || aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStm ) ) 236 { 237 xObj = GetViewData()->GetDocShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName ); 238 } 239 else 240 { 241 try 242 { 243 uno::Reference< embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage(); 244 uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator( 245 ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString( 246 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator") ) ), 247 uno::UNO_QUERY_THROW ); 248 249 embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard( 250 xTmpStor, 251 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DummyName" ) ), 252 uno::Sequence< beans::PropertyValue >() ); 253 254 // TODO/LATER: in future InsertedObjectInfo will be used to get container related information 255 // for example whether the object should be an iconified one 256 xObj = aInfo.Object; 257 if ( xObj.is() ) 258 GetViewData()->GetDocShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName ); 259 } 260 catch( uno::Exception& ) 261 {} 262 } 263 264 if ( xObj.is() ) 265 { 266 // try to get the replacement image from the clipboard 267 Graphic aGraphic; 268 sal_uLong nGrFormat = 0; 269 270 // (wg. Selection Manager bei Trustet Solaris) 271 #ifndef SOLARIS 272 if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) ) 273 nGrFormat = SOT_FORMATSTR_ID_SVXB; 274 else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) ) 275 nGrFormat = SOT_FORMAT_GDIMETAFILE; 276 else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) ) 277 nGrFormat = SOT_FORMAT_BITMAP; 278 #endif 279 280 // insert replacement image ( if there is one ) into the object helper 281 if ( nGrFormat ) 282 { 283 datatransfer::DataFlavor aDataFlavor; 284 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor ); 285 PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect ); 286 } 287 else 288 PasteObject( aPos, xObj, &aObjDesc.maSize ); 289 290 // let object stay in loaded state after insertion 291 SdrOle2Obj::Unload( xObj, embed::Aspects::MSOLE_CONTENT ); 292 bRet = sal_True; 293 } 294 else 295 { 296 DBG_ERROR("Error creating external OLE object"); 297 } 298 } 299 //TODO/LATER: if format is not available, create picture 300 } 301 } 302 else if ( nFormatId == SOT_FORMATSTR_ID_LINK ) // LINK is also in ScImportExport 303 { 304 bRet = PasteDDE( rxTransferable ); 305 } 306 else if ( ScImportExport::IsFormatSupported( nFormatId ) || nFormatId == SOT_FORMAT_RTF ) 307 { 308 if ( nFormatId == SOT_FORMAT_RTF && aDataHelper.HasFormat( SOT_FORMATSTR_ID_EDITENGINE ) ) 309 { 310 // use EditView's PasteSpecial / Drop 311 PasteRTF( nPosX, nPosY, rxTransferable ); 312 bRet = sal_True; 313 } 314 else 315 { 316 ScAddress aCellPos( nPosX, nPosY, GetViewData()->GetTabNo() ); 317 ScImportExport aObj( GetViewData()->GetDocument(), aCellPos ); 318 319 ::rtl::OUString aStr; 320 SotStorageStreamRef xStream; 321 if ( aDataHelper.GetSotStorageStream( nFormatId, xStream ) && xStream.Is() ) 322 // mba: clipboard always must contain absolute URLs (could be from alien source) 323 bRet = aObj.ImportStream( *xStream, String(), nFormatId ); 324 else if (nFormatId == FORMAT_STRING && aDataHelper.GetString( nFormatId, aStr )) 325 { 326 // Do CSV dialog if more than one line. 327 sal_Int32 nDelim = aStr.indexOf('\n'); 328 #if 0 329 ::rtl::OString tmpStr = OUStringToOString( aStr, 330 RTL_TEXTENCODING_UTF8 ); 331 fprintf( stderr, "String is '%s' (%d) [%d]\n", tmpStr.getStr(), 332 tmpStr.getLength(), nDelim); 333 #endif 334 if (nDelim >= 0 && nDelim != aStr.getLength () - 1) 335 { 336 ScImportStringStream aStrm( aStr); 337 ScAbstractDialogFactory* pFact = 338 ScAbstractDialogFactory::Create(); 339 AbstractScImportAsciiDlg *pDlg = 340 pFact->CreateScImportAsciiDlg( NULL, String(), &aStrm, 341 RID_SCDLG_ASCII); 342 343 if (pDlg->Execute() == RET_OK) 344 { 345 ScAsciiOptions aOptions; 346 pDlg->GetOptions( aOptions ); 347 aObj.SetExtOptions( aOptions ); 348 349 bRet = aObj.ImportString( aStr, nFormatId ); 350 351 // TODO: what if (aObj.IsOverflow()) 352 // Content was partially pasted, which can be undone by 353 // the user though. 354 if (aObj.IsOverflow()) 355 bRet = sal_False; 356 } 357 else 358 bRet = sal_True; 359 // Yes, no failure, don't raise a "couldn't paste" 360 // dialog if user cancelled. 361 delete pDlg; 362 } 363 else 364 bRet = aObj.ImportString( aStr, nFormatId ); 365 } 366 else if (nFormatId != FORMAT_STRING && aDataHelper.GetString( nFormatId, aStr )) 367 bRet = aObj.ImportString( aStr, nFormatId ); 368 369 InvalidateAttribs(); 370 GetViewData()->UpdateInputHandler(); 371 } 372 } 373 else if (nFormatId == SOT_FORMATSTR_ID_SBA_DATAEXCHANGE) 374 { 375 // import of database data into table 376 377 const DataFlavorExVector& rVector = aDataHelper.GetDataFlavorExVector(); 378 if ( svx::ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) ) 379 { 380 // transport the whole ODataAccessDescriptor as slot parameter 381 svx::ODataAccessDescriptor aDesc = svx::ODataAccessObjectTransferable::extractObjectDescriptor(aDataHelper); 382 uno::Any aDescAny; 383 uno::Sequence<beans::PropertyValue> aProperties = aDesc.createPropertyValueSequence(); 384 aDescAny <<= aProperties; 385 SfxUsrAnyItem aDataDesc(SID_SBA_IMPORT, aDescAny); 386 387 ScDocShell* pDocSh = GetViewData()->GetDocShell(); 388 SCTAB nTab = GetViewData()->GetTabNo(); 389 390 ClickCursor(nPosX, nPosY, sal_False); // set cursor position 391 392 // Creation of database area "Import1" isn't here, but in the DocShell 393 // slot execute, so it can be added to the undo action 394 395 ScDBData* pDBData = pDocSh->GetDBData( ScRange(nPosX,nPosY,nTab), SC_DB_OLD, SC_DBSEL_KEEP ); 396 String sTarget; 397 if (pDBData) 398 sTarget = pDBData->GetName(); 399 else 400 { 401 ScAddress aCellPos( nPosX,nPosY,nTab ); 402 aCellPos.Format( sTarget, SCA_ABS_3D, pDoc, pDoc->GetAddressConvention() ); 403 } 404 SfxStringItem aTarget(FN_PARAM_1, sTarget); 405 406 sal_Bool bAreaIsNew = !pDBData; 407 SfxBoolItem aAreaNew(FN_PARAM_2, bAreaIsNew); 408 409 // asynchronous, to avoid doing the whole import in drop handler 410 SfxDispatcher& rDisp = GetViewData()->GetDispatcher(); 411 rDisp.Execute(SID_SBA_IMPORT, SFX_CALLMODE_ASYNCHRON, 412 &aDataDesc, &aTarget, &aAreaNew, (void*)0 ); 413 414 bRet = sal_True; 415 } 416 } 417 else if (nFormatId == SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE) 418 { 419 // insert database field control 420 421 if ( ::svx::OColumnTransferable::canExtractColumnDescriptor( aDataHelper.GetDataFlavorExVector(), CTF_COLUMN_DESCRIPTOR | CTF_CONTROL_EXCHANGE ) ) 422 { 423 MakeDrawLayer(); 424 ScDrawView* pScDrawView = GetScDrawView(); 425 SdrObject* pObj = pScDrawView->CreateFieldControl( ::svx::OColumnTransferable::extractColumnDescriptor( aDataHelper ) ); 426 if (pObj) 427 { 428 Point aInsPos = aPos; 429 Rectangle aRect(pObj->GetLogicRect()); 430 aInsPos.X() -= aRect.GetSize().Width() / 2; 431 aInsPos.Y() -= aRect.GetSize().Height() / 2; 432 if ( aInsPos.X() < 0 ) aInsPos.X() = 0; 433 if ( aInsPos.Y() < 0 ) aInsPos.Y() = 0; 434 aRect.SetPos(aInsPos); 435 pObj->SetLogicRect(aRect); 436 437 if ( pObj->ISA(SdrUnoObj) ) 438 pObj->NbcSetLayer(SC_LAYER_CONTROLS); 439 else 440 pObj->NbcSetLayer(SC_LAYER_FRONT); 441 if (pObj->ISA(SdrObjGroup)) 442 { 443 SdrObjListIter aIter( *pObj, IM_DEEPWITHGROUPS ); 444 SdrObject* pSubObj = aIter.Next(); 445 while (pSubObj) 446 { 447 if ( pSubObj->ISA(SdrUnoObj) ) 448 pSubObj->NbcSetLayer(SC_LAYER_CONTROLS); 449 else 450 pSubObj->NbcSetLayer(SC_LAYER_FRONT); 451 pSubObj = aIter.Next(); 452 } 453 } 454 455 pScDrawView->InsertObjectSafe(pObj, *pScDrawView->GetSdrPageView()); 456 457 GetViewData()->GetViewShell()->SetDrawShell( sal_True ); 458 bRet = sal_True; 459 } 460 } 461 } 462 else if (nFormatId == SOT_FORMAT_BITMAP) 463 { 464 Bitmap aBmp; 465 if( aDataHelper.GetBitmap( FORMAT_BITMAP, aBmp ) ) 466 bRet = PasteBitmap( aPos, aBmp ); 467 } 468 else if (nFormatId == SOT_FORMAT_GDIMETAFILE) 469 { 470 GDIMetaFile aMtf; 471 if( aDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) ) 472 bRet = PasteMetaFile( aPos, aMtf ); 473 } 474 else if (nFormatId == SOT_FORMATSTR_ID_SVXB) 475 { 476 SotStorageStreamRef xStm; 477 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ) ) 478 { 479 Graphic aGraphic; 480 *xStm >> aGraphic; 481 bRet = PasteGraphic( aPos, aGraphic, EMPTY_STRING, EMPTY_STRING ); 482 } 483 } 484 else if ( nFormatId == SOT_FORMATSTR_ID_DRAWING ) 485 { 486 SotStorageStreamRef xStm; 487 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ) ) 488 { 489 MakeDrawLayer(); // before loading model, so 3D factory has been created 490 491 SvtPathOptions aPathOpt; 492 String aPath = aPathOpt.GetPalettePath(); 493 494 ScDocShellRef aDragShellRef( new ScDocShell ); 495 aDragShellRef->DoInitNew(NULL); 496 FmFormModel* pModel = new FmFormModel( aPath, NULL, aDragShellRef ); 497 498 pModel->GetItemPool().FreezeIdRanges(); 499 xStm->Seek(0); 500 501 com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) ); 502 SvxDrawingLayerImport( pModel, xInputStream ); 503 504 // set everything to right layer: 505 sal_uLong nObjCount = 0; 506 sal_uInt16 nPages = pModel->GetPageCount(); 507 for (sal_uInt16 i=0; i<nPages; i++) 508 { 509 SdrPage* pPage = pModel->GetPage(i); 510 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS ); 511 SdrObject* pObject = aIter.Next(); 512 while (pObject) 513 { 514 if ( pObject->ISA(SdrUnoObj) ) 515 pObject->NbcSetLayer(SC_LAYER_CONTROLS); 516 else 517 pObject->NbcSetLayer(SC_LAYER_FRONT); 518 pObject = aIter.Next(); 519 } 520 521 nObjCount += pPage->GetObjCount(); // #105888# count group object only once 522 } 523 524 PasteDraw( aPos, pModel, (nObjCount > 1) ); // grouped if more than 1 object 525 delete pModel; 526 aDragShellRef->DoClose(); 527 bRet = sal_True; 528 } 529 } 530 else if ( (nFormatId == SOT_FORMATSTR_ID_BIFF_5) || (nFormatId == SOT_FORMATSTR_ID_BIFF_8) ) 531 { 532 // do excel import into a clipboard document 533 //TODO/MBA: testing 534 uno::Reference < io::XInputStream > xStm; 535 if( aDataHelper.GetInputStream( nFormatId, xStm ) ) 536 { 537 #if 0 538 SotStorage aDest( "d:\\test.xls" ); // to see the file 539 pStor->CopyTo( &aDest ); 540 #endif 541 ScDocument* pInsDoc = new ScDocument( SCDOCMODE_CLIP ); 542 SCTAB nSrcTab = 0; // Biff5 in clipboard: always sheet 0 543 pInsDoc->ResetClip( pDoc, nSrcTab ); 544 545 SfxMedium aMed; 546 aMed.GetItemSet()->Put( SfxUsrAnyItem( SID_INPUTSTREAM, uno::makeAny( xStm ) ) ); 547 FltError eErr = ScFormatFilter::Get().ScImportExcel( aMed, pInsDoc, EIF_AUTO ); 548 if ( eErr == eERR_OK ) 549 { 550 ScRange aSource; 551 const ScExtDocOptions* pExtOpt = pInsDoc->GetExtDocOptions(); 552 const ScExtTabSettings* pTabSett = pExtOpt ? pExtOpt->GetTabSettings( nSrcTab ) : 0; 553 if( pTabSett && pTabSett->maUsedArea.IsValid() ) 554 { 555 aSource = pTabSett->maUsedArea; 556 // ensure correct sheet indexes 557 aSource.aStart.SetTab( nSrcTab ); 558 aSource.aEnd.SetTab( nSrcTab ); 559 // #92240# don't use selection area: if cursor is moved in Excel after Copy, selection 560 // represents the new cursor position and not the copied area 561 } 562 else 563 { 564 DBG_ERROR("no dimension"); //! possible? 565 SCCOL nFirstCol, nLastCol; 566 SCROW nFirstRow, nLastRow; 567 if ( pInsDoc->GetDataStart( nSrcTab, nFirstCol, nFirstRow ) ) 568 pInsDoc->GetCellArea( nSrcTab, nLastCol, nLastRow ); 569 else 570 { 571 nFirstCol = nLastCol = 0; 572 nFirstRow = nLastRow = 0; 573 } 574 aSource = ScRange( nFirstCol, nFirstRow, nSrcTab, 575 nLastCol, nLastRow, nSrcTab ); 576 } 577 578 if ( pLogicPos ) 579 { 580 // position specified (Drag&Drop) - change selection 581 MoveCursorAbs( nPosX, nPosY, SC_FOLLOW_NONE, sal_False, sal_False ); 582 Unmark(); 583 } 584 585 pInsDoc->SetClipArea( aSource ); 586 PasteFromClip( IDF_ALL, pInsDoc, 587 PASTE_NOFUNC, sal_False, sal_False, sal_False, INS_NONE, IDF_NONE, 588 bAllowDialogs ); 589 delete pInsDoc; 590 591 bRet = sal_True; 592 } 593 } 594 } 595 else if ( nFormatId == SOT_FORMAT_FILE ) 596 { 597 String aFile; 598 if ( aDataHelper.GetString( nFormatId, aFile ) ) 599 bRet = PasteFile( aPos, aFile, bLink ); 600 } 601 else if ( nFormatId == SOT_FORMAT_FILE_LIST ) 602 { 603 FileList aFileList; 604 if ( aDataHelper.GetFileList( nFormatId, aFileList ) ) 605 { 606 sal_uLong nCount = aFileList.Count(); 607 for( sal_uLong i = 0; i < nCount ; i++ ) 608 { 609 String aFile = aFileList.GetFile( i ); 610 611 PasteFile( aPos, aFile, bLink ); 612 #if 0 613 SfxStringItem aNameItem( FID_INSERT_FILE, aFile ); 614 SfxPointItem aPosItem( FN_PARAM_1, aPos ); 615 SfxDispatcher* pDisp = 616 GetViewData()->GetViewShell()->GetViewFrame()->GetDispatcher(); 617 if (pDisp) 618 pDisp->Execute( FID_INSERT_FILE, SFX_CALLMODE_ASYNCHRON, 619 &aNameItem, &aPosItem, (void*)0 ); 620 #endif 621 622 aPos.X() += 400; 623 aPos.Y() += 400; 624 } 625 bRet = sal_True; 626 } 627 } 628 else if ( nFormatId == SOT_FORMATSTR_ID_SOLK || 629 nFormatId == SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR || 630 nFormatId == SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK || 631 nFormatId == SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) 632 { 633 bRet = PasteBookmark( nFormatId, rxTransferable, nPosX, nPosY ); 634 } 635 636 pDoc->SetPastingDrawFromOtherDoc( sal_False ); 637 638 return bRet; 639 } 640 641 ByteString lcl_GetSubString( sal_Char* pData, long nStart, long nDataSize ) 642 { 643 if ( nDataSize <= nStart /* || pData[nDataSize] != 0 */ ) 644 { 645 DBG_ERROR("DDE Data: invalid data"); 646 return ByteString(); 647 } 648 return ByteString( pData + nStart ); 649 } 650 651 sal_Bool ScViewFunc::PasteDDE( const uno::Reference<datatransfer::XTransferable>& rxTransferable ) 652 { 653 TransferableDataHelper aDataHelper( rxTransferable ); 654 655 // get link data from transferable before string data, 656 // so the source knows it will be used for a link 657 658 uno::Sequence<sal_Int8> aSequence; 659 if ( !aDataHelper.GetSequence( SOT_FORMATSTR_ID_LINK, aSequence ) ) 660 { 661 DBG_ERROR("DDE Data not found."); 662 return sal_False; 663 } 664 665 // check size (only if string is available in transferable) 666 667 sal_uInt16 nCols = 1; 668 sal_uInt16 nRows = 1; 669 if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) ) 670 { 671 String aDataStr; 672 if ( aDataHelper.GetString( SOT_FORMAT_STRING, aDataStr ) ) 673 { 674 // get size from string the same way as in ScDdeLink::DataChanged 675 676 aDataStr.ConvertLineEnd(LINEEND_LF); 677 xub_StrLen nLen = aDataStr.Len(); 678 if (nLen && aDataStr.GetChar(nLen-1) == '\n') 679 aDataStr.Erase(nLen-1); 680 681 if (aDataStr.Len()) 682 { 683 nRows = aDataStr.GetTokenCount( '\n' ); 684 String aLine = aDataStr.GetToken( 0, '\n' ); 685 if (aLine.Len()) 686 nCols = aLine.GetTokenCount( '\t' ); 687 } 688 } 689 } 690 691 // create formula 692 693 long nSeqLen = aSequence.getLength(); 694 sal_Char* pData = (sal_Char*)aSequence.getConstArray(); 695 696 rtl_TextEncoding eSysEnc = gsl_getSystemTextEncoding(); 697 698 ByteString aByteApp = lcl_GetSubString( pData, 0, nSeqLen ); 699 ByteString aByteTopic = lcl_GetSubString( pData, aByteApp.Len() + 1, nSeqLen ); 700 ByteString aByteItem = lcl_GetSubString( pData, aByteApp.Len() + aByteTopic.Len() + 2, nSeqLen ); 701 702 String aApp( aByteApp, eSysEnc ); 703 String aTopic( aByteTopic, eSysEnc ); 704 String aItem( aByteItem, eSysEnc ); 705 706 // TODO: we could define ocQuote for " 707 const String aQuote( '"' ); 708 const String& sSep = ScCompiler::GetNativeSymbol( ocSep); 709 String aFormula( '=' ); 710 aFormula += ScCompiler::GetNativeSymbol( ocDde); 711 aFormula += ScCompiler::GetNativeSymbol( ocOpen); 712 aFormula += aQuote; 713 aFormula += aApp; 714 aFormula += aQuote; 715 aFormula += sSep; 716 aFormula += aQuote; 717 aFormula += aTopic; 718 aFormula += aQuote; 719 aFormula += sSep; 720 aFormula += aQuote; 721 aFormula += aItem; 722 aFormula += aQuote; 723 aFormula += ScCompiler::GetNativeSymbol( ocClose); 724 725 // mark range 726 727 SCTAB nTab = GetViewData()->GetTabNo(); 728 SCCOL nCurX = GetViewData()->GetCurX(); 729 SCROW nCurY = GetViewData()->GetCurY(); 730 HideAllCursors(); 731 DoneBlockMode(); 732 InitBlockMode( nCurX, nCurY, nTab ); 733 MarkCursor( nCurX+static_cast<SCCOL>(nCols)-1, nCurY+static_cast<SCROW>(nRows)-1, nTab ); 734 ShowAllCursors(); 735 736 // enter formula 737 738 EnterMatrix( aFormula ); 739 CursorPosChanged(); 740 741 return sal_True; 742 } 743 744 745