LibreOffice Module sc (master) 1
docfuncutil.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 <docfuncutil.hxx>
21#include <document.hxx>
22#include <undobase.hxx>
23#include <global.hxx>
24#include <undoblk.hxx>
25#include <columnspanset.hxx>
26
27#include <memory>
28#include <utility>
29
30namespace sc {
31
32bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark )
33{
34 SCTAB nTabCount = rDoc.GetTableCount();
35 for (const auto& rTab : rMark)
36 {
37 if (rTab >= nTabCount)
38 break;
39
40 if (rDoc.IsTabProtected(rTab))
41 return true;
42 }
43
44 return false;
45}
46
48 ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange,
49 InsertDeleteFlags nFlags, bool bOnlyMarked )
50{
52 SCTAB nTab = rRange.aStart.Tab();
53 pUndoDoc->InitUndo(rDoc, nTab, nTab);
54 SCTAB nTabCount = rDoc.GetTableCount();
55 for (const auto& rTab : rMark)
56 if (rTab != nTab)
57 pUndoDoc->AddUndoTab( rTab, rTab );
58 ScRange aCopyRange = rRange;
59 aCopyRange.aStart.SetTab(0);
60 aCopyRange.aEnd.SetTab(nTabCount-1);
61
62 // in case of "Format/Standard" copy all attributes, because CopyToDocument
63 // with InsertDeleteFlags::HARDATTR only is too time-consuming:
64 InsertDeleteFlags nUndoDocFlags = nFlags;
65 if (nFlags & InsertDeleteFlags::ATTRIB)
66 nUndoDocFlags |= InsertDeleteFlags::ATTRIB;
67 if (nFlags & InsertDeleteFlags::EDITATTR) // Edit-Engine-Attribute
68 nUndoDocFlags |= InsertDeleteFlags::STRING; // -> cells will be changed
69 if (nFlags & InsertDeleteFlags::NOTE)
70 nUndoDocFlags |= InsertDeleteFlags::CONTENTS; // copy all cells with their notes
71 // do not copy note captions to undo document
72 nUndoDocFlags |= InsertDeleteFlags::NOCAPTIONS;
73 rDoc.CopyToDocument(aCopyRange, nUndoDocFlags, bOnlyMarked, *pUndoDoc, &rMark);
74
75 return pUndoDoc;
76}
77
79 SfxUndoManager* pUndoMgr, ScDocShell* pDocSh, const ScMarkData& rMark,
80 const ScRange& rRange, ScDocumentUniquePtr&& pUndoDoc, InsertDeleteFlags nFlags,
81 const std::shared_ptr<ScSimpleUndo::DataSpansType>& pSpans,
82 bool bMulti, bool bDrawUndo )
83{
84 std::unique_ptr<ScUndoDeleteContents> pUndo(
86 pDocSh, rMark, rRange, std::move(pUndoDoc), bMulti, nFlags, bDrawUndo));
87 pUndo->SetDataSpans(pSpans);
88
89 pUndoMgr->AddUndoAction(std::move(pUndo));
90}
91
92std::shared_ptr<ScSimpleUndo::DataSpansType> DocFuncUtil::getNonEmptyCellSpans(
93 const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange )
94{
95 auto pDataSpans = std::make_shared<ScSimpleUndo::DataSpansType>();
96 for (const SCTAB nTab : rMark)
97 {
98 SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
99 SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
100
101 std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r =
102 pDataSpans->insert(std::make_pair(nTab, std::make_unique<sc::ColumnSpanSet>()));
103
104 if (r.second)
105 {
106 sc::ColumnSpanSet *const pSet = r.first->second.get();
107 pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true);
108 }
109 }
110
111 return pDataSpans;
112}
113
114}
115
116/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SCCOL Col() const
Definition: address.hxx:279
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1919
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:2072
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:317
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
void scan(const ScDocument &rDoc, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bVal)
Scan specified range in a specified sheet and mark all non-empty cells with specified boolean value.
static void addDeleteContentsUndo(SfxUndoManager *pUndoMgr, ScDocShell *pDocSh, const ScMarkData &rMark, const ScRange &rRange, ScDocumentUniquePtr &&pUndoDoc, InsertDeleteFlags nFlags, const std::shared_ptr< ScSimpleUndo::DataSpansType > &pSpans, bool bMulti, bool bDrawUndo)
Definition: docfuncutil.cxx:78
static ScDocumentUniquePtr createDeleteContentsUndoDoc(ScDocument &rDoc, const ScMarkData &rMark, const ScRange &rRange, InsertDeleteFlags nFlags, bool bOnlyMarked)
Definition: docfuncutil.cxx:47
static std::shared_ptr< ScSimpleUndo::DataSpansType > getNonEmptyCellSpans(const ScDocument &rDoc, const ScMarkData &rMark, const ScRange &rRange)
Definition: docfuncutil.cxx:92
static bool hasProtectedTab(const ScDocument &rDoc, const ScMarkData &rMark)
Definition: docfuncutil.cxx:32
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2717
@ SCDOCMODE_UNDO
Definition: document.hxx:257
InsertDeleteFlags
Definition: global.hxx:149
@ NOTE
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
@ NOCAPTIONS
Sparklines in a cell.
@ EDITATTR
Drawing objects.
@ STRING
Dates, times, datetime values.
@ ATTRIB
Internal use only (d&d undo): do not delete caption objects of cell notes.
CAUTION! The following defines must be in the same namespace as the respective type.
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17