xref: /AOO41X/main/xmloff/source/text/XMLTextListItemContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <tools/debug.hxx>
31*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
32*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
33*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
34*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
35*cdf0e10cSrcweir #include "txtparai.hxx"
36*cdf0e10cSrcweir #include "txtlists.hxx"
37*cdf0e10cSrcweir #include "XMLTextListBlockContext.hxx"
38*cdf0e10cSrcweir #include <xmloff/txtimp.hxx>
39*cdf0e10cSrcweir // --> OD 2008-05-08 #refactorlists#
40*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
42*cdf0e10cSrcweir #include <xmloff/xmlnumi.hxx>
43*cdf0e10cSrcweir // <--
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "XMLTextListItemContext.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using ::rtl::OUString;
49*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir using namespace ::com::sun::star;
52*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
53*cdf0e10cSrcweir using namespace ::xmloff::token;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir TYPEINIT1( XMLTextListItemContext, SvXMLImportContext );
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir XMLTextListItemContext::XMLTextListItemContext(
58*cdf0e10cSrcweir                         SvXMLImport& rImport,
59*cdf0e10cSrcweir                         XMLTextImportHelper& rTxtImp,
60*cdf0e10cSrcweir                         const sal_uInt16 nPrfx,
61*cdf0e10cSrcweir                         const OUString& rLName,
62*cdf0e10cSrcweir                         const Reference< xml::sax::XAttributeList > & xAttrList,
63*cdf0e10cSrcweir                         const sal_Bool bIsHeader )
64*cdf0e10cSrcweir     : SvXMLImportContext( rImport, nPrfx, rLName ),
65*cdf0e10cSrcweir       rTxtImport( rTxtImp ),
66*cdf0e10cSrcweir       nStartValue( -1 ),
67*cdf0e10cSrcweir       // --> OD 2008-05-07 #refactorlists#
68*cdf0e10cSrcweir       mnSubListCount( 0 ),
69*cdf0e10cSrcweir       mxNumRulesOverride()
70*cdf0e10cSrcweir       // <--
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir     static ::rtl::OUString s_NumberingRules(
73*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("NumberingRules"));
74*cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
75*cdf0e10cSrcweir 	for( sal_Int16 i=0; i < nAttrCount; i++ )
76*cdf0e10cSrcweir 	{
77*cdf0e10cSrcweir 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
78*cdf0e10cSrcweir 		const OUString& rValue = xAttrList->getValueByIndex( i );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 		OUString aLocalName;
81*cdf0e10cSrcweir 		sal_uInt16 nPrefix =
82*cdf0e10cSrcweir 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
83*cdf0e10cSrcweir 															&aLocalName );
84*cdf0e10cSrcweir 		if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix &&
85*cdf0e10cSrcweir 			IsXMLToken( aLocalName, XML_START_VALUE ) )
86*cdf0e10cSrcweir 		{
87*cdf0e10cSrcweir 			sal_Int32 nTmp = rValue.toInt32();
88*cdf0e10cSrcweir 			if( nTmp >= 0 && nTmp <= SHRT_MAX )
89*cdf0e10cSrcweir 				nStartValue = (sal_Int16)nTmp;
90*cdf0e10cSrcweir 		}
91*cdf0e10cSrcweir         // --> OD 2008-05-08 #refactorlists#
92*cdf0e10cSrcweir         else if ( nPrefix == XML_NAMESPACE_TEXT &&
93*cdf0e10cSrcweir                   IsXMLToken( aLocalName, XML_STYLE_OVERRIDE ) )
94*cdf0e10cSrcweir         {
95*cdf0e10cSrcweir             const ::rtl::OUString sListStyleOverrideName = rValue;
96*cdf0e10cSrcweir             if ( sListStyleOverrideName.getLength() > 0 )
97*cdf0e10cSrcweir             {
98*cdf0e10cSrcweir                 OUString sDisplayStyleName(
99*cdf0e10cSrcweir                         GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
100*cdf0e10cSrcweir                                                          sListStyleOverrideName ) );
101*cdf0e10cSrcweir                 const Reference < container::XNameContainer >& rNumStyles =
102*cdf0e10cSrcweir                                                     rTxtImp.GetNumberingStyles();
103*cdf0e10cSrcweir                 if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
104*cdf0e10cSrcweir                 {
105*cdf0e10cSrcweir                     Reference < style::XStyle > xStyle;
106*cdf0e10cSrcweir                     Any aAny = rNumStyles->getByName( sDisplayStyleName );
107*cdf0e10cSrcweir                     aAny >>= xStyle;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
110*cdf0e10cSrcweir                     aAny = xPropSet->getPropertyValue(s_NumberingRules);
111*cdf0e10cSrcweir                     aAny >>= mxNumRulesOverride;
112*cdf0e10cSrcweir                 }
113*cdf0e10cSrcweir                 else
114*cdf0e10cSrcweir                 {
115*cdf0e10cSrcweir                     const SvxXMLListStyleContext* pListStyle =
116*cdf0e10cSrcweir                                         rTxtImp.FindAutoListStyle( sListStyleOverrideName );
117*cdf0e10cSrcweir                     if( pListStyle )
118*cdf0e10cSrcweir                     {
119*cdf0e10cSrcweir                         mxNumRulesOverride = pListStyle->GetNumRules();
120*cdf0e10cSrcweir                         if( !mxNumRulesOverride.is() )
121*cdf0e10cSrcweir                         {
122*cdf0e10cSrcweir                             pListStyle->CreateAndInsertAuto();
123*cdf0e10cSrcweir                             mxNumRulesOverride = pListStyle->GetNumRules();
124*cdf0e10cSrcweir                         }
125*cdf0e10cSrcweir                     }
126*cdf0e10cSrcweir                 }
127*cdf0e10cSrcweir             }
128*cdf0e10cSrcweir         }
129*cdf0e10cSrcweir         // <--
130*cdf0e10cSrcweir 		else if ( (XML_NAMESPACE_XML == nPrefix) &&
131*cdf0e10cSrcweir 			 IsXMLToken(aLocalName, XML_ID)   )
132*cdf0e10cSrcweir 		{
133*cdf0e10cSrcweir 			(void) rValue;
134*cdf0e10cSrcweir //FIXME: there is no UNO API for list items
135*cdf0e10cSrcweir 		}
136*cdf0e10cSrcweir 	}
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	// If this is a <text:list-item> element, then remember it as a sign
139*cdf0e10cSrcweir 	// that a bullet has to be generated.
140*cdf0e10cSrcweir 	if( !bIsHeader ) {
141*cdf0e10cSrcweir 		rTxtImport.GetTextListHelper().SetListItem( this );
142*cdf0e10cSrcweir     }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir XMLTextListItemContext::~XMLTextListItemContext()
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir void XMLTextListItemContext::EndElement()
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	// finish current list item
153*cdf0e10cSrcweir 	rTxtImport.GetTextListHelper().SetListItem( 0 );
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir SvXMLImportContext *XMLTextListItemContext::CreateChildContext(
157*cdf0e10cSrcweir 		sal_uInt16 nPrefix,
158*cdf0e10cSrcweir 		const OUString& rLocalName,
159*cdf0e10cSrcweir 		const Reference< xml::sax::XAttributeList > & xAttrList )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir 	SvXMLImportContext *pContext = 0;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap();
164*cdf0e10cSrcweir 	sal_Bool bHeading = sal_False;
165*cdf0e10cSrcweir 	switch( rTokenMap.Get( nPrefix, rLocalName ) )
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir 	case XML_TOK_TEXT_H:
168*cdf0e10cSrcweir 		bHeading = sal_True;
169*cdf0e10cSrcweir 	case XML_TOK_TEXT_P:
170*cdf0e10cSrcweir 		pContext = new XMLParaContext( GetImport(),
171*cdf0e10cSrcweir 									   nPrefix, rLocalName,
172*cdf0e10cSrcweir 									   xAttrList, bHeading );
173*cdf0e10cSrcweir         if (rTxtImport.IsProgress())
174*cdf0e10cSrcweir             GetImport().GetProgressBarHelper()->Increment();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 		break;
177*cdf0e10cSrcweir 	case XML_TOK_TEXT_LIST:
178*cdf0e10cSrcweir         // --> OD 2008-05-07 #refactorlists#
179*cdf0e10cSrcweir //        pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
180*cdf0e10cSrcweir //                                            nPrefix, rLocalName,
181*cdf0e10cSrcweir //                                            xAttrList );
182*cdf0e10cSrcweir         ++mnSubListCount;
183*cdf0e10cSrcweir 		pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
184*cdf0e10cSrcweir                                                 nPrefix, rLocalName,
185*cdf0e10cSrcweir                                                 xAttrList,
186*cdf0e10cSrcweir                                                 (mnSubListCount > 1) );
187*cdf0e10cSrcweir         // <--
188*cdf0e10cSrcweir 		break;
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	if( !pContext )
192*cdf0e10cSrcweir 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	return pContext;
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 
198