Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/xml/sax/FastToken.hpp>
21 : #include <com/sun/star/drawing/LineStyle.hpp>
22 : #include <com/sun/star/beans/XMultiPropertySet.hpp>
23 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 : #include <com/sun/star/container/XNamed.hpp>
25 :
26 : #include "oox/helper/attributelist.hxx"
27 : #include "oox/ppt/pptshape.hxx"
28 : #include "oox/ppt/pptshapecontext.hxx"
29 : #include "oox/ppt/pptshapepropertiescontext.hxx"
30 : #include "oox/ppt/slidepersist.hxx"
31 : #include "oox/drawingml/shapestylecontext.hxx"
32 : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
33 : #include "oox/drawingml/lineproperties.hxx"
34 : #include "oox/drawingml/drawingmltypes.hxx"
35 : #include "oox/drawingml/customshapegeometry.hxx"
36 : #include "oox/drawingml/textbodycontext.hxx"
37 : #include "oox/drawingml/transform2dcontext.hxx"
38 :
39 : using namespace oox::core;
40 : using namespace ::com::sun::star;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::drawing;
43 : using namespace ::com::sun::star::beans;
44 : using namespace ::com::sun::star::text;
45 : using namespace ::com::sun::star::xml::sax;
46 :
47 : namespace oox { namespace ppt {
48 :
49 : // CT_Shape
50 0 : PPTShapeContext::PPTShapeContext( ContextHandler2Helper& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
51 : : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
52 0 : , mpSlidePersistPtr( pSlidePersistPtr )
53 : {
54 0 : }
55 :
56 0 : oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
57 : {
58 0 : oox::drawingml::ShapePtr aShapePtr;
59 0 : oox::drawingml::ShapePtr aChoiceShapePtr1;
60 0 : oox::drawingml::ShapePtr aChoiceShapePtr2;
61 0 : std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
62 0 : while( aRevIter != rShapes.rend() )
63 : {
64 0 : if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
65 : {
66 0 : if( !oSubTypeIndex.has() && aChoiceShapePtr1 == 0 )
67 0 : aChoiceShapePtr1 = *aRevIter;
68 0 : else if( aChoiceShapePtr2 == 0 )
69 0 : aChoiceShapePtr2 = *aRevIter;
70 0 : if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
71 : {
72 0 : aShapePtr = *aRevIter;
73 0 : break;
74 : }
75 : }
76 0 : std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
77 0 : aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
78 0 : if ( aShapePtr.get() )
79 0 : break;
80 0 : ++aRevIter;
81 : }
82 0 : if( aShapePtr == 0 )
83 0 : return aChoiceShapePtr1 ? aChoiceShapePtr1 : aChoiceShapePtr2;
84 0 : return aShapePtr;
85 : }
86 :
87 : // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
88 0 : oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
89 : const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
90 : {
91 0 : oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
92 0 : return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
93 : }
94 :
95 0 : ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
96 : {
97 0 : if( getNamespace( aElementToken ) == NMSP_dsp )
98 0 : aElementToken = NMSP_ppt | getBaseToken( aElementToken );
99 :
100 0 : switch( aElementToken )
101 : {
102 : // nvSpPr CT_ShapeNonVisual begin
103 : // case PPT_TOKEN( drElemPr ):
104 : // break;
105 : case PPT_TOKEN( cNvPr ):
106 : {
107 0 : mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
108 0 : mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
109 0 : mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
110 0 : break;
111 : }
112 : case PPT_TOKEN( ph ):
113 : {
114 0 : sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
115 0 : mpShapePtr->setSubType( nSubType );
116 0 : if( rAttribs.hasAttribute( XML_idx ) )
117 0 : mpShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
118 0 : if ( nSubType )
119 : {
120 0 : PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
121 0 : if ( pPPTShapePtr )
122 : {
123 0 : oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
124 0 : if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
125 : {
126 : // inheriting properties from placeholder objects by cloning shape
127 0 : sal_Int32 nFirstPlaceholder = 0;
128 0 : sal_Int32 nSecondPlaceholder = 0;
129 0 : switch( nSubType )
130 : {
131 : case XML_ctrTitle : // slide/layout
132 0 : nFirstPlaceholder = XML_ctrTitle;
133 0 : nSecondPlaceholder = XML_title;
134 0 : break;
135 :
136 : case XML_subTitle : // slide/layout
137 0 : nFirstPlaceholder = XML_subTitle;
138 0 : nSecondPlaceholder = XML_title;
139 0 : break;
140 :
141 : case XML_obj : // slide/layout
142 0 : nFirstPlaceholder = XML_obj;
143 0 : nSecondPlaceholder = XML_body;
144 0 : break;
145 :
146 : case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
147 : case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
148 : case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
149 : case XML_hdr : // notes/notesmaster/handoutmaster
150 : case XML_body : // slide/layout/master/notes/notesmaster
151 : case XML_title : // slide/layout/master/
152 : case XML_chart : // slide/layout
153 : case XML_tbl : // slide/layout
154 : case XML_clipArt : // slide/layout
155 : case XML_dgm : // slide/layout
156 : case XML_media : // slide/layout
157 : case XML_sldImg : // notes/notesmaster
158 : case XML_pic : // slide/layout
159 0 : nFirstPlaceholder = nSubType;
160 : default:
161 0 : break;
162 : }
163 0 : if ( nFirstPlaceholder )
164 : {
165 0 : oox::drawingml::ShapePtr pPlaceholder;
166 0 : if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
167 : {
168 0 : if( pPPTShapePtr->getSubTypeIndex().has() )
169 0 : pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
170 0 : if ( !pPlaceholder.get() )
171 0 : pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
172 0 : mpSlidePersistPtr->getShapes()->getChildren() );
173 : }
174 0 : else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
175 : {
176 0 : SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
177 0 : if ( pMasterPersist.get() ) {
178 0 : if( pPPTShapePtr->getSubTypeIndex().has() )
179 0 : pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
180 : // TODO: Check if this is required for non-notes pages as well...
181 0 : if ( !pPlaceholder.get() || ( pMasterPersist->isNotesPage() && pPlaceholder->getSubType() != nFirstPlaceholder &&
182 0 : pPlaceholder->getSubType() != nSecondPlaceholder ) )
183 : {
184 0 : pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
185 0 : pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
186 : }
187 0 : }
188 : }
189 0 : if ( pPlaceholder.get() )
190 : {
191 : OSL_TRACE("shape %s will get shape reference %s applied", OUStringToOString(mpShapePtr->getId(), RTL_TEXTENCODING_UTF8 ).getStr(), OUStringToOString(pPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
192 0 : mpShapePtr->applyShapeReference( *pPlaceholder.get() );
193 0 : PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
194 0 : if ( pPPTShape )
195 0 : pPPTShape->setReferenced( true );
196 0 : pPPTShapePtr->setPlaceholder( pPlaceholder );
197 0 : }
198 : }
199 : }
200 : }
201 :
202 : }
203 0 : break;
204 : }
205 :
206 : // nvSpPr CT_ShapeNonVisual end
207 :
208 : case PPT_TOKEN( spPr ):
209 0 : return new PPTShapePropertiesContext( *this, *mpShapePtr );
210 :
211 : case PPT_TOKEN( style ):
212 0 : return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
213 :
214 : case PPT_TOKEN( txBody ):
215 : {
216 0 : oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
217 0 : xTextBody->getTextProperties().maPropertyMap.setProperty( PROP_FontIndependentLineSpacing, static_cast< sal_Bool >( sal_True ));
218 0 : mpShapePtr->setTextBody( xTextBody );
219 0 : return new oox::drawingml::TextBodyContext( *this, *xTextBody );
220 : }
221 : case PPT_TOKEN( txXfrm ):
222 : {
223 0 : return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
224 : }
225 : }
226 :
227 0 : return this;
228 : }
229 :
230 :
231 0 : } }
232 :
233 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|