fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / diagram / diagramfragmenthandler.cxx
blob658b46eff1973b7c2e292c17569ae1af0434f335
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 <osl/diagnose.h>
22 #include "diagramdefinitioncontext.hxx"
23 #include "diagramfragmenthandler.hxx"
24 #include "datamodelcontext.hxx"
25 #include "oox/drawingml/colorchoicecontext.hxx"
27 using namespace ::oox::core;
28 using namespace ::com::sun::star::xml::sax;
29 using namespace ::com::sun::star::uno;
31 namespace oox { namespace drawingml {
33 DiagramDataFragmentHandler::DiagramDataFragmentHandler( XmlFilterBase& rFilter,
34 const OUString& rFragmentPath,
35 const DiagramDataPtr pDataPtr )
36 throw( )
37 : FragmentHandler( rFilter, rFragmentPath )
38 , mpDataPtr( pDataPtr )
42 DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) throw ()
47 void SAL_CALL DiagramDataFragmentHandler::endDocument()
48 throw (SAXException, RuntimeException)
54 Reference< XFastContextHandler > SAL_CALL
55 DiagramDataFragmentHandler::createFastChildContext( ::sal_Int32 aElement,
56 const Reference< XFastAttributeList >& )
57 throw ( SAXException, RuntimeException)
59 Reference< XFastContextHandler > xRet;
61 switch( aElement )
63 case DGM_TOKEN( dataModel ):
64 xRet.set( new DataModelContext( *this, mpDataPtr ) );
65 break;
66 default:
67 break;
70 if( !xRet.is() )
71 xRet = getFastContextHandler();
73 return xRet;
76 ///////////////////
78 DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( XmlFilterBase& rFilter,
79 const OUString& rFragmentPath,
80 const DiagramLayoutPtr pDataPtr )
81 throw( )
82 : FragmentHandler( rFilter, rFragmentPath )
83 , mpDataPtr( pDataPtr )
87 DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) throw ()
92 void SAL_CALL DiagramLayoutFragmentHandler::endDocument()
93 throw (SAXException, RuntimeException)
99 Reference< XFastContextHandler > SAL_CALL
100 DiagramLayoutFragmentHandler::createFastChildContext( ::sal_Int32 aElement,
101 const Reference< XFastAttributeList >& xAttribs )
102 throw ( SAXException, RuntimeException)
104 Reference< XFastContextHandler > xRet;
106 switch( aElement )
108 case DGM_TOKEN( layoutDef ):
109 xRet.set( new DiagramDefinitionContext( *this, xAttribs, mpDataPtr ) );
110 break;
111 default:
112 break;
115 if( !xRet.is() )
116 xRet = getFastContextHandler();
118 return xRet;
121 ///////////////////////
123 DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase& rFilter,
124 const OUString& rFragmentPath,
125 DiagramQStyleMap& rStylesMap ) :
126 FragmentHandler2( rFilter, rFragmentPath ),
127 maStyleName(),
128 maStyleEntry(),
129 mrStylesMap( rStylesMap )
132 ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::createStyleMatrixContext(
133 sal_Int32 nElement,
134 const AttributeList& rAttribs,
135 ShapeStyleRef& o_rStyle )
137 o_rStyle.mnThemedIdx = (nElement == DGM_TOKEN(fontRef)) ?
138 rAttribs.getToken( XML_idx, XML_none ) : rAttribs.getInteger( XML_idx, 0 );
139 return new ColorContext( *this, o_rStyle.maPhClr );
142 ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement,
143 const AttributeList& rAttribs )
145 // state-table like way of navigating the color fragment. we
146 // currently ignore everything except styleLbl in the colorsDef
147 // element
148 switch( getCurrentElement() )
150 case XML_ROOT_CONTEXT:
151 return nElement == DGM_TOKEN(styleDef) ? this : NULL;
152 case DGM_TOKEN(styleDef):
153 return nElement == DGM_TOKEN(styleLbl) ? this : NULL;
154 case DGM_TOKEN(styleLbl):
155 return nElement == DGM_TOKEN(style) ? this : NULL;
156 case DGM_TOKEN(style):
158 switch( nElement )
160 case DGM_TOKEN(lnRef) : // CT_StyleMatrixReference
161 return createStyleMatrixContext(nElement,rAttribs,
162 maStyleEntry.maLineStyle);
163 case DGM_TOKEN(fillRef) : // CT_StyleMatrixReference
164 return createStyleMatrixContext(nElement,rAttribs,
165 maStyleEntry.maFillStyle);
166 case DGM_TOKEN(effectRef) : // CT_StyleMatrixReference
167 return createStyleMatrixContext(nElement,rAttribs,
168 maStyleEntry.maEffectStyle);
169 case DGM_TOKEN(fontRef) : // CT_FontRe ference
170 return createStyleMatrixContext(nElement,rAttribs,
171 maStyleEntry.maTextStyle);
173 return 0;
177 return 0;
181 void DiagramQStylesFragmentHandler::onStartElement( const AttributeList& rAttribs )
183 if( getCurrentElement() == DGM_TOKEN( styleDef ) )
185 maStyleName = rAttribs.getString( XML_name, OUString() );
186 maStyleEntry = mrStylesMap[maStyleName];
190 /////////////////////
192 void DiagramQStylesFragmentHandler::onEndElement( )
194 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
195 mrStylesMap[maStyleName] = maStyleEntry;
198 ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase& rFilter,
199 const OUString& rFragmentPath,
200 DiagramColorMap& rColorsMap ) :
201 FragmentHandler2(rFilter,rFragmentPath),
202 maColorName(),
203 maColorEntry(),
204 mrColorsMap(rColorsMap)
207 ::oox::core::ContextHandlerRef ColorFragmentHandler::onCreateContext( sal_Int32 nElement,
208 const AttributeList& /*rAttribs*/ )
210 // state-table like way of navigating the color fragment. we
211 // currently ignore everything except styleLbl in the colorsDef
212 // element
213 switch( getCurrentElement() )
215 case XML_ROOT_CONTEXT:
216 return nElement == DGM_TOKEN(colorsDef) ? this : NULL;
217 case DGM_TOKEN(colorsDef):
218 return nElement == DGM_TOKEN(styleLbl) ? this : NULL;
219 case DGM_TOKEN(styleLbl):
220 return ((nElement == DGM_TOKEN(fillClrLst)) ||
221 (nElement == DGM_TOKEN(linClrLst)) ||
222 (nElement == DGM_TOKEN(effectClrLst)) ||
223 (nElement == DGM_TOKEN(txLinClrLst)) ||
224 (nElement == DGM_TOKEN(txFillClrLst)) ||
225 (nElement == DGM_TOKEN(txEffectClrLst))) ? this : NULL;
227 // the actual colors - defer to color fragment handlers.
229 // TODO(F1): well, actually, there might be *several* color
230 // definitions in it, after all it's called list. but
231 // apparently colorChoiceContext doesn't handle that anyway...
232 case DGM_TOKEN(fillClrLst):
233 return new ColorContext( *this, maColorEntry.maFillColor );
234 case DGM_TOKEN(linClrLst):
235 return new ColorContext( *this, maColorEntry.maLineColor );
236 case DGM_TOKEN(effectClrLst):
237 return new ColorContext( *this, maColorEntry.maEffectColor );
238 case DGM_TOKEN(txFillClrLst):
239 return new ColorContext( *this, maColorEntry.maTextFillColor );
240 case DGM_TOKEN(txLinClrLst):
241 return new ColorContext( *this, maColorEntry.maTextLineColor );
242 case DGM_TOKEN(txEffectClrLst):
243 return new ColorContext( *this, maColorEntry.maTextEffectColor );
246 return 0;
250 void ColorFragmentHandler::onStartElement( const AttributeList& rAttribs )
252 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
254 maColorName = rAttribs.getString( XML_name, OUString() );
255 maColorEntry = mrColorsMap[maColorName];
259 void ColorFragmentHandler::onEndElement( )
261 if( getCurrentElement() == DGM_TOKEN(styleLbl) )
262 mrColorsMap[maColorName] = maColorEntry;
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */