Import Tk 8.6.10

This commit is contained in:
Steve Dower
2020-09-24 22:55:34 +01:00
parent 5ba5cbc9af
commit 42c69189d9
365 changed files with 24323 additions and 12832 deletions

View File

@@ -49,7 +49,7 @@ static void NotifyVisibility(TkWindow *winPtr, XEvent *eventPtr);
*----------------------------------------------------------------------
*/
void
int
XDestroyWindow(
Display *display, /* Display. */
Window window) /* Window. */
@@ -65,35 +65,41 @@ XDestroyWindow(
TkMacOSXSelDeadWindow(macWin->winPtr);
macWin->toplevel->referenceCount--;
if (!Tk_IsTopLevel(macWin->winPtr) ) {
if (!Tk_IsTopLevel(macWin->winPtr)) {
TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
if (macWin->winPtr->parentPtr != NULL) {
TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr);
}
if (macWin->visRgn) {
CFRelease(macWin->visRgn);
macWin->visRgn = NULL;
}
if (macWin->aboveVisRgn) {
CFRelease(macWin->aboveVisRgn);
macWin->aboveVisRgn = NULL;
}
if (macWin->drawRgn) {
CFRelease(macWin->drawRgn);
macWin->drawRgn = NULL;
}
if (macWin->toplevel->referenceCount == 0) {
ckfree(macWin->toplevel);
}
ckfree(macWin);
return;
return Success;
}
if (macWin->visRgn) {
CFRelease(macWin->visRgn);
macWin->visRgn = NULL;
}
if (macWin->aboveVisRgn) {
CFRelease(macWin->aboveVisRgn);
macWin->aboveVisRgn = NULL;
}
if (macWin->drawRgn) {
CFRelease(macWin->drawRgn);
macWin->drawRgn = NULL;
}
macWin->view = nil;
@@ -105,6 +111,7 @@ XDestroyWindow(
if (macWin->toplevel->referenceCount == 0) {
ckfree(macWin->toplevel);
}
return Success;
}
/*
@@ -124,12 +131,14 @@ XDestroyWindow(
*----------------------------------------------------------------------
*/
void
int
XMapWindow(
Display *display, /* Display. */
Window window) /* Window. */
{
MacDrawable *macWin = (MacDrawable *) window;
TkWindow *winPtr = macWin->winPtr;
NSWindow *win = TkMacOSXDrawableWindow(window);
XEvent event;
/*
@@ -145,33 +154,40 @@ XMapWindow(
}
display->request++;
macWin->winPtr->flags |= TK_MAPPED;
if (Tk_IsTopLevel(macWin->winPtr)) {
if (!Tk_IsEmbedded(macWin->winPtr)) {
NSWindow *win = TkMacOSXDrawableWindow(window);
winPtr->flags |= TK_MAPPED;
if (Tk_IsTopLevel(winPtr)) {
if (!Tk_IsEmbedded(winPtr)) {
/*
* We want to activate Tk when a toplevel is mapped
* but we must not supply YES here. This is because
* during Tk initialization the root window is mapped
* before applicationDidFinishLaunching returns. Forcing
* the app to activate too early can make the menu bar
* unresponsive.
* We want to activate Tk when a toplevel is mapped but we must not
* supply YES here. This is because during Tk initialization the
* root window is mapped before applicationDidFinishLaunching
* returns. Forcing the app to activate too early can make the menu
* bar unresponsive.
*/
TkMacOSXApplyWindowAttributes(winPtr, win);
[win setExcludedFromWindowsMenu:NO];
[NSApp activateIgnoringOtherApps:NO];
if ( [win canBecomeKeyWindow] ) {
[[win contentView] setNeedsDisplay:YES];
if ([win canBecomeKeyWindow]) {
[win makeKeyAndOrderFront:NSApp];
} else {
[win orderFrontRegardless];
}
TkMacOSXApplyWindowAttributes(macWin->winPtr, win);
} else {
TkWindow *contWinPtr = TkpGetOtherWindow(winPtr);
/*
* Rebuild the container's clipping region and display
* the window.
*/
TkWindow *contWinPtr = TkpGetOtherWindow(macWin->winPtr);
TkMacOSXInvalClipRgns((Tk_Window)contWinPtr);
TkMacOSXInvalClipRgns((Tk_Window) contWinPtr);
TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
}
TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr);
TkMacOSXInvalClipRgns((Tk_Window) winPtr);
/*
* We only need to send the MapNotify event for toplevel windows.
@@ -184,16 +200,22 @@ XMapWindow(
event.xmap.window = window;
event.xmap.type = MapNotify;
event.xmap.event = window;
event.xmap.override_redirect = macWin->winPtr->atts.override_redirect;
event.xmap.override_redirect = winPtr->atts.override_redirect;
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
} else {
/*
* Rebuild the parent's clipping region and display the window.
*
* For non-toplevel windows, rebuild the parent's clipping region
* and redisplay the window.
*/
TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr);
TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr);
}
if ([NSApp isDrawing]) {
[[win contentView] setNeedsRedisplay:YES];
} else {
[[win contentView] setNeedsDisplay:YES];
}
/*
@@ -204,14 +226,8 @@ XMapWindow(
event.xany.display = display;
event.xvisibility.type = VisibilityNotify;
event.xvisibility.state = VisibilityUnobscured;
NotifyVisibility(macWin->winPtr, &event);
/*
* Make sure that subwindows get displayed.
*/
GenerateConfigureNotify(macWin->winPtr, 1);
NotifyVisibility(winPtr, &event);
return Success;
}
/*
@@ -265,7 +281,7 @@ NotifyVisibility(
*----------------------------------------------------------------------
*/
void
int
XUnmapWindow(
Display *display, /* Display. */
Window window) /* Window. */
@@ -273,18 +289,14 @@ XUnmapWindow(
MacDrawable *macWin = (MacDrawable *) window;
TkWindow *winPtr = macWin->winPtr;
TkWindow *parentPtr = winPtr->parentPtr;
NSWindow *win = TkMacOSXDrawableWindow(window);
XEvent event;
display->request++;
if (Tk_IsTopLevel(winPtr)) {
if (!Tk_IsEmbedded(winPtr) &&
winPtr->wmInfoPtr->hints.initial_state!=IconicState) {
NSWindow *win = TkMacOSXDrawableWindow(window);
if ([win isVisible]) {
[[win parentWindow] removeChildWindow:win];
[win orderOut:NSApp];
}
[win orderOut:nil];
}
TkMacOSXInvalClipRgns((Tk_Window) winPtr);
@@ -302,20 +314,27 @@ XUnmapWindow(
event.xunmap.from_configure = false;
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
} else {
/*
* Rebuild the visRgn clip region for the parent so it will be allowed
* to draw in the space from which this subwindow was removed.
* to draw in the space from which this subwindow was removed and then
* redraw the window.
*/
if (parentPtr && parentPtr->privatePtr->visRgn) {
TkMacOSXInvalidateViewRegion(TkMacOSXDrawableView(parentPtr->privatePtr),
parentPtr->privatePtr->visRgn);
TkMacOSXInvalidateViewRegion(
TkMacOSXDrawableView(parentPtr->privatePtr),
parentPtr->privatePtr->visRgn);
}
TkMacOSXInvalClipRgns((Tk_Window) parentPtr);
TkMacOSXUpdateClipRgn(parentPtr);
}
winPtr->flags &= ~TK_MAPPED;
if ([NSApp isDrawing]) {
[[win contentView] setNeedsRedisplay:YES];
} else {
[[win contentView] setNeedsDisplay:YES];
}
return Success;
}
/*
@@ -335,7 +354,7 @@ XUnmapWindow(
*----------------------------------------------------------------------
*/
void
int
XResizeWindow(
Display *display, /* Display. */
Window window, /* Window. */
@@ -343,11 +362,14 @@ XResizeWindow(
unsigned int height)
{
MacDrawable *macWin = (MacDrawable *) window;
display->request++;
if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
NSWindow *w = macWin->winPtr->wmInfoPtr->window;
if (w) {
NSRect r = [w contentRectForFrameRect:[w frame]];
r.origin.y += r.size.height - height;
r.size.width = width;
r.size.height = height;
@@ -356,6 +378,7 @@ XResizeWindow(
} else {
MoveResizeWindow(macWin);
}
return Success;
}
/*
@@ -363,8 +386,8 @@ XResizeWindow(
*
* XMoveResizeWindow --
*
* Move or resize a given X window. See X windows documentation
* for further details.
* Move or resize a given X window. See X windows documentation for
* further details.
*
* Results:
* None.
@@ -375,7 +398,7 @@ XResizeWindow(
*----------------------------------------------------------------------
*/
void
int
XMoveResizeWindow(
Display *display, /* Display. */
Window window, /* Window. */
@@ -388,27 +411,30 @@ XMoveResizeWindow(
display->request++;
if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
NSWindow *w = macWin->winPtr->wmInfoPtr->window;
if (w) {
/* We explicitly convert everything to doubles so we don't get
if (w) {
/*
* We explicitly convert everything to doubles so we don't get
* surprised (again) by what happens when you do arithmetic with
* unsigned ints.
*/
CGFloat X = (CGFloat)x;
CGFloat Y = (CGFloat)y;
CGFloat Width = (CGFloat)width;
CGFloat Height = (CGFloat)height;
CGFloat XOff = (CGFloat)macWin->winPtr->wmInfoPtr->xInParent;
CGFloat YOff = (CGFloat)macWin->winPtr->wmInfoPtr->yInParent;
NSRect r = NSMakeRect(X + XOff,
tkMacOSXZeroScreenHeight - Y - YOff - Height,
Width, Height);
CGFloat X = (CGFloat) x;
CGFloat Y = (CGFloat) y;
CGFloat Width = (CGFloat) width;
CGFloat Height = (CGFloat) height;
CGFloat XOff = (CGFloat) macWin->winPtr->wmInfoPtr->xInParent;
CGFloat YOff = (CGFloat) macWin->winPtr->wmInfoPtr->yInParent;
NSRect r = NSMakeRect(
X + XOff, TkMacOSXZeroScreenHeight() - Y - YOff - Height,
Width, Height);
[w setFrame:[w frameRectForContentRect:r] display:YES];
}
} else {
MoveResizeWindow(macWin);
}
return Success;
}
/*
@@ -416,8 +442,7 @@ XMoveResizeWindow(
*
* XMoveWindow --
*
* Move a given X window. See X windows documentation for further
* details.
* Move a given X window. See X windows documentation for further details.
*
* Results:
* None.
@@ -428,7 +453,7 @@ XMoveResizeWindow(
*----------------------------------------------------------------------
*/
void
int
XMoveWindow(
Display *display, /* Display. */
Window window, /* Window. */
@@ -439,12 +464,15 @@ XMoveWindow(
display->request++;
if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
NSWindow *w = macWin->winPtr->wmInfoPtr->window;
if (w) {
[w setFrameTopLeftPoint:NSMakePoint(x, tkMacOSXZeroScreenHeight - y)];
[w setFrameTopLeftPoint: NSMakePoint(
x, TkMacOSXZeroScreenHeight() - y)];
}
} else {
MoveResizeWindow(macWin);
}
return Success;
}
/*
@@ -481,7 +509,6 @@ MoveResizeWindow(
if (contWinPtr) {
macParent = contWinPtr->privatePtr;
} else {
/*
* Here we should handle out of process embedding. At this point,
* we are assuming that the changes.x,y is not maintained, if you
@@ -490,7 +517,6 @@ MoveResizeWindow(
*/
}
} else {
/*
* TODO: update all xOff & yOffs
*/
@@ -571,7 +597,7 @@ GenerateConfigureNotify(
*----------------------------------------------------------------------
*/
void
int
XRaiseWindow(
Display *display, /* Display. */
Window window) /* Window. */
@@ -582,11 +608,11 @@ XRaiseWindow(
if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
TkWmRestackToplevel(macWin->winPtr, Above, NULL);
} else {
/*
* TODO: this should generate damage
*/
}
return Success;
}
#if 0
@@ -617,7 +643,6 @@ XLowerWindow(
if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
TkWmRestackToplevel(macWin->winPtr, Below, NULL);
} else {
/*
* TODO: this should generate damage
*/
@@ -643,7 +668,7 @@ XLowerWindow(
*----------------------------------------------------------------------
*/
void
int
XConfigureWindow(
Display *display, /* Display. */
Window w, /* Window. */
@@ -680,14 +705,17 @@ XConfigureWindow(
TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr);
TkMacOSXWinBounds(winPtr, &bounds);
r = NSMakeRect(bounds.left,
[view bounds].size.height - bounds.bottom,
bounds.right - bounds.left, bounds.bottom - bounds.top);
[view bounds].size.height - bounds.bottom,
bounds.right - bounds.left, bounds.bottom - bounds.top);
[view setNeedsDisplayInRect:r];
}
}
/* TkGenWMMoveRequestEvent(macWin->winPtr,
macWin->winPtr->changes.x, macWin->winPtr->changes.y); */
#if 0
TkGenWMMoveRequestEvent(macWin->winPtr,
macWin->winPtr->changes.x, macWin->winPtr->changes.y);
#endif
return Success;
}
/*
@@ -709,14 +737,14 @@ XConfigureWindow(
void
TkMacOSXSetDrawingEnabled(
TkWindow *winPtr,
int flag)
TkWindow *winPtr,
int flag)
{
TkWindow *childPtr;
MacDrawable *macWin = winPtr->privatePtr;
if (macWin) {
if (flag ) {
if (flag) {
macWin->flags &= ~TK_DO_NOT_DRAW;
} else {
macWin->flags |= TK_DO_NOT_DRAW;
@@ -724,8 +752,8 @@ TkMacOSXSetDrawingEnabled(
}
/*
* Set the flag for all children & their descendants, excluding
* Toplevels. (??? Do we need to exclude Toplevels?)
* Set the flag for all children & their descendants, excluding Toplevels.
* (??? Do we need to exclude Toplevels?)
*/
childPtr = winPtr->childList;
@@ -889,7 +917,6 @@ TkMacOSXUpdateClipRgn(
}
CFRelease(rgn);
} else {
/*
* An unmapped window has empty clip regions to prevent any
* (erroneous) drawing into it or its children from becoming
@@ -919,8 +946,8 @@ TkMacOSXUpdateClipRgn(
* TkMacOSXVisableClipRgn --
*
* This function returns the Macintosh clipping region for the given
* window. The caller is responsible for disposing of the returned
* region via TkDestroyRegion().
* window. The caller is responsible for disposing of the returned region
* via TkDestroyRegion().
*
* Results:
* The region.
@@ -938,7 +965,7 @@ TkMacOSXVisableClipRgn(
if (winPtr->privatePtr->flags & TK_CLIP_INVALID) {
TkMacOSXUpdateClipRgn(winPtr);
}
return (TkRegion)HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn);
return (TkRegion) HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn);
}
/*
@@ -958,7 +985,12 @@ TkMacOSXVisableClipRgn(
*/
static OSStatus
InvalViewRect(int msg, HIShapeRef rgn, const CGRect *rect, void *ref) {
InvalViewRect(
int msg,
HIShapeRef rgn,
const CGRect *rect,
void *ref)
{
static CGAffineTransform t;
NSView *view = ref;
@@ -1038,7 +1070,7 @@ TkMacOSXInvalidateWindow(
*----------------------------------------------------------------------
*/
NSWindow*
NSWindow *
TkMacOSXDrawableWindow(
Drawable drawable)
{
@@ -1056,6 +1088,7 @@ TkMacOSXDrawableWindow(
result = macWin->winPtr->wmInfoPtr->window;
} else if (macWin->toplevel && (macWin->toplevel->flags & TK_EMBEDDED)) {
TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr);
if (contWinPtr) {
result = TkMacOSXDrawableWindow((Drawable) contWinPtr->privatePtr);
}
@@ -1109,7 +1142,7 @@ TkMacOSXGetDrawablePort(
*----------------------------------------------------------------------
*/
NSView*
NSView *
TkMacOSXDrawableView(
MacDrawable *macWin)
{
@@ -1123,6 +1156,7 @@ TkMacOSXDrawableView(
result = macWin->toplevel->view;
} else {
TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr);
if (contWinPtr) {
result = TkMacOSXDrawableView(contWinPtr->privatePtr);
}
@@ -1150,7 +1184,6 @@ void *
TkMacOSXGetRootControl(
Drawable drawable)
{
/*
* will probably need to fix this up for embedding
*/
@@ -1267,7 +1300,8 @@ TkMacOSXWinBounds(
TkWindow *winPtr,
void *bounds)
{
Rect *b = (Rect *)bounds;
Rect *b = (Rect *) bounds;
b->left = winPtr->privatePtr->xOff;
b->top = winPtr->privatePtr->yOff;
b->right = b->left + winPtr->changes.width;
@@ -1310,7 +1344,7 @@ TkMacOSXWinCGBounds(
* UpdateOffsets --
*
* Updates the X & Y offsets of the given TkWindow from the TopLevel it is
* a decendant of.
* a descendant of.
*
* Results:
* None.
@@ -1331,7 +1365,6 @@ UpdateOffsets(
TkWindow *childPtr;
if (winPtr->privatePtr == NULL) {
/*
* We haven't called Tk_MakeWindowExist for this window yet. The offset
* information will be postponed and calulated at that time. (This will