+#ifdef HAVE_MOTIF
+ 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);
+
+#else /* HAVE_ATHENA */
+# ifdef HAVE_XawViewportSetCoordinates
+
+ int margin = 16; /* should be line height or something. */
+ int count = 0;
+ int pos;
+ Dimension list_h = 0, vp_h = 0;
+ Dimension top_margin = 4; /* I don't know where this value comes from */
+ Position vp_x = 0, vp_y = 0, current_y;
+ double cratio;
+ Widget viewport = XtParent(demo_list);
+ Widget sb = (viewport ? XtNameToWidget(viewport, "*vertical") : 0);
+ float sb_top = 0, sb_size = 0;
+ XawListReturnStruct *current = XawListShowCurrent(demo_list);
+ if (!current || !sb) return;
+
+ XtVaGetValues(demo_list,
+ XtNnumberStrings, &count,
+ XtNheight, &list_h,
+ 0);
+ if (count < 2 || list_h < 10) return;
+
+ XtVaGetValues(viewport, XtNheight, &vp_h, XtNx, &vp_x, XtNy, &vp_y, 0);
+ if (vp_h < 10) return;
+
+ XtVaGetValues(sb, XtNtopOfThumb, &sb_top, XtNshown, &sb_size, 0);
+ if (sb_size <= 0) return;
+
+ pos = current->list_index;
+ cratio = ((double) pos) / ((double) count);
+ current_y = (cratio * list_h);
+
+ if (cratio < sb_top ||
+ cratio > sb_top + sb_size)
+ {
+ if (cratio < sb_top)
+ current_y -= (vp_h - margin - margin);
+ else
+ current_y -= margin;
+
+ if ((long)current_y >= (long) list_h)
+ current_y = (Position) ((long)list_h - (long)vp_h);
+
+ if ((long)current_y < (long)top_margin)
+ current_y = (Position)top_margin;
+
+ XawViewportSetCoordinates (viewport, vp_x, current_y);
+ }
+# endif /* HAVE_XawViewportSetCoordinates */
+#endif /* HAVE_ATHENA */
+}
+
+
+static void
+next_cb (Widget button, XtPointer client_data, XtPointer call_data)
+{
+ saver_info *si = (saver_info *) client_data;
+
+#ifdef HAVE_ATHENA
+ int cnt;
+ XawListReturnStruct *current = XawListShowCurrent(demo_list);
+ if (current->list_index == XAW_LIST_NONE)
+ XawListHighlight(demo_list,1);
+ else
+ {
+ XtVaGetValues(demo_list,
+ XtNnumberStrings, &cnt,
+ NULL);
+ if (current->list_index + 1 < cnt)
+ {
+ current->list_index++;
+ XawListHighlight(demo_list, current->list_index);
+ }
+ }
+
+ ensure_selected_item_visible (demo_list);
+ current = XawListShowCurrent(demo_list);
+ demo_mode_hack (si, current->string);
+
+#else /* HAVE_MOTIF */
+