filters

ListStyle.cpp
1/* ListStyle: Stores (and writes) list-based information that is
2 * needed at the head of an OO document.
3 *
4 * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 * For further information visit http://libwpd.sourceforge.net
22 *
23 */
24
25/* "This product is not manufactured, approved, or supported by
26 * Corel Corporation or Corel Corporation Limited."
27 */
28#include "FilterInternal.h"
29#include "ListStyle.h"
30#include "DocumentElement.h"
31
32OrderedListLevelStyle::OrderedListLevelStyle(const _SH_PropertyList &xPropList) :
33 mPropList(xPropList)
34{
35}
36
37void OrderedListStyle::updateListLevel(const int iLevel, const _SH_PropertyList &xPropList)
38{
39 if (iLevel < 0)
40 return;
41 if (!isListLevelDefined(iLevel))
42 setListLevel(iLevel, new OrderedListLevelStyle(xPropList));
43}
44
45void OrderedListLevelStyle::write(DocumentHandler &xHandler, int iLevel) const
46{
47 _SH_String sLevel;
48 sLevel.sprintf("%i", (iLevel+1));
49
50 TagOpenElement listLevelStyleOpen("text:list-level-style-number");
51 listLevelStyleOpen.addAttribute("text:level", sLevel);
52 listLevelStyleOpen.addAttribute("text:style-name", "Numbering Symbols");
53 if (mPropList["style:num-prefix"])
54 listLevelStyleOpen.addAttribute("style:num-prefix", mPropList["style:num-prefix"]->getStr());
55 if (mPropList["style:num-suffix"])
56 listLevelStyleOpen.addAttribute("style:num-suffix", mPropList["style:num-suffix"]->getStr());
57 if (mPropList["style:num-format"])
58 listLevelStyleOpen.addAttribute("style:num-format", mPropList["style:num-format"]->getStr());
59 if (mPropList["text:start-value"])
60 listLevelStyleOpen.addAttribute("text:start-value", mPropList["text:start-value"]->getStr());
61 listLevelStyleOpen.write(xHandler);
62
63 TagOpenElement stylePropertiesOpen("style:properties");
64 if (mPropList["text:space-before"])
65 stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
66 if (mPropList["text:min-label-width"])
67 stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
68 if (mPropList["text:min-label-distance"])
69 stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
70 stylePropertiesOpen.write(xHandler);
71
72 xHandler.endElement("style:properties");
73 xHandler.endElement("text:list-level-style-number");
74}
75
76UnorderedListLevelStyle::UnorderedListLevelStyle(const _SH_PropertyList &xPropList)
77 : mPropList(xPropList)
78{
79}
80
81void UnorderedListStyle::updateListLevel(const int iLevel, const _SH_PropertyList &xPropList)
82{
83 if (iLevel < 0)
84 return;
85 if (!isListLevelDefined(iLevel))
86 setListLevel(iLevel, new UnorderedListLevelStyle(xPropList));
87}
88
89void UnorderedListLevelStyle::write(DocumentHandler &xHandler, int iLevel) const
90{
91 _SH_String sLevel;
92 sLevel.sprintf("%i", (iLevel+1));
93 TagOpenElement listLevelStyleOpen("text:list-level-style-bullet");
94 listLevelStyleOpen.addAttribute("text:level", sLevel);
95 listLevelStyleOpen.addAttribute("text:style-name", "Bullet Symbols");
96 listLevelStyleOpen.addAttribute("style:num-suffice", ".");
97 if (mPropList["text:bullet-char"])
98 listLevelStyleOpen.addAttribute("text:bullet-char", mPropList["text:bullet-char"]->getStr());
99 listLevelStyleOpen.write(xHandler);
100
101 TagOpenElement stylePropertiesOpen("style:properties");
102 if (mPropList["text:space-before"])
103 stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
104 if (mPropList["text:min-label-width"])
105 stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
106 if (mPropList["text:min-label-distance"])
107 stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
108 stylePropertiesOpen.addAttribute("style:font-name", "OpenSymbol");
109 stylePropertiesOpen.write(xHandler);
110
111 xHandler.endElement("style:properties");
112 xHandler.endElement("text:list-level-style-bullet");
113}
114
115ListStyle::ListStyle(const char *psName, const int iListID) :
116 Style(psName),
117 miListID(iListID)
118{
119 for (int i=0; i<WP6_NUM_LIST_LEVELS; i++)
120 mppListLevels[i] = NULL;
121
122}
123
124ListStyle::~ListStyle()
125{
126 for (int i=0; i<WP6_NUM_LIST_LEVELS; i++) {
127 if (mppListLevels[i])
128 delete(mppListLevels[i]);
129 }
130
131}
132
133const bool ListStyle::isListLevelDefined(int iLevel) const
134{
135 if (mppListLevels[iLevel] == NULL)
136 return false;
137
138 return true;
139}
140
141void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle)
142{
143 // can't uncomment this next line without adding some extra logic.
144 // figure out which is best: use the initial message, or constantly
145 // update?
146 if (mppListLevels[iLevel] == NULL)
147 mppListLevels[iLevel] = iListLevelStyle;
148}
149
150void ListStyle::write(DocumentHandler &xHandler) const
151{
152 TagOpenElement listStyleOpenElement("text:list-style");
153 listStyleOpenElement.addAttribute("style:name", getName());
154 listStyleOpenElement.write(xHandler);
155
156 for (int i=0; i<WP6_NUM_LIST_LEVELS; i++) {
157 if (mppListLevels[i] != NULL)
158 mppListLevels[i]->write(xHandler, i);
159 }
160
161 xHandler.endElement("text:list-style");
162}