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/themeelementscontext.hxx" 25cdf0e10cSrcweir #include "oox/drawingml/clrschemecontext.hxx" 26cdf0e10cSrcweir #include "oox/drawingml/lineproperties.hxx" 27cdf0e10cSrcweir #include "oox/drawingml/linepropertiescontext.hxx" 28cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx" 29cdf0e10cSrcweir #include "oox/drawingml/fillpropertiesgroupcontext.hxx" 30cdf0e10cSrcweir #include "oox/drawingml/theme.hxx" 31cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir using ::rtl::OUString; 34cdf0e10cSrcweir using namespace ::oox::core; 35cdf0e10cSrcweir using namespace ::com::sun::star::uno; 36cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace oox { 39cdf0e10cSrcweir namespace drawingml { 40cdf0e10cSrcweir 41cdf0e10cSrcweir // ============================================================================ 42cdf0e10cSrcweir 43cdf0e10cSrcweir class FillStyleListContext : public ContextHandler 44cdf0e10cSrcweir { 45cdf0e10cSrcweir public: 46cdf0e10cSrcweir FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList ); 47cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 48cdf0e10cSrcweir 49cdf0e10cSrcweir private: 50cdf0e10cSrcweir FillStyleList& mrFillStyleList; 51cdf0e10cSrcweir }; 52cdf0e10cSrcweir 53cdf0e10cSrcweir FillStyleListContext::FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList ) : 54cdf0e10cSrcweir ContextHandler( rParent ), 55cdf0e10cSrcweir mrFillStyleList( rFillStyleList ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir Reference< XFastContextHandler > FillStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) 60cdf0e10cSrcweir throw (SAXException, RuntimeException) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir switch( nElement ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir case A_TOKEN( noFill ): 65cdf0e10cSrcweir case A_TOKEN( solidFill ): 66cdf0e10cSrcweir case A_TOKEN( gradFill ): 67cdf0e10cSrcweir case A_TOKEN( blipFill ): 68cdf0e10cSrcweir case A_TOKEN( pattFill ): 69cdf0e10cSrcweir case A_TOKEN( grpFill ): 70cdf0e10cSrcweir mrFillStyleList.push_back( FillPropertiesPtr( new FillProperties ) ); 71cdf0e10cSrcweir return FillPropertiesContext::createFillContext( *this, nElement, xAttribs, *mrFillStyleList.back() ); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir return 0; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir // ============================================================================ 77cdf0e10cSrcweir 78cdf0e10cSrcweir class LineStyleListContext : public ContextHandler 79cdf0e10cSrcweir { 80cdf0e10cSrcweir public: 81cdf0e10cSrcweir LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList ); 82cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 83cdf0e10cSrcweir 84cdf0e10cSrcweir private: 85cdf0e10cSrcweir LineStyleList& mrLineStyleList; 86cdf0e10cSrcweir }; 87cdf0e10cSrcweir 88cdf0e10cSrcweir LineStyleListContext::LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList ) : 89cdf0e10cSrcweir ContextHandler( rParent ), 90cdf0e10cSrcweir mrLineStyleList( rLineStyleList ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir Reference< XFastContextHandler > LineStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) 95cdf0e10cSrcweir throw (SAXException, RuntimeException) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir switch( nElement ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir case A_TOKEN( ln ): 100cdf0e10cSrcweir mrLineStyleList.push_back( LinePropertiesPtr( new LineProperties ) ); 101cdf0e10cSrcweir return new LinePropertiesContext( *this, xAttribs, *mrLineStyleList.back() ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir return 0; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir // ============================================================================ 107cdf0e10cSrcweir 108cdf0e10cSrcweir class EffectStyleListContext : public ContextHandler 109cdf0e10cSrcweir { 110cdf0e10cSrcweir public: 111cdf0e10cSrcweir EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList ); 112cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 113cdf0e10cSrcweir 114cdf0e10cSrcweir private: 115cdf0e10cSrcweir EffectStyleList& mrEffectStyleList; 116cdf0e10cSrcweir }; 117cdf0e10cSrcweir 118cdf0e10cSrcweir EffectStyleListContext::EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList ) : 119cdf0e10cSrcweir ContextHandler( rParent ), 120cdf0e10cSrcweir mrEffectStyleList( rEffectStyleList ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir Reference< XFastContextHandler > EffectStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& /*xAttribs*/ ) throw (SAXException, RuntimeException) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir switch( nElement ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir case A_TOKEN( effectStyle ): 129cdf0e10cSrcweir mrEffectStyleList.push_back( EffectStyleList::value_type( new PropertyMap ) ); 130cdf0e10cSrcweir // TODO: import effect styles 131cdf0e10cSrcweir return 0; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir return 0; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir // ============================================================================ 137cdf0e10cSrcweir 138cdf0e10cSrcweir class FontSchemeContext : public ContextHandler 139cdf0e10cSrcweir { 140cdf0e10cSrcweir public: 141cdf0e10cSrcweir FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme ); 142cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 143cdf0e10cSrcweir virtual void SAL_CALL endFastElement( sal_Int32 nElement ) throw (SAXException, RuntimeException); 144cdf0e10cSrcweir 145cdf0e10cSrcweir private: 146cdf0e10cSrcweir FontScheme& mrFontScheme; 147cdf0e10cSrcweir TextCharacterPropertiesPtr mxCharProps; 148cdf0e10cSrcweir }; 149cdf0e10cSrcweir 150cdf0e10cSrcweir FontSchemeContext::FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme ) : 151cdf0e10cSrcweir ContextHandler( rParent ), 152cdf0e10cSrcweir mrFontScheme( rFontScheme ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir Reference< XFastContextHandler > FontSchemeContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) 157cdf0e10cSrcweir throw (SAXException, RuntimeException) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 160cdf0e10cSrcweir switch( nElement ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir case A_TOKEN( majorFont ): 163cdf0e10cSrcweir mxCharProps.reset( new TextCharacterProperties ); 164cdf0e10cSrcweir mrFontScheme[ XML_major ] = mxCharProps; 165cdf0e10cSrcweir return this; 166cdf0e10cSrcweir case A_TOKEN( minorFont ): 167cdf0e10cSrcweir mxCharProps.reset( new TextCharacterProperties ); 168cdf0e10cSrcweir mrFontScheme[ XML_minor ] = mxCharProps; 169cdf0e10cSrcweir return this; 170cdf0e10cSrcweir 171cdf0e10cSrcweir case A_TOKEN( latin ): 172cdf0e10cSrcweir if( mxCharProps.get() ) 173cdf0e10cSrcweir mxCharProps->maLatinFont.setAttributes( aAttribs ); 174cdf0e10cSrcweir break; 175cdf0e10cSrcweir case A_TOKEN( ea ): 176cdf0e10cSrcweir if( mxCharProps.get() ) 177cdf0e10cSrcweir mxCharProps->maAsianFont.setAttributes( aAttribs ); 178cdf0e10cSrcweir break; 179cdf0e10cSrcweir case A_TOKEN( cs ): 180cdf0e10cSrcweir if( mxCharProps.get() ) 181cdf0e10cSrcweir mxCharProps->maComplexFont.setAttributes( aAttribs ); 182cdf0e10cSrcweir break; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir return 0; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir void FontSchemeContext::endFastElement( sal_Int32 nElement ) throw (SAXException, RuntimeException) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir switch( nElement ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir case A_TOKEN( majorFont ): 192cdf0e10cSrcweir case A_TOKEN( minorFont ): 193cdf0e10cSrcweir mxCharProps.reset(); 194cdf0e10cSrcweir break; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir // ============================================================================ 199cdf0e10cSrcweir 200cdf0e10cSrcweir ThemeElementsContext::ThemeElementsContext( ContextHandler& rParent, Theme& rTheme ) : 201cdf0e10cSrcweir ContextHandler( rParent ), 202cdf0e10cSrcweir mrTheme( rTheme ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir Reference< XFastContextHandler > ThemeElementsContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir // CT_BaseStyles 209cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 210cdf0e10cSrcweir switch( nElement ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir case A_TOKEN( clrScheme ): // CT_ColorScheme 213cdf0e10cSrcweir return new clrSchemeContext( *this, mrTheme.getClrScheme() ); 214cdf0e10cSrcweir case A_TOKEN( fontScheme ): // CT_FontScheme 215cdf0e10cSrcweir return new FontSchemeContext( *this, mrTheme.getFontScheme() ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir case A_TOKEN( fmtScheme ): // CT_StyleMatrix 218cdf0e10cSrcweir mrTheme.setStyleName( xAttribs->getOptionalValue( XML_name ) ); 219cdf0e10cSrcweir return this; 220cdf0e10cSrcweir 221cdf0e10cSrcweir case A_TOKEN( fillStyleLst ): // CT_FillStyleList 222cdf0e10cSrcweir return new FillStyleListContext( *this, mrTheme.getFillStyleList() ); 223cdf0e10cSrcweir case A_TOKEN( lnStyleLst ): // CT_LineStyleList 224cdf0e10cSrcweir return new LineStyleListContext( *this, mrTheme.getLineStyleList() ); 225cdf0e10cSrcweir case A_TOKEN( effectStyleLst ): // CT_EffectStyleList 226cdf0e10cSrcweir return new EffectStyleListContext( *this, mrTheme.getEffectStyleList() ); 227cdf0e10cSrcweir case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList 228cdf0e10cSrcweir return new FillStyleListContext( *this, mrTheme.getBgFillStyleList() ); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir return 0; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir // ============================================================================ 234cdf0e10cSrcweir 235cdf0e10cSrcweir } // namespace drawingml 236cdf0e10cSrcweir } // namespace oox 237cdf0e10cSrcweir 238