Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / olinetab.hxx
blob45c4a65a6b9b04fb0f0d31aaab91bb801cb85114
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 #pragma once
22 #include "scdllapi.h"
23 #include "address.hxx"
25 #include <map>
27 #define SC_OL_MAXDEPTH 7
29 class ScTable;
31 class ScOutlineEntry
33 SCCOLROW nStart;
34 SCSIZE nSize;
35 bool bHidden;
36 bool bVisible;
38 public:
39 ScOutlineEntry( SCCOLROW nNewStart, SCCOLROW nNewSize, bool bNewHidden );
40 ScOutlineEntry( const ScOutlineEntry& rEntry );
42 SC_DLLPUBLIC SCCOLROW GetStart() const { return nStart;}
43 SCSIZE GetSize() const { return nSize;}
44 SC_DLLPUBLIC SCCOLROW GetEnd() const;
46 /**
47 * @return true is the group is hidden, false otherwise.
49 SC_DLLPUBLIC bool IsHidden() const { return bHidden;}
51 /**
52 * @return true if the control is visible, false otherwise.
54 SC_DLLPUBLIC bool IsVisible() const { return bVisible;}
56 void Move( SCCOLROW nDelta );
57 void SetSize( SCSIZE nNewSize );
58 void SetPosSize( SCCOLROW nNewPos, SCSIZE nNewSize );
59 void SetHidden( bool bNewHidden );
60 void SetVisible( bool bNewVisible );
62 OString dumpAsString() const;
65 class ScOutlineCollection
67 typedef std::map<SCCOLROW, ScOutlineEntry> MapType;
68 MapType m_Entries;
70 public:
71 typedef MapType::iterator iterator;
72 typedef MapType::const_iterator const_iterator;
74 ScOutlineCollection();
76 size_t size() const;
77 void clear();
78 void insert(ScOutlineEntry const& rEntry);
79 iterator begin();
80 iterator end();
81 const_iterator begin() const;
82 const_iterator end() const;
83 iterator erase(const iterator& pos);
84 bool empty() const;
86 iterator FindStart(SCCOLROW nMinStart);
88 OString dumpAsString() const;
91 class SC_DLLPUBLIC ScOutlineArray
93 friend class ScSubOutlineIterator;
95 private:
96 size_t nDepth;
97 ScOutlineCollection aCollections[SC_OL_MAXDEPTH];
99 bool DecDepth();
100 void FindEntry(
101 SCCOLROW nSearchPos, size_t& rFindLevel, size_t& rFindIndex,
102 size_t nMaxLevel = SC_OL_MAXDEPTH);
104 void PromoteSub(SCCOLROW nStartPos, SCCOLROW nEndPos, size_t nStartLevel);
106 public:
107 ScOutlineArray();
108 ScOutlineArray( const ScOutlineArray& rArray );
110 size_t GetDepth() const { return nDepth;}
112 bool FindTouchedLevel(
113 SCCOLROW nBlockStart, SCCOLROW nBlockEnd, size_t& rFindLevel) const;
115 bool Insert( SCCOLROW nStartPos, SCCOLROW nEndPos, bool& rSizeChanged,
116 bool bHidden = false );
117 bool Remove( SCCOLROW nBlockStart, SCCOLROW nBlockEnd, bool& rSizeChanged );
119 ScOutlineEntry* GetEntry(size_t nLevel, size_t nIndex);
120 const ScOutlineEntry* GetEntry(size_t nLevel, size_t nIndex) const;
121 size_t GetCount(size_t nLevel) const;
122 const ScOutlineEntry* GetEntryByPos(size_t nLevel, SCCOLROW nPos) const;
124 bool GetEntryIndex(size_t nLevel, SCCOLROW nPos, size_t& rnIndex) const;
125 bool GetEntryIndexInRange(
126 size_t nLevel, SCCOLROW nBlockStart, SCCOLROW nBlockEnd, size_t& rnIndex) const;
128 void SetVisibleBelow(
129 size_t nLevel, size_t nEntry, bool bValue, bool bSkipHidden = false);
131 void GetRange(SCCOLROW& rStart, SCCOLROW& rEnd) const;
132 void ExtendBlock(size_t nLevel, SCCOLROW& rBlkStart, SCCOLROW& rBlkEnd);
134 bool TestInsertSpace(SCSIZE nSize, SCCOLROW nMaxVal) const;
135 void InsertSpace(SCCOLROW nStartPos, SCSIZE nSize);
136 bool DeleteSpace(SCCOLROW nStartPos, SCSIZE nSize);
138 bool ManualAction(
139 SCCOLROW nStartPos, SCCOLROW nEndPos, bool bShow, const ScTable& rTable, bool bCol);
141 void finalizeImport(const ScTable& rTable);
143 void RemoveAll();
145 OString dumpAsString() const;
148 class ScOutlineTable
150 private:
151 ScOutlineArray aColOutline;
152 ScOutlineArray aRowOutline;
154 public:
155 ScOutlineTable();
156 ScOutlineTable( const ScOutlineTable& rOutline );
158 const ScOutlineArray& GetColArray() const { return aColOutline; }
159 ScOutlineArray& GetColArray() { return aColOutline; }
160 const ScOutlineArray& GetRowArray() const { return aRowOutline; }
161 ScOutlineArray& GetRowArray() { return aRowOutline; }
163 bool TestInsertCol( SCSIZE nSize );
164 void InsertCol( SCCOL nStartCol, SCSIZE nSize );
165 bool DeleteCol( SCCOL nStartCol, SCSIZE nSize ); // TRUE: Undo only using original
166 bool TestInsertRow( SCSIZE nSize );
167 void InsertRow( SCROW nStartRow, SCSIZE nSize );
168 bool DeleteRow( SCROW nStartRow, SCSIZE nSize );
171 class ScSubOutlineIterator
173 private:
174 ScOutlineArray* pArray;
175 SCCOLROW nStart;
176 SCCOLROW nEnd;
177 size_t nSubLevel;
178 size_t nSubEntry;
179 size_t nDepth;
181 public:
182 ScSubOutlineIterator( ScOutlineArray* pOutlineArray );
183 ScSubOutlineIterator( ScOutlineArray* pOutlineArray, size_t nLevel, size_t nEntry );
185 ScOutlineEntry* GetNext();
186 size_t LastLevel() const { return nSubLevel;}
187 size_t LastEntry() const;
188 void DeleteLast();
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */