STOFFList.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 /* libstaroffice
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 STOFF_LIST_H
00035 #  define STOFF_LIST_H
00036 
00037 #include <iostream>
00038 
00039 #include <vector>
00040 
00041 #include <librevenge/librevenge.h>
00042 
00043 #include "libstaroffice_internal.hxx"
00044 
00045 class STOFFFont;
00046 
00048 struct STOFFListLevel {
00050   enum Type { DEFAULT, NONE, BULLET, NUMBER };
00051 
00053   STOFFListLevel() : m_type(NONE), m_propertyList(), m_font(),
00054     m_startValue(0)
00055   {
00056   }
00058   ~STOFFListLevel();
00059 
00061   bool isDefault() const
00062   {
00063     return m_type ==DEFAULT;
00064   }
00066   bool isNumeric() const
00067   {
00068     return m_type==NUMBER;
00069   }
00071   bool operator==(STOFFListLevel const &levl) const
00072   {
00073     return cmp(levl)==0;
00074   }
00076   bool operator!=(STOFFListLevel const &levl) const
00077   {
00078     return !operator==(levl);
00079   }
00081   void addTo(librevenge::RVNGPropertyList &propList) const;
00082 
00084   int getStartValue() const
00085   {
00086     return m_startValue <= 0 ? 1 : m_startValue;
00087   }
00088 
00090   int cmp(STOFFListLevel const &levl) const;
00092   Type m_type;
00094   librevenge::RVNGPropertyList m_propertyList;
00096   shared_ptr<STOFFFont> m_font;
00098   int m_startValue;
00099 };
00100 
00102 class STOFFList
00103 {
00104 public:
00106   explicit STOFFList(bool outline) : m_outline(outline), m_name(""), m_levels(), m_actLevel(-1), m_actualIndices(), m_nextIndices(), m_modifyMarker(1)
00107   {
00108     m_id[0] = m_id[1] = -1;
00109   }
00110 
00112   int getId() const
00113   {
00114     return m_id[0];
00115   }
00116 
00118   int getMarker() const
00119   {
00120     return m_modifyMarker;
00121   }
00123   void resize(int levl);
00125   bool isCompatibleWith(int levl, STOFFListLevel const &level) const;
00127   bool isCompatibleWith(STOFFList const &newList) const;
00129   void updateIndicesFrom(STOFFList const &list);
00130 
00135   void swapId() const
00136   {
00137     int tmp = m_id[0];
00138     m_id[0] = m_id[1];
00139     m_id[1] = tmp;
00140   }
00141 
00143   void setId(int newId) const;
00144 
00146   STOFFListLevel getLevel(int levl) const
00147   {
00148     if (levl >= 0 && levl < int(m_levels.size()))
00149       return m_levels[size_t(levl)];
00150     STOFF_DEBUG_MSG(("STOFFList::getLevel: can not find level %d\n", levl));
00151     return STOFFListLevel();
00152   }
00154   int numLevels() const
00155   {
00156     return int(m_levels.size());
00157   }
00159   void set(int levl, STOFFListLevel const &level);
00160 
00162   void setLevel(int levl) const;
00164   void openElement() const;
00166   void closeElement() const {}
00168   int getStartValueForNextElement() const;
00170   void setStartValueForNextElement(int value);
00171 
00173   bool isNumeric(int levl) const;
00174 
00176   bool addTo(int level, librevenge::RVNGPropertyList &pList) const;
00177 
00179   bool m_outline;
00181   librevenge::RVNGString m_name;
00182 protected:
00184   std::vector<STOFFListLevel> m_levels;
00185 
00187   mutable int m_actLevel;
00188   mutable std::vector<int> m_actualIndices, m_nextIndices;
00190   mutable int m_id[2];
00192   mutable int m_modifyMarker;
00193 };
00194 
00196 class STOFFListManager
00197 {
00198 public:
00200   STOFFListManager() : m_listList(), m_sendIdMarkerList() { }
00202   ~STOFFListManager() { }
00204   bool needToSend(int index, std::vector<int> &idMarkerList) const;
00206   shared_ptr<STOFFList> getList(int index) const;
00208   shared_ptr<STOFFList> getNewList(shared_ptr<STOFFList> actList, int levl, STOFFListLevel const &level);
00210   shared_ptr<STOFFList> addList(shared_ptr<STOFFList> actList);
00211 protected:
00213   std::vector<STOFFList> m_listList;
00215   mutable std::vector<int> m_sendIdMarkerList;
00216 };
00217 #endif
00218 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: