1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libodfgen
3  * Version: MPL 2.0 / LGPLv2.1+
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Major Contributor(s):
10  * Copyright (C) 2002-2003 William Lachance (wrlach@gmail.com)
11  *
12  * For minor contributions see the git repository.
13  *
14  * Alternatively, the contents of this file may be used under the terms
15  * of the GNU Lesser General Public License Version 2.1 or later
16  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
17  * applicable instead of those above.
18  *
19  * For further information visit http://libwpd.sourceforge.net
20  */
21 
22 /* "This product is not manufactured, approved, or supported by
23  * Corel Corporation or Corel Corporation Limited."
24  */
25 #ifndef _LISTSTYLE_HXX_
26 #define _LISTSTYLE_HXX_
27 
28 #include <map>
29 #include <memory>
30 #include <stack>
31 #include <vector>
32 #include <librevenge/librevenge.h>
33 
34 #include "Style.hxx"
35 
36 class ListLevelStyle
37 {
38 public:
~ListLevelStyle()39 	virtual ~ListLevelStyle() {};
40 	virtual void write(OdfDocumentHandler *pHandler, int iLevel) const = 0;
41 };
42 
43 class OrderedListLevelStyle : public ListLevelStyle
44 {
45 public:
46 	explicit OrderedListLevelStyle(const librevenge::RVNGPropertyList &xPropList);
47 	void write(OdfDocumentHandler *pHandler, int iLevel) const override;
48 private:
49 	librevenge::RVNGPropertyList mPropList;
50 };
51 
52 class UnorderedListLevelStyle : public ListLevelStyle
53 {
54 public:
55 	explicit UnorderedListLevelStyle(const librevenge::RVNGPropertyList &xPropList);
56 	void write(OdfDocumentHandler *pHandler, int iLevel) const override;
57 private:
58 	librevenge::RVNGPropertyList mPropList;
59 };
60 
61 class ListStyle : public Style
62 {
63 public:
64 	ListStyle(const char *psName, const int iListID, Style::Zone zone);
65 	~ListStyle() override;
66 	void updateListLevel(const int iLevel, const librevenge::RVNGPropertyList &xPropList, bool ordered);
67 	void write(OdfDocumentHandler *pHandler) const override;
getListID()68 	int getListID()
69 	{
70 		return miListID;
71 	}
72 	bool isListLevelDefined(int iLevel) const;
getDisplayName() const73 	librevenge::RVNGString getDisplayName() const
74 	{
75 		return mDisplayName;
76 	}
setDisplayName(const char * displayName=nullptr)77 	void setDisplayName(const char *displayName=nullptr)
78 	{
79 		if (!displayName || !*displayName)
80 			mDisplayName="";
81 		else
82 			mDisplayName = displayName;
83 	}
84 
85 protected:
86 	void setListLevel(int iLevel, std::unique_ptr<ListLevelStyle> iListLevelStyle);
87 
88 private:
89 	ListStyle(const ListStyle &);
90 	ListStyle &operator=(const ListStyle &);
91 	//! the display name ( if defined)
92 	librevenge::RVNGString mDisplayName;
93 	//! the list id
94 	const int miListID;
95 	std::map<int, std::unique_ptr<ListLevelStyle>> mxListLevels;
96 };
97 
98 /** a list manager */
99 class ListManager
100 {
101 public:
102 	// list state
103 	struct State
104 	{
105 		State();
106 		State(const State &state);
107 
108 		std::shared_ptr<ListStyle> mpCurrentListStyle;
109 		unsigned int miCurrentListLevel;
110 		unsigned int miLastListLevel;
111 		unsigned int miLastListNumber;
112 		bool mbListContinueNumbering;
113 		bool mbListElementParagraphOpened;
114 		std::stack<bool> mbListElementOpened;
115 	private:
116 		State &operator=(const State &state);
117 	};
118 
119 public:
120 	//! constructor
121 	ListManager();
122 	//! destructor
123 	virtual ~ListManager();
124 
125 	/// call to define a list level
126 	void defineLevel(const librevenge::RVNGPropertyList &propList, bool ordered, Style::Zone zone);
127 
128 	/// write all
write(OdfDocumentHandler * pHandler) const129 	virtual void write(OdfDocumentHandler *pHandler) const
130 	{
131 		write(pHandler, Style::Z_Style);
132 		write(pHandler, Style::Z_StyleAutomatic);
133 		write(pHandler, Style::Z_ContentAutomatic);
134 	}
135 	// write automatic/named style
136 	void write(OdfDocumentHandler *pHandler, Style::Zone zone) const;
137 
138 	/// access to the current list state
139 	State &getState();
140 	/// pop the list state (if possible)
141 	void popState();
142 	/// push the list state by adding an empty value
143 	void pushState();
144 
145 protected:
146 	// list styles
147 	unsigned int miNumListStyles;
148 	// list styles
149 	std::vector<std::shared_ptr<ListStyle>> mListStylesVector;
150 	// a map id -> last list style defined with id
151 	std::map<int, std::shared_ptr<ListStyle>> mIdListStyleMap;
152 
153 	//! list states
154 	std::stack<State> mStatesStack;
155 };
156 
157 #endif
158 
159 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
160