Dillo
iterator.hh
Go to the documentation of this file.
1 #ifndef __ITERATOR_HH__
2 #define __ITERATOR_HH__
3 
4 #ifndef __INCLUDED_FROM_DW_CORE_HH__
5 # error Do not include this file directly, use "core.hh" instead.
6 #endif
7 
8 namespace dw {
9 namespace core {
10 
20 {
21 protected:
22  Iterator(Widget *widget, Content::Type mask, bool atEnd);
23  Iterator(Iterator &it);
24  ~Iterator();
25 
27 
28 private:
31 
32 public:
33  bool equals (Object *other);
35 
36  inline Widget *getWidget () { return widget; }
37  inline Content *getContent () { return &content; }
38  inline Content::Type getMask () { return mask; }
39 
40  virtual void unref ();
41 
47  virtual bool next () = 0;
48 
54  virtual bool prev () = 0;
55 
64  virtual void highlight (int start, int end, HighlightLayer layer) = 0;
65 
74  virtual void unhighlight (int direction, HighlightLayer layer) = 0;
75 
83  virtual void getAllocation (int start, int end, Allocation *allocation) = 0;
84 
85  inline Iterator *cloneIterator () { return (Iterator*)clone(); }
86 
87  static void scrollTo (Iterator *it1, Iterator *it2, int start, int end,
88  HPosition hpos, VPosition vpos);
89 };
90 
91 
96 class EmptyIterator: public Iterator
97 {
98 private:
100 
101 public:
102  EmptyIterator (Widget *widget, Content::Type mask, bool atEnd);
103 
106  bool next ();
107  bool prev ();
108  void highlight (int start, int end, HighlightLayer layer);
109  void unhighlight (int direction, HighlightLayer layer);
110  void getAllocation (int start, int end, Allocation *allocation);
111 };
112 
113 
118 class TextIterator: public Iterator
119 {
120 private:
122  const char *text;
123 
125 
126 public:
128  const char *text);
129 
131 
132  bool next ();
133  bool prev ();
134  void getAllocation (int start, int end, Allocation *allocation);
135 };
136 
137 
147 {
148 private:
149  class Stack: public lout::container::typed::Vector<Iterator>
150  {
151  public:
152  inline Stack (): lout::container::typed::Vector<Iterator> (4, false) { }
153  ~Stack ();
154  inline Iterator *getTop () { return get (size () - 1); }
155  inline void push (Iterator *it) { put(it, -1); }
156  inline void pop() { getTop()->unref (); remove (size () - 1); }
157  };
158 
160 
162  bool fromEnd);
164  bool fromEnd);
165 
169 
170  inline DeepIterator () { }
171 
172  static Widget *getRespectiveParent (Widget *widget, Content::Type mask);
173  inline Widget *getRespectiveParent (Widget *widget) {
174  return getRespectiveParent (widget, mask);
175  }
176 
177  static int getRespectiveLevel (Widget *widget, Content::Type mask);
178  inline int getRespectiveLevel (Widget *widget) {
179  return getRespectiveLevel (widget, mask);
180  }
181 
182 public:
183  DeepIterator(Iterator *it);
184  ~DeepIterator();
185 
187 
189  inline Iterator *getTopIterator () { return stack.getTop(); }
190  inline Content *getContent () { return &content; }
191 
192  bool isEmpty ();
193 
194  bool next ();
195  bool prev ();
198 
207  inline void highlight (int start, int end, HighlightLayer layer)
208  { stack.getTop()->highlight (start, end, layer); }
209 
217  inline void getAllocation (int start, int end, Allocation *allocation)
218  { stack.getTop()->getAllocation (start, end, allocation); }
219 
220  inline void unhighlight (int direction, HighlightLayer layer)
221  { stack.getTop()->unhighlight (direction, layer); }
222 
223  inline static void scrollTo (DeepIterator *it1, DeepIterator *it2,
224  int start, int end,
225  HPosition hpos, VPosition vpos)
226  { Iterator::scrollTo(it1->stack.getTop(), it2->stack.getTop(),
227  start, end, hpos, vpos); }
228 };
229 
231 {
232 public:
233  // START and END must not clash with any char value
234  // neither for signed nor unsigned char.
235  enum { START = 257, END = 258 };
236 
237 private:
239  int pos, ch;
240 
241  CharIterator ();
242 
243 public:
244  CharIterator (Widget *widget, bool followReferences);
245  ~CharIterator ();
246 
249 
250  bool next ();
251  bool prev ();
252  inline int getChar() { return ch; }
254 
255  static void highlight (CharIterator *it1, CharIterator *it2,
256  HighlightLayer layer);
257  static void unhighlight (CharIterator *it1, CharIterator *it2,
258  HighlightLayer layer);
259 
260  inline static void scrollTo (CharIterator *it1, CharIterator *it2,
261  HPosition hpos, VPosition vpos)
262  { DeepIterator::scrollTo(it1->it, it2->it, it1->pos, it2->pos,
263  hpos, vpos); }
264 };
265 
266 } // namespace core
267 } // namespace dw
268 
269 #endif // __ITERATOR_HH__
Content content
Definition: iterator.hh:26
~DeepIterator()
Definition: iterator.cc:591
virtual void unhighlight(int direction, HighlightLayer layer)=0
Shrink highlighted region to no longer contain the current content.
static void highlight(CharIterator *it1, CharIterator *it2, HighlightLayer layer)
Definition: iterator.cc:857
const char * text
Definition: iterator.hh:122
Typed version of container::untyped::Vector.
Definition: container.hh:425
int getChar()
Definition: iterator.hh:252
void push(Iterator *it)
Definition: iterator.hh:155
EmptyIterator(EmptyIterator &it)
Definition: iterator.cc:217
Content::Type mask
Definition: iterator.hh:166
Definition: iterator.hh:149
This implementation of dw::core::Iterator can be used by widgets with no contents.
Definition: iterator.hh:96
CharIterator * cloneCharIterator()
Definition: iterator.hh:253
A class for fast concatenation of a large number of strings.
Definition: misc.hh:565
bool equals(Object *other)
Returns, whether two objects are equal.
Definition: iterator.cc:50
Iterator * getTopIterator()
Definition: iterator.hh:189
lout::object::Object * clone()
Return an exact copy of the object.
Definition: iterator.cc:221
Stack()
Definition: iterator.hh:152
bool prev()
Definition: iterator.cc:821
Type
Definition: types.hh:199
virtual bool prev()=0
Move iterator backward and store content it.
DeepIterator * cloneDeepIterator()
Definition: iterator.hh:196
lout::object::Object * clone()
Return an exact copy of the object.
Definition: iterator.cc:763
~Iterator()
Definition: iterator.cc:46
Iterator * cloneIterator()
Definition: iterator.hh:85
Content::Type getMask()
Definition: iterator.hh:38
This is the base class for many other classes, which defines very common virtual methods.
Definition: object.hh:24
static int getRespectiveLevel(Widget *widget, Content::Type mask)
Definition: iterator.cc:475
bool hasContents
Definition: iterator.hh:168
~Stack()
Definition: iterator.cc:338
int size()
Definition: container.hh:418
static Widget * getRespectiveParent(Widget *widget, Content::Type mask)
Definition: iterator.cc:462
int getRespectiveLevel(Widget *widget)
Definition: iterator.hh:178
void put(Iterator *newElement, int newPos=-1)
Definition: container.hh:431
int compareTo(lout::object::Comparable *other)
Compare two objects, this and other.
Definition: iterator.cc:226
bool isEmpty()
Definition: iterator.cc:662
Instances of a sub class of may be compared (less, greater).
Definition: object.hh:41
static void scrollTo(DeepIterator *it1, DeepIterator *it2, int start, int end, HPosition hpos, VPosition vpos)
Definition: iterator.hh:223
~CharIterator()
Definition: iterator.cc:757
bool prev()
Move iterator backward and store content it.
Definition: iterator.cc:704
Iterators are used to iterate through the contents of a widget.
Definition: iterator.hh:19
static Iterator * searchDownward(Iterator *it, Content::Type mask, bool fromEnd)
Definition: iterator.cc:356
void unhighlight(int direction, HighlightLayer layer)
Shrink highlighted region to no longer contain the current content.
Definition: iterator.cc:254
Iterator(Widget *widget, Content::Type mask, bool atEnd)
Definition: iterator.cc:34
Definition: iterator.hh:235
CharIterator()
Definition: iterator.cc:736
static Iterator * searchSideward(Iterator *it, Content::Type mask, bool fromEnd)
Definition: iterator.cc:403
lout::object::Object * clone()
Return an exact copy of the object.
Definition: iterator.cc:596
Widget * getRespectiveParent(Widget *widget)
Definition: iterator.hh:173
virtual void unref()
Delete the iterator.
Definition: iterator.cc:82
void intoStringBuffer(lout::misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition: iterator.cc:58
bool next()
Move iterator forward and store content it.
Definition: iterator.cc:238
TextIterator(TextIterator &it)
Definition: iterator.cc:273
Represents the allocation, i.e. actual position and size of a dw::core::Widget.
Definition: types.hh:163
DeepIterator()
Definition: iterator.hh:170
HPosition
Definition: types.hh:15
int compareTo(lout::object::Comparable *other)
Compare two objects, this and other.
Definition: iterator.cc:278
VPosition
Definition: types.hh:25
void pop()
Definition: iterator.hh:156
Vector(int initSize, bool ownerOfObjects)
Definition: container.hh:428
bool next()
Move iterator forward and store content it.
Definition: iterator.cc:671
The base class of all dillo widgets.
Definition: widget.hh:23
Stack stack
Definition: iterator.hh:159
static void scrollTo(Iterator *it1, Iterator *it2, int start, int end, HPosition hpos, VPosition vpos)
Scrolls the viewport, so that the region between it1 and it2 is seen, according to hpos and vpos...
Definition: iterator.cc:98
Definition: container.cc:27
int compareTo(lout::object::Comparable *other)
Compare two objects, this and other.
Definition: iterator.cc:610
Definition: types.hh:197
DeepIterator * createVariant(Iterator *it)
Definition: iterator.cc:656
int pos
Definition: iterator.hh:239
void highlight(int start, int end, HighlightLayer layer)
Extend highlighted region to contain part of the current content.
Definition: iterator.cc:250
virtual void getAllocation(int start, int end, Allocation *allocation)=0
Return the shape, which a part of the item, the iterator points on, allocates.
HighlightLayer
Definition: types.hh:42
A stack of iterators, to iterate recursively through a widget tree.
Definition: iterator.hh:146
virtual bool next()=0
Move iterator forward and store content it.
void unhighlight(int direction, HighlightLayer layer)
Definition: iterator.hh:220
virtual void highlight(int start, int end, HighlightLayer layer)=0
Extend highlighted region to contain part of the current content.
Definition: iterator.hh:235
void getAllocation(int start, int end, Allocation *allocation)
Return the shape, which a part of the item, the iterator points on, allocates.
Definition: iterator.hh:217
void highlight(int start, int end, HighlightLayer layer)
Highlight a part of the current content.
Definition: iterator.hh:207
bool next()
Definition: iterator.cc:782
This implementation of dw::core::Iterator can be used by widgets having one text word as contents...
Definition: iterator.hh:118
Dw is in this namespace, or sub namespaces of this one.
Definition: alignedtablecell.cc:28
Widget * widget
Definition: iterator.hh:29
void getAllocation(int start, int end, Allocation *allocation)
Return the shape, which a part of the item, the iterator points on, allocates.
Definition: iterator.cc:258
Content * getContent()
Definition: iterator.hh:190
Content content
Definition: iterator.hh:167
int compareTo(lout::object::Comparable *other)
Compare two objects, this and other.
Definition: iterator.cc:772
Widget * getWidget()
Definition: iterator.hh:36
static void scrollTo(CharIterator *it1, CharIterator *it2, HPosition hpos, VPosition vpos)
Definition: iterator.hh:260
static void unhighlight(CharIterator *it1, CharIterator *it2, HighlightLayer layer)
Definition: iterator.cc:887
void getAllocation(int start, int end, Allocation *allocation)
Return the shape, which a part of the item, the iterator points on, allocates.
Definition: iterator.cc:328
int ch
Definition: iterator.hh:239
bool next()
Move iterator forward and store content it.
Definition: iterator.cc:304
Content * getContent()
Definition: iterator.hh:37
bool prev()
Move iterator backward and store content it.
Definition: iterator.cc:316
virtual Object * clone()
Return an exact copy of the object.
Definition: object.cc:68
bool prev()
Move iterator backward and store content it.
Definition: iterator.cc:244
DeepIterator * it
Definition: iterator.hh:238
Iterator * getTop()
Definition: iterator.hh:154
Definition: iterator.hh:230
Content::Type mask
Definition: iterator.hh:30