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_CONTROLLER_SELECTION_MANAGER_HXX
25 #define SD_SLIDESORTER_CONTROLLER_SELECTION_MANAGER_HXX
26 
27 #include "model/SlsSharedPageDescriptor.hxx"
28 #include "controller/SlsAnimator.hxx"
29 #include <sal/types.h>
30 #include <tools/gen.hxx>
31 #include <basegfx/range/b2irectangle.hxx>
32 #include <vector>
33 
34 class Link;
35 class SdPage;
36 
37 namespace sd { namespace slidesorter {
38 class SlideSorter;
39 } }
40 
41 namespace sd { namespace slidesorter { namespace controller {
42 
43 class SlideSorterController;
44 class SelectionObserver;
45 
46 /** This class is a part of the controller and handles the selection of
47     slides.
48     <p>It has methods to modify the selected slides (delete them or
49     move them to other places in the document), change the visible area so
50     to make the selected slides visible, tell listeners when the selection
51     changes.</p>
52 */
53 class SelectionManager
54 {
55 public:
56     /** Create a new SelectionManger for the given slide sorter.
57     */
58     SelectionManager (SlideSorter& rSlideSorter);
59 
60     ~SelectionManager (void);
61 
62     /** Delete the currently selected slides.  When this method returns the
63         selection is empty.
64         @param bSelectFollowingPage
65             When <TRUE/> then after deleting the selected pages make the
66             slide after the last selected page the new current page.
67             When <FALSE/> then make the first slide before the selected
68             pages the new current slide.
69     */
70     void DeleteSelectedPages (const bool bSelectFollowingPage = true);
71 
72     /** Call this method after the selection has changed (possible several
73         calls to the PageSelector) to invalidate the relevant slots and send
74         appropriate events.
75     */
76     void SelectionHasChanged (const bool bMakeSelectionVisible = true);
77 
78     /** Add a listener that is called when the selection of the slide sorter
79         changes.
80         @param rListener
81             When this method is called multiple times for the same listener
82             the second and all following calls are ignored.  Each listener
83             is added only once.
84     */
85     void AddSelectionChangeListener (const Link& rListener);
86 
87     /** Remove a listener that was called when the selection of the slide
88         sorter changes.
89         @param rListener
90             It is save to pass a listener that was not added are has been
91             removed previously.  Such calls are ignored.
92     */
93     void RemoveSelectionChangeListener (const Link& rListener);
94 
95     /** Return the position where to insert pasted slides based on the
96         current selection.  When there is a selection then the insert
97         position is behind the last slide.  When the selection is empty then
98         most of the time the insert position is at the end of the document.
99         There is an exception right after the display of a popup-menu.  The
100         position of the associated insertion marker is stored here and reset
101         the next time the selection changes.
102     */
103     sal_Int32 GetInsertionPosition (void) const;
104 
105     /** Store an insertion position temporarily.  It is reset when the
106         selection changes the next time.
107     */
108     void SetInsertionPosition (const sal_Int32 nInsertionPosition);
109 
110     ::boost::shared_ptr<SelectionObserver> GetSelectionObserver (void) const;
111 
112 private:
113     SlideSorter& mrSlideSorter;
114     SlideSorterController& mrController;
115 
116     ::std::vector<Link> maSelectionChangeListeners;
117 
118     /** This array stores the indices of the  selected page descriptors at
119         the time when the edit mode is switched to EM_MASTERPAGE.  With this
120         we can restore the selection when switching back to EM_PAGE mode.
121     */
122     ::std::vector<SdPage*> maSelectionBeforeSwitch;
123 
124     /** When this flag is set then on the next call to Paint() the selection
125         is moved into the visible area.
126     */
127     bool mbIsMakeSelectionVisiblePending;
128 
129     /** The insertion position is only temporarily valid.  Negative values
130         indicate that the explicit insertion position is not valid.  In this
131         case GetInsertionPosition() calculates it from the current selection.
132     */
133     sal_Int32 mnInsertionPosition;
134 
135     /** Animation id for a scroll animation the will eventually set the top
136         and left of the visible area to maRequestedTopLeft.
137     */
138     Animator::AnimationId mnAnimationId;
139     Point maRequestedTopLeft;
140 
141     class PageInsertionListener;
142     ::boost::scoped_ptr<PageInsertionListener> mpPageInsertionListener;
143 
144     ::boost::shared_ptr<SelectionObserver> mpSelectionObserver;
145 
146     /** Delete the given list of normal pages.  This method is a helper
147         function for DeleteSelectedPages().
148         @param rSelectedNormalPages
149             A list of normal pages.  Supplying master pages is an error.
150     */
151     void DeleteSelectedNormalPages (const ::std::vector<SdPage*>& rSelectedNormalPages);
152 
153     /** Delete the given list of master pages.  This method is a helper
154         function for DeleteSelectedPages().
155         @param rSelectedMasterPages
156             A list of master pages.  Supplying normal pages is an error.
157     */
158     void DeleteSelectedMasterPages (const ::std::vector<SdPage*>& rSelectedMasterPages);
159 };
160 
161 } } } // end of namespace ::sd::slidesorter::controller
162 
163 #endif
164