http://ftp.x.org/contrib/applications/xscreensaver-2.17.tar.gz
[xscreensaver] / driver / demo.c
index a0ae2dab66c1b2d0b09f4c833d4f75822724cb15..0877ad4ef50b89c3a51f55effa429aa5522f604b 100644 (file)
 
 #include <X11/Intrinsic.h>
 
+/* We don't actually use any widget internals, but these are included
+   so that gdb will have debug info for the widgets... */
+#include <X11/IntrinsicP.h>
+#include <X11/ShellP.h>
+
 #ifdef HAVE_MOTIF
 # include <Xm/Xm.h>
 # include <Xm/Text.h>
@@ -363,18 +368,19 @@ next_cb (Widget button, XtPointer client_data, XtPointer call_data)
   int *pos_list;
   int pos_count;
   if (! XmListGetSelectedPos (demo_list, &pos_list, &pos_count))
-    XmListSelectPos (demo_list, 1, True);
+    {
+      XmListDeselectAllItems(demo_list);       /* LessTif lossage */
+      XmListSelectPos (demo_list, 1, True);
+    }
   else
     {
-      int pos = pos_list [0];
-      XmListSelectPos (demo_list, pos + 1, True);
-      XtFree ((char *) pos_list);
-      if (! XmListGetSelectedPos (demo_list, &pos_list, &pos_count))
-       abort ();
-      if (pos_list [0] == pos)
-       XmListSelectPos (demo_list, 1, True);
-      XtFree ((char *) pos_list);
+      int pos = pos_list[0] + 1;
+      if (pos > si->prefs.screenhacks_count)
+       pos = 1;
+      XmListDeselectAllItems(demo_list);       /* LessTif lossage */
+      XmListSelectPos (demo_list, pos, True);
     }
+  XtFree ((char *) pos_list);
   ensure_selected_item_visible (demo_list);
   demo_mode_hack (si, get_text_string (text_line));
 
@@ -409,9 +415,13 @@ prev_cb (Widget button, XtPointer client_data, XtPointer call_data)
   int *pos_list;
   int pos_count;
   if (! XmListGetSelectedPos (demo_list, &pos_list, &pos_count))
-    XmListSelectPos (demo_list, 0, True);
+    {
+      XmListDeselectAllItems(demo_list);       /* LessTif lossage */
+      XmListSelectPos (demo_list, 0, True);
+    }
   else
     {
+      XmListDeselectAllItems(demo_list);       /* LessTif lossage */
       XmListSelectPos (demo_list, pos_list [0] - 1, True);
       XtFree ((char *) pos_list);
     }
@@ -451,6 +461,7 @@ restart_cb (Widget button, XtPointer client_data, XtPointer call_data)
   demo_mode_restart_process (si);
 }
 
+
 void
 pop_up_dialog_box (Widget dialog, Widget form, int where)
 {
@@ -481,13 +492,12 @@ pop_up_dialog_box (Widget dialog, Widget form, int where)
   XtSetArg (av [ac], XtNheight, &h); ac++;
   XtGetValues (form, av, ac);
 
-#ifdef DEBUG
+  /* for debugging -- don't ask */
   if (where >= 69)
     {
       where -= 69;
       sw = (sw * 7) / 12;
     }
-#endif
 
   switch (where)
     {
@@ -575,6 +585,32 @@ make_screenhack_dialog (saver_info *si)
       XmStringFree (xmstr);
     }
 
+  /* Cause the most-recently-run hack to be selected in the list.
+     Do some voodoo to make it be roughly centered in the list (really,
+     just make it not be within +/- 5 of the top/bottom if possible.)
+   */
+  if (ssi->current_hack > 0)
+    {
+      int i = ssi->current_hack+1;
+      int top = i + 5;
+      int bot = i - 5;
+      if (bot < 1) bot = 1;
+      if (top > si->prefs.screenhacks_count)
+       top = si->prefs.screenhacks_count;
+
+      XmListDeselectAllItems(demo_list);       /* LessTif lossage */
+      XmListSelectPos (demo_list, bot, False);
+      ensure_selected_item_visible (demo_list);
+
+      XmListDeselectAllItems(demo_list);       /* LessTif lossage */
+      XmListSelectPos (demo_list, top, False);
+      ensure_selected_item_visible (demo_list);
+
+      XmListDeselectAllItems(demo_list);       /* LessTif lossage */
+      XmListSelectPos (demo_list, i, False);
+      ensure_selected_item_visible (demo_list);
+    }
+
 #else  /* HAVE_ATHENA */
 
   XtVaSetValues (demo_list,
@@ -583,12 +619,15 @@ make_screenhack_dialog (saver_info *si)
                 0);
   XtAddCallback (demo_list, XtNcallback, select_cb, si);
 
+  /* ####   still need to do the "select most-recently-run hack"
+     ####   thing for Athena.
+  */
+
 #endif /* HAVE_ATHENA */
 
   pop_up_dialog_box(demo_dialog, demo_form,
-#ifdef DEBUG
+                   /* for debugging -- don't ask */
                    (si->prefs.debug_p ? 69 : 0) +
-#endif
                    0);
 }
 
@@ -703,21 +742,20 @@ res_done_cb (Widget button, XtPointer client_data, XtPointer call_data)
   p->unfade_p = res.unfade;
   p->lock_p = res.lock_p;
 
-#ifdef DEBUG
   if (p->debug_p && p->verbose_p)
     fprintf (stderr, "%s: parameters changed:\n\
        timeout: %d\n\tcycle:   %d\n\tlock:    %d\n\tpasswd:  %d\n\
        fade:    %d\n\tfade:    %d\n\tverbose: %d\n\tinstall: %d\n\
        fade:    %d\n\tunfade:  %d\n\tlock:    %d\n",
             progname, p->timeout, p->cycle, p->lock_timeout,
-# ifdef NO_LOCKING
+#ifdef NO_LOCKING
             0,
-# else
+#else
             p->passwd_timeout,
-# endif
+#endif
             p->fade_seconds, p->fade_ticks, p->verbose_p, p->install_cmap_p,
             p->fade_p, p->unfade_p, p->lock_p);
-#endif /* DEBUG */
+
 
 #if defined(HAVE_MIT_SAVER_EXTENSION) || defined(HAVE_SGI_SAVER_EXTENSION)
   if (p->use_mit_saver_extension || p->use_sgi_saver_extension)
@@ -871,9 +909,8 @@ pop_resources_dialog (saver_info *si)
   set_toggle_button_state (lock_toggle, res.lock_p);
 
   pop_up_dialog_box (resources_dialog, resources_form,
-#ifdef DEBUG
+                    /* for debugging -- don't ask */
                     (si->prefs.debug_p ? 69 : 0) +
-#endif
                     1);
 }