Update ooo320-m1
[ooovba.git] / sd / source / ui / view / OutlinerIterator.cxx
blobd19a260963750c5d12f4b51e38cc1544c9d67c7d
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: OutlinerIterator.cxx,v $
10 * $Revision: 1.9 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "OutlinerIterator.hxx"
35 #include "OutlinerIteratorImpl.hxx"
36 #include <svx/svditer.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include "Outliner.hxx"
41 #include "drawdoc.hxx"
42 #include "DrawViewShell.hxx"
43 #include "drawview.hxx"
44 #include "sdpage.hxx"
45 #ifndef SD_FRAME_VIEW
46 #include "FrameView.hxx"
47 #endif
48 #include "DrawDocShell.hxx"
49 #include "Window.hxx"
51 namespace sd { namespace outliner {
54 //===== IteratorPosition ======================================================
56 IteratorPosition::IteratorPosition (void)
57 : mnText(0)
58 , mnPageIndex(-1)
59 , mePageKind(PK_STANDARD)
60 , meEditMode(EM_PAGE)
64 IteratorPosition::IteratorPosition (const IteratorPosition& aPosition)
65 : mxObject(aPosition.mxObject)
66 , mnText(aPosition.mnText)
67 , mnPageIndex(aPosition.mnPageIndex)
68 , mePageKind(aPosition.mePageKind)
69 , meEditMode(aPosition.meEditMode)
73 IteratorPosition::IteratorPosition (SdrObject* pObject, sal_Int32 nText, sal_Int32 nPageIndex, PageKind ePageKind, EditMode eEditMode)
74 : mxObject(pObject)
75 , mnText(nText)
76 , mnPageIndex(nPageIndex)
77 , mePageKind(ePageKind)
78 , meEditMode(eEditMode)
82 IteratorPosition::~IteratorPosition (void)
86 IteratorPosition& IteratorPosition::operator= (const IteratorPosition& aPosition)
88 mxObject = aPosition.mxObject;
89 mnText = aPosition.mnText;
90 mnPageIndex = aPosition.mnPageIndex;
91 mePageKind = aPosition.mePageKind;
92 meEditMode = aPosition.meEditMode;
93 return *this;
96 bool IteratorPosition::operator== (const IteratorPosition& aPosition) const
98 return mxObject.get() == aPosition.mxObject.get()
99 && mnText == aPosition.mnText
100 && mnPageIndex == aPosition.mnPageIndex
101 && mePageKind == aPosition.mePageKind
102 && meEditMode == aPosition.meEditMode;
108 //===== Iterator ==============================================================
110 Iterator::Iterator (void)
112 mpIterator = NULL;
115 Iterator::Iterator (const Iterator& rIterator)
117 mpIterator = rIterator.mpIterator->Clone();
120 Iterator::Iterator (IteratorImplBase* pObject)
122 mpIterator = pObject;
125 Iterator::Iterator (const IteratorImplBase& rObject)
127 mpIterator = rObject.Clone();
130 Iterator::~Iterator (void)
132 delete mpIterator;
135 Iterator& Iterator::operator= (const Iterator& rIterator)
137 if (this != &rIterator)
139 delete mpIterator;
140 if (rIterator.mpIterator != NULL)
141 mpIterator = rIterator.mpIterator->Clone();
142 else
143 mpIterator = NULL;
145 return *this;
148 const IteratorPosition& Iterator::operator* () const
150 DBG_ASSERT (mpIterator!=NULL, "::sd::outliner::Iterator::operator* : missing implementation object");
151 return mpIterator->GetPosition();
154 Iterator& Iterator::operator++ ()
156 if (mpIterator!=NULL)
157 mpIterator->GotoNextText();
158 return *this;
161 Iterator Iterator::operator++ (int)
163 Iterator aTmp (*this);
164 if (mpIterator!=NULL)
165 mpIterator->GotoNextText();
166 return aTmp;
169 bool Iterator::operator== (const Iterator& rIterator)
171 if (mpIterator == NULL || rIterator.mpIterator==NULL)
172 return mpIterator == rIterator.mpIterator;
173 else
174 return *mpIterator == *rIterator.mpIterator;
177 bool Iterator::operator!= (const Iterator& rIterator)
179 return ! operator==(rIterator);
182 void Iterator::Reverse (void)
184 if (mpIterator != NULL)
185 mpIterator->Reverse();
188 //===== IteratorFactory =======================================================
190 OutlinerContainer::OutlinerContainer (Outliner* pOutliner)
191 : mpOutliner(pOutliner)
195 Iterator OutlinerContainer::begin (void)
197 return CreateIterator (BEGIN);
200 Iterator OutlinerContainer::end (void)
202 return CreateIterator (END);
205 Iterator OutlinerContainer::current (void)
207 return CreateIterator (CURRENT);
211 Iterator OutlinerContainer::CreateIterator (IteratorLocation aLocation)
213 // Decide on certain features of the outliner which kind of iterator to
214 // use.
215 if (mpOutliner->mbRestrictSearchToSelection)
216 // There is a selection. Search only in this.
217 return CreateSelectionIterator (
218 mpOutliner->maMarkListCopy,
219 mpOutliner->mpDrawDocument,
220 mpOutliner->mpViewShell,
221 mpOutliner->mbDirectionIsForward,
222 aLocation);
223 else
224 // Search in the whole document.
225 return CreateDocumentIterator (
226 mpOutliner->mpDrawDocument,
227 mpOutliner->mpViewShell,
228 mpOutliner->mbDirectionIsForward,
229 aLocation);
232 Iterator OutlinerContainer::CreateSelectionIterator (
233 const ::std::vector<SdrObjectWeakRef>& rObjectList,
234 SdDrawDocument* pDocument,
235 const ::boost::shared_ptr<ViewShell>& rpViewShell,
236 bool bDirectionIsForward,
237 IteratorLocation aLocation)
239 OSL_ASSERT(rpViewShell.get());
241 sal_Int32 nObjectIndex;
243 if (bDirectionIsForward)
244 switch (aLocation)
246 case CURRENT:
247 case BEGIN:
248 default:
249 nObjectIndex = 0;
250 break;
251 case END:
252 nObjectIndex = rObjectList.size();
253 break;
255 else
256 switch (aLocation)
258 case CURRENT:
259 case BEGIN:
260 default:
261 nObjectIndex = rObjectList.size()-1;
262 break;
263 case END:
264 nObjectIndex = -1;
265 break;
268 return Iterator (new SelectionIteratorImpl (
269 rObjectList, nObjectIndex, pDocument, rpViewShell, bDirectionIsForward));
272 Iterator OutlinerContainer::CreateViewIterator (
273 SdDrawDocument* pDocument,
274 const ::boost::shared_ptr<ViewShell>& rpViewShell,
275 bool bDirectionIsForward,
276 IteratorLocation aLocation)
278 OSL_ASSERT(rpViewShell.get());
280 const ::boost::shared_ptr<DrawViewShell> pDrawViewShell(
281 ::boost::dynamic_pointer_cast<DrawViewShell>(rpViewShell));
282 sal_Int32 nPageIndex = GetPageIndex (
283 pDocument,
284 rpViewShell,
285 pDrawViewShell.get() ? pDrawViewShell->GetPageKind() : PK_STANDARD,
286 pDrawViewShell.get() ? pDrawViewShell->GetEditMode() : EM_PAGE,
287 bDirectionIsForward,
288 aLocation);
290 return Iterator (new ViewIteratorImpl (
291 nPageIndex, pDocument, rpViewShell, bDirectionIsForward));
294 Iterator OutlinerContainer::CreateDocumentIterator (
295 SdDrawDocument* pDocument,
296 const ::boost::shared_ptr<ViewShell>& rpViewShell,
297 bool bDirectionIsForward,
298 IteratorLocation aLocation)
300 OSL_ASSERT(rpViewShell.get());
302 PageKind ePageKind;
303 EditMode eEditMode;
305 switch (aLocation)
307 case BEGIN:
308 default:
309 if (bDirectionIsForward)
311 ePageKind = PK_STANDARD;
312 eEditMode = EM_PAGE;
314 else
316 ePageKind = PK_HANDOUT;
317 eEditMode = EM_MASTERPAGE;
319 break;
321 case END:
322 if (bDirectionIsForward)
324 ePageKind = PK_HANDOUT;
325 eEditMode = EM_MASTERPAGE;
327 else
329 ePageKind = PK_STANDARD;
330 eEditMode = EM_PAGE;
332 break;
334 case CURRENT:
335 const ::boost::shared_ptr<DrawViewShell> pDrawViewShell(
336 ::boost::dynamic_pointer_cast<DrawViewShell>(rpViewShell));
337 if (pDrawViewShell.get())
339 ePageKind = pDrawViewShell->GetPageKind();
340 eEditMode = pDrawViewShell->GetEditMode();
342 else
344 ePageKind = PK_STANDARD;
345 eEditMode = EM_PAGE;
347 break;
350 sal_Int32 nPageIndex = GetPageIndex (pDocument, rpViewShell,
351 ePageKind, eEditMode, bDirectionIsForward, aLocation);
353 return Iterator (
354 new DocumentIteratorImpl (nPageIndex, ePageKind, eEditMode,
355 pDocument, rpViewShell, bDirectionIsForward));
358 sal_Int32 OutlinerContainer::GetPageIndex (
359 SdDrawDocument* pDocument,
360 const ::boost::shared_ptr<ViewShell>& rpViewShell,
361 PageKind ePageKind,
362 EditMode eEditMode,
363 bool bDirectionIsForward,
364 IteratorLocation aLocation)
366 OSL_ASSERT(rpViewShell);
368 sal_Int32 nPageIndex;
369 sal_Int32 nPageCount;
371 const ::boost::shared_ptr<DrawViewShell> pDrawViewShell(
372 ::boost::dynamic_pointer_cast<DrawViewShell>(rpViewShell));
374 switch (eEditMode)
376 case EM_PAGE:
377 nPageCount = pDocument->GetSdPageCount (ePageKind);
378 break;
379 case EM_MASTERPAGE:
380 nPageCount = pDocument->GetMasterSdPageCount(ePageKind);
381 break;
382 default:
383 nPageCount = 0;
386 switch (aLocation)
388 case CURRENT:
389 if (pDrawViewShell.get())
390 nPageIndex = pDrawViewShell->GetCurPageId() - 1;
391 else
393 const SdPage* pPage = rpViewShell->GetActualPage();
394 if (pPage != NULL)
395 nPageIndex = (pPage->GetPageNum()-1)/2;
396 else
397 nPageIndex = 0;
399 break;
401 case BEGIN:
402 default:
403 if (bDirectionIsForward)
404 nPageIndex = 0;
405 else
406 nPageIndex = nPageCount-1;
407 break;
409 case END:
410 if (bDirectionIsForward)
411 nPageIndex = nPageCount;
412 else
413 nPageIndex = -1;
414 break;
417 return nPageIndex;
423 //===== IteratorImplBase ====================================================
425 IteratorImplBase::IteratorImplBase(SdDrawDocument* pDocument,
426 const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
427 bool bDirectionIsForward)
428 : maPosition()
429 , mpDocument (pDocument)
430 , mpViewShellWeak (rpViewShellWeak)
431 , mbDirectionIsForward (bDirectionIsForward)
433 ::boost::shared_ptr<DrawViewShell> pDrawViewShell;
434 if ( ! mpViewShellWeak.expired())
435 pDrawViewShell = ::boost::dynamic_pointer_cast<DrawViewShell>(rpViewShellWeak.lock());
437 if (pDrawViewShell.get())
439 maPosition.mePageKind = pDrawViewShell->GetPageKind();
440 maPosition.meEditMode = pDrawViewShell->GetEditMode();
442 else
444 maPosition.mePageKind = PK_STANDARD;
445 maPosition.meEditMode = EM_PAGE;
449 IteratorImplBase::IteratorImplBase( SdDrawDocument* pDocument,
450 const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
451 bool bDirectionIsForward, PageKind ePageKind, EditMode eEditMode)
452 : maPosition()
453 , mpDocument (pDocument)
454 , mpViewShellWeak (rpViewShellWeak)
455 , mbDirectionIsForward (bDirectionIsForward)
457 maPosition.mePageKind = ePageKind;
458 maPosition.meEditMode = eEditMode;
461 IteratorImplBase::~IteratorImplBase (void)
464 bool IteratorImplBase::operator== (const IteratorImplBase& rIterator) const
466 return maPosition == rIterator.maPosition;
469 bool IteratorImplBase::IsEqual (const IteratorImplBase& rIterator, IteratorType ) const
471 // When this method is executed instead of the ones from derived classes
472 // then the argument is of another type then the object itself. In this
473 // just compare the position objects.
474 return maPosition == rIterator.maPosition;
477 const IteratorPosition& IteratorImplBase::GetPosition (void)
479 return maPosition;
485 IteratorImplBase* IteratorImplBase::Clone (IteratorImplBase* pObject) const
487 if (pObject != NULL)
489 pObject->maPosition = maPosition;
490 pObject->mpDocument = mpDocument;
491 pObject->mpViewShellWeak = mpViewShellWeak;
492 pObject->mbDirectionIsForward = mbDirectionIsForward;
494 return pObject;
499 void IteratorImplBase::Reverse (void)
501 mbDirectionIsForward = ! mbDirectionIsForward;
506 //===== SelectionIteratorImpl ===========================================
508 SelectionIteratorImpl::SelectionIteratorImpl (
509 const ::std::vector<SdrObjectWeakRef>& rObjectList,
510 sal_Int32 nObjectIndex,
511 SdDrawDocument* pDocument,
512 const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
513 bool bDirectionIsForward)
514 : IteratorImplBase (pDocument, rpViewShellWeak, bDirectionIsForward),
515 mrObjectList(rObjectList),
516 mnObjectIndex(nObjectIndex)
520 SelectionIteratorImpl::~SelectionIteratorImpl (void)
523 IteratorImplBase* SelectionIteratorImpl::Clone (IteratorImplBase* pObject) const
525 SelectionIteratorImpl* pIterator = static_cast<SelectionIteratorImpl*>(pObject);
526 if (pIterator == NULL)
527 pIterator = new SelectionIteratorImpl (
528 mrObjectList, mnObjectIndex, mpDocument, mpViewShellWeak, mbDirectionIsForward);
529 return pIterator;
533 void SelectionIteratorImpl::GotoNextText (void)
535 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( mrObjectList.at(mnObjectIndex).get() );
536 if (mbDirectionIsForward)
538 if( pTextObj )
540 ++maPosition.mnText;
541 if( maPosition.mnText >= pTextObj->getTextCount() )
543 maPosition.mnText = 0;
544 ++mnObjectIndex;
547 else
549 ++mnObjectIndex;
552 else
554 if( pTextObj )
556 --maPosition.mnText;
557 if( maPosition.mnText < 0 )
559 maPosition.mnText = -1;
560 --mnObjectIndex;
563 else
565 --mnObjectIndex;
566 maPosition.mnText = -1;
569 if( (maPosition.mnText == -1) && (mnObjectIndex >= 0) )
571 pTextObj = dynamic_cast< SdrTextObj* >( mrObjectList.at(mnObjectIndex).get() );
572 if( pTextObj )
573 maPosition.mnText = pTextObj->getTextCount() - 1;
576 if( maPosition.mnText == -1 )
577 maPosition.mnText = 0;
582 const IteratorPosition& SelectionIteratorImpl::GetPosition (void)
584 maPosition.mxObject = mrObjectList.at(mnObjectIndex);
586 return maPosition;
590 bool SelectionIteratorImpl::operator== (const IteratorImplBase& rIterator) const
592 return rIterator.IsEqual (*this, SELECTION);
596 bool SelectionIteratorImpl::IsEqual (
597 const IteratorImplBase& rIterator,
598 IteratorType aType) const
600 if (aType == SELECTION)
602 const SelectionIteratorImpl* pSelectionIterator =
603 static_cast<const SelectionIteratorImpl*>(&rIterator);
604 return mpDocument == pSelectionIterator->mpDocument
605 && mnObjectIndex == pSelectionIterator->mnObjectIndex;
607 else
608 return false;
614 //===== ViewIteratorImpl ================================================
616 ViewIteratorImpl::ViewIteratorImpl (
617 sal_Int32 nPageIndex,
618 SdDrawDocument* pDocument,
619 const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
620 bool bDirectionIsForward)
621 : IteratorImplBase (pDocument, rpViewShellWeak, bDirectionIsForward),
622 mbPageChangeOccured(false),
623 mpPage(NULL),
624 mpObjectIterator(NULL)
626 SetPage (nPageIndex);
632 ViewIteratorImpl::ViewIteratorImpl (
633 sal_Int32 nPageIndex,
634 SdDrawDocument* pDocument,
635 const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
636 bool bDirectionIsForward,
637 PageKind ePageKind,
638 EditMode eEditMode)
639 : IteratorImplBase (pDocument, rpViewShellWeak, bDirectionIsForward, ePageKind, eEditMode),
640 mbPageChangeOccured(false),
641 mpPage(NULL),
642 mpObjectIterator(NULL)
644 SetPage (nPageIndex);
650 ViewIteratorImpl::~ViewIteratorImpl (void)
657 IteratorImplBase* ViewIteratorImpl::Clone (IteratorImplBase* pObject) const
660 ViewIteratorImpl* pIterator = static_cast<ViewIteratorImpl*>(pObject);
661 if (pIterator == NULL)
662 pIterator = new ViewIteratorImpl (
663 maPosition.mnPageIndex, mpDocument, mpViewShellWeak, mbDirectionIsForward);
665 IteratorImplBase::Clone (pObject);
667 if (mpObjectIterator != NULL)
669 pIterator->mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, !mbDirectionIsForward);
671 // No direct way to set the object iterator to the current object.
672 pIterator->maPosition.mxObject.reset(NULL);
673 while (pIterator->mpObjectIterator->IsMore() && pIterator->maPosition.mxObject!=maPosition.mxObject)
674 pIterator->maPosition.mxObject.reset(pIterator->mpObjectIterator->Next());
676 else
677 pIterator->mpObjectIterator = NULL;
679 return pIterator;
684 void ViewIteratorImpl::GotoNextText(void)
686 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( maPosition.mxObject.get() );
687 if( pTextObj )
689 if (mbDirectionIsForward)
691 ++maPosition.mnText;
692 if( maPosition.mnText < pTextObj->getTextCount() )
693 return;
695 else
697 --maPosition.mnText;
698 if( maPosition.mnText >= 0 )
699 return;
703 if (mpObjectIterator != NULL && mpObjectIterator->IsMore())
704 maPosition.mxObject.reset(mpObjectIterator->Next());
705 else
706 maPosition.mxObject.reset(NULL);
708 if (!maPosition.mxObject.is() )
710 if (mbDirectionIsForward)
711 SetPage (maPosition.mnPageIndex+1);
712 else
713 SetPage (maPosition.mnPageIndex-1);
715 if (mpPage != NULL)
716 mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, !mbDirectionIsForward);
717 if (mpObjectIterator!=NULL && mpObjectIterator->IsMore())
718 maPosition.mxObject.reset(mpObjectIterator->Next());
719 else
720 maPosition.mxObject.reset(NULL);
723 maPosition.mnText = 0;
724 if( !mbDirectionIsForward && maPosition.mxObject.is() )
726 pTextObj = dynamic_cast< SdrTextObj* >( maPosition.mxObject.get() );
727 if( pTextObj )
728 maPosition.mnText = pTextObj->getTextCount() - 1;
735 void ViewIteratorImpl::SetPage (sal_Int32 nPageIndex)
737 mbPageChangeOccured = (maPosition.mnPageIndex!=nPageIndex);
738 if (mbPageChangeOccured)
740 maPosition.mnPageIndex = nPageIndex;
742 sal_Int32 nPageCount;
743 if (maPosition.meEditMode == EM_PAGE)
744 nPageCount = mpDocument->GetSdPageCount(maPosition.mePageKind);
745 else
746 nPageCount = mpDocument->GetMasterSdPageCount(
747 maPosition.mePageKind);
749 // Get page pointer. Here we have three cases: regular pages,
750 // master pages and invalid page indices. The later ones are not
751 // errors but the effect of the iterator advancing to the next page
752 // and going past the last one. This dropping of the rim at the far
753 // side is detected here and has to be reacted to by the caller.
754 if (nPageIndex>=0 && nPageIndex < nPageCount)
756 if (maPosition.meEditMode == EM_PAGE)
757 mpPage = mpDocument->GetSdPage (
758 (USHORT)nPageIndex,
759 maPosition.mePageKind);
760 else
761 mpPage = mpDocument->GetMasterSdPage (
762 (USHORT)nPageIndex,
763 maPosition.mePageKind);
765 else
766 mpPage = NULL;
769 // Set up object list iterator.
770 if (mpPage != NULL)
771 mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, ! mbDirectionIsForward);
772 else
773 mpObjectIterator = NULL;
775 // Get object pointer.
776 if (mpObjectIterator!=NULL && mpObjectIterator->IsMore())
777 maPosition.mxObject.reset( mpObjectIterator->Next() );
778 else
779 maPosition.mxObject.reset( NULL );
781 maPosition.mnText = 0;
782 if( !mbDirectionIsForward && maPosition.mxObject.is() )
784 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( maPosition.mxObject.get() );
785 if( pTextObj )
786 maPosition.mnText = pTextObj->getTextCount() - 1;
794 void ViewIteratorImpl::Reverse (void)
796 IteratorImplBase::Reverse ();
798 // Create reversed object list iterator.
799 if (mpObjectIterator != NULL)
800 delete mpObjectIterator;
801 if (mpPage != NULL)
802 mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, ! mbDirectionIsForward);
803 else
804 mpObjectIterator = NULL;
806 // Move iterator to the current object.
807 SdrObjectWeakRef xObject = maPosition.mxObject;
808 maPosition.mxObject.reset(NULL);
809 while (mpObjectIterator->IsMore() && maPosition.mxObject != xObject)
810 maPosition.mxObject.reset(mpObjectIterator->Next());
816 //===== DocumentIteratorImpl ============================================
818 DocumentIteratorImpl::DocumentIteratorImpl (
819 sal_Int32 nPageIndex,
820 PageKind ePageKind, EditMode eEditMode,
821 SdDrawDocument* pDocument,
822 const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
823 bool bDirectionIsForward)
824 : ViewIteratorImpl (nPageIndex, pDocument, rpViewShellWeak, bDirectionIsForward,
825 ePageKind, eEditMode)
827 if (eEditMode == EM_PAGE)
828 mnPageCount = pDocument->GetSdPageCount (ePageKind);
829 else
830 mnPageCount = pDocument->GetMasterSdPageCount(ePageKind);
836 DocumentIteratorImpl::~DocumentIteratorImpl (void)
842 IteratorImplBase* DocumentIteratorImpl::Clone (IteratorImplBase* pObject) const
844 DocumentIteratorImpl* pIterator = static_cast<DocumentIteratorImpl*>(pObject);
845 if (pIterator == NULL)
846 pIterator = new DocumentIteratorImpl (
847 maPosition.mnPageIndex, maPosition.mePageKind, maPosition.meEditMode,
848 mpDocument, mpViewShellWeak, mbDirectionIsForward);
849 // Finish the cloning.
850 return ViewIteratorImpl::Clone (pIterator);
856 void DocumentIteratorImpl::GotoNextText (void)
858 bool bSetToOnePastLastPage = false;
859 bool bViewChanged = false;
861 ViewIteratorImpl::GotoNextText();
863 if (mbDirectionIsForward)
865 if (maPosition.mnPageIndex >= mnPageCount)
867 // Switch to master page.
868 if (maPosition.meEditMode == EM_PAGE)
870 maPosition.meEditMode = EM_MASTERPAGE;
871 SetPage (0);
874 // Switch to next view mode.
875 else
877 if (maPosition.mePageKind == PK_HANDOUT)
878 // Not really necessary but makes things more clear.
879 bSetToOnePastLastPage = true;
880 else
882 maPosition.meEditMode = EM_PAGE;
883 if (maPosition.mePageKind == PK_STANDARD)
884 maPosition.mePageKind = PK_NOTES;
885 else if (maPosition.mePageKind == PK_NOTES)
886 maPosition.mePageKind = PK_HANDOUT;
887 SetPage (0);
890 bViewChanged = true;
893 else
894 if (maPosition.mnPageIndex < 0)
896 // Switch from master pages to draw pages.
897 if (maPosition.meEditMode == EM_MASTERPAGE)
899 maPosition.meEditMode = EM_PAGE;
900 bSetToOnePastLastPage = true;
903 // Switch to previous view mode.
904 else
906 if (maPosition.mePageKind == PK_STANDARD)
907 SetPage (-1);
908 else
910 maPosition.meEditMode = EM_MASTERPAGE;
911 if (maPosition.mePageKind == PK_HANDOUT)
912 maPosition.mePageKind = PK_NOTES;
913 else if (maPosition.mePageKind == PK_NOTES)
914 maPosition.mePageKind = PK_STANDARD;
915 bSetToOnePastLastPage = true;
918 bViewChanged = true;
921 if (bViewChanged)
923 // Get new page count;
924 sal_Int32 nPageCount;
925 if (maPosition.meEditMode == EM_PAGE)
926 nPageCount = mpDocument->GetSdPageCount (maPosition.mePageKind);
927 else
928 nPageCount = mpDocument->GetMasterSdPageCount(maPosition.mePageKind);
930 // Now that we know the number of pages we can set the current page index.
931 if (bSetToOnePastLastPage)
932 SetPage (nPageCount);
937 } } // end of namespace ::sd::outliner