tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / docshell / docfuncutil.cxx
blobce1a25d6187833a0d3ef732c486fc66900c82b05
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <docfuncutil.hxx>
21 #include <document.hxx>
22 #include <undobase.hxx>
23 #include <global.hxx>
24 #include <undoblk.hxx>
25 #include <columnspanset.hxx>
27 #include <memory>
28 #include <utility>
30 namespace sc {
32 bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark )
34 SCTAB nTabCount = rDoc.GetTableCount();
35 for (const auto& rTab : rMark)
37 if (rTab >= nTabCount)
38 break;
40 if (rDoc.IsTabProtected(rTab))
41 return true;
44 return false;
47 ScDocumentUniquePtr DocFuncUtil::createDeleteContentsUndoDoc(
48 ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange,
49 InsertDeleteFlags nFlags, bool bOnlyMarked )
51 ScDocumentUniquePtr pUndoDoc(new ScDocument(SCDOCMODE_UNDO));
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);
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);
75 return pUndoDoc;
78 void DocFuncUtil::addDeleteContentsUndo(
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 )
84 std::unique_ptr<ScUndoDeleteContents> pUndo(
85 new ScUndoDeleteContents(
86 pDocSh, rMark, rRange, std::move(pUndoDoc), bMulti, nFlags, bDrawUndo));
87 pUndo->SetDataSpans(pSpans);
89 pUndoMgr->AddUndoAction(std::move(pUndo));
92 std::shared_ptr<ScSimpleUndo::DataSpansType> DocFuncUtil::getNonEmptyCellSpans(
93 const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange )
95 auto pDataSpans = std::make_shared<ScSimpleUndo::DataSpansType>();
96 for (const SCTAB nTab : rMark)
98 SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
99 SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
101 std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r =
102 pDataSpans->insert(std::make_pair(nTab, std::make_unique<sc::ColumnSpanSet>()));
104 if (r.second)
106 sc::ColumnSpanSet *const pSet = r.first->second.get();
107 pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true);
111 return pDataSpans;
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */