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/ppt/pptimport.hxx" 29 #include "oox/drawingml/chart/chartconverter.hxx" 30 #include "oox/dump/pptxdumper.hxx" 31 #include "oox/drawingml/table/tablestylelistfragmenthandler.hxx" 32 #include "oox/helper/graphichelper.hxx" 33 #include "oox/ole/vbaproject.hxx" 34 35 using ::rtl::OUString; 36 using namespace ::com::sun::star; 37 using namespace ::com::sun::star::uno; 38 using namespace ::com::sun::star::xml::sax; 39 using namespace oox::core; 40 41 namespace oox { namespace ppt { 42 43 OUString SAL_CALL PowerPointImport_getImplementationName() throw() 44 { 45 return CREATE_OUSTRING( "com.sun.star.comp.oox.ppt.PowerPointImport" ); 46 } 47 48 uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames() throw() 49 { 50 Sequence< OUString > aSeq( 2 ); 51 aSeq[ 0 ] = CREATE_OUSTRING( "com.sun.star.document.ImportFilter" ); 52 aSeq[ 1 ] = CREATE_OUSTRING( "com.sun.star.document.ExportFilter" ); 53 return aSeq; 54 } 55 56 uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception ) 57 { 58 return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) ); 59 } 60 61 PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) : 62 XmlFilterBase( rxContext ), 63 mxChartConv( new ::oox::drawingml::chart::ChartConverter ) 64 { 65 } 66 67 PowerPointImport::~PowerPointImport() 68 { 69 } 70 71 bool PowerPointImport::importDocument() throw() 72 { 73 /* to activate the PPTX dumper, define the environment variable 74 OOO_PPTXDUMPER and insert the full path to the file 75 file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */ 76 OOX_DUMP_FILE( ::oox::dump::pptx::Dumper ); 77 78 OUString aFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "officeDocument" ) ); 79 FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) ); 80 maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "tableStyles" ) ); 81 return importFragment( xPresentationFragmentHandler ); 82 83 84 } 85 86 bool PowerPointImport::exportDocument() throw() 87 { 88 return false; 89 } 90 91 sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const 92 { 93 sal_Int32 nColor = 0; 94 if ( mpActualSlidePersist ) 95 { 96 sal_Bool bColorMapped = sal_False; 97 oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() ); 98 if ( pClrMapPtr ) 99 bColorMapped = pClrMapPtr->getColorMap( nToken ); 100 101 if ( !bColorMapped ) // try masterpage mapping 102 { 103 SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist(); 104 if ( pMasterPersist ) 105 { 106 pClrMapPtr = pMasterPersist->getClrMap(); 107 if ( pClrMapPtr ) 108 bColorMapped = pClrMapPtr->getColorMap( nToken ); 109 } 110 } 111 oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() ); 112 if ( pClrSchemePtr ) 113 pClrSchemePtr->getColor( nToken, nColor ); 114 else 115 { 116 ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme(); 117 if( pTheme ) 118 { 119 pTheme->getClrScheme().getColor( nToken, nColor ); 120 } 121 else 122 { 123 OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL"); 124 } 125 } 126 } 127 return nColor; 128 } 129 130 const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const 131 { 132 return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0; 133 } 134 135 ::oox::vml::Drawing* PowerPointImport::getVmlDrawing() 136 { 137 return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0; 138 } 139 140 const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles() 141 { 142 if ( !mpTableStyleList && maTableStyleListPath.getLength() ) 143 { 144 mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() ); 145 importFragment( new oox::drawingml::table::TableStyleListFragmentHandler( 146 *this, maTableStyleListPath, *mpTableStyleList ) ); 147 } 148 return mpTableStyleList;; 149 } 150 151 ::oox::drawingml::chart::ChartConverter& PowerPointImport::getChartConverter() 152 { 153 return *mxChartConv; 154 } 155 156 namespace { 157 158 class PptGraphicHelper : public GraphicHelper 159 { 160 public: 161 explicit PptGraphicHelper( const PowerPointImport& rFilter ); 162 virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const; 163 private: 164 const PowerPointImport& mrFilter; 165 }; 166 167 PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) : 168 GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ), 169 mrFilter( rFilter ) 170 { 171 } 172 173 sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const 174 { 175 return mrFilter.getSchemeColor( nToken ); 176 } 177 178 } // namespace 179 180 GraphicHelper* PowerPointImport::implCreateGraphicHelper() const 181 { 182 return new PptGraphicHelper( *this ); 183 } 184 185 ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const 186 { 187 return new ::oox::ole::VbaProject( getComponentContext(), getModel(), CREATE_OUSTRING( "Impress" ) ); 188 } 189 190 OUString PowerPointImport::implGetImplementationName() const 191 { 192 return PowerPointImport_getImplementationName(); 193 } 194 195 }} 196