Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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 :
26 : #include "XMLChartPropertyContext.hxx"
27 :
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;
36 :
37 :
38 0 : TYPEINIT1( XMLChartStyleContext, XMLPropStyleContext );
39 :
40 0 : void XMLChartStyleContext::SetAttribute(
41 : sal_uInt16 nPrefixKey,
42 : const OUString& rLocalName,
43 : const OUString& rValue )
44 : {
45 0 : if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
46 : {
47 0 : msDataStyleName =rValue;
48 : }
49 0 : else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
50 : {
51 0 : msPercentageDataStyleName =rValue;
52 : }
53 : else
54 : {
55 0 : XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
56 : }
57 0 : }
58 :
59 0 : 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 ) :
64 :
65 : XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
66 0 : mrStyles( rStyles )
67 0 : {}
68 :
69 0 : XMLChartStyleContext::~XMLChartStyleContext()
70 0 : {}
71 :
72 : namespace
73 : {
74 :
75 0 : void lcl_NumberFormatStyleToProperty( const OUString& rStyleName, const OUString& rPropertyName,
76 : const SvXMLStylesContext& rStylesContext,
77 : const uno::Reference< beans::XPropertySet >& rPropSet )
78 : {
79 0 : if( !rStyleName.isEmpty())
80 : {
81 : SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)rStylesContext.FindStyleChildContext(
82 0 : XML_STYLE_FAMILY_DATA_STYLE, rStyleName, true );
83 0 : if( pStyle )
84 : {
85 0 : uno::Any aNumberFormat;
86 0 : sal_Int32 nNumberFormat = pStyle->GetKey();
87 0 : aNumberFormat <<= nNumberFormat;
88 0 : rPropSet->setPropertyValue( rPropertyName, aNumberFormat );
89 : }
90 : }
91 0 : }
92 :
93 : }
94 :
95 0 : void XMLChartStyleContext::FillPropertySet(
96 : const uno::Reference< beans::XPropertySet > & rPropSet )
97 : {
98 : try
99 : {
100 0 : XMLShapeStyleContext::FillPropertySet( rPropSet );
101 : }
102 0 : catch( beans::UnknownPropertyException& )
103 : {
104 : DBG_ASSERT( false, "unknown property exception -> shape style not completely imported for chart style" );
105 : }
106 :
107 0 : lcl_NumberFormatStyleToProperty( msDataStyleName, OUString( "NumberFormat" ), mrStyles, rPropSet );
108 0 : lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, OUString( "PercentageNumberFormat" ), mrStyles, rPropSet );
109 0 : }
110 :
111 0 : SvXMLImportContext *XMLChartStyleContext::CreateChildContext(
112 : sal_uInt16 nPrefix,
113 : const OUString& rLocalName,
114 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
115 : {
116 0 : SvXMLImportContext* pContext = NULL;
117 :
118 0 : if( XML_NAMESPACE_STYLE == nPrefix )
119 : {
120 0 : sal_uInt32 nFamily = 0;
121 0 : if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
122 0 : nFamily = XML_TYPE_PROP_TEXT;
123 0 : else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
124 0 : nFamily = XML_TYPE_PROP_PARAGRAPH;
125 0 : else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
126 0 : nFamily = XML_TYPE_PROP_GRAPHIC;
127 0 : else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
128 0 : nFamily = XML_TYPE_PROP_CHART;
129 0 : if( nFamily )
130 : {
131 : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
132 0 : GetStyles()->GetImportPropertyMapper( GetFamily() );
133 0 : if( xImpPrMap.is() )
134 : pContext = new XMLChartPropertyContext(
135 0 : GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
136 0 : GetProperties(), xImpPrMap );
137 : }
138 : }
139 :
140 0 : if( !pContext )
141 : pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
142 0 : xAttrList );
143 :
144 0 : return pContext;
145 : }
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|