diff options
-rw-r--r-- | generic/tkTest.c | 41 | ||||
-rw-r--r-- | tests/event.test | 22 |
2 files changed, 44 insertions, 19 deletions
diff --git a/generic/tkTest.c b/generic/tkTest.c index a5f1c34..2eaa4de 100644 --- a/generic/tkTest.c +++ b/generic/tkTest.c @@ -1688,14 +1688,16 @@ ImageDelete( * * ProcessEventsObjCmd -- * - * This function implements the "processevents" command. Currently - * It processes all <Enter> or <Leave> events on the queue. + * This function implements the "processevents" command which processes + * all queued events of a type specified by one of the arguments to the + * command. Currently the supported arguments are leave, enter, and + * motion. Others could be added if needed. * * Results: - * A standard Tcl result. + * A standard Tcl result. * * Side effects: - * Events are processed + * Events are processed * *---------------------------------------------------------------------- */ @@ -1705,20 +1707,43 @@ CrossingRestrictProc( ClientData arg, XEvent *eventPtr) { - if (eventPtr->type == EnterNotify || eventPtr->type == LeaveNotify) { - return TK_PROCESS_EVENT; + int *eventTypes = (int *) arg; + for (int *t = eventTypes; *t != 0; t++) { + if (eventPtr->type == *t) { + return TK_PROCESS_EVENT; + } } return TK_DEFER_EVENT; } -static int ProcessEventsObjCmd(ClientData dummy, +static int ProcessEventsObjCmd( + ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[]) { ClientData oldArg; Tk_RestrictProc *oldProc; - oldProc = Tk_RestrictEvents(CrossingRestrictProc, NULL, &oldArg); + int index; + static const char *const eventTypeNames[] = { + "leave", "enter", "motion", NULL}; + static const int eventTypes[] = { + LeaveNotify, EnterNotify, MotionNotify}; + int whichEvents[100]; + if (objc < 2) { + Tcl_WrongNumArgs(interp, 1, objv, "eventtype ?eventtype ...?"); + return TCL_ERROR; + } + for (int n = 1; n < objc; n++) { + if (Tcl_GetIndexFromObj(interp, objv[n], eventTypeNames, "eventtype", 0, + &index) != TCL_OK) { + return TCL_ERROR; + } + whichEvents[n - 1] = eventTypes[index]; + } + whichEvents[objc - 1] = 0; + oldProc = Tk_RestrictEvents(CrossingRestrictProc, (void *) whichEvents, + &oldArg); while (Tcl_ServiceEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {}; Tk_RestrictEvents(oldProc, oldArg, &oldArg); return TCL_OK; diff --git a/tests/event.test b/tests/event.test index 8a69104..7bdf57c 100644 --- a/tests/event.test +++ b/tests/event.test @@ -933,11 +933,11 @@ test event-9.11 {pointer window container = parent} -setup { update; # finish display of window set result "|" } -body { - processevents + processevents enter leave bind all <Leave> {append result "<Leave> %d %W|"} bind all <Enter> {append result "<Enter> %d %W|"} destroy .one.f1.f2 - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -962,7 +962,7 @@ test event-9.12 {pointer window container != parent} -setup { bind all <Leave> {append result "<Leave> %d %W|"} bind all <Enter> {append result "<Enter> %d %W|"} destroy .one.g - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -985,7 +985,7 @@ test event-9.13 {pointer window is a toplevel, toplevel destination} -setup { bind all <Enter> {append result "<Enter> %d %W|"} destroy .two waitForWindowEvent .one <Enter> - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -1010,7 +1010,7 @@ test event-9.14 {pointer window is a toplevel, tk internal destination} -setup { bind all <Enter> {append result "<Enter> %d %W|"} destroy .two waitForWindowEvent .one.f1.f2 <Enter> - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -1032,7 +1032,7 @@ test event-9.15 {pointer window is a toplevel, destination is screen root} -setu bind all <Leave> {append result "<Leave> %d %W|"} bind all <Enter> {append result "<Enter> %d %W|"} destroy .two - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -1056,7 +1056,7 @@ test event-9.16 {Successive destructions (pointer window + parent), single gener bind all <Leave> {append result "<Leave> %d %W|"} bind all <Enter> {append result "<Enter> %d %W|"} destroy .one.f1 - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -1083,7 +1083,7 @@ test event-9.17 {Successive destructions (pointer window + parent), separate cro update; # make sure window is gone destroy .one.f1 update; # make sure window is gone - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -1106,7 +1106,7 @@ test event-9.18 {Successive destructions (pointer window + ancestors including i bind all <Enter> {append result "<Enter> %d %W|"} destroy .two waitForWindowEvent .one <Enter> - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -1136,7 +1136,7 @@ test event-9.19 {Successive destructions (pointer window + ancestors including i bind all <Enter> {append result "<Enter> %d %W|"} destroy .three waitForWindowEvent .two.f1.f2 <Enter> - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} @@ -1159,7 +1159,7 @@ test event-9.20 {Successive destructions (pointer window + ancestors including i bind all <Leave> {append result "<Leave> %d %W|"} bind all <Enter> {append result "<Enter> %d %W|"} destroy .two - processevents + processevents enter leave set result } -cleanup { bind all <Leave> {} |