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