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 INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSPAGESELECTOR_HXX
21 : #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSPAGESELECTOR_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 : class SdPage;
31 :
32 : namespace sd { namespace slidesorter {
33 : class SlideSorter;
34 : } }
35 :
36 : namespace sd { namespace slidesorter { namespace model {
37 : class SlideSorterModel;
38 : } } }
39 :
40 : namespace sd { namespace slidesorter { namespace controller {
41 :
42 : class SlideSorterController;
43 :
44 : /** A sub-controller that handles page selection of the slide browser.
45 : Selecting a page does not make it the current page (of the main view)
46 : automatically as this would not be desired in a multi selection. This
47 : has to be done explicitly by calling the
48 : CurrentSlideManager::SetCurrentSlide() method.
49 :
50 : Indices of pages relate always to the number of all pages in the model
51 : (as returned by GetPageCount()) not just the selected pages.
52 : */
53 64 : class PageSelector : private ::boost::noncopyable
54 : {
55 : public:
56 : PageSelector (SlideSorter& rSlideSorter);
57 :
58 : void SelectAllPages();
59 : void DeselectAllPages();
60 :
61 : /** Update the selection state of all page descriptors to be the same as
62 : that of the corresponding pages of the SdPage objects and issue
63 : redraw requests where necessary.
64 : */
65 : void GetCoreSelection();
66 :
67 : /** Update the selection state of the SdPage objects to be the same as
68 : that of the correspinding page descriptors.
69 : */
70 : void SetCoreSelection();
71 :
72 : /** Select the specified descriptor. The selection state of the other
73 : descriptors is not affected.
74 : */
75 : void SelectPage (int nPageIndex);
76 : /** Select the descriptor that is associated with the given page. The
77 : selection state of the other descriptors is not affected.
78 : */
79 : void SelectPage (const SdPage* pPage);
80 : /** Select the specified descriptor. The selection state of the other
81 : descriptors is not affected.
82 : */
83 : void SelectPage (const model::SharedPageDescriptor& rpDescriptor);
84 :
85 : /** Return whether the specified page is selected. This convenience
86 : method is a substitute for
87 : SlideSorterModel::GetPageDescriptor(i)->IsSelected() is included
88 : here to make this class more self contained.
89 : */
90 : bool IsPageSelected (int nPageIndex);
91 :
92 : /** Deselect the descriptor that is associated with the given page.
93 : @param bUpdateCurrentPage
94 : When <TRUE/> then the current page is updated to the first slide
95 : of the remaining selection.
96 : */
97 : void DeselectPage (
98 : int nPageIndex,
99 : const bool bUpdateCurrentPage = true);
100 : void DeselectPage (
101 : const model::SharedPageDescriptor& rpDescriptor,
102 : const bool bUpdateCurrentPage = true);
103 :
104 : /** This convenience method returns the same number of pages that
105 : SlideSorterModel.GetPageCount() returns. It is included here so
106 : that it is self contained for iterating over all pages to select or
107 : deselect them.
108 : */
109 : int GetPageCount() const;
110 85 : int GetSelectedPageCount() const { return mnSelectedPageCount;}
111 :
112 : /** Return the anchor for a range selection. This usually is the first
113 : selected page after all pages have been deselected.
114 : @return
115 : The returned anchor may be NULL.
116 : */
117 0 : model::SharedPageDescriptor GetSelectionAnchor() const { return mpSelectionAnchor;}
118 :
119 : typedef ::std::vector<SdPage*> PageSelection;
120 :
121 : /** Return an object that describes the current selection. The caller
122 : can use that object to later restore the selection.
123 : @return
124 : The object returned describes the selection via indices. So
125 : even if pages are exchanged a later call to SetPageSelection()
126 : is valid.
127 : */
128 : ::boost::shared_ptr<PageSelection> GetPageSelection() const;
129 :
130 : /** Restore a page selection according to the given selection object.
131 : @param rSelection
132 : Typically obtained by calling GetPageSelection() this object
133 : is used to restore the selection. If pages were exchanged since
134 : the last call to GetPageSelection() it is still valid to call
135 : this method with the selection. When pages have been inserted
136 : or removed the result may be unexpected.
137 : @param bUpdateCurrentPage
138 : When <TRUE/> (the default value) then after setting the
139 : selection update the current page to the first page of the
140 : selection.
141 : When called from within UpdateCurrentPage() then this flag is
142 : used to prevent a recursion loop.
143 : */
144 : void SetPageSelection (
145 : const ::boost::shared_ptr<PageSelection>& rSelection,
146 : const bool bUpdateCurrentPage = true);
147 :
148 : /** Call this method after the model has changed to set the number
149 : of selected pages.
150 : */
151 : void CountSelectedPages();
152 :
153 : /** Use the UpdateLock whenever you do a complex selection, i.e. call
154 : more than one method in a row. An active lock prevents intermediate
155 : changes of the current slide.
156 : */
157 : class UpdateLock
158 : {
159 : public:
160 : UpdateLock (SlideSorter& rSlideSorter);
161 : UpdateLock (PageSelector& rPageSelector);
162 : ~UpdateLock();
163 : void Release();
164 : private:
165 : PageSelector* mpSelector;
166 : };
167 :
168 : class BroadcastLock
169 : {
170 : public:
171 : BroadcastLock (SlideSorter& rSlideSorter);
172 : BroadcastLock (PageSelector& rPageSelector);
173 : ~BroadcastLock();
174 : private:
175 : PageSelector& mrSelector;
176 : };
177 :
178 : private:
179 : model::SlideSorterModel& mrModel;
180 : SlideSorter& mrSlideSorter;
181 : SlideSorterController& mrController;
182 : int mnSelectedPageCount;
183 : int mnBroadcastDisableLevel;
184 : bool mbSelectionChangeBroadcastPending;
185 : model::SharedPageDescriptor mpMostRecentlySelectedPage;
186 : /// Anchor for a range selection.
187 : model::SharedPageDescriptor mpSelectionAnchor;
188 : model::SharedPageDescriptor mpCurrentPage;
189 : sal_Int32 mnUpdateLockCount;
190 : bool mbIsUpdateCurrentPagePending;
191 :
192 : /** Enable the broadcasting of selection change events. This calls the
193 : SlideSorterController::SelectionHasChanged() method to do the actual
194 : work. When EnableBroadcasting has been called as many times as
195 : DisableBroadcasting() was called before and the selection has been
196 : changed in the mean time, this change will be broadcasted.
197 : */
198 : void EnableBroadcasting();
199 :
200 : /** Disable the broadcasting of selection change events. Subsequent
201 : changes of the selection will set a flag that triggers the sending
202 : of events when EnableBroadcasting() is called.
203 : */
204 : void DisableBroadcasting();
205 :
206 : void UpdateCurrentPage (const bool bUpdateOnlyWhenPending = false);
207 :
208 : void CheckConsistency() const;
209 : };
210 :
211 : } } } // end of namespace ::sd::slidesorter::controller
212 :
213 : #endif
214 :
215 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|