xref: /AOO41X/main/sd/source/ui/view/OutlinerIterator.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "OutlinerIterator.hxx"
32*cdf0e10cSrcweir #include "OutlinerIteratorImpl.hxx"
33*cdf0e10cSrcweir #include <svx/svditer.hxx>
34*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
35*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
36*cdf0e10cSrcweir #include "Outliner.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "drawdoc.hxx"
39*cdf0e10cSrcweir #include "DrawViewShell.hxx"
40*cdf0e10cSrcweir #include "drawview.hxx"
41*cdf0e10cSrcweir #include "sdpage.hxx"
42*cdf0e10cSrcweir #ifndef SD_FRAME_VIEW
43*cdf0e10cSrcweir #include "FrameView.hxx"
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #include "DrawDocShell.hxx"
46*cdf0e10cSrcweir #include "Window.hxx"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir namespace sd { namespace outliner {
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //===== IteratorPosition ======================================================
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir IteratorPosition::IteratorPosition (void)
54*cdf0e10cSrcweir : mnText(0)
55*cdf0e10cSrcweir , mnPageIndex(-1)
56*cdf0e10cSrcweir , mePageKind(PK_STANDARD)
57*cdf0e10cSrcweir , meEditMode(EM_PAGE)
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir }
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir IteratorPosition::IteratorPosition (const IteratorPosition& aPosition)
62*cdf0e10cSrcweir : mxObject(aPosition.mxObject)
63*cdf0e10cSrcweir , mnText(aPosition.mnText)
64*cdf0e10cSrcweir , mnPageIndex(aPosition.mnPageIndex)
65*cdf0e10cSrcweir , mePageKind(aPosition.mePageKind)
66*cdf0e10cSrcweir , meEditMode(aPosition.meEditMode)
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir IteratorPosition::~IteratorPosition (void)
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir IteratorPosition& IteratorPosition::operator= (const IteratorPosition& aPosition)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     mxObject = aPosition.mxObject;
77*cdf0e10cSrcweir 	mnText = aPosition.mnText;
78*cdf0e10cSrcweir     mnPageIndex = aPosition.mnPageIndex;
79*cdf0e10cSrcweir     mePageKind = aPosition.mePageKind;
80*cdf0e10cSrcweir     meEditMode = aPosition.meEditMode;
81*cdf0e10cSrcweir     return *this;
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir bool IteratorPosition::operator== (const IteratorPosition& aPosition) const
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     return mxObject.get() == aPosition.mxObject.get()
87*cdf0e10cSrcweir 		&& mnText == aPosition.mnText
88*cdf0e10cSrcweir         && mnPageIndex == aPosition.mnPageIndex
89*cdf0e10cSrcweir         && mePageKind == aPosition.mePageKind
90*cdf0e10cSrcweir         && meEditMode == aPosition.meEditMode;
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir //===== Iterator ==============================================================
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir Iterator::Iterator (void)
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     mpIterator = NULL;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir Iterator::Iterator (const Iterator& rIterator)
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     mpIterator = rIterator.mpIterator->Clone();
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir Iterator::Iterator (IteratorImplBase* pObject)
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     mpIterator = pObject;
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir Iterator::~Iterator (void)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     delete mpIterator;
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir Iterator& Iterator::operator= (const Iterator& rIterator)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     if (this != &rIterator)
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         delete mpIterator;
123*cdf0e10cSrcweir         if (rIterator.mpIterator != NULL)
124*cdf0e10cSrcweir             mpIterator = rIterator.mpIterator->Clone();
125*cdf0e10cSrcweir         else
126*cdf0e10cSrcweir             mpIterator = NULL;
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     return *this;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir const IteratorPosition& Iterator::operator* () const
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     DBG_ASSERT (mpIterator!=NULL, "::sd::outliner::Iterator::operator* : missing implementation object");
134*cdf0e10cSrcweir     return mpIterator->GetPosition();
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir Iterator& Iterator::operator++ ()
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir     if (mpIterator!=NULL)
140*cdf0e10cSrcweir         mpIterator->GotoNextText();
141*cdf0e10cSrcweir     return *this;
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir Iterator Iterator::operator++ (int)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     Iterator aTmp (*this);
147*cdf0e10cSrcweir     if (mpIterator!=NULL)
148*cdf0e10cSrcweir         mpIterator->GotoNextText();
149*cdf0e10cSrcweir     return aTmp;
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir bool Iterator::operator== (const Iterator& rIterator)
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     if (mpIterator == NULL || rIterator.mpIterator==NULL)
155*cdf0e10cSrcweir         return mpIterator == rIterator.mpIterator;
156*cdf0e10cSrcweir     else
157*cdf0e10cSrcweir         return *mpIterator == *rIterator.mpIterator;
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir bool Iterator::operator!= (const Iterator& rIterator)
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     return ! operator==(rIterator);
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir void Iterator::Reverse (void)
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     if (mpIterator != NULL)
168*cdf0e10cSrcweir         mpIterator->Reverse();
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir //===== IteratorFactory =======================================================
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir OutlinerContainer::OutlinerContainer (Outliner* pOutliner)
174*cdf0e10cSrcweir : mpOutliner(pOutliner)
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir Iterator OutlinerContainer::begin (void)
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir     return CreateIterator (BEGIN);
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir Iterator OutlinerContainer::end (void)
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     return CreateIterator (END);
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir Iterator OutlinerContainer::current (void)
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     return CreateIterator (CURRENT);
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir Iterator OutlinerContainer::CreateIterator (IteratorLocation aLocation)
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir     // Decide on certain features of the outliner which kind of iterator to
197*cdf0e10cSrcweir     // use.
198*cdf0e10cSrcweir     if (mpOutliner->mbRestrictSearchToSelection)
199*cdf0e10cSrcweir         // There is a selection.  Search only in this.
200*cdf0e10cSrcweir         return CreateSelectionIterator (
201*cdf0e10cSrcweir             mpOutliner->maMarkListCopy,
202*cdf0e10cSrcweir             mpOutliner->mpDrawDocument,
203*cdf0e10cSrcweir             mpOutliner->mpViewShell,
204*cdf0e10cSrcweir             mpOutliner->mbDirectionIsForward,
205*cdf0e10cSrcweir             aLocation);
206*cdf0e10cSrcweir     else
207*cdf0e10cSrcweir         // Search in the whole document.
208*cdf0e10cSrcweir         return CreateDocumentIterator (
209*cdf0e10cSrcweir             mpOutliner->mpDrawDocument,
210*cdf0e10cSrcweir             mpOutliner->mpViewShell,
211*cdf0e10cSrcweir             mpOutliner->mbDirectionIsForward,
212*cdf0e10cSrcweir             aLocation);
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir Iterator OutlinerContainer::CreateSelectionIterator (
216*cdf0e10cSrcweir     const ::std::vector<SdrObjectWeakRef>& rObjectList,
217*cdf0e10cSrcweir     SdDrawDocument* pDocument,
218*cdf0e10cSrcweir     const ::boost::shared_ptr<ViewShell>& rpViewShell,
219*cdf0e10cSrcweir     bool bDirectionIsForward,
220*cdf0e10cSrcweir     IteratorLocation aLocation)
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir     OSL_ASSERT(rpViewShell.get());
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     sal_Int32 nObjectIndex;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     if (bDirectionIsForward)
227*cdf0e10cSrcweir         switch (aLocation)
228*cdf0e10cSrcweir         {
229*cdf0e10cSrcweir             case CURRENT:
230*cdf0e10cSrcweir             case BEGIN:
231*cdf0e10cSrcweir             default:
232*cdf0e10cSrcweir                 nObjectIndex = 0;
233*cdf0e10cSrcweir                 break;
234*cdf0e10cSrcweir             case END:
235*cdf0e10cSrcweir                 nObjectIndex = rObjectList.size();
236*cdf0e10cSrcweir                 break;
237*cdf0e10cSrcweir         }
238*cdf0e10cSrcweir     else
239*cdf0e10cSrcweir         switch (aLocation)
240*cdf0e10cSrcweir         {
241*cdf0e10cSrcweir             case CURRENT:
242*cdf0e10cSrcweir             case BEGIN:
243*cdf0e10cSrcweir             default:
244*cdf0e10cSrcweir                 nObjectIndex = rObjectList.size()-1;
245*cdf0e10cSrcweir                 break;
246*cdf0e10cSrcweir             case END:
247*cdf0e10cSrcweir                 nObjectIndex = -1;
248*cdf0e10cSrcweir                 break;
249*cdf0e10cSrcweir         }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     return Iterator (new SelectionIteratorImpl (
252*cdf0e10cSrcweir         rObjectList, nObjectIndex, pDocument, rpViewShell, bDirectionIsForward));
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir Iterator OutlinerContainer::CreateDocumentIterator (
256*cdf0e10cSrcweir     SdDrawDocument* pDocument,
257*cdf0e10cSrcweir     const ::boost::shared_ptr<ViewShell>& rpViewShell,
258*cdf0e10cSrcweir     bool bDirectionIsForward,
259*cdf0e10cSrcweir     IteratorLocation aLocation)
260*cdf0e10cSrcweir {
261*cdf0e10cSrcweir     OSL_ASSERT(rpViewShell.get());
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     PageKind ePageKind;
264*cdf0e10cSrcweir     EditMode eEditMode;
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir     switch (aLocation)
267*cdf0e10cSrcweir     {
268*cdf0e10cSrcweir         case BEGIN:
269*cdf0e10cSrcweir         default:
270*cdf0e10cSrcweir             if (bDirectionIsForward)
271*cdf0e10cSrcweir             {
272*cdf0e10cSrcweir                 ePageKind = PK_STANDARD;
273*cdf0e10cSrcweir                 eEditMode = EM_PAGE;
274*cdf0e10cSrcweir             }
275*cdf0e10cSrcweir             else
276*cdf0e10cSrcweir             {
277*cdf0e10cSrcweir                 ePageKind = PK_HANDOUT;
278*cdf0e10cSrcweir                 eEditMode = EM_MASTERPAGE;
279*cdf0e10cSrcweir             }
280*cdf0e10cSrcweir             break;
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir         case END:
283*cdf0e10cSrcweir             if (bDirectionIsForward)
284*cdf0e10cSrcweir             {
285*cdf0e10cSrcweir                 ePageKind = PK_HANDOUT;
286*cdf0e10cSrcweir                 eEditMode = EM_MASTERPAGE;
287*cdf0e10cSrcweir             }
288*cdf0e10cSrcweir             else
289*cdf0e10cSrcweir             {
290*cdf0e10cSrcweir                 ePageKind = PK_STANDARD;
291*cdf0e10cSrcweir                 eEditMode = EM_PAGE;
292*cdf0e10cSrcweir             }
293*cdf0e10cSrcweir             break;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir         case CURRENT:
296*cdf0e10cSrcweir             const ::boost::shared_ptr<DrawViewShell> pDrawViewShell(
297*cdf0e10cSrcweir                 ::boost::dynamic_pointer_cast<DrawViewShell>(rpViewShell));
298*cdf0e10cSrcweir             if (pDrawViewShell.get())
299*cdf0e10cSrcweir             {
300*cdf0e10cSrcweir                 ePageKind = pDrawViewShell->GetPageKind();
301*cdf0e10cSrcweir                 eEditMode = pDrawViewShell->GetEditMode();
302*cdf0e10cSrcweir             }
303*cdf0e10cSrcweir             else
304*cdf0e10cSrcweir             {
305*cdf0e10cSrcweir                 ePageKind = PK_STANDARD;
306*cdf0e10cSrcweir                 eEditMode = EM_PAGE;
307*cdf0e10cSrcweir             }
308*cdf0e10cSrcweir             break;
309*cdf0e10cSrcweir     }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir     sal_Int32 nPageIndex = GetPageIndex (pDocument, rpViewShell,
312*cdf0e10cSrcweir         ePageKind, eEditMode, bDirectionIsForward, aLocation);
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir     return Iterator (
315*cdf0e10cSrcweir         new DocumentIteratorImpl (nPageIndex, ePageKind, eEditMode,
316*cdf0e10cSrcweir             pDocument, rpViewShell, bDirectionIsForward));
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir sal_Int32 OutlinerContainer::GetPageIndex (
320*cdf0e10cSrcweir     SdDrawDocument* pDocument,
321*cdf0e10cSrcweir     const ::boost::shared_ptr<ViewShell>& rpViewShell,
322*cdf0e10cSrcweir     PageKind ePageKind,
323*cdf0e10cSrcweir     EditMode eEditMode,
324*cdf0e10cSrcweir     bool bDirectionIsForward,
325*cdf0e10cSrcweir     IteratorLocation aLocation)
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir     OSL_ASSERT(rpViewShell);
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     sal_Int32 nPageIndex;
330*cdf0e10cSrcweir     sal_Int32 nPageCount;
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir     const ::boost::shared_ptr<DrawViewShell> pDrawViewShell(
333*cdf0e10cSrcweir         ::boost::dynamic_pointer_cast<DrawViewShell>(rpViewShell));
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     switch (eEditMode)
336*cdf0e10cSrcweir     {
337*cdf0e10cSrcweir         case EM_PAGE:
338*cdf0e10cSrcweir             nPageCount = pDocument->GetSdPageCount (ePageKind);
339*cdf0e10cSrcweir             break;
340*cdf0e10cSrcweir         case EM_MASTERPAGE:
341*cdf0e10cSrcweir             nPageCount = pDocument->GetMasterSdPageCount(ePageKind);
342*cdf0e10cSrcweir             break;
343*cdf0e10cSrcweir         default:
344*cdf0e10cSrcweir             nPageCount = 0;
345*cdf0e10cSrcweir     }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir     switch (aLocation)
348*cdf0e10cSrcweir     {
349*cdf0e10cSrcweir         case CURRENT:
350*cdf0e10cSrcweir             if (pDrawViewShell.get())
351*cdf0e10cSrcweir                 nPageIndex = pDrawViewShell->GetCurPageId() - 1;
352*cdf0e10cSrcweir             else
353*cdf0e10cSrcweir             {
354*cdf0e10cSrcweir                 const SdPage* pPage = rpViewShell->GetActualPage();
355*cdf0e10cSrcweir                 if (pPage != NULL)
356*cdf0e10cSrcweir                     nPageIndex = (pPage->GetPageNum()-1)/2;
357*cdf0e10cSrcweir                 else
358*cdf0e10cSrcweir                     nPageIndex = 0;
359*cdf0e10cSrcweir             }
360*cdf0e10cSrcweir             break;
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir         case BEGIN:
363*cdf0e10cSrcweir         default:
364*cdf0e10cSrcweir             if (bDirectionIsForward)
365*cdf0e10cSrcweir                 nPageIndex = 0;
366*cdf0e10cSrcweir             else
367*cdf0e10cSrcweir                 nPageIndex = nPageCount-1;
368*cdf0e10cSrcweir             break;
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         case END:
371*cdf0e10cSrcweir             if (bDirectionIsForward)
372*cdf0e10cSrcweir                 nPageIndex = nPageCount;
373*cdf0e10cSrcweir             else
374*cdf0e10cSrcweir                 nPageIndex = -1;
375*cdf0e10cSrcweir             break;
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir     return nPageIndex;
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir //===== IteratorImplBase ====================================================
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir IteratorImplBase::IteratorImplBase(SdDrawDocument* pDocument,
387*cdf0e10cSrcweir     const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
388*cdf0e10cSrcweir     bool bDirectionIsForward)
389*cdf0e10cSrcweir :	maPosition()
390*cdf0e10cSrcweir ,	mpDocument (pDocument)
391*cdf0e10cSrcweir ,	mpViewShellWeak (rpViewShellWeak)
392*cdf0e10cSrcweir ,	mbDirectionIsForward (bDirectionIsForward)
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir     ::boost::shared_ptr<DrawViewShell> pDrawViewShell;
395*cdf0e10cSrcweir     if ( ! mpViewShellWeak.expired())
396*cdf0e10cSrcweir         pDrawViewShell = ::boost::dynamic_pointer_cast<DrawViewShell>(rpViewShellWeak.lock());
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     if (pDrawViewShell.get())
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         maPosition.mePageKind = pDrawViewShell->GetPageKind();
401*cdf0e10cSrcweir         maPosition.meEditMode = pDrawViewShell->GetEditMode();
402*cdf0e10cSrcweir     }
403*cdf0e10cSrcweir     else
404*cdf0e10cSrcweir     {
405*cdf0e10cSrcweir         maPosition.mePageKind = PK_STANDARD;
406*cdf0e10cSrcweir         maPosition.meEditMode = EM_PAGE;
407*cdf0e10cSrcweir     }
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir IteratorImplBase::IteratorImplBase( SdDrawDocument* pDocument,
411*cdf0e10cSrcweir     const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
412*cdf0e10cSrcweir     bool bDirectionIsForward, PageKind ePageKind, EditMode eEditMode)
413*cdf0e10cSrcweir : maPosition()
414*cdf0e10cSrcweir , mpDocument (pDocument)
415*cdf0e10cSrcweir , mpViewShellWeak (rpViewShellWeak)
416*cdf0e10cSrcweir , mbDirectionIsForward (bDirectionIsForward)
417*cdf0e10cSrcweir {
418*cdf0e10cSrcweir     maPosition.mePageKind = ePageKind;
419*cdf0e10cSrcweir     maPosition.meEditMode = eEditMode;
420*cdf0e10cSrcweir }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir IteratorImplBase::~IteratorImplBase (void)
423*cdf0e10cSrcweir {}
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir bool IteratorImplBase::operator== (const IteratorImplBase& rIterator) const
426*cdf0e10cSrcweir {
427*cdf0e10cSrcweir     return maPosition == rIterator.maPosition;
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir bool IteratorImplBase::IsEqual (const IteratorImplBase& rIterator, IteratorType ) const
431*cdf0e10cSrcweir {
432*cdf0e10cSrcweir     // When this method is executed instead of the ones from derived classes
433*cdf0e10cSrcweir     // then the argument is of another type then the object itself.  In this
434*cdf0e10cSrcweir     // just compare the position objects.
435*cdf0e10cSrcweir     return maPosition == rIterator.maPosition;
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir const IteratorPosition& IteratorImplBase::GetPosition (void)
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     return maPosition;
441*cdf0e10cSrcweir }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir IteratorImplBase* IteratorImplBase::Clone (IteratorImplBase* pObject) const
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir     if (pObject != NULL)
449*cdf0e10cSrcweir     {
450*cdf0e10cSrcweir         pObject->maPosition = maPosition;
451*cdf0e10cSrcweir         pObject->mpDocument = mpDocument;
452*cdf0e10cSrcweir         pObject->mpViewShellWeak = mpViewShellWeak;
453*cdf0e10cSrcweir         pObject->mbDirectionIsForward = mbDirectionIsForward;
454*cdf0e10cSrcweir     }
455*cdf0e10cSrcweir     return pObject;
456*cdf0e10cSrcweir }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir void IteratorImplBase::Reverse (void)
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir     mbDirectionIsForward = ! mbDirectionIsForward;
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir //===== SelectionIteratorImpl ===========================================
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir SelectionIteratorImpl::SelectionIteratorImpl (
470*cdf0e10cSrcweir     const ::std::vector<SdrObjectWeakRef>& rObjectList,
471*cdf0e10cSrcweir     sal_Int32 nObjectIndex,
472*cdf0e10cSrcweir     SdDrawDocument* pDocument,
473*cdf0e10cSrcweir     const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
474*cdf0e10cSrcweir     bool bDirectionIsForward)
475*cdf0e10cSrcweir     : IteratorImplBase (pDocument, rpViewShellWeak, bDirectionIsForward),
476*cdf0e10cSrcweir       mrObjectList(rObjectList),
477*cdf0e10cSrcweir       mnObjectIndex(nObjectIndex)
478*cdf0e10cSrcweir {
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir SelectionIteratorImpl::~SelectionIteratorImpl (void)
482*cdf0e10cSrcweir {}
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir IteratorImplBase* SelectionIteratorImpl::Clone (IteratorImplBase* pObject) const
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir     SelectionIteratorImpl* pIterator = static_cast<SelectionIteratorImpl*>(pObject);
487*cdf0e10cSrcweir     if (pIterator == NULL)
488*cdf0e10cSrcweir         pIterator = new SelectionIteratorImpl (
489*cdf0e10cSrcweir             mrObjectList, mnObjectIndex, mpDocument, mpViewShellWeak, mbDirectionIsForward);
490*cdf0e10cSrcweir     return pIterator;
491*cdf0e10cSrcweir }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir void SelectionIteratorImpl::GotoNextText (void)
495*cdf0e10cSrcweir {
496*cdf0e10cSrcweir 	SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( mrObjectList.at(mnObjectIndex).get() );
497*cdf0e10cSrcweir     if (mbDirectionIsForward)
498*cdf0e10cSrcweir 	{
499*cdf0e10cSrcweir 		if( pTextObj )
500*cdf0e10cSrcweir 		{
501*cdf0e10cSrcweir 			++maPosition.mnText;
502*cdf0e10cSrcweir 			if( maPosition.mnText >= pTextObj->getTextCount() )
503*cdf0e10cSrcweir 			{
504*cdf0e10cSrcweir 				maPosition.mnText = 0;
505*cdf0e10cSrcweir 		        ++mnObjectIndex;
506*cdf0e10cSrcweir 			}
507*cdf0e10cSrcweir 		}
508*cdf0e10cSrcweir 		else
509*cdf0e10cSrcweir 		{
510*cdf0e10cSrcweir 			++mnObjectIndex;
511*cdf0e10cSrcweir 		}
512*cdf0e10cSrcweir 	}
513*cdf0e10cSrcweir     else
514*cdf0e10cSrcweir 	{
515*cdf0e10cSrcweir 		if( pTextObj )
516*cdf0e10cSrcweir 		{
517*cdf0e10cSrcweir 			--maPosition.mnText;
518*cdf0e10cSrcweir 			if( maPosition.mnText < 0 )
519*cdf0e10cSrcweir 			{
520*cdf0e10cSrcweir 				maPosition.mnText = -1;
521*cdf0e10cSrcweir 		        --mnObjectIndex;
522*cdf0e10cSrcweir 			}
523*cdf0e10cSrcweir 		}
524*cdf0e10cSrcweir 		else
525*cdf0e10cSrcweir 		{
526*cdf0e10cSrcweir 			--mnObjectIndex;
527*cdf0e10cSrcweir 			maPosition.mnText = -1;
528*cdf0e10cSrcweir 		}
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 		if( (maPosition.mnText == -1) && (mnObjectIndex >= 0) )
531*cdf0e10cSrcweir 		{
532*cdf0e10cSrcweir 			pTextObj = dynamic_cast< SdrTextObj* >( mrObjectList.at(mnObjectIndex).get() );
533*cdf0e10cSrcweir 			if( pTextObj )
534*cdf0e10cSrcweir 				maPosition.mnText = pTextObj->getTextCount() - 1;
535*cdf0e10cSrcweir 		}
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 		if( maPosition.mnText == -1 )
538*cdf0e10cSrcweir 			maPosition.mnText = 0;
539*cdf0e10cSrcweir 	}
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir const IteratorPosition& SelectionIteratorImpl::GetPosition (void)
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir     maPosition.mxObject = mrObjectList.at(mnObjectIndex);
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     return maPosition;
548*cdf0e10cSrcweir }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir bool SelectionIteratorImpl::operator== (const IteratorImplBase& rIterator) const
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir     return rIterator.IsEqual (*this, SELECTION);
554*cdf0e10cSrcweir }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir bool SelectionIteratorImpl::IsEqual (
558*cdf0e10cSrcweir     const IteratorImplBase& rIterator,
559*cdf0e10cSrcweir     IteratorType aType) const
560*cdf0e10cSrcweir {
561*cdf0e10cSrcweir     if (aType == SELECTION)
562*cdf0e10cSrcweir     {
563*cdf0e10cSrcweir         const SelectionIteratorImpl* pSelectionIterator =
564*cdf0e10cSrcweir             static_cast<const SelectionIteratorImpl*>(&rIterator);
565*cdf0e10cSrcweir         return mpDocument == pSelectionIterator->mpDocument
566*cdf0e10cSrcweir             && mnObjectIndex == pSelectionIterator->mnObjectIndex;
567*cdf0e10cSrcweir     }
568*cdf0e10cSrcweir     else
569*cdf0e10cSrcweir         return false;
570*cdf0e10cSrcweir }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir //===== ViewIteratorImpl ================================================
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir ViewIteratorImpl::ViewIteratorImpl (
578*cdf0e10cSrcweir     sal_Int32 nPageIndex,
579*cdf0e10cSrcweir     SdDrawDocument* pDocument,
580*cdf0e10cSrcweir     const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
581*cdf0e10cSrcweir     bool bDirectionIsForward)
582*cdf0e10cSrcweir     : IteratorImplBase (pDocument, rpViewShellWeak, bDirectionIsForward),
583*cdf0e10cSrcweir       mbPageChangeOccured(false),
584*cdf0e10cSrcweir       mpPage(NULL),
585*cdf0e10cSrcweir       mpObjectIterator(NULL)
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir     SetPage (nPageIndex);
588*cdf0e10cSrcweir }
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir ViewIteratorImpl::ViewIteratorImpl (
594*cdf0e10cSrcweir     sal_Int32 nPageIndex,
595*cdf0e10cSrcweir     SdDrawDocument* pDocument,
596*cdf0e10cSrcweir     const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
597*cdf0e10cSrcweir     bool bDirectionIsForward,
598*cdf0e10cSrcweir     PageKind ePageKind,
599*cdf0e10cSrcweir     EditMode eEditMode)
600*cdf0e10cSrcweir     : IteratorImplBase (pDocument, rpViewShellWeak, bDirectionIsForward, ePageKind, eEditMode),
601*cdf0e10cSrcweir       mbPageChangeOccured(false),
602*cdf0e10cSrcweir       mpPage(NULL),
603*cdf0e10cSrcweir       mpObjectIterator(NULL)
604*cdf0e10cSrcweir {
605*cdf0e10cSrcweir     SetPage (nPageIndex);
606*cdf0e10cSrcweir }
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir ViewIteratorImpl::~ViewIteratorImpl (void)
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir IteratorImplBase* ViewIteratorImpl::Clone (IteratorImplBase* pObject) const
619*cdf0e10cSrcweir {
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir     ViewIteratorImpl* pIterator = static_cast<ViewIteratorImpl*>(pObject);
622*cdf0e10cSrcweir     if (pIterator == NULL)
623*cdf0e10cSrcweir         pIterator = new ViewIteratorImpl (
624*cdf0e10cSrcweir             maPosition.mnPageIndex, mpDocument, mpViewShellWeak, mbDirectionIsForward);
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir     IteratorImplBase::Clone (pObject);
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir     if (mpObjectIterator != NULL)
629*cdf0e10cSrcweir     {
630*cdf0e10cSrcweir         pIterator->mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, !mbDirectionIsForward);
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir         // No direct way to set the object iterator to the current object.
633*cdf0e10cSrcweir         pIterator->maPosition.mxObject.reset(NULL);
634*cdf0e10cSrcweir         while (pIterator->mpObjectIterator->IsMore() && pIterator->maPosition.mxObject!=maPosition.mxObject)
635*cdf0e10cSrcweir             pIterator->maPosition.mxObject.reset(pIterator->mpObjectIterator->Next());
636*cdf0e10cSrcweir     }
637*cdf0e10cSrcweir     else
638*cdf0e10cSrcweir         pIterator->mpObjectIterator = NULL;
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     return pIterator;
641*cdf0e10cSrcweir }
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir void ViewIteratorImpl::GotoNextText(void)
646*cdf0e10cSrcweir {
647*cdf0e10cSrcweir 	SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( maPosition.mxObject.get() );
648*cdf0e10cSrcweir 	if( pTextObj )
649*cdf0e10cSrcweir 	{
650*cdf0e10cSrcweir 	    if (mbDirectionIsForward)
651*cdf0e10cSrcweir 		{
652*cdf0e10cSrcweir 			++maPosition.mnText;
653*cdf0e10cSrcweir 			if( maPosition.mnText < pTextObj->getTextCount() )
654*cdf0e10cSrcweir 				return;
655*cdf0e10cSrcweir 		}
656*cdf0e10cSrcweir 		else
657*cdf0e10cSrcweir 		{
658*cdf0e10cSrcweir 			--maPosition.mnText;
659*cdf0e10cSrcweir 			if( maPosition.mnText >= 0 )
660*cdf0e10cSrcweir 				return;
661*cdf0e10cSrcweir 		}
662*cdf0e10cSrcweir 	}
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     if (mpObjectIterator != NULL && mpObjectIterator->IsMore())
665*cdf0e10cSrcweir         maPosition.mxObject.reset(mpObjectIterator->Next());
666*cdf0e10cSrcweir     else
667*cdf0e10cSrcweir         maPosition.mxObject.reset(NULL);
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir     if (!maPosition.mxObject.is() )
670*cdf0e10cSrcweir     {
671*cdf0e10cSrcweir         if (mbDirectionIsForward)
672*cdf0e10cSrcweir             SetPage (maPosition.mnPageIndex+1);
673*cdf0e10cSrcweir         else
674*cdf0e10cSrcweir             SetPage (maPosition.mnPageIndex-1);
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir         if (mpPage != NULL)
677*cdf0e10cSrcweir             mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, !mbDirectionIsForward);
678*cdf0e10cSrcweir         if (mpObjectIterator!=NULL && mpObjectIterator->IsMore())
679*cdf0e10cSrcweir             maPosition.mxObject.reset(mpObjectIterator->Next());
680*cdf0e10cSrcweir         else
681*cdf0e10cSrcweir             maPosition.mxObject.reset(NULL);
682*cdf0e10cSrcweir     }
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir 	maPosition.mnText = 0;
685*cdf0e10cSrcweir 	if( !mbDirectionIsForward && maPosition.mxObject.is() )
686*cdf0e10cSrcweir 	{
687*cdf0e10cSrcweir 		pTextObj = dynamic_cast< SdrTextObj* >( maPosition.mxObject.get() );
688*cdf0e10cSrcweir 		if( pTextObj )
689*cdf0e10cSrcweir 			maPosition.mnText = pTextObj->getTextCount() - 1;
690*cdf0e10cSrcweir 	}
691*cdf0e10cSrcweir }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir void ViewIteratorImpl::SetPage (sal_Int32 nPageIndex)
697*cdf0e10cSrcweir {
698*cdf0e10cSrcweir     mbPageChangeOccured = (maPosition.mnPageIndex!=nPageIndex);
699*cdf0e10cSrcweir     if (mbPageChangeOccured)
700*cdf0e10cSrcweir     {
701*cdf0e10cSrcweir         maPosition.mnPageIndex = nPageIndex;
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir         sal_Int32 nPageCount;
704*cdf0e10cSrcweir         if (maPosition.meEditMode == EM_PAGE)
705*cdf0e10cSrcweir             nPageCount = mpDocument->GetSdPageCount(maPosition.mePageKind);
706*cdf0e10cSrcweir         else
707*cdf0e10cSrcweir             nPageCount = mpDocument->GetMasterSdPageCount(
708*cdf0e10cSrcweir                 maPosition.mePageKind);
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir         // Get page pointer.  Here we have three cases: regular pages,
711*cdf0e10cSrcweir         // master pages and invalid page indices.  The later ones are not
712*cdf0e10cSrcweir         // errors but the effect of the iterator advancing to the next page
713*cdf0e10cSrcweir         // and going past the last one.  This dropping of the rim at the far
714*cdf0e10cSrcweir         // side is detected here and has to be reacted to by the caller.
715*cdf0e10cSrcweir         if (nPageIndex>=0 && nPageIndex < nPageCount)
716*cdf0e10cSrcweir         {
717*cdf0e10cSrcweir             if (maPosition.meEditMode == EM_PAGE)
718*cdf0e10cSrcweir                 mpPage = mpDocument->GetSdPage (
719*cdf0e10cSrcweir                     (sal_uInt16)nPageIndex,
720*cdf0e10cSrcweir                     maPosition.mePageKind);
721*cdf0e10cSrcweir             else
722*cdf0e10cSrcweir                 mpPage = mpDocument->GetMasterSdPage (
723*cdf0e10cSrcweir                     (sal_uInt16)nPageIndex,
724*cdf0e10cSrcweir                     maPosition.mePageKind);
725*cdf0e10cSrcweir         }
726*cdf0e10cSrcweir         else
727*cdf0e10cSrcweir             mpPage = NULL;
728*cdf0e10cSrcweir     }
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir     // Set up object list iterator.
731*cdf0e10cSrcweir     if (mpPage != NULL)
732*cdf0e10cSrcweir         mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, ! mbDirectionIsForward);
733*cdf0e10cSrcweir     else
734*cdf0e10cSrcweir         mpObjectIterator = NULL;
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir     // Get object pointer.
737*cdf0e10cSrcweir     if (mpObjectIterator!=NULL && mpObjectIterator->IsMore())
738*cdf0e10cSrcweir         maPosition.mxObject.reset( mpObjectIterator->Next() );
739*cdf0e10cSrcweir     else
740*cdf0e10cSrcweir         maPosition.mxObject.reset( NULL );
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir 	maPosition.mnText = 0;
743*cdf0e10cSrcweir 	if( !mbDirectionIsForward && maPosition.mxObject.is() )
744*cdf0e10cSrcweir 	{
745*cdf0e10cSrcweir 		SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( maPosition.mxObject.get() );
746*cdf0e10cSrcweir 		if( pTextObj )
747*cdf0e10cSrcweir 			maPosition.mnText = pTextObj->getTextCount() - 1;
748*cdf0e10cSrcweir 	}
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir }
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir void ViewIteratorImpl::Reverse (void)
756*cdf0e10cSrcweir {
757*cdf0e10cSrcweir     IteratorImplBase::Reverse ();
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir     // Create reversed object list iterator.
760*cdf0e10cSrcweir     if (mpObjectIterator != NULL)
761*cdf0e10cSrcweir         delete mpObjectIterator;
762*cdf0e10cSrcweir     if (mpPage != NULL)
763*cdf0e10cSrcweir         mpObjectIterator = new SdrObjListIter(*mpPage, IM_DEEPNOGROUPS, ! mbDirectionIsForward);
764*cdf0e10cSrcweir     else
765*cdf0e10cSrcweir         mpObjectIterator = NULL;
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir     // Move iterator to the current object.
768*cdf0e10cSrcweir     SdrObjectWeakRef xObject = maPosition.mxObject;
769*cdf0e10cSrcweir     maPosition.mxObject.reset(NULL);
770*cdf0e10cSrcweir     while (mpObjectIterator->IsMore() && maPosition.mxObject != xObject)
771*cdf0e10cSrcweir         maPosition.mxObject.reset(mpObjectIterator->Next());
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir //===== DocumentIteratorImpl ============================================
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir DocumentIteratorImpl::DocumentIteratorImpl (
780*cdf0e10cSrcweir     sal_Int32 nPageIndex,
781*cdf0e10cSrcweir     PageKind ePageKind, EditMode eEditMode,
782*cdf0e10cSrcweir     SdDrawDocument* pDocument,
783*cdf0e10cSrcweir     const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
784*cdf0e10cSrcweir     bool bDirectionIsForward)
785*cdf0e10cSrcweir     : ViewIteratorImpl (nPageIndex, pDocument, rpViewShellWeak, bDirectionIsForward,
786*cdf0e10cSrcweir         ePageKind, eEditMode)
787*cdf0e10cSrcweir {
788*cdf0e10cSrcweir     if (eEditMode == EM_PAGE)
789*cdf0e10cSrcweir         mnPageCount = pDocument->GetSdPageCount (ePageKind);
790*cdf0e10cSrcweir     else
791*cdf0e10cSrcweir         mnPageCount = pDocument->GetMasterSdPageCount(ePageKind);
792*cdf0e10cSrcweir }
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir DocumentIteratorImpl::~DocumentIteratorImpl (void)
798*cdf0e10cSrcweir {}
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir IteratorImplBase* DocumentIteratorImpl::Clone (IteratorImplBase* pObject) const
804*cdf0e10cSrcweir {
805*cdf0e10cSrcweir     DocumentIteratorImpl* pIterator = static_cast<DocumentIteratorImpl*>(pObject);
806*cdf0e10cSrcweir     if (pIterator == NULL)
807*cdf0e10cSrcweir         pIterator = new DocumentIteratorImpl (
808*cdf0e10cSrcweir             maPosition.mnPageIndex, maPosition.mePageKind, maPosition.meEditMode,
809*cdf0e10cSrcweir             mpDocument, mpViewShellWeak, mbDirectionIsForward);
810*cdf0e10cSrcweir     // Finish the cloning.
811*cdf0e10cSrcweir     return ViewIteratorImpl::Clone (pIterator);
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir void DocumentIteratorImpl::GotoNextText (void)
818*cdf0e10cSrcweir {
819*cdf0e10cSrcweir     bool bSetToOnePastLastPage = false;
820*cdf0e10cSrcweir     bool bViewChanged = false;
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir     ViewIteratorImpl::GotoNextText();
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir     if (mbDirectionIsForward)
825*cdf0e10cSrcweir     {
826*cdf0e10cSrcweir         if (maPosition.mnPageIndex >= mnPageCount)
827*cdf0e10cSrcweir         {
828*cdf0e10cSrcweir             // Switch to master page.
829*cdf0e10cSrcweir             if (maPosition.meEditMode == EM_PAGE)
830*cdf0e10cSrcweir             {
831*cdf0e10cSrcweir                 maPosition.meEditMode = EM_MASTERPAGE;
832*cdf0e10cSrcweir                 SetPage (0);
833*cdf0e10cSrcweir             }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir             // Switch to next view mode.
836*cdf0e10cSrcweir             else
837*cdf0e10cSrcweir             {
838*cdf0e10cSrcweir                 if (maPosition.mePageKind == PK_HANDOUT)
839*cdf0e10cSrcweir                     // Not really necessary but makes things more clear.
840*cdf0e10cSrcweir                     bSetToOnePastLastPage = true;
841*cdf0e10cSrcweir                 else
842*cdf0e10cSrcweir                 {
843*cdf0e10cSrcweir                     maPosition.meEditMode = EM_PAGE;
844*cdf0e10cSrcweir                     if (maPosition.mePageKind == PK_STANDARD)
845*cdf0e10cSrcweir                         maPosition.mePageKind = PK_NOTES;
846*cdf0e10cSrcweir                     else if (maPosition.mePageKind == PK_NOTES)
847*cdf0e10cSrcweir                         maPosition.mePageKind = PK_HANDOUT;
848*cdf0e10cSrcweir                     SetPage (0);
849*cdf0e10cSrcweir                 }
850*cdf0e10cSrcweir             }
851*cdf0e10cSrcweir             bViewChanged = true;
852*cdf0e10cSrcweir         }
853*cdf0e10cSrcweir     }
854*cdf0e10cSrcweir     else
855*cdf0e10cSrcweir         if (maPosition.mnPageIndex < 0)
856*cdf0e10cSrcweir         {
857*cdf0e10cSrcweir             // Switch from master pages to draw pages.
858*cdf0e10cSrcweir             if (maPosition.meEditMode == EM_MASTERPAGE)
859*cdf0e10cSrcweir             {
860*cdf0e10cSrcweir                 maPosition.meEditMode = EM_PAGE;
861*cdf0e10cSrcweir                 bSetToOnePastLastPage = true;
862*cdf0e10cSrcweir             }
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir             // Switch to previous view mode.
865*cdf0e10cSrcweir             else
866*cdf0e10cSrcweir             {
867*cdf0e10cSrcweir                 if (maPosition.mePageKind == PK_STANDARD)
868*cdf0e10cSrcweir                     SetPage (-1);
869*cdf0e10cSrcweir                 else
870*cdf0e10cSrcweir                 {
871*cdf0e10cSrcweir                     maPosition.meEditMode = EM_MASTERPAGE;
872*cdf0e10cSrcweir                     if (maPosition.mePageKind == PK_HANDOUT)
873*cdf0e10cSrcweir                         maPosition.mePageKind = PK_NOTES;
874*cdf0e10cSrcweir                     else if (maPosition.mePageKind == PK_NOTES)
875*cdf0e10cSrcweir                         maPosition.mePageKind = PK_STANDARD;
876*cdf0e10cSrcweir                     bSetToOnePastLastPage = true;
877*cdf0e10cSrcweir                 }
878*cdf0e10cSrcweir             }
879*cdf0e10cSrcweir             bViewChanged = true;
880*cdf0e10cSrcweir         }
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir     if (bViewChanged)
883*cdf0e10cSrcweir     {
884*cdf0e10cSrcweir         // Get new page count;
885*cdf0e10cSrcweir         sal_Int32 nPageCount;
886*cdf0e10cSrcweir         if (maPosition.meEditMode == EM_PAGE)
887*cdf0e10cSrcweir             nPageCount = mpDocument->GetSdPageCount (maPosition.mePageKind);
888*cdf0e10cSrcweir         else
889*cdf0e10cSrcweir             nPageCount = mpDocument->GetMasterSdPageCount(maPosition.mePageKind);
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir         // Now that we know the number of pages we can set the current page index.
892*cdf0e10cSrcweir         if (bSetToOnePastLastPage)
893*cdf0e10cSrcweir             SetPage (nPageCount);
894*cdf0e10cSrcweir     }
895*cdf0e10cSrcweir }
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir } } // end of namespace ::sd::outliner
899