http://svn.poeml.de/viewvc/ppc/src-unpacked/xscreensaver/xscreensaver-4.12.tar.bz2...
[xscreensaver] / driver / demo-Gtk.c
index f0ca8e4aa96a784d6d0dd6bbf49acfffd4b8b9cc..715ca3934f55a472ed8a2b8300177e391a65d9b3 100644 (file)
@@ -1,5 +1,5 @@
 /* demo-Gtk.c --- implements the interactive demo-mode and options dialogs.
- * xscreensaver, Copyright (c) 1993-2002 Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright (c) 1993-2003 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 # include <unistd.h>
 #endif
 
+# ifdef __GNUC__
+#  define STFU __extension__  /* ignore gcc -pendantic warnings in next sexp */
+# else
+#  define STFU /* */
+# endif
+
+
 #ifdef ENABLE_NLS
 # include <locale.h>
 #endif /* ENABLE_NLS */
 # define DEFAULT_ICONDIR GLADE_DIR
 #endif
 
+#ifndef HAVE_XML
+ /* Kludge: this is defined in demo-Gtk-conf.c when HAVE_XML.
+    It is unused otherwise, so in that case, stub it out. */
+ static const char *hack_configuration_path = 0;
+#endif
+
+
 
 #include "version.h"
 #include "prefs.h"
@@ -293,12 +307,14 @@ ensure_selected_item_visible (GtkWidget *widget)
   
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
   if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-    return;
-
-  path = gtk_tree_model_get_path (model, &iter);
+       path = gtk_tree_path_new_first ();
+  else
+       path = gtk_tree_model_get_path (model, &iter);
   
-  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (widget),
-                               path, NULL, FALSE, 0.0, 0.0);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (widget), path, NULL, FALSE);
+
+  gtk_tree_path_free (path);
+
 #else /* !HAVE_GTK2 */
 
   GtkScrolledWindow *scroller = 0;
@@ -422,7 +438,8 @@ warning_dialog (GtkWidget *parent, const char *message,
   while (parent && !parent->window)
     parent = parent->parent;
 
-  if (!GTK_WIDGET (parent)->window) /* too early to pop up transient dialogs */
+  if (!parent ||
+      !GTK_WIDGET (parent)->window) /* too early to pop up transient dialogs */
     {
       fprintf (stderr, "%s: too early for dialog?\n", progname);
       return;
@@ -505,13 +522,13 @@ warning_dialog (GtkWidget *parent, const char *message,
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
   gtk_container_set_border_width (GTK_CONTAINER (dialog), 10);
   gtk_window_set_title (GTK_WINDOW (dialog), progclass);
-  GTK_WIDGET_SET_FLAGS (ok, GTK_CAN_DEFAULT);
+  STFU GTK_WIDGET_SET_FLAGS (ok, GTK_CAN_DEFAULT);
   gtk_widget_show (ok);
   gtk_widget_grab_focus (ok);
 
   if (cancel)
     {
-      GTK_WIDGET_SET_FLAGS (cancel, GTK_CAN_DEFAULT); 
+      STFU GTK_WIDGET_SET_FLAGS (cancel, GTK_CAN_DEFAULT); 
       gtk_widget_show (cancel);
     }
   gtk_widget_show (label);
@@ -631,9 +648,9 @@ about_menu_cb (GtkMenuItem *menuitem, gpointer user_data)
      look as good in the plain-old default Latin1 "C" locale.)
    */
 #ifdef HAVE_GTK2
-  sprintf(copy, ("Copyright \xC2\xA9 1991-2002 %s"), s);
+  sprintf(copy, ("Copyright \xC2\xA9 1991-2003 %s"), s);
 #else  /* !HAVE_GTK2 */
-  sprintf(copy, ("Copyright \251 1991-2002 %s"), s);
+  sprintf(copy, ("Copyright \251 1991-2003 %s"), s);
 #endif /* !HAVE_GTK2 */
 
   sprintf (msg, "%s\n\n%s", copy, desc);
@@ -760,7 +777,6 @@ doc_menu_cb (GtkMenuItem *menuitem, gpointer user_data)
   sprintf (help_command + strlen(help_command),
            p->load_url_command, p->help_url, p->help_url);
   strcat (help_command, " ) &");
-fprintf(stderr, "## %s\n", help_command);
   system (help_command);
   free (help_command);
 }
@@ -841,6 +857,12 @@ await_xscreensaver (state *s)
                "\n"));
 
       if (root_p)
+
+# ifdef __GNUC__
+        __extension__     /* don't warn about "string length is greater than
+                             the length ISO C89 compilers are required to
+                             support" in the following expression... */
+# endif
         strcat (buf,
          _("You are running as root.  This usually means that xscreensaver\n"
             "was unable to contact your X server because access control is\n"
@@ -979,7 +1001,7 @@ force_list_select_item (state *s, GtkWidget *list, int list_elt, Bool scroll_p)
   if (!was) gtk_widget_set_sensitive (parent, True);
 #ifdef HAVE_GTK2
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
-  g_assert (model);
+  STFU g_assert (model);
   gtk_tree_model_iter_nth_child (model, &iter, NULL, list_elt);
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
   gtk_tree_selection_select_iter (selection, &iter);
@@ -1127,7 +1149,7 @@ hack_time_text (state *s, const char *line, Time *store, Bool sec_p)
       else
         {
           char c;
-          if (sscanf (line, "%u%c", &value, &c) != 1)
+          if (sscanf (line, "%d%c", &value, &c) != 1)
             value = -1;
           if (!sec_p)
             value *= 60;
@@ -1497,7 +1519,7 @@ flush_popup_changes_and_save (state *s)
   else if (!strcasecmp (visual, "greyscale"))          visual = "GrayScale";
   else if (!strcasecmp (visual, "pseudocolor"))        visual = "PseudoColor";
   else if (!strcasecmp (visual, "directcolor"))        visual = "DirectColor";
-  else if (1 == sscanf (visual, " %ld %c", &id, &c))   ;
+  else if (1 == sscanf (visual, " %lu %c", &id, &c))   ;
   else if (1 == sscanf (visual, " 0x%lx %c", &id, &c)) ;
   else
     {
@@ -1621,7 +1643,7 @@ list_activated_cb (GtkTreeView       *list,
   char *str;
   int list_elt;
 
-  g_return_if_fail (!gdk_pointer_is_grabbed ());
+  STFU g_return_if_fail (!gdk_pointer_is_grabbed ());
 
   str = gtk_tree_path_to_string (path);
   list_elt = strtol (str, NULL, 10);
@@ -2334,6 +2356,15 @@ populate_prefs_page (state *s)
 {
   saver_preferences *p = &s->prefs;
 
+  Bool can_lock_p = True;
+
+  /* Disable all the "lock" controls if locking support was not provided
+     at compile-time, or if running on MacOS. */
+# if defined(NO_LOCKING) || defined(__APPLE__)
+  can_lock_p = False;
+# endif
+
+
   /* The file supports timeouts of less than a minute, but the GUI does
      not, so throttle the values to be at least one minute (since "0" is
      a bad rounding choice...)
@@ -2433,8 +2464,9 @@ populate_prefs_page (state *s)
 
     /* Blanking and Locking
      */
-    SENSITIZE ("lock_spinbutton", p->lock_p);
-    SENSITIZE ("lock_mlabel",     p->lock_p);
+    SENSITIZE ("lock_button",     can_lock_p);
+    SENSITIZE ("lock_spinbutton", can_lock_p && p->lock_p);
+    SENSITIZE ("lock_mlabel",     can_lock_p && p->lock_p);
 
     /* DPMS
      */
@@ -2470,14 +2502,7 @@ populate_prefs_page (state *s)
 static void
 populate_popup_window (state *s)
 {
-  saver_preferences *p = &s->prefs;
-  GtkWidget *parent = name_to_widget (s, "settings_vbox");
   GtkLabel *doc = GTK_LABEL (name_to_widget (s, "doc"));
-  int list_elt = selected_list_element (s);
-  int hack_number = (list_elt >= 0 && list_elt < s->list_count
-                     ? s->list_elt_to_hack_number[list_elt]
-                     : -1);
-  screenhack *hack = (hack_number >= 0 ? p->screenhacks[hack_number] : 0);
   char *doc_string = 0;
 
   /* #### not in Gtk 1.2
@@ -2491,14 +2516,24 @@ populate_popup_window (state *s)
       s->cdata = 0;
     }
 
-  if (hack)
-    {
-      GtkWidget *cmd = GTK_WIDGET (name_to_widget (s, "cmd_text"));
-      const char *cmd_line = gtk_entry_get_text (GTK_ENTRY (cmd));
-      s->cdata = load_configurator (cmd_line, s->debug_p);
-      if (s->cdata && s->cdata->widget)
-        gtk_box_pack_start (GTK_BOX (parent), s->cdata->widget, TRUE, TRUE, 0);
-    }
+  {
+    saver_preferences *p = &s->prefs;
+    int list_elt = selected_list_element (s);
+    int hack_number = (list_elt >= 0 && list_elt < s->list_count
+                       ? s->list_elt_to_hack_number[list_elt]
+                       : -1);
+    screenhack *hack = (hack_number >= 0 ? p->screenhacks[hack_number] : 0);
+    if (hack)
+      {
+        GtkWidget *parent = name_to_widget (s, "settings_vbox");
+        GtkWidget *cmd = GTK_WIDGET (name_to_widget (s, "cmd_text"));
+        const char *cmd_line = gtk_entry_get_text (GTK_ENTRY (cmd));
+        s->cdata = load_configurator (cmd_line, s->debug_p);
+        if (s->cdata && s->cdata->widget)
+          gtk_box_pack_start (GTK_BOX (parent), s->cdata->widget,
+                              TRUE, TRUE, 0);
+      }
+  }
 
   doc_string = (s->cdata
                 ? s->cdata->description
@@ -3238,7 +3273,14 @@ get_best_gl_visual (state *s)
             sprintf (buf, "%s: running %s", blurb(), av[0]);
             perror (buf);
           }
-        exit (1);                               /* exits fork */
+
+        /* Note that one must use _exit() instead of exit() in procs forked
+           off of Gtk programs -- Gtk installs an atexit handler that has a
+           copy of the X connection (which we've already closed, for safety.)
+           If one uses exit() instead of _exit(), then one sometimes gets a
+           spurious "Gdk-ERROR: Fatal IO error on X server" error message.
+        */
+        _exit (1);                              /* exits fork */
         break;
       }
     default:
@@ -3404,8 +3446,15 @@ launch_preview_subproc (state *s)
 
         exec_command (p->shell, new_cmd, p->nice_inferior);
         /* Don't bother printing an error message when we are unable to
-           exec subprocesses; we handle that by polling the pid later. */
-        exit (1);  /* exits child fork */
+           exec subprocesses; we handle that by polling the pid later.
+
+           Note that one must use _exit() instead of exit() in procs forked
+           off of Gtk programs -- Gtk installs an atexit handler that has a
+           copy of the X connection (which we've already closed, for safety.)
+           If one uses exit() instead of _exit(), then one sometimes gets a
+           spurious "Gdk-ERROR: Fatal IO error on X server" error message.
+        */
+        _exit (1);  /* exits child fork */
         break;
 
       default:
@@ -3863,6 +3912,12 @@ g_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
 }
 
 
+#ifdef __GNUC__
+ __extension__     /* shut up about "string length is greater than the length
+                      ISO C89 compilers are required to support" when including
+                      the .ad file... */
+#endif
+
 static char *defaults[] = {
 #include "XScreenSaver_ad.h"
  0
@@ -4406,7 +4461,7 @@ main (int argc, char **argv)
       gtk_widget_ref (outer_vbox);
       gtk_container_remove (GTK_CONTAINER (s->toplevel_widget),
                             outer_vbox);
-      GTK_OBJECT_SET_FLAGS (outer_vbox, GTK_FLOATING);
+      STFU GTK_OBJECT_SET_FLAGS (outer_vbox, GTK_FLOATING);
       gtk_container_add (GTK_CONTAINER (capplet), outer_vbox);
 
       /* Find the window above us, and set the title and close handler. */