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 <osl/diagnose.h>
22 #include "diagramdefinitioncontext.hxx"
23 #include "diagramfragmenthandler.hxx"
24 #include "datamodelcontext.hxx"
25 #include "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
& rDataPtr
)
37 : FragmentHandler2( rFilter
, rFragmentPath
)
38 , mpDataPtr( rDataPtr
)
42 DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) throw ()
47 void SAL_CALL
DiagramDataFragmentHandler::endDocument()
48 throw (SAXException
, RuntimeException
, std::exception
)
54 DiagramDataFragmentHandler::onCreateContext( ::sal_Int32 aElement
,
55 const AttributeList
& )
59 case DGM_TOKEN( dataModel
):
60 return new DataModelContext( *this, mpDataPtr
);
68 DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( XmlFilterBase
& rFilter
,
69 const OUString
& rFragmentPath
,
70 const DiagramLayoutPtr
& rDataPtr
)
72 : FragmentHandler2( rFilter
, rFragmentPath
)
73 , mpDataPtr( rDataPtr
)
77 DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) throw ()
82 void SAL_CALL
DiagramLayoutFragmentHandler::endDocument()
83 throw (SAXException
, RuntimeException
, std::exception
)
89 DiagramLayoutFragmentHandler::onCreateContext( ::sal_Int32 aElement
,
90 const AttributeList
& rAttribs
)
94 case DGM_TOKEN( layoutDef
):
95 return new DiagramDefinitionContext( *this, AttributeList( rAttribs
), mpDataPtr
);
103 DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase
& rFilter
,
104 const OUString
& rFragmentPath
,
105 DiagramQStyleMap
& rStylesMap
) :
106 FragmentHandler2( rFilter
, rFragmentPath
),
109 mrStylesMap( rStylesMap
)
112 ::oox::core::ContextHandlerRef
DiagramQStylesFragmentHandler::createStyleMatrixContext(
114 const AttributeList
& rAttribs
,
115 ShapeStyleRef
& o_rStyle
)
117 o_rStyle
.mnThemedIdx
= (nElement
== DGM_TOKEN(fontRef
)) ?
118 rAttribs
.getToken( XML_idx
, XML_none
) : rAttribs
.getInteger( XML_idx
, 0 );
119 return new ColorContext( *this, o_rStyle
.maPhClr
);
122 ::oox::core::ContextHandlerRef
DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement
,
123 const AttributeList
& rAttribs
)
125 // state-table like way of navigating the color fragment. we
126 // currently ignore everything except styleLbl in the colorsDef
128 switch( getCurrentElement() )
130 case XML_ROOT_CONTEXT
:
131 return nElement
== DGM_TOKEN(styleDef
) ? this : NULL
;
132 case DGM_TOKEN(styleDef
):
133 return nElement
== DGM_TOKEN(styleLbl
) ? this : NULL
;
134 case DGM_TOKEN(styleLbl
):
135 return nElement
== DGM_TOKEN(style
) ? this : NULL
;
136 case DGM_TOKEN(style
):
140 case DGM_TOKEN(lnRef
) : // CT_StyleMatrixReference
141 return createStyleMatrixContext(nElement
,rAttribs
,
142 maStyleEntry
.maLineStyle
);
143 case DGM_TOKEN(fillRef
) : // CT_StyleMatrixReference
144 return createStyleMatrixContext(nElement
,rAttribs
,
145 maStyleEntry
.maFillStyle
);
146 case DGM_TOKEN(effectRef
) : // CT_StyleMatrixReference
147 return createStyleMatrixContext(nElement
,rAttribs
,
148 maStyleEntry
.maEffectStyle
);
149 case DGM_TOKEN(fontRef
) : // CT_FontRe ference
150 return createStyleMatrixContext(nElement
,rAttribs
,
151 maStyleEntry
.maTextStyle
);
160 void DiagramQStylesFragmentHandler::onStartElement( const AttributeList
& rAttribs
)
162 if( getCurrentElement() == DGM_TOKEN( styleLbl
) )
164 maStyleName
= rAttribs
.getString( XML_name
, OUString() );
165 maStyleEntry
= mrStylesMap
[maStyleName
];
169 void DiagramQStylesFragmentHandler::onEndElement( )
171 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
172 mrStylesMap
[maStyleName
] = maStyleEntry
;
175 ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase
& rFilter
,
176 const OUString
& rFragmentPath
,
177 DiagramColorMap
& rColorsMap
) :
178 FragmentHandler2(rFilter
,rFragmentPath
),
181 mrColorsMap(rColorsMap
)
184 ::oox::core::ContextHandlerRef
ColorFragmentHandler::onCreateContext( sal_Int32 nElement
,
185 const AttributeList
& /*rAttribs*/ )
187 // state-table like way of navigating the color fragment. we
188 // currently ignore everything except styleLbl in the colorsDef
190 switch( getCurrentElement() )
192 case XML_ROOT_CONTEXT
:
193 return nElement
== DGM_TOKEN(colorsDef
) ? this : NULL
;
194 case DGM_TOKEN(colorsDef
):
195 return nElement
== DGM_TOKEN(styleLbl
) ? this : NULL
;
196 case DGM_TOKEN(styleLbl
):
200 // the actual colors - defer to color fragment handlers.
202 // TODO(F1): well, actually, there might be *several* color
203 // definitions in it, after all its called list. but
204 // apparently ColorContext doesn't handle that anyway...
205 case DGM_TOKEN(fillClrLst
):
206 return new ColorContext( *this, maColorEntry
.maFillColor
);
207 case DGM_TOKEN(linClrLst
):
208 return new ColorContext( *this, maColorEntry
.maLineColor
);
209 case DGM_TOKEN(effectClrLst
):
210 return new ColorContext( *this, maColorEntry
.maEffectColor
);
211 case DGM_TOKEN(txFillClrLst
):
212 return new ColorContext( *this, maColorEntry
.maTextFillColor
);
213 case DGM_TOKEN(txLinClrLst
):
214 return new ColorContext( *this, maColorEntry
.maTextLineColor
);
215 case DGM_TOKEN(txEffectClrLst
):
216 return new ColorContext( *this, maColorEntry
.maTextEffectColor
);
225 void ColorFragmentHandler::onStartElement( const AttributeList
& rAttribs
)
227 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
229 maColorName
= rAttribs
.getString( XML_name
, OUString() );
230 maColorEntry
= mrColorsMap
[maColorName
];
234 void ColorFragmentHandler::onEndElement( )
236 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
237 mrColorsMap
[maColorName
] = maColorEntry
;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */