xref: /AOO41X/main/xmloff/source/chart/XMLChartStyleContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "XMLChartStyleContext.hxx"
27cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
28cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
29cdf0e10cSrcweir #include <xmloff/xmlnumfi.hxx>
30cdf0e10cSrcweir #include <xmloff/families.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "XMLChartPropertyContext.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace com::sun::star;
35cdf0e10cSrcweir using ::xmloff::token::IsXMLToken;
36cdf0e10cSrcweir using ::xmloff::token::XML_DATA_STYLE_NAME;
37cdf0e10cSrcweir using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME;
38cdf0e10cSrcweir using ::xmloff::token::XML_TEXT_PROPERTIES;
39cdf0e10cSrcweir using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
40cdf0e10cSrcweir using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
41cdf0e10cSrcweir using ::xmloff::token::XML_CHART_PROPERTIES;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir TYPEINIT1( XMLChartStyleContext, XMLPropStyleContext );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // protected
47cdf0e10cSrcweir 
SetAttribute(sal_uInt16 nPrefixKey,const::rtl::OUString & rLocalName,const::rtl::OUString & rValue)48cdf0e10cSrcweir void XMLChartStyleContext::SetAttribute(
49cdf0e10cSrcweir 	sal_uInt16 nPrefixKey,
50cdf0e10cSrcweir 	const ::rtl::OUString& rLocalName,
51cdf0e10cSrcweir 	const ::rtl::OUString& rValue )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir 		msDataStyleName =rValue;
56cdf0e10cSrcweir 	}
57cdf0e10cSrcweir     else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir         msPercentageDataStyleName =rValue;
60cdf0e10cSrcweir     }
61cdf0e10cSrcweir 	else
62cdf0e10cSrcweir 	{
63cdf0e10cSrcweir 		XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
64cdf0e10cSrcweir 	}
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir //public
68cdf0e10cSrcweir 
69cdf0e10cSrcweir // CTOR
XMLChartStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily)70cdf0e10cSrcweir XMLChartStyleContext::XMLChartStyleContext(
71cdf0e10cSrcweir 	SvXMLImport& rImport, sal_uInt16 nPrfx,
72cdf0e10cSrcweir 	const ::rtl::OUString& rLName,
73cdf0e10cSrcweir 	const uno::Reference< xml::sax::XAttributeList > & xAttrList,
74cdf0e10cSrcweir 	SvXMLStylesContext& rStyles, sal_uInt16 nFamily ) :
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
77cdf0e10cSrcweir 		mrStyles( rStyles )
78cdf0e10cSrcweir {}
79cdf0e10cSrcweir 
80cdf0e10cSrcweir // DTOR
~XMLChartStyleContext()81cdf0e10cSrcweir XMLChartStyleContext::~XMLChartStyleContext()
82cdf0e10cSrcweir {}
83cdf0e10cSrcweir 
84cdf0e10cSrcweir namespace
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 
lcl_NumberFormatStyleToProperty(const::rtl::OUString & rStyleName,const::rtl::OUString & rPropertyName,const SvXMLStylesContext & rStylesContext,const uno::Reference<beans::XPropertySet> & rPropSet)87cdf0e10cSrcweir     void lcl_NumberFormatStyleToProperty( const ::rtl::OUString& rStyleName, const ::rtl::OUString& rPropertyName,
88cdf0e10cSrcweir                                       const SvXMLStylesContext& rStylesContext,
89cdf0e10cSrcweir                                       const uno::Reference< beans::XPropertySet >& rPropSet )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     if( rStyleName.getLength())
92cdf0e10cSrcweir 	{
93cdf0e10cSrcweir 		SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)rStylesContext.FindStyleChildContext(
94cdf0e10cSrcweir 			XML_STYLE_FAMILY_DATA_STYLE, rStyleName, sal_True );
95cdf0e10cSrcweir 		if( pStyle )
96cdf0e10cSrcweir 		{
97cdf0e10cSrcweir 			uno::Any aNumberFormat;
98cdf0e10cSrcweir 			sal_Int32 nNumberFormat = pStyle->GetKey();
99cdf0e10cSrcweir 			aNumberFormat <<= nNumberFormat;
100cdf0e10cSrcweir 			rPropSet->setPropertyValue( rPropertyName, aNumberFormat );
101cdf0e10cSrcweir 		}
102cdf0e10cSrcweir 	}
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir }// anonymous namespace
106cdf0e10cSrcweir 
FillPropertySet(const uno::Reference<beans::XPropertySet> & rPropSet)107cdf0e10cSrcweir void XMLChartStyleContext::FillPropertySet(
108cdf0e10cSrcweir 	const uno::Reference< beans::XPropertySet > & rPropSet )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     try
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir 	    XMLShapeStyleContext::FillPropertySet( rPropSet );
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir     catch( beans::UnknownPropertyException&  )
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         DBG_ASSERT( false, "unknown property exception -> shape style not completly imported for chart style" );
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     lcl_NumberFormatStyleToProperty( msDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberFormat" )), mrStyles, rPropSet );
120cdf0e10cSrcweir     lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PercentageNumberFormat" )), mrStyles, rPropSet );
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)123cdf0e10cSrcweir SvXMLImportContext *XMLChartStyleContext::CreateChildContext(
124cdf0e10cSrcweir     sal_uInt16 nPrefix,
125cdf0e10cSrcweir     const ::rtl::OUString& rLocalName,
126cdf0e10cSrcweir     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	SvXMLImportContext* pContext = NULL;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	if( XML_NAMESPACE_STYLE == nPrefix )
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		sal_uInt32 nFamily = 0;
133cdf0e10cSrcweir 		if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
134cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_TEXT;
135cdf0e10cSrcweir 		else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
136cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_PARAGRAPH;
137cdf0e10cSrcweir 		else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
138cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_GRAPHIC;
139cdf0e10cSrcweir 		else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
140cdf0e10cSrcweir 			nFamily = XML_TYPE_PROP_CHART;
141cdf0e10cSrcweir 		if( nFamily )
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			UniReference < SvXMLImportPropertyMapper > xImpPrMap =
144cdf0e10cSrcweir 				GetStyles()->GetImportPropertyMapper( GetFamily() );
145cdf0e10cSrcweir 			if( xImpPrMap.is() )
146cdf0e10cSrcweir 				pContext = new XMLChartPropertyContext(
147cdf0e10cSrcweir 					GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
148cdf0e10cSrcweir 					GetProperties(), xImpPrMap );
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	if( !pContext )
153cdf0e10cSrcweir 		pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
154cdf0e10cSrcweir                                                              xAttrList );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	return pContext;
157cdf0e10cSrcweir }
158