/* A general interface to the widgets of different toolkits.
+
Copyright (C) 1992, 1993 Lucid, Inc.
-Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+Copyright (C) 1994-1996, 1999-2011 Free Software Foundation, Inc.
This file is part of the Lucid Widget Library.
#endif
#include <setjmp.h>
-#include "../src/lisp.h"
+#include <lisp.h>
#include <sys/types.h>
#include <stdio.h>
all_widget_info = NULL;
#ifdef USE_MOTIF
-char *lwlib_toolkit_type = "motif";
+const char *lwlib_toolkit_type = "motif";
#else
-char *lwlib_toolkit_type = "lucid";
+const char *lwlib_toolkit_type = "lucid";
#endif
static widget_value *merge_widget_value (widget_value *,
widget_value *,
int, int *);
static void instantiate_widget_instance (widget_instance *);
-static int my_strcasecmp (char *, char *);
+static int my_strcasecmp (const char *, const char *);
static void safe_free_str (char *);
static void free_widget_value_tree (widget_value *);
static widget_value *copy_widget_value_tree (widget_value *,
change_type);
-static widget_info *allocate_widget_info (char *, char *, LWLIB_ID,
+static widget_info *allocate_widget_info (const char *, const char *, LWLIB_ID,
widget_value *,
lw_callback, lw_callback,
lw_callback, lw_callback);
static widget_info *get_widget_info (LWLIB_ID, Boolean);
static widget_instance *get_widget_instance (Widget, Boolean);
static widget_instance *find_instance (LWLIB_ID, Widget, Boolean);
-static Boolean safe_strcmp (char *, char *);
-static Widget name_to_widget (widget_instance *, char *);
+static Boolean safe_strcmp (const char *, const char *);
+static Widget name_to_widget (widget_instance *, const char *);
static void set_one_value (widget_instance *, widget_value *, Boolean);
static void update_one_widget_instance (widget_instance *, Boolean);
static void update_all_widget_values (widget_info *, Boolean);
static void initialize_widget_instance (widget_instance *);
-static widget_creation_function find_in_table (char *, widget_creation_entry *);
-static Boolean dialog_spec_p (char *);
+static widget_creation_function find_in_table (const char *, const widget_creation_entry *);
+static Boolean dialog_spec_p (const char *);
static void destroy_one_instance (widget_instance *);
static void lw_pop_all_widgets (LWLIB_ID, Boolean);
static Boolean get_one_value (widget_instance *, widget_value *);
static void show_one_widget_busy (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 */
char *
-safe_strdup (s)
- const char *s;
+safe_strdup (const char *s)
{
char *result;
if (! s) return 0;
- result = (char *) malloc (strlen (s) + 1);
- if (! result)
- return 0;
+ result = (char *) xmalloc (strlen (s) + 1);
strcpy (result, s);
return result;
}
/* Like strcmp but ignore differences in case. */
static int
-my_strcasecmp (s1, s2)
- char *s1, *s2;
+my_strcasecmp (const char *s1, const char *s2)
{
while (1)
{
}
static void
-safe_free_str (s)
- char *s;
+safe_free_str (char *s)
{
- free (s);
+ xfree (s);
}
static widget_value *widget_value_free_list = 0;
static int malloc_cpt = 0;
widget_value *
-malloc_widget_value ()
+malloc_widget_value (void)
{
widget_value *wv;
if (widget_value_free_list)
}
else
{
- wv = (widget_value *) malloc (sizeof (widget_value));
+ wv = (widget_value *) xmalloc (sizeof (widget_value));
malloc_cpt++;
}
- lwlib_memset ((void*) wv, 0, sizeof (widget_value));
+ memset ((void*) wv, 0, sizeof (widget_value));
return wv;
}
by malloc_widget_value(), and no substructures.
*/
void
-free_widget_value (wv)
- widget_value *wv;
+free_widget_value (widget_value *wv)
{
if (wv->free_list)
abort ();
{
/* When the number of already allocated cells is too big,
We free it. */
- free (wv);
+ xfree (wv);
malloc_cpt--;
}
else
}
static void
-free_widget_value_tree (wv)
- widget_value *wv;
+free_widget_value_tree (widget_value *wv)
{
if (!wv)
return;
- free (wv->name);
- free (wv->value);
- free (wv->key);
+ xfree (wv->name);
+ xfree (wv->value);
+ xfree (wv->key);
wv->name = wv->value = wv->key = (char *) 0xDEADBEEF;
}
static widget_value *
-copy_widget_value_tree (val, change)
- widget_value* val;
- change_type change;
+copy_widget_value_tree (widget_value *val, change_type change)
{
widget_value* copy;
}
static widget_info *
-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;
+allocate_widget_info (const char* type,
+ const 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));
+ widget_info* info = (widget_info*) xmalloc (sizeof (widget_info));
info->type = safe_strdup (type);
info->name = safe_strdup (name);
info->id = id;
}
static void
-free_widget_info (info)
- widget_info* info;
+free_widget_info (widget_info *info)
{
safe_free_str (info->type);
safe_free_str (info->name);
free_widget_value_tree (info->val);
- lwlib_memset ((void*)info, 0xDEADBEEF, sizeof (widget_info));
- free (info);
+ memset ((void*)info, 0xDEADBEEF, sizeof (widget_info));
+ xfree (info);
}
static void
-mark_widget_destroyed (widget, closure, call_data)
- Widget widget;
- XtPointer closure;
- XtPointer call_data;
+mark_widget_destroyed (Widget widget, XtPointer closure, XtPointer call_data)
{
widget_instance* instance = (widget_instance*)closure;
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);
+ (widget_instance*) xmalloc (sizeof (widget_instance));
+ memset (instance, 0, sizeof *instance);
instance->parent = parent;
instance->pop_up_p = pop_up_p;
instance->info = info;
}
static void
-free_widget_instance (instance)
- widget_instance* instance;
+free_widget_instance (widget_instance *instance)
{
- lwlib_memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance));
- free (instance);
+ memset ((void*)instance, 0xDEADBEEF, sizeof (widget_instance));
+ xfree (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;
/* 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;
+lw_get_widget_info (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;
WIDGET, or null if WIDGET is not a lwlib widget. */
widget_instance *
-lw_get_widget_instance (widget)
- Widget widget;
+lw_get_widget_instance (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;
\f
/* utility function for widget_value */
static Boolean
-safe_strcmp (s1, s2)
- char* s1;
- char* s2;
+safe_strcmp (const char *s1, const char *s2)
{
if (!!s1 ^ !!s2) return True;
return (s1 && s2) ? strcmp (s1, s2) : s1 ? False : !!s2;
(nc == STRUCTURAL_CHANGE ? "structural" : "???")))), \
nc, desc, a1, a2)
#else
-# define EXPLAIN(name, oc, nc, desc, a1, a2)
+# define EXPLAIN(name, oc, nc, desc, a1, a2) ((void) 0)
#endif
static widget_value *
-merge_widget_value (val1, val2, level, change_p)
- widget_value* val1;
- widget_value* val2;
- int level;
- int *change_p;
+merge_widget_value (widget_value *val1,
+ widget_value *val2,
+ int level,
+ int *change_p)
{
change_type change, this_one_change;
widget_value* merged_next;
\f
/* modifying the widgets */
static Widget
-name_to_widget (instance, name)
- widget_instance* instance;
- char* name;
+name_to_widget (widget_instance *instance, const char *name)
{
Widget widget = NULL;
widget = XtNameToWidget (instance->widget, real_name);
- free (real_name);
+ xfree (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);
}
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;
}
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;
}
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;
/* creating the widgets */
static void
-initialize_widget_instance (instance)
- widget_instance* instance;
+initialize_widget_instance (widget_instance *instance)
{
widget_value* val;
static widget_creation_function
-find_in_table (type, table)
- char* type;
- widget_creation_entry* table;
+find_in_table (const char *type, const widget_creation_entry *table)
{
- widget_creation_entry* cur;
+ const widget_creation_entry* cur;
for (cur = table; cur->type; cur++)
if (!my_strcasecmp (type, cur->type))
return cur->function;
}
static Boolean
-dialog_spec_p (name)
- char* name;
+dialog_spec_p (const char *name)
{
/* return True if name matches [EILPQeilpq][1-9][Bb] or
[EILPQeilpq][1-9][Bb][Rr][1-9] */
}
static void
-instantiate_widget_instance (instance)
- widget_instance* instance;
+instantiate_widget_instance (widget_instance *instance)
{
widget_creation_function function = NULL;
}
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;
+lw_register_widget (const char* type,
+ const 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,
}
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;
}
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;
}
Widget
-#ifdef PROTOTYPES
-lw_create_widget (char* type, char* name, LWLIB_ID id, widget_value* val,
+lw_create_widget (const char* type, const 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)
-#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, highlight_cb);
\f
/* destroying the widgets */
static void
-destroy_one_instance (instance)
- widget_instance* instance;
+destroy_one_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
xaw_destroy_instance (instance);
else
#endif
- /* do not remove the empty statement */
- ;
+ {
+ /* Empty compound statement to terminate if-then-else chain. */
+ }
}
free_widget_instance (instance);
}
void
-lw_destroy_widget (w)
- Widget w;
+lw_destroy_widget (Widget w)
{
widget_instance* instance = get_widget_instance (w, True);
}
void
-lw_destroy_all_widgets (id)
- LWLIB_ID id;
+lw_destroy_all_widgets (LWLIB_ID id)
{
widget_info* info = get_widget_info (id, True);
widget_instance* instance;
}
void
-lw_destroy_everything ()
+lw_destroy_everything (void)
{
while (all_widget_info)
lw_destroy_all_widgets (all_widget_info->id);
}
void
-lw_destroy_all_pop_ups ()
+lw_destroy_all_pop_ups (void)
{
widget_info* info;
widget_info* next;
}
#ifdef USE_MOTIF
-extern Widget first_child (/* Widget */); /* garbage */
+extern Widget first_child (Widget); /* garbage */
#endif
Widget
-lw_raise_all_pop_up_widgets ()
+lw_raise_all_pop_up_widgets (void)
{
widget_info* info;
widget_instance* instance;
}
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;
}
void
-lw_pop_up_all_widgets (id)
- LWLIB_ID id;
+lw_pop_up_all_widgets (LWLIB_ID id)
{
lw_pop_all_widgets (id, True);
}
void
-lw_pop_down_all_widgets (id)
- LWLIB_ID id;
+lw_pop_down_all_widgets (LWLIB_ID id)
{
lw_pop_all_widgets (id, False);
}
void
-lw_popup_menu (widget, event)
- Widget widget;
- XEvent *event;
+lw_popup_menu (Widget widget, XEvent *event)
{
#if defined (USE_LUCID)
if (lw_lucid_widget_p (widget))
\f/* get the values back */
static Boolean
-get_one_value (instance, val)
- widget_instance* instance;
- widget_value* val;
+get_one_value (widget_instance *instance, widget_value *val)
{
Widget widget = name_to_widget (instance, val->name);
}
Boolean
-lw_get_some_values (id, val_out)
- LWLIB_ID id;
- widget_value* val_out;
+lw_get_some_values (LWLIB_ID id, widget_value *val_out)
{
widget_info* info = get_widget_info (id, False);
widget_instance* instance;
}
widget_value*
-lw_get_all_values (id)
- LWLIB_ID id;
+lw_get_all_values (LWLIB_ID id)
{
widget_info* info = get_widget_info (id, False);
widget_value* val = info->val;
/* 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 (instance, w)
- widget_instance* instance;
- Widget w;
+lw_get_widget_value_for_widget (widget_instance *instance, Widget w)
{
char* name = XtName (w);
widget_value* cur;
/* 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. */
+/* This function can be used as 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, closure, call_data)
- Widget widget;
- XtPointer closure;
- XtPointer call_data;
+lw_internal_update_other_instances (Widget widget,
+ XtPointer closure,
+ XtPointer call_data)
{
widget_instance* instance = (widget_instance*)closure;
char* name = XtName (widget);
\f/* get the id */
LWLIB_ID
-lw_get_widget_id (w)
- Widget w;
+lw_get_widget_id (Widget w)
{
widget_instance* instance = get_widget_instance (w, False);
\f/* set the keyboard focus */
void
-lw_set_keyboard_focus (parent, w)
- Widget parent;
- Widget w;
+lw_set_keyboard_focus (Widget parent, Widget w)
{
#if defined (USE_MOTIF)
xm_set_keyboard_focus (parent, 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;
}
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;
/* 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);
/* 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;
+lw_window_is_in_menubar (Window win, Widget menubar_widget)
{
return menubar_widget
#if defined (USE_LUCID)
/* Motif hack to set the main window areas. */
void
-lw_set_main_areas (parent, menubar, work_area)
- Widget parent;
- Widget menubar;
- Widget work_area;
+lw_set_main_areas (Widget parent, Widget menubar, Widget work_area)
{
#if defined (USE_MOTIF)
xm_set_main_areas (parent, menubar, work_area);
/* 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);
to similar ones that are supported. */
int
-lw_separator_p (label, type, motif_p)
- char *label;
- enum menu_separator *type;
- int motif_p;
+lw_separator_p (const char *label, enum menu_separator *type, int motif_p)
{
int separator_p = 0;
if (strlen (label) >= 3
- && bcmp (label, "--:", 3) == 0)
+ && memcmp (label, "--:", 3) == 0)
{
static struct separator_table
{
- char *name;
+ const char *name;
enum menu_separator type;
}
separator_names[] =
}
}
else if (strlen (label) > 3
- && bcmp (label, "--", 2) == 0
+ && memcmp (label, "--", 2) == 0
&& label[2] != '-')
{
/* Alternative, more Emacs-style names. */
static struct separator_table
{
- char *name;
+ const char *name;
enum menu_separator type;
}
separator_names[] =
return separator_p;
}
-
-/* arch-tag: 3d730f36-a441-4a71-9971-48ef3b5a4d9f
- (do not change this comment) */