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 #ifndef SD_SLIDESORTER_CURRENT_SLIDE_MANAGER_HXX
25 #define SD_SLIDESORTER_CURRENT_SLIDE_MANAGER_HXX
26 
27 #include "model/SlsSharedPageDescriptor.hxx"
28 #include <vcl/timer.hxx>
29 #include <tools/link.hxx>
30 #include <com/sun/star/drawing/XDrawPage.hpp>
31 
32 class SdPage;
33 
34 namespace sd { namespace slidesorter {
35 class SlideSorter;
36 } }
37 
38 
39 namespace sd { namespace slidesorter { namespace controller {
40 
41 /** Manage the current slide.  This includes setting the according flags at
42     the PageDescriptor objects and setting the current slide at the main
43     view shell.
44 
45     Switching pages is triggered only after a little delay.  This allows
46     fast travelling through a larger set of slides without having to wait
47     for the edit view to update its content after every slide change.
48 */
49 class CurrentSlideManager
50 {
51 public:
52     /** Create a new CurrentSlideManager object that manages the current
53         slide for the given SlideSorter.
54     */
55     CurrentSlideManager (SlideSorter& rSlideSorter);
56 
57     ~CurrentSlideManager (void);
58 
59     /** Call this when the current page of the main view shell has been
60         switched.  Use SwitchCurrentSlide() to initiate such a switch.
61     */
62     void NotifyCurrentSlideChange (const sal_Int32 nSlideIndex);
63     void NotifyCurrentSlideChange (const SdPage* pPage);
64 
65     /** Call this method to switch the current page of the main view shell
66         to the given slide.  Use CurrentSlideHasChanged() when the current
67         slide change has been initiated by someone else.
68         @param nSlideIndex
69             Zero based index in the range [0,number-of-slides).
70         @param bUpdateSelection
71             When <TRUE/> then the page selection is cleared and only the new
72             current slide is selected.
73     */
74     void SwitchCurrentSlide (
75         const sal_Int32 nSlideIndex,
76         const bool bUpdateSelection = false);
77     void SwitchCurrentSlide (
78         const model::SharedPageDescriptor& rpSlide,
79         const bool bUpdateSelection = false);
80 
81     /** Return the page descriptor for the current slide.  Note, that when
82         there is no current slide then the returned pointer is empty.
83     */
84     model::SharedPageDescriptor GetCurrentSlide (void);
85 
86     /** Release all references to model data.
87     */
88     void PrepareModelChange (void);
89 
90     /** Modify inner state in reaction to a change of the SlideSorterModel.
91     */
92     void HandleModelChange (void);
93 
94 private:
95     SlideSorter& mrSlideSorter;
96     sal_Int32 mnCurrentSlideIndex;
97     model::SharedPageDescriptor mpCurrentSlide;
98     /** Timer to control the delay after which to ask
99         XController/ViewShellBase to switch to another slide.
100     */
101     Timer maSwitchPageDelayTimer;
102 
103     bool IsCurrentSlideIsValid (void);
104     void SetCurrentSlideAtViewShellBase (const model::SharedPageDescriptor& rpSlide);
105     void SetCurrentSlideAtTabControl (const model::SharedPageDescriptor& rpSlide);
106     void SetCurrentSlideAtXController (const model::SharedPageDescriptor& rpSlide);
107 
108     /** When switching from one slide to a new current slide then this
109         method releases all ties to the old slide.
110     */
111     void ReleaseCurrentSlide (void);
112 
113     /** When switching from one slide to a new current slide then this
114         method connects to the new current slide.
115     */
116     void AcquireCurrentSlide (const sal_Int32 nSlideIndex);
117 
118     DECL_LINK(SwitchPageCallback,void*);
119 };
120 
121 
122 } } } // end of namespace ::sd::slidesorter::controller
123 
124 #endif
125