EditTable Widget Q&A
-
Q1. What is EditTable ?
-
EditTable is INT's comprehensive widget
for displaying and editing tabular data.
-
Q2. How can I customize the table ? For example, how can I define the
size and the annotation of my own table?
-
By default, the table size is 16x16, and the row/column annotations
are automatically labelled with numerical or alphabetic sequences. Columns
are annotated in spreadsheet fashion with character strings that are automatically
generated in alphabetical order (A, B,..,Z, AA, AB... etc.) Rows are annotated
automatically with sequential integers. See the Code
Example of question number 1.
For example, if you want to define a 3X3 table, with the column annotation "C1, C2, C3" and the row annotation "R1, R2, R3", you can assign values to the resources: XmNnumberOfColumns, XmNnumberOfRows, XmNautomaticColumnAnnotation, XmNautomaticRowAnnotation.
EditTable provides you with many resources. Refer to the EditTable Reference for more information.
Code Example
-
Q3. How can I set the background color of the annotation areas ?
-
There are two methods to do this:
1. Obtain the widget id of the annotation area through a call to XintScrollGetChild, then call XtSetValues or XtVaSetValues to set XmNbackground of the annotation widget.
2. Set the background color in the resource default file. You can use the names of the annotation widgets, documented under 'Scroll Components' in the EditTable manual, to set the background color.
For a more detailed description of XintScrollGetChild and the XintScroll widget, refer to the Reference Guide
Code Example
-
Q4. How can I control the attributes of cells?
-
The EditTable convenience functions XintEditTableSetCell?????() allow
you to specify the attributes for individual or groups of cells.
Refer to the functions section of the EditTable Reference for more information.
Code Example
-
Q5. How can I freeze/unfreeze Rows & Columns?
-
The EditTable convenience functions XintEditTableFreezeRow(),
XintEditTableUnfreezeRow() allow you to freeze/unfreeze rows.
The EditTable convenience functions XintEditTableFreezeColumn(), XintEditTableUnfreezeColumn() allow you to freeze/unfreeze columns.
Refer to the functions section of the EditTable Reference for more information.
Code Example
-
Q6. How can I hide Rows/Columns?
-
The EditTable convenience functions XintEditTableChangeRowVisibility(),
XintEditTableChangeColumnVisibility() allow you to hide/show rows &
columns.
Refer to the functions section of the EditTable Reference for more information.
Code Example
-
Q7. How can I set datatypes for columns (including user formatted
data)?
-
In a table, data values can be any of the following: Integers, Short
integers, Long integers, Floating point numbers, Double-precision
floating point numbers, character strings and pointers. The data type is
set on a column basis. Formatting the column can be done either with the
resource XmNdefaultColumnDataFormat, the format attribute for the column
or the FormatCellCallback. For pointer types, EditTable ALWAYS uses the
FormatCellCallback.
The format for a column is specified using the convenience function XintEditTableDefineColumnFormat.
Refer to the functions section of the EditTable Reference for more information.
Click here for code
-
Q8. How can I add/use local callbacks?
-
EditTable provides many callbacks, and a convenience function
XintEditTableAddLocalCallBack to attach specific callbacks to individual
cells.
Question No. 9 provides a good example.
Refer to the functions section of the EditTable Reference for more information.
-
Q9. How can I selectively deny the editing of a cell?
-
In the following example, the checkEditModeCallback is used to
disable editing of cell(2,2). In the checkEditMode callback routine, the
doit flag of the callback structure is set to false, making the cell non
editable.
Code Example
-
Q10. How can I insert/delete programatically?
-
Use the convenience functions XintEditTableInsertColumns/Rows() and
XintEditTableDeleteColumns/Rows()
Refer to the functions section of the EditTable Reference for more information.
-
Q11. Why do I have to click the table cell twice to get the I beam
cursor in the cell ?
-
EditTable has two modes: Display and Edit . The display mode
is the default mode. Usually, the focus is not in the table when it is
launched. A single click, with mouse pointer over the table, will change
the focus to the table, but the table is still in the display mode. A
second click on the cell pointer will then switch the cell into edit
mode.
-
Q12. How can I put a widget in a cell/cells?
-
The EditTable widget offers a simple yet powerful mechanism to insert
a widget inside a cell or to use a single widget (gadget excluded)
across an entire range of cells.
Simply create the embedded widget with the table as the parent and use the constraint resource XmNcellWidgetRange to specify the range of cells which are to contain this widget.
It may be important to make the contents of the widget reflect the visual characteristics of the underlying cell. EditTable will automatically set the necessary cell resources on the widget if the constraint resource XmNcellWidgetSetResources is set to True (which is the default).
Refer to the resources section of the EditTable Reference for more information.
This code fragment should be added to the program in Question No. 7
-
Q13. How can I span cells?
-
The cell spanning feature of EditTable enables cells to span across
several columns and/or rows. The size of the span (in rows and columns)
is determined by the span factor. This span factor can be applied to all
of the cells in the table, or a subset of the table locations.
Cell spanning is enabled by the resource XmNspanMode, which also determines the manner in which the cells will be drawn. EditTable also provides you with a convenience function XintEditTableSpanSetRange(), with which you can set the span range factor.
Refer to the resources and functions section of the EditTable Reference for more information.
Code Example
-
Q14. How can I attach a pull_down menu widget to a cell?
-
First, create a pulldown menu widget and the associated children.
Then create an option menu widget with the table as its parent and the
pulldown menu as the value of its resource XmNsubMenuId. As in Q12 the
cellWidget constraint resources have to be set on the option menu to
attach it to a cell.
Code Example
-
Q15. How can I increase the value of a cell with a keystroke?
-
First, write your own action procedure which can increase the value
of your specific cell; then tie it to the user action (keystroke) via a
translation table.
Refer to the translations and actions section of the EditTable Reference for more information.
Code Example
-
Q16. How can I batch updates to the table?
-
You can batch your updates to the table by setting the value of the
resource XmNfreezeUpdate to True before the application is to perform a
series of updates on the table. Then set it back to False after you
finish, and EditTable will automatically recalculate its new geometry
and redisplay itself.
EditTable also offers a convenience function XintEditTableFreezeUpdate for this purpose. Typically, you can use it this way:
: : XintEditTableFreezeUpdate(Table, True); : .....your updates : XintEditTableFreezeUpdate(Table, False); :
-
Q17. How do I make EditTable behave like XmList?
-
By default, in EditTable, when you press button 1, two actions,
EditTableEnter(Pointer) and EditTableStartSelect(single), will be
triggered. StartSelect will clear all the previous selections and select
the current cell.
If you want to enable selections by row, the default list of actions must be changed in the translation table. Change EditTableStartSelect(single) to EditTableStartSelect(row) and to get multiple selections change it to EditTableStartSelect(multiple,row).
For example:
: static char table_translations[] = "Shift <Btn1Down>: EditTableStartSelect(multiple,row)\n\ Button <Motion>: EditTableExtendSelect()\n\ Shift <Btn2Down>: EditTableClearSelection()\n\ Shift <Btn3Down>: EditTableClearAllSelections()\n\ Ctrl <Btn1Down>: EditTableExtendSelect()"; : :Refer to the translations and actions section of the EditTable Reference for more information.
-
Q18. How do I implement "DRAG & DROP" in EditTable?
-
Drag and Drop is implemented by changing the translation table to use
the drap and drop actions provided by EditTable. The following code will
allow you to move columns/rows around inside the table.
: static char annotation_translations[] = "~Ctrl ~Shift ~Meta ~Alt <Btn1Down> AnnotationStartSelect()\n\ : : <Btn2Down>: AnnotationStartDrag(move)\n\ <Btn2Up>: AnnotationEndDrag()\n\ : : Shift <Btn3Down>: EditTableClearAllSelections()"; : :Refer to the translations and actions section of the EditTable Reference for more information.
-
Q19. How do I control navigation and pointer in EditTable?
-
EditTable's navigational behaviour is defined by its translation
table.
For example, suppose you want use the "Tab" key, to move the cursor to below and right:
: static char table_translations[] = " : None<Key> Tab: EditTableEnterCell(Right)\ EditTableEnterCell(Down)\ EditTableClearAllSelections()\n\ : :Refer to the translations and actions section of the EditTable Reference for more information.
-
Q20. How do I place a particular group of adjacent cells in the
center of viewing area ?
-
EditTable must be created with an XintScroll Widget as its parent to
do this. The Scroll convenience function XintScrollScrollToPosition()
will move the table to map the range of cells to a particular position.
Refer to the Scroll widget section of the Reference Guide for more information.
Code Example
-
Q21. Can I create several scrolled EditTables in an application and
have them share scroll bar(s)?
-
Multiple INT Scroll widgets can share scrollbar(s) so that it is
possible to synchronize the scrolling of multiple EditTable widgets.
The following example shows you how to let two EditTable share a vertical scroll bar.
Code Example
-
Q22. How can I output the content of an EditTable to a PostScript
file?
-
use the INT convenience function XintEditTableOutputPostscript() to
create a PostScript file that contains the image of the specified cells.
Refer to the functions section of the EditTable Reference for more information.
Code Example
-
Q23. How can I add Graphic Objects to an EditTable?
-
Use the INT convenience functions XintCreate...Object() to add
Graphic Objects to an EditTable. The parent of the object is always the
table widget.
Code Example
-
Q24. How can I read data from an ASCII file into an EditTable widget?
-
Use the INT convenience function XintEditTableReadAscii()
Refer to the functions section of the EditTable Reference for more information.
Code Example