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