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