Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / columnspanset.hxx
blob98533e240f37d32e207b792978d17fb53960d013
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/.
8 */
10 #ifndef SC_COLUMNSPANSET_HXX
11 #define SC_COLUMNSPANSET_HXX
13 #include "address.hxx"
15 #include <vector>
16 #include <mdds/flat_segment_tree.hpp>
17 #include <boost/noncopyable.hpp>
19 class ScDocument;
20 class ScColumn;
21 class ScMarkData;
22 class ScRange;
24 namespace sc {
26 struct ColumnBlockConstPosition;
28 /**
29 * Structure that stores segments of boolean flags per column, and perform
30 * custom action on those segments.
32 class ColumnSpanSet : boost::noncopyable
34 typedef mdds::flat_segment_tree<SCROW, bool> ColumnSpansType;
36 struct ColumnType
38 ColumnSpansType maSpans;
39 ColumnSpansType::const_iterator miPos;
41 ColumnType(SCROW nStart, SCROW nEnd, bool bInit);
44 typedef std::vector<ColumnType*> TableType;
45 typedef std::vector<TableType*> DocType;
47 DocType maDoc;
48 bool mbInit;
50 ColumnType& getColumn(SCTAB nTab, SCCOL nCol);
52 public:
53 class Action
55 public:
56 virtual ~Action() = 0;
57 virtual void startColumn(SCTAB nTab, SCCOL nCol);
58 virtual void execute(const ScAddress& rPos, SCROW nLength, bool bVal) = 0;
61 class ColumnAction
63 public:
64 virtual ~ColumnAction() = 0;
65 virtual void startColumn(ScColumn* pCol) = 0;
66 virtual void execute(SCROW nRow1, SCROW nRow2, bool bVal) = 0;
69 ColumnSpanSet(bool bInit);
70 ~ColumnSpanSet();
72 void set(SCTAB nTab, SCCOL nCol, SCROW nRow, bool bVal);
73 void set(SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2, bool bVal);
74 void set(const ScRange& rRange, bool bVal);
76 void executeAction(Action& ac) const;
77 void executeColumnAction(ScDocument& rDoc, ColumnAction& ac) const;
80 /**
81 * Keep track of spans in a single column only.
83 class SingleColumnSpanSet
85 public:
86 typedef mdds::flat_segment_tree<SCROW, bool> ColumnSpansType;
88 struct Span
90 SCROW mnRow1;
91 SCROW mnRow2;
93 Span(SCROW nRow1, SCROW nRow2) : mnRow1(nRow1), mnRow2(nRow2) {}
96 typedef std::vector<Span> SpansType;
98 SingleColumnSpanSet();
101 * Scan an entire column and tag all non-empty cell positions.
103 void scan(const ScColumn& rColumn);
106 * Scan a column between specified range, and tag all non-empty cell
107 * positions.
109 void scan(const ScColumn& rColumn, SCROW nStart, SCROW nEnd);
111 void scan(
112 ColumnBlockConstPosition& rBlockPos, const ScColumn& rColumn, SCROW nStart, SCROW nEnd);
115 * Scan all marked data and tag all marked segments in specified column.
117 void scan(const ScMarkData& rMark, SCTAB nTab, SCCOL nCol);
119 void set(SCROW nRow1, SCROW nRow2, bool bVal);
121 void getRows(std::vector<SCROW> &rRows) const;
123 void getSpans(SpansType& rSpans) const;
125 private:
126 ColumnSpansType maSpans;
131 #endif
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */