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