1994-01-18 23:47:41 +00:00
|
|
|
|
/* The lwlib interface to "xlwmenu" menus.
|
|
|
|
|
Copyright (C) 1992 Lucid, Inc.
|
2005-08-07 10:56:27 +00:00
|
|
|
|
Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004,
|
2006-02-05 23:44:47 +00:00
|
|
|
|
2005, 2006 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
|
|
|
|
|
along with GNU Emacs; see the file COPYING. If not, write to
|
2005-07-04 15:47:28 +00:00
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02110-1301, USA. */
|
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
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-05-22 13:30:20 +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
|
|
|
|
|
x_print_complete_resource_name (widget)
|
|
|
|
|
Widget widget;
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
highlight_hook (w, client_data, call_data)
|
|
|
|
|
Widget w;
|
|
|
|
|
XtPointer client_data;
|
|
|
|
|
XtPointer call_data;
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
1994-01-18 23:47:41 +00:00
|
|
|
|
static void
|
1994-01-31 05:35:36 +00:00
|
|
|
|
pre_hook (w, client_data, call_data)
|
|
|
|
|
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
|
1994-01-31 05:35:36 +00:00
|
|
|
|
pick_hook (w, client_data, call_data)
|
|
|
|
|
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
|
1994-01-31 05:35:36 +00:00
|
|
|
|
xlw_create_menubar (instance)
|
|
|
|
|
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);
|
2000-01-17 09:09:39 +00:00
|
|
|
|
XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
|
|
|
|
|
(XtPointer)instance);
|
1994-01-18 23:47:41 +00:00
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Widget
|
1994-01-31 05:35:36 +00:00
|
|
|
|
xlw_create_popup_menu (instance)
|
|
|
|
|
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);
|
2000-01-17 09:09:39 +00:00
|
|
|
|
XtAddCallback (widget, XtNhighlightCallback, highlight_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
|
1994-01-31 05:35:36 +00:00
|
|
|
|
lw_lucid_widget_p (widget)
|
|
|
|
|
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
|
|
|
|
#ifdef PROTOTYPES
|
|
|
|
|
xlw_update_one_widget (widget_instance* instance, Widget widget,
|
|
|
|
|
widget_value* val, Boolean deep_p)
|
|
|
|
|
#else
|
1994-01-31 05:35:36 +00:00
|
|
|
|
xlw_update_one_widget (instance, widget, val, deep_p)
|
|
|
|
|
widget_instance* instance;
|
|
|
|
|
Widget widget;
|
|
|
|
|
widget_value* val;
|
|
|
|
|
Boolean deep_p;
|
2003-05-22 13:30:20 +00:00
|
|
|
|
#endif
|
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
|
1994-01-31 05:35:36 +00:00
|
|
|
|
xlw_update_one_value (instance, widget, val)
|
|
|
|
|
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
|
|
|
|
#ifdef PROTOTYPES
|
|
|
|
|
xlw_pop_instance (widget_instance* instance, Boolean up)
|
|
|
|
|
#else
|
1994-01-31 05:35:36 +00:00
|
|
|
|
xlw_pop_instance (instance, up)
|
|
|
|
|
widget_instance* instance;
|
|
|
|
|
Boolean up;
|
2003-05-22 13:30:20 +00:00
|
|
|
|
#endif
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1995-08-02 07:13:45 +00:00
|
|
|
|
xlw_popup_menu (widget, event)
|
1994-01-31 05:35:36 +00:00
|
|
|
|
Widget widget;
|
1995-08-02 07:13:45 +00:00
|
|
|
|
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
|
1994-01-31 05:35:36 +00:00
|
|
|
|
xlw_destroy_instance (instance)
|
|
|
|
|
widget_instance* instance;
|
1994-01-18 23:47:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (instance->widget)
|
|
|
|
|
XtDestroyWidget (instance->widget);
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 15:45:59 +00:00
|
|
|
|
/* arch-tag: 541e3912-477d-406e-9bf2-dbf2b7ff8c3b
|
|
|
|
|
(do not change this comment) */
|