(code_convert_string): Maybe use make_unibyte_string.
[bpt/emacs.git] / lwlib / lwlib.c
index e18f95b..981c92e 100644 (file)
@@ -15,7 +15,8 @@ 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., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 #ifdef NeXT
 #undef __STRICT_BSD__ /* ick */
@@ -28,6 +29,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "lwlib-utils.h"
 #include <X11/StringDefs.h>
 
+#ifdef __osf__
+#include <string.h>
+#include <stdlib.h>
+extern long *xmalloc();
+#endif
+
 #if defined (USE_LUCID)
 #include "lwlib-Xlw.h"
 #endif
@@ -61,9 +68,14 @@ ERROR! no more than one of USE_MOTIF and USE_OLIT may be defined.
 static widget_info*
 all_widget_info = NULL;
 
+#ifdef USE_MOTIF
+char *lwlib_toolkit_type = "motif";
+#else
+char *lwlib_toolkit_type = "lucid";
+#endif
 \f/* Forward declarations */
 static void
-instanciate_widget_instance (/* widget_instance* instance */);
+instantiate_widget_instance (/* widget_instance* instance */);
 
 lwlib_memset (address, value, length)
      char *address;
@@ -150,7 +162,7 @@ malloc_widget_value ()
   return wv;
 }
 
-/* this is analagous to free().  It frees only what was allocated
+/* this is analogous to free().  It frees only what was allocated
    by malloc_widget_value(), and no substructures. 
  */
 void
@@ -189,7 +201,7 @@ free_widget_value_tree (wv)
 
   if (wv->toolkit_data && wv->free_toolkit_data)
     {
-      free (wv->toolkit_data);
+      XtFree (wv->toolkit_data);
       wv->toolkit_data = (void *) 0xDEADBEEF;
     }
 
@@ -226,6 +238,7 @@ copy_widget_value_tree (val, change)
   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);
@@ -299,7 +312,7 @@ allocate_widget_instance (info, parent, pop_up_p)
   instance->next = info->instances;
   info->instances = instance;
 
-  instanciate_widget_instance (instance);
+  instantiate_widget_instance (instance);
 
   XtAddCallback (instance->widget, XtNdestroyCallback,
                 mark_widget_destroyed, (XtPointer)instance);
@@ -427,7 +440,7 @@ merge_widget_value (val1, val2, level)
      widget_value* val2;
      int level;
 {
-  change_type change;
+  change_type change, this_one_change;
   widget_value* merged_next;
   widget_value* merged_contents;
 
@@ -499,20 +512,32 @@ merge_widget_value (val1, val2, level)
       
       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;
     }
 
+  this_one_change = change;
+
   merged_next = merge_widget_value (val1->next, val2->next, level);
 
   if (val1->next && !merged_next)
@@ -531,12 +556,13 @@ merge_widget_value (val1, val2, level)
 
   val1->next = merged_next;
 
+  val1->this_one_change = this_one_change;
   val1->change = change;
   
   if (change > NO_CHANGE && val1->toolkit_data)
     {
       if (val1->free_toolkit_data)
-       free (val1->toolkit_data);
+       XtFree (val1->toolkit_data);
       val1->toolkit_data = NULL;
     }
 
@@ -748,7 +774,7 @@ dialog_spec_p (name)
 }
 
 static void
-instanciate_widget_instance (instance)
+instantiate_widget_instance (instance)
      widget_instance* instance;
 {
   widget_creation_function function = NULL;
@@ -984,7 +1010,7 @@ lw_destroy_all_pop_ups ()
 }
 
 #ifdef USE_MOTIF
-extern Widget first_child (Widget);    /* garbage */
+extern Widget first_child (/* Widget */);      /* garbage */
 #endif
 
 Widget
@@ -1079,24 +1105,25 @@ lw_pop_down_all_widgets (id)
 }
 
 void
-lw_popup_menu (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);
+    xol_popup_menu (widget, event);
 #endif
 #if defined (USE_XAW)
   if (lw_xaw_widget_p (widget))
-    xaw_popup_menu (widget);
+    xaw_popup_menu (widget, event);
 #endif
 }
 
@@ -1184,6 +1211,10 @@ lw_get_widget_value_for_widget (instance, w)
 }
 
 \f/* update other instances value when one thing changed */
+
+/* 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. */
@@ -1193,17 +1224,14 @@ lw_internal_update_other_instances (widget, closure, call_data)
      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 */
@@ -1215,7 +1243,7 @@ lw_internal_update_other_instances (widget, closure, call_data)
   if (!info->instances->next)
     return;
 
-  updating = True;
+  lwlib_updating = True;
 
   for (val = info->val; val && strcmp (val->name, name); val = val->next);
 
@@ -1224,7 +1252,7 @@ lw_internal_update_other_instances (widget, closure, call_data)
       if (cur != instance)
        set_one_value (cur, val, True);
 
-  updating = False;
+  lwlib_updating = False;
 }
 
 
@@ -1308,9 +1336,9 @@ lw_refigure_widget (w, doit)
 #endif
 #if defined (USE_MOTIF)
   if (doit)
-    XtUnmanageChild (w);
-  else
     XtManageChild (w);
+  else
+    XtUnmanageChild (w);
 #endif
 }
 
@@ -1326,9 +1354,10 @@ lw_window_is_in_menubar (win, menubar_widget)
       && XtWindow (menubar_widget) == win;
 #endif
 #if defined (USE_MOTIF)
-      && XtWindowToWidget (XtDisplay (menubar_widget), win)
-      && (XtParent (XtWindowToWidget (XtDisplay (menubar_widget), win))
-         == menubar_widget);
+      && ((XtWindow (menubar_widget) == win)
+         || (XtWindowToWidget (XtDisplay (menubar_widget), win)
+             && (XtParent (XtWindowToWidget (XtDisplay (menubar_widget), win))
+                 == menubar_widget)));
 #endif
 }