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 
33 namespace oox::drawingml::chart {
34 
35 using ::oox::core::ContextHandler2Helper;
37 
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 
66 void 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 
80  ContextBase< TitleModel >( rParent, rModel )
81 {
82 }
83 
85 {
86 }
87 
88 ContextHandlerRef TitleContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
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 
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 
138  ContextBase< LegendModel >( rParent, rModel )
139 {
140 }
141 
143 {
144 }
145 
146 ContextHandlerRef LegendContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
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: */
Handler for a chart legend entry context (c:legendEntry element).
LayoutRef mxLayout
Legend text formatting.
Definition: titlemodel.hxx:77
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
TextRef mxText
Layout/position of the frame.
Definition: titlemodel.hxx:50
bool mbOverlay
Legend position.
Definition: titlemodel.hxx:79
TitleContext(::oox::core::ContextHandler2Helper &rParent, TitleModel &rModel)
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
bool isCurrentElement(sal_Int32 nElement) const
Returns true, if nElement contains the identifier of the currently processed element.
TextBodyRef mxTextProp
Legend shape formatting.
Definition: titlemodel.hxx:76
virtual void onCharacters(const OUString &rChars) override
Will be called before a new child element starts, or if the current element is about to be left...
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
TextBodyRef mxTextProp
Title shape formatting.
Definition: titlemodel.hxx:48
ShapeRef mxShapeProp
Legend entries formatting.
Definition: titlemodel.hxx:75
OUString maFormula
Map of values, indexed by point identifier.
LegendContext(::oox::core::ContextHandler2Helper &rParent, LegendModel &rModel)
sal_Int32 mnPosition
Layout/position of the legend.
Definition: titlemodel.hxx:78
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
LegendEntryContext(::oox::core::ContextHandler2Helper &rParent, LegendEntryModel &rModel)
Provides access to attribute values of an element.
const sal_uInt16 idx[]
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Will be called to create a context handler for the passed element.
float v
Handler for a chart layout context (c:layout element).
LayoutRef mxLayout
Title text formatting.
Definition: titlemodel.hxx:49
::rtl::Reference< ContextHandler > ContextHandlerRef
Handler for a chart text context (c:tx element).
Handler for a string sequence context (c:multiLvlStrRef, c:strLit, c:strRef elements).
TextBodyRef mxTextBody
The string data or formula link of this text.
Definition: titlemodel.hxx:34
Helper class that provides a context stack.
bool mbOverlay
Text source of the title.
Definition: titlemodel.hxx:51
bool mbLabelDeleted
Legend entry index.
Definition: titlemodel.hxx:61
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
TextContext(::oox::core::ContextHandler2Helper &rParent, TextModel &rModel)