Commit 07bf635f authored by Richard M. Stallman's avatar Richard M. Stallman

Initial revision

parent 87cd38d6
This diff is collapsed.
/* Defines a function to find the Widget that XtDispatchEvent() would use.
Copyright (C) 1992 Lucid, Inc.
This file is part of the Lucid Widget Library.
The Lucid Widget Library is free software; you can redistribute it and/or
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,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/*
* The function XtWidgetToDispatchTo(), given an XEvent, returns the
* widget that XtDispatchEvent() would send that event to if called now.
* This file copies much code from the X11r4 Xt source, and is thus a
* portability problem. It also requires data structures defined in
* IntrinsicI.h, which is a non-exported Xt header file, so you can't
* compile this file unless you have the Xt sources online.
*/
#include <IntrinsicI.h> /* Don't change this: see comments in Imakefile. */
#include <X11/Xatom.h>
#include "dispatch.h"
#ifdef THIS_IS_X11R4
#ifdef THIS_IS_X11R5
ERROR!! only one of THIS_IS_X11R4 or THIS_IS_X11R5 must be defined.
#endif
#else /* ! THIS_IS_X11R4 */
#ifndef THIS_IS_X11R5
ERROR!! one of THIS_IS_X11R4 or THIS_IS_X11R5 must be defined.
#endif
#endif /* ! THIS_IS_X11R4 */
/* ## All of the code on this page was copied from the X11R5 lib/Xt/Event.c,
## but is compatible with X11R4; the code in Event.c is different, but
## functionally equivalent for our purposes.
*/
#if __STDC__
#define Const const
#else
#define Const /**/
#endif
#define NonMaskableMask ((EventMask)0x80000000L)
#define COMP_EXPOSE (widget->core.widget_class->core_class.compress_exposure)
#define COMP_EXPOSE_TYPE (COMP_EXPOSE & 0x0f)
#define GRAPHICS_EXPOSE ((XtExposeGraphicsExpose & COMP_EXPOSE) || \
(XtExposeGraphicsExposeMerged & COMP_EXPOSE))
#define NO_EXPOSE (XtExposeNoExpose & COMP_EXPOSE)
/* -- lots of stuff we don't need to copy, omitted -- */
static EventMask Const masks[] = {
0, /* Error, should never see */
0, /* Reply, should never see */
KeyPressMask, /* KeyPress */
KeyReleaseMask, /* KeyRelease */
ButtonPressMask, /* ButtonPress */
ButtonReleaseMask, /* ButtonRelease */
PointerMotionMask /* MotionNotify */
| ButtonMotionMask,
EnterWindowMask, /* EnterNotify */
LeaveWindowMask, /* LeaveNotify */
FocusChangeMask, /* FocusIn */
FocusChangeMask, /* FocusOut */
KeymapStateMask, /* KeymapNotify */
ExposureMask, /* Expose */
NonMaskableMask, /* GraphicsExpose, in GC */
NonMaskableMask, /* NoExpose, in GC */
VisibilityChangeMask, /* VisibilityNotify */
SubstructureNotifyMask, /* CreateNotify */
StructureNotifyMask /* DestroyNotify */
| SubstructureNotifyMask,
StructureNotifyMask /* UnmapNotify */
| SubstructureNotifyMask,
StructureNotifyMask /* MapNotify */
| SubstructureNotifyMask,
SubstructureRedirectMask, /* MapRequest */
StructureNotifyMask /* ReparentNotify */
| SubstructureNotifyMask,
StructureNotifyMask /* ConfigureNotify */
| SubstructureNotifyMask,
SubstructureRedirectMask, /* ConfigureRequest */
StructureNotifyMask /* GravityNotify */
| SubstructureNotifyMask,
ResizeRedirectMask, /* ResizeRequest */
StructureNotifyMask /* CirculateNotify */
| SubstructureNotifyMask,
SubstructureRedirectMask, /* CirculateRequest */
PropertyChangeMask, /* PropertyNotify */
NonMaskableMask, /* SelectionClear */
NonMaskableMask, /* SelectionRequest */
NonMaskableMask, /* SelectionNotify */
ColormapChangeMask, /* ColormapNotify */
NonMaskableMask, /* ClientMessage */
NonMaskableMask /* MappingNotify */
};
#ifdef THIS_IS_X11R4
static /* in R5, this is not static, so we don't need to define it at all */
EventMask _XtConvertTypeToMask (eventType)
int eventType;
{
eventType &= 0x7f; /* Events sent with XSendEvent have high bit set. */
if (eventType < XtNumber(masks))
return masks[eventType];
else
return 0;
}
#endif /* R4 */
/* -- _XtOnGrabList() omitted -- */
static Widget LookupSpringLoaded(grabList)
XtGrabList grabList;
{
XtGrabList gl;
for (gl = grabList; gl != NULL; gl = gl->next) {
if (gl->spring_loaded)
if (XtIsSensitive(gl->widget))
return gl->widget;
else
return NULL;
if (gl->exclusive) break;
}
return NULL;
}
/* This function is new. */
static Boolean WouldDispatchEvent(event, widget, mask, pd)
register XEvent *event;
Widget widget;
EventMask mask;
XtPerDisplay pd;
{
XtEventRec *p;
Boolean would_dispatched = False;
if ((mask == ExposureMask) ||
((event->type == NoExpose) && NO_EXPOSE) ||
((event->type == GraphicsExpose) && GRAPHICS_EXPOSE) )
if (widget->core.widget_class->core_class.expose != NULL )
return True;
if ((mask == VisibilityChangeMask) &&
XtClass(widget)->core_class.visible_interest)
return True;
for (p=widget->core.event_table; p != NULL; p = p->next)
if ((mask & p->mask) != 0
#ifdef THIS_IS_X11R4
|| (mask == 0 && p->non_filter)
#endif
)
return True;
return False;
}
/* #### This function is mostly copied from DecideToDispatch().
*/
typedef enum _GrabType {pass, ignore, remap} GrabType;
Widget
XtWidgetToDispatchTo (XEvent* event)
{
register Widget widget;
EventMask mask;
GrabType grabType;
Widget dspWidget;
Time time = 0;
XtPerDisplay pd;
XtPerDisplayInput pdi;
XtGrabList grabList;
widget = XtWindowToWidget (event->xany.display, event->xany.window);
pd = _XtGetPerDisplay(event->xany.display);
pdi = _XtGetPerDisplayInput(event->xany.display);
grabList = *_XtGetGrabList(pdi);
mask = _XtConvertTypeToMask(event->xany.type);
grabType = pass;
switch (event->xany.type & 0x7f) {
case KeyPress:
case KeyRelease: grabType = remap; break;
case ButtonPress:
case ButtonRelease: grabType = remap; break;
case MotionNotify: grabType = ignore;
#define XKnownButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
Button4MotionMask|Button5MotionMask)
mask |= (event->xmotion.state & XKnownButtons);
#undef XKnownButtons
break;
case EnterNotify: grabType = ignore; break;
}
if (widget == NULL) {
if (grabType != remap) return False;
/* event occurred in a non-widget window, but we've promised also
to dispatch it to the nearest accessible spring_loaded widget */
else if ((widget = LookupSpringLoaded(grabList)) != NULL)
return widget;
return False;
}
switch(grabType) {
case pass:
return widget;
case ignore:
if ((grabList == NULL || _XtOnGrabList(widget,grabList))
&& XtIsSensitive(widget)) {
return widget;
}
return NULL;
case remap:
{
Widget was_dispatched_to= NULL;
extern Widget _XtFindRemapWidget();
extern void _XtUngrabBadGrabs();
dspWidget = _XtFindRemapWidget(event, widget, mask, pdi);
if ((grabList == NULL ||
_XtOnGrabList(dspWidget, grabList)) &&
XtIsSensitive(dspWidget)) {
if (WouldDispatchEvent (event, dspWidget, mask, pd))
was_dispatched_to = dspWidget;
}
/* Also dispatch to nearest accessible spring_loaded. */
/* Fetch this afterward to reflect modal list changes */
grabList = *_XtGetGrabList(pdi);
widget = LookupSpringLoaded(grabList);
if (widget != NULL && widget != dspWidget) {
if (!was_dispatched_to)
was_dispatched_to = widget;
}
return was_dispatched_to;
}
}
/* should never reach here */
return NULL;
}
/* The lwlib interface to "xlwmenu" menus.
Copyright (C) 1992 Lucid, Inc.
This file is part of the Lucid Widget Library.
The Lucid Widget Library is free software; you can redistribute it and/or
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,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#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"
/* Menu callbacks */
static void
pre_hook (Widget w, XtPointer client_data, XtPointer call_data)
{
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
pick_hook (Widget w, XtPointer client_data, XtPointer call_data)
{
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 */
static Widget
xlw_create_menubar (widget_instance* instance)
{
Widget widget =
XtVaCreateWidget (instance->info->name, xlwMenuWidgetClass,
instance->parent,
XtNmenu, instance->info->val,
0);
XtAddCallback (widget, XtNopen, pre_hook, (XtPointer)instance);
XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
return widget;
}
static Widget
xlw_create_popup_menu (widget_instance* instance)
{
Widget popup_shell =
XtCreatePopupShell (instance->info->name, overrideShellWidgetClass,
instance->parent, NULL, 0);
Widget widget =
XtVaCreateManagedWidget ("popup", xlwMenuWidgetClass,
popup_shell,
XtNmenu, instance->info->val,
XtNhorizontal, False,
0);
XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
return popup_shell;
}
widget_creation_entry
xlw_creation_table [] =
{
{"menubar", xlw_create_menubar},
{"popup", xlw_create_popup_menu},
{NULL, NULL}
};
Boolean
lw_lucid_widget_p (Widget widget)
{
WidgetClass the_class = XtClass (widget);
if (the_class == xlwMenuWidgetClass)
return True;
if (the_class == overrideShellWidgetClass)
return
XtClass (((CompositeWidget)widget)->composite.children [0])
== xlwMenuWidgetClass;
return False;
}
void
xlw_update_one_widget (widget_instance* instance, Widget widget,
widget_value* val, Boolean deep_p)
{
XlwMenuWidget mw;
if (XtIsShell (widget))
mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
else
mw = (XlwMenuWidget)widget;
XtVaSetValues (widget, XtNmenu, val, 0);
}
void
xlw_update_one_value (widget_instance* instance, Widget widget,
widget_value* val)
{
return;
}
void
xlw_pop_instance (widget_instance* instance, Boolean up)
{
}
void
xlw_popup_menu (Widget widget)
{
XButtonPressedEvent dummy;
XlwMenuWidget mw;
if (!XtIsShell (widget))
return;
mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
dummy.type = ButtonPress;
dummy.serial = 0;
dummy.send_event = 0;
dummy.display = XtDisplay (widget);
dummy.window = XtWindow (XtParent (widget));
dummy.time = CurrentTime;
dummy.button = 0;
XQueryPointer (dummy.display, dummy.window, &dummy.root,
&dummy.subwindow, &dummy.x_root, &dummy.y_root,
&dummy.x, &dummy.y, &dummy.state);
pop_up_menu (mw, &dummy);
}
/* Destruction of instances */
void
xlw_destroy_instance (widget_instance* instance)
{
if (instance->widget)
XtDestroyWidget (instance->widget);
}
#ifndef LWLIB_XLW_H
#define LWLIB_XLW_H
#include "lwlib-internal.h"
extern widget_creation_entry xlw_creation_table [];
extern widget_creation_function xlw_create_dialog;
Boolean
lw_lucid_widget_p (Widget widget);
void
xlw_update_one_widget (widget_instance* instance, Widget widget,
widget_value* val, Boolean deep_p);
void
xlw_update_one_value (widget_instance* instance, Widget widget,
widget_value* val);
void
xlw_destroy_instance (widget_instance* instance);
void
xlw_pop_instance (widget_instance* instance, Boolean up);
void
xlw_popup_menu (Widget widget);
#endif /* LWLIB_XLW_H */
This diff is collapsed.
#ifndef LWLIB_XM_H
#define LWLIB_XM_H
#include "lwlib-internal.h"
extern widget_creation_entry xm_creation_table [];
Widget
xm_create_dialog (widget_instance* instance);
Boolean
lw_motif_widget_p (Widget widget);
void
xm_update_one_widget (widget_instance* instance, Widget widget,
widget_value* val, Boolean deep_p);
void
xm_update_one_value (widget_instance* instance, Widget widget,
widget_value* val);
void
xm_destroy_instance (widget_instance* instance);
void
xm_set_keyboard_focus (Widget parent, Widget w);
void
xm_popup_menu (Widget widget);
void
xm_pop_instance (widget_instance* instance, Boolean up);
#endif /* LWLIB_XM_H */
#ifndef LWLIB_XOL_H
#define LWLIB_XOL_H
#include "lwlib-internal.h"
extern widget_creation_entry xol_creation_table [];
extern Widget xol_create_dialog (widget_instance *);
Boolean
lw_olit_widget_p (Widget widget);
void
xol_update_one_widget (widget_instance* instance, Widget widget,
widget_value* val, Boolean deep_p);
void
xol_update_one_value (widget_instance* instance, Widget widget,
widget_value* val);
void
xol_destroy_instance (widget_instance* instance);
void
xol_pop_instance (widget_instance* instance, Boolean up);
void
xol_popup_menu (Widget widget);
#endif /* LWLIB_XOL_H */
#ifndef LWLIB_INTERNAL_H
#define LWLIB_INTERNAL_H
#include "lwlib.h"
/*
extern char *strdup (const char *);
extern int strcasecmp (const char *, const char *);
*/
typedef struct _widget_instance
{
Widget widget;
Widget parent;
Boolean pop_up_p;
struct _widget_info* info;
struct _widget_instance* next;
} widget_instance;
typedef struct _widget_info
{
char* type;
char* name;
LWLIB_ID id;
widget_value* val;
Boolean busy;
lw_callback pre_activate_cb;
lw_callback selection_cb;
lw_callback post_activate_cb;
struct _widget_instance* instances;
struct _widget_info* next;
} widget_info;
typedef Widget
(*widget_creation_function) (widget_instance* instance);
typedef struct _widget_creation_entry
{
char* type;
widget_creation_function function;
} widget_creation_entry;
/* update all other instances of a widget. Can be used in a callback when
a wiget has been used by the user */
void
lw_internal_update_other_instances (Widget widget, XtPointer closure,
XtPointer call_data);
/* get the widget_value for a widget in a given instance */
widget_value*
lw_get_widget_value_for_widget (widget_instance* instance, Widget w);
#endif /* LWLIB_INTERNAL_H */
/* Defines some widget utility functions.
Copyright (C) 1992 Lucid, Inc.
This file is part of the Lucid Widget Library.
The Lucid Widget Library is free software; you can redistribute it and/or
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,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <memory.h>
#include <X11/Xatom.h>
#include <X11/IntrinsicP.h>
#include <X11/ObjectP.h>
#include "lwlib-utils.h"
/* Redisplay the contents of the widget, without first clearing it. */
void
XtNoClearRefreshWidget (Widget widget)
{
XEvent event;
event.type = Expose;
event.xexpose.serial = 0;
event.xexpose.send_event = 0;
event.xexpose.display = XtDisplay (widget);
event.xexpose.window = XtWindow (widget);
event.xexpose.x = 0;
event.xexpose.y = 0;
event.xexpose.width = widget->core.width;
event.xexpose.height = widget->core.height;
event.xexpose.count = 0;
(*widget->core.widget_class->core_class.expose)
(widget, &event, (Region)NULL);
}
/*
* Apply a function to all the subwidgets of a given widget recursively.
*/
void
XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
{
if (XtIsComposite (w))
{
CompositeWidget cw = (CompositeWidget) w;
/* We have to copy the children list before mapping over it, because
the procedure might add/delete elements, which would lose badly.
*/
int nkids = cw->composite.num_children;
Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
int i;
memcpy (kids, cw->composite.children, sizeof (Widget) * nkids);
for (i = 0; i < nkids; i++)
/* This prevent us from using gadgets, why is it here? */
/* if (XtIsWidget (kids [i])) */
{
/* do the kiddies first in case we're destroying */
XtApplyToWidgets (kids [i], proc, arg);
proc (kids [i], arg);
}
free (kids);
}
}
/*
* Apply a function to all the subwidgets of a given widget recursively.
* Stop as soon as the function returns non NULL and returns this as a value.
*/
void *
XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
{
void* result;
if (XtIsComposite (w))
{
CompositeWidget cw = (CompositeWidget)w;
int i;
for (i = 0; i < cw->composite.num_children; i++)
if (XtIsWidget (cw->composite.children [i])){