Update ooo320-m1
[ooovba.git] / xmloff / source / text / XMLTextListItemContext.cxx
blob2acb8da650036e3593107ece7060abb98cad6c58
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: XMLTextListItemContext.cxx,v $
10 * $Revision: 1.12.2.1 $
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 <tools/debug.hxx>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/nmspmap.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include "txtparai.hxx"
39 #include "txtlists.hxx"
40 #include "XMLTextListBlockContext.hxx"
41 #include <xmloff/txtimp.hxx>
42 // --> OD 2008-05-08 #refactorlists#
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #include <com/sun/star/style/XStyle.hpp>
45 #include <xmloff/xmlnumi.hxx>
46 // <--
48 #include "XMLTextListItemContext.hxx"
51 using ::rtl::OUString;
52 using ::rtl::OUStringBuffer;
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::uno;
56 using namespace ::xmloff::token;
58 TYPEINIT1( XMLTextListItemContext, SvXMLImportContext );
60 XMLTextListItemContext::XMLTextListItemContext(
61 SvXMLImport& rImport,
62 XMLTextImportHelper& rTxtImp,
63 const sal_uInt16 nPrfx,
64 const OUString& rLName,
65 const Reference< xml::sax::XAttributeList > & xAttrList,
66 const sal_Bool bIsHeader )
67 : SvXMLImportContext( rImport, nPrfx, rLName ),
68 rTxtImport( rTxtImp ),
69 nStartValue( -1 ),
70 // --> OD 2008-05-07 #refactorlists#
71 mnSubListCount( 0 ),
72 mxNumRulesOverride()
73 // <--
75 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
76 for( sal_Int16 i=0; i < nAttrCount; i++ )
78 const OUString& rAttrName = xAttrList->getNameByIndex( i );
79 const OUString& rValue = xAttrList->getValueByIndex( i );
81 OUString aLocalName;
82 sal_uInt16 nPrefix =
83 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
84 &aLocalName );
85 if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix &&
86 IsXMLToken( aLocalName, XML_START_VALUE ) )
88 sal_Int32 nTmp = rValue.toInt32();
89 if( nTmp >= 0 && nTmp <= SHRT_MAX )
90 nStartValue = (sal_Int16)nTmp;
92 // --> OD 2008-05-08 #refactorlists#
93 else if ( nPrefix == XML_NAMESPACE_TEXT &&
94 IsXMLToken( aLocalName, XML_STYLE_OVERRIDE ) )
96 const ::rtl::OUString sListStyleOverrideName = rValue;
97 if ( sListStyleOverrideName.getLength() > 0 )
99 OUString sDisplayStyleName(
100 GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
101 sListStyleOverrideName ) );
102 const Reference < container::XNameContainer >& rNumStyles =
103 rTxtImp.GetNumberingStyles();
104 if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
106 Reference < style::XStyle > xStyle;
107 Any aAny = rNumStyles->getByName( sDisplayStyleName );
108 aAny >>= xStyle;
110 uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
111 aAny = xPropSet->getPropertyValue( rTxtImp.sNumberingRules );
112 aAny >>= mxNumRulesOverride;
114 else
116 const SvxXMLListStyleContext* pListStyle =
117 rTxtImp.FindAutoListStyle( sListStyleOverrideName );
118 if( pListStyle )
120 mxNumRulesOverride = pListStyle->GetNumRules();
121 if( !mxNumRulesOverride.is() )
123 pListStyle->CreateAndInsertAuto();
124 mxNumRulesOverride = pListStyle->GetNumRules();
130 // <--
131 else if ( (XML_NAMESPACE_XML == nPrefix) &&
132 IsXMLToken(aLocalName, XML_ID) )
134 (void) rValue;
135 //FIXME: there is no UNO API for list items
139 // If this is a <text:list-item> element, then remember it as a sign
140 // that a bullet has to be generated.
141 if( !bIsHeader ) {
142 rTxtImport.GetTextListHelper().SetListItem( this );
147 XMLTextListItemContext::~XMLTextListItemContext()
151 void XMLTextListItemContext::EndElement()
153 // finish current list item
154 rTxtImport.GetTextListHelper().SetListItem( 0 );
157 SvXMLImportContext *XMLTextListItemContext::CreateChildContext(
158 sal_uInt16 nPrefix,
159 const OUString& rLocalName,
160 const Reference< xml::sax::XAttributeList > & xAttrList )
162 SvXMLImportContext *pContext = 0;
164 const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap();
165 sal_Bool bHeading = sal_False;
166 switch( rTokenMap.Get( nPrefix, rLocalName ) )
168 case XML_TOK_TEXT_H:
169 bHeading = sal_True;
170 case XML_TOK_TEXT_P:
171 pContext = new XMLParaContext( GetImport(),
172 nPrefix, rLocalName,
173 xAttrList, bHeading );
174 if (rTxtImport.IsProgress())
175 GetImport().GetProgressBarHelper()->Increment();
177 break;
178 case XML_TOK_TEXT_LIST:
179 // --> OD 2008-05-07 #refactorlists#
180 // pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
181 // nPrefix, rLocalName,
182 // xAttrList );
183 ++mnSubListCount;
184 pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
185 nPrefix, rLocalName,
186 xAttrList,
187 (mnSubListCount > 1) );
188 // <--
189 break;
192 if( !pContext )
193 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
195 return pContext;