1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmltabi.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/style/TabAlign.hpp>
34 #include <rtl/ustrbuf.hxx>
35 #include <xmloff/xmltkmap.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include "xmlnmspe.hxx"
38 #include <xmloff/xmlimp.hxx>
39 #include <com/sun/star/style/TabStop.hpp>
40 #include <xmloff/xmltoken.hxx>
41 #include "i18nmap.hxx"
42 #include <xmloff/xmluconv.hxx>
44 #include "xmltabi.hxx"
46 #define _SVSTDARR_USHORTS
47 #include <svtools/svstdarr.hxx>
49 using ::rtl::OUString
;
50 using ::rtl::OUStringBuffer
;
52 using namespace ::com::sun::star
;
53 using namespace ::xmloff::token
;
57 enum SvXMLTokenMapAttrs
59 XML_TOK_TABSTOP_POSITION
,
62 XML_TOK_TABSTOP_LEADER_STYLE
,
63 XML_TOK_TABSTOP_LEADER_TEXT
,
64 XML_TOK_TABSTOP_END
=XML_TOK_UNKNOWN
67 static __FAR_DATA SvXMLTokenMapEntry aTabsAttributesAttrTokenMap
[] =
69 { XML_NAMESPACE_STYLE
, XML_POSITION
, XML_TOK_TABSTOP_POSITION
},
70 { XML_NAMESPACE_STYLE
, XML_TYPE
, XML_TOK_TABSTOP_TYPE
},
71 { XML_NAMESPACE_STYLE
, XML_CHAR
, XML_TOK_TABSTOP_CHAR
},
72 { XML_NAMESPACE_STYLE
, XML_LEADER_TEXT
, XML_TOK_TABSTOP_LEADER_TEXT
},
73 { XML_NAMESPACE_STYLE
, XML_LEADER_STYLE
, XML_TOK_TABSTOP_LEADER_STYLE
},
79 class SvxXMLTabStopContext_Impl
: public SvXMLImportContext
82 style::TabStop aTabStop
;
87 SvxXMLTabStopContext_Impl( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
88 const OUString
& rLName
,
89 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
91 virtual ~SvxXMLTabStopContext_Impl();
93 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
94 const OUString
& rLocalName
,
95 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
97 const style::TabStop
& getTabStop() const { return aTabStop
; }
100 TYPEINIT1( SvxXMLTabStopContext_Impl
, SvXMLImportContext
);
102 SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
103 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
104 const OUString
& rLName
,
105 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
106 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
108 aTabStop
.Position
= 0;
109 aTabStop
.Alignment
= style::TabAlign_LEFT
;
110 aTabStop
.DecimalChar
= sal_Unicode( ',' );
111 aTabStop
.FillChar
= sal_Unicode( ' ' );
112 sal_Unicode cTextFillChar
= 0;
114 SvXMLTokenMap
aTokenMap( aTabsAttributesAttrTokenMap
);
116 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
117 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
119 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
122 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
124 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
127 switch( aTokenMap
.Get( nPrefix
, aLocalName
) )
129 case XML_TOK_TABSTOP_POSITION
:
130 if( GetImport().GetMM100UnitConverter().convertMeasure( nVal
,
132 aTabStop
.Position
= nVal
;
134 case XML_TOK_TABSTOP_TYPE
:
135 if( IsXMLToken( rValue
, XML_LEFT
) )
137 aTabStop
.Alignment
= style::TabAlign_LEFT
;
139 else if( IsXMLToken( rValue
, XML_RIGHT
) )
141 aTabStop
.Alignment
= style::TabAlign_RIGHT
;
143 else if( IsXMLToken( rValue
, XML_CENTER
) )
145 aTabStop
.Alignment
= style::TabAlign_CENTER
;
147 else if( IsXMLToken( rValue
, XML_CHAR
) )
149 aTabStop
.Alignment
= style::TabAlign_DECIMAL
;
151 else if( IsXMLToken( rValue
, XML_DEFAULT
) )
153 aTabStop
.Alignment
= style::TabAlign_DEFAULT
;
156 case XML_TOK_TABSTOP_CHAR
:
157 if( 0 != rValue
.getLength() )
158 aTabStop
.DecimalChar
= rValue
[0];
160 case XML_TOK_TABSTOP_LEADER_STYLE
:
161 if( IsXMLToken( rValue
, XML_NONE
) )
162 aTabStop
.FillChar
= ' ';
163 else if( IsXMLToken( rValue
, XML_DOTTED
) )
164 aTabStop
.FillChar
= '.';
166 aTabStop
.FillChar
= '_';
168 case XML_TOK_TABSTOP_LEADER_TEXT
:
169 if( 0 != rValue
.getLength() )
170 cTextFillChar
= rValue
[0];
175 if( cTextFillChar
!= 0 && aTabStop
.FillChar
!= ' ' )
176 aTabStop
.FillChar
= cTextFillChar
;
179 SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
183 SvXMLImportContext
*SvxXMLTabStopContext_Impl::CreateChildContext(
185 const OUString
& rLocalName
,
186 const uno::Reference
< xml::sax::XAttributeList
> & )
188 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
194 typedef SvxXMLTabStopContext_Impl
*SvxXMLTabStopContext_Impl_ImplPtr
;
195 SV_DECL_PTRARR( SvxXMLTabStopArray_Impl
, SvxXMLTabStopContext_Impl_ImplPtr
, 20, 5 )
200 TYPEINIT1( SvxXMLTabStopImportContext
, XMLElementPropertyContext
);
202 SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
203 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
204 const OUString
& rLName
,
205 const XMLPropertyState
& rProp
,
206 ::std::vector
< XMLPropertyState
> &rProps
)
207 : XMLElementPropertyContext( rImport
, nPrfx
, rLName
, rProp
, rProps
),
212 SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
216 sal_uInt16 nCount
= mpTabStops
->Count();
220 SvxXMLTabStopContext_Impl
*pTabStop
= (*mpTabStops
)[nCount
];
221 mpTabStops
->Remove( nCount
, 1 );
222 pTabStop
->ReleaseRef();
229 SvXMLImportContext
*SvxXMLTabStopImportContext::CreateChildContext(
231 const OUString
& rLocalName
,
232 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
234 SvXMLImportContext
*pContext
= 0;
236 if( XML_NAMESPACE_STYLE
== nPrefix
&& IsXMLToken( rLocalName
, XML_TAB_STOP
) )
238 // create new tabstop import context
239 SvxXMLTabStopContext_Impl
*pTabStopContext
=
240 new SvxXMLTabStopContext_Impl( GetImport(), nPrefix
, rLocalName
,
243 // add new tabstop to array of tabstops
245 mpTabStops
= new SvxXMLTabStopArray_Impl
;
247 mpTabStops
->Insert( pTabStopContext
, mpTabStops
->Count() );
248 pTabStopContext
->AddRef();
250 pContext
= pTabStopContext
;
254 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
260 void SvxXMLTabStopImportContext::EndElement( )
262 sal_uInt16 nCount
= mpTabStops
? mpTabStops
->Count() : 0;
263 uno::Sequence
< style::TabStop
> aSeq( nCount
);
267 sal_uInt16 nNewCount
= 0;
269 style::TabStop
* pTabStops
= aSeq
.getArray();
270 for( sal_uInt16 i
=0; i
< nCount
; i
++ )
272 SvxXMLTabStopContext_Impl
*pTabStopContext
= (*mpTabStops
)[i
];
273 const style::TabStop
& rTabStop
= pTabStopContext
->getTabStop();
274 sal_Bool bDflt
= style::TabAlign_DEFAULT
== rTabStop
.Alignment
;
277 *pTabStops
++ = pTabStopContext
->getTabStop();
284 if( nCount
!= nNewCount
)
285 aSeq
.realloc( nNewCount
);
287 aProp
.maValue
<<= aSeq
;
289 SetInsert( sal_True
);
290 XMLElementPropertyContext::EndElement();