LibreOffice Module lotuswordpro (master) 1
xfliststyle.cxx
Go to the documentation of this file.
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 ************************************************************************/
61#include <xfilter/xfglobal.hxx>
62#include <xfilter/xfutil.hxx>
63
65 : m_nLevel(0)
66 , m_nDisplayLevel(0)
67 , m_fIndent(0)
68 , m_fMinLabelWidth(0.499)
69 , m_fMinLabelDistance(0)
70 , m_eAlign(enumXFAlignStart)
71 , m_eListType(enumXFListLevelNumber)
72{}
73
75{
76}
77
79{
80 IXFAttrList *pAttrList = pStrm->GetAttrList();
81
82 pAttrList->Clear();
83 pAttrList->AddAttribute( "text:level", OUString::number(static_cast<sal_Int32>(m_nLevel)) );
84 //text:style-name,ignore now.
85 m_aNumFmt.ToXml(pStrm);
86 if( m_nDisplayLevel )
87 pAttrList->AddAttribute( "text:display-levels", OUString::number(static_cast<sal_Int32>(m_nDisplayLevel)) );
88
89 pStrm->StartElement( "text:list-level-style-number" );
90
91 //<style:properties>...</style:properties>
92 pAttrList->Clear();
93 if( m_fIndent > FLOAT_MIN )
94 {
95 pAttrList->AddAttribute( "text:space-before", OUString::number(m_fIndent) + "cm" );
96 }
98 {
99 pAttrList->AddAttribute( "text:min-label-width", OUString::number(m_fMinLabelWidth) + "cm" );
100 }
102 {
103 pAttrList->AddAttribute( "text:min-label-distance", OUString::number(m_fMinLabelDistance) + "cm" );
104 }
105 pAttrList->AddAttribute( "fo:text-align", GetAlignName(m_eAlign) );
106
107 pStrm->StartElement( "style:properties" );
108 pStrm->EndElement( "style:properties" );
109
110 pStrm->EndElement( "text:list-level-style-number" );
111}
112
114{
115 IXFAttrList *pAttrList = pStrm->GetAttrList();
116
117 pAttrList->Clear();
118 pAttrList->AddAttribute( "text:level", OUString::number(static_cast<sal_Int32>(m_nLevel)) );
119 //text:style-name,ignore now.
120 m_aNumFmt.ToXml(pStrm);
121 //bullet-char
122 pAttrList->AddAttribute( "text:bullet-char", m_chBullet );
123
124 pStrm->StartElement( "text:list-level-style-bullet" );
125
126 //<style:properties>...</style:properties>
127 pAttrList->Clear();
128 if( m_fIndent != 0 )
129 {
130 pAttrList->AddAttribute( "text:space-before", OUString::number(m_fIndent) + "cm" );
131 }
132 if( m_fMinLabelWidth != 0 )
133 {
134 pAttrList->AddAttribute( "text:min-label-width", OUString::number(m_fMinLabelWidth) + "cm" );
135 }
136 if( m_fMinLabelDistance != 0 )
137 {
138 pAttrList->AddAttribute( "text:min-label-distance", OUString::number(m_fMinLabelDistance) + "cm" );
139 }
140
141 pAttrList->AddAttribute( "fo:text-align", GetAlignName(m_eAlign) );
142
143 if( !m_strFontName.isEmpty() )
144 {
145 pAttrList->AddAttribute( "style:font-name", m_strFontName );
146 }
147 pStrm->StartElement( "style:properties" );
148 pStrm->EndElement( "style:properties" );
149
150 pStrm->EndElement( "text:list-level-style-bullet" );
151}
152
154{
155 XFNumFmt nf;
156 nf.SetSuffix( "." );
157 nf.SetFormat( "1" );
158
159 for( int i=0; i<10; i++ )
160 {
161 m_pListLevels[i].reset(new XFListlevelNumber());
162 m_pListLevels[i]->SetListlevelType(enumXFListLevelNumber);
163 m_pListLevels[i]->SetMinLabelWidth(0.499);
164 m_pListLevels[i]->SetIndent(0.501*(i+1));
165 m_pListLevels[i]->SetLevel(i+1);
166 static_cast<XFListlevelNumber*>(m_pListLevels[i].get())->SetNumFmt(nf);
167 }
168}
169
171{
172 for( int i=0; i<10; i++ )
173 {
174 const enumXFListLevel type = other.m_pListLevels[i]->m_eListType;
176 {
177 XFListlevelNumber *pNum = static_cast<XFListlevelNumber*>(other.m_pListLevels[i].get());
178 m_pListLevels[i].reset(new XFListlevelNumber(*pNum));
179 }
180 else if( type == enumXFListLevelBullet )
181 {
182 XFListLevelBullet *pBullet = static_cast<XFListLevelBullet*>(other.m_pListLevels[i].get());
183 m_pListLevels[i].reset(new XFListLevelBullet(*pBullet));
184 }
185 else
186 m_pListLevels[i].reset();
187 }
188}
189
191{
192}
193
194void XFListStyle::SetDisplayLevel(sal_Int32 level, sal_Int16 nDisplayLevel)
195{
196 assert(level>=1&&level<=10);
197
198 XFListLevel *pLevel = m_pListLevels[level-1].get();
199 if( !pLevel )
200 {
201 m_pListLevels[level-1].reset(new XFListlevelNumber());
202 pLevel = m_pListLevels[level-1].get();
204 pLevel->SetLevel(level+1);
205 pLevel->SetMinLabelWidth(0.499);
206 pLevel->SetIndent(0.501*(level+1));
207 }
208 pLevel->SetDisplayLevel(nDisplayLevel);
209}
210
211void XFListStyle::SetListPosition(sal_Int32 level,
212 double indent,
213 double minLabelWidth,
214 double minLabelDistance,
215 enumXFAlignType align
216 )
217{
218 assert(level>=1&&level<=10);
219
220 XFListLevel *pLevel = m_pListLevels[level-1].get();
221 if( !pLevel )
222 {
223 m_pListLevels[level-1].reset( new XFListLevelBullet() );
224 pLevel = m_pListLevels[level-1].get();
226 pLevel->SetLevel(level+1);
227 }
228 pLevel->SetIndent(indent);
229 pLevel->SetMinLabelWidth(minLabelWidth);
230 pLevel->SetMinLabelDistance(minLabelDistance);
231 pLevel->SetAlignType(align);
232}
233
234void XFListStyle::SetListBullet(sal_Int32 level,
235 OUString const & bullet,
236 const OUString& fontname,
237 const OUString& prefix,
238 const OUString& suffix
239 )
240{
241 assert(level>=1&&level<=10);
242
243 std::unique_ptr<XFListLevelBullet> pLevel(new XFListLevelBullet());
244 pLevel->SetPrefix(prefix);
245 pLevel->SetSuffix(suffix);
246 pLevel->SetBulletChar(bullet);
247 pLevel->SetFontName(fontname);
248
249 pLevel->SetListlevelType(enumXFListLevelBullet);
250 pLevel->SetMinLabelWidth(0.499);
251 pLevel->SetIndent(0.501*level);
252 pLevel->SetLevel(level);
253 m_pListLevels[level-1] = std::move(pLevel);
254}
255
256void XFListStyle::SetListNumber(sal_Int32 level, XFNumFmt const & fmt, sal_Int16 start )
257{
258 assert(level>=1&&level<=10);
259
260 std::unique_ptr<XFListlevelNumber> pLevel(new XFListlevelNumber());
261 pLevel->SetNumFmt(fmt);
262 pLevel->SetStartValue(start);
263
264 pLevel->SetListlevelType(enumXFListLevelNumber);
265 pLevel->SetMinLabelWidth(0.499);
266 pLevel->SetIndent(0.501*level);
267 pLevel->SetLevel(level);
268 m_pListLevels[level-1] = std::move(pLevel);
269}
270
272{
273 IXFAttrList *pAttrList = pStrm->GetAttrList();
274
275 pAttrList->Clear();
276 pAttrList->AddAttribute( "style:name", GetStyleName() );
277 if( !GetParentStyleName().isEmpty() )
278 pAttrList->AddAttribute("style:parent-style-name",GetParentStyleName());
279 pStrm->StartElement( "text:list-style" );
280
281 for(auto const & pLevel : m_pListLevels)
282 {
283 if( pLevel )
284 pLevel->ToXml(pStrm);
285 }
286
287 pStrm->EndElement( "text:list-style" );
288}
289
290/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nLevel
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
virtual void ToXml(IXFStream *pStrm) override
OUString m_strFontName
void SetDisplayLevel(sal_Int16 nDisplayLevel)
double m_fMinLabelWidth
virtual void ToXml(IXFStream *pStrm)
Definition: xfliststyle.cxx:74
void SetIndent(double indent)
sal_Int16 m_nLevel
void SetLevel(sal_Int16 level)
double m_fIndent
void SetMinLabelDistance(double distance)
sal_Int16 m_nDisplayLevel
void SetMinLabelWidth(double labelWidth)
void SetListlevelType(enumXFListLevel type)
enumXFAlignType m_eAlign
void SetAlignType(enumXFAlignType align)
double m_fMinLabelDistance
void SetListNumber(sal_Int32 level, XFNumFmt const &numFmt, sal_Int16 nStartValue)
void SetListBullet(sal_Int32 level, OUString const &bullet_char, const OUString &fontname, const OUString &prefix, const OUString &suffix)
virtual void ToXml(IXFStream *pStrm) override
std::unique_ptr< XFListLevel > m_pListLevels[10]
void SetDisplayLevel(sal_Int32 level, sal_Int16 nShowLevel)
virtual ~XFListStyle() override
void SetListPosition(sal_Int32 level, double indent, double minLabelWidth, double minLabelDistance, enumXFAlignType align=enumXFAlignStart)
virtual void ToXml(IXFStream *pStrm) override
Definition: xfliststyle.cxx:78
Bullet number format.
Definition: xfnumfmt.hxx:71
void SetFormat(const OUString &format)
Definition: xfnumfmt.hxx:120
void ToXml(IXFStream *pStrm)
Definition: xfnumfmt.hxx:130
void SetSuffix(const OUString &suffix)
Definition: xfnumfmt.hxx:96
implements ixfstyle interface.
Definition: xfstyle.hxx:70
virtual OUString GetStyleName() override
@descr get style name.
Definition: xfstyle.cxx:70
virtual OUString GetParentStyleName() override
@descr set parent style name.
Definition: xfstyle.cxx:80
int i
ResultType type
enumXFAlignType
Definition: xfdefs.hxx:172
@ enumXFAlignStart
Definition: xfdefs.hxx:174
#define FLOAT_MIN
Definition: xfglobal.hxx:66
enumXFListLevel
Definition: xfliststyle.hxx:70
@ enumXFListLevelNumber
Definition: xfliststyle.hxx:72
@ enumXFListLevelBullet
Definition: xfliststyle.hxx:71
OUString GetAlignName(enumXFAlignType align)
Definition: xfutil.cxx:296