EW_Node

EW_Node

ew

1998 12-05


CLASS

EW_Node - shared functionality for widgets and windows


SYNOPSIS

Class EW_Node contains shared functionality between the classes EW_Window and EW_Widget. It would rarely be instantiated or used by itself except to generically address such functionality.


PUBLIC MEMBER FUNCTIONS



long GetNewed(void)
Returns non-zero if the node was constructed with a new call. Generally, trying to delete an object which was not constructed with new is an undefined operation. However, EW_Node detects this situation and just outputs an application error message without allowing the delete to occur. But, note that the destructors can still occur, which will probably cause failures.



EW_WidgetList *GetWidgetList(void)
Returns the widget list containing this node's children. This list should only be altered through the node's member functions, not by addressing the list directly.



void AddWidget(EW_Widget *widget,long placement)

void AddWidget(EW_Widget *widget)

void RemoveWidget(EW_Widget *widget)
Add/Remove a child widget to/from this widget's list of children. Currently acceptable values for placement are as follows. Enumeration values are given for clarity; they are subject to change.



EW_ADD_BEGINNING 0 Add to the beginning of the widget list.
EW_ADD_BEFORE 1 Add before the current widget on the widget list. The current widget can be selected by using the member functions of GPL_IDoubleList<>.
EW_ADD_AFTER 2 Add after the current widget on the widget list.
EW_ADD_END 3 Add to the end of the widget list.


If not specified, the default placement is EW_ADD_END.



virtual void SetGeometry(long x,long y,long w,long h)

void GetGeometry(long *x,long *y,long *w,long *h)
Set/Get the relative geometry of the node, from the lower left origin x,y and of size w,h.



virtual void SetOrigin(long x,long y)

void GetOrigin(long *x,long *y)

virtual void SetSize(long w,long h)

void GetSize(long *w,long *h)
Set/Get the origin and size elements of the geometry separately.



EW_Node *GetParent()
Returns the parent node, potentially NULL.



virtual void SetRootWindow(EW_Window *window)

virtual EW_Window *GetRootWindow(void)
Set/Get the window to which an ancestor of this node is directly rooted, potentially itself if the node is a window. Setting the root window is generally only done internally. Getting the root window is neccesary to direct text and graphics operations.



virtual void SetParentWidget(EW_Widget *widget)

virtual EW_Widget *GetParentWidget(void)
By default, the parent widget stays NULL. But, EW_Widget replaces these virtuals to set/get the parent widget.



long IsWindow(void)
Returns TRUE if the node is an EW_Window.



void SetDirty(long index,long set)

long GetDirty(long index)

void SetDirty(long set)

long GetDirty(void)
Set/Get the dirtiness flag used to control redraw operations. The versions with the index argument are generally only used internally within EW and allow specific access to the dirtiness for the next frame (index=0) and the following frame (index=1) during double-buffered operations. Currently acceptable values for set are as follows. Enumeration values are given for clarity; they are subject to change.



EW_DIRTY_NOT 0 This widget and none of its decendents need to be redrawn.
EW_DIRTY_CHILD 1 Some descendent of this widget needs to be redrawn.
EW_DIRTY_PARTIAL 2 Some of this widget's direct children need to be redrawn. This is usually used for intelligent widgets that only require a partial redraw on themselves based on changes in their children.
EW_DIRTY_COMPLETE 4 This widget needs to be completely redrawn.
EW_DIRTY_PENDING 8 OR-able. Mark as pending.
EW_DIRTY_IF_PENDING 16 OR-able. Only set if the old value is marked with EW_DIRTY_PENDING.



void SetNodeSizing(long set)

long GetNodeSizing(void)
Set/Get auto-sizing rules for the node. Note that this does allow autosizing for windows as well as widgets. Currently acceptable values for set are as follows. Enumeration values are given for clarity; they are subject to change.



EW_NODE_SIZING_NULL 0 No auto-sizing.
EW_NODE_SIZING_FIT_CHILD_X 1 Auto-size in the X direction.
EW_NODE_SIZING_FIT_CHILD_Y 2 Auto-size in the Y direction.
EW_NODE_SIZING_FIT_CHILD (EW_NODE_SIZING_FIT_CHILD_X| EW_NODE_SIZING_FIT_CHILD_Y) Auto-size in both directions.


Note that many window managers poorly handle windows that are fixed in a single direction, if at all. For this reason, windows should use either EW_NODE_SIZING_NULL or EW_NODE_SIZING_FIT_CHILD, never EW_NODE_SIZING_FIT_CHILD_X or EW_NODE_SIZING_FIT_CHILD_Y.
Note also that use of EW_Node::SetNodeSizing() and EW_Widget::SetBounds() in the same window is a likely cause of undesirable behavior since geometries can be undeterminable. The simplest example is if a parent uses EW_NODE_SIZING_FIT_CHILD and the child uses EW_BOUNDS_FILL_PARENT. Each node/widget expects the value from the other. One potential reaction is oscillating resizes resulting in continuous refreshes.



void GetChildrenExtents(long *mincx,long *mincy,long *maxcx,long *maxcy)
Get the minimum and maximum X and Y values of all the corners of all this widget's children in a bounding rectange from mincx,mincy to maxcx,maxcy. Note that this function does not rewind the list. It starts from the current position, so any children before that position are ignored.


FILES

wds/node.h Widget/Window node header file


SEE ALSO

EW_Intro(3), EW_Widget(3), EW_Window(3)


NOTES

EW_Node has a special mechanism to prevent applications from using delete on nodes not created with ew(new). This appears to be a common error in widget hierarchy construction, since widgetlists automatically delete recursively during deconstruction. This can be otherwise properly addressed by ew(new)'ing objects, attaching them to a parent node, and let them garbage collect themselves. Alternatively, widgets allocated automatically, such as a non-pointer part of another object, must be removed from their parent widgetlist before it destructs. This special mechanism prevent the otherwise undefined behavior of deleting these objects. Note, however that destructors may still occur, which can very easily cause problems. EW_WidgetList::~EW_WidgetList reduces this possibility by removing non-newed nodes before they would be automatically deleted.


Because of this mechanism, all objects that are derived from EW_Node, perhaps through several levels of inheritance, must list the object through which they inherit EW_Node first on their list of objects from which they inherit.