Unlike FancyListBox and ListTree which have specific rules to arrange their display items, WorkArea does not have a fixed geometry management policy. Therefore, the EZwgl library provides an option for an application to hook in its own geometry manager. This section discusses the issues on writing geometry managers.
Upon creation, EZ_CreateWorkArea
initialize the geometry manager to a default
one, which arrange display items in rows and
columns.
The responsiblity of a geometry manager is to assign a location for each display item, and possiblly re-assign the dimensions of display items (e.g. make the height of a row of items the same). A geometry manager is invoked whenever the library thinks the geometry of its hosting WorkArea widget needs to be recomputed. For example, after the window has been resized or an item has been deleted.
\subsection*Supporting Routines To acomplish its tasks, a geometry manager needs helps from a few supporting functions, functions that allow the geometry manager to compute and/or alter the dimension of display items and to assign locations for display items.
The following functions are specifically designed to help
geometry managers for WorkArea widgets to do their jobs.
Some of them will not work if used for other purposes.
void EZ_ComputeItemSize(EZ_Item *item, int *w_ret, int *h_ret)
This function computes the dimension of a display item.
void EZ_SetItemPosition(EZ_Item *item, int x, int y)
This function sets the location of the upper-left corner of a display item.
void EZ_SetItemWidth(EZ_Item *item, int width)
This function sets the width of a display item.
void EZ_SetItemHeight(EZ_Item *item, int height)
This function sets the height of a display item.
void EZ_SetItemDimension(EZ_Item *item, int width, int height)
This function sets the size of a display item.
int EZ_GetItemWidth(EZ_Item *item)
This function returns the width of a display item.
int EZ_GetItemHeight(EZ_Item *item)
This function returns the height of a display item.
void EZ_GetItemDimension(EZ_Item *item, int width_ret, int height_ret)
This function returns the size of a display item.
\subsection*The Prototype of a Geometry Manager
void GeometryManager(void *private_data, EZ_Item **items, int nitems, int ox, int oy, int width, int height, int xspacing, int yspacing, int *width_ret, int *height_ret)
The meaning of the arguments are explained below.
private_data
This arguments specifies a collection of
private data needed by the geometry manager.
It should point to a static storage.
It must be registered at the time the geometry manager
is attached to a WorkArea widget. When the library invokes a geometry
manager, it will pass this pointer as the first argument to the
geometry manager.
items
This argument specifies an array of display
items. When invoked, the library passes the list of display items
managed by the host WorkArea widget to this argument.
nitems
This argument specifies the number of elements
in items
. Normally, the actual dimension of items
is
larger than this number.
ox,oy, width, height
These four arguments specify
the rectangle in the widget window that is to be used for
displaying items
. (ox,oy)
is the upper-left corner
of the rectangle; width, height
are the horizontal and
vertical dimension of the rectangle. When invoked, the host widget
passes its widgetBorderWidth
to ox
and oy
,
passes widgetWidth - 2*widgetBorderWidth
to width and passes
widgetHeight - 2*widgetBorderWidth
to height.
xspacing, yspacing
These two arguments specify the
prefered spacing between neighboring items,
in the horizontal direction and
in the vertical direction, respectively. The host WorkArea widget
passes its internal paddings to the geometry manager when invoked.
widgh_ret, height_ret
These two arguments specify
the returns for the computed total size required to display
items
. The host WorkArea widget needs these information
to setup its scrollbars.
void EZ_SetWorkAreaGeometryManager(EZ_Widget *workArea,
EZ_WorkAreaGeometryManager manager,
void *manager_data)
This function sets the private geometry manager for a WorkArea widget.