1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/style/TabAlign.hpp> 31*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 32*cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx> 33*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 34*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 35*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/style/TabStop.hpp> 37*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 38*cdf0e10cSrcweir #include "xmloff/i18nmap.hxx" 39*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include "xmltabi.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #define _SVSTDARR_USHORTS 44*cdf0e10cSrcweir #include <svl/svstdarr.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using ::rtl::OUString; 47*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace ::com::sun::star; 50*cdf0e10cSrcweir using namespace ::xmloff::token; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // --- 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir enum SvXMLTokenMapAttrs 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir XML_TOK_TABSTOP_POSITION, 57*cdf0e10cSrcweir XML_TOK_TABSTOP_TYPE, 58*cdf0e10cSrcweir XML_TOK_TABSTOP_CHAR, 59*cdf0e10cSrcweir XML_TOK_TABSTOP_LEADER_STYLE, 60*cdf0e10cSrcweir XML_TOK_TABSTOP_LEADER_TEXT, 61*cdf0e10cSrcweir XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN 62*cdf0e10cSrcweir }; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] = 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_POSITION, XML_TOK_TABSTOP_POSITION }, 67*cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_TYPE, XML_TOK_TABSTOP_TYPE }, 68*cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_CHAR, XML_TOK_TABSTOP_CHAR }, 69*cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_LEADER_TEXT, XML_TOK_TABSTOP_LEADER_TEXT }, 70*cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_LEADER_STYLE, XML_TOK_TABSTOP_LEADER_STYLE }, 71*cdf0e10cSrcweir XML_TOKEN_MAP_END 72*cdf0e10cSrcweir }; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // --- 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir class SvxXMLTabStopContext_Impl : public SvXMLImportContext 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir private: 79*cdf0e10cSrcweir style::TabStop aTabStop; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir public: 82*cdf0e10cSrcweir TYPEINFO(); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, 85*cdf0e10cSrcweir const OUString& rLName, 86*cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList > & xAttrList ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir virtual ~SvxXMLTabStopContext_Impl(); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, 91*cdf0e10cSrcweir const OUString& rLocalName, 92*cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList > & xAttrList ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir const style::TabStop& getTabStop() const { return aTabStop; } 95*cdf0e10cSrcweir }; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl( 100*cdf0e10cSrcweir SvXMLImport& rImport, sal_uInt16 nPrfx, 101*cdf0e10cSrcweir const OUString& rLName, 102*cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 103*cdf0e10cSrcweir : SvXMLImportContext( rImport, nPrfx, rLName ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir aTabStop.Position = 0; 106*cdf0e10cSrcweir aTabStop.Alignment = style::TabAlign_LEFT; 107*cdf0e10cSrcweir aTabStop.DecimalChar = sal_Unicode( ',' ); 108*cdf0e10cSrcweir aTabStop.FillChar = sal_Unicode( ' ' ); 109*cdf0e10cSrcweir sal_Unicode cTextFillChar = 0; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 114*cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir const OUString& rAttrName = xAttrList->getNameByIndex( i ); 117*cdf0e10cSrcweir OUString aLocalName; 118*cdf0e10cSrcweir sal_uInt16 nPrefix = 119*cdf0e10cSrcweir GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, 120*cdf0e10cSrcweir &aLocalName ); 121*cdf0e10cSrcweir const OUString& rValue = xAttrList->getValueByIndex( i ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir sal_Int32 nVal; 124*cdf0e10cSrcweir switch( aTokenMap.Get( nPrefix, aLocalName ) ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir case XML_TOK_TABSTOP_POSITION: 127*cdf0e10cSrcweir if( GetImport().GetMM100UnitConverter().convertMeasure( nVal, 128*cdf0e10cSrcweir rValue ) ) 129*cdf0e10cSrcweir aTabStop.Position = nVal; 130*cdf0e10cSrcweir break; 131*cdf0e10cSrcweir case XML_TOK_TABSTOP_TYPE: 132*cdf0e10cSrcweir if( IsXMLToken( rValue, XML_LEFT ) ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir aTabStop.Alignment = style::TabAlign_LEFT; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir else if( IsXMLToken( rValue, XML_RIGHT ) ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir aTabStop.Alignment = style::TabAlign_RIGHT; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir else if( IsXMLToken( rValue, XML_CENTER ) ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir aTabStop.Alignment = style::TabAlign_CENTER; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir else if( IsXMLToken( rValue, XML_CHAR ) ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir aTabStop.Alignment = style::TabAlign_DECIMAL; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else if( IsXMLToken( rValue, XML_DEFAULT ) ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir aTabStop.Alignment = style::TabAlign_DEFAULT; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir break; 153*cdf0e10cSrcweir case XML_TOK_TABSTOP_CHAR: 154*cdf0e10cSrcweir if( 0 != rValue.getLength() ) 155*cdf0e10cSrcweir aTabStop.DecimalChar = rValue[0]; 156*cdf0e10cSrcweir break; 157*cdf0e10cSrcweir case XML_TOK_TABSTOP_LEADER_STYLE: 158*cdf0e10cSrcweir if( IsXMLToken( rValue, XML_NONE ) ) 159*cdf0e10cSrcweir aTabStop.FillChar = ' '; 160*cdf0e10cSrcweir else if( IsXMLToken( rValue, XML_DOTTED ) ) 161*cdf0e10cSrcweir aTabStop.FillChar = '.'; 162*cdf0e10cSrcweir else 163*cdf0e10cSrcweir aTabStop.FillChar = '_'; 164*cdf0e10cSrcweir break; 165*cdf0e10cSrcweir case XML_TOK_TABSTOP_LEADER_TEXT: 166*cdf0e10cSrcweir if( 0 != rValue.getLength() ) 167*cdf0e10cSrcweir cTextFillChar = rValue[0]; 168*cdf0e10cSrcweir break; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir if( cTextFillChar != 0 && aTabStop.FillChar != ' ' ) 173*cdf0e10cSrcweir aTabStop.FillChar = cTextFillChar; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl() 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext( 181*cdf0e10cSrcweir sal_uInt16 nPrefix, 182*cdf0e10cSrcweir const OUString& rLocalName, 183*cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList > & ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir typedef SvxXMLTabStopContext_Impl *SvxXMLTabStopContext_Impl_ImplPtr; 192*cdf0e10cSrcweir SV_DECL_PTRARR( SvxXMLTabStopArray_Impl, SvxXMLTabStopContext_Impl_ImplPtr, 20, 5 ) 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // --- 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir SvxXMLTabStopImportContext::SvxXMLTabStopImportContext( 200*cdf0e10cSrcweir SvXMLImport& rImport, sal_uInt16 nPrfx, 201*cdf0e10cSrcweir const OUString& rLName, 202*cdf0e10cSrcweir const XMLPropertyState& rProp, 203*cdf0e10cSrcweir ::std::vector< XMLPropertyState > &rProps ) 204*cdf0e10cSrcweir : XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ), 205*cdf0e10cSrcweir mpTabStops( NULL ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext() 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir if( mpTabStops ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir sal_uInt16 nCount = mpTabStops->Count(); 214*cdf0e10cSrcweir while( nCount ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir nCount--; 217*cdf0e10cSrcweir SvxXMLTabStopContext_Impl *pTabStop = (*mpTabStops)[nCount]; 218*cdf0e10cSrcweir mpTabStops->Remove( nCount, 1 ); 219*cdf0e10cSrcweir pTabStop->ReleaseRef(); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir delete mpTabStops; 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext( 227*cdf0e10cSrcweir sal_uInt16 nPrefix, 228*cdf0e10cSrcweir const OUString& rLocalName, 229*cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir SvXMLImportContext *pContext = 0; 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir // create new tabstop import context 236*cdf0e10cSrcweir SvxXMLTabStopContext_Impl *pTabStopContext = 237*cdf0e10cSrcweir new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName, 238*cdf0e10cSrcweir xAttrList ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // add new tabstop to array of tabstops 241*cdf0e10cSrcweir if( !mpTabStops ) 242*cdf0e10cSrcweir mpTabStops = new SvxXMLTabStopArray_Impl; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir mpTabStops->Insert( pTabStopContext, mpTabStops->Count() ); 245*cdf0e10cSrcweir pTabStopContext->AddRef(); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir pContext = pTabStopContext; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir else 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir return pContext; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir void SvxXMLTabStopImportContext::EndElement( ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir sal_uInt16 nCount = mpTabStops ? mpTabStops->Count() : 0; 260*cdf0e10cSrcweir uno::Sequence< style::TabStop> aSeq( nCount ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir if( mpTabStops ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir sal_uInt16 nNewCount = 0; 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir style::TabStop* pTabStops = aSeq.getArray(); 267*cdf0e10cSrcweir for( sal_uInt16 i=0; i < nCount; i++ ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i]; 270*cdf0e10cSrcweir const style::TabStop& rTabStop = pTabStopContext->getTabStop(); 271*cdf0e10cSrcweir sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment; 272*cdf0e10cSrcweir if( !bDflt || 0==i ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir *pTabStops++ = pTabStopContext->getTabStop(); 275*cdf0e10cSrcweir nNewCount++; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir if( bDflt && 0==i ) 278*cdf0e10cSrcweir break; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir if( nCount != nNewCount ) 282*cdf0e10cSrcweir aSeq.realloc( nNewCount ); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir aProp.maValue <<= aSeq; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir SetInsert( sal_True ); 287*cdf0e10cSrcweir XMLElementPropertyContext::EndElement(); 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir 294