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_SLIDE_SORTER_CONTROLLER_HXX
25 #define SD_SLIDESORTER_SLIDE_SORTER_CONTROLLER_HXX
26 
27 #include "model/SlsSharedPageDescriptor.hxx"
28 #include "ViewShell.hxx"
29 
30 #include <com/sun/star/drawing/XDrawPages.hpp>
31 
32 #include <sfx2/shell.hxx>
33 #include <sfx2/viewfac.hxx>
34 #include <tools/link.hxx>
35 #include <tools/gen.hxx>
36 #include <comphelper/implementationreference.hxx>
37 
38 namespace sd { namespace slidesorter {
39 class SlideSorter;
40 } }
41 
42 namespace sd { namespace slidesorter { namespace view {
43 class SlideSorterView;
44 class HighlightObject;
45 } } }
46 
47 namespace sd { namespace slidesorter { namespace model {
48 class SlideSorterModel;
49 } } }
50 
51 namespace css = ::com::sun::star;
52 
53 namespace sd { namespace slidesorter { namespace controller {
54 
55 class Animator;
56 class Clipboard;
57 class CurrentSlideManager;
58 class FocusManager;
59 class InsertionIndicatorHandler;
60 class Listener;
61 class PageSelector;
62 class ScrollBarManager;
63 class SelectionFunction;
64 class SelectionManager;
65 class SelectionObserver;
66 class SlotManager;
67 class VisibleAreaManager;
68 
69 class SlideSorterController
70 {
71 public:
72     /** Create a new controller for the slide sorter.
73         @param pParentWindow
74             The window that contains the controls of the new
75             controller.
76     */
77     SlideSorterController (SlideSorter& rSlideSorter);
78 
79     /** Late initialization.  Call this method once a new new object has been
80         created.
81     */
82     virtual void Init (void);
83 
84     virtual ~SlideSorterController (void);
85 
86     void Dispose (void);
87 
88     /** Place and size the scroll bars and the browser window so that the
89         given rectangle is filled.
90         @return
91             The space occupied by the browser window is returned.
92     */
93     Rectangle Resize (const Rectangle& rAvailableSpace);
94 
95     /** Determine which of the UI elements--the scroll bars, the scroll bar
96         filler, the actual slide sorter view--are visible and place them in
97         the area last passed to Resize().
98         @param bForce
99             When <TRUE/> is given (<FALSE/> is the default) then the content
100             window and with it the SlideSorterView is resized event when its
101             size does not change (the size does change when the visibility
102             of scroll bars changes.)
103         @return
104             Returns the space occupied by the browser window.
105     */
106     Rectangle Rearrange (bool bForce = false);
107 
108     /** Return the descriptor of the page that is rendered under the
109         given position.  This takes the IsOnlyPreviewTriggersMouseOver
110         property into account.
111         @return
112             Returns a pointer to a page descriptor instead of a
113             reference because when no page is found at the position
114             then NULL is returned to indicate this.
115     */
116     model::SharedPageDescriptor GetPageAt (const Point& rPixelPosition);
117 
118     PageSelector& GetPageSelector (void);
119     FocusManager& GetFocusManager (void);
120     controller::Clipboard& GetClipboard (void);
121 
122     /** Return the object that manages the scroll bars.
123     */
124     ScrollBarManager& GetScrollBarManager (void);
125 
126     ::boost::shared_ptr<CurrentSlideManager> GetCurrentSlideManager (void) const;
127     ::boost::shared_ptr<SlotManager> GetSlotManager (void) const;
128     ::boost::shared_ptr<SelectionManager> GetSelectionManager (void) const;
129     ::boost::shared_ptr<InsertionIndicatorHandler> GetInsertionIndicatorHandler (void) const;
130 
131     /** This method forwards the call to the SlideSorterView and executes
132         pending operations like moving selected pages into the visible area.
133     */
134     void Paint (const Rectangle& rRect, ::Window* pWin);
135 
136 	void FuTemporary (SfxRequest& rRequest);
137 	void FuPermanent (SfxRequest& rRequest);
138 	void FuSupport (SfxRequest& rRequest);
139     bool Command (
140         const CommandEvent& rEvent,
141         ::sd::Window* pWindow);
142 
143 	void GetCtrlState (SfxItemSet &rSet);
144 	void GetStatusBarState (SfxItemSet& rSet);
145 
146 	void ExecCtrl (SfxRequest& rRequest);
147 	void GetAttrState (SfxItemSet& rSet);
148 	void ExecStatusBar (SfxRequest& rRequest);
149 
150     bool IsLocked (void) const;
151 
152     /** Create an object of this inner class to prevent updates due to model
153         changes.
154     */
155     class ModelChangeLock
156     {public:
157         ModelChangeLock (SlideSorterController& rController);
158         ~ModelChangeLock (void);
159         void Release (void);
160     private:
161         SlideSorterController* mpController;
162     };
163     friend class ModelChangeLock;
164 
165 
166     /** Handle a change of the model, that is, handle the removal and
167         insertion of whole pages or a change of the edit mode.
168 
169         This method is a convenience function that simply calls
170         PreModelChange() and then PostModelChange().
171     */
172     void HandleModelChange (void);
173 
174     DECL_LINK(WindowEventHandler, VclWindowEvent*);
175 
176     /** Update the display of all pages.  This involves a redraw and
177         releasing previews and caches.
178     */
179     void UpdateAllPages (void);
180 
181     /** This factory method creates a selection function.
182     */
183     virtual FunctionReference CreateSelectionFunction (SfxRequest& rRequest);
184 
185     /** When the current function of the view shell is the slide sorter
186         selection function then return a reference to it.  Otherwise return
187         an empty reference.
188     */
189     ::rtl::Reference<SelectionFunction> GetCurrentSelectionFunction (void);
190 
191     /** Prepare for a change of the edit mode.  Depending on the current
192         edit mode we may save the selection so that it can be restored when
193         later changing back to the current edit mode.
194     */
195     void PrepareEditModeChange (void);
196 
197     /** Set a new edit mode and return whether the edit mode really
198         has been changed.  For proper saving and restoring of the selection
199         this method should be called between calls to
200         PrepareEditModeChange() and FinishEditModeChange().
201         @return
202             A return value of <TRUE/> indicates that the edit mode has
203             changed.
204     */
205     bool ChangeEditMode (EditMode eEditMode);
206 
207     /** Finish the change of the edit mode.  Here we may select a page or
208         restore a previously saved selection.
209     */
210     void FinishEditModeChange (void);
211 
212     /** Call this method when the name of one of the pages has changed.
213         This is then notified to the accessibility object, when that exists.
214         @param nPageIndex
215             The index of the page whose name has been changed.
216         @param rsOldName
217             The old name of the page.  The new name can be taken from the
218             page object.
219     */
220     void PageNameHasChanged (int nPageIndex, const String& rsOldName);
221 
222     /** Return whether a context menu has been opened by the called
223         SlideSorterController object and is still open.
224     */
225     bool IsContextMenuOpen (void) const;
226 
227     /** Provide the set of pages to be displayed in the slide sorter.  The
228         GetDocumentSlides() method can be found only in the SlideSorterModel.
229     */
230     void SetDocumentSlides (const css::uno::Reference<css::container::XIndexAccess>& rxSlides);
231 
232     /** Return an Animator object.
233     */
234     ::boost::shared_ptr<Animator> GetAnimator (void) const;
235 
236     VisibleAreaManager& GetVisibleAreaManager (void) const;
237 
238     void CheckForMasterPageAssignment (void);
239     void CheckForSlideTransitionAssignment (void);
240 
241 private:
242     SlideSorter& mrSlideSorter;
243     model::SlideSorterModel& mrModel;
244     view::SlideSorterView& mrView;
245     ::boost::scoped_ptr<PageSelector> mpPageSelector;
246     ::boost::scoped_ptr<FocusManager> mpFocusManager;
247     ::boost::shared_ptr<SlotManager> mpSlotManager;
248     ::boost::scoped_ptr<controller::Clipboard> mpClipboard;
249     ::boost::scoped_ptr<ScrollBarManager> mpScrollBarManager;
250     mutable ::boost::shared_ptr<CurrentSlideManager> mpCurrentSlideManager;
251     ::boost::shared_ptr<SelectionManager> mpSelectionManager;
252     ::boost::shared_ptr<InsertionIndicatorHandler> mpInsertionIndicatorHandler;
253     ::boost::shared_ptr<Animator> mpAnimator;
254     ::boost::scoped_ptr<VisibleAreaManager> mpVisibleAreaManager;
255 
256     // The listener listens to UNO events and thus is a UNO object.
257     // For proper life time management and at the same time free access to
258     // the implementation object we use the ImplementationReference class.
259     ::rtl::Reference<controller::Listener> mpListener;
260 
261     int mnModelChangeLockCount;
262     bool mbIsForcedRearrangePending;
263 
264     bool mbPreModelChangeDone;
265     bool mbPostModelChangePending;
266 
267     ::std::vector<Link> maSelectionChangeListeners;
268 
269     /** This array stores the indices of the  selected page descriptors at
270         the time when the edit mode is switched to EM_MASTERPAGE.  With this
271         we can restore the selection when switching back to EM_PAGE mode.
272     */
273     ::std::vector<SdPage*> maSelectionBeforeSwitch;
274     /// The current page before the edit mode is switched to EM_MASTERPAGE.
275     int mnCurrentPageBeforeSwitch;
276 
277     /** The master page to select after the edit mode is changed.  This
278         member is used to pass the pointer from PrepareEditModeChange() to
279         FinishEditModeChange().
280     */
281     SdPage* mpEditModeChangeMasterPage;
282 
283     /** This rectangle in the parent window encloses scroll bars and slide
284         sorter window.  It is set when Resize() is called.
285     */
286     Rectangle maTotalWindowArea;
287 
288     /** This counter is used to avoid processing of reentrant calls to
289         Paint().
290     */
291     sal_Int32 mnPaintEntranceCount;
292 
293     /** Remember whether the context menu is open.
294     */
295     bool mbIsContextMenuOpen;
296 
297     /** Delete the given list of normal pages.  This method is a helper
298         function for DeleteSelectedPages().
299         @param rSelectedNormalPages
300             A list of normal pages.  Supplying master pages is an error.
301     */
302     void DeleteSelectedNormalPages (const ::std::vector<SdPage*>& rSelectedNormalPages);
303 
304     /** Delete the given list of master pages.  This method is a helper
305         function for DeleteSelectedPages().
306         @param rSelectedMasterPages
307             A list of master pages.  Supplying normal pages is an error.
308     */
309     void DeleteSelectedMasterPages (const ::std::vector<SdPage*>& rSelectedMasterPages);
310 
311     /** Prepare for several model changes, i.e. prevent time-consuming and
312         non-critical operations like repaints until UnlockModelChange() is
313         called.  Critical operations like releasing references to pages that
314         do not exist anymore are executed.
315     */
316     void LockModelChange (void);
317 
318     /** Further calls to HandleModelChange() will result in a full featured
319         update of model, view, and controller.  When HandleModelChange() has
320         been called since the last LockModelChange() then this is done right
321         away to bring the view up-to-date.
322     */
323     void UnlockModelChange (void);
324 
325     /** Prepare for a model change.  This method does all the things that
326         need to be done _before_ the model changes, e.g. because they need
327         access to the model data before the change.
328     */
329     void PreModelChange (void);
330 
331     /** Complete a model change.  This includes the recreation of data
332         structures that depend on the model and the request for a repaint to
333         show the changes.
334     */
335     void PostModelChange (void);
336 };
337 
338 } } } // end of namespace ::sd::slidesorter::controller
339 
340 #endif
341