1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
12 #include "address.hxx"
16 #include <mdds/flat_segment_tree.hpp>
26 struct ColumnBlockConstPosition
;
27 class SingleColumnSpanSet
;
34 RowSpan(SCROW nRow1
, SCROW nRow2
);
37 struct SC_DLLPUBLIC ColRowSpan
42 ColRowSpan(SCCOLROW nStart
, SCCOLROW nEnd
);
46 * Structure that stores segments of boolean flags per column, and perform
47 * custom action on those segments.
52 typedef mdds::flat_segment_tree
<SCROW
, bool> ColumnSpansType
;
57 ColumnSpansType maSpans
;
58 ColumnSpansType::const_iterator miPos
;
60 ColumnType(SCROW nStart
, SCROW nEnd
, bool bInit
);
61 ColumnType(const ColumnType
& rOther
);
64 typedef std::vector
<std::optional
<ColumnType
>> TableType
;
66 std::vector
<TableType
> maTables
;
68 ColumnType
& getColumn(const ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol
);
74 virtual ~Action() = 0;
75 virtual void startColumn(SCTAB nTab
, SCCOL nCol
);
76 virtual void execute(const ScAddress
& rPos
, SCROW nLength
, bool bVal
) = 0;
82 virtual ~ColumnAction() = 0;
83 virtual void startColumn(ScColumn
* pCol
) = 0;
84 virtual void execute(SCROW nRow1
, SCROW nRow2
, bool bVal
) = 0;
88 ColumnSpanSet(const ColumnSpanSet
&) = delete;
89 ColumnSpanSet
& operator=(const ColumnSpanSet
&) = delete;
90 ColumnSpanSet(ColumnSpanSet
&&) = default;
91 ColumnSpanSet
& operator=(ColumnSpanSet
&&) = default;
94 void set(const ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol
, SCROW nRow
, bool bVal
);
95 void set(const ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol
, SCROW nRow1
, SCROW nRow2
, bool bVal
);
96 void set(const ScDocument
& rDoc
, const ScRange
& rRange
, bool bVal
);
98 void set(const ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol
, const SingleColumnSpanSet
& rSingleSet
, bool bVal
);
101 * Scan specified range in a specified sheet and mark all non-empty cells
102 * with specified boolean value.
104 void scan(const ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
, bool bVal
);
106 void executeAction(ScDocument
& rDoc
, Action
& ac
) const;
107 void executeColumnAction(ScDocument
& rDoc
, ColumnAction
& ac
) const;
111 * Keep track of spans in a single column only.
113 class SingleColumnSpanSet
116 typedef mdds::flat_segment_tree
<SCROW
, bool> ColumnSpansType
;
118 typedef std::vector
<RowSpan
> SpansType
;
120 SingleColumnSpanSet(ScSheetLimits
const &);
123 * Scan an entire column and tag all non-empty cell positions.
125 void scan(const ScColumn
& rColumn
);
128 * Scan a column between specified range, and tag all non-empty cell
131 void scan(const ScColumn
& rColumn
, SCROW nStart
, SCROW nEnd
);
134 ColumnBlockConstPosition
& rBlockPos
, const ScColumn
& rColumn
, SCROW nStart
, SCROW nEnd
);
137 * Scan all marked data and tag all marked segments in specified column.
139 void scan(const ScMarkData
& rMark
, SCTAB nTab
, SCCOL nCol
);
141 void scan(const ScRangeList
& rRanges
, SCTAB nTab
, SCCOL nCol
);
143 void set(SCROW nRow1
, SCROW nRow2
, bool bVal
);
145 void getRows(std::vector
<SCROW
> &rRows
) const;
147 void getSpans(SpansType
& rSpans
) const;
149 void swap( SingleColumnSpanSet
& r
);
151 /** Whether there isn't any row tagged. */
155 ScSheetLimits
const & mrSheetLimits
;
156 ColumnSpansType maSpans
;
160 * Optimized ColumnSpanSet version that operates on a single ScRange.
162 class RangeColumnSpanSet
165 RangeColumnSpanSet( const ScRange
& spanRange
)
166 : range( spanRange
) {}
167 void executeColumnAction(ScDocument
& rDoc
, sc::ColumnSpanSet::ColumnAction
& ac
) const;
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */