LibreOffice Module sc (master)  1
viewfun3.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 <scitems.hxx>
21 #include <svx/svdpage.hxx>
22 #include <sfx2/docfile.hxx>
23 #include <comphelper/classids.hxx>
24 #include <sot/formats.hxx>
25 #include <sot/storage.hxx>
26 #include <vcl/graph.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/weld.hxx>
29 #include <tools/urlobj.hxx>
30 #include <sot/exchange.hxx>
31 #include <memory>
32 #include <vcl/uitest/logger.hxx>
34 
35 #include <attrib.hxx>
36 #include <patattr.hxx>
37 #include <dociter.hxx>
38 #include <viewfunc.hxx>
39 #include <tabvwsh.hxx>
40 #include <docsh.hxx>
41 #include <docfunc.hxx>
42 #include <undoblk.hxx>
43 #include <refundo.hxx>
44 #include <globstr.hrc>
45 #include <scresid.hxx>
46 #include <global.hxx>
47 #include <transobj.hxx>
48 #include <drwtrans.hxx>
49 #include <chgtrack.hxx>
50 #include <waitoff.hxx>
51 #include <scmod.hxx>
52 #include <inputopt.hxx>
53 #include <warnbox.hxx>
54 #include <drwlayer.hxx>
55 #include <editable.hxx>
56 #include <docuno.hxx>
57 #include <clipparam.hxx>
58 #include <undodat.hxx>
59 #include <drawview.hxx>
60 #include <cliputil.hxx>
61 #include <clipoptions.hxx>
62 #include <gridwin.hxx>
63 #include <com/sun/star/util/XCloneable.hpp>
64 
65 using namespace com::sun::star;
66 
67 namespace {
68 
69 void collectUIInformation(const std::map<OUString, OUString>& aParameters, const OUString& action)
70 {
71  EventDescription aDescription;
72  aDescription.aID = "grid_window";
73  aDescription.aAction = action;
74  aDescription.aParameters = aParameters;
75  aDescription.aParent = "MainWindow";
76  aDescription.aKeyWord = "ScGridWinUIObject";
77 
78  UITestLogger::getInstance().logEvent(aDescription);
79 }
80 
81 }
82 
83 // GlobalName of writer-DocShell from comphelper/classids.hxx
84 
85 // C U T
86 
88 {
89  UpdateInputLine();
90 
91  ScEditableTester aTester( this );
92  if (!aTester.IsEditable()) // selection editable?
93  {
94  ErrorMessage( aTester.GetMessageId() );
95  return;
96  }
97 
98  ScRange aRange; // delete this range
99  if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
100  {
101  ScDocument* pDoc = GetViewData().GetDocument();
102  ScDocShell* pDocSh = GetViewData().GetDocShell();
103  ScMarkData& rMark = GetViewData().GetMarkData();
104  const bool bRecord(pDoc->IsUndoEnabled()); // Undo/Redo
105 
106  ScDocShellModificator aModificator( *pDocSh );
107 
108  if ( !rMark.IsMarked() && !rMark.IsMultiMarked() ) // mark the range if not marked yet
109  {
110  DoneBlockMode();
111  InitOwnBlockMode();
112  rMark.SetMarkArea( aRange );
113  MarkDataChanged();
114  }
115 
116  CopyToClip( nullptr, true, false, true/*bIncludeObjects*/ ); // copy to clipboard
117 
118  ScAddress aOldEnd( aRange.aEnd ); // combined cells in this range?
119  pDoc->ExtendMerge( aRange, true );
120 
121  ScDocumentUniquePtr pUndoDoc;
122  if ( bRecord )
123  {
124  pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
125  pUndoDoc->InitUndoSelected( pDoc, rMark );
126  // all sheets - CopyToDocument skips those that don't exist in pUndoDoc
127  ScRange aCopyRange = aRange;
128  aCopyRange.aStart.SetTab(0);
129  aCopyRange.aEnd.SetTab(pDoc->GetTableCount()-1);
131  pDoc->BeginDrawUndo();
132  }
133 
134  sal_uInt16 nExtFlags = 0;
135  pDocSh->UpdatePaintExt( nExtFlags, aRange );
136 
137  rMark.MarkToMulti();
138  pDoc->DeleteSelection( InsertDeleteFlags::ALL, rMark );
139  pDoc->DeleteObjectsInSelection( rMark );
140  rMark.MarkToSimple();
141 
142  if ( !AdjustRowHeight( aRange.aStart.Row(), aRange.aEnd.Row() ) )
143  pDocSh->PostPaint( aRange, PaintPartFlags::Grid, nExtFlags );
144 
145  if ( bRecord ) // Draw-Undo now available
146  pDocSh->GetUndoManager()->AddUndoAction(
147  std::make_unique<ScUndoCut>( pDocSh, aRange, aOldEnd, rMark, std::move(pUndoDoc) ) );
148 
149  aModificator.SetDocumentModified();
150  pDocSh->UpdateOle(&GetViewData());
151 
152  CellContentChanged();
153 
154  OUString aStartAddress = aRange.aStart.GetColRowString();
155  OUString aEndAddress = aRange.aEnd.GetColRowString();
156 
157  collectUIInformation({{"RANGE", aStartAddress + ":" + aEndAddress}}, "CUT");
158  }
159  else
160  ErrorMessage( STR_NOMULTISELECT );
161 }
162 
163 // C O P Y
164 
165 bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, bool bCut, bool bApi, bool bIncludeObjects, bool bStopEdit )
166 {
167  ScRange aRange;
168  ScMarkType eMarkType = GetViewData().GetSimpleArea( aRange );
169  ScMarkData& rMark = GetViewData().GetMarkData();
170  bool bDone = false;
171 
172  if ( eMarkType == SC_MARK_SIMPLE || eMarkType == SC_MARK_SIMPLE_FILTERED )
173  {
174  ScRangeList aRangeList( aRange );
175  bDone = CopyToClip( pClipDoc, aRangeList, bCut, bApi, bIncludeObjects, bStopEdit );
176  }
177  else if (eMarkType == SC_MARK_MULTI)
178  {
179  ScRangeList aRangeList;
180  rMark.MarkToSimple();
181  rMark.FillRangeListWithMarks(&aRangeList, false);
182  bDone = CopyToClip( pClipDoc, aRangeList, bCut, bApi, bIncludeObjects, bStopEdit );
183  }
184  else
185  {
186  if (!bApi)
187  ErrorMessage(STR_NOMULTISELECT);
188  }
189  if( !bCut ){
190  OUString aStartAddress = aRange.aStart.GetColRowString();
191  OUString aEndAddress = aRange.aEnd.GetColRowString();
192  collectUIInformation({{"RANGE", aStartAddress + ":" + aEndAddress}}, "COPY");
193  }
194  return bDone;
195 }
196 
197 // Copy the content of the Range into clipboard.
198 bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, bool bCut, bool bApi, bool bIncludeObjects, bool bStopEdit )
199 {
200  if ( rRanges.empty() )
201  return false;
202  if ( bStopEdit )
203  UpdateInputLine();
204 
205  bool bDone;
206  if (rRanges.size() > 1) // isMultiRange
207  bDone = CopyToClipMultiRange(pClipDoc, rRanges, bCut, bApi, bIncludeObjects);
208  else
209  bDone = CopyToClipSingleRange(pClipDoc, rRanges, bCut, bIncludeObjects);
210 
211  return bDone;
212 }
213 
214 bool ScViewFunc::CopyToClipSingleRange( ScDocument* pClipDoc, const ScRangeList& rRanges, bool bCut, bool bIncludeObjects )
215 {
216  ScRange aRange = rRanges[0];
217  ScClipParam aClipParam( aRange, bCut );
218  aClipParam.maRanges = rRanges;
219  ScDocument* pDoc = GetViewData().GetDocument();
220  ScMarkData& rMark = GetViewData().GetMarkData();
221 
222  if ( !pDoc
223  || pDoc->HasSelectedBlockMatrixFragment( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), rMark ) )
224  return false;
225 
226  bool bSysClip = false;
227  if ( !pClipDoc ) // no clip doc specified
228  {
229  // Create one (deleted by ScTransferObj).
230  pClipDoc = new ScDocument( SCDOCMODE_CLIP );
231  bSysClip = true; // and copy into system
232  }
233  if ( !bCut )
234  {
235  ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
236  if ( pChangeTrack )
237  pChangeTrack->ResetLastCut();
238  }
239 
240  if ( bSysClip && bIncludeObjects )
241  {
242  bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange );
243  // Update ScGlobal::xDrawClipDocShellRef.
245  }
246 
247  // is this necessary?, will setting the doc id upset the
248  // following paste operation with range? would be nicer to just set this always
249  // and lose the 'if' above
250  aClipParam.setSourceDocID( pDoc->GetDocumentID() );
251 
252  if (SfxObjectShell* pObjectShell = pDoc->GetDocumentShell())
253  {
254  // Copy document properties from pObjectShell to pClipDoc (to its clip options, as it has no object shell).
255  uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(pObjectShell->GetModel(), uno::UNO_QUERY);
256  uno::Reference<util::XCloneable> xCloneable(xDocumentPropertiesSupplier->getDocumentProperties(), uno::UNO_QUERY);
257  std::unique_ptr<ScClipOptions> pOptions(new ScClipOptions);
258  pOptions->m_xDocumentProperties.set(xCloneable->createClone(), uno::UNO_QUERY);
259  pClipDoc->SetClipOptions(std::move(pOptions));
260  }
261 
262  pDoc->CopyToClip( aClipParam, pClipDoc, &rMark, false, bIncludeObjects );
263  if (ScDrawLayer* pDrawLayer = pClipDoc->GetDrawLayer())
264  {
265  ScClipParam& rClipDocClipParam = pClipDoc->GetClipParam();
266  ScRangeListVector& rRangesVector = rClipDocClipParam.maProtectedChartRangesVector;
267  SCTAB nTabCount = pClipDoc->GetTableCount();
268  for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
269  {
270  SdrPage* pPage = pDrawLayer->GetPage( static_cast< sal_uInt16 >( nTab ) );
271  if ( pPage )
272  {
273  ScChartHelper::FillProtectedChartRangesVector( rRangesVector, pDoc, pPage );
274  }
275  }
276  }
277 
278  if ( bSysClip )
279  {
282  }
283  pClipDoc->ExtendMerge( aRange, true );
284 
285  if ( bSysClip )
286  {
287  ScDocShell* pDocSh = GetViewData().GetDocShell();
289  pDocSh->FillTransferableObjectDescriptor( aObjDesc );
290  aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
291  // maSize is set in ScTransferObj ctor
292 
293  rtl::Reference<ScTransferObj> pTransferObj(new ScTransferObj( ScDocumentUniquePtr(pClipDoc), aObjDesc ));
295  {
297  pTransferObj->SetDrawPersist( aPersistRef );// keep persist for ole objects alive
298  }
299  pTransferObj->CopyToClipboard( GetActiveWin() );
300  }
301 
302  return true;
303 }
304 
305 bool ScViewFunc::CopyToClipMultiRange( const ScDocument* pInputClipDoc, const ScRangeList& rRanges, bool bCut, bool bApi, bool bIncludeObjects )
306 {
307  if (bCut)
308  {
309  // We don't support cutting of multi-selections.
310  if (!bApi)
311  ErrorMessage(STR_NOMULTISELECT);
312  return false;
313  }
314  if (pInputClipDoc)
315  {
316  // TODO: What's this for?
317  if (!bApi)
318  ErrorMessage(STR_NOMULTISELECT);
319  return false;
320  }
321 
322  ScClipParam aClipParam( rRanges[0], bCut );
323  aClipParam.maRanges = rRanges;
324  ScDocument* pDoc = GetViewData().GetDocument();
325  ScMarkData& rMark = GetViewData().GetMarkData();
326  bool bDone = false;
327  bool bSuccess = false;
328  aClipParam.mbCutMode = false;
329 
330  do
331  {
333 
334  // Check for geometrical feasibility of the ranges.
335  bool bValidRanges = true;
336  ScRange const * p = &aClipParam.maRanges.front();
337  SCCOL nPrevColDelta = 0;
338  SCROW nPrevRowDelta = 0;
339  SCCOL nPrevCol = p->aStart.Col();
340  SCROW nPrevRow = p->aStart.Row();
341  SCCOL nPrevColSize = p->aEnd.Col() - p->aStart.Col() + 1;
342  SCROW nPrevRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
343  for ( size_t i = 1; i < aClipParam.maRanges.size(); ++i )
344  {
345  p = &aClipParam.maRanges[i];
347  p->aStart.Col(), p->aStart.Row(), p->aEnd.Col(), p->aEnd.Row(), rMark) )
348  {
349  if (!bApi)
350  ErrorMessage(STR_MATRIXFRAGMENTERR);
351  return false;
352  }
353 
354  SCCOL nColDelta = p->aStart.Col() - nPrevCol;
355  SCROW nRowDelta = p->aStart.Row() - nPrevRow;
356 
357  if ((nColDelta && nRowDelta) || (nPrevColDelta && nRowDelta) || (nPrevRowDelta && nColDelta))
358  {
359  bValidRanges = false;
360  break;
361  }
362 
363  if (aClipParam.meDirection == ScClipParam::Unspecified)
364  {
365  if (nColDelta)
366  aClipParam.meDirection = ScClipParam::Column;
367  if (nRowDelta)
368  aClipParam.meDirection = ScClipParam::Row;
369  }
370 
371  SCCOL nColSize = p->aEnd.Col() - p->aStart.Col() + 1;
372  SCROW nRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
373 
374  if (aClipParam.meDirection == ScClipParam::Column && nRowSize != nPrevRowSize)
375  {
376  // column-oriented ranges must have identical row size.
377  bValidRanges = false;
378  break;
379  }
380  if (aClipParam.meDirection == ScClipParam::Row && nColSize != nPrevColSize)
381  {
382  // likewise, row-oriented ranges must have identical
383  // column size.
384  bValidRanges = false;
385  break;
386  }
387 
388  nPrevCol = p->aStart.Col();
389  nPrevRow = p->aStart.Row();
390  nPrevColDelta = nColDelta;
391  nPrevRowDelta = nRowDelta;
392  nPrevColSize = nColSize;
393  nPrevRowSize = nRowSize;
394  }
395  if (!bValidRanges)
396  break;
397  pDoc->CopyToClip(aClipParam, pDocClip.get(), &rMark, false, bIncludeObjects );
398 
399  ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
400  if ( pChangeTrack )
401  pChangeTrack->ResetLastCut(); // no more cut-mode
402 
403  ScDocShell* pDocSh = GetViewData().GetDocShell();
405  pDocSh->FillTransferableObjectDescriptor( aObjDesc );
406  aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
407  // maSize is set in ScTransferObj ctor
408 
409  rtl::Reference<ScTransferObj> pTransferObj(new ScTransferObj( std::move(pDocClip), aObjDesc ));
411  {
413  pTransferObj->SetDrawPersist( aPersistRef ); // keep persist for ole objects alive
414  }
415  pTransferObj->CopyToClipboard( GetActiveWin() ); // system clipboard
416 
417  bSuccess = true;
418  }
419  while (false);
420 
421  if (!bSuccess && !bApi)
422  ErrorMessage(STR_NOMULTISELECT);
423 
424  bDone = bSuccess;
425 
426  return bDone;
427 }
428 
430 {
431  ScRange aRange;
432  if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
433  {
434  ScDocument* pDoc = GetViewData().GetDocument();
435  ScMarkData& rMark = GetViewData().GetMarkData();
436  if ( !pDoc->HasSelectedBlockMatrixFragment(
437  aRange.aStart.Col(), aRange.aStart.Row(),
438  aRange.aEnd.Col(), aRange.aEnd.Row(),
439  rMark ) )
440  {
441  ScDocumentUniquePtr pClipDoc(new ScDocument( SCDOCMODE_CLIP )); // create one (deleted by ScTransferObj)
442 
443  bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange, &rMark );
445 
446  ScClipParam aClipParam(aRange, false);
447  pDoc->CopyToClip(aClipParam, pClipDoc.get(), &rMark, false, true);
448 
450  pClipDoc->ExtendMerge( aRange, true );
451 
452  ScDocShell* pDocSh = GetViewData().GetDocShell();
454  pDocSh->FillTransferableObjectDescriptor( aObjDesc );
455  aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
456  ScTransferObj* pTransferObj = new ScTransferObj( std::move(pClipDoc), aObjDesc );
457  return pTransferObj;
458  }
459  }
460 
461  return nullptr;
462 }
463 
464 // P A S T E
465 
467 {
468  ScViewData& rViewData = GetViewData();
469  SCCOL nPosX = rViewData.GetCurX();
470  SCROW nPosY = rViewData.GetCurY();
471  vcl::Window* pWin = GetActiveWin();
472  Point aPos = pWin->PixelToLogic( rViewData.GetScrPos( nPosX, nPosY,
473  rViewData.GetActivePart() ) );
475  if (pDrawClip)
476  {
477  const OUString& aSrcShellID = pDrawClip->GetShellID();
478  OUString aDestShellID = SfxObjectShell::CreateShellID(rViewData.GetDocShell());
479  PasteDraw(aPos, pDrawClip->GetModel(), false, aSrcShellID, aDestShellID);
480  }
481 }
482 
484 {
485  UpdateInputLine();
486 
487  vcl::Window* pWin = GetActiveWin();
488  css::uno::Reference<css::datatransfer::XTransferable2> xTransferable2(ScTabViewShell::GetClipData(pWin));
489  const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(xTransferable2);
490  // keep a reference in case the clipboard is changed during PasteFromClip
491  const ScDrawTransferObj* pDrawClip = ScDrawTransferObj::GetOwnClipboard(xTransferable2);
492  if (pOwnClip)
493  {
494  PasteFromClip( InsertDeleteFlags::ALL, pOwnClip->GetDocument(),
495  ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
496  true ); // allow warning dialog
497  }
498  else if (pDrawClip)
499  PasteDraw();
500  else
501  {
503 
504  {
507 
508  SotClipboardFormatId nFormat; // output param for GetExchangeAction
509  sal_uInt8 nEventAction; // output param for GetExchangeAction
510 
511  uno::Reference<css::datatransfer::XTransferable> xTransferable( aDataHelper.GetXTransferable() );
513  aDataHelper.GetDataFlavorExVector(),
514  SotExchangeDest::SCDOC_FREE_AREA,
517  nFormat, nEventAction, SotClipboardFormatId::NONE,
518  &xTransferable );
519 
520  if ( nAction != EXCHG_INOUT_ACTION_NONE )
521  {
522  switch( nAction )
523  {
528  // SotClipboardFormatId::BITMAP
529  // SotClipboardFormatId::PNG
530  // SotClipboardFormatId::GDIMETAFILE
531  // SotClipboardFormatId::SVXB
532  PasteFromSystem(nFormat);
533  break;
534  default:
535  nAction = EXCHG_INOUT_ACTION_NONE;
536  }
537  }
538 
539  if ( nAction == EXCHG_INOUT_ACTION_NONE )
540  {
541  // first SvDraw-model, then drawing
542  // (only one drawing is allowed)
543 
544  if (aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ))
545  {
546  // special case for tables from drawing
547  if( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) )
548  {
549  PasteFromSystem( SotClipboardFormatId::RTF );
550  }
551  else if( aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) )
552  {
553  PasteFromSystem( SotClipboardFormatId::RICHTEXT );
554  }
555  else
556  {
557  PasteFromSystem( SotClipboardFormatId::DRAWING );
558  }
559  }
560  else if (aDataHelper.HasFormat( SotClipboardFormatId::EMBED_SOURCE ))
561  {
562  // If it's a Writer object, insert RTF instead of OLE
563 
564  // Else, if the class id is all-zero, and SYLK is available,
565  // it probably is spreadsheet cells that have been put
566  // on the clipboard by OOo, so use the SYLK. (fdo#31077)
567 
568  bool bDoRtf = false;
570  if( aDataHelper.GetTransferableObjectDescriptor( SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDesc ) )
571  {
572  bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) ||
574  && ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) ) );
575  }
576  if ( bDoRtf )
577  PasteFromSystem( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT );
578  else if ( aObjDesc.maClassName == SvGlobalName( 0,0,0,0,0,0,0,0,0,0,0 )
579  && aDataHelper.HasFormat( SotClipboardFormatId::SYLK ))
580  PasteFromSystem( SotClipboardFormatId::SYLK );
581  else
582  PasteFromSystem( SotClipboardFormatId::EMBED_SOURCE );
583  }
584  else if (aDataHelper.HasFormat( SotClipboardFormatId::LINK_SOURCE ))
585  PasteFromSystem( SotClipboardFormatId::LINK_SOURCE );
586  // the following format can not affect scenario from #89579#
587  else if (aDataHelper.HasFormat( SotClipboardFormatId::EMBEDDED_OBJ_OLE ))
588  PasteFromSystem( SotClipboardFormatId::EMBEDDED_OBJ_OLE );
589  // SotClipboardFormatId::PRIVATE no longer here (can't work if pOwnClip is NULL)
590  else if (aDataHelper.HasFormat(nBiff8)) // before xxx_OLE formats
591  PasteFromSystem(nBiff8);
592  else if (aDataHelper.HasFormat(nBiff5))
593  PasteFromSystem(nBiff5);
594  else if (aDataHelper.HasFormat(SotClipboardFormatId::RTF))
595  PasteFromSystem(SotClipboardFormatId::RTF);
596  else if (aDataHelper.HasFormat(SotClipboardFormatId::RICHTEXT))
597  PasteFromSystem(SotClipboardFormatId::RICHTEXT);
598  else if (aDataHelper.HasFormat(SotClipboardFormatId::HTML))
599  PasteFromSystem(SotClipboardFormatId::HTML);
600  else if (aDataHelper.HasFormat(SotClipboardFormatId::HTML_SIMPLE))
601  PasteFromSystem(SotClipboardFormatId::HTML_SIMPLE);
602  else if (aDataHelper.HasFormat(SotClipboardFormatId::SYLK))
603  PasteFromSystem(SotClipboardFormatId::SYLK);
604  else if (aDataHelper.HasFormat(SotClipboardFormatId::STRING_TSVC))
605  PasteFromSystem(SotClipboardFormatId::STRING_TSVC);
606  else if (aDataHelper.HasFormat(SotClipboardFormatId::STRING))
607  PasteFromSystem(SotClipboardFormatId::STRING);
608  // xxx_OLE formats come last, like in SotExchange tables
609  else if (aDataHelper.HasFormat( SotClipboardFormatId::EMBED_SOURCE_OLE ))
610  PasteFromSystem( SotClipboardFormatId::EMBED_SOURCE_OLE );
611  else if (aDataHelper.HasFormat( SotClipboardFormatId::LINK_SOURCE_OLE ))
612  PasteFromSystem( SotClipboardFormatId::LINK_SOURCE_OLE );
613  }
614  }
615  }
616  // no exception-> SID_PASTE has FastCall-flag from idl
617  // will be called in case of empty clipboard (#42531#)
618 }
619 
620 void ScViewFunc::PasteFromTransferable( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
621 {
622  ScTransferObj *pOwnClip=nullptr;
623  ScDrawTransferObj *pDrawClip=nullptr;
624  uno::Reference<lang::XUnoTunnel> xTunnel( rxTransferable, uno::UNO_QUERY );
625  if ( xTunnel.is() )
626  {
627  sal_Int64 nHandle = xTunnel->getSomething( ScTransferObj::getUnoTunnelId() );
628  if ( nHandle )
629  pOwnClip = reinterpret_cast<ScTransferObj*>( static_cast<sal_IntPtr>(nHandle));
630  else
631  {
632  nHandle = xTunnel->getSomething( ScDrawTransferObj::getUnoTunnelId() );
633  if ( nHandle )
634  pDrawClip = reinterpret_cast<ScDrawTransferObj*>( static_cast<sal_IntPtr>(nHandle) );
635  }
636  }
637 
638  if (pOwnClip)
639  {
640  PasteFromClip( InsertDeleteFlags::ALL, pOwnClip->GetDocument(),
641  ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
642  true ); // allow warning dialog
643  }
644  else if (pDrawClip)
645  {
646  ScViewData& rViewData = GetViewData();
647  SCCOL nPosX = rViewData.GetCurX();
648  SCROW nPosY = rViewData.GetCurY();
649  vcl::Window* pWin = GetActiveWin();
650  Point aPos = pWin->PixelToLogic( rViewData.GetScrPos( nPosX, nPosY, rViewData.GetActivePart() ) );
651  PasteDraw(
652  aPos, pDrawClip->GetModel(), false,
653  pDrawClip->GetShellID(), SfxObjectShell::CreateShellID(rViewData.GetDocShell()));
654  }
655  else
656  {
657  TransferableDataHelper aDataHelper( rxTransferable );
660  SotClipboardFormatId nFormatId = SotClipboardFormatId::NONE;
661  // first SvDraw-model, then drawing
662  // (only one drawing is allowed)
663 
664  if (aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ))
665  nFormatId = SotClipboardFormatId::DRAWING;
666  else if (aDataHelper.HasFormat( SotClipboardFormatId::SVXB ))
667  nFormatId = SotClipboardFormatId::SVXB;
668  else if (aDataHelper.HasFormat( SotClipboardFormatId::EMBED_SOURCE ))
669  {
670  // If it's a Writer object, insert RTF instead of OLE
671  bool bDoRtf = false;
673  if( aDataHelper.GetTransferableObjectDescriptor( SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDesc ) )
674  {
675  bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) ||
677  && ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) ));
678  }
679  if ( bDoRtf )
680  nFormatId = aDataHelper.HasFormat( SotClipboardFormatId::RTF ) ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT;
681  else
682  nFormatId = SotClipboardFormatId::EMBED_SOURCE;
683  }
684  else if (aDataHelper.HasFormat( SotClipboardFormatId::LINK_SOURCE ))
685  nFormatId = SotClipboardFormatId::LINK_SOURCE;
686  // the following format can not affect scenario from #89579#
687  else if (aDataHelper.HasFormat( SotClipboardFormatId::EMBEDDED_OBJ_OLE ))
688  nFormatId = SotClipboardFormatId::EMBEDDED_OBJ_OLE;
689  // SotClipboardFormatId::PRIVATE no longer here (can't work if pOwnClip is NULL)
690  else if (aDataHelper.HasFormat(nBiff8)) // before xxx_OLE formats
691  nFormatId = nBiff8;
692  else if (aDataHelper.HasFormat(nBiff5))
693  nFormatId = nBiff5;
694  else if (aDataHelper.HasFormat(SotClipboardFormatId::RTF))
695  nFormatId = SotClipboardFormatId::RTF;
696  else if (aDataHelper.HasFormat(SotClipboardFormatId::RICHTEXT))
697  nFormatId = SotClipboardFormatId::RICHTEXT;
698  else if (aDataHelper.HasFormat(SotClipboardFormatId::HTML))
699  nFormatId = SotClipboardFormatId::HTML;
700  else if (aDataHelper.HasFormat(SotClipboardFormatId::HTML_SIMPLE))
701  nFormatId = SotClipboardFormatId::HTML_SIMPLE;
702  else if (aDataHelper.HasFormat(SotClipboardFormatId::SYLK))
703  nFormatId = SotClipboardFormatId::SYLK;
704  else if (aDataHelper.HasFormat(SotClipboardFormatId::STRING_TSVC))
705  nFormatId = SotClipboardFormatId::STRING_TSVC;
706  else if (aDataHelper.HasFormat(SotClipboardFormatId::STRING))
707  nFormatId = SotClipboardFormatId::STRING;
708  else if (aDataHelper.HasFormat(SotClipboardFormatId::GDIMETAFILE))
709  nFormatId = SotClipboardFormatId::GDIMETAFILE;
710  else if (aDataHelper.HasFormat(SotClipboardFormatId::BITMAP))
711  nFormatId = SotClipboardFormatId::BITMAP;
712  // xxx_OLE formats come last, like in SotExchange tables
713  else if (aDataHelper.HasFormat( SotClipboardFormatId::EMBED_SOURCE_OLE ))
714  nFormatId = SotClipboardFormatId::EMBED_SOURCE_OLE;
715  else if (aDataHelper.HasFormat( SotClipboardFormatId::LINK_SOURCE_OLE ))
716  nFormatId = SotClipboardFormatId::LINK_SOURCE_OLE;
717  else
718  return;
719 
720  PasteDataFormat( nFormatId, aDataHelper.GetTransferable(),
721  GetViewData().GetCurX(), GetViewData().GetCurY(), nullptr );
722  }
723 }
724 
726 {
727  UpdateInputLine();
728 
729  bool bRet = true;
730  vcl::Window* pWin = GetActiveWin();
731  // keep a reference in case the clipboard is changed during PasteFromClip
733  if ( nFormatId == SotClipboardFormatId::NONE && pOwnClip )
734  {
735  PasteFromClip( InsertDeleteFlags::ALL, pOwnClip->GetDocument(),
736  ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
737  !bApi ); // allow warning dialog
738  }
739  else
740  {
742  if ( !aDataHelper.GetTransferable().is() )
743  return false;
744 
745  SCCOL nPosX = 0;
746  SCROW nPosY = 0;
747 
748  ScViewData& rViewData = GetViewData();
749  ScRange aRange;
750  if ( rViewData.GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
751  {
752  nPosX = aRange.aStart.Col();
753  nPosY = aRange.aStart.Row();
754  }
755  else
756  {
757  nPosX = rViewData.GetCurX();
758  nPosY = rViewData.GetCurY();
759  }
760 
761  bRet = PasteDataFormat( nFormatId, aDataHelper.GetTransferable(),
762  nPosX, nPosY,
763  nullptr, false, !bApi ); // allow warning dialog
764 
765  if ( !bRet && !bApi )
766  ErrorMessage(STR_PASTE_ERROR);
767  }
768  return bRet;
769 }
770 
771 // P A S T E
772 
774  const uno::Reference<datatransfer::XTransferable>& rxTransferable,
775  SdrObject& rHitObj)
776 {
777  TransferableDataHelper aDataHelper( rxTransferable );
778 
779  if ( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) )
780  {
782  ScDrawView* pScDrawView = GetScDrawView();
783 
784  if( pScDrawView && aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ) )
785  {
786  Graphic aGraphic;
787 
788  ReadGraphic( *xStm, aGraphic );
789 
790  const OUString aBeginUndo(ScResId(STR_UNDO_DRAGDROP));
791 
792  if(pScDrawView->ApplyGraphicToObject( rHitObj, aGraphic, aBeginUndo, "", "" ))
793  {
794  return true;
795  }
796  }
797  }
798  else if ( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ) )
799  {
800  GDIMetaFile aMtf;
801  ScDrawView* pScDrawView = GetScDrawView();
802 
803  if( pScDrawView && aDataHelper.GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE, aMtf ) )
804  {
805  const OUString aBeginUndo(ScResId(STR_UNDO_DRAGDROP));
806 
807  if(pScDrawView->ApplyGraphicToObject( rHitObj, Graphic(aMtf), aBeginUndo, "", "" ))
808  {
809  return true;
810  }
811  }
812  }
813  else if ( aDataHelper.HasFormat( SotClipboardFormatId::BITMAP ) || aDataHelper.HasFormat( SotClipboardFormatId::PNG ) )
814  {
815  BitmapEx aBmpEx;
816  ScDrawView* pScDrawView = GetScDrawView();
817 
818  if( pScDrawView && aDataHelper.GetBitmapEx( SotClipboardFormatId::BITMAP, aBmpEx ) )
819  {
820  const OUString aBeginUndo(ScResId(STR_UNDO_DRAGDROP));
821 
822  if(pScDrawView->ApplyGraphicToObject( rHitObj, Graphic(aBmpEx), aBeginUndo, "", "" ))
823  {
824  return true;
825  }
826  }
827  }
828 
829  return false;
830 }
831 
832 static bool lcl_SelHasAttrib( const ScDocument* pDoc, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
833  const ScMarkData& rTabSelection, HasAttrFlags nMask )
834 {
835  return std::any_of(rTabSelection.begin(), rTabSelection.end(),
836  [&](const SCTAB& rTab) { return pDoc->HasAttrib( nCol1, nRow1, rTab, nCol2, nRow2, rTab, nMask ); });
837 }
838 
839 // paste into sheet:
840 
841 // internal paste
842 
843 namespace {
844 
845 bool checkDestRangeForOverwrite(const ScRangeList& rDestRanges, const ScDocument* pDoc, const ScMarkData& rMark, weld::Window* pParentWnd)
846 {
847  bool bIsEmpty = true;
848  size_t nRangeSize = rDestRanges.size();
849  for (const auto& rTab : rMark)
850  {
851  for (size_t i = 0; i < nRangeSize && bIsEmpty; ++i)
852  {
853  const ScRange& rRange = rDestRanges[i];
854  bIsEmpty = pDoc->IsBlockEmpty(
855  rTab, rRange.aStart.Col(), rRange.aStart.Row(),
856  rRange.aEnd.Col(), rRange.aEnd.Row());
857  }
858  if (!bIsEmpty)
859  break;
860  }
861 
862  if (!bIsEmpty)
863  {
864  ScReplaceWarnBox aBox(pParentWnd);
865  if (aBox.run() != RET_YES)
866  {
867  // changing the configuration is within the ScReplaceWarnBox
868  return false;
869  }
870  }
871  return true;
872 }
873 
874 }
875 
877  ScPasteFunc nFunction, bool bSkipEmpty,
878  bool bTranspose, bool bAsLink,
879  InsCellCmd eMoveMode, InsertDeleteFlags nUndoExtraFlags,
880  bool bAllowDialogs )
881 {
882  if (!pClipDoc)
883  {
884  OSL_FAIL("PasteFromClip: pClipDoc=0 not allowed");
885  return false;
886  }
887 
888  if (GetViewData().SelectionForbidsCellFill())
889  return false;
890 
891  // undo: save all or no content
893  if (nFlags & InsertDeleteFlags::CONTENTS)
894  nContFlags |= InsertDeleteFlags::CONTENTS;
895  if (nFlags & InsertDeleteFlags::ATTRIB)
896  nContFlags |= InsertDeleteFlags::ATTRIB;
897  // move attributes to undo without copying them from clip to doc
898  InsertDeleteFlags nUndoFlags = nContFlags;
899  if (nUndoExtraFlags & InsertDeleteFlags::ATTRIB)
900  nUndoFlags |= InsertDeleteFlags::ATTRIB;
901  // do not copy note captions into undo document
902  nUndoFlags |= InsertDeleteFlags::NOCAPTIONS;
903 
904  ScClipParam& rClipParam = pClipDoc->GetClipParam();
905  if (rClipParam.isMultiRange())
906  {
907  // Source data is multi-range.
908  return PasteMultiRangesFromClip(
909  nFlags, pClipDoc, nFunction, bSkipEmpty, bTranspose, bAsLink, bAllowDialogs,
910  eMoveMode, nUndoFlags);
911  }
912 
913  ScMarkData& rMark = GetViewData().GetMarkData();
914  if (rMark.IsMultiMarked())
915  {
916  // Source data is single-range but destination is multi-range.
917  return PasteFromClipToMultiRanges(
918  nFlags, pClipDoc, nFunction, bSkipEmpty, bTranspose, bAsLink, bAllowDialogs,
919  eMoveMode, nUndoFlags);
920  }
921 
922  bool bCutMode = pClipDoc->IsCutMode(); // if transposing, take from original clipdoc
923  bool bIncludeFiltered = bCutMode;
924 
925  // paste drawing: also if InsertDeleteFlags::NOTE is set (to create drawing layer for note captions)
926  bool bPasteDraw = ( pClipDoc->GetDrawLayer() && ( nFlags & (InsertDeleteFlags::OBJECTS|InsertDeleteFlags::NOTE) ) );
927 
928  ScDocShellRef aTransShellRef; // for objects in xTransClip - must remain valid as long as xTransClip
929  ScDocument* pOrigClipDoc = nullptr;
930  ScDocumentUniquePtr xTransClip;
931  if ( bTranspose )
932  {
933  SCCOL nX;
934  SCROW nY;
935  // include filtered rows until TransposeClip can skip them
936  bIncludeFiltered = true;
937  pClipDoc->GetClipArea( nX, nY, true );
938  if ( nY > static_cast<sal_Int32>(pClipDoc->MaxCol()) ) // too many lines for transpose
939  {
940  ErrorMessage(STR_PASTE_FULL);
941  return false;
942  }
943  pOrigClipDoc = pClipDoc; // refs
944 
945  if ( bPasteDraw )
946  {
947  aTransShellRef = new ScDocShell; // DocShell needs a Ref immediately
948  aTransShellRef->DoInitNew();
949  }
950  ScDrawLayer::SetGlobalDrawPersist( aTransShellRef.get() );
951 
952  xTransClip.reset( new ScDocument( SCDOCMODE_CLIP ));
953  pClipDoc->TransposeClip( xTransClip.get(), nFlags, bAsLink );
954  pClipDoc = xTransClip.get();
955 
957  }
958 
959  SCCOL nStartCol;
960  SCROW nStartRow;
961  SCTAB nStartTab;
962  SCCOL nEndCol;
963  SCROW nEndRow;
964  SCTAB nEndTab;
965  SCCOL nClipSizeX;
966  SCROW nClipSizeY;
967  pClipDoc->GetClipArea( nClipSizeX, nClipSizeY, true ); // size in clipboard doc
968 
969  // size in target doc: include filtered rows only if CutMode is set
970  SCCOL nDestSizeX;
971  SCROW nDestSizeY;
972  pClipDoc->GetClipArea( nDestSizeX, nDestSizeY, bIncludeFiltered );
973 
974  ScDocument* pDoc = GetViewData().GetDocument();
975  ScDocShell* pDocSh = GetViewData().GetDocShell();
976  SfxUndoManager* pUndoMgr = pDocSh->GetUndoManager();
977  const bool bRecord(pDoc->IsUndoEnabled());
978 
979  ScDocShellModificator aModificator( *pDocSh );
980 
981  ScRange aMarkRange;
982  ScMarkData aFilteredMark( rMark); // local copy for all modifications
983  ScMarkType eMarkType = GetViewData().GetSimpleArea( aMarkRange, aFilteredMark);
984  bool bMarkIsFiltered = (eMarkType == SC_MARK_SIMPLE_FILTERED);
985  bool bNoPaste = ((eMarkType != SC_MARK_SIMPLE && !bMarkIsFiltered) ||
986  (bMarkIsFiltered && (eMoveMode != INS_NONE || bAsLink)));
987 
988  if (!bNoPaste)
989  {
990  if (!rMark.IsMarked())
991  {
992  // Create a selection with clipboard row count and check that for
993  // filtered.
994  nStartCol = GetViewData().GetCurX();
995  nStartRow = GetViewData().GetCurY();
996  nStartTab = GetViewData().GetTabNo();
997  nEndCol = nStartCol + nDestSizeX;
998  nEndRow = nStartRow + nDestSizeY;
999  nEndTab = nStartTab;
1000  aMarkRange = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
1001  if (ScViewUtil::HasFiltered( aMarkRange, pDoc))
1002  {
1003  bMarkIsFiltered = true;
1004  // Fit to clipboard's row count unfiltered rows. If there is no
1005  // fit assume that pasting is not possible. Note that nDestSizeY is
1006  // size-1 (difference).
1007  if (!ScViewUtil::FitToUnfilteredRows( aMarkRange, pDoc, nDestSizeY+1))
1008  bNoPaste = true;
1009  }
1010  aFilteredMark.SetMarkArea( aMarkRange);
1011  }
1012  else
1013  {
1014  // Expand the marked area when the destination area is larger than the
1015  // current selection, to get the undo do the right thing. (i#106711)
1016  ScRange aRange;
1017  aFilteredMark.GetMarkArea( aRange );
1018  if( (aRange.aEnd.Col() - aRange.aStart.Col()) < nDestSizeX )
1019  {
1020  aRange.aEnd.SetCol(aRange.aStart.Col() + nDestSizeX);
1021  aFilteredMark.SetMarkArea(aRange);
1022  }
1023  }
1024  }
1025 
1026  if (bNoPaste)
1027  {
1028  ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
1029  return false;
1030  }
1031 
1032  SCROW nUnfilteredRows = aMarkRange.aEnd.Row() - aMarkRange.aStart.Row() + 1;
1033  ScRangeList aRangeList;
1034  if (bMarkIsFiltered)
1035  {
1036  ScViewUtil::UnmarkFiltered( aFilteredMark, pDoc);
1037  aFilteredMark.FillRangeListWithMarks( &aRangeList, false);
1038  nUnfilteredRows = 0;
1039  size_t ListSize = aRangeList.size();
1040  for ( size_t i = 0; i < ListSize; ++i )
1041  {
1042  ScRange & r = aRangeList[i];
1043  nUnfilteredRows += r.aEnd.Row() - r.aStart.Row() + 1;
1044  }
1045 #if 0
1046  /* This isn't needed but could be a desired restriction. */
1047  // For filtered, destination rows have to be an exact multiple of
1048  // source rows. Note that nDestSizeY is size-1 (difference), so
1049  // nDestSizeY==0 fits always.
1050  if ((nUnfilteredRows % (nDestSizeY+1)) != 0)
1051  {
1052  /* FIXME: this should be a more descriptive error message then. */
1053  ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
1054  return false;
1055  }
1056 #endif
1057  }
1058 
1059  // Also for a filtered selection the area is used, for undo et al.
1060  if ( aFilteredMark.IsMarked() || bMarkIsFiltered )
1061  {
1062  aMarkRange.GetVars( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
1063  SCCOL nBlockAddX = nEndCol-nStartCol;
1064  SCROW nBlockAddY = nEndRow-nStartRow;
1065 
1066  // request, if the selection is greater than one row/column, but smaller
1067  // as the Clipboard (then inserting is done beyond the selection)
1068 
1069  // ClipSize is not size, but difference
1070  if ( ( nBlockAddX != 0 && nBlockAddX < nDestSizeX ) ||
1071  ( nBlockAddY != 0 && nBlockAddY < nDestSizeY ) ||
1072  ( bMarkIsFiltered && nUnfilteredRows < nDestSizeY+1 ) )
1073  {
1074  ScWaitCursorOff aWaitOff( GetFrameWin() );
1075  OUString aMessage = ScResId( STR_PASTE_BIGGER );
1076 
1077  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetViewData().GetDialogParent(),
1078  VclMessageType::Question, VclButtonsType::YesNo,
1079  aMessage));
1080  xQueryBox->set_default_response(RET_NO);
1081  if (xQueryBox->run() != RET_YES)
1082  {
1083  return false;
1084  }
1085  }
1086 
1087  if (nBlockAddX <= nDestSizeX)
1088  nEndCol = nStartCol + nDestSizeX;
1089 
1090  if (nBlockAddY <= nDestSizeY)
1091  {
1092  nEndRow = nStartRow + nDestSizeY;
1093  if (bMarkIsFiltered || nEndRow > aMarkRange.aEnd.Row())
1094  {
1095  // Same as above if nothing was marked: re-fit selection to
1096  // unfiltered rows. Extending the selection actually may
1097  // introduce filtered rows where there weren't any before, so
1098  // we also need to test for that.
1099  aMarkRange = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
1100  if (bMarkIsFiltered || ScViewUtil::HasFiltered( aMarkRange, pDoc))
1101  {
1102  bMarkIsFiltered = true;
1103  // Worst case: all rows up to the end of the sheet are filtered.
1104  if (!ScViewUtil::FitToUnfilteredRows( aMarkRange, pDoc, nDestSizeY+1))
1105  {
1106  ErrorMessage(STR_PASTE_FULL);
1107  return false;
1108  }
1109  }
1110  aMarkRange.GetVars( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab);
1111  aFilteredMark.SetMarkArea( aMarkRange);
1112  if (bMarkIsFiltered)
1113  {
1114  ScViewUtil::UnmarkFiltered( aFilteredMark, pDoc);
1115  aFilteredMark.FillRangeListWithMarks( &aRangeList, true);
1116  }
1117  }
1118  }
1119  }
1120  else
1121  {
1122  nStartCol = GetViewData().GetCurX();
1123  nStartRow = GetViewData().GetCurY();
1124  nStartTab = GetViewData().GetTabNo();
1125  nEndCol = nStartCol + nDestSizeX;
1126  nEndRow = nStartRow + nDestSizeY;
1127  nEndTab = nStartTab;
1128  }
1129 
1130  bool bOffLimits = !pDoc->ValidCol(nEndCol) || !pDoc->ValidRow(nEndRow);
1131 
1132  // target-range, as displayed:
1133  ScRange aUserRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab );
1134 
1135  // should lines be inserted?
1136  // ( too large nEndCol/nEndRow are detected below)
1137  bool bInsertCells = ( eMoveMode != INS_NONE && !bOffLimits );
1138  if ( bInsertCells )
1139  {
1140  // Instead of EnterListAction, the paste undo action is merged into the
1141  // insert action, so Repeat can insert the right cells
1142 
1143  MarkRange( aUserRange ); // set through CopyFromClip
1144 
1145  // CutMode is reset on insertion of cols/rows but needed again on cell move
1146  bool bCut = pClipDoc->IsCutMode();
1147  if (!InsertCells( eMoveMode, bRecord, true )) // is inserting possible?
1148  {
1149  return false;
1150  // #i21036# EnterListAction isn't used, and InsertCells doesn't insert
1151  // its undo action on failure, so no undo handling is needed here
1152  }
1153  if ( bCut )
1154  pClipDoc->SetCutMode( bCut );
1155  }
1156  else if (!bOffLimits)
1157  {
1158  bool bAskIfNotEmpty = bAllowDialogs &&
1159  ( nFlags & InsertDeleteFlags::CONTENTS ) &&
1160  nFunction == ScPasteFunc::NONE &&
1161  SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
1162  if ( bAskIfNotEmpty )
1163  {
1164  ScRangeList aTestRanges(aUserRange);
1165  if (!checkDestRangeForOverwrite(aTestRanges, pDoc, aFilteredMark, GetViewData().GetDialogParent()))
1166  return false;
1167  }
1168  }
1169 
1170  SCCOL nClipStartX; // enlarge clipboard-range
1171  SCROW nClipStartY;
1172  pClipDoc->GetClipStart( nClipStartX, nClipStartY );
1173  SCCOL nUndoEndCol = nClipStartX + nClipSizeX;
1174  SCROW nUndoEndRow = nClipStartY + nClipSizeY; // end of source area in clipboard document
1175  bool bClipOver = false;
1176  // #i68690# ExtendMerge for the clip doc must be called with the clipboard's sheet numbers.
1177  // The same end column/row can be used for all calls because the clip doc doesn't contain
1178  // content outside the clip area.
1179  for (SCTAB nClipTab=0; nClipTab < pClipDoc->GetTableCount(); nClipTab++)
1180  if ( pClipDoc->HasTable(nClipTab) )
1181  if ( pClipDoc->ExtendMerge( nClipStartX,nClipStartY, nUndoEndCol,nUndoEndRow, nClipTab ) )
1182  bClipOver = true;
1183  nUndoEndCol -= nClipStartX + nClipSizeX;
1184  nUndoEndRow -= nClipStartY + nClipSizeY; // now contains only the difference added by ExtendMerge
1185  nUndoEndCol = sal::static_int_cast<SCCOL>( nUndoEndCol + nEndCol );
1186  nUndoEndRow = sal::static_int_cast<SCROW>( nUndoEndRow + nEndRow ); // destination area, expanded for merged cells
1187 
1188  if (nUndoEndCol>pClipDoc->MaxCol() || nUndoEndRow>pClipDoc->MaxRow())
1189  {
1190  ErrorMessage(STR_PASTE_FULL);
1191  return false;
1192  }
1193 
1194  pDoc->ExtendMergeSel( nStartCol,nStartRow, nUndoEndCol,nUndoEndRow, aFilteredMark );
1195 
1196  // check cell-protection
1197 
1198  ScEditableTester aTester( pDoc, nStartTab, nStartCol,nStartRow, nUndoEndCol,nUndoEndRow );
1199  if (!aTester.IsEditable())
1200  {
1201  ErrorMessage(aTester.GetMessageId());
1202  return false;
1203  }
1204 
1207 
1208  ScDocFunc& rDocFunc = pDocSh->GetDocFunc();
1209  if ( bRecord )
1210  {
1211  OUString aUndo = ScResId( pClipDoc->IsCutMode() ? STR_UNDO_MOVE : STR_UNDO_COPY );
1212  pUndoMgr->EnterListAction( aUndo, aUndo, 0, GetViewData().GetViewShell()->GetViewShellId() );
1213  }
1214 
1215  if (bClipOver)
1216  if (lcl_SelHasAttrib( pDoc, nStartCol,nStartRow, nUndoEndCol,nUndoEndRow, aFilteredMark, HasAttrFlags::Overlapped ))
1217  { // "Cell merge not possible if cells already merged"
1218  ScDocAttrIterator aIter( pDoc, nStartTab, nStartCol, nStartRow, nUndoEndCol, nUndoEndRow );
1219  const ScPatternAttr* pPattern = nullptr;
1220  SCCOL nCol = -1;
1221  SCROW nRow1 = -1;
1222  SCROW nRow2 = -1;
1223  while ( ( pPattern = aIter.GetNext( nCol, nRow1, nRow2 ) ) != nullptr )
1224  {
1225  const ScMergeAttr& rMergeFlag = pPattern->GetItem(ATTR_MERGE);
1226  const ScMergeFlagAttr& rMergeFlagAttr = pPattern->GetItem(ATTR_MERGE_FLAG);
1227  if (rMergeFlag.IsMerged() || rMergeFlagAttr.IsOverlapped())
1228  {
1229  ScRange aRange(nCol, nRow1, nStartTab);
1230  pDoc->ExtendOverlapped(aRange);
1231  pDoc->ExtendMerge(aRange, true);
1232  rDocFunc.UnmergeCells(aRange, bRecord, nullptr /*TODO: should pass combined UndoDoc if bRecord*/);
1233  }
1234  }
1235  }
1236 
1237  if ( !bCutMode )
1238  {
1239  ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1240  if ( pChangeTrack )
1241  pChangeTrack->ResetLastCut(); // no more cut-mode
1242  }
1243 
1244  bool bColInfo = ( nStartRow==0 && nEndRow==pDoc->MaxRow() );
1245  bool bRowInfo = ( nStartCol==0 && nEndCol==pDoc->MaxCol() );
1246 
1247  ScDocumentUniquePtr pUndoDoc;
1248  std::unique_ptr<ScDocument> pRefUndoDoc;
1249  std::unique_ptr<ScRefUndoData> pUndoData;
1250 
1251  if ( bRecord )
1252  {
1253  pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
1254  pUndoDoc->InitUndoSelected( pDoc, aFilteredMark, bColInfo, bRowInfo );
1255 
1256  // all sheets - CopyToDocument skips those that don't exist in pUndoDoc
1257  SCTAB nTabCount = pDoc->GetTableCount();
1258  pDoc->CopyToDocument( nStartCol, nStartRow, 0, nUndoEndCol, nUndoEndRow, nTabCount-1,
1259  nUndoFlags, false, *pUndoDoc );
1260 
1261  if ( bCutMode )
1262  {
1263  pRefUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
1264  pRefUndoDoc->InitUndo( pDoc, 0, nTabCount-1 );
1265 
1266  pUndoData.reset(new ScRefUndoData( pDoc ));
1267  }
1268  }
1269 
1270  sal_uInt16 nExtFlags = 0;
1271  pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
1272  nEndCol, nEndRow, nEndTab ); // content before the change
1273 
1274  if (GetViewData().IsActive())
1275  {
1276  DoneBlockMode();
1277  InitOwnBlockMode();
1278  }
1279  rMark.SetMarkArea( aUserRange );
1280  MarkDataChanged();
1281 
1282  // copy from clipboard
1283  // save original data in case of calculation
1284 
1285  ScDocumentUniquePtr pMixDoc;
1286  if (nFunction != ScPasteFunc::NONE)
1287  {
1288  bSkipEmpty = false;
1289  if ( nFlags & InsertDeleteFlags::CONTENTS )
1290  {
1291  pMixDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
1292  pMixDoc->InitUndo( pDoc, nStartTab, nEndTab );
1293  pDoc->CopyToDocument(nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab,
1294  InsertDeleteFlags::CONTENTS, false, *pMixDoc);
1295  }
1296  }
1297 
1298  /* Make draw layer and start drawing undo.
1299  - Needed before AdjustBlockHeight to track moved drawing objects.
1300  - Needed before pDoc->CopyFromClip to track inserted note caption objects.
1301  */
1302  if ( bPasteDraw )
1303  pDocSh->MakeDrawLayer();
1304  if ( bRecord )
1305  pDoc->BeginDrawUndo();
1306 
1307  InsertDeleteFlags nNoObjFlags = nFlags & ~InsertDeleteFlags::OBJECTS;
1308  if (!bAsLink)
1309  {
1310  // copy normally (original range)
1311  pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags,
1312  pRefUndoDoc.get(), pClipDoc, true, false, bIncludeFiltered,
1313  bSkipEmpty, (bMarkIsFiltered ? &aRangeList : nullptr) );
1314 
1315  // adapt refs manually in case of transpose
1316  if ( bTranspose && bCutMode && (nFlags & InsertDeleteFlags::CONTENTS) )
1317  pDoc->UpdateTranspose( aUserRange.aStart, pOrigClipDoc, aFilteredMark, pRefUndoDoc.get() );
1318  }
1319  else if (!bTranspose)
1320  {
1321  // copy with bAsLink=TRUE
1322  pDoc->CopyFromClip( aUserRange, aFilteredMark, nNoObjFlags, pRefUndoDoc.get(), pClipDoc,
1323  true, true, bIncludeFiltered, bSkipEmpty );
1324  }
1325  else
1326  {
1327  // copy all content (TransClipDoc contains only formula)
1328  pDoc->CopyFromClip( aUserRange, aFilteredMark, nContFlags, pRefUndoDoc.get(), pClipDoc );
1329  }
1330 
1331  // skipped rows and merged cells don't mix
1332  if ( !bIncludeFiltered && pClipDoc->HasClipFilteredRows() )
1333  rDocFunc.UnmergeCells( aUserRange, false, nullptr );
1334 
1335  pDoc->ExtendMergeSel( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, true ); // refresh
1336  // new range
1337 
1338  if ( pMixDoc ) // calculate with original data?
1339  {
1340  pDoc->MixDocument( aUserRange, nFunction, bSkipEmpty, pMixDoc.get() );
1341  }
1342  pMixDoc.reset();
1343 
1344  AdjustBlockHeight(); // update row heights before pasting objects
1345 
1346  ::std::vector< OUString > aExcludedChartNames;
1347  SdrPage* pPage = nullptr;
1348 
1349  if ( nFlags & InsertDeleteFlags::OBJECTS )
1350  {
1351  ScDrawView* pScDrawView = GetScDrawView();
1352  SdrModel* pModel = ( pScDrawView ? pScDrawView->GetModel() : nullptr );
1353  pPage = ( pModel ? pModel->GetPage( static_cast< sal_uInt16 >( nStartTab ) ) : nullptr );
1354  if ( pPage )
1355  {
1356  ScChartHelper::GetChartNames( aExcludedChartNames, pPage );
1357  }
1358 
1359  // Paste the drawing objects after the row heights have been updated.
1360 
1361  pDoc->CopyFromClip( aUserRange, aFilteredMark, InsertDeleteFlags::OBJECTS, pRefUndoDoc.get(), pClipDoc,
1362  true, false, bIncludeFiltered );
1363  }
1364 
1365  pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab,
1366  nEndCol, nEndRow, nEndTab ); // content after the change
1367 
1368  // if necessary, delete autofilter-heads
1369  if (bCutMode)
1370  if (pDoc->RefreshAutoFilter( nClipStartX,nClipStartY, nClipStartX+nClipSizeX,
1371  nClipStartY+nClipSizeY, nStartTab ))
1372  {
1373  pDocSh->PostPaint(
1374  ScRange(nClipStartX, nClipStartY, nStartTab, nClipStartX+nClipSizeX, nClipStartY, nStartTab),
1376  }
1377 
1379 
1380  if ( bRecord )
1381  {
1382  ScDocumentUniquePtr pRedoDoc;
1383  // copy redo data after appearance of the first undo
1384  // don't create Redo-Doc without RefUndoDoc
1385 
1386  if (pRefUndoDoc)
1387  {
1388  pRedoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
1389  pRedoDoc->InitUndo( pDoc, nStartTab, nEndTab, bColInfo, bRowInfo );
1390 
1391  // move adapted refs to Redo-Doc
1392 
1393  SCTAB nTabCount = pDoc->GetTableCount();
1394  pRedoDoc->AddUndoTab( 0, nTabCount-1 );
1395  pDoc->CopyUpdated( pRefUndoDoc.get(), pRedoDoc.get() );
1396 
1397  // move old refs to Undo-Doc
1398 
1399  // not charts?
1400  pUndoDoc->AddUndoTab( 0, nTabCount-1 );
1401  pRefUndoDoc->DeleteArea( nStartCol, nStartRow, nEndCol, nEndRow, aFilteredMark, InsertDeleteFlags::ALL );
1402  pRefUndoDoc->CopyToDocument( 0,0,0, pUndoDoc->MaxCol(), pUndoDoc->MaxRow(), nTabCount-1,
1403  InsertDeleteFlags::FORMULA, false, *pUndoDoc );
1404  pRefUndoDoc.reset();
1405  }
1406 
1407  // DeleteUnchanged for pUndoData is in ScUndoPaste ctor,
1408  // UndoData for redo is made during first undo
1409 
1410  ScUndoPasteOptions aOptions; // store options for repeat
1411  aOptions.nFunction = nFunction;
1412  aOptions.bSkipEmpty = bSkipEmpty;
1413  aOptions.bTranspose = bTranspose;
1414  aOptions.bAsLink = bAsLink;
1415  aOptions.eMoveMode = eMoveMode;
1416 
1417  std::unique_ptr<SfxUndoAction> pUndo(new ScUndoPaste(
1418  pDocSh, ScRange(nStartCol, nStartRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
1419  aFilteredMark, std::move(pUndoDoc), std::move(pRedoDoc), nFlags | nUndoFlags, std::move(pUndoData),
1420  false, &aOptions )); // false = Redo data not yet copied
1421 
1422  if ( bInsertCells )
1423  {
1424  // Merge the paste undo action into the insert action.
1425  // Use ScUndoWrapper so the ScUndoPaste pointer can be stored in the insert action.
1426 
1427  pUndoMgr->AddUndoAction( std::make_unique<ScUndoWrapper>( std::move(pUndo) ), true );
1428  }
1429  else
1430  pUndoMgr->AddUndoAction( std::move(pUndo) );
1431  pUndoMgr->LeaveListAction();
1432  }
1433 
1435  if (bColInfo)
1436  {
1437  nPaint |= PaintPartFlags::Top;
1438  nUndoEndCol = pDoc->MaxCol(); // just for drawing !
1439  }
1440  if (bRowInfo)
1441  {
1442  nPaint |= PaintPartFlags::Left;
1443  nUndoEndRow = pDoc->MaxRow(); // just for drawing !
1444  }
1445  pDocSh->PostPaint(
1446  ScRange(nStartCol, nStartRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
1447  nPaint, nExtFlags);
1448  // AdjustBlockHeight has already been called above
1449 
1450  ResetAutoSpell();
1451  aModificator.SetDocumentModified();
1452  PostPasteFromClip(aUserRange, rMark);
1453 
1454  if ( nFlags & InsertDeleteFlags::OBJECTS )
1455  {
1456  ScModelObj* pModelObj = comphelper::getUnoTunnelImplementation<ScModelObj>( pDocSh->GetModel() );
1457  if ( pPage && pModelObj )
1458  {
1459  bool bSameDoc = ( rClipParam.getSourceDocID() == pDoc->GetDocumentID() );
1460  const ScRangeListVector& rProtectedChartRangesVector( rClipParam.maProtectedChartRangesVector );
1461  ScChartHelper::CreateProtectedChartListenersAndNotify( pDoc, pPage, pModelObj, nStartTab,
1462  rProtectedChartRangesVector, aExcludedChartNames, bSameDoc );
1463  }
1464  }
1465  OUString aStartAddress = aMarkRange.aStart.GetColRowString();
1466  OUString aEndAddress = aMarkRange.aEnd.GetColRowString();
1467  collectUIInformation({{"RANGE", aStartAddress + ":" + aEndAddress}}, "PASTE");
1468  return true;
1469 }
1470 
1472  InsertDeleteFlags nFlags, ScDocument* pClipDoc, ScPasteFunc nFunction,
1473  bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs,
1474  InsCellCmd eMoveMode, InsertDeleteFlags nUndoFlags)
1475 {
1476  ScViewData& rViewData = GetViewData();
1477  ScDocument* pDoc = rViewData.GetDocument();
1478  ScDocShell* pDocSh = rViewData.GetDocShell();
1479  ScMarkData aMark(rViewData.GetMarkData());
1480  const ScAddress& rCurPos = rViewData.GetCurPos();
1481  ScClipParam& rClipParam = pClipDoc->GetClipParam();
1482  SCCOL nColSize = rClipParam.getPasteColSize();
1483  SCROW nRowSize = rClipParam.getPasteRowSize();
1484 
1485  if (bTranspose)
1486  {
1487  if (static_cast<SCROW>(rCurPos.Col()) + nRowSize-1 > static_cast<SCROW>(pClipDoc->MaxCol()))
1488  {
1489  ErrorMessage(STR_PASTE_FULL);
1490  return false;
1491  }
1492 
1494  pClipDoc->TransposeClip(pTransClip.get(), nFlags, bAsLink);
1495  pClipDoc = pTransClip.release();
1496  SCCOL nTempColSize = nColSize;
1497  nColSize = static_cast<SCCOL>(nRowSize);
1498  nRowSize = static_cast<SCROW>(nTempColSize);
1499  }
1500 
1501  if (!pDoc->ValidCol(rCurPos.Col()+nColSize-1) || !pDoc->ValidRow(rCurPos.Row()+nRowSize-1))
1502  {
1503  ErrorMessage(STR_PASTE_FULL);
1504  return false;
1505  }
1506 
1507  // Determine the first and last selected sheet numbers.
1508  SCTAB nTab1 = aMark.GetFirstSelected();
1509  SCTAB nTab2 = aMark.GetLastSelected();
1510 
1511  ScDocShellModificator aModificator(*pDocSh);
1512 
1513  // For multi-selection paste, we don't support cell duplication for larger
1514  // destination range. In case the destination is marked, we reset it to
1515  // the clip size.
1516  ScRange aMarkedRange(rCurPos.Col(), rCurPos.Row(), nTab1,
1517  rCurPos.Col()+nColSize-1, rCurPos.Row()+nRowSize-1, nTab2);
1518 
1519  // Extend the marked range to account for filtered rows in the destination
1520  // area.
1521  if (ScViewUtil::HasFiltered(aMarkedRange, pDoc))
1522  {
1523  if (!ScViewUtil::FitToUnfilteredRows(aMarkedRange, pDoc, nRowSize))
1524  return false;
1525  }
1526 
1527  bool bAskIfNotEmpty =
1528  bAllowDialogs && (nFlags & InsertDeleteFlags::CONTENTS) &&
1529  nFunction == ScPasteFunc::NONE && SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
1530 
1531  if (bAskIfNotEmpty)
1532  {
1533  ScRangeList aTestRanges(aMarkedRange);
1534  if (!checkDestRangeForOverwrite(aTestRanges, pDoc, aMark, GetViewData().GetDialogParent()))
1535  return false;
1536  }
1537 
1538  aMark.SetMarkArea(aMarkedRange);
1539  MarkRange(aMarkedRange);
1540 
1541  bool bInsertCells = (eMoveMode != INS_NONE);
1542  if (bInsertCells)
1543  {
1544  if (!InsertCells(eMoveMode, pDoc->IsUndoEnabled(), true))
1545  return false;
1546  }
1547 
1548  bool bRowInfo = ( aMarkedRange.aStart.Col()==0 && aMarkedRange.aEnd.Col()==pClipDoc->MaxCol() );
1549  ScDocumentUniquePtr pUndoDoc;
1550  if (pDoc->IsUndoEnabled())
1551  {
1552  pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
1553  pUndoDoc->InitUndoSelected(pDoc, aMark, false, bRowInfo);
1554  pDoc->CopyToDocument(aMarkedRange, nUndoFlags, false, *pUndoDoc, &aMark);
1555  }
1556 
1557  ScDocumentUniquePtr pMixDoc;
1558  if ( bSkipEmpty || nFunction != ScPasteFunc::NONE)
1559  {
1560  if ( nFlags & InsertDeleteFlags::CONTENTS )
1561  {
1562  pMixDoc.reset(new ScDocument(SCDOCMODE_UNDO));
1563  pMixDoc->InitUndoSelected(pDoc, aMark);
1564  pDoc->CopyToDocument(aMarkedRange, InsertDeleteFlags::CONTENTS, false, *pMixDoc, &aMark);
1565  }
1566  }
1567 
1568  /* Make draw layer and start drawing undo.
1569  - Needed before AdjustBlockHeight to track moved drawing objects.
1570  - Needed before pDoc->CopyFromClip to track inserted note caption objects.
1571  */
1572  if (nFlags & InsertDeleteFlags::OBJECTS)
1573  pDocSh->MakeDrawLayer();
1574  if (pDoc->IsUndoEnabled())
1575  pDoc->BeginDrawUndo();
1576 
1577  InsertDeleteFlags nNoObjFlags = nFlags & ~InsertDeleteFlags::OBJECTS;
1578  pDoc->CopyMultiRangeFromClip(rCurPos, aMark, nNoObjFlags, pClipDoc,
1579  true, bAsLink, false, bSkipEmpty);
1580 
1581  if (pMixDoc)
1582  pDoc->MixDocument(aMarkedRange, nFunction, bSkipEmpty, pMixDoc.get());
1583 
1584  AdjustBlockHeight(); // update row heights before pasting objects
1585 
1586  if (nFlags & InsertDeleteFlags::OBJECTS)
1587  {
1588  // Paste the drawing objects after the row heights have been updated.
1589  pDoc->CopyMultiRangeFromClip(rCurPos, aMark, InsertDeleteFlags::OBJECTS, pClipDoc,
1590  true, false, false, true);
1591  }
1592 
1593  if (bRowInfo)
1594  pDocSh->PostPaint(aMarkedRange.aStart.Col(), aMarkedRange.aStart.Row(), nTab1, pClipDoc->MaxCol(), pClipDoc->MaxRow(), nTab1, PaintPartFlags::Grid|PaintPartFlags::Left);
1595  else
1596  {
1597  ScRange aTmp = aMarkedRange;
1598  aTmp.aStart.SetTab(nTab1);
1599  aTmp.aEnd.SetTab(nTab1);
1600  pDocSh->PostPaint(aTmp, PaintPartFlags::Grid);
1601  }
1602 
1603  if (pDoc->IsUndoEnabled())
1604  {
1605  SfxUndoManager* pUndoMgr = pDocSh->GetUndoManager();
1606  OUString aUndo = ScResId(
1607  pClipDoc->IsCutMode() ? STR_UNDO_CUT : STR_UNDO_COPY);
1608  pUndoMgr->EnterListAction(aUndo, aUndo, 0, GetViewData().GetViewShell()->GetViewShellId());
1609 
1610  ScUndoPasteOptions aOptions; // store options for repeat
1611  aOptions.nFunction = nFunction;
1612  aOptions.bSkipEmpty = bSkipEmpty;
1613  aOptions.bTranspose = bTranspose;
1614  aOptions.bAsLink = bAsLink;
1615  aOptions.eMoveMode = eMoveMode;
1616 
1617  std::unique_ptr<ScUndoPaste> pUndo(new ScUndoPaste(pDocSh,
1618  aMarkedRange, aMark, std::move(pUndoDoc), nullptr, nFlags|nUndoFlags, nullptr, false, &aOptions));
1619 
1620  if (bInsertCells)
1621  pUndoMgr->AddUndoAction(std::make_unique<ScUndoWrapper>(std::move(pUndo)), true);
1622  else
1623  pUndoMgr->AddUndoAction(std::move(pUndo));
1624 
1625  pUndoMgr->LeaveListAction();
1626  }
1627 
1628  ResetAutoSpell();
1629  aModificator.SetDocumentModified();
1630  PostPasteFromClip(aMarkedRange, aMark);
1631  return true;
1632 }
1633 
1635  InsertDeleteFlags nFlags, ScDocument* pClipDoc, ScPasteFunc nFunction,
1636  bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs,
1637  InsCellCmd eMoveMode, InsertDeleteFlags nUndoFlags )
1638 {
1639  if (bTranspose)
1640  {
1641  // We don't allow transpose for this yet.
1642  ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
1643  return false;
1644  }
1645 
1646  if (eMoveMode != INS_NONE)
1647  {
1648  // We don't allow insertion mode either. Too complicated.
1649  ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
1650  return false;
1651  }
1652 
1653  ScViewData& rViewData = GetViewData();
1654  ScClipParam& rClipParam = pClipDoc->GetClipParam();
1655  if (rClipParam.mbCutMode)
1656  {
1657  // No cut and paste with this, please.
1658  ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
1659  return false;
1660  }
1661 
1662  const ScAddress& rCurPos = rViewData.GetCurPos();
1663  ScDocument* pDoc = rViewData.GetDocument();
1664 
1665  ScRange aSrcRange = rClipParam.getWholeRange();
1666  SCROW nRowSize = aSrcRange.aEnd.Row() - aSrcRange.aStart.Row() + 1;
1667  SCCOL nColSize = aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1;
1668 
1669  if (!pDoc->ValidCol(rCurPos.Col()+nColSize-1) || !pDoc->ValidRow(rCurPos.Row()+nRowSize-1))
1670  {
1671  ErrorMessage(STR_PASTE_FULL);
1672  return false;
1673  }
1674 
1675  ScMarkData aMark(rViewData.GetMarkData());
1676 
1677  ScRangeList aRanges;
1678  aMark.MarkToSimple();
1679  aMark.FillRangeListWithMarks(&aRanges, false);
1680  if (!ScClipUtil::CheckDestRanges(pDoc, nColSize, nRowSize, aMark, aRanges))
1681  {
1682  ErrorMessage(STR_MSSG_PASTEFROMCLIP_0);
1683  return false;
1684  }
1685 
1686  ScDocShell* pDocSh = rViewData.GetDocShell();
1687 
1688  ScDocShellModificator aModificator(*pDocSh);
1689 
1690  bool bAskIfNotEmpty =
1691  bAllowDialogs && (nFlags & InsertDeleteFlags::CONTENTS) &&
1692  nFunction == ScPasteFunc::NONE && SC_MOD()->GetInputOptions().GetReplaceCellsWarn();
1693 
1694  if (bAskIfNotEmpty)
1695  {
1696  if (!checkDestRangeForOverwrite(aRanges, pDoc, aMark, GetViewData().GetDialogParent()))
1697  return false;
1698  }
1699 
1700  ScDocumentUniquePtr pUndoDoc;
1701  if (pDoc->IsUndoEnabled())
1702  {
1703  pUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
1704  pUndoDoc->InitUndoSelected(pDoc, aMark);
1705  for (size_t i = 0, n = aRanges.size(); i < n; ++i)
1706  {
1707  pDoc->CopyToDocument(
1708  aRanges[i], nUndoFlags, false, *pUndoDoc, &aMark);
1709  }
1710  }
1711 
1712  ScDocumentUniquePtr pMixDoc;
1713  if (bSkipEmpty || nFunction != ScPasteFunc::NONE)
1714  {
1715  if (nFlags & InsertDeleteFlags::CONTENTS)
1716  {
1717  pMixDoc.reset(new ScDocument(SCDOCMODE_UNDO));
1718  pMixDoc->InitUndoSelected(pDoc, aMark);
1719  for (size_t i = 0, n = aRanges.size(); i < n; ++i)
1720  {
1721  pDoc->CopyToDocument(
1722  aRanges[i], InsertDeleteFlags::CONTENTS, false, *pMixDoc, &aMark);
1723  }
1724  }
1725  }
1726 
1727  if (nFlags & InsertDeleteFlags::OBJECTS)
1728  pDocSh->MakeDrawLayer();
1729  if (pDoc->IsUndoEnabled())
1730  pDoc->BeginDrawUndo();
1731 
1732  // First, paste everything but the drawing objects.
1733  for (size_t i = 0, n = aRanges.size(); i < n; ++i)
1734  {
1735  pDoc->CopyFromClip(
1736  aRanges[i], aMark, (nFlags & ~InsertDeleteFlags::OBJECTS), nullptr, pClipDoc,
1737  false, false, true, bSkipEmpty);
1738  }
1739 
1740  if (pMixDoc)
1741  {
1742  for (size_t i = 0, n = aRanges.size(); i < n; ++i)
1743  pDoc->MixDocument(aRanges[i], nFunction, bSkipEmpty, pMixDoc.get());
1744  }
1745 
1746  AdjustBlockHeight(); // update row heights before pasting objects
1747 
1748  // Then paste the objects.
1749  if (nFlags & InsertDeleteFlags::OBJECTS)
1750  {
1751  for (size_t i = 0, n = aRanges.size(); i < n; ++i)
1752  {
1753  pDoc->CopyFromClip(
1754  aRanges[i], aMark, InsertDeleteFlags::OBJECTS, nullptr, pClipDoc,
1755  false, false, true, bSkipEmpty);
1756  }
1757  }
1758 
1759  // Refresh the range that includes all pasted ranges. We only need to
1760  // refresh the current sheet.
1762  bool bRowInfo = (aSrcRange.aStart.Col()==0 && aSrcRange.aEnd.Col()==pClipDoc->MaxCol());
1763  if (bRowInfo)
1764  nPaint |= PaintPartFlags::Left;
1765  pDocSh->PostPaint(aRanges, nPaint);
1766 
1767  if (pDoc->IsUndoEnabled())
1768  {
1769  SfxUndoManager* pUndoMgr = pDocSh->GetUndoManager();
1770  OUString aUndo = ScResId(
1771  pClipDoc->IsCutMode() ? STR_UNDO_CUT : STR_UNDO_COPY);
1772  pUndoMgr->EnterListAction(aUndo, aUndo, 0, GetViewData().GetViewShell()->GetViewShellId());
1773 
1774  ScUndoPasteOptions aOptions; // store options for repeat
1775  aOptions.nFunction = nFunction;
1776  aOptions.bSkipEmpty = bSkipEmpty;
1777  aOptions.bTranspose = bTranspose;
1778  aOptions.bAsLink = bAsLink;
1779  aOptions.eMoveMode = eMoveMode;
1780 
1781 
1782  pUndoMgr->AddUndoAction(
1783  std::make_unique<ScUndoPaste>(
1784  pDocSh, aRanges, aMark, std::move(pUndoDoc), nullptr, nFlags|nUndoFlags, nullptr, false, &aOptions));
1785  pUndoMgr->LeaveListAction();
1786  }
1787 
1788  ResetAutoSpell();
1789  aModificator.SetDocumentModified();
1790  PostPasteFromClip(aRanges, aMark);
1791 
1792  return false;
1793 }
1794 
1795 void ScViewFunc::PostPasteFromClip(const ScRangeList& rPasteRanges, const ScMarkData& rMark)
1796 {
1797  ScViewData& rViewData = GetViewData();
1798  ScDocShell* pDocSh = rViewData.GetDocShell();
1799  pDocSh->UpdateOle(&rViewData);
1800 
1801  SelectionChanged(true);
1802 
1804  if (!pModelObj)
1805  return;
1806 
1807  ScRangeList aChangeRanges;
1808  for (size_t i = 0, n = rPasteRanges.size(); i < n; ++i)
1809  {
1810  const ScRange& r = rPasteRanges[i];
1811  for (const auto& rTab : rMark)
1812  {
1813  ScRange aChangeRange(r);
1814  aChangeRange.aStart.SetTab(rTab);
1815  aChangeRange.aEnd.SetTab(rTab);
1816  aChangeRanges.push_back(aChangeRange);
1817  }
1818  }
1819  HelperNotifyChanges::Notify(*pModelObj, aChangeRanges);
1820 }
1821 
1822 // D R A G A N D D R O P
1823 
1824 // inside the doc
1825 
1826 bool ScViewFunc::MoveBlockTo( const ScRange& rSource, const ScAddress& rDestPos,
1827  bool bCut )
1828 {
1829  ScDocShell* pDocSh = GetViewData().GetDocShell();
1830  HideAllCursors();
1831 
1832  bool bSuccess = true;
1833  SCTAB nDestTab = rDestPos.Tab();
1834  const ScMarkData& rMark = GetViewData().GetMarkData();
1835  if ( rSource.aStart.Tab() == nDestTab && rSource.aEnd.Tab() == nDestTab && rMark.GetSelectCount() > 1 )
1836  {
1837  // moving within one table and several tables selected -> apply to all selected tables
1838 
1839  OUString aUndo = ScResId( bCut ? STR_UNDO_MOVE : STR_UNDO_COPY );
1840  pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, GetViewData().GetViewShell()->GetViewShellId() );
1841 
1842  // collect ranges of consecutive selected tables
1843 
1844  ScRange aLocalSource = rSource;
1845  ScAddress aLocalDest = rDestPos;
1846  SCTAB nTabCount = pDocSh->GetDocument().GetTableCount();
1847  SCTAB nStartTab = 0;
1848  while ( nStartTab < nTabCount && bSuccess )
1849  {
1850  while ( nStartTab < nTabCount && !rMark.GetTableSelect(nStartTab) )
1851  ++nStartTab;
1852  if ( nStartTab < nTabCount )
1853  {
1854  SCTAB nEndTab = nStartTab;
1855  while ( nEndTab+1 < nTabCount && rMark.GetTableSelect(nEndTab+1) )
1856  ++nEndTab;
1857 
1858  aLocalSource.aStart.SetTab( nStartTab );
1859  aLocalSource.aEnd.SetTab( nEndTab );
1860  aLocalDest.SetTab( nStartTab );
1861 
1862  bSuccess = pDocSh->GetDocFunc().MoveBlock(
1863  aLocalSource, aLocalDest, bCut, true/*bRecord*/, true/*bPaint*/, true/*bApi*/ );
1864 
1865  nStartTab = nEndTab + 1;
1866  }
1867  }
1868 
1869  pDocSh->GetUndoManager()->LeaveListAction();
1870  }
1871  else
1872  {
1873  // move the block as specified
1874  bSuccess = pDocSh->GetDocFunc().MoveBlock(
1875  rSource, rDestPos, bCut, true/*bRecord*/, true/*bPaint*/, true/*bApi*/ );
1876  }
1877 
1878  ShowAllCursors();
1879  if (bSuccess)
1880  {
1881  // mark destination range
1882  ScAddress aDestEnd(
1883  rDestPos.Col() + rSource.aEnd.Col() - rSource.aStart.Col(),
1884  rDestPos.Row() + rSource.aEnd.Row() - rSource.aStart.Row(),
1885  nDestTab );
1886 
1887  bool bIncludeFiltered = bCut;
1888  if ( !bIncludeFiltered )
1889  {
1890  // find number of non-filtered rows
1891  SCROW nPastedCount = pDocSh->GetDocument().CountNonFilteredRows(
1892  rSource.aStart.Row(), rSource.aEnd.Row(), rSource.aStart.Tab());
1893 
1894  if ( nPastedCount == 0 )
1895  nPastedCount = 1;
1896  aDestEnd.SetRow( rDestPos.Row() + nPastedCount - 1 );
1897  }
1898 
1899  MarkRange( ScRange( rDestPos, aDestEnd ), false );
1900 
1901  pDocSh->UpdateOle(&GetViewData());
1902  SelectionChanged();
1903  ResetAutoSpell();
1904  }
1905  return bSuccess;
1906 }
1907 
1908 // link inside the doc
1909 
1910 bool ScViewFunc::LinkBlock( const ScRange& rSource, const ScAddress& rDestPos )
1911 {
1912  // check overlapping
1913 
1914  if ( rSource.aStart.Tab() == rDestPos.Tab() )
1915  {
1916  SCCOL nDestEndCol = rDestPos.Col() + ( rSource.aEnd.Col() - rSource.aStart.Col() );
1917  SCROW nDestEndRow = rDestPos.Row() + ( rSource.aEnd.Row() - rSource.aStart.Row() );
1918 
1919  if ( rSource.aStart.Col() <= nDestEndCol && rDestPos.Col() <= rSource.aEnd.Col() &&
1920  rSource.aStart.Row() <= nDestEndRow && rDestPos.Row() <= rSource.aEnd.Row() )
1921  {
1922  return false;
1923  }
1924  }
1925 
1926  // run with paste
1927 
1928  ScDocument* pDoc = GetViewData().GetDocument();
1930  pDoc->CopyTabToClip( rSource.aStart.Col(), rSource.aStart.Row(),
1931  rSource.aEnd.Col(), rSource.aEnd.Row(),
1932  rSource.aStart.Tab(), pClipDoc.get() );
1933 
1934  // mark destination area (set cursor, no marks)
1935 
1936  if ( GetViewData().GetTabNo() != rDestPos.Tab() )
1937  SetTabNo( rDestPos.Tab() );
1938 
1939  MoveCursorAbs( rDestPos.Col(), rDestPos.Row(), SC_FOLLOW_NONE, false, false );
1940 
1941  // Paste
1942 
1943  PasteFromClip( InsertDeleteFlags::ALL, pClipDoc.get(), ScPasteFunc::NONE, false, false, true ); // as a link
1944 
1945  return true;
1946 }
1947 
1949  SCROW nStartRow , SCCOL nStartCol ,
1950  SCROW nEndRow , SCCOL nEndCol ,
1951  std::vector<std::unique_ptr<ScDataFormFragment>>& rEdits,
1952  sal_uInt16 aColLength )
1953 {
1954  ScDocument* pDoc = GetViewData().GetDocument();
1955  ScDocShell* pDocSh = GetViewData().GetDocShell();
1956  ScMarkData& rMark = GetViewData().GetMarkData();
1957  ScDocShellModificator aModificator( *pDocSh );
1958  SfxUndoManager* pUndoMgr = pDocSh->GetUndoManager();
1959  if ( pDoc )
1960  {
1961  const bool bRecord( pDoc->IsUndoEnabled());
1962  ScDocumentUniquePtr pUndoDoc;
1963  ScDocumentUniquePtr pRedoDoc;
1964  std::unique_ptr<ScRefUndoData> pUndoData;
1965  SCTAB nTab = GetViewData().GetTabNo();
1966  SCTAB nStartTab = nTab;
1967  SCTAB nEndTab = nTab;
1968 
1969  {
1970  ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1971  if ( pChangeTrack )
1972  pChangeTrack->ResetLastCut(); // no more cut-mode
1973  }
1974  ScRange aUserRange( nStartCol, nCurrentRow, nStartTab, nEndCol, nCurrentRow, nEndTab );
1975  bool bColInfo = ( nStartRow==0 && nEndRow==pDoc->MaxRow() );
1976  bool bRowInfo = ( nStartCol==0 && nEndCol==pDoc->MaxCol() );
1977  SCCOL nUndoEndCol = nStartCol+aColLength-1;
1978  SCROW nUndoEndRow = nCurrentRow;
1979 
1980  if ( bRecord )
1981  {
1982  pUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
1983  pUndoDoc->InitUndoSelected( pDoc , rMark , bColInfo , bRowInfo );
1984  pDoc->CopyToDocument( aUserRange , InsertDeleteFlags::VALUE , false, *pUndoDoc );
1985  }
1986  sal_uInt16 nExtFlags = 0;
1987  pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nStartRow, nStartTab , nEndCol, nEndRow, nEndTab ); // content before the change
1988  pDoc->BeginDrawUndo();
1989 
1990  for(sal_uInt16 i = 0; i < aColLength; i++)
1991  {
1992  if (rEdits[i] != nullptr)
1993  {
1994  OUString aFieldName = rEdits[i]->m_xEdit->get_text();
1995  pDoc->SetString( nStartCol + i, nCurrentRow, nTab, aFieldName );
1996  }
1997  }
1998  pDocSh->UpdatePaintExt( nExtFlags, nStartCol, nCurrentRow, nStartTab, nEndCol, nCurrentRow, nEndTab ); // content after the change
1999  std::unique_ptr<SfxUndoAction> pUndo( new ScUndoDataForm( pDocSh,
2000  nStartCol, nCurrentRow, nStartTab,
2001  nUndoEndCol, nUndoEndRow, nEndTab, rMark,
2002  std::move(pUndoDoc), std::move(pRedoDoc),
2003  std::move(pUndoData) ) );
2004  pUndoMgr->AddUndoAction( std::make_unique<ScUndoWrapper>( std::move(pUndo) ), true );
2005 
2007  if (bColInfo)
2008  {
2009  nPaint |= PaintPartFlags::Top;
2010  nUndoEndCol = pDoc->MaxCol(); // just for drawing !
2011  }
2012  if (bRowInfo)
2013  {
2014  nPaint |= PaintPartFlags::Left;
2015  nUndoEndRow = pDoc->MaxRow(); // just for drawing !
2016  }
2017 
2018  pDocSh->PostPaint(
2019  ScRange(nStartCol, nCurrentRow, nStartTab, nUndoEndCol, nUndoEndRow, nEndTab),
2020  nPaint, nExtFlags);
2021  pDocSh->UpdateOle(&GetViewData());
2022  }
2023 }
2024 
2025 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC void UpdateTranspose(const ScAddress &rDestPos, ScDocument *pClipDoc, const ScMarkData &rMark, ScDocument *pUndoDoc)
Definition: documen3.cxx:1090
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3053
void BeginDrawUndo()
Definition: documen9.cxx:58
#define EXCHG_IN_ACTION_COPY
SCROW getPasteRowSize()
Same as the above method, but returns the row size of the compressed range.
Definition: clipparam.cxx:73
static ScDrawTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Definition: drwtrans.cxx:230
static const com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: transobj.cxx:922
OUString GetColRowString() const
Create a human-readable string representation of the cell address.
Definition: address.cxx:2492
bool RefreshAutoFilter(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: document.cxx:5675
void MarkToSimple()
Definition: markdata.cxx:237
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
void GetClipStart(SCCOL &nClipX, SCROW &nClipY)
Definition: document.cxx:3173
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScAddress aStart
Definition: address.hxx:500
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
SC_DLLPUBLIC bool CopyToClip(ScDocument *pClipDoc, bool bCut, bool bApi=false, bool bIncludeObjects=false, bool bStopEdit=true)
Definition: viewfun3.cxx:165
void SetCutMode(bool bCut)
Definition: document.cxx:2055
HasAttrFlags
Definition: global.hxx:193
bool PasteFromClipToMultiRanges(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction, bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs, InsCellCmd eMoveMode, InsertDeleteFlags nUndoFlags)
Definition: viewfun3.cxx:1634
static void FillProtectedChartRangesVector(ScRangeListVector &rRangesVector, const ScDocument *pDocument, const SdrPage *pPage)
Sheet / outlining (grouping) information.
SCROW Row() const
Definition: address.hxx:262
OUString GetTitle(sal_uInt16 nMaxLen=0) const
void MarkToMulti()
Definition: markdata.cxx:224
void ReadGraphic(SvStream &rIStream, Graphic &rGraphic)
void CopyFromClip(const ScRange &rDestRange, const ScMarkData &rMark, InsertDeleteFlags nInsFlag, ScDocument *pRefUndoDoc, ScDocument *pClipDoc, bool bResetCut=true, bool bAsLink=false, bool bIncludeFiltered=true, bool bSkipAttrForEmpty=false, const ScRangeList *pDestRanges=nullptr)
If pDestRanges is given it overrides rDestRange, rDestRange in this case is the overall encompassing ...
Definition: document.cxx:2801
static sal_uInt8 GetExchangeAction(const DataFlavorExVector &rDataFlavorExVector, SotExchangeDest nDestination, sal_uInt16 nSourceOptions, sal_uInt8 nUserAction, SotClipboardFormatId &rFormat, sal_uInt8 &rDefaultAction, SotClipboardFormatId nOnlyTestFormat=SotClipboardFormatId::NONE, const css::uno::Reference< css::datatransfer::XTransferable > *pxTransferable=nullptr, SotExchangeActionFlags *pActionFlags=nullptr)
SC_DLLPUBLIC void TransposeClip(ScDocument *pTransClip, InsertDeleteFlags nFlags, bool bAsLink)
Definition: document.cxx:2331
static SfxObjectShell * SetDrawClipDoc(bool bAnyOle)
Definition: transobj.cxx:815
SCROW GetCurY() const
Definition: viewdata.hxx:402
SdrModel * GetModel() const
Definition: drwtrans.hxx:79
bool IsOverlapped() const
Definition: attrib.hxx:102
Warning box for "Replace cell contents?".
Definition: warnbox.hxx:27
sal_Int64 n
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:387
ScRangeListVector maProtectedChartRangesVector
Definition: clipparam.hxx:38
void CopyMultiRangeFromClip(const ScAddress &rDestPos, const ScMarkData &rMark, InsertDeleteFlags nInsFlag, ScDocument *pClipDoc, bool bResetCut=true, bool bAsLink=false, bool bIncludeFiltered=true, bool bSkipAttrForEmpty=false)
Definition: document.cxx:3018
#define SO3_SW_CLASSID
static bool HasFiltered(const ScRange &rRange, const ScDocument *pDoc)
Definition: viewutil.cxx:272
void setSourceDocID(sal_uInt32 nVal)
Definition: clipparam.hxx:66
ScAddress aEnd
Definition: address.hxx:501
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
Direction meDirection
Definition: clipparam.hxx:35
bool CheckDestRanges(const ScDocument *pDoc, SCCOL nSrcCols, SCROW nSrcRows, const ScMarkData &rMark, const ScRangeList &rDest)
Definition: cliputil.cxx:96
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
Definition: tabvwshc.cxx:483
Stores options which are only relevant for clipboard documents.
Definition: clipoptions.hxx:19
css::uno::Reference< css::frame::XModel > GetModel() const
void SetClipOptions(std::unique_ptr< ScClipOptions > pClipOptions)
Definition: documen3.cxx:1991
void FillTransferableObjectDescriptor(TransferableObjectDescriptor &rDesc) const
bool HasFormat(SotClipboardFormatId nFormat) const
void GetClipArea(SCCOL &nClipX, SCROW &nClipY, bool bIncludeFiltered)
Definition: document.cxx:3121
SC_DLLPUBLIC bool HasAttrib(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, HasAttrFlags nMask) const
Definition: document.cxx:5182
constexpr TypedWhichId< ScMergeAttr > ATTR_MERGE(144)
SCCOL getPasteColSize()
Get the column size of a pasted range.
Definition: clipparam.cxx:43
Internal use only (d&d undo): do not delete caption objects of cell notes.
#define EXCHG_IN_ACTION_DEFAULT
void GetMarkArea(ScRange &rRange) const
Definition: markdata.cxx:112
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2805
RET_NO
static UITestLogger & getInstance()
void logEvent(const EventDescription &rDescription)
static void SetGlobalDrawPersist(SfxObjectShell *pPersist)
Definition: drwlayer.cxx:2335
RET_YES
SC_DLLPUBLIC void CutToClip()
Not used?
Definition: viewfun3.cxx:87
void PostPasteFromClip(const ScRangeList &rPasteRanges, const ScMarkData &rMark)
Definition: viewfun3.cxx:1795
void UpdateOle(const ScViewData *pViewData, bool bSnapSize=false)
Definition: docsh6.cxx:152
bool CopyToClipSingleRange(ScDocument *pClipDoc, const ScRangeList &rRanges, bool bCut, bool bIncludeObjects)
Definition: viewfun3.cxx:214
ScClipParam & GetClipParam()
Definition: document.cxx:2552
void UpdatePaintExt(sal_uInt16 &rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab)
Definition: docsh3.cxx:226
bool PasteOnDrawObjectLinked(const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, SdrObject &rHitObj)
Definition: viewfun3.cxx:773
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:873
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
#define EXCHG_INOUT_ACTION_NONE
SC_DLLPUBLIC void CopyUpdated(ScDocument *pPosDoc, ScDocument *pDestDoc)
From this document this method copies the cells of positions at which there are also cells in pPosDoc...
Definition: documen3.cxx:781
SCTAB GetSelectCount() const
Definition: markdata.cxx:195
bool IsMultiMarked() const
Definition: markdata.hxx:83
void CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, InsertDeleteFlags nFlags, bool bMarked, ScDocument &rDestDoc, const ScMarkData *pMarks=nullptr, bool bColRowFlags=true)
Definition: document.cxx:2076
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1144
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:191
SCTAB Tab() const
Definition: address.hxx:271
bool mbCutMode
Definition: clipparam.hxx:36
ScDocument * GetDocument() const
Definition: viewdata.cxx:859
#define EXCHG_OUT_ACTION_INSERT_GRAPH
SotClipboardFormatId
ScDocument * GetDocument() const
Definition: transobj.hxx:81
SC_DLLPUBLIC void PasteFromSystem()
Definition: viewfun3.cxx:483
void SetCol(SCCOL nColP)
Definition: address.hxx:279
ScDrawLayer * MakeDrawLayer()
Definition: docsh2.cxx:166
sal_Int32 nHandle
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2392
void CopyTabToClip(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, ScDocument *pClipDoc)
Definition: document.cxx:2277
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
Definition: patattr.hxx:70
bool empty() const
Definition: rangelst.hxx:89
const char * GetMessageId() const
Definition: editable.cxx:152
ScPasteFunc
Definition: global.hxx:189
void SetMarkArea(const ScRange &rRange)
Definition: markdata.cxx:97
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: document.cxx:3366
static void GetChartNames(::std::vector< OUString > &rChartNames, const SdrPage *pPage)
bool HasOLEObjectsInArea(const ScRange &rRange, const ScMarkData *pTabMark=nullptr)
Definition: documen9.cxx:274
void SetTab(SCTAB nTabP)
Definition: address.hxx:283
bool HasClipFilteredRows()
Definition: document.cxx:3190
#define SFX_TITLE_FULLNAME
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1059
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:872
T * get() const
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
sal_uInt32 getSourceDocID() const
Definition: clipparam.hxx:65
SCROW CountNonFilteredRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:4550
static void SetClipDocName(const OUString &rNew)
Definition: global.cxx:490
bool IsMarked() const
Definition: markdata.hxx:82
int i
Point GetScrPos(SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich, bool bAllowNeg=false, SCTAB nForTab=-1) const
Definition: viewdata.cxx:2319
bool LinkBlock(const ScRange &rSource, const ScAddress &rDestPos)
Definition: viewfun3.cxx:1910
void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges, const OUString &rType=OUString("cell-change"), const css::uno::Sequence< css::beans::PropertyValue > &rProperties=css::uno::Sequence< css::beans::PropertyValue >())
Definition: docsh.hxx:477
ScMarkType
States GetSimpleArea() returns for the underlying selection marks, so the caller can react if the res...
Definition: viewdata.hxx:61
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2613
css::uno::Reference< css::datatransfer::XTransferable > GetXTransferable() const
sal_Int16 SCCOL
Definition: types.hxx:22
void DeleteSelection(InsertDeleteFlags nDelFlag, const ScMarkData &rMark, bool bBroadcast=true)
Definition: document.cxx:5935
InsertDeleteFlags
Definition: global.hxx:158
bool ValidCol(SCCOL nCol) const
Definition: document.hxx:875
static tools::SvRef< ScDocShell > xDrawClipDocShellRef
Definition: global.hxx:583
#define SC_MOD()
Definition: scmod.hxx:253
const SdrPage * GetPage(sal_uInt16 nPgNum) const
size_t size() const
Definition: rangelst.hxx:90
static OUString CreateShellID(const SfxObjectShell *pShell)
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
Definition: viewdata.cxx:1173
bool IsCutMode()
Definition: document.cxx:2065
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3069
ScTransferObj * CopyToTransferable()
Definition: viewfun3.cxx:429
ScPasteFunc nFunction
Definition: undoblk.hxx:166
bool PasteMultiRangesFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction, bool bSkipEmpty, bool bTranspose, bool bAsLink, bool bAllowDialogs, InsCellCmd eMoveMode, InsertDeleteFlags nUndoFlags)
Definition: viewfun3.cxx:1471
bool MoveBlockTo(const ScRange &rSource, const ScAddress &rDestPos, bool bCut)
Definition: viewfun3.cxx:1826
iterator end()
Definition: markdata.cxx:954
bool IsEditable() const
Definition: editable.hxx:84
bool IsBlockEmpty(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bIgnoreNotes=false) const
Definition: document.cxx:5299
void GetVars(SCCOL &nCol1, SCROW &nRow1, SCTAB &nTab1, SCCOL &nCol2, SCROW &nRow2, SCTAB &nTab2) const
Definition: address.hxx:693
void ResetLastCut()
Definition: chgtrack.hxx:1059
bool HasSelectedBlockMatrixFragment(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const ScMarkData &rMark) const
Definition: document.cxx:5410
ScRangeList maRanges
Definition: clipparam.hxx:34
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:99
SC_DLLPUBLIC bool ExtendMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, SCTAB nTab, bool bRefresh=false)
Definition: document.cxx:5571
SC_DLLPUBLIC bool PasteFromClip(InsertDeleteFlags nFlags, ScDocument *pClipDoc, ScPasteFunc nFunction=ScPasteFunc::NONE, bool bSkipEmpty=false, bool bTranspose=false, bool bAsLink=false, InsCellCmd eMoveMode=INS_NONE, InsertDeleteFlags nUndoExtraFlags=InsertDeleteFlags::NONE, bool bAllowDialogs=false)
Definition: viewfun3.cxx:876
sal_uInt32 GetDocumentID() const
an ID unique to each document instance
Definition: documen2.cxx:252
SCCOL Col() const
Definition: address.hxx:267
size_t LeaveListAction()
ScAddress GetCurPos() const
Definition: viewdata.cxx:4023
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotStorageStream > &rStreamRef)
bool CopyToClipMultiRange(const ScDocument *pClipDoc, const ScRangeList &rRanges, bool bCut, bool bApi, bool bIncludeObjects)
Definition: viewfun3.cxx:305
Point PixelToLogic(const Point &rDevicePt) const
bool IsMerged() const
Definition: attrib.hxx:72
ScModelObj * getMustPropagateChangesModel(const ScDocShell &rDocShell)
Definition: docsh.hxx:469
::std::vector< ScRangeList > ScRangeListVector
Definition: charthelper.hxx:30
bool UnmergeCells(const ScRange &rRange, bool bRecord, ScUndoRemoveMerge *pUndoRemoveMerge)
Definition: docfunc.cxx:5043
bool GetGDIMetaFile(SotClipboardFormatId nFormat, GDIMetaFile &rMtf, size_t nMaxActions=0)
constexpr TypedWhichId< ScMergeFlagAttr > ATTR_MERGE_FLAG(145)
iterator begin()
Definition: markdata.cxx:949
sal_Int32 SCROW
Definition: types.hxx:18
ScRange getWholeRange() const
Return a single range that encompasses all individual ranges.
Definition: clipparam.cxx:103
bool ValidRow(SCROW nRow) const
Definition: document.hxx:876
const OUString & GetShellID() const
Definition: drwtrans.cxx:641
static bool lcl_SelHasAttrib(const ScDocument *pDoc, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, const ScMarkData &rTabSelection, HasAttrFlags nMask)
Definition: viewfun3.cxx:832
unsigned char sal_uInt8
void ExtendMergeSel(SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW &rEndRow, const ScMarkData &rMark, bool bRefresh=false)
Definition: document.cxx:5543
#define EXCHG_OUT_ACTION_INSERT_BITMAP
static void CreateProtectedChartListenersAndNotify(ScDocument *pDoc, const SdrPage *pPage, ScModelObj *pModelObj, SCTAB nTab, const ScRangeListVector &rRangesVector, const ::std::vector< OUString > &rExcludedChartNames, bool bSameDoc=true)
static bool FitToUnfilteredRows(ScRange &rRange, const ScDocument *pDoc, size_t nRows)
Fit a range to cover nRows number of unfiltered rows.
Definition: viewutil.cxx:258
void PasteFromTransferable(const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable)
Definition: viewfun3.cxx:620
bool DoInitNew(SfxMedium *pMedium=nullptr)
InsCellCmd
Definition: global.hxx:299
bool GetBitmapEx(SotClipboardFormatId nFormat, BitmapEx &rBmp)
SdrObject * ApplyGraphicToObject(SdrObject &rHitObject, const Graphic &rGraphic, const OUString &rBeginUndoText, const OUString &rFile, const OUString &rFilter)
Definition: drawview.cxx:1113
static void UnmarkFiltered(ScMarkData &rMark, const ScDocument *pDoc)
Definition: viewutil.cxx:223
static SC_DLLPUBLIC ScTransferObj * GetOwnClipboard(const css::uno::Reference< css::datatransfer::XTransferable2 > &)
Definition: transobj.cxx:196
const INetURLObject & GetURLObject() const
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
SC_DLLPUBLIC void DataFormPutData(SCROW nCurrentRow, SCROW nStartRow, SCCOL nStartCol, SCROW nEndRow, SCCOL nEndCol, std::vector< std::unique_ptr< ScDataFormFragment >> &rEdits, sal_uInt16 aColLength)
Definition: viewfun3.cxx:1948
void * p
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: drwtrans.cxx:746
#define EXCHG_OUT_ACTION_INSERT_SVXB
const ScPatternAttr * GetNext(SCCOL &rCol, SCROW &rRow1, SCROW &rRow2)
Definition: dociter.cxx:2653
#define SO3_SWWEB_CLASSID
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
void PasteDraw()
Definition: viewfun3.cxx:466
OUString GetURLNoPass(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void SetDocumentModified()
Definition: docsh.cxx:3158
void MixDocument(const ScRange &rRange, ScPasteFunc nFunction, bool bSkipEmpty, ScDocument *pSrcDoc)
Definition: document.cxx:3211
ScRange & front()
Definition: rangelst.hxx:93
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1058
bool GetTransferableObjectDescriptor(SotClipboardFormatId nFormat, TransferableObjectDescriptor &rDesc)
bool IsUndoEnabled() const
Definition: document.hxx:1531
InsCellCmd eMoveMode
Definition: undoblk.hxx:170
#define EXCHG_OUT_ACTION_INSERT_GDIMETAFILE
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:218
bool MoveBlock(const ScRange &rSource, const ScAddress &rDestPos, bool bCut, bool bRecord, bool bPaint, bool bApi)
Definition: docfunc.cxx:2832
void DeleteObjectsInSelection(const ScMarkData &rMark)
Definition: documen9.cxx:266
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:184
std::map< OUString, OUString > aParameters
PaintPartFlags
Definition: global.hxx:119
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Definition: clipparam.hxx:30
SC_DLLPUBLIC void ExtendOverlapped(SCCOL &rStartCol, SCROW &rStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5481
const css::uno::Reference< css::datatransfer::XTransferable > & GetTransferable() const
virtual sal_Int64 SAL_CALL getSomething(const com::sun::star::uno::Sequence< sal_Int8 > &rId) override
Definition: transobj.cxx:927
SdrModel * GetModel() const
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:450
sal_Int16 SCTAB
Definition: types.hxx:23
void CopyToClip(const ScClipParam &rClipParam, ScDocument *pClipDoc, const ScMarkData *pMarks, bool bKeepScenarioFlags, bool bIncludeObjects)
Definition: document.cxx:2175
SCCOL GetCurX() const
Definition: viewdata.hxx:401
bool isMultiRange() const
Definition: clipparam.cxx:38
const DataFlavorExVector & GetDataFlavorExVector() const
SfxMedium * GetMedium() const