| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 | /* libwps |
| 3 | * Version: MPL 2.0 / LGPLv2.1+ |
| 4 | * |
| 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 | * |
| 9 | * Major Contributor(s): |
| 10 | * Copyright (C) 2009, 2011 Alonso Laurent ([email protected]) |
| 11 | * Copyright (C) 2006, 2007 Andrew Ziem |
| 12 | * Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 13 | * Copyright (C) 2004 Marc Maurer ([email protected]) |
| 14 | * Copyright (C) 2003-2005 William Lachance ([email protected]) |
| 15 | * |
| 16 | * For minor contributions see the git repository. |
| 17 | * |
| 18 | * Alternatively, the contents of this file may be used under the terms |
| 19 | * of the GNU Lesser General Public License Version 2.1 or later |
| 20 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 21 | * applicable instead of those above. |
| 22 | * |
| 23 | * For further information visit http://libwps.sourceforge.net |
| 24 | */ |
| 25 | |
| 26 | #ifndef WPS_LIST_H |
| 27 | # define WPS_LIST_H |
| 28 | |
| 29 | #include <iostream> |
| 30 | #include <vector> |
| 31 | |
| 32 | #include <librevenge/librevenge.h> |
| 33 | #include "libwps_internal.h" |
| 34 | |
| 35 | /** a small structure used to store the informations about a list */ |
| 36 | class WPSList |
| 37 | { |
| 38 | public: |
| 39 | /** small structure to keep information about a level */ |
| 40 | struct Level |
| 41 | { |
| 42 | |
| 43 | /** basic constructor */ |
| 44 | Level() |
| 45 | : m_labelIndent(0.0) |
| 46 | , m_labelWidth(0.0) |
| 47 | , m_startValue(-1) |
| 48 | , m_type(libwps::NONE) |
| 49 | , m_prefix("") |
| 50 | , m_suffix("") |
| 51 | , m_bullet("") |
| 52 | , m_sendToInterface(false) { } |
| 53 | |
| 54 | /** returns true if the level type was not set */ |
| 55 | bool isDefault() const |
| 56 | { |
| 57 | return m_type ==libwps::NONE; |
| 58 | } |
| 59 | /** returns true if the list is decimal, alpha or roman */ |
| 60 | bool isNumeric() const |
| 61 | { |
| 62 | return m_type !=libwps::NONE && m_type != libwps::BULLET; |
| 63 | } |
| 64 | /** add the information of this level in the propList */ |
| 65 | void addTo(librevenge::RVNGPropertyList &propList, int startVal) const; |
| 66 | |
| 67 | /** returns true, if addTo has been called */ |
| 68 | bool isSendToInterface() const |
| 69 | { |
| 70 | return m_sendToInterface; |
| 71 | } |
| 72 | /** reset the sendToInterface flag */ |
| 73 | void resetSendToInterface() const |
| 74 | { |
| 75 | m_sendToInterface = false; |
| 76 | } |
| 77 | |
| 78 | /** returns the start value (if set) or 1 */ |
| 79 | int getStartValue() const |
| 80 | { |
| 81 | return m_startValue <= -1 ? 1 : m_startValue; |
| 82 | } |
| 83 | |
| 84 | //! full comparison function |
| 85 | int cmp(Level const &levl) const; |
| 86 | |
| 87 | //! type comparison function |
| 88 | int cmpType(Level const &levl) const; |
| 89 | |
| 90 | //! operator<< |
| 91 | friend std::ostream &operator<<(std::ostream &o, Level const &ft); |
| 92 | |
| 93 | double m_labelIndent /** the list indent*/; |
| 94 | double m_labelWidth /** the list width */; |
| 95 | /** the actual value (if this is an ordered level ) */ |
| 96 | int m_startValue; |
| 97 | /** the type of the level */ |
| 98 | libwps::NumberingType m_type; |
| 99 | librevenge::RVNGString m_prefix /** string which preceedes the number if we have an ordered level*/, |
| 100 | m_suffix/** string which follows the number if we have an ordered level*/, |
| 101 | m_bullet /** the bullet if we have an bullet level */; |
| 102 | |
| 103 | protected: |
| 104 | /** true if it is already send to librevenge::RVNGTextInterface */ |
| 105 | mutable bool m_sendToInterface; |
| 106 | }; |
| 107 | |
| 108 | /** default constructor */ |
| 109 | WPSList() |
| 110 | : m_levels() |
| 111 | , m_actLevel(-1) |
| 112 | , m_actualIndices() |
| 113 | , m_nextIndices() |
| 114 | , m_id(-1) |
| 115 | , m_previousId(-1) {} |
| 116 | |
| 117 | /** returns the list id */ |
| 118 | int getId() const |
| 119 | { |
| 120 | return m_id; |
| 121 | } |
| 122 | |
| 123 | /** returns the previous list id |
| 124 | |
| 125 | \note a cheat because writerperfect imposes to get a new id if the level 1 changes |
| 126 | */ |
| 127 | int getPreviousId() const |
| 128 | { |
| 129 | return m_previousId; |
| 130 | } |
| 131 | |
| 132 | /** set the list id */ |
| 133 | void setId(int newId); |
| 134 | |
| 135 | /** returns the number of level */ |
| 136 | int numLevels() const |
| 137 | { |
| 138 | return int(m_levels.size()); |
| 139 | } |
| 140 | /** sets a level */ |
| 141 | void set(int levl, Level const &level); |
| 142 | |
| 143 | /** set the list level */ |
| 144 | void setLevel(int levl) const; |
| 145 | /** open the list element */ |
| 146 | void openElement() const; |
| 147 | /** close the list element */ |
| 148 | void closeElement() const {} |
| 149 | |
| 150 | /** returns true is a level is numeric */ |
| 151 | bool isNumeric(int levl) const; |
| 152 | |
| 153 | /** returns true of the level must be send to the document interface */ |
| 154 | bool mustSendLevel(int level) const; |
| 155 | |
| 156 | /** add level definition to propList */ |
| 157 | void addLevelTo(int level, librevenge::RVNGPropertyList &propList) const; |
| 158 | |
| 159 | protected: |
| 160 | std::vector<Level> m_levels; |
| 161 | |
| 162 | mutable int m_actLevel; |
| 163 | mutable std::vector<int> m_actualIndices, m_nextIndices; |
| 164 | mutable int m_id, m_previousId; |
| 165 | }; |
| 166 | |
| 167 | #endif |
| 168 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |