Import Tk 8.6.10
This commit is contained in:
@@ -13,13 +13,19 @@
|
||||
*/
|
||||
|
||||
#include "tkMacOSXPrivate.h"
|
||||
#include "tkMacOSXConstants.h"
|
||||
|
||||
/*
|
||||
* Forward declarations of procedures defined later in this file:
|
||||
*/
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1080
|
||||
static int DebuggerObjCmd (ClientData dummy, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *const objv[]);
|
||||
int objc, Tcl_Obj *const objv[]);
|
||||
#endif
|
||||
static int PressButtonObjCmd (ClientData dummy, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *const objv[]);
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
@@ -46,8 +52,10 @@ TkplatformtestInit(
|
||||
* Add commands for platform specific tests on MacOS here.
|
||||
*/
|
||||
|
||||
Tcl_CreateObjCommand(interp, "debugger", DebuggerObjCmd,
|
||||
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
||||
#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;
|
||||
}
|
||||
@@ -57,7 +65,8 @@ TkplatformtestInit(
|
||||
*
|
||||
* DebuggerObjCmd --
|
||||
*
|
||||
* This procedure simply calls the low level debugger.
|
||||
* This procedure simply calls the low level debugger, which was
|
||||
* deprecated in OSX 10.8.
|
||||
*
|
||||
* Results:
|
||||
* A standard Tcl result.
|
||||
@@ -68,6 +77,7 @@ TkplatformtestInit(
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1080
|
||||
static int
|
||||
DebuggerObjCmd(
|
||||
ClientData clientData, /* Not used. */
|
||||
@@ -78,34 +88,136 @@ DebuggerObjCmd(
|
||||
Debugger();
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
* TkTestSimulateDrawing --
|
||||
*
|
||||
* A test widget display procedure which records calls can use this to
|
||||
* avoid duplicate calls which would occur due to fact that no valid
|
||||
* graphics context is available to the idle task which is running the
|
||||
* display proc. Note that no actual drawing to the screen will take
|
||||
* place when this flag is set. This is just a wrapper for the NSApp
|
||||
* property.
|
||||
* TkTestLogDisplay --
|
||||
*
|
||||
* The test image display procedure calls this to determine whether it
|
||||
* should write a log message recording that it has being run. On OSX
|
||||
* 10.14 and later, only calls to the display procedure which occur inside
|
||||
* of the drawRect method should be logged, since those are the only ones
|
||||
* which actually draw anything. On earlier systems the opposite is true.
|
||||
* The calls from within the drawRect method are redundant, since the
|
||||
* first time the display procedure is run it will do the drawing and that
|
||||
* first call will usually not occur inside of drawRect.
|
||||
*
|
||||
* Results:
|
||||
* Calls to low level drawing routines will return without actually
|
||||
* drawing anything to the screen.
|
||||
* On OSX 10.14 and later, returns true if and only if called from
|
||||
* within [NSView drawRect]. On earlier systems returns false if
|
||||
* and only if called from with [NSView drawRect].
|
||||
*
|
||||
* Side effects:
|
||||
* None
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
MODULE_SCOPE void
|
||||
TkTestSimulateDrawing(Bool yesno) {
|
||||
[NSApp setSimulateDrawing:yesno];
|
||||
MODULE_SCOPE Bool
|
||||
TkTestLogDisplay(void) {
|
||||
if ([NSApp macMinorVersion] >= 14) {
|
||||
return [NSApp isDrawing];
|
||||
} else {
|
||||
return ![NSApp isDrawing];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user