Update to tk 8.5.19

This commit is contained in:
Zachary Ware
2017-11-24 17:53:51 -06:00
parent 27e7dfc7da
commit c67b328f06
325 changed files with 12511 additions and 12047 deletions

View File

@@ -22,6 +22,8 @@
#include "tkMacOSXDebug.h"
#include <Carbon/Carbon.h>
#define DEBUG_ZOMBIES 0
/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_WINDOWS
@@ -55,7 +57,7 @@
/*Objects for use in setting background color and opacity of window.*/
NSColor *colorName = NULL;
NSString *opaqueTag = NULL;
BOOL opaqueTag = FALSE;
static const struct {
const UInt64 validAttrs, defaultAttrs, forceOnAttrs, forceOffAttrs;
@@ -196,6 +198,48 @@ static int tkMacOSXWmAttrNotifyVal = 0;
static Tcl_HashTable windowTable;
static int windowHashInit = false;
#pragma mark NSWindow(TKWm)
/*
* Conversion of coordinates between window and screen.
*/
@implementation NSWindow(TKWm)
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
- (NSPoint) convertPointToScreen: (NSPoint) point
{
return [self convertBaseToScreen:point];
}
- (NSPoint) convertPointFromScreen: (NSPoint)point
{
return [self convertScreenToBase:point];
}
@end
#else
- (NSPoint) convertPointToScreen: (NSPoint) point
{
NSRect pointrect;
pointrect.origin = point;
pointrect.size.width = 0;
pointrect.size.height = 0;
return [self convertRectToScreen:pointrect].origin;
}
- (NSPoint) convertPointFromScreen: (NSPoint)point
{
NSRect pointrect;
pointrect.origin = point;
pointrect.size.width = 0;
pointrect.size.height = 0;
return [self convertRectFromScreen:pointrect].origin;
}
@end
#endif
#pragma mark -
/*
* Forward declarations for procedures defined in this file:
*/
@@ -344,6 +388,7 @@ static void RemapWindows(TkWindow *winPtr,
@end
@implementation TKWindow(TKWm)
- (BOOL) canBecomeKeyWindow
{
TkWindow *winPtr = TkMacOSXGetTkWindow(self);
@@ -353,6 +398,58 @@ static void RemapWindows(TkWindow *winPtr,
kWindowNoActivatesAttribute)) ? NO : YES;
}
#if DEBUG_ZOMBIES
- (id) retain
{
id result = [super retain];
const char *title = [[self title] UTF8String];
if (title == nil) {
title = "unnamed window";
}
if (DEBUG_ZOMBIES > 1){
printf("Retained <%s>. Count is: %lu\n", title, [self retainCount]);
}
return result;
}
- (id) autorelease
{
static int xcount = 0;
id result = [super autorelease];
const char *title = [[self title] UTF8String];
if (title == nil) {
title = "unnamed window";
}
if (DEBUG_ZOMBIES > 1){
printf("Autoreleased <%s>. Count is %lu\n", title, [self retainCount]);
}
return result;
}
- (oneway void) release {
const char *title = [[self title] UTF8String];
if (title == nil) {
title = "unnamed window";
}
if (DEBUG_ZOMBIES > 1){
printf("Releasing <%s>. Count is %lu\n", title, [self retainCount]);
}
[super release];
}
- (void) dealloc {
const char *title = [[self title] UTF8String];
if (title == nil) {
title = "unnamed window";
}
if (DEBUG_ZOMBIES > 0){
printf(">>>> Freeing <%s>. Count is %lu\n", title, [self retainCount]);
}
[super dealloc];
}
#endif
@end
#pragma mark -
@@ -464,28 +561,18 @@ static TkWindow*
FrontWindowAtPoint(
int x, int y)
{
NSPoint p = NSMakePoint(x, tkMacOSXZeroScreenHeight - y);
NSWindow *win = nil;
NSInteger windowCount;
NSInteger *windowNumbers;
NSArray *windows = [NSApp orderedWindows];
TkWindow *front = NULL;
NSCountWindows(&windowCount);
if (windowCount) {
windowNumbers = (NSInteger *) ckalloc(windowCount * sizeof(NSInteger));
NSWindowList(windowCount, windowNumbers);
for (NSInteger index = 0; index < windowCount; index++) {
NSWindow *w = [NSApp windowWithWindowNumber:windowNumbers[index]];
for (NSWindow *w in windows) {
if (w && NSMouseInRect(p, [w frame], NO)) {
win = w;
front = TkMacOSXGetTkWindow(w);
break;
}
}
ckfree((char *) windowNumbers);
}
return (win ? TkMacOSXGetTkWindow(win) : NULL);
return front;
}
/*
*----------------------------------------------------------------------
@@ -681,6 +768,7 @@ TkWmMapWindow(
*/
XMapWindow(winPtr->display, winPtr->window);
}
/*
@@ -703,7 +791,7 @@ TkWmMapWindow(
void
TkWmUnmapWindow(
TkWindow *winPtr) /* Top-level window that's about to be
* mapped. */
* unmapped. */
{
XUnmapWindow(winPtr->display, winPtr->window);
}
@@ -786,17 +874,45 @@ TkWmDeadWindow(
*/
NSWindow *window = wmPtr->window;
if (window && !Tk_IsEmbedded(winPtr) ) {
[[window parentWindow] removeChildWindow:window];
NSWindow *parent = [window parentWindow];
if (parent) {
[parent removeChildWindow:window];
}
[window close];
TkMacOSXUnregisterMacWindow(window);
if (winPtr->window) {
((MacDrawable *)winPtr->window)->view = nil;
if (winPtr->window) {
((MacDrawable *) winPtr->window)->view = nil;
}
#if DEBUG_ZOMBIES > 0
{
const char *title = [[window title] UTF8String];
if (title == nil) {
title = "unnamed window";
}
printf(">>>> Closing <%s>. Count is: %lu\n", title, [window retainCount]);
}
TkMacOSXMakeCollectableAndRelease(wmPtr->window);
}
#endif
[window release];
wmPtr->window = NULL;
ckfree((char *) wmPtr);
/* Activate the highest window left on the screen. */
NSArray *windows = [NSApp orderedWindows];
if ( [windows count] > 0 ) {
NSWindow *front = [windows objectAtIndex:0];
if ( front && [front canBecomeKeyWindow] ) {
[front makeKeyAndOrderFront:NSApp];
}
}
[NSApp _resetAutoreleasePool];
#if DEBUG_ZOMBIES > 0
fprintf(stderr, "================= Pool dump ===================\n");
[NSAutoreleasePool showPools];
#endif
}
ckfree((char *)wmPtr);
winPtr->wmInfoPtr = NULL;
}
@@ -1652,8 +1768,8 @@ WmForgetCmd(
MacDrawable *macWin;
Tk_MakeWindowExist(winPtr);
Tk_MakeWindowExist(winPtr->parentPtr);
Tk_MakeWindowExist(frameWin);
Tk_MakeWindowExist((Tk_Window)winPtr->parentPtr);
macWin = (MacDrawable *) winPtr->window;
@@ -2403,7 +2519,6 @@ WmManageCmd(
register Tk_Window frameWin = (Tk_Window)winPtr;
register WmInfo *wmPtr = winPtr->wmInfoPtr;
char *oldClass = (char*)Tk_Class(frameWin);
if (!Tk_IsTopLevel(frameWin)) {
MacDrawable *macWin = (MacDrawable *) winPtr->window;
@@ -4997,7 +5112,7 @@ TkUnsupported1ObjCmd(
};
Tk_Window tkwin = clientData;
TkWindow *winPtr;
int index;
int index, i;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
@@ -5006,56 +5121,40 @@ TkUnsupported1ObjCmd(
/* Iterate through objc/objv to set correct background color and toggle opacity of window. */
int i;
for (i= 0; i < objc; i++) {
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*black*") == 1) {
colorName = [NSColor blackColor]; // use #000000 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*dark*") == 1) {
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*black*")) {
colorName = [NSColor blackColor]; // use #000000 in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*dark*")) {
colorName = [NSColor darkGrayColor]; //use #545454 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*light*") == 1) {
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*light*")) {
colorName = [NSColor lightGrayColor]; //use #ababab in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*white*")) {
colorName = [NSColor whiteColor]; //use #ffffff in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "gray*")) {
colorName = [NSColor grayColor]; //use #7f7f7f in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*red*")) {
colorName = [NSColor redColor]; //use #ff0000 in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*green*")) {
colorName = [NSColor greenColor]; //use #00ff00 in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*blue*")) {
colorName = [NSColor blueColor]; //use #0000ff in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*cyan*")) {
colorName = [NSColor cyanColor]; //use #00ffff in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*yellow*")) {
colorName = [NSColor yellowColor]; //use #ffff00 in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*magenta*")) {
colorName = [NSColor magentaColor]; //use #ff00ff in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*orange*")) {
colorName = [NSColor orangeColor]; //use #ff8000 in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*purple*")) {
colorName = [NSColor purpleColor]; //use #800080 in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*brown*")){
colorName = [NSColor brownColor]; //use #996633 in Tk scripts to match
} else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*clear*")) {
colorName = [NSColor clearColor]; //use systemTransparent in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*white*") == 1) {
colorName = [NSColor whiteColor]; //use #ffffff in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "gray*") == 1) {
colorName = [NSColor grayColor]; //use #7f7f7f in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*red*") == 1) {
colorName = [NSColor redColor]; //use #ff0000 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*green*") == 1) {
colorName = [NSColor greenColor]; //use #00ff00 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*blue*") == 1) {
colorName = [NSColor blueColor]; //use #0000ff in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*cyan*") == 1) {
colorName = [NSColor cyanColor]; //use #00ffff in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*yellow*") == 1) {
colorName = [NSColor yellowColor]; //use #ffff00 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*magenta*") == 1) {
colorName = [NSColor magentaColor]; //use #ff00ff in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*orange*") == 1) {
colorName = [NSColor orangeColor]; //use #ff8000 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*purple*") == 1) {
colorName = [NSColor purpleColor]; //use #800080 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*brown*") == 1){
colorName = [NSColor brownColor]; //use #996633 in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*clear*") == 1) {
colorName = [NSColor clearColor]; //use systemTransparent in Tk scripts to match
}
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*opacity*") == 1) {
opaqueTag=@"YES";
if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*opacity*")) {
opaqueTag = YES;
}
}
@@ -5174,22 +5273,22 @@ WmWinStyle(
{ "moveToActiveSpace", tkMoveToActiveSpaceAttribute },
{ "nonActivating", tkNonactivatingPanelAttribute },
{ "hud", tkHUDWindowAttribute },
{ "black", NULL },
{ "dark", NULL },
{ "light", NULL },
{ "gray", NULL },
{ "red", NULL },
{ "green", NULL },
{ "blue", NULL },
{ "cyan", NULL },
{ "yellow", NULL },
{ "magenta", NULL },
{ "orange", NULL },
{ "purple", NULL },
{ "brown", NULL },
{ "clear", NULL },
{ "opacity", NULL },
{ "fullscreen", NULL },
{ "black", 0 },
{ "dark", 0 },
{ "light", 0 },
{ "gray", 0 },
{ "red", 0 },
{ "green", 0 },
{ "blue", 0 },
{ "cyan", 0 },
{ "yellow", 0 },
{ "magenta", 0 },
{ "orange", 0 },
{ "purple", 0 },
{ "brown", 0 },
{ "clear", 0 },
{ "opacity", 0 },
{ "fullscreen", 0 },
{ NULL }
};
@@ -5384,7 +5483,6 @@ TkMacOSXMakeRealWindowExist(
* TODO: Here we should handle out of process embedding.
*/
}
WindowClass macClass = wmPtr->macClass;
wmPtr->attributes &= (tkAlwaysValidAttributes |
macClassAttrs[macClass].validAttrs);
@@ -5418,11 +5516,10 @@ TkMacOSXMakeRealWindowExist(
NSWindow *window = [[winClass alloc] initWithContentRect:contentRect
styleMask:styleMask backing:NSBackingStoreBuffered defer:YES];
if (!window) {
Tcl_Panic("couldn't allocate new Mac window");
Tcl_Panic("couldn't allocate new Mac window");
}
TkMacOSXMakeUncollectable(window);
TKContentView *contentView = [[TKContentView alloc]
initWithFrame:NSZeroRect];
initWithFrame:NSZeroRect];
[window setContentView:contentView];
[contentView release];
[window setDelegate:NSApp];
@@ -5447,7 +5544,7 @@ TkMacOSXMakeRealWindowExist(
[window setBackgroundColor: colorName];
}
if (opaqueTag != NULL) {
if (opaqueTag) {
#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD
[window setOpaque: opaqueTag];
#else
@@ -5457,7 +5554,7 @@ TkMacOSXMakeRealWindowExist(
[window setDocumentEdited:NO];
wmPtr->window = window;
macWin->view = contentView;
macWin->view = window.contentView;
TkMacOSXApplyWindowAttributes(winPtr, window);
NSRect geometry = InitialWindowBounds(winPtr, window);
@@ -5466,7 +5563,6 @@ TkMacOSXMakeRealWindowExist(
geometry.origin.y = tkMacOSXZeroScreenHeight - (geometry.origin.y +
geometry.size.height);
[window setFrame:geometry display:NO];
TkMacOSXRegisterOffScreenWindow((Window) macWin, window);
macWin->flags |= TK_HOST_EXISTS;
}
@@ -5855,15 +5951,21 @@ TkpChangeFocus(
* didn't originally belong to topLevelPtr's
* application. */
{
/*
* We don't really need to do anything on the Mac. Tk will keep all this
* state for us.
*/
if (winPtr->atts.override_redirect) {
return 0;
}
if (Tk_IsTopLevel(winPtr) && !Tk_IsEmbedded(winPtr) ){
NSWindow *win = TkMacOSXDrawableWindow(winPtr->window);
TkWmRestackToplevel(winPtr, Above, NULL);
if (force ) {
[NSApp activateIgnoringOtherApps:YES];
}
if ( win && [win canBecomeKeyWindow] ) {
[win makeKeyAndOrderFront:NSApp];
}
}
/*
* Remember the current serial number for the X server and issue a dummy
* server request. This marks the position at which we changed the focus,
@@ -5880,7 +5982,7 @@ TkpChangeFocus(
* WmStackorderToplevelWrapperMap --
*
* This procedure will create a table that maps the reparent wrapper X id
* for a toplevel to the TkWindow structure that is wraps. Tk keeps track
* for a toplevel to the TkWindow structure that it wraps. Tk keeps track
* of a mapping from the window X id to the TkWindow structure but that
* does us no good here since we only get the X id of the wrapper window.
* Only those toplevel windows that are mapped have a position in the
@@ -5939,12 +6041,10 @@ TkWindow **
TkWmStackorderToplevel(
TkWindow *parentPtr) /* Parent toplevel window. */
{
TkWindow *childWinPtr, **windows, **window_ptr;
TkWindow *childWinPtr, **windows, **windowPtr;
Tcl_HashTable table;
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
NSInteger windowCount;
NSInteger *windowNumbers;
/*
* Map mac windows to a TkWindow of the wrapped toplevel.
@@ -5971,31 +6071,26 @@ TkWmStackorderToplevel(
goto done;
}
NSCountWindows(&windowCount);
NSArray *macWindows = [NSApp orderedWindows];
NSInteger windowCount = [macWindows count];
if (!windowCount) {
ckfree((char *) windows);
ckfree((char *)windows);
windows = NULL;
} else {
window_ptr = windows + table.numEntries;
*window_ptr-- = NULL;
windowNumbers = (NSInteger*)ckalloc(windowCount * sizeof(NSInteger));
NSWindowList(windowCount, windowNumbers);
for (NSInteger index = 0; index < windowCount; index++) {
NSWindow *w = [NSApp windowWithWindowNumber:windowNumbers[index]];
if (w) {
hPtr = Tcl_FindHashEntry(&table, (char*) w);
if (hPtr != NULL) {
childWinPtr = Tcl_GetHashValue(hPtr);
*window_ptr-- = childWinPtr;
}
windowPtr = windows + table.numEntries;
*windowPtr-- = NULL;
for (NSWindow *w in macWindows) {
hPtr = Tcl_FindHashEntry(&table, (char*) w);
if (hPtr != NULL) {
childWinPtr = Tcl_GetHashValue(hPtr);
*windowPtr-- = childWinPtr;
}
}
if (window_ptr != (windows-1)) {
if (windowPtr != windows-1) {
Tcl_Panic("num matched toplevel windows does not equal num "
"children");
"children");
}
ckfree((char *) windowNumbers);
}
done:
@@ -6557,7 +6652,6 @@ RemapWindows(
MacDrawable *parentWin)
{
TkWindow *childPtr;
/*
* Remove the OS specific window. It will get rebuilt when the window gets
* Mapped.