/src/libstaroffice/src/lib/STOFFList.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
2 | | |
3 | | /* libstaroffice |
4 | | * Version: MPL 2.0 / LGPLv2+ |
5 | | * |
6 | | * The contents of this file are subject to the Mozilla Public License Version |
7 | | * 2.0 (the "License"); you may not use this file except in compliance with |
8 | | * the License or as specified alternatively below. You may obtain a copy of |
9 | | * the License at http://www.mozilla.org/MPL/ |
10 | | * |
11 | | * Software distributed under the License is distributed on an "AS IS" basis, |
12 | | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
13 | | * for the specific language governing rights and limitations under the |
14 | | * License. |
15 | | * |
16 | | * Major Contributor(s): |
17 | | * Copyright (C) 2002 William Lachance (wrlach@gmail.com) |
18 | | * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) |
19 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
20 | | * Copyright (C) 2006, 2007 Andrew Ziem |
21 | | * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) |
22 | | * |
23 | | * |
24 | | * All Rights Reserved. |
25 | | * |
26 | | * For minor contributions see the git repository. |
27 | | * |
28 | | * Alternatively, the contents of this file may be used under the terms of |
29 | | * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
30 | | * in which case the provisions of the LGPLv2+ are applicable |
31 | | * instead of those above. |
32 | | */ |
33 | | |
34 | | #ifndef STOFF_LIST_H |
35 | | # define STOFF_LIST_H |
36 | | |
37 | | #include <iostream> |
38 | | |
39 | | #include <vector> |
40 | | |
41 | | #include <librevenge/librevenge.h> |
42 | | |
43 | | #include "libstaroffice_internal.hxx" |
44 | | |
45 | | class STOFFFont; |
46 | | |
47 | | /** small structure to keep information about a list level */ |
48 | | struct STOFFListLevel { |
49 | | /** the type of the level */ |
50 | | enum Type { DEFAULT, NONE, BULLET, NUMBER }; |
51 | | |
52 | | /** basic constructor */ |
53 | | STOFFListLevel() |
54 | 2.57M | : m_type(NONE) |
55 | 2.57M | , m_propertyList() |
56 | 2.57M | , m_font() |
57 | 2.57M | , m_startValue(0) |
58 | 2.57M | { |
59 | 2.57M | } |
60 | 692k | STOFFListLevel(STOFFListLevel const &)=default; |
61 | | STOFFListLevel(STOFFListLevel &&)=default; |
62 | 345k | STOFFListLevel &operator=(STOFFListLevel const &)=default; |
63 | 219k | STOFFListLevel &operator=(STOFFListLevel &&)=default; |
64 | | /** destructor */ |
65 | | ~STOFFListLevel(); |
66 | | |
67 | | /** returns true if the level type was not set */ |
68 | | bool isDefault() const |
69 | 18.3k | { |
70 | 18.3k | return m_type==DEFAULT; |
71 | 18.3k | } |
72 | | /** returns true if the list is decimal, alpha or roman */ |
73 | | bool isNumeric() const |
74 | 26.3k | { |
75 | 26.3k | return m_type==NUMBER; |
76 | 26.3k | } |
77 | | //! operator== |
78 | | bool operator==(STOFFListLevel const &levl) const |
79 | 128k | { |
80 | 128k | return cmp(levl)==0; |
81 | 128k | } |
82 | | //! operator!= |
83 | | bool operator!=(STOFFListLevel const &levl) const |
84 | 0 | { |
85 | 0 | return !operator==(levl); |
86 | 0 | } |
87 | | /** add the information of this level in the propList */ |
88 | | void addTo(librevenge::RVNGPropertyList &propList) const; |
89 | | |
90 | | /** returns the start value (if set) or 1 */ |
91 | | int getStartValue() const |
92 | 222k | { |
93 | 222k | return m_startValue <= 0 ? 1 : m_startValue; |
94 | 222k | } |
95 | | |
96 | | /** comparison function ( compare all values excepted m_startValues */ |
97 | | int cmp(STOFFListLevel const &levl) const; |
98 | | /** the type of the level */ |
99 | | Type m_type; |
100 | | //! the propertyList |
101 | | librevenge::RVNGPropertyList m_propertyList; |
102 | | /// the font |
103 | | std::shared_ptr<STOFFFont> m_font; |
104 | | /** the actual value (if this is an ordered level ) */ |
105 | | int m_startValue; |
106 | | }; |
107 | | |
108 | | /** a small structure used to store the informations about a list */ |
109 | | class STOFFList |
110 | | { |
111 | | public: |
112 | | /** default constructor */ |
113 | | explicit STOFFList(bool outline) |
114 | 19.2k | : m_outline(outline) |
115 | 19.2k | , m_name(""), m_levels() |
116 | 19.2k | , m_actLevel(-1) |
117 | 19.2k | , m_actualIndices() |
118 | 19.2k | , m_nextIndices() |
119 | 19.2k | , m_modifyMarker(1) |
120 | 19.2k | { |
121 | 19.2k | m_id[0] = m_id[1] = -1; |
122 | 19.2k | } |
123 | | |
124 | | /** returns the list id */ |
125 | | int getId() const |
126 | 73.5k | { |
127 | 73.5k | return m_id[0]; |
128 | 73.5k | } |
129 | | |
130 | | /** returns the actual modify marker */ |
131 | | int getMarker() const |
132 | 10.5k | { |
133 | 10.5k | return m_modifyMarker; |
134 | 10.5k | } |
135 | | /** resize the number of level of the list (keeping only n level) */ |
136 | | void resize(int levl); |
137 | | /** returns true if we can add a new level in the list without changing is meaning */ |
138 | | bool isCompatibleWith(int levl, STOFFListLevel const &level) const; |
139 | | /** returns true if the list is compatible with the defined level of new list */ |
140 | | bool isCompatibleWith(STOFFList const &newList) const; |
141 | | /** update the indices, the actual level from newList */ |
142 | | void updateIndicesFrom(STOFFList const &list); |
143 | | |
144 | | /** swap the list id |
145 | | |
146 | | \note a cheat because writerperfect imposes to get a new id if the level 1 changes |
147 | | */ |
148 | | void swapId() const |
149 | 0 | { |
150 | 0 | int tmp = m_id[0]; |
151 | 0 | m_id[0] = m_id[1]; |
152 | 0 | m_id[1] = tmp; |
153 | 0 | } |
154 | | |
155 | | /** set the list id */ |
156 | | void setId(int newId) const; |
157 | | |
158 | | /** returns a level if it exists */ |
159 | | STOFFListLevel getLevel(int levl) const |
160 | 5.60k | { |
161 | 5.60k | if (levl >= 0 && levl < int(m_levels.size())) |
162 | 5.60k | return m_levels[size_t(levl)]; |
163 | 0 | STOFF_DEBUG_MSG(("STOFFList::getLevel: can not find level %d\n", levl)); |
164 | 0 | return STOFFListLevel(); |
165 | 5.60k | } |
166 | | /** returns the number of level */ |
167 | | int numLevels() const |
168 | 8.72k | { |
169 | 8.72k | return int(m_levels.size()); |
170 | 8.72k | } |
171 | | /** sets a level */ |
172 | | void set(int levl, STOFFListLevel const &level); |
173 | | |
174 | | /** set the list level */ |
175 | | void setLevel(int levl) const; |
176 | | /** open the list element */ |
177 | | void openElement() const; |
178 | | /** close the list element */ |
179 | 7.96k | void closeElement() const {} |
180 | | /** returns the startvalue corresponding to the actual level ( or -1 for an unknown/unordered list) */ |
181 | | int getStartValueForNextElement() const; |
182 | | /** set the startvalue corresponding to the actual level*/ |
183 | | void setStartValueForNextElement(int value); |
184 | | |
185 | | /** returns true is a level is numeric */ |
186 | | bool isNumeric(int levl) const; |
187 | | |
188 | | /// retrieve the list level property |
189 | | bool addTo(int level, librevenge::RVNGPropertyList &pList) const; |
190 | | |
191 | | /// flag to know if the list is a outline list |
192 | | bool m_outline; |
193 | | /// the list name |
194 | | librevenge::RVNGString m_name; |
195 | | protected: |
196 | | //! the different levels |
197 | | std::vector<STOFFListLevel> m_levels; |
198 | | |
199 | | //! the actual levels |
200 | | mutable int m_actLevel; |
201 | | mutable std::vector<int> m_actualIndices, m_nextIndices; |
202 | | //! the identificator ( actual and auxilliar ) |
203 | | mutable int m_id[2]; |
204 | | //! a modification marker ( can be used to check if a list has been send to a interface ) |
205 | | mutable int m_modifyMarker; |
206 | | }; |
207 | | |
208 | | /** a manager which manages the lists, keeps the different kind of lists, to assure the unicity of each list */ |
209 | | class STOFFListManager |
210 | | { |
211 | | public: |
212 | | //! the constructor |
213 | | STOFFListManager() |
214 | 197k | : m_listList() |
215 | 197k | , m_sendIdMarkerList() { } |
216 | | //! the destructor |
217 | 197k | ~STOFFListManager() { } |
218 | | /** check if a list need to be send/resend to the interface */ |
219 | | bool needToSend(int index, std::vector<int> &idMarkerList) const; |
220 | | //! returns a list with given index ( if found ) |
221 | | std::shared_ptr<STOFFList> getList(int index) const; |
222 | | //! returns a new list corresponding to a list where we have a new level |
223 | | std::shared_ptr<STOFFList> getNewList(std::shared_ptr<STOFFList> actList, int levl, STOFFListLevel const &level); |
224 | | //! add a new list |
225 | | std::shared_ptr<STOFFList> addList(std::shared_ptr<STOFFList> actList); |
226 | | protected: |
227 | | //! the list of created list |
228 | | std::vector<STOFFList> m_listList; |
229 | | //! the list of send list to interface |
230 | | mutable std::vector<int> m_sendIdMarkerList; |
231 | | }; |
232 | | #endif |
233 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |