1c45d927aSAndrew Rist /**************************************************************
2*916729d0Smseidel  *
3c45d927aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c45d927aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c45d927aSAndrew Rist  * distributed with this work for additional information
6c45d927aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c45d927aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c45d927aSAndrew Rist  * "License"); you may not use this file except in compliance
9c45d927aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*916729d0Smseidel  *
11c45d927aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*916729d0Smseidel  *
13c45d927aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c45d927aSAndrew Rist  * software distributed under the License is distributed on an
15c45d927aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c45d927aSAndrew Rist  * KIND, either express or implied.  See the License for the
17c45d927aSAndrew Rist  * specific language governing permissions and limitations
18c45d927aSAndrew Rist  * under the License.
19*916729d0Smseidel  *
20c45d927aSAndrew Rist  *************************************************************/
21c45d927aSAndrew Rist 
22c45d927aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SD_SLIDESORTER_PAGE_SELECTOR_HXX
25cdf0e10cSrcweir #define SD_SLIDESORTER_PAGE_SELECTOR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "model/SlsSharedPageDescriptor.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
30cdf0e10cSrcweir #include <vector>
31cdf0e10cSrcweir #include <memory>
3212f6b488SPedro Giffuni #include <boost/noncopyable.hpp>
3312f6b488SPedro Giffuni 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir class SdPage;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace sd { namespace slidesorter {
38cdf0e10cSrcweir class SlideSorter;
39cdf0e10cSrcweir } }
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace model {
42cdf0e10cSrcweir class SlideSorterModel;
43cdf0e10cSrcweir } } }
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace view {
46cdf0e10cSrcweir class SlideSorterView;
47cdf0e10cSrcweir } } }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace controller {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir class SlideSorterController;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir /** A sub-controller that handles page selection of the slide browser.
55cdf0e10cSrcweir     Selecting a page does not make it the current page (of the main view)
56cdf0e10cSrcweir     automatically as this would not be desired in a multi selection.  This
57cdf0e10cSrcweir     has to be done explicitly by calling the
58cdf0e10cSrcweir     CurrentSlideManager::SetCurrentSlide() method.
59cdf0e10cSrcweir 
6030acf5e8Spfg     Indices of pages relate always to the number of all pages in the model
61cdf0e10cSrcweir     (as returned by GetPageCount()) not just the selected pages.
62cdf0e10cSrcweir */
6312f6b488SPedro Giffuni class PageSelector : private ::boost::noncopyable
64cdf0e10cSrcweir {
65cdf0e10cSrcweir public:
66cdf0e10cSrcweir     PageSelector (SlideSorter& rSlideSorter);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     void SelectAllPages (void);
69cdf0e10cSrcweir     void DeselectAllPages (void);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     /** Update the selection state of all page descriptors to be the same as
72cdf0e10cSrcweir         that of the corresponding pages of the SdPage objects and issue
73cdf0e10cSrcweir         redraw requests where necessary.
74cdf0e10cSrcweir     */
75cdf0e10cSrcweir     void GetCoreSelection (void);
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /** Update the selection state of the SdPage objects to be the same as
78*916729d0Smseidel         that of the corresponding page descriptors.
79cdf0e10cSrcweir     */
80cdf0e10cSrcweir     void SetCoreSelection (void);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /** Select the specified descriptor.  The selection state of the other
83cdf0e10cSrcweir         descriptors is not affected.
84cdf0e10cSrcweir     */
85cdf0e10cSrcweir     void SelectPage (int nPageIndex);
86cdf0e10cSrcweir     /** Select the descriptor that is associated with the given page.  The
87cdf0e10cSrcweir         selection state of the other descriptors is not affected.
88cdf0e10cSrcweir     */
89cdf0e10cSrcweir     void SelectPage (const SdPage* pPage);
90cdf0e10cSrcweir     /** Select the specified descriptor.  The selection state of the other
91cdf0e10cSrcweir         descriptors is not affected.
92cdf0e10cSrcweir     */
93cdf0e10cSrcweir     void SelectPage (const model::SharedPageDescriptor& rpDescriptor);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     /** Return whether the specified page is selected.  This convenience
96*916729d0Smseidel         method is a substitute for
97cdf0e10cSrcweir         SlideSorterModel::GetPageDescriptor(i)->IsSelected() is included
98cdf0e10cSrcweir         here to make this class more self contained.
99*916729d0Smseidel     */
100cdf0e10cSrcweir     bool IsPageSelected (int nPageIndex);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     /** Deselect the descriptor that is associated with the given page.
103cdf0e10cSrcweir         @param bUpdateCurrentPage
104cdf0e10cSrcweir             When <TRUE/> then the current page is updated to the first slide
105cdf0e10cSrcweir             of the remaining selection.
106cdf0e10cSrcweir     */
107cdf0e10cSrcweir     void DeselectPage (
108cdf0e10cSrcweir         int nPageIndex,
109cdf0e10cSrcweir         const bool bUpdateCurrentPage = true);
110cdf0e10cSrcweir     void DeselectPage (
111cdf0e10cSrcweir         const SdPage* pPage,
112cdf0e10cSrcweir         const bool bUpdateCurrentPage = true);
113cdf0e10cSrcweir     void DeselectPage (
114cdf0e10cSrcweir         const model::SharedPageDescriptor& rpDescriptor,
115cdf0e10cSrcweir         const bool bUpdateCurrentPage = true);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** This convenience method returns the same number of pages that
118cdf0e10cSrcweir         SlideSorterModel.GetPageCount() returns.  It is included here so
119cdf0e10cSrcweir         that it is self contained for iterating over all pages to select or
120cdf0e10cSrcweir         deselect them.
121cdf0e10cSrcweir     */
122cdf0e10cSrcweir     int GetPageCount (void) const;
123cdf0e10cSrcweir     int GetSelectedPageCount (void) const;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     /** Return the anchor for a range selection.  This usually is the first
126cdf0e10cSrcweir         selected page after all pages have been deselected.
127cdf0e10cSrcweir         @return
128cdf0e10cSrcweir             The returned anchor may be NULL.
129cdf0e10cSrcweir     */
130cdf0e10cSrcweir     model::SharedPageDescriptor GetSelectionAnchor (void) const;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     typedef ::std::vector<SdPage*> PageSelection;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     /** Return an object that describes the current selection.  The caller
136cdf0e10cSrcweir         can use that object to later restore the selection.
137cdf0e10cSrcweir         @return
138cdf0e10cSrcweir             The object returned describes the selection via indices.  So
139cdf0e10cSrcweir             even if pages are exchanged a later call to SetPageSelection()
140cdf0e10cSrcweir             is valid.
141cdf0e10cSrcweir     */
142cdf0e10cSrcweir     ::boost::shared_ptr<PageSelection> GetPageSelection (void) const;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     /** Restore a page selection according to the given selection object.
145cdf0e10cSrcweir         @param rSelection
146cdf0e10cSrcweir             Typically obtained by calling GetPageSelection() this object
147cdf0e10cSrcweir             is used to restore the selection.  If pages were exchanged since
148cdf0e10cSrcweir             the last call to GetPageSelection() it is still valid to call
149cdf0e10cSrcweir             this method with the selection.  When pages have been inserted
150cdf0e10cSrcweir             or removed the result may be unexpected.
151cdf0e10cSrcweir         @param bUpdateCurrentPage
152cdf0e10cSrcweir             When <TRUE/> (the default value) then after setting the
153cdf0e10cSrcweir             selection update the current page to the first page of the
154cdf0e10cSrcweir             selection.
15586e1cf34SPedro Giffuni             When called from within UpdateCurrentPage() then this flag is
156cdf0e10cSrcweir             used to prevent a recursion loop.
157cdf0e10cSrcweir     */
158cdf0e10cSrcweir     void SetPageSelection (
159cdf0e10cSrcweir         const ::boost::shared_ptr<PageSelection>& rSelection,
160cdf0e10cSrcweir         const bool bUpdateCurrentPage = true);
161cdf0e10cSrcweir 
1627950f2afSmseidel     /** Call this method after the model has changed to set the number
163cdf0e10cSrcweir         of selected pages.
164cdf0e10cSrcweir     */
165cdf0e10cSrcweir     void CountSelectedPages (void);
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     /** Use the UpdateLock whenever you do a complex selection, i.e. call
168cdf0e10cSrcweir         more than one method in a row.  An active lock prevents intermediate
169cdf0e10cSrcweir         changes of the current slide.
170cdf0e10cSrcweir     */
171cdf0e10cSrcweir     class UpdateLock
172cdf0e10cSrcweir     {
173cdf0e10cSrcweir     public:
174cdf0e10cSrcweir         UpdateLock (SlideSorter& rSlideSorter);
175cdf0e10cSrcweir         UpdateLock (PageSelector& rPageSelector);
176cdf0e10cSrcweir         ~UpdateLock (void);
177cdf0e10cSrcweir         void Release (void);
178cdf0e10cSrcweir     private:
179cdf0e10cSrcweir         PageSelector* mpSelector;
180cdf0e10cSrcweir     };
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     class BroadcastLock
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir     public:
185cdf0e10cSrcweir         BroadcastLock (SlideSorter& rSlideSorter);
186cdf0e10cSrcweir         BroadcastLock (PageSelector& rPageSelector);
187cdf0e10cSrcweir         ~BroadcastLock (void);
188cdf0e10cSrcweir     private:
189cdf0e10cSrcweir         PageSelector& mrSelector;
190cdf0e10cSrcweir     };
191cdf0e10cSrcweir 
192cdf0e10cSrcweir private:
193cdf0e10cSrcweir     model::SlideSorterModel& mrModel;
194cdf0e10cSrcweir     SlideSorter& mrSlideSorter;
195cdf0e10cSrcweir     SlideSorterController& mrController;
196cdf0e10cSrcweir     int mnSelectedPageCount;
197cdf0e10cSrcweir     int mnBroadcastDisableLevel;
198cdf0e10cSrcweir     bool mbSelectionChangeBroadcastPending;
199cdf0e10cSrcweir     model::SharedPageDescriptor mpMostRecentlySelectedPage;
200cdf0e10cSrcweir     /// Anchor for a range selection.
201cdf0e10cSrcweir     model::SharedPageDescriptor mpSelectionAnchor;
202cdf0e10cSrcweir     model::SharedPageDescriptor mpCurrentPage;
203cdf0e10cSrcweir     sal_Int32 mnUpdateLockCount;
204cdf0e10cSrcweir     bool mbIsUpdateCurrentPagePending;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     /** Enable the broadcasting of selection change events.  This calls the
207cdf0e10cSrcweir         SlideSorterController::SelectionHasChanged() method to do the actual
208cdf0e10cSrcweir         work.  When EnableBroadcasting has been called as many times as
209cdf0e10cSrcweir         DisableBroadcasting() was called before and the selection has been
210cdf0e10cSrcweir         changed in the mean time, this change will be broadcasted.
211cdf0e10cSrcweir     */
212cdf0e10cSrcweir     void EnableBroadcasting (void);
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     /** Disable the broadcasting of selection change events.  Subsequent
215cdf0e10cSrcweir         changes of the selection will set a flag that triggers the sending
216cdf0e10cSrcweir         of events when EnableBroadcasting() is called.
217cdf0e10cSrcweir     */
218cdf0e10cSrcweir     void DisableBroadcasting (void);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     void UpdateCurrentPage (const bool bUpdateOnlyWhenPending = false);
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     void CheckConsistency (void) const;
223cdf0e10cSrcweir };
224cdf0e10cSrcweir 
225cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::controller
226cdf0e10cSrcweir 
227cdf0e10cSrcweir #endif
228