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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_slideshow.hxx"
30 
31 // must be first
32 #include <canvas/debug.hxx>
33 #include <tools/diagnose_ex.h>
34 #include <canvas/verbosetrace.hxx>
35 
36 #include <comphelper/anytostring.hxx>
37 #include <cppuhelper/exc_hlp.hxx>
38 
39 #include "externalshapebase.hxx"
40 #include "eventmultiplexer.hxx"
41 #include "vieweventhandler.hxx"
42 #include "intrinsicanimationeventhandler.hxx"
43 #include "tools.hxx"
44 
45 #include <boost/noncopyable.hpp>
46 
47 
48 using namespace ::com::sun::star;
49 
50 
51 namespace slideshow
52 {
53     namespace internal
54     {
55         class ExternalShapeBase::ExternalShapeBaseListener : public ViewEventHandler,
56                                                              public IntrinsicAnimationEventHandler,
57                                                              private boost::noncopyable
58         {
59         public:
60             explicit ExternalShapeBaseListener( ExternalShapeBase& rBase ) :
61                 mrBase( rBase )
62             {}
63 
64 
65         private:
66             // ViewEventHandler
67             // -------------------------------------------------
68 
69             virtual void viewAdded( const UnoViewSharedPtr& ) {}
70             virtual void viewRemoved( const UnoViewSharedPtr& ) {}
71             virtual void viewChanged( const UnoViewSharedPtr& rView )
72             {
73                 mrBase.implViewChanged(rView);
74             }
75             virtual void viewsChanged()
76             {
77                 mrBase.implViewsChanged();
78             }
79 
80 
81             // IntrinsicAnimationEventHandler
82             // -------------------------------------------------
83 
84             virtual bool enableAnimations()
85             {
86                 return mrBase.implStartIntrinsicAnimation();
87             }
88             virtual bool disableAnimations()
89             {
90                 return mrBase.implEndIntrinsicAnimation();
91             }
92 
93             ExternalShapeBase& mrBase;
94         };
95 
96 
97         ExternalShapeBase::ExternalShapeBase( const uno::Reference< drawing::XShape >& 	xShape,
98                                               double									nPrio,
99                                               const SlideShowContext&                   rContext ) :
100             mxComponentContext( rContext.mxComponentContext ),
101             mxShape( xShape ),
102             mpListener( new ExternalShapeBaseListener(*this) ),
103             mpShapeManager( rContext.mpSubsettableShapeManager ),
104             mrEventMultiplexer( rContext.mrEventMultiplexer ),
105             mnPriority( nPrio ), // TODO(F1): When ZOrder someday becomes usable: make this ( getAPIShapePrio( xShape ) ),
106             maBounds( getAPIShapeBounds( xShape ) )
107         {
108             ENSURE_OR_THROW( mxShape.is(), "ExternalShapeBase::ExternalShapeBase(): Invalid XShape" );
109 
110             mpShapeManager->addIntrinsicAnimationHandler( mpListener );
111             mrEventMultiplexer.addViewHandler( mpListener );
112         }
113 
114 		// ---------------------------------------------------------------------
115 
116         ExternalShapeBase::~ExternalShapeBase()
117         {
118             try
119             {
120                 mrEventMultiplexer.removeViewHandler( mpListener );
121                 mpShapeManager->removeIntrinsicAnimationHandler( mpListener );
122             }
123             catch (uno::Exception &)
124             {
125                 OSL_ENSURE( false, rtl::OUStringToOString(
126                                 comphelper::anyToString(
127                                     cppu::getCaughtException() ),
128                                 RTL_TEXTENCODING_UTF8 ).getStr() );
129             }
130         }
131 
132 		// ---------------------------------------------------------------------
133 
134         uno::Reference< drawing::XShape > ExternalShapeBase::getXShape() const
135         {
136             return mxShape;
137         }
138 
139 		// ---------------------------------------------------------------------
140 
141         void ExternalShapeBase::play()
142         {
143             implStartIntrinsicAnimation();
144         }
145 
146 		// ---------------------------------------------------------------------
147 
148         void ExternalShapeBase::stop()
149         {
150             implEndIntrinsicAnimation();
151         }
152 
153 		// ---------------------------------------------------------------------
154 
155         void ExternalShapeBase::pause()
156         {
157             implPauseIntrinsicAnimation();
158         }
159 
160 		// ---------------------------------------------------------------------
161 
162         bool ExternalShapeBase::isPlaying() const
163         {
164             return implIsIntrinsicAnimationPlaying();
165         }
166 
167 		// ---------------------------------------------------------------------
168 
169         void ExternalShapeBase::setMediaTime(double fTime)
170         {
171             implSetIntrinsicAnimationTime(fTime);
172         }
173 
174 		// ---------------------------------------------------------------------
175 
176         bool ExternalShapeBase::update() const
177         {
178 			return render();
179         }
180 
181 		// ---------------------------------------------------------------------
182 
183         bool ExternalShapeBase::render() const
184         {
185             if( maBounds.getRange().equalZero() )
186             {
187                 // zero-sized shapes are effectively invisible,
188                 // thus, we save us the rendering...
189                 return true;
190             }
191 
192             return implRender( maBounds );
193         }
194 
195 		// ---------------------------------------------------------------------
196 
197         bool ExternalShapeBase::isContentChanged() const
198 		{
199 			return true;
200         }
201 
202 		// ---------------------------------------------------------------------
203 
204         ::basegfx::B2DRectangle ExternalShapeBase::getBounds() const
205         {
206         	return maBounds;
207         }
208 
209 		// ---------------------------------------------------------------------
210 
211         ::basegfx::B2DRectangle ExternalShapeBase::getDomBounds() const
212         {
213             return maBounds;
214         }
215 
216 		// ---------------------------------------------------------------------
217 
218         ::basegfx::B2DRectangle ExternalShapeBase::getUpdateArea() const
219         {
220             return maBounds;
221         }
222 
223 		// ---------------------------------------------------------------------
224 
225         bool ExternalShapeBase::isVisible() const
226 		{
227 			return true;
228 		}
229 
230 		// ---------------------------------------------------------------------
231 
232         double ExternalShapeBase::getPriority() const
233         {
234             return mnPriority;
235         }
236 
237 		// ---------------------------------------------------------------------
238 
239         bool ExternalShapeBase::isBackgroundDetached() const
240         {
241             // external shapes always have their own window/surface
242 			return true;
243         }
244 
245     }
246 }
247