Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "controller/SlsPageSelector.hxx"
31 : :
32 : : #include "SlideSorter.hxx"
33 : : #include "SlideSorterViewShell.hxx"
34 : : #include "controller/SlideSorterController.hxx"
35 : : #include "controller/SlsSelectionManager.hxx"
36 : : #include "controller/SlsAnimator.hxx"
37 : : #include "controller/SlsCurrentSlideManager.hxx"
38 : : #include "controller/SlsVisibleAreaManager.hxx"
39 : : #include "model/SlsPageDescriptor.hxx"
40 : : #include "model/SlsPageEnumerationProvider.hxx"
41 : : #include "model/SlideSorterModel.hxx"
42 : : #include "view/SlideSorterView.hxx"
43 : :
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>
50 : : #include <boost/shared_ptr.hpp>
51 : :
52 : :
53 : : using namespace ::com::sun::star;
54 : : using namespace ::com::sun::star::uno;
55 : : using namespace ::sd::slidesorter::model;
56 : : using namespace ::sd::slidesorter::view;
57 : :
58 : :
59 : : namespace sd { namespace slidesorter { namespace controller {
60 : :
61 : 130 : PageSelector::PageSelector (SlideSorter& rSlideSorter)
62 [ + - ]: 130 : : mrModel(rSlideSorter.GetModel()),
63 : : mrSlideSorter(rSlideSorter),
64 [ + - ]: 130 : mrController(mrSlideSorter.GetController()),
65 : : mnSelectedPageCount(0),
66 : : mnBroadcastDisableLevel(0),
67 : : mbSelectionChangeBroadcastPending(false),
68 : : mpMostRecentlySelectedPage(),
69 : : mpSelectionAnchor(),
70 : : mpCurrentPage(),
71 : : mnUpdateLockCount(0),
72 [ + - ][ + - ]: 260 : mbIsUpdateCurrentPagePending(false)
[ + - ]
73 : : {
74 [ + - ]: 130 : CountSelectedPages ();
75 : 130 : }
76 : :
77 : :
78 : :
79 : :
80 : 0 : void PageSelector::SelectAllPages (void)
81 : : {
82 [ # # ]: 0 : VisibleAreaManager::TemporaryDisabler aDisabler (mrSlideSorter);
83 : 0 : PageSelector::UpdateLock aLock (*this);
84 : :
85 [ # # ]: 0 : int nPageCount = mrModel.GetPageCount();
86 [ # # ]: 0 : for (int nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
87 [ # # ][ # # ]: 0 : SelectPage(nPageIndex);
[ # # ]
88 : 0 : }
89 : :
90 : :
91 : :
92 : :
93 : 268 : void PageSelector::DeselectAllPages (void)
94 : : {
95 [ + - ]: 268 : VisibleAreaManager::TemporaryDisabler aDisabler (mrSlideSorter);
96 : 268 : PageSelector::UpdateLock aLock (*this);
97 : :
98 [ + - ]: 268 : int nPageCount = mrModel.GetPageCount();
99 [ + + ]: 544 : for (int nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
100 [ + - ]: 276 : DeselectPage(nPageIndex);
101 : :
102 : : DBG_ASSERT (mnSelectedPageCount==0,
103 : : "PageSelector::DeselectAllPages: the selected pages counter is not 0");
104 : 268 : mnSelectedPageCount = 0;
105 [ + - ][ + - ]: 268 : mpSelectionAnchor.reset();
[ + - ]
106 : 268 : }
107 : :
108 : :
109 : :
110 : :
111 : 130 : void PageSelector::GetCoreSelection (void)
112 : : {
113 : 130 : PageSelector::UpdateLock aLock (*this);
114 : :
115 : 130 : bool bSelectionHasChanged (true);
116 : 130 : mnSelectedPageCount = 0;
117 : : model::PageEnumeration aAllPages (
118 [ + - ]: 130 : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
119 [ + - ][ - + ]: 130 : while (aAllPages.HasMoreElements())
120 : : {
121 [ # # ]: 0 : model::SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
122 [ # # ][ # # ]: 0 : if (pDescriptor->GetCoreSelection())
123 : : {
124 [ # # ][ # # ]: 0 : mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(pDescriptor);
[ # # ]
125 [ # # ][ # # ]: 0 : mrSlideSorter.GetView().RequestRepaint(pDescriptor);
126 : 0 : bSelectionHasChanged = true;
127 : : }
128 : :
129 [ # # ][ # # ]: 0 : if (pDescriptor->HasState(PageDescriptor::ST_Selected))
130 : 0 : mnSelectedPageCount++;
131 [ # # ]: 0 : }
132 : :
133 [ + - ]: 130 : if (bSelectionHasChanged)
134 : : {
135 [ - + ]: 130 : if (mnBroadcastDisableLevel > 0)
136 : 0 : mbSelectionChangeBroadcastPending = true;
137 : : else
138 [ + - ][ + - ]: 130 : mrController.GetSelectionManager()->SelectionHasChanged();
[ + - ]
139 [ + - ][ + - ]: 130 : }
140 : 130 : }
141 : :
142 : :
143 : :
144 : :
145 : 0 : void PageSelector::SetCoreSelection (void)
146 : : {
147 : : model::PageEnumeration aAllPages (
148 [ # # ]: 0 : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
149 [ # # ][ # # ]: 0 : while (aAllPages.HasMoreElements())
150 : : {
151 [ # # ]: 0 : model::SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
152 [ # # ]: 0 : pDescriptor->SetCoreSelection();
153 [ # # ][ # # ]: 0 : }
154 : 0 : }
155 : :
156 : :
157 : :
158 : :
159 : 8 : void PageSelector::SelectPage (int nPageIndex)
160 : : {
161 [ + - ]: 8 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
162 [ + - ]: 8 : if (pDescriptor.get() != NULL)
163 [ + - ][ + - ]: 8 : SelectPage(pDescriptor);
164 : 8 : }
165 : :
166 : :
167 : :
168 : :
169 : 268 : void PageSelector::SelectPage (const SdPage* pPage)
170 : : {
171 [ + - ]: 268 : const sal_Int32 nPageIndex (mrModel.GetIndex(pPage));
172 [ + - ]: 268 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
173 [ + - ][ + - ]: 268 : if (pDescriptor.get()!=NULL && pDescriptor->GetPage()==pPage)
[ + - ][ + - ]
174 [ + - ][ + - ]: 268 : SelectPage(pDescriptor);
175 : 268 : }
176 : :
177 : :
178 : :
179 : :
180 : 544 : void PageSelector::SelectPage (const SharedPageDescriptor& rpDescriptor)
181 : : {
182 [ + - + + ]: 1088 : if (rpDescriptor.get()!=NULL
[ + + ]
183 : 544 : && mrSlideSorter.GetView().SetState(rpDescriptor, PageDescriptor::ST_Selected, true))
184 : : {
185 : 268 : ++mnSelectedPageCount;
186 : 268 : mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor,true);
187 : 268 : mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
188 : :
189 : 268 : mpMostRecentlySelectedPage = rpDescriptor;
190 [ + - ]: 268 : if (mpSelectionAnchor == NULL)
191 : 268 : mpSelectionAnchor = rpDescriptor;
192 : :
193 [ + + ]: 268 : if (mnBroadcastDisableLevel > 0)
194 : 130 : mbSelectionChangeBroadcastPending = true;
195 : : else
196 [ + - ]: 138 : mrController.GetSelectionManager()->SelectionHasChanged();
197 : 268 : UpdateCurrentPage();
198 : :
199 : 268 : CheckConsistency();
200 : : }
201 : 544 : }
202 : :
203 : :
204 : :
205 : :
206 : 276 : void PageSelector::DeselectPage (
207 : : int nPageIndex,
208 : : const bool bUpdateCurrentPage)
209 : : {
210 [ + - ]: 276 : model::SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
211 [ + - ]: 276 : if (pDescriptor.get() != NULL)
212 [ + - ][ + - ]: 276 : DeselectPage(pDescriptor, bUpdateCurrentPage);
213 : 276 : }
214 : :
215 : :
216 : :
217 : :
218 : 276 : void PageSelector::DeselectPage (
219 : : const SharedPageDescriptor& rpDescriptor,
220 : : const bool bUpdateCurrentPage)
221 : : {
222 [ + - + + ]: 552 : if (rpDescriptor.get()!=NULL
[ + + ]
223 : 276 : && mrSlideSorter.GetView().SetState(rpDescriptor, PageDescriptor::ST_Selected, false))
224 : : {
225 : 268 : --mnSelectedPageCount;
226 : 268 : mrSlideSorter.GetController().GetVisibleAreaManager().RequestVisible(rpDescriptor);
227 : 268 : mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
228 [ + + ]: 268 : if (mpMostRecentlySelectedPage == rpDescriptor)
229 : 138 : mpMostRecentlySelectedPage.reset();
230 [ + + ]: 268 : if (mnBroadcastDisableLevel > 0)
231 : 130 : mbSelectionChangeBroadcastPending = true;
232 : : else
233 [ + - ]: 138 : mrController.GetSelectionManager()->SelectionHasChanged();
234 [ + - ]: 268 : if (bUpdateCurrentPage)
235 : 268 : UpdateCurrentPage();
236 : :
237 : 268 : CheckConsistency();
238 : : }
239 : 276 : }
240 : :
241 : :
242 : :
243 : :
244 : 536 : void PageSelector::CheckConsistency (void) const
245 : : {
246 : 536 : int nSelectionCount (0);
247 [ + + ]: 1088 : for (int nPageIndex=0,nPageCount=mrModel.GetPageCount(); nPageIndex<nPageCount; nPageIndex++)
248 : : {
249 [ + - ]: 552 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
250 : : assert(pDescriptor);
251 [ + - ][ + + ]: 552 : if (pDescriptor->HasState(PageDescriptor::ST_Selected))
252 : 268 : ++nSelectionCount;
253 [ + - ]: 552 : }
254 : 536 : if (nSelectionCount!=mnSelectedPageCount)
255 : : {
256 : : assert(nSelectionCount==mnSelectedPageCount);
257 : : }
258 : 536 : }
259 : :
260 : :
261 : :
262 : :
263 : 0 : bool PageSelector::IsPageSelected (int nPageIndex)
264 : : {
265 [ # # ]: 0 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
266 [ # # ]: 0 : if (pDescriptor.get() != NULL)
267 [ # # ]: 0 : return pDescriptor->HasState(PageDescriptor::ST_Selected);
268 : : else
269 [ # # ]: 0 : return false;
270 : : }
271 : :
272 : :
273 : :
274 : :
275 : 804 : int PageSelector::GetPageCount (void) const
276 : : {
277 : 804 : return mrModel.GetPageCount();
278 : : }
279 : :
280 : :
281 : :
282 : :
283 : 268 : int PageSelector::GetSelectedPageCount (void) const
284 : : {
285 : 268 : return mnSelectedPageCount;
286 : : }
287 : :
288 : :
289 : :
290 : :
291 : 0 : SharedPageDescriptor PageSelector::GetSelectionAnchor (void) const
292 : : {
293 : 0 : return mpSelectionAnchor;
294 : : }
295 : :
296 : :
297 : :
298 : :
299 : 260 : void PageSelector::CountSelectedPages (void)
300 : : {
301 : 260 : mnSelectedPageCount = 0;
302 : : model::PageEnumeration aSelectedPages (
303 [ + - ]: 260 : model::PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
304 [ + - ][ + + ]: 390 : while (aSelectedPages.HasMoreElements())
305 : : {
306 : 130 : mnSelectedPageCount++;
307 [ + - ][ + - ]: 130 : aSelectedPages.GetNextElement();
308 [ + - ]: 260 : }
309 : 260 : }
310 : :
311 : :
312 : :
313 : :
314 : 130 : void PageSelector::EnableBroadcasting (void)
315 : : {
316 [ + - ]: 130 : if (mnBroadcastDisableLevel > 0)
317 : 130 : mnBroadcastDisableLevel --;
318 [ + - ][ + - ]: 130 : if (mnBroadcastDisableLevel==0 && mbSelectionChangeBroadcastPending)
319 : : {
320 [ + - ]: 130 : mrController.GetSelectionManager()->SelectionHasChanged();
321 : 130 : mbSelectionChangeBroadcastPending = false;
322 : : }
323 : 130 : }
324 : :
325 : :
326 : :
327 : :
328 : 130 : void PageSelector::DisableBroadcasting (void)
329 : : {
330 : 130 : mnBroadcastDisableLevel ++;
331 : 130 : }
332 : :
333 : :
334 : :
335 : :
336 : 268 : ::boost::shared_ptr<PageSelector::PageSelection> PageSelector::GetPageSelection (void) const
337 : : {
338 [ + - ][ + - ]: 268 : ::boost::shared_ptr<PageSelection> pSelection (new PageSelection());
339 [ + - ]: 268 : pSelection->reserve(GetSelectedPageCount());
340 : :
341 [ + - ]: 268 : int nPageCount = GetPageCount();
342 [ + + ]: 544 : for (int nIndex=0; nIndex<nPageCount; nIndex++)
343 : : {
344 [ + - ]: 276 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
345 [ + - ][ + - ]: 276 : if (pDescriptor.get()!=NULL && pDescriptor->HasState(PageDescriptor::ST_Selected))
[ + + ][ + + ]
346 [ + - ][ + - ]: 268 : pSelection->push_back(pDescriptor->GetPage());
347 [ + - ]: 276 : }
348 : :
349 : 268 : return pSelection;
350 : : }
351 : :
352 : :
353 : :
354 : :
355 : 268 : void PageSelector::SetPageSelection (
356 : : const ::boost::shared_ptr<PageSelection>& rpSelection,
357 : : const bool bUpdateCurrentPage)
358 : : {
359 : 268 : PageSelection::const_iterator iPage;
360 [ + - ][ + - ]: 536 : for (iPage=rpSelection->begin(); iPage!=rpSelection->end(); ++iPage)
[ + + ]
361 [ + - ]: 268 : SelectPage(*iPage);
362 [ - + ]: 268 : if (bUpdateCurrentPage)
363 [ # # ]: 0 : UpdateCurrentPage();
364 : 268 : }
365 : :
366 : :
367 : :
368 : :
369 : 934 : void PageSelector::UpdateCurrentPage (const bool bUpdateOnlyWhenPending)
370 : : {
371 [ + + ]: 934 : if (mnUpdateLockCount > 0)
372 : : {
373 : 268 : mbIsUpdateCurrentPagePending = true;
374 : 268 : return;
375 : : }
376 : :
377 [ + + ][ + + ]: 666 : if ( ! mbIsUpdateCurrentPagePending && bUpdateOnlyWhenPending)
378 : 130 : return;
379 : :
380 : 536 : mbIsUpdateCurrentPagePending = false;
381 : :
382 : : // Make the first selected page the current page.
383 : 536 : const sal_Int32 nPageCount (GetPageCount());
384 [ + + ]: 1482 : for (sal_Int32 nIndex=0; nIndex<nPageCount; ++nIndex)
385 : : {
386 [ + - ]: 548 : SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nIndex));
387 [ + - ][ + - ]: 548 : if (pDescriptor && pDescriptor->HasState(PageDescriptor::ST_Selected))
[ + + ][ + + ]
388 : : {
389 : : // Switching the current slide normally sets also the selection
390 : : // to just the new current slide. To prevent that, we store
391 : : // (and at the end of this scope restore) the current selection.
392 [ + - ]: 268 : ::boost::shared_ptr<PageSelection> pSelection (GetPageSelection());
393 : :
394 [ + - ][ + - ]: 268 : mrController.GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
[ + - ]
395 : :
396 : : // Restore the selection and prevent a recursive call to
397 : : // UpdateCurrentPage().
398 [ + - ]: 268 : SetPageSelection(pSelection, false);
399 [ + - ]: 548 : return;
400 : : }
401 [ + - ][ + + ]: 548 : }
402 : :
403 : : // No page is selected. Do not change the current slide.
404 : : }
405 : :
406 : :
407 : :
408 : :
409 : : //===== PageSelector::UpdateLock ==============================================
410 : :
411 : 0 : PageSelector::UpdateLock::UpdateLock (SlideSorter& rSlideSorter)
412 : 0 : : mpSelector(&rSlideSorter.GetController().GetPageSelector())
413 : : {
414 : 0 : ++mpSelector->mnUpdateLockCount;
415 : 0 : }
416 : :
417 : :
418 : :
419 : :
420 : 398 : PageSelector::UpdateLock::UpdateLock (PageSelector& rSelector)
421 : 398 : : mpSelector(&rSelector)
422 : : {
423 : 398 : ++mpSelector->mnUpdateLockCount;
424 : 398 : }
425 : :
426 : :
427 : :
428 : :
429 : 398 : PageSelector::UpdateLock::~UpdateLock (void)
430 : : {
431 : 398 : Release();
432 : 398 : }
433 : :
434 : 398 : void PageSelector::UpdateLock::Release (void)
435 : : {
436 [ + - ]: 398 : if (mpSelector != NULL)
437 : : {
438 : 398 : --mpSelector->mnUpdateLockCount;
439 : : OSL_ASSERT(mpSelector->mnUpdateLockCount >= 0);
440 [ + - ]: 398 : if (mpSelector->mnUpdateLockCount == 0)
441 : 398 : mpSelector->UpdateCurrentPage(true);
442 : :
443 : 398 : mpSelector = NULL;
444 : : }
445 : 398 : }
446 : :
447 : :
448 : :
449 : :
450 : : //===== PageSelector::BroadcastLock ==============================================
451 : :
452 : 0 : PageSelector::BroadcastLock::BroadcastLock (SlideSorter& rSlideSorter)
453 : 0 : : mrSelector(rSlideSorter.GetController().GetPageSelector())
454 : : {
455 : 0 : mrSelector.DisableBroadcasting();
456 : 0 : }
457 : :
458 : :
459 : :
460 : :
461 : 130 : PageSelector::BroadcastLock::BroadcastLock (PageSelector& rSelector)
462 : 130 : : mrSelector(rSelector)
463 : : {
464 : 130 : mrSelector.DisableBroadcasting();
465 : 130 : }
466 : :
467 : :
468 : :
469 : :
470 : 130 : PageSelector::BroadcastLock::~BroadcastLock (void)
471 : : {
472 : 130 : mrSelector.EnableBroadcasting();
473 : 130 : }
474 : :
475 : : } } } // end of namespace ::sd::slidesorter::controller
476 : :
477 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|