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/titlecontext.hxx>
22 #include <drawingml/shapepropertiescontext.hxx>
23 #include <drawingml/textbodycontext.hxx>
24 #include <drawingml/chart/datasourcecontext.hxx>
25 #include <drawingml/chart/titlemodel.hxx>
26 #include <oox/helper/attributelist.hxx>
27 #include <oox/token/namespaces.hxx>
28 #include <oox/token/tokens.hxx>
30 #include <osl/diagnose.h>
33 namespace oox::drawingml::chart
{
35 using ::oox::core::ContextHandler2Helper
;
36 using ::oox::core::ContextHandlerRef
;
38 TextContext::TextContext( ContextHandler2Helper
& rParent
, TextModel
& rModel
) :
39 ContextBase
< TextModel
>( rParent
, rModel
)
43 TextContext::~TextContext()
47 ContextHandlerRef
TextContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& )
49 // this context handler is used for <c:tx> and embedded <c:v> elements
50 if( isCurrentElement( C_TOKEN( tx
) ) ) switch( nElement
)
53 return new TextBodyContext( *this, mrModel
.mxTextBody
.create() );
55 case C_TOKEN( strRef
):
56 OSL_ENSURE( !mrModel
.mxDataSeq
, "TextContext::onCreateContext - multiple data sequences" );
57 return new StringSequenceContext( *this, mrModel
.mxDataSeq
.create() );
60 OSL_ENSURE( !mrModel
.mxDataSeq
, "TextContext::onCreateContext - multiple data sequences" );
61 return this; // collect value in onCharacters()
66 void TextContext::onCharacters( const OUString
& rChars
)
68 if( isCurrentElement( C_TOKEN( v
) ) )
70 // Static text is stored as a single string formula token for Excel document.
71 mrModel
.mxDataSeq
.create().maFormula
= "\"" + rChars
+ "\"";
73 // Also store it as a single element type for non-Excel document.
74 mrModel
.mxDataSeq
->maData
[0] <<= rChars
;
75 mrModel
.mxDataSeq
->mnPointCount
= 1;
79 TitleContext::TitleContext( ContextHandler2Helper
& rParent
, TitleModel
& rModel
) :
80 ContextBase
< TitleModel
>( rParent
, rModel
)
84 TitleContext::~TitleContext()
88 ContextHandlerRef
TitleContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
90 // this context handler is used for <c:title> only
93 case C_TOKEN( layout
):
94 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
96 case C_TOKEN( overlay
):
97 mrModel
.mbOverlay
= rAttribs
.getBool( XML_val
, true );
100 case C_TOKEN( spPr
):
101 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
104 return new TextContext( *this, mrModel
.mxText
.create() );
106 case C_TOKEN( txPr
):
107 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
112 LegendEntryContext::LegendEntryContext( ContextHandler2Helper
& rParent
, LegendEntryModel
& rModel
) :
113 ContextBase
< LegendEntryModel
>( rParent
, rModel
)
117 LegendEntryContext::~LegendEntryContext()
121 ContextHandlerRef
LegendEntryContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
123 // this context handler is used for <c:legendEntry> only
127 mrModel
.mnLegendEntryIdx
= rAttribs
.getInteger( XML_val
, -1 );
130 case C_TOKEN( delete ):
131 mrModel
.mbLabelDeleted
= rAttribs
.getBool( XML_val
, true );
137 LegendContext::LegendContext( ContextHandler2Helper
& rParent
, LegendModel
& rModel
) :
138 ContextBase
< LegendModel
>( rParent
, rModel
)
142 LegendContext::~LegendContext()
146 ContextHandlerRef
LegendContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
148 // this context handler is used for <c:legend> only
151 case C_TOKEN( layout
):
152 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
154 case C_TOKEN( legendPos
):
155 mrModel
.mnPosition
= rAttribs
.getToken( XML_val
, XML_r
);
158 case C_TOKEN( legendEntry
):
159 return new LegendEntryContext( *this, mrModel
.maLegendEntries
.create() );
161 case C_TOKEN( overlay
):
162 mrModel
.mbOverlay
= rAttribs
.getBool( XML_val
, true );
165 case C_TOKEN( spPr
):
166 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
168 case C_TOKEN( txPr
):
169 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
174 } // namespace oox::drawingml::chart
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */