1999-10-03 19:36:13 +00:00
|
|
|
/* Copyright Massachusetts Institute of Technology 1985 */
|
|
|
|
|
2021-08-29 11:28:36 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 1985, 1986, 1987 by the Massachusetts Institute of Technology
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this
|
|
|
|
software and its documentation for any purpose and without
|
|
|
|
fee is hereby granted, provided that the above copyright
|
|
|
|
notice appear in all copies and that both that copyright
|
|
|
|
notice and this permission notice appear in supporting
|
|
|
|
documentation, and that the name of M.I.T. not be used in
|
|
|
|
advertising or publicity pertaining to distribution of the
|
|
|
|
software without specific, written prior permission.
|
|
|
|
M.I.T. makes no representations about the suitability of
|
|
|
|
this software for any purpose. It is provided "as is"
|
|
|
|
without express or implied warranty.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
|
2007-02-27 02:54:29 +00:00
|
|
|
/*
|
2023-01-01 10:31:12 +00:00
|
|
|
Copyright (C) 2001-2023 Free Software Foundation, Inc.
|
2007-02-27 02:54:29 +00:00
|
|
|
|
2008-05-09 04:51:27 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
2007-02-27 02:54:29 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2016-03-10 15:34:52 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or (at
|
|
|
|
your option) any later version.
|
2007-02-27 02:54:29 +00:00
|
|
|
|
|
|
|
This program 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
|
2017-09-13 22:52:52 +00:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2007-02-27 02:54:29 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* XMenu: MIT Project Athena, X Window system menu package
|
|
|
|
*
|
|
|
|
* XMenuActivate - Maps a given menu to the display and activates
|
|
|
|
* the menu for user selection. The user is allowed to
|
|
|
|
* specify which pane and selection will be current,
|
|
|
|
* the X and Y location of the menu (relative to the
|
|
|
|
* parent window) and the mouse button event mask that
|
|
|
|
* will be used to identify a selection request.
|
|
|
|
*
|
|
|
|
* A menu selection is shown to be current by placing
|
|
|
|
* a highlight box around the selection as the mouse
|
|
|
|
* cursor enters its active region. Inactive selections
|
|
|
|
* will not be highlighted. As the mouse cursor moved
|
|
|
|
* from one menu pane to another menu pane the pane being
|
|
|
|
* entered is raised and made current and the pane being
|
|
|
|
* left is lowered.
|
|
|
|
*
|
|
|
|
* Anytime XMenuActivate returns, the p_num and
|
|
|
|
* s_num are left at their last known values (i.e.,
|
|
|
|
* the last known current pane and selection indices).
|
|
|
|
* The following are the defined return states:
|
|
|
|
*
|
|
|
|
* 1) If at any time an error occurs the data
|
|
|
|
* pointer is left untouched and XM_FAILURE
|
2003-02-04 14:56:31 +00:00
|
|
|
* is returned.
|
1999-10-03 19:36:13 +00:00
|
|
|
*
|
|
|
|
* 2) When a selection request is received (i.e.,
|
|
|
|
* when the specified mouse event occurs) the
|
|
|
|
* data pointer will be set to the data
|
|
|
|
* associated with the particular selection
|
|
|
|
* current at the time of the selection request
|
|
|
|
* and XM_SUCCESS is returned.
|
|
|
|
*
|
|
|
|
* 3) If no selection was current at the time a
|
|
|
|
* selection request is made the data pointer
|
|
|
|
* will be left untouched and XM_NO_SELECT will
|
|
|
|
* be returned.
|
|
|
|
*
|
2003-02-04 14:56:31 +00:00
|
|
|
* 4) If the selection that was current at the time
|
1999-10-03 19:36:13 +00:00
|
|
|
* a selection request is made is not an active
|
|
|
|
* selection the data pointer will be left
|
|
|
|
* untouched and XM_IA_SELECT will be returned.
|
|
|
|
*
|
|
|
|
* Since X processes events in an asynchronous manner
|
|
|
|
* it is likely that XMenuActivate will encounter
|
|
|
|
* a "foreign event" while it is executing. Foreign
|
|
|
|
* events are handled in one of three ways:
|
|
|
|
*
|
|
|
|
* 1) The event is discarded. This is the default
|
|
|
|
* mode and requires no action on the part of the
|
|
|
|
* application.
|
|
|
|
*
|
|
|
|
* 2) The application has identified an asynchronous
|
|
|
|
* event handler that will be called and the
|
|
|
|
* foreign event handed off to it. Note:
|
|
|
|
* AEQ mode disables this mode temporarily.
|
|
|
|
*
|
|
|
|
* 3) The application has enabled asynchronous event
|
|
|
|
* queuing mode. In this mode all foreign events
|
2011-11-23 07:03:56 +00:00
|
|
|
* will be queued up until XMenuActivate
|
1999-10-03 19:36:13 +00:00
|
|
|
* terminates; at which time they will be
|
|
|
|
* returned to the X event queue. As long as
|
|
|
|
* AEQ mode is enabled any asynchronous event
|
|
|
|
* handler as temporarily disabled.
|
|
|
|
*
|
|
|
|
* Any events encountered while taking down the menu
|
|
|
|
* (i.e., exposure events from occluded windows) will
|
|
|
|
* automatically be returned to the X event queue after
|
|
|
|
* XMenuActivate has cleaned the queue of any of its own
|
|
|
|
* events that are no longer needed.
|
|
|
|
*
|
|
|
|
* Author: Tony Della Fera, DEC
|
|
|
|
* March 12, 1986
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "XMenuInt.h"
|
2004-12-27 15:23:22 +00:00
|
|
|
#include <X11/keysym.h>
|
1999-10-03 19:36:13 +00:00
|
|
|
|
2002-04-22 18:27:03 +00:00
|
|
|
/* For debug, set this to 0 to not grab the keyboard on menu popup */
|
|
|
|
int x_menu_grab_keyboard = 1;
|
|
|
|
|
2004-11-12 08:28:57 +00:00
|
|
|
static Wait_func wait_func;
|
|
|
|
static void* wait_data;
|
2022-03-01 06:44:02 +00:00
|
|
|
static Translate_func translate_func = NULL;
|
2004-11-12 08:28:57 +00:00
|
|
|
|
|
|
|
void
|
2010-07-04 05:57:11 +00:00
|
|
|
XMenuActivateSetWaitFunction (Wait_func func, void *data)
|
2004-11-12 08:28:57 +00:00
|
|
|
{
|
|
|
|
wait_func = func;
|
|
|
|
wait_data = data;
|
|
|
|
}
|
|
|
|
|
2022-03-01 06:44:02 +00:00
|
|
|
void
|
|
|
|
XMenuActivateSetTranslateFunction (Translate_func func)
|
|
|
|
{
|
|
|
|
translate_func = func;
|
|
|
|
}
|
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
int
|
2010-07-04 05:57:11 +00:00
|
|
|
XMenuActivate(
|
|
|
|
register Display *display, /* Display to put menu on. */
|
|
|
|
register XMenu *menu, /* Menu to activate. */
|
|
|
|
int *p_num, /* Pane number selected. */
|
|
|
|
int *s_num, /* Selection number selected. */
|
|
|
|
int x_pos, /* X coordinate of menu position. */
|
|
|
|
int y_pos, /* Y coordinate of menu position. */
|
|
|
|
unsigned int event_mask, /* Mouse button event mask. */
|
|
|
|
char **data, /* Pointer to return data value. */
|
Modernize to C89, for better static checking.
* Activate.c (XMenuActivate): Callback's first arg is readonly.
* AddPane.c (XMenuAddPane): Label is readonly. Rename local
to avoid shadowing.
* AddSel.c (XMenuAddSelection): Help arg is readonly. Rename local.
* Create.c (atoi, atof): Remove decls; include <stdlib.h>.
(MAX_INACT_PNUM, TILE_BUF_SIZE): Remove; unused.
(x_get_resource_string): Args are readonly.
(XAllocDisplayColor): colorName is readonly.
(XMenuCreate): def_env is readonly. Remove unused locals. Avoid
"else;".
* Destroy.c (XMenuDestroy): Return void.
* Error.c (XMenuError): Remove const pointer.
* EvHand.c (XMenuEventHandler): Return void.
* FindPane.c, FindSel.c: Include <string.h>.
* InsPane.c (XMenuInsertPane): Rename local to avoid shadowing.
* InsSel.c (XMenuInsertSelection): Likewise.
* Internal.c (toggle_color, BUFFER_SIZE): Remove; unused.
(_XMErrorList): Now const.
(_XMWinQueInit, _XMRecomputeGlobals, _XMTransToOrigin, _XMRefreshPane):
(_XMRefreshSelection): Return void.
(_XMWinQueFlush, _XMRefreshSelection): Rename locals to avoid
shadowing.
(_XMWinQueFlush): Use stack, not heap. Don't use uninitialized var.
* SetAEQ.c (XMenuSetAEQ): Now returns void.
* SetFrz.c (XMenuSetFreeze): Likewise.
* X10.h (XAssoc): Use void * for generic pointer.
* XDelAssoc.c: Include XMenuInt.h rather than duplicating part of it.
* XDestAssoc.c, XMakeAssoc.c: Likewise.
* XDestAssoc.c (XDestroyAssocTable): Return void.
* XMakeAssoc.c (XMakeAssoc): Use void * for generic pointer.
* XMenu.h, XMenuInt.h: Adjust to signature changes. Use const
for pointers to readonly storage.
* insque.c: Include XMenuInt.h, to check our own signature.
(emacs_insque, emacs_remque): Use void * for generic pointers.
2011-04-16 08:25:42 +00:00
|
|
|
void (*help_callback) (char const *, int, int)) /* Help callback. */
|
1999-10-03 19:36:13 +00:00
|
|
|
{
|
|
|
|
int status; /* X routine call status. */
|
|
|
|
int orig_x; /* Upper left menu origin X coord. */
|
|
|
|
int orig_y; /* Upper left menu origin Y coord. */
|
|
|
|
int ret_val; /* Return value. */
|
|
|
|
|
|
|
|
register XMPane *p_ptr; /* Current XMPane. */
|
|
|
|
register XMPane *event_xmp; /* Event XMPane pointer. */
|
|
|
|
register XMPane *cur_p; /* Current pane. */
|
|
|
|
register XMSelect *cur_s; /* Current selection. */
|
|
|
|
XMWindow *event_xmw; /* Event XMWindow pointer. */
|
|
|
|
XEvent event; /* X input event. */
|
|
|
|
XEvent peek_event; /* X input peek ahead event. */
|
|
|
|
|
|
|
|
Bool selection = False; /* Selection has been made. */
|
|
|
|
Bool forward = True; /* Moving forward in the pane list. */
|
|
|
|
|
|
|
|
Window root, child;
|
|
|
|
int root_x, root_y, win_x, win_y;
|
|
|
|
unsigned int mask;
|
2004-12-27 15:23:22 +00:00
|
|
|
KeySym keysym;
|
1999-10-03 19:36:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Define and allocate a foreign event queue to hold events
|
|
|
|
* that don't belong to XMenu. These events are later restored
|
|
|
|
* to the X event queue.
|
|
|
|
*/
|
|
|
|
typedef struct _xmeventque {
|
|
|
|
XEvent event;
|
|
|
|
struct _xmeventque *next;
|
|
|
|
} XMEventQue;
|
|
|
|
|
|
|
|
XMEventQue *feq = NULL; /* Foreign event queue. */
|
|
|
|
XMEventQue *feq_tmp; /* Foreign event queue temporary. */
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* If there are no panes in the menu then return failure
|
|
|
|
* because the menu is not initialized.
|
|
|
|
*/
|
|
|
|
if (menu->p_count == 0) {
|
|
|
|
_XMErrorCode = XME_NOT_INIT;
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the desired current pane.
|
|
|
|
*/
|
|
|
|
cur_p = _XMGetPanePtr(menu, *p_num);
|
|
|
|
if (cur_p == NULL) {
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
cur_p->activated = cur_p->active;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the desired current selection.
|
|
|
|
* If the current selection index is out of range a null current selection
|
|
|
|
* will be assumed and the cursor will be placed in the current pane
|
|
|
|
* header.
|
|
|
|
*/
|
|
|
|
cur_s = _XMGetSelectionPtr(cur_p, *s_num);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute origin of menu so that cursor is in
|
|
|
|
* Correct pane and selection.
|
|
|
|
*/
|
2003-02-04 14:56:31 +00:00
|
|
|
_XMTransToOrigin(display,
|
|
|
|
menu,
|
|
|
|
cur_p, cur_s,
|
|
|
|
x_pos, y_pos,
|
1999-10-03 19:36:13 +00:00
|
|
|
&orig_x, &orig_y);
|
|
|
|
menu->x_pos = orig_x; /* Store X and Y coords of menu. */
|
|
|
|
menu->y_pos = orig_y;
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
if (XMenuRecompute(display, menu) == XM_FAILURE) {
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush the window creation queue.
|
|
|
|
* This batches all window creates since lazy evaluation
|
|
|
|
* is more efficient than individual evaluation.
|
|
|
|
* This routine also does an XFlush().
|
|
|
|
*/
|
|
|
|
if (_XMWinQueFlush(display, menu, cur_p, cur_s) == _FAILURE) {
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure windows are in correct order (in case we were passed
|
|
|
|
* an already created menu in incorrect order.)
|
|
|
|
*/
|
|
|
|
for(p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next)
|
|
|
|
XRaiseWindow(display, p_ptr->window);
|
|
|
|
for(p_ptr = menu->p_list->prev; p_ptr != cur_p->prev; p_ptr = p_ptr->prev)
|
|
|
|
XRaiseWindow(display, p_ptr->window);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure all selection windows are mapped.
|
|
|
|
*/
|
|
|
|
for (
|
|
|
|
p_ptr = menu->p_list->next;
|
|
|
|
p_ptr != menu->p_list;
|
|
|
|
p_ptr = p_ptr->next
|
|
|
|
){
|
|
|
|
XMapSubwindows(display, p_ptr->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronize the X buffers and the event queue.
|
|
|
|
* From here on, all events in the queue that don't belong to
|
|
|
|
* XMenu are sent back to the application via an application
|
|
|
|
* provided event handler or discarded if the application has
|
|
|
|
* not provided an event handler.
|
|
|
|
*/
|
|
|
|
XSync(display, 0);
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* Grab the mouse for menu input.
|
|
|
|
*/
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
status = XGrabPointer(
|
|
|
|
display,
|
|
|
|
menu->parent,
|
|
|
|
True,
|
|
|
|
event_mask,
|
|
|
|
GrabModeAsync,
|
|
|
|
GrabModeAsync,
|
|
|
|
None,
|
|
|
|
menu->mouse_cursor,
|
|
|
|
CurrentTime
|
|
|
|
);
|
2002-04-22 18:27:03 +00:00
|
|
|
if (status == Success && x_menu_grab_keyboard)
|
|
|
|
{
|
|
|
|
status = XGrabKeyboard (display,
|
|
|
|
menu->parent,
|
|
|
|
False,
|
|
|
|
GrabModeAsync,
|
|
|
|
GrabModeAsync,
|
|
|
|
CurrentTime);
|
|
|
|
if (status != Success)
|
|
|
|
XUngrabPointer(display, CurrentTime);
|
|
|
|
}
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
if (status == _X_FAILURE) {
|
|
|
|
_XMErrorCode = XME_GRAB_MOUSE;
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map the menu panes.
|
|
|
|
*/
|
|
|
|
XMapWindow(display, cur_p->window);
|
|
|
|
for (p_ptr = menu->p_list->next;
|
2003-02-04 14:56:31 +00:00
|
|
|
p_ptr != cur_p;
|
1999-10-03 19:36:13 +00:00
|
|
|
p_ptr = p_ptr->next)
|
|
|
|
XMapWindow(display, p_ptr->window);
|
|
|
|
for (p_ptr = cur_p->next;
|
|
|
|
p_ptr != menu->p_list;
|
|
|
|
p_ptr = p_ptr->next)
|
|
|
|
XMapWindow(display, p_ptr->window);
|
|
|
|
|
|
|
|
XRaiseWindow(display, cur_p->window); /* Make sure current */
|
|
|
|
/* pane is on top. */
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
cur_s = NULL; /* Clear current selection. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Begin event processing loop.
|
|
|
|
*/
|
|
|
|
while (1) {
|
2004-11-12 08:28:57 +00:00
|
|
|
if (wait_func) (*wait_func) (wait_data);
|
1999-10-03 19:36:13 +00:00
|
|
|
XNextEvent(display, &event); /* Get next event. */
|
|
|
|
switch (event.type) { /* Dispatch on the event type. */
|
|
|
|
case Expose:
|
|
|
|
event_xmp = (XMPane *)XLookUpAssoc(display,
|
2003-02-04 14:56:31 +00:00
|
|
|
menu->assoc_tab,
|
1999-10-03 19:36:13 +00:00
|
|
|
event.xexpose.window);
|
|
|
|
if (event_xmp == NULL) {
|
|
|
|
/*
|
|
|
|
* If AEQ mode is enabled then queue the event.
|
|
|
|
*/
|
|
|
|
if (menu->aeq) {
|
|
|
|
feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue));
|
|
|
|
if (feq_tmp == NULL) {
|
|
|
|
_XMErrorCode = XME_CALLOC;
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
feq_tmp->event = event;
|
|
|
|
feq_tmp->next = feq;
|
|
|
|
feq = feq_tmp;
|
|
|
|
}
|
|
|
|
else if (_XMEventHandler) (*_XMEventHandler)(&event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (event_xmp->activated) {
|
|
|
|
XSetWindowBackground(display,
|
2003-02-04 14:56:31 +00:00
|
|
|
event_xmp->window,
|
1999-10-03 19:36:13 +00:00
|
|
|
menu->bkgnd_color);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
XSetWindowBackgroundPixmap(display,
|
|
|
|
event_xmp->window,
|
|
|
|
menu->inact_pixmap);
|
|
|
|
}
|
|
|
|
_XMRefreshPane(display, menu, event_xmp);
|
|
|
|
break;
|
|
|
|
case EnterNotify:
|
2003-02-04 14:56:31 +00:00
|
|
|
/*
|
1999-10-03 19:36:13 +00:00
|
|
|
* First wait a small period of time, and see
|
|
|
|
* if another EnterNotify event follows hard on the
|
|
|
|
* heels of this one. i.e., the user is simply
|
|
|
|
* "passing through". If so, ignore this one.
|
|
|
|
*/
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
event_xmw = (XMWindow *)XLookUpAssoc(display,
|
|
|
|
menu->assoc_tab,
|
|
|
|
event.xcrossing.window);
|
|
|
|
if (event_xmw == NULL) break;
|
|
|
|
if (event_xmw->type == SELECTION) {
|
|
|
|
/*
|
|
|
|
* We have entered a selection.
|
|
|
|
*/
|
|
|
|
/* if (XPending(display) == 0) usleep(150000); */
|
|
|
|
if (XPending(display) != 0) {
|
|
|
|
XPeekEvent(display, &peek_event);
|
|
|
|
if(peek_event.type == LeaveNotify) {
|
|
|
|
break;
|
|
|
|
}
|
2003-02-04 14:56:31 +00:00
|
|
|
}
|
1999-10-03 19:36:13 +00:00
|
|
|
cur_s = (XMSelect *)event_xmw;
|
2000-07-21 14:36:24 +00:00
|
|
|
help_callback (cur_s->help_string,
|
|
|
|
cur_p->serial, cur_s->serial);
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* If the pane we are in is active and the
|
|
|
|
* selection entered is active then activate
|
|
|
|
* the selection.
|
|
|
|
*/
|
|
|
|
if (cur_p->active && cur_s->active > 0) {
|
|
|
|
cur_s->activated = 1;
|
|
|
|
_XMRefreshSelection(display, menu, cur_s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* We have entered a pane.
|
|
|
|
*/
|
|
|
|
/* if (XPending(display) == 0) usleep(150000); */
|
|
|
|
if (XPending(display) != 0) {
|
|
|
|
XPeekEvent(display, &peek_event);
|
|
|
|
if (peek_event.type == EnterNotify) break;
|
|
|
|
}
|
|
|
|
XQueryPointer(display,
|
|
|
|
menu->parent,
|
|
|
|
&root, &child,
|
|
|
|
&root_x, &root_y,
|
|
|
|
&win_x, &win_y,
|
|
|
|
&mask);
|
|
|
|
event_xmp = (XMPane *)XLookUpAssoc(display,
|
|
|
|
menu->assoc_tab,
|
|
|
|
child);
|
|
|
|
if (event_xmp == NULL) break;
|
|
|
|
if (event_xmp == cur_p) break;
|
|
|
|
if (event_xmp->serial > cur_p->serial) forward = True;
|
|
|
|
else forward = False;
|
|
|
|
p_ptr = cur_p;
|
|
|
|
while (p_ptr != event_xmp) {
|
|
|
|
if (forward) p_ptr = p_ptr->next;
|
|
|
|
else p_ptr = p_ptr->prev;
|
|
|
|
XRaiseWindow(display, p_ptr->window);
|
|
|
|
}
|
|
|
|
if (cur_p->activated) {
|
|
|
|
cur_p->activated = False;
|
|
|
|
XSetWindowBackgroundPixmap(display,
|
|
|
|
cur_p->window,
|
|
|
|
menu->inact_pixmap);
|
|
|
|
_XMRefreshPane(display, menu, cur_p);
|
|
|
|
}
|
|
|
|
if (event_xmp->active) event_xmp->activated = True;
|
|
|
|
#if 1
|
|
|
|
/*
|
|
|
|
* i suspect the we don't get an EXPOSE event when backing
|
|
|
|
* store is enabled; the menu windows content is probably
|
|
|
|
* not drawn in when it should be in that case.
|
|
|
|
* in that case, this is probably an ugly fix!
|
|
|
|
* i hope someone more familiar with this code would
|
|
|
|
* take it from here. -- caveh@eng.sun.com.
|
|
|
|
*/
|
|
|
|
XSetWindowBackground(display,
|
2003-02-04 14:56:31 +00:00
|
|
|
event_xmp->window,
|
1999-10-03 19:36:13 +00:00
|
|
|
menu->bkgnd_color);
|
|
|
|
_XMRefreshPane(display, menu, event_xmp);
|
|
|
|
#endif
|
|
|
|
cur_p = event_xmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LeaveNotify:
|
|
|
|
event_xmw = (XMWindow *)XLookUpAssoc(
|
|
|
|
display,
|
|
|
|
menu->assoc_tab,
|
|
|
|
event.xcrossing.window
|
|
|
|
);
|
|
|
|
if (event_xmw == NULL) break;
|
|
|
|
if(cur_s == NULL) break;
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* If the current selection was activated then
|
|
|
|
* deactivate it.
|
|
|
|
*/
|
2022-03-02 03:12:09 +00:00
|
|
|
/* Emacs specific, HELP_STRING cannot be validly NULL
|
|
|
|
* in the real XMenu library. */
|
|
|
|
help_callback (NULL, cur_p->serial, cur_s->serial);
|
1999-10-03 19:36:13 +00:00
|
|
|
if (cur_s->activated) {
|
|
|
|
cur_s->activated = False;
|
|
|
|
_XMRefreshSelection(display, menu, cur_s);
|
|
|
|
}
|
|
|
|
cur_s = NULL;
|
|
|
|
break;
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
*p_num = cur_p->serial;
|
|
|
|
/*
|
|
|
|
* Check to see if there is a current selection.
|
|
|
|
*/
|
|
|
|
if (cur_s != NULL) {
|
|
|
|
/*
|
|
|
|
* Set the selection number to the current selection.
|
|
|
|
*/
|
|
|
|
*s_num = cur_s->serial;
|
|
|
|
/*
|
|
|
|
* If the current selection was activated then
|
|
|
|
* we have a valid selection otherwise we have
|
|
|
|
* an inactive selection.
|
|
|
|
*/
|
|
|
|
if (cur_s->activated) {
|
|
|
|
*data = cur_s->data;
|
|
|
|
ret_val = XM_SUCCESS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret_val = XM_IA_SELECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* No selection was current.
|
|
|
|
*/
|
|
|
|
ret_val = XM_NO_SELECT;
|
|
|
|
}
|
|
|
|
selection = True;
|
|
|
|
break;
|
2004-12-27 15:23:22 +00:00
|
|
|
case KeyPress:
|
|
|
|
case KeyRelease:
|
|
|
|
keysym = XLookupKeysym (&event.xkey, 0);
|
|
|
|
|
|
|
|
/* Pop down on C-g and Escape. */
|
|
|
|
if ((keysym == XK_g && (event.xkey.state & ControlMask) != 0)
|
|
|
|
|| keysym == XK_Escape) /* Any escape, ignore modifiers. */
|
|
|
|
{
|
|
|
|
ret_val = XM_NO_SELECT;
|
|
|
|
selection = True;
|
|
|
|
}
|
|
|
|
break;
|
1999-10-03 19:36:13 +00:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* If AEQ mode is enabled then queue the event.
|
|
|
|
*/
|
|
|
|
if (menu->aeq) {
|
|
|
|
feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue));
|
|
|
|
if (feq_tmp == NULL) {
|
|
|
|
_XMErrorCode = XME_CALLOC;
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
feq_tmp->event = event;
|
|
|
|
feq_tmp->next = feq;
|
|
|
|
feq = feq_tmp;
|
|
|
|
}
|
|
|
|
else if (_XMEventHandler) (*_XMEventHandler)(&event);
|
2022-03-01 06:44:02 +00:00
|
|
|
break;
|
|
|
|
#ifdef HAVE_XINPUT2
|
|
|
|
case GenericEvent:
|
|
|
|
if (translate_func)
|
|
|
|
translate_func (&event);
|
|
|
|
#endif
|
1999-10-03 19:36:13 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If a selection has been made, break out of the event loop.
|
|
|
|
*/
|
|
|
|
if (selection == True) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmap the menu.
|
|
|
|
*/
|
|
|
|
for ( p_ptr = menu->p_list->next;
|
|
|
|
p_ptr != menu->p_list;
|
2003-02-04 14:56:31 +00:00
|
|
|
p_ptr = p_ptr->next)
|
1999-10-03 19:36:13 +00:00
|
|
|
{
|
|
|
|
XUnmapWindow(display, p_ptr->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ungrab the mouse.
|
|
|
|
*/
|
|
|
|
XUngrabPointer(display, CurrentTime);
|
2002-04-22 18:27:03 +00:00
|
|
|
XUngrabKeyboard(display, CurrentTime);
|
1999-10-03 19:36:13 +00:00
|
|
|
|
2003-02-04 14:56:31 +00:00
|
|
|
/*
|
1999-10-03 19:36:13 +00:00
|
|
|
* Restore bits under where the menu was if we managed
|
|
|
|
* to save them and free the pixmap.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is a current selection deactivate it.
|
|
|
|
*/
|
|
|
|
if (cur_s != NULL) cur_s->activated = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deactivate the current pane.
|
|
|
|
*/
|
|
|
|
cur_p->activated = 0;
|
|
|
|
XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronize the X buffers and the X event queue.
|
|
|
|
*/
|
|
|
|
XSync(display, 0);
|
2003-02-04 14:56:31 +00:00
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* Dispatch any events remaining on the queue.
|
|
|
|
*/
|
|
|
|
while (QLength(display)) {
|
|
|
|
/*
|
|
|
|
* Fetch the next event.
|
|
|
|
*/
|
|
|
|
XNextEvent(display, &event);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discard any events left on the queue that belong to XMenu.
|
|
|
|
* All others are held and then returned to the event queue.
|
|
|
|
*/
|
|
|
|
switch (event.type) {
|
|
|
|
case Expose:
|
|
|
|
case EnterNotify:
|
|
|
|
case LeaveNotify:
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
|
|
|
/*
|
|
|
|
* Does this event belong to one of XMenu's windows?
|
|
|
|
* If so, discard it and process the next event.
|
|
|
|
* If not fall through and treat it as a foreign event.
|
|
|
|
*/
|
|
|
|
event_xmp = (XMPane *)XLookUpAssoc(
|
|
|
|
display,
|
|
|
|
menu->assoc_tab,
|
|
|
|
event.xbutton.window
|
|
|
|
);
|
|
|
|
if (event_xmp != NULL) continue;
|
2022-03-14 20:14:23 +00:00
|
|
|
FALLTHROUGH;
|
|
|
|
default:
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* This is a foreign event.
|
|
|
|
* Queue it for later return to the X event queue.
|
|
|
|
*/
|
|
|
|
feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue));
|
|
|
|
if (feq_tmp == NULL) {
|
|
|
|
_XMErrorCode = XME_CALLOC;
|
|
|
|
return(XM_FAILURE);
|
|
|
|
}
|
|
|
|
feq_tmp->event = event;
|
|
|
|
feq_tmp->next = feq;
|
|
|
|
feq = feq_tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Return any foreign events that were queued to the X event queue.
|
|
|
|
*/
|
|
|
|
while (feq != NULL) {
|
|
|
|
feq_tmp = feq;
|
|
|
|
XPutBackEvent(display, &feq_tmp->event);
|
|
|
|
feq = feq_tmp->next;
|
|
|
|
free((char *)feq_tmp);
|
|
|
|
}
|
2003-02-04 14:56:31 +00:00
|
|
|
|
2004-11-12 08:28:57 +00:00
|
|
|
wait_func = 0;
|
|
|
|
|
1999-10-03 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* Return successfully.
|
|
|
|
*/
|
|
|
|
_XMErrorCode = XME_NO_ERROR;
|
|
|
|
return(ret_val);
|
|
|
|
|
|
|
|
}
|