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 <libwpd/libwpd.h>
class WPXPropertyList;
class WPXDocumentInterface;
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_labelBeforeSpace(0.0), m_labelWidth(0.1), m_labelAfterSpace(0.0), m_numBeforeLabels(0), m_alignment(LEFT), m_startValue(0),
m_label(""), m_prefix(""), m_suffix(""), m_bullet(""), m_extra("") {
}
~MWAWListLevel() {}
bool isDefault() const {
return m_type ==DEFAULT;
}
bool isNumeric() const {
return m_type !=DEFAULT && m_type !=NONE && m_type != BULLET;
}
void addTo(WPXPropertyList &propList) 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;
double m_labelBeforeSpace ;
double m_labelWidth ;
double m_labelAfterSpace ;
int m_numBeforeLabels;
Alignment m_alignment;
int m_startValue;
WPXString m_label ,
m_prefix ,
m_suffix,
m_bullet ;
std::string m_extra;
};
class MWAWList
{
public:
MWAWList() : m_levels(), m_actLevel(-1), m_actualIndices(), m_nextIndices() {
m_id[0] = m_id[1] = -1;
}
int getId() const {
return m_id[0];
}
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 {
int tmp = m_id[0];
m_id[0] = m_id[1];
m_id[1] = tmp;
}
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;
void sendTo(WPXDocumentInterface &docInterface, int level) const;
protected:
std::vector<MWAWListLevel> m_levels;
mutable int m_actLevel;
mutable std::vector<int> m_actualIndices, m_nextIndices;
mutable int m_id[2];
};
class MWAWListManager
{
public:
MWAWListManager() : m_listList(), m_sendIdList() { }
~MWAWListManager() { }
bool send(int index, WPXDocumentInterface &docInterface) const;
shared_ptr<MWAWList> getList(int index) const;
shared_ptr<MWAWList> getNewList(shared_ptr<MWAWList> actList, int levl, MWAWListLevel const &level);
protected:
void resetSend(size_t id) const;
std::vector<MWAWList> m_listList;
mutable std::vector<bool> m_sendIdList;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWList::MWAWList
MWAWList()
default constructor
Definition: MWAWList.hxx:108
MWAWListLevel::CENTER
Definition: MWAWList.hxx:53
MWAWList::setId
void setId(int newId) const
set the list id
Definition: MWAWList.cxx:239
MWAWListLevel::isDefault
bool isDefault() const
returns true if the level type was not set
Definition: MWAWList.hxx:63
MWAWListLevel::Alignment
Alignment
the item alignement
Definition: MWAWList.hxx:53
MWAWListLevel::~MWAWListLevel
~MWAWListLevel()
destructor
Definition: MWAWList.hxx:60
MWAWListManager::getNewList
shared_ptr< MWAWList > getNewList(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:385
MWAWListLevel::UPPER_ALPHA
Definition: MWAWList.hxx:49
MWAWListLevel::m_labelBeforeSpace
double m_labelBeforeSpace
the extra space between inserting a label
Definition: MWAWList.hxx:86
MWAWList::openElement
void openElement() const
open the list element
Definition: MWAWList.cxx:318
MWAWListLevel::MWAWListLevel
MWAWListLevel()
basic constructor
Definition: MWAWList.hxx:56
MWAWListLevel::cmp
int cmp(MWAWListLevel const &levl) const
comparison function ( compare all values excepted m_startValues
Definition: MWAWList.cxx:103
MWAWListLevel::isNumeric
bool isNumeric() const
returns true if the list is decimal, alpha or roman
Definition: MWAWList.hxx:67
MWAWListLevel::NONE
Definition: MWAWList.hxx:49
MWAWList::updateIndicesFrom
void updateIndicesFrom(MWAWList const &list)
update the indices, the actual level from newList
Definition: MWAWList.cxx:205
MWAWListLevel::LOWER_ALPHA
Definition: MWAWList.hxx:49
MWAWList::getLevel
MWAWListLevel getLevel(int levl) const
returns a level if it exists
Definition: MWAWList.hxx:140
MWAWListLevel
small structure to keep information about a list level
Definition: MWAWList.hxx:47
MWAWListLevel::m_numBeforeLabels
int m_numBeforeLabels
the number of label to show before this
Definition: MWAWList.hxx:90
MWAWList::m_nextIndices
std::vector< int > m_nextIndices
Definition: MWAWList.hxx:176
MWAWList::getStartValueForNextElement
int getStartValueForNextElement() const
returns the startvalue corresponding to the actual level ( or -1 for an unknown/unordered list) ...
Definition: MWAWList.cxx:307
MWAWListLevel::LOWER_ROMAN
Definition: MWAWList.hxx:50
MWAWList::m_id
int m_id[2]
the identificator ( actual and auxilliar )
Definition: MWAWList.hxx:178
MWAWListLevel::m_labelAfterSpace
double m_labelAfterSpace
the minimum distance between the label and the text
Definition: MWAWList.hxx:88
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:111
MWAWList::setStartValueForNextElement
void setStartValueForNextElement(int value)
set the startvalue corresponding to the actual level
Definition: MWAWList.cxx:298
MWAWList::m_levels
std::vector< MWAWListLevel > m_levels
the different levels
Definition: MWAWList.hxx:172
MWAWListLevel::LEFT
Definition: MWAWList.hxx:53
MWAWList::setLevel
void setLevel(int levl) const
set the list level
Definition: MWAWList.cxx:284
MWAWListLevel::m_suffix
WPXString m_suffix
string which follows the number if we have an ordered level
Definition: MWAWList.hxx:95
MWAWListLevel::m_prefix
WPXString m_prefix
string which preceedes the number if we have an ordered level
Definition: MWAWList.hxx:95
MWAWList::getId
int getId() const
returns the list id
Definition: MWAWList.hxx:113
MWAWListLevel::DEFAULT
Definition: MWAWList.hxx:49
MWAWList::sendTo
void sendTo(WPXDocumentInterface &docInterface, int level) const
send the list level information to the document interface.
Definition: MWAWList.cxx:245
MWAWListLevel::RIGHT
Definition: MWAWList.hxx:53
MWAWListLevel::UPPER_ROMAN
Definition: MWAWList.hxx:50
MWAWList::resize
void resize(int levl)
resize the number of level of the list (keeping only n level)
Definition: MWAWList.cxx:190
MWAWList::closeElement
void closeElement() const
close the list element
Definition: MWAWList.hxx:158
MWAWListManager::resetSend
void resetSend(size_t id) const
reset the list id corresponding to a list
Definition: MWAWList.cxx:362
MWAWListManager::getList
shared_ptr< MWAWList > getList(int index) const
returns a list with given index ( if found )
Definition: MWAWList.cxx:372
MWAWListManager
a manager which manages the lists, keeps the different kind of lists, to assure the unicity of each l...
Definition: MWAWList.hxx:182
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:216
MWAWListLevel::DECIMAL
Definition: MWAWList.hxx:49
MWAWListManager::~MWAWListManager
~MWAWListManager()
the destructor
Definition: MWAWList.hxx:188
MWAWListLevel::m_type
Type m_type
the type of the level
Definition: MWAWList.hxx:85
MWAWListLevel::getStartValue
int getStartValue() const
returns the start value (if set) or 1
Definition: MWAWList.hxx:74
MWAWListLevel::LABEL
Definition: MWAWList.hxx:50
MWAWListLevel::operator<<
friend std::ostream & operator<<(std::ostream &o, MWAWListLevel const &ft)
operator<<
Definition: MWAWList.cxx:131
MWAWList::m_actualIndices
std::vector< int > m_actualIndices
Definition: MWAWList.hxx:176
MWAWListManager::m_sendIdList
std::vector< bool > m_sendIdList
the list of send list to interface
Definition: MWAWList.hxx:201
MWAWListLevel::m_extra
std::string m_extra
extra data
Definition: MWAWList.hxx:100
MWAWList::isNumeric
bool isNumeric(int levl) const
returns true is a level is numeric
Definition: MWAWList.cxx:328
MWAWListLevel::BULLET
Definition: MWAWList.hxx:49
MWAWListLevel::m_bullet
WPXString m_bullet
the bullet if we have an bullet level
Definition: MWAWList.hxx:95
MWAWListLevel::m_alignment
Alignment m_alignment
the alignement ( left, center, ...)
Definition: MWAWList.hxx:92
MWAWListLevel::m_label
WPXString m_label
the text label
Definition: MWAWList.hxx:95
MWAWList::numLevels
int numLevels() const
returns the number of level
Definition: MWAWList.hxx:147
MWAWList::swapId
void swapId() const
swap the list id
Definition: MWAWList.hxx:130
MWAWListLevel::m_labelWidth
double m_labelWidth
the minimum label width
Definition: MWAWList.hxx:87
MWAWList
a small structure used to store the informations about a list
Definition: MWAWList.hxx:104
MWAWListLevel::Type
Type
the type of the level
Definition: MWAWList.hxx:49
MWAWListLevel::m_startValue
int m_startValue
the actual value (if this is an ordered level )
Definition: MWAWList.hxx:94
MWAWListManager::MWAWListManager
MWAWListManager()
the constructor
Definition: MWAWList.hxx:186
MWAWList::m_actLevel
int m_actLevel
the actual levels
Definition: MWAWList.hxx:175
MWAWList::set
void set(int levl, MWAWListLevel const &level)
sets a level
Definition: MWAWList.cxx:269
MWAWListManager::m_listList
std::vector< MWAWList > m_listList
the list of created list
Definition: MWAWList.hxx:199
MWAWListManager::send
bool send(int index, WPXDocumentInterface &docInterface) const
send the list to the document interface.
Definition: MWAWList.cxx:341
MWAWListLevel::addTo
void addTo(WPXPropertyList &propList) const
add the information of this level in the propList
Definition: MWAWList.cxx:46