diff options
author | culler <culler> | 2019-10-18 21:59:41 (GMT) |
---|---|---|
committer | culler <culler> | 2019-10-18 21:59:41 (GMT) |
commit | daffadca1d118cf535300fea3c60baa6ee0dd5f7 (patch) | |
tree | 5b2fd8fe60b2e6e3b854bb8461056c8cb13307cd /macosx/tkMacOSXTest.c | |
parent | 4669b30d528ac2f442b9081592033ae42c5c0b8f (diff) | |
download | tk-daffadca1d118cf535300fea3c60baa6ee0dd5f7.zip tk-daffadca1d118cf535300fea3c60baa6ee0dd5f7.tar.gz tk-daffadca1d118cf535300fea3c60baa6ee0dd5f7.tar.bz2 |
Added a regression test, which involved adding a command to tkMacOSXTest.c to simulate mouse button press events.
Diffstat (limited to 'macosx/tkMacOSXTest.c')
-rw-r--r-- | macosx/tkMacOSXTest.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index f109b7a..09736e6 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -13,6 +13,7 @@ */ #include "tkMacOSXPrivate.h" +#include "tkMacOSXConstants.h" /* * Forward declarations of procedures defined later in this file: @@ -22,6 +23,8 @@ static int DebuggerObjCmd (ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); #endif +static int PressButtonObjCmd (ClientData dummy, Tcl_Interp *interp, + int objc, Tcl_Obj *const objv[]); /* @@ -52,6 +55,7 @@ TkplatformtestInit( #if MAC_OS_X_VERSION_MAX_ALLOWED < 1080 Tcl_CreateObjCommand(interp, "debugger", DebuggerObjCmd, NULL, NULL); #endif + Tcl_CreateObjCommand(interp, "pressbutton", PressButtonObjCmd, NULL, NULL); return TCL_OK; } @@ -119,6 +123,102 @@ TkTestLogDisplay(void) { } } +/* + *---------------------------------------------------------------------- + * + * PressButtonObjCmd -- + * + * This Tcl command simulates a button press at a specific screen + * location. It injects NSEvents into the NSApplication event queue, + * as opposed to adding events to the Tcl queue as event generate + * would do. One application is for testing the grab command. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + /* ARGSUSED */ +static int +PressButtonObjCmd( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ + int x, y, i, value, wNum; + CGPoint pt; + NSPoint loc; + NSEvent *motion, *press, *release; + NSArray *screens = [NSScreen screens]; + CGFloat ScreenHeight = 0; + enum {X=1, Y}; + + if (screens && [screens count]) { + ScreenHeight = [[screens objectAtIndex:0] frame].size.height; + } + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "x y"); + return TCL_ERROR; + } + for (i = 1; i < objc; i++) { + if (Tcl_GetIntFromObj(interp,objv[i],&value) != TCL_OK) { + return TCL_ERROR; + } + switch (i) { + case X: + x = value; + break; + case Y: + y = value; + break; + default: + break; + } + } + pt.x = loc.x = x; + pt.y = y; + loc.y = ScreenHeight - y; + wNum = 0; + CGWarpMouseCursorPosition(pt); + motion = [NSEvent mouseEventWithType:NSMouseMoved + location:loc + modifierFlags:0 + timestamp:GetCurrentEventTime() + windowNumber:wNum + context:nil + eventNumber:0 + clickCount:1 + pressure:0.0]; + [NSApp postEvent:motion atStart:NO]; + press = [NSEvent mouseEventWithType:NSLeftMouseDown + location:loc + modifierFlags:0 + timestamp:GetCurrentEventTime() + windowNumber:wNum + context:nil + eventNumber:1 + clickCount:1 + pressure:0.0]; + [NSApp postEvent:press atStart:NO]; + release = [NSEvent mouseEventWithType:NSLeftMouseUp + location:loc + modifierFlags:0 + timestamp:GetCurrentEventTime() + windowNumber:wNum + context:nil + eventNumber:2 + clickCount:1 + pressure:0.0]; + [NSApp postEvent:release atStart:NO]; + return TCL_OK; +} + /* * Local Variables: |