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 :
21 : #include "model/SlideSorterModel.hxx"
22 :
23 : #include "SlideSorter.hxx"
24 : #include "model/SlsPageDescriptor.hxx"
25 : #include "model/SlsPageEnumerationProvider.hxx"
26 : #include "controller/SlideSorterController.hxx"
27 : #include "controller/SlsProperties.hxx"
28 : #include "controller/SlsPageSelector.hxx"
29 : #include "controller/SlsCurrentSlideManager.hxx"
30 : #include "controller/SlsSlotManager.hxx"
31 : #include "view/SlideSorterView.hxx"
32 : #include "taskpane/SlideSorterCacheDisplay.hxx"
33 : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
34 : #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
35 : #include <com/sun/star/beans/XPropertySet.hpp>
36 : #include <com/sun/star/beans/UnknownPropertyException.hpp>
37 :
38 : #include "ViewShellBase.hxx"
39 : #include "DrawViewShell.hxx"
40 : #include "DrawDocShell.hxx"
41 : #include "drawdoc.hxx"
42 : #include "sdpage.hxx"
43 : #include "FrameView.hxx"
44 :
45 : #include <tools/diagnose_ex.h>
46 :
47 : using namespace ::com::sun::star;
48 : using namespace ::com::sun::star::uno;
49 :
50 : namespace sd { namespace slidesorter { namespace model {
51 :
52 : namespace {
53 : class CompareToXDrawPage
54 : {
55 : public:
56 : CompareToXDrawPage (const Reference<drawing::XDrawPage>& rxSlide) : mxSlide(rxSlide) {}
57 : bool operator() (const SharedPageDescriptor& rpDescriptor)
58 : { return rpDescriptor.get()!=NULL && rpDescriptor->GetXDrawPage()==mxSlide; }
59 : private:
60 : Reference<drawing::XDrawPage> mxSlide;
61 : };
62 :
63 0 : bool PrintModel (const SlideSorterModel& rModel)
64 : {
65 0 : for (sal_Int32 nIndex=0,nCount=rModel.GetPageCount(); nIndex<nCount; ++nIndex)
66 : {
67 0 : SharedPageDescriptor pDescriptor (rModel.GetPageDescriptor(nIndex));
68 0 : if (pDescriptor)
69 : {
70 : OSL_TRACE("%d %d %d %d %x",
71 : nIndex,
72 : pDescriptor->GetPageIndex(),
73 : pDescriptor->GetVisualState().mnPageId,
74 : FromCoreIndex(pDescriptor->GetPage()->GetPageNum()),
75 : pDescriptor->GetPage());
76 : }
77 : else
78 : {
79 : OSL_TRACE("%d", nIndex);
80 : }
81 0 : }
82 :
83 0 : return true;
84 : }
85 157 : bool CheckModel (const SlideSorterModel& rModel)
86 : {
87 346 : for (sal_Int32 nIndex=0,nCount=rModel.GetPageCount(); nIndex<nCount; ++nIndex)
88 : {
89 189 : SharedPageDescriptor pDescriptor (rModel.GetPageDescriptor(nIndex));
90 189 : if ( ! pDescriptor)
91 : {
92 0 : PrintModel(rModel);
93 : OSL_ASSERT(pDescriptor);
94 0 : return false;
95 : }
96 189 : if (nIndex != pDescriptor->GetPageIndex())
97 : {
98 0 : PrintModel(rModel);
99 : OSL_ASSERT(nIndex == pDescriptor->GetPageIndex());
100 0 : return false;
101 : }
102 189 : if (nIndex != pDescriptor->GetVisualState().mnPageId)
103 : {
104 0 : PrintModel(rModel);
105 : OSL_ASSERT(nIndex == pDescriptor->GetVisualState().mnPageId);
106 0 : return false;
107 : }
108 189 : }
109 :
110 157 : return true;
111 : }
112 : }
113 :
114 :
115 :
116 :
117 65 : SlideSorterModel::SlideSorterModel (SlideSorter& rSlideSorter)
118 : : maMutex(),
119 : mrSlideSorter(rSlideSorter),
120 : mxSlides(),
121 : mePageKind(PK_STANDARD),
122 : meEditMode(EM_PAGE),
123 65 : maPageDescriptors(0)
124 : {
125 65 : }
126 :
127 :
128 :
129 :
130 195 : SlideSorterModel::~SlideSorterModel (void)
131 : {
132 65 : ClearDescriptorList ();
133 130 : }
134 :
135 :
136 :
137 :
138 65 : void SlideSorterModel::Init (void)
139 : {
140 65 : }
141 :
142 :
143 :
144 :
145 65 : void SlideSorterModel::Dispose (void)
146 : {
147 65 : ClearDescriptorList ();
148 65 : }
149 :
150 :
151 :
152 :
153 2187 : SdDrawDocument* SlideSorterModel::GetDocument (void)
154 : {
155 2187 : if (mrSlideSorter.GetViewShellBase() != NULL)
156 2187 : return mrSlideSorter.GetViewShellBase()->GetDocument();
157 : else
158 0 : return NULL;
159 : }
160 :
161 :
162 :
163 :
164 0 : bool SlideSorterModel::SetEditMode (EditMode eEditMode)
165 : {
166 0 : bool bEditModeChanged = false;
167 0 : if (meEditMode != eEditMode)
168 : {
169 0 : meEditMode = eEditMode;
170 0 : UpdatePageList();
171 0 : ClearDescriptorList();
172 0 : bEditModeChanged = true;
173 : }
174 0 : return bEditModeChanged;
175 : }
176 :
177 :
178 :
179 :
180 1 : EditMode SlideSorterModel::GetEditMode (void) const
181 : {
182 1 : return meEditMode;
183 : }
184 :
185 :
186 :
187 :
188 1 : PageKind SlideSorterModel::GetPageType (void) const
189 : {
190 1 : return mePageKind;
191 : }
192 :
193 :
194 :
195 :
196 23499 : sal_Int32 SlideSorterModel::GetPageCount (void) const
197 : {
198 23499 : return maPageDescriptors.size();
199 : }
200 :
201 :
202 :
203 :
204 8985 : SharedPageDescriptor SlideSorterModel::GetPageDescriptor (
205 : const sal_Int32 nPageIndex,
206 : const bool bCreate) const
207 : {
208 8985 : ::osl::MutexGuard aGuard (maMutex);
209 :
210 8985 : SharedPageDescriptor pDescriptor;
211 :
212 8985 : if (nPageIndex>=0 && nPageIndex<GetPageCount())
213 : {
214 8609 : pDescriptor = maPageDescriptors[nPageIndex];
215 8609 : if (pDescriptor == 0 && bCreate && mxSlides.is())
216 : {
217 65 : SdPage* pPage = GetPage(nPageIndex);
218 : pDescriptor.reset(new PageDescriptor (
219 65 : Reference<drawing::XDrawPage>(mxSlides->getByIndex(nPageIndex),UNO_QUERY),
220 : pPage,
221 65 : nPageIndex));
222 65 : maPageDescriptors[nPageIndex] = pDescriptor;
223 : }
224 : }
225 :
226 8985 : return pDescriptor;
227 : }
228 :
229 :
230 :
231 :
232 138 : sal_Int32 SlideSorterModel::GetIndex (const Reference<drawing::XDrawPage>& rxSlide) const
233 : {
234 138 : ::osl::MutexGuard aGuard (maMutex);
235 :
236 : // First try to guess the right index.
237 276 : Reference<beans::XPropertySet> xSet (rxSlide, UNO_QUERY);
238 138 : if (xSet.is())
239 : {
240 : try
241 : {
242 138 : const Any aNumber (xSet->getPropertyValue("Number"));
243 138 : sal_Int16 nNumber (-1);
244 138 : aNumber >>= nNumber;
245 138 : nNumber -= 1;
246 138 : SharedPageDescriptor pDescriptor (GetPageDescriptor(nNumber, false));
247 414 : if (pDescriptor.get() != NULL
248 552 : && pDescriptor->GetXDrawPage() == rxSlide)
249 : {
250 138 : return nNumber;
251 0 : }
252 : }
253 0 : catch (uno::Exception&)
254 : {
255 : DBG_UNHANDLED_EXCEPTION();
256 : }
257 : }
258 :
259 : // Guess was wrong, iterate over all slides and search for the right
260 : // one.
261 0 : const sal_Int32 nCount (maPageDescriptors.size());
262 0 : for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
263 : {
264 0 : SharedPageDescriptor pDescriptor (maPageDescriptors[nIndex]);
265 :
266 : // Make sure that the descriptor exists. Without it the given slide
267 : // can not be found.
268 0 : if (pDescriptor.get() == NULL)
269 : {
270 : // Call GetPageDescriptor() to create the missing descriptor.
271 0 : pDescriptor = GetPageDescriptor(nIndex,true);
272 : }
273 :
274 0 : if (pDescriptor->GetXDrawPage() == rxSlide)
275 0 : return nIndex;
276 0 : }
277 :
278 138 : return -1;
279 : }
280 :
281 :
282 :
283 :
284 134 : sal_Int32 SlideSorterModel::GetIndex (const SdrPage* pPage) const
285 : {
286 134 : if (pPage == NULL)
287 0 : return -1;
288 :
289 134 : ::osl::MutexGuard aGuard (maMutex);
290 :
291 : // First try to guess the right index.
292 134 : sal_Int16 nNumber ((pPage->GetPageNum()-1)/2);
293 268 : SharedPageDescriptor pDescriptor (GetPageDescriptor(nNumber, false));
294 268 : if (pDescriptor.get() != NULL
295 134 : && pDescriptor->GetPage() == pPage)
296 : {
297 134 : return nNumber;
298 : }
299 :
300 : // Guess was wrong, iterate over all slides and search for the right
301 : // one.
302 0 : const sal_Int32 nCount (maPageDescriptors.size());
303 0 : for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
304 : {
305 0 : pDescriptor = maPageDescriptors[nIndex];
306 :
307 : // Make sure that the descriptor exists. Without it the given slide
308 : // can not be found.
309 0 : if (pDescriptor.get() == NULL)
310 : {
311 : // Call GetPageDescriptor() to create the missing descriptor.
312 0 : pDescriptor = GetPageDescriptor(nIndex, true);
313 : }
314 :
315 0 : if (pDescriptor->GetPage() == pPage)
316 0 : return nIndex;
317 : }
318 :
319 134 : return -1;
320 : }
321 :
322 :
323 :
324 :
325 0 : sal_uInt16 SlideSorterModel::GetCoreIndex (const sal_Int32 nIndex) const
326 : {
327 0 : SharedPageDescriptor pDescriptor (GetPageDescriptor(nIndex));
328 0 : if (pDescriptor)
329 0 : return pDescriptor->GetPage()->GetPageNum();
330 : else
331 0 : return mxSlides->getCount()*2+1;
332 : }
333 :
334 :
335 :
336 :
337 : /** For now this method uses a trivial algorithm: throw away all descriptors
338 : and create them anew (on demand). The main problem that we are facing
339 : when designing a better algorithm is that we can not compare pointers to
340 : pages stored in the PageDescriptor objects and those obtained from the
341 : document: pages may have been deleted and others may have been created
342 : at the exact same memory locations.
343 : */
344 146 : void SlideSorterModel::Resync (void)
345 : {
346 146 : ::osl::MutexGuard aGuard (maMutex);
347 :
348 : // Check if document and this model really differ.
349 146 : bool bIsUpToDate (true);
350 146 : SdDrawDocument* pDocument = GetDocument();
351 146 : if (pDocument!=NULL && maPageDescriptors.size()==pDocument->GetSdPageCount(mePageKind))
352 : {
353 178 : for (sal_Int32 nIndex=0,nCount=maPageDescriptors.size(); nIndex<nCount; ++nIndex)
354 : {
355 194 : if (maPageDescriptors[nIndex]
356 194 : && maPageDescriptors[nIndex]->GetPage()
357 194 : != GetPage(nIndex))
358 : {
359 : OSL_TRACE("page %d differs", nIndex);
360 0 : bIsUpToDate = false;
361 0 : break;
362 : }
363 : }
364 : }
365 : else
366 : {
367 65 : bIsUpToDate = false;
368 : OSL_TRACE("models differ");
369 : }
370 :
371 146 : if ( ! bIsUpToDate)
372 : {
373 65 : SynchronizeDocumentSelection(); // Try to make the current selection persistent.
374 65 : ClearDescriptorList ();
375 65 : AdaptSize();
376 65 : SynchronizeModelSelection();
377 65 : mrSlideSorter.GetController().GetPageSelector().CountSelectedPages();
378 : }
379 146 : CheckModel(*this);
380 146 : }
381 :
382 :
383 :
384 :
385 195 : void SlideSorterModel::ClearDescriptorList (void)
386 : {
387 195 : DescriptorContainer aDescriptors;
388 :
389 : {
390 195 : ::osl::MutexGuard aGuard (maMutex);
391 195 : aDescriptors.swap(maPageDescriptors);
392 : }
393 :
394 269 : for (DescriptorContainer::iterator iDescriptor=aDescriptors.begin(), iEnd=aDescriptors.end();
395 : iDescriptor!=iEnd;
396 : ++iDescriptor)
397 : {
398 74 : if (iDescriptor->get() != NULL)
399 : {
400 74 : if ( ! iDescriptor->unique())
401 : {
402 : OSL_TRACE("SlideSorterModel::ClearDescriptorList: trying to delete page descriptor that is still used with count %d", iDescriptor->use_count());
403 : // No assertion here because that can hang the office when
404 : // opening a dialog from here.
405 : }
406 74 : iDescriptor->reset();
407 : }
408 195 : }
409 195 : }
410 :
411 :
412 :
413 :
414 65 : void SlideSorterModel::SynchronizeDocumentSelection (void)
415 : {
416 65 : ::osl::MutexGuard aGuard (maMutex);
417 :
418 130 : PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
419 130 : while (aAllPages.HasMoreElements())
420 : {
421 0 : SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
422 0 : pDescriptor->GetPage()->SetSelected(pDescriptor->HasState(PageDescriptor::ST_Selected));
423 65 : }
424 65 : }
425 :
426 :
427 :
428 :
429 65 : void SlideSorterModel::SynchronizeModelSelection (void)
430 : {
431 65 : ::osl::MutexGuard aGuard (maMutex);
432 :
433 130 : PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
434 195 : while (aAllPages.HasMoreElements())
435 : {
436 65 : SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
437 65 : pDescriptor->SetState(PageDescriptor::ST_Selected, pDescriptor->GetPage()->IsSelected());
438 130 : }
439 65 : }
440 :
441 :
442 :
443 :
444 146 : ::osl::Mutex& SlideSorterModel::GetMutex (void)
445 : {
446 146 : return maMutex;
447 : }
448 :
449 :
450 :
451 :
452 65 : void SlideSorterModel::SetDocumentSlides (
453 : const Reference<container::XIndexAccess>& rxSlides)
454 : {
455 65 : ::osl::MutexGuard aGuard (maMutex);
456 :
457 : // Reset the current page so to cause everbody to release references to it.
458 65 : mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(-1);
459 :
460 65 : mxSlides = rxSlides;
461 65 : Resync();
462 :
463 65 : ViewShell* pViewShell = mrSlideSorter.GetViewShell();
464 65 : if (pViewShell != NULL)
465 : {
466 65 : SdPage* pPage = pViewShell->getCurrentPage();
467 65 : if (pPage != NULL)
468 65 : mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
469 65 : pPage);
470 : else
471 : {
472 : // No current page. This can only be when the slide sorter is
473 : // the main view shell. Get current slide form frame view.
474 0 : const FrameView* pFrameView = pViewShell->GetFrameView();
475 0 : if (pFrameView != NULL)
476 0 : mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
477 0 : pFrameView->GetSelectedPage());
478 : else
479 : {
480 : // No frame view. As a last resort use the first slide as
481 : // current slide.
482 0 : mrSlideSorter.GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
483 0 : sal_Int32(0));
484 : }
485 : }
486 : }
487 :
488 65 : mrSlideSorter.GetController().GetSlotManager()->NotifyEditModeChange();
489 65 : }
490 :
491 :
492 :
493 :
494 65 : Reference<container::XIndexAccess> SlideSorterModel::GetDocumentSlides (void) const
495 : {
496 65 : ::osl::MutexGuard aGuard (maMutex);
497 65 : return mxSlides;
498 : }
499 :
500 :
501 :
502 :
503 65 : void SlideSorterModel::UpdatePageList (void)
504 : {
505 65 : ::osl::MutexGuard aGuard (maMutex);
506 :
507 130 : Reference<container::XIndexAccess> xPages;
508 :
509 : // Get the list of pages according to the edit mode.
510 130 : Reference<frame::XController> xController (mrSlideSorter.GetXController());
511 65 : if (xController.is())
512 : {
513 65 : switch (meEditMode)
514 : {
515 : case EM_MASTERPAGE:
516 : {
517 : Reference<drawing::XMasterPagesSupplier> xSupplier (
518 0 : xController->getModel(), UNO_QUERY);
519 0 : if (xSupplier.is())
520 : {
521 0 : xPages = Reference<container::XIndexAccess>(
522 0 : xSupplier->getMasterPages(), UNO_QUERY);
523 0 : }
524 : }
525 0 : break;
526 :
527 : case EM_PAGE:
528 : {
529 : Reference<drawing::XDrawPagesSupplier> xSupplier (
530 65 : xController->getModel(), UNO_QUERY);
531 65 : if (xSupplier.is())
532 : {
533 130 : xPages = Reference<container::XIndexAccess>(
534 130 : xSupplier->getDrawPages(), UNO_QUERY);
535 65 : }
536 : }
537 65 : break;
538 :
539 : default:
540 : // We should never get here.
541 : OSL_ASSERT(false);
542 0 : break;
543 : }
544 : }
545 :
546 130 : mrSlideSorter.GetController().SetDocumentSlides(xPages);
547 65 : }
548 :
549 :
550 :
551 :
552 65 : void SlideSorterModel::AdaptSize (void)
553 : {
554 65 : if (mxSlides.is())
555 65 : maPageDescriptors.resize(mxSlides->getCount());
556 : else
557 0 : maPageDescriptors.resize(0);
558 65 : }
559 :
560 :
561 :
562 :
563 65 : bool SlideSorterModel::IsReadOnly (void) const
564 : {
565 130 : if (mrSlideSorter.GetViewShellBase() != NULL
566 65 : && mrSlideSorter.GetViewShellBase()->GetDocShell())
567 65 : return mrSlideSorter.GetViewShellBase()->GetDocShell()->IsReadOnly();
568 : else
569 0 : return true;
570 : }
571 :
572 :
573 :
574 :
575 0 : void SlideSorterModel::SaveCurrentSelection (void)
576 : {
577 0 : PageEnumeration aPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
578 0 : while (aPages.HasMoreElements())
579 : {
580 0 : SharedPageDescriptor pDescriptor (aPages.GetNextElement());
581 : pDescriptor->SetState(
582 : PageDescriptor::ST_WasSelected,
583 0 : pDescriptor->HasState(PageDescriptor::ST_Selected));
584 0 : }
585 0 : }
586 :
587 :
588 :
589 :
590 0 : Region SlideSorterModel::RestoreSelection (void)
591 : {
592 0 : Region aRepaintRegion;
593 0 : PageEnumeration aPages (PageEnumerationProvider::CreateAllPagesEnumeration(*this));
594 0 : while (aPages.HasMoreElements())
595 : {
596 0 : SharedPageDescriptor pDescriptor (aPages.GetNextElement());
597 0 : if (pDescriptor->SetState(
598 : PageDescriptor::ST_Selected,
599 0 : pDescriptor->HasState(PageDescriptor::ST_WasSelected)))
600 : {
601 0 : aRepaintRegion.Union(pDescriptor->GetBoundingBox());
602 : }
603 0 : }
604 0 : return aRepaintRegion;
605 : }
606 :
607 :
608 :
609 :
610 60 : bool SlideSorterModel::NotifyPageEvent (const SdrPage* pSdrPage)
611 : {
612 60 : ::osl::MutexGuard aGuard (maMutex);
613 :
614 60 : SdPage* pPage = const_cast<SdPage*>(dynamic_cast<const SdPage*>(pSdrPage));
615 60 : if (pPage == NULL)
616 0 : return false;
617 :
618 : // We are only interested in pages that are currently served by this
619 : // model.
620 60 : if (pPage->GetPageKind() != mePageKind)
621 16 : return false;
622 44 : if (pPage->IsMasterPage() != (meEditMode==EM_MASTERPAGE))
623 33 : return false;
624 :
625 11 : if (pPage->IsInserted())
626 10 : InsertSlide(pPage);
627 : else
628 1 : DeleteSlide(pPage);
629 11 : CheckModel(*this);
630 :
631 11 : return true;
632 : }
633 :
634 :
635 :
636 :
637 10 : void SlideSorterModel::InsertSlide (SdPage* pPage)
638 : {
639 : // Find the index at which to insert the given page.
640 10 : sal_uInt16 nCoreIndex (pPage->GetPageNum());
641 10 : sal_Int32 nIndex (FromCoreIndex(nCoreIndex));
642 10 : if (pPage != GetPage(nIndex))
643 0 : return;
644 :
645 : // Check that the pages in the document before and after the given page
646 : // are present in this model.
647 10 : if (nIndex>0)
648 10 : if (GetPage(nIndex-1) != GetPageDescriptor(nIndex-1)->GetPage())
649 0 : return;
650 10 : if (size_t(nIndex)<maPageDescriptors.size()-1)
651 1 : if (GetPage(nIndex+1) != GetPageDescriptor(nIndex)->GetPage())
652 0 : return;
653 :
654 : // Insert the given page at index nIndex
655 : maPageDescriptors.insert(
656 10 : maPageDescriptors.begin()+nIndex,
657 : SharedPageDescriptor(
658 : new PageDescriptor (
659 10 : Reference<drawing::XDrawPage>(mxSlides->getByIndex(nIndex),UNO_QUERY),
660 : pPage,
661 20 : nIndex)));
662 :
663 : // Update page indices.
664 10 : UpdateIndices(nIndex+1);
665 : OSL_TRACE("page inserted");
666 : }
667 :
668 :
669 :
670 :
671 1 : void SlideSorterModel::DeleteSlide (const SdPage* pPage)
672 : {
673 1 : sal_Int32 nIndex(0);
674 :
675 : // Caution, GetIndex() may be negative since it uses GetPageNumber()-1
676 : // for calculation, so do this only when page is inserted, else the
677 : // GetPageNumber() will be zero and thus GetIndex() == -1
678 1 : if(pPage->IsInserted())
679 : {
680 0 : nIndex = GetIndex(pPage);
681 : }
682 : else
683 : {
684 : // if not inserted, search for page
685 2 : for(; nIndex < static_cast<sal_Int32>(maPageDescriptors.size()); nIndex++)
686 : {
687 2 : if(maPageDescriptors[nIndex]->GetPage() == pPage)
688 : {
689 1 : break;
690 : }
691 : }
692 : }
693 :
694 1 : if(nIndex >= 0 && nIndex < static_cast<sal_Int32>(maPageDescriptors.size()))
695 : {
696 1 : if (maPageDescriptors[nIndex])
697 1 : if (maPageDescriptors[nIndex]->GetPage() != pPage)
698 1 : return;
699 :
700 1 : maPageDescriptors.erase(maPageDescriptors.begin()+nIndex);
701 1 : UpdateIndices(nIndex);
702 : }
703 : OSL_TRACE("page removed");
704 : }
705 :
706 :
707 :
708 :
709 11 : void SlideSorterModel::UpdateIndices (const sal_Int32 nFirstIndex)
710 : {
711 38 : for (sal_Int32 nDescriptorIndex=0,nCount=maPageDescriptors.size();
712 : nDescriptorIndex<nCount;
713 : ++nDescriptorIndex)
714 : {
715 27 : SharedPageDescriptor& rpDescriptor (maPageDescriptors[nDescriptorIndex]);
716 27 : if (rpDescriptor)
717 : {
718 27 : if (nDescriptorIndex < nFirstIndex)
719 : {
720 22 : if (rpDescriptor->GetPageIndex()!=nDescriptorIndex)
721 : {
722 : OSL_ASSERT(rpDescriptor->GetPageIndex()==nDescriptorIndex);
723 : }
724 : }
725 : else
726 : {
727 5 : rpDescriptor->SetPageIndex(nDescriptorIndex);
728 : }
729 : }
730 : }
731 11 : }
732 :
733 :
734 :
735 :
736 183 : SdPage* SlideSorterModel::GetPage (const sal_Int32 nSdIndex) const
737 : {
738 183 : SdDrawDocument* pModel = const_cast<SlideSorterModel*>(this)->GetDocument();
739 183 : if (pModel != NULL)
740 : {
741 183 : if (meEditMode == EM_PAGE)
742 183 : return pModel->GetSdPage ((sal_uInt16)nSdIndex, mePageKind);
743 : else
744 0 : return pModel->GetMasterSdPage ((sal_uInt16)nSdIndex, mePageKind);
745 : }
746 : else
747 0 : return NULL;
748 : }
749 :
750 :
751 33 : } } } // end of namespace ::sd::slidesorter::model
752 :
753 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|