Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / chart / XMLChartStyleContext.cxx
bloba3fc7a8299482eb926887c6de082d8a33e77f4d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLChartStyleContext.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlnmspe.hxx>
23 #include <xmloff/xmlnumfi.hxx>
24 #include <xmloff/families.hxx>
25 #include <xmloff/xmltypes.hxx>
26 #include <tools/debug.hxx>
28 #include "XMLChartPropertyContext.hxx"
30 using namespace com::sun::star;
31 using ::xmloff::token::IsXMLToken;
32 using ::xmloff::token::XML_DATA_STYLE_NAME;
33 using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME;
34 using ::xmloff::token::XML_TEXT_PROPERTIES;
35 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
36 using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
37 using ::xmloff::token::XML_CHART_PROPERTIES;
40 void XMLChartStyleContext::SetAttribute(
41 sal_uInt16 nPrefixKey,
42 const OUString& rLocalName,
43 const OUString& rValue )
45 if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
47 msDataStyleName =rValue;
49 else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
51 msPercentageDataStyleName =rValue;
53 else
55 XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
59 XMLChartStyleContext::XMLChartStyleContext(
60 SvXMLImport& rImport, sal_uInt16 nPrfx,
61 const OUString& rLName,
62 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
63 SvXMLStylesContext& rStyles, sal_uInt16 nFamily ) :
65 XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
66 mrStyles( rStyles )
69 XMLChartStyleContext::~XMLChartStyleContext()
72 namespace
75 void lcl_NumberFormatStyleToProperty( const OUString& rStyleName, const OUString& rPropertyName,
76 const SvXMLStylesContext& rStylesContext,
77 const uno::Reference< beans::XPropertySet >& rPropSet )
79 if( !rStyleName.isEmpty())
81 const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext *>(rStylesContext.FindStyleChildContext(
82 XML_STYLE_FAMILY_DATA_STYLE, rStyleName, true ));
83 if( pStyle )
85 sal_Int32 nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
86 rPropSet->setPropertyValue( rPropertyName, uno::Any(nNumberFormat) );
93 void XMLChartStyleContext::FillPropertySet(
94 const uno::Reference< beans::XPropertySet > & rPropSet )
96 try
98 XMLShapeStyleContext::FillPropertySet( rPropSet );
100 catch( beans::UnknownPropertyException& )
102 DBG_ASSERT( false, "unknown property exception -> shape style not completely imported for chart style" );
105 lcl_NumberFormatStyleToProperty( msDataStyleName, "NumberFormat", mrStyles, rPropSet );
106 lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, "PercentageNumberFormat", mrStyles, rPropSet );
109 SvXMLImportContext *XMLChartStyleContext::CreateChildContext(
110 sal_uInt16 nPrefix,
111 const OUString& rLocalName,
112 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
114 SvXMLImportContext* pContext = nullptr;
116 if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
118 sal_uInt32 nFamily = 0;
119 if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
120 nFamily = XML_TYPE_PROP_TEXT;
121 else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
122 nFamily = XML_TYPE_PROP_PARAGRAPH;
123 else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
124 nFamily = XML_TYPE_PROP_GRAPHIC;
125 else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
126 nFamily = XML_TYPE_PROP_CHART;
127 if( nFamily )
129 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
130 GetStyles()->GetImportPropertyMapper( GetFamily() );
131 if( xImpPrMap.is() )
132 pContext = new XMLChartPropertyContext(
133 GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
134 GetProperties(), xImpPrMap );
138 if( !pContext )
139 pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
140 xAttrList );
142 return pContext;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */