Dillo
Public Member Functions | Public Attributes | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
dw::core::Widget Class Referenceabstract

The base class of all dillo widgets. More...

#include <widget.hh>

Public Member Functions

void setDeleteCallback (DW_Callback_t func, void *data)
 
 Widget ()
 
 ~Widget ()
 
bool needsResize ()
 
bool needsAllocate ()
 
bool extremesChanged ()
 
bool wasAllocated ()
 
bool usesHints ()
 
bool hasContents ()
 
bool blockLevel ()
 
void setParent (Widget *parent)
 
style::StylegetStyle ()
 
AllocationgetAllocation ()
 
void sizeRequest (Requisition *requisition)
 This method is a wrapper for Widget::sizeRequestImpl(); it calls the latter only when needed.
 
void getExtremes (Extremes *extremes)
 Wrapper for Widget::getExtremesImpl().
 
void sizeAllocate (Allocation *allocation)
 Wrapper for Widget::sizeAllocateImpl, calls the latter only when needed.
 
virtual void setWidth (int width)
 
virtual void setAscent (int ascent)
 
virtual void setDescent (int descent)
 
bool intersects (Rectangle *area, Rectangle *intersection)
 Calculates the intersection of widget->allocation and area, returned in intersection (in widget coordinates!).
 
virtual void draw (View *view, Rectangle *area)=0
 
bool buttonPress (EventButton *event)
 
bool buttonRelease (EventButton *event)
 
bool motionNotify (EventMotion *event)
 
void enterNotify (EventCrossing *event)
 
void leaveNotify (EventCrossing *event)
 
virtual void setStyle (style::Style *style)
 Change the style of a widget.
 
void setBgColor (style::Color *bgColor)
 Set the background "behind" the widget, if it is not the background of the parent widget, e.g. the background of a table row.
 
style::ColorgetBgColor ()
 Get the actual background of a widget.
 
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, height) (widget coordinates).
 
void drawWidgetBox (View *view, Rectangle *area, bool inverse)
 Draw borders and background of a widget.
 
void drawSelected (View *view, Rectangle *area)
 
void setButtonSensitive (bool buttonSensitive)
 
bool isButtonSensitive ()
 
WidgetgetParent ()
 
WidgetgetTopLevel ()
 Get the widget at the root of the tree, this widget is part from.
 
int getLevel ()
 Get the level of the widget within the tree.
 
WidgetgetNearestCommonAncestor (Widget *otherWidget)
 Get the widget with the highest level, which is a direct ancestor of widget1 and widget2.
 
LayoutgetLayout ()
 
virtual WidgetgetWidgetAtPoint (int x, int y, int level)
 Search recursively through widget.
 
void scrollTo (HPosition hpos, VPosition vpos, int x, int y, int width, int height)
 
virtual Iteratoriterator (Content::Type mask, bool atEnd)=0
 Return an iterator for this widget.
 
virtual void removeChild (Widget *child)
 
- Public Member Functions inherited from lout::identity::IdentifiableObject
 IdentifiableObject ()
 
virtual void intoStringBuffer (misc::StringBuffer *sb)
 Store a textual representation of the object in a misc::StringBuffer.
 
int getClassId ()
 Returns the class identifier.
 
const char * getClassName ()
 Return the name, under which the class of this object was registered.
 
bool instanceOf (int otherClassId)
 Returns, whether this class is an instance of the class, given by otherClassId, or of a sub class of this class.
 
- Public Member Functions inherited from lout::object::Object
virtual ~Object ()
 The destructor is defined as virtual (but not abstract), so that destruction of Object's works properly.
 
virtual bool equals (Object *other)
 Returns, whether two objects are equal.
 
virtual int hashValue ()
 Return a hash value for the object.
 
virtual Objectclone ()
 Return an exact copy of the object.
 
const char * toString ()
 Use object::Object::intoStringBuffer to return a textual representation of the object.
 
virtual size_t sizeOf ()
 Return the number of bytes, this object totally uses.
 

Public Attributes

int parentRef
 This value is defined by the parent widget, and used for incremential resizing.
 

Static Public Attributes

static int CLASS_ID = -1
 

Protected Types

enum  Flags {
  NEEDS_RESIZE = 1 << 0, NEEDS_ALLOCATE = 1 << 1, EXTREMES_CHANGED = 1 << 2, USES_HINTS = 1 << 3,
  HAS_CONTENTS = 1 << 4, WAS_ALLOCATED = 1 << 5, BLOCK_LEVEL = 1 << 6
}
 

Protected Member Functions

int getHeight ()
 
int getContentWidth ()
 
int getContentHeight ()
 
void setFlags (Flags f)
 
void unsetFlags (Flags f)
 
void queueDraw ()
 
void queueDrawArea (int x, int y, int width, int height)
 
void queueResize (int ref, bool extremesChanged)
 This method should be called, when a widget changes its size.
 
virtual void sizeRequestImpl (Requisition *requisition)=0
 See Sizes of Dillo Widgets.
 
virtual void getExtremesImpl (Extremes *extremes)
 See Sizes of Dillo Widgets.
 
virtual void sizeAllocateImpl (Allocation *allocation)
 See Sizes of Dillo Widgets.
 
virtual void resizeDrawImpl ()
 Called after sizeAllocateImpl() to redraw necessary areas. By default the whole widget is redrawn.
 
virtual void markSizeChange (int ref)
 See Sizes of Dillo Widgets.
 
virtual void markExtremesChange (int ref)
 See Sizes of Dillo Widgets.
 
virtual bool buttonPressImpl (EventButton *event)
 
virtual bool buttonReleaseImpl (EventButton *event)
 
virtual bool motionNotifyImpl (EventMotion *event)
 
virtual void enterNotifyImpl (EventCrossing *event)
 
virtual void leaveNotifyImpl (EventCrossing *event)
 
char * addAnchor (const char *name)
 
char * addAnchor (const char *name, int y)
 
void changeAnchor (char *name, int y)
 
void removeAnchor (char *name)
 
void setCursor (style::Cursor cursor)
 
bool selectionButtonPress (Iterator *it, int charPos, int linkNo, EventButton *event, bool withinContent)
 
bool selectionButtonRelease (Iterator *it, int charPos, int linkNo, EventButton *event, bool withinContent)
 
bool selectionButtonMotion (Iterator *it, int charPos, int linkNo, EventMotion *event, bool withinContent)
 
bool selectionHandleEvent (SelectionState::EventType eventType, Iterator *it, int charPos, int linkNo, MousePositionEvent *event)
 
- Protected Member Functions inherited from lout::identity::IdentifiableObject
void registerName (const char *className, int *classId)
 This method must be called in the constructor for the sub class. See class comment for details.
 

Protected Attributes

Allocation allocation
 The current allocation: size and position, always relative to the canvas.
 
Layoutlayout
 

Private Attributes

Widgetparent
 The parent widget, NULL for top-level widgets.
 
style::Stylestyle
 
Flags flags
 
Requisition requisition
 Size_request() stores the result of the last call of size_request_impl().
 
Extremes extremes
 Analogue to dw::core::Widget::requisition.
 
style::ColorbgColor
 See dw::core::Widget::setBgColor().
 
bool buttonSensitive
 See dw::core::Widget::setButtonSensitive().
 
bool buttonSensitiveSet
 See dw::core::Widget::setButtonSensitive().
 
void * deleteCallbackData
 
DW_Callback_t deleteCallbackFunc
 

Friends

class Layout
 

Detailed Description

The base class of all dillo widgets.

See Also
Dillo Widget Overview, Layout and Widgets

Member Enumeration Documentation

enum dw::core::Widget::Flags
protected
Enumerator:
NEEDS_RESIZE 

Set, when dw::core::Widget::requisition is not up to date anymore.

NEEDS_ALLOCATE 

Only used internally, set to enforce size allocation.

(I've forgotten the case, for which this is necessary.)

EXTREMES_CHANGED 

Set, when dw::core::Widget::extremes is not up to date anymore.

USES_HINTS 

Set by the widget itself (in the constructor), when set... methods are implemented.

Will hopefully be removed, after redesigning the size model.

HAS_CONTENTS 

Set by the widget itself (in the constructor), when it contains some contents, e.g. an image, as opposed to a horizontal ruler.

Will hopefully be removed, after redesigning the size model.

WAS_ALLOCATED 

Set, when a widget was already once allocated,.

The dw::Image widget uses this flag, see dw::Image::setBuffer.

BLOCK_LEVEL 

Set for block-level widgets (as opposed to inline widgets)

Constructor & Destructor Documentation

dw::core::Widget::Widget ( )
dw::core::Widget::~Widget ( )

Member Function Documentation

char* dw::core::Widget::addAnchor ( const char *  name)
inlineprotected
char* dw::core::Widget::addAnchor ( const char *  name,
int  y 
)
inlineprotected
bool dw::core::Widget::blockLevel ( )
inline
bool dw::core::Widget::buttonPress ( EventButton event)
bool dw::core::Widget::buttonPressImpl ( EventButton event)
protectedvirtual

Reimplemented in dw::Textblock, dw::core::ui::Embed, and dw::Image.

bool dw::core::Widget::buttonRelease ( EventButton event)
bool dw::core::Widget::buttonReleaseImpl ( EventButton event)
protectedvirtual

Reimplemented in dw::Textblock, and dw::Image.

void dw::core::Widget::changeAnchor ( char *  name,
int  y 
)
inlineprotected
virtual void dw::core::Widget::draw ( View view,
Rectangle area 
)
pure virtual

Area is given in widget coordinates.

Implemented in dw::Textblock, dw::Table, dw::core::ui::Embed, dw::Image, dw::Ruler, and dw::Bullet.

Referenced by dw::Textblock::drawLine().

void dw::core::Widget::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, height) (widget coordinates).

area is given in widget coordinates.

Todo:
Background images?

References dw::core::style::StyleAttrs::backgroundColor, dw::core::style::drawBackground(), dw::core::style::drawBorder(), dw::core::Rectangle::height, dw::core::Rectangle::width, dw::core::Rectangle::x, and dw::core::Rectangle::y.

void dw::core::Widget::drawSelected ( View view,
Rectangle area 
)
void dw::core::Widget::drawWidgetBox ( View view,
Rectangle area,
bool  inverse 
)

Draw borders and background of a widget.

area is given in widget coordinates.

Todo:
Adjust following comment from the old dw sources.
Todo:
Background images?

References dw::core::style::drawBackground(), dw::core::style::drawBorder(), dw::core::Rectangle::height, dw::core::Rectangle::width, dw::core::Rectangle::x, and dw::core::Rectangle::y.

Referenced by dw::Ruler::draw().

void dw::core::Widget::enterNotify ( EventCrossing event)
void dw::core::Widget::enterNotifyImpl ( EventCrossing event)
protectedvirtual
bool dw::core::Widget::extremesChanged ( )
inline

References EXTREMES_CHANGED, and flags.

Allocation* dw::core::Widget::getAllocation ( )
inline
style::Color * dw::core::Widget::getBgColor ( )

Get the actual background of a widget.

References dw::core::style::StyleAttrs::backgroundColor, bgColor, getBgColor(), parent, and style.

Referenced by getBgColor().

int dw::core::Widget::getContentHeight ( )
inlineprotected
int dw::core::Widget::getContentWidth ( )
inlineprotected
void dw::core::Widget::getExtremes ( Extremes extremes)
void dw::core::Widget::getExtremesImpl ( Extremes extremes)
protectedvirtual
int dw::core::Widget::getHeight ( )
inlineprotected
Layout* dw::core::Widget::getLayout ( )
inline

References layout.

Referenced by dw::core::Iterator::scrollTo().

int dw::core::Widget::getLevel ( )

Get the level of the widget within the tree.

The root widget has the level 0.

References parent.

Referenced by dw::core::DeepIterator::DeepIterator(), and getNearestCommonAncestor().

Widget * dw::core::Widget::getNearestCommonAncestor ( Widget otherWidget)

Get the widget with the highest level, which is a direct ancestor of widget1 and widget2.

References getLevel(), and parent.

Referenced by dw::core::Layout::moveToWidget().

Widget* dw::core::Widget::getParent ( )
inline
style::Style* dw::core::Widget::getStyle ( )
inline
Widget * dw::core::Widget::getTopLevel ( )

Get the widget at the root of the tree, this widget is part from.

References parent.

Referenced by dw::core::Layout::moveToWidget().

Widget * dw::core::Widget::getWidgetAtPoint ( int  x,
int  y,
int  level 
)
virtual
bool dw::core::Widget::hasContents ( )
inline

References flags, and HAS_CONTENTS.

Referenced by dw::Textblock::getWordExtremes().

bool dw::core::Widget::intersects ( Rectangle area,
Rectangle intersection 
)

Calculates the intersection of widget->allocation and area, returned in intersection (in widget coordinates!).

Typically used by containers when drawing their children. Returns whether intersection is not empty.

References dw::core::Rectangle::height, dw::core::Rectangle::intersectsWith(), dw::core::Rectangle::width, dw::core::Rectangle::x, and dw::core::Rectangle::y.

Referenced by dw::Textblock::drawLine().

bool dw::core::Widget::isButtonSensitive ( )
inline
virtual Iterator* dw::core::Widget::iterator ( Content::Type  mask,
bool  atEnd 
)
pure virtual

Return an iterator for this widget.

mask can narrow the types returned by the iterator, this can enhance performance quite much, e.g. when only searching for child widgets.

With atEnd == false, the iterator starts before the beginning, i.e. the first call of dw::core::Iterator::next will let the iterator point on the first piece of contents. Likewise, With atEnd == true, the iterator starts after the last piece of contents, call dw::core::Iterator::prev in this case.

Implemented in dw::Textblock, dw::Table, dw::core::ui::Embed, dw::Image, dw::Ruler, and dw::Bullet.

Referenced by dw::core::CharIterator::CharIterator(), dw::core::DeepIterator::DeepIterator(), dw::core::DeepIterator::next(), dw::core::DeepIterator::prev(), dw::core::DeepIterator::searchDownward(), and dw::core::DeepIterator::searchSideward().

void dw::core::Widget::leaveNotify ( EventCrossing event)
void dw::core::Widget::leaveNotifyImpl ( EventCrossing event)
protectedvirtual
void dw::core::Widget::markExtremesChange ( int  ref)
protectedvirtual

See Sizes of Dillo Widgets.

Reimplemented in dw::Textblock.

void dw::core::Widget::markSizeChange ( int  ref)
protectedvirtual

See Sizes of Dillo Widgets.

Reimplemented in dw::Textblock.

bool dw::core::Widget::motionNotify ( EventMotion event)
bool dw::core::Widget::motionNotifyImpl ( EventMotion event)
protectedvirtual

Reimplemented in dw::Textblock, and dw::Image.

bool dw::core::Widget::needsAllocate ( )
inline

References flags, and NEEDS_ALLOCATE.

bool dw::core::Widget::needsResize ( )
inline

References flags, and NEEDS_RESIZE.

void dw::core::Widget::queueDraw ( )
inlineprotected
void dw::core::Widget::queueDrawArea ( int  x,
int  y,
int  width,
int  height 
)
protected
Todo:
Maybe only the intersection?

Referenced by queueDraw().

void dw::core::Widget::queueResize ( int  ref,
bool  extremesChanged 
)
protected

This method should be called, when a widget changes its size.

References parent, and parentRef.

Referenced by dw::Textblock::addParbreak(), dw::core::ui::Resource::queueResize(), dw::ListItem::setMaxValue(), and dw::TableCell::setMaxValue().

void dw::core::Widget::removeAnchor ( char *  name)
inlineprotected
void dw::core::Widget::removeChild ( Widget child)
virtual
virtual void dw::core::Widget::resizeDrawImpl ( )
inlineprotectedvirtual

Called after sizeAllocateImpl() to redraw necessary areas. By default the whole widget is redrawn.

Reimplemented in dw::Textblock, and dw::Table.

References queueDraw().

void dw::core::Widget::scrollTo ( HPosition  hpos,
VPosition  vpos,
int  x,
int  y,
int  width,
int  height 
)

References scrollTo().

Referenced by scrollTo().

bool dw::core::Widget::selectionButtonMotion ( Iterator it,
int  charPos,
int  linkNo,
EventMotion event,
bool  withinContent 
)
inlineprotected
bool dw::core::Widget::selectionButtonPress ( Iterator it,
int  charPos,
int  linkNo,
EventButton event,
bool  withinContent 
)
inlineprotected
bool dw::core::Widget::selectionButtonRelease ( Iterator it,
int  charPos,
int  linkNo,
EventButton event,
bool  withinContent 
)
inlineprotected
bool dw::core::Widget::selectionHandleEvent ( SelectionState::EventType  eventType,
Iterator it,
int  charPos,
int  linkNo,
MousePositionEvent event 
)
inlineprotected
void dw::core::Widget::setAscent ( int  ascent)
virtual
void dw::core::Widget::setBgColor ( style::Color bgColor)

Set the background "behind" the widget, if it is not the background of the parent widget, e.g. the background of a table row.

void dw::core::Widget::setButtonSensitive ( bool  buttonSensitive)
void dw::core::Widget::setCursor ( style::Cursor  cursor)
inlineprotected
void dw::core::Widget::setDeleteCallback ( DW_Callback_t  func,
void *  data 
)
inline
void dw::core::Widget::setDescent ( int  descent)
virtual
void dw::core::Widget::setFlags ( Flags  f)
inlineprotected
void dw::core::Widget::setParent ( Widget parent)

References buttonSensitive, and layout.

Referenced by dw::Textblock::addWidget().

void dw::core::Widget::setStyle ( style::Style style)
virtual

Change the style of a widget.

The old style is automatically unreferred, the new is referred. If this call causes the widget to change its size, dw::core::Widget::queueResize is called.

Reimplemented in dw::core::ui::Embed.

References dw::core::style::Style::ref(), dw::core::style::StyleAttrs::sizeDiffs(), and dw::core::style::Style::unref().

Referenced by dw::Textblock::addWidget(), dw::Textblock::changeLinkColor(), and dw::core::ui::Embed::setStyle().

void dw::core::Widget::setWidth ( int  width)
virtual
void dw::core::Widget::sizeAllocate ( Allocation allocation)
void dw::core::Widget::sizeAllocateImpl ( Allocation allocation)
protectedvirtual
void dw::core::Widget::sizeRequest ( Requisition requisition)

This method is a wrapper for Widget::sizeRequestImpl(); it calls the latter only when needed.

Todo:
Check requisition == &(this->requisition) and do what?

References dw::core::Requisition::ascent, DBG_OBJ_SET_NUM, dw::core::Requisition::descent, and dw::core::Requisition::width.

Referenced by dw::Textblock::calcWidgetSize().

virtual void dw::core::Widget::sizeRequestImpl ( Requisition requisition)
protectedpure virtual
void dw::core::Widget::unsetFlags ( Flags  f)
inlineprotected

References flags.

Referenced by dw::Ruler::Ruler().

bool dw::core::Widget::usesHints ( )
inline
bool dw::core::Widget::wasAllocated ( )
inline

References flags, and WAS_ALLOCATED.

Referenced by dw::Textblock::sizeAllocateImpl().

Friends And Related Function Documentation

friend class Layout
friend

Member Data Documentation

Allocation dw::core::Widget::allocation
protected
style::Color* dw::core::Widget::bgColor
private
bool dw::core::Widget::buttonSensitive
private
bool dw::core::Widget::buttonSensitiveSet
private
int dw::core::Widget::CLASS_ID = -1
static
void* dw::core::Widget::deleteCallbackData
private

Referenced by setDeleteCallback().

DW_Callback_t dw::core::Widget::deleteCallbackFunc
private

Referenced by setDeleteCallback().

Extremes dw::core::Widget::extremes
private
Flags dw::core::Widget::flags
private
Layout* dw::core::Widget::layout
protected
Widget* dw::core::Widget::parent
private

The parent widget, NULL for top-level widgets.

Referenced by getBgColor(), getLevel(), getNearestCommonAncestor(), getParent(), getTopLevel(), and queueResize().

int dw::core::Widget::parentRef

This value is defined by the parent widget, and used for incremential resizing.

See documentation for an explanation.

Referenced by dw::Textblock::accumulateWordForLine(), dw::Textblock::addWidget(), queueResize(), and dw::Textblock::rewrap().

Requisition dw::core::Widget::requisition
private

Size_request() stores the result of the last call of size_request_impl().

Do not read this directly, but call size_request().

style::Style* dw::core::Widget::style
private

The documentation for this class was generated from the following files: