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 : static_cast<XFListlevelNumber*>(m_pListLevels[i])->SetNumFmt(nf);
167 14 : }
168 14 : }
169 :
170 0 : XFListStyle::XFListStyle(const XFListStyle& other):XFStyle(other)
171 : {
172 0 : for( int i=0; i<10; i++ )
173 : {
174 0 : const enumXFListLevel type = other.m_pListLevels[i]->m_eListType;
175 0 : if( type == enumXFListLevelNumber )
176 : {
177 0 : XFListlevelNumber *pNum = static_cast<XFListlevelNumber*>(other.m_pListLevels[i]);
178 0 : m_pListLevels[i] = new XFListlevelNumber(*pNum);
179 : }
180 0 : else if( type == enumXFListLevelBullet )
181 : {
182 0 : XFListLevelBullet *pBullet = static_cast<XFListLevelBullet*>(other.m_pListLevels[i]);
183 0 : m_pListLevels[i] = new XFListLevelBullet(*pBullet);
184 : }
185 : else
186 0 : m_pListLevels[i] = NULL;
187 : }
188 0 : }
189 :
190 0 : XFListStyle& XFListStyle::operator=(const XFListStyle& other)
191 : {
192 0 : for( int i=0; i<10; i++ )
193 : {
194 0 : const enumXFListLevel type = other.m_pListLevels[i]->m_eListType;
195 0 : if( type == enumXFListLevelNumber )
196 : {
197 0 : XFListlevelNumber *pNum = static_cast<XFListlevelNumber*>(m_pListLevels[i]);
198 0 : m_pListLevels[i] = new XFListlevelNumber(*pNum);
199 : }
200 0 : else if( type == enumXFListLevelBullet )
201 : {
202 0 : XFListLevelBullet *pBullet = static_cast<XFListLevelBullet*>(m_pListLevels[i]);
203 0 : m_pListLevels[i] = new XFListLevelBullet(*pBullet);
204 : }
205 : else
206 0 : m_pListLevels[i] = NULL;
207 : }
208 0 : return *this;
209 : }
210 :
211 42 : XFListStyle::~XFListStyle()
212 : {
213 154 : for( int i=0; i<10; i++ )
214 : {
215 140 : if( m_pListLevels[i] )
216 140 : delete m_pListLevels[i];
217 : }
218 28 : }
219 :
220 64 : void XFListStyle::SetDisplayLevel(sal_Int32 level, sal_Int16 nDisplayLevel)
221 : {
222 : assert(level>=1&&level<=10);
223 :
224 64 : XFListLevel *pLevel = m_pListLevels[level-1];
225 64 : if( !pLevel )
226 : {
227 0 : pLevel = new XFListlevelNumber();
228 0 : pLevel->SetListlevelType(enumXFListLevelNumber);
229 0 : pLevel->SetLevel(level+1);
230 0 : pLevel->SetMinLabelWidth(0.499);
231 0 : pLevel->SetIndent(0.501*(level+1));
232 0 : pLevel->SetDisplayLevel(nDisplayLevel);
233 0 : m_pListLevels[level-1] = pLevel;
234 : }
235 : else
236 64 : pLevel->SetDisplayLevel(nDisplayLevel);
237 64 : }
238 :
239 117 : void XFListStyle::SetListPosition(sal_Int32 level,
240 : double indent,
241 : double minLabelWidth,
242 : double minLabelDistance,
243 : enumXFAlignType align
244 : )
245 : {
246 : assert(level>=1&&level<=10);
247 :
248 117 : XFListLevel *pLevel = m_pListLevels[level-1];
249 117 : if( !pLevel )
250 : {
251 0 : pLevel = new XFListLevelBullet();
252 0 : pLevel->SetListlevelType(enumXFListLevelNumber);
253 0 : pLevel->SetLevel(level+1);
254 0 : pLevel->SetIndent(indent);
255 0 : pLevel->SetMinLabelWidth(minLabelWidth);
256 0 : pLevel->SetMinLabelDistance(minLabelDistance);
257 0 : pLevel->SetAlignType(align);
258 0 : m_pListLevels[level-1] = pLevel;
259 : }
260 : else
261 : {
262 117 : pLevel->SetIndent(indent);
263 117 : pLevel->SetMinLabelWidth(minLabelWidth);
264 117 : pLevel->SetMinLabelDistance(minLabelDistance);
265 117 : pLevel->SetAlignType(align);
266 : }
267 117 : }
268 :
269 0 : void XFListStyle::SetListBullet(sal_Int32 level,
270 : UChar32 bullet,
271 : const OUString& fontname,
272 : const OUString& prefix,
273 : const OUString& suffix
274 : )
275 : {
276 : assert(level>=1&&level<=10);
277 :
278 0 : if( m_pListLevels[level-1] )
279 0 : delete m_pListLevels[level-1];
280 :
281 0 : XFListLevelBullet *pLevel = new XFListLevelBullet();
282 0 : pLevel->SetPrefix(prefix);
283 0 : pLevel->SetSuffix(suffix);
284 0 : pLevel->SetBulletChar(bullet);
285 0 : pLevel->SetFontName(fontname);
286 :
287 0 : pLevel->SetListlevelType(enumXFListLevelBullet);
288 0 : pLevel->SetMinLabelWidth(0.499);
289 0 : pLevel->SetIndent(0.501*level);
290 0 : pLevel->SetLevel(level);
291 0 : m_pListLevels[level-1] = pLevel;
292 0 : }
293 :
294 117 : void XFListStyle::SetListNumber(sal_Int32 level, XFNumFmt& fmt, sal_Int16 start )
295 : {
296 : assert(level>=1&&level<=10);
297 :
298 117 : if( m_pListLevels[level-1] )
299 117 : delete m_pListLevels[level-1];
300 :
301 117 : XFListlevelNumber *pLevel = new XFListlevelNumber();
302 117 : pLevel->SetNumFmt(fmt);
303 117 : pLevel->SetStartValue(start);
304 :
305 117 : pLevel->SetListlevelType(enumXFListLevelNumber);
306 117 : pLevel->SetMinLabelWidth(0.499);
307 117 : pLevel->SetIndent(0.501*level);
308 117 : pLevel->SetLevel(level);
309 117 : m_pListLevels[level-1] = pLevel;
310 117 : }
311 :
312 11 : void XFListStyle::ToXml(IXFStream *pStrm)
313 : {
314 11 : IXFAttrList *pAttrList = pStrm->GetAttrList();
315 :
316 11 : pAttrList->Clear();
317 11 : pAttrList->AddAttribute( "style:name", GetStyleName() );
318 11 : if( !GetParentStyleName().isEmpty() )
319 0 : pAttrList->AddAttribute("style:parent-style-name",GetParentStyleName());
320 11 : pStrm->StartElement( "text:list-style" );
321 :
322 121 : for( int i=0; i<10; i++ )
323 : {
324 110 : XFListLevel *pLevel = m_pListLevels[i];
325 110 : if( pLevel )
326 110 : pLevel->ToXml(pStrm);
327 : }
328 :
329 11 : pStrm->EndElement( "text:list-style" );
330 11 : }
331 :
332 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|