How can I make a List widget containing toggle buttons as well as text?
|
8-Aug-02 10:00 GMT
|
We often need to present a list of text-based items or choices
to a user. The XmList widget is ideal for this, but
unfortunately it can only contain a list of text strings (or
XmStrings):
About the only way to achieve this effect using the stock
Motif widget set is to manually create individual toggle
buttons and position them beside each row of the list. This
would be cumbersome and tricky to work with.
However, the XRT/table widget, available from Sitraka, can
easily be configured to function as a "super" list widget,
containing toggle buttons as well as textual items. A list is
simply a one-column "grid" with some special behavior, which
proves to be a simple task for XRT/table. We'll outline the
key elements needed to create a table that functions as a list
and contains toggle buttons in one column.
The first step is to create an XRT/table instance, configuring
it at the outset to function as a list, for example:
table = XtVaCreateManagedWidget("table",
xtXrtTableWidgetClass, parent,
XmNxrtTblNumColumns, 2,
XmNxrtTblMode, XRTTBL_MODE_LIST,
XmNxrtTblSelectionPolicy, XRTTBL_SELECT_MULTIRANGE,
XmNxrtTblTraversableContext, False,
NULL);
We have created a second column to contain the toggle buttons
(which do not exist yet). Setting the XRT/table XmNxrtTblMode
resource to XRTTBL_MODE_LIST causes XRT/table to mimic the
behavior of the XmList widget. The other resources refine the
behavior of the "list" (specifying multiple selection and
non-editable content).
The next step is to add toggle buttons to table's second
column. To do this, we create a toggle button widget as a
child of the table, for example:
togglebutton = XtVaCreateWidget("Complete",
xmToggleButtonWidgetClass,
table,
XmNxrtTblWidgetLocation,
XrtTblSetContext(XRTTBL_ALLCELLS, 1),
NULL);
Since it is a child of the table, we use the XRT/table
XmNxrtTblWidgetLocation constraint resource to specify its
location. But here's the interesting part - the value of this
resource effectively tells the table to place this widget in
all the cells of the second column.
How can one widget be located in several places? Through the
use of XRT/table's widget cloning feature. When one widget is
set to more than one cell, XRT/table automatically creates its
own internal copies (clones, if you will) of the widget to
fill the rows.
Here is the XRT/table version of the list, complete with
toggle buttons:
Later, we can add callbacks to the toggle buttons to be
notified when they are clicked, and then use an XRT/table
method call to map the click to a specific cell, but this is
beyond the scope of this tip.
For more information on XRT/table, visit Sitraka on the web
at:
www.sitraka.com/xrt/md
Sponsored
by Sitraka, makers of XRT PDS, the unbeatable Motif
widget suite - click here to download a FREE Evaluation
Sponsored
by X-Designer - The Leading X/Motif GUI Builder
- Click to download a FREE evaluation
Goto top of page
|