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"
27 #include "rtl/ustrbuf.hxx"
28 #include <osl/diagnose.h>
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.
72 aBuf
.append('"').append(rChars
).append('"');
73 mrModel
.mxDataSeq
.create().maFormula
= aBuf
.makeStringAndClear();
75 // Also store it as a single element type for non-Excel document.
76 mrModel
.mxDataSeq
->maData
[0] <<= rChars
;
80 TitleContext::TitleContext( ContextHandler2Helper
& rParent
, TitleModel
& rModel
) :
81 ContextBase
< TitleModel
>( rParent
, rModel
)
85 TitleContext::~TitleContext()
89 ContextHandlerRef
TitleContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
91 bool bMSO2007Doc
= getFilter().isMSO2007Document();
92 // this context handler is used for <c:title> only
95 case C_TOKEN( layout
):
96 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
98 case C_TOKEN( overlay
):
99 mrModel
.mbOverlay
= rAttribs
.getBool( XML_val
, !bMSO2007Doc
);
102 case C_TOKEN( spPr
):
103 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
106 return new TextContext( *this, mrModel
.mxText
.create() );
108 case C_TOKEN( txPr
):
109 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
114 LegendContext::LegendContext( ContextHandler2Helper
& rParent
, LegendModel
& rModel
) :
115 ContextBase
< LegendModel
>( rParent
, rModel
)
119 LegendContext::~LegendContext()
123 ContextHandlerRef
LegendContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
125 bool bMSO2007Doc
= getFilter().isMSO2007Document();
126 // this context handler is used for <c:legend> only
129 case C_TOKEN( layout
):
130 return new LayoutContext( *this, mrModel
.mxLayout
.create() );
132 case C_TOKEN( legendPos
):
133 mrModel
.mnPosition
= rAttribs
.getToken( XML_val
, XML_r
);
136 case C_TOKEN( overlay
):
137 mrModel
.mbOverlay
= rAttribs
.getBool( XML_val
, !bMSO2007Doc
);
140 case C_TOKEN( spPr
):
141 return new ShapePropertiesContext( *this, mrModel
.mxShapeProp
.create() );
143 case C_TOKEN( txPr
):
144 return new TextBodyContext( *this, mrModel
.mxTextProp
.create() );
150 } // namespace drawingml
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */