fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / docshell / docfuncutil.cxx
blob1adb1355d55612d9e33046f46d9f2bad59e9931b
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 <markdata.hxx>
23 #include <undobase.hxx>
24 #include <global.hxx>
25 #include <undoblk.hxx>
27 #include <memory>
29 namespace sc {
31 bool DocFuncUtil::hasProtectedTab( const ScDocument& rDoc, const ScMarkData& rMark )
33 SCTAB nTabCount = rDoc.GetTableCount();
34 ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
35 for (; itr != itrEnd && *itr < nTabCount; ++itr)
36 if (rDoc.IsTabProtected(*itr))
37 return true;
39 return false;
42 ScDocument* DocFuncUtil::createDeleteContentsUndoDoc(
43 ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange,
44 InsertDeleteFlags nFlags, bool bOnlyMarked )
46 std::unique_ptr<ScDocument> pUndoDoc(new ScDocument(SCDOCMODE_UNDO));
47 SCTAB nTab = rRange.aStart.Tab();
48 pUndoDoc->InitUndo(&rDoc, nTab, nTab);
49 SCTAB nTabCount = rDoc.GetTableCount();
50 ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
51 for (; itr != itrEnd; ++itr)
52 if (*itr != nTab)
53 pUndoDoc->AddUndoTab( *itr, *itr );
54 ScRange aCopyRange = rRange;
55 aCopyRange.aStart.SetTab(0);
56 aCopyRange.aEnd.SetTab(nTabCount-1);
58 // in case of "Format/Standard" copy all attributes, because CopyToDocument
59 // with IDF_HARDATTR only is too time-consuming:
60 InsertDeleteFlags nUndoDocFlags = nFlags;
61 if (nFlags & IDF_ATTRIB)
62 nUndoDocFlags |= IDF_ATTRIB;
63 if (nFlags & IDF_EDITATTR) // Edit-Engine-Attribute
64 nUndoDocFlags |= IDF_STRING; // -> cells will be changed
65 if (nFlags & IDF_NOTE)
66 nUndoDocFlags |= IDF_CONTENTS; // copy all cells with their notes
67 // do not copy note captions to undo document
68 nUndoDocFlags |= IDF_NOCAPTIONS;
69 rDoc.CopyToDocument(aCopyRange, nUndoDocFlags, bOnlyMarked, pUndoDoc.get(), &rMark);
71 return pUndoDoc.release();
74 void DocFuncUtil::addDeleteContentsUndo(
75 svl::IUndoManager* pUndoMgr, ScDocShell* pDocSh, const ScMarkData& rMark,
76 const ScRange& rRange, ScDocument* pUndoDoc, InsertDeleteFlags nFlags,
77 const boost::shared_ptr<ScSimpleUndo::DataSpansType>& pSpans,
78 bool bMulti, bool bDrawUndo )
80 std::unique_ptr<ScUndoDeleteContents> pUndo(
81 new ScUndoDeleteContents(
82 pDocSh, rMark, rRange, pUndoDoc, bMulti, nFlags, bDrawUndo));
83 pUndo->SetDataSpans(pSpans);
85 pUndoMgr->AddUndoAction(pUndo.release());
88 ScSimpleUndo::DataSpansType* DocFuncUtil::getNonEmptyCellSpans(
89 const ScDocument& rDoc, const ScMarkData& rMark, const ScRange& rRange )
91 std::unique_ptr<ScSimpleUndo::DataSpansType> pDataSpans(new ScSimpleUndo::DataSpansType);
92 ScMarkData::const_iterator it = rMark.begin(), itEnd = rMark.end();
93 for (; it != itEnd; ++it)
95 SCTAB nTab = *it;
97 SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
98 SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
100 std::pair<ScSimpleUndo::DataSpansType::iterator,bool> r =
101 pDataSpans->insert(nTab, new sc::ColumnSpanSet(false));
103 if (r.second)
105 sc::ColumnSpanSet* pSet = r.first->second;
106 pSet->scan(rDoc, nTab, nCol1, nRow1, nCol2, nRow2, true);
110 return pDataSpans.release();
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */