1994-01-18 23:47:41 +00:00
|
|
|
|
/* The lwlib interface to "xlwmenu" menus.
|
2011-02-10 05:03:29 +00:00
|
|
|
|
|
|
|
|
|
Copyright (C) 1992 Lucid, Inc.
|
2017-01-01 03:14:01 +00:00
|
|
|
|
Copyright (C) 1994, 2000-2017 Free Software Foundation, Inc.
|
1994-01-18 23:47:41 +00:00
|
|
|
|
|
|
|
|
|
This file is part of the Lucid Widget Library.
|
|
|
|
|
|
2003-02-04 14:56:31 +00:00
|
|
|
|
The Lucid Widget Library is free software; you can redistribute it and/or
|
1994-01-18 23:47:41 +00:00
|
|
|
|
modify it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
The Lucid Widget Library is distributed in the hope that it will be useful,
|
2003-02-04 14:56:31 +00:00
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1994-01-18 23:47:41 +00:00
|
|
|
|
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
|
2017-09-13 22:52:52 +00:00
|
|
|
|
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
|
1994-01-18 23:47:41 +00:00
|
|
|
|
|
Add support for large files, plus some locale improvements.
* dispatch.c, lwlib-Xaw.c, lwlib-Xlw.c, lwlib-Xm.c, lwlib.c, xlwmenu.c,
xrdb-cpp.c, xrdb.c:
Include <config.h> before any system include files.
* lwlib-Xm.c, lwlib.c:
Do not include <stdlib.h> or <string.h>, as <config.h> does this.
1999-10-19 07:21:16 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2009-10-19 04:27:09 +00:00
|
|
|
|
#include <setjmp.h>
|
2011-02-10 05:03:29 +00:00
|
|
|
|
#include <lisp.h>
|
2001-12-02 05:00:27 +00:00
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
#include "lwlib-Xlw.h"
|
|
|
|
|
#include <X11/StringDefs.h>
|
|
|
|
|
#include <X11/IntrinsicP.h>
|
|
|
|
|
#include <X11/ObjectP.h>
|
|
|
|
|
#include <X11/CompositeP.h>
|
|
|
|
|
#include <X11/Shell.h>
|
|
|
|
|
#include "xlwmenu.h"
|
|
|
|
|
|
2001-03-23 11:12:25 +00:00
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
/* Print the complete X resource name of widget WIDGET to stderr.
|
|
|
|
|
This is sometimes handy to have available. */
|
|
|
|
|
|
|
|
|
|
void
|
Change function definition from K&R to prototype. Fix prototype warnings.
* lwlib-Xaw.c (xaw_generic_callback, command_reset)
(xaw_update_one_value): Reformat.
(xaw_update_one_widget): Reformat and remove dead code.
(xaw_scrollbar_scroll, xaw_scrollbar_jump, xaw_create_scrollbar)
(xaw_update_scrollbar): Remove (not used).
(make_dialog): Change from K&R to prototype. Remove dead code.
(xaw_creation_table): Remove scrollbar entry.
* lwlib-Xlw.c (x_print_complete_resource_name): Change from K&R to
prototype.
(xlw_update_one_value): Reformat.
* lwlib-Xm.c (x_print_complete_resource_name)
(make_destroyed_instance, free_destroyed_instance, first_child)
(lw_motif_widget_p, resource_motif_string, destroy_all_children)
(xm_arm_callback, xm_update_label, xm_update_list)
(xm_update_pushbutton, xm_update_cascadebutton)
(xm_update_toggle, xm_update_radiobox, make_menu_in_widget)
(update_one_menu_entry, xm_update_menu, xm_update_text)
(xm_update_text_field, xm_update_one_widget)
(xm_update_one_value, activate_button, dialog_key_cb)
(make_dialog, mark_dead_instance_destroyed)
(find_matching_instance, recenter_widget, recycle_instance)
(xm_create_dialog, make_menubar, remove_grabs, make_popup_menu)
(make_main, xm_destroy_instance, xm_popup_menu)
(set_min_dialog_size, xm_pop_instance, do_call)
(xm_internal_update_other_instances, xm_generic_callback)
(xm_nosel_callback, xm_pull_down_callback, xm_pop_down_callback)
(xm_set_keyboard_focus, xm_set_main_areas, xm_manage_resizing): Change
from K&R to prototype.
* lwlib-int.h (widget_creation_function): Fix prototype.
* lwlib.c (allocate_widget_info, lw_register_widget): Change from K&R
to prototype.
(lw_internal_update_other_instances, merge_widget_value): Reformat.
* xlwmenu.c (size_menu_item): Change from K&R to prototype.
Change label_width and height to int.
(draw_arrow, draw_shadow_rectangle, draw_shadow_rhombus)
(draw_separator, display_menu, fit_to_screen, motion_event_is_in_menu)
(map_event_to_widget_value): Reformat.
(display_menu_item): Change from K&R to prototype.
2010-07-08 10:29:51 +00:00
|
|
|
|
x_print_complete_resource_name (Widget widget)
|
2001-03-23 11:12:25 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
String names[100];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100 && widget != NULL; ++i)
|
|
|
|
|
{
|
|
|
|
|
names[i] = XtName (widget);
|
|
|
|
|
widget = XtParent (widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (--i; i >= 1; --i)
|
|
|
|
|
fprintf (stderr, "%s.", names[i]);
|
|
|
|
|
fprintf (stderr, "%s\n", names[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* 0 */
|
|
|
|
|
|
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
/* Menu callbacks */
|
2000-01-17 09:09:39 +00:00
|
|
|
|
|
|
|
|
|
/* Callback XtNhighlightCallback for Lucid menus. W is the menu
|
|
|
|
|
widget, CLIENT_DATA contains a pointer to the widget_instance
|
|
|
|
|
for the menu, CALL_DATA contains a pointer to the widget_value
|
|
|
|
|
structure for the highlighted menu item. The latter may be null
|
|
|
|
|
if there isn't any highlighted menu item. */
|
|
|
|
|
|
|
|
|
|
static void
|
2010-07-04 05:47:55 +00:00
|
|
|
|
highlight_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
2000-01-17 09:09:39 +00:00
|
|
|
|
{
|
|
|
|
|
widget_instance *instance = (widget_instance *) client_data;
|
|
|
|
|
|
|
|
|
|
if (instance->info->highlight_cb
|
|
|
|
|
&& !w->core.being_destroyed)
|
|
|
|
|
instance->info->highlight_cb (w, instance->info->id, call_data);
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-01 15:20:33 +00:00
|
|
|
|
static void
|
2010-07-04 05:47:55 +00:00
|
|
|
|
enter_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
2007-01-01 15:20:33 +00:00
|
|
|
|
{
|
|
|
|
|
highlight_hook (w, client_data, call_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-07-04 05:47:55 +00:00
|
|
|
|
leave_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
2007-01-01 15:20:33 +00:00
|
|
|
|
{
|
|
|
|
|
highlight_hook (w, client_data, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
static void
|
2010-07-04 05:47:55 +00:00
|
|
|
|
pre_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
widget_instance* instance = (widget_instance*)client_data;
|
|
|
|
|
widget_value* val;
|
|
|
|
|
|
|
|
|
|
if (w->core.being_destroyed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
val = lw_get_widget_value_for_widget (instance, w);
|
|
|
|
|
if (instance->info->pre_activate_cb)
|
|
|
|
|
instance->info->pre_activate_cb (w, instance->info->id,
|
|
|
|
|
val ? val->call_data : NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-07-04 05:47:55 +00:00
|
|
|
|
pick_hook (Widget w, XtPointer client_data, XtPointer call_data)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
widget_instance* instance = (widget_instance*)client_data;
|
|
|
|
|
widget_value* contents_val = (widget_value*)call_data;
|
|
|
|
|
widget_value* widget_val;
|
|
|
|
|
XtPointer widget_arg;
|
|
|
|
|
|
|
|
|
|
if (w->core.being_destroyed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (instance->info->selection_cb && contents_val && contents_val->enabled
|
|
|
|
|
&& !contents_val->contents)
|
|
|
|
|
instance->info->selection_cb (w, instance->info->id,
|
|
|
|
|
contents_val->call_data);
|
|
|
|
|
|
|
|
|
|
widget_val = lw_get_widget_value_for_widget (instance, w);
|
|
|
|
|
widget_arg = widget_val ? widget_val->call_data : NULL;
|
|
|
|
|
if (instance->info->post_activate_cb)
|
|
|
|
|
instance->info->post_activate_cb (w, instance->info->id, widget_arg);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* creation functions */
|
1994-02-18 13:24:41 +00:00
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
static Widget
|
2010-07-04 05:47:55 +00:00
|
|
|
|
xlw_create_menubar (widget_instance *instance)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
1994-02-15 13:54:14 +00:00
|
|
|
|
Widget widget;
|
1994-09-16 18:39:54 +00:00
|
|
|
|
Arg al[5];
|
1994-02-23 08:39:25 +00:00
|
|
|
|
int ac = 0;
|
1994-02-15 13:54:14 +00:00
|
|
|
|
|
1994-02-23 08:39:25 +00:00
|
|
|
|
XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
|
1994-09-16 18:39:54 +00:00
|
|
|
|
#ifdef emacs
|
|
|
|
|
XtSetArg (al[ac], XtNshowGrip, 0); ac++;
|
|
|
|
|
XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
|
|
|
|
|
XtSetArg (al[ac], XtNallowResize, 1); ac++;
|
|
|
|
|
#endif
|
1994-02-15 13:54:14 +00:00
|
|
|
|
|
1994-02-23 08:39:25 +00:00
|
|
|
|
/* This used to use XtVaCreateWidget, but an old Xt version
|
|
|
|
|
has a bug in XtVaCreateWidget that frees instance->info->name. */
|
1994-02-19 20:53:26 +00:00
|
|
|
|
widget
|
1994-02-23 08:39:25 +00:00
|
|
|
|
= XtCreateWidget (instance->info->name, xlwMenuWidgetClass,
|
|
|
|
|
instance->parent, al, ac);
|
1994-02-15 13:59:18 +00:00
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
|
|
|
|
|
XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
|
2007-01-01 15:20:33 +00:00
|
|
|
|
XtAddCallback (widget, XtNleaveCallback, leave_hook, (XtPointer)instance);
|
|
|
|
|
XtAddCallback (widget, XtNenterCallback, enter_hook, (XtPointer)instance);
|
1994-01-18 23:47:41 +00:00
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Widget
|
2010-07-04 05:47:55 +00:00
|
|
|
|
xlw_create_popup_menu (widget_instance *instance)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
1994-02-19 20:53:26 +00:00
|
|
|
|
Widget popup_shell
|
|
|
|
|
= XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
|
|
|
|
|
instance->parent, NULL, 0);
|
2003-02-04 14:56:31 +00:00
|
|
|
|
|
1994-02-15 13:59:18 +00:00
|
|
|
|
Widget widget;
|
1994-02-23 08:39:25 +00:00
|
|
|
|
Arg al[2];
|
|
|
|
|
int ac = 0;
|
1994-02-15 13:59:18 +00:00
|
|
|
|
|
1994-02-23 08:39:25 +00:00
|
|
|
|
XtSetArg (al[ac], XtNmenu, instance->info->val); ac++;
|
|
|
|
|
XtSetArg (al[ac], XtNhorizontal, False); ac++;
|
1994-02-15 13:59:18 +00:00
|
|
|
|
|
1994-02-23 08:39:25 +00:00
|
|
|
|
/* This used to use XtVaManagedCreateWidget, but an old Xt version
|
|
|
|
|
has a bug in XtVaManagedCreateWidget that frees instance->info->name. */
|
1994-02-19 20:53:26 +00:00
|
|
|
|
widget
|
1994-02-23 08:39:25 +00:00
|
|
|
|
= XtCreateManagedWidget ("popup", xlwMenuWidgetClass,
|
|
|
|
|
popup_shell, al, ac);
|
1994-02-15 13:59:18 +00:00
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
|
2007-01-01 15:20:33 +00:00
|
|
|
|
XtAddCallback (widget, XtNleaveCallback, leave_hook, (XtPointer)instance);
|
|
|
|
|
XtAddCallback (widget, XtNenterCallback, enter_hook, (XtPointer)instance);
|
2004-01-12 01:45:22 +00:00
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
return popup_shell;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-04 14:56:31 +00:00
|
|
|
|
widget_creation_entry
|
1994-01-18 23:47:41 +00:00
|
|
|
|
xlw_creation_table [] =
|
|
|
|
|
{
|
|
|
|
|
{"menubar", xlw_create_menubar},
|
|
|
|
|
{"popup", xlw_create_popup_menu},
|
|
|
|
|
{NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Boolean
|
2010-07-04 05:47:55 +00:00
|
|
|
|
lw_lucid_widget_p (Widget widget)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
WidgetClass the_class = XtClass (widget);
|
1994-02-19 20:53:26 +00:00
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
if (the_class == xlwMenuWidgetClass)
|
|
|
|
|
return True;
|
|
|
|
|
if (the_class == overrideShellWidgetClass)
|
1994-02-19 20:53:26 +00:00
|
|
|
|
return (XtClass (((CompositeWidget)widget)->composite.children [0])
|
|
|
|
|
== xlwMenuWidgetClass);
|
1994-01-18 23:47:41 +00:00
|
|
|
|
return False;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2003-05-22 13:30:20 +00:00
|
|
|
|
xlw_update_one_widget (widget_instance* instance, Widget widget,
|
|
|
|
|
widget_value* val, Boolean deep_p)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
1994-02-23 08:39:25 +00:00
|
|
|
|
Arg al[1];
|
1994-01-18 23:47:41 +00:00
|
|
|
|
|
1994-02-23 08:39:25 +00:00
|
|
|
|
/* This used to use XtVaSetValues, but some old Xt versions
|
|
|
|
|
that have a bug in XtVaCreateWidget might have it here too. */
|
|
|
|
|
XtSetArg (al[0], XtNmenu, instance->info->val);
|
|
|
|
|
|
|
|
|
|
XtSetValues (widget, al, 1);
|
1994-01-18 23:47:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
Change function definition from K&R to prototype. Fix prototype warnings.
* lwlib-Xaw.c (xaw_generic_callback, command_reset)
(xaw_update_one_value): Reformat.
(xaw_update_one_widget): Reformat and remove dead code.
(xaw_scrollbar_scroll, xaw_scrollbar_jump, xaw_create_scrollbar)
(xaw_update_scrollbar): Remove (not used).
(make_dialog): Change from K&R to prototype. Remove dead code.
(xaw_creation_table): Remove scrollbar entry.
* lwlib-Xlw.c (x_print_complete_resource_name): Change from K&R to
prototype.
(xlw_update_one_value): Reformat.
* lwlib-Xm.c (x_print_complete_resource_name)
(make_destroyed_instance, free_destroyed_instance, first_child)
(lw_motif_widget_p, resource_motif_string, destroy_all_children)
(xm_arm_callback, xm_update_label, xm_update_list)
(xm_update_pushbutton, xm_update_cascadebutton)
(xm_update_toggle, xm_update_radiobox, make_menu_in_widget)
(update_one_menu_entry, xm_update_menu, xm_update_text)
(xm_update_text_field, xm_update_one_widget)
(xm_update_one_value, activate_button, dialog_key_cb)
(make_dialog, mark_dead_instance_destroyed)
(find_matching_instance, recenter_widget, recycle_instance)
(xm_create_dialog, make_menubar, remove_grabs, make_popup_menu)
(make_main, xm_destroy_instance, xm_popup_menu)
(set_min_dialog_size, xm_pop_instance, do_call)
(xm_internal_update_other_instances, xm_generic_callback)
(xm_nosel_callback, xm_pull_down_callback, xm_pop_down_callback)
(xm_set_keyboard_focus, xm_set_main_areas, xm_manage_resizing): Change
from K&R to prototype.
* lwlib-int.h (widget_creation_function): Fix prototype.
* lwlib.c (allocate_widget_info, lw_register_widget): Change from K&R
to prototype.
(lw_internal_update_other_instances, merge_widget_value): Reformat.
* xlwmenu.c (size_menu_item): Change from K&R to prototype.
Change label_width and height to int.
(draw_arrow, draw_shadow_rectangle, draw_shadow_rhombus)
(draw_separator, display_menu, fit_to_screen, motion_event_is_in_menu)
(map_event_to_widget_value): Reformat.
(display_menu_item): Change from K&R to prototype.
2010-07-08 10:29:51 +00:00
|
|
|
|
xlw_update_one_value (widget_instance *instance,
|
|
|
|
|
Widget widget,
|
|
|
|
|
widget_value *val)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2003-05-22 13:30:20 +00:00
|
|
|
|
xlw_pop_instance (widget_instance* instance, Boolean up)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2010-07-04 05:47:55 +00:00
|
|
|
|
xlw_popup_menu (Widget widget, XEvent *event)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
XlwMenuWidget mw;
|
|
|
|
|
|
|
|
|
|
if (!XtIsShell (widget))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
|
|
|
|
|
|
1995-08-02 07:13:45 +00:00
|
|
|
|
if (event)
|
2004-01-12 01:45:22 +00:00
|
|
|
|
XtCallActionProc ((Widget) mw, "start", event, NULL, 0);
|
1995-08-02 07:13:45 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2004-01-12 01:45:22 +00:00
|
|
|
|
XEvent dummy;
|
|
|
|
|
XButtonPressedEvent *bd = &dummy.xbutton;
|
|
|
|
|
|
|
|
|
|
bd->type = ButtonPress;
|
|
|
|
|
bd->serial = 0;
|
|
|
|
|
bd->send_event = 0;
|
|
|
|
|
bd->display = XtDisplay (widget);
|
|
|
|
|
bd->window = XtWindow (XtParent (widget));
|
|
|
|
|
bd->time = CurrentTime;
|
|
|
|
|
bd->button = 0;
|
|
|
|
|
XQueryPointer (bd->display, bd->window, &bd->root,
|
|
|
|
|
&bd->subwindow, &bd->x_root, &bd->y_root,
|
|
|
|
|
&bd->x, &bd->y, &bd->state);
|
|
|
|
|
|
|
|
|
|
XtCallActionProc ((Widget) mw, "start", &dummy, NULL, 0);
|
1995-08-02 07:13:45 +00:00
|
|
|
|
}
|
1994-01-18 23:47:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Destruction of instances */
|
|
|
|
|
void
|
2010-07-04 05:47:55 +00:00
|
|
|
|
xlw_destroy_instance (widget_instance *instance)
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (instance->widget)
|
|
|
|
|
XtDestroyWidget (instance->widget);
|
|
|
|
|
}
|