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