Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / chart / titlecontext.cxx
blob042b12553483d464b5b548063dd289c756599497
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/core/xmlfilterbase.hxx>
27 #include <oox/helper/attributelist.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <osl/diagnose.h>
35 namespace oox {
36 namespace drawingml {
37 namespace chart {
39 using ::oox::core::ContextHandler2Helper;
40 using ::oox::core::ContextHandlerRef;
42 TextContext::TextContext( ContextHandler2Helper& rParent, TextModel& rModel ) :
43 ContextBase< TextModel >( rParent, rModel )
47 TextContext::~TextContext()
51 ContextHandlerRef TextContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
53 // this context handler is used for <c:tx> and embedded <c:v> elements
54 if( isCurrentElement( C_TOKEN( tx ) ) ) switch( nElement )
56 case C_TOKEN( rich ):
57 return new TextBodyContext( *this, mrModel.mxTextBody.create() );
59 case C_TOKEN( strRef ):
60 OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
61 return new StringSequenceContext( *this, mrModel.mxDataSeq.create() );
63 case C_TOKEN( v ):
64 OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
65 return this; // collect value in onCharacters()
67 return nullptr;
70 void TextContext::onCharacters( const OUString& rChars )
72 if( isCurrentElement( C_TOKEN( v ) ) )
74 // Static text is stored as a single string formula token for Excel document.
75 mrModel.mxDataSeq.create().maFormula = "\"" + rChars + "\"";
77 // Also store it as a single element type for non-Excel document.
78 mrModel.mxDataSeq->maData[0] <<= rChars;
79 mrModel.mxDataSeq->mnPointCount = 1;
83 TitleContext::TitleContext( ContextHandler2Helper& rParent, TitleModel& rModel ) :
84 ContextBase< TitleModel >( rParent, rModel )
88 TitleContext::~TitleContext()
92 ContextHandlerRef TitleContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
94 bool bMSO2007Doc = getFilter().isMSO2007Document();
95 // this context handler is used for <c:title> only
96 switch( nElement )
98 case C_TOKEN( layout ):
99 return new LayoutContext( *this, mrModel.mxLayout.create() );
101 case C_TOKEN( overlay ):
102 mrModel.mbOverlay = rAttribs.getBool( XML_val, !bMSO2007Doc );
103 return nullptr;
105 case C_TOKEN( spPr ):
106 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
108 case C_TOKEN( tx ):
109 return new TextContext( *this, mrModel.mxText.create() );
111 case C_TOKEN( txPr ):
112 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
114 return nullptr;
117 LegendContext::LegendContext( ContextHandler2Helper& rParent, LegendModel& rModel ) :
118 ContextBase< LegendModel >( rParent, rModel )
122 LegendContext::~LegendContext()
126 ContextHandlerRef LegendContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
128 bool bMSO2007Doc = getFilter().isMSO2007Document();
129 // this context handler is used for <c:legend> only
130 switch( nElement )
132 case C_TOKEN( layout ):
133 return new LayoutContext( *this, mrModel.mxLayout.create() );
135 case C_TOKEN( legendPos ):
136 mrModel.mnPosition = rAttribs.getToken( XML_val, XML_r );
137 return nullptr;
139 case C_TOKEN( overlay ):
140 mrModel.mbOverlay = rAttribs.getBool( XML_val, !bMSO2007Doc );
141 return nullptr;
143 case C_TOKEN( spPr ):
144 return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
146 case C_TOKEN( txPr ):
147 return new TextBodyContext( *this, mrModel.mxTextProp.create() );
149 return nullptr;
152 } // namespace chart
153 } // namespace drawingml
154 } // namespace oox
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */