| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 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 ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 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 MWAW_LIST_H |
| 35 |
# define MWAW_LIST_H |
| 36 |
|
| 37 |
#include <iostream> |
| 38 |
|
| 39 |
#include <vector> |
| 40 |
|
| 41 |
#include <librevenge/librevenge.h> |
| 42 |
|
| 43 |
#include "libmwaw_internal.hxx" |
| 44 |
|
| 45 |
/** small structure to keep information about a list level */ |
| 46 |
struct MWAWListLevel { |
| 47 |
/** the type of the level */ |
| 48 |
enum Type { DEFAULT, NONE, BULLET, DECIMAL, LOWER_ALPHA, UPPER_ALPHA, |
| 49 |
LOWER_ROMAN, UPPER_ROMAN, LABEL |
| 50 |
}; |
| 51 |
//! the item alignment |
| 52 |
enum Alignment { LEFT, RIGHT, CENTER }; |
| 53 |
|
| 54 |
/** basic constructor */ |
| 55 |
MWAWListLevel() |
| 56 |
: m_type(NONE) |
| 57 |
, m_numBeforeLabels(0) |
| 58 |
, m_labelBeforeSpace(0.0) |
| 59 |
, m_labelWidth(0.1) |
| 60 |
, m_labelAfterSpace(0.0) |
| 61 |
, m_alignment(LEFT) |
| 62 |
, m_startValue(0) |
| 63 |
, m_label("") |
| 64 |
, m_prefix("") |
| 65 |
, m_suffix("") |
| 66 |
, m_bullet("") |
| 67 |
, m_spanId(-1) |
| 68 |
, m_extra("") |
| 69 |
{ |
| 70 |
} |
| 71 |
MWAWListLevel(MWAWListLevel const &)=default; |
| 72 |
MWAWListLevel &operator=(MWAWListLevel const &)=default; |
| 73 |
MWAWListLevel &operator=(MWAWListLevel &&)=default; |
| 74 |
/** destructor */ |
| 75 |
~MWAWListLevel() {} |
| 76 |
|
| 77 |
/** returns true if the level type was not set */ |
| 78 |
bool isDefault() const |
| 79 |
{ |
| 80 |
return m_type ==DEFAULT; |
| 81 |
} |
| 82 |
/** returns true if the list is decimal, alpha or roman */ |
| 83 |
bool isNumeric() const |
| 84 |
{ |
| 85 |
return m_type !=DEFAULT && m_type !=NONE && m_type != BULLET; |
| 86 |
} |
| 87 |
/** add the information of this level in the propList */ |
| 88 |
void addTo(librevenge::RVNGPropertyList &propList, MWAWFontManagerPtr fontManager) const; |
| 89 |
|
| 90 |
/** returns the start value (if set) or 1 */ |
| 91 |
int getStartValue() const |
| 92 |
{ |
| 93 |
return m_startValue <= 0 ? 1 : m_startValue; |
| 94 |
} |
| 95 |
|
| 96 |
/** comparison function ( compare all values excepted m_startValues */ |
| 97 |
int cmp(MWAWListLevel const &levl) const; |
| 98 |
|
| 99 |
//! operator<< |
| 100 |
friend std::ostream &operator<<(std::ostream &o, MWAWListLevel const &ft); |
| 101 |
|
| 102 |
/** the type of the level */ |
| 103 |
Type m_type; |
| 104 |
/** the number of label to show before this */ |
| 105 |
int m_numBeforeLabels; |
| 106 |
double m_labelBeforeSpace /** the extra space between inserting a label */; |
| 107 |
double m_labelWidth /** the minimum label width */; |
| 108 |
double m_labelAfterSpace /** the minimum distance between the label and the text */; |
| 109 |
//! the alignment ( left, center, ...) |
| 110 |
Alignment m_alignment; |
| 111 |
/** the actual value (if this is an ordered level ) */ |
| 112 |
int m_startValue; |
| 113 |
librevenge::RVNGString m_label /** the text label */, |
| 114 |
m_prefix /** string which preceedes the number if we have an ordered level*/, |
| 115 |
m_suffix/** string which follows the number if we have an ordered level*/, |
| 116 |
m_bullet /** the bullet if we have an bullet level */; |
| 117 |
/// the style span id |
| 118 |
int m_spanId; |
| 119 |
//! extra data |
| 120 |
std::string m_extra; |
| 121 |
}; |
| 122 |
|
| 123 |
/** a small structure used to store the informations about a list */ |
| 124 |
class MWAWList |
| 125 |
{ |
| 126 |
public: |
| 127 |
/** default constructor */ |
| 128 |
MWAWList() |
| 129 |
: m_levels() |
| 130 |
, m_actualIndices() |
| 131 |
, m_nextIndices() |
| 132 |
, m_actLevel(-1) |
| 133 |
, m_modifyMarker(1) |
| 134 |
{ |
| 135 |
for (auto &id : m_id) id = -1; |
| 136 |
} |
| 137 |
|
| 138 |
/** returns the list id */ |
| 139 |
int getId() const |
| 140 |
{ |
| 141 |
return m_id[0]; |
| 142 |
} |
| 143 |
|
| 144 |
/** returns the actual modify marker */ |
| 145 |
int getMarker() const |
| 146 |
{ |
| 147 |
return m_modifyMarker; |
| 148 |
} |
| 149 |
/** resize the number of level of the list (keeping only n level) */ |
| 150 |
void resize(int levl); |
| 151 |
/** returns true if we can add a new level in the list without changing is meaning */ |
| 152 |
bool isCompatibleWith(int levl, MWAWListLevel const &level) const; |
| 153 |
/** returns true if the list is compatible with the defined level of new list */ |
| 154 |
bool isCompatibleWith(MWAWList const &newList) const; |
| 155 |
/** update the indices, the actual level from newList */ |
| 156 |
void updateIndicesFrom(MWAWList const &list); |
| 157 |
|
| 158 |
/** swap the list id |
| 159 |
|
| 160 |
\note a cheat because writerperfect imposes to get a new id if the level 1 changes |
| 161 |
*/ |
| 162 |
void swapId() const |
| 163 |
{ |
| 164 |
std::swap(m_id[0], m_id[1]); |
| 165 |
} |
| 166 |
|
| 167 |
/** set the list id */ |
| 168 |
void setId(int newId) const; |
| 169 |
|
| 170 |
/** returns a level if it exists */ |
| 171 |
MWAWListLevel getLevel(int levl) const |
| 172 |
{ |
| 173 |
if (levl >= 0 && levl < int(m_levels.size())) |
| 174 |
return m_levels[size_t(levl)]; |
| 175 |
MWAW_DEBUG_MSG(("MWAWList::getLevel: can not find level %d\n", levl)); |
| 176 |
return MWAWListLevel(); |
| 177 |
} |
| 178 |
/** returns the number of level */ |
| 179 |
int numLevels() const |
| 180 |
{ |
| 181 |
return int(m_levels.size()); |
| 182 |
} |
| 183 |
/** sets a level */ |
| 184 |
void set(int levl, MWAWListLevel const &level); |
| 185 |
|
| 186 |
/** set the list level */ |
| 187 |
void setLevel(int levl) const; |
| 188 |
/** open the list element */ |
| 189 |
void openElement() const; |
| 190 |
/** close the list element */ |
| 191 |
void closeElement() const {} |
| 192 |
/** returns the startvalue corresponding to the actual level ( or -1 for an unknown/unordered list) */ |
| 193 |
int getStartValueForNextElement() const; |
| 194 |
/** set the startvalue corresponding to the actual level*/ |
| 195 |
void setStartValueForNextElement(int value); |
| 196 |
|
| 197 |
/** returns true is a level is numeric */ |
| 198 |
bool isNumeric(int levl) const; |
| 199 |
|
| 200 |
/// retrieve the list level property |
| 201 |
bool addTo(int level, librevenge::RVNGPropertyList &pList, MWAWFontManagerPtr fontManager) const; |
| 202 |
|
| 203 |
protected: |
| 204 |
//! the different levels |
| 205 |
std::vector<MWAWListLevel> m_levels; |
| 206 |
|
| 207 |
mutable std::vector<int> m_actualIndices, m_nextIndices; |
| 208 |
//! the actual levels |
| 209 |
mutable int m_actLevel; |
| 210 |
//! the identificator ( actual and auxilliar ) |
| 211 |
mutable int m_id[2]; |
| 212 |
//! a modification marker ( can be used to check if a list has been send to a interface ) |
| 213 |
mutable int m_modifyMarker; |
| 214 |
}; |
| 215 |
|
| 216 |
/** a manager which manages the lists, keeps the different kind of lists, to assure the unicity of each list */ |
| 217 |
class MWAWListManager |
| 218 |
{ |
| 219 |
public: |
| 220 |
//! the constructor |
| 221 |
explicit MWAWListManager(MWAWFontManagerPtr const &fontManager); |
| 222 |
//! the destructor |
| 223 |
~MWAWListManager(); |
| 224 |
/** check if a list need to be send/resend to the interface */ |
| 225 |
bool needToSend(int index, std::vector<int> &idMarkerList) const; |
| 226 |
//! returns a list with given index ( if found ) |
| 227 |
std::shared_ptr<MWAWList> getList(int index) const; |
| 228 |
//! returns a new list corresponding to a list where we have a new level |
| 229 |
std::shared_ptr<MWAWList> getNewList(std::shared_ptr<MWAWList> actList, int levl, MWAWListLevel const &level); |
| 230 |
protected: |
| 231 |
//! the font manager |
| 232 |
MWAWFontManagerPtr m_fontManager; |
| 233 |
//! the list of created list |
| 234 |
std::vector<MWAWList> m_listList; |
| 235 |
//! the list of send list to interface |
| 236 |
mutable std::vector<int> m_sendIdMarkerList; |
| 237 |
}; |
| 238 |
#endif |
| 239 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |