1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/style/TabAlign.hpp>
21 #include <rtl/ustrbuf.hxx>
22 #include <xmloff/xmltkmap.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmlimp.hxx>
26 #include <com/sun/star/style/TabStop.hpp>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/i18nmap.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include "xmltabi.hxx"
33 using namespace ::com::sun::star
;
34 using namespace ::xmloff::token
;
36 enum SvXMLTokenMapAttrs
38 XML_TOK_TABSTOP_POSITION
,
41 XML_TOK_TABSTOP_LEADER_STYLE
,
42 XML_TOK_TABSTOP_LEADER_TEXT
,
43 XML_TOK_TABSTOP_END
=XML_TOK_UNKNOWN
46 static SvXMLTokenMapEntry aTabsAttributesAttrTokenMap
[] =
48 { XML_NAMESPACE_STYLE
, XML_POSITION
, XML_TOK_TABSTOP_POSITION
},
49 { XML_NAMESPACE_STYLE
, XML_TYPE
, XML_TOK_TABSTOP_TYPE
},
50 { XML_NAMESPACE_STYLE
, XML_CHAR
, XML_TOK_TABSTOP_CHAR
},
51 { XML_NAMESPACE_STYLE
, XML_LEADER_TEXT
, XML_TOK_TABSTOP_LEADER_TEXT
},
52 { XML_NAMESPACE_STYLE
, XML_LEADER_STYLE
, XML_TOK_TABSTOP_LEADER_STYLE
},
58 class SvxXMLTabStopContext_Impl
: public SvXMLImportContext
61 style::TabStop aTabStop
;
66 SvxXMLTabStopContext_Impl( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
67 const OUString
& rLName
,
68 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
70 virtual ~SvxXMLTabStopContext_Impl();
72 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
73 const OUString
& rLocalName
,
74 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
) SAL_OVERRIDE
;
76 const style::TabStop
& getTabStop() const { return aTabStop
; }
79 TYPEINIT1( SvxXMLTabStopContext_Impl
, SvXMLImportContext
);
81 SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
82 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
83 const OUString
& rLName
,
84 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
85 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
87 aTabStop
.Position
= 0;
88 aTabStop
.Alignment
= style::TabAlign_LEFT
;
89 aTabStop
.DecimalChar
= ',';
90 aTabStop
.FillChar
= ' ';
91 sal_Unicode cTextFillChar
= 0;
93 SvXMLTokenMap
aTokenMap( aTabsAttributesAttrTokenMap
);
95 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
96 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
98 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
101 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
103 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
106 switch( aTokenMap
.Get( nPrefix
, aLocalName
) )
108 case XML_TOK_TABSTOP_POSITION
:
109 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
112 aTabStop
.Position
= nVal
;
115 case XML_TOK_TABSTOP_TYPE
:
116 if( IsXMLToken( rValue
, XML_LEFT
) )
118 aTabStop
.Alignment
= style::TabAlign_LEFT
;
120 else if( IsXMLToken( rValue
, XML_RIGHT
) )
122 aTabStop
.Alignment
= style::TabAlign_RIGHT
;
124 else if( IsXMLToken( rValue
, XML_CENTER
) )
126 aTabStop
.Alignment
= style::TabAlign_CENTER
;
128 else if( IsXMLToken( rValue
, XML_CHAR
) )
130 aTabStop
.Alignment
= style::TabAlign_DECIMAL
;
132 else if( IsXMLToken( rValue
, XML_DEFAULT
) )
134 aTabStop
.Alignment
= style::TabAlign_DEFAULT
;
137 case XML_TOK_TABSTOP_CHAR
:
138 if( !rValue
.isEmpty() )
139 aTabStop
.DecimalChar
= rValue
[0];
141 case XML_TOK_TABSTOP_LEADER_STYLE
:
142 if( IsXMLToken( rValue
, XML_NONE
) )
143 aTabStop
.FillChar
= ' ';
144 else if( IsXMLToken( rValue
, XML_DOTTED
) )
145 aTabStop
.FillChar
= '.';
147 aTabStop
.FillChar
= '_';
149 case XML_TOK_TABSTOP_LEADER_TEXT
:
150 if( !rValue
.isEmpty() )
151 cTextFillChar
= rValue
[0];
156 if( cTextFillChar
!= 0 && aTabStop
.FillChar
!= ' ' )
157 aTabStop
.FillChar
= cTextFillChar
;
160 SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
164 SvXMLImportContext
*SvxXMLTabStopContext_Impl::CreateChildContext(
166 const OUString
& rLocalName
,
167 const uno::Reference
< xml::sax::XAttributeList
> & )
169 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
172 TYPEINIT1( SvxXMLTabStopImportContext
, XMLElementPropertyContext
);
174 SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
175 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
176 const OUString
& rLName
,
177 const XMLPropertyState
& rProp
,
178 ::std::vector
< XMLPropertyState
> &rProps
)
179 : XMLElementPropertyContext( rImport
, nPrfx
, rLName
, rProp
, rProps
),
184 SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
188 while( !mpTabStops
->empty() )
190 SvxXMLTabStopContext_Impl
*pTabStop
= mpTabStops
->back();
191 mpTabStops
->pop_back();
192 pTabStop
->ReleaseRef();
199 SvXMLImportContext
*SvxXMLTabStopImportContext::CreateChildContext(
201 const OUString
& rLocalName
,
202 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
204 SvXMLImportContext
*pContext
= 0;
206 if( XML_NAMESPACE_STYLE
== nPrefix
&& IsXMLToken( rLocalName
, XML_TAB_STOP
) )
208 // create new tabstop import context
209 SvxXMLTabStopContext_Impl
*pTabStopContext
=
210 new SvxXMLTabStopContext_Impl( GetImport(), nPrefix
, rLocalName
,
213 // add new tabstop to array of tabstops
215 mpTabStops
= new SvxXMLTabStopArray_Impl
;
217 mpTabStops
->push_back( pTabStopContext
);
218 pTabStopContext
->AddFirstRef();
220 pContext
= pTabStopContext
;
224 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
230 void SvxXMLTabStopImportContext::EndElement( )
232 sal_uInt16 nCount
= mpTabStops
? mpTabStops
->size() : 0;
233 uno::Sequence
< style::TabStop
> aSeq( nCount
);
237 sal_uInt16 nNewCount
= 0;
239 style::TabStop
* pTabStops
= aSeq
.getArray();
240 for( sal_uInt16 i
=0; i
< nCount
; i
++ )
242 SvxXMLTabStopContext_Impl
*pTabStopContext
= (*mpTabStops
)[i
];
243 const style::TabStop
& rTabStop
= pTabStopContext
->getTabStop();
244 bool bDflt
= style::TabAlign_DEFAULT
== rTabStop
.Alignment
;
247 *pTabStops
++ = pTabStopContext
->getTabStop();
254 if( nCount
!= nNewCount
)
255 aSeq
.realloc( nNewCount
);
257 aProp
.maValue
<<= aSeq
;
260 XMLElementPropertyContext::EndElement();
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */