Update ooo320-m1
[ooovba.git] / oox / source / drawingml / colorchoicecontext.cxx
blob3dff6aac52a7ac00e094ada79cfc423347e8009a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: colorchoicecontext.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/drawingml/colorchoicecontext.hxx"
32 #include "oox/helper/attributelist.hxx"
33 #include "oox/core/namespaces.hxx"
34 #include "oox/drawingml/color.hxx"
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::RuntimeException;
38 using ::com::sun::star::xml::sax::SAXException;
39 using ::com::sun::star::xml::sax::XFastAttributeList;
40 using ::com::sun::star::xml::sax::XFastContextHandler;
41 using ::oox::core::ContextHandler;
43 namespace oox {
44 namespace drawingml {
46 // ============================================================================
48 ColorValueContext::ColorValueContext( ContextHandler& rParent, Color& rColor ) :
49 ContextHandler( rParent ),
50 mrColor( rColor )
54 void ColorValueContext::startFastElement( sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
55 throw (SAXException, RuntimeException)
57 AttributeList aAttribs( rxAttribs );
58 switch( nElement )
60 case A_TOKEN( scrgbClr ):
61 mrColor.setScrgbClr(
62 aAttribs.getInteger( XML_r, 0 ),
63 aAttribs.getInteger( XML_g, 0 ),
64 aAttribs.getInteger( XML_b, 0 ) );
65 break;
67 case A_TOKEN( srgbClr ):
68 mrColor.setSrgbClr( aAttribs.getIntegerHex( XML_val, 0 ) );
69 break;
71 case A_TOKEN( hslClr ):
72 mrColor.setHslClr(
73 aAttribs.getInteger( XML_hue, 0 ),
74 aAttribs.getInteger( XML_sat, 0 ),
75 aAttribs.getInteger( XML_lum, 0 ) );
76 break;
78 case A_TOKEN( sysClr ):
79 mrColor.setSysClr(
80 aAttribs.getToken( XML_val, XML_TOKEN_INVALID ),
81 aAttribs.getIntegerHex( XML_lastClr, -1 ) );
82 break;
84 case A_TOKEN( schemeClr ):
85 mrColor.setSchemeClr( aAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
86 break;
88 case A_TOKEN( prstClr ):
89 mrColor.setPrstClr( aAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
90 break;
94 Reference< XFastContextHandler > ColorValueContext::createFastChildContext(
95 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
97 AttributeList aAttribs( rxAttribs );
98 switch( nElement )
100 case A_TOKEN( alpha ):
101 case A_TOKEN( alphaMod ):
102 case A_TOKEN( alphaOff ):
103 case A_TOKEN( blue ):
104 case A_TOKEN( blueMod ):
105 case A_TOKEN( blueOff ):
106 case A_TOKEN( hue ):
107 case A_TOKEN( hueMod ):
108 case A_TOKEN( hueOff ):
109 case A_TOKEN( lum ):
110 case A_TOKEN( lumMod ):
111 case A_TOKEN( lumOff ):
112 case A_TOKEN( green ):
113 case A_TOKEN( greenMod ):
114 case A_TOKEN( greenOff ):
115 case A_TOKEN( red ):
116 case A_TOKEN( redMod ):
117 case A_TOKEN( redOff ):
118 case A_TOKEN( sat ):
119 case A_TOKEN( satMod ):
120 case A_TOKEN( satOff ):
121 case A_TOKEN( shade ):
122 case A_TOKEN( tint ):
123 mrColor.addTransformation( nElement, aAttribs.getInteger( XML_val, 0 ) );
124 break;
125 case A_TOKEN( comp ):
126 case A_TOKEN( gamma ):
127 case A_TOKEN( gray ):
128 case A_TOKEN( inv ):
129 case A_TOKEN( invGamma ):
130 mrColor.addTransformation( nElement );
131 break;
133 return 0;
136 // ============================================================================
138 ColorContext::ColorContext( ContextHandler& rParent, Color& rColor ) :
139 ContextHandler( rParent ),
140 mrColor( rColor )
144 Reference< XFastContextHandler > ColorContext::createFastChildContext(
145 sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
147 switch( nElement )
149 case A_TOKEN( scrgbClr ):
150 case A_TOKEN( srgbClr ):
151 case A_TOKEN( hslClr ):
152 case A_TOKEN( sysClr ):
153 case A_TOKEN( schemeClr ):
154 case A_TOKEN( prstClr ):
155 return new ColorValueContext( *this, mrColor );
157 return 0;
160 // ============================================================================
162 } // namespace drawingml
163 } // namespace oox