summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXWm.c
diff options
context:
space:
mode:
authormarc_culler <marc.culler@gmail.com>2020-09-07 18:54:18 (GMT)
committermarc_culler <marc.culler@gmail.com>2020-09-07 18:54:18 (GMT)
commitc504b8fc55ded70a21166e2d2c8ee960c4cef962 (patch)
tree0da9127b894250f10dd50567b18499ab921802be /macosx/tkMacOSXWm.c
parented3e00f106834b22064086e15e4062321d07b8ca (diff)
parent42fdbf1e581d12fe5d3a33e37b66c2dce3898a17 (diff)
downloadtk-c504b8fc55ded70a21166e2d2c8ee960c4cef962.zip
tk-c504b8fc55ded70a21166e2d2c8ee960c4cef962.tar.gz
tk-c504b8fc55ded70a21166e2d2c8ee960c4cef962.tar.bz2
Fix [39cbacb9e8] and revisit [d72abe6b54] both dealing with inappropriate mouse button events. Refactor mouse event code.
Diffstat (limited to 'macosx/tkMacOSXWm.c')
-rw-r--r--macosx/tkMacOSXWm.c147
1 files changed, 39 insertions, 108 deletions
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index b1998bc..15a7cde 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -193,13 +193,6 @@ static const Tk_GeomMgr wmMgrType = {
static int tkMacOSXWmAttrNotifyVal = 0;
/*
- * Hash table for Mac Window -> TkWindow mapping.
- */
-
-static Tcl_HashTable windowTable;
-static int windowHashInit = false;
-
-/*
* Forward declarations for procedures defined in this file:
*/
@@ -360,11 +353,21 @@ static void RemoveTransient(TkWindow *winPtr);
#pragma mark -
-#pragma mark TKWindow(TKWm)
+@implementation TKPanel: NSPanel
+@synthesize tkWindow = _tkWindow;
+@end
+
+@implementation TKDrawerWindow: NSWindow
+@synthesize tkWindow = _tkWindow;
+@end
@implementation TKWindow: NSWindow
+@synthesize mouseInResizeArea = _mouseInResizeArea;
+@synthesize tkWindow = _tkWindow;
@end
+#pragma mark TKWindow(TKWm)
+
@implementation TKWindow(TKWm)
/*
@@ -885,7 +888,7 @@ TkWmDeadWindow(
TkWindow *winPtr) /* Top-level window that's being deleted. */
{
WmInfo *wmPtr = winPtr->wmInfoPtr, *wmPtr2;
- NSWindow *ourNSWindow;
+ TKWindow *deadNSWindow;
if (wmPtr == NULL) {
return;
@@ -964,27 +967,27 @@ TkWmDeadWindow(
* the parent. Then close and release the NSWindow.
*/
- ourNSWindow = wmPtr->window;
- if (ourNSWindow && !Tk_IsEmbedded(winPtr)) {
- NSWindow *parent = [ourNSWindow parentWindow];
- TkMacOSXUnregisterMacWindow(ourNSWindow);
+ deadNSWindow = (TKWindow *)wmPtr->window;
+ if (deadNSWindow && !Tk_IsEmbedded(winPtr)) {
+ NSWindow *parent = [deadNSWindow parentWindow];
+ [deadNSWindow setTkWindow:None];
if (winPtr->window) {
((MacDrawable *)winPtr->window)->view = nil;
}
wmPtr->window = NULL;
if (parent) {
- [parent removeChildWindow:ourNSWindow];
+ [parent removeChildWindow:deadNSWindow];
}
#if DEBUG_ZOMBIES > 1
{
- const char *title = [[ourNSWindow title] UTF8String];
+ const char *title = [[deadNSWindow title] UTF8String];
if (title == nil) {
title = "unnamed window";
}
fprintf(stderr, ">>>> Closing <%s>. Count is: %lu\n", title,
- [ourNSWindow retainCount]);
+ [deadNSWindow retainCount]);
}
#endif
@@ -1011,7 +1014,7 @@ TkWmDeadWindow(
wmPtr2 = winPtr2->wmInfoPtr;
isOnScreen = (wmPtr2->hints.initial_state != IconicState &&
wmPtr2->hints.initial_state != WithdrawnState);
- if (w != ourNSWindow && isOnScreen && [w canBecomeKeyWindow]) {
+ if (w != deadNSWindow && isOnScreen && [w canBecomeKeyWindow]) {
[w makeKeyAndOrderFront:NSApp];
break;
}
@@ -1021,12 +1024,12 @@ TkWmDeadWindow(
* Prevent zombies on systems with a TouchBar.
*/
- if (ourNSWindow == [NSApp keyWindow]) {
+ if (deadNSWindow == [NSApp keyWindow]) {
[NSApp _setKeyWindow:nil];
[NSApp _setMainWindow:nil];
}
- [ourNSWindow close];
- [ourNSWindow release];
+ [deadNSWindow close];
+ [deadNSWindow release];
[NSApp _resetAutoreleasePool];
#if DEBUG_ZOMBIES > 1
@@ -5382,7 +5385,8 @@ TkGetTransientMaster(
*
* TkMacOSXGetXWindow --
*
- * Returns the X window Id associated with the given NSWindow*.
+ * Stub function that returns the X window Id associated with the
+ * given NSWindow*.
*
* Results:
* The window id is returned. None is returned if not a Tk window.
@@ -5397,16 +5401,9 @@ Window
TkMacOSXGetXWindow(
void *macWinPtr)
{
- Tcl_HashEntry *hPtr;
-
- if (!macWinPtr || !windowHashInit) {
- return None;
- }
- hPtr = Tcl_FindHashEntry(&windowTable, macWinPtr);
- if (hPtr == NULL) {
- return None;
- }
- return (Window) Tcl_GetHashValue(hPtr);
+ TKWindow *w = (TKWindow *)macWinPtr;
+ Window window = (Window) TkMacOSXGetTkWindow(w);
+ return window ? window : None;
}
/*
@@ -5429,11 +5426,14 @@ TkWindow*
TkMacOSXGetTkWindow(
NSWindow *w)
{
- Window window = TkMacOSXGetXWindow(w);
+ Window window = None;
TkDisplay *dispPtr = TkGetDisplayList();
-
+ if ([w respondsToSelector: @selector (tkWindow)]) {
+ window = [(TKWindow *)w tkWindow];
+ }
return (window != None ?
(TkWindow *)Tk_IdToWindow(dispPtr->display, window) : NULL);
+
}
/*
@@ -6110,16 +6110,16 @@ TkMacOSXMakeRealWindowExist(
NSUnifiedTitleAndToolbarWindowMask : 0) |
((attributes & kWindowSideTitlebarAttribute) ? 1 << 9 : 0) |
(attributes >> WM_NSMASK_SHIFT);
- Class winClass = (macClass == kDrawerWindowClass ? [NSDrawerWindow class] :
+ Class winClass = (macClass == kDrawerWindowClass ? [TKDrawerWindow class] :
(styleMask & (NSUtilityWindowMask|NSDocModalWindowMask|
- NSNonactivatingPanelMask|NSHUDWindowMask)) ? [NSPanel class] :
+ NSNonactivatingPanelMask|NSHUDWindowMask)) ? [TKPanel class] :
[TKWindow class]);
NSRect structureRect = [winClass frameRectForContentRect:NSZeroRect
styleMask:styleMask];
NSRect contentRect = NSMakeRect(5 - structureRect.origin.x,
TkMacOSXZeroScreenHeight() - (TkMacOSXZeroScreenTop() + 5 +
structureRect.origin.y + structureRect.size.height + 200), 200, 200);
- NSWindow *window = [[winClass alloc] initWithContentRect:contentRect
+ TKWindow *window = [[winClass alloc] initWithContentRect:contentRect
styleMask:styleMask backing:NSBackingStoreBuffered defer:YES];
if (!window) {
Tcl_Panic("couldn't allocate new Mac window");
@@ -6132,7 +6132,7 @@ TkMacOSXMakeRealWindowExist(
[window setAcceptsMouseMovedEvents:YES];
[window setReleasedWhenClosed:NO];
if (styleMask & NSUtilityWindowMask) {
- [(NSPanel*)window setFloatingPanel:YES];
+ [(TKPanel*)window setFloatingPanel:YES];
}
if ((styleMask & (NSTexturedBackgroundWindowMask|NSHUDWindowMask)) &&
!(styleMask & NSDocModalWindowMask)) {
@@ -6152,7 +6152,7 @@ TkMacOSXMakeRealWindowExist(
geometry.origin.y = TkMacOSXZeroScreenHeight() - (geometry.origin.y +
geometry.size.height);
[window setFrame:geometry display:YES];
- TkMacOSXRegisterOffScreenWindow((Window) macWin, window);
+ [window setTkWindow: (Window) macWin];
macWin->flags |= TK_HOST_EXISTS;
if (overrideRedirect) {
@@ -6205,75 +6205,6 @@ TkpRedrawWidget(Tk_Window tkwin) {
}
}
-/*
- *----------------------------------------------------------------------
- *
- * TkMacOSXRegisterOffScreenWindow --
- *
- * This function adds the passed in Off Screen Port to the hash table that
- * maps Mac windows to root X windows.
- *
- * Results:
- * None.
- *
- * Side effects:
- * An entry is added to the windowTable hash table.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TkMacOSXRegisterOffScreenWindow(
- Window window, /* Window structure. */
- void *portPtr) /* Pointer to a Mac Window. */
-{
- Tcl_HashEntry *valueHashPtr;
- int isNew;
-
- if (!windowHashInit) {
- Tcl_InitHashTable(&windowTable, TCL_ONE_WORD_KEYS);
- windowHashInit = true;
- }
- valueHashPtr = Tcl_CreateHashEntry(&windowTable, (char *) portPtr, &isNew);
- if (!isNew) {
- Tcl_Panic("Same macintosh window allocated twice!");
- }
- Tcl_SetHashValue(valueHashPtr, window);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TkMacOSXUnregisterMacWindow --
- *
- * Given a macintosh port window, this function removes the association
- * between this window and the root X window that Tk cares about.
- *
- * Results:
- * None.
- *
- * Side effects:
- * An entry is removed from the windowTable hash table.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TkMacOSXUnregisterMacWindow(
- void *macWinPtr) /* Reference to a Mac Window */
-{
- Tcl_HashEntry *entryPtr;
-
- if (!windowHashInit) {
- Tcl_Panic("TkMacOSXUnregisterMacWindow: unmapping before inited");
- }
- entryPtr = Tcl_FindHashEntry(&windowTable, macWinPtr);
- if (!entryPtr) {
- TkMacOSXDbgMsg("Failed to find window %p", macWinPtr);
- } else {
- Tcl_DeleteHashEntry(entryPtr);
- }
-}
/*
*----------------------------------------------------------------------
@@ -6884,7 +6815,7 @@ ApplyWindowAttributeFlagChanges(
if ((wmPtr->flags & WM_TOPMOST) != (oldFlags & WM_TOPMOST)) {
[macWindow setLevel:(wmPtr->flags & WM_TOPMOST) ?
kCGUtilityWindowLevel : ([macWindow isKindOfClass:
- [NSPanel class]] && [macWindow isFloatingPanel] ?
+ [TKPanel class]] && [macWindow isFloatingPanel] ?
kCGFloatingWindowLevel : kCGNormalWindowLevel)];
}