Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <osl/diagnose.h>
21 : :
22 : : #include "diagramdefinitioncontext.hxx"
23 : : #include "diagramfragmenthandler.hxx"
24 : : #include "datamodelcontext.hxx"
25 : : #include "oox/drawingml/colorchoicecontext.hxx"
26 : :
27 : : using namespace ::oox::core;
28 : : using namespace ::com::sun::star::xml::sax;
29 : : using namespace ::com::sun::star::uno;
30 : : using ::rtl::OUString;
31 : :
32 : : namespace oox { namespace drawingml {
33 : :
34 : 3 : DiagramDataFragmentHandler::DiagramDataFragmentHandler( XmlFilterBase& rFilter,
35 : : const OUString& rFragmentPath,
36 : : const DiagramDataPtr pDataPtr )
37 : : throw( )
38 : : : FragmentHandler( rFilter, rFragmentPath )
39 [ + - ]: 3 : , mpDataPtr( pDataPtr )
40 : : {
41 : 3 : }
42 : :
43 [ + - ]: 3 : DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) throw ()
44 : : {
45 : :
46 [ - + ]: 6 : }
47 : :
48 : 3 : void SAL_CALL DiagramDataFragmentHandler::endDocument()
49 : : throw (SAXException, RuntimeException)
50 : : {
51 : :
52 : 3 : }
53 : :
54 : :
55 : : Reference< XFastContextHandler > SAL_CALL
56 : 3 : DiagramDataFragmentHandler::createFastChildContext( ::sal_Int32 aElement,
57 : : const Reference< XFastAttributeList >& )
58 : : throw ( SAXException, RuntimeException)
59 : : {
60 : 3 : Reference< XFastContextHandler > xRet;
61 : :
62 [ + - ]: 3 : switch( aElement )
63 : : {
64 : : case DGM_TOKEN( dataModel ):
65 [ + - ][ + - ]: 3 : xRet.set( new DataModelContext( *this, mpDataPtr ) );
[ + - ]
66 : 3 : break;
67 : : default:
68 : 0 : break;
69 : : }
70 : :
71 [ - + ]: 3 : if( !xRet.is() )
72 [ # # ][ # # ]: 0 : xRet = getFastContextHandler();
73 : :
74 : 3 : return xRet;
75 : : }
76 : :
77 : : ///////////////////
78 : :
79 : 0 : DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( XmlFilterBase& rFilter,
80 : : const OUString& rFragmentPath,
81 : : const DiagramLayoutPtr pDataPtr )
82 : : throw( )
83 : : : FragmentHandler( rFilter, rFragmentPath )
84 [ # # ]: 0 : , mpDataPtr( pDataPtr )
85 : : {
86 : 0 : }
87 : :
88 [ # # ]: 0 : DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) throw ()
89 : : {
90 : :
91 [ # # ]: 0 : }
92 : :
93 : 0 : void SAL_CALL DiagramLayoutFragmentHandler::endDocument()
94 : : throw (SAXException, RuntimeException)
95 : : {
96 : :
97 : 0 : }
98 : :
99 : :
100 : : Reference< XFastContextHandler > SAL_CALL
101 : 0 : DiagramLayoutFragmentHandler::createFastChildContext( ::sal_Int32 aElement,
102 : : const Reference< XFastAttributeList >& xAttribs )
103 : : throw ( SAXException, RuntimeException)
104 : : {
105 : 0 : Reference< XFastContextHandler > xRet;
106 : :
107 [ # # ]: 0 : switch( aElement )
108 : : {
109 : : case DGM_TOKEN( layoutDef ):
110 [ # # ][ # # ]: 0 : xRet.set( new DiagramDefinitionContext( *this, xAttribs, mpDataPtr ) );
[ # # ]
111 : 0 : break;
112 : : default:
113 : 0 : break;
114 : : }
115 : :
116 [ # # ]: 0 : if( !xRet.is() )
117 [ # # ][ # # ]: 0 : xRet = getFastContextHandler();
118 : :
119 : 0 : return xRet;
120 : : }
121 : :
122 : : ///////////////////////
123 : :
124 : 0 : DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase& rFilter,
125 : : const OUString& rFragmentPath,
126 : : DiagramQStyleMap& rStylesMap ) :
127 : : FragmentHandler2( rFilter, rFragmentPath ),
128 : : maStyleName(),
129 : : maStyleEntry(),
130 [ # # ]: 0 : mrStylesMap( rStylesMap )
131 : 0 : {}
132 : :
133 : 0 : ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::createStyleMatrixContext(
134 : : sal_Int32 nElement,
135 : : const AttributeList& rAttribs,
136 : : ShapeStyleRef& o_rStyle )
137 : : {
138 : : o_rStyle.mnThemedIdx = (nElement == DGM_TOKEN(fontRef)) ?
139 [ # # ]: 0 : rAttribs.getToken( XML_idx, XML_none ) : rAttribs.getInteger( XML_idx, 0 );
140 [ # # ]: 0 : return new ColorContext( *this, o_rStyle.maPhClr );
141 : : }
142 : :
143 : 0 : ::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement,
144 : : const AttributeList& rAttribs )
145 : : {
146 : : // state-table like way of navigating the color fragment. we
147 : : // currently ignore everything except styleLbl in the colorsDef
148 : : // element
149 [ # # # # : 0 : switch( getCurrentElement() )
# ]
150 : : {
151 : : case XML_ROOT_CONTEXT:
152 [ # # ]: 0 : return nElement == DGM_TOKEN(styleDef) ? this : NULL;
153 : : case DGM_TOKEN(styleDef):
154 [ # # ]: 0 : return nElement == DGM_TOKEN(styleLbl) ? this : NULL;
155 : : case DGM_TOKEN(styleLbl):
156 [ # # ]: 0 : return nElement == DGM_TOKEN(style) ? this : NULL;
157 : : case DGM_TOKEN(style):
158 : : {
159 [ # # # # : 0 : switch( nElement )
# ]
160 : : {
161 : : case DGM_TOKEN(lnRef) : // CT_StyleMatrixReference
162 : : return createStyleMatrixContext(nElement,rAttribs,
163 : 0 : maStyleEntry.maLineStyle);
164 : : case DGM_TOKEN(fillRef) : // CT_StyleMatrixReference
165 : : return createStyleMatrixContext(nElement,rAttribs,
166 : 0 : maStyleEntry.maFillStyle);
167 : : case DGM_TOKEN(effectRef) : // CT_StyleMatrixReference
168 : : return createStyleMatrixContext(nElement,rAttribs,
169 : 0 : maStyleEntry.maEffectStyle);
170 : : case DGM_TOKEN(fontRef) : // CT_FontRe ference
171 : : return createStyleMatrixContext(nElement,rAttribs,
172 : 0 : maStyleEntry.maTextStyle);
173 : : }
174 : 0 : return 0;
175 : : }
176 : : }
177 : :
178 : 0 : return 0;
179 : : }
180 : :
181 : :
182 : 0 : void DiagramQStylesFragmentHandler::onStartElement( const AttributeList& rAttribs )
183 : : {
184 [ # # ]: 0 : if( getCurrentElement() == DGM_TOKEN( styleDef ) )
185 : : {
186 [ # # ]: 0 : maStyleName = rAttribs.getString( XML_name, OUString() );
187 : 0 : maStyleEntry = mrStylesMap[maStyleName];
188 : : }
189 : 0 : }
190 : :
191 : : /////////////////////
192 : :
193 : 0 : void DiagramQStylesFragmentHandler::onEndElement( )
194 : : {
195 [ # # ]: 0 : if( getCurrentElement() == DGM_TOKEN(styleLbl) )
196 : 0 : mrStylesMap[maStyleName] = maStyleEntry;
197 : 0 : }
198 : :
199 : 0 : ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase& rFilter,
200 : : const ::rtl::OUString& rFragmentPath,
201 : : DiagramColorMap& rColorsMap ) :
202 : : FragmentHandler2(rFilter,rFragmentPath),
203 : : maColorName(),
204 : : maColorEntry(),
205 [ # # ]: 0 : mrColorsMap(rColorsMap)
206 : 0 : {}
207 : :
208 : 0 : ::oox::core::ContextHandlerRef ColorFragmentHandler::onCreateContext( sal_Int32 nElement,
209 : : const AttributeList& /*rAttribs*/ )
210 : : {
211 : : // state-table like way of navigating the color fragment. we
212 : : // currently ignore everything except styleLbl in the colorsDef
213 : : // element
214 [ # # # # : 0 : switch( getCurrentElement() )
# # # # #
# ]
215 : : {
216 : : case XML_ROOT_CONTEXT:
217 [ # # ]: 0 : return nElement == DGM_TOKEN(colorsDef) ? this : NULL;
218 : : case DGM_TOKEN(colorsDef):
219 [ # # ]: 0 : return nElement == DGM_TOKEN(styleLbl) ? this : NULL;
220 : : case DGM_TOKEN(styleLbl):
221 : : return ((nElement == DGM_TOKEN(fillClrLst)) ||
222 : : (nElement == DGM_TOKEN(linClrLst)) ||
223 : : (nElement == DGM_TOKEN(effectClrLst)) ||
224 : : (nElement == DGM_TOKEN(txLinClrLst)) ||
225 : : (nElement == DGM_TOKEN(txFillClrLst)) ||
226 [ # # ][ # # ]: 0 : (nElement == DGM_TOKEN(txEffectClrLst))) ? this : NULL;
[ # # ][ # # ]
[ # # ][ # # ]
227 : :
228 : : // the actual colors - defer to color fragment handlers.
229 : :
230 : : // TODO(F1): well, actually, there might be *several* color
231 : : // definitions in it, after all it's called list. but
232 : : // apparently colorChoiceContext doesn't handle that anyway...
233 : : case DGM_TOKEN(fillClrLst):
234 [ # # ]: 0 : return new ColorContext( *this, maColorEntry.maFillColor );
235 : : case DGM_TOKEN(linClrLst):
236 [ # # ]: 0 : return new ColorContext( *this, maColorEntry.maLineColor );
237 : : case DGM_TOKEN(effectClrLst):
238 [ # # ]: 0 : return new ColorContext( *this, maColorEntry.maEffectColor );
239 : : case DGM_TOKEN(txFillClrLst):
240 [ # # ]: 0 : return new ColorContext( *this, maColorEntry.maTextFillColor );
241 : : case DGM_TOKEN(txLinClrLst):
242 [ # # ]: 0 : return new ColorContext( *this, maColorEntry.maTextLineColor );
243 : : case DGM_TOKEN(txEffectClrLst):
244 [ # # ]: 0 : return new ColorContext( *this, maColorEntry.maTextEffectColor );
245 : : }
246 : :
247 : 0 : return 0;
248 : : }
249 : :
250 : :
251 : 0 : void ColorFragmentHandler::onStartElement( const AttributeList& rAttribs )
252 : : {
253 [ # # ]: 0 : if( getCurrentElement() == DGM_TOKEN(styleLbl) )
254 : : {
255 [ # # ]: 0 : maColorName = rAttribs.getString( XML_name, OUString() );
256 : 0 : maColorEntry = mrColorsMap[maColorName];
257 : : }
258 : 0 : }
259 : :
260 : 0 : void ColorFragmentHandler::onEndElement( )
261 : : {
262 [ # # ]: 0 : if( getCurrentElement() == DGM_TOKEN(styleLbl) )
263 : 0 : mrColorsMap[maColorName] = maColorEntry;
264 : 0 : }
265 : :
266 : :
267 [ + - ][ + - ]: 285 : } }
268 : :
269 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|