]> code.delx.au - gnu-emacs/blobdiff - lwlib/lwlib.c
Update for MH-E release 7.95.
[gnu-emacs] / lwlib / lwlib.c
index 21ca8987f7b2f325312ecfbeba2fe08dfeddf779..39b9400c5c861399af3e27a6e17ac658c4fb1b9a 100644 (file)
 
 This file is part of the Lucid Widget Library.
 
-The Lucid Widget Library is free software; you can redistribute it and/or 
+The Lucid Widget Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 The Lucid Widget Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of 
+but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #ifdef NeXT
 #undef __STRICT_BSD__ /* ick */
 #endif
 
-#include <stdlib.h>
-#include <unistd.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "../src/lisp.h"
+
 #include <sys/types.h>
-#include <string.h>
 #include <stdio.h>
+#include <ctype.h>
 #include "lwlib-int.h"
 #include "lwlib-utils.h"
 #include <X11/StringDefs.h>
 
-#if defined(__GNUC__) && !defined(alloca)
-#define alloca __builtin_alloca
-#endif
-
-#if ((!__GNUC__) && !defined(__hpux)) && !defined(AIXV3)
-#include <alloca.h>
-#endif
-
-#if defined(AIXV3)
-#pragma alloca
-#endif
-
 #if defined (USE_LUCID)
 #include "lwlib-Xlw.h"
 #endif
 #if defined (USE_MOTIF)
 #include "lwlib-Xm.h"
+#else /* not USE_MOTIF */
+#if defined (USE_LUCID)
+#define USE_XAW
+#endif /* not USE_MOTIF && USE_LUCID */
 #endif
-#if defined (USE_OLIT)
-#include "lwlib-Xol.h"
+#if defined (USE_XAW)
+#include <X11/Xaw/Paned.h>
+#include "lwlib-Xaw.h"
 #endif
 
-#if !defined (USE_LUCID) && !defined (USE_MOTIF) && !defined (USE_OLIT)
-ERROR!  At least one of USE_LUCID, USE_MOTIF or USE_OLIT must be defined.
+#if !defined (USE_LUCID) && !defined (USE_MOTIF)
+ #error  At least one of USE_LUCID or USE_MOTIF must be defined.
 #endif
 
-#if defined (USE_MOTIF) && defined (USE_OLIT)
-ERROR! no more than one of USE_MOTIF and USE_OLIT may be defined.
+#ifndef max
+#define max(x, y) ((x) > (y) ? (x) : (y))
 #endif
 
 /* List of all widgets managed by the library. */
 static widget_info*
 all_widget_info = NULL;
 
-\f/* Forward declarations */
-static void
-instanciate_widget_instance (widget_instance* instance);
+#ifdef USE_MOTIF
+char *lwlib_toolkit_type = "motif";
+#else
+char *lwlib_toolkit_type = "lucid";
+#endif
+
+static widget_value *merge_widget_value P_ ((widget_value *,
+                                            widget_value *,
+                                            int, int *));
+static void instantiate_widget_instance P_ ((widget_instance *));
+static int my_strcasecmp P_ ((char *, char *));
+static void safe_free_str P_ ((char *));
+static void free_widget_value_tree P_ ((widget_value *));
+static widget_value *copy_widget_value_tree P_ ((widget_value *,
+                                                change_type));
+static widget_info *allocate_widget_info P_ ((char *, char *, LWLIB_ID,
+                                             widget_value *,
+                                             lw_callback, lw_callback,
+                                             lw_callback, lw_callback));
+static void free_widget_info P_ ((widget_info *));
+static void mark_widget_destroyed P_ ((Widget, XtPointer, XtPointer));
+static widget_instance *allocate_widget_instance P_ ((widget_info *,
+                                                     Widget, Boolean));
+static void free_widget_instance P_ ((widget_instance *));
+static widget_info *get_widget_info P_ ((LWLIB_ID, Boolean));
+static widget_instance *get_widget_instance P_ ((Widget, Boolean));
+static widget_instance *find_instance P_ ((LWLIB_ID, Widget, Boolean));
+static Boolean safe_strcmp P_ ((char *, char *));
+static Widget name_to_widget P_ ((widget_instance *, char *));
+static void set_one_value P_ ((widget_instance *, widget_value *, Boolean));
+static void update_one_widget_instance P_ ((widget_instance *, Boolean));
+static void update_all_widget_values P_ ((widget_info *, Boolean));
+static void initialize_widget_instance P_ ((widget_instance *));
+static widget_creation_function find_in_table P_ ((char *, widget_creation_entry *));
+static Boolean dialog_spec_p P_ ((char *));
+static void destroy_one_instance P_ ((widget_instance *));
+static void lw_pop_all_widgets P_ ((LWLIB_ID, Boolean));
+static Boolean get_one_value P_ ((widget_instance *, widget_value *));
+static void show_one_widget_busy P_ ((Widget, Boolean));
+
+void
+lwlib_memset (address, value, length)
+     char *address;
+     int value;
+     size_t length;
+{
+  int i;
+
+  for (i = 0; i < length; i++)
+    address[i] = value;
+}
+
+void
+lwlib_bcopy (from, to, length)
+     char *from;
+     char *to;
+     int length;
+{
+  int i;
 
+  for (i = 0; i < length; i++)
+    to[i] = from[i];
+}
 \f/* utility functions for widget_instance and widget_info */
-static char *
-safe_strdup (char* s)
+char *
+safe_strdup (s)
+     const char *s;
 {
   char *result;
   if (! s) return 0;
@@ -81,13 +139,36 @@ safe_strdup (char* s)
   return result;
 }
 
+/* Like strcmp but ignore differences in case.  */
+
+static int
+my_strcasecmp (s1, s2)
+     char *s1, *s2;
+{
+  while (1)
+    {
+      int c1 = *s1++;
+      int c2 = *s2++;
+      if (isupper (c1))
+       c1 = tolower (c1);
+      if (isupper (c2))
+       c2 = tolower (c2);
+      if (c1 != c2)
+       return (c1 > c2 ? 1 : -1);
+      if (c1 == 0)
+       return 0;
+    }
+}
+
 static void
-safe_free_str (char* s)
+safe_free_str (s)
+     char *s;
 {
   if (s) free (s);
 }
 
 static widget_value *widget_value_free_list = 0;
+static int malloc_cpt = 0;
 
 widget_value *
 malloc_widget_value ()
@@ -102,13 +183,14 @@ malloc_widget_value ()
   else
     {
       wv = (widget_value *) malloc (sizeof (widget_value));
+      malloc_cpt++;
     }
-  memset (wv, 0, sizeof (widget_value));
+  lwlib_memset ((void*) wv, 0, sizeof (widget_value));
   return wv;
 }
 
-/* this is analagous to free().  It frees only what was allocated
-   by malloc_widget_value(), and no substructures. 
+/* this is analogous to free().  It frees only what was allocated
+   by malloc_widget_value(), and no substructures.
  */
 void
 free_widget_value (wv)
@@ -116,12 +198,24 @@ free_widget_value (wv)
 {
   if (wv->free_list)
     abort ();
-  wv->free_list = widget_value_free_list;
-  widget_value_free_list = wv;
+
+  if (malloc_cpt > 25)
+    {
+      /* When the number of already allocated cells is too big,
+        We free it.  */
+      free (wv);
+      malloc_cpt--;
+    }
+  else
+    {
+      wv->free_list = widget_value_free_list;
+      widget_value_free_list = wv;
+    }
 }
 
 static void
-free_widget_value_tree (widget_value* wv)
+free_widget_value_tree (wv)
+     widget_value *wv;
 {
   if (!wv)
     return;
@@ -134,7 +228,7 @@ free_widget_value_tree (widget_value* wv)
 
   if (wv->toolkit_data && wv->free_toolkit_data)
     {
-      free (wv->toolkit_data);
+      XtFree (wv->toolkit_data);
       wv->toolkit_data = (void *) 0xDEADBEEF;
     }
 
@@ -152,10 +246,12 @@ free_widget_value_tree (widget_value* wv)
 }
 
 static widget_value *
-copy_widget_value_tree (widget_value* val, change_type change)
+copy_widget_value_tree (val, change)
+     widget_value* val;
+     change_type change;
 {
   widget_value* copy;
-  
+
   if (!val)
     return NULL;
   if (val == (widget_value *) 1)
@@ -165,10 +261,13 @@ copy_widget_value_tree (widget_value* val, change_type change)
   copy->name = safe_strdup (val->name);
   copy->value = safe_strdup (val->value);
   copy->key = safe_strdup (val->key);
+  copy->help = val->help;
   copy->enabled = val->enabled;
+  copy->button_type = val->button_type;
   copy->selected = val->selected;
   copy->edited = False;
   copy->change = change;
+  copy->this_one_change = change;
   copy->contents = copy_widget_value_tree (val->contents, change);
   copy->call_data = val->call_data;
   copy->next = copy_widget_value_tree (val->next, change);
@@ -178,9 +277,16 @@ copy_widget_value_tree (widget_value* val, change_type change)
 }
 
 static widget_info *
-allocate_widget_info (char* type, char* name, LWLIB_ID id, widget_value* val,
-                     lw_callback pre_activate_cb, lw_callback selection_cb,
-                     lw_callback post_activate_cb)
+allocate_widget_info (type, name, id, val, pre_activate_cb,
+                     selection_cb, post_activate_cb, highlight_cb)
+     char* type;
+     char* name;
+     LWLIB_ID id;
+     widget_value* val;
+     lw_callback pre_activate_cb;
+     lw_callback selection_cb;
+     lw_callback post_activate_cb;
+     lw_callback highlight_cb;
 {
   widget_info* info = (widget_info*)malloc (sizeof (widget_info));
   info->type = safe_strdup (type);
@@ -191,6 +297,7 @@ allocate_widget_info (char* type, char* name, LWLIB_ID id, widget_value* val,
   info->pre_activate_cb = pre_activate_cb;
   info->selection_cb = selection_cb;
   info->post_activate_cb = post_activate_cb;
+  info->highlight_cb = highlight_cb;
   info->instances = NULL;
 
   info->next = all_widget_info;
@@ -200,17 +307,21 @@ allocate_widget_info (char* type, char* name, LWLIB_ID id, widget_value* val,
 }
 
 static void
-free_widget_info (widget_info* info)
+free_widget_info (info)
+     widget_info* info;
 {
   safe_free_str (info->type);
   safe_free_str (info->name);
   free_widget_value_tree (info->val);
-  memset ((void*)info, 0xDEADBEEF, sizeof (widget_info));
+  lwlib_memset ((void*)info, 0xDEADBEEF, sizeof (widget_info));
   free (info);
 }
 
 static void
-mark_widget_destroyed (Widget widget, XtPointer closure, XtPointer call_data)
+mark_widget_destroyed (widget, closure, call_data)
+     Widget widget;
+     XtPointer closure;
+     XtPointer call_data;
 {
   widget_instance* instance = (widget_instance*)closure;
 
@@ -219,18 +330,29 @@ mark_widget_destroyed (Widget widget, XtPointer closure, XtPointer call_data)
     instance->widget = NULL;
 }
 
+/* The messy #ifdef PROTOTYPES here and elsewhere are prompted by a
+   flood of warnings about argument promotion from proprietary ISO C
+   compilers.  (etags still only makes one entry for each function.)  */
 static widget_instance *
+#ifdef PROTOTYPES
 allocate_widget_instance (widget_info* info, Widget parent, Boolean pop_up_p)
+#else
+allocate_widget_instance (info, parent, pop_up_p)
+     widget_info* info;
+     Widget parent;
+     Boolean pop_up_p;
+#endif
 {
   widget_instance* instance =
     (widget_instance*)malloc (sizeof (widget_instance));
+  bzero (instance, sizeof *instance);
   instance->parent = parent;
   instance->pop_up_p = pop_up_p;
   instance->info = info;
   instance->next = info->instances;
   info->instances = instance;
 
-  instanciate_widget_instance (instance);
+  instantiate_widget_instance (instance);
 
   XtAddCallback (instance->widget, XtNdestroyCallback,
                 mark_widget_destroyed, (XtPointer)instance);
@@ -238,14 +360,21 @@ allocate_widget_instance (widget_info* info, Widget parent, Boolean pop_up_p)
 }
 
 static void
-free_widget_instance (widget_instance* instance)
+free_widget_instance (instance)
+     widget_instance* instance;
 {
-  memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance));
+  lwlib_memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance));
   free (instance);
 }
 
 static widget_info *
+#ifdef PROTOTYPES
 get_widget_info (LWLIB_ID id, Boolean remove_p)
+#else
+get_widget_info (id, remove_p)
+     LWLIB_ID id;
+     Boolean remove_p;
+#endif
 {
   widget_info* info;
   widget_info* prev;
@@ -266,8 +395,23 @@ get_widget_info (LWLIB_ID id, Boolean remove_p)
   return NULL;
 }
 
+/* Internal function used by the library dependent implementation to get the
+   widget_value for a given widget in an instance */
+widget_info *
+lw_get_widget_info (id)
+     LWLIB_ID id;
+{
+  return get_widget_info (id, 0);
+}
+
 static widget_instance *
+#ifdef PROTOTYPES
 get_widget_instance (Widget widget, Boolean remove_p)
+#else
+get_widget_instance (widget, remove_p)
+     Widget widget;
+     Boolean remove_p;
+#endif
 {
   widget_info* info;
   widget_instance* instance;
@@ -290,8 +434,25 @@ get_widget_instance (Widget widget, Boolean remove_p)
   return (widget_instance *) 0;
 }
 
+/* Value is a pointer to the widget_instance corresponding to
+   WIDGET, or null if WIDGET is not a lwlib widget.  */
+
+widget_instance *
+lw_get_widget_instance (widget)
+     Widget widget;
+{
+  return get_widget_instance (widget, False);
+}
+
 static widget_instance*
+#ifdef PROTOTYPES
 find_instance (LWLIB_ID id, Widget parent, Boolean pop_up_p)
+#else
+find_instance (id, parent, pop_up_p)
+     LWLIB_ID id;
+     Widget parent;
+     Boolean pop_up_p;
+#endif
 {
   widget_info* info = get_widget_info (id, False);
   widget_instance* instance;
@@ -307,18 +468,14 @@ find_instance (LWLIB_ID id, Widget parent, Boolean pop_up_p)
 \f
 /* utility function for widget_value */
 static Boolean
-safe_strcmp (char* s1, char* s2)
+safe_strcmp (s1, s2)
+     char* s1;
+     char* s2;
 {
   if (!!s1 ^ !!s2) return True;
   return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2;
 }
 
-static int
-max (int i1, int i2)
-{
-  return i1 > i2 ? i1 : i2;
-}
-
 
 #if 0
 # define EXPLAIN(name, oc, nc, desc, a1, a2)                           \
@@ -340,25 +497,33 @@ max (int i1, int i2)
 
 
 static widget_value *
-merge_widget_value (widget_value* val1, widget_value* val2, int level)
+merge_widget_value (val1, val2, level, change_p)
+     widget_value* val1;
+     widget_value* val2;
+     int level;
+     int *change_p;
 {
-  change_type change;
+  change_type change, this_one_change;
   widget_value* merged_next;
   widget_value* merged_contents;
 
   if (!val1)
     {
       if (val2)
-       return copy_widget_value_tree (val2, STRUCTURAL_CHANGE);
+       {
+         *change_p = 1;
+         return copy_widget_value_tree (val2, STRUCTURAL_CHANGE);
+       }
       else
        return NULL;
     }
   if (!val2)
     {
+      *change_p = 1;
       free_widget_value_tree (val1);
       return NULL;
     }
-  
+
   change = NO_CHANGE;
 
   if (safe_strcmp (val1->name, val2->name))
@@ -385,6 +550,13 @@ merge_widget_value (widget_value* val1, widget_value* val2, int level)
       safe_free_str (val1->key);
       val1->key = safe_strdup (val2->key);
     }
+  if (! EQ (val1->help, val2->help))
+    {
+      EXPLAIN (val1->name, change, VISIBLE_CHANGE, "help change",
+              val1->help, val2->help);
+      change = max (change, VISIBLE_CHANGE);
+      val1->help = val2->help;
+    }
   if (val1->enabled != val2->enabled)
     {
       EXPLAIN (val1->name, change, VISIBLE_CHANGE, "enablement change",
@@ -392,6 +564,13 @@ merge_widget_value (widget_value* val1, widget_value* val2, int level)
       change = max (change, VISIBLE_CHANGE);
       val1->enabled = val2->enabled;
     }
+  if (val1->button_type != val2->button_type)
+    {
+      EXPLAIN (val1->name, change, VISIBLE_CHANGE, "button type change",
+              val1->button_type, val2->button_type);
+      change = max (change, VISIBLE_CHANGE);
+      val1->button_type = val2->button_type;
+    }
   if (val1->selected != val2->selected)
     {
       EXPLAIN (val1->name, change, VISIBLE_CHANGE, "selection change",
@@ -410,25 +589,38 @@ merge_widget_value (widget_value* val1, widget_value* val2, int level)
   if (level > 0)
     {
       merged_contents =
-       merge_widget_value (val1->contents, val2->contents, level - 1);
-      
+       merge_widget_value (val1->contents, val2->contents, level - 1,
+                           change_p);
+
       if (val1->contents && !merged_contents)
        {
-         EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents gone)",
+         /* This used to say INVISIBLE_CHANGE,
+            but it is visible and vitally important when
+            the contents of the menu bar itself are entirely deleted.
+
+            But maybe it doesn't matter.  This fails to fix the bug.  */
+         EXPLAIN (val1->name, change, STRUCTURAL_CHANGE, "(contents gone)",
                   0, 0);
-         change = max (change, INVISIBLE_CHANGE);
+         change = max (change, STRUCTURAL_CHANGE);
        }
       else if (merged_contents && merged_contents->change != NO_CHANGE)
        {
          EXPLAIN (val1->name, change, INVISIBLE_CHANGE, "(contents change)",
                   0, 0);
          change = max (change, INVISIBLE_CHANGE);
+#if 0 /* This was replaced by the August 9 1996 change in lwlib-Xm.c.  */
+#ifdef USE_MOTIF
+         change = max (merged_contents->change, change);
+#endif
+#endif
        }
-      
+
       val1->contents = merged_contents;
     }
 
-  merged_next = merge_widget_value (val1->next, val2->next, level);
+  this_one_change = change;
+
+  merged_next = merge_widget_value (val1->next, val2->next, level, change_p);
 
   if (val1->next && !merged_next)
     {
@@ -446,12 +638,14 @@ merge_widget_value (widget_value* val1, widget_value* val2, int level)
 
   val1->next = merged_next;
 
+  val1->this_one_change = this_one_change;
   val1->change = change;
-  
+
   if (change > NO_CHANGE && val1->toolkit_data)
     {
+      *change_p = 1;
       if (val1->free_toolkit_data)
-       free (val1->toolkit_data);
+       XtFree (val1->toolkit_data);
       val1->toolkit_data = NULL;
     }
 
@@ -461,7 +655,9 @@ merge_widget_value (widget_value* val1, widget_value* val2, int level)
 \f
 /* modifying the widgets */
 static Widget
-name_to_widget (widget_instance* instance, char* name)
+name_to_widget (instance, name)
+     widget_instance* instance;
+     char* name;
 {
   Widget widget = NULL;
 
@@ -473,20 +669,29 @@ name_to_widget (widget_instance* instance, char* name)
   else
     {
       int length = strlen (name) + 2;
-      char* real_name = (char *) alloca (length);
+      char* real_name = (char *) xmalloc (length);
       real_name [0] = '*';
       strcpy (real_name + 1, name);
-      
+
       widget = XtNameToWidget (instance->widget, real_name);
+
+      free (real_name);
     }
   return widget;
 }
 
 static void
+#ifdef PROTOTYPES
 set_one_value (widget_instance* instance, widget_value* val, Boolean deep_p)
+#else
+set_one_value (instance, val, deep_p)
+     widget_instance* instance;
+     widget_value* val;
+     Boolean deep_p;
+#endif
 {
   Widget widget = name_to_widget (instance, val->name);
-  
+
   if (widget)
     {
 #if defined (USE_LUCID)
@@ -497,15 +702,21 @@ set_one_value (widget_instance* instance, widget_value* val, Boolean deep_p)
       if (lw_motif_widget_p (instance->widget))
        xm_update_one_widget (instance, widget, val, deep_p);
 #endif
-#if defined (USE_OLIT)
-      if (lw_olit_widget_p (instance->widget))
-       xol_update_one_widget (instance, widget, val, deep_p);
+#if defined (USE_XAW)
+      if (lw_xaw_widget_p (instance->widget))
+       xaw_update_one_widget (instance, widget, val, deep_p);
 #endif
     }
 }
 
 static void
+#ifdef PROTOTYPES
 update_one_widget_instance (widget_instance* instance, Boolean deep_p)
+#else
+update_one_widget_instance (instance, deep_p)
+     widget_instance* instance;
+     Boolean deep_p;
+#endif
 {
   widget_value *val;
 
@@ -519,7 +730,13 @@ update_one_widget_instance (widget_instance* instance, Boolean deep_p)
 }
 
 static void
+#ifdef PROTOTYPES
 update_all_widget_values (widget_info* info, Boolean deep_p)
+#else
+update_all_widget_values (info, deep_p)
+     widget_info* info;
+     Boolean deep_p;
+#endif
 {
   widget_instance* instance;
   widget_value* val;
@@ -531,8 +748,15 @@ update_all_widget_values (widget_info* info, Boolean deep_p)
     val->change = NO_CHANGE;
 }
 
-void
+int
+#ifdef PROTOTYPES
 lw_modify_all_widgets (LWLIB_ID id, widget_value* val, Boolean deep_p)
+#else
+lw_modify_all_widgets (id, val, deep_p)
+     LWLIB_ID id;
+     widget_value* val;
+     Boolean deep_p;
+#endif
 {
   widget_info* info = get_widget_info (id, False);
   widget_value* new_val;
@@ -541,9 +765,10 @@ lw_modify_all_widgets (LWLIB_ID id, widget_value* val, Boolean deep_p)
   widget_value* prev;
   widget_value* next;
   int          found;
+  int change_p = 0;
 
   if (!info)
-    return;
+    return 0;
 
   for (new_val = val; new_val; new_val = new_val->next)
     {
@@ -556,7 +781,8 @@ lw_modify_all_widgets (LWLIB_ID id, widget_value* val, Boolean deep_p)
            found = True;
            next = cur->next;
            cur->next = NULL;
-           cur = merge_widget_value (cur, new_val, deep_p ? 1000 : 1);
+           cur = merge_widget_value (cur, new_val, deep_p ? 1000 : 1,
+                                     &change_p);
            if (prev)
              prev->next = cur ? cur : next;
            else
@@ -572,18 +798,21 @@ lw_modify_all_widgets (LWLIB_ID id, widget_value* val, Boolean deep_p)
            prev->next = copy_widget_value_tree (new_val, STRUCTURAL_CHANGE);
          else
            info->val = copy_widget_value_tree (new_val, STRUCTURAL_CHANGE);
+         change_p = 1;
        }
       new_val->next = next_new_val;
     }
 
   update_all_widget_values (info, deep_p);
+  return change_p;
 }
 
 \f
 /* creating the widgets */
 
 static void
-initialize_widget_instance (widget_instance* instance)
+initialize_widget_instance (instance)
+     widget_instance* instance;
 {
   widget_value* val;
 
@@ -598,23 +827,26 @@ initialize_widget_instance (widget_instance* instance)
 
 
 static widget_creation_function
-find_in_table (char* type, widget_creation_entry* table)
+find_in_table (type, table)
+     char* type;
+     widget_creation_entry* table;
 {
   widget_creation_entry* cur;
   for (cur = table; cur->type; cur++)
-    if (!strcasecmp (type, cur->type))
+    if (!my_strcasecmp (type, cur->type))
       return cur->function;
   return NULL;
 }
 
 static Boolean
-dialog_spec_p (char* name)
+dialog_spec_p (name)
+     char* name;
 {
-  /* return True if name matches [EILPQeilpq][1-9][Bb] or 
+  /* return True if name matches [EILPQeilpq][1-9][Bb] or
      [EILPQeilpq][1-9][Bb][Rr][1-9] */
   if (!name)
     return False;
-  
+
   switch (name [0])
     {
     case 'E': case 'I': case 'L': case 'P': case 'Q':
@@ -634,14 +866,15 @@ dialog_spec_p (char* name)
        }
       else
        return False;
-    
+
     default:
       return False;
     }
 }
 
 static void
-instanciate_widget_instance (widget_instance* instance)
+instantiate_widget_instance (instance)
+     widget_instance* instance;
 {
   widget_creation_function function = NULL;
 
@@ -653,9 +886,9 @@ instanciate_widget_instance (widget_instance* instance)
   if (!function)
     function = find_in_table (instance->info->type, xm_creation_table);
 #endif
-#if defined (USE_OLIT)
+#if defined (USE_XAW)
   if (!function)
-    function = find_in_table (instance->info->type, xol_creation_table);
+    function = find_in_table (instance->info->type, xaw_creation_table);
 #endif
 
   if (!function)
@@ -669,12 +902,13 @@ instanciate_widget_instance (widget_instance* instance)
          if (!function)
            function = xm_create_dialog;
 #endif
-#if defined (USE_OLIT)
-         /* not yet */
+#if defined (USE_XAW)
+         if (!function)
+           function = xaw_create_dialog;
 #endif
        }
     }
-  
+
   if (!function)
     {
       printf ("No creation function for widget type %s\n",
@@ -690,31 +924,52 @@ instanciate_widget_instance (widget_instance* instance)
   /*   XtRealizeWidget (instance->widget);*/
 }
 
-void 
-lw_register_widget (char* type, char* name, LWLIB_ID id, widget_value* val,
-                   lw_callback pre_activate_cb, lw_callback selection_cb,
-                   lw_callback post_activate_cb)
+void
+lw_register_widget (type, name, id, val, pre_activate_cb,
+                   selection_cb, post_activate_cb, highlight_cb)
+     char* type;
+     char* name;
+     LWLIB_ID id;
+     widget_value* val;
+     lw_callback pre_activate_cb;
+     lw_callback selection_cb;
+     lw_callback post_activate_cb;
+     lw_callback highlight_cb;
 {
   if (!get_widget_info (id, False))
     allocate_widget_info (type, name, id, val, pre_activate_cb, selection_cb,
-                         post_activate_cb);
+                         post_activate_cb, highlight_cb);
 }
 
 Widget
+#ifdef PROTOTYPES
 lw_get_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
+#else
+lw_get_widget (id, parent, pop_up_p)
+     LWLIB_ID id;
+     Widget parent;
+     Boolean pop_up_p;
+#endif
 {
   widget_instance* instance;
-  
+
   instance = find_instance (id, parent, pop_up_p);
   return instance ? instance->widget : NULL;
 }
 
 Widget
+#ifdef PROTOTYPES
 lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
+#else
+lw_make_widget (id, parent, pop_up_p)
+     LWLIB_ID id;
+     Widget parent;
+     Boolean pop_up_p;
+#endif
 {
   widget_instance* instance;
   widget_info* info;
-  
+
   instance = find_instance (id, parent, pop_up_p);
   if (!instance)
     {
@@ -730,19 +985,36 @@ lw_make_widget (LWLIB_ID id, Widget parent, Boolean pop_up_p)
 }
 
 Widget
+#ifdef PROTOTYPES
 lw_create_widget (char* type, char* name, LWLIB_ID id, widget_value* val,
-                 Widget parent, Boolean pop_up_p, lw_callback pre_activate_cb,
-                 lw_callback selection_cb, lw_callback post_activate_cb)
+                 Widget parent, Boolean pop_up_p,
+                 lw_callback pre_activate_cb, lw_callback selection_cb,
+                 lw_callback post_activate_cb, lw_callback highlight_cb)
+#else
+lw_create_widget (type, name, id, val, parent, pop_up_p, pre_activate_cb,
+                 selection_cb, post_activate_cb, highlight_cb)
+     char* type;
+     char* name;
+     LWLIB_ID id;
+     widget_value* val;
+     Widget parent;
+     Boolean pop_up_p;
+     lw_callback pre_activate_cb;
+     lw_callback selection_cb;
+     lw_callback post_activate_cb;
+     lw_callback highlight_cb;
+#endif
 {
   lw_register_widget (type, name, id, val, pre_activate_cb, selection_cb,
-                     post_activate_cb);
+                     post_activate_cb, highlight_cb);
   return lw_make_widget (id, parent, pop_up_p);
 }
-                 
+
 \f
 /* destroying the widgets */
 static void
-destroy_one_instance (widget_instance* instance)
+destroy_one_instance (instance)
+     widget_instance* instance;
 {
   /* Remove the destroy callback on the widget; that callback will try to
      dereference the instance object (to set its widget slot to 0, since the
@@ -771,9 +1043,9 @@ destroy_one_instance (widget_instance* instance)
        xm_destroy_instance (instance);
       else
 #endif
-#if defined (USE_OLIT)
-      if (lw_olit_widget_p (instance->widget))
-       xol_destroy_instance (instance);
+#if defined (USE_XAW)
+      if (lw_xaw_widget_p (instance->widget))
+       xaw_destroy_instance (instance);
       else
 #endif
        /* do not remove the empty statement */
@@ -784,10 +1056,11 @@ destroy_one_instance (widget_instance* instance)
 }
 
 void
-lw_destroy_widget (Widget w)
+lw_destroy_widget (w)
+     Widget w;
 {
   widget_instance* instance = get_widget_instance (w, True);
-  
+
   if (instance)
     {
       widget_info *info = instance->info;
@@ -800,7 +1073,8 @@ lw_destroy_widget (Widget w)
 }
 
 void
-lw_destroy_all_widgets (LWLIB_ID id)
+lw_destroy_all_widgets (id)
+     LWLIB_ID id;
 {
   widget_info* info = get_widget_info (id, True);
   widget_instance* instance;
@@ -842,7 +1116,7 @@ lw_destroy_all_pop_ups ()
 }
 
 #ifdef USE_MOTIF
-extern Widget first_child (Widget);    /* garbage */
+extern Widget first_child (/* Widget */);      /* garbage */
 #endif
 
 Widget
@@ -879,7 +1153,13 @@ lw_raise_all_pop_up_widgets ()
 }
 
 static void
+#ifdef PROTOTYPES
 lw_pop_all_widgets (LWLIB_ID id, Boolean up)
+#else
+lw_pop_all_widgets (id, up)
+     LWLIB_ID id;
+     Boolean up;
+#endif
 {
   widget_info* info = get_widget_info (id, False);
   widget_instance* instance;
@@ -888,58 +1168,72 @@ lw_pop_all_widgets (LWLIB_ID id, Boolean up)
     for (instance = info->instances; instance; instance = instance->next)
       if (instance->pop_up_p && instance->widget)
        {
-         if (!XtIsRealized (instance->widget))
-           XtRealizeWidget (instance->widget);
 #if defined (USE_LUCID)
          if (lw_lucid_widget_p (instance->widget))
-           xlw_pop_instance (instance, up);
+           {
+             XtRealizeWidget (instance->widget);
+             xlw_pop_instance (instance, up);
+           }
 #endif
 #if defined (USE_MOTIF)
          if (lw_motif_widget_p (instance->widget))
-           xm_pop_instance (instance, up);
+           {
+             XtRealizeWidget (instance->widget);
+             xm_pop_instance (instance, up);
+           }
 #endif
-#if defined (USE_OLIT)
-         if (lw_olit_widget_p (instance->widget))
-           xol_pop_instance (instance, up);
+#if defined (USE_XAW)
+         if (lw_xaw_widget_p (instance->widget))
+           {
+             XtRealizeWidget (XtParent (instance->widget));
+             XtRealizeWidget (instance->widget);
+             xaw_pop_instance (instance, up);
+           }
 #endif
        }
 }
 
 void
-lw_pop_up_all_widgets (LWLIB_ID id)
+lw_pop_up_all_widgets (id)
+     LWLIB_ID id;
 {
   lw_pop_all_widgets (id, True);
 }
 
 void
-lw_pop_down_all_widgets (LWLIB_ID id)
+lw_pop_down_all_widgets (id)
+     LWLIB_ID id;
 {
   lw_pop_all_widgets (id, False);
 }
 
 void
-lw_popup_menu (Widget widget)
+lw_popup_menu (widget, event)
+     Widget widget;
+     XEvent *event;
 {
 #if defined (USE_LUCID)
   if (lw_lucid_widget_p (widget))
-    xlw_popup_menu (widget);
+    xlw_popup_menu (widget, event);
 #endif
 #if defined (USE_MOTIF)
   if (lw_motif_widget_p (widget))
-    xm_popup_menu (widget);
+    xm_popup_menu (widget, event);
 #endif
-#if defined (USE_OLIT)
-  if (lw_olit_widget_p (widget))
-    xol_popup_menu (widget);
+#if defined (USE_XAW)
+  if (lw_xaw_widget_p (widget))
+    xaw_popup_menu (widget, event);
 #endif
 }
 
 \f/* get the values back */
 static Boolean
-get_one_value (widget_instance* instance, widget_value* val)
+get_one_value (instance, val)
+     widget_instance* instance;
+     widget_value* val;
 {
   Widget widget = name_to_widget (instance, val->name);
-      
+
   if (widget)
     {
 #if defined (USE_LUCID)
@@ -950,9 +1244,9 @@ get_one_value (widget_instance* instance, widget_value* val)
       if (lw_motif_widget_p (instance->widget))
        xm_update_one_value (instance, widget, val);
 #endif
-#if defined (USE_OLIT)
-      if (lw_olit_widget_p (instance->widget))
-       xol_update_one_value (instance, widget, val);
+#if defined (USE_XAW)
+      if (lw_xaw_widget_p (instance->widget))
+       xaw_update_one_value (instance, widget, val);
 #endif
       return True;
     }
@@ -961,7 +1255,9 @@ get_one_value (widget_instance* instance, widget_value* val)
 }
 
 Boolean
-lw_get_some_values (LWLIB_ID id, widget_value* val_out)
+lw_get_some_values (id, val_out)
+     LWLIB_ID id;
+     widget_value* val_out;
 {
   widget_info* info = get_widget_info (id, False);
   widget_instance* instance;
@@ -983,7 +1279,8 @@ lw_get_some_values (LWLIB_ID id, widget_value* val_out)
 }
 
 widget_value*
-lw_get_all_values (LWLIB_ID id)
+lw_get_all_values (id)
+     LWLIB_ID id;
 {
   widget_info* info = get_widget_info (id, False);
   widget_value* val = info->val;
@@ -996,7 +1293,9 @@ lw_get_all_values (LWLIB_ID id)
 /* internal function used by the library dependent implementation to get the
    widget_value for a given widget in an instance */
 widget_value*
-lw_get_widget_value_for_widget (widget_instance* instance, Widget w)
+lw_get_widget_value_for_widget (instance, w)
+     widget_instance* instance;
+     Widget w;
 {
   char* name = XtName (w);
   widget_value* cur;
@@ -1007,24 +1306,27 @@ lw_get_widget_value_for_widget (widget_instance* instance, Widget w)
 }
 
 \f/* update other instances value when one thing changed */
-/* This function can be used as a an XtCallback for the widgets that get 
+
+/* To forbid recursive calls */
+static Boolean lwlib_updating;
+
+/* This function can be used as a an XtCallback for the widgets that get
   modified to update other instances of the widgets.  Closure should be the
   widget_instance. */
 void
-lw_internal_update_other_instances (Widget widget, XtPointer closure,
-                                   XtPointer call_data)
+lw_internal_update_other_instances (widget, closure, call_data)
+     Widget widget;
+     XtPointer closure;
+     XtPointer call_data;
 {
-  /* To forbid recursive calls */
-  static Boolean updating;
-  
   widget_instance* instance = (widget_instance*)closure;
   char* name = XtName (widget);
   widget_info* info;
   widget_instance* cur;
   widget_value* val;
 
-  /* never recurse as this could cause infinite recursions. */
-  if (updating)
+  /* Avoid possibly infinite recursion.  */
+  if (lwlib_updating)
     return;
 
   /* protect against the widget being destroyed */
@@ -1036,7 +1338,7 @@ lw_internal_update_other_instances (Widget widget, XtPointer closure,
   if (!info->instances->next)
     return;
 
-  updating = True;
+  lwlib_updating = True;
 
   for (val = info->val; val && strcmp (val->name, name); val = val->next);
 
@@ -1045,14 +1347,15 @@ lw_internal_update_other_instances (Widget widget, XtPointer closure,
       if (cur != instance)
        set_one_value (cur, val, True);
 
-  updating = False;
+  lwlib_updating = False;
 }
 
 
 \f/* get the id */
 
 LWLIB_ID
-lw_get_widget_id (Widget w)
+lw_get_widget_id (w)
+     Widget w;
 {
   widget_instance* instance = get_widget_instance (w, False);
 
@@ -1061,7 +1364,9 @@ lw_get_widget_id (Widget w)
 
 \f/* set the keyboard focus */
 void
-lw_set_keyboard_focus (Widget parent, Widget w)
+lw_set_keyboard_focus (parent, w)
+     Widget parent;
+     Widget w;
 {
 #if defined (USE_MOTIF)
   xm_set_keyboard_focus (parent, w);
@@ -1072,26 +1377,38 @@ lw_set_keyboard_focus (Widget parent, Widget w)
 
 \f/* Show busy */
 static void
+#ifdef PROTOTYPES
 show_one_widget_busy (Widget w, Boolean flag)
+#else
+show_one_widget_busy (w, flag)
+     Widget w;
+     Boolean flag;
+#endif
 {
   Pixel foreground = 0;
   Pixel background = 1;
   Widget widget_to_invert = XtNameToWidget (w, "*sheet");
   if (!widget_to_invert)
     widget_to_invert = w;
-  
+
   XtVaGetValues (widget_to_invert,
                 XtNforeground, &foreground,
                 XtNbackground, &background,
-                0);
+                NULL);
   XtVaSetValues (widget_to_invert,
                 XtNforeground, background,
                 XtNbackground, foreground,
-                0);
+                NULL);
 }
 
 void
+#ifdef PROTOTYPES
 lw_show_busy (Widget w, Boolean busy)
+#else
+lw_show_busy (w, busy)
+     Widget w;
+     Boolean busy;
+#endif
 {
   widget_instance* instance = get_widget_instance (w, False);
   widget_info* info;
@@ -1109,3 +1426,190 @@ lw_show_busy (Widget w, Boolean busy)
        }
     }
 }
+
+/* This hack exists because Lucid/Athena need to execute the strange
+   function below to support geometry management. */
+void
+#ifdef PROTOTYPES
+lw_refigure_widget (Widget w, Boolean doit)
+#else
+lw_refigure_widget (w, doit)
+     Widget w;
+     Boolean doit;
+#endif
+{
+#if defined (USE_XAW)
+  XawPanedSetRefigureMode (w, doit);
+#endif
+#if defined (USE_MOTIF)
+  if (doit)
+    XtManageChild (w);
+  else
+    XtUnmanageChild (w);
+#endif
+}
+
+/* Toolkit independent way of determining if an event window is in the
+   menubar. */
+Boolean
+lw_window_is_in_menubar (win, menubar_widget)
+     Window win;
+     Widget menubar_widget;
+{
+  return menubar_widget
+#if defined (USE_LUCID)
+      && XtWindow (menubar_widget) == win;
+#endif
+#if defined (USE_MOTIF)
+      && ((XtWindow (menubar_widget) == win)
+         || (XtWindowToWidget (XtDisplay (menubar_widget), win)
+             && (XtParent (XtWindowToWidget (XtDisplay (menubar_widget), win))
+                 == menubar_widget)));
+#endif
+}
+
+/* Motif hack to set the main window areas. */
+void
+lw_set_main_areas (parent, menubar, work_area)
+     Widget parent;
+     Widget menubar;
+     Widget work_area;
+{
+#if defined (USE_MOTIF)
+  xm_set_main_areas (parent, menubar, work_area);
+#endif
+}
+
+/* Manage resizing for Motif.  This disables resizing when the menubar
+   is about to be modified. */
+void
+#ifdef PROTOTYPES
+lw_allow_resizing (Widget w, Boolean flag)
+#else
+lw_allow_resizing (w, flag)
+     Widget w;
+     Boolean flag;
+#endif
+{
+#if defined (USE_MOTIF)
+  xm_manage_resizing (w, flag);
+#endif
+}
+
+
+/* Value is non-zero if LABEL is a menu separator.  If it is, *TYPE is
+   set to an appropriate enumerator of type enum menu_separator.
+   MOTIF_P non-zero means map separator types not supported by Motif
+   to similar ones that are supported.  */
+
+int
+lw_separator_p (label, type, motif_p)
+     char *label;
+     enum menu_separator *type;
+     int motif_p;
+{
+  int separator_p = 0;
+
+  if (strlen (label) >= 3
+      && bcmp (label, "--:", 3) == 0)
+    {
+      static struct separator_table
+      {
+       char *name;
+       enum menu_separator type;
+      }
+      separator_names[] =
+      {
+       {"space",                     SEPARATOR_NO_LINE},
+       {"noLine",                    SEPARATOR_NO_LINE},
+       {"singleLine",                SEPARATOR_SINGLE_LINE},
+       {"doubleLine",                SEPARATOR_DOUBLE_LINE},
+       {"singleDashedLine",          SEPARATOR_SINGLE_DASHED_LINE},
+       {"doubleDashedLine",          SEPARATOR_DOUBLE_DASHED_LINE},
+       {"shadowEtchedIn",            SEPARATOR_SHADOW_ETCHED_IN},
+       {"shadowEtchedOut",           SEPARATOR_SHADOW_ETCHED_OUT},
+       {"shadowEtchedInDash",        SEPARATOR_SHADOW_ETCHED_IN_DASH},
+       {"shadowEtchedOutDash",       SEPARATOR_SHADOW_ETCHED_OUT_DASH},
+       {"shadowDoubleEtchedIn",      SEPARATOR_SHADOW_DOUBLE_ETCHED_IN},
+       {"shadowDoubleEtchedOut",     SEPARATOR_SHADOW_DOUBLE_ETCHED_OUT},
+       {"shadowDoubleEtchedInDash",  SEPARATOR_SHADOW_DOUBLE_ETCHED_IN_DASH},
+       {"shadowDoubleEtchedOutDash", SEPARATOR_SHADOW_DOUBLE_ETCHED_OUT_DASH},
+       {0,0}
+      };
+
+      int i;
+
+      label += 3;
+      for (i = 0; separator_names[i].name; ++i)
+       if (strcmp (label, separator_names[i].name) == 0)
+         {
+           separator_p = 1;
+           *type = separator_names[i].type;
+
+           /* If separator type is not supported under Motif,
+              use a similar one.  */
+           if (motif_p && *type >= SEPARATOR_SHADOW_DOUBLE_ETCHED_IN)
+             *type -= 4;
+           break;
+         }
+    }
+  else if (strlen (label) > 3
+          && bcmp (label, "--", 2) == 0
+          && label[2] != '-')
+    {
+      /* Alternative, more Emacs-style names.  */
+      static struct separator_table
+      {
+       char *name;
+       enum menu_separator type;
+      }
+      separator_names[] =
+      {
+       {"space",                        SEPARATOR_NO_LINE},
+       {"no-line",                      SEPARATOR_NO_LINE},
+       {"single-line",                  SEPARATOR_SINGLE_LINE},
+       {"double-line",                  SEPARATOR_DOUBLE_LINE},
+       {"single-dashed-line",           SEPARATOR_SINGLE_DASHED_LINE},
+       {"double-dashed-line",           SEPARATOR_DOUBLE_DASHED_LINE},
+       {"shadow-etched-in",             SEPARATOR_SHADOW_ETCHED_IN},
+       {"shadow-etched-out",            SEPARATOR_SHADOW_ETCHED_OUT},
+       {"shadow-etched-in-dash",        SEPARATOR_SHADOW_ETCHED_IN_DASH},
+       {"shadow-etched-out-dash",       SEPARATOR_SHADOW_ETCHED_OUT_DASH},
+       {"shadow-double-etched-in",      SEPARATOR_SHADOW_DOUBLE_ETCHED_IN},
+       {"shadow-double-etched-out",     SEPARATOR_SHADOW_DOUBLE_ETCHED_OUT},
+       {"shadow-double-etched-in-dash", SEPARATOR_SHADOW_DOUBLE_ETCHED_IN_DASH},
+       {"shadow-double-etched-out-dash",SEPARATOR_SHADOW_DOUBLE_ETCHED_OUT_DASH},
+       {0,0}
+      };
+
+      int i;
+
+      label += 2;
+      for (i = 0; separator_names[i].name; ++i)
+       if (strcmp (label, separator_names[i].name) == 0)
+         {
+           separator_p = 1;
+           *type = separator_names[i].type;
+
+           /* If separator type is not supported under Motif,
+              use a similar one.  */
+           if (motif_p && *type >= SEPARATOR_SHADOW_DOUBLE_ETCHED_IN)
+             *type -= 4;
+           break;
+         }
+    }
+  else
+    {
+      /* Old-style separator, maybe.  It's a separator if it contains
+        only dashes.  */
+      while (*label == '-')
+       ++label;
+      separator_p = *label == 0;
+      *type = SEPARATOR_SHADOW_ETCHED_IN;
+    }
+
+  return separator_p;
+}
+
+/* arch-tag: 3d730f36-a441-4a71-9971-48ef3b5a4d9f
+   (do not change this comment) */