MWAWList.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 #ifndef MWAW_LIST_H
00035 #  define MWAW_LIST_H
00036 
00037 #include <iostream>
00038 
00039 #include <vector>
00040 
00041 #include <libwpd/libwpd.h>
00042 
00043 class WPXPropertyList;
00044 
00046 struct MWAWListLevel {
00048   enum Type { DEFAULT, NONE, BULLET, DECIMAL, LOWER_ALPHA, UPPER_ALPHA,
00049               LOWER_ROMAN, UPPER_ROMAN, LABEL
00050             };
00052   enum Alignment { LEFT, RIGHT, CENTER };
00053 
00055   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),
00056     m_label(""), m_prefix(""), m_suffix(""), m_bullet(""), m_extra("") {
00057   }
00059   ~MWAWListLevel() {}
00060 
00062   bool isDefault() const {
00063     return m_type ==DEFAULT;
00064   }
00066   bool isNumeric() const {
00067     return m_type !=DEFAULT && m_type !=NONE && m_type != BULLET;
00068   }
00070   void addTo(WPXPropertyList &propList) const;
00071 
00073   int getStartValue() const {
00074     return m_startValue <= 0 ? 1 : m_startValue;
00075   }
00076 
00078   int cmp(MWAWListLevel const &levl) const;
00079 
00081   friend std::ostream &operator<<(std::ostream &o, MWAWListLevel const &ft);
00082 
00084   Type m_type;
00085   double m_labelBeforeSpace ;
00086   double m_labelWidth ;
00087   double m_labelAfterSpace ;
00089   int m_numBeforeLabels;
00091   Alignment m_alignment;
00093   int m_startValue;
00094   WPXString m_label ,
00095             m_prefix ,
00096             m_suffix,
00097             m_bullet ;
00099   std::string m_extra;
00100 };
00101 
00103 class MWAWList
00104 {
00105 public:
00107   MWAWList() : m_levels(), m_actLevel(-1), m_actualIndices(), m_nextIndices(), m_modifyMarker(1) {
00108     m_id[0] = m_id[1] = -1;
00109   }
00110 
00112   int getId() const {
00113     return m_id[0];
00114   }
00115 
00117   int getMarker() const {
00118     return m_modifyMarker;
00119   }
00121   void resize(int levl);
00123   bool isCompatibleWith(int levl, MWAWListLevel const &level) const;
00125   bool isCompatibleWith(MWAWList const &newList) const;
00127   void updateIndicesFrom(MWAWList const &list);
00128 
00133   void swapId() const {
00134     int tmp = m_id[0];
00135     m_id[0] = m_id[1];
00136     m_id[1] = tmp;
00137   }
00138 
00140   void setId(int newId) const;
00141 
00143   MWAWListLevel getLevel(int levl) const {
00144     if (levl >= 0 && levl < int(m_levels.size()))
00145       return m_levels[size_t(levl)];
00146     MWAW_DEBUG_MSG(("MWAWList::getLevel: can not find level %d\n", levl));
00147     return MWAWListLevel();
00148   }
00150   int numLevels() const {
00151     return int(m_levels.size());
00152   }
00154   void set(int levl, MWAWListLevel const &level);
00155 
00157   void setLevel(int levl) const;
00159   void openElement() const;
00161   void closeElement() const {}
00163   int getStartValueForNextElement() const;
00165   void setStartValueForNextElement(int value);
00166 
00168   bool isNumeric(int levl) const;
00169 
00171   bool addTo(int level, WPXPropertyList &pList) const;
00172 
00173 protected:
00175   std::vector<MWAWListLevel> m_levels;
00176 
00178   mutable int m_actLevel;
00179   mutable std::vector<int> m_actualIndices, m_nextIndices;
00181   mutable int m_id[2];
00183   mutable int m_modifyMarker;
00184 };
00185 
00187 class MWAWListManager
00188 {
00189 public:
00191   MWAWListManager() : m_listList(), m_sendIdMarkerList() { }
00193   ~MWAWListManager() { }
00195   bool needToSend(int index, std::vector<int> &idMarkerList) const;
00197   shared_ptr<MWAWList> getList(int index) const;
00199   shared_ptr<MWAWList> getNewList(shared_ptr<MWAWList> actList, int levl, MWAWListLevel const &level);
00200 protected:
00202   std::vector<MWAWList> m_listList;
00204   mutable std::vector<int> m_sendIdMarkerList;
00205 };
00206 #endif
00207 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: