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