Update ooo320-m1
[ooovba.git] / sd / source / ui / slidesorter / controller / SlsPageSelector.cxx
blob9322ff531ac6869524ee1dcffba8b31c84673b52
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsPageSelector.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "controller/SlsPageSelector.hxx"
35 #include "SlideSorter.hxx"
36 #include "SlideSorterViewShell.hxx"
37 #include "controller/SlideSorterController.hxx"
38 #include "controller/SlsSelectionManager.hxx"
39 #include "model/SlsPageDescriptor.hxx"
40 #include "model/SlsPageEnumerationProvider.hxx"
41 #include "model/SlideSorterModel.hxx"
42 #include "view/SlideSorterView.hxx"
44 #include "sdpage.hxx"
45 #include "ViewShell.hxx"
46 #include "DrawViewShell.hxx"
47 #include "ViewShellBase.hxx"
48 #include <com/sun/star/drawing/XDrawView.hpp>
49 #include <com/sun/star/beans/XPropertySet.hpp>
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::uno;
53 using namespace ::sd::slidesorter::model;
54 using namespace ::sd::slidesorter::view;
56 namespace sd { namespace slidesorter { namespace controller {
59 PageSelector::PageSelector (SlideSorter& rSlideSorter)
60 : mrModel(rSlideSorter.GetModel()),
61 mrSlideSorter(rSlideSorter),
62 mrController(mrSlideSorter.GetController()),
63 mnSelectedPageCount(0),
64 mnBroadcastDisableLevel(0),
65 mbSelectionChangeBroadcastPending(false),
66 mpMostRecentlySelectedPage(),
67 mpSelectionAnchor()
69 CountSelectedPages ();
75 void PageSelector::SelectAllPages (void)
77 int nPageCount = mrModel.GetPageCount();
78 for (int nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
79 SelectPage (nPageIndex);
85 void PageSelector::DeselectAllPages (void)
87 int nPageCount = mrModel.GetPageCount();
88 for (int nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
89 DeselectPage (nPageIndex);
90 DBG_ASSERT (mnSelectedPageCount==0,
91 "PageSelector::DeselectAllPages: the selected pages counter is not 0");
92 mnSelectedPageCount = 0;
93 mpMostRecentlySelectedPage.reset();
94 mpSelectionAnchor.reset();
100 void PageSelector::UpdateAllPages (void)
102 bool bSelectionHasChanged (true);
103 mnSelectedPageCount = 0;
104 model::PageEnumeration aAllPages (
105 model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
106 while (aAllPages.HasMoreElements())
108 model::SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
109 if (pDescriptor->UpdateSelection())
111 mrSlideSorter.GetView().RequestRepaint(pDescriptor);
112 bSelectionHasChanged = true;
115 if (pDescriptor->IsSelected())
116 mnSelectedPageCount++;
119 if (bSelectionHasChanged)
121 if (mnBroadcastDisableLevel > 0)
122 mbSelectionChangeBroadcastPending = true;
123 else
124 mrController.GetSelectionManager()->SelectionHasChanged();
131 void PageSelector::SelectPage (int nPageIndex)
133 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
134 if (pDescriptor.get() != NULL)
135 SelectPage(pDescriptor);
141 void PageSelector::SelectPage (const SdPage* pPage)
143 int nPageIndex = (pPage->GetPageNum()-1) / 2;
144 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
145 if (pDescriptor.get()!=NULL && pDescriptor->GetPage()==pPage)
146 SelectPage(pDescriptor);
152 void PageSelector::SelectPage (const SharedPageDescriptor& rpDescriptor)
154 if (rpDescriptor.get()!=NULL && rpDescriptor->Select())
156 mnSelectedPageCount ++;
157 mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
159 mpMostRecentlySelectedPage = rpDescriptor;
160 if (mpSelectionAnchor == NULL)
161 mpSelectionAnchor = rpDescriptor;
163 if (mnBroadcastDisableLevel > 0)
164 mbSelectionChangeBroadcastPending = true;
165 else
166 mrController.GetSelectionManager()->SelectionHasChanged();
173 void PageSelector::DeselectPage (int nPageIndex)
175 model::SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
176 if (pDescriptor.get() != NULL)
177 DeselectPage(pDescriptor);
183 void PageSelector::DeselectPage (const SdPage* pPage)
185 int nPageIndex = (pPage->GetPageNum()-1) / 2;
186 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
187 if (pDescriptor.get()!=NULL && pDescriptor->GetPage()==pPage)
188 DeselectPage(pDescriptor);
194 void PageSelector::DeselectPage (const SharedPageDescriptor& rpDescriptor)
196 if (rpDescriptor.get()!=NULL && rpDescriptor->Deselect())
198 mnSelectedPageCount --;
199 mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
200 if (mpMostRecentlySelectedPage == rpDescriptor)
201 mpMostRecentlySelectedPage.reset();
202 if (mnBroadcastDisableLevel > 0)
203 mbSelectionChangeBroadcastPending = true;
204 else
205 mrController.GetSelectionManager()->SelectionHasChanged();
212 bool PageSelector::IsPageSelected (int nPageIndex)
214 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
215 if (pDescriptor.get() != NULL)
216 return pDescriptor->IsSelected();
217 else
218 return false;
224 int PageSelector::GetPageCount (void) const
226 return mrModel.GetPageCount();
232 int PageSelector::GetSelectedPageCount (void) const
234 return mnSelectedPageCount;
240 void PageSelector::PrepareModelChange (void)
242 DeselectAllPages ();
248 void PageSelector::HandleModelChange (void)
250 UpdateAllPages();
256 SharedPageDescriptor PageSelector::GetMostRecentlySelectedPage (void) const
258 return mpMostRecentlySelectedPage;
264 SharedPageDescriptor PageSelector::GetSelectionAnchor (void) const
266 return mpSelectionAnchor;
272 void PageSelector::CountSelectedPages (void)
274 mnSelectedPageCount = 0;
275 model::PageEnumeration aSelectedPages (
276 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
277 while (aSelectedPages.HasMoreElements())
279 mnSelectedPageCount++;
280 aSelectedPages.GetNextElement();
287 void PageSelector::EnableBroadcasting (bool bMakeSelectionVisible)
289 if (mnBroadcastDisableLevel > 0)
290 mnBroadcastDisableLevel --;
291 if (mnBroadcastDisableLevel==0 && mbSelectionChangeBroadcastPending)
293 mrController.GetSelectionManager()->SelectionHasChanged(bMakeSelectionVisible);
294 mbSelectionChangeBroadcastPending = false;
301 void PageSelector::DisableBroadcasting (void)
303 mnBroadcastDisableLevel ++;
309 ::boost::shared_ptr<PageSelector::PageSelection> PageSelector::GetPageSelection (void) const
311 ::boost::shared_ptr<PageSelection> pSelection (new PageSelection());
312 pSelection->reserve(GetSelectedPageCount());
314 int nPageCount = GetPageCount();
315 for (int nIndex=0; nIndex<nPageCount; nIndex++)
317 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
318 if (pDescriptor.get()!=NULL && pDescriptor->IsSelected())
319 pSelection->push_back(pDescriptor->GetPage());
322 return pSelection;
328 void PageSelector::SetPageSelection (const ::boost::shared_ptr<PageSelection>& rpSelection)
330 PageSelection::const_iterator iPage;
331 for (iPage=rpSelection->begin(); iPage!=rpSelection->end(); ++iPage)
332 SelectPage(*iPage);
338 } } } // end of namespace ::sd::slidesorter::controller