Update git submodules
[LibreOffice.git] / sd / source / ui / inc / OutlinerIteratorImpl.hxx
blob84b11e47b636603344fc7b3826ea293d496f0f1a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <svx/svditer.hxx>
23 #include <OutlinerIterator.hxx>
24 #include <optional>
26 class SdDrawDocument;
27 class SdPage;
29 namespace sd {
31 class ViewShell;
33 namespace outliner {
35 /** Base class for the polymorphic implementation class of the
36 <type>Iterator</type> class. The iterators based on this class are
37 basically uni directional iterators. Their direction can, however, be
38 reversed at any point of their life time.
40 class IteratorImplBase
42 public:
43 /** The constructor stores the given arguments to be used by the derived
44 classes.
45 @param pDocument
46 The document provides the information to be iterated on.
47 @param pViewShellWeak
48 Some information has to be taken from the view shell.
49 @param bDirectionIsForward
50 This flag defines the iteration direction. When <TRUE/> then
51 the direction is forwards otherwise it is backwards.
53 IteratorImplBase (SdDrawDocument* pDocument,
54 const std::weak_ptr<ViewShell>& rpViewShellWeak,
55 bool bDirectionIsForward);
56 IteratorImplBase (SdDrawDocument* pDocument,
57 std::weak_ptr<ViewShell> pViewShellWeak,
58 bool bDirectionIsForward, PageKind ePageKind, EditMode eEditMode);
59 virtual ~IteratorImplBase();
61 /** Advance to the next text of the current object or to the next object.
62 This takes the iteration direction into
63 account. The new object pointed to can be retrieved (among other
64 information) by calling the <member>GetPosition</member> method.
66 virtual void GotoNextText() = 0;
67 /** Return an object that describes the current object.
68 @return
69 The returned object describes the current object pointed to by
70 the iterator. See the description of
71 <type>IteratorPosition</type> for details on the available
72 information.
74 virtual const IteratorPosition& GetPosition();
75 /** Create an exact copy of this object. No argument should be
76 specified when called from the outside. It then creates an object
77 first and passes that to the inherited <member>Clone()</member>
78 methods to fill in class specific information.
79 @return
80 Returns a copy of this object. When this method is called with
81 an argument then this value will be returned.
83 virtual IteratorImplBase* Clone (IteratorImplBase* pObject=nullptr) const;
84 /** Test the equality of the this object and the given iterator. Two
85 iterators are taken to be equal when they point to the same object.
86 Iteration direction is not taken into account.
87 @param rIterator
88 The iterator to compare to.
89 @return
90 When both iterators are equal <TRUE/> is returned, <FALSE/> otherwise.
92 virtual bool operator== (const IteratorImplBase& rIterator) const;
93 /** This method is used by the equality operator. It is part of a "multimethod" pattern.
94 @param rIterator
95 The iterator to compare to.
96 @return
97 Returns <TRUE/> when both iterators point to the same object.
99 virtual bool IsEqualSelection(const IteratorImplBase& rIterator) const;
100 /** Reverse the direction of iteration. The current object stays the same.
102 virtual void Reverse();
104 protected:
105 /// The current position as returned by <member>GetPosition()</member>.
106 IteratorPosition maPosition;
107 /// The document on whose data the iterator operates.
108 SdDrawDocument* mpDocument;
109 /// Necessary secondary source of information.
110 std::weak_ptr<ViewShell> mpViewShellWeak;
111 /// Specifies the search direction.
112 bool mbDirectionIsForward;
115 /** Iterator all objects that belong to the current mark list
116 a.k.a. selection. It is assumed that all marked objects belong to the
117 same page. It is further assumed that the mark list does not change
118 while an iterator is alive. It is therefore the responsibility of an
119 iterator's owner to handle the case of a changed mark list.
121 <p>For documentation of the methods please refer to the base class
122 <type>IteratorImplBase</type>.</p>
124 class SelectionIteratorImpl final
125 : public IteratorImplBase
127 public:
128 SelectionIteratorImpl (
129 const ::std::vector< ::unotools::WeakReference<SdrObject> >& rObjectList,
130 sal_Int32 nObjectIndex,
131 SdDrawDocument* pDocument,
132 const std::weak_ptr<ViewShell>& rpViewShellWeak,
133 bool bDirectionIsForward);
134 SelectionIteratorImpl (const SelectionIteratorImpl& rObject);
135 virtual ~SelectionIteratorImpl() override;
137 virtual void GotoNextText() override;
138 virtual const IteratorPosition& GetPosition() override;
139 virtual IteratorImplBase* Clone (IteratorImplBase* pObject = nullptr) const override;
140 virtual bool operator== (const IteratorImplBase& rIterator) const override;
142 private:
143 const ::std::vector<::unotools::WeakReference<SdrObject>>& mrObjectList;
144 sal_Int32 mnObjectIndex;
146 /** Compare the given iterator with this object. This method handles
147 only the case that the given iterator is an instance of this class.
148 @param rIterator
149 The iterator to compare to.
150 @return
151 Returns <TRUE/> when both iterators point to the same object.
153 virtual bool IsEqualSelection(const IteratorImplBase& rIterator) const override;
155 IteratorImplBase& operator= (const IteratorImplBase& rIterator);
158 /** Iterator for iteration over all objects in a single view. On reaching
159 the last object on the last page (or the first object on the first page)
160 the view is *not* switched. Further calls to the
161 <member>GotoNextObject()</member> method will be ignored.
163 <p>For documentation of the methods please refer to the base class
164 <type>IteratorImplBase</type>.</p>
166 class ViewIteratorImpl : public IteratorImplBase
168 public:
169 ViewIteratorImpl (
170 sal_Int32 nPageIndex,
171 SdDrawDocument* pDocument,
172 const std::weak_ptr<ViewShell>& rpViewShellWeak,
173 bool bDirectionIsForward);
174 ViewIteratorImpl (
175 sal_Int32 nPageIndex,
176 SdDrawDocument* pDocument,
177 const std::weak_ptr<ViewShell>& rpViewShellWeak,
178 bool bDirectionIsForward,
179 PageKind ePageKind,
180 EditMode eEditMode);
181 virtual ~ViewIteratorImpl() override;
183 virtual void GotoNextText() override;
184 virtual IteratorImplBase* Clone (IteratorImplBase* pObject = nullptr) const override;
185 virtual void Reverse() override;
187 protected:
188 /** Set up page pointer and object list iterator for the specified
189 page.
190 @param nPageIndex
191 Index of the new page. It may lie outside the valid range for
192 page indices.
194 void SetPage (sal_Int32 nPageIndex);
196 private:
197 /// Indicates whether a page changed occurred on switching to current page.
198 bool mbPageChangeOccurred;
199 /// Pointer to the page associated with the current page index. May be NULL.
200 SdPage* mpPage;
201 /// Iterator of all objects on the current page.
202 std::optional<SdrObjListIter> moObjectIterator;
204 // Don't use this operator.
205 ViewIteratorImpl& operator= (const ViewIteratorImpl&) = delete;
208 /** Iterator for iteration over all objects in all views. It automatically
209 switches views when reaching the end/beginning of a view.
211 <p>For documentation of the methods please refer to the base class
212 <type>IteratorImplBase</type>.</p>
214 class DocumentIteratorImpl final : public ViewIteratorImpl
216 public:
217 DocumentIteratorImpl (
218 sal_Int32 nPageIndex,
219 PageKind ePageKind,
220 EditMode eEditMode,
221 SdDrawDocument* pDocument,
222 const std::weak_ptr<ViewShell>& rpViewShellWeak,
223 bool bDirectionIsForward);
224 virtual ~DocumentIteratorImpl() override;
226 virtual void GotoNextText() override;
227 virtual IteratorImplBase* Clone (IteratorImplBase* pObject = nullptr) const override;
229 private:
230 /// Number of pages in the view that is specified by <member>maPosition</member>.
231 sal_Int32 mnPageCount;
233 // Don't use this operator.
234 DocumentIteratorImpl& operator= (const DocumentIteratorImpl& ) = delete;
237 } } // end of namespace ::sd::outliner
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */