Branch data 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 : 1285 : XFListLevel::XFListLevel()
63 : : {
64 : 1285 : m_nLevel = 0;
65 : 1285 : m_nDisplayLevel = 0;
66 : 1285 : m_fIndent = 0;
67 : 1285 : m_fMinLabelWidth = 0.499;
68 : 1285 : m_fMinLabelDistance = 0;
69 : 1285 : m_eAlign = enumXFAlignStart;
70 : 1285 : m_eListType = enumXFListLevelNumber;
71 : 1285 : }
72 : :
73 : 0 : void XFListLevel::ToXml(IXFStream * /*pStrm*/)
74 : : {
75 : 0 : }
76 : :
77 : : //----------------------------------------------------
78 : :
79 : 550 : void XFListlevelNumber::ToXml(IXFStream *pStrm)
80 : : {
81 : 550 : IXFAttrList *pAttrList = pStrm->GetAttrList();
82 : :
83 : 550 : pAttrList->Clear();
84 [ + - ]: 550 : pAttrList->AddAttribute( A2OUSTR("text:level"), Int16ToOUString(m_nLevel) );
85 : : //text:style-name,ignore now.
86 : 550 : m_aNumFmt.ToXml(pStrm);
87 [ + + ]: 550 : if( m_nDisplayLevel )
88 [ + - ]: 240 : pAttrList->AddAttribute( A2OUSTR("text:display-levels"), Int16ToOUString(m_nDisplayLevel) );
89 : :
90 [ + - ]: 550 : pStrm->StartElement( A2OUSTR("text:list-level-style-number") );
91 : :
92 : : //<style:properties>...</style:properties>
93 : 550 : pAttrList->Clear();
94 [ + + ]: 550 : if( m_fIndent > FLOAT_MIN )
95 : : {
96 [ + - ][ + - ]: 100 : pAttrList->AddAttribute( A2OUSTR("text:space-before"), DoubleToOUString(m_fIndent) + A2OUSTR("cm") );
97 : : }
98 [ + - ]: 550 : if( m_fMinLabelWidth > FLOAT_MIN )
99 : : {
100 [ + - ][ + - ]: 550 : pAttrList->AddAttribute( A2OUSTR("text:min-label-width"), DoubleToOUString(m_fMinLabelWidth) + A2OUSTR("cm") );
101 : : }
102 [ - + ]: 550 : if( m_fMinLabelDistance > FLOAT_MIN )
103 : : {
104 [ # # ][ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("text:min-label-distance"), DoubleToOUString(m_fMinLabelDistance) + A2OUSTR("cm") );
105 : : }
106 [ + - ]: 550 : pAttrList->AddAttribute( A2OUSTR("fo:text-align"), GetAlignName(m_eAlign) );
107 : :
108 : :
109 [ + - ]: 550 : pStrm->StartElement( A2OUSTR("style:properties") );
110 [ + - ]: 550 : pStrm->EndElement( A2OUSTR("style:properties") );
111 : :
112 [ + - ]: 550 : pStrm->EndElement( A2OUSTR("text:list-level-style-number") );
113 : 550 : }
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 : 70 : XFListStyle::XFListStyle()
158 : : {
159 : 70 : XFNumFmt nf;
160 : 70 : nf.SetSuffix( A2OUSTR(".") );
161 : 70 : nf.SetFormat( A2OUSTR("1") );
162 : :
163 [ + + ]: 770 : for( int i=0; i<10; i++ )
164 : : {
165 [ + - ][ + - ]: 700 : m_pListLevels[i] = new XFListlevelNumber();
166 : 700 : m_pListLevels[i]->SetListlevelType(enumXFListLevelNumber);
167 : 700 : m_pListLevels[i]->SetMinLabelWidth(0.499);
168 : 700 : m_pListLevels[i]->SetIndent(0.501*(i+1));
169 : 700 : m_pListLevels[i]->SetLevel(i+1);
170 : 700 : ( (XFListlevelNumber*)m_pListLevels[i])->SetNumFmt(nf);
171 : 70 : }
172 : 70 : }
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 : 70 : XFListStyle::~XFListStyle()
218 : : {
219 [ + + ]: 770 : for( int i=0; i<10; i++ )
220 : : {
221 [ + - ]: 700 : if( m_pListLevels[i] )
222 [ + - ][ + - ]: 700 : delete m_pListLevels[i];
223 : : }
224 [ - + ]: 140 : }
225 : :
226 : 320 : void XFListStyle::SetDisplayLevel(sal_Int32 level, sal_Int16 nDisplayLevel)
227 : : {
228 : : assert(level>=1&&level<=10);
229 : :
230 : 320 : XFListLevel *pLevel = m_pListLevels[level-1];
231 [ - + ]: 320 : 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 : 320 : pLevel->SetDisplayLevel(nDisplayLevel);
243 : 320 : }
244 : :
245 : 585 : 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 : 585 : XFListLevel *pLevel = m_pListLevels[level-1];
255 [ - + ]: 585 : 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 : 585 : pLevel->SetIndent(indent);
269 : 585 : pLevel->SetMinLabelWidth(minLabelWidth);
270 : 585 : pLevel->SetMinLabelDistance(minLabelDistance);
271 : 585 : pLevel->SetAlignType(align);
272 : : }
273 : 585 : }
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 : 585 : void XFListStyle::SetListNumber(sal_Int32 level, XFNumFmt& fmt, sal_Int16 start )
301 : : {
302 : : assert(level>=1&&level<=10);
303 : :
304 [ + - ]: 585 : if( m_pListLevels[level-1] )
305 [ + - ]: 585 : delete m_pListLevels[level-1];
306 : :
307 [ + - ]: 585 : XFListlevelNumber *pLevel = new XFListlevelNumber();
308 : 585 : pLevel->SetNumFmt(fmt);
309 : 585 : pLevel->SetStartValue(start);
310 : : //
311 : 585 : pLevel->SetListlevelType(enumXFListLevelNumber);
312 : 585 : pLevel->SetMinLabelWidth(0.499);
313 : 585 : pLevel->SetIndent(0.501*level);
314 : 585 : pLevel->SetLevel(level);
315 : 585 : m_pListLevels[level-1] = pLevel;
316 : 585 : }
317 : :
318 : 55 : void XFListStyle::ToXml(IXFStream *pStrm)
319 : : {
320 : 55 : std::vector<XFListLevel*>::iterator it;
321 [ + - ]: 55 : IXFAttrList *pAttrList = pStrm->GetAttrList();
322 : :
323 [ + - ]: 55 : pAttrList->Clear();
324 [ + - ][ + - ]: 55 : pAttrList->AddAttribute( A2OUSTR("style:name"), GetStyleName() );
325 [ - + ][ + - ]: 55 : if( !GetParentStyleName().isEmpty() )
326 [ # # ][ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),GetParentStyleName());
327 [ + - ]: 55 : pStrm->StartElement( A2OUSTR("text:list-style") );
328 : :
329 [ + + ]: 605 : for( int i=0; i<10; i++ )
330 : : {
331 : 550 : XFListLevel *pLevel = m_pListLevels[i];
332 [ + - ]: 550 : if( pLevel )
333 [ + - ]: 550 : pLevel->ToXml(pStrm);
334 : : }
335 : :
336 [ + - ]: 55 : pStrm->EndElement( A2OUSTR("text:list-style") );
337 : 55 : }
338 : :
339 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|