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