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