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 110 : void XFListlevelNumber::ToXml(IXFStream *pStrm)
78 : {
79 110 : IXFAttrList *pAttrList = pStrm->GetAttrList();
80 :
81 110 : pAttrList->Clear();
82 110 : pAttrList->AddAttribute( "text:level", OUString::number((sal_Int32)m_nLevel) );
83 : //text:style-name,ignore now.
84 110 : m_aNumFmt.ToXml(pStrm);
85 110 : if( m_nDisplayLevel )
86 48 : pAttrList->AddAttribute( "text:display-levels", OUString::number((sal_Int32)m_nDisplayLevel) );
87 :
88 110 : pStrm->StartElement( "text:list-level-style-number" );
89 :
90 : //<style:properties>...</style:properties>
91 110 : pAttrList->Clear();
92 110 : if( m_fIndent > FLOAT_MIN )
93 : {
94 20 : pAttrList->AddAttribute( "text:space-before", OUString::number(m_fIndent) + "cm" );
95 : }
96 110 : if( m_fMinLabelWidth > FLOAT_MIN )
97 : {
98 110 : pAttrList->AddAttribute( "text:min-label-width", OUString::number(m_fMinLabelWidth) + "cm" );
99 : }
100 110 : if( m_fMinLabelDistance > FLOAT_MIN )
101 : {
102 0 : pAttrList->AddAttribute( "text:min-label-distance", OUString::number(m_fMinLabelDistance) + "cm" );
103 : }
104 110 : pAttrList->AddAttribute( "fo:text-align", GetAlignName(m_eAlign) );
105 :
106 110 : pStrm->StartElement( "style:properties" );
107 110 : pStrm->EndElement( "style:properties" );
108 :
109 110 : pStrm->EndElement( "text:list-level-style-number" );
110 110 : }
111 :
112 0 : void XFListLevelBullet::ToXml(IXFStream *pStrm)
113 : {
114 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
115 :
116 0 : pAttrList->Clear();
117 0 : pAttrList->AddAttribute( "text:level", OUString::number((sal_Int32)m_nLevel) );
118 : //text:style-name,ignore now.
119 0 : m_aNumFmt.ToXml(pStrm);
120 : //bullet-char
121 0 : OUString bullet(m_chBullet);
122 0 : pAttrList->AddAttribute( "text:bullet-char", bullet );
123 :
124 0 : pStrm->StartElement( "text:list-level-style-bullet" );
125 :
126 : //<style:properties>...</style:properties>
127 0 : pAttrList->Clear();
128 0 : if( m_fIndent != 0 )
129 : {
130 0 : pAttrList->AddAttribute( "text:space-before", OUString::number(m_fIndent) + "cm" );
131 : }
132 0 : if( m_fMinLabelWidth != 0 )
133 : {
134 0 : pAttrList->AddAttribute( "text:min-label-width", OUString::number(m_fMinLabelWidth) + "cm" );
135 : }
136 0 : if( m_fMinLabelDistance != 0 )
137 : {
138 0 : pAttrList->AddAttribute( "text:min-label-distance", OUString::number(m_fMinLabelDistance) + "cm" );
139 : }
140 :
141 0 : pAttrList->AddAttribute( "fo:text-align", GetAlignName(m_eAlign) );
142 :
143 0 : if( !m_strFontName.isEmpty() )
144 : {
145 0 : pAttrList->AddAttribute( "style:font-name", m_strFontName );
146 : }
147 0 : pStrm->StartElement( "style:properties" );
148 0 : pStrm->EndElement( "style:properties" );
149 :
150 0 : pStrm->EndElement( "text:list-level-style-bullet" );
151 0 : }
152 :
153 14 : XFListStyle::XFListStyle()
154 : {
155 14 : XFNumFmt nf;
156 14 : nf.SetSuffix( "." );
157 14 : nf.SetFormat( "1" );
158 :
159 154 : for( int i=0; i<10; i++ )
160 : {
161 140 : m_pListLevels[i] = new XFListlevelNumber();
162 140 : m_pListLevels[i]->SetListlevelType(enumXFListLevelNumber);
163 140 : m_pListLevels[i]->SetMinLabelWidth(0.499);
164 140 : m_pListLevels[i]->SetIndent(0.501*(i+1));
165 140 : m_pListLevels[i]->SetLevel(i+1);
166 140 : ( (XFListlevelNumber*)m_pListLevels[i])->SetNumFmt(nf);
167 14 : }
168 14 : }
169 :
170 0 : XFListStyle::XFListStyle(const XFListStyle& other):XFStyle(other)
171 : {
172 : enumXFListLevel type;
173 0 : for( int i=0; i<10; i++ )
174 : {
175 0 : type = other.m_pListLevels[i]->m_eListType;
176 0 : if( type == enumXFListLevelNumber )
177 : {
178 0 : XFListlevelNumber *pNum = (XFListlevelNumber*)other.m_pListLevels[i];
179 0 : m_pListLevels[i] = new XFListlevelNumber(*pNum);
180 : }
181 0 : else if( type == enumXFListLevelBullet )
182 : {
183 0 : XFListLevelBullet *pBullet = (XFListLevelBullet*)other.m_pListLevels[i];
184 0 : m_pListLevels[i] = new XFListLevelBullet(*pBullet);
185 : }
186 : else
187 0 : m_pListLevels[i] = NULL;
188 : }
189 0 : }
190 :
191 0 : XFListStyle& XFListStyle::operator=(const XFListStyle& other)
192 : {
193 : enumXFListLevel type;
194 0 : for( int i=0; i<10; i++ )
195 : {
196 0 : type = other.m_pListLevels[i]->m_eListType;
197 0 : if( type == enumXFListLevelNumber )
198 : {
199 0 : XFListlevelNumber *pNum = (XFListlevelNumber*)m_pListLevels[i];
200 0 : m_pListLevels[i] = new XFListlevelNumber(*pNum);
201 : }
202 0 : else if( type == enumXFListLevelBullet )
203 : {
204 0 : XFListLevelBullet *pBullet = (XFListLevelBullet*)m_pListLevels[i];
205 0 : m_pListLevels[i] = new XFListLevelBullet(*pBullet);
206 : }
207 : else
208 0 : m_pListLevels[i] = NULL;
209 : }
210 0 : return *this;
211 : }
212 :
213 42 : XFListStyle::~XFListStyle()
214 : {
215 154 : for( int i=0; i<10; i++ )
216 : {
217 140 : if( m_pListLevels[i] )
218 140 : delete m_pListLevels[i];
219 : }
220 28 : }
221 :
222 64 : void XFListStyle::SetDisplayLevel(sal_Int32 level, sal_Int16 nDisplayLevel)
223 : {
224 : assert(level>=1&&level<=10);
225 :
226 64 : XFListLevel *pLevel = m_pListLevels[level-1];
227 64 : if( !pLevel )
228 : {
229 0 : pLevel = new XFListlevelNumber();
230 0 : pLevel->SetListlevelType(enumXFListLevelNumber);
231 0 : pLevel->SetLevel(level+1);
232 0 : pLevel->SetMinLabelWidth(0.499);
233 0 : pLevel->SetIndent(0.501*(level+1));
234 0 : pLevel->SetDisplayLevel(nDisplayLevel);
235 0 : m_pListLevels[level-1] = pLevel;
236 : }
237 : else
238 64 : pLevel->SetDisplayLevel(nDisplayLevel);
239 64 : }
240 :
241 117 : void XFListStyle::SetListPosition(sal_Int32 level,
242 : double indent,
243 : double minLabelWidth,
244 : double minLabelDistance,
245 : enumXFAlignType align
246 : )
247 : {
248 : assert(level>=1&&level<=10);
249 :
250 117 : XFListLevel *pLevel = m_pListLevels[level-1];
251 117 : if( !pLevel )
252 : {
253 0 : pLevel = new XFListLevelBullet();
254 0 : pLevel->SetListlevelType(enumXFListLevelNumber);
255 0 : pLevel->SetLevel(level+1);
256 0 : pLevel->SetIndent(indent);
257 0 : pLevel->SetMinLabelWidth(minLabelWidth);
258 0 : pLevel->SetMinLabelDistance(minLabelDistance);
259 0 : pLevel->SetAlignType(align);
260 0 : m_pListLevels[level-1] = pLevel;
261 : }
262 : else
263 : {
264 117 : pLevel->SetIndent(indent);
265 117 : pLevel->SetMinLabelWidth(minLabelWidth);
266 117 : pLevel->SetMinLabelDistance(minLabelDistance);
267 117 : pLevel->SetAlignType(align);
268 : }
269 117 : }
270 :
271 0 : void XFListStyle::SetListBullet(sal_Int32 level,
272 : UChar32 bullet,
273 : const OUString& fontname,
274 : const OUString& prefix,
275 : const OUString& suffix
276 : )
277 : {
278 : assert(level>=1&&level<=10);
279 :
280 0 : if( m_pListLevels[level-1] )
281 0 : delete m_pListLevels[level-1];
282 :
283 0 : XFListLevelBullet *pLevel = new XFListLevelBullet();
284 0 : pLevel->SetPrefix(prefix);
285 0 : pLevel->SetSuffix(suffix);
286 0 : pLevel->SetBulletChar(bullet);
287 0 : pLevel->SetFontName(fontname);
288 :
289 0 : pLevel->SetListlevelType(enumXFListLevelBullet);
290 0 : pLevel->SetMinLabelWidth(0.499);
291 0 : pLevel->SetIndent(0.501*level);
292 0 : pLevel->SetLevel(level);
293 0 : m_pListLevels[level-1] = pLevel;
294 0 : }
295 :
296 117 : void XFListStyle::SetListNumber(sal_Int32 level, XFNumFmt& fmt, sal_Int16 start )
297 : {
298 : assert(level>=1&&level<=10);
299 :
300 117 : if( m_pListLevels[level-1] )
301 117 : delete m_pListLevels[level-1];
302 :
303 117 : XFListlevelNumber *pLevel = new XFListlevelNumber();
304 117 : pLevel->SetNumFmt(fmt);
305 117 : pLevel->SetStartValue(start);
306 :
307 117 : pLevel->SetListlevelType(enumXFListLevelNumber);
308 117 : pLevel->SetMinLabelWidth(0.499);
309 117 : pLevel->SetIndent(0.501*level);
310 117 : pLevel->SetLevel(level);
311 117 : m_pListLevels[level-1] = pLevel;
312 117 : }
313 :
314 11 : void XFListStyle::ToXml(IXFStream *pStrm)
315 : {
316 11 : IXFAttrList *pAttrList = pStrm->GetAttrList();
317 :
318 11 : pAttrList->Clear();
319 11 : pAttrList->AddAttribute( "style:name", GetStyleName() );
320 11 : if( !GetParentStyleName().isEmpty() )
321 0 : pAttrList->AddAttribute("style:parent-style-name",GetParentStyleName());
322 11 : pStrm->StartElement( "text:list-style" );
323 :
324 121 : for( int i=0; i<10; i++ )
325 : {
326 110 : XFListLevel *pLevel = m_pListLevels[i];
327 110 : if( pLevel )
328 110 : pLevel->ToXml(pStrm);
329 : }
330 :
331 11 : pStrm->EndElement( "text:list-style" );
332 11 : }
333 :
334 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|