1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSPAGESELECTOR_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CONTROLLER_SLSPAGESELECTOR_HXX
23 #include "model/SlsSharedPageDescriptor.hxx"
25 #include <com/sun/star/drawing/XDrawPage.hpp>
28 #include <boost/noncopyable.hpp>
32 namespace sd
{ namespace slidesorter
{
36 namespace sd
{ namespace slidesorter
{ namespace model
{
37 class SlideSorterModel
;
40 namespace sd
{ namespace slidesorter
{ namespace 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
: private ::boost::noncopyable
56 PageSelector (SlideSorter
& rSlideSorter
);
58 void SelectAllPages();
59 void DeselectAllPages();
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.
65 void GetCoreSelection();
67 /** Update the selection state of the SdPage objects to be the same as
68 that of the correspinding page descriptors.
70 void SetCoreSelection();
72 /** Select the specified descriptor. The selection state of the other
73 descriptors is not affected.
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.
79 void SelectPage (const SdPage
* pPage
);
80 /** Select the specified descriptor. The selection state of the other
81 descriptors is not affected.
83 void SelectPage (const model::SharedPageDescriptor
& rpDescriptor
);
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.
90 bool IsPageSelected (int nPageIndex
);
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.
99 const bool bUpdateCurrentPage
= true);
101 const model::SharedPageDescriptor
& rpDescriptor
,
102 const bool bUpdateCurrentPage
= true);
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
109 int GetPageCount() const;
110 int GetSelectedPageCount() const { return mnSelectedPageCount
;}
112 /** Return the anchor for a range selection. This usually is the first
113 selected page after all pages have been deselected.
115 The returned anchor may be NULL.
117 model::SharedPageDescriptor
GetSelectionAnchor() const { return mpSelectionAnchor
;}
119 typedef ::std::vector
<SdPage
*> PageSelection
;
121 /** Return an object that describes the current selection. The caller
122 can use that object to later restore the selection.
124 The object returned describes the selection via indices. So
125 even if pages are exchanged a later call to SetPageSelection()
128 ::boost::shared_ptr
<PageSelection
> GetPageSelection() const;
130 /** Restore a page selection according to the given selection object.
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
141 When called from within UpdateCurrentPage() then this flag is
142 used to prevent a recursion loop.
144 void SetPageSelection (
145 const ::boost::shared_ptr
<PageSelection
>& rSelection
,
146 const bool bUpdateCurrentPage
= true);
148 /** Call this method after the model has changed to set the number
151 void CountSelectedPages();
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.
160 UpdateLock (SlideSorter
& rSlideSorter
);
161 UpdateLock (PageSelector
& rPageSelector
);
165 PageSelector
* mpSelector
;
171 BroadcastLock (SlideSorter
& rSlideSorter
);
172 BroadcastLock (PageSelector
& rPageSelector
);
175 PageSelector
& mrSelector
;
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
;
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.
198 void EnableBroadcasting();
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.
204 void DisableBroadcasting();
206 void UpdateCurrentPage (const bool bUpdateOnlyWhenPending
= false);
208 void CheckConsistency() const;
211 } } } // end of namespace ::sd::slidesorter::controller
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */