00001 #ifndef __ITERATOR_HH__
00002 #define __ITERATOR_HH__
00003
00004 #ifndef __INCLUDED_FROM_DW_CORE_HH__
00005 # error Do not include this file directly, use "core.hh" instead.
00006 #endif
00007
00008 namespace dw {
00009 namespace core {
00010
00019 class Iterator: public lout::object::Object, public lout::misc::Comparable
00020 {
00021 protected:
00022 Iterator(Widget *widget, Content::Type mask, bool atEnd);
00023 Iterator(Iterator &it);
00024 ~Iterator();
00025
00026 Content content;
00027
00028 private:
00029 Widget *widget;
00030 Content::Type mask;
00031
00032 public:
00033 bool equals (Object *other);
00034
00035 inline Widget *getWidget () { return widget; }
00036 inline Content *getContent () { return &content; }
00037 inline Content::Type getMask () { return mask; }
00038
00039 virtual void unref ();
00040
00046 virtual bool next () = 0;
00047
00053 virtual bool prev () = 0;
00054
00063 virtual void highlight (int start, int end, HighlightLayer layer) = 0;
00064
00073 virtual void unhighlight (int direction, HighlightLayer layer) = 0;
00074
00082 virtual void getAllocation (int start, int end, Allocation *allocation) = 0;
00083
00084 inline Iterator *cloneIterator () { return (Iterator*)clone(); }
00085
00086 static void scrollTo (Iterator *it1, Iterator *it2, int start, int end,
00087 HPosition hpos, VPosition vpos);
00088 };
00089
00090
00095 class EmptyIterator: public Iterator
00096 {
00097 private:
00098 EmptyIterator (EmptyIterator &it);
00099
00100 public:
00101 EmptyIterator (Widget *widget, Content::Type mask, bool atEnd);
00102
00103 lout::object::Object *clone();
00104 int compareTo(lout::misc::Comparable *other);
00105 bool next ();
00106 bool prev ();
00107 void highlight (int start, int end, HighlightLayer layer);
00108 void unhighlight (int direction, HighlightLayer layer);
00109 void getAllocation (int start, int end, Allocation *allocation);
00110 };
00111
00112
00117 class TextIterator: public Iterator
00118 {
00119 private:
00121 const char *text;
00122
00123 TextIterator (TextIterator &it);
00124
00125 public:
00126 TextIterator (Widget *widget, Content::Type mask, bool atEnd,
00127 const char *text);
00128
00129 int compareTo(lout::misc::Comparable *other);
00130
00131 bool next ();
00132 bool prev ();
00133 void getAllocation (int start, int end, Allocation *allocation);
00134 };
00135
00136
00145 class DeepIterator: public lout::object::Object, public lout::misc::Comparable
00146 {
00147 private:
00148 class Stack: public lout::container::typed::Vector<Iterator>
00149 {
00150 public:
00151 inline Stack (): lout::container::typed::Vector<Iterator> (4, false) { }
00152 ~Stack ();
00153 inline Iterator *getTop () { return get (size () - 1); }
00154 inline void push (Iterator *it) { put(it, -1); }
00155 inline void pop() { getTop()->unref (); remove (size () - 1); }
00156 };
00157
00158 Stack stack;
00159
00160 static Iterator *searchDownward (Iterator *it, Content::Type mask,
00161 bool fromEnd);
00162 static Iterator *searchSideward (Iterator *it, Content::Type mask,
00163 bool fromEnd);
00164
00165 Content::Type mask;
00166 Content content;
00167 bool hasContents;
00168
00169 inline DeepIterator () { }
00170
00171 public:
00172 DeepIterator(Iterator *it);
00173 ~DeepIterator();
00174
00175 lout::object::Object *clone ();
00176
00177 DeepIterator *createVariant(Iterator *it);
00178 inline Iterator *getTopIterator () { return stack.getTop(); }
00179 inline Content *getContent () { return &content; }
00180
00181 bool isEmpty ();
00182
00183 bool next ();
00184 bool prev ();
00185 inline DeepIterator *cloneDeepIterator() { return (DeepIterator*)clone(); }
00186 int compareTo(lout::misc::Comparable *other);
00187
00196 inline void highlight (int start, int end, HighlightLayer layer)
00197 { stack.getTop()->highlight (start, end, layer); }
00198
00206 inline void getAllocation (int start, int end, Allocation *allocation)
00207 { stack.getTop()->getAllocation (start, end, allocation); }
00208
00209 inline void unhighlight (int direction, HighlightLayer layer)
00210 { stack.getTop()->unhighlight (direction, layer); }
00211
00212 inline static void scrollTo (DeepIterator *it1, DeepIterator *it2,
00213 int start, int end,
00214 HPosition hpos, VPosition vpos)
00215 { Iterator::scrollTo(it1->stack.getTop(), it2->stack.getTop(),
00216 start, end, hpos, vpos); }
00217 };
00218
00219 class CharIterator: public lout::object::Object, public lout::misc::Comparable
00220 {
00221 public:
00222
00223
00224 enum { START = 257, END = 258 };
00225
00226 private:
00227 DeepIterator *it;
00228 int pos, ch;
00229
00230 CharIterator ();
00231
00232 public:
00233 CharIterator (Widget *widget);
00234 ~CharIterator ();
00235
00236 lout::object::Object *clone();
00237 int compareTo(lout::misc::Comparable *other);
00238
00239 bool next ();
00240 bool prev ();
00241 inline int getChar() { return ch; }
00242 inline CharIterator *cloneCharIterator() { return (CharIterator*)clone(); }
00243
00244 static void highlight (CharIterator *it1, CharIterator *it2,
00245 HighlightLayer layer);
00246 static void unhighlight (CharIterator *it1, CharIterator *it2,
00247 HighlightLayer layer);
00248
00249 inline static void scrollTo (CharIterator *it1, CharIterator *it2,
00250 HPosition hpos, VPosition vpos)
00251 { DeepIterator::scrollTo(it1->it, it2->it, it1->pos, it2->pos,
00252 hpos, vpos); }
00253 };
00254
00255 }
00256 }
00257
00258 #endif // __ITERATOR_HH__