Dillo v3.1.1-95-g3af05307
Loading...
Searching...
No Matches
oofawarewidget_iterator.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "oofawarewidget.hh"
21#include "ooffloatsmgr.hh"
22#include "oofposabsmgr.hh"
23#include "oofposfixedmgr.hh"
24
25using namespace dw;
26using namespace dw::core;
27using namespace lout::misc;
28using namespace lout::object;
29
30namespace dw {
31
32namespace oof {
33
34// "numContentsInFlow" is passed here to avoid indirectly calling the (virtual)
35// method numContentsInFlow() from the constructor.
37 (OOFAwareWidget *widget, Content::Type mask, bool atEnd,
38 int numContentsInFlow) :
39 Iterator (widget, mask, atEnd)
40{
41 if (atEnd) {
43 while (sectionIndex >= 0 &&
47 } else {
48 sectionIndex = 0;
49 index = -1;
50 }
51
53}
54
56 int index)
57{
58 this->sectionIndex = sectionIndex;
59 this->index = index;
60
61 if (sectionIndex < 0 || index < 0)
62 content.type = core::Content::START;
63 else if (sectionIndex >= NUM_SECTIONS || index >= numParts (sectionIndex))
64 content.type = core::Content::END;
65 else
66 getPart (sectionIndex, index, &content);
67}
68
70 int numContentsInFlow)
71{
72 DBG_OBJ_ENTER_O ("iterator", 0, getWidget(), "numParts", "%d, %d",
73 sectionIndex, numContentsInFlow);
74
75 OOFAwareWidget *widget = (OOFAwareWidget*)getWidget();
76 int result;
77
78 if (sectionIndex < 0 || sectionIndex > NUM_SECTIONS) {
79 DBG_OBJ_MARKF_O("iterator", 0, getWidget(), "invalid sectionIndex %d",
80 sectionIndex);
81 result = 0;
82 } else if (sectionIndex == 0)
83 result = numContentsInFlow == -1 ?
84 this->numContentsInFlow () : numContentsInFlow;
85 else
86 result = widget->outOfFlowMgr[sectionIndex - 1] ?
87 widget->outOfFlowMgr[sectionIndex - 1]->getNumWidgets () : 0;
88
89 DBG_OBJ_MSGF_O ("iterator", 1, getWidget(), "=> %d", result);
90 DBG_OBJ_LEAVE_O (getWidget());
91 return result;
92}
93
95 int index,
96 Content *content)
97{
98 OOFAwareWidget *widget = (OOFAwareWidget*)getWidget();
99
100 if (sectionIndex == 0)
101 getContentInFlow (index, content);
102 else {
104 content->widget =
105 widget->outOfFlowMgr[sectionIndex - 1]->getWidget (index);
106 }
107}
108
110{
112 sb->append (", sectionIndex = ");
113 sb->appendInt (sectionIndex);
114 sb->append (", index = ");
115 sb->appendInt (index);
116}
117
119{
121
122 if (sectionIndex != otherTI->sectionIndex)
123 return sectionIndex - otherTI->sectionIndex;
124 else
125 return index - otherTI->index;
126}
127
129{
130 DBG_OBJ_ENTER0_O ("iterator", 0, getWidget (),
131 "OOFAwareWidgetIterator/next");
132
134 StringBuffer sb;
135 intoStringBuffer (&sb);
136 DBG_OBJ_MSGF_O ("iterator", 1, getWidget (),
137 "initial value: %s; sectionIndex = %d, index = %d",
138 sb.getChars (), sectionIndex, index);
139 }
140
141 bool found = false;
142
143 if (content.type != Content::END) {
144 while (!found) {
145 ++index;
146
147 if (sectionIndex >= 0 && sectionIndex < NUM_SECTIONS &&
148 index >= 0 && index < numParts (sectionIndex)) {
149 getPart (sectionIndex, index, &content);
150 } else {
151 while (++sectionIndex < NUM_SECTIONS &&
152 numParts (sectionIndex) == 0) ;
153
154 if (sectionIndex >= NUM_SECTIONS) {
155 content.type = Content::END;
156 break;
157 } else {
158 index = -1;
159 continue;
160 }
161 }
162 found = (content.type & getMask());
163 }
164 }
165
167 StringBuffer sb;
168 intoStringBuffer (&sb);
169 DBG_OBJ_MSGF_O ("iterator", 1, getWidget (), "final value: %s",
170 sb.getChars ());
171 }
172
173 DBG_OBJ_LEAVE_VAL_O (getWidget (), "%s", boolToStr (found));
174 return found;
175}
176
178{
179 DBG_OBJ_ENTER0_O ("iterator", 0, getWidget (),
180 "OOFAwareWidgetIterator/prev");
181
183 StringBuffer sb;
184 intoStringBuffer (&sb);
185 DBG_OBJ_MSGF_O ("iterator", 1, getWidget (),
186 "initial value: %s; sectionIndex = %d, index = %d",
187 sb.getChars (), sectionIndex, index);
188 }
189
190 bool found = false;
191
192 if (content.type != Content::START) {
193 while (!found) {
194 index--;
195
196 if (sectionIndex >= 0 && sectionIndex < NUM_SECTIONS &&
197 index >= 0 && index < numParts (sectionIndex)) {
198 getPart (sectionIndex, index, &content);
199 } else {
200 while (--sectionIndex >= 0 && numParts (sectionIndex) == 0) ;
201
202 if (sectionIndex < 0) {
203 content.type = Content::START;
204 break;
205 } else {
206 index = numParts (sectionIndex);
207 continue;
208 }
209 }
210 found = (content.type & getMask());
211 }
212 }
213
215 StringBuffer sb;
216 intoStringBuffer (&sb);
217 DBG_OBJ_MSGF_O ("iterator", 1, getWidget (), "final value: %s",
218 sb.getChars ());
219 }
220
221 DBG_OBJ_LEAVE_VAL_O (getWidget (), "%s", boolToStr (found));
222 return found;
223}
224
226 HighlightLayer layer)
227{
228 // TODO What about OOF widgets?
229}
230
233 layer)
234{
235 // TODO What about OOF widgets?
236}
237
239 int end,
241 *allocation)
242{
243 // TODO Consider start and end?
244 OOFAwareWidget *widget = (OOFAwareWidget*)getWidget();
245 *allocation = *(widget->outOfFlowMgr[sectionIndex - 1]
246 ->getWidget(index)->getAllocation());
247}
248
249} // namespace oof
250
251} // namespace dw
Iterators are used to iterate through the contents of a widget.
Definition iterator.hh:20
void intoStringBuffer(lout::misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition iterator.cc:58
Allocation * getAllocation()
Definition widget.hh:484
Allocation allocation
The current allocation: size and position, always relative to the canvas.
Definition widget.hh:204
void getPart(int sectionIndex, int index, core::Content *content)
int numParts(int sectionIndex, int numContentsInFlow=-1)
OOFAwareWidgetIterator(OOFAwareWidget *widget, core::Content::Type mask, bool atEnd, int numContentsInFlow)
int compareTo(lout::object::Comparable *other)
Compare two objects, this and other.
void unhighlightOOF(int direction, core::HighlightLayer layer)
bool next()
Move iterator forward and store content it.
void getAllocationOOF(int start, int end, core::Allocation *allocation)
void highlightOOF(int start, int end, core::HighlightLayer layer)
void intoStringBuffer(lout::misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
bool prev()
Move iterator backward and store content it.
Base class for widgets which can act as container and generator for widgets out of flow.
OutOfFlowMgr * outOfFlowMgr[NUM_OOFM]
virtual int getNumWidgets()=0
virtual core::Widget * getWidget(int i)=0
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition identity.cc:70
A class for fast concatenation of a large number of strings.
Definition misc.hh:570
void appendInt(int n)
Definition misc.hh:594
void append(const char *str)
Append a NUL-terminated string to the buffer, with copying.
Definition misc.hh:593
const char * getChars()
Return a NUL-terminated strings containing all appended strings.
Definition misc.cc:86
Instances of a sub class of may be compared (less, greater).
Definition object.hh:42
#define DBG_IF_RTFL
Definition debug.hh:73
#define DBG_OBJ_LEAVE_O(obj)
#define DBG_OBJ_ENTER0_O(aspect, prio, obj, funname)
#define DBG_OBJ_LEAVE_VAL_O(obj, fmt,...)
#define DBG_OBJ_MSGF_O(aspect, prio, obj, fmt,...)
#define DBG_OBJ_MARKF_O(aspect, prio, obj, fmt,...)
#define DBG_OBJ_ENTER_O(aspect, prio, obj, funname, fmt,...)
The core of Dw is defined in this namespace.
Definition core.hh:23
HighlightLayer
Definition types.hh:43
Dw is in this namespace, or sub namespaces of this one.
Miscellaneous stuff, which does not fit anywhere else.
Definition misc.cc:31
const char * boolToStr(bool b)
Definition misc.hh:108
Here, some common classes (or interfaces) are defined, to standardize the access to other classes.
Definition object.cc:30
Represents the allocation, i.e.
Definition types.hh:164
@ WIDGET_OOF_CONT
widget out of flow (OOF); this widget (containing this content) is only the container (parent),...
Definition types.hh:212
Widget * widget
Definition types.hh:237