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 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include "slideshow.hxx"
27 #include "ViewShellBase.hxx"
28 #include <rtl/ref.hxx>
29 #include <tools/link.hxx>
30 #include <boost/enable_shared_from_this.hpp>
31 
32 namespace sd {
33 
34 /** This class is used when a display is removed or added to restart the
35     slide show.  This is necessary at least with DirectX because
36     deactivating a display invalidates DirectX resources.  Accessing those
37     leads to a crash.
38 
39     During a restart a possibly installed presenter extension is given the
40     oportunity to show or hide depending on the number of available displays.
41 */
42 class SlideShowRestarter
43     : public boost::enable_shared_from_this<SlideShowRestarter>
44 {
45 public:
46     /** Create a new SlideShowRestarter object.
47         @param rpSlideShow
48             The slide show is used to determine the current slide, which is
49             restored after the restart, and of course to stop and start the
50             slide show.
51         @param pViewShellBase
52             Used to get access to a slot dispatcher.
53     */
54     SlideShowRestarter (
55         const ::rtl::Reference<SlideShow>& rpSlideShow,
56         ViewShellBase* pViewShellBase);
57     virtual ~SlideShowRestarter (void);
58 
59     /** Restarting the slide show is an asynchronous multi step process
60         which is started by calling this method.
61     */
62     void Restart (void);
63 
64 private:
65     sal_Int32 mnEventId;
66     ::rtl::Reference<SlideShow> mpSlideShow;
67     ViewShellBase* mpViewShellBase;
68     ::boost::shared_ptr<SlideShowRestarter> mpSelf;
69     sal_Int32 mnDisplayCount;
70     SfxDispatcher* mpDispatcher;
71     sal_Int32 mnCurrentSlideNumber;
72 
73     /** The display count is used to determine whether the number of
74         displays has changed and thus whether restarting the slide show is
75         really necessary.
76     */
77     sal_Int32 GetDisplayCount (void);
78 
79     DECL_LINK(EndPresentation, void*);
80 
81     /** Restart the presentation on the slide last shown before the restart
82         was initiated.
83     */
84     void StartPresentation (void);
85 };
86 
87 } // end of namespace sd
88