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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * For further information visit http://libwpd.sourceforge.net
21 *
22 */
23
24 /* "This product is not manufactured, approved, or supported by
25 * Corel Corporation or Corel Corporation Limited."
26 */
27 #include "FilterInternal.hxx"
28 #include "ListStyle.hxx"
29 #include "DocumentElement.hxx"
30
OrderedListLevelStyle(const WPXPropertyList & xPropList)31 OrderedListLevelStyle::OrderedListLevelStyle(const WPXPropertyList &xPropList) :
32 mPropList(xPropList)
33 {
34 }
35
updateListLevel(const int iLevel,const WPXPropertyList & xPropList)36 void OrderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList)
37 {
38 if (iLevel < 0)
39 return;
40 if (!isListLevelDefined(iLevel))
41 setListLevel(iLevel, new OrderedListLevelStyle(xPropList));
42 }
43
write(DocumentHandler * pHandler,int iLevel) const44 void OrderedListLevelStyle::write(DocumentHandler *pHandler, int iLevel) const
45 {
46 WPXString sLevel;
47 sLevel.sprintf("%i", (iLevel+1));
48
49 TagOpenElement listLevelStyleOpen("text:list-level-style-number");
50 listLevelStyleOpen.addAttribute("text:level", sLevel);
51 listLevelStyleOpen.addAttribute("text:style-name", "Numbering Symbols");
52 if (mPropList["style:num-prefix"])
53 listLevelStyleOpen.addAttribute("style:num-prefix", mPropList["style:num-prefix"]->getStr());
54 if (mPropList["style:num-suffix"])
55 listLevelStyleOpen.addAttribute("style:num-suffix", mPropList["style:num-suffix"]->getStr());
56 if (mPropList["style:num-format"])
57 listLevelStyleOpen.addAttribute("style:num-format", mPropList["style:num-format"]->getStr());
58 if (mPropList["text:start-value"])
59 listLevelStyleOpen.addAttribute("text:start-value", mPropList["text:start-value"]->getStr());
60 listLevelStyleOpen.write(pHandler);
61
62 TagOpenElement stylePropertiesOpen("style:properties");
63 if (mPropList["text:space-before"])
64 stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
65 if (mPropList["text:min-label-width"])
66 stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
67 if (mPropList["text:min-label-distance"])
68 stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
69 stylePropertiesOpen.write(pHandler);
70
71 pHandler->endElement("style:properties");
72 pHandler->endElement("text:list-level-style-number");
73 }
74
UnorderedListLevelStyle(const WPXPropertyList & xPropList)75 UnorderedListLevelStyle::UnorderedListLevelStyle(const WPXPropertyList &xPropList)
76 : mPropList(xPropList)
77 {
78 }
79
updateListLevel(const int iLevel,const WPXPropertyList & xPropList)80 void UnorderedListStyle::updateListLevel(const int iLevel, const WPXPropertyList &xPropList)
81 {
82 if (iLevel < 0)
83 return;
84 if (!isListLevelDefined(iLevel))
85 setListLevel(iLevel, new UnorderedListLevelStyle(xPropList));
86 }
87
write(DocumentHandler * pHandler,int iLevel) const88 void UnorderedListLevelStyle::write(DocumentHandler *pHandler, int iLevel) const
89 {
90 WPXString sLevel;
91 sLevel.sprintf("%i", (iLevel+1));
92 TagOpenElement listLevelStyleOpen("text:list-level-style-bullet");
93 listLevelStyleOpen.addAttribute("text:level", sLevel);
94 listLevelStyleOpen.addAttribute("text:style-name", "Bullet Symbols");
95 listLevelStyleOpen.addAttribute("style:num-suffice", ".");
96 if (mPropList["text:bullet-char"])
97 listLevelStyleOpen.addAttribute("text:bullet-char", mPropList["text:bullet-char"]->getStr());
98 listLevelStyleOpen.write(pHandler);
99
100 TagOpenElement stylePropertiesOpen("style:properties");
101 if (mPropList["text:space-before"])
102 stylePropertiesOpen.addAttribute("text:space-before", mPropList["text:space-before"]->getStr());
103 if (mPropList["text:min-label-width"])
104 stylePropertiesOpen.addAttribute("text:min-label-width", mPropList["text:min-label-width"]->getStr());
105 if (mPropList["text:min-label-distance"])
106 stylePropertiesOpen.addAttribute("text:min-label-distance", mPropList["text:min-label-distance"]->getStr());
107 stylePropertiesOpen.addAttribute("style:font-name", "OpenSymbol");
108 stylePropertiesOpen.write(pHandler);
109
110 pHandler->endElement("style:properties");
111 pHandler->endElement("text:list-level-style-bullet");
112 }
113
ListStyle(const char * psName,const int iListID)114 ListStyle::ListStyle(const char *psName, const int iListID) :
115 Style(psName),
116 miListID(iListID)
117 {
118 for (int i=0; i<WP6_NUM_LIST_LEVELS; i++)
119 mppListLevels[i] = NULL;
120
121 }
122
~ListStyle()123 ListStyle::~ListStyle()
124 {
125 for (int i=0; i<WP6_NUM_LIST_LEVELS; i++) {
126 if (mppListLevels[i])
127 delete(mppListLevels[i]);
128 }
129
130 }
131
isListLevelDefined(int iLevel) const132 bool ListStyle::isListLevelDefined(int iLevel) const
133 {
134 if (mppListLevels[iLevel] == NULL)
135 return false;
136
137 return true;
138 }
139
setListLevel(int iLevel,ListLevelStyle * iListLevelStyle)140 void ListStyle::setListLevel(int iLevel, ListLevelStyle *iListLevelStyle)
141 {
142 // can't uncomment this next line without adding some extra logic.
143 // figure out which is best: use the initial message, or constantly
144 // update?
145 if (mppListLevels[iLevel] == NULL)
146 mppListLevels[iLevel] = iListLevelStyle;
147 }
148
write(DocumentHandler * pHandler) const149 void ListStyle::write(DocumentHandler *pHandler) const
150 {
151 TagOpenElement listStyleOpenElement("text:list-style");
152 listStyleOpenElement.addAttribute("style:name", getName());
153 listStyleOpenElement.write(pHandler);
154
155 for (int i=0; i<WP6_NUM_LIST_LEVELS; i++) {
156 if (mppListLevels[i] != NULL)
157 mppListLevels[i]->write(pHandler, i);
158 }
159
160 pHandler->endElement("text:list-style");
161 }
162