1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/drawingml/colorchoicecontext.hxx"
25 #include "oox/helper/attributelist.hxx"
26 #include "oox/drawingml/color.hxx"
27 
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::RuntimeException;
30 using ::com::sun::star::xml::sax::SAXException;
31 using ::com::sun::star::xml::sax::XFastAttributeList;
32 using ::com::sun::star::xml::sax::XFastContextHandler;
33 using ::oox::core::ContextHandler;
34 
35 namespace oox {
36 namespace drawingml {
37 
38 // ============================================================================
39 
ColorValueContext(ContextHandler & rParent,Color & rColor)40 ColorValueContext::ColorValueContext( ContextHandler& rParent, Color& rColor ) :
41     ContextHandler( rParent ),
42     mrColor( rColor )
43 {
44 }
45 
startFastElement(sal_Int32 nElement,const Reference<XFastAttributeList> & rxAttribs)46 void ColorValueContext::startFastElement( sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
47 	throw (SAXException, RuntimeException)
48 {
49     AttributeList aAttribs( rxAttribs );
50     switch( nElement )
51     {
52         case A_TOKEN( scrgbClr ):
53             mrColor.setScrgbClr(
54                 aAttribs.getInteger( XML_r, 0 ),
55                 aAttribs.getInteger( XML_g, 0 ),
56                 aAttribs.getInteger( XML_b, 0 ) );
57         break;
58 
59         case A_TOKEN( srgbClr ):
60             mrColor.setSrgbClr( aAttribs.getIntegerHex( XML_val, 0 ) );
61         break;
62 
63         case A_TOKEN( hslClr ):
64             mrColor.setHslClr(
65                 aAttribs.getInteger( XML_hue, 0 ),
66                 aAttribs.getInteger( XML_sat, 0 ),
67                 aAttribs.getInteger( XML_lum, 0 ) );
68         break;
69 
70         case A_TOKEN( sysClr ):
71             mrColor.setSysClr(
72                 aAttribs.getToken( XML_val, XML_TOKEN_INVALID ),
73                 aAttribs.getIntegerHex( XML_lastClr, -1 ) );
74         break;
75 
76         case A_TOKEN( schemeClr ):
77             mrColor.setSchemeClr( aAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
78         break;
79 
80         case A_TOKEN( prstClr ):
81             mrColor.setPrstClr( aAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
82 		break;
83     }
84 }
85 
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> & rxAttribs)86 Reference< XFastContextHandler > ColorValueContext::createFastChildContext(
87         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
88 {
89     AttributeList aAttribs( rxAttribs );
90     switch( nElement )
91     {
92         case A_TOKEN( alpha ):
93         case A_TOKEN( alphaMod ):
94         case A_TOKEN( alphaOff ):
95         case A_TOKEN( blue ):
96         case A_TOKEN( blueMod ):
97         case A_TOKEN( blueOff ):
98         case A_TOKEN( hue ):
99         case A_TOKEN( hueMod ):
100         case A_TOKEN( hueOff ):
101         case A_TOKEN( lum ):
102         case A_TOKEN( lumMod ):
103         case A_TOKEN( lumOff ):
104         case A_TOKEN( green ):
105         case A_TOKEN( greenMod ):
106         case A_TOKEN( greenOff ):
107         case A_TOKEN( red ):
108         case A_TOKEN( redMod ):
109         case A_TOKEN( redOff ):
110         case A_TOKEN( sat ):
111         case A_TOKEN( satMod ):
112         case A_TOKEN( satOff ):
113         case A_TOKEN( shade ):
114         case A_TOKEN( tint ):
115             mrColor.addTransformation( nElement, aAttribs.getInteger( XML_val, 0 ) );
116 		break;
117         case A_TOKEN( comp ):
118         case A_TOKEN( gamma ):
119         case A_TOKEN( gray ):
120         case A_TOKEN( inv ):
121         case A_TOKEN( invGamma ):
122             mrColor.addTransformation( nElement );
123         break;
124 	}
125     return 0;
126 }
127 
128 // ============================================================================
129 
ColorContext(ContextHandler & rParent,Color & rColor)130 ColorContext::ColorContext( ContextHandler& rParent, Color& rColor ) :
131     ContextHandler( rParent ),
132     mrColor( rColor )
133 {
134 }
135 
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> &)136 Reference< XFastContextHandler > ColorContext::createFastChildContext(
137         sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
138 {
139     switch( nElement )
140     {
141         case A_TOKEN( scrgbClr ):
142         case A_TOKEN( srgbClr ):
143         case A_TOKEN( hslClr ):
144         case A_TOKEN( sysClr ):
145         case A_TOKEN( schemeClr ):
146         case A_TOKEN( prstClr ):
147             return new ColorValueContext( *this, mrColor );
148     }
149     return 0;
150 }
151 
152 // ============================================================================
153 
154 } // namespace drawingml
155 } // namespace oox
156 
157