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