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 <librevenge/librevenge.h>
00042 
00044 struct MWAWListLevel {
00046   enum Type { DEFAULT, NONE, BULLET, DECIMAL, LOWER_ALPHA, UPPER_ALPHA,
00047               LOWER_ROMAN, UPPER_ROMAN, LABEL
00048             };
00050   enum Alignment { LEFT, RIGHT, CENTER };
00051 
00053   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),
00054     m_label(""), m_prefix(""), m_suffix(""), m_bullet(""), m_extra("")
00055   {
00056   }
00058   ~MWAWListLevel() {}
00059 
00061   bool isDefault() const
00062   {
00063     return m_type ==DEFAULT;
00064   }
00066   bool isNumeric() const
00067   {
00068     return m_type !=DEFAULT && m_type !=NONE && m_type != BULLET;
00069   }
00071   void addTo(librevenge::RVNGPropertyList &propList) const;
00072 
00074   int getStartValue() const
00075   {
00076     return m_startValue <= 0 ? 1 : m_startValue;
00077   }
00078 
00080   int cmp(MWAWListLevel const &levl) const;
00081 
00083   friend std::ostream &operator<<(std::ostream &o, MWAWListLevel const &ft);
00084 
00086   Type m_type;
00087   double m_labelBeforeSpace ;
00088   double m_labelWidth ;
00089   double m_labelAfterSpace ;
00091   int m_numBeforeLabels;
00093   Alignment m_alignment;
00095   int m_startValue;
00096   librevenge::RVNGString m_label ,
00097              m_prefix ,
00098              m_suffix,
00099              m_bullet ;
00101   std::string m_extra;
00102 };
00103 
00105 class MWAWList
00106 {
00107 public:
00109   MWAWList() : m_levels(), m_actLevel(-1), m_actualIndices(), m_nextIndices(), m_modifyMarker(1)
00110   {
00111     m_id[0] = m_id[1] = -1;
00112   }
00113 
00115   int getId() const
00116   {
00117     return m_id[0];
00118   }
00119 
00121   int getMarker() const
00122   {
00123     return m_modifyMarker;
00124   }
00126   void resize(int levl);
00128   bool isCompatibleWith(int levl, MWAWListLevel const &level) const;
00130   bool isCompatibleWith(MWAWList const &newList) const;
00132   void updateIndicesFrom(MWAWList const &list);
00133 
00138   void swapId() const
00139   {
00140     int tmp = m_id[0];
00141     m_id[0] = m_id[1];
00142     m_id[1] = tmp;
00143   }
00144 
00146   void setId(int newId) const;
00147 
00149   MWAWListLevel getLevel(int levl) const
00150   {
00151     if (levl >= 0 && levl < int(m_levels.size()))
00152       return m_levels[size_t(levl)];
00153     MWAW_DEBUG_MSG(("MWAWList::getLevel: can not find level %d\n", levl));
00154     return MWAWListLevel();
00155   }
00157   int numLevels() const
00158   {
00159     return int(m_levels.size());
00160   }
00162   void set(int levl, MWAWListLevel const &level);
00163 
00165   void setLevel(int levl) const;
00167   void openElement() const;
00169   void closeElement() const {}
00171   int getStartValueForNextElement() const;
00173   void setStartValueForNextElement(int value);
00174 
00176   bool isNumeric(int levl) const;
00177 
00179   bool addTo(int level, librevenge::RVNGPropertyList &pList) const;
00180 
00181 protected:
00183   std::vector<MWAWListLevel> m_levels;
00184 
00186   mutable int m_actLevel;
00187   mutable std::vector<int> m_actualIndices, m_nextIndices;
00189   mutable int m_id[2];
00191   mutable int m_modifyMarker;
00192 };
00193 
00195 class MWAWListManager
00196 {
00197 public:
00199   MWAWListManager() : m_listList(), m_sendIdMarkerList() { }
00201   ~MWAWListManager() { }
00203   bool needToSend(int index, std::vector<int> &idMarkerList) const;
00205   shared_ptr<MWAWList> getList(int index) const;
00207   shared_ptr<MWAWList> getNewList(shared_ptr<MWAWList> actList, int levl, MWAWListLevel const &level);
00208 protected:
00210   std::vector<MWAWList> m_listList;
00212   mutable std::vector<int> m_sendIdMarkerList;
00213 };
00214 #endif
00215 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: