LibreOffice Module oox (master) 1
titlecontext.cxx
Go to the documentation of this file.
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
21
27#include <oox/token/namespaces.hxx>
28#include <oox/token/tokens.hxx>
29
30#include <osl/diagnose.h>
31
32
33namespace oox::drawingml::chart {
34
35using ::oox::core::ContextHandler2Helper;
37
38TextContext::TextContext( ContextHandler2Helper& rParent, TextModel& rModel ) :
39 ContextBase< TextModel >( rParent, rModel )
40{
41}
42
44{
45}
46
48{
49 // this context handler is used for <c:tx> and embedded <c:v> elements
50 if( isCurrentElement( C_TOKEN( tx ) ) ) switch( nElement )
51 {
52 case C_TOKEN( rich ):
53 return new TextBodyContext( *this, mrModel.mxTextBody.create() );
54
55 case C_TOKEN( strRef ):
56 OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
57 return new StringSequenceContext( *this, mrModel.mxDataSeq.create() );
58
59 case C_TOKEN( v ):
60 OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
61 return this; // collect value in onCharacters()
62 }
63 return nullptr;
64}
65
66void TextContext::onCharacters( const OUString& rChars )
67{
68 if( isCurrentElement( C_TOKEN( v ) ) )
69 {
70 // Static text is stored as a single string formula token for Excel document.
71 mrModel.mxDataSeq.create().maFormula = "\"" + rChars + "\"";
72
73 // Also store it as a single element type for non-Excel document.
74 mrModel.mxDataSeq->maData[0] <<= rChars;
75 mrModel.mxDataSeq->mnPointCount = 1;
76 }
77}
78
79TitleContext::TitleContext( ContextHandler2Helper& rParent, TitleModel& rModel ) :
80 ContextBase< TitleModel >( rParent, rModel )
81{
82}
83
85{
86}
87
89{
90 // this context handler is used for <c:title> only
91 switch( nElement )
92 {
93 case C_TOKEN( layout ):
94 return new LayoutContext( *this, mrModel.mxLayout.create() );
95
96 case C_TOKEN( overlay ):
97 mrModel.mbOverlay = rAttribs.getBool( XML_val, true );
98 return nullptr;
99
100 case C_TOKEN( spPr ):
101 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
102
103 case C_TOKEN( tx ):
104 return new TextContext( *this, mrModel.mxText.create() );
105
106 case C_TOKEN( txPr ):
107 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
108 }
109 return nullptr;
110}
111
112LegendEntryContext::LegendEntryContext( ContextHandler2Helper& rParent, LegendEntryModel& rModel ) :
113 ContextBase< LegendEntryModel >( rParent, rModel )
114{
115}
116
118{
119}
120
122{
123 // this context handler is used for <c:legendEntry> only
124 switch( nElement )
125 {
126 case C_TOKEN( idx ):
127 mrModel.mnLegendEntryIdx = rAttribs.getInteger( XML_val, -1 );
128 return nullptr;
129
130 case C_TOKEN( delete ):
131 mrModel.mbLabelDeleted = rAttribs.getBool( XML_val, true );
132 return nullptr;
133 }
134 return nullptr;
135}
136
137LegendContext::LegendContext( ContextHandler2Helper& rParent, LegendModel& rModel ) :
138 ContextBase< LegendModel >( rParent, rModel )
139{
140}
141
143{
144}
145
147{
148 // this context handler is used for <c:legend> only
149 switch( nElement )
150 {
151 case C_TOKEN( layout ):
152 return new LayoutContext( *this, mrModel.mxLayout.create() );
153
154 case C_TOKEN( legendPos ):
155 mrModel.mnPosition = rAttribs.getToken( XML_val, XML_r );
156 return nullptr;
157
158 case C_TOKEN( legendEntry ):
159 return new LegendEntryContext( *this, mrModel.maLegendEntries.create() );
160
161 case C_TOKEN( overlay ):
162 mrModel.mbOverlay = rAttribs.getBool( XML_val, true );
163 return nullptr;
164
165 case C_TOKEN( spPr ):
166 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
167
168 case C_TOKEN( txPr ):
169 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
170 }
171 return nullptr;
172}
173
174} // namespace oox::drawingml::chart
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
Handler for a chart layout context (c:layout element).
LegendContext(::oox::core::ContextHandler2Helper &rParent, LegendModel &rModel)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Handler for a chart legend entry context (c:legendEntry element).
LegendEntryContext(::oox::core::ContextHandler2Helper &rParent, LegendEntryModel &rModel)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Handler for a string sequence context (c:multiLvlStrRef, c:strLit, c:strRef elements).
Handler for a chart text context (c:tx element).
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
TextContext(::oox::core::ContextHandler2Helper &rParent, TextModel &rModel)
virtual void onCharacters(const OUString &rChars) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
TitleContext(::oox::core::ContextHandler2Helper &rParent, TitleModel &rModel)
float v
const sal_uInt16 idx[]
::rtl::Reference< ContextHandler > ContextHandlerRef
OUString maFormula
Map of values, indexed by point identifier.
bool mbLabelDeleted
Legend entry index.
Definition: titlemodel.hxx:61
ShapeRef mxShapeProp
Legend entries formatting.
Definition: titlemodel.hxx:74
LayoutRef mxLayout
Legend text formatting.
Definition: titlemodel.hxx:76
TextBodyRef mxTextProp
Legend shape formatting.
Definition: titlemodel.hxx:75
bool mbOverlay
Legend position.
Definition: titlemodel.hxx:78
sal_Int32 mnPosition
Layout/position of the legend.
Definition: titlemodel.hxx:77
TextBodyRef mxTextBody
The string data or formula link of this text.
Definition: titlemodel.hxx:34
LayoutRef mxLayout
Title text formatting.
Definition: titlemodel.hxx:49
TextBodyRef mxTextProp
Title shape formatting.
Definition: titlemodel.hxx:48
bool mbOverlay
Text source of the title.
Definition: titlemodel.hxx:51
TextRef mxText
Layout/position of the frame.
Definition: titlemodel.hxx:50