1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/style/TabAlign.hpp>
30 #include <rtl/ustrbuf.hxx>
31 #include <xmloff/xmltkmap.hxx>
32 #include <xmloff/nmspmap.hxx>
33 #include "xmloff/xmlnmspe.hxx"
34 #include <xmloff/xmlimp.hxx>
35 #include <com/sun/star/style/TabStop.hpp>
36 #include <xmloff/xmltoken.hxx>
37 #include "xmloff/i18nmap.hxx"
38 #include <xmloff/xmluconv.hxx>
39 #include <svl/svstdarr.hxx>
40 #include "xmltabi.hxx"
42 using ::rtl::OUString
;
43 using ::rtl::OUStringBuffer
;
45 using namespace ::com::sun::star
;
46 using namespace ::xmloff::token
;
48 enum SvXMLTokenMapAttrs
50 XML_TOK_TABSTOP_POSITION
,
53 XML_TOK_TABSTOP_LEADER_STYLE
,
54 XML_TOK_TABSTOP_LEADER_TEXT
,
55 XML_TOK_TABSTOP_END
=XML_TOK_UNKNOWN
58 static SvXMLTokenMapEntry aTabsAttributesAttrTokenMap
[] =
60 { XML_NAMESPACE_STYLE
, XML_POSITION
, XML_TOK_TABSTOP_POSITION
},
61 { XML_NAMESPACE_STYLE
, XML_TYPE
, XML_TOK_TABSTOP_TYPE
},
62 { XML_NAMESPACE_STYLE
, XML_CHAR
, XML_TOK_TABSTOP_CHAR
},
63 { XML_NAMESPACE_STYLE
, XML_LEADER_TEXT
, XML_TOK_TABSTOP_LEADER_TEXT
},
64 { XML_NAMESPACE_STYLE
, XML_LEADER_STYLE
, XML_TOK_TABSTOP_LEADER_STYLE
},
70 class SvxXMLTabStopContext_Impl
: public SvXMLImportContext
73 style::TabStop aTabStop
;
78 SvxXMLTabStopContext_Impl( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
79 const OUString
& rLName
,
80 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
82 virtual ~SvxXMLTabStopContext_Impl();
84 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
85 const OUString
& rLocalName
,
86 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
88 const style::TabStop
& getTabStop() const { return aTabStop
; }
91 TYPEINIT1( SvxXMLTabStopContext_Impl
, SvXMLImportContext
);
93 SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
94 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
95 const OUString
& rLName
,
96 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
97 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
99 aTabStop
.Position
= 0;
100 aTabStop
.Alignment
= style::TabAlign_LEFT
;
101 aTabStop
.DecimalChar
= sal_Unicode( ',' );
102 aTabStop
.FillChar
= sal_Unicode( ' ' );
103 sal_Unicode cTextFillChar
= 0;
105 SvXMLTokenMap
aTokenMap( aTabsAttributesAttrTokenMap
);
107 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
108 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
110 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
113 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
115 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
118 switch( aTokenMap
.Get( nPrefix
, aLocalName
) )
120 case XML_TOK_TABSTOP_POSITION
:
121 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
124 aTabStop
.Position
= nVal
;
127 case XML_TOK_TABSTOP_TYPE
:
128 if( IsXMLToken( rValue
, XML_LEFT
) )
130 aTabStop
.Alignment
= style::TabAlign_LEFT
;
132 else if( IsXMLToken( rValue
, XML_RIGHT
) )
134 aTabStop
.Alignment
= style::TabAlign_RIGHT
;
136 else if( IsXMLToken( rValue
, XML_CENTER
) )
138 aTabStop
.Alignment
= style::TabAlign_CENTER
;
140 else if( IsXMLToken( rValue
, XML_CHAR
) )
142 aTabStop
.Alignment
= style::TabAlign_DECIMAL
;
144 else if( IsXMLToken( rValue
, XML_DEFAULT
) )
146 aTabStop
.Alignment
= style::TabAlign_DEFAULT
;
149 case XML_TOK_TABSTOP_CHAR
:
150 if( !rValue
.isEmpty() )
151 aTabStop
.DecimalChar
= rValue
[0];
153 case XML_TOK_TABSTOP_LEADER_STYLE
:
154 if( IsXMLToken( rValue
, XML_NONE
) )
155 aTabStop
.FillChar
= ' ';
156 else if( IsXMLToken( rValue
, XML_DOTTED
) )
157 aTabStop
.FillChar
= '.';
159 aTabStop
.FillChar
= '_';
161 case XML_TOK_TABSTOP_LEADER_TEXT
:
162 if( !rValue
.isEmpty() )
163 cTextFillChar
= rValue
[0];
168 if( cTextFillChar
!= 0 && aTabStop
.FillChar
!= ' ' )
169 aTabStop
.FillChar
= cTextFillChar
;
172 SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
176 SvXMLImportContext
*SvxXMLTabStopContext_Impl::CreateChildContext(
178 const OUString
& rLocalName
,
179 const uno::Reference
< xml::sax::XAttributeList
> & )
181 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
187 class SvxXMLTabStopArray_Impl
: public std::vector
<SvxXMLTabStopContext_Impl
*> {};
192 TYPEINIT1( SvxXMLTabStopImportContext
, XMLElementPropertyContext
);
194 SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
195 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
196 const OUString
& rLName
,
197 const XMLPropertyState
& rProp
,
198 ::std::vector
< XMLPropertyState
> &rProps
)
199 : XMLElementPropertyContext( rImport
, nPrfx
, rLName
, rProp
, rProps
),
204 SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
208 while( !mpTabStops
->empty() )
210 SvxXMLTabStopContext_Impl
*pTabStop
= mpTabStops
->back();
211 mpTabStops
->pop_back();
212 pTabStop
->ReleaseRef();
219 SvXMLImportContext
*SvxXMLTabStopImportContext::CreateChildContext(
221 const OUString
& rLocalName
,
222 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
224 SvXMLImportContext
*pContext
= 0;
226 if( XML_NAMESPACE_STYLE
== nPrefix
&& IsXMLToken( rLocalName
, XML_TAB_STOP
) )
228 // create new tabstop import context
229 SvxXMLTabStopContext_Impl
*pTabStopContext
=
230 new SvxXMLTabStopContext_Impl( GetImport(), nPrefix
, rLocalName
,
233 // add new tabstop to array of tabstops
235 mpTabStops
= new SvxXMLTabStopArray_Impl
;
237 mpTabStops
->push_back( pTabStopContext
);
238 pTabStopContext
->AddRef();
240 pContext
= pTabStopContext
;
244 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
250 void SvxXMLTabStopImportContext::EndElement( )
252 sal_uInt16 nCount
= mpTabStops
? mpTabStops
->size() : 0;
253 uno::Sequence
< style::TabStop
> aSeq( nCount
);
257 sal_uInt16 nNewCount
= 0;
259 style::TabStop
* pTabStops
= aSeq
.getArray();
260 for( sal_uInt16 i
=0; i
< nCount
; i
++ )
262 SvxXMLTabStopContext_Impl
*pTabStopContext
= (*mpTabStops
)[i
];
263 const style::TabStop
& rTabStop
= pTabStopContext
->getTabStop();
264 sal_Bool bDflt
= style::TabAlign_DEFAULT
== rTabStop
.Alignment
;
267 *pTabStops
++ = pTabStopContext
->getTabStop();
274 if( nCount
!= nNewCount
)
275 aSeq
.realloc( nNewCount
);
277 aProp
.maValue
<<= aSeq
;
279 SetInsert( sal_True
);
280 XMLElementPropertyContext::EndElement();
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */