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 */
#include "lwlib-utils.h"
#include <X11/StringDefs.h>
-#if defined(__GNUC__) && !defined(alloca)
-#define alloca __builtin_alloca
-#endif
-
-#if ((!__GNUC__) && !defined(__hpux)) && !defined(_AIX)
-#include <alloca.h>
-#endif
-
-#if defined(_AIX)
-#pragma alloca
+#ifdef __osf__
+#include <string.h>
+#include <stdlib.h>
+extern long *xmalloc();
#endif
#if defined (USE_LUCID)
ERROR! no more than one of USE_MOTIF and USE_OLIT may be defined.
#endif
+#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;
+#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;
+ int value;
+ int length;
+{
+ int i;
+
+ for (i = 0; i < length; i++)
+ address[i] = value;
+}
+
+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 */
char *
safe_strdup (s)
wv = (widget_value *) malloc (sizeof (widget_value));
malloc_cpt++;
}
- memset (wv, 0, sizeof (widget_value));
+ lwlib_memset (wv, 0, sizeof (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
if (wv->toolkit_data && wv->free_toolkit_data)
{
- free (wv->toolkit_data);
+ XtFree (wv->toolkit_data);
wv->toolkit_data = (void *) 0xDEADBEEF;
}
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);
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);
}
instance->next = info->instances;
info->instances = instance;
- instanciate_widget_instance (instance);
+ instantiate_widget_instance (instance);
XtAddCallback (instance->widget, XtNdestroyCallback,
mark_widget_destroyed, (XtPointer)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);
}
return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2;
}
-static int
-max (i1, i2)
- int i1;
- int i2;
-{
- return i1 > i2 ? i1 : i2;
-}
-
#if 0
# define EXPLAIN(name, oc, nc, desc, a1, a2) \
widget_value* val2;
int level;
{
- change_type change;
+ change_type change, this_one_change;
widget_value* merged_next;
widget_value* merged_contents;
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)
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;
}
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
-instanciate_widget_instance (instance)
+instantiate_widget_instance (instance)
widget_instance* instance;
{
widget_creation_function function = NULL;
}
#ifdef USE_MOTIF
-extern Widget first_child (Widget); /* garbage */
+extern Widget first_child (/* Widget */); /* garbage */
#endif
Widget
}
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
}
}
\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. */
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 */
if (!info->instances->next)
return;
- updating = True;
+ lwlib_updating = True;
for (val = info->val; val && strcmp (val->name, name); val = val->next);
if (cur != instance)
set_one_value (cur, val, True);
- updating = False;
+ lwlib_updating = False;
}
}
}
}
+
+/* This hack exists because Lucid/Athena need to execute the strange
+ function below to support geometry management. */
+void
+lw_refigure_widget (w, doit)
+ Widget w;
+ Boolean doit;
+{
+#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
+lw_allow_resizing (w, flag)
+ Widget w;
+ Boolean flag;
+{
+#if defined (USE_MOTIF)
+ xm_manage_resizing (w, flag);
+#endif
+}