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