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>
26 #include "XMLChartPropertyContext.hxx"
28 using namespace com::sun::star
;
29 using ::xmloff::token::IsXMLToken
;
30 using ::xmloff::token::XML_DATA_STYLE_NAME
;
31 using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME
;
32 using ::xmloff::token::XML_TEXT_PROPERTIES
;
33 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES
;
34 using ::xmloff::token::XML_GRAPHIC_PROPERTIES
;
35 using ::xmloff::token::XML_CHART_PROPERTIES
;
38 TYPEINIT1( XMLChartStyleContext
, XMLPropStyleContext
);
42 void XMLChartStyleContext::SetAttribute(
43 sal_uInt16 nPrefixKey
,
44 const OUString
& rLocalName
,
45 const OUString
& rValue
)
47 if( IsXMLToken( rLocalName
, XML_DATA_STYLE_NAME
) )
49 msDataStyleName
=rValue
;
51 else if( IsXMLToken( rLocalName
, XML_PERCENTAGE_DATA_STYLE_NAME
) )
53 msPercentageDataStyleName
=rValue
;
57 XMLShapeStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
64 XMLChartStyleContext::XMLChartStyleContext(
65 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
66 const OUString
& rLName
,
67 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
68 SvXMLStylesContext
& rStyles
, sal_uInt16 nFamily
) :
70 XMLShapeStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, nFamily
),
75 XMLChartStyleContext::~XMLChartStyleContext()
81 void lcl_NumberFormatStyleToProperty( const OUString
& rStyleName
, const OUString
& rPropertyName
,
82 const SvXMLStylesContext
& rStylesContext
,
83 const uno::Reference
< beans::XPropertySet
>& rPropSet
)
85 if( !rStyleName
.isEmpty())
87 SvXMLNumFormatContext
* pStyle
= (SvXMLNumFormatContext
*)rStylesContext
.FindStyleChildContext(
88 XML_STYLE_FAMILY_DATA_STYLE
, rStyleName
, sal_True
);
91 uno::Any aNumberFormat
;
92 sal_Int32 nNumberFormat
= pStyle
->GetKey();
93 aNumberFormat
<<= nNumberFormat
;
94 rPropSet
->setPropertyValue( rPropertyName
, aNumberFormat
);
99 }// anonymous namespace
101 void XMLChartStyleContext::FillPropertySet(
102 const uno::Reference
< beans::XPropertySet
> & rPropSet
)
106 XMLShapeStyleContext::FillPropertySet( rPropSet
);
108 catch( beans::UnknownPropertyException
& )
110 DBG_ASSERT( false, "unknown property exception -> shape style not completely imported for chart style" );
113 lcl_NumberFormatStyleToProperty( msDataStyleName
, OUString( "NumberFormat" ), mrStyles
, rPropSet
);
114 lcl_NumberFormatStyleToProperty( msPercentageDataStyleName
, OUString( "PercentageNumberFormat" ), mrStyles
, rPropSet
);
117 SvXMLImportContext
*XMLChartStyleContext::CreateChildContext(
119 const OUString
& rLocalName
,
120 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
122 SvXMLImportContext
* pContext
= NULL
;
124 if( XML_NAMESPACE_STYLE
== nPrefix
)
126 sal_uInt32 nFamily
= 0;
127 if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) )
128 nFamily
= XML_TYPE_PROP_TEXT
;
129 else if( IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
) )
130 nFamily
= XML_TYPE_PROP_PARAGRAPH
;
131 else if( IsXMLToken( rLocalName
, XML_GRAPHIC_PROPERTIES
) )
132 nFamily
= XML_TYPE_PROP_GRAPHIC
;
133 else if( IsXMLToken( rLocalName
, XML_CHART_PROPERTIES
) )
134 nFamily
= XML_TYPE_PROP_CHART
;
137 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
138 GetStyles()->GetImportPropertyMapper( GetFamily() );
140 pContext
= new XMLChartPropertyContext(
141 GetImport(), nPrefix
, rLocalName
, xAttrList
, nFamily
,
142 GetProperties(), xImpPrMap
);
147 pContext
= XMLShapeStyleContext::CreateChildContext( nPrefix
, rLocalName
,
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */