diff options
Diffstat (limited to 'generic/tkEvent.c')
-rw-r--r-- | generic/tkEvent.c | 110 |
1 files changed, 51 insertions, 59 deletions
diff --git a/generic/tkEvent.c b/generic/tkEvent.c index 7c41c22..dfa46ff 100644 --- a/generic/tkEvent.c +++ b/generic/tkEvent.c @@ -73,7 +73,7 @@ typedef struct TkWindowEvent { * Array of event masks corresponding to each X event: */ -static unsigned long realEventMasks[MappingNotify+1] = { +static const unsigned long realEventMasks[MappingNotify+1] = { 0, 0, KeyPressMask, /* KeyPress */ @@ -114,7 +114,7 @@ static unsigned long realEventMasks[MappingNotify+1] = { 0 /* Mapping Notify */ }; -static unsigned long virtualEventMasks[TK_LASTEVENT-VirtualEvent] = { +static const unsigned long virtualEventMasks[TK_LASTEVENT-VirtualEvent] = { VirtualEventMask, /* VirtualEvents */ ActivateMask, /* ActivateNotify */ ActivateMask, /* DeactivateNotify */ @@ -245,16 +245,10 @@ InvokeFocusHandlers( } /* - * MouseWheel events are not focus specific on Mac OS X. + * Only key-related events are directed according to the focus. */ -#ifdef MAC_OSX_TK -#define FOCUS_DIRECTED_EVENT_MASK (KeyPressMask|KeyReleaseMask) -#else -#define FOCUS_DIRECTED_EVENT_MASK (KeyPressMask|KeyReleaseMask|MouseWheelMask) -#endif - - if (mask & FOCUS_DIRECTED_EVENT_MASK) { + if (mask & (KeyPressMask|KeyReleaseMask)) { (*winPtrPtr)->dispPtr->lastEventTime = eventPtr->xkey.time; *winPtrPtr = TkFocusKeyEvent(*winPtrPtr, eventPtr); if (*winPtrPtr == NULL) { @@ -326,7 +320,7 @@ InvokeMouseHandlers( *---------------------------------------------------------------------- */ -#if defined(TK_USE_INPUT_METHODS) +#ifdef TK_USE_INPUT_METHODS static void CreateXIC( TkWindow *winPtr) @@ -357,10 +351,10 @@ CreateXIC( XFree(preedit_attlist); } - + if (winPtr->inputContext == NULL) { /* XCreateIC failed. */ - return; + return; } /* @@ -668,7 +662,7 @@ InvokeClientMessageHandlers( if (tmpPtr == NULL) { tsdPtr->lastCmPtr = prevPtr; } - (void) ckfree((char *) curPtr); + ckfree(curPtr); curPtr = tmpPtr; continue; } @@ -730,7 +724,7 @@ InvokeGenericHandlers( if (tmpPtr == NULL) { tsdPtr->lastGenericPtr = prevPtr; } - (void) ckfree((char *) curPtr); + ckfree(curPtr); curPtr = tmpPtr; continue; } @@ -738,7 +732,7 @@ InvokeGenericHandlers( int done; tsdPtr->handlersActive++; - done = (*curPtr->proc)(curPtr->clientData, eventPtr); + done = curPtr->proc(curPtr->clientData, eventPtr); tsdPtr->handlersActive--; if (done) { return done; @@ -794,7 +788,7 @@ Tk_CreateEventHandler( * No event handlers defined at all, so must create. */ - handlerPtr = (TkEventHandler *) ckalloc(sizeof(TkEventHandler)); + handlerPtr = ckalloc(sizeof(TkEventHandler)); winPtr->handlerList = handlerPtr; } else { int found = 0; @@ -825,8 +819,7 @@ Tk_CreateEventHandler( * No event handler matched, so create a new one. */ - handlerPtr->nextPtr = (TkEventHandler *) - ckalloc(sizeof(TkEventHandler)); + handlerPtr->nextPtr = ckalloc(sizeof(TkEventHandler)); handlerPtr = handlerPtr->nextPtr; } @@ -873,7 +866,7 @@ Tk_DeleteEventHandler( register InProgress *ipPtr; TkEventHandler *prevPtr; register TkWindow *winPtr = (TkWindow *) token; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); /* @@ -912,7 +905,7 @@ Tk_DeleteEventHandler( } else { prevPtr->nextPtr = handlerPtr->nextPtr; } - ckfree((char *) handlerPtr); + ckfree(handlerPtr); /* * No need to call XSelectInput: Tk always selects on all events for all @@ -945,10 +938,10 @@ Tk_CreateGenericHandler( ClientData clientData) /* One-word value to pass to proc. */ { GenericHandler *handlerPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - handlerPtr = (GenericHandler *) ckalloc(sizeof(GenericHandler)); + handlerPtr = ckalloc(sizeof(GenericHandler)); handlerPtr->proc = proc; handlerPtr->clientData = clientData; @@ -986,7 +979,7 @@ Tk_DeleteGenericHandler( ClientData clientData) { GenericHandler * handler; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); for (handler=tsdPtr->genericList ; handler ; handler=handler->nextPtr) { @@ -1019,7 +1012,7 @@ Tk_CreateClientMessageHandler( Tk_ClientMessageProc *proc) /* Function to call on event. */ { GenericHandler *handlerPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); /* @@ -1027,7 +1020,7 @@ Tk_CreateClientMessageHandler( * with an extra clientData field we'll never use. */ - handlerPtr = (GenericHandler *) ckalloc(sizeof(GenericHandler)); + handlerPtr = ckalloc(sizeof(GenericHandler)); handlerPtr->proc = (Tk_GenericProc *) proc; handlerPtr->clientData = NULL; /* never used */ @@ -1065,7 +1058,7 @@ Tk_DeleteClientMessageHandler( Tk_ClientMessageProc *proc) { GenericHandler * handler; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); for (handler=tsdPtr->cmList ; handler!=NULL ; handler=handler->nextPtr) { @@ -1096,7 +1089,7 @@ Tk_DeleteClientMessageHandler( void TkEventInit(void) { - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); tsdPtr->handlersActive = 0; @@ -1131,9 +1124,8 @@ TkXErrorHandler( ClientData clientData, /* Pointer to flag we set. */ XErrorEvent *errEventPtr) /* X error info. */ { - int *error; + int *error = clientData; - error = (int *) clientData; *error = 1; return 0; } @@ -1174,7 +1166,7 @@ ParentXId( gotXError = 0; handler = Tk_CreateErrorHandler(display, -1, -1, -1, - TkXErrorHandler, (ClientData) (&gotXError)); + TkXErrorHandler, &gotXError); /* * Get the parent window. @@ -1224,7 +1216,7 @@ Tk_HandleEvent( unsigned long mask; InProgress ip; Tcl_Interp *interp = NULL; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); UpdateButtonEventState(eventPtr); @@ -1278,7 +1270,7 @@ Tk_HandleEvent( * code. */ - Tcl_Preserve((ClientData) interp); + Tcl_Preserve(interp); result = ((InvokeFocusHandlers(&winPtr, mask, eventPtr)) || (InvokeMouseHandlers(winPtr, mask, eventPtr))); @@ -1307,7 +1299,7 @@ Tk_HandleEvent( XSetICFocus(winPtr->inputContext); } } -#endif +#endif /*TK_USE_INPUT_METHODS*/ /* * For events where it hasn't already been done, update the current time @@ -1338,7 +1330,7 @@ Tk_HandleEvent( Tk_InternAtom((Tk_Window) winPtr, "WM_PROTOCOLS")) { TkWmProtocolEventProc(winPtr, eventPtr); } else { - InvokeClientMessageHandlers(tsdPtr, (Tk_Window)winPtr, + InvokeClientMessageHandlers(tsdPtr, (Tk_Window) winPtr, eventPtr); } } @@ -1346,7 +1338,7 @@ Tk_HandleEvent( for (handlerPtr = winPtr->handlerList; handlerPtr != NULL; ) { if ((handlerPtr->mask & mask) != 0) { ip.nextHandler = handlerPtr->nextPtr; - (*(handlerPtr->proc))(handlerPtr->clientData, eventPtr); + handlerPtr->proc(handlerPtr->clientData, eventPtr); handlerPtr = ip.nextHandler; } else { handlerPtr = handlerPtr->nextPtr; @@ -1380,7 +1372,7 @@ Tk_HandleEvent( releaseInterpreter: if (interp != NULL) { - Tcl_Release((ClientData) interp); + Tcl_Release(interp); } /* @@ -1418,7 +1410,7 @@ TkEventDeadWindow( { register TkEventHandler *handlerPtr; register InProgress *ipPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); /* @@ -1439,7 +1431,7 @@ TkEventDeadWindow( ipPtr->winPtr = None; } } - ckfree((char *) handlerPtr); + ckfree(handlerPtr); } } @@ -1467,7 +1459,7 @@ TkCurrentTime( TkDisplay *dispPtr) /* Display for which the time is desired. */ { register XEvent *eventPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (tsdPtr->pendingPtr == NULL) { @@ -1521,7 +1513,7 @@ Tk_RestrictEvents( * argument. */ { Tk_RestrictProc *prev; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); prev = tsdPtr->restrictProc; @@ -1614,7 +1606,7 @@ Tk_QueueWindowEvent( */ if (!(dispPtr->flags & TK_DISPLAY_COLLAPSE_MOTION_EVENTS)) { - wevPtr = (TkWindowEvent *) ckalloc(sizeof(TkWindowEvent)); + wevPtr = ckalloc(sizeof(TkWindowEvent)); wevPtr->header.proc = WindowEventProc; wevPtr->event = *eventPtr; Tcl_QueueEvent(&wevPtr->header, position); @@ -1642,11 +1634,11 @@ Tk_QueueWindowEvent( Tcl_QueueEvent(&dispPtr->delayedMotionPtr->header, position); dispPtr->delayedMotionPtr = NULL; - Tcl_CancelIdleCall(DelayedMotionProc, (ClientData) dispPtr); + Tcl_CancelIdleCall(DelayedMotionProc, dispPtr); } } - wevPtr = (TkWindowEvent *) ckalloc(sizeof(TkWindowEvent)); + wevPtr = ckalloc(sizeof(TkWindowEvent)); wevPtr->header.proc = WindowEventProc; wevPtr->event = *eventPtr; if ((eventPtr->type == MotionNotify) && (position == TCL_QUEUE_TAIL)) { @@ -1660,7 +1652,7 @@ Tk_QueueWindowEvent( Tcl_Panic("Tk_QueueWindowEvent found unexpected delayed motion event"); } dispPtr->delayedMotionPtr = wevPtr; - Tcl_DoWhenIdle(DelayedMotionProc, (ClientData) dispPtr); + Tcl_DoWhenIdle(DelayedMotionProc, dispPtr); } else { Tcl_QueueEvent(&wevPtr->header, position); } @@ -1736,14 +1728,14 @@ WindowEventProc( { TkWindowEvent *wevPtr = (TkWindowEvent *) evPtr; Tk_RestrictAction result; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (!(flags & TCL_WINDOW_EVENTS)) { return 0; } if (tsdPtr->restrictProc != NULL) { - result = (*tsdPtr->restrictProc)(tsdPtr->restrictArg, &wevPtr->event); + result = tsdPtr->restrictProc(tsdPtr->restrictArg, &wevPtr->event); if (result != TK_PROCESS_EVENT) { if (result == TK_DEFER_EVENT) { return 0; @@ -1835,7 +1827,7 @@ DelayedMotionProc( ClientData clientData) /* Pointer to display containing a delayed * motion event to be serviced. */ { - TkDisplay *dispPtr = (TkDisplay *) clientData; + TkDisplay *dispPtr = clientData; if (dispPtr->delayedMotionPtr == NULL) { Tcl_Panic("DelayedMotionProc found no delayed mouse motion event"); @@ -1867,7 +1859,7 @@ TkCreateExitHandler( { ExitHandler *exitPtr; - exitPtr = (ExitHandler *) ckalloc(sizeof(ExitHandler)); + exitPtr = ckalloc(sizeof(ExitHandler)); exitPtr->proc = proc; exitPtr->clientData = clientData; Tcl_MutexLock(&exitMutex); @@ -1932,7 +1924,7 @@ TkDeleteExitHandler( } else { prevPtr->nextPtr = exitPtr->nextPtr; } - ckfree((char *) exitPtr); + ckfree(exitPtr); break; } } @@ -1963,10 +1955,10 @@ TkCreateThreadExitHandler( ClientData clientData) /* Arbitrary value to pass to proc. */ { ExitHandler *exitPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - exitPtr = (ExitHandler *) ckalloc(sizeof(ExitHandler)); + exitPtr = ckalloc(sizeof(ExitHandler)); exitPtr->proc = proc; exitPtr->clientData = clientData; @@ -2004,7 +1996,7 @@ TkDeleteThreadExitHandler( ClientData clientData) /* Arbitrary value to pass to proc. */ { ExitHandler *exitPtr, *prevPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); for (prevPtr = NULL, exitPtr = tsdPtr->firstExitPtr; exitPtr != NULL; @@ -2016,7 +2008,7 @@ TkDeleteThreadExitHandler( } else { prevPtr->nextPtr = exitPtr->nextPtr; } - ckfree((char *) exitPtr); + ckfree(exitPtr); return; } } @@ -2059,8 +2051,8 @@ TkFinalize( firstExitPtr = exitPtr->nextPtr; Tcl_MutexUnlock(&exitMutex); - (*exitPtr->proc)(exitPtr->clientData); - ckfree((char *) exitPtr); + exitPtr->proc(exitPtr->clientData); + ckfree(exitPtr); Tcl_MutexLock(&exitMutex); } firstExitPtr = NULL; @@ -2092,7 +2084,7 @@ TkFinalizeThread( ClientData clientData) /* Arbitrary value to pass to proc. */ { ExitHandler *exitPtr; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) + ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); Tcl_DeleteThreadExitHandler(TkFinalizeThread, NULL); @@ -2109,8 +2101,8 @@ TkFinalizeThread( */ tsdPtr->firstExitPtr = exitPtr->nextPtr; - (*exitPtr->proc)(exitPtr->clientData); - ckfree((char *) exitPtr); + exitPtr->proc(exitPtr->clientData); + ckfree(exitPtr); } } } |