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 <drawingml/chart/datasourcecontext.hxx>
22 #include <oox/drawingml/chart/datasourcemodel.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <oox/core/xmlfilterbase.hxx>
26 #include <oox/helper/attributelist.hxx>
27 #include <oox/token/namespaces.hxx>
28 #include <oox/token/tokens.hxx>
29 #include <svl/zforlist.hxx>
30 #include <osl/diagnose.h>
36 using ::oox::core::ContextHandler2Helper
;
37 using ::oox::core::ContextHandlerRef
;
39 using namespace ::com::sun::star
;
41 DoubleSequenceContext::DoubleSequenceContext( ContextHandler2Helper
& rParent
, DataSequenceModel
& rModel
) :
42 DataSequenceContextBase( rParent
, rModel
),
47 DoubleSequenceContext::~DoubleSequenceContext()
51 ContextHandlerRef
DoubleSequenceContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
53 switch( getCurrentElement() )
55 case C_TOKEN( numRef
):
59 case C_TOKEN( numCache
):
64 case C_TOKEN( numCache
):
65 case C_TOKEN( numLit
):
68 case C_TOKEN( formatCode
):
70 case C_TOKEN( ptCount
):
71 mrModel
.mnPointCount
= rAttribs
.getInteger( XML_val
, -1 );
74 mnPtIndex
= rAttribs
.getInteger( XML_idx
, -1 );
90 void DoubleSequenceContext::onCharacters( const OUString
& rChars
)
92 switch( getCurrentElement() )
95 mrModel
.maFormula
= rChars
;
97 case C_TOKEN( formatCode
):
98 mrModel
.maFormatCode
= rChars
;
103 /* Import categories as String even though it could
105 * n#810508: xVal needs to be imported as double
106 * TODO: NumberFormat conversion, remove the check then.
108 if( isParentElement( C_TOKEN( cat
), 4 ) )
110 // workaround for bug n#889755
111 SvNumberFormatter
* pNumFrmt
= getNumberFormatter();
114 sal_uInt32 nKey
= pNumFrmt
->GetEntryKey( mrModel
.maFormatCode
);
115 bool bNoKey
= ( nKey
== NUMBERFORMAT_ENTRY_NOT_FOUND
);
118 OUString aFormatCode
= mrModel
.maFormatCode
;
119 sal_Int32 nCheckPos
= 0;
120 SvNumFormatType nType
;
121 pNumFrmt
->PutEntry( aFormatCode
, nCheckPos
, nType
, nKey
);
122 bNoKey
= (nCheckPos
!= 0);
126 mrModel
.maData
[ mnPtIndex
] <<= rChars
;
130 double fValue
= rChars
.toDouble();
131 ::Color
* pColor
= nullptr;
132 OUString aFormattedValue
;
133 pNumFrmt
->GetOutputString( fValue
, nKey
, aFormattedValue
, &pColor
);
134 mrModel
.maData
[ mnPtIndex
] <<= aFormattedValue
;
139 mrModel
.maData
[ mnPtIndex
] <<= rChars
;
144 mrModel
.maData
[ mnPtIndex
] <<= rChars
.toDouble();
152 SvNumberFormatter
* DoubleSequenceContext::getNumberFormatter()
154 if( mpNumberFormatter
== nullptr )
156 uno::Reference
<uno::XComponentContext
> rContext
=
157 getFilter().getComponentContext();
158 mpNumberFormatter
.reset(
159 new SvNumberFormatter(rContext
, LANGUAGE_DONTKNOW
) );
161 return mpNumberFormatter
.get();
165 StringSequenceContext::StringSequenceContext( ContextHandler2Helper
& rParent
, DataSequenceModel
& rModel
)
166 : DataSequenceContextBase( rParent
, rModel
)
171 StringSequenceContext::~StringSequenceContext()
175 ContextHandlerRef
StringSequenceContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
177 switch( getCurrentElement() )
179 case C_TOKEN( multiLvlStrRef
):
183 case C_TOKEN( multiLvlStrCache
):
188 case C_TOKEN( strRef
):
192 case C_TOKEN( strCache
):
197 case C_TOKEN( strCache
):
198 case C_TOKEN( strLit
):
201 case C_TOKEN( ptCount
):
202 mrModel
.mnPointCount
= rAttribs
.getInteger( XML_val
, -1 );
205 mnPtIndex
= rAttribs
.getInteger( XML_idx
, -1 );
210 case C_TOKEN( multiLvlStrCache
):
213 case C_TOKEN( ptCount
):
214 mrModel
.mnPointCount
= rAttribs
.getInteger(XML_val
, -1);
215 mrModel
.mnLevelCount
--; // normalize level count
218 mrModel
.mnLevelCount
++;
227 mnPtIndex
= rAttribs
.getInteger(XML_idx
, -1);
243 void StringSequenceContext::onCharacters( const OUString
& rChars
)
245 switch( getCurrentElement() )
248 mrModel
.maFormula
= rChars
;
252 mrModel
.maData
[ (mrModel
.mnLevelCount
-1) * mrModel
.mnPointCount
+ mnPtIndex
] <<= rChars
;
257 DataSourceContext::DataSourceContext( ContextHandler2Helper
& rParent
, DataSourceModel
& rModel
) :
258 ContextBase
< DataSourceModel
>( rParent
, rModel
)
262 DataSourceContext::~DataSourceContext()
266 ContextHandlerRef
DataSourceContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& )
268 switch( getCurrentElement() )
271 case C_TOKEN( xVal
):
274 case C_TOKEN( multiLvlStrRef
):
275 case C_TOKEN( strLit
):
276 case C_TOKEN( strRef
):
277 OSL_ENSURE( !mrModel
.mxDataSeq
, "DataSourceContext::onCreateContext - multiple data sequences" );
278 return new StringSequenceContext( *this, mrModel
.mxDataSeq
.create() );
280 case C_TOKEN( numLit
):
281 case C_TOKEN( numRef
):
282 OSL_ENSURE( !mrModel
.mxDataSeq
, "DataSourceContext::onCreateContext - multiple data sequences" );
283 return new DoubleSequenceContext( *this, mrModel
.mxDataSeq
.create() );
287 case C_TOKEN( plus
):
288 case C_TOKEN( minus
):
290 case C_TOKEN( yVal
):
291 case C_TOKEN( bubbleSize
):
294 case C_TOKEN( numLit
):
295 case C_TOKEN( numRef
):
296 OSL_ENSURE( !mrModel
.mxDataSeq
, "DataSourceContext::onCreateContext - multiple data sequences" );
297 return new DoubleSequenceContext( *this, mrModel
.mxDataSeq
.create() );
305 } // namespace drawingml
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */