bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / inc / OutlinerIteratorImpl.hxx
blob0181b5ac0c7501ac85e912f8124838cf6e6ddb58
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 #ifndef INCLUDED_SD_SOURCE_UI_INC_OUTLINERITERATORIMPL_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_OUTLINERITERATORIMPL_HXX
23 #include <OutlinerIterator.hxx>
24 #include <memory>
26 class SdDrawDocument;
27 class SdPage;
28 class SdrObjListIter;
30 namespace sd {
32 class ViewShell;
34 namespace outliner {
36 /** Base class for the polymorphic implementation class of the
37 <type>Iterator</type> class. The iterators based on this class are
38 basically uni directional iterators. Their direction can, however, be
39 reversed at any point of their life time.
41 class IteratorImplBase
43 public:
44 /** The constructor stores the given arguments to be used by the derived
45 classes.
46 @param pDocument
47 The document provides the information to be iterated on.
48 @param pViewShellWeak
49 Some information has to be taken from the view shell.
50 @param bDirectionIsForward
51 This flag defines the iteration direction. When <TRUE/> then
52 the direction is forwards otherwise it is backwards.
54 IteratorImplBase (SdDrawDocument* pDocument,
55 const std::weak_ptr<ViewShell>& rpViewShellWeak,
56 bool bDirectionIsForward);
57 IteratorImplBase (SdDrawDocument* pDocument,
58 const std::weak_ptr<ViewShell>& rpViewShellWeak,
59 bool bDirectionIsForward, PageKind ePageKind, EditMode eEditMode);
60 virtual ~IteratorImplBase();
62 /** Advance to the next text of the current object or to the next object.
63 This takes the iteration direction into
64 account. The new object pointed to can be retrieved (among other
65 information) by calling the <member>GetPosition</member> method.
67 virtual void GotoNextText() = 0;
68 /** Return an object that describes the current object.
69 @return
70 The returned object describes the current object pointed to by
71 the iterator. See the description of
72 <type>IteratorPosition</type> for details on the available
73 information.
75 virtual const IteratorPosition& GetPosition();
76 /** Create an exact copy of this object. No argument should be
77 specified when called from the outside. It then creates an object
78 first and passes that to the inherited <member>Clone()</member>
79 methods to fill in class specific information.
80 @return
81 Returns a copy of this object. When this method is called with
82 an argument then this value will be returned.
84 virtual IteratorImplBase* Clone (IteratorImplBase* pObject=nullptr) const;
85 /** Test the equality of the this object and the given iterator. Two
86 iterators are taken to be equal when they point to the same object.
87 Iteration direction is not taken into account.
88 @param rIterator
89 The iterator to compare to.
90 @return
91 When both iterators are equal <TRUE/> is returned, <FALSE/> otherwise.
93 virtual bool operator== (const IteratorImplBase& rIterator) const;
94 /** This method is used by the equality operator. It is part of a "multimethod" pattern.
95 @param rIterator
96 The iterator to compare to.
97 @return
98 Returns <TRUE/> when both iterators point to the same object.
100 virtual bool IsEqualSelection(const IteratorImplBase& rIterator) const;
101 /** Reverse the direction of iteration. The current object stays the same.
103 virtual void Reverse();
105 protected:
106 /// The current position as returned by <member>GetPosition()</member>.
107 IteratorPosition maPosition;
108 /// The document on whose data the iterator operates.
109 SdDrawDocument* mpDocument;
110 /// Necessary secondary source of information.
111 std::weak_ptr<ViewShell> mpViewShellWeak;
112 /// Specifies the search direction.
113 bool mbDirectionIsForward;
116 /** Iterator all objects that belong to the current mark list
117 a.k.a. selection. It is assumed that all marked objects belong to the
118 same page. It is further assumed that the mark list does not change
119 while an iterator is alive. It is therefore the responsibility of an
120 iterator's owner to handle the case of a changed mark list.
122 <p>For documentation of the methods please refere to the base class
123 <type>IteratorImplBase</type>.</p>
125 class SelectionIteratorImpl
126 : public IteratorImplBase
128 public:
129 SelectionIteratorImpl (
130 const ::std::vector< tools::WeakReference<SdrObject> >& rObjectList,
131 sal_Int32 nObjectIndex,
132 SdDrawDocument* pDocument,
133 const std::weak_ptr<ViewShell>& rpViewShellWeak,
134 bool bDirectionIsForward);
135 SelectionIteratorImpl (const SelectionIteratorImpl& rObject);
136 virtual ~SelectionIteratorImpl() override;
138 virtual void GotoNextText() override;
139 virtual const IteratorPosition& GetPosition() override;
140 virtual IteratorImplBase* Clone (IteratorImplBase* pObject = nullptr) const override;
141 virtual bool operator== (const IteratorImplBase& rIterator) const override;
143 private:
144 const ::std::vector<tools::WeakReference<SdrObject>>& mrObjectList;
145 sal_Int32 mnObjectIndex;
147 /** Compare the given iterator with this object. This method handles
148 only the case that the given iterator is an instance of this class.
149 @param rIterator
150 The iterator to compare to.
151 @return
152 Returns <TRUE/> when both iterators point to the same object.
154 virtual bool IsEqualSelection(const IteratorImplBase& rIterator) const override;
156 IteratorImplBase& operator= (const IteratorImplBase& rIterator);
159 /** Iterator for iteration over all objects in a single view. On reaching
160 the last object on the last page (or the first object on the first page)
161 the view is *not* switched. Further calls to the
162 <member>GotoNextObject()</member> method will be ignored.
164 <p>For documentation of the methods please refere to the base class
165 <type>IteratorImplBase</type>.</p>
167 class ViewIteratorImpl : public IteratorImplBase
169 public:
170 ViewIteratorImpl (
171 sal_Int32 nPageIndex,
172 SdDrawDocument* pDocument,
173 const std::weak_ptr<ViewShell>& rpViewShellWeak,
174 bool bDirectionIsForward);
175 ViewIteratorImpl (
176 sal_Int32 nPageIndex,
177 SdDrawDocument* pDocument,
178 const std::weak_ptr<ViewShell>& rpViewShellWeak,
179 bool bDirectionIsForward,
180 PageKind ePageKind,
181 EditMode eEditMode);
182 virtual ~ViewIteratorImpl() override;
184 virtual void GotoNextText() override;
185 virtual IteratorImplBase* Clone (IteratorImplBase* pObject = nullptr) const override;
186 virtual void Reverse() override;
188 protected:
189 /** Set up page pointer and object list iterator for the specified
190 page.
191 @param nPageIndex
192 Index of the new page. It may lie outside the valid range for
193 page indices.
195 void SetPage (sal_Int32 nPageIndex);
197 private:
198 /// Indicates whether a page changed occurred on switching to current page.
199 bool mbPageChangeOccurred;
200 /// Pointer to the page associated with the current page index. May be NULL.
201 SdPage* mpPage;
202 /// Iterator of all objects on the current page.
203 std::unique_ptr<SdrObjListIter> mpObjectIterator;
205 // Don't use this operator.
206 ViewIteratorImpl& operator= (const ViewIteratorImpl&) = delete;
209 /** Iterator for iteration over all objects in all views. It automatically
210 switches views when reaching the end/beginning of a view.
212 <p>For documentation of the methods please refere to the base class
213 <type>IteratorImplBase</type>.</p>
215 class DocumentIteratorImpl : public ViewIteratorImpl
217 public:
218 DocumentIteratorImpl (
219 sal_Int32 nPageIndex,
220 PageKind ePageKind,
221 EditMode eEditMode,
222 SdDrawDocument* pDocument,
223 const std::weak_ptr<ViewShell>& rpViewShellWeak,
224 bool bDirectionIsForward);
225 virtual ~DocumentIteratorImpl() override;
227 virtual void GotoNextText() override;
228 virtual IteratorImplBase* Clone (IteratorImplBase* pObject = nullptr) const override;
230 private:
231 /// Number of pages in the view that is specified by <member>maPosition</member>.
232 sal_Int32 mnPageCount;
234 // Don't use this operator.
235 DocumentIteratorImpl& operator= (const DocumentIteratorImpl& ) = delete;
238 } } // end of namespace ::sd::outliner
240 #endif
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */