123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609 |
- #include "copyright.h"
- #include <config.h>
- #include "XMenuInt.h"
- #include <X11/keysym.h>
- int x_menu_grab_keyboard = 1;
- static Wait_func wait_func;
- static void* wait_data;
- void
- XMenuActivateSetWaitFunction (Wait_func func, void *data)
- {
- wait_func = func;
- wait_data = data;
- }
- int
- XMenuActivate(
- register Display *display,
- register XMenu *menu,
- int *p_num,
- int *s_num,
- int x_pos,
- int y_pos,
- unsigned int event_mask,
- char **data,
- void (*help_callback) (char const *, int, int))
- {
- int status;
- int orig_x;
- int orig_y;
- int ret_val;
- register XMPane *p_ptr;
- register XMPane *event_xmp;
- register XMPane *cur_p;
- register XMSelect *cur_s;
- XMWindow *event_xmw;
- XEvent event;
- XEvent peek_event;
- Bool selection = False;
- Bool forward = True;
- Window root, child;
- int root_x, root_y, win_x, win_y;
- unsigned int mask;
- KeySym keysym;
-
- typedef struct _xmeventque {
- XEvent event;
- struct _xmeventque *next;
- } XMEventQue;
- XMEventQue *feq = NULL;
- XMEventQue *feq_tmp;
-
- if (menu->p_count == 0) {
- _XMErrorCode = XME_NOT_INIT;
- return(XM_FAILURE);
- }
-
- cur_p = _XMGetPanePtr(menu, *p_num);
- if (cur_p == NULL) {
- return(XM_FAILURE);
- }
- cur_p->activated = cur_p->active;
-
- cur_s = _XMGetSelectionPtr(cur_p, *s_num);
-
- _XMTransToOrigin(display,
- menu,
- cur_p, cur_s,
- x_pos, y_pos,
- &orig_x, &orig_y);
- menu->x_pos = orig_x;
- menu->y_pos = orig_y;
- if (XMenuRecompute(display, menu) == XM_FAILURE) {
- return(XM_FAILURE);
- }
-
- if (_XMWinQueFlush(display, menu, cur_p, cur_s) == _FAILURE) {
- return(XM_FAILURE);
- }
-
- 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);
-
- for (
- p_ptr = menu->p_list->next;
- p_ptr != menu->p_list;
- p_ptr = p_ptr->next
- ){
- XMapSubwindows(display, p_ptr->window);
- }
-
- XSync(display, 0);
-
- status = XGrabPointer(
- display,
- menu->parent,
- True,
- event_mask,
- GrabModeAsync,
- GrabModeAsync,
- None,
- menu->mouse_cursor,
- CurrentTime
- );
- if (status == Success && x_menu_grab_keyboard)
- {
- status = XGrabKeyboard (display,
- menu->parent,
- False,
- GrabModeAsync,
- GrabModeAsync,
- CurrentTime);
- if (status != Success)
- XUngrabPointer(display, CurrentTime);
- }
- if (status == _X_FAILURE) {
- _XMErrorCode = XME_GRAB_MOUSE;
- return(XM_FAILURE);
- }
-
- XMapWindow(display, cur_p->window);
- for (p_ptr = menu->p_list->next;
- p_ptr != cur_p;
- 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);
-
- cur_s = NULL;
-
- while (1) {
- if (wait_func) (*wait_func) (wait_data);
- XNextEvent(display, &event);
- switch (event.type) {
- case Expose:
- event_xmp = (XMPane *)XLookUpAssoc(display,
- menu->assoc_tab,
- event.xexpose.window);
- if (event_xmp == NULL) {
-
- 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,
- event_xmp->window,
- menu->bkgnd_color);
- }
- else {
- XSetWindowBackgroundPixmap(display,
- event_xmp->window,
- menu->inact_pixmap);
- }
- _XMRefreshPane(display, menu, event_xmp);
- break;
- case EnterNotify:
-
- event_xmw = (XMWindow *)XLookUpAssoc(display,
- menu->assoc_tab,
- event.xcrossing.window);
- if (event_xmw == NULL) break;
- if (event_xmw->type == SELECTION) {
-
-
- if (XPending(display) != 0) {
- XPeekEvent(display, &peek_event);
- if(peek_event.type == LeaveNotify) {
- break;
- }
- }
- cur_s = (XMSelect *)event_xmw;
- help_callback (cur_s->help_string,
- cur_p->serial, cur_s->serial);
-
- if (cur_p->active && cur_s->active > 0) {
- cur_s->activated = 1;
- _XMRefreshSelection(display, menu, cur_s);
- }
- }
- else {
-
-
- 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
-
- XSetWindowBackground(display,
- event_xmp->window,
- 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;
-
- if (cur_s->activated) {
- cur_s->activated = False;
- _XMRefreshSelection(display, menu, cur_s);
- }
- cur_s = NULL;
- break;
- case ButtonPress:
- case ButtonRelease:
- *p_num = cur_p->serial;
-
- if (cur_s != NULL) {
-
- *s_num = cur_s->serial;
-
- if (cur_s->activated) {
- *data = cur_s->data;
- ret_val = XM_SUCCESS;
- }
- else {
- ret_val = XM_IA_SELECT;
- }
- }
- else {
-
- ret_val = XM_NO_SELECT;
- }
- selection = True;
- break;
- case KeyPress:
- case KeyRelease:
- keysym = XLookupKeysym (&event.xkey, 0);
-
- if ((keysym == XK_g && (event.xkey.state & ControlMask) != 0)
- || keysym == XK_Escape)
- {
- ret_val = XM_NO_SELECT;
- selection = True;
- }
- break;
- default:
-
- 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);
- }
-
- if (selection == True) break;
- }
-
- for ( p_ptr = menu->p_list->next;
- p_ptr != menu->p_list;
- p_ptr = p_ptr->next)
- {
- XUnmapWindow(display, p_ptr->window);
- }
-
- XUngrabPointer(display, CurrentTime);
- XUngrabKeyboard(display, CurrentTime);
-
-
- if (cur_s != NULL) cur_s->activated = 0;
-
- cur_p->activated = 0;
- XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap);
-
- XSync(display, 0);
-
- while (QLength(display)) {
-
- XNextEvent(display, &event);
-
- switch (event.type) {
- case Expose:
- case EnterNotify:
- case LeaveNotify:
- case ButtonPress:
- case ButtonRelease:
-
- event_xmp = (XMPane *)XLookUpAssoc(
- display,
- menu->assoc_tab,
- event.xbutton.window
- );
- if (event_xmp != NULL) continue;
- default:
-
- 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;
- }
- }
-
- while (feq != NULL) {
- feq_tmp = feq;
- XPutBackEvent(display, &feq_tmp->event);
- feq = feq_tmp->next;
- free((char *)feq_tmp);
- }
- wait_func = 0;
-
- _XMErrorCode = XME_NO_ERROR;
- return(ret_val);
- }
|