+ char *string = 0;
+ if (lcb->item)
+ XmStringGetLtoR (lcb->item, XmSTRING_DEFAULT_CHARSET, &string);
+ set_text_string (text_line, (string ? string : ""));
+ if (lcb->reason == XmCR_DEFAULT_ACTION && string)
+ demo_mode_hack (si, string);
+ if (string)
+ XtFree (string);
+#endif /* HAVE_MOTIF */
+ steal_focus_and_colormap (demo_dialog);
+}
+
+
+#if 0 /* configure does this now */
+#ifdef HAVE_ATHENA
+# if !defined(_Viewport_h)
+ /* The R4 Athena libs don't have this function. I don't know the right
+ way to tell, but I note that the R5 version of Viewport.h defines
+ _XawViewport_h, while the R4 version defines _Viewport_h. So we'll
+ try and key off of that... */
+# define HAVE_XawViewportSetCoordinates
+# endif
+#endif /* HAVE_ATHENA */
+#endif /* 0 */
+
+
+/* Why this behavior isn't automatic in *either* toolkit, I'll never know.
+ */
+static void
+ensure_selected_item_visible (Widget list)
+{
+#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 */