Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / diagram / diagramfragmenthandler.cxx
bloba85fe611dd181f9b25ed86019fad2f0dcc000eed
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 .
21 #include "diagramdefinitioncontext.hxx"
22 #include "diagramfragmenthandler.hxx"
23 #include "datamodelcontext.hxx"
24 #include "drawingml/colorchoicecontext.hxx"
25 #include <oox/helper/attributelist.hxx>
26 #include <oox/token/namespaces.hxx>
28 using namespace ::oox::core;
29 using namespace ::com::sun::star::xml::sax;
30 using namespace ::com::sun::star::uno;
32 namespace oox { namespace drawingml {
34 DiagramDataFragmentHandler::DiagramDataFragmentHandler( XmlFilterBase& rFilter,
35 const OUString& rFragmentPath,
36 const DiagramDataPtr& rDataPtr )
37 throw( )
38 : FragmentHandler2( rFilter, rFragmentPath )
39 , mpDataPtr( rDataPtr )
43 DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) throw ()
48 void SAL_CALL DiagramDataFragmentHandler::endDocument()
53 ContextHandlerRef
54 DiagramDataFragmentHandler::onCreateContext( ::sal_Int32 aElement,
55 const AttributeList& )
57 switch( aElement )
59 case DGM_TOKEN( dataModel ):
60 return new DataModelContext( *this, mpDataPtr );
61 default:
62 break;
65 return this;
68 DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( XmlFilterBase& rFilter,
69 const OUString& rFragmentPath,
70 const DiagramLayoutPtr& rDataPtr )
71 throw( )
72 : FragmentHandler2( rFilter, rFragmentPath )
73 , mpDataPtr( rDataPtr )
77 DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) throw ()
82 void SAL_CALL DiagramLayoutFragmentHandler::endDocument()
87 ContextHandlerRef
88 DiagramLayoutFragmentHandler::onCreateContext( ::sal_Int32 aElement,
89 const AttributeList& rAttribs )
91 switch( aElement )
93 case DGM_TOKEN( layoutDef ):
94 return new DiagramDefinitionContext( *this, AttributeList( rAttribs ), mpDataPtr );
95 default:
96 break;
99 return this;
102 DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase& rFilter,
103 const OUString& rFragmentPath,
104 DiagramQStyleMap& rStylesMap ) :
105 FragmentHandler2( rFilter, rFragmentPath ),
106 maStyleName(),
107 maStyleEntry(),
108 mrStylesMap( rStylesMap )
111 ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::createStyleMatrixContext(
112 sal_Int32 nElement,
113 const AttributeList& rAttribs,
114 ShapeStyleRef& o_rStyle )
116 o_rStyle.mnThemedIdx = (nElement == DGM_TOKEN(fontRef)) ?
117 rAttribs.getToken( XML_idx, XML_none ) : rAttribs.getInteger( XML_idx, 0 );
118 return new ColorContext( *this, o_rStyle.maPhClr );
121 ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement,
122 const AttributeList& rAttribs )
124 // state-table like way of navigating the color fragment. we
125 // currently ignore everything except styleLbl in the colorsDef
126 // element
127 switch( getCurrentElement() )
129 case XML_ROOT_CONTEXT:
130 return nElement == DGM_TOKEN(styleDef) ? this : nullptr;
131 case DGM_TOKEN(styleDef):
132 return nElement == DGM_TOKEN(styleLbl) ? this : nullptr;
133 case DGM_TOKEN(styleLbl):
134 return nElement == DGM_TOKEN(style) ? this : nullptr;
135 case DGM_TOKEN(style):
137 switch( nElement )
139 case DGM_TOKEN(lnRef) : // CT_StyleMatrixReference
140 return createStyleMatrixContext(nElement,rAttribs,
141 maStyleEntry.maLineStyle);
142 case DGM_TOKEN(fillRef) : // CT_StyleMatrixReference
143 return createStyleMatrixContext(nElement,rAttribs,
144 maStyleEntry.maFillStyle);
145 case DGM_TOKEN(effectRef) : // CT_StyleMatrixReference
146 return createStyleMatrixContext(nElement,rAttribs,
147 maStyleEntry.maEffectStyle);
148 case DGM_TOKEN(fontRef) : // CT_FontRe ference
149 return createStyleMatrixContext(nElement,rAttribs,
150 maStyleEntry.maTextStyle);
152 return nullptr;
156 return nullptr;
159 void DiagramQStylesFragmentHandler::onStartElement( const AttributeList& rAttribs )
161 if( getCurrentElement() == DGM_TOKEN( styleLbl ) )
163 maStyleName = rAttribs.getString( XML_name, OUString() );
164 maStyleEntry = mrStylesMap[maStyleName];
168 void DiagramQStylesFragmentHandler::onEndElement( )
170 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
171 mrStylesMap[maStyleName] = maStyleEntry;
174 ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase& rFilter,
175 const OUString& rFragmentPath,
176 DiagramColorMap& rColorsMap ) :
177 FragmentHandler2(rFilter,rFragmentPath),
178 maColorName(),
179 maColorEntry(),
180 mrColorsMap(rColorsMap)
183 ::oox::core::ContextHandlerRef ColorFragmentHandler::onCreateContext( sal_Int32 nElement,
184 const AttributeList& /*rAttribs*/ )
186 // state-table like way of navigating the color fragment. we
187 // currently ignore everything except styleLbl in the colorsDef
188 // element
189 switch( getCurrentElement() )
191 case XML_ROOT_CONTEXT:
192 return nElement == DGM_TOKEN(colorsDef) ? this : nullptr;
193 case DGM_TOKEN(colorsDef):
194 return nElement == DGM_TOKEN(styleLbl) ? this : nullptr;
195 case DGM_TOKEN(styleLbl):
197 switch( nElement )
199 // the actual colors - defer to color fragment handlers.
201 // TODO(F1): well, actually, there might be *several* color
202 // definitions in it, after all its called list. but
203 // apparently ColorContext doesn't handle that anyway...
204 case DGM_TOKEN(fillClrLst):
205 return new ColorContext( *this, maColorEntry.maFillColor );
206 case DGM_TOKEN(linClrLst):
207 return new ColorContext( *this, maColorEntry.maLineColor );
208 case DGM_TOKEN(effectClrLst):
209 return new ColorContext( *this, maColorEntry.maEffectColor );
210 case DGM_TOKEN(txFillClrLst):
211 return new ColorContext( *this, maColorEntry.maTextFillColor );
212 case DGM_TOKEN(txLinClrLst):
213 return new ColorContext( *this, maColorEntry.maTextLineColor );
214 case DGM_TOKEN(txEffectClrLst):
215 return new ColorContext( *this, maColorEntry.maTextEffectColor );
217 break;
221 return nullptr;
224 void ColorFragmentHandler::onStartElement( const AttributeList& rAttribs )
226 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
228 maColorName = rAttribs.getString( XML_name, OUString() );
229 maColorEntry = mrColorsMap[maColorName];
233 void ColorFragmentHandler::onEndElement( )
235 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
236 mrColorsMap[maColorName] = maColorEntry;
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */