xref: /AOO41X/main/xmloff/source/chart/XMLChartStyleContext.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 "XMLChartStyleContext.hxx"
31*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
32*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
33*cdf0e10cSrcweir #include <xmloff/xmlnumfi.hxx>
34*cdf0e10cSrcweir #include <xmloff/families.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "XMLChartPropertyContext.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace com::sun::star;
39*cdf0e10cSrcweir using ::xmloff::token::IsXMLToken;
40*cdf0e10cSrcweir using ::xmloff::token::XML_DATA_STYLE_NAME;
41*cdf0e10cSrcweir using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME;
42*cdf0e10cSrcweir using ::xmloff::token::XML_TEXT_PROPERTIES;
43*cdf0e10cSrcweir using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
44*cdf0e10cSrcweir using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
45*cdf0e10cSrcweir using ::xmloff::token::XML_CHART_PROPERTIES;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir TYPEINIT1( XMLChartStyleContext, XMLPropStyleContext );
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir // protected
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir void XMLChartStyleContext::SetAttribute(
53*cdf0e10cSrcweir 	sal_uInt16 nPrefixKey,
54*cdf0e10cSrcweir 	const ::rtl::OUString& rLocalName,
55*cdf0e10cSrcweir 	const ::rtl::OUString& rValue )
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir 	if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
58*cdf0e10cSrcweir 	{
59*cdf0e10cSrcweir 		msDataStyleName =rValue;
60*cdf0e10cSrcweir 	}
61*cdf0e10cSrcweir     else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
62*cdf0e10cSrcweir 	{
63*cdf0e10cSrcweir         msPercentageDataStyleName =rValue;
64*cdf0e10cSrcweir     }
65*cdf0e10cSrcweir 	else
66*cdf0e10cSrcweir 	{
67*cdf0e10cSrcweir 		XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
68*cdf0e10cSrcweir 	}
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir //public
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir // CTOR
74*cdf0e10cSrcweir XMLChartStyleContext::XMLChartStyleContext(
75*cdf0e10cSrcweir 	SvXMLImport& rImport, sal_uInt16 nPrfx,
76*cdf0e10cSrcweir 	const ::rtl::OUString& rLName,
77*cdf0e10cSrcweir 	const uno::Reference< xml::sax::XAttributeList > & xAttrList,
78*cdf0e10cSrcweir 	SvXMLStylesContext& rStyles, sal_uInt16 nFamily ) :
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir         XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
81*cdf0e10cSrcweir 		mrStyles( rStyles )
82*cdf0e10cSrcweir {}
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir // DTOR
85*cdf0e10cSrcweir XMLChartStyleContext::~XMLChartStyleContext()
86*cdf0e10cSrcweir {}
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir namespace
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     void lcl_NumberFormatStyleToProperty( const ::rtl::OUString& rStyleName, const ::rtl::OUString& rPropertyName,
92*cdf0e10cSrcweir                                       const SvXMLStylesContext& rStylesContext,
93*cdf0e10cSrcweir                                       const uno::Reference< beans::XPropertySet >& rPropSet )
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     if( rStyleName.getLength())
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 		SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)rStylesContext.FindStyleChildContext(
98*cdf0e10cSrcweir 			XML_STYLE_FAMILY_DATA_STYLE, rStyleName, sal_True );
99*cdf0e10cSrcweir 		if( pStyle )
100*cdf0e10cSrcweir 		{
101*cdf0e10cSrcweir 			uno::Any aNumberFormat;
102*cdf0e10cSrcweir 			sal_Int32 nNumberFormat = pStyle->GetKey();
103*cdf0e10cSrcweir 			aNumberFormat <<= nNumberFormat;
104*cdf0e10cSrcweir 			rPropSet->setPropertyValue( rPropertyName, aNumberFormat );
105*cdf0e10cSrcweir 		}
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir }// anonymous namespace
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void XMLChartStyleContext::FillPropertySet(
112*cdf0e10cSrcweir 	const uno::Reference< beans::XPropertySet > & rPropSet )
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     try
115*cdf0e10cSrcweir     {
116*cdf0e10cSrcweir 	    XMLShapeStyleContext::FillPropertySet( rPropSet );
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir     catch( beans::UnknownPropertyException&  )
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         DBG_ASSERT( false, "unknown property exception -> shape style not completly imported for chart style" );
121*cdf0e10cSrcweir     }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     lcl_NumberFormatStyleToProperty( msDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberFormat" )), mrStyles, rPropSet );
124*cdf0e10cSrcweir     lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PercentageNumberFormat" )), mrStyles, rPropSet );
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir SvXMLImportContext *XMLChartStyleContext::CreateChildContext(
128*cdf0e10cSrcweir     sal_uInt16 nPrefix,
129*cdf0e10cSrcweir     const ::rtl::OUString& rLocalName,
130*cdf0e10cSrcweir     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir 	SvXMLImportContext* pContext = NULL;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	if( XML_NAMESPACE_STYLE == nPrefix )
135*cdf0e10cSrcweir 	{
136*cdf0e10cSrcweir 		sal_uInt32 nFamily = 0;
137*cdf0e10cSrcweir 		if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
138*cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_TEXT;
139*cdf0e10cSrcweir 		else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
140*cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_PARAGRAPH;
141*cdf0e10cSrcweir 		else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
142*cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_GRAPHIC;
143*cdf0e10cSrcweir 		else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
144*cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_CHART;
145*cdf0e10cSrcweir 		if( nFamily )
146*cdf0e10cSrcweir 		{
147*cdf0e10cSrcweir 			UniReference < SvXMLImportPropertyMapper > xImpPrMap =
148*cdf0e10cSrcweir 				GetStyles()->GetImportPropertyMapper( GetFamily() );
149*cdf0e10cSrcweir 			if( xImpPrMap.is() )
150*cdf0e10cSrcweir 				pContext = new XMLChartPropertyContext(
151*cdf0e10cSrcweir 					GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
152*cdf0e10cSrcweir 					GetProperties(), xImpPrMap );
153*cdf0e10cSrcweir 		}
154*cdf0e10cSrcweir 	}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	if( !pContext )
157*cdf0e10cSrcweir 		pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
158*cdf0e10cSrcweir                                                              xAttrList );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	return pContext;
161*cdf0e10cSrcweir }
162