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