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