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 
30 namespace sc {
31 
32 bool 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 
92 std::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: */
ScAddress aStart
Definition: address.hxx:500
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1890
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
Sheet / outlining (grouping) information.
SCROW Row() const
Definition: address.hxx:262
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
ScAddress aEnd
Definition: address.hxx:501
Internal use only (d&d undo): do not delete caption objects of cell notes.
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
void CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, InsertDeleteFlags nFlags, bool bMarked, ScDocument &rDestDoc, const ScMarkData *pMarks=nullptr, bool bColRowFlags=true)
Definition: document.cxx:2076
SCTAB Tab() const
Definition: address.hxx:271
void SetTab(SCTAB nTabP)
Definition: address.hxx:283
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2613
sal_Int16 SCCOL
Definition: types.hxx:22
InsertDeleteFlags
Definition: global.hxx:159
static bool hasProtectedTab(const ScDocument &rDoc, const ScMarkData &rMark)
Definition: docfuncutil.cxx:32
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
static std::shared_ptr< ScSimpleUndo::DataSpansType > getNonEmptyCellSpans(const ScDocument &rDoc, const ScMarkData &rMark, const ScRange &rRange)
Definition: docfuncutil.cxx:92
SCCOL Col() const
Definition: address.hxx:267
sal_Int32 SCROW
Definition: types.hxx:18
Dates, times, datetime values.
static ScDocumentUniquePtr createDeleteContentsUndoDoc(ScDocument &rDoc, const ScMarkData &rMark, const ScRange &rRange, InsertDeleteFlags nFlags, bool bOnlyMarked)
Definition: docfuncutil.cxx:47
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
sal_Int16 SCTAB
Definition: types.hxx:23