Dillo
widget.hh
Go to the documentation of this file.
1 #ifndef __DW_WIDGET_HH__
2 #define __DW_WIDGET_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 #include "../lout/identity.hh"
9 
13 typedef void (*DW_Callback_t)(void *data);
14 
15 namespace dw {
16 namespace core {
17 
24 {
25  friend class Layout;
26 
27 protected:
28  enum Flags {
33  NEEDS_RESIZE = 1 << 0,
34 
40  NEEDS_ALLOCATE = 1 << 1,
41 
46  EXTREMES_CHANGED = 1 << 2,
47 
54  USES_HINTS = 1 << 3,
55 
62  HAS_CONTENTS = 1 << 4,
63 
69  WAS_ALLOCATED = 1 << 5,
70 
74  BLOCK_LEVEL = 1 << 6,
75  };
76 
77 private:
83 
85 
93 
98 
103 
108 
113 
114 public:
122 
123 protected:
124 
130 
131  inline int getHeight () { return allocation.ascent + allocation.descent; }
132  inline int getContentWidth() { return allocation.width
133  - style->boxDiffWidth (); }
134  inline int getContentHeight() { return getHeight ()
135  - style->boxDiffHeight (); }
136 
138 
139  inline void setFlags (Flags f) { flags = (Flags)(flags | f); }
140  inline void unsetFlags (Flags f) { flags = (Flags)(flags & ~f); }
141 
142 
143  inline void queueDraw ()
144  {
146  }
147  void queueDrawArea (int x, int y, int width, int height);
148  void queueResize (int ref, bool extremesChanged);
149 
153  virtual void sizeRequestImpl (Requisition *requisition) = 0;
154 
158  virtual void getExtremesImpl (Extremes *extremes);
159 
163  virtual void sizeAllocateImpl (Allocation *allocation);
164 
169  virtual void resizeDrawImpl () { queueDraw (); };
170 
174  virtual void markSizeChange (int ref);
175 
179  virtual void markExtremesChange (int ref);
180 
181  virtual bool buttonPressImpl (EventButton *event);
182  virtual bool buttonReleaseImpl (EventButton *event);
183  virtual bool motionNotifyImpl (EventMotion *event);
184  virtual void enterNotifyImpl (EventCrossing *event);
185  virtual void leaveNotifyImpl (EventCrossing *event);
186 
187  inline char *addAnchor (const char* name)
188  { return layout->addAnchor (this, name); }
189 
190  inline char *addAnchor (const char* name, int y)
191  { return layout->addAnchor (this, name, y); }
192 
193  inline void changeAnchor (char* name, int y)
194  { layout->changeAnchor (this, name, y); }
195 
196  inline void removeAnchor (char* name)
197  { layout->removeAnchor (this, name); }
198 
199  //inline void updateBgColor () { layout->updateBgColor (); }
200 
201  inline void setCursor (style::Cursor cursor)
202  { layout->setCursor (cursor); }
203 
204  inline bool selectionButtonPress (Iterator *it, int charPos, int linkNo,
205  EventButton *event, bool withinContent)
206  { return layout->selectionState.buttonPress (it, charPos, linkNo, event); }
207 
208  inline bool selectionButtonRelease (Iterator *it, int charPos, int linkNo,
209  EventButton *event, bool withinContent)
210  { return layout->selectionState.buttonRelease (it, charPos, linkNo, event);}
211 
212  inline bool selectionButtonMotion (Iterator *it, int charPos, int linkNo,
213  EventMotion *event, bool withinContent)
214  { return layout->selectionState.buttonMotion (it, charPos, linkNo, event); }
215 
217  Iterator *it, int charPos, int linkNo,
218  MousePositionEvent *event)
219  { return layout->selectionState.handleEvent (eventType, it, charPos, linkNo,
220  event); }
221 
222 private:
225 
226 public:
227  inline void setDeleteCallback(DW_Callback_t func, void *data)
228  { deleteCallbackFunc = func; deleteCallbackData = data; }
229 
230 public:
231  static int CLASS_ID;
232 
233  Widget ();
234  ~Widget ();
235 
236  inline bool needsResize () { return flags & NEEDS_RESIZE; }
237  inline bool needsAllocate () { return flags & NEEDS_ALLOCATE; }
238  inline bool extremesChanged () { return flags & EXTREMES_CHANGED; }
239  inline bool wasAllocated () { return flags & WAS_ALLOCATED; }
240  inline bool usesHints () { return flags & USES_HINTS; }
241  inline bool hasContents () { return flags & HAS_CONTENTS; }
242  inline bool blockLevel () { return flags & BLOCK_LEVEL; }
243 
244  void setParent (Widget *parent);
245 
246  inline style::Style *getStyle () { return style; }
248  inline Allocation *getAllocation () { return &allocation; }
249 
251  void getExtremes (Extremes *extremes);
253  virtual void setWidth (int width);
254  virtual void setAscent (int ascent);
255  virtual void setDescent (int descent);
256 
257  bool intersects (Rectangle *area, Rectangle *intersection);
258 
260  virtual void draw (View *view, Rectangle *area) = 0;
261 
262  bool buttonPress (EventButton *event);
263  bool buttonRelease (EventButton *event);
264  bool motionNotify (EventMotion *event);
265  void enterNotify (EventCrossing *event);
266  void leaveNotify (EventCrossing *event);
267 
268  virtual void setStyle (style::Style *style);
271 
272  void drawBox (View *view, style::Style *style, Rectangle *area,
273  int x, int y, int width, int height, bool inverse);
274  void drawWidgetBox (View *view, Rectangle *area, bool inverse);
275  void drawSelected (View *view, Rectangle *area);
276 
278  inline bool isButtonSensitive () { return buttonSensitive; }
279 
280  inline Widget *getParent () { return parent; }
281  Widget *getTopLevel ();
282  int getLevel ();
283  Widget *getNearestCommonAncestor (Widget *otherWidget);
284 
285  inline Layout *getLayout () { return layout; }
286 
287  virtual Widget *getWidgetAtPoint (int x, int y, int level);
288 
289  void scrollTo (HPosition hpos, VPosition vpos,
290  int x, int y, int width, int height);
291 
305  virtual Iterator *iterator (Content::Type mask, bool atEnd) = 0;
306  virtual void removeChild (Widget *child);
307 };
308 
309 } // namespace dw
310 } // namespace core
311 
312 #endif // __DW_WIDGET_HH__