1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <xmloff/xmlimppr.hxx>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <tools/diagnose_ex.h>
31 #include "XMLChartPropertyContext.hxx"
33 using namespace com::sun::star
;
34 using ::xmloff::token::IsXMLToken
;
35 using ::xmloff::token::XML_DATA_STYLE_NAME
;
36 using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME
;
37 using ::xmloff::token::XML_TEXT_PROPERTIES
;
38 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES
;
39 using ::xmloff::token::XML_GRAPHIC_PROPERTIES
;
40 using ::xmloff::token::XML_CHART_PROPERTIES
;
43 void XMLChartStyleContext::SetAttribute(
44 sal_uInt16 nPrefixKey
,
45 const OUString
& rLocalName
,
46 const OUString
& rValue
)
48 if( IsXMLToken( rLocalName
, XML_DATA_STYLE_NAME
) )
50 msDataStyleName
=rValue
;
52 else if( IsXMLToken( rLocalName
, XML_PERCENTAGE_DATA_STYLE_NAME
) )
54 msPercentageDataStyleName
=rValue
;
58 XMLShapeStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
62 XMLChartStyleContext::XMLChartStyleContext(
63 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
64 const OUString
& rLName
,
65 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
66 SvXMLStylesContext
& rStyles
, sal_uInt16 nFamily
) :
68 XMLShapeStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, nFamily
),
72 XMLChartStyleContext::~XMLChartStyleContext()
78 void lcl_NumberFormatStyleToProperty( const OUString
& rStyleName
, const OUString
& rPropertyName
,
79 const SvXMLStylesContext
& rStylesContext
,
80 const uno::Reference
< beans::XPropertySet
>& rPropSet
)
82 if( !rStyleName
.isEmpty())
84 const SvXMLNumFormatContext
* pStyle
= static_cast<const SvXMLNumFormatContext
*>(rStylesContext
.FindStyleChildContext(
85 XML_STYLE_FAMILY_DATA_STYLE
, rStyleName
, true ));
88 sal_Int32 nNumberFormat
= const_cast<SvXMLNumFormatContext
*>(pStyle
)->GetKey();
89 rPropSet
->setPropertyValue( rPropertyName
, uno::Any(nNumberFormat
) );
96 void XMLChartStyleContext::FillPropertySet(
97 const uno::Reference
< beans::XPropertySet
> & rPropSet
)
101 XMLShapeStyleContext::FillPropertySet( rPropSet
);
103 catch( beans::UnknownPropertyException
& )
105 TOOLS_WARN_EXCEPTION( "xmloff", "unknown property exception -> shape style not completely imported for chart style" );
108 lcl_NumberFormatStyleToProperty( msDataStyleName
, "NumberFormat", mrStyles
, rPropSet
);
109 lcl_NumberFormatStyleToProperty( msPercentageDataStyleName
, "PercentageNumberFormat", mrStyles
, rPropSet
);
112 SvXMLImportContextRef
XMLChartStyleContext::CreateChildContext(
114 const OUString
& rLocalName
,
115 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
117 SvXMLImportContextRef xContext
;
119 if( XML_NAMESPACE_STYLE
== nPrefix
|| XML_NAMESPACE_LO_EXT
== nPrefix
)
121 sal_uInt32 nFamily
= 0;
122 if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
123 nFamily
= XML_TYPE_PROP_TEXT
;
124 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
125 nFamily
= XML_TYPE_PROP_PARAGRAPH
;
126 else if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
127 nFamily
= XML_TYPE_PROP_GRAPHIC
;
128 else if( IsXMLToken( rLocalName
, XML_CHART_PROPERTIES
) )
129 nFamily
= XML_TYPE_PROP_CHART
;
132 rtl::Reference
< SvXMLImportPropertyMapper
> xImpPrMap
=
133 GetStyles()->GetImportPropertyMapper( GetFamily() );
135 xContext
= new XMLChartPropertyContext(
136 GetImport(), nPrefix
, rLocalName
, xAttrList
, nFamily
,
137 GetProperties(), xImpPrMap
);
142 xContext
= XMLShapeStyleContext::CreateChildContext( nPrefix
, rLocalName
,
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */