1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // must be first
32*cdf0e10cSrcweir #include <canvas/debug.hxx>
33*cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
34*cdf0e10cSrcweir #include <tools/urlobj.hxx>
35*cdf0e10cSrcweir #include <tools/stream.hxx>
36*cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
37*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
38*cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
39*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
40*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
41*cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
42*cdf0e10cSrcweir #include <cppcanvas/polypolygon.hxx>
43*cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/drawing/ColorMode.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/text/GraphicCrop.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequenceSequence.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequence.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/drawing/XLayerSupplier.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/drawing/XLayerManager.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #include "drawshapesubsetting.hxx"
57*cdf0e10cSrcweir #include "drawshape.hxx"
58*cdf0e10cSrcweir #include "backgroundshape.hxx"
59*cdf0e10cSrcweir #include "mediashape.hxx"
60*cdf0e10cSrcweir #include "appletshape.hxx"
61*cdf0e10cSrcweir #include "shapeimporter.hxx"
62*cdf0e10cSrcweir #include "slideshowexceptions.hxx"
63*cdf0e10cSrcweir #include "gdimtftools.hxx"
64*cdf0e10cSrcweir #include "tools.hxx"
65*cdf0e10cSrcweir #include "slideshowcontext.hxx"
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
68*cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir using namespace com::sun::star;
71*cdf0e10cSrcweir using namespace ::comphelper;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir namespace slideshow {
74*cdf0e10cSrcweir namespace internal {
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir namespace {
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir bool importShapeGraphic(
79*cdf0e10cSrcweir     GraphicObject & o_rGraphic,
80*cdf0e10cSrcweir     uno::Reference<beans::XPropertySet> const& xPropSet )
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     rtl::OUString aURL;
83*cdf0e10cSrcweir     if( !getPropertyValue( aURL, xPropSet, OUSTR("GraphicURL")) ||
84*cdf0e10cSrcweir         aURL.getLength() == 0 )
85*cdf0e10cSrcweir     {
86*cdf0e10cSrcweir         // no or empty property - cannot import shape graphic
87*cdf0e10cSrcweir         return false;
88*cdf0e10cSrcweir     }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     rtl::OUString const aVndUrl(
91*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) );
92*cdf0e10cSrcweir     sal_Int32 nIndex( aURL.indexOf( aVndUrl ) );
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     if(nIndex != -1)
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir         // skip past the end of the "vnd..." prefix
97*cdf0e10cSrcweir         nIndex += aVndUrl.getLength();
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         if(nIndex >= aURL.getLength())
100*cdf0e10cSrcweir         {
101*cdf0e10cSrcweir             OSL_ENSURE( false, "ShapeImporter::importShape(): "
102*cdf0e10cSrcweir                         "embedded graphic has no graphic ID" );
103*cdf0e10cSrcweir             return false;
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         // unique ID string found in URL, extract
107*cdf0e10cSrcweir         // to separate string
108*cdf0e10cSrcweir         rtl::OUString const aUniqueId(
109*cdf0e10cSrcweir             aURL.copy( nIndex, aURL.getLength() - nIndex ) );
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir         // TODO(T2): Creating a GraphicObject is not
112*cdf0e10cSrcweir         // thread safe (internally calls VCL, and has
113*cdf0e10cSrcweir         // unguarded internal singleton mpGlobalMgr)
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         // fetch already loaded graphic from graphic manager.
116*cdf0e10cSrcweir         ByteString const aOldString( static_cast<String>(aUniqueId),
117*cdf0e10cSrcweir                                      RTL_TEXTENCODING_UTF8 );
118*cdf0e10cSrcweir         o_rGraphic = GraphicObject( aOldString );
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir         if( GRAPHIC_DEFAULT == o_rGraphic.GetType()
122*cdf0e10cSrcweir             || GRAPHIC_NONE == o_rGraphic.GetType() )
123*cdf0e10cSrcweir         {
124*cdf0e10cSrcweir             // even the GrfMgr does not seem to know this graphic
125*cdf0e10cSrcweir             return false;
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     else
129*cdf0e10cSrcweir     {
130*cdf0e10cSrcweir         // no special string found, graphic must be
131*cdf0e10cSrcweir         // external. Load via GraphicIm porter
132*cdf0e10cSrcweir         INetURLObject aTmp( aURL );
133*cdf0e10cSrcweir         boost::scoped_ptr<SvStream> pGraphicStream(
134*cdf0e10cSrcweir             utl::UcbStreamHelper::CreateStream(
135*cdf0e10cSrcweir                 aTmp.GetMainURL( INetURLObject::NO_DECODE ),
136*cdf0e10cSrcweir                 STREAM_READ ) );
137*cdf0e10cSrcweir         if( !pGraphicStream )
138*cdf0e10cSrcweir         {
139*cdf0e10cSrcweir             OSL_ENSURE( false, "ShapeImporter::importShape(): "
140*cdf0e10cSrcweir                         "cannot create input stream for graphic" );
141*cdf0e10cSrcweir             return false;
142*cdf0e10cSrcweir         }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         Graphic aTmpGraphic;
145*cdf0e10cSrcweir         if( GraphicConverter::Import(
146*cdf0e10cSrcweir                 *pGraphicStream, aTmpGraphic ) != ERRCODE_NONE )
147*cdf0e10cSrcweir         {
148*cdf0e10cSrcweir             OSL_ENSURE( false, "ShapeImporter::importShape(): "
149*cdf0e10cSrcweir                         "Failed to import shape graphic from given URL" );
150*cdf0e10cSrcweir             return false;
151*cdf0e10cSrcweir         }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir         o_rGraphic = GraphicObject( aTmpGraphic );
154*cdf0e10cSrcweir     }
155*cdf0e10cSrcweir     return true;
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir /** This shape implementation just acts as a dummy for the layermanager.
159*cdf0e10cSrcweir     Its sole role is for hit test detection of group shapes.
160*cdf0e10cSrcweir */
161*cdf0e10cSrcweir class ShapeOfGroup : public Shape
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir public:
164*cdf0e10cSrcweir     ShapeOfGroup( ShapeSharedPtr const&                      pGroupShape,
165*cdf0e10cSrcweir                   uno::Reference<drawing::XShape> const&     xShape,
166*cdf0e10cSrcweir                   uno::Reference<beans::XPropertySet> const& xPropSet,
167*cdf0e10cSrcweir                   double                                     nPrio );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     // Shape:
170*cdf0e10cSrcweir     virtual uno::Reference<drawing::XShape> getXShape() const;
171*cdf0e10cSrcweir     virtual void addViewLayer( ViewLayerSharedPtr const& pNewLayer,
172*cdf0e10cSrcweir                                bool                      bRedrawLayer );
173*cdf0e10cSrcweir     virtual bool removeViewLayer( ViewLayerSharedPtr const& pNewLayer );
174*cdf0e10cSrcweir     virtual bool clearAllViewLayers();
175*cdf0e10cSrcweir     virtual bool update() const;
176*cdf0e10cSrcweir     virtual bool render() const;
177*cdf0e10cSrcweir     virtual bool isContentChanged() const;
178*cdf0e10cSrcweir     virtual basegfx::B2DRectangle getBounds() const;
179*cdf0e10cSrcweir     virtual basegfx::B2DRectangle getDomBounds() const;
180*cdf0e10cSrcweir     virtual basegfx::B2DRectangle getUpdateArea() const;
181*cdf0e10cSrcweir     virtual bool isVisible() const;
182*cdf0e10cSrcweir     virtual double getPriority() const;
183*cdf0e10cSrcweir     virtual bool isBackgroundDetached() const;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir private:
186*cdf0e10cSrcweir     ShapeSharedPtr const                  mpGroupShape;
187*cdf0e10cSrcweir     uno::Reference<drawing::XShape> const mxShape;
188*cdf0e10cSrcweir     double const                          mnPrio;
189*cdf0e10cSrcweir     basegfx::B2DPoint                     maPosOffset;
190*cdf0e10cSrcweir     double                                mnWidth;
191*cdf0e10cSrcweir     double                                mnHeight;
192*cdf0e10cSrcweir };
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir ShapeOfGroup::ShapeOfGroup( ShapeSharedPtr const&                      pGroupShape,
195*cdf0e10cSrcweir                             uno::Reference<drawing::XShape> const&     xShape,
196*cdf0e10cSrcweir                             uno::Reference<beans::XPropertySet> const& xPropSet,
197*cdf0e10cSrcweir                             double                                     nPrio ) :
198*cdf0e10cSrcweir     mpGroupShape(pGroupShape),
199*cdf0e10cSrcweir     mxShape(xShape),
200*cdf0e10cSrcweir     mnPrio(nPrio)
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     // read bound rect
203*cdf0e10cSrcweir     uno::Any const aTmpRect_( xPropSet->getPropertyValue( OUSTR("BoundRect") ));
204*cdf0e10cSrcweir     awt::Rectangle const aTmpRect( aTmpRect_.get<awt::Rectangle>() );
205*cdf0e10cSrcweir     basegfx::B2DRectangle const groupPosSize( pGroupShape->getBounds() );
206*cdf0e10cSrcweir     maPosOffset = basegfx::B2DPoint( aTmpRect.X - groupPosSize.getMinX(),
207*cdf0e10cSrcweir                                      aTmpRect.Y - groupPosSize.getMinY() );
208*cdf0e10cSrcweir     mnWidth = aTmpRect.Width;
209*cdf0e10cSrcweir     mnHeight = aTmpRect.Height;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir uno::Reference<drawing::XShape> ShapeOfGroup::getXShape() const
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir     return mxShape;
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir void ShapeOfGroup::addViewLayer( ViewLayerSharedPtr const& /*pNewLayer*/,
218*cdf0e10cSrcweir                                  bool                      /*bRedrawLayer*/ )
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir bool ShapeOfGroup::removeViewLayer( ViewLayerSharedPtr const& /*pNewLayer*/ )
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir     return true;
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir bool ShapeOfGroup::clearAllViewLayers()
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir     return true;
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir bool ShapeOfGroup::update() const
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     return true;
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir bool ShapeOfGroup::render() const
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir     return true;
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir bool ShapeOfGroup::isContentChanged() const
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir     return false;
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir basegfx::B2DRectangle ShapeOfGroup::getBounds() const
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir     basegfx::B2DRectangle const groupPosSize( mpGroupShape->getBounds() );
250*cdf0e10cSrcweir     double const posX = (groupPosSize.getMinX() + maPosOffset.getX());
251*cdf0e10cSrcweir     double const posY = (groupPosSize.getMinY() + maPosOffset.getY());
252*cdf0e10cSrcweir     return basegfx::B2DRectangle( posX, posY, posX + mnWidth, posY + mnHeight );
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir basegfx::B2DRectangle ShapeOfGroup::getDomBounds() const
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir     return getBounds();
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir basegfx::B2DRectangle ShapeOfGroup::getUpdateArea() const
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     return getBounds();
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir bool ShapeOfGroup::isVisible() const
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     return mpGroupShape->isVisible();
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir double ShapeOfGroup::getPriority() const
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir     return mnPrio;
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir bool ShapeOfGroup::isBackgroundDetached() const
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir     return false;
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir } // anon namespace
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir ShapeSharedPtr ShapeImporter::createShape(
283*cdf0e10cSrcweir     uno::Reference<drawing::XShape> const& xCurrShape,
284*cdf0e10cSrcweir     uno::Reference<beans::XPropertySet> const& xPropSet,
285*cdf0e10cSrcweir     rtl::OUString const& shapeType ) const
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir     if( shapeType.equalsAsciiL(
288*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MediaShape") ) ||
289*cdf0e10cSrcweir 		shapeType.equalsAsciiL(
290*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.MediaShape") ) )
291*cdf0e10cSrcweir     {
292*cdf0e10cSrcweir         // Media shape (video etc.). This is a special object
293*cdf0e10cSrcweir         return createMediaShape(xCurrShape,
294*cdf0e10cSrcweir                                 mnAscendingPrio,
295*cdf0e10cSrcweir                                 mrContext);
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir     else if( shapeType.equalsAsciiL(
298*cdf0e10cSrcweir                  RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.PluginShape") ))
299*cdf0e10cSrcweir     {
300*cdf0e10cSrcweir         // PropertyValues to copy from XShape to plugin
301*cdf0e10cSrcweir         static const char* aPropertyValues[] =
302*cdf0e10cSrcweir             {
303*cdf0e10cSrcweir                 "PluginURL",
304*cdf0e10cSrcweir                 "PluginMimeType",
305*cdf0e10cSrcweir                 "PluginCommands"
306*cdf0e10cSrcweir             };
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir         // (Netscape)Plugin shape. This is a special object
309*cdf0e10cSrcweir         return createAppletShape( xCurrShape,
310*cdf0e10cSrcweir                                   mnAscendingPrio,
311*cdf0e10cSrcweir                                   ::rtl::OUString(
312*cdf0e10cSrcweir                                       RTL_CONSTASCII_USTRINGPARAM(
313*cdf0e10cSrcweir                                           "com.sun.star.comp.sfx2.PluginObject" )),
314*cdf0e10cSrcweir                                   aPropertyValues,
315*cdf0e10cSrcweir                                   sizeof(aPropertyValues)/sizeof(*aPropertyValues),
316*cdf0e10cSrcweir                                   mrContext );
317*cdf0e10cSrcweir     }
318*cdf0e10cSrcweir     else if( shapeType.equalsAsciiL(
319*cdf0e10cSrcweir                  RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.AppletShape") ))
320*cdf0e10cSrcweir     {
321*cdf0e10cSrcweir         // PropertyValues to copy from XShape to applet
322*cdf0e10cSrcweir         static const char* aPropertyValues[] =
323*cdf0e10cSrcweir             {
324*cdf0e10cSrcweir                 "AppletCodeBase",
325*cdf0e10cSrcweir                 "AppletName",
326*cdf0e10cSrcweir                 "AppletCode",
327*cdf0e10cSrcweir                 "AppletCommands",
328*cdf0e10cSrcweir                 "AppletIsScript"
329*cdf0e10cSrcweir             };
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir         // (Java)Applet shape. This is a special object
332*cdf0e10cSrcweir         return createAppletShape( xCurrShape,
333*cdf0e10cSrcweir                                   mnAscendingPrio,
334*cdf0e10cSrcweir                                   ::rtl::OUString(
335*cdf0e10cSrcweir                                       RTL_CONSTASCII_USTRINGPARAM(
336*cdf0e10cSrcweir                                           "com.sun.star.comp.sfx2.AppletObject" )),
337*cdf0e10cSrcweir                                   aPropertyValues,
338*cdf0e10cSrcweir                                   sizeof(aPropertyValues)/sizeof(*aPropertyValues),
339*cdf0e10cSrcweir                                   mrContext );
340*cdf0e10cSrcweir     }
341*cdf0e10cSrcweir     else if( shapeType.equalsAsciiL(
342*cdf0e10cSrcweir                  RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.OLE2Shape") ) ||
343*cdf0e10cSrcweir              shapeType.equalsAsciiL(
344*cdf0e10cSrcweir 				RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.OLE2Shape") ) )
345*cdf0e10cSrcweir     {
346*cdf0e10cSrcweir         // #i46224# Mark OLE shapes as foreign content - scan them for
347*cdf0e10cSrcweir         // unsupported actions, and fallback to bitmap, if necessary
348*cdf0e10cSrcweir         return DrawShape::create( xCurrShape,
349*cdf0e10cSrcweir                                   mxPage,
350*cdf0e10cSrcweir                                   mnAscendingPrio,
351*cdf0e10cSrcweir                                   true,
352*cdf0e10cSrcweir                                   mrContext );
353*cdf0e10cSrcweir     }
354*cdf0e10cSrcweir     else if( shapeType.equalsAsciiL(
355*cdf0e10cSrcweir                  RTL_CONSTASCII_STRINGPARAM(
356*cdf0e10cSrcweir                      "com.sun.star.drawing.GraphicObjectShape") ) ||
357*cdf0e10cSrcweir 			 shapeType.equalsAsciiL(
358*cdf0e10cSrcweir                  RTL_CONSTASCII_STRINGPARAM(
359*cdf0e10cSrcweir                      "com.sun.star.presentation.GraphicObjectShape") ) )
360*cdf0e10cSrcweir     {
361*cdf0e10cSrcweir         GraphicObject aGraphicObject;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir         // to get hold of GIF animations, inspect Graphic
364*cdf0e10cSrcweir         // objects more thoroughly (the plain-jane shape
365*cdf0e10cSrcweir         // metafile of course would only contain the first
366*cdf0e10cSrcweir         // animation frame)
367*cdf0e10cSrcweir         if( !importShapeGraphic( aGraphicObject, xPropSet ) )
368*cdf0e10cSrcweir             return ShapeSharedPtr(); // error loading graphic -
369*cdf0e10cSrcweir                                      // #142147# no placeholders in
370*cdf0e10cSrcweir                                      // slideshow
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         if( !aGraphicObject.IsAnimated() )
373*cdf0e10cSrcweir         {
374*cdf0e10cSrcweir             // no animation - simply utilize plain draw shape import
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir             // import shape as bitmap - either its a bitmap
377*cdf0e10cSrcweir             // anyway, or its a metafile, which currently the
378*cdf0e10cSrcweir             // metafile renderer might not display correctly.
379*cdf0e10cSrcweir             return DrawShape::create( xCurrShape,
380*cdf0e10cSrcweir                                       mxPage,
381*cdf0e10cSrcweir                                       mnAscendingPrio,
382*cdf0e10cSrcweir                                       true,
383*cdf0e10cSrcweir                                       mrContext );
384*cdf0e10cSrcweir         }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir         // now extract relevant shape attributes via API
388*cdf0e10cSrcweir         // ---------------------------------------------
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir         drawing::ColorMode eColorMode( drawing::ColorMode_STANDARD );
391*cdf0e10cSrcweir         sal_Int16 nLuminance(0);
392*cdf0e10cSrcweir         sal_Int16 nContrast(0);
393*cdf0e10cSrcweir         sal_Int16 nRed(0);
394*cdf0e10cSrcweir         sal_Int16 nGreen(0);
395*cdf0e10cSrcweir         sal_Int16 nBlue(0);
396*cdf0e10cSrcweir         double    nGamma(1.0);
397*cdf0e10cSrcweir         sal_Int16 nTransparency(0);
398*cdf0e10cSrcweir         sal_Int32 nRotation(0);
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir         getPropertyValue( eColorMode, xPropSet, OUSTR("GraphicColorMode") );
401*cdf0e10cSrcweir         getPropertyValue( nLuminance, xPropSet, OUSTR("AdjustLuminance") );
402*cdf0e10cSrcweir         getPropertyValue( nContrast, xPropSet, OUSTR("AdjustContrast") );
403*cdf0e10cSrcweir         getPropertyValue( nRed, xPropSet, OUSTR("AdjustRed") );
404*cdf0e10cSrcweir         getPropertyValue( nGreen, xPropSet, OUSTR("AdjustGreen") );
405*cdf0e10cSrcweir         getPropertyValue( nBlue, xPropSet, OUSTR("AdjustBlue") );
406*cdf0e10cSrcweir         getPropertyValue( nGamma, xPropSet, OUSTR("Gamma") );
407*cdf0e10cSrcweir         getPropertyValue( nTransparency, xPropSet, OUSTR("Transparency") );
408*cdf0e10cSrcweir         getPropertyValue( nRotation, xPropSet, OUSTR("RotateAngle") );
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir         GraphicAttr aGraphAttrs;
411*cdf0e10cSrcweir         aGraphAttrs.SetDrawMode( (GraphicDrawMode)eColorMode );
412*cdf0e10cSrcweir         aGraphAttrs.SetLuminance( nLuminance );
413*cdf0e10cSrcweir         aGraphAttrs.SetContrast( nContrast );
414*cdf0e10cSrcweir         aGraphAttrs.SetChannelR( nRed );
415*cdf0e10cSrcweir         aGraphAttrs.SetChannelG( nGreen );
416*cdf0e10cSrcweir         aGraphAttrs.SetChannelB( nBlue );
417*cdf0e10cSrcweir         aGraphAttrs.SetGamma( nGamma );
418*cdf0e10cSrcweir         aGraphAttrs.SetTransparency( static_cast<sal_uInt8>(nTransparency) );
419*cdf0e10cSrcweir         aGraphAttrs.SetRotation( static_cast<sal_uInt16>(nRotation*10) );
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir         text::GraphicCrop aGraphCrop;
422*cdf0e10cSrcweir         if( getPropertyValue( aGraphCrop, xPropSet, OUSTR("GraphicCrop") ))
423*cdf0e10cSrcweir         {
424*cdf0e10cSrcweir             aGraphAttrs.SetCrop( aGraphCrop.Left,
425*cdf0e10cSrcweir                                  aGraphCrop.Top,
426*cdf0e10cSrcweir                                  aGraphCrop.Right,
427*cdf0e10cSrcweir                                  aGraphCrop.Bottom );
428*cdf0e10cSrcweir         }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir         // fetch readily transformed and color-modified
431*cdf0e10cSrcweir         // graphic
432*cdf0e10cSrcweir         // ---------------------------------------------
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir         Graphic aGraphic(
435*cdf0e10cSrcweir             aGraphicObject.GetTransformedGraphic(
436*cdf0e10cSrcweir                 aGraphicObject.GetPrefSize(),
437*cdf0e10cSrcweir                 aGraphicObject.GetPrefMapMode(),
438*cdf0e10cSrcweir                 aGraphAttrs ) );
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir         return DrawShape::create( xCurrShape,
441*cdf0e10cSrcweir                                   mxPage,
442*cdf0e10cSrcweir                                   mnAscendingPrio,
443*cdf0e10cSrcweir                                   aGraphic,
444*cdf0e10cSrcweir                                   mrContext );
445*cdf0e10cSrcweir     }
446*cdf0e10cSrcweir     else
447*cdf0e10cSrcweir     {
448*cdf0e10cSrcweir         return DrawShape::create( xCurrShape,
449*cdf0e10cSrcweir                                   mxPage,
450*cdf0e10cSrcweir                                   mnAscendingPrio,
451*cdf0e10cSrcweir                                   false,
452*cdf0e10cSrcweir                                   mrContext );
453*cdf0e10cSrcweir     }
454*cdf0e10cSrcweir }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir bool ShapeImporter::isSkip(
457*cdf0e10cSrcweir     uno::Reference<beans::XPropertySet> const& xPropSet,
458*cdf0e10cSrcweir     rtl::OUString const& shapeType,
459*cdf0e10cSrcweir     uno::Reference< drawing::XLayer> const& xLayer )
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir     // skip empty presentation objects:
462*cdf0e10cSrcweir     bool bEmpty = false;
463*cdf0e10cSrcweir     if( getPropertyValue( bEmpty,
464*cdf0e10cSrcweir                           xPropSet,
465*cdf0e10cSrcweir                           OUSTR("IsEmptyPresentationObject")) &&
466*cdf0e10cSrcweir         bEmpty )
467*cdf0e10cSrcweir     {
468*cdf0e10cSrcweir         return true;
469*cdf0e10cSrcweir     }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir     //skip shapes which corresponds to annotations
472*cdf0e10cSrcweir     if(xLayer.is())
473*cdf0e10cSrcweir     {
474*cdf0e10cSrcweir         rtl::OUString layerName;
475*cdf0e10cSrcweir         uno::Reference<beans::XPropertySet> xPropLayerSet(
476*cdf0e10cSrcweir                                                           xLayer, uno::UNO_QUERY );
477*cdf0e10cSrcweir         const uno::Any& a(xPropLayerSet->getPropertyValue(rtl::OUString::createFromAscii("Name")) );
478*cdf0e10cSrcweir         bool const bRet = (a >>= layerName);
479*cdf0e10cSrcweir         if(bRet)
480*cdf0e10cSrcweir         {
481*cdf0e10cSrcweir             if( layerName.equals(rtl::OUString::createFromAscii("DrawnInSlideshow")))
482*cdf0e10cSrcweir             {
483*cdf0e10cSrcweir                 //Transform shapes into PolyPolygons
484*cdf0e10cSrcweir                 importPolygons(xPropSet);
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir                 return true;
487*cdf0e10cSrcweir             }
488*cdf0e10cSrcweir         }
489*cdf0e10cSrcweir     }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir     // don't export presentation placeholders on masterpage
492*cdf0e10cSrcweir     // they can be non empty when user edits the default texts
493*cdf0e10cSrcweir     if(mbConvertingMasterPage)
494*cdf0e10cSrcweir     {
495*cdf0e10cSrcweir         if(shapeType.equalsAsciiL(
496*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation."
497*cdf0e10cSrcweir                                            "TitleTextShape") ) ||
498*cdf0e10cSrcweir             shapeType.equalsAsciiL(
499*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation."
500*cdf0e10cSrcweir                                            "OutlinerShape") ))
501*cdf0e10cSrcweir         {
502*cdf0e10cSrcweir             return true;
503*cdf0e10cSrcweir         }
504*cdf0e10cSrcweir     }
505*cdf0e10cSrcweir     return false;
506*cdf0e10cSrcweir }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir void ShapeImporter::importPolygons(uno::Reference<beans::XPropertySet> const& xPropSet) {
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir     drawing::PointSequenceSequence aRetval;
512*cdf0e10cSrcweir     sal_Int32			nLineColor=0;
513*cdf0e10cSrcweir     double				fLineWidth;
514*cdf0e10cSrcweir     getPropertyValue( aRetval, xPropSet, OUSTR("PolyPolygon") );
515*cdf0e10cSrcweir     getPropertyValue( nLineColor, xPropSet, OUSTR("LineColor") );
516*cdf0e10cSrcweir     getPropertyValue( fLineWidth, xPropSet, OUSTR("LineWidth") );
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 	drawing::PointSequence* pOuterSequence = aRetval.getArray();
519*cdf0e10cSrcweir 	awt::Point* pInnerSequence = pOuterSequence->getArray();
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 	::basegfx::B2DPolygon aPoly;
522*cdf0e10cSrcweir     basegfx::B2DPoint aPoint;
523*cdf0e10cSrcweir     for( sal_Int32 nCurrPoly=0; nCurrPoly<pOuterSequence->getLength(); ++nCurrPoly, ++pInnerSequence )
524*cdf0e10cSrcweir     {
525*cdf0e10cSrcweir         aPoint.setX((*pInnerSequence).X);
526*cdf0e10cSrcweir         aPoint.setY((*pInnerSequence).Y);
527*cdf0e10cSrcweir         aPoly.append( aPoint );
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir     UnoViewVector::const_iterator aIter=(mrContext.mrViewContainer).begin();
530*cdf0e10cSrcweir     UnoViewVector::const_iterator aEnd=(mrContext.mrViewContainer).end();
531*cdf0e10cSrcweir     while(aIter != aEnd)
532*cdf0e10cSrcweir     {
533*cdf0e10cSrcweir         ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
534*cdf0e10cSrcweir             ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( (*aIter)->getCanvas(),
535*cdf0e10cSrcweir                                                                           aPoly ) );
536*cdf0e10cSrcweir         if( pPolyPoly )
537*cdf0e10cSrcweir         {
538*cdf0e10cSrcweir                 pPolyPoly->setRGBALineColor( unoColor2RGBColor( nLineColor ).getIntegerColor() );
539*cdf0e10cSrcweir                 pPolyPoly->setStrokeWidth(fLineWidth);
540*cdf0e10cSrcweir                 pPolyPoly->draw();
541*cdf0e10cSrcweir                 maPolygons.push_back(pPolyPoly);
542*cdf0e10cSrcweir         }
543*cdf0e10cSrcweir         aIter++;
544*cdf0e10cSrcweir     }
545*cdf0e10cSrcweir }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir ShapeSharedPtr ShapeImporter::importBackgroundShape() // throw (ShapeLoadFailedException)
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir     if( maShapesStack.empty() )
550*cdf0e10cSrcweir         throw ShapeLoadFailedException();
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir     XShapesEntry& rTop = maShapesStack.top();
553*cdf0e10cSrcweir     ShapeSharedPtr pBgShape(
554*cdf0e10cSrcweir         createBackgroundShape(mxPage,
555*cdf0e10cSrcweir                               uno::Reference<drawing::XDrawPage>(
556*cdf0e10cSrcweir                                   rTop.mxShapes,
557*cdf0e10cSrcweir                                   uno::UNO_QUERY_THROW),
558*cdf0e10cSrcweir                               mrContext) );
559*cdf0e10cSrcweir     mnAscendingPrio += 1.0;
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir     return pBgShape;
562*cdf0e10cSrcweir }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir ShapeSharedPtr ShapeImporter::importShape() // throw (ShapeLoadFailedException)
565*cdf0e10cSrcweir {
566*cdf0e10cSrcweir     ShapeSharedPtr pRet;
567*cdf0e10cSrcweir     bool bIsGroupShape = false;
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir     while( !maShapesStack.empty() && !pRet )
570*cdf0e10cSrcweir     {
571*cdf0e10cSrcweir         XShapesEntry& rTop = maShapesStack.top();
572*cdf0e10cSrcweir         if( rTop.mnPos < rTop.mnCount )
573*cdf0e10cSrcweir         {
574*cdf0e10cSrcweir             uno::Reference<drawing::XShape> const xCurrShape(
575*cdf0e10cSrcweir                 rTop.mxShapes->getByIndex( rTop.mnPos ), uno::UNO_QUERY );
576*cdf0e10cSrcweir             ++rTop.mnPos;
577*cdf0e10cSrcweir             uno::Reference<beans::XPropertySet> xPropSet(
578*cdf0e10cSrcweir                 xCurrShape, uno::UNO_QUERY );
579*cdf0e10cSrcweir             if( !xPropSet.is() )
580*cdf0e10cSrcweir             {
581*cdf0e10cSrcweir                 // we definitely need the properties of
582*cdf0e10cSrcweir                 // the shape here. This will also fail,
583*cdf0e10cSrcweir                 // if getByIndex did not return a valid
584*cdf0e10cSrcweir                 // shape
585*cdf0e10cSrcweir                 throw ShapeLoadFailedException();
586*cdf0e10cSrcweir             }
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir             //Retrieve the layer for the current shape
589*cdf0e10cSrcweir             uno::Reference< drawing::XLayer > xDrawnInSlideshow;
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir             uno::Reference< drawing::XLayerSupplier > xLayerSupplier(mxPagesSupplier, uno::UNO_QUERY);
592*cdf0e10cSrcweir 		    if(xLayerSupplier.is())
593*cdf0e10cSrcweir             {
594*cdf0e10cSrcweir                 uno::Reference< container::XNameAccess > xNameAccess = xLayerSupplier->getLayerManager();
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 	    	    uno::Reference< drawing::XLayerManager > xLayerManager(xNameAccess, uno::UNO_QUERY);
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir 		   	    xDrawnInSlideshow = xLayerManager->getLayerForShape(xCurrShape);
599*cdf0e10cSrcweir 		    }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir             rtl::OUString const shapeType( xCurrShape->getShapeType());
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir             // is this shape presentation-invisible?
604*cdf0e10cSrcweir             if( !isSkip(xPropSet, shapeType, xDrawnInSlideshow) )
605*cdf0e10cSrcweir             {
606*cdf0e10cSrcweir                 bIsGroupShape = shapeType.equalsAsciiL(
607*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM(
608*cdf0e10cSrcweir                         "com.sun.star.drawing.GroupShape") );
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir                 if( rTop.mpGroupShape ) // in group particle mode?
611*cdf0e10cSrcweir                 {
612*cdf0e10cSrcweir                     pRet.reset( new ShapeOfGroup(
613*cdf0e10cSrcweir                                     rTop.mpGroupShape /* container shape */,
614*cdf0e10cSrcweir                                     xCurrShape, xPropSet,
615*cdf0e10cSrcweir                                     mnAscendingPrio ) );
616*cdf0e10cSrcweir                 }
617*cdf0e10cSrcweir                 else
618*cdf0e10cSrcweir                 {
619*cdf0e10cSrcweir                     pRet = createShape( xCurrShape, xPropSet, shapeType );
620*cdf0e10cSrcweir                 }
621*cdf0e10cSrcweir                 mnAscendingPrio += 1.0;
622*cdf0e10cSrcweir             }
623*cdf0e10cSrcweir         }
624*cdf0e10cSrcweir         if( rTop.mnPos >= rTop.mnCount )
625*cdf0e10cSrcweir         {
626*cdf0e10cSrcweir             // group or top-level shapes finished:
627*cdf0e10cSrcweir             maShapesStack.pop();
628*cdf0e10cSrcweir         }
629*cdf0e10cSrcweir         if( bIsGroupShape && pRet )
630*cdf0e10cSrcweir         {
631*cdf0e10cSrcweir             // push new group on the stack: group traversal
632*cdf0e10cSrcweir             maShapesStack.push( XShapesEntry( pRet ) );
633*cdf0e10cSrcweir         }
634*cdf0e10cSrcweir     }
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir     return pRet;
637*cdf0e10cSrcweir }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir bool ShapeImporter::isImportDone() const
640*cdf0e10cSrcweir {
641*cdf0e10cSrcweir     return maShapesStack.empty();
642*cdf0e10cSrcweir }
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir PolyPolygonVector ShapeImporter::getPolygons()
645*cdf0e10cSrcweir {
646*cdf0e10cSrcweir     return maPolygons;
647*cdf0e10cSrcweir }
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir ShapeImporter::ShapeImporter( uno::Reference<drawing::XDrawPage> const&          xPage,
650*cdf0e10cSrcweir                               uno::Reference<drawing::XDrawPage> const&          xActualPage,
651*cdf0e10cSrcweir                               uno::Reference<drawing::XDrawPagesSupplier> const& xPagesSupplier,
652*cdf0e10cSrcweir                               const SlideShowContext&                            rContext,
653*cdf0e10cSrcweir                               sal_Int32                                          nOrdNumStart,
654*cdf0e10cSrcweir                               bool                                               bConvertingMasterPage ) :
655*cdf0e10cSrcweir     mxPage( xActualPage ),
656*cdf0e10cSrcweir     mxPagesSupplier( xPagesSupplier ),
657*cdf0e10cSrcweir     mrContext( rContext ),
658*cdf0e10cSrcweir     maPolygons(),
659*cdf0e10cSrcweir     maShapesStack(),
660*cdf0e10cSrcweir     mnAscendingPrio( nOrdNumStart ),
661*cdf0e10cSrcweir     mbConvertingMasterPage( bConvertingMasterPage )
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir     uno::Reference<drawing::XShapes> const xShapes(
664*cdf0e10cSrcweir         xPage, uno::UNO_QUERY_THROW );
665*cdf0e10cSrcweir     maShapesStack.push( XShapesEntry(xShapes) );
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir } // namespace internal
669*cdf0e10cSrcweir } // namespace presentation
670*cdf0e10cSrcweir 
671