Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / oox / source / drawingml / diagram / diagramfragmenthandler.cxx
blobb65fca3f98fcbae22914dd2c3f0175a2b7934bc4
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>
27 #include <utility>
29 using namespace ::oox::core;
30 using namespace ::com::sun::star::xml::sax;
31 using namespace ::com::sun::star::uno;
33 namespace oox::drawingml {
35 DiagramDataFragmentHandler::DiagramDataFragmentHandler( XmlFilterBase& rFilter,
36 const OUString& rFragmentPath,
37 OoxDiagramDataPtr xDataPtr )
38 : FragmentHandler2( rFilter, rFragmentPath )
39 , mpDataPtr(std::move( xDataPtr ))
43 DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) noexcept
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 DiagramLayoutPtr xDataPtr )
71 : FragmentHandler2( rFilter, rFragmentPath )
72 , mpDataPtr(std::move( xDataPtr ))
76 DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) noexcept
81 void SAL_CALL DiagramLayoutFragmentHandler::endDocument()
86 ContextHandlerRef
87 DiagramLayoutFragmentHandler::onCreateContext( ::sal_Int32 aElement,
88 const AttributeList& rAttribs )
90 switch( aElement )
92 case DGM_TOKEN( layoutDef ):
93 return new DiagramDefinitionContext( *this, rAttribs, mpDataPtr );
94 default:
95 break;
98 return this;
101 DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase& rFilter,
102 const OUString& rFragmentPath,
103 DiagramQStyleMap& rStylesMap ) :
104 FragmentHandler2( rFilter, rFragmentPath ),
105 maStyleEntry(),
106 mrStylesMap( rStylesMap )
109 ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::createStyleMatrixContext(
110 sal_Int32 nElement,
111 const AttributeList& rAttribs,
112 ShapeStyleRef& o_rStyle )
114 o_rStyle.mnThemedIdx = (nElement == A_TOKEN(fontRef)) ?
115 rAttribs.getToken( XML_idx, XML_none ) : rAttribs.getInteger( XML_idx, 0 );
116 return new ColorContext( *this, o_rStyle.maPhClr );
119 ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement,
120 const AttributeList& rAttribs )
122 // state-table like way of navigating the color fragment. we
123 // currently ignore everything except styleLbl in the styleDef
124 // element
125 switch( getCurrentElement() )
127 case XML_ROOT_CONTEXT:
128 return nElement == DGM_TOKEN(styleDef) ? this : nullptr;
129 case DGM_TOKEN(styleDef):
130 return nElement == DGM_TOKEN(styleLbl) ? this : nullptr;
131 case DGM_TOKEN(styleLbl):
132 return nElement == DGM_TOKEN(style) ? this : nullptr;
133 case DGM_TOKEN(style):
135 switch( nElement )
137 case A_TOKEN(lnRef): // CT_StyleMatrixReference
138 return createStyleMatrixContext(nElement,rAttribs,
139 maStyleEntry.maLineStyle);
140 case A_TOKEN(fillRef): // CT_StyleMatrixReference
141 return createStyleMatrixContext(nElement,rAttribs,
142 maStyleEntry.maFillStyle);
143 case A_TOKEN(effectRef): // CT_StyleMatrixReference
144 return createStyleMatrixContext(nElement,rAttribs,
145 maStyleEntry.maEffectStyle);
146 case A_TOKEN(fontRef): // CT_FontReference
147 return createStyleMatrixContext(nElement,rAttribs,
148 maStyleEntry.maTextStyle);
150 return nullptr;
154 return nullptr;
157 void DiagramQStylesFragmentHandler::onStartElement( const AttributeList& rAttribs )
159 if( getCurrentElement() == DGM_TOKEN( styleLbl ) )
161 maStyleName = rAttribs.getStringDefaulted( XML_name);
162 maStyleEntry = mrStylesMap[maStyleName];
166 void DiagramQStylesFragmentHandler::onEndElement( )
168 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
169 mrStylesMap[maStyleName] = maStyleEntry;
172 ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase& rFilter,
173 const OUString& rFragmentPath,
174 DiagramColorMap& rColorsMap ) :
175 FragmentHandler2(rFilter,rFragmentPath),
176 maColorEntry(),
177 mrColorsMap(rColorsMap)
180 ::oox::core::ContextHandlerRef ColorFragmentHandler::onCreateContext( sal_Int32 nElement,
181 const AttributeList& /*rAttribs*/ )
183 // state-table like way of navigating the color fragment. we
184 // currently ignore everything except styleLbl in the colorsDef
185 // element
186 switch( getCurrentElement() )
188 case XML_ROOT_CONTEXT:
189 return nElement == DGM_TOKEN(colorsDef) ? this : nullptr;
190 case DGM_TOKEN(colorsDef):
191 return nElement == DGM_TOKEN(styleLbl) ? this : nullptr;
192 case DGM_TOKEN(styleLbl):
194 switch( nElement )
196 // the actual colors - defer to color fragment handlers.
198 case DGM_TOKEN(fillClrLst):
199 return new ColorsContext( *this, maColorEntry.maFillColors );
200 case DGM_TOKEN(linClrLst):
201 return new ColorsContext( *this, maColorEntry.maLineColors );
202 case DGM_TOKEN(effectClrLst):
203 return new ColorsContext( *this, maColorEntry.maEffectColors );
204 case DGM_TOKEN(txFillClrLst):
205 return new ColorsContext( *this, maColorEntry.maTextFillColors );
206 case DGM_TOKEN(txLinClrLst):
207 return new ColorsContext( *this, maColorEntry.maTextLineColors );
208 case DGM_TOKEN(txEffectClrLst):
209 return new ColorsContext( *this, maColorEntry.maTextEffectColors );
211 break;
215 return nullptr;
218 void ColorFragmentHandler::onStartElement( const AttributeList& rAttribs )
220 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
222 maColorName = rAttribs.getStringDefaulted( XML_name);
223 maColorEntry = mrColorsMap[maColorName];
227 void ColorFragmentHandler::onEndElement( )
229 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
230 mrColorsMap[maColorName] = maColorEntry;
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */