On 12/16/21 00:22, Chris Sorenson wrote:
Tried it out, but it not yield the desired result, unfortunately. The list widget gets resized but it does not update the visible item count property. I need to somehow catch the resize event and update it manually, but I don't find any suitable callback.Hrm, do you have XmNvisualPolicy set to XmVARIABLE on the scrolled window?
I investigated the issue further. As it turns out, the ScrolledList behaves correctly, i.e. if it is resized by the parent widget, then the visible item count is re-calculated and updated. The problem is the RowColumn: With orientation set to XmVERTICAL (the default), the widgets are only resized along the x-axis. Their height, however, remains fixed. Therefore, the ScrolledList widget inside that RowColumn gets its height never properly updated and cannot adjust its visible item cound. When setting the RowColumn's orientation to XmHORIZONTAL, the behavior is mirrored: The heights of the childrens are updated, but their respective width remains fixed. Setting the orientation to both XmVERTICAL and XmHORIZONTAL to somehow "merge" these two ways of behavior is not possible. I also tried using a Form-Widget instead of a RowColumn and use XmATTACH_FORM for all directions (top, bottom, left and right), but the Form would not resize the ScrollList widget either. I have attached a small example program to illustrate the behavior. Just try to resize the main window and observe how the ScrolledList widget is NOT properly resized. Maybe it's a feature, I don't know. But it looks like I'll have to write my own manager widget to accomplish the task. Best, Holger
/* * scrolled_list_rowcol.c * * Example program to illustrate resizing behavior of a RowColumn widget * * Compile with (on FreeBSD 13.0): * clang -o scrolled_list_rowcol scrolled_list_rowcol.c -I/usr/local/include -L/usr/local/lib -lXm -lXt -lX11 */ #include <Xm/List.h> #include <Xm/RowColumn.h> #include <Xm/PushB.h> #include <stdio.h> #define NUM_STRINGS 15 int main(int argc, char *argv[]) { XtAppContext app; Widget toplevel, list_w, rowcol, button; XmStringTable str_list; char buf[256]; Arg args[10]; int n; /* Initialize toolkit and parse command line options. */ toplevel = XtVaOpenApplication(&app, "scrolled_list", NULL, 0, &argc, argv, NULL, sessionShellWidgetClass, NULL); /* Initlize the RowColumn widget. */ n = 0; XtSetArg(args[n], XmNadjustLast, True); /* does not help, unfortunately. */ ++n; XtSetArg(args[n], XmNorientation, XmVERTICAL); ++n; rowcol = XmCreateRowColumn(toplevel, "rowcolumn", args, n); /* Some widget to make RowColumn meaningful. */ button = XmCreatePushButton(rowcol, "This is a button", NULL, 0); /* Create a list of XmString's. */ str_list = (XmStringTable)XtMalloc(NUM_STRINGS * sizeof(XmString)); for (n = 0; n < NUM_STRINGS; ++n) { snprintf(buf, sizeof(buf), "This is string %d", n); str_list[n] = XmStringCreateLocalized(buf); } /* Initialize the ScrolledListWidget. */ n = 0; XtSetArg(args[n], XmNvisibleItemCount, 5); ++n; XtSetArg(args[n], XmNvisualPolicy, XmVARIABLE); ++n; XtSetArg(args[n], XmNitemCount, NUM_STRINGS); ++n; XtSetArg(args[n], XmNitems, str_list); ++n; list_w = XmCreateScrolledList(rowcol, "list_w", args, n); /* Free the strings. */ for (n = 0; n < NUM_STRINGS; ++n) XmStringFree(str_list[n]); /* Setup and launch application. */ XtManageChild(button); XtManageChild(list_w); XtManageChild(rowcol); XtRealizeWidget(toplevel); XtAppMainLoop(app); return 0; }