MWAWList.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef MWAW_LIST_H
# define MWAW_LIST_H
#include <iostream>
#include <vector>
#include <librevenge/librevenge.h>
#include "libmwaw_internal.hxx"
struct MWAWListLevel {
enum Type { DEFAULT, NONE, BULLET, DECIMAL, LOWER_ALPHA, UPPER_ALPHA,
LOWER_ROMAN, UPPER_ROMAN, LABEL
};
enum Alignment { LEFT, RIGHT, CENTER };
MWAWListLevel()
: m_type(NONE)
, m_numBeforeLabels(0)
, m_labelBeforeSpace(0.0)
, m_labelWidth(0.1)
, m_labelAfterSpace(0.0)
, m_alignment(LEFT)
, m_startValue(0)
, m_label("")
, m_prefix("")
, m_suffix("")
, m_bullet("")
, m_spanId(-1)
, m_extra("")
{
}
MWAWListLevel(MWAWListLevel const &)=default;
MWAWListLevel &operator=(MWAWListLevel const &)=default;
MWAWListLevel &operator=(MWAWListLevel &&)=default;
~MWAWListLevel() {}
bool isDefault() const
{
return m_type ==DEFAULT;
}
bool isNumeric() const
{
return m_type !=DEFAULT && m_type !=NONE && m_type != BULLET;
}
void addTo(librevenge::RVNGPropertyList &propList, MWAWFontManagerPtr fontManager) const;
int getStartValue() const
{
return m_startValue <= 0 ? 1 : m_startValue;
}
int cmp(MWAWListLevel const &levl) const;
friend std::ostream &operator<<(std::ostream &o, MWAWListLevel const &ft);
Type m_type;
int m_numBeforeLabels;
double m_labelBeforeSpace ;
double m_labelWidth ;
double m_labelAfterSpace ;
Alignment m_alignment;
int m_startValue;
librevenge::RVNGString m_label ,
m_prefix ,
m_suffix,
m_bullet ;
int m_spanId;
std::string m_extra;
};
class MWAWList
{
public:
MWAWList()
: m_levels()
, m_actualIndices()
, m_nextIndices()
, m_actLevel(-1)
, m_modifyMarker(1)
{
for (auto &id : m_id) id = -1;
}
int getId() const
{
return m_id[0];
}
int getMarker() const
{
return m_modifyMarker;
}
void resize(int levl);
bool isCompatibleWith(int levl, MWAWListLevel const &level) const;
bool isCompatibleWith(MWAWList const &newList) const;
void updateIndicesFrom(MWAWList const &list);
void swapId() const
{
std::swap(m_id[0], m_id[1]);
}
void setId(int newId) const;
MWAWListLevel getLevel(int levl) const
{
if (levl >= 0 && levl < int(m_levels.size()))
return m_levels[size_t(levl)];
MWAW_DEBUG_MSG(("MWAWList::getLevel: can not find level %d\n", levl));
return MWAWListLevel();
}
int numLevels() const
{
return int(m_levels.size());
}
void set(int levl, MWAWListLevel const &level);
void setLevel(int levl) const;
void openElement() const;
void closeElement() const {}
int getStartValueForNextElement() const;
void setStartValueForNextElement(int value);
bool isNumeric(int levl) const;
bool addTo(int level, librevenge::RVNGPropertyList &pList, MWAWFontManagerPtr fontManager) const;
protected:
std::vector<MWAWListLevel> m_levels;
mutable std::vector<int> m_actualIndices, m_nextIndices;
mutable int m_actLevel;
mutable int m_id[2];
mutable int m_modifyMarker;
};
class MWAWListManager
{
public:
explicit MWAWListManager(MWAWFontManagerPtr const &fontManager);
~MWAWListManager();
bool needToSend(int index, std::vector<int> &idMarkerList) const;
std::shared_ptr<MWAWList> getList(int index) const;
std::shared_ptr<MWAWList> getNewList(std::shared_ptr<MWAWList> actList, int levl, MWAWListLevel const &level);
protected:
MWAWFontManagerPtr m_fontManager;
std::vector<MWAWList> m_listList;
mutable std::vector<int> m_sendIdMarkerList;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWListManager::needToSend
bool needToSend(int index, std::vector< int > &idMarkerList) const
check if a list need to be send/resend to the interface
Definition MWAWList.cxx:373
MWAWListManager::m_listList
std::vector< MWAWList > m_listList
the list of created list
Definition MWAWList.hxx:234
MWAWListManager::m_fontManager
MWAWFontManagerPtr m_fontManager
the font manager
Definition MWAWList.hxx:232
MWAWListManager::m_sendIdMarkerList
std::vector< int > m_sendIdMarkerList
the list of send list to interface
Definition MWAWList.hxx:236
MWAWListManager::getNewList
std::shared_ptr< MWAWList > getNewList(std::shared_ptr< MWAWList > actList, int levl, MWAWListLevel const &level)
returns a new list corresponding to a list where we have a new level
Definition MWAWList.cxx:404
MWAWListManager::MWAWListManager
MWAWListManager(MWAWFontManagerPtr const &fontManager)
the constructor
Definition MWAWList.cxx:365
MWAWListManager::getList
std::shared_ptr< MWAWList > getList(int index) const
returns a list with given index ( if found )
Definition MWAWList.cxx:391
MWAWListManager::~MWAWListManager
~MWAWListManager()
the destructor
Definition MWAWList.cxx:369
MWAWList
a small structure used to store the informations about a list
Definition MWAWList.hxx:125
MWAWList::getStartValueForNextElement
int getStartValueForNextElement() const
returns the startvalue corresponding to the actual level ( or -1 for an unknown/unordered list)
Definition MWAWList.cxx:331
MWAWList::setStartValueForNextElement
void setStartValueForNextElement(int value)
set the startvalue corresponding to the actual level
Definition MWAWList.cxx:319
MWAWList::MWAWList
MWAWList()
default constructor
Definition MWAWList.hxx:128
MWAWList::m_nextIndices
std::vector< int > m_nextIndices
Definition MWAWList.hxx:207
MWAWList::getLevel
MWAWListLevel getLevel(int levl) const
returns a level if it exists
Definition MWAWList.hxx:171
MWAWList::getId
int getId() const
returns the list id
Definition MWAWList.hxx:139
MWAWList::swapId
void swapId() const
swap the list id
Definition MWAWList.hxx:162
MWAWList::m_levels
std::vector< MWAWListLevel > m_levels
the different levels
Definition MWAWList.hxx:205
MWAWList::set
void set(int levl, MWAWListLevel const &level)
sets a level
Definition MWAWList.cxx:286
MWAWList::closeElement
void closeElement() const
close the list element
Definition MWAWList.hxx:191
MWAWList::m_modifyMarker
int m_modifyMarker
a modification marker ( can be used to check if a list has been send to a interface )
Definition MWAWList.hxx:213
MWAWList::m_id
int m_id[2]
the identificator ( actual and auxilliar )
Definition MWAWList.hxx:211
MWAWList::m_actualIndices
std::vector< int > m_actualIndices
Definition MWAWList.hxx:207
MWAWList::getMarker
int getMarker() const
returns the actual modify marker
Definition MWAWList.hxx:145
MWAWList::setId
void setId(int newId) const
set the list id
Definition MWAWList.cxx:261
MWAWList::isCompatibleWith
bool isCompatibleWith(int levl, MWAWListLevel const &level) const
returns true if we can add a new level in the list without changing is meaning
Definition MWAWList.cxx:238
MWAWList::isNumeric
bool isNumeric(int levl) const
returns true is a level is numeric
Definition MWAWList.cxx:352
MWAWList::openElement
void openElement() const
open the list element
Definition MWAWList.cxx:342
MWAWList::updateIndicesFrom
void updateIndicesFrom(MWAWList const &list)
update the indices, the actual level from newList
Definition MWAWList.cxx:226
MWAWList::numLevels
int numLevels() const
returns the number of level
Definition MWAWList.hxx:179
MWAWList::setLevel
void setLevel(int levl) const
set the list level
Definition MWAWList.cxx:305
MWAWList::addTo
bool addTo(int level, librevenge::RVNGPropertyList &pList, MWAWFontManagerPtr fontManager) const
retrieve the list level property
Definition MWAWList.cxx:267
MWAWList::resize
void resize(int levl)
resize the number of level of the list (keeping only n level)
Definition MWAWList.cxx:210
MWAWList::m_actLevel
int m_actLevel
the actual levels
Definition MWAWList.hxx:209
libmwaw_internal.hxx
MWAWFontManagerPtr
std::shared_ptr< MWAWFontManager > MWAWFontManagerPtr
a smart pointer of MWAWFontManager
Definition libmwaw_internal.hxx:547
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition libmwaw_internal.hxx:129
MWAWListLevel
small structure to keep information about a list level
Definition MWAWList.hxx:46
MWAWListLevel::cmp
int cmp(MWAWListLevel const &levl) const
comparison function ( compare all values excepted m_startValues
Definition MWAWList.cxx:116
MWAWListLevel::Alignment
Alignment
the item alignment
Definition MWAWList.hxx:52
MWAWListLevel::RIGHT
@ RIGHT
Definition MWAWList.hxx:52
MWAWListLevel::CENTER
@ CENTER
Definition MWAWList.hxx:52
MWAWListLevel::LEFT
@ LEFT
Definition MWAWList.hxx:52
MWAWListLevel::getStartValue
int getStartValue() const
returns the start value (if set) or 1
Definition MWAWList.hxx:91
MWAWListLevel::~MWAWListLevel
~MWAWListLevel()
destructor
Definition MWAWList.hxx:75
MWAWListLevel::m_labelAfterSpace
double m_labelAfterSpace
the minimum distance between the label and the text
Definition MWAWList.hxx:108
MWAWListLevel::isNumeric
bool isNumeric() const
returns true if the list is decimal, alpha or roman
Definition MWAWList.hxx:83
MWAWListLevel::m_extra
std::string m_extra
extra data
Definition MWAWList.hxx:120
MWAWListLevel::addTo
void addTo(librevenge::RVNGPropertyList &propList, MWAWFontManagerPtr fontManager) const
add the information of this level in the propList
Definition MWAWList.cxx:47
MWAWListLevel::Type
Type
the type of the level
Definition MWAWList.hxx:48
MWAWListLevel::UPPER_ROMAN
@ UPPER_ROMAN
Definition MWAWList.hxx:49
MWAWListLevel::LOWER_ALPHA
@ LOWER_ALPHA
Definition MWAWList.hxx:48
MWAWListLevel::BULLET
@ BULLET
Definition MWAWList.hxx:48
MWAWListLevel::LABEL
@ LABEL
Definition MWAWList.hxx:49
MWAWListLevel::UPPER_ALPHA
@ UPPER_ALPHA
Definition MWAWList.hxx:48
MWAWListLevel::LOWER_ROMAN
@ LOWER_ROMAN
Definition MWAWList.hxx:49
MWAWListLevel::DEFAULT
@ DEFAULT
Definition MWAWList.hxx:48
MWAWListLevel::NONE
@ NONE
Definition MWAWList.hxx:48
MWAWListLevel::DECIMAL
@ DECIMAL
Definition MWAWList.hxx:48
MWAWListLevel::MWAWListLevel
MWAWListLevel()
basic constructor
Definition MWAWList.hxx:55
MWAWListLevel::m_bullet
librevenge::RVNGString m_bullet
the bullet if we have an bullet level
Definition MWAWList.hxx:116
MWAWListLevel::m_type
Type m_type
the type of the level
Definition MWAWList.hxx:103
MWAWListLevel::MWAWListLevel
MWAWListLevel(MWAWListLevel const &)=default
MWAWListLevel::operator<<
friend std::ostream & operator<<(std::ostream &o, MWAWListLevel const &ft)
operator<<
Definition MWAWList.cxx:146
MWAWListLevel::m_labelBeforeSpace
double m_labelBeforeSpace
the extra space between inserting a label
Definition MWAWList.hxx:106
MWAWListLevel::m_label
librevenge::RVNGString m_label
the text label
Definition MWAWList.hxx:113
MWAWListLevel::m_startValue
int m_startValue
the actual value (if this is an ordered level )
Definition MWAWList.hxx:112
MWAWListLevel::operator=
MWAWListLevel & operator=(MWAWListLevel const &)=default
MWAWListLevel::isDefault
bool isDefault() const
returns true if the level type was not set
Definition MWAWList.hxx:78
MWAWListLevel::m_prefix
librevenge::RVNGString m_prefix
string which preceedes the number if we have an ordered level
Definition MWAWList.hxx:114
MWAWListLevel::m_spanId
int m_spanId
the style span id
Definition MWAWList.hxx:118
MWAWListLevel::m_suffix
librevenge::RVNGString m_suffix
string which follows the number if we have an ordered level
Definition MWAWList.hxx:115
MWAWListLevel::m_alignment
Alignment m_alignment
the alignment ( left, center, ...)
Definition MWAWList.hxx:110
MWAWListLevel::operator=
MWAWListLevel & operator=(MWAWListLevel &&)=default
MWAWListLevel::m_numBeforeLabels
int m_numBeforeLabels
the number of label to show before this
Definition MWAWList.hxx:105
MWAWListLevel::m_labelWidth
double m_labelWidth
the minimum label width
Definition MWAWList.hxx:107