Widget In A Cell


Introduction

The EditTable widget offers a simple yet powerful mechanism to insert a widget inside a cell or to use a single widget across an entire range of cells. Any valid Motif widget, with the exception of composite widgets such as RowColumn or Form widgets, can be inserted. Gadgets are not supported. To insert a widget into one or more cells, the application simply creates the widget with EditTable as the parent and uses constraint resource XmNcellWidgetRange to specify the range of cells that are to contain this widget. The example below illustrates a push button widget and a toggle button widget, each propagated to an entire column in an electronic checkbook.


Figure 10: Example of a Widget In a Cell Application.

It is important for the contents of a widget to reflect the visual characteristics that are to be displayed in the cell before the cell that contains the widget is drawn. EditTable will automatically set the cell resources listed below on the widget if the constraint resource XmNcellWidgetSetResources is set to True. This occurs before the XmNcellWidgetDisplayCallback callback is called.

Resource NameAutomatic Setting
XmNlabelStringCurrent cell content, as a string.
XmNfontListCurrent cell font.
XmNbackgroundCurrent cell background.
XmNforegroundCurrent cell foreground.
XmNalignmentCurrent cell alignment.
XmNsensitiveCurrent cell sensitivity.

The values of these resources are available in the callback structure XintEditTableCellWidgetCallbackStruct. If XmNcellWidgetSetResources is False, or it is necessary to change one or more values, this can be done in the callback. The callback also permits other widget resources, which are not in the list above, to be set.

If XmNcellWidgetSetResources is False and XmNcellWidgetDisplayCallback is not called, the visual characteristics of the cells will be undefined!

In most applications it will be sufficient to set XmNcellWidgetSetResources to True and omit the XmNcellWidgetDisplayCallback. The ToggleButton widget is an example of an instance where XmNcellWidgetDisplayCallback is necessary in order to get information about the cell state to use in setting the XmNset resource.

Due to the power and speed of the Widget in a Cell mechanism, The XmString data type (to enable internationalization of the interface application) is easily supported. This is accomplished by specifying a Motif Label widget across a range of cells.

Constraint resource XmNcellWidgetOverrideTranslations allows the programmer to determine the focus for navigation events when the widget is mapped to the table. If set to True, arrows and tab keys take you back to the table process rather than remaining in the mapped widget. The XintEditTableGetCellWidget convenience function may be used to get the widget associated with a particular cell location.

Because the Widget in a Cell mechanism associates a range of cells with a single widget, a callback that is attached to the widget will be called as long as the current location is within that range. It is usually important to know the specific table location associated with any user event. For this purpose, the XintEditTableGetCellPointerPosition function should be used to return the table location of the cell pointer.