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 .
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 : FragmentHandler2( rFilter
, rFragmentPath
)
38 , mpDataPtr( rDataPtr
)
42 DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) throw ()
47 void SAL_CALL
DiagramDataFragmentHandler::endDocument()
53 DiagramDataFragmentHandler::onCreateContext( ::sal_Int32 aElement
,
54 const AttributeList
& )
58 case DGM_TOKEN( dataModel
):
59 return new DataModelContext( *this, mpDataPtr
);
67 DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( XmlFilterBase
& rFilter
,
68 const OUString
& rFragmentPath
,
69 const DiagramLayoutPtr
& rDataPtr
)
70 : FragmentHandler2( rFilter
, rFragmentPath
)
71 , mpDataPtr( rDataPtr
)
75 DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) throw ()
80 void SAL_CALL
DiagramLayoutFragmentHandler::endDocument()
86 DiagramLayoutFragmentHandler::onCreateContext( ::sal_Int32 aElement
,
87 const AttributeList
& rAttribs
)
91 case DGM_TOKEN( layoutDef
):
92 return new DiagramDefinitionContext( *this, rAttribs
, mpDataPtr
);
100 DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase
& rFilter
,
101 const OUString
& rFragmentPath
,
102 DiagramQStyleMap
& rStylesMap
) :
103 FragmentHandler2( rFilter
, rFragmentPath
),
106 mrStylesMap( rStylesMap
)
109 ::oox::core::ContextHandlerRef
DiagramQStylesFragmentHandler::createStyleMatrixContext(
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
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
):
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
);
157 void DiagramQStylesFragmentHandler::onStartElement( const AttributeList
& rAttribs
)
159 if( getCurrentElement() == DGM_TOKEN( styleLbl
) )
161 maStyleName
= rAttribs
.getString( XML_name
, OUString() );
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
),
178 mrColorsMap(rColorsMap
)
181 ::oox::core::ContextHandlerRef
ColorFragmentHandler::onCreateContext( sal_Int32 nElement
,
182 const AttributeList
& /*rAttribs*/ )
184 // state-table like way of navigating the color fragment. we
185 // currently ignore everything except styleLbl in the colorsDef
187 switch( getCurrentElement() )
189 case XML_ROOT_CONTEXT
:
190 return nElement
== DGM_TOKEN(colorsDef
) ? this : nullptr;
191 case DGM_TOKEN(colorsDef
):
192 return nElement
== DGM_TOKEN(styleLbl
) ? this : nullptr;
193 case DGM_TOKEN(styleLbl
):
197 // the actual colors - defer to color fragment handlers.
199 // TODO(F1): well, actually, there might be *several* color
200 // definitions in it, after all it's called list. But
201 // apparently ColorContext doesn't handle that anyway...
202 case DGM_TOKEN(fillClrLst
):
203 return new ColorContext( *this, maColorEntry
.maFillColor
);
204 case DGM_TOKEN(linClrLst
):
205 return new ColorContext( *this, maColorEntry
.maLineColor
);
206 case DGM_TOKEN(effectClrLst
):
207 return new ColorContext( *this, maColorEntry
.maEffectColor
);
208 case DGM_TOKEN(txFillClrLst
):
209 return new ColorContext( *this, maColorEntry
.maTextFillColor
);
210 case DGM_TOKEN(txLinClrLst
):
211 return new ColorContext( *this, maColorEntry
.maTextLineColor
);
212 case DGM_TOKEN(txEffectClrLst
):
213 return new ColorContext( *this, maColorEntry
.maTextEffectColor
);
222 void ColorFragmentHandler::onStartElement( const AttributeList
& rAttribs
)
224 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
226 maColorName
= rAttribs
.getString( XML_name
, OUString() );
227 maColorEntry
= mrColorsMap
[maColorName
];
231 void ColorFragmentHandler::onEndElement( )
233 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
234 mrColorsMap
[maColorName
] = maColorEntry
;
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */