xref: /trunk/main/sd/source/ui/slideshow/slideshowimpl.hxx (revision 9d97e9635cf537de28a9272394b68cfd2c8f8314)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef _SD_SlideShowImpl_HXX_
23 #define _SD_SlideShowImpl_HXX_
24 
25 #include "sal/config.h"
26 #include "com/sun/star/uno/XComponentContext.hpp"
27 #include "cppuhelper/compbase1.hxx"
28 #include "cppuhelper/compbase2.hxx"
29 #include "cppuhelper/basemutex.hxx"
30 #include "cppuhelper/propertysetmixin.hxx"
31 #include <com/sun/star/awt/XActivateListener.hpp>
32 #include <com/sun/star/presentation/XSlideShow.hpp>
33 #include <com/sun/star/presentation/XSlideShowView.hpp>
34 #include <com/sun/star/presentation/XSlideShowListener.hpp>
35 #include <com/sun/star/presentation/XSlideShowController.hpp>
36 #include "com/sun/star/presentation/XShapeEventListener.hpp"
37 #include <com/sun/star/awt/WindowEvent.hpp>
38 #include <com/sun/star/awt/XWindowListener.hpp>
39 #include <com/sun/star/awt/XWindow.hpp>
40 #include <com/sun/star/awt/XWindowPeer.hpp>
41 #include <com/sun/star/util/XModifyListener.hpp>
42 #include <com/sun/star/awt/XPaintListener.hpp>
43 #include <com/sun/star/awt/XPointer.hpp>
44 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
45 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
46 #include <com/sun/star/presentation/ClickAction.hpp>
47 #include <com/sun/star/media/XManager.hpp>
48 #include <com/sun/star/media/XPlayer.hpp>
49 
50 #include <toolkit/helper/vclunohelper.hxx>
51 
52 #include <basegfx/matrix/b2dhommatrix.hxx>
53 #include <basegfx/tools/canvastools.hxx>
54 #include <vcl/help.hxx>
55 #include <tools/urlobj.hxx>
56 #include <unotools/pathoptions.hxx>
57 #include <unotools/saveopt.hxx>
58 #include <sfx2/bindings.hxx>
59 #include <sfx2/dispatch.hxx>
60 #include <sfx2/viewfrm.hxx>
61 #include <basic/sbstar.hxx>
62 #include <svx/svdpagv.hxx>
63 #include <svx/fmshell.hxx>
64 
65 #ifndef _SVX_SVXIDS_HRC
66 #include <svx/svxids.hrc>
67 #endif
68 #include "sdmod.hxx"
69 #include "cusshow.hxx"
70 #include "ViewShellBase.hxx"
71 #include "PresentationViewShell.hxx"
72 #include "ViewShell.hxx"
73 #include "drawview.hxx"
74 #include "drawdoc.hxx"
75 
76 #include "showwindow.hxx"
77 
78 #include "optsitem.hxx"
79 #include "FrameView.hxx"
80 #include "DrawDocShell.hxx"
81 
82 #ifndef _SD_APP_HRC_
83 #include "app.hrc"
84 #endif
85 
86 #include "slideshow.hxx"
87 
88 class SfxViewFrame;
89 class SfxRequest;
90 
91 namespace css = ::com::sun::star;
92 
93 namespace sd
94 {
95 class SlideShowView;
96 class AnimationSlideController;
97 class PaneHider;
98 
99 // --------------------------------------------------------------------
100 
101 struct PresentationSettingsEx : public PresentationSettings
102 {
103     sal_Bool mbRehearseTimings;
104     sal_Bool mbPreview;
105     ::Window* mpParentWindow;
106     css::uno::Reference< css::drawing::XDrawPage > mxStartPage;
107     css::uno::Reference< css::animations::XAnimationNode > mxAnimationNode;
108 
109     PresentationSettingsEx( const PresentationSettingsEx& );
110     PresentationSettingsEx( PresentationSettings& );
111 
112     void SetArguments( const css::uno::Sequence< css::beans::PropertyValue >& rArguments ) throw (css::lang::IllegalArgumentException);
113 
114     void SetPropertyValue( const ::rtl::OUString& rProperty, const css::uno::Any& rValue ) throw (css::lang::IllegalArgumentException);
115 };
116 
117 // --------------------------------------------------------------------
118 
119 struct WrappedShapeEventImpl
120 {
121     css::presentation::ClickAction meClickAction;
122     sal_Int32 mnVerb;
123     ::rtl::OUString maStrBookmark;
WrappedShapeEventImplsd::WrappedShapeEventImpl124     WrappedShapeEventImpl() : meClickAction( css::presentation::ClickAction_NONE ), mnVerb( 0 ) {};
125 };
126 
127 typedef boost::shared_ptr< WrappedShapeEventImpl > WrappedShapeEventImplPtr;
128 typedef std::map< css::uno::Reference< css::drawing::XShape >, WrappedShapeEventImplPtr > WrappedShapeEventImplMap;
129 
130 // --------------------------------------------------------------------
131 
132 class SlideShowListenerProxy : private ::cppu::BaseMutex,
133         public ::cppu::WeakImplHelper2< css::presentation::XSlideShowListener, css::presentation::XShapeEventListener >
134 {
135 public:
136     SlideShowListenerProxy( const rtl::Reference< SlideshowImpl >& xController, const css::uno::Reference< css::presentation::XSlideShow >& xSlideShow );
137     virtual ~SlideShowListenerProxy();
138 
139     void addAsSlideShowListener();
140     void removeAsSlideShowListener();
141 
142     void addSlideShowListener( const css::uno::Reference< css::presentation::XSlideShowListener >& Listener );
143     void removeSlideShowListener( const css::uno::Reference< css::presentation::XSlideShowListener >& Listener );
144 
145     void addShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape );
146     void removeShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape );
147 
148     // css::animations::XAnimationListener
149     virtual void SAL_CALL beginEvent( const css::uno::Reference< css::animations::XAnimationNode >& Node ) throw (css::uno::RuntimeException);
150     virtual void SAL_CALL endEvent( const css::uno::Reference< css::animations::XAnimationNode >& Node ) throw (css::uno::RuntimeException);
151     virtual void SAL_CALL repeat( const css::uno::Reference< css::animations::XAnimationNode >& Node, ::sal_Int32 Repeat ) throw (css::uno::RuntimeException);
152 
153     // css::presentation::XSlideShowListener:
154     virtual void SAL_CALL paused() throw (css::uno::RuntimeException);
155     virtual void SAL_CALL resumed() throw (css::uno::RuntimeException);
156     virtual void SAL_CALL slideTransitionStarted() throw (css::uno::RuntimeException);
157     virtual void SAL_CALL slideTransitionEnded() throw (css::uno::RuntimeException);
158     virtual void SAL_CALL slideAnimationsEnded() throw (css::uno::RuntimeException);
159     virtual void SAL_CALL slideEnded(sal_Bool bReverse) throw (css::uno::RuntimeException);
160     virtual void SAL_CALL hyperLinkClicked(const ::rtl::OUString & hyperLink) throw (css::uno::RuntimeException);
161 
162     // css::lang::XEventListener:
163     virtual void SAL_CALL disposing(const css::lang::EventObject & Source) throw (css::uno::RuntimeException);
164 
165     // css::presentation::XShapeEventListener:
166     virtual void SAL_CALL click(const css::uno::Reference< css::drawing::XShape > & xShape, const css::awt::MouseEvent & aOriginalEvent) throw (css::uno::RuntimeException);
167 
168     ::cppu::OInterfaceContainerHelper maListeners;
169 
170     rtl::Reference< SlideshowImpl > mxController;
171     css::uno::Reference< css::presentation::XSlideShow > mxSlideShow;
172 };
173 
174 // --------------------------------------------------------------------
175 
176 typedef ::cppu::WeakComponentImplHelper2< css::presentation::XSlideShowController, css::container::XIndexAccess > SlideshowImplBase;
177 
178 class SlideshowImpl : private ::cppu::BaseMutex, public SlideshowImplBase
179 {
180 friend class SlideShow;
181 friend class SlideShowView;
182 
183 public:
184     explicit SlideshowImpl( const css::uno::Reference< css::presentation::XPresentation2 >& xPresentation, ViewShell* pViewSh, ::sd::View* pView, SdDrawDocument* pDoc, ::Window* pParentWindow);
185 
186     // css::presentation::XSlideShowController:
187     virtual ::sal_Bool SAL_CALL getAlwaysOnTop() throw (css::uno::RuntimeException);
188     virtual void SAL_CALL setAlwaysOnTop( ::sal_Bool _alwaysontop ) throw (css::uno::RuntimeException);
189     virtual ::sal_Bool SAL_CALL getMouseVisible() throw (css::uno::RuntimeException);
190     virtual void SAL_CALL setMouseVisible( ::sal_Bool _mousevisible ) throw (css::uno::RuntimeException);
191     virtual ::sal_Bool SAL_CALL getUsePen() throw (css::uno::RuntimeException);
192     virtual void SAL_CALL setUsePen( ::sal_Bool _usepen ) throw (css::uno::RuntimeException);
193     virtual ::sal_Int32 SAL_CALL getPenColor() throw (css::uno::RuntimeException);
194     virtual void SAL_CALL setPenColor( ::sal_Int32 _pencolor ) throw (css::uno::RuntimeException);
195     virtual void SAL_CALL setUseEraser( ::sal_Bool _usepen ) throw (css::uno::RuntimeException);
196     virtual double SAL_CALL getPenWidth() throw (css::uno::RuntimeException);
197     virtual void SAL_CALL setPenWidth( double dStrokeWidth ) throw (css::uno::RuntimeException);
198     virtual void SAL_CALL setEraseAllInk( bool bEraseAllInk ) throw (css::uno::RuntimeException);
199     virtual void SAL_CALL setEraseInk( sal_Int32 nEraseInkSize ) throw (css::uno::RuntimeException);
200     virtual void SAL_CALL setPenMode( bool bSwitchPenMode) throw (css::uno::RuntimeException);
201     virtual void SAL_CALL setEraserMode( bool bSwitchEraserMode ) throw (css::uno::RuntimeException);
202     virtual ::sal_Bool SAL_CALL isRunning(  ) throw (css::uno::RuntimeException);
203     virtual ::sal_Int32 SAL_CALL getSlideCount(  ) throw (css::uno::RuntimeException);
204     virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL getSlideByIndex( ::sal_Int32 Index ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException);
205     virtual void SAL_CALL addSlideShowListener( const css::uno::Reference< css::presentation::XSlideShowListener >& Listener ) throw (css::uno::RuntimeException);
206     virtual void SAL_CALL removeSlideShowListener( const css::uno::Reference< css::presentation::XSlideShowListener >& Listener ) throw (css::uno::RuntimeException);
207     virtual void SAL_CALL gotoNextEffect(  ) throw (css::uno::RuntimeException);
208     virtual void SAL_CALL gotoPreviousEffect(  ) throw (css::uno::RuntimeException);
209     virtual void SAL_CALL gotoFirstSlide(  ) throw (css::uno::RuntimeException);
210     virtual void SAL_CALL gotoNextSlide(  ) throw (css::uno::RuntimeException);
211     virtual void SAL_CALL gotoPreviousSlide(  ) throw (css::uno::RuntimeException);
212     virtual void SAL_CALL gotoLastSlide(  ) throw (css::uno::RuntimeException);
213     virtual void SAL_CALL gotoBookmark( const ::rtl::OUString& Bookmark ) throw (css::uno::RuntimeException);
214     virtual void SAL_CALL gotoSlide( const css::uno::Reference< css::drawing::XDrawPage >& Page ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException);
215     virtual void SAL_CALL gotoSlideIndex( ::sal_Int32 Index ) throw (css::uno::RuntimeException);
216     virtual void SAL_CALL stopSound(  ) throw (css::uno::RuntimeException);
217     virtual void SAL_CALL pause(  ) throw (css::uno::RuntimeException);
218     virtual void SAL_CALL resume(  ) throw (css::uno::RuntimeException);
219     virtual ::sal_Bool SAL_CALL isPaused(  ) throw (css::uno::RuntimeException);
220     virtual void SAL_CALL blankScreen( ::sal_Int32 Color ) throw (css::uno::RuntimeException);
221     virtual void SAL_CALL activate(  ) throw (css::uno::RuntimeException);
222     virtual void SAL_CALL deactivate(  ) throw (css::uno::RuntimeException);
223     virtual ::sal_Bool SAL_CALL isActive(  ) throw (css::uno::RuntimeException);
224     virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL getCurrentSlide(  ) throw (css::uno::RuntimeException);
225     virtual ::sal_Int32 SAL_CALL getCurrentSlideIndex(  ) throw (css::uno::RuntimeException);
226     virtual ::sal_Int32 SAL_CALL getNextSlideIndex(  ) throw (css::uno::RuntimeException);
227     virtual ::sal_Bool SAL_CALL isEndless(  ) throw (css::uno::RuntimeException);
228     virtual ::sal_Bool SAL_CALL isFullScreen(  ) throw (css::uno::RuntimeException);
229     virtual css::uno::Reference< css::presentation::XSlideShow > SAL_CALL getSlideShow(  ) throw (css::uno::RuntimeException);
230 
231     // XIndexAccess
232     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (::com::sun::star::uno::RuntimeException);
233     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
234     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException);
235     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException);
236 
237     // will be called from the SlideShowListenerProxy when this event is fired from the XSlideShow
238     void slideEnded(const bool bReverse);
239     void hyperLinkClicked(const ::rtl::OUString & hyperLink) throw (css::uno::RuntimeException);
240     void click(const css::uno::Reference< css::drawing::XShape > & xShape, const css::awt::MouseEvent & aOriginalEvent);
241 
242     // ends the presentation async
243     void endPresentation();
244 
getViewShell() const245     ViewShell* getViewShell() const { return mpViewShell; }
246 
247     void paint( const Rectangle& rRect );
248     bool keyInput(const KeyEvent& rKEvt);
249     void mouseButtonUp(const MouseEvent& rMEvt);
250 
251 private:
252     SlideshowImpl(SlideshowImpl &); // not defined
253     void operator =(SlideshowImpl &); // not defined
254 
255     virtual ~SlideshowImpl();
256 
257     // overload WeakComponentImplHelperBase::disposing()
258     // This function is called upon disposing the component,
259     // if your component needs special work when it becomes
260     // disposed, do it here.
261     virtual void SAL_CALL disposing();
262 
263     // internal
264     bool startShow( PresentationSettingsEx* pPresSettings );
265     bool startPreview(
266         const css::uno::Reference< css::drawing::XDrawPage >& xDrawPage,
267         const css::uno::Reference< css::animations::XAnimationNode >& xAnimationNode,
268         ::Window* pParent );
269 
getShowWindow() const270     ShowWindow* getShowWindow() const { return mpShowWindow; }
271 
272         /** forces an async call to update in the main thread */
273     void startUpdateTimer();
274 
275     double update();
276 
277     void createSlideList( bool bAll, bool bStartWithActualSlide, const String& rPresSlide );
278 
279     void displayCurrentSlide (const bool bSkipAllMainSequenceEffects = false);
280 
281     void displaySlideNumber( sal_Int32 nSlide );
282     void displaySlideIndex( sal_Int32 nIndex );
283     sal_Int32 getCurrentSlideNumber();
284     sal_Int32 getFirstSlideNumber();
285     sal_Int32 getLastSlideNumber();
isInputFreezed() const286     inline bool isInputFreezed() const { return mbInputFreeze; }
287 
288     void jumpToBookmark( const String& sBookmark );
289 
290     void hideChildWindows();
291     void showChildWindows();
292 
293     void resize( const Size& rSize );
294 
295     void setActiveXToolbarsVisible( sal_Bool bVisible );
296 
297     DECL_LINK( updateHdl, Timer* );
298     DECL_LINK( PostYieldListener, void* );
299     DECL_LINK( ReadyForNextInputHdl, Timer* );
300     DECL_LINK( endPresentationHdl, void* );
301     DECL_LINK( ContextMenuSelectHdl, Menu * );
302     DECL_LINK( ContextMenuHdl, void* );
303     DECL_LINK( deactivateHdl, Timer* );
304     DECL_LINK( EventListenerHdl, VclSimpleEvent* );
305 
306     // helper
307     void receiveRequest(SfxRequest& rReq);
308 
309     /** called only by the slideshow view when the first paint event occurs.
310         This actually starts the slideshow. */
311     void onFirstPaint();
312 
getRestoreSlide() const313     long getRestoreSlide() const { return mnRestoreSlide; }
314 
315 private:
316     bool startShowImpl(
317         const css::uno::Sequence< css::beans::PropertyValue >& aProperties );
318 
319     SfxViewFrame* getViewFrame() const;
320     SfxDispatcher* getDispatcher() const;
321     SfxBindings* getBindings() const;
322 
323     sal_Int32 getSlideNumberForBookmark( const rtl::OUString& rStrBookmark );
324 
325     void removeShapeEvents();
326     void registerShapeEvents( sal_Int32 nSlideNumber );
327     void registerShapeEvents( css::uno::Reference< css::drawing::XShapes >& xShapes ) throw (css::uno::Exception);
328 
329     css::uno::Reference< css::presentation::XSlideShow > createSlideShow() const;
330 
331     void setAutoSaveState( bool bOn );
332     void gotoPreviousSlide (const bool bSkipAllMainSequenceEffects);
333 
334     /** Called by PostYieldListener and updateHdl handlers this method is
335         responsible to call the slideshow update() method and, depending on
336         its return value, wait for a certain amount of time before another
337         call to update() is scheduled.
338     */
339     sal_Int32 updateSlideShow (void);
340 
341     css::uno::Reference< css::presentation::XSlideShow > mxShow;
342     comphelper::ImplementationReference< ::sd::SlideShowView, css::presentation::XSlideShowView > mxView;
343     css::uno::Reference< css::frame::XModel > mxModel;
344 
345     Timer maUpdateTimer;
346     Timer maInputFreezeTimer;
347     Timer maDeactivateTimer;
348 
349     ::sd::View* mpView;
350     ViewShell* mpViewShell;
351     DrawDocShell* mpDocSh;
352     SdDrawDocument* mpDoc;
353 
354     SfxItemSet*     mpNewAttr;
355     ::Window*       mpParentWindow;
356     ShowWindow*     mpShowWindow;
357     PushButton*     mpTimeButton;
358 
359     boost::shared_ptr< AnimationSlideController > mpSlideController;
360 
361     long            mnRestoreSlide;
362     Point           maSlideOrigin;
363     Point           maPopupMousePos;
364     Size            maSlideSize;
365     Size            maPresSize;
366     AnimationMode   meAnimationMode;
367     String          maCharBuffer;
368     Pointer         maOldPointer;
369     Pointer         maPencil;
370     std::vector< ::sd::Window* > maDrawModeWindows;
371     ::sd::Window*   mpOldActiveWindow;
372     Link            maStarBASICGlobalErrorHdl;
373     unsigned long   mnChildMask;
374     bool            mbGridVisible;
375     bool            mbBordVisible;
376     bool            mbSlideBorderVisible;
377     bool            mbSetOnlineSpelling;
378     bool            mbDisposed;
379     bool            mbMouseIsDrawing;
380     bool            mbAutoSaveWasOn;
381     bool            mbRehearseTimings;
382     bool            mbDesignMode;
383     bool            mbIsPaused;
384     bool            mbWasPaused; // used to cache pause state during context menu
385     bool            mbInputFreeze;
386     sal_Bool        mbActive;
387 
388     PresentationSettings maPresSettings;
389     sal_Int32       mnUserPaintColor;
390 
391     bool            mbUsePen;
392     double          mdUserPaintStrokeWidth;
393 
394     // used in updateHdl to prevent recursive calls
395     sal_Int32       mnEntryCounter;
396 
397     sal_Int32       mnLastSlideNumber;
398     WrappedShapeEventImplMap    maShapeEventMap;
399 
400     ::rtl::OUString msOnClick;
401     ::rtl::OUString msBookmark;
402     ::rtl::OUString msVerb;
403 
404     css::uno::Reference< css::drawing::XDrawPage > mxPreviewDrawPage;
405     css::uno::Reference< css::animations::XAnimationNode > mxPreviewAnimationNode;
406 
407     css::uno::Reference< css::media::XPlayer > mxPlayer;
408 
409     ::std::auto_ptr<PaneHider> mpPaneHider;
410 
411     sal_uLong   mnEndShowEvent;
412     sal_uLong   mnContextMenuEvent;
413     sal_Int32 mnUpdateEvent;
414 
415     css::uno::Reference< css::presentation::XPresentation2 > mxPresentation;
416     ::rtl::Reference< SlideShowListenerProxy > mxListenerProxy;
417 };
418 
419 } // namespace ::sd
420 
421 #endif
422 
423 /* vim: set noet sw=4 ts=4: */
424