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