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 "oox/drawingml/chart/titlecontext.hxx"
22 #include "oox/drawingml/shapepropertiescontext.hxx"
23 #include "oox/drawingml/textbodycontext.hxx"
24 #include "oox/drawingml/chart/datasourcecontext.hxx"
25 #include "oox/drawingml/chart/titlemodel.hxx"
27 #include "rtl/ustrbuf.hxx"
33 // ============================================================================
35 using ::oox::core::ContextHandler2Helper
;
36 using ::oox::core::ContextHandlerRef
;
38 // ============================================================================
40 TextContext::TextContext( ContextHandler2Helper
& rParent
, TextModel
& rModel
) :
41 ContextBase
< TextModel
>( rParent
, rModel
)
45 TextContext::~TextContext()
49 ContextHandlerRef
TextContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& )
51 // this context handler is used for <c:tx> and embedded <c:v> elements
52 if( isCurrentElement( C_TOKEN( tx
) ) ) switch( nElement
)
55 return new TextBodyContext( *this, mrModel
.mxTextBody
.create() );
57 case C_TOKEN( strRef
):
58 OSL_ENSURE( !mrModel
.mxDataSeq
, "TextContext::onCreateContext - multiple data sequences" );
59 return new StringSequenceContext( *this, mrModel
.mxDataSeq
.create() );
62 OSL_ENSURE( !mrModel
.mxDataSeq
, "TextContext::onCreateContext - multiple data sequences" );
63 return this; // collect value in onCharacters()
68 void TextContext::onCharacters( const OUString
& rChars
)
70 if( isCurrentElement( C_TOKEN( v
) ) )
72 // Static text is stored as a single string formula token for Excel document.
74 aBuf
.append('"').append(rChars
).append('"');
75 mrModel
.mxDataSeq
.create().maFormula
= aBuf
.makeStringAndClear();
77 // Also store it as a single element type for non-Excel document.
78 mrModel
.mxDataSeq
->maData
[0] <<= rChars
;
82 // ============================================================================
84 TitleContext::TitleContext( ContextHandler2Helper
& rParent
, TitleModel
& rModel
) :
85 ContextBase
< TitleModel
>( rParent
, rModel
)
89 TitleContext::~TitleContext()
93 ContextHandlerRef
TitleContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
95 // this context handler is used for <c:title> only
98 case C_TOKEN( layout
):
99 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
101 case C_TOKEN( overlay
):
102 // default is 'false', not 'true' as specified
103 mrModel
.mbOverlay
= rAttribs
.getBool( XML_val
, false );
106 case C_TOKEN( spPr
):
107 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
110 return new TextContext( *this, mrModel
.mxText
.create() );
112 case C_TOKEN( txPr
):
113 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
118 // ============================================================================
120 LegendContext::LegendContext( ContextHandler2Helper
& rParent
, LegendModel
& rModel
) :
121 ContextBase
< LegendModel
>( rParent
, rModel
)
125 LegendContext::~LegendContext()
129 ContextHandlerRef
LegendContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
131 // this context handler is used for <c:legend> only
134 case C_TOKEN( layout
):
135 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
137 case C_TOKEN( legendPos
):
138 mrModel
.mnPosition
= rAttribs
.getToken( XML_val
, XML_r
);
141 case C_TOKEN( overlay
):
142 // default is 'false', not 'true' as specified
143 mrModel
.mbOverlay
= rAttribs
.getBool( XML_val
, false );
146 case C_TOKEN( spPr
):
147 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
149 case C_TOKEN( txPr
):
150 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
155 // ============================================================================
158 } // namespace drawingml
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */