Home Home Company Information Email Japanese

XRT/table FAQ

General

I can't seem to set and override translations on the widget.

You need to be sure that translations are also set on the clip children of the table. If you are trying to set translations on a widget in a table cell, set the translations on that widget, not the table. Note that if you are setting translations on a widget created by the CreateWidgetCallback, you must set them when the callback gets called for XRTTBL_REASON_CREATE_WIDGET_END rather than BEGIN. If you set it before the widget is created, the table will install its translations over yours.

I have added some [rows|columns] to my table, but they don't appear.

When no values are specified for new [rows|columns] and XmNxrtTblPixel[Height|Width]Context is set to XRTTBL_VARIABLE, new [rows|columns] will be invisible when created.

How can I make sure that my rows stay a certain minimum height? When the cells are empty they go to back to there default height which is too small.


Use XmNxrtTblMinFlexible[Width|Height] together with XmNxrtTblPixel[Width|Height]Context set to XRTTBL_FLEXIBLE. These settings allow your table to grow when you resize the windows, but puts a lower limit on the size of the cells.

You can use XmNxrtTblResizeCellCallback to control the resizing. The call_data for this callback contains information regarding the current or new widget dimensions. You can override the new height and width to a preferred value; or you can prevent the resize by setting the "doit" flag to false.

How do I prevent my table from flickering when I update the resources?

Set XmNxrtTblRepaint to XRTTBL_REPAINT_OFF while updating, and then to XRTTBL_REPAINT_ON when you are done.

How do I place a label in the far outer top-left corner of the table?

Use the context (XRTTBL_LABEL, XRTTBL_LABEL).

I am able to specify colors by simply giving the name of the color in quotes if I use XRT widgets. Why can't I do that when specifying a color for non XRT widgets?


XRT products convert color strings into pixel values for you. Here is a function you can use to allow you to use color names.

Pixel GetNamedColor(Widget widget, String colorname)
{
    Display *display;
    Colormap cmap;
    XColor  alloc_color, exact_color;
    display = XtDisplay(widget);
    XtVaGetValues(widget, XtNcolormap, &cmap, NULL);
    if (XAllocNamedColor(display, cmap, colorname, &alloc_color, &exact_color))
        return alloc_color.pixel;
    else
        fprintf(stderr,"Can't allocate color!\n");
}

The following will set the colors on a scrollbar. The slider will be red, and the trough area will be green.

XtVaSetValues(scrollbar_id,
    XmNtroughColor, GetNamedColor(toplevel, "green"),
    XmNbackground, GetNamedColor(toplevel, "red"),
    NULL);

When I traverse from one table to another, why is the EnterCell callback of the second table not invoked?


Make sure that the context of the cell you are traversing to in the second table is traversable. Here is how to set all cells in a table as traversable.

XtVaSetValues(table,
    XmNxrtTblContext,
    XrtTblSetContext(XRTTBL_ALLCELLS, XRTTBL_ALLCELLS),
    XmNxrtTblTraversableContext, True,
    NULL);

How can I change the color of the scrollbar(s)?

You can use fallback resources to set the default background color for the entire application when you call XtAppInitialize(). For example, if you want your scrollbars in your program (let's call it "Your_app") to be grey, try:

static char *fallback[] = { "Your_app*.background: grey85", NULL};
...
toplevel = XtAppInitialize(&app_context, "Your_app", NULL, 0, &argc, argv,
    fallback, NULL, 0);

Another way to do it is by using XtVaGetValues to get the widget id, and setting the value for the widget. This second method has the advantage of allowing you to change the color whenever you want to in the program, and changing the horizontal and vertical scrollbars separately. Try:

Widget scrollbar_id;
Pixel trough_col, slider_col;
...
XtVaGetValues(table, XmNxrtTblHorizontalScrollBar, &scrollbar_id, NULL);

and then set its values as a normal Motif XmScrollBar widget:

XtVaSetValues(scrollbar_id,
    XmNtroughColor, trough_col,
    XmNbackground, slider_col,
    NULL);

I can't seem to get more than one context to work in XtVaSetValues().

With XRT/table you may only set a context once in a call to XtVaCreateManagedWidget or XtVaSetValues. You may, however, use additional calls to XtVaSetValues to set as many contexts as needed.

What is the easiest way to put data in the table?

Read it in from a text file XrtTblReadAscii(). If your data is not conveniently in a delimited ASCII text file, and you don't want to bother building up your own XrtTblCellValues structure, use XrtTblAddRows(). With this function, you need only to create arrays of string values which you add as a row of values to an empty table. If you really need to get fancy, we provide the source for XrtTblReadAscii() (in $XRTHOME/src/table/util/) from which you can get ideas.

How do I search and sort the data in a table?

There are two good examples of this functionality. Check out the spreadsheet demo. The search feature in this demo is quite complex. For a simpler example, check out $XRTHOME/src/table/examples/list.c. You will need to compile this by entering "make list". This search will only find the first instance of a string. Both of the above demos will sort data when you click on a column label. The tables can only sort on one column.

I'm having problems installing my own converters.

Make sure you set your converter after you have called the XtClassInitialize() for the appropriate class.

The outer cells of a large table (about 2000x2000) get clipped.

Some customers have reported this problem. It appears to be related to early versions of vuewm (window manager). Try running the application on a machine with a more recent window manager. XRT/table widget should be able to handle a 2 billion x 2 billion table.

Why can't I get a validate callback on a label?

You should set the selection policy to XRTTBL_SELECT_MULTIRANGE.

Widgets in Cells

I am cloning widgets. Why can't I change the resources of the cloned widgets?

Resources for cloned widgets are specified by XmNxrtTableWidgetLocation or XmNxrtTableWidgetContext at the time of widget creation, and cannot be changed afterwards. This is different from earlier versions of XRT/table.

Why can't I clone Option Menus?

Motif Option Menus cannot be cloned and reused like other Motif widgets because of their composite nature.

You have a couple of choices:

You can manage them yourself by destroying them yourself and recreating them as needed. You can use the XmNxrtTblCreateWidgetCallback, ..DisplayWidgetCallback and ..WidgetSetValueCallback to help you do this (see the reference pages in your manual for details). This may be a complex undertaking in general but it should be possible to tailor it you the needs of your app.

You can use the ComboBox from XRT/field. This widget has similar semantics to the Motif OptionMenu but can be efficiently managed by XRT/table.

Cell Selection

How do I select new cells without deselecting previously selected cells?

Use Ctrl-Btn1Down to select additional cells. See the Translations and Actions Reference on page 195 of your manual.

I can't select anything in my table.

Your SelectionPolicy is probably not set correctly. Please see page 89 in the manual.

Why is my Select callback getting called three times for every selection?

The Select callback gets called for three reasons -- SELECT_BEGIN, SELECT_END, and SELECT_EXTEND. You should check the reason for the callback. See page 91 of the manual.

Drag and Drop

How do I disable a table as a drop site?

Set XmNxrtTblImportTargets to NULL.

How do I disable a table as a drag site?

You must also disable drag on these children. Another way is to add the following to your resource file.

*XtXrtTable.XtXrtTableClipChildren.translations: #override  \n\
    Shift <Btn2Down>:      NoAction() \n\
    Ctrl <Btn2Down>:       NoAction() \n\
    <Btn2Down>:            NoAction()

"Can't register widget as a drop site more than once" when I register a widget to a range of my table.

You are getting this message probably because you are using XmNxrtTblWidgetLocation and XrtTblSetContext(XRTTBL_ALLCELLS, i). When registering widgets to range of cells try XrtTblSetRange() instead of XrtTblSetContext(). Set XmNxrtTblWidgetLocation to: XrtTblSetRange(start_row, start_column, end_row, end_column);

The importing of drop site data doesn't work.

For importing data, the conversion procedure should be as follows:

ImportingConversionProcedure(
    Widget table,
    String target,          /* Name of target type */
    XrtTblContext *context, /* Region of operation */
    String *processed,      /* list of targets already processed */
    Boolean insert,         /* insert data if possible */
    XtPointer data,         /* pointer to data to import */
    unsigned long data_len  /* length of data to import */
)

Current Cell

How do I permanently hide the text widget?

Set XmNxrtTblTraversableContext to False.

How do I force a particular cell to be the current cell?

Use XrtTblTraverseToCell().

How do I make the Enter key trigger a ValidateCell callback, instead of traversing to another cell?

You will need to set your own translations on the entry widget:

Widget XmTextWidgetID;
static char trans[] = "<key>Return: CommitEdit(False)";
...
XtVaGetValues(table,
    XmNxrtTblText, &XmTextWidgetID,
    NULL);
XtOverrideTranslations(XmTextWidgetID, XtParseTranslationTable(trans));

How do I position text within a cell or label in table?

The vertical and horizontal position of text in the XRT/table widget can be controlled by setting the XmNxrtAlignmentContext resource. The following code will center column labels in a XRT/table widget:

XtVaSetValues(TableWidget,
    XmNxrtTblContext, XrtTblSetContext(XRTTBL_LABEL,XRTTBL_ALL),
    XmNxrtTblAlignmentContext, XmALIGNMENT_CENTER,
    NULL);

When I traverse to a cell, why does the text always jump to the top-left corner, even though my alignment is set otherwise?


The editing takes place in an XmText widget by default. The XmText widget does not allow you to specify the location of the text, but instead defaults to its own top left location.

XRT/table Performance

Speed can sometimes be a problem with applications that either use a large amount of data or try to set too many contexts. One common mistake is to use too many XtVaSetValues to set contexts. You should program your own series in this case. Another performance problem occurs in tables with heavily customized cells, such as cells with individual background colors. In this case, it is worth the effort to manage your contexts programmatically.

For large data (larger than 1000x1000), you should use XmNxrtTblCellValueCallback together with XmNxrtTblXmStringSetMode set to XRTTBL_SET_STRING. With this method, the table should support 2 billion rows by 2 billion columns.

Printing with XRT/table

I get a segmentation fault when I use XrtTblDrawPS().

All parameters which are doubles must be passed as a pointer.

How can I print several non-contiguous ranges of my table?

XRT/table comes with several routines for printing - XrtTblVaDrawPS(), XrtTblWriteAscii(), and XrtTblWriteSylk(). These routines have a "range" parameter that allows you to specify a rectangular area of data to print. You are provided with the source code for XrtTblWriteAscii() (in $XRTHOME/src/table/util/routines.c). You can simply extend this routine to provide support for multiple ranges. The other two routines, however, are supplied as objects only, and thus you can output only a single range when using XrtTblVaDrawPS() and XrtTblWriteSylk().

When trying to print using XrtTblVaDrawPS(), the generated .ps file tries to reference undefined /HeaderFont and /FooterFont.


HeaderFont and FooterFont are defined only when valid strings for XRTTBL_PS_HEADER and XRTTBL_PS_FOOTER are passed to XrtTblVaDrawPS(). Please, check that you are specifying header/footer strings when calling XrtTblVaDrawPS(). The simple workaround is to set XRTTBL_PS_HEADER and XRTTBL_PS_FOOTER as "" (empty string), and then pass valid header/footer in XmNxrtTblPrintCallback.

Why do some widgets, like labels, not print, even though I can see them on the screen?

XrtTblVaDrawPS() prints only properly managed children of XRT/table. Check the value of XmNxrtTblLocation. The default value of this resource is set to XRTTBLOCATION_NONE, which won't print.

Samples and Examples

Spanned cells

The following example SelectCallback will allow you to select a spanned cell, no matter where you click in the span. The default behavior is that the spanned cell will be selected only if your cursor is on the top-left cell of the span. The other areas are insensitive. This sample code shows how you can change the selected cell in the callback structure.

void cellCB(Widget w, XtPointer clientD, XrtTblSelectCallbackStruct *callD)
{
    XrtTblRange range;
    if (callD->reason == XRTTBL_REASON_SELECT_BEGIN
        || callD->reason == XRTTBL_REASON_SELECT_EXTEND)
    {
        if (XrtTblGetSpanByRowCol(w, callD->row, callD->column, &range))
        {
              callD->row = range.start_row;
              callD->column = range.start_column;
        }
    }
}