LibreOffice Module sc (master) 1
viewfun5.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
21#include <com/sun/star/embed/Aspects.hpp>
22#include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
23
24#include <svx/unomodel.hxx>
26
27#include <svx/fmmodel.hxx>
28#include <svx/svditer.hxx>
29#include <svx/svdobj.hxx>
30#include <svx/svdogrp.hxx>
31#include <svx/svdouno.hxx>
32#include <svx/svdoole2.hxx>
33#include <svx/svdpage.hxx>
34#include <sfx2/dispatch.hxx>
35#include <sfx2/docfile.hxx>
37#include <sot/formats.hxx>
38#include <sot/filelist.hxx>
39#include <sot/storage.hxx>
40#include <svl/stritem.hxx>
41#include <vcl/transfer.hxx>
42#include <vcl/graph.hxx>
44#include <osl/thread.h>
46#include <o3tl/string_view.hxx>
47
49#include <comphelper/lok.hxx>
52#include <comphelper/string.hxx>
53
54#include <viewfunc.hxx>
55#include <docsh.hxx>
56#include <drawview.hxx>
57#include <impex.hxx>
58#include <dbdata.hxx>
59#include <sc.hrc>
60#include <filter.hxx>
61#include <globstr.hrc>
62#include <global.hxx>
63#include <scextopt.hxx>
64#include <tabvwsh.hxx>
65#include <compiler.hxx>
66#include <scmod.hxx>
67
68#include <asciiopt.hxx>
69#include <scabstdlg.hxx>
70#include <clipparam.hxx>
71#include <markdata.hxx>
72#include <sfx2/frame.hxx>
73#include <svx/dbaexchange.hxx>
74#include <memory>
75
76using namespace com::sun::star;
77
79 const uno::Reference<datatransfer::XTransferable>& rxTransferable,
80 SCCOL nPosX, SCROW nPosY, const Point* pLogicPos, bool bLink, bool bAllowDialogs )
81{
83 rDoc.SetPastingDrawFromOtherDoc( true );
84
85 Point aPos; // inserting position (1/100 mm)
86 if (pLogicPos)
87 aPos = *pLogicPos;
88 else
89 {
90 // inserting position isn't needed for text formats
91 bool bIsTextFormat = ( ScImportExport::IsFormatSupported( nFormatId ) ||
92 nFormatId == SotClipboardFormatId::RTF );
93 if ( !bIsTextFormat )
94 {
95 // Window MapMode isn't drawing MapMode if DrawingLayer hasn't been created yet
96
97 SCTAB nTab = GetViewData().GetTabNo();
98 tools::Long nXT = 0;
99 for (SCCOL i=0; i<nPosX; i++)
100 nXT += rDoc.GetColWidth(i,nTab);
101 if (rDoc.IsNegativePage(nTab))
102 nXT = -nXT;
103 tools::Long nYT = rDoc.GetRowHeight( 0, nPosY-1, nTab);
106 }
107 }
108
109 TransferableDataHelper aDataHelper( rxTransferable );
110 bool bRet = false;
111
112 // handle individual formats
113
114 if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE ||
115 nFormatId == SotClipboardFormatId::LINK_SOURCE ||
116 nFormatId == SotClipboardFormatId::EMBED_SOURCE_OLE ||
117 nFormatId == SotClipboardFormatId::LINK_SOURCE_OLE ||
118 nFormatId == SotClipboardFormatId::EMBEDDED_OBJ_OLE )
119 {
120 uno::Reference < io::XInputStream > xStm;
122
123 if (aDataHelper.GetTransferableObjectDescriptor(SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDesc))
124 xStm = aDataHelper.GetInputStream(nFormatId, OUString());
125
126 if (xStm.is())
127 {
128 if ( aObjDesc.maClassName == SvGlobalName( SO3_SC_CLASSID_60 ) )
129 {
130 uno::Reference < embed::XStorage > xStore = ::comphelper::OStorageHelper::GetStorageFromInputStream( xStm );
131
132 // mba: BaseURL doesn't make sense for clipboard
133 // #i43716# Medium must be allocated with "new".
134 // DoLoad stores the pointer and deletes it with the SfxObjectShell.
135 SfxMedium* pMedium = new SfxMedium( xStore, OUString() );
136
137 // TODO/LATER: is it a problem that we don't support binary formats here?
138 ScDocShellRef xDocShRef = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT);
139 if (xDocShRef->DoLoad(pMedium))
140 {
141 ScDocument& rSrcDoc = xDocShRef->GetDocument();
142 SCTAB nSrcTab = rSrcDoc.GetVisibleTab();
143 if (!rSrcDoc.HasTable(nSrcTab))
144 nSrcTab = 0;
145
146 ScMarkData aSrcMark(rSrcDoc.GetSheetLimits());
147 aSrcMark.SelectOneTable( nSrcTab ); // for CopyToClip
149
150 SCCOL nFirstCol, nLastCol;
151 SCROW nFirstRow, nLastRow;
152 if ( rSrcDoc.GetDataStart( nSrcTab, nFirstCol, nFirstRow ) )
153 {
154 rSrcDoc.GetCellArea( nSrcTab, nLastCol, nLastRow );
155 if (nLastCol < nFirstCol)
156 nLastCol = nFirstCol;
157 if (nLastRow < nFirstRow)
158 nLastRow = nFirstRow;
159 }
160 else
161 {
162 nFirstCol = nLastCol = 0;
163 nFirstRow = nLastRow = 0;
164 }
165
166 bool bIncludeObjects = false; // include drawing layer objects in CopyToClip ?
167
168 if (nFormatId == SotClipboardFormatId::EMBED_SOURCE)
169 {
170 const ScDrawLayer* pDraw = rSrcDoc.GetDrawLayer();
171 SCCOL nPrintEndCol = nFirstCol;
172 SCROW nPrintEndRow = nFirstRow;
173 bool bHasObjects = pDraw && pDraw->HasObjects();
174 // Extend the range to include the drawing layer objects.
175 if (bHasObjects && rSrcDoc.GetPrintArea(nSrcTab, nPrintEndCol, nPrintEndRow, true))
176 {
177 nLastCol = std::max<SCCOL>(nLastCol, nPrintEndCol);
178 nLastRow = std::max<SCROW>(nLastRow, nPrintEndRow);
179 }
180
181 bIncludeObjects = bHasObjects;
182 }
183
184 ScClipParam aClipParam(ScRange(nFirstCol, nFirstRow, nSrcTab, nLastCol, nLastRow, nSrcTab), false);
185 rSrcDoc.CopyToClip(aClipParam, pClipDoc.get(), &aSrcMark, false, bIncludeObjects);
186 ScGlobal::SetClipDocName( xDocShRef->GetTitle( SFX_TITLE_FULLNAME ) );
187
188 SetCursor( nPosX, nPosY );
189 Unmark();
190 PasteFromClip( InsertDeleteFlags::ALL, pClipDoc.get(),
192 bAllowDialogs );
193 bRet = true;
194 }
195
196 xDocShRef->DoClose();
197 xDocShRef.clear();
198 }
199 else
200 {
201 OUString aName;
202 uno::Reference < embed::XEmbeddedObject > xObj = GetViewData().GetViewShell()->GetObjectShell()->
203 GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
204 if ( xObj.is() )
205 {
206 // try to get the replacement image from the clipboard
207 Graphic aGraphic;
208 SotClipboardFormatId nGrFormat = SotClipboardFormatId::NONE;
209
210 // limit the size of the preview metafile to 100000 actions
211 GDIMetaFile aMetafile;
212 if (aDataHelper.GetGDIMetaFile(SotClipboardFormatId::GDIMETAFILE, aMetafile, 100000))
213 {
214 nGrFormat = SotClipboardFormatId::GDIMETAFILE;
215 aGraphic = aMetafile;
216 }
217
218 // insert replacement image ( if there is one ) into the object helper
219 if ( nGrFormat != SotClipboardFormatId::NONE )
220 {
221 datatransfer::DataFlavor aDataFlavor;
222 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
223 PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
224 }
225 else
226 PasteObject( aPos, xObj, &aObjDesc.maSize );
227
228 bRet = true;
229 }
230 else
231 {
232 OSL_FAIL("Error in CreateAndLoad");
233 }
234 }
235 }
236 else
237 {
238 if ( aDataHelper.GetTransferableObjectDescriptor( SotClipboardFormatId::OBJECTDESCRIPTOR_OLE, aObjDesc ) )
239 {
240 OUString aName;
241 uno::Reference < embed::XEmbeddedObject > xObj;
242 xStm = aDataHelper.GetInputStream(SotClipboardFormatId::EMBED_SOURCE_OLE, OUString());
243 if (!xStm.is())
244 aDataHelper.GetInputStream(SotClipboardFormatId::EMBEDDED_OBJ_OLE, OUString());
245
246 if (xStm.is())
247 {
249 }
250 else
251 {
252 try
253 {
254 uno::Reference< embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
255 uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator =
256 embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() );
257
258 embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
259 xTmpStor,
260 "DummyName",
261 uno::Sequence< beans::PropertyValue >() );
262
263 // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
264 // for example whether the object should be an iconified one
265 xObj = aInfo.Object;
266 if ( xObj.is() )
268 }
269 catch( uno::Exception& )
270 {}
271 }
272
273 if ( xObj.is() )
274 {
275 // try to get the replacement image from the clipboard
276 Graphic aGraphic;
277 SotClipboardFormatId nGrFormat = SotClipboardFormatId::NONE;
278
279// (for Selection Manager in Trusted Solaris)
280#ifndef __sun
281 if( aDataHelper.GetGraphic( SotClipboardFormatId::SVXB, aGraphic ) )
282 nGrFormat = SotClipboardFormatId::SVXB;
283 else if( aDataHelper.GetGraphic( SotClipboardFormatId::GDIMETAFILE, aGraphic ) )
284 nGrFormat = SotClipboardFormatId::GDIMETAFILE;
285 else if( aDataHelper.GetGraphic( SotClipboardFormatId::BITMAP, aGraphic ) )
286 nGrFormat = SotClipboardFormatId::BITMAP;
287#endif
288
289 // insert replacement image ( if there is one ) into the object helper
290 if ( nGrFormat != SotClipboardFormatId::NONE )
291 {
292 datatransfer::DataFlavor aDataFlavor;
293 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
294 PasteObject( aPos, xObj, &aObjDesc.maSize, &aGraphic, aDataFlavor.MimeType, aObjDesc.mnViewAspect );
295 }
296 else
297 PasteObject( aPos, xObj, &aObjDesc.maSize );
298
299 // let object stay in loaded state after insertion
300 SdrOle2Obj::Unload( xObj, embed::Aspects::MSOLE_CONTENT );
301 bRet = true;
302 }
303 else
304 {
305 OSL_FAIL("Error creating external OLE object");
306 }
307 }
308 //TODO/LATER: if format is not available, create picture
309 }
310 }
311 else if ( nFormatId == SotClipboardFormatId::LINK ) // LINK is also in ScImportExport
312 {
313 bRet = PasteLink( rxTransferable );
314 }
315 else if ( ScImportExport::IsFormatSupported( nFormatId ) || nFormatId == SotClipboardFormatId::RTF ||
316 nFormatId == SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT )
317 {
318 if ( nFormatId == SotClipboardFormatId::RTF && ( aDataHelper.HasFormat( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT ) ) )
319 {
320 // use EditView's PasteSpecial / Drop
321 PasteRTF( nPosX, nPosY, rxTransferable );
322 bRet = true;
323 }
324 else
325 {
326 ScAddress aCellPos( nPosX, nPosY, GetViewData().GetTabNo() );
327 auto pObj = std::make_shared<ScImportExport>(GetViewData().GetDocument(), aCellPos);
328 pObj->SetOverwriting( true );
329
330
331 auto pStrBuffer = std::make_shared<OUString>();
333 if ( aDataHelper.GetSotStorageStream( nFormatId, xStream ) && xStream.is() )
334 {
335 // Static variables for per-session storage. This could be
336 // changed to longer-term storage in future.
337 static bool bHaveSavedPreferences = false;
338 static LanguageType eSavedLanguage;
339 static bool bSavedDateConversion;
340 static bool bSavedScientificConversion;
341
342 if (nFormatId == SotClipboardFormatId::HTML &&
344 {
345 if (bHaveSavedPreferences)
346 {
347 ScAsciiOptions aOptions;
348 aOptions.SetLanguage(eSavedLanguage);
349 aOptions.SetDetectSpecialNumber(bSavedDateConversion);
350 aOptions.SetDetectScientificNumber(bSavedScientificConversion);
351 pObj->SetExtOptions(aOptions);
352 }
353 else
354 {
355 // Launch the text import options dialog. For now, we do
356 // this for html pasting only, but in the future it may
357 // make sense to do it for other data types too.
359 vcl::Window* pParent = GetActiveWin();
361 pFact->CreateScTextImportOptionsDlg(pParent ? pParent->GetFrameWeld() : nullptr));
362
363 if (pDlg->Execute() == RET_OK)
364 {
365 ScAsciiOptions aOptions;
366 aOptions.SetLanguage(pDlg->GetLanguageType());
367 aOptions.SetDetectSpecialNumber(pDlg->IsDateConversionSet());
368 aOptions.SetDetectScientificNumber(pDlg->IsScientificConversionSet());
369 if (!pDlg->IsKeepAskingSet())
370 {
371 bHaveSavedPreferences = true;
372 eSavedLanguage = pDlg->GetLanguageType();
373 bSavedDateConversion = pDlg->IsDateConversionSet();
374 bSavedScientificConversion = pDlg->IsScientificConversionSet();
375 }
376 pObj->SetExtOptions(aOptions);
377 }
378 else
379 {
380 // prevent error dialog for user cancel action
381 bRet = true;
382 }
383 }
384 }
385 if(!bRet)
386 bRet = pObj->ImportStream( *xStream, OUString(), nFormatId );
387 // mba: clipboard always must contain absolute URLs (could be from alien source)
388 }
389 else if ((nFormatId == SotClipboardFormatId::STRING || nFormatId == SotClipboardFormatId::STRING_TSVC)
390 && aDataHelper.GetString( nFormatId, *pStrBuffer ))
391 {
392 // Do CSV dialog if more than one line. But not if invoked from Automation.
393 const SfxViewShell* pViewShell = SfxViewShell::Current();
394 sal_Int32 nDelim = pStrBuffer->indexOf('\n');
396 && nDelim >= 0 && nDelim != pStrBuffer->getLength () - 1)
397 {
398 vcl::Window* pParent = GetActiveWin();
399
400 auto pStrm = std::make_shared<ScImportStringStream>(*pStrBuffer);
401
404 pFact->CreateScImportAsciiDlg(pParent ? pParent->GetFrameWeld() : nullptr, OUString(), pStrm.get(), SC_PASTETEXT));
405
406 bAllowDialogs = bAllowDialogs && !SC_MOD()->IsInExecuteDrop();
407
408 pDlg->StartExecuteAsync([this, pDlg, &rDoc, pStrm, nFormatId, pStrBuffer, pObj, bAllowDialogs](sal_Int32 nResult){
409 bool bShowErrorDialog = bAllowDialogs;
410 if (RET_OK == nResult)
411 {
412 ScAsciiOptions aOptions;
413 pDlg->GetOptions( aOptions );
414 pDlg->SaveParameters();
415 pObj->SetExtOptions( aOptions );
416 pObj->ImportString( *pStrBuffer, nFormatId );
417
418 // TODO: what if (aObj.IsOverflow())
419 // Content was partially pasted, which can be undone by
420 // the user though.
421 bShowErrorDialog = bShowErrorDialog && pObj->IsOverflow();
422 }
423 else
424 {
425 bShowErrorDialog = false;
426 // Yes, no failure, don't raise a "couldn't paste"
427 // dialog if user cancelled.
428 }
429
432
433 rDoc.SetPastingDrawFromOtherDoc( false );
434
435 if (bShowErrorDialog)
436 ErrorMessage(STR_PASTE_ERROR);
437 pDlg->disposeOnce();
438 });
439 return true;
440 }
441 else
442 bRet = pObj->ImportString( *pStrBuffer, nFormatId );
443 }
444 else if ((nFormatId != SotClipboardFormatId::STRING && nFormatId != SotClipboardFormatId::STRING_TSVC)
445 && aDataHelper.GetString( nFormatId, *pStrBuffer ))
446 bRet = pObj->ImportString( *pStrBuffer, nFormatId );
447
450 }
451 }
452 else if (nFormatId == SotClipboardFormatId::SBA_DATAEXCHANGE)
453 {
454 // import of database data into table
455
456 const DataFlavorExVector& rVector = aDataHelper.GetDataFlavorExVector();
458 {
459 // transport the whole ODataAccessDescriptor as slot parameter
461 uno::Any aDescAny;
462 uno::Sequence<beans::PropertyValue> aProperties = aDesc.createPropertyValueSequence();
463 aDescAny <<= aProperties;
464 SfxUnoAnyItem aDataDesc(SID_SBA_IMPORT, aDescAny);
465
466 ScDocShell* pDocSh = GetViewData().GetDocShell();
467 SCTAB nTab = GetViewData().GetTabNo();
468
469 ClickCursor(nPosX, nPosY, false); // set cursor position
470
471 // Creation of database area "Import1" isn't here, but in the DocShell
472 // slot execute, so it can be added to the undo action
473
474 ScDBData* pDBData = pDocSh->GetDBData( ScRange(nPosX,nPosY,nTab), SC_DB_OLD, ScGetDBSelection::Keep );
475 OUString sTarget;
476 if (pDBData)
477 sTarget = pDBData->GetName();
478 else
479 {
480 ScAddress aCellPos( nPosX,nPosY,nTab );
481 sTarget = aCellPos.Format(ScRefFlags::ADDR_ABS_3D, &rDoc, rDoc.GetAddressConvention());
482 }
483 SfxStringItem aTarget(FN_PARAM_1, sTarget);
484
485 bool bAreaIsNew = !pDBData;
486 SfxBoolItem aAreaNew(FN_PARAM_2, bAreaIsNew);
487
488 // asynchronous, to avoid doing the whole import in drop handler
490 rDisp.ExecuteList(SID_SBA_IMPORT, SfxCallMode::ASYNCHRON,
491 { &aDataDesc, &aTarget, &aAreaNew });
492
493 bRet = true;
494 }
495 }
496 else if (nFormatId == SotClipboardFormatId::SBA_FIELDDATAEXCHANGE)
497 {
498 // insert database field control
499
500 if ( svx::OColumnTransferable::canExtractColumnDescriptor( aDataHelper.GetDataFlavorExVector(), ColumnTransferFormatFlags::COLUMN_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE ) )
501 {
503 ScDrawView* pScDrawView = GetScDrawView();
505 if (pObj)
506 {
507 Point aInsPos = aPos;
508 tools::Rectangle aRect(pObj->GetLogicRect());
509 aInsPos.AdjustX( -(aRect.GetSize().Width() / 2) );
510 aInsPos.AdjustY( -(aRect.GetSize().Height() / 2) );
511 if ( aInsPos.X() < 0 ) aInsPos.setX( 0 );
512 if ( aInsPos.Y() < 0 ) aInsPos.setY( 0 );
513 aRect.SetPos(aInsPos);
514 pObj->SetLogicRect(aRect);
515
516 if ( dynamic_cast<const SdrUnoObj*>( pObj.get() ) != nullptr )
517 pObj->NbcSetLayer(SC_LAYER_CONTROLS);
518 else
519 pObj->NbcSetLayer(SC_LAYER_FRONT);
520 if (dynamic_cast<const SdrObjGroup*>( pObj.get() ) != nullptr)
521 {
522 SdrObjListIter aIter( *pObj, SdrIterMode::DeepWithGroups );
523 SdrObject* pSubObj = aIter.Next();
524 while (pSubObj)
525 {
526 if ( dynamic_cast<const SdrUnoObj*>( pSubObj) != nullptr )
528 else
529 pSubObj->NbcSetLayer(SC_LAYER_FRONT);
530 pSubObj = aIter.Next();
531 }
532 }
533
534 pScDrawView->InsertObjectSafe(pObj.get(), *pScDrawView->GetSdrPageView());
535
537 bRet = true;
538 }
539 }
540 }
541 else if (nFormatId == SotClipboardFormatId::BITMAP || nFormatId == SotClipboardFormatId::PNG || nFormatId == SotClipboardFormatId::JPEG)
542 {
543 BitmapEx aBmpEx;
544 if( aDataHelper.GetBitmapEx( SotClipboardFormatId::BITMAP, aBmpEx ) )
545 bRet = PasteBitmapEx( aPos, aBmpEx );
546 }
547 else if (nFormatId == SotClipboardFormatId::GDIMETAFILE)
548 {
549 GDIMetaFile aMtf;
550 if( aDataHelper.GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE, aMtf ) )
551 bRet = PasteMetaFile( aPos, aMtf );
552 }
553 else if (nFormatId == SotClipboardFormatId::SVXB)
554 {
556 if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ) )
557 {
558 Graphic aGraphic;
559 TypeSerializer aSerializer(*xStm);
560 aSerializer.readGraphic(aGraphic);
561 bRet = PasteGraphic( aPos, aGraphic, OUString() );
562 }
563 }
564 else if ( nFormatId == SotClipboardFormatId::DRAWING )
565 {
567 if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStm ) )
568 {
569 MakeDrawLayer(); // before loading model, so 3D factory has been created
570
571 ScDocShellRef aDragShellRef( new ScDocShell );
572 aDragShellRef->MakeDrawLayer();
573 aDragShellRef->DoInitNew();
574
575 ScDrawLayer* pModel = aDragShellRef->GetDocument().GetDrawLayer();
576
577 xStm->Seek(0);
578
579 css::uno::Reference< css::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
580 SvxDrawingLayerImport( pModel, xInputStream );
581
582 // set everything to right layer:
583 size_t nObjCount = 0;
584 sal_uInt16 nPages = pModel->GetPageCount();
585 for (sal_uInt16 i=0; i<nPages; i++)
586 {
587 SdrPage* pPage = pModel->GetPage(i);
588 SdrObjListIter aIter( pPage, SdrIterMode::DeepWithGroups );
589 SdrObject* pObject = aIter.Next();
590 while (pObject)
591 {
592 if ( dynamic_cast<const SdrUnoObj*>( pObject) != nullptr )
593 pObject->NbcSetLayer(SC_LAYER_CONTROLS);
594 else
595 pObject->NbcSetLayer(SC_LAYER_FRONT);
596 pObject = aIter.Next();
597 }
598
599 nObjCount += pPage->GetObjCount(); // count group object only once
600 }
601
602 PasteDraw(aPos, pModel, (nObjCount > 1), u"A", u"B"); // grouped if more than 1 object
603 aDragShellRef->DoClose();
604 bRet = true;
605 }
606 }
607 else if ( (nFormatId == SotClipboardFormatId::BIFF_5) || (nFormatId == SotClipboardFormatId::BIFF_8) )
608 {
609 // do excel import into a clipboard document
610 //TODO/MBA: testing
611 uno::Reference <io::XInputStream> xStm = aDataHelper.GetInputStream(nFormatId, OUString());
612 if (xStm.is())
613 {
614 ScDocument aInsDoc( SCDOCMODE_CLIP );
615 SCTAB nSrcTab = 0; // Biff5 in clipboard: always sheet 0
616 aInsDoc.ResetClip( &rDoc, nSrcTab );
617
618 SfxMedium aMed;
619 aMed.GetItemSet().Put( SfxUnoAnyItem( SID_INPUTSTREAM, uno::Any( xStm ) ) );
620 ErrCode eErr = ScFormatFilter::Get().ScImportExcel( aMed, &aInsDoc, EIF_AUTO );
621 if ( eErr == ERRCODE_NONE )
622 {
623 ScRange aSource;
624 const ScExtDocOptions* pExtOpt = aInsDoc.GetExtDocOptions();
625 const ScExtTabSettings* pTabSett = pExtOpt ? pExtOpt->GetTabSettings( nSrcTab ) : nullptr;
626 if( pTabSett && pTabSett->maUsedArea.IsValid() )
627 {
628 aSource = pTabSett->maUsedArea;
629 // ensure correct sheet indexes
630 aSource.aStart.SetTab( nSrcTab );
631 aSource.aEnd.SetTab( nSrcTab );
632// don't use selection area: if cursor is moved in Excel after Copy, selection
633// represents the new cursor position and not the copied area
634 }
635 else
636 {
637 OSL_FAIL("no dimension");
638 SCCOL nFirstCol, nLastCol;
639 SCROW nFirstRow, nLastRow;
640 if ( aInsDoc.GetDataStart( nSrcTab, nFirstCol, nFirstRow ) )
641 aInsDoc.GetCellArea( nSrcTab, nLastCol, nLastRow );
642 else
643 {
644 nFirstCol = nLastCol = 0;
645 nFirstRow = nLastRow = 0;
646 }
647 aSource = ScRange( nFirstCol, nFirstRow, nSrcTab,
648 nLastCol, nLastRow, nSrcTab );
649 }
650
651 if ( pLogicPos )
652 {
653 // position specified (Drag&Drop) - change selection
654 MoveCursorAbs( nPosX, nPosY, SC_FOLLOW_NONE, false, false );
655 Unmark();
656 }
657
658 aInsDoc.SetClipArea( aSource );
661 bAllowDialogs );
662 bRet = true;
663 }
664 }
665 }
666 else if ( nFormatId == SotClipboardFormatId::SIMPLE_FILE )
667 {
668 OUString aFile;
669 if ( aDataHelper.GetString( nFormatId, aFile ) )
670 bRet = PasteFile( aPos, aFile, bLink );
671 }
672 else if ( nFormatId == SotClipboardFormatId::FILE_LIST )
673 {
674 FileList aFileList;
675 if ( aDataHelper.GetFileList( nFormatId, aFileList ) )
676 {
677 sal_uLong nCount = aFileList.Count();
678 for( sal_uLong i = 0; i < nCount ; i++ )
679 {
680 OUString aFile = aFileList.GetFile( i );
681
682 PasteFile( aPos, aFile, bLink );
683
684 aPos.AdjustX(400 );
685 aPos.AdjustY(400 );
686 }
687 bRet = true;
688 }
689 }
690 else if ( nFormatId == SotClipboardFormatId::SOLK ||
691 nFormatId == SotClipboardFormatId::UNIFORMRESOURCELOCATOR ||
692 nFormatId == SotClipboardFormatId::NETSCAPE_BOOKMARK ||
693 nFormatId == SotClipboardFormatId::FILEGRPDESCRIPTOR )
694 {
695 bRet = PasteBookmark( nFormatId, rxTransferable, nPosX, nPosY );
696 }
697
698 rDoc.SetPastingDrawFromOtherDoc( false );
699
700 return bRet;
701}
702
703bool ScViewFunc::PasteLink( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
704{
705 TransferableDataHelper aDataHelper( rxTransferable );
706
707 // get link data from transferable before string data,
708 // so the source knows it will be used for a link
709
710 uno::Sequence<sal_Int8> aSequence = aDataHelper.GetSequence(SotClipboardFormatId::LINK, OUString());
711 if (!aSequence.hasElements())
712 {
713 OSL_FAIL("DDE Data not found.");
714 return false;
715 }
716
717 // check size (only if string is available in transferable)
718
719 sal_uInt16 nCols = 1;
720 sal_uInt16 nRows = 1;
721 if ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) )
722 {
723 OUString aDataStr;
724 if ( aDataHelper.GetString( SotClipboardFormatId::STRING, aDataStr ) )
725 {
726 // get size from string the same way as in ScDdeLink::DataChanged
727
728 aDataStr = convertLineEnd(aDataStr, LINEEND_LF);
729 sal_Int32 nLen = aDataStr.getLength();
730 if (nLen && aDataStr[nLen-1] == '\n')
731 aDataStr = aDataStr.copy(0, nLen-1);
732
733 if (!aDataStr.isEmpty())
734 {
735 nRows = comphelper::string::getTokenCount(aDataStr, '\n');
736 std::u16string_view aLine = o3tl::getToken(aDataStr, 0, '\n' );
737 if (!aLine.empty())
738 nCols = comphelper::string::getTokenCount(aLine, '\t');
739 }
740 }
741 }
742
743 // create formula
744
745 sal_Int32 nSeqLen = aSequence.getLength();
746 const char* p = reinterpret_cast<const char*>(aSequence.getConstArray());
747
748 rtl_TextEncoding eSysEnc = osl_getThreadTextEncoding();
749
750 // char array delimited by \0.
751 // app \0 topic \0 item \0 (extra \0) where the extra is optional.
752 ::std::vector<OUString> aStrs;
753 const char* pStart = p;
754 sal_Int32 nStart = 0;
755 for (sal_Int32 i = 0; i < nSeqLen; ++i, ++p)
756 {
757 if (*p == '\0')
758 {
759 sal_Int32 nLen = i - nStart;
760 aStrs.emplace_back(pStart, nLen, eSysEnc);
761 nStart = ++i;
762 pStart = ++p;
763 }
764 }
765
766 if (aStrs.size() < 3)
767 return false;
768
769 const OUString& pApp = aStrs[0];
770 const OUString& pTopic = aStrs[1];
771 const OUString& pItem = aStrs[2];
772 const OUString* pExtra = nullptr;
773 if (aStrs.size() > 3)
774 pExtra = &aStrs[3];
775
776 if ( pExtra && *pExtra == "calc:extref" )
777 {
778 // Paste this as an external reference. Note that paste link always
779 // uses Calc A1 syntax even when another formula syntax is specified
780 // in the UI.
781 EnterMatrix("='"
782 + ScGlobal::GetAbsDocName(pTopic, GetViewData().GetDocument().GetDocumentShell())
783 + "'#" + pItem
785 return true;
786 }
787 else
788 {
789 // DDE in all other cases.
790
791 // TODO: we could define ocQuote for "
794 + "\"" + pApp + "\""
796 + "\"" + pTopic + "\""
798 + "\"" + pItem + "\""
801 }
802
803 // mark range
804
805 SCTAB nTab = GetViewData().GetTabNo();
806 SCCOL nCurX = GetViewData().GetCurX();
807 SCROW nCurY = GetViewData().GetCurY();
810 InitBlockMode( nCurX, nCurY, nTab );
811 MarkCursor( nCurX+static_cast<SCCOL>(nCols)-1, nCurY+static_cast<SCROW>(nRows)-1, nTab );
814
815 return true;
816}
817
818/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
Reference< XInputStream > xStream
@ SC_PASTETEXT
Definition: asciiopt.hxx:111
size_t Count() const
OUString GetFile(size_t nIndex) const
rtl::Reference< SdrObject > CreateFieldControl(std::u16string_view rFieldDesc) const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
virtual VclPtr< AbstractScTextImportOptionsDlg > CreateScTextImportOptionsDlg(weld::Window *pParent)=0
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
virtual VclPtr< AbstractScImportAsciiDlg > CreateScImportAsciiDlg(weld::Window *pParent, const OUString &aDatName, SvStream *pInStream, ScImportAsciiCall eCall)=0
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2074
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
void SetLanguage(LanguageType e)
Definition: asciiopt.hxx:90
void SetDetectScientificNumber(bool bSet)
Definition: asciiopt.hxx:84
void SetDetectSpecialNumber(bool bSet)
Definition: asciiopt.hxx:83
const OUString & GetName() const
Definition: dbdata.hxx:127
ScDBData * GetDBData(const ScRange &rMarked, ScGetDBMode eMode, ScGetDBSelection eSel)
Definition: docsh5.cxx:115
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:898
SCTAB GetVisibleTab() const
Definition: document.hxx:879
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4161
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4122
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:492
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:982
void SetClipArea(const ScRange &rArea, bool bCut=false)
Definition: document.cxx:3132
SC_DLLPUBLIC void CopyToClip(const ScClipParam &rClipParam, ScDocument *pClipDoc, const ScMarkData *pMarks, bool bKeepScenarioFlags, bool bIncludeObjects)
Definition: document.cxx:2142
ScExtDocOptions * GetExtDocOptions()
Definition: document.hxx:644
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1084
SC_DLLPUBLIC void ResetClip(ScDocument *pSourceDoc, const ScMarkData *pMarks)
Definition: documen2.cxx:525
SC_DLLPUBLIC bool GetCellArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow) const
Definition: document.cxx:998
SC_DLLPUBLIC bool GetPrintArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bNotes=true) const
Definition: documen2.cxx:611
void SetPastingDrawFromOtherDoc(bool bVal)
Definition: document.hxx:2525
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:2502
SC_DLLPUBLIC bool GetDataStart(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow) const
Definition: documen2.cxx:679
bool HasObjects() const
Definition: drwlayer.cxx:430
bool InsertObjectSafe(SdrObject *pObj, SdrPageView &rPV)
Definition: drawview.cxx:797
Extended options held by an ScDocument containing additional settings for filters.
Definition: scextopt.hxx:77
const ScExtTabSettings * GetTabSettings(SCTAB nTab) const
Definition: scextopt.cxx:180
virtual ErrCode ScImportExcel(SfxMedium &, ScDocument *, const EXCIMPFORMAT)=0
static SC_DLLPUBLIC ScFormatFilterPlugin & Get()
Definition: impex.cxx:2684
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
Definition: global2.cxx:287
static void SetClipDocName(const OUString &rNew)
Definition: global.cxx:499
static bool IsFormatSupported(SotClipboardFormatId nFormat)
Definition: impex.cxx:225
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void SelectOneTable(SCTAB nTab)
Definition: markdata.cxx:174
ScAddress aEnd
Definition: address.hxx:498
bool IsValid() const
Definition: address.hxx:544
ScAddress aStart
Definition: address.hxx:497
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:613
void InitBlockMode(SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, bool bTestNeg=false, bool bCols=false, bool bRows=false, bool bForceNeg=false)
Definition: tabview2.cxx:453
void DoneBlockMode(bool bContinue=false)
Definition: tabview2.cxx:509
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1553
void MakeDrawLayer()
Definition: tabview2.cxx:1529
void MarkCursor(SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, bool bCols=false, bool bRows=false, bool bCellSelection=false)
Definition: tabview2.cxx:549
SC_DLLPUBLIC void MoveCursorAbs(SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, bool bShift, bool bControl, bool bKeepOld=false, bool bKeepSel=false)
Definition: tabview3.cxx:1191
ScViewData & GetViewData()
Definition: tabview.hxx:344
void ShowAllCursors()
Definition: tabview3.cxx:234
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:878
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:363
void Unmark()
Definition: tabview3.cxx:1744
void ClickCursor(SCCOL nPosX, SCROW nPosY, bool bControl)
Definition: tabview3.cxx:162
ScDrawView * GetScDrawView()
Definition: tabview.hxx:352
void CursorPosChanged()
Definition: tabview3.cxx:626
void HideAllCursors()
Definition: tabview3.cxx:220
void InvalidateAttribs()
Definition: tabview3.cxx:252
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3140
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
void UpdateInputHandler(bool bForce=false)
Definition: viewdata.cxx:4007
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOL GetCurX() const
Definition: viewdata.hxx:401
bool PasteGraphic(const Point &rPos, const Graphic &rGraphic, const OUString &rFile)
Definition: viewfun7.cxx:384
bool PasteBookmark(SotClipboardFormatId nFormatId, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, SCCOL nPosX, SCROW nPosY)
Definition: viewfun4.cxx:681
bool PasteLink(const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable)
Definition: viewfun5.cxx:703
void PasteRTF(SCCOL nCol, SCROW nStartRow, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable)
Definition: viewfun4.cxx:78
bool PasteDataFormat(SotClipboardFormatId nFormatId, const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, SCCOL nPosX, SCROW nPosY, const Point *pLogicPos, bool bLink=false, bool bAllowDialogs=false)
Definition: viewfun5.cxx:78
void EnterMatrix(const OUString &rString, ::formula::FormulaGrammar::Grammar eGram)
Definition: viewfunc.cxx:839
bool PasteMetaFile(const Point &, const GDIMetaFile &)
Definition: viewfun7.cxx:378
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmptyCells=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
Definition: viewfun3.cxx:871
bool PasteBitmapEx(const Point &, const BitmapEx &)
Definition: viewfun7.cxx:372
void PasteDraw()
Definition: viewfun3.cxx:467
bool PasteObject(const Point &, const css::uno::Reference< css::embed::XEmbeddedObject > &, const Size *, const Graphic *=nullptr, const OUString &=OUString(), sal_Int64 nAspect=css::embed::Aspects::MSOLE_CONTENT)
Definition: viewfun7.cxx:285
bool PasteFile(const Point &, const OUString &, bool bLink)
Definition: viewfun4.cxx:579
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
SdrObject * Next()
size_t GetObjCount() const
virtual void NbcSetLayer(SdrLayerID nLayer)
bool Unload()
SdrPageView * GetSdrPageView() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemSet & GetItemSet() const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
bool isLOKMobilePhone() const
virtual SfxObjectShell * GetObjectShell() override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
css::uno::Sequence< sal_Int8 > GetSequence(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool GetTransferableObjectDescriptor(SotClipboardFormatId nFormat, TransferableObjectDescriptor &rDesc)
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
const DataFlavorExVector & GetDataFlavorExVector() const
bool GetFileList(SotClipboardFormatId nFormat, FileList &rFileList) const
css::uno::Reference< css::io::XInputStream > GetInputStream(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotTempStream > &rStreamRef) const
bool GetGDIMetaFile(SotClipboardFormatId nFormat, GDIMetaFile &rMtf, size_t nMaxActions=0) const
bool HasFormat(SotClipboardFormatId nFormat) const
bool GetBitmapEx(SotClipboardFormatId nFormat, BitmapEx &rBmp) const
bool GetGraphic(SotClipboardFormatId nFormat, Graphic &rGraphic) const
void readGraphic(Graphic &rGraphic)
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
static css::uno::Reference< css::embed::XStorage > GetStorageFromInputStream(const css::uno::Reference< css::io::XInputStream > &xStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static const OUString & GetNativeSymbol(OpCode eOp)
#define SO3_SC_CLASSID_60
static bool extractColumnDescriptor(const TransferableDataHelper &_rData, OUString &_rDatasource, OUString &_rDatabaseLocation, OUString &_rConnectionResource, sal_Int32 &_nCommandType, OUString &_rCommand, OUString &_rFieldName)
static bool canExtractColumnDescriptor(const DataFlavorExVector &_rFlavors, ColumnTransferFormatFlags _nFormats)
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
static bool canExtractObjectDescriptor(const DataFlavorExVector &_rFlavors)
static ODataAccessDescriptor extractObjectDescriptor(const TransferableDataHelper &_rData)
void SetPos(const Point &rPoint)
constexpr Size GetSize() const
weld::Window * GetFrameWeld() const
int nCount
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2720
@ SCDOCMODE_CLIP
Definition: document.hxx:257
float u
EmbeddedObjectRef * pObject
#define ERRCODE_NONE
::std::vector< DataFlavorEx > DataFlavorExVector
@ EIF_AUTO
Definition: filter.hxx:39
SotClipboardFormatId
constexpr SdrLayerID SC_LAYER_FRONT(0)
@ INS_NONE
Definition: global.hxx:295
@ Keep
Keep selection as is, expand to used data area if no selection.
constexpr SdrLayerID SC_LAYER_CONTROLS(3)
@ SC_DB_OLD
don't create
Definition: global.hxx:386
OUString aName
void * p
LINEEND_LF
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
int i
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
long Long
#define SFX_TITLE_FULLNAME
ocDde
ocClose
ocOpen
ocSep
#define SC_MOD()
Definition: scmod.hxx:247
sal_uIntPtr sal_uLong
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Definition: clipparam.hxx:31
Extended settings for a sheet, used in import/export filters.
Definition: scextopt.hxx:48
ScRange maUsedArea
Used area in the sheet (columns/rows only).
Definition: scextopt.hxx:49
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
SVXCORE_DLLPUBLIC bool SvxDrawingLayerImport(SdrModel *pModel, const css::uno::Reference< css::io::XInputStream > &xInputStream)
RET_OK
@ SC_FOLLOW_NONE
Definition: viewdata.hxx:52