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