dillo  3.0.5
About: dillo is a small, fast, extensible Web browser particularly suitable for older or smaller computers and embedded systems (but only limited or no support for frames, CSS, JavaScript, Java).
  Fossies Dox: dillo-3.0.5.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

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 
83  {
84  private:
86 
87  public:
88  inline WidgetImgRenderer (Widget *widget) { this->widget = widget; }
89 
90  bool readyToDraw ();
91  void getBgArea (int *x, int *y, int *width, int *height);
92  void getRefArea (int *xRef, int *yRef, int *widthRef, int *heightRef);
94  void draw (int x, int y, int width, int height);
95  };
96 
98 
99 private:
105 
107 
115 
120 
125 
130 
135 
136 public:
144 
145 protected:
146 
152 
153  inline int getHeight () { return allocation.ascent + allocation.descent; }
154  inline int getContentWidth() { return allocation.width
155  - style->boxDiffWidth (); }
156  inline int getContentHeight() { return getHeight ()
157  - style->boxDiffHeight (); }
158 
160 
161  inline void setFlags (Flags f) { flags = (Flags)(flags | f); }
162  inline void unsetFlags (Flags f) { flags = (Flags)(flags & ~f); }
163 
164 
165  inline void queueDraw ()
166  {
168  }
169  void queueDrawArea (int x, int y, int width, int height);
170  void queueResize (int ref, bool extremesChanged);
171 
175  virtual void sizeRequestImpl (Requisition *requisition) = 0;
176 
180  virtual void getExtremesImpl (Extremes *extremes);
181 
185  virtual void sizeAllocateImpl (Allocation *allocation);
186 
191  virtual void resizeDrawImpl () { queueDraw (); };
192 
196  virtual void markSizeChange (int ref);
197 
201  virtual void markExtremesChange (int ref);
202 
203  virtual bool buttonPressImpl (EventButton *event);
204  virtual bool buttonReleaseImpl (EventButton *event);
205  virtual bool motionNotifyImpl (EventMotion *event);
206  virtual void enterNotifyImpl (EventCrossing *event);
207  virtual void leaveNotifyImpl (EventCrossing *event);
208 
209  inline char *addAnchor (const char* name)
210  { return layout->addAnchor (this, name); }
211 
212  inline char *addAnchor (const char* name, int y)
213  { return layout->addAnchor (this, name, y); }
214 
215  inline void changeAnchor (char* name, int y)
216  { layout->changeAnchor (this, name, y); }
217 
218  inline void removeAnchor (char* name)
219  { layout->removeAnchor (this, name); }
220 
221  //inline void updateBgColor () { layout->updateBgColor (); }
222 
223  inline void setCursor (style::Cursor cursor)
224  { layout->setCursor (cursor); }
225 #if 0
226  inline bool selectionButtonPress (Iterator *it, int charPos, int linkNo,
227  EventButton *event, bool withinContent)
228  { return layout->selectionState.buttonPress (it, charPos, linkNo, event); }
229 
230  inline bool selectionButtonRelease (Iterator *it, int charPos, int linkNo,
231  EventButton *event, bool withinContent)
232  { return layout->selectionState.buttonRelease (it, charPos, linkNo, event);}
233 
234  inline bool selectionButtonMotion (Iterator *it, int charPos, int linkNo,
235  EventMotion *event, bool withinContent)
236  { return layout->selectionState.buttonMotion (it, charPos, linkNo, event); }
237 #endif
239  Iterator *it, int charPos, int linkNo,
240  MousePositionEvent *event)
241  { return layout->selectionState.handleEvent (eventType, it, charPos, linkNo,
242  event); }
243 
244 private:
247 
248 public:
249  inline void setDeleteCallback(DW_Callback_t func, void *data)
250  { deleteCallbackFunc = func; deleteCallbackData = data; }
251 
252 public:
253  static int CLASS_ID;
254 
255  Widget ();
256  ~Widget ();
257 
258  inline bool needsResize () { return flags & NEEDS_RESIZE; }
259  inline bool needsAllocate () { return flags & NEEDS_ALLOCATE; }
260  inline bool extremesChanged () { return flags & EXTREMES_CHANGED; }
261  inline bool wasAllocated () { return flags & WAS_ALLOCATED; }
262  inline bool usesHints () { return flags & USES_HINTS; }
263  inline bool hasContents () { return flags & HAS_CONTENTS; }
264  inline bool blockLevel () { return flags & BLOCK_LEVEL; }
265 
266  void setParent (Widget *parent);
267 
268  inline style::Style *getStyle () { return style; }
270  inline Allocation *getAllocation () { return &allocation; }
271 
273  void getExtremes (Extremes *extremes);
275  virtual void setWidth (int width);
276  virtual void setAscent (int ascent);
277  virtual void setDescent (int descent);
278 
279  bool intersects (Rectangle *area, Rectangle *intersection);
280 
282  virtual void draw (View *view, Rectangle *area) = 0;
283 
284  bool buttonPress (EventButton *event);
285  bool buttonRelease (EventButton *event);
286  bool motionNotify (EventMotion *event);
287  void enterNotify (EventCrossing *event);
288  void leaveNotify (EventCrossing *event);
289 
290  virtual void setStyle (style::Style *style);
293 
294  void drawBox (View *view, style::Style *style, Rectangle *area,
295  int x, int y, int width, int height, bool inverse);
296  void drawWidgetBox (View *view, Rectangle *area, bool inverse);
297  void drawSelected (View *view, Rectangle *area);
298 
300  inline bool isButtonSensitive () { return buttonSensitive; }
301 
302  inline Widget *getParent () { return parent; }
303  Widget *getTopLevel ();
304  int getLevel ();
305  Widget *getNearestCommonAncestor (Widget *otherWidget);
306 
307  inline Layout *getLayout () { return layout; }
308 
309  virtual Widget *getWidgetAtPoint (int x, int y, int level);
310 
311  void scrollTo (HPosition hpos, VPosition vpos,
312  int x, int y, int width, int height);
313 
314  void getPaddingArea (int *xPad, int *yPad, int *widthPad, int *heightPad);
315 
329  virtual Iterator *iterator (Content::Type mask, bool atEnd) = 0;
330  virtual void removeChild (Widget *child);
331 };
332 
333 } // namespace core
334 } // namespace dw
335 
336 #endif // __DW_WIDGET_HH__
dw::core::Widget::removeAnchor
void removeAnchor(char *name)
Definition: widget.hh:218
dw::core::Widget::addAnchor
char * addAnchor(const char *name)
Definition: widget.hh:209
dw::core::SelectionState::buttonMotion
bool buttonMotion(Iterator *it, int charPos, int linkNo, EventMotion *event)
Definition: selection.cc:192
dw::core::Widget::needsAllocate
bool needsAllocate()
Definition: widget.hh:259
dw::core::Widget::buttonPress
bool buttonPress(EventButton *event)
Definition: widget.cc:293
dw::core::style::Cursor
Cursor
Definition: style.hh:198
dw::core::Widget::draw
virtual void draw(View *view, Rectangle *area)=0
dw::core::HPosition
HPosition
Definition: types.hh:15
dw::core::Widget::WidgetImgRenderer::widget
Widget * widget
Definition: widget.hh:85
dw::core::Widget::WidgetImgRenderer::getRefArea
void getRefArea(int *xRef, int *yRef, int *widthRef, int *heightRef)
Return the "reference area".
Definition: widget.cc:46
DW_Callback_t
void(* DW_Callback_t)(void *data)
The type for callback functions.
Definition: widget.hh:13
dw::core::Requisition
Definition: types.hh:172
dw::core::SelectionState::EventType
EventType
Definition: selection.hh:220
dw::core::Widget::NEEDS_RESIZE
Set, when dw::core::Widget::requisition is not up to date anymore.
Definition: widget.hh:33
dw::core::MousePositionEvent
Base class for all mouse events related to a specific position.
Definition: events.hh:48
dw::core::Widget::deleteCallbackData
void * deleteCallbackData
Definition: widget.hh:245
dw::core::EventCrossing
Represents a enter or leave notify event.
Definition: events.hh:74
dw::core::Layout::selectionState
SelectionState selectionState
Definition: layout.hh:184
dw::core::EventButton
Represents a button press or release event.
Definition: events.hh:57
dw::core::Widget::layout
Layout * layout
Definition: widget.hh:159
dw::core::Widget::enterNotify
void enterNotify(EventCrossing *event)
Definition: widget.cc:308
dw::core::style::Color
Definition: style.hh:709
dw::core::Widget::scrollTo
void scrollTo(HPosition hpos, VPosition vpos, int x, int y, int width, int height)
Definition: widget.cc:589
dw::core::Widget::getPaddingArea
void getPaddingArea(int *xPad, int *yPad, int *widthPad, int *heightPad)
Return the padding area (content plus padding).
Definition: widget.cc:602
dw::core::Widget::setAscent
virtual void setAscent(int ascent)
Definition: widget.cc:637
dw::core::Content::Type
Type
Definition: types.hh:187
dw::core::Widget::getLevel
int getLevel()
Get the level of the widget within the tree.
Definition: widget.cc:499
dw::core::Widget::removeChild
virtual void removeChild(Widget *child)
Definition: widget.cc:676
dw::core::Widget::WidgetImgRenderer::draw
void draw(int x, int y, int width, int height)
Draw (or queue for drawing) an area, which is given in canvas coordinates.
Definition: widget.cc:57
dw::core::Iterator
Iterators are used to iterate through the contents of a widget.
Definition: iterator.hh:19
dw::core::Widget::setButtonSensitive
void setButtonSensitive(bool buttonSensitive)
Definition: widget.cc:474
dw::core::Widget::EXTREMES_CHANGED
Set, when dw::core::Widget::extremes is not up to date anymore.
Definition: widget.hh:46
dw::core::Widget::isButtonSensitive
bool isButtonSensitive()
Definition: widget.hh:300
dw::core::Widget::setWidth
virtual void setWidth(int width)
Definition: widget.cc:633
dw::core::Layout::setCursor
void setCursor(style::Cursor cursor)
Definition: layout.cc:717
dw::core::Widget::getBgColor
style::Color * getBgColor()
Get the actual background of a widget.
Definition: widget.cc:377
dw::core::Widget::setFlags
void setFlags(Flags f)
Definition: widget.hh:161
dw::core::Widget::parentRef
int parentRef
This value is defined by the parent widget, and used for incremential resizing.
Definition: widget.hh:143
dw::core::Widget::setCursor
void setCursor(style::Cursor cursor)
Definition: widget.hh:223
dw::core::Widget::setParent
void setParent(Widget *parent)
Definition: widget.cc:144
dw::core::Widget::buttonSensitive
bool buttonSensitive
See dw::core::Widget::setButtonSensitive().
Definition: widget.hh:129
dw::core::Allocation
Represents the allocation, i.e. actual position and size of a dw::core::Widget.
Definition: types.hh:163
dw::core::Widget::WidgetImgRenderer::getBgArea
void getBgArea(int *x, int *y, int *width, int *height)
Return the area covered by the background image.
Definition: widget.cc:40
dw::core::Widget::getParent
Widget * getParent()
Definition: widget.hh:302
dw::core::Widget::getStyle
style::Style * getStyle()
Definition: widget.hh:268
dw::core::Widget::style
style::Style * style
Definition: widget.hh:104
dw::core::Widget::iterator
virtual Iterator * iterator(Content::Type mask, bool atEnd)=0
Return an iterator for this widget.
dw::core::Widget::markSizeChange
virtual void markSizeChange(int ref)
See Sizes of Dillo Widgets.
Definition: widget.cc:625
dw::core::Widget::sizeAllocate
void sizeAllocate(Allocation *allocation)
Wrapper for Widget::sizeAllocateImpl, calls the latter only when needed.
Definition: widget.cc:249
dw::core::Widget::markExtremesChange
virtual void markExtremesChange(int ref)
See Sizes of Dillo Widgets.
Definition: widget.cc:629
dw::core::Widget::blockLevel
bool blockLevel()
Definition: widget.hh:264
dw::core::Widget::getLayout
Layout * getLayout()
Definition: widget.hh:307
dw::core::Widget::sizeRequestImpl
virtual void sizeRequestImpl(Requisition *requisition)=0
See Sizes of Dillo Widgets.
dw::core::Widget::WidgetImgRenderer::WidgetImgRenderer
WidgetImgRenderer(Widget *widget)
Definition: widget.hh:88
dw::core::SelectionState::buttonRelease
bool buttonRelease(Iterator *it, int charPos, int linkNo, EventButton *event)
Definition: selection.cc:150
dw::core::Widget::getContentHeight
int getContentHeight()
Definition: widget.hh:156
dw::core::Widget::getHeight
int getHeight()
Definition: widget.hh:153
dw::core::Widget::resizeDrawImpl
virtual void resizeDrawImpl()
Called after sizeAllocateImpl() to redraw necessary areas. By default the whole widget is redrawn.
Definition: widget.hh:191
dw::core::Widget::getNearestCommonAncestor
Widget * getNearestCommonAncestor(Widget *otherWidget)
Get the widget with the highest level, which is a direct ancestor of widget1 and widget2.
Definition: widget.cc:516
dw::core::Allocation::descent
int descent
Definition: types.hh:169
dw::core::style::StyleAttrs::boxDiffHeight
int boxDiffHeight()
Definition: style.hh:558
dw::core::Widget::drawWidgetBox
void drawWidgetBox(View *view, Rectangle *area, bool inverse)
Draw borders and background of a widget.
Definition: widget.cc:436
dw::core::Widget::hasContents
bool hasContents()
Definition: widget.hh:263
dw::core::Widget::HAS_CONTENTS
Set by the widget itself (in the constructor), when it contains some contents, e.g....
Definition: widget.hh:62
dw::core::Widget::sizeAllocateImpl
virtual void sizeAllocateImpl(Allocation *allocation)
See Sizes of Dillo Widgets.
Definition: widget.cc:621
dw::core::Widget::motionNotifyImpl
virtual bool motionNotifyImpl(EventMotion *event)
Definition: widget.cc:655
dw::core::EventMotion
Represents a mouse motion event.
Definition: events.hh:67
dw::core::Widget::Widget
Widget()
Definition: widget.cc:67
dw::core::Widget::addAnchor
char * addAnchor(const char *name, int y)
Definition: widget.hh:212
dw::core::Widget::WidgetImgRenderer
Implementation which represents the whole widget.
Definition: widget.hh:82
dw::core::Widget::requisition
Requisition requisition
Size_request() stores the result of the last call of size_request_impl().
Definition: widget.hh:114
dw::core::Widget::BLOCK_LEVEL
Set for block-level widgets (as opposed to inline widgets)
Definition: widget.hh:74
dw::core::Layout::changeAnchor
void changeAnchor(Widget *widget, char *name, int y)
Definition: layout.cc:681
dw::core::Layout::addAnchor
char * addAnchor(Widget *widget, const char *name)
Definition: layout.cc:658
dw::core::Widget::deleteCallbackFunc
DW_Callback_t deleteCallbackFunc
Definition: widget.hh:246
dw::core::Widget::intersects
bool intersects(Rectangle *area, Rectangle *intersection)
Calculates the intersection of widget->allocation and area, returned in intersection (in widget coord...
Definition: widget.cc:123
dw::core::Widget::enterNotifyImpl
virtual void enterNotifyImpl(EventCrossing *event)
Definition: widget.cc:660
dw::core::Widget::setDeleteCallback
void setDeleteCallback(DW_Callback_t func, void *data)
Definition: widget.hh:249
dw::core::Layout
The central class for managing and drawing a widget tree.
Definition: layout.hh:16
dw::core::Widget::bgColor
style::Color * bgColor
See dw::core::Widget::setBgColor().
Definition: widget.hh:124
dw::core::Widget::getWidgetAtPoint
virtual Widget * getWidgetAtPoint(int x, int y, int level)
Search recursively through widget.
Definition: widget.cc:552
dw::core::Widget::parent
Widget * parent
The parent widget, NULL for top-level widgets.
Definition: widget.hh:103
dw::core::Widget::getTopLevel
Widget * getTopLevel()
Get the widget at the root of the tree, this widget is part from.
Definition: widget.cc:484
dw::core::Widget::NEEDS_ALLOCATE
Only used internally, set to enforce size allocation.
Definition: widget.hh:40
dw::core::Widget::needsResize
bool needsResize()
Definition: widget.hh:258
dw::core::Rectangle
dw::core::Shape implemtation for simple rectangles.
Definition: types.hh:69
dw::core::Widget::getAllocation
Allocation * getAllocation()
Definition: widget.hh:270
dw::core::Extremes
Definition: types.hh:179
dw::core::View
An interface to encapsulate platform dependent drawing.
Definition: view.hh:16
dw::core::Widget::buttonPressImpl
virtual bool buttonPressImpl(EventButton *event)
Definition: widget.cc:645
dw::core::style::StyleImage::ExternalWidgetImgRenderer
Suitable for widgets and parts of widgets.
Definition: style.hh:812
dw::core::Widget::CLASS_ID
static int CLASS_ID
Definition: widget.hh:253
dw::core::Widget::sizeRequest
void sizeRequest(Requisition *requisition)
This method is a wrapper for Widget::sizeRequestImpl(); it calls the latter only when needed.
Definition: widget.cc:214
dw::core::Widget::getExtremes
void getExtremes(Extremes *extremes)
Wrapper for Widget::getExtremesImpl().
Definition: widget.cc:232
dw::core::Widget::buttonSensitiveSet
bool buttonSensitiveSet
See dw::core::Widget::setButtonSensitive().
Definition: widget.hh:134
dw::core::Widget::buttonRelease
bool buttonRelease(EventButton *event)
Definition: widget.cc:298
dw::core::Widget::Flags
Flags
Definition: widget.hh:28
dw::core::Widget::unsetFlags
void unsetFlags(Flags f)
Definition: widget.hh:162
dw::core::Widget::getContentWidth
int getContentWidth()
Definition: widget.hh:154
dw::core::Widget::extremes
Extremes extremes
Analogue to dw::core::Widget::requisition.
Definition: widget.hh:119
dw::core::Widget::WidgetImgRenderer::readyToDraw
bool readyToDraw()
If this method returns false, nothing is done at all.
Definition: widget.cc:35
dw::core::Widget::extremesChanged
bool extremesChanged()
Definition: widget.hh:260
dw::core::Widget::queueDraw
void queueDraw()
Definition: widget.hh:165
dw::core::Widget::selectionHandleEvent
bool selectionHandleEvent(SelectionState::EventType eventType, Iterator *it, int charPos, int linkNo, MousePositionEvent *event)
Definition: widget.hh:238
dw::core::style::StyleAttrs::boxDiffWidth
int boxDiffWidth()
Definition: style.hh:549
dw::core::Allocation::ascent
int ascent
Definition: types.hh:168
lout::identity::IdentifiableObject
Instances of classes, which are sub classes of this class, may be identified at run-time.
Definition: identity.hh:98
dw::core::Widget::queueDrawArea
void queueDrawArea(int x, int y, int width, int height)
Definition: widget.cc:158
dw::core::Widget::motionNotify
bool motionNotify(EventMotion *event)
Definition: widget.cc:303
dw::core::VPosition
VPosition
Definition: types.hh:25
dw::core::Widget::setDescent
virtual void setDescent(int descent)
Definition: widget.cc:641
dw::core::Widget::USES_HINTS
Set by the widget itself (in the constructor), when set... methods are implemented.
Definition: widget.hh:54
dw::core::Widget::~Widget
~Widget()
Definition: widget.cc:93
dw::core::Widget::wasAllocated
bool wasAllocated()
Definition: widget.hh:261
dw::core::SelectionState::handleEvent
bool handleEvent(EventType eventType, Iterator *it, int charPos, int linkNo, MousePositionEvent *event)
General form of dw::core::SelectionState::buttonPress, dw::core::SelectionState::buttonRelease and dw...
Definition: selection.cc:215
dw::core::Widget::usesHints
bool usesHints()
Definition: widget.hh:262
dw::core::Widget::widgetImgRenderer
WidgetImgRenderer * widgetImgRenderer
Definition: widget.hh:97
dw::core::Widget::leaveNotify
void leaveNotify(EventCrossing *event)
Definition: widget.cc:313
dw::core::Widget::setBgColor
void setBgColor(style::Color *bgColor)
Set the background "behind" the widget, if it is not the background of the parent widget,...
Definition: widget.cc:369
dw::core::Widget::flags
Flags flags
Definition: widget.hh:106
dw::core::Widget::setStyle
virtual void setStyle(style::Style *style)
Change the style of a widget.
Definition: widget.cc:325
dw::core::Widget
The base class of all dillo widgets.
Definition: widget.hh:23
dw::core::Widget::getExtremesImpl
virtual void getExtremesImpl(Extremes *extremes)
See Sizes of Dillo Widgets.
Definition: widget.cc:613
dw::core::Widget::queueResize
void queueResize(int ref, bool extremesChanged)
This method should be called, when a widget changes its size.
Definition: widget.cc:171
dw::core::SelectionState::buttonPress
bool buttonPress(Iterator *it, int charPos, int linkNo, EventButton *event)
Definition: selection.cc:93
dw::core::Widget::allocation
Allocation allocation
The current allocation: size and position, always relative to the canvas.
Definition: widget.hh:151
dw
Dw is in this namespace, or sub namespaces of this one.
Definition: alignedtextblock.cc:26
dw::core::Widget::drawSelected
void drawSelected(View *view, Rectangle *area)
Definition: widget.cc:469
dw::core::Widget::buttonReleaseImpl
virtual bool buttonReleaseImpl(EventButton *event)
Definition: widget.cc:650
dw::core::Widget::WAS_ALLOCATED
Set, when a widget was already once allocated,.
Definition: widget.hh:69
dw::core::Widget::WidgetImgRenderer::getStyle
style::Style * getStyle()
Return the style this background image is part of.
Definition: widget.cc:52
dw::core::style::Style
Definition: style.hh:571
dw::core::Widget::drawBox
void drawBox(View *view, style::Style *style, Rectangle *area, int x, int y, int width, int height, bool inverse)
Draw borders and background of a widget part, which allocation is given by (x, y, width,...
Definition: widget.cc:400
dw::core::Allocation::width
int width
Definition: types.hh:167
dw::core::Layout::removeAnchor
void removeAnchor(Widget *widget, char *name)
Definition: layout.cc:691
dw::core::Widget::changeAnchor
void changeAnchor(char *name, int y)
Definition: widget.hh:215
dw::core::Widget::leaveNotifyImpl
virtual void leaveNotifyImpl(EventCrossing *event)
Definition: widget.cc:668