LibreOffice Module svx (master)  1
svditer.cxx
Go to the documentation of this file.
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 #include <svx/svditer.hxx>
21 #include <svx/svdpage.hxx>
22 #include <svx/svdobj.hxx>
23 #include <svx/svdmark.hxx>
24 #include <osl/diagnose.h>
25 
26 SdrObjListIter::SdrObjListIter(const SdrObjList* pObjList, SdrIterMode eMode, bool bReverse)
27 : maObjList(),
28  mnIndex(0),
29  mbReverse(bReverse),
30  mbUseZOrder(true)
31 {
32  if(nullptr != pObjList)
33  {
34  ImpProcessObjectList(*pObjList, eMode);
35  }
36 
37  Reset();
38 }
39 
40 SdrObjListIter::SdrObjListIter(const SdrObjList* pObjList, bool bUseZOrder, SdrIterMode eMode, bool bReverse)
41 : maObjList(),
42  mnIndex(0),
43  mbReverse(bReverse),
44  mbUseZOrder(bUseZOrder)
45 {
46  if(nullptr != pObjList)
47  {
48  // correct when we have no ObjectNavigationOrder
49  if(!mbUseZOrder && !pObjList->HasObjectNavigationOrder())
50  {
51  mbUseZOrder = false;
52  }
53 
54  ImpProcessObjectList(*pObjList, eMode);
55  }
56 
57  Reset();
58 }
59 
60 SdrObjListIter::SdrObjListIter(const SdrObject& rSdrObject, SdrIterMode eMode, bool bReverse)
61 : maObjList(),
62  mnIndex(0),
63  mbReverse(bReverse),
64  mbUseZOrder(true)
65 {
66  ImpProcessObj(rSdrObject, eMode);
67  Reset();
68 }
69 
70 SdrObjListIter::SdrObjListIter(const SdrPage* pSdrPage, SdrIterMode eMode, bool bReverse)
71 : maObjList(),
72  mnIndex(0),
73  mbReverse(bReverse),
74  mbUseZOrder(true)
75 {
76  if (pSdrPage)
77  ImpProcessObjectList(*pSdrPage, eMode);
78  Reset();
79 }
80 
82 : maObjList(),
83  mnIndex(0),
84  mbReverse(false),
85  mbUseZOrder(true)
86 {
87  ImpProcessMarkList(rMarkList, eMode);
88  Reset();
89 }
90 
92 { for(size_t nIdx(0), nCount(rObjList.GetObjCount()); nIdx < nCount; ++nIdx)
93  {
94  const SdrObject* pSdrObject(mbUseZOrder
95  ? rObjList.GetObj(nIdx)
96  : rObjList.GetObjectForNavigationPosition(nIdx));
97 
98  if(nullptr == pSdrObject)
99  {
100  OSL_ENSURE(false, "SdrObjListIter: corrupted SdrObjList (!)");
101  }
102  else
103  {
104  ImpProcessObj(*pSdrObject, eMode);
105  }
106  }
107 }
108 
110 {
111  for( size_t nIdx = 0, nCount = rMarkList.GetMarkCount(); nIdx < nCount; ++nIdx )
112  {
113  if( SdrObject* pObj = rMarkList.GetMark( nIdx )->GetMarkedSdrObj() )
114  {
115  ImpProcessObj(*pObj, eMode);
116  }
117  }
118 }
119 
121 {
122  // TTTT: Note: The behaviour has changed here, it will now deep-iterate
123  // for SdrObjGroup and E3dScene. Old version only deep-dived for SdrObjGroup,
124  // E3dScene was just added flat. This is now more correct, but potentially
125  // there will exist code in the 3D area that *self-iterates* with local
126  // functions/methods due to this iterator was not doing the expected thing.
127  // These will be difficult to find, but in most cases should do no harm,
128  // but cost runtime. Will need to have an eye on this aspect on continued
129  // changes...
130  const SdrObjList* pChildren(rSdrObject.getChildrenOfSdrObject());
131  const bool bIsGroup(nullptr != pChildren);
132 
133  if(!bIsGroup || (SdrIterMode::DeepNoGroups != eMode))
134  {
135  maObjList.push_back(&rSdrObject);
136  }
137 
138  if(bIsGroup && (SdrIterMode::Flat != eMode))
139  {
140  ImpProcessObjectList(*pChildren, eMode);
141  }
142 }
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t GetMarkCount() const
Definition: svdmark.hxx:180
virtual SdrObjList * getChildrenOfSdrObject() const
Definition: svdobj.cxx:310
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:770
size_t GetObjCount() const
Definition: svdpage.cxx:764
SdrObject * GetObjectForNavigationPosition(const sal_uInt32 nNavigationPosition) const
Return the object for the given navigation position.
Definition: svdpage.cxx:890
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:230
int nCount
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
SdrObjListIter(const SdrObjList *pObjList, SdrIterMode eMode=SdrIterMode::DeepNoGroups, bool bReverse=false)
Definition: svditer.cxx:26
void ImpProcessObjectList(const SdrObjList &rSdrObjList, SdrIterMode eMode)
Definition: svditer.cxx:91
bool HasObjectNavigationOrder() const
Return whether there is an explicit, user defined, object navigation order.
Definition: svdpage.cxx:839
Abstract DrawObject.
Definition: svdobj.hxx:258
SdrIterMode
Definition: svditer.hxx:36
bool mbUseZOrder
Definition: svditer.hxx:43
void ImpProcessMarkList(const SdrMarkList &rMarkList, SdrIterMode eMode)
Definition: svditer.cxx:109
void ImpProcessObj(const SdrObject &rSdrObject, SdrIterMode eMode)
Definition: svditer.cxx:120
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:365
bool mbReverse
void Reset()
Definition: svditer.hxx:61
int mnIndex
std::vector< const SdrObject * > maObjList
Definition: svditer.hxx:40