Update git submodules
[LibreOffice.git] / sd / source / ui / slidesorter / inc / controller / SlsPageSelector.hxx
blob6a4b75004780d90efc49b28c0ae41be85ee25dd3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <model/SlsSharedPageDescriptor.hxx>
24 #include <vector>
25 #include <memory>
27 #include <sddllapi.h>
29 class SdPage;
31 namespace sd::slidesorter
33 class SlideSorter;
35 namespace sd::slidesorter::model
37 class SlideSorterModel;
40 namespace sd::slidesorter::controller
42 class SlideSorterController;
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.
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.
53 class PageSelector
55 public:
56 explicit PageSelector(SlideSorter& rSlideSorter);
57 PageSelector(const PageSelector&) = delete;
58 PageSelector& operator=(const PageSelector&) = delete;
60 // Exported for unit test
61 SD_DLLPUBLIC void SelectAllPages();
62 SD_DLLPUBLIC void DeselectAllPages();
64 /** Update the selection state of all page descriptors to be the same as
65 that of the corresponding pages of the SdPage objects and issue
66 redraw requests where necessary.
68 void GetCoreSelection();
70 /** Update the selection state of the SdPage objects to be the same as
71 that of the corresponding page descriptors.
73 void SetCoreSelection();
75 /** Select the specified descriptor. The selection state of the other
76 descriptors is not affected.
78 void SelectPage(int nPageIndex);
79 /** Select the descriptor that is associated with the given page. The
80 selection state of the other descriptors is not affected.
82 void SelectPage(const SdPage* pPage);
83 /** Select the specified descriptor. The selection state of the other
84 descriptors is not affected.
86 void SelectPage(const model::SharedPageDescriptor& rpDescriptor);
88 /** Return whether the specified page is selected. This convenience
89 method is a substitute for
90 SlideSorterModel::GetPageDescriptor(i)->HasState(ST_Selected) is
91 included here to make this class more self contained.
93 SD_DLLPUBLIC bool IsPageSelected(int nPageIndex);
95 /** Return whether the specified page is visible. This convenience
96 method is a substitute for
97 SlideSorterModel::GetPageDescriptor(i)->HasState(ST_Visible) is
98 included here to make this class more self contained.
100 bool IsPageVisible(int nPageIndex);
102 /** Deselect the descriptor that is associated with the given page.
103 The current page is updated to the first slide
104 of the remaining selection.
106 void DeselectPage(int nPageIndex);
107 void DeselectPage(const model::SharedPageDescriptor& rpDescriptor,
108 const bool bUpdateCurrentPage = true);
110 /** This convenience method returns the same number of pages that
111 SlideSorterModel.GetPageCount() returns. It is included here so
112 that it is self contained for iterating over all pages to select or
113 deselect them.
115 int GetPageCount() const;
116 int GetSelectedPageCount() const { return mnSelectedPageCount; }
118 /** Return the anchor for a range selection. This usually is the first
119 selected page after all pages have been deselected.
120 @return
121 The returned anchor may be NULL.
123 const model::SharedPageDescriptor& GetSelectionAnchor() const { return mpSelectionAnchor; }
125 typedef ::std::vector<SdPage*> PageSelection;
127 /** Return an object that describes the current selection. The caller
128 can use that object to later restore the selection.
129 @return
130 The object returned describes the selection via indices. So
131 even if pages are exchanged a later call to SetPageSelection()
132 is valid.
134 std::shared_ptr<PageSelection> GetPageSelection() const;
136 /** Restore a page selection according to the given selection object.
137 @param rSelection
138 Typically obtained by calling GetPageSelection() this object
139 is used to restore the selection. If pages were exchanged since
140 the last call to GetPageSelection() it is still valid to call
141 this method with the selection. When pages have been inserted
142 or removed the result may be unexpected.
143 @param bUpdateCurrentPage
144 When <TRUE/> (the default value) then after setting the
145 selection update the current page to the first page of the
146 selection.
147 When called from within UpdateCurrentPage() then this flag is
148 used to prevent a recursion loop.
150 void SetPageSelection(const std::shared_ptr<PageSelection>& rSelection,
151 const bool bUpdateCurrentPage);
153 /** Call this method after the model has changed to set the number
154 of selected pages.
156 void CountSelectedPages();
158 /** Use the UpdateLock whenever you do a complex selection, i.e. call
159 more than one method in a row. An active lock prevents intermediate
160 changes of the current slide.
162 class UpdateLock
164 public:
165 UpdateLock(SlideSorter const& rSlideSorter);
166 UpdateLock(PageSelector& rPageSelector);
167 ~UpdateLock();
168 void Release();
170 private:
171 PageSelector* mpSelector;
174 class BroadcastLock
176 public:
177 BroadcastLock(SlideSorter const& rSlideSorter);
178 BroadcastLock(PageSelector& rPageSelector);
179 ~BroadcastLock();
181 private:
182 PageSelector& mrSelector;
185 private:
186 model::SlideSorterModel& mrModel;
187 SlideSorter& mrSlideSorter;
188 SlideSorterController& mrController;
189 int mnSelectedPageCount;
190 int mnBroadcastDisableLevel;
191 bool mbSelectionChangeBroadcastPending;
192 model::SharedPageDescriptor mpMostRecentlySelectedPage;
193 /// Anchor for a range selection.
194 model::SharedPageDescriptor mpSelectionAnchor;
195 sal_Int32 mnUpdateLockCount;
196 bool mbIsUpdateCurrentPagePending;
198 /** Enable the broadcasting of selection change events. This calls the
199 SlideSorterController::SelectionHasChanged() method to do the actual
200 work. When EnableBroadcasting has been called as many times as
201 DisableBroadcasting() was called before and the selection has been
202 changed in the meantime, this change will be broadcasted.
204 void EnableBroadcasting();
206 /** Disable the broadcasting of selection change events. Subsequent
207 changes of the selection will set a flag that triggers the sending
208 of events when EnableBroadcasting() is called.
210 void DisableBroadcasting();
212 void UpdateCurrentPage(const bool bUpdateOnlyWhenPending = false);
214 void CheckConsistency() const;
217 } // end of namespace ::sd::slidesorter::controller
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */