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>
29 using namespace ::oox::core
;
31 namespace oox::drawingml
{
33 DiagramDataFragmentHandler::DiagramDataFragmentHandler( XmlFilterBase
& rFilter
,
34 const OUString
& rFragmentPath
,
35 OoxDiagramDataPtr xDataPtr
)
36 : FragmentHandler2( rFilter
, rFragmentPath
)
37 , mpDataPtr(std::move( xDataPtr
))
41 DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) noexcept
46 void SAL_CALL
DiagramDataFragmentHandler::endDocument()
52 DiagramDataFragmentHandler::onCreateContext( ::sal_Int32 aElement
,
53 const AttributeList
& )
57 case DGM_TOKEN( dataModel
):
58 return new DataModelContext( *this, mpDataPtr
);
66 DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( XmlFilterBase
& rFilter
,
67 const OUString
& rFragmentPath
,
68 DiagramLayoutPtr xDataPtr
)
69 : FragmentHandler2( rFilter
, rFragmentPath
)
70 , mpDataPtr(std::move( xDataPtr
))
74 DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) noexcept
79 void SAL_CALL
DiagramLayoutFragmentHandler::endDocument()
85 DiagramLayoutFragmentHandler::onCreateContext( ::sal_Int32 aElement
,
86 const AttributeList
& rAttribs
)
90 case DGM_TOKEN( layoutDef
):
91 return new DiagramDefinitionContext( *this, rAttribs
, mpDataPtr
);
99 DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase
& rFilter
,
100 const OUString
& rFragmentPath
,
101 DiagramQStyleMap
& rStylesMap
) :
102 FragmentHandler2( rFilter
, rFragmentPath
),
104 mrStylesMap( rStylesMap
)
107 ::oox::core::ContextHandlerRef
DiagramQStylesFragmentHandler::createStyleMatrixContext(
109 const AttributeList
& rAttribs
,
110 ShapeStyleRef
& o_rStyle
)
112 o_rStyle
.mnThemedIdx
= (nElement
== A_TOKEN(fontRef
)) ?
113 rAttribs
.getToken( XML_idx
, XML_none
) : rAttribs
.getInteger( XML_idx
, 0 );
114 return new ColorContext( *this, o_rStyle
.maPhClr
);
117 ::oox::core::ContextHandlerRef
DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement
,
118 const AttributeList
& rAttribs
)
120 // state-table like way of navigating the color fragment. we
121 // currently ignore everything except styleLbl in the styleDef
123 switch( getCurrentElement() )
125 case XML_ROOT_CONTEXT
:
126 return nElement
== DGM_TOKEN(styleDef
) ? this : nullptr;
127 case DGM_TOKEN(styleDef
):
128 return nElement
== DGM_TOKEN(styleLbl
) ? this : nullptr;
129 case DGM_TOKEN(styleLbl
):
130 return nElement
== DGM_TOKEN(style
) ? this : nullptr;
131 case DGM_TOKEN(style
):
135 case A_TOKEN(lnRef
): // CT_StyleMatrixReference
136 return createStyleMatrixContext(nElement
,rAttribs
,
137 maStyleEntry
.maLineStyle
);
138 case A_TOKEN(fillRef
): // CT_StyleMatrixReference
139 return createStyleMatrixContext(nElement
,rAttribs
,
140 maStyleEntry
.maFillStyle
);
141 case A_TOKEN(effectRef
): // CT_StyleMatrixReference
142 return createStyleMatrixContext(nElement
,rAttribs
,
143 maStyleEntry
.maEffectStyle
);
144 case A_TOKEN(fontRef
): // CT_FontReference
145 return createStyleMatrixContext(nElement
,rAttribs
,
146 maStyleEntry
.maTextStyle
);
155 void DiagramQStylesFragmentHandler::onStartElement( const AttributeList
& rAttribs
)
157 if( getCurrentElement() == DGM_TOKEN( styleLbl
) )
159 maStyleName
= rAttribs
.getStringDefaulted( XML_name
);
160 maStyleEntry
= mrStylesMap
[maStyleName
];
164 void DiagramQStylesFragmentHandler::onEndElement( )
166 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
167 mrStylesMap
[maStyleName
] = maStyleEntry
;
170 ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase
& rFilter
,
171 const OUString
& rFragmentPath
,
172 DiagramColorMap
& rColorsMap
) :
173 FragmentHandler2(rFilter
,rFragmentPath
),
175 mrColorsMap(rColorsMap
)
178 ::oox::core::ContextHandlerRef
ColorFragmentHandler::onCreateContext( sal_Int32 nElement
,
179 const AttributeList
& /*rAttribs*/ )
181 // state-table like way of navigating the color fragment. we
182 // currently ignore everything except styleLbl in the colorsDef
184 switch( getCurrentElement() )
186 case XML_ROOT_CONTEXT
:
187 return nElement
== DGM_TOKEN(colorsDef
) ? this : nullptr;
188 case DGM_TOKEN(colorsDef
):
189 return nElement
== DGM_TOKEN(styleLbl
) ? this : nullptr;
190 case DGM_TOKEN(styleLbl
):
194 // the actual colors - defer to color fragment handlers.
196 case DGM_TOKEN(fillClrLst
):
197 return new ColorsContext( *this, maColorEntry
.maFillColors
);
198 case DGM_TOKEN(linClrLst
):
199 return new ColorsContext( *this, maColorEntry
.maLineColors
);
200 case DGM_TOKEN(effectClrLst
):
201 return new ColorsContext( *this, maColorEntry
.maEffectColors
);
202 case DGM_TOKEN(txFillClrLst
):
203 return new ColorsContext( *this, maColorEntry
.maTextFillColors
);
204 case DGM_TOKEN(txLinClrLst
):
205 return new ColorsContext( *this, maColorEntry
.maTextLineColors
);
206 case DGM_TOKEN(txEffectClrLst
):
207 return new ColorsContext( *this, maColorEntry
.maTextEffectColors
);
216 void ColorFragmentHandler::onStartElement( const AttributeList
& rAttribs
)
218 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
220 maColorName
= rAttribs
.getStringDefaulted( XML_name
);
221 maColorEntry
= mrColorsMap
[maColorName
];
225 void ColorFragmentHandler::onEndElement( )
227 if( getCurrentElement() == DGM_TOKEN(styleLbl
) )
228 mrColorsMap
[maColorName
] = maColorEntry
;
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */