Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /*************************************************************************
57 : * @file
58 : * Styles for ordered list and unordered list.
59 : ************************************************************************/
60 : #include "xfliststyle.hxx"
61 :
62 257 : XFListLevel::XFListLevel()
63 : {
64 257 : m_nLevel = 0;
65 257 : m_nDisplayLevel = 0;
66 257 : m_fIndent = 0;
67 257 : m_fMinLabelWidth = 0.499;
68 257 : m_fMinLabelDistance = 0;
69 257 : m_eAlign = enumXFAlignStart;
70 257 : m_eListType = enumXFListLevelNumber;
71 257 : }
72 :
73 0 : void XFListLevel::ToXml(IXFStream * /*pStrm*/)
74 : {
75 0 : }
76 :
77 : //----------------------------------------------------
78 :
79 110 : void XFListlevelNumber::ToXml(IXFStream *pStrm)
80 : {
81 110 : IXFAttrList *pAttrList = pStrm->GetAttrList();
82 :
83 110 : pAttrList->Clear();
84 110 : pAttrList->AddAttribute( A2OUSTR("text:level"), Int16ToOUString(m_nLevel) );
85 : //text:style-name,ignore now.
86 110 : m_aNumFmt.ToXml(pStrm);
87 110 : if( m_nDisplayLevel )
88 48 : pAttrList->AddAttribute( A2OUSTR("text:display-levels"), Int16ToOUString(m_nDisplayLevel) );
89 :
90 110 : pStrm->StartElement( A2OUSTR("text:list-level-style-number") );
91 :
92 : //<style:properties>...</style:properties>
93 110 : pAttrList->Clear();
94 110 : if( m_fIndent > FLOAT_MIN )
95 : {
96 20 : pAttrList->AddAttribute( A2OUSTR("text:space-before"), DoubleToOUString(m_fIndent) + A2OUSTR("cm") );
97 : }
98 110 : if( m_fMinLabelWidth > FLOAT_MIN )
99 : {
100 110 : pAttrList->AddAttribute( A2OUSTR("text:min-label-width"), DoubleToOUString(m_fMinLabelWidth) + A2OUSTR("cm") );
101 : }
102 110 : if( m_fMinLabelDistance > FLOAT_MIN )
103 : {
104 0 : pAttrList->AddAttribute( A2OUSTR("text:min-label-distance"), DoubleToOUString(m_fMinLabelDistance) + A2OUSTR("cm") );
105 : }
106 110 : pAttrList->AddAttribute( A2OUSTR("fo:text-align"), GetAlignName(m_eAlign) );
107 :
108 :
109 110 : pStrm->StartElement( A2OUSTR("style:properties") );
110 110 : pStrm->EndElement( A2OUSTR("style:properties") );
111 :
112 110 : pStrm->EndElement( A2OUSTR("text:list-level-style-number") );
113 110 : }
114 :
115 0 : void XFListLevelBullet::ToXml(IXFStream *pStrm)
116 : {
117 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
118 :
119 0 : pAttrList->Clear();
120 0 : pAttrList->AddAttribute( A2OUSTR("text:level"), Int16ToOUString(m_nLevel) );
121 : //text:style-name,ignore now.
122 0 : m_aNumFmt.ToXml(pStrm);
123 : //bullet-char
124 0 : rtl::OUString bullet(m_chBullet);
125 0 : pAttrList->AddAttribute( A2OUSTR("text:bullet-char"), bullet );
126 :
127 0 : pStrm->StartElement( A2OUSTR("text:list-level-style-bullet") );
128 :
129 : //<style:properties>...</style:properties>
130 0 : pAttrList->Clear();
131 0 : if( m_fIndent != 0 )
132 : {
133 0 : pAttrList->AddAttribute( A2OUSTR("text:space-before"), DoubleToOUString(m_fIndent) + A2OUSTR("cm") );
134 : }
135 0 : if( m_fMinLabelWidth != 0 )
136 : {
137 0 : pAttrList->AddAttribute( A2OUSTR("text:min-label-width"), DoubleToOUString(m_fMinLabelWidth) + A2OUSTR("cm") );
138 : }
139 0 : if( m_fMinLabelDistance != 0 )
140 : {
141 0 : pAttrList->AddAttribute( A2OUSTR("text:min-label-distance"), DoubleToOUString(m_fMinLabelDistance) + A2OUSTR("cm") );
142 : }
143 :
144 0 : pAttrList->AddAttribute( A2OUSTR("fo:text-align"), GetAlignName(m_eAlign) );
145 :
146 0 : if( !m_strFontName.isEmpty() )
147 : {
148 0 : pAttrList->AddAttribute( A2OUSTR("style:font-name"), m_strFontName );
149 : }
150 0 : pStrm->StartElement( A2OUSTR("style:properties") );
151 0 : pStrm->EndElement( A2OUSTR("style:properties") );
152 :
153 0 : pStrm->EndElement( A2OUSTR("text:list-level-style-bullet") );
154 0 : }
155 :
156 : //----------------------------------------------------
157 14 : XFListStyle::XFListStyle()
158 : {
159 14 : XFNumFmt nf;
160 14 : nf.SetSuffix( A2OUSTR(".") );
161 14 : nf.SetFormat( A2OUSTR("1") );
162 :
163 154 : for( int i=0; i<10; i++ )
164 : {
165 140 : m_pListLevels[i] = new XFListlevelNumber();
166 140 : m_pListLevels[i]->SetListlevelType(enumXFListLevelNumber);
167 140 : m_pListLevels[i]->SetMinLabelWidth(0.499);
168 140 : m_pListLevels[i]->SetIndent(0.501*(i+1));
169 140 : m_pListLevels[i]->SetLevel(i+1);
170 140 : ( (XFListlevelNumber*)m_pListLevels[i])->SetNumFmt(nf);
171 14 : }
172 14 : }
173 :
174 0 : XFListStyle::XFListStyle(const XFListStyle& other):XFStyle(other)
175 : {
176 : enumXFListLevel type;
177 0 : for( int i=0; i<10; i++ )
178 : {
179 0 : type = other.m_pListLevels[i]->m_eListType;
180 0 : if( type == enumXFListLevelNumber )
181 : {
182 0 : XFListlevelNumber *pNum = (XFListlevelNumber*)other.m_pListLevels[i];
183 0 : m_pListLevels[i] = new XFListlevelNumber(*pNum);
184 : }
185 0 : else if( type == enumXFListLevelBullet )
186 : {
187 0 : XFListLevelBullet *pBullet = (XFListLevelBullet*)other.m_pListLevels[i];
188 0 : m_pListLevels[i] = new XFListLevelBullet(*pBullet);
189 : }
190 : else
191 0 : m_pListLevels[i] = NULL;
192 : }
193 0 : }
194 :
195 0 : XFListStyle& XFListStyle::operator=(const XFListStyle& other)
196 : {
197 : enumXFListLevel type;
198 0 : for( int i=0; i<10; i++ )
199 : {
200 0 : type = other.m_pListLevels[i]->m_eListType;
201 0 : if( type == enumXFListLevelNumber )
202 : {
203 0 : XFListlevelNumber *pNum = (XFListlevelNumber*)m_pListLevels[i];
204 0 : m_pListLevels[i] = new XFListlevelNumber(*pNum);
205 : }
206 0 : else if( type == enumXFListLevelBullet )
207 : {
208 0 : XFListLevelBullet *pBullet = (XFListLevelBullet*)m_pListLevels[i];
209 0 : m_pListLevels[i] = new XFListLevelBullet(*pBullet);
210 : }
211 : else
212 0 : m_pListLevels[i] = NULL;
213 : }
214 0 : return *this;
215 : }
216 :
217 42 : XFListStyle::~XFListStyle()
218 : {
219 154 : for( int i=0; i<10; i++ )
220 : {
221 140 : if( m_pListLevels[i] )
222 140 : delete m_pListLevels[i];
223 : }
224 28 : }
225 :
226 64 : void XFListStyle::SetDisplayLevel(sal_Int32 level, sal_Int16 nDisplayLevel)
227 : {
228 : assert(level>=1&&level<=10);
229 :
230 64 : XFListLevel *pLevel = m_pListLevels[level-1];
231 64 : if( !pLevel )
232 : {
233 0 : pLevel = new XFListlevelNumber();
234 0 : pLevel->SetListlevelType(enumXFListLevelNumber);
235 0 : pLevel->SetLevel(level+1);
236 0 : pLevel->SetMinLabelWidth(0.499);
237 0 : pLevel->SetIndent(0.501*(level+1));
238 0 : pLevel->SetDisplayLevel(nDisplayLevel);
239 0 : m_pListLevels[level-1] = pLevel;
240 : }
241 : else
242 64 : pLevel->SetDisplayLevel(nDisplayLevel);
243 64 : }
244 :
245 117 : void XFListStyle::SetListPosition(sal_Int32 level,
246 : double indent,
247 : double minLabelWidth,
248 : double minLabelDistance,
249 : enumXFAlignType align
250 : )
251 : {
252 : assert(level>=1&&level<=10);
253 :
254 117 : XFListLevel *pLevel = m_pListLevels[level-1];
255 117 : if( !pLevel )
256 : {
257 0 : pLevel = new XFListLevelBullet();
258 0 : pLevel->SetListlevelType(enumXFListLevelNumber);
259 0 : pLevel->SetLevel(level+1);
260 0 : pLevel->SetIndent(indent);
261 0 : pLevel->SetMinLabelWidth(minLabelWidth);
262 0 : pLevel->SetMinLabelDistance(minLabelDistance);
263 0 : pLevel->SetAlignType(align);
264 0 : m_pListLevels[level-1] = pLevel;
265 : }
266 : else
267 : {
268 117 : pLevel->SetIndent(indent);
269 117 : pLevel->SetMinLabelWidth(minLabelWidth);
270 117 : pLevel->SetMinLabelDistance(minLabelDistance);
271 117 : pLevel->SetAlignType(align);
272 : }
273 117 : }
274 :
275 0 : void XFListStyle::SetListBullet(sal_Int32 level,
276 : UChar32 bullet,
277 : rtl::OUString fontname,
278 : rtl::OUString prefix,
279 : rtl::OUString suffix
280 : )
281 : {
282 : assert(level>=1&&level<=10);
283 :
284 0 : if( m_pListLevels[level-1] )
285 0 : delete m_pListLevels[level-1];
286 :
287 0 : XFListLevelBullet *pLevel = new XFListLevelBullet();
288 0 : pLevel->SetPrefix(prefix);
289 0 : pLevel->SetSuffix(suffix);
290 0 : pLevel->SetBulletChar(bullet);
291 0 : pLevel->SetFontName(fontname);
292 : //
293 0 : pLevel->SetListlevelType(enumXFListLevelBullet);
294 0 : pLevel->SetMinLabelWidth(0.499);
295 0 : pLevel->SetIndent(0.501*level);
296 0 : pLevel->SetLevel(level);
297 0 : m_pListLevels[level-1] = pLevel;
298 0 : }
299 :
300 117 : void XFListStyle::SetListNumber(sal_Int32 level, XFNumFmt& fmt, sal_Int16 start )
301 : {
302 : assert(level>=1&&level<=10);
303 :
304 117 : if( m_pListLevels[level-1] )
305 117 : delete m_pListLevels[level-1];
306 :
307 117 : XFListlevelNumber *pLevel = new XFListlevelNumber();
308 117 : pLevel->SetNumFmt(fmt);
309 117 : pLevel->SetStartValue(start);
310 : //
311 117 : pLevel->SetListlevelType(enumXFListLevelNumber);
312 117 : pLevel->SetMinLabelWidth(0.499);
313 117 : pLevel->SetIndent(0.501*level);
314 117 : pLevel->SetLevel(level);
315 117 : m_pListLevels[level-1] = pLevel;
316 117 : }
317 :
318 11 : void XFListStyle::ToXml(IXFStream *pStrm)
319 : {
320 11 : IXFAttrList *pAttrList = pStrm->GetAttrList();
321 :
322 11 : pAttrList->Clear();
323 11 : pAttrList->AddAttribute( A2OUSTR("style:name"), GetStyleName() );
324 11 : if( !GetParentStyleName().isEmpty() )
325 0 : pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),GetParentStyleName());
326 11 : pStrm->StartElement( A2OUSTR("text:list-style") );
327 :
328 121 : for( int i=0; i<10; i++ )
329 : {
330 110 : XFListLevel *pLevel = m_pListLevels[i];
331 110 : if( pLevel )
332 110 : pLevel->ToXml(pStrm);
333 : }
334 :
335 11 : pStrm->EndElement( A2OUSTR("text:list-style") );
336 11 : }
337 :
338 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|