+static void
+ensure_selected_item_visible (list)
+ Widget list;
+{
+ int *pos_list = 0;
+ int pos_count = 0;
+ if (XmListGetSelectedPos (list, &pos_list, &pos_count) && pos_count > 0)
+ {
+ int top = -2;
+ int visible = 0;
+ XtVaGetValues (list,
+ XmNtopItemPosition, &top,
+ XmNvisibleItemCount, &visible,
+ 0);
+ if (pos_list[0] >= top + visible)
+ {
+ int pos = pos_list[0] - visible + 1;
+ if (pos < 0) pos = 0;
+ XmListSetPos (list, pos);
+ }
+ else if (pos_list[0] < top)
+ {
+ XmListSetPos (list, pos_list[0]);
+ }
+ }
+ if (pos_list)
+ XtFree ((char *) pos_list);
+}
+