diff options
Diffstat (limited to 'macosx/tkMacOSXWm.c')
-rw-r--r-- | macosx/tkMacOSXWm.c | 3634 |
1 files changed, 1855 insertions, 1779 deletions
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 7b95a2e..1f4e2e2 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -2,13 +2,14 @@ * tkMacOSXWm.c -- * * This module takes care of the interactions between a Tk-based - * application and the window manager. Among other things, it - * implements the "wm" command and passes geometry information - * to the window manager. + * application and the window manager. Among other things, it implements + * the "wm" command and passes geometry information to the window + * manager. * * Copyright (c) 1994-1997 Sun Microsystems, Inc. - * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright 2001-2009, Apple Inc. + * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright (c) 2010 Kevin Walzer/WordTech Communications LLC. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -27,57 +28,165 @@ */ /* + * Window attributes and classes + */ + +#define WM_NSMASK_SHIFT 36 +#define tkWindowDoesNotHideAttribute \ + ((UInt64) 1 << kHIWindowBitDoesNotHide) +#define tkCanJoinAllSpacesAttribute \ + ((UInt64) NSWindowCollectionBehaviorCanJoinAllSpaces << 34) +#define tkMoveToActiveSpaceAttribute \ + ((UInt64) NSWindowCollectionBehaviorMoveToActiveSpace << 34) +#define tkNonactivatingPanelAttribute \ + ((UInt64) NSNonactivatingPanelMask << WM_NSMASK_SHIFT) +#define tkHUDWindowAttribute \ + ((UInt64) NSHUDWindowMask << WM_NSMASK_SHIFT) +#define tkAlwaysValidAttributes (kWindowNoUpdatesAttribute \ + | kWindowNoActivatesAttribute | kWindowHideOnSuspendAttribute \ + | kWindowHideOnFullScreenAttribute | kWindowNoConstrainAttribute \ + | kWindowNoShadowAttribute | kWindowLiveResizeAttribute \ + | kWindowOpaqueForEventsAttribute | kWindowIgnoreClicksAttribute \ + | kWindowDoesNotCycleAttribute | tkWindowDoesNotHideAttribute \ + | tkCanJoinAllSpacesAttribute | tkMoveToActiveSpaceAttribute \ + | tkNonactivatingPanelAttribute | tkHUDWindowAttribute) + + +/*Objects for use in setting background color and opacity of window.*/ +NSColor *colorName = NULL; +NSString *opaqueTag = NULL; + +static const struct { + const UInt64 validAttrs, defaultAttrs, forceOnAttrs, forceOffAttrs; + int flags; NSUInteger styleMask; +} macClassAttrs[] = { + [kAlertWindowClass] = { + .defaultAttrs = kWindowDoesNotCycleAttribute, }, + [kMovableAlertWindowClass] = { + .defaultAttrs = kWindowDoesNotCycleAttribute, }, + [kModalWindowClass] = { + .defaultAttrs = kWindowDoesNotCycleAttribute, }, + [kMovableModalWindowClass] = { + .validAttrs = kWindowCloseBoxAttribute | kWindowMetalAttribute | + kWindowFullZoomAttribute | kWindowResizableAttribute, + .defaultAttrs = kWindowDoesNotCycleAttribute, }, + [kFloatingWindowClass] = { + .validAttrs = kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | + kWindowMetalAttribute | kWindowToolbarButtonAttribute | + kWindowNoTitleBarAttribute | kWindowFullZoomAttribute | + kWindowResizableAttribute | kWindowSideTitlebarAttribute, + .defaultAttrs = kWindowStandardFloatingAttributes | + kWindowHideOnSuspendAttribute | kWindowDoesNotCycleAttribute, + .forceOnAttrs = kWindowResizableAttribute, + .forceOffAttrs = kWindowCollapseBoxAttribute, + .styleMask = NSUtilityWindowMask, }, + [kDocumentWindowClass] = { + .validAttrs = kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | + kWindowMetalAttribute | kWindowToolbarButtonAttribute | + kWindowNoTitleBarAttribute | + kWindowUnifiedTitleAndToolbarAttribute | + kWindowInWindowMenuAttribute | kWindowFullZoomAttribute | + kWindowResizableAttribute, + .forceOnAttrs = kWindowResizableAttribute, + .defaultAttrs = kWindowStandardDocumentAttributes | + kWindowLiveResizeAttribute | kWindowInWindowMenuAttribute, }, + [kUtilityWindowClass] = { + .validAttrs = kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | + kWindowMetalAttribute | kWindowToolbarButtonAttribute | + kWindowNoTitleBarAttribute | kWindowFullZoomAttribute | + kWindowResizableAttribute | kWindowSideTitlebarAttribute, + .defaultAttrs = kWindowStandardFloatingAttributes | + kWindowHideOnFullScreenAttribute | + tkWindowDoesNotHideAttribute | tkNonactivatingPanelAttribute | + kWindowDoesNotCycleAttribute, + .forceOnAttrs = kWindowResizableAttribute, + .forceOffAttrs = kWindowCollapseBoxAttribute, + .flags = WM_TOPMOST, + .styleMask = NSUtilityWindowMask, }, + [kHelpWindowClass] = { + .defaultAttrs = kWindowHideOnSuspendAttribute, + .forceOnAttrs = kWindowNoTitleBarAttribute | + kWindowDoesNotCycleAttribute, + .flags = WM_TOPMOST, }, + [kSheetWindowClass] = { + .validAttrs = kWindowResizableAttribute, + .forceOnAttrs = kWindowNoTitleBarAttribute | + kWindowDoesNotCycleAttribute, + .styleMask = NSDocModalWindowMask, }, + [kToolbarWindowClass] = { + .defaultAttrs = kWindowHideOnSuspendAttribute, + .forceOnAttrs = kWindowNoTitleBarAttribute | + kWindowDoesNotCycleAttribute, + .styleMask = NSUtilityWindowMask, }, + [kPlainWindowClass] = { + .defaultAttrs = kWindowDoesNotCycleAttribute, + .forceOnAttrs = kWindowNoTitleBarAttribute, }, + [kOverlayWindowClass] = { + .forceOnAttrs = kWindowNoTitleBarAttribute | + kWindowDoesNotCycleAttribute, + .flags = WM_TOPMOST | WM_TRANSPARENT, }, + [kSheetAlertWindowClass] = { + .forceOnAttrs = kWindowNoTitleBarAttribute | + kWindowDoesNotCycleAttribute, + .styleMask = NSDocModalWindowMask, }, + [kAltPlainWindowClass] = { + .defaultAttrs = kWindowDoesNotCycleAttribute, + .forceOnAttrs = kWindowNoTitleBarAttribute, }, + [kSimpleWindowClass] = { + .defaultAttrs = kWindowDoesNotCycleAttribute, + .forceOnAttrs = kWindowNoTitleBarAttribute, }, + [kDrawerWindowClass] = { + .validAttrs = kWindowMetalAttribute | kWindowResizableAttribute, + .forceOnAttrs = kWindowNoTitleBarAttribute | + kWindowDoesNotCycleAttribute, }, +}; + +#define ForceAttributes(attributes, class) \ + ((attributes) & (~macClassAttrs[(class)].forceOffAttrs | \ + (macClassAttrs[(class)].forceOnAttrs & ~kWindowResizableAttribute))) + +/* * Data for [wm attributes] command: */ + typedef enum { - WMATT_ALPHA, WMATT_FULLSCREEN, WMATT_MODIFIED,/* WMATT_NOTIFY,*/ + WMATT_ALPHA, WMATT_FULLSCREEN, WMATT_MODIFIED, WMATT_NOTIFY, WMATT_TITLEPATH, WMATT_TOPMOST, WMATT_TRANSPARENT, _WMATT_LAST_ATTRIBUTE } WmAttribute; -static const char *WmAttributeNames[] = { - "-alpha", "-fullscreen", "-modified",/* "-notify",*/ +static const char *const WmAttributeNames[] = { + "-alpha", "-fullscreen", "-modified", "-notify", "-titlepath", "-topmost", "-transparent", NULL }; /* - * This is a list of all of the toplevels that have been mapped so far. It is - * used by the menu code to inval windows that were damaged by menus, and will - * eventually also be used to keep track of floating windows. - */ - -TkMacOSXWindowList *tkMacOSXWindowListPtr = NULL; - -/* - * The variable below is used to enable or disable tracing in this - * module. If tracing is enabled, then information is printed on - * standard output about interesting interactions with the window - * manager. + * The variable below is used to enable or disable tracing in this module. If + * tracing is enabled, then information is printed on standard output about + * interesting interactions with the window manager. */ static int wmTracing = 0; /* - * The following structure is the official type record for geometry - * management of top-level windows. + * The following structure is the official type record for geometry management + * of top-level windows. */ static void TopLevelReqProc(ClientData dummy, Tk_Window tkwin); -static /* const */ Tk_GeomMgr wmMgrType = { - "wm", /* name */ - TopLevelReqProc, /* requestProc */ - (Tk_GeomLostSlaveProc *) NULL, /* lostSlaveProc */ +static const Tk_GeomMgr wmMgrType = { + "wm", /* name */ + TopLevelReqProc, /* requestProc */ + NULL, /* lostSlaveProc */ }; /* * The following keeps state for Aqua dock icon bounce notification. */ -#if 0 static int tkMacOSXWmAttrNotifyVal = 0; -#endif /* * Hash table for Mac Window -> TkWindow mapping. @@ -90,106 +199,295 @@ static int windowHashInit = false; * Forward declarations for procedures defined in this file: */ -static void InitialWindowBounds(TkWindow *winPtr, WindowRef macWindow, - Rect *geometry); -static int ParseGeometry(Tcl_Interp *interp, char *string, TkWindow *winPtr); -static void TopLevelEventProc(ClientData clientData, XEvent *eventPtr); -static void WmStackorderToplevelWrapperMap(TkWindow *winPtr, Display *display, - Tcl_HashTable *table); -static void UpdateGeometryInfo(ClientData clientData); -static void UpdateSizeHints(TkWindow *winPtr); -static void UpdateVRootGeometry(WmInfo *wmPtr); -static int WmAspectCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmAttributesCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmClientCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmColormapwindowsCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmCommandCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmDeiconifyCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmFocusmodelCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -#if 0 -static int WmForgetCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -#endif -static int WmFrameCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmGeometryCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmGridCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmGroupCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmIconbitmapCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmIconifyCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmIconmaskCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmIconnameCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmIconpositionCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmIconwindowCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -#if 0 -static int WmManageCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -#endif -static int WmMaxsizeCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmMinsizeCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmOverrideredirectCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmPositionfromCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmStateCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static int WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -static int WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp, - int objc, Tcl_Obj *const objv[]); -static void WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr); -static int WmWinStyle(Tcl_Interp *interp, TkWindow *winPtr, int objc, - Tcl_Obj * const objv[]); -static void ApplyWindowClassAttributeChanges(TkWindow *winPtr, - WindowRef macWindow, WindowClass oldClass, - WindowAttributes oldAttributes, int create); -static void ApplyMasterOverrideChanges(TkWindow *winPtr, WindowRef macWindow); -static WindowGroupRef WmGetWindowGroup(TkWindow *winPtr); -static void GetMinSize(TkWindow *winPtr, int *minWidthPtr, int *minHeightPtr); -static void GetMaxSize(TkWindow *winPtr, int *maxWidthPtr, int *maxHeightPtr); -#if 0 -static void RemapWindows(TkWindow *winPtr, MacDrawable *parentWin); +static NSRect InitialWindowBounds(TkWindow *winPtr, + NSWindow *macWindow); +static int ParseGeometry(Tcl_Interp *interp, char *string, + TkWindow *winPtr); +static void TopLevelEventProc(ClientData clientData, + XEvent *eventPtr); +static void WmStackorderToplevelWrapperMap(TkWindow *winPtr, + Display *display, Tcl_HashTable *table); +static void UpdateGeometryInfo(ClientData clientData); +static void UpdateSizeHints(TkWindow *winPtr); +static void UpdateVRootGeometry(WmInfo *wmPtr); +static int WmAspectCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmAttributesCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmClientCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmColormapwindowsCmd(Tk_Window tkwin, + TkWindow *winPtr, Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmCommandCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmDeiconifyCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmFocusmodelCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmForgetCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmFrameCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmGeometryCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmGridCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmGroupCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmIconbitmapCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmIconifyCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmIconmaskCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmIconnameCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmIconpositionCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmIconwindowCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmManageCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmMaxsizeCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmMinsizeCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmOverrideredirectCmd(Tk_Window tkwin, + TkWindow *winPtr, Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmPositionfromCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmStateCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static int WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +static void WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr); +static int WmWinStyle(Tcl_Interp *interp, TkWindow *winPtr, + int objc, Tcl_Obj *const objv[]); +static void ApplyWindowAttributeFlagChanges(TkWindow *winPtr, + NSWindow *macWindow, UInt64 oldAttributes, + int oldFlags, int create, int initial); +static void ApplyMasterOverrideChanges(TkWindow *winPtr, + NSWindow *macWindow); +static void GetMinSize(TkWindow *winPtr, int *minWidthPtr, + int *minHeightPtr); +static void GetMaxSize(TkWindow *winPtr, int *maxWidthPtr, + int *maxHeightPtr); +static void RemapWindows(TkWindow *winPtr, + MacDrawable *parentWin); + +#pragma mark TKWindow(TKWm) + +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 +@interface NSWindow(TkWm) +- (void) setCanCycle: (BOOL) canCycleFlag; +@end #endif +@interface NSDrawerWindow : NSWindow +{ + id _i1, _i2; +} +@end + +@implementation TKWindow +@end + +@implementation TKWindow(TKWm) +- (BOOL) canBecomeKeyWindow +{ + TkWindow *winPtr = TkMacOSXGetTkWindow(self); + + return (winPtr && winPtr->wmInfoPtr && (winPtr->wmInfoPtr->macClass == + kHelpWindowClass || winPtr->wmInfoPtr->attributes & + kWindowNoActivatesAttribute)) ? NO : YES; +} +@end + +#pragma mark - + +/* + *---------------------------------------------------------------------- + * + * SetWindowSizeLimits -- + * + * Sets NSWindow size limits + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static void +SetWindowSizeLimits( + TkWindow *winPtr) +{ + NSWindow *macWindow = TkMacOSXDrawableWindow(winPtr->window); + WmInfo *wmPtr = winPtr->wmInfoPtr; + int minWidth, minHeight, maxWidth, maxHeight, base; + + if (!macWindow) { + return; + } + GetMinSize(winPtr, &minWidth, &minHeight); + GetMaxSize(winPtr, &maxWidth, &maxHeight); + if (wmPtr->gridWin) { + base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc); + if (base < 0) { + base = 0; + } + minWidth = base + (minWidth * wmPtr->widthInc); + maxWidth = base + (maxWidth * wmPtr->widthInc); + base = winPtr->reqHeight - (wmPtr->reqGridHeight * wmPtr->heightInc); + if (base < 0) { + base = 0; + } + minHeight = base + (minHeight * wmPtr->heightInc); + maxHeight = base + (maxHeight * wmPtr->heightInc); + } + if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) { + minWidth = maxWidth = wmPtr->configWidth; + } + if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) { + minHeight = maxHeight = wmPtr->configHeight; + } + if (wmPtr->gridWin) { + [macWindow setResizeIncrements:NSMakeSize(wmPtr->widthInc, + wmPtr->heightInc)]; + } else if (wmPtr->sizeHintsFlags & PAspect && wmPtr->minAspect.x == + wmPtr->maxAspect.x && wmPtr->minAspect.y == wmPtr->maxAspect.y) { + NSSize aspect = NSMakeSize(wmPtr->minAspect.x, wmPtr->minAspect.y); + CGFloat ratio = aspect.width/aspect.height; + [macWindow setContentAspectRatio:aspect]; + if ((CGFloat)minWidth/(CGFloat)minHeight > ratio) { + minHeight = lround(minWidth / ratio); + } else { + minWidth = lround(minHeight * ratio); + } + if ((CGFloat)maxWidth/(CGFloat)maxHeight > ratio) { + maxWidth = lround(maxHeight * ratio); + } else { + maxHeight = lround(maxWidth / ratio); + } + if ((CGFloat)wmPtr->configWidth/(CGFloat)wmPtr->configHeight > ratio) { + wmPtr->configWidth = lround(wmPtr->configHeight * ratio); + if (wmPtr->configWidth < minWidth) { + wmPtr->configWidth = minWidth; + wmPtr->configHeight = minHeight; + } + } else { + wmPtr->configHeight = lround(wmPtr->configWidth / ratio); + if (wmPtr->configHeight < minHeight) { + wmPtr->configWidth = minWidth; + wmPtr->configHeight = minHeight; + } + } + } else { + [macWindow setResizeIncrements:NSMakeSize(1.0, 1.0)]; + } + [macWindow setContentMinSize:NSMakeSize(minWidth, minHeight)]; + [macWindow setContentMaxSize:NSMakeSize(maxWidth, maxHeight)]; +} + +/* + *---------------------------------------------------------------------- + * + * FrontWindowAtPoint -- + * + * Find frontmost toplevel window at a given screen location. + * + * Results: + * TkWindow*. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static TkWindow* +FrontWindowAtPoint( + int x, int y) +{ + + NSPoint p = NSMakePoint(x, tkMacOSXZeroScreenHeight - y); + NSWindow *win = nil; + NSInteger windowCount; + NSInteger *windowNumbers; + + 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]]; + if (w && NSMouseInRect(p, [w frame], NO)) { + win = w; + break; + } + } + ckfree((char *) windowNumbers); + } + return (win ? TkMacOSXGetTkWindow(win) : NULL); +} + /* *---------------------------------------------------------------------- * * TkWmNewWindow -- * - * This procedure is invoked whenever a new top-level - * window is created. Its job is to initialize the WmInfo - * structure for the window. + * This procedure is invoked whenever a new top-level window is created. + * Its job is to initialize the WmInfo structure for the window. * * Results: * None. @@ -204,9 +502,8 @@ void TkWmNewWindow( TkWindow *winPtr) /* Newly-created top-level window. */ { - WmInfo *wmPtr; + WmInfo *wmPtr = (WmInfo *) ckalloc(sizeof(WmInfo)); - wmPtr = (WmInfo *) ckalloc(sizeof(WmInfo)); wmPtr->winPtr = winPtr; wmPtr->reparent = None; wmPtr->titleUid = NULL; @@ -239,9 +536,9 @@ TkWmNewWindow( wmPtr->x = winPtr->changes.x; wmPtr->y = winPtr->changes.y; wmPtr->parentWidth = winPtr->changes.width - + 2*winPtr->changes.border_width; + + 2*winPtr->changes.border_width; wmPtr->parentHeight = winPtr->changes.height - + 2*winPtr->changes.border_width; + + 2*winPtr->changes.border_width; wmPtr->xInParent = 0; wmPtr->yInParent = 0; wmPtr->cmapList = NULL; @@ -255,26 +552,27 @@ TkWmNewWindow( wmPtr->cmdArgv = NULL; wmPtr->clientMachine = NULL; wmPtr->flags = WM_NEVER_MAPPED; - wmPtr->style = -1; wmPtr->macClass = kDocumentWindowClass; - wmPtr->attributes = kWindowStandardDocumentAttributes - | kWindowLiveResizeAttribute; + wmPtr->attributes = macClassAttrs[kDocumentWindowClass].defaultAttrs; wmPtr->scrollWinPtr = NULL; + wmPtr->menuPtr = NULL; + wmPtr->window = nil; winPtr->wmInfoPtr = wmPtr; UpdateVRootGeometry(wmPtr); + /* - * Tk must monitor structure events for top-level windows, in order - * to detect size and position changes caused by window managers. + * Tk must monitor structure events for top-level windows, in order to + * detect size and position changes caused by window managers. */ Tk_CreateEventHandler((Tk_Window) winPtr, StructureNotifyMask, - TopLevelEventProc, (ClientData) winPtr); + TopLevelEventProc, winPtr); /* - * Arrange for geometry requests to be reflected from the window - * to the window manager. + * Arrange for geometry requests to be reflected from the window to the + * window manager. */ Tk_ManageGeometry((Tk_Window) winPtr, &wmMgrType, (ClientData) 0); @@ -285,51 +583,52 @@ TkWmNewWindow( * * TkWmMapWindow -- * - * This procedure is invoked to map a top-level window. This - * module gets a chance to update all window-manager-related - * information in properties before the window manager sees - * the map event and checks the properties. It also gets to - * decide whether or not to even map the window after all. + * This procedure is invoked to map a top-level window. This module gets + * a chance to update all window-manager-related information in + * properties before the window manager sees the map event and checks the + * properties. It also gets to decide whether or not to even map the + * window after all. * * Results: * None. * * Side effects: - * Properties of winPtr may get updated to provide up-to-date - * information to the window manager. The window may also get - * mapped, but it may not be if this procedure decides that - * isn't appropriate (e.g. because the window is withdrawn). + * Properties of winPtr may get updated to provide up-to-date information + * to the window manager. The window may also get mapped, but it may not + * be if this procedure decides that isn't appropriate (e.g. because the + * window is withdrawn). * *---------------------------------------------------------------------- */ void TkWmMapWindow( - TkWindow *winPtr) /* Top-level window that's about to - * be mapped. */ + TkWindow *winPtr) /* Top-level window that's about to be + * mapped. */ { WmInfo *wmPtr = winPtr->wmInfoPtr; if (wmPtr->flags & WM_NEVER_MAPPED) { - wmPtr->flags &= ~WM_NEVER_MAPPED; - /* * Create the underlying Mac window for this Tk window. */ + if (!TkMacOSXHostToplevelExists(winPtr)) { TkMacOSXMakeRealWindowExist(winPtr); } + wmPtr->flags &= ~WM_NEVER_MAPPED; + /* * Generate configure event when we first map the window. */ + TkGenWMConfigureEvent((Tk_Window) winPtr, wmPtr->x, wmPtr->y, -1, -1, TK_LOCATION_CHANGED); /* - * This is the first time this window has ever been mapped. - * Store all the window-manager-related information for the - * window. + * This is the first time this window has ever been mapped. Store all + * the window-manager-related information for the window. */ if (wmPtr->titleUid == NULL) { @@ -363,11 +662,12 @@ TkWmMapWindow( /* * Update geometry information. */ + wmPtr->flags |= WM_ABOUT_TO_MAP; if (wmPtr->flags & WM_UPDATE_PENDING) { - Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr); + Tk_CancelIdleCall(UpdateGeometryInfo, winPtr); } - UpdateGeometryInfo((ClientData) winPtr); + UpdateGeometryInfo(winPtr); wmPtr->flags &= ~WM_ABOUT_TO_MAP; /* @@ -382,8 +682,8 @@ TkWmMapWindow( * * TkWmUnmapWindow -- * - * This procedure is invoked to unmap a top-level window. - * On the Macintosh all we do is call XUnmapWindow. + * This procedure is invoked to unmap a top-level window. On the + * Macintosh all we do is call XUnmapWindow. * * Results: * None. @@ -396,8 +696,8 @@ TkWmMapWindow( void TkWmUnmapWindow( - TkWindow *winPtr) /* Top-level window that's about to - * be mapped. */ + TkWindow *winPtr) /* Top-level window that's about to be + * mapped. */ { XUnmapWindow(winPtr->display, winPtr->window); } @@ -407,9 +707,8 @@ TkWmUnmapWindow( * * TkWmDeadWindow -- * - * This procedure is invoked when a top-level window is - * about to be deleted. It cleans up the wm-related data - * structures for the window. + * This procedure is invoked when a top-level window is about to be + * deleted. It cleans up the wm-related data structures for the window. * * Results: * None. @@ -424,12 +723,14 @@ void TkWmDeadWindow( TkWindow *winPtr) /* Top-level window that's being deleted. */ { - WmInfo *wmPtr = winPtr->wmInfoPtr; - WmInfo *wmPtr2; + WmInfo *wmPtr = winPtr->wmInfoPtr, *wmPtr2; if (wmPtr == NULL) { return; } + Tk_ManageGeometry((Tk_Window) winPtr, NULL, NULL); + Tk_DeleteEventHandler((Tk_Window) winPtr, StructureNotifyMask, + TopLevelEventProc, winPtr); if (wmPtr->hints.flags & IconPixmapHint) { Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap); } @@ -459,17 +760,36 @@ TkWmDeadWindow( protPtr = wmPtr->protPtr; wmPtr->protPtr = protPtr->nextPtr; - Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC); + Tcl_EventuallyFree(protPtr, TCL_DYNAMIC); } if (wmPtr->cmdArgv != NULL) { ckfree((char *) wmPtr->cmdArgv); } if (wmPtr->clientMachine != NULL) { - ckfree((char *) wmPtr->clientMachine); + ckfree(wmPtr->clientMachine); } if (wmPtr->flags & WM_UPDATE_PENDING) { - Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr); + Tk_CancelIdleCall(UpdateGeometryInfo, winPtr); } + + /* + * Delete the Mac window and remove it from the windowTable. The window + * could be nil if the window was never mapped. However, we don't do this + * for embedded windows, they don't go in the window list, and they do not + * own their portPtr's. + */ + + NSWindow *window = wmPtr->window; + if (window && !Tk_IsEmbedded(winPtr) ) { + [[window parentWindow] removeChildWindow:window]; + [window close]; + TkMacOSXUnregisterMacWindow(window); + if (winPtr->window) { + ((MacDrawable *)winPtr->window)->view = nil; + } + TkMacOSXMakeCollectableAndRelease(wmPtr->window); + } + ckfree((char *) wmPtr); winPtr->wmInfoPtr = NULL; } @@ -479,11 +799,10 @@ TkWmDeadWindow( * * TkWmSetClass -- * - * This procedure is invoked whenever a top-level window's - * class is changed. If the window has been mapped then this - * procedure updates the window manager property for the - * class. If the window hasn't been mapped, the update is - * deferred until just before the first mapping. + * This procedure is invoked whenever a top-level window's class is + * changed. If the window has been mapped then this procedure updates the + * window manager property for the class. If the window hasn't been + * mapped, the update is deferred until just before the first mapping. * * Results: * None. @@ -506,8 +825,8 @@ TkWmSetClass( * * Tk_WmObjCmd -- * - * This procedure is invoked to process the "wm" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm" Tcl command. See the + * user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -527,23 +846,23 @@ Tk_WmObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { Tk_Window tkwin = (Tk_Window) clientData; - static const char *optionStrings[] = { + static const char *const optionStrings[] = { "aspect", "attributes", "client", "colormapwindows", - "command", "deiconify", "focusmodel",/* "forget",*/ + "command", "deiconify", "focusmodel", "forget", "frame", "geometry", "grid", "group", "iconbitmap", "iconify", "iconmask", "iconname", "iconphoto", "iconposition", "iconwindow", - /*"manage", */"maxsize", "minsize", "overrideredirect", + "manage", "maxsize", "minsize", "overrideredirect", "positionfrom", "protocol", "resizable", "sizefrom", "stackorder", "state", "title", "transient", "withdraw", NULL }; enum options { WMOPT_ASPECT, WMOPT_ATTRIBUTES, WMOPT_CLIENT, WMOPT_COLORMAPWINDOWS, - WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL,/* WMOPT_FORGET,*/ + WMOPT_COMMAND, WMOPT_DEICONIFY, WMOPT_FOCUSMODEL, WMOPT_FORGET, WMOPT_FRAME, WMOPT_GEOMETRY, WMOPT_GRID, WMOPT_GROUP, WMOPT_ICONBITMAP, WMOPT_ICONIFY, WMOPT_ICONMASK, WMOPT_ICONNAME, WMOPT_ICONPHOTO, WMOPT_ICONPOSITION, WMOPT_ICONWINDOW, - /*WMOPT_MANAGE, */WMOPT_MAXSIZE, WMOPT_MINSIZE, WMOPT_OVERRIDEREDIRECT, + WMOPT_MANAGE, WMOPT_MAXSIZE, WMOPT_MINSIZE, WMOPT_OVERRIDEREDIRECT, WMOPT_POSITIONFROM, WMOPT_PROTOCOL, WMOPT_RESIZABLE, WMOPT_SIZEFROM, WMOPT_STACKORDER, WMOPT_STATE, WMOPT_TITLE, WMOPT_TRANSIENT, WMOPT_WITHDRAW }; @@ -552,7 +871,7 @@ Tk_WmObjCmd( TkWindow *winPtr; if (objc < 2) { -wrongNumArgs: + wrongNumArgs: Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?"); return TCL_ERROR; } @@ -572,7 +891,7 @@ wrongNumArgs: } if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } @@ -585,84 +904,77 @@ wrongNumArgs: return TCL_ERROR; } if (!Tk_IsTopLevel(winPtr) -#if 0 - && (index != WMOPT_MANAGE) && (index != WMOPT_FORGET) -#endif - ) { + && (index != WMOPT_MANAGE) && (index != WMOPT_FORGET)) { Tcl_AppendResult(interp, "window \"", winPtr->pathName, "\" isn't a top-level window", NULL); return TCL_ERROR; } switch ((enum options) index) { - case WMOPT_ASPECT: - return WmAspectCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ATTRIBUTES: - return WmAttributesCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_CLIENT: - return WmClientCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_COLORMAPWINDOWS: - return WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_COMMAND: - return WmCommandCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_DEICONIFY: - return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_FOCUSMODEL: - return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv); -#if 0 - case WMOPT_FORGET: - return WmForgetCmd(tkwin, winPtr, interp, objc, objv); -#endif - case WMOPT_FRAME: - return WmFrameCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_GEOMETRY: - return WmGeometryCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_GRID: - return WmGridCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_GROUP: - return WmGroupCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONBITMAP: - return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONIFY: - return WmIconifyCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONMASK: - return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONNAME: - return WmIconnameCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONPHOTO: - return WmIconphotoCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONPOSITION: - return WmIconpositionCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_ICONWINDOW: - return WmIconwindowCmd(tkwin, winPtr, interp, objc, objv); -#if 0 - case WMOPT_MANAGE: - return WmManageCmd(tkwin, winPtr, interp, objc, objv); -#endif - case WMOPT_MAXSIZE: - return WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_MINSIZE: - return WmMinsizeCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_OVERRIDEREDIRECT: - return WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_POSITIONFROM: - return WmPositionfromCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_PROTOCOL: - return WmProtocolCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_RESIZABLE: - return WmResizableCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_SIZEFROM: - return WmSizefromCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_STACKORDER: - return WmStackorderCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_STATE: - return WmStateCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_TITLE: - return WmTitleCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_TRANSIENT: - return WmTransientCmd(tkwin, winPtr, interp, objc, objv); - case WMOPT_WITHDRAW: - return WmWithdrawCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ASPECT: + return WmAspectCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ATTRIBUTES: + return WmAttributesCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_CLIENT: + return WmClientCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_COLORMAPWINDOWS: + return WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_COMMAND: + return WmCommandCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_DEICONIFY: + return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_FOCUSMODEL: + return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_FORGET: + return WmForgetCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_FRAME: + return WmFrameCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_GEOMETRY: + return WmGeometryCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_GRID: + return WmGridCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_GROUP: + return WmGroupCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONBITMAP: + return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONIFY: + return WmIconifyCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONMASK: + return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONNAME: + return WmIconnameCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONPHOTO: + return WmIconphotoCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONPOSITION: + return WmIconpositionCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_ICONWINDOW: + return WmIconwindowCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_MANAGE: + return WmManageCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_MAXSIZE: + return WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_MINSIZE: + return WmMinsizeCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_OVERRIDEREDIRECT: + return WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_POSITIONFROM: + return WmPositionfromCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_PROTOCOL: + return WmProtocolCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_RESIZABLE: + return WmResizableCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_SIZEFROM: + return WmSizefromCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_STACKORDER: + return WmStackorderCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_STATE: + return WmStateCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_TITLE: + return WmTitleCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_TRANSIENT: + return WmTransientCmd(tkwin, winPtr, interp, objc, objv); + case WMOPT_WITHDRAW: + return WmWithdrawCmd(tkwin, winPtr, interp, objc, objv); } /* This should not happen */ @@ -674,8 +986,8 @@ wrongNumArgs: * * WmAspectCmd -- * - * This procedure is invoked to process the "wm aspect" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm aspect" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -717,15 +1029,14 @@ WmAspectCmd( wmPtr->sizeHintsFlags &= ~PAspect; } else { if ((Tcl_GetIntFromObj(interp, objv[3], &numer1) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) { + || (Tcl_GetIntFromObj(interp, objv[4], &denom1) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[5], &numer2) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[6], &denom2) != TCL_OK)) { return TCL_ERROR; } if ((numer1 <= 0) || (denom1 <= 0) || (numer2 <= 0) || - (denom2 <= 0)) { - Tcl_SetResult(interp, "aspect number can't be <= 0", - TCL_STATIC); + (denom2 <= 0)) { + Tcl_SetResult(interp, "aspect number can't be <= 0", TCL_STATIC); return TCL_ERROR; } wmPtr->minAspect.x = numer1; @@ -744,19 +1055,21 @@ WmAspectCmd( * * WmSetAttribute -- * - * Helper routine for WmAttributesCmd. Sets the value - * of the specified attribute. + * Helper routine for WmAttributesCmd. Sets the value of the specified + * attribute. * * Returns: * - * TCL_OK if successful, TCL_ERROR otherwise. In case of an - * error, leaves a message in the interpreter's result. + * TCL_OK if successful, TCL_ERROR otherwise. In case of an error, leaves + * a message in the interpreter's result. * *---------------------------------------------------------------------- */ -static int WmSetAttribute( + +static int +WmSetAttribute( TkWindow *winPtr, /* Toplevel to work with */ - WindowRef macWindow, + NSWindow *macWindow, Tcl_Interp *interp, /* Current interpreter */ WmAttribute attribute, /* Code of attribute to set */ Tcl_Obj *value) /* New value */ @@ -765,154 +1078,113 @@ static int WmSetAttribute( int boolean; switch (attribute) { - case WMATT_ALPHA: { - double dval; + case WMATT_ALPHA: { + double dval; - if (Tcl_GetDoubleFromObj(interp, value, &dval) != TCL_OK) { - return TCL_ERROR; - } - /* - * The user should give (transparent) 0 .. 1.0 (opaque) - */ - if (dval < 0.0) { - dval = 0.0; - } else if (dval > 1.0) { - dval = 1.0; - } - ChkErr(SetWindowAlpha, macWindow, dval); - break; + if (Tcl_GetDoubleFromObj(interp, value, &dval) != TCL_OK) { + return TCL_ERROR; } - case WMATT_FULLSCREEN: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; - } - if (boolean != ((wmPtr->flags & WM_FULLSCREEN) != 0)) { - if(TkMacOSXMakeFullscreen(winPtr, macWindow, boolean, interp) - != TCL_OK) { - return TCL_ERROR; - } - } - break; - case WMATT_MODIFIED: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; - } - if (boolean != IsWindowModified(macWindow)) { - ChkErr(SetWindowModified, macWindow, boolean); - } - break; -#if 0 - case WMATT_NOTIFY: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + + /* + * The user should give (transparent) 0 .. 1.0 (opaque) + */ + + if (dval < 0.0) { + dval = 0.0; + } else if (dval > 1.0) { + dval = 1.0; + } + [macWindow setAlphaValue:dval]; + break; + } + case WMATT_FULLSCREEN: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean != ((wmPtr->flags & WM_FULLSCREEN) != 0)) { + if (TkMacOSXMakeFullscreen(winPtr, macWindow, boolean, interp) + != TCL_OK) { return TCL_ERROR; } - if (boolean == !tkMacOSXWmAttrNotifyVal) { - static NMRec notifyRec; - - if (boolean) { - bzero(¬ifyRec, sizeof(notifyRec)); - notifyRec.qType = nmType; - notifyRec.nmMark = 1; - ChkErr(NMInstall, ¬ifyRec); - } else { - ChkErr(NMRemove, ¬ifyRec); - } - tkMacOSXWmAttrNotifyVal = boolean; - } - break; -#endif - case WMATT_TITLEPATH: { - const char *path; - OSStatus err; - - path = Tcl_FSGetNativePath(value); - if (path && *path) { - FSRef ref; - Boolean d; - - err = ChkErr(FSPathMakeRef, (const unsigned char*) path, &ref, - &d); - if (err == noErr) { - TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef, - err = ChkErr(HIWindowSetProxyFSRef, macWindow, &ref); - ) TK_ELSE_MAC_OS_X (4, - AliasHandle alias; - - err = ChkErr(FSNewAlias, NULL, &ref, &alias); - if (err == noErr) { - err = ChkErr(SetWindowProxyAlias, macWindow, - alias); - DisposeHandle((Handle) alias); - } - ) TK_ENDIF - } - } else { - int len; + } + break; + case WMATT_MODIFIED: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean != [macWindow isDocumentEdited]) { + [macWindow setDocumentEdited:boolean]; + } + break; + case WMATT_NOTIFY: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean == !tkMacOSXWmAttrNotifyVal) { + static NSInteger request = -1; - Tcl_GetStringFromObj(value, &len); - if (!len) { - err = ChkErr(RemoveWindowProxy, macWindow); - } else { - err = fnfErr; - } + if (request >= 0) { + [NSApp cancelUserAttentionRequest:request]; + request = -1; } - if (err != noErr) { - return TCL_ERROR; + if (boolean) { + request = [NSApp requestUserAttention:NSCriticalRequest]; } - break; + tkMacOSXWmAttrNotifyVal = boolean; } - case WMATT_TOPMOST: { - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; - } - if (boolean != ((wmPtr->flags & WM_TOPMOST) != 0)) { - WindowGroupRef group; + break; + case WMATT_TITLEPATH: { + const char *path = Tcl_FSGetNativePath(value); + NSString *filename = @""; - if (boolean) { - wmPtr->flags |= WM_TOPMOST; - } else { - wmPtr->flags &= ~WM_TOPMOST; - } - group = WmGetWindowGroup(winPtr); - if (group && group != GetWindowGroup(macWindow)) { - ChkErr(SetWindowGroup, macWindow, group); - } + if (path && *path) { + filename = [NSString stringWithUTF8String:path]; + } + [macWindow setRepresentedFilename:filename]; + break; + } + case WMATT_TOPMOST: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean != ((wmPtr->flags & WM_TOPMOST) != 0)) { + int oldFlags = wmPtr->flags; + + if (boolean) { + wmPtr->flags |= WM_TOPMOST; + } else { + wmPtr->flags &= ~WM_TOPMOST; } - break; + ApplyWindowAttributeFlagChanges(winPtr, macWindow, + wmPtr->attributes, oldFlags, 1, 0); } - case WMATT_TRANSPARENT: - if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { - return TCL_ERROR; + break; + case WMATT_TRANSPARENT: + if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) { + return TCL_ERROR; + } + if (boolean != ((wmPtr->flags & WM_TRANSPARENT) != 0)) { + UInt64 oldAttributes = wmPtr->attributes; + int oldFlags = wmPtr->flags; + + if (boolean) { + wmPtr->flags |= WM_TRANSPARENT; + wmPtr->attributes |= kWindowNoShadowAttribute; + } else { + wmPtr->flags &= ~WM_TRANSPARENT; + wmPtr->attributes &= ~kWindowNoShadowAttribute; } - if (boolean != ((wmPtr->flags & WM_TRANSPARENT) != 0)) { - WindowAttributes oldAttributes = wmPtr->attributes; - - if (boolean) { - wmPtr->flags |= WM_TRANSPARENT; - wmPtr->attributes |= kWindowNoShadowAttribute; - TK_IF_MAC_OS_X_API (3, HIWindowChangeFeatures, - UInt32 features; - - ChkErr(GetWindowFeatures, macWindow, &features); - if (features & kWindowIsOpaque) { - ChkErr(HIWindowChangeFeatures, macWindow, 0, - kWindowIsOpaque); - } - ) TK_ENDIF - } else { - wmPtr->flags &= ~WM_TRANSPARENT; - wmPtr->attributes &= ~kWindowNoShadowAttribute; - } - ApplyWindowClassAttributeChanges(winPtr, macWindow, - wmPtr->macClass, oldAttributes, 1); - ChkErr(ReshapeCustomWindow, macWindow); - TkMacOSXInvalidateWindow((MacDrawable *)(winPtr->window), - TK_PARENT_WINDOW); + ApplyWindowAttributeFlagChanges(winPtr, macWindow, oldAttributes, + oldFlags, 1, 0); + [macWindow setBackgroundColor:boolean ? [NSColor clearColor] : nil]; + [macWindow setOpaque:!boolean]; + TkMacOSXInvalidateWindow((MacDrawable *) winPtr->window, + TK_PARENT_WINDOW); } - break; - case _WMATT_LAST_ATTRIBUTE: - default: - return TCL_ERROR; + break; + case _WMATT_LAST_ATTRIBUTE: + default: + return TCL_ERROR; } return TCL_OK; } @@ -922,73 +1194,47 @@ static int WmSetAttribute( * * WmGetAttribute -- * - * Helper routine for WmAttributesCmd. Returns the current value - * of the specified attribute. + * Helper routine for WmAttributesCmd. Returns the current value of the + * specified attribute. * *---------------------------------------------------------------------- */ -static Tcl_Obj *WmGetAttribute( + +static Tcl_Obj * +WmGetAttribute( TkWindow *winPtr, /* Toplevel to work with */ - WindowRef macWindow, + NSWindow *macWindow, WmAttribute attribute) /* Code of attribute to get */ { - WmInfo *wmPtr = winPtr->wmInfoPtr; Tcl_Obj *result = NULL; + WmInfo *wmPtr = winPtr->wmInfoPtr; switch (attribute) { - case WMATT_ALPHA: { - float fval = 1.0; - - ChkErr(GetWindowAlpha, macWindow, &fval); - result = Tcl_NewDoubleObj(fval); - break; - } - case WMATT_FULLSCREEN: - result = Tcl_NewBooleanObj(wmPtr->flags & WM_FULLSCREEN); - break; - case WMATT_MODIFIED: - result = Tcl_NewBooleanObj(IsWindowModified(macWindow)); - break; -#if 0 - case WMATT_NOTIFY: - result = Tcl_NewBooleanObj(tkMacOSXWmAttrNotifyVal); - break; -#endif - case WMATT_TITLEPATH: { - FSRef ref; - UInt8 path[PATH_MAX+1]; - OSStatus err; - - TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef, - err = ChkErr(HIWindowGetProxyFSRef, macWindow, &ref); - ) TK_ELSE_MAC_OS_X (4, - Boolean wasChanged; - AliasHandle alias; - - err = ChkErr(GetWindowProxyAlias, macWindow, &alias); - if (err == noErr) { - err = ChkErr(FSResolveAlias, NULL, alias, &ref, - &wasChanged); - } - ) TK_ENDIF - if (err == noErr) { - err = ChkErr(FSRefMakePath, &ref, path, PATH_MAX); - } - if (err != noErr) { - *path = 0; - } - result = Tcl_NewStringObj((char*) path, -1); - break; - } - case WMATT_TOPMOST: - result = Tcl_NewBooleanObj(wmPtr->flags & WM_TOPMOST); - break; - case WMATT_TRANSPARENT: - result = Tcl_NewBooleanObj(wmPtr->flags & WM_TRANSPARENT); - break; - case _WMATT_LAST_ATTRIBUTE: - default: - break; + case WMATT_ALPHA: + result = Tcl_NewDoubleObj([macWindow alphaValue]); + break; + case WMATT_FULLSCREEN: + result = Tcl_NewBooleanObj(wmPtr->flags & WM_FULLSCREEN); + break; + case WMATT_MODIFIED: + result = Tcl_NewBooleanObj([macWindow isDocumentEdited]); + break; + case WMATT_NOTIFY: + result = Tcl_NewBooleanObj(tkMacOSXWmAttrNotifyVal); + break; + case WMATT_TITLEPATH: + result = Tcl_NewStringObj([[macWindow representedFilename] UTF8String], + -1); + break; + case WMATT_TOPMOST: + result = Tcl_NewBooleanObj(wmPtr->flags & WM_TOPMOST); + break; + case WMATT_TRANSPARENT: + result = Tcl_NewBooleanObj(wmPtr->flags & WM_TRANSPARENT); + break; + case _WMATT_LAST_ATTRIBUTE: + default: + break; } return result; } @@ -1019,7 +1265,7 @@ WmAttributesCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { int attribute = 0; - WindowRef macWindow; + NSWindow *macWindow; if (winPtr->window == None) { Tk_MakeWindowExist((Tk_Window) winPtr); @@ -1070,8 +1316,8 @@ WmAttributesCmd( * * WmClientCmd -- * - * This procedure is invoked to process the "wm client" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm client" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1107,16 +1353,15 @@ WmClientCmd( argv3 = Tcl_GetStringFromObj(objv[3], &length); if (argv3[0] == 0) { if (wmPtr->clientMachine != NULL) { - ckfree((char *) wmPtr->clientMachine); + ckfree(wmPtr->clientMachine); wmPtr->clientMachine = NULL; } return TCL_OK; } if (wmPtr->clientMachine != NULL) { - ckfree((char *) wmPtr->clientMachine); + ckfree(wmPtr->clientMachine); } - wmPtr->clientMachine = (char *) - ckalloc((unsigned) (length + 1)); + wmPtr->clientMachine = ckalloc(length + 1); strcpy(wmPtr->clientMachine, argv3); return TCL_OK; } @@ -1126,9 +1371,8 @@ WmClientCmd( * * WmColormapwindowsCmd -- * - * This procedure is invoked to process the "wm colormapwindows" - * Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm colormapwindows" Tcl + * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1172,12 +1416,10 @@ WmColormapwindowsCmd( != TCL_OK) { return TCL_ERROR; } - cmapList = (TkWindow **) ckalloc((unsigned) - ((windowObjc+1)*sizeof(TkWindow*))); + cmapList = (TkWindow **) ckalloc((windowObjc+1) * sizeof(TkWindow*)); for (i = 0; i < windowObjc; i++) { if (TkGetWindowFromObj(interp, tkwin, windowObjv[i], - (Tk_Window *) &winPtr2) != TCL_OK) - { + (Tk_Window *) &winPtr2) != TCL_OK) { ckfree((char *) cmapList); return TCL_ERROR; } @@ -1198,15 +1440,14 @@ WmColormapwindowsCmd( } wmPtr->flags |= WM_COLORMAPS_EXPLICIT; if (wmPtr->cmapList != NULL) { - ckfree((char *)wmPtr->cmapList); + ckfree((char *) wmPtr->cmapList); } wmPtr->cmapList = cmapList; wmPtr->cmapCount = windowObjc; /* - * On the Macintosh all of this is just an excercise - * in compatability as we don't support colormaps. If - * we did they would be installed here. + * On the Macintosh all of this is just an excercise in compatability as + * we don't support colormaps. If we did they would be installed here. */ return TCL_OK; @@ -1217,8 +1458,8 @@ WmColormapwindowsCmd( * * WmCommandCmd -- * - * This procedure is invoked to process the "wm command" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm command" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1248,9 +1489,9 @@ WmCommandCmd( } if (objc == 3) { if (wmPtr->cmdArgv != NULL) { - Tcl_SetResult(interp, - Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv), - TCL_DYNAMIC); + argv3 = Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv); + Tcl_SetResult(interp, argv3, TCL_VOLATILE); + ckfree(argv3); } return TCL_OK; } @@ -1299,6 +1540,7 @@ WmDeiconifyCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { register WmInfo *wmPtr = winPtr->wmInfoPtr; + if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "window"); return TCL_ERROR; @@ -1344,7 +1586,7 @@ WmFocusmodelCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { register WmInfo *wmPtr = winPtr->wmInfoPtr; - static const char *optionStrings[] = { + static const char *const optionStrings[] = { "active", "passive", NULL }; enum options { OPT_ACTIVE, OPT_PASSIVE }; @@ -1361,7 +1603,7 @@ WmFocusmodelCmd( } if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_ACTIVE) { @@ -1371,7 +1613,6 @@ WmFocusmodelCmd( } return TCL_OK; } -#if 0 /* *---------------------------------------------------------------------- @@ -1391,57 +1632,54 @@ WmFocusmodelCmd( */ static int -WmForgetCmd(tkwin, winPtr, interp, objc, objv) - Tk_Window tkwin; /* Main window of the application. */ - TkWindow *winPtr; /* Toplevel or Frame to work with */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ +WmForgetCmd( + Tk_Window tkwin, /* Main window of the application. */ + TkWindow *winPtr, /* Toplevel or Frame to work with */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { -#if 1 - Tcl_AppendResult(interp, "wm forget is not yet supported", (char*)NULL); - return TCL_ERROR; -#else + register Tk_Window frameWin = (Tk_Window)winPtr; - char *oldClass = (char*)Tk_Class(frameWin); if (Tk_IsTopLevel(frameWin)) { - MacDrawable *macWin = (MacDrawable *) winPtr->window; - CGrafPtr destPort = TkMacOSXGetDrawablePort(winPtr->window); + + MacDrawable *macWin; + + Tk_MakeWindowExist(winPtr); + Tk_MakeWindowExist(winPtr->parentPtr); + + macWin = (MacDrawable *) winPtr->window; TkFocusJoin(winPtr); Tk_UnmapWindow(frameWin); - if (destPort != NULL) { - WindowRef winRef; - winRef = GetWindowFromPort(destPort); - TkMacOSXUnregisterMacWindow(winRef); - DisposeWindow(winRef); - } - macWin->grafPtr = NULL; macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel; macWin->flags &= ~TK_HOST_EXISTS; - RemapWindows(winPtr, macWin); TkWmDeadWindow(winPtr); - winPtr->flags &= ~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); + RemapWindows(winPtr, (MacDrawable *) winPtr->parentPtr->window); + + winPtr->flags &=~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); + + /* + * Flags (above) must be cleared before calling TkMapTopFrame (below). + */ TkMapTopFrame(frameWin); } else { - /* Already not managed by wm - ignore it */ + /* Already not managed by wm - ignore it */ } return TCL_OK; -#endif } -#endif /* *---------------------------------------------------------------------- * * WmFrameCmd -- * - * This procedure is invoked to process the "wm frame" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm frame" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1472,7 +1710,7 @@ WmFrameCmd( if (window == None) { window = Tk_WindowId((Tk_Window) winPtr); } - sprintf(buf, "0x%x", (unsigned int) window); + sprintf(buf, "0x%x", (unsigned) window); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_OK; } @@ -1525,8 +1763,8 @@ WmGeometryCmd( width = winPtr->changes.width; height = winPtr->changes.height; } - sprintf(buf, "%dx%d%c%d%c%d", width, height, xSign, wmPtr->x, - ySign, wmPtr->y); + sprintf(buf, "%dx%d%c%d%c%d", + width, height, xSign, wmPtr->x, ySign, wmPtr->y); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_OK; } @@ -1545,8 +1783,8 @@ WmGeometryCmd( * * WmGridCmd -- * - * This procedure is invoked to process the "wm grid" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm grid" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1586,8 +1824,8 @@ WmGridCmd( } if (*Tcl_GetString(objv[3]) == '\0') { /* - * Turn off gridding and reset the width and height - * to make sense as ungridded numbers. + * Turn off gridding and reset the width and height to make sense as + * ungridded numbers. */ wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc); @@ -1601,9 +1839,9 @@ WmGridCmd( wmPtr->heightInc = 1; } else { if ((Tcl_GetIntFromObj(interp, objv[3], &reqWidth) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[6], &heightInc) != TCL_OK)) { + || (Tcl_GetIntFromObj(interp, objv[4], &reqHeight) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[5], &widthInc) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[6], &heightInc)!=TCL_OK)) { return TCL_ERROR; } if (reqWidth < 0) { @@ -1635,8 +1873,8 @@ WmGridCmd( * * WmGroupCmd -- * - * This procedure is invoked to process the "wm group" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm group" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1687,7 +1925,7 @@ WmGroupCmd( } wmPtr->hints.window_group = Tk_WindowId(tkwin2); wmPtr->hints.flags |= WindowGroupHint; - wmPtr->leaderName = ckalloc((unsigned) (length + 1)); + wmPtr->leaderName = ckalloc(length + 1); strcpy(wmPtr->leaderName, argv3); } return TCL_OK; @@ -1766,8 +2004,8 @@ WmIconbitmapCmd( * * WmIconifyCmd -- * - * This procedure is invoked to process the "wm iconify" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm iconify" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -1850,8 +2088,7 @@ WmIconmaskCmd( } if (objc == 3) { if (wmPtr->hints.flags & IconMaskHint) { - Tcl_SetResult(interp, - (char*)Tk_NameOfBitmap(winPtr->display, + Tcl_SetResult(interp, (char *) Tk_NameOfBitmap(winPtr->display, wmPtr->hints.icon_mask), TCL_STATIC); } return TCL_OK; @@ -1907,20 +2144,20 @@ WmIconnameCmd( return TCL_ERROR; } if (objc == 3) { - Tcl_SetResult(interp, - (char*)((wmPtr->iconName != NULL) ? - wmPtr->iconName : ""), TCL_STATIC); - return TCL_OK; - } else { if (wmPtr->iconName != NULL) { - ckfree((char *) wmPtr->iconName); - } - argv3 = Tcl_GetStringFromObj(objv[3], &length); - wmPtr->iconName = ckalloc((unsigned) (length + 1)); - strcpy(wmPtr->iconName, argv3); - if (!(wmPtr->flags & WM_NEVER_MAPPED)) { - XSetIconName(winPtr->display, winPtr->window, wmPtr->iconName); + Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->iconName, -1)); } + return TCL_OK; + } + + if (wmPtr->iconName != NULL) { + ckfree(wmPtr->iconName); + } + argv3 = Tcl_GetStringFromObj(objv[3], &length); + wmPtr->iconName = ckalloc(length + 1); + strcpy(wmPtr->iconName, argv3); + if (!(wmPtr->flags & WM_NEVER_MAPPED)) { + XSetIconName(winPtr->display, winPtr->window, wmPtr->iconName); } return TCL_OK; } @@ -1930,10 +2167,9 @@ WmIconnameCmd( * * WmIconphotoCmd -- * - * This procedure is invoked to process the "wm iconphoto" - * Tcl command. - * See the user documentation for details on what it does. - * Not yet implemented for OS X. + * This procedure is invoked to process the "wm iconphoto" Tcl command. + * See the user documentation for details on what it does. Not yet + * implemented for OS X. * * Results: * A standard Tcl result. @@ -1968,10 +2204,12 @@ WmIconphotoCmd( return TCL_ERROR; } } + /* * Iterate over all images to retrieve their sizes, in order to allocate a * buffer large enough to hold all images. */ + for (i = 3 + isDefault; i < objc; i++) { photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i])); if (photo == NULL) { @@ -1981,10 +2219,12 @@ WmIconphotoCmd( } Tk_PhotoGetSize(photo, &width, &height); } + /* - * This requires implementation for OS X, but we silently return - * for now. + * TODO: This requires implementation for OS X, but we silently return for + * now. */ + return TCL_OK; } @@ -1993,9 +2233,8 @@ WmIconphotoCmd( * * WmIconpositionCmd -- * - * This procedure is invoked to process the "wm iconposition" - * Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm iconposition" Tcl + * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2127,15 +2366,14 @@ WmIconwindowCmd( } return TCL_OK; } -#if 0 /* *---------------------------------------------------------------------- * * WmManageCmd -- * - * This procedure is invoked to process the "wm manage" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm manage" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2152,12 +2390,9 @@ WmManageCmd( TkWindow *winPtr, /* Toplevel or Frame to work with */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { -#if 1 - Tcl_AppendResult(interp, "wm manage is not yet supported", (char*)NULL); - return TCL_ERROR; -#else + register Tk_Window frameWin = (Tk_Window)winPtr; register WmInfo *wmPtr = winPtr->wmInfoPtr; char *oldClass = (char*)Tk_Class(frameWin); @@ -2165,6 +2400,12 @@ WmManageCmd( if (!Tk_IsTopLevel(frameWin)) { MacDrawable *macWin = (MacDrawable *) winPtr->window; + if (!Tk_IsManageable(frameWin)) { + Tcl_AppendResult(interp, "window \"", + Tk_PathName(frameWin), "\" is not manageable: must be " + "a frame, labelframe or toplevel", NULL); + return TCL_ERROR; + } TkFocusSplit(winPtr); Tk_UnmapWindow(frameWin); if (wmPtr == NULL) { @@ -2178,26 +2419,24 @@ WmManageCmd( } wmPtr = winPtr->wmInfoPtr; winPtr->flags &= ~TK_MAPPED; - macWin->grafPtr = NULL; macWin->toplevel = macWin; RemapWindows(winPtr, macWin); - winPtr->flags |= (TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); - TkMapTopFrame (frameWin); + winPtr->flags |= + (TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED); + TkMapTopFrame(frameWin); } else if (Tk_IsTopLevel(frameWin)) { /* Already managed by wm - ignore it */ } return TCL_OK; -#endif } -#endif /* *---------------------------------------------------------------------- * * WmMaxsizeCmd -- * - * This procedure is invoked to process the "wm maxsize" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm maxsize" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2247,8 +2486,8 @@ WmMaxsizeCmd( * * WmMinsizeCmd -- * - * This procedure is invoked to process the "wm minsize" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm minsize" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2283,7 +2522,7 @@ WmMinsizeCmd( return TCL_OK; } if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) { + || (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) { return TCL_ERROR; } wmPtr->minWidth = width; @@ -2298,9 +2537,8 @@ WmMinsizeCmd( * * WmOverrideredirectCmd -- * - * This procedure is invoked to process the "wm overrideredirect" - * Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm overrideredirect" Tcl + * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2327,8 +2565,8 @@ WmOverrideredirectCmd( return TCL_ERROR; } if (objc == 3) { - Tcl_SetBooleanObj(Tcl_GetObjResult(interp), - Tk_Attributes((Tk_Window) winPtr)->override_redirect); + Tcl_SetObjResult(interp, Tcl_NewBooleanObj( + Tk_Attributes((Tk_Window) winPtr)->override_redirect)); return TCL_OK; } if (Tcl_GetBooleanFromObj(interp, objv[3], &boolean) != TCL_OK) { @@ -2345,9 +2583,8 @@ WmOverrideredirectCmd( * * WmPositionfromCmd -- * - * This procedure is invoked to process the "wm positionfrom" - * Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm positionfrom" Tcl + * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2367,7 +2604,7 @@ WmPositionfromCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { register WmInfo *wmPtr = winPtr->wmInfoPtr; - static const char *optionStrings[] = { + static const char *const optionStrings[] = { "program", "user", NULL }; enum options { OPT_PROGRAM, OPT_USER }; @@ -2389,7 +2626,7 @@ WmPositionfromCmd( wmPtr->sizeHintsFlags &= ~(USPosition|PPosition); } else { if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_USER) { @@ -2444,6 +2681,7 @@ WmProtocolCmd( /* * Return a list of all defined protocols for the window. */ + for (protPtr = wmPtr->protPtr; protPtr != NULL; protPtr = protPtr->nextPtr) { Tcl_AppendElement(interp, @@ -2468,9 +2706,8 @@ WmProtocolCmd( } /* - * Delete any current protocol handler, then create a new - * one with the specified command, unless the command is - * empty. + * Delete any current protocol handler, then create a new one with the + * specified command, unless the command is empty. */ for (protPtr = wmPtr->protPtr, prevPtr = NULL; protPtr != NULL; @@ -2481,7 +2718,7 @@ WmProtocolCmd( } else { prevPtr->nextPtr = protPtr->nextPtr; } - Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC); + Tcl_EventuallyFree(protPtr, TCL_DYNAMIC); break; } } @@ -2524,7 +2761,8 @@ WmResizableCmd( { register WmInfo *wmPtr = winPtr->wmInfoPtr; int width, height; - WindowAttributes oldAttributes = wmPtr->attributes; + UInt64 oldAttributes = wmPtr->attributes; + int oldFlags = wmPtr->flags; if ((objc != 3) && (objc != 5)) { Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?"); @@ -2568,8 +2806,7 @@ WmResizableCmd( wmPtr->scrollWinPtr->instanceData); } WmUpdateGeom(wmPtr, winPtr); - ApplyWindowClassAttributeChanges(winPtr, NULL, wmPtr->macClass, - oldAttributes, 1); + ApplyWindowAttributeFlagChanges(winPtr, NULL, oldAttributes, oldFlags, 1,0); return TCL_OK; } @@ -2599,7 +2836,7 @@ WmSizefromCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { register WmInfo *wmPtr = winPtr->wmInfoPtr; - static const char *optionStrings[] = { + static const char *const optionStrings[] = { "program", "user", NULL }; enum options { OPT_PROGRAM, OPT_USER }; @@ -2622,7 +2859,7 @@ WmSizefromCmd( wmPtr->sizeHintsFlags &= ~(USSize|PSize); } else { if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_USER) { @@ -2664,7 +2901,7 @@ WmStackorderCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { TkWindow **windows, **window_ptr; - static const char *optionStrings[] = { + static const char *const optionStrings[] = { "isabove", "isbelow", NULL }; enum options { OPT_ISABOVE, OPT_ISBELOW }; @@ -2679,13 +2916,13 @@ WmStackorderCmd( windows = TkWmStackorderToplevel(winPtr); if (windows == NULL) { Tcl_Panic("TkWmStackorderToplevel failed"); - } else { - for (window_ptr = windows; *window_ptr ; window_ptr++) { - Tcl_AppendElement(interp, (*window_ptr)->pathName); - } - ckfree((char *) windows); - return TCL_OK; } + + for (window_ptr = windows; *window_ptr ; window_ptr++) { + Tcl_AppendElement(interp, (*window_ptr)->pathName); + } + ckfree((char *) windows); + return TCL_OK; } else { TkWindow *winPtr2; int index1=-1, index2=-1, result; @@ -2714,33 +2951,35 @@ WmStackorderCmd( } /* - * Lookup stacking order of all toplevels that are children - * of "." and find the position of winPtr and winPtr2 - * in the stacking order. + * Lookup stacking order of all toplevels that are children of "." and + * find the position of winPtr and winPtr2 in the stacking order. */ windows = TkWmStackorderToplevel(winPtr->mainPtr->winPtr); - if (windows == NULL) { Tcl_AppendResult(interp, "TkWmStackorderToplevel failed", NULL); return TCL_ERROR; - } else { - for (window_ptr = windows; *window_ptr ; window_ptr++) { - if (*window_ptr == winPtr) - index1 = (window_ptr - windows); - if (*window_ptr == winPtr2) - index2 = (window_ptr - windows); - } - if (index1 == -1) - Tcl_Panic("winPtr window not found"); - if (index2 == -1) - Tcl_Panic("winPtr2 window not found"); + } - ckfree((char *) windows); + for (window_ptr = windows; *window_ptr ; window_ptr++) { + if (*window_ptr == winPtr) { + index1 = (window_ptr - windows); + } + if (*window_ptr == winPtr2) { + index2 = (window_ptr - windows); + } + } + if (index1 == -1) { + Tcl_Panic("winPtr window not found"); + } + if (index2 == -1) { + Tcl_Panic("winPtr2 window not found"); } + ckfree((char *) windows); + if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0, - &index) != TCL_OK) { + &index) != TCL_OK) { return TCL_ERROR; } if (index == OPT_ISABOVE) { @@ -2748,7 +2987,7 @@ WmStackorderCmd( } else { /* OPT_ISBELOW */ result = index1 < index2; } - Tcl_SetIntObj(Tcl_GetObjResult(interp), result); + Tcl_SetObjResult(interp, Tcl_NewBooleanObj(result)); return TCL_OK; } return TCL_OK; @@ -2759,8 +2998,8 @@ WmStackorderCmd( * * WmStateCmd -- * - * This procedure is invoked to process the "wm state" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm state" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2780,7 +3019,7 @@ WmStateCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { register WmInfo *wmPtr = winPtr->wmInfoPtr; - static const char *optionStrings[] = { + static const char *const optionStrings[] = { "normal", "iconic", "withdrawn", "zoomed", NULL }; enum options { OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN, OPT_ZOOMED }; @@ -2810,9 +3049,10 @@ WmStateCmd( if (index == OPT_NORMAL) { TkpWmSetState(winPtr, NormalState); + /* - * This varies from 'wm deiconify' because it does not - * force the window to be raised and receive focus + * This varies from 'wm deiconify' because it does not force the + * window to be raised and receive focus */ } else if (index == OPT_ICONIC) { if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) { @@ -2831,29 +3071,27 @@ WmStateCmd( } else { /* OPT_ZOOMED */ TkpWmSetState(winPtr, ZoomState); } + } else if (wmPtr->iconFor != NULL) { + Tcl_SetResult(interp, "icon", TCL_STATIC); } else { - if (wmPtr->iconFor != NULL) { - Tcl_SetResult(interp, "icon", TCL_STATIC); - } else { - if (wmPtr->hints.initial_state == NormalState || - wmPtr->hints.initial_state == ZoomState) { - wmPtr->hints.initial_state = (TkMacOSXIsWindowZoomed(winPtr) ? - ZoomState : NormalState); - } - switch (wmPtr->hints.initial_state) { - case NormalState: - Tcl_SetResult(interp, "normal", TCL_STATIC); - break; - case IconicState: - Tcl_SetResult(interp, "iconic", TCL_STATIC); - break; - case WithdrawnState: - Tcl_SetResult(interp, "withdrawn", TCL_STATIC); - break; - case ZoomState: - Tcl_SetResult(interp, "zoomed", TCL_STATIC); - break; - } + if (wmPtr->hints.initial_state == NormalState || + wmPtr->hints.initial_state == ZoomState) { + wmPtr->hints.initial_state = (TkMacOSXIsWindowZoomed(winPtr) ? + ZoomState : NormalState); + } + switch (wmPtr->hints.initial_state) { + case NormalState: + Tcl_SetResult(interp, "normal", TCL_STATIC); + break; + case IconicState: + Tcl_SetResult(interp, "iconic", TCL_STATIC); + break; + case WithdrawnState: + Tcl_SetResult(interp, "withdrawn", TCL_STATIC); + break; + case ZoomState: + Tcl_SetResult(interp, "zoomed", TCL_STATIC); + break; } } return TCL_OK; @@ -2864,8 +3102,8 @@ WmStateCmd( * * WmTitleCmd -- * - * This procedure is invoked to process the "wm title" Tcl command. - * See the user documentation for details on what it does. + * This procedure is invoked to process the "wm title" Tcl command. See + * the user documentation for details on what it does. * * Results: * A standard Tcl result. @@ -2933,7 +3171,7 @@ WmTransientCmd( register WmInfo *wmPtr = winPtr->wmInfoPtr; Tk_Window master; WmInfo *wmPtr2; - char *argv3; + char *masterWindowName; int length; if ((objc != 3) && (objc != 4)) { @@ -2981,13 +3219,13 @@ WmTransientCmd( return TCL_ERROR; } - argv3 = Tcl_GetStringFromObj(objv[3], &length); wmPtr->master = Tk_WindowId(master); + masterWindowName = Tcl_GetStringFromObj(objv[3], &length); if (wmPtr->masterWindowName != NULL) { ckfree(wmPtr->masterWindowName); } - wmPtr->masterWindowName = ckalloc((unsigned) length+1); - strcpy(wmPtr->masterWindowName, argv3); + wmPtr->masterWindowName = ckalloc(length+1); + strcpy(wmPtr->masterWindowName, masterWindowName); } ApplyMasterOverrideChanges(winPtr, NULL); return TCL_OK; @@ -3037,13 +3275,14 @@ WmWithdrawCmd( * Invoked by those wm subcommands that affect geometry. * Schedules a geometry update. */ + static void -WmUpdateGeom(wmPtr, winPtr) -WmInfo *wmPtr; -TkWindow *winPtr; +WmUpdateGeom( + WmInfo *wmPtr, + TkWindow *winPtr) { if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3054,33 +3293,33 @@ TkWindow *winPtr; * Tk_SetGrid -- * * This procedure is invoked by a widget when it wishes to set a grid - * coordinate system that controls the size of a top-level window. - * It provides a C interface equivalent to the "wm grid" command and - * is usually asscoiated with the -setgrid option. + * coordinate system that controls the size of a top-level window. It + * provides a C interface equivalent to the "wm grid" command and is + * usually asscoiated with the -setgrid option. * * Results: * None. * * Side effects: - * Grid-related information will be passed to the window manager, so - * that the top-level window associated with tkwin will resize on - * even grid units. If some other window already controls gridding - * for the top-level window then this procedure call has no effect. + * Grid-related information will be passed to the window manager, so that + * the top-level window associated with tkwin will resize on even grid + * units. If some other window already controls gridding for the + * top-level window then this procedure call has no effect. * *---------------------------------------------------------------------- */ void Tk_SetGrid( - Tk_Window tkwin, /* Token for window. New window mgr info - * will be posted for the top-level window + Tk_Window tkwin, /* Token for window. New window mgr info will + * be posted for the top-level window * associated with this window. */ - int reqWidth, /* Width (in grid units) corresponding to - * the requested geometry for tkwin. */ - int reqHeight, /* Height (in grid units) corresponding to - * the requested geometry for tkwin. */ - int widthInc, int heightInc)/* Pixel increments corresponding to a - * change of one grid unit. */ + int reqWidth, /* Width (in grid units) corresponding to the + * requested geometry for tkwin. */ + int reqHeight, /* Height (in grid units) corresponding to the + * requested geometry for tkwin. */ + int widthInc, int heightInc)/* Pixel increments corresponding to a change + * of one grid unit. */ { TkWindow *winPtr = (TkWindow *) tkwin; WmInfo *wmPtr; @@ -3120,15 +3359,15 @@ Tk_SetGrid( } /* - * If gridding was previously off, then forget about any window - * size requests made by the user or via "wm geometry": these are - * in pixel units and there's no easy way to translate them to - * grid units since the new requested size of the top-level window in - * pixels may not yet have been registered yet (it may filter up - * the hierarchy in DoWhenIdle handlers). However, if the window - * has never been mapped yet then just leave the window size alone: - * assume that it is intended to be in grid units but just happened - * to have been specified before this procedure was called. + * If gridding was previously off, then forget about any window size + * requests made by the user or via "wm geometry": these are in pixel + * units and there's no easy way to translate them to grid units since the + * new requested size of the top-level window in pixels may not yet have + * been registered yet (it may filter up the hierarchy in DoWhenIdle + * handlers). However, if the window has never been mapped yet then just + * leave the window size alone: assume that it is intended to be in grid + * units but just happened to have been specified before this procedure + * was called. */ if ((wmPtr->gridWin == NULL) && !(wmPtr->flags & WM_NEVER_MAPPED)) { @@ -3137,8 +3376,8 @@ Tk_SetGrid( } /* - * Set the new gridding information, and start the process of passing - * all of this information to the window manager. + * Set the new gridding information, and start the process of passing all + * of this information to the window manager. */ wmPtr->gridWin = tkwin; @@ -3149,7 +3388,7 @@ Tk_SetGrid( wmPtr->sizeHintsFlags |= PBaseSize|PResizeInc; wmPtr->flags |= WM_UPDATE_SIZE_HINTS; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3159,16 +3398,15 @@ Tk_SetGrid( * * Tk_UnsetGrid -- * - * This procedure cancels the effect of a previous call - * to Tk_SetGrid. + * This procedure cancels the effect of a previous call to Tk_SetGrid. * * Results: * None. * * Side effects: * If tkwin currently controls gridding for its top-level window, - * gridding is cancelled for that top-level window; if some other - * window controls gridding then this procedure has no effect. + * gridding is cancelled for that top-level window; if some other window + * controls gridding then this procedure has no effect. * *---------------------------------------------------------------------- */ @@ -3207,7 +3445,7 @@ Tk_UnsetGrid( wmPtr->flags |= WM_UPDATE_SIZE_HINTS; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3224,8 +3462,8 @@ Tk_UnsetGrid( * None. * * Side effects: - * Tk's internal data structures for the window get modified to - * reflect the structural change. + * Tk's internal data structures for the window get modified to reflect + * the structural change. * *---------------------------------------------------------------------- */ @@ -3235,7 +3473,7 @@ TopLevelEventProc( ClientData clientData, /* Window for which event occurred. */ XEvent *eventPtr) /* Event that just happened. */ { - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; winPtr->wmInfoPtr->flags |= WM_VROOT_OFFSET_STALE; if (eventPtr->type == DestroyNotify) { @@ -3249,7 +3487,8 @@ TopLevelEventProc( */ Tk_ErrorHandler handler = Tk_CreateErrorHandler(winPtr->display, - -1, -1, -1, (Tk_ErrorProc *) NULL, (ClientData) NULL); + -1, -1, -1, NULL, NULL); + Tk_DestroyWindow((Tk_Window) winPtr); Tk_DeleteErrorHandler(handler); } @@ -3266,15 +3505,15 @@ TopLevelEventProc( * * TopLevelReqProc -- * - * This procedure is invoked by the geometry manager whenever - * the requested size for a top-level window is changed. + * This procedure is invoked by the geometry manager whenever the + * requested size for a top-level window is changed. * * Results: * None. * * Side effects: - * Arrange for the window to be resized to satisfy the request - * (this happens as a when-idle action). + * Arrange for the window to be resized to satisfy the request (this + * happens as a when-idle action). * *---------------------------------------------------------------------- */ @@ -3291,7 +3530,7 @@ TopLevelReqProc( wmPtr = winPtr->wmInfoPtr; wmPtr->flags |= WM_UPDATE_SIZE_HINTS; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } } @@ -3301,19 +3540,18 @@ TopLevelReqProc( * * UpdateGeometryInfo -- * - * This procedure is invoked when a top-level window is first - * mapped, and also as a when-idle procedure, to bring the - * geometry and/or position of a top-level window back into - * line with what has been requested by the user and/or widgets. - * This procedure doesn't return until the window manager has - * responded to the geometry change. + * This procedure is invoked when a top-level window is first mapped, and + * also as a when-idle procedure, to bring the geometry and/or position + * of a top-level window back into line with what has been requested by + * the user and/or widgets. This procedure doesn't return until the + * window manager has responded to the geometry change. * * Results: * None. * * Side effects: - * The window's size and location may change, unless the WM prevents - * that from happening. + * The window's size and location may change, unless the WM prevents that + * from happening. * *---------------------------------------------------------------------- */ @@ -3322,10 +3560,9 @@ static void UpdateGeometryInfo( ClientData clientData) /* Pointer to the window's record. */ { - TkWindow *winPtr = (TkWindow *) clientData; + TkWindow *winPtr = clientData; WmInfo *wmPtr = winPtr->wmInfoPtr; int x, y, width, height, min, max; - unsigned long serial; wmPtr->flags &= ~WM_UPDATE_PENDING; @@ -3334,14 +3571,12 @@ UpdateGeometryInfo( } /* - * Compute the new size for the top-level window. See the - * user documentation for details on this, but the size - * requested depends on (a) the size requested internally - * by the window's widgets, (b) the size requested by the - * user in a "wm geometry" command or via wm-based interactive - * resizing (if any), and (c) whether or not the window is - * gridded. Don't permit sizes <= 0 because this upsets - * the X server. + * Compute the new size for the top-level window. See the user + * documentation for details on this, but the size requested depends on + * (a) the size requested internally by the window's widgets, (b) the size + * requested by the user in a "wm geometry" command or via wm-based + * interactive resizing (if any), and (c) whether or not the window is + * gridded. Don't permit sizes <= 0 because this upsets the X server. */ if (wmPtr->width == -1) { @@ -3416,10 +3651,10 @@ UpdateGeometryInfo( /* * Compute the new position for the upper-left pixel of the window's - * decorative frame. This is tricky, because we need to include the - * border widths supplied by a reparented parent in this calculation, - * but can't use the parent's current overall size since that may - * change as a result of this code. + * decorative frame. This is tricky, because we need to include the border + * widths supplied by a reparented parent in this calculation, but can't + * use the parent's current overall size since that may change as a result + * of this code. */ if (wmPtr->flags & WM_NEGATIVE_X) { @@ -3436,10 +3671,10 @@ UpdateGeometryInfo( } /* - * If the window's size is going to change and the window is - * supposed to not be resizable by the user, then we have to - * update the size hints. There may also be a size-hint-update - * request pending from somewhere else, too. + * If the window's size is going to change and the window is supposed to + * not be resizable by the user, then we have to update the size hints. + * There may also be a size-hint-update request pending from somewhere + * else, too. */ if (((width != winPtr->changes.width) @@ -3453,22 +3688,21 @@ UpdateGeometryInfo( } /* - * Reconfigure the window if it isn't already configured correctly. - * A few tricky points: + * Reconfigure the window if it isn't already configured correctly. A few + * tricky points: * - * 1. If the window is embedded and the container is also in this - * process, don't actually reconfigure the window; just pass the - * desired size on to the container. Also, zero out any position - * information, since embedded windows are not allowed to move. - * 2. Sometimes the window manager will give us a different size - * than we asked for (e.g. mwm has a minimum size for windows), so - * base the size check on what we *asked for* last time, not what we - * got. - * 3. Don't move window unless a new position has been requested for - * it. This is because of "features" in some window managers (e.g. - * twm, as of 4/24/91) where they don't interpret coordinates - * according to ICCCM. Moving a window to its current location may - * cause it to shift position on the screen. + * 1. If the window is embedded and the container is also in this process, + * don't actually reconfigure the window; just pass the desired size on + * to the container. Also, zero out any position information, since + * embedded windows are not allowed to move. + * 2. Sometimes the window manager will give us a different size than we + * asked for (e.g. mwm has a minimum size for windows), so base the + * size check on what we *asked for* last time, not what we got. + * 3. Don't move window unless a new position has been requested for it. + * This is because of "features" in some window managers (e.g. twm, as + * of 4/24/91) where they don't interpret coordinates according to + * ICCCM. Moving a window to its current location may cause it to shift + * position on the screen. */ if (Tk_IsEmbedded(winPtr)) { @@ -3482,9 +3716,9 @@ UpdateGeometryInfo( /* * This window is embedded and the container is also in this * process, so we don't need to do anything special about the - * geometry, except to make sure that the desired size is known - * by the container. Also, zero out any position information, - * since embedded windows are not allowed to move. + * geometry, except to make sure that the desired size is known by + * the container. Also, zero out any position information, since + * embedded windows are not allowed to move. */ wmPtr->x = wmPtr->y = 0; @@ -3493,7 +3727,6 @@ UpdateGeometryInfo( } return; } - serial = NextRequest(winPtr->display); if (wmPtr->flags & WM_MOVE_PENDING) { wmPtr->configWidth = width; wmPtr->configHeight = height; @@ -3501,9 +3734,10 @@ UpdateGeometryInfo( TkMacOSXDbgMsg("Moving to %d %d, resizing to %d x %d", x, y, width, height); } + SetWindowSizeLimits(winPtr); wmPtr->flags |= WM_SYNC_PENDING; XMoveResizeWindow(winPtr->display, winPtr->window, x, y, - (unsigned) width, (unsigned) height); + wmPtr->configWidth, wmPtr->configHeight); wmPtr->flags &= ~WM_SYNC_PENDING; } else if ((width != wmPtr->configWidth) || (height != wmPtr->configHeight)) { @@ -3512,10 +3746,13 @@ UpdateGeometryInfo( if (wmTracing) { TkMacOSXDbgMsg("Resizing to %d x %d\n", width, height); } + SetWindowSizeLimits(winPtr); wmPtr->flags |= WM_SYNC_PENDING; - XResizeWindow(winPtr->display, winPtr->window, (unsigned) width, - (unsigned) height); + XResizeWindow(winPtr->display, winPtr->window, wmPtr->configWidth, + wmPtr->configHeight); wmPtr->flags &= ~WM_SYNC_PENDING; + } else { + SetWindowSizeLimits(winPtr); } } @@ -3524,9 +3761,8 @@ UpdateGeometryInfo( * * UpdateSizeHints -- * - * This procedure is called to update the window manager's - * size hints information from the information in a WmInfo - * structure. + * This procedure is called to update the window manager's size hints + * information from the information in a WmInfo structure. * * Results: * None. @@ -3544,8 +3780,6 @@ UpdateSizeHints( WmInfo *wmPtr = winPtr->wmInfoPtr; wmPtr->flags &= ~WM_UPDATE_SIZE_HINTS; - - return; } /* @@ -3553,13 +3787,12 @@ UpdateSizeHints( * * ParseGeometry -- * - * This procedure parses a geometry string and updates - * information used to control the geometry of a top-level - * window. + * This procedure parses a geometry string and updates information used + * to control the geometry of a top-level window. * * Results: - * A standard Tcl return value, plus an error message in - * the interp's result if an error occurs. + * A standard Tcl return value, plus an error message in the interp's + * result if an error occurs. * * Side effects: * The size and/or location of winPtr may change. @@ -3572,8 +3805,8 @@ ParseGeometry( Tcl_Interp *interp, /* Used for error reporting. */ char *string, /* String containing new geometry. Has the * standard form "=wxh+x+y". */ - TkWindow *winPtr) /* Pointer to top-level window whose - * geometry is to be changed. */ + TkWindow *winPtr) /* Pointer to top-level window whose geometry + * is to be changed. */ { WmInfo *wmPtr = winPtr->wmInfoPtr; int x, y, width, height, flags; @@ -3589,9 +3822,9 @@ ParseGeometry( } /* - * Parse the width and height, if they are present. Don't - * actually update any of the fields of wmPtr until we've - * successfully parsed the entire geometry string. + * Parse the width and height, if they are present. Don't actually update + * any of the fields of wmPtr until we've successfully parsed the entire + * geometry string. */ width = wmPtr->width; @@ -3645,10 +3878,10 @@ ParseGeometry( } /* - * Assume that the geometry information came from the user, - * unless an explicit source has been specified. Otherwise - * most window managers assume that the size hints were - * program-specified and they ignore them. + * Assume that the geometry information came from the user, unless an + * explicit source has been specified. Otherwise most window managers + * assume that the size hints were program-specified and they ignore + * them. */ if ((wmPtr->sizeHintsFlags & (USPosition|PPosition)) == 0) { @@ -3658,9 +3891,9 @@ ParseGeometry( } /* - * Everything was parsed OK. Update the fields of *wmPtr and - * arrange for the appropriate information to be percolated out - * to the window manager at the next idle moment. + * Everything was parsed OK. Update the fields of *wmPtr and arrange for + * the appropriate information to be percolated out to the window manager + * at the next idle moment. */ wmPtr->width = width; @@ -3680,12 +3913,12 @@ ParseGeometry( wmPtr->flags = flags; if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) { - Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr); + Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr); wmPtr->flags |= WM_UPDATE_PENDING; } return TCL_OK; -error: + error: Tcl_AppendResult(interp, "bad geometry specifier \"", string, "\"", NULL); return TCL_ERROR; } @@ -3695,15 +3928,15 @@ error: * * Tk_GetRootCoords -- * - * Given a token for a window, this procedure traces through the - * window's lineage to find the (virtual) root-window coordinates - * corresponding to point (0,0) in the window. + * Given a token for a window, this procedure traces through the window's + * lineage to find the (virtual) root-window coordinates corresponding to + * point (0,0) in the window. * * Results: - * The locations pointed to by xPtr and yPtr are filled in with - * the root coordinates of the (0,0) point in tkwin. If a virtual - * root window is in effect for the window, then the coordinates - * in the virtual root are returned. + * The locations pointed to by xPtr and yPtr are filled in with the root + * coordinates of the (0,0) point in tkwin. If a virtual root window is + * in effect for the window, then the coordinates in the virtual root are + * returned. * * Side effects: * None. @@ -3721,9 +3954,8 @@ Tk_GetRootCoords( TkWindow *winPtr = (TkWindow *) tkwin; /* - * Search back through this window's parents all the way to a - * top-level window, combining the offsets of each window within - * its parent. + * Search back through this window's parents all the way to a top-level + * window, combining the offsets of each window within its parent. */ x = y = 0; @@ -3731,54 +3963,55 @@ Tk_GetRootCoords( x += winPtr->changes.x + winPtr->changes.border_width; y += winPtr->changes.y + winPtr->changes.border_width; if (winPtr->flags & TK_TOP_LEVEL) { + TkWindow *otherPtr; + if (!(Tk_IsEmbedded(winPtr))) { x += winPtr->wmInfoPtr->xInParent; y += winPtr->wmInfoPtr->yInParent; break; - } else { - TkWindow *otherPtr = TkpGetOtherWindow(winPtr); + } - if (otherPtr != NULL) { - /* - * The container window is in the same application. - * Query its coordinates. - */ - winPtr = otherPtr; + otherPtr = TkpGetOtherWindow(winPtr); + if (otherPtr == NULL) { + if (tkMacOSXEmbedHandler->getOffsetProc != NULL) { + Point theOffset; /* - * Remember to offset by the container window here, - * since at the end of this if branch, we will - * pop out to the container's parent... + * We do not require that the changes.x & changes.y for a + * non-Tk master window be kept up to date. So we first + * subtract off the possibly bogus values that have been + * added on at the top of this pass through the loop, and + * then call out to the getOffsetProc to give us the + * correct offset. */ - x += winPtr->changes.x + winPtr->changes.border_width; - y += winPtr->changes.y + winPtr->changes.border_width; + x -= winPtr->changes.x + winPtr->changes.border_width; + y -= winPtr->changes.y + winPtr->changes.border_width; - } else { - Point theOffset; + tkMacOSXEmbedHandler->getOffsetProc((Tk_Window) winPtr, + &theOffset); - if (tkMacOSXEmbedHandler->getOffsetProc != NULL) { - /* - * We do not require that the changes.x & changes.y for - * a non-Tk master window be kept up to date. So we - * first subtract off the possibly bogus values that - * have been added on at the top of this pass through - * the loop, and then call out to the getOffsetProc to - * give us the correct offset. - */ + x += theOffset.h; + y += theOffset.v; + } + break; + } - x -= winPtr->changes.x + winPtr->changes.border_width; - y -= winPtr->changes.y + winPtr->changes.border_width; + /* + * The container window is in the same application. Query its + * coordinates. + */ - tkMacOSXEmbedHandler->getOffsetProc((Tk_Window) winPtr, - &theOffset); + winPtr = otherPtr; - x += theOffset.h; - y += theOffset.v; - } - break; - } - } + /* + * Remember to offset by the container window here, since at the + * end of this if branch, we will pop out to the container's + * parent... + */ + + x += winPtr->changes.x + winPtr->changes.border_width; + y += winPtr->changes.y + winPtr->changes.border_width; } winPtr = winPtr->parentPtr; } @@ -3791,14 +4024,14 @@ Tk_GetRootCoords( * * Tk_CoordsToWindow -- * - * This is a Macintosh specific implementation of this function. - * Given the root coordinates of a point, this procedure returns - * the token for the top-most window covering that point, if - * there exists such a window in this application. + * This is a Macintosh specific implementation of this function. Given + * the root coordinates of a point, this procedure returns the token for + * the top-most window covering that point, if there exists such a window + * in this application. * * Results: - * The return result is either a token for the window corresponding - * to rootX and rootY, or else NULL to indicate that there is no such + * The return result is either a token for the window corresponding to + * rootX and rootY, or else NULL to indicate that there is no such * window. * * Side effects: @@ -3809,45 +4042,33 @@ Tk_GetRootCoords( Tk_Window Tk_CoordsToWindow( - int rootX, int rootY, /* Coordinates of point in root window. If - * a virtual-root window manager is in use, + int rootX, int rootY, /* Coordinates of point in root window. If a + * virtual-root window manager is in use, * these coordinates refer to the virtual * root, not the real root. */ - Tk_Window tkwin) /* Token for any window in application; - * used to identify the display. */ + Tk_Window tkwin) /* Token for any window in application; used + * to identify the display. */ { - WindowPtr whichWin; - Point where; - Window rootChild; TkWindow *winPtr, *childPtr; - TkWindow *nextPtr; /* Coordinates of highest child found so - * far that contains point. */ + TkWindow *nextPtr; /* Coordinates of highest child found so far + * that contains point. */ int x, y; /* Coordinates in winPtr. */ int tmpx, tmpy, bd; - TkDisplay *dispPtr; /* * Step 1: find the top-level window that contains the desired point. */ - where.h = rootX; - where.v = rootY; - FindWindow(where, &whichWin); - if (whichWin == NULL) { - return NULL; - } - rootChild = TkMacOSXGetXWindow(whichWin); - dispPtr = TkGetDisplayList(); - winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, rootChild); - if (winPtr == NULL) { + winPtr = FrontWindowAtPoint(rootX, rootY); + if (!winPtr) { return NULL; } /* - * Step 2: work down through the hierarchy underneath this window. - * At each level, scan through all the children to find the highest - * one in the stacking order that contains the point. Then repeat - * the whole process on that child. + * Step 2: work down through the hierarchy underneath this window. At each + * level, scan through all the children to find the highest one in the + * stacking order that contains the point. Then repeat the whole process + * on that child. */ x = rootX - winPtr->wmInfoPtr->xInParent; @@ -3871,8 +4092,8 @@ Tk_CoordsToWindow( bd = childPtr->changes.border_width; if ((tmpx >= -bd) && (tmpy >= -bd) - && (tmpx < (childPtr->changes.width + bd)) - && (tmpy < (childPtr->changes.height + bd))) { + && (tmpx < (childPtr->changes.width + bd)) + && (tmpy < (childPtr->changes.height + bd))) { nextPtr = childPtr; } } @@ -3914,13 +4135,12 @@ Tk_CoordsToWindow( * Given a Tk Window, and coordinates of a point relative to that window * this procedure returns the top-most child of the window (excluding * toplevels) covering that point, if there exists such a window in this - * application. - * It also sets newX, and newY to the coords of the point relative to the - * window returned. + * application. It also sets newX, and newY to the coords of the point + * relative to the window returned. * * Results: - * The return result is either a token for the window corresponding - * to rootX and rootY, or else NULL to indicate that there is no such + * The return result is either a token for the window corresponding to + * rootX and rootY, or else NULL to indicate that there is no such * window. newX and newY are also set to the coords of the point relative * to the returned window. * @@ -3932,15 +4152,15 @@ Tk_CoordsToWindow( Tk_Window Tk_TopCoordsToWindow( - Tk_Window tkwin, /* Token for a Tk Window which defines the; + Tk_Window tkwin, /* Token for a Tk Window which defines the * coordinates for rootX & rootY */ int rootX, int rootY, /* Coordinates of a point in tkWin. */ int *newX, int *newY) /* Coordinates of point in the upperMost child * of tkWin containing (rootX,rootY) */ { TkWindow *winPtr, *childPtr; - TkWindow *nextPtr; /* Coordinates of highest child found so - * far that contains point. */ + TkWindow *nextPtr; /* Coordinates of highest child found so far + * that contains point. */ int x, y; /* Coordinates in winPtr. */ Window *children; /* Children of winPtr, or NULL. */ @@ -4005,24 +4225,23 @@ Tk_TopCoordsToWindow( * * UpdateVRootGeometry -- * - * This procedure is called to update all the virtual root - * geometry information in wmPtr. + * This procedure is called to update all the virtual root geometry + * information in wmPtr. * * Results: * None. * * Side effects: - * The vRootX, vRootY, vRootWidth, and vRootHeight fields in - * wmPtr are filled with the most up-to-date information. + * The vRootX, vRootY, vRootWidth, and vRootHeight fields in wmPtr are + * filled with the most up-to-date information. * *---------------------------------------------------------------------- */ static void UpdateVRootGeometry( - WmInfo *wmPtr) /* Window manager information to be - * updated. The wmPtr->vRoot field must - * be valid. */ + WmInfo *wmPtr) /* Window manager information to be updated. + * The wmPtr->vRoot field must be valid. */ { TkWindow *winPtr = wmPtr->winPtr; unsigned int bd, dummy; @@ -4048,8 +4267,7 @@ UpdateVRootGeometry( * Refresh the virtual root information if it's out of date. */ - handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1, - (Tk_ErrorProc *) NULL, (ClientData) NULL); + handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1, NULL, NULL); status = XGetGeometry(winPtr->display, wmPtr->vRoot, &dummy2, &wmPtr->vRootX, &wmPtr->vRootY, &wmPtr->vRootWidth, &wmPtr->vRootHeight, &bd, &dummy); @@ -4061,7 +4279,7 @@ UpdateVRootGeometry( Tk_DeleteErrorHandler(handler); if (status == 0) { /* - * The virtual root is gone! Pretend that it never existed. + * The virtual root is gone! Pretend that it never existed. */ wmPtr->vRoot = None; @@ -4074,16 +4292,15 @@ UpdateVRootGeometry( * * Tk_GetVRootGeometry -- * - * This procedure returns information about the virtual root - * window corresponding to a particular Tk window. + * This procedure returns information about the virtual root window + * corresponding to a particular Tk window. * * Results: - * The values at xPtr, yPtr, widthPtr, and heightPtr are set - * with the offset and dimensions of the root window corresponding - * to tkwin. If tkwin is being managed by a virtual root window - * manager these values correspond to the virtual root window being - * used for tkwin; otherwise the offsets will be 0 and the - * dimensions will be those of the screen. + * The values at xPtr, yPtr, widthPtr, and heightPtr are set with the + * offset and dimensions of the root window corresponding to tkwin. If + * tkwin is being managed by a virtual root window manager these values + * correspond to the virtual root window being used for tkwin; otherwise + * the offsets will be 0 and the dimensions will be those of the screen. * * Side effects: * Vroot window information is refreshed if it is out of date. @@ -4114,8 +4331,8 @@ Tk_GetVRootGeometry( wmPtr = winPtr->wmInfoPtr; /* - * Make sure that the geometry information is up-to-date, then copy - * it out to the caller. + * Make sure that the geometry information is up-to-date, then copy it out + * to the caller. */ if (wmPtr->flags & WM_VROOT_OFFSET_STALE) { @@ -4132,18 +4349,17 @@ Tk_GetVRootGeometry( * * Tk_MoveToplevelWindow -- * - * This procedure is called instead of Tk_MoveWindow to adjust - * the x-y location of a top-level window. It delays the actual - * move to a later time and keeps window-manager information - * up-to-date with the move + * This procedure is called instead of Tk_MoveWindow to adjust the x-y + * location of a top-level window. It delays the actual move to a later + * time and keeps window-manager information up-to-date with the move. * * Results: * None. * * Side effects: * The window is eventually moved so that its upper-left corner - * (actually, the upper-left corner of the window's decorative - * frame, if there is one) is at (x,y). + * (actually, the upper-left corner of the window's decorative frame, if + * there is one) is at (x,y). * *---------------------------------------------------------------------- */ @@ -4151,8 +4367,7 @@ Tk_GetVRootGeometry( void Tk_MoveToplevelWindow( Tk_Window tkwin, /* Window to move. */ - int x, int y) /* New location for window (within - * parent). */ + int x, int y) /* New location for window (within parent). */ { TkWindow *winPtr = (TkWindow *) tkwin; WmInfo *wmPtr = winPtr->wmInfoPtr; @@ -4171,16 +4386,15 @@ Tk_MoveToplevelWindow( /* * If the window has already been mapped, must bring its geometry - * up-to-date immediately, otherwise an event might arrive from the - * server that would overwrite wmPtr->x and wmPtr->y and lose the - * new position. + * up-to-date immediately, otherwise an event might arrive from the server + * that would overwrite wmPtr->x and wmPtr->y and lose the new position. */ if (!(wmPtr->flags & WM_NEVER_MAPPED)) { if (wmPtr->flags & WM_UPDATE_PENDING) { - Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr); + Tk_CancelIdleCall(UpdateGeometryInfo, winPtr); } - UpdateGeometryInfo((ClientData) winPtr); + UpdateGeometryInfo(winPtr); } } @@ -4195,9 +4409,9 @@ Tk_MoveToplevelWindow( * None. * * Side effects: - * WinPtr gets restacked as specified by aboveBelow and otherPtr. - * This procedure doesn't return until the restack has taken - * effect and the ConfigureNotify event for it has been received. + * WinPtr gets restacked as specified by aboveBelow and otherPtr. This + * procedure doesn't return until the restack has taken effect and the + * ConfigureNotify event for it has been received. * *---------------------------------------------------------------------- */ @@ -4207,28 +4421,25 @@ TkWmRestackToplevel( TkWindow *winPtr, /* Window to restack. */ int aboveBelow, /* Gives relative position for restacking; * must be Above or Below. */ - TkWindow *otherPtr) /* Window relative to which to restack; - * if NULL, then winPtr gets restacked - * above or below *all* siblings. */ + TkWindow *otherPtr) /* Window relative to which to restack; if + * NULL, then winPtr gets restacked above or + * below *all* siblings. */ { - WmInfo *wmPtr; - - WindowRef macWindow, otherMacWindow, frontWindow, tmpWindow; - - wmPtr = winPtr->wmInfoPtr; + NSWindow *macWindow; + NSInteger otherMacWindowNumber; /* * Get the mac window. Make sure it exists & is mapped. */ + if (winPtr->window == None) { Tk_MakeWindowExist((Tk_Window) winPtr); } if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) { - /* - * Can't set stacking order properly until the window is on the - * screen (mapping it may give it a reparent window), so make sure - * it's on the screen. + * Can't set stacking order properly until the window is on the screen + * (mapping it may give it a reparent window), so make sure it's on + * the screen. */ TkWmMapWindow(winPtr); @@ -4238,6 +4449,7 @@ TkWmRestackToplevel( /* * Get the window in which a raise or lower is in relation to. */ + if (otherPtr != NULL) { if (otherPtr->window == None) { Tk_MakeWindowExist((Tk_Window) otherPtr); @@ -4245,56 +4457,13 @@ TkWmRestackToplevel( if (otherPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) { TkWmMapWindow(otherPtr); } - otherMacWindow = TkMacOSXDrawableWindow(otherPtr->window); + otherMacWindowNumber = [TkMacOSXDrawableWindow(otherPtr->window) + windowNumber]; } else { - otherMacWindow = NULL; - } - - frontWindow = ActiveNonFloatingWindow(); - - if (aboveBelow == Above) { - if (macWindow == frontWindow) { - /* - * Do nothing - it's already at the top. - */ - } else if (otherMacWindow == frontWindow || otherMacWindow == NULL) { - /* - * Raise the window to the top. If the window is visible then - * we also make it the active window. - */ - - if (wmPtr->hints.initial_state == WithdrawnState) { - BringToFront(macWindow); - } else { - SelectWindow(macWindow); - } - } else { - /* - * Find the window to be above. (Front window will actually be the - * window to be behind.) Front window is NULL if no other windows. - */ - - while (frontWindow != NULL && - (tmpWindow=GetNextWindow(frontWindow)) != otherMacWindow) { - frontWindow = tmpWindow; - } - if (frontWindow != NULL) { - SendBehind(macWindow, frontWindow); - } - } - } else { - /* - * Send behind. If it was in front find another window to make active. - */ - - if (macWindow == frontWindow) { - tmpWindow = GetNextWindow(macWindow); - if (tmpWindow != NULL) { - SelectWindow(tmpWindow); - } - } - SendBehind(macWindow, otherMacWindow); + otherMacWindowNumber = 0; } + [macWindow orderWindow:(aboveBelow == Above ? NSWindowAbove : NSWindowBelow) + relativeTo:otherMacWindowNumber]; } /* @@ -4303,27 +4472,26 @@ TkWmRestackToplevel( * TkWmAddToColormapWindows -- * * This procedure is called to add a given window to the - * WM_COLORMAP_WINDOWS property for its top-level, if it - * isn't already there. It is invoked by the Tk code that - * creates a new colormap, in order to make sure that colormap - * information is propagated to the window manager by default. + * WM_COLORMAP_WINDOWS property for its top-level, if it isn't already + * there. It is invoked by the Tk code that creates a new colormap, in + * order to make sure that colormap information is propagated to the + * window manager by default. * * Results: * None. * * Side effects: - * WinPtr's window gets added to the WM_COLORMAP_WINDOWS - * property of its nearest top-level ancestor, unless the - * colormaps have been set explicitly with the - * "wm colormapwindows" command. + * WinPtr's window gets added to the WM_COLORMAP_WINDOWS property of its + * nearest top-level ancestor, unless the colormaps have been set + * explicitly with the "wm colormapwindows" command. * *---------------------------------------------------------------------- */ void TkWmAddToColormapWindows( - TkWindow *winPtr) /* Window with a non-default colormap. - * Should not be a top-level window. */ + TkWindow *winPtr) /* Window with a non-default colormap. Should + * not be a top-level window. */ { TkWindow *topPtr; TkWindow **oldPtr, **newPtr; @@ -4363,14 +4531,13 @@ TkWmAddToColormapWindows( } /* - * Make a new bigger array and use it to reset the property. - * Automatically add the toplevel itself as the last element - * of the list. + * Make a new bigger array and use it to reset the property. Automatically + * add the toplevel itself as the last element of the list. */ - newPtr = (TkWindow **) ckalloc((unsigned) ((count+2)*sizeof(TkWindow*))); + newPtr = ckalloc((count+2) * sizeof(TkWindow *)); if (count > 0) { - memcpy(newPtr, oldPtr, count * sizeof(TkWindow*)); + memcpy(newPtr, oldPtr, count * sizeof(TkWindow *)); } if (count == 0) { count++; @@ -4385,9 +4552,8 @@ TkWmAddToColormapWindows( topPtr->wmInfoPtr->cmapCount = count+1; /* - * On the Macintosh all of this is just an excercise - * in compatability as we don't support colormaps. If - * we did they would be installed here. + * On the Macintosh all of this is just an excercise in compatability as + * we don't support colormaps. If we did they would be installed here. */ } @@ -4397,16 +4563,16 @@ TkWmAddToColormapWindows( * TkWmRemoveFromColormapWindows -- * * This procedure is called to remove a given window from the - * WM_COLORMAP_WINDOWS property for its top-level. It is invoked - * when windows are deleted. + * WM_COLORMAP_WINDOWS property for its top-level. It is invoked when + * windows are deleted. * * Results: * None. * * Side effects: - * WinPtr's window gets removed from the WM_COLORMAP_WINDOWS - * property of its nearest top-level ancestor, unless the - * top-level itself is being deleted too. + * WinPtr's window gets removed from the WM_COLORMAP_WINDOWS property of + * its nearest top-level ancestor, unless the top-level itself is being + * deleted too. * *---------------------------------------------------------------------- */ @@ -4424,8 +4590,8 @@ TkWmRemoveFromColormapWindows( for (topPtr = winPtr->parentPtr; ; topPtr = topPtr->parentPtr) { if (topPtr == NULL) { /* - * Ancestors have been deleted, so skip the whole operation. - * Seems like this can't ever happen? + * Ancestors have been deleted, so skip the whole operation. Seems + * like this can't ever happen? */ return; @@ -4436,16 +4602,15 @@ TkWmRemoveFromColormapWindows( } if (topPtr->flags & TK_ALREADY_DEAD) { /* - * Top-level is being deleted, so there's no need to cleanup - * the WM_COLORMAP_WINDOWS property. + * Top-level is being deleted, so there's no need to cleanup the + * WM_COLORMAP_WINDOWS property. */ return; } /* - * Find the window and slide the following ones down to cover - * it up. + * Find the window and slide the following ones down to cover it up. */ count = topPtr->wmInfoPtr->cmapCount; @@ -4469,10 +4634,10 @@ TkWmRemoveFromColormapWindows( * Fetch the position of the mouse pointer. * * Results: - * *xPtr and *yPtr are filled in with the (virtual) root coordinates - * of the mouse pointer for tkwin's display. If the pointer isn't - * on tkwin's screen, then -1 values are returned for both - * coordinates. The argument tkwin must be a toplevel window. + * *xPtr and *yPtr are filled in with the (virtual) root coordinates of + * the mouse pointer for tkwin's display. If the pointer isn't on tkwin's + * screen, then -1 values are returned for both coordinates. The argument + * tkwin must be a toplevel window. * * Side effects: * None. @@ -4482,8 +4647,8 @@ TkWmRemoveFromColormapWindows( void TkGetPointerCoords( - Tk_Window tkwin, /* Toplevel window that identifies screen - * on which lookup is to be done. */ + Tk_Window tkwin, /* Toplevel window that identifies screen on + * which lookup is to be done. */ int *xPtr, int *yPtr) /* Store pointer coordinates here. */ { XQueryPointer(NULL, None, NULL, NULL, xPtr, yPtr, NULL, NULL, NULL); @@ -4494,13 +4659,13 @@ TkGetPointerCoords( * * InitialWindowBounds -- * - * This function calculates the initial bounds for a new Mac - * toplevel window. Unless the geometry is specified by the user - * this code will auto place the windows in a cascade diagonially - * across the main monitor of the Mac. + * This function calculates the initial bounds for a new Mac toplevel + * window. Unless the geometry is specified by the user this code will + * auto place the windows in a cascade diagonially across the main + * monitor of the Mac. * * Results: - * The bounds are returned in geometry. + * Window bounds. * * Side effects: * None. @@ -4508,44 +4673,25 @@ TkGetPointerCoords( *---------------------------------------------------------------------- */ -static void +static NSRect InitialWindowBounds( TkWindow *winPtr, /* Window to get initial bounds for. */ - WindowRef macWindow, - Rect *geometry) /* On return the initial bounds. */ + NSWindow *macWindow) { WmInfo *wmPtr = winPtr->wmInfoPtr; if (!(wmPtr->sizeHintsFlags & (USPosition | PPosition))) { - WindowRef parent; + static NSPoint cascadePoint = { .x = 0, .y = 0 }; + NSRect frame; - parent = GetFrontWindowOfClass(wmPtr->macClass, false); - if (parent && parent == macWindow) { - parent = GetNextWindowOfClass(parent, wmPtr->macClass, false); - } - if (parent && parent != macWindow) { - Rect bounds; - - ChkErr(RepositionWindow, macWindow, parent, - kWindowCascadeOnParentWindowScreen); - ChkErr(GetWindowBounds, macWindow, kWindowStructureRgn, &bounds); - wmPtr->x = bounds.left; - wmPtr->y = bounds.top; - } else { - static SInt16 menuBarHeight = 0; - - if (!menuBarHeight) { - ChkErr(GetThemeMenuBarHeight, &menuBarHeight); - } - wmPtr->x = 5; - wmPtr->y = menuBarHeight + 5; - } + cascadePoint = [macWindow cascadeTopLeftFromPoint:cascadePoint]; + frame = [macWindow frame]; + wmPtr->x = frame.origin.x; + wmPtr->y = tkMacOSXZeroScreenHeight - (frame.origin.y + + frame.size.height); } - - geometry->left = wmPtr->x; - geometry->top = wmPtr->y; - geometry->right = wmPtr->x + winPtr->changes.width; - geometry->bottom = wmPtr->y + winPtr->changes.height; + return NSMakeRect(wmPtr->x, wmPtr->y, winPtr->changes.width, + winPtr->changes.height); } /* @@ -4553,9 +4699,9 @@ InitialWindowBounds( * * TkMacOSXResizable -- * - * This function determines if the passed in window is part of - * a toplevel window that is resizable. If the window is - * resizable in the x, y or both directions, true is returned. + * This function determines if the passed in window is part of a toplevel + * window that is resizable. If the window is resizable in the x, y or + * both directions, true is returned. * * Results: * True if resizable, false otherwise. @@ -4593,10 +4739,10 @@ TkMacOSXResizable( * * TkMacOSXGrowToplevel -- * - * The function is invoked when the user clicks in the grow region - * of a Tk window. The function will handle the dragging - * procedure and not return until completed. Finally, the function - * may place information Tk's event queue is the window was resized. + * The function is invoked when the user clicks in the grow region of a + * Tk window. The function will handle the dragging procedure and not + * return until completed. Finally, the function may place information + * Tk's event queue is the window was resized. * * Results: * True if events were placed on event queue, false otherwise. @@ -4609,104 +4755,9 @@ TkMacOSXResizable( int TkMacOSXGrowToplevel( - WindowRef whichWindow, - Point start) + void *whichWindow, + XPoint start) { - Point where = start; - TkDisplay *dispPtr; - Rect portRect; - CGrafPtr destPort = GetWindowPort(whichWindow); - - QDGlobalToLocalPoint(destPort, &where); - GetPortBounds(destPort, &portRect); - if (where.h > (portRect.right - 16) && - where.v > (portRect.bottom - 16)) { - Window window; - TkWindow *winPtr; - WmInfo *wmPtr; - int minWidth, minHeight, maxWidth, maxHeight; - Rect limits, bounds, *maxBounds; - Boolean resizeResult; - - window = TkMacOSXGetXWindow(whichWindow); - dispPtr = TkGetDisplayList(); - winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window); - wmPtr = winPtr->wmInfoPtr; - maxBounds = (Rect*)(dispPtr->display->screens->ext_data); - - if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) && - (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) { - return false; - } - GetMinSize(winPtr, &minWidth, &minHeight); - GetMaxSize(winPtr, &maxWidth, &maxHeight); - if (wmPtr->gridWin != NULL) { - int base = winPtr->reqWidth - (wmPtr->reqGridWidth - * wmPtr->widthInc); - - if (base < 0) { - base = 0; - } - limits.left = base + (minWidth * wmPtr->widthInc); - limits.right = base + (maxWidth * wmPtr->widthInc); - base = winPtr->reqHeight - (wmPtr->reqGridHeight - * wmPtr->heightInc); - if (base < 0) { - base = 0; - } - limits.top = base + (minHeight * wmPtr->heightInc); - limits.bottom = base + (maxHeight * wmPtr->heightInc); - } else { - limits.left = minWidth; - limits.right = maxWidth; - limits.top = minHeight; - limits.bottom = maxHeight; - } - if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) { - limits.left = limits.right = winPtr->changes.width; - } - if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) { - limits.top = limits.bottom = winPtr->changes.height; - } - if (PtInRect(start, maxBounds)) { - Rect strBounds, strWidths, limitBounds; - - ChkErr(GetWindowBounds, whichWindow, kWindowStructureRgn, - &strBounds); - ChkErr(GetWindowStructureWidths, whichWindow, &strWidths); - - limitBounds.left = limits.left + (strBounds.left + strWidths.left); - limitBounds.right = limits.right + - (strBounds.left + strWidths.left + strWidths.right); - limitBounds.top = limits.top + (strBounds.top + strWidths.top); - limitBounds.bottom = limits.bottom + - (strBounds.top + strWidths.top + strWidths.bottom); - if (limitBounds.left < maxBounds->left) { - limitBounds.left = maxBounds->left; - } - if (limitBounds.right > maxBounds->right) { - limitBounds.right = maxBounds->right; - } - if (limitBounds.top < maxBounds->top) { - limitBounds.top = maxBounds->top; - } - if (limitBounds.bottom > maxBounds->bottom) { - limitBounds.bottom = maxBounds->bottom; - } - limits.left = limitBounds.left - (strBounds.left + strWidths.left); - limits.right = limitBounds.right - - (strBounds.left + strWidths.left + strWidths.right); - limits.top = limitBounds.top - (strBounds.top + strWidths.top); - limits.bottom = limitBounds.bottom - - (strBounds.top + strWidths.top + strWidths.bottom); - } - TkMacOSXTrackingLoop(1); - resizeResult = ResizeWindow(whichWindow, start, &limits, &bounds); - TkMacOSXTrackingLoop(0); - if (resizeResult) { - return true; - } - } return false; } @@ -4715,8 +4766,8 @@ TkMacOSXGrowToplevel( * * TkSetWMName -- * - * Set the title for a toplevel window. If the window is embedded, - * do not change the window title. + * Set the title for a toplevel window. If the window is embedded, do not + * change the window title. * * Results: * None. @@ -4732,20 +4783,13 @@ TkSetWMName( TkWindow *winPtr, Tk_Uid titleUid) { - CFStringRef title; - if (Tk_IsEmbedded(winPtr)) { return; } - title = CFStringCreateWithBytes(NULL, (const unsigned char*) titleUid, - strlen(titleUid), kCFStringEncodingUTF8, false); - if (title) { - WindowRef macWin = TkMacOSXDrawableWindow(winPtr->window); - - SetWindowTitleWithCFString(macWin, title); - CFRelease(title); - } + NSString *title = [[NSString alloc] initWithUTF8String:titleUid]; + [TkMacOSXDrawableWindow(winPtr->window) setTitle:title]; + [title release]; } /* @@ -4753,8 +4797,8 @@ TkSetWMName( * * TkGetTransientMaster -- * - * If the passed window has the TRANSIENT_FOR property set this - * will return the master window. Otherwise it will return None. + * If the passed window has the TRANSIENT_FOR property set this will + * return the master window. Otherwise it will return None. * * Results: * The master window or None. @@ -4780,7 +4824,7 @@ TkGetTransientMaster( * * TkMacOSXGetXWindow -- * - * Returns the X window Id associated with the given WindowRef. + * Returns the X window Id associated with the given NSWindow*. * * Results: * The window id is returned. None is returned if not a Tk window. @@ -4793,14 +4837,14 @@ TkGetTransientMaster( Window TkMacOSXGetXWindow( - WindowRef macWinPtr) + void *macWinPtr) { Tcl_HashEntry *hPtr; - if ((macWinPtr == NULL) || !windowHashInit) { + if (!macWinPtr || !windowHashInit) { return None; } - hPtr = Tcl_FindHashEntry(&windowTable, (char *) macWinPtr); + hPtr = Tcl_FindHashEntry(&windowTable, macWinPtr); if (hPtr == NULL) { return None; } @@ -4810,12 +4854,38 @@ TkMacOSXGetXWindow( /* *---------------------------------------------------------------------- * + * TkMacOSXGetTkWindow -- + * + * Returns the TkWindow* associated with the given NSWindow*. + * + * Results: + * The TkWindow* returned. NULL is returned if not a Tk window. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +TkWindow* +TkMacOSXGetTkWindow( + NSWindow *w) +{ + Window window = TkMacOSXGetXWindow(w); + TkDisplay *dispPtr = TkGetDisplayList(); + + return (window != None ? + (TkWindow *)Tk_IdToWindow(dispPtr->display, window) : NULL); +} + +/* + *---------------------------------------------------------------------- + * * TkMacOSXIsWindowZoomed -- * - * Ask Carbon if the given window is in the zoomed out state. - * Because dragging & growing a window can change the Carbon - * zoom state, we cannot rely on wmInfoPtr->hints.initial_state - * for this information. + * Ask Carbon if the given window is in the zoomed out state. Because + * dragging & growing a window can change the Carbon zoom state, we + * cannot rely on wmInfoPtr->hints.initial_state for this information. * * Results: * True if window is zoomed out, false otherwise. @@ -4830,41 +4900,7 @@ MODULE_SCOPE int TkMacOSXIsWindowZoomed( TkWindow *winPtr) { - WmInfo *wmPtr = winPtr->wmInfoPtr; - int maxWidth, maxHeight; - Point idealSize; - - if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) && - (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) { - return false; - } - GetMaxSize(winPtr, &maxWidth, &maxHeight); - if (wmPtr->gridWin != NULL) { - int base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc); - - if (base < 0) { - base = 0; - } - maxWidth = base + (maxWidth * wmPtr->widthInc); - base = winPtr->reqHeight - (wmPtr->reqGridHeight * wmPtr->heightInc); - if (base < 0) { - base = 0; - } - maxHeight = base + (maxHeight * wmPtr->heightInc); - } - if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) { - idealSize.h = winPtr->changes.width; - } else { - idealSize.h = maxWidth; - } - if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) { - idealSize.v = winPtr->changes.height; - } else { - idealSize.v = maxHeight; - } - - return IsWindowInStandardState(TkMacOSXDrawableWindow(winPtr->window), - &idealSize, NULL); + return [TkMacOSXDrawableWindow(winPtr->window) isZoomed]; } /* @@ -4872,11 +4908,10 @@ TkMacOSXIsWindowZoomed( * * TkMacOSXZoomToplevel -- * - * The function is invoked when the user clicks in the zoom region - * of a Tk window or when the window state is set/unset to "zoomed" - * manually. If the window is to be zoomed (in or out), the window - * size is changed and events are generated to let Tk know what - * happened. + * The function is invoked when the user clicks in the zoom region of a + * Tk window or when the window state is set/unset to "zoomed" manually. + * If the window is to be zoomed (in or out), the window size is changed + * and events are generated to let Tk know what happened. * * Results: * True if events were placed on event queue, false otherwise. @@ -4889,65 +4924,33 @@ TkMacOSXIsWindowZoomed( int TkMacOSXZoomToplevel( - WindowRef whichWindow, /* The Macintosh window to zoom. */ + void *whichWindow, /* The Macintosh window to zoom. */ short zoomPart) /* Either inZoomIn or inZoomOut */ { - Window window; - TkDisplay *dispPtr; - TkWindow *winPtr; + NSWindow *window = whichWindow; + TkWindow *winPtr = TkMacOSXGetTkWindow(window); WmInfo *wmPtr; - Point idealSize; - int maxWidth, maxHeight; - OSStatus err; - window = TkMacOSXGetXWindow(whichWindow); - dispPtr = TkGetDisplayList(); - winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window); + if (!winPtr || !winPtr->wmInfoPtr) { + return false; + } wmPtr = winPtr->wmInfoPtr; - if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) && (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) { return false; } - GetMaxSize(winPtr, &maxWidth, &maxHeight); - if (wmPtr->gridWin != NULL) { - int base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc); - if (base < 0) { - base = 0; - } - maxWidth = base + (maxWidth * wmPtr->widthInc); - base = winPtr->reqHeight - (wmPtr->reqGridHeight * wmPtr->heightInc); - if (base < 0) { - base = 0; - } - maxHeight = base + (maxHeight * wmPtr->heightInc); - } - if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) { - idealSize.h = winPtr->changes.width; - } else { - idealSize.h = maxWidth; - } - if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) { - idealSize.v = winPtr->changes.height; - } else { - idealSize.v = maxHeight; - } - - /* Do nothing if already in desired zoom state */ - if (!IsWindowInStandardState(whichWindow, &idealSize, NULL) == - (zoomPart == inZoomIn)) { - return false; - } + /* + * Do nothing if already in desired zoom state. + */ - err = ChkErr(ZoomWindowIdeal, whichWindow, zoomPart, &idealSize); - if (err == noErr) { - wmPtr->hints.initial_state = - (zoomPart == inZoomIn ? NormalState : ZoomState); - return true; - } else { + if (![window isZoomed] == (zoomPart == inZoomIn)) { return false; } + [window zoom:NSApp]; + wmPtr->hints.initial_state = + (zoomPart == inZoomIn ? NormalState : ZoomState); + return true; } /* @@ -4956,9 +4959,8 @@ TkMacOSXZoomToplevel( * TkUnsupported1Cmd -- * * This procedure is invoked to process the - * "::tk::unsupported::MacWindowStyle" Tcl command. - * This command allows you to set the style of decoration - * for a Macintosh window. + * "::tk::unsupported::MacWindowStyle" Tcl command. This command allows + * you to set the style of decoration for a Macintosh window. * * Results: * A standard Tcl result. @@ -4972,19 +4974,18 @@ TkMacOSXZoomToplevel( /* ARGSUSED */ int TkUnsupported1ObjCmd( - ClientData clientData, /* Main window associated with - * interpreter. */ + ClientData clientData, /* Main window associated with interpreter. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj * const objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { - static const char *subcmds[] = { + static const char *const subcmds[] = { "style", NULL }; enum SubCmds { TKMWS_STYLE }; - Tk_Window tkwin = (Tk_Window) clientData; + Tk_Window tkwin = clientData; TkWindow *winPtr; int index; @@ -4993,8 +4994,64 @@ TkUnsupported1ObjCmd( return TCL_ERROR; } - winPtr = (TkWindow *) Tk_NameToWindow(interp, - Tcl_GetString(objv[2]), tkwin); + + /* 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) { + colorName = [NSColor darkGrayColor]; //use #545454 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*light*") == 1) { + colorName = [NSColor lightGrayColor]; //use #ababab 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"; + } + } + + + winPtr = (TkWindow *) + Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin); if (winPtr == NULL) { return TCL_ERROR; } @@ -5005,8 +5062,8 @@ TkUnsupported1ObjCmd( return TCL_ERROR; } - if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option", - 0, &index) != TCL_OK) { + if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option", 0, + &index) != TCL_OK) { return TCL_ERROR; } if (((enum SubCmds) index) == TKMWS_STYLE) { @@ -5026,9 +5083,8 @@ TkUnsupported1ObjCmd( * WmWinStyle -- * * This procedure is invoked to process the - * "::tk::unsupported::MacWindowStyle style" subcommand. - * This command allows you to set the style of decoration - * for a Macintosh window. + * "::tk::unsupported::MacWindowStyle style" subcommand. This command + * allows you to set the style of decoration for a Macintosh window. * * Results: * A standard Tcl result. @@ -5038,6 +5094,7 @@ TkUnsupported1ObjCmd( * *---------------------------------------------------------------------- */ + static int WmWinStyle( Tcl_Interp *interp, /* Current interpreter. */ @@ -5047,53 +5104,37 @@ WmWinStyle( { struct StrIntMap { const char *strValue; - UInt32 intValue; - }; - static const struct StrIntMap styleMap[] = { - { "documentProc", documentProc }, - { "noGrowDocProc", documentProc }, - { "dBoxProc", dBoxProc }, - { "plainDBox", plainDBox }, - { "altDBoxProc", altDBoxProc }, - { "movableDBoxProc", movableDBoxProc }, - { "zoomDocProc", zoomDocProc }, - { "zoomNoGrow", zoomNoGrow }, - { "floatProc", floatGrowProc }, - { "floatGrowProc", floatGrowProc }, - { "floatZoomProc", floatZoomGrowProc }, - { "floatZoomGrowProc", floatZoomGrowProc }, - { "floatSideProc", floatSideGrowProc }, - { "floatSideGrowProc", floatSideGrowProc }, - { "floatSideZoomProc", floatSideZoomGrowProc }, - { "floatSideZoomGrowProc", floatSideZoomGrowProc }, - { NULL, 0 } + UInt64 intValue; }; static const struct StrIntMap classMap[] = { - { "alert", kAlertWindowClass }, - { "moveableAlert", kMovableAlertWindowClass }, - { "modal", kModalWindowClass }, - { "moveableModal", kMovableModalWindowClass }, - { "floating", kFloatingWindowClass }, - { "document", kDocumentWindowClass }, - { "utility", kUtilityWindowClass }, - { "help", kHelpWindowClass }, - { "sheet", kSheetWindowClass }, - { "toolbar", kToolbarWindowClass }, - { "plain", kPlainWindowClass }, - { "overlay", kOverlayWindowClass }, - { "sheetAlert", kSheetAlertWindowClass }, - { "altPlain", kAltPlainWindowClass }, - { "simple", kSimpleWindowClass }, - { "drawer", kDrawerWindowClass }, - { NULL, 0 } + { "alert", kAlertWindowClass }, + { "moveableAlert", kMovableAlertWindowClass }, + { "modal", kModalWindowClass }, + { "moveableModal", kMovableModalWindowClass }, + { "floating", kFloatingWindowClass }, + { "document", kDocumentWindowClass }, + { "utility", kUtilityWindowClass }, + { "help", kHelpWindowClass }, + { "sheet", kSheetWindowClass }, + { "toolbar", kToolbarWindowClass }, + { "plain", kPlainWindowClass }, + { "overlay", kOverlayWindowClass }, + { "sheetAlert", kSheetAlertWindowClass }, + { "altPlain", kAltPlainWindowClass }, + { "simple", kSimpleWindowClass }, + { "drawer", kDrawerWindowClass }, + { NULL } }; static const struct StrIntMap compositeAttrMap[] = { - { "none", kWindowNoAttributes }, - { "standardDocument", kWindowStandardDocumentAttributes }, - { "standardFloating", kWindowStandardFloatingAttributes }, - { "fullZoom", kWindowFullZoomAttribute }, - { NULL, 0 } + { "none", kWindowNoAttributes }, + { "standardDocument", kWindowStandardDocumentAttributes }, + { "standardFloating", kWindowStandardFloatingAttributes }, + { "fullZoom", kWindowFullZoomAttribute }, + { NULL } }; + + /* Map window attributes. Color and opacity are mapped to NULL; these are parsed from the objv in TkUnsupported1ObjCmd.*/ + static const struct StrIntMap attrMap[] = { { "closeBox", kWindowCloseBoxAttribute }, { "horizontalZoom", kWindowHorizontalZoomAttribute }, @@ -5118,107 +5159,120 @@ WmWinStyle( { "liveResize", kWindowLiveResizeAttribute }, { "ignoreClicks", kWindowIgnoreClicksAttribute }, { "noConstrain", kWindowNoConstrainAttribute }, - { NULL, 0 } + { "doesNotHide", tkWindowDoesNotHideAttribute }, + { "canJoinAllSpaces", tkCanJoinAllSpacesAttribute }, + { "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 }, + { NULL } }; + int index, i; WmInfo *wmPtr = winPtr->wmInfoPtr; if (objc == 3) { - if (wmPtr->style != -1) { - for (i = 0; styleMap[i].strValue != NULL; i++) { - if (wmPtr->style == (short)(styleMap[i].intValue)) { - Tcl_SetObjResult(interp, - Tcl_NewStringObj(styleMap[i].strValue, -1)); - return TCL_OK; - } - } - Tcl_Panic("invalid style"); - } else { - Tcl_Obj *attributeList, *newResult = NULL; - WindowAttributes attributes; + Tcl_Obj *attributeList, *newResult = NULL; + UInt64 attributes; - for (i = 0; classMap[i].strValue != NULL; i++) { - if (wmPtr->macClass == classMap[i].intValue) { - newResult = Tcl_NewStringObj(classMap[i].strValue, -1); - break; - } - } - if (newResult == NULL) { - Tcl_Panic("invalid class"); + for (i = 0; classMap[i].strValue != NULL; i++) { + if (wmPtr->macClass == classMap[i].intValue) { + newResult = Tcl_NewStringObj(classMap[i].strValue, -1); + break; } + } + if (newResult == NULL) { + Tcl_Panic("invalid class"); + } - attributeList = Tcl_NewListObj(0, NULL); - attributes = wmPtr->attributes; - for (i = 0; compositeAttrMap[i].strValue != NULL; i++) { - UInt32 intValue = compositeAttrMap[i].intValue; + attributeList = Tcl_NewListObj(0, NULL); + attributes = wmPtr->attributes; - if (intValue && (attributes & intValue) == intValue) { - Tcl_ListObjAppendElement(interp, attributeList, - Tcl_NewStringObj(compositeAttrMap[i].strValue, - -1)); - attributes &= ~intValue; - break; - } - } - for (i = 0; attrMap[i].strValue != NULL; i++) { - if (attributes & attrMap[i].intValue) { - Tcl_ListObjAppendElement(interp, attributeList, - Tcl_NewStringObj(attrMap[i].strValue, -1)); - } + for (i = 0; compositeAttrMap[i].strValue != NULL; i++) { + UInt64 intValue = compositeAttrMap[i].intValue; + + if (intValue && (attributes & intValue) == intValue) { + Tcl_ListObjAppendElement(interp, attributeList, + Tcl_NewStringObj(compositeAttrMap[i].strValue, + -1)); + attributes &= ~intValue; + break; } - Tcl_ListObjAppendElement(interp, newResult, attributeList); - Tcl_SetObjResult(interp, newResult); } - } else if (objc == 4) { - if (Tcl_GetIndexFromObjStruct(interp, objv[3], styleMap, - sizeof(struct StrIntMap), "style", 0, &index) != TCL_OK) { - return TCL_ERROR; + for (i = 0; attrMap[i].strValue != NULL; i++) { + if (attributes & attrMap[i].intValue) { + Tcl_ListObjAppendElement(interp, attributeList, + Tcl_NewStringObj(attrMap[i].strValue, -1)); + } } - wmPtr->style = styleMap[index].intValue; - } else if (objc == 5) { + Tcl_ListObjAppendElement(interp, newResult, attributeList); + Tcl_SetObjResult(interp, newResult); + } else { int attrObjc; Tcl_Obj **attrObjv = NULL; - WindowClass oldClass = wmPtr->macClass; - WindowAttributes oldAttributes = wmPtr->attributes; + WindowClass macClass; + UInt64 oldAttributes = wmPtr->attributes; + int oldFlags = wmPtr->flags; if (Tcl_GetIndexFromObjStruct(interp, objv[3], classMap, sizeof(struct StrIntMap), "class", 0, &index) != TCL_OK) { goto badClassAttrs; } - wmPtr->macClass = classMap[index].intValue; - if (!IsValidWindowClass(wmPtr->macClass)) { - goto badClassAttrs; - } - if (Tcl_ListObjGetElements(interp, objv[4], &attrObjc, &attrObjv) - != TCL_OK) { - goto badClassAttrs; - } - wmPtr->attributes = kWindowNoAttributes; - for (i = 0; i < attrObjc; i++) { - if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i], - compositeAttrMap, sizeof(struct StrIntMap), - "attribute", 0, &index) == TCL_OK) { - wmPtr->attributes |= compositeAttrMap[index].intValue; - } else if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i], - attrMap, sizeof(struct StrIntMap), - "attribute", 0, &index) == TCL_OK) { - Tcl_ResetResult(interp); - wmPtr->attributes |= attrMap[index].intValue; - } else { + macClass = classMap[index].intValue; + if (objc == 5) { + if (Tcl_ListObjGetElements(interp, objv[4], &attrObjc, &attrObjv) + != TCL_OK) { goto badClassAttrs; } + wmPtr->attributes = kWindowNoAttributes; + for (i = 0; i < attrObjc; i++) { + if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i], + compositeAttrMap, sizeof(struct StrIntMap), + "attribute", 0, &index) == TCL_OK) { + wmPtr->attributes |= compositeAttrMap[index].intValue; + } else if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i], + attrMap, sizeof(struct StrIntMap), + "attribute", 0, &index) == TCL_OK) { + Tcl_ResetResult(interp); + wmPtr->attributes |= attrMap[index].intValue; + } else { + goto badClassAttrs; + } + } + } else { + wmPtr->attributes = macClassAttrs[macClass].defaultAttrs; } - ApplyWindowClassAttributeChanges(winPtr, NULL, oldClass, oldAttributes, - 0); - wmPtr->style = -1; + wmPtr->attributes &= (tkAlwaysValidAttributes | + macClassAttrs[macClass].validAttrs); + wmPtr->flags |= macClassAttrs[macClass].flags; + wmPtr->macClass = macClass; + + ApplyWindowAttributeFlagChanges(winPtr, NULL, oldAttributes, oldFlags, + 0, 1); + return TCL_OK; badClassAttrs: - wmPtr->macClass = oldClass; wmPtr->attributes = oldAttributes; return TCL_ERROR; } + + return TCL_OK; } @@ -5227,8 +5281,8 @@ WmWinStyle( * * TkpMakeMenuWindow -- * - * Configure the window to be either a undecorated pull-down - * (or pop-up) menu, or as a toplevel floating menu (palette). + * Configure the window to be either a undecorated pull-down (or pop-up) + * menu, or as a toplevel floating menu (palette). * * Results: * None. @@ -5242,10 +5296,10 @@ WmWinStyle( void TkpMakeMenuWindow( Tk_Window tkwin, /* New window. */ - int transient) /* 1 means menu is only posted briefly as - * a popup or pulldown or cascade. 0 means - * menu is always visible, e.g. as a - * floating menu. */ + int transient) /* 1 means menu is only posted briefly as a + * popup or pulldown or cascade. 0 means menu + * is always visible, e.g. as a floating + * menu. */ { TkWindow *winPtr = (TkWindow *) tkwin; @@ -5265,8 +5319,8 @@ TkpMakeMenuWindow( * * TkMacOSXMakeRealWindowExist -- * - * This function finally creates the real Macintosh window that - * the Mac actually understands. + * This function finally creates the real Macintosh window that the Mac + * actually understands. * * Results: * None. @@ -5282,13 +5336,7 @@ TkMacOSXMakeRealWindowExist( TkWindow *winPtr) /* Tk window. */ { WmInfo *wmPtr = winPtr->wmInfoPtr; - WindowRef newWindow = NULL; - ControlRef rootControl = NULL; MacDrawable *macWin; - Rect initialBounds = {42, 0, 43, 1}, geometry, strWidths; - short structureW, structureH; - TkMacOSXWindowList *listPtr; - OSStatus err; if (TkMacOSXHostToplevelExists(winPtr)) { return; @@ -5315,8 +5363,8 @@ TkMacOSXMakeRealWindowExist( Tcl_Panic("TkMacOSXMakeRealWindowExist could not find container"); } if (tkMacOSXEmbedHandler->containerExistProc && - tkMacOSXEmbedHandler->containerExistProc((Tk_Window) winPtr) != - TCL_OK) { + tkMacOSXEmbedHandler->containerExistProc((Tk_Window) winPtr) + != TCL_OK) { Tcl_Panic("ContainerExistProc could not make container"); } return; @@ -5326,89 +5374,86 @@ TkMacOSXMakeRealWindowExist( */ } - if (wmPtr->style == -1) { - if (!IsValidWindowClass(wmPtr->macClass)) { - TkMacOSXDbgMsg("Invalid window class: %ld", wmPtr->macClass); - wmPtr->macClass = kPlainWindowClass; - } - wmPtr->attributes = (wmPtr->attributes | kWindowAsyncDragAttribute) & - GetAvailableWindowAttributes(wmPtr->macClass); - err = ChkErr(CreateNewWindow, wmPtr->macClass, wmPtr->attributes, - &initialBounds, &newWindow); - if (err != noErr) { - newWindow = NULL; - } - } else { - TkMacOSXDbgMsg("Window creation via NewCWindow API is deprecated, " - "use a window class instead of style %d", wmPtr->style); - newWindow = NewCWindow(NULL, &initialBounds, "\p", false, - wmPtr->style, (WindowRef) -1, true, 0); - } - - if (newWindow == NULL) { + WindowClass macClass = wmPtr->macClass; + wmPtr->attributes &= (tkAlwaysValidAttributes | + macClassAttrs[macClass].validAttrs); + wmPtr->flags |= macClassAttrs[macClass].flags | + ((wmPtr->attributes & kWindowResizableAttribute) ? 0 : + WM_WIDTH_NOT_RESIZABLE|WM_HEIGHT_NOT_RESIZABLE); + UInt64 attributes = (wmPtr->attributes & + ~macClassAttrs[macClass].forceOffAttrs) | + macClassAttrs[macClass].forceOnAttrs; + NSUInteger styleMask = macClassAttrs[macClass].styleMask | + ((attributes & kWindowNoTitleBarAttribute) ? 0 : NSTitledWindowMask) | + ((attributes & kWindowCloseBoxAttribute) ? NSClosableWindowMask : 0) | + ((attributes & kWindowCollapseBoxAttribute) ? + NSMiniaturizableWindowMask : 0) | + ((attributes & kWindowResizableAttribute) ? NSResizableWindowMask : 0) | + ((attributes & kWindowMetalAttribute) ? + NSTexturedBackgroundWindowMask : 0) | + ((attributes & kWindowUnifiedTitleAndToolbarAttribute) ? + NSUnifiedTitleAndToolbarWindowMask : 0) | + ((attributes & kWindowSideTitlebarAttribute) ? 1 << 9 : 0) | + (attributes >> WM_NSMASK_SHIFT); + Class winClass = (macClass == kDrawerWindowClass ? [NSDrawerWindow class] : + (styleMask & (NSUtilityWindowMask|NSDocModalWindowMask| + NSNonactivatingPanelMask|NSHUDWindowMask)) ? [NSPanel 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 + styleMask:styleMask backing:NSBackingStoreBuffered defer:YES]; + if (!window) { Tcl_Panic("couldn't allocate new Mac window"); } - - ChkErr(GetWindowStructureWidths, newWindow, &strWidths); - if (wmPtr->macClass == kFloatingWindowClass) { - /* - * Workaround GetWindowStructureWidths() Carbon bug: + TkMacOSXMakeUncollectable(window); + TKContentView *contentView = [[TKContentView alloc] + initWithFrame:NSZeroRect]; + [window setContentView:contentView]; + [contentView release]; + [window setDelegate:NSApp]; + [window setAcceptsMouseMovedEvents:YES]; + [window setReleasedWhenClosed:NO]; + [window setAutodisplay:NO]; + if (styleMask & NSUtilityWindowMask) { + [(NSPanel*)window setFloatingPanel:YES]; + } + if ((styleMask & (NSTexturedBackgroundWindowMask|NSHUDWindowMask)) && + !(styleMask & NSDocModalWindowMask)) { + /* + * Workaround for [Bug 2824538]: Texured windows are draggable + * from opaque content. */ - - strWidths.top = 16; + [window setMovableByWindowBackground:NO]; } - wmPtr->xInParent = strWidths.left; - wmPtr->yInParent = strWidths.top; - structureW = strWidths.left + strWidths.right; - structureH = strWidths.top + strWidths.bottom; - wmPtr->parentWidth = winPtr->changes.width + structureW; - wmPtr->parentHeight = winPtr->changes.height + structureH; - InitialWindowBounds(winPtr, newWindow, &geometry); - geometry.right += structureW; - geometry.bottom += structureH; - ChkErr(SetWindowBounds, newWindow, kWindowStructureRgn, &geometry); - TkMacOSXInstallWindowCarbonEventHandler(NULL, newWindow); - if (ChkErr(CreateRootControl, newWindow, &rootControl) != noErr ) { - Tcl_Panic("couldn't create root control for new Mac window"); - } - if (wmPtr->attributes & kWindowResizableAttribute) { - HIViewRef growBoxView; - err = HIViewFindByID(HIViewGetRoot(newWindow), - kHIViewWindowGrowBoxID, &growBoxView); - if (err == noErr && !HIGrowBoxViewIsTransparent(growBoxView)) { - ChkErr(HIGrowBoxViewSetTransparent, growBoxView, true); - } - } + /* Set background color and opacity of window if those flags are set. */ + if (colorName != NULL) { + [window setBackgroundColor: colorName]; + } - /* - * Add this window to the list of toplevel windows. - */ + if (opaqueTag != NULL) { + [window setOpaque: opaqueTag]; + } - listPtr = (TkMacOSXWindowList *) ckalloc(sizeof(TkMacOSXWindowList)); - listPtr->nextPtr = tkMacOSXWindowListPtr; - listPtr->winPtr = winPtr; - tkMacOSXWindowListPtr = listPtr; + [window setDocumentEdited:NO]; + wmPtr->window = window; + macWin->view = contentView; + TkMacOSXApplyWindowAttributes(winPtr, window); - macWin->grafPtr = GetWindowPort(newWindow); - macWin->rootControl = rootControl; + NSRect geometry = InitialWindowBounds(winPtr, window); + geometry.size.width += structureRect.size.width; + geometry.size.height += structureRect.size.height; + geometry.origin.y = tkMacOSXZeroScreenHeight - (geometry.origin.y + + geometry.size.height); + [window setFrame:geometry display:NO]; - if (wmPtr->master != None || winPtr->atts.override_redirect) { - ApplyMasterOverrideChanges(winPtr, newWindow); - } - SetWindowModified(newWindow, false); - TkMacOSXRegisterOffScreenWindow((Window) macWin, (GWorldPtr) newWindow); + TkMacOSXRegisterOffScreenWindow((Window) macWin, window); macWin->flags |= TK_HOST_EXISTS; - ChkErr(GetWindowClass, newWindow, &(wmPtr->macClass)); - ChkErr(GetWindowAttributes, newWindow, &(wmPtr->attributes)); - -#ifdef TK_MAC_DEBUG_WINDOWS - TkMacOSXInitNamedDebugSymbol(HIToolbox, void, DebugPrintWindow, WindowRef); - if (DebugPrintWindow) { - DebugPrintWindow(newWindow); - } -#endif /* TK_MAC_DEBUG_WINDOWS */ } /* @@ -5416,8 +5461,8 @@ TkMacOSXMakeRealWindowExist( * * TkMacOSXRegisterOffScreenWindow -- * - * This function adds the passed in Off Screen Port to the - * hash table that maps Mac windows to root X windows. + * This function adds the passed in Off Screen Port to the hash table + * that maps Mac windows to root X windows. * * Results: * None. @@ -5431,7 +5476,7 @@ TkMacOSXMakeRealWindowExist( void TkMacOSXRegisterOffScreenWindow( Window window, /* Window structure. */ - GWorldPtr portPtr) /* Pointer to a Mac GWorld. */ + void *portPtr) /* Pointer to a Mac Window. */ { Tcl_HashEntry *valueHashPtr; int isNew; @@ -5452,9 +5497,8 @@ TkMacOSXRegisterOffScreenWindow( * * TkMacOSXUnregisterMacWindow -- * - * Given a macintosh port window, this function removes the - * association between this window and the root X window that - * Tk cares about. + * Given a macintosh port window, this function removes the association + * between this window and the root X window that Tk cares about. * * Results: * None. @@ -5467,16 +5511,16 @@ TkMacOSXRegisterOffScreenWindow( void TkMacOSXUnregisterMacWindow( - WindowRef macWinPtr) /* Reference to a Mac Window */ + void *macWinPtr) /* Reference to a Mac Window */ { Tcl_HashEntry *entryPtr; if (!windowHashInit) { Tcl_Panic("TkMacOSXUnregisterMacWindow: unmapping before inited"); } - entryPtr = Tcl_FindHashEntry(&windowTable,(char *) macWinPtr); + entryPtr = Tcl_FindHashEntry(&windowTable, macWinPtr); if (!entryPtr) { - TkMacOSXDbgMsg("Failed to find window %08x", (int) macWinPtr); + TkMacOSXDbgMsg("Failed to find window %p", macWinPtr); } else { Tcl_DeleteHashEntry(entryPtr); } @@ -5487,9 +5531,8 @@ TkMacOSXUnregisterMacWindow( * * TkMacOSXSetScrollbarGrow -- * - * Sets a flag for a toplevel window indicating that the passed - * Tk scrollbar window will display the grow region for the - * toplevel window. + * Sets a flag for a toplevel window indicating that the passed Tk + * scrollbar window will display the grow region for the toplevel window. * * Results: * None. @@ -5521,15 +5564,15 @@ TkMacOSXSetScrollbarGrow( * TkWmFocusToplevel -- * * This is a utility procedure invoked by focus-management code. It - * exists because of the extra wrapper windows that exist under - * Unix; its job is to map from wrapper windows to the - * corresponding toplevel windows. On PCs and Macs there are no - * wrapper windows so no mapping is necessary; this procedure just - * determines whether a window is a toplevel or not. + * exists because of the extra wrapper windows that exist under Unix; its + * job is to map from wrapper windows to the corresponding toplevel + * windows. On PCs and Macs there are no wrapper windows so no mapping is + * necessary; this procedure just determines whether a window is a + * toplevel or not. * * Results: - * If winPtr is a toplevel window, returns the pointer to the - * window; otherwise returns NULL. + * If winPtr is a toplevel window, returns the pointer to the window; + * otherwise returns NULL. * * Side effects: * None. @@ -5553,13 +5596,13 @@ TkWmFocusToplevel( * * TkpGetWrapperWindow -- * - * This is a utility procedure invoked by focus-management code. It - * maps to the wrapper for a top-level, which is just the same - * as the top-level on Macs and PCs. + * This is a utility procedure invoked by focus-management code. It maps + * to the wrapper for a top-level, which is just the same as the + * top-level on Macs and PCs. * * Results: - * If winPtr is a toplevel window, returns the pointer to the - * window; otherwise returns NULL. + * If winPtr is a toplevel window, returns the pointer to the window; + * otherwise returns NULL. * * Side effects: * None. @@ -5583,8 +5626,8 @@ TkpGetWrapperWindow( * * TkpWmSetState -- * - * Sets the window manager state for the wrapper window of a - * given toplevel window. + * Sets the window manager state for the wrapper window of a given + * toplevel window. * * Results: * None. @@ -5596,13 +5639,13 @@ TkpGetWrapperWindow( */ void -TkpWmSetState(winPtr, state) - TkWindow *winPtr; /* Toplevel window to operate on. */ - int state; /* One of IconicState, ZoomState, NormalState, +TkpWmSetState( + TkWindow *winPtr, /* Toplevel window to operate on. */ + int state) /* One of IconicState, ZoomState, NormalState, * or WithdrawnState. */ { WmInfo *wmPtr = winPtr->wmInfoPtr; - WindowRef macWin; + NSWindow *macWin; wmPtr->hints.initial_state = state; if (wmPtr->flags & WM_NEVER_MAPPED) { @@ -5615,25 +5658,23 @@ TkpWmSetState(winPtr, state) Tk_UnmapWindow((Tk_Window) winPtr); } else if (state == IconicState) { /* - * The window always gets unmapped. If we can show the - * icon version of the window we also collapse it. + * The window always gets unmapped. If we can show the icon version of + * the window we also collapse it. */ - if (IsWindowCollapsable(macWin) && !IsWindowCollapsed(macWin)) { - CollapseWindow(macWin, true); + + if (macWin && ([macWin styleMask] & NSMiniaturizableWindowMask) && + ![macWin isMiniaturized]) { + [macWin miniaturize:NSApp]; } Tk_UnmapWindow((Tk_Window) winPtr); - } else if (state == NormalState) { - Tk_MapWindow((Tk_Window) winPtr); - if (IsWindowCollapsable(macWin) && IsWindowCollapsed(macWin)) { - CollapseWindow(macWin, false); - } - TkMacOSXZoomToplevel(macWin, inZoomIn); - } else if (state == ZoomState) { + } else if (state == NormalState || state == ZoomState) { Tk_MapWindow((Tk_Window) winPtr); - if (IsWindowCollapsable(macWin) && IsWindowCollapsed(macWin)) { - CollapseWindow(macWin, false); + if (macWin && ([macWin styleMask] & NSMiniaturizableWindowMask) && + [macWin isMiniaturized]) { + [macWin deminiaturize:NSApp]; } - TkMacOSXZoomToplevel(macWin, inZoomOut); + TkMacOSXZoomToplevel(macWin, state == NormalState ? inZoomIn : + inZoomOut); } } @@ -5655,16 +5696,9 @@ TkpWmSetState(winPtr, state) int TkpIsWindowFloating( - WindowRef wRef) + void *wRef) { - WindowClass class; - - if (wRef == NULL) { - return 0; - } - - GetWindowClass(wRef, &class); - return (class == kFloatingWindowClass); + return [(NSWindow *)wRef level] == kCGFloatingWindowLevel; } /* @@ -5695,9 +5729,9 @@ TkMacOSXWindowClass( * * TkMacOSXWindowOffset -- * - * Determines the x and y offset from the orgin of the toplevel - * window dressing (the structure region, ie. title bar) and the - * orgin of the content area. + * Determines the x and y offset from the orgin of the toplevel window + * dressing (the structure region, i.e. title bar) and the orgin of the + * content area. * * Results: * The x & y offset in pixels. @@ -5710,19 +5744,19 @@ TkMacOSXWindowClass( void TkMacOSXWindowOffset( - WindowRef wRef, + void *wRef, int *xOffset, int *yOffset) { - Window window; - TkDisplay *dispPtr; - TkWindow *winPtr; + TkWindow *winPtr = TkMacOSXGetTkWindow(wRef); - window = TkMacOSXGetXWindow(wRef); - dispPtr = TkGetDisplayList(); - winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window); - *xOffset = winPtr->wmInfoPtr->xInParent; - *yOffset = winPtr->wmInfoPtr->yInParent; + if (winPtr && winPtr->wmInfoPtr) { + *xOffset = winPtr->wmInfoPtr->xInParent; + *yOffset = winPtr->wmInfoPtr->yInParent; + } else { + *xOffset = 0; + *yOffset = 0; + } } /* @@ -5730,8 +5764,8 @@ TkMacOSXWindowOffset( * * TkpGetMS -- * - * Return a relative time in milliseconds. It doesn't matter - * when the epoch was. + * Return a relative time in milliseconds. It doesn't matter when the + * epoch was. * * Results: * Number of milliseconds. @@ -5784,15 +5818,14 @@ XSetInputFocus( * * TkpChangeFocus -- * - * This procedure is a stub on the Mac because we always own the - * focus if we are a front most application. + * This procedure is a stub on the Mac because we always own the focus if + * we are a front most application. * * Results: - * The return value is the serial number of the command that - * changed the focus. It may be needed by the caller to filter - * out focus change events that were queued before the command. - * If the procedure doesn't actually change the focus then - * it returns 0. + * The return value is the serial number of the command that changed the + * focus. It may be needed by the caller to filter out focus change + * events that were queued before the command. If the procedure doesn't + * actually change the focus then it returns 0. * * Side effects: * None. @@ -5801,15 +5834,15 @@ XSetInputFocus( */ int -TkpChangeFocus(winPtr, force) - TkWindow *winPtr; /* Window that is to receive the X focus. */ - int force; /* Non-zero means claim the focus even - * if it didn't originally belong to - * topLevelPtr's application. */ +TkpChangeFocus( + TkWindow *winPtr, /* Window that is to receive the X focus. */ + int force) /* Non-zero means claim the focus even if it + * 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. + * We don't really need to do anything on the Mac. Tk will keep all this + * state for us. */ if (winPtr->atts.override_redirect) { @@ -5817,10 +5850,10 @@ TkpChangeFocus(winPtr, force) } /* - * 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, so we can distinguish FocusIn and FocusOut - * events on either side of the mark. + * 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, + * so we can distinguish FocusIn and FocusOut events on either side of the + * mark. */ return NextRequest(winPtr->display); @@ -5831,13 +5864,12 @@ TkpChangeFocus(winPtr, force) * * 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 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 stacking order. - * + * 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 + * 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 + * stacking order. * * Results: * None. @@ -5856,15 +5888,12 @@ WmStackorderToplevelWrapperMap( { TkWindow *childPtr; Tcl_HashEntry *hPtr; - WindowRef macWindow; int newEntry; if (Tk_IsMapped(winPtr) && Tk_IsTopLevel(winPtr) && (winPtr->display == display)) { - macWindow = TkMacOSXDrawableWindow(winPtr->window); - hPtr = Tcl_CreateHashEntry(table, - (const char *) macWindow, &newEntry); + (char*) TkMacOSXDrawableWindow(winPtr->window), &newEntry); Tcl_SetHashValue(hPtr, winPtr); } @@ -5882,8 +5911,8 @@ WmStackorderToplevelWrapperMap( * This procedure returns the stack order of toplevel windows. * * Results: - * An array of pointers to tk window objects in stacking order - * or else NULL if there was an error. + * An array of pointers to tk window objects in stacking order or else + * NULL if there was an error. * * Side effects: * None. @@ -5892,14 +5921,15 @@ WmStackorderToplevelWrapperMap( */ TkWindow ** -TkWmStackorderToplevel(parentPtr) - TkWindow *parentPtr; /* Parent toplevel window. */ +TkWmStackorderToplevel( + TkWindow *parentPtr) /* Parent toplevel window. */ { - WindowRef frontWindow; TkWindow *childWinPtr, **windows, **window_ptr; Tcl_HashTable table; Tcl_HashEntry *hPtr; Tcl_HashSearch search; + NSInteger windowCount; + NSInteger *windowNumbers; /* * Map mac windows to a TkWindow of the wrapped toplevel. @@ -5908,12 +5938,11 @@ TkWmStackorderToplevel(parentPtr) Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS); WmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table); - windows = (TkWindow **) ckalloc((table.numEntries+1) - * sizeof(TkWindow *)); + windows = ckalloc((table.numEntries+1) * sizeof(TkWindow *)); /* - * Special cases: If zero or one toplevels were mapped - * there is no need to enumerate Windows. + * Special cases: If zero or one toplevels were mapped there is no need to + * enumerate Windows. */ switch (table.numEntries) { @@ -5922,32 +5951,39 @@ TkWmStackorderToplevel(parentPtr) goto done; case 1: hPtr = Tcl_FirstHashEntry(&table, &search); - windows[0] = (TkWindow *) Tcl_GetHashValue(hPtr); + windows[0] = Tcl_GetHashValue(hPtr); windows[1] = NULL; goto done; } - frontWindow = GetFrontWindowOfClass(kAllWindowClasses, false); - if (frontWindow == NULL) { + NSCountWindows(&windowCount); + if (!windowCount) { ckfree((char *) windows); windows = NULL; } else { window_ptr = windows + table.numEntries; *window_ptr-- = NULL; - while (frontWindow != NULL) { - hPtr = Tcl_FindHashEntry(&table, (char *) frontWindow); + windowNumbers = 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 = (TkWindow *) Tcl_GetHashValue(hPtr); + childWinPtr = Tcl_GetHashValue(hPtr); *window_ptr-- = childWinPtr; } - frontWindow = GetNextWindow(frontWindow); } - if (window_ptr != (windows-1)) + } + if (window_ptr != (windows-1)) { Tcl_Panic("num matched toplevel windows does not equal num " "children"); + } + ckfree((char *) windowNumbers); } - done: + done: Tcl_DeleteHashTable(&table); return windows; } @@ -5955,9 +5991,9 @@ TkWmStackorderToplevel(parentPtr) /* *---------------------------------------------------------------------- * - * ApplyWindowClassAttributeChanges -- + * TkMacOSXApplyWindowAttributes -- * - * This procedure applies carbon window class and attribute changes. + * This procedure applies all window attributes to the NSWindow. * * Results: * None. @@ -5968,21 +6004,49 @@ TkWmStackorderToplevel(parentPtr) *---------------------------------------------------------------------- */ -static void -ApplyWindowClassAttributeChanges( +void +TkMacOSXApplyWindowAttributes( TkWindow *winPtr, - WindowRef macWindow, - WindowClass oldClass, - WindowAttributes oldAttributes, - int create) + NSWindow *macWindow) { WmInfo *wmPtr = winPtr->wmInfoPtr; - WindowAttributes newAttributes = wmPtr->attributes | - kWindowAsyncDragAttribute; + ApplyWindowAttributeFlagChanges(winPtr, macWindow, 0, 0, 0, 1); + if (wmPtr->master != None || winPtr->atts.override_redirect) { + ApplyMasterOverrideChanges(winPtr, macWindow); + } +} + +/* + *---------------------------------------------------------------------- + * + * ApplyWindowAttributeFlagChanges -- + * + * This procedure applies window attribute and flag changes. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ - if (wmPtr->macClass != oldClass || newAttributes != oldAttributes) { - Rect strWidths; +static void +ApplyWindowAttributeFlagChanges( + TkWindow *winPtr, + NSWindow *macWindow, + UInt64 oldAttributes, + int oldFlags, + int create, + int initial) +{ + WmInfo *wmPtr = winPtr->wmInfoPtr; + UInt64 newAttributes = ForceAttributes(wmPtr->attributes, wmPtr->macClass); + UInt64 changedAttributes = newAttributes ^ ForceAttributes(oldAttributes, + wmPtr->macClass); + if (changedAttributes || wmPtr->flags != oldFlags || initial) { if (!macWindow) { if (winPtr->window == None) { if (create) { @@ -6000,45 +6064,110 @@ ApplyWindowClassAttributeChanges( } macWindow = TkMacOSXDrawableWindow(winPtr->window); } - if (wmPtr->macClass != oldClass) { - TK_IF_MAC_OS_X_API (4, HIWindowChangeClass, - ChkErr(HIWindowChangeClass, macWindow, wmPtr->macClass); - ) TK_ENDIF - ChkErr(GetWindowClass, macWindow, &(wmPtr->macClass)); - } - if (newAttributes != oldAttributes) { - newAttributes &= GetAvailableWindowAttributes(wmPtr->macClass); - ChkErr(ChangeWindowAttributes, macWindow, - newAttributes & (newAttributes ^ oldAttributes), - oldAttributes & (newAttributes ^ oldAttributes)); - } - ChkErr(GetWindowAttributes, macWindow, &(wmPtr->attributes)); - if ((wmPtr->attributes ^ oldAttributes) & kWindowResizableAttribute) { - if (wmPtr->attributes & kWindowResizableAttribute) { - HIViewRef growBoxView; - OSStatus err = HIViewFindByID(HIViewGetRoot(macWindow), - kHIViewWindowGrowBoxID, &growBoxView); - - if (err == noErr && !HIGrowBoxViewIsTransparent(growBoxView)) { - ChkErr(HIGrowBoxViewSetTransparent, growBoxView, true); - } + if ((changedAttributes & kWindowCloseBoxAttribute) || initial) { + [[macWindow standardWindowButton:NSWindowCloseButton] + setEnabled:!!(newAttributes & kWindowCloseBoxAttribute)]; + } + if ((changedAttributes & kWindowCollapseBoxAttribute) || initial) { + [[macWindow standardWindowButton:NSWindowMiniaturizeButton] + setEnabled:!!(newAttributes & kWindowCollapseBoxAttribute)]; + } + if ((changedAttributes & (kWindowResizableAttribute | + kWindowFullZoomAttribute)) || initial) { + [macWindow setShowsResizeIndicator: + !!(newAttributes & kWindowResizableAttribute)]; + [[macWindow standardWindowButton:NSWindowZoomButton] + setEnabled:(newAttributes & kWindowResizableAttribute) && + (newAttributes & kWindowFullZoomAttribute)]; + if (newAttributes & kWindowResizableAttribute) { + wmPtr->flags &= ~(WM_WIDTH_NOT_RESIZABLE | + WM_HEIGHT_NOT_RESIZABLE); + } else { + wmPtr->flags |= (WM_WIDTH_NOT_RESIZABLE | + WM_HEIGHT_NOT_RESIZABLE); } - TkMacOSXInvalClipRgns((Tk_Window) winPtr); - TkMacOSXInvalidateWindow((MacDrawable *)(winPtr->window), - TK_PARENT_WINDOW); + WmUpdateGeom(wmPtr, winPtr); + } + if ((changedAttributes & kWindowToolbarButtonAttribute) || initial) { + [macWindow setShowsToolbarButton: + !!(newAttributes & kWindowToolbarButtonAttribute)]; + if ((newAttributes & kWindowToolbarButtonAttribute) && + ![macWindow toolbar]) { + NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@""]; + [toolbar setVisible:NO]; + [macWindow setToolbar:toolbar]; + [toolbar release]; + NSCell *toolbarButtonCell = [[macWindow standardWindowButton: + NSWindowToolbarButton] cell]; + [toolbarButtonCell setTarget:[macWindow contentView]]; + [toolbarButtonCell setAction:@selector(tkToolbarButton:)]; + } + } + if ((changedAttributes & kWindowNoShadowAttribute) || initial) { + [macWindow setHasShadow: + !(newAttributes & kWindowNoShadowAttribute)]; + } + if ((changedAttributes & kWindowHideOnSuspendAttribute) || initial) { + [macWindow setHidesOnDeactivate: + !!(newAttributes & kWindowHideOnSuspendAttribute)]; + } + if ((changedAttributes & kWindowInWindowMenuAttribute) || initial) { + [macWindow setExcludedFromWindowsMenu: + !(newAttributes & kWindowInWindowMenuAttribute)]; + } + if ((changedAttributes & kWindowIgnoreClicksAttribute) || initial) { + [macWindow setIgnoresMouseEvents: + !!(newAttributes & kWindowIgnoreClicksAttribute)]; + } + if ((changedAttributes & tkWindowDoesNotHideAttribute) || initial) { + [macWindow setCanHide: + !(newAttributes & tkWindowDoesNotHideAttribute)]; + } + if ((changedAttributes & (kWindowDoesNotCycleAttribute | + tkCanJoinAllSpacesAttribute | tkMoveToActiveSpaceAttribute)) || + initial) { + NSWindowCollectionBehavior b = NSWindowCollectionBehaviorDefault; + if (newAttributes & tkCanJoinAllSpacesAttribute) { + b |= NSWindowCollectionBehaviorCanJoinAllSpaces; + } else if (newAttributes & tkMoveToActiveSpaceAttribute) { + b |= NSWindowCollectionBehaviorMoveToActiveSpace; + } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + if (newAttributes & kWindowDoesNotCycleAttribute) { + b |= NSWindowCollectionBehaviorIgnoresCycle; + } else { + b |= NSWindowCollectionBehaviorParticipatesInCycle; + } +#endif + [macWindow setCollectionBehavior:b]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 + if (((changedAttributes & kWindowDoesNotCycleAttribute) || initial) +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + && tkMacOSXMacOSXVersion < 1060 +#endif + ) { + [macWindow setCanCycle: + !(newAttributes & kWindowDoesNotCycleAttribute)]; + } +#endif + } + if ((wmPtr->flags & WM_TOPMOST) != (oldFlags & WM_TOPMOST)) { + [macWindow setLevel:(wmPtr->flags & WM_TOPMOST) ? + kCGUtilityWindowLevel : ([macWindow isKindOfClass: + [NSPanel class]] && [macWindow isFloatingPanel] ? + kCGFloatingWindowLevel : kCGNormalWindowLevel)]; } /* * The change of window class/attributes might have changed the window * structure widths: */ - GetWindowStructureWidths(macWindow, &strWidths); - wmPtr->xInParent = strWidths.left; - wmPtr->yInParent = strWidths.top; - wmPtr->parentWidth = winPtr->changes.width + strWidths.left - + strWidths.right; - wmPtr->parentHeight = winPtr->changes.height + strWidths.top - + strWidths.bottom; + + NSRect structureRect = [macWindow frameRectForContentRect:NSZeroRect]; + wmPtr->xInParent = -structureRect.origin.x; + wmPtr->yInParent = structureRect.origin.y + structureRect.size.height; + wmPtr->parentWidth = winPtr->changes.width + structureRect.size.width; + wmPtr->parentHeight = winPtr->changes.height + structureRect.size.height; } } @@ -6061,28 +6190,28 @@ ApplyWindowClassAttributeChanges( static void ApplyMasterOverrideChanges( TkWindow *winPtr, - WindowRef macWindow) + NSWindow *macWindow) { WmInfo *wmPtr = winPtr->wmInfoPtr; - WindowClass oldClass = wmPtr->macClass; - WindowAttributes oldAttributes = wmPtr->attributes; + UInt64 oldAttributes = wmPtr->attributes; + int oldFlags = wmPtr->flags; /* * FIX: We need an UpdateWrapper equivalent to make this 100% correct */ if (winPtr->atts.override_redirect) { - if (oldClass == kDocumentWindowClass) { + if (wmPtr->macClass == kDocumentWindowClass) { wmPtr->macClass = kSimpleWindowClass; - wmPtr->attributes = kWindowNoAttributes; + wmPtr->attributes = macClassAttrs[kSimpleWindowClass].defaultAttrs; } wmPtr->attributes |= kWindowNoActivatesAttribute; } else { - if (oldClass == kSimpleWindowClass && + if (wmPtr->macClass == kSimpleWindowClass && oldAttributes == kWindowNoActivatesAttribute) { wmPtr->macClass = kDocumentWindowClass; - wmPtr->attributes = kWindowStandardDocumentAttributes - | kWindowLiveResizeAttribute; + wmPtr->attributes = + macClassAttrs[kDocumentWindowClass].defaultAttrs; } wmPtr->attributes &= ~kWindowNoActivatesAttribute; } @@ -6091,75 +6220,40 @@ ApplyMasterOverrideChanges( macWindow = TkMacOSXDrawableWindow(winPtr->window); } if (macWindow) { - WindowGroupRef group; - - ApplyWindowClassAttributeChanges(winPtr, macWindow, oldClass, - oldAttributes, 0); - if (winPtr->atts.override_redirect && wmPtr->master != None) { wmPtr->flags |= WM_TOPMOST; } else { wmPtr->flags &= ~WM_TOPMOST; } - group = WmGetWindowGroup(winPtr); - if (group && group != GetWindowGroup(macWindow)) { - ChkErr(SetWindowGroup, macWindow, group); - } - } -} - -/* - *---------------------------------------------------------------------- - * - * WmGetWindowGroup -- - * - * Gets the window group a toplevel should be placed in. - * - * Results: - * A WindowGroupRef. - * - * Side effects: - * A transient window group for the master (if any) may be created. - * - *---------------------------------------------------------------------- - */ - -static WindowGroupRef -WmGetWindowGroup( - TkWindow *winPtr) -{ - WmInfo *wmPtr = winPtr->wmInfoPtr; - WindowGroupRef group = NULL; - - if (wmPtr->flags & WM_TOPMOST) { - group = GetWindowGroupOfClass(kUtilityWindowClass); - } else if (wmPtr->master != None) { - TkDisplay *dispPtr = TkGetDisplayList(); - TkWindow *masterWinPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display, - wmPtr->master); - - if (masterWinPtr && masterWinPtr->window != None && - TkMacOSXHostToplevelExists(masterWinPtr)) { - WindowRef masterMacWin = - TkMacOSXDrawableWindow(masterWinPtr->window); - - if (masterMacWin && GetWindowProperty(masterMacWin, 'Tk ', 'TsGp', - sizeof(group), NULL, &group) != noErr) { - ChkErr(CreateWindowGroup, 0, &group); - if (group) { - ChkErr(SetWindowGroupParent, group, - GetWindowGroup(masterMacWin)); - ChkErr(SetWindowGroupOwner, group, masterMacWin); - ChkErr(SetWindowProperty, masterMacWin, 'Tk ', 'TsGp', - sizeof(group), &group); + NSWindow *parentWindow = [macWindow parentWindow]; + if (wmPtr->master != None) { + TkDisplay *dispPtr = TkGetDisplayList(); + TkWindow *masterWinPtr = (TkWindow *) + Tk_IdToWindow(dispPtr->display, wmPtr->master); + + if (masterWinPtr && masterWinPtr->window != None && + TkMacOSXHostToplevelExists(masterWinPtr)) { + NSWindow *masterMacWin = + TkMacOSXDrawableWindow(masterWinPtr->window); + + if (masterMacWin && masterMacWin != parentWindow && + (winPtr->flags & TK_MAPPED)) { + if (parentWindow) { + [parentWindow removeChildWindow:macWindow]; + } + [masterMacWin addChildWindow:macWindow + ordered:NSWindowAbove]; + if (wmPtr->flags & WM_TOPMOST) { + [macWindow setLevel:kCGUtilityWindowLevel]; + } } } + } else if (parentWindow) { + [parentWindow removeChildWindow:macWindow]; } + ApplyWindowAttributeFlagChanges(winPtr, macWindow, oldAttributes, + oldFlags, 0, 0); } - if (!group) { - group = GetWindowGroupOfClass(wmPtr->macClass); - } - return group; } /* @@ -6181,19 +6275,23 @@ WmGetWindowGroup( int TkMacOSXMakeFullscreen( TkWindow *winPtr, - WindowRef window, + NSWindow *window, int fullscreen, Tcl_Interp *interp) { WmInfo *wmPtr = winPtr->wmInfoPtr; int result = TCL_OK, wasFullscreen = (wmPtr->flags & WM_FULLSCREEN); + static unsigned long prevMask = 0, prevPres = 0; + if (fullscreen) { int screenWidth = WidthOfScreen(Tk_Screen(winPtr)); int screenHeight = HeightOfScreen(Tk_Screen(winPtr)); + /* * Check max width and height if set by the user. */ + if ((wmPtr->maxWidth > 0 && wmPtr->maxWidth < screenWidth) || (wmPtr->maxHeight > 0 && wmPtr->maxHeight < screenHeight)) { if (interp) { @@ -6205,101 +6303,62 @@ TkMacOSXMakeFullscreen( result = TCL_ERROR; wmPtr->flags &= ~WM_FULLSCREEN; } else { - Rect bounds, screenBounds = {0, 0, screenHeight, screenWidth}; - - ChkErr(GetWindowBounds, window, kWindowContentRgn, &bounds); - if (!EqualRect(&bounds, &screenBounds)) { - if (!wasFullscreen) { - wmPtr->configX = wmPtr->x; - wmPtr->configY = wmPtr->y; - wmPtr->configAttributes = wmPtr->attributes; - wmPtr->attributes &= ~kWindowResizableAttribute; - ApplyWindowClassAttributeChanges(winPtr, window, - wmPtr->macClass, wmPtr->configAttributes, 0); - } + NSRect bounds = [window contentRectForFrameRect:[window frame]]; + NSRect screenBounds = NSMakeRect(0, 0, screenWidth, screenHeight); + + if (!NSEqualRects(bounds, screenBounds) && !wasFullscreen) { + wmPtr->configX = wmPtr->x; + wmPtr->configY = wmPtr->y; + wmPtr->configAttributes = wmPtr->attributes; + wmPtr->attributes &= ~kWindowResizableAttribute; + ApplyWindowAttributeFlagChanges(winPtr, window, + wmPtr->configAttributes, wmPtr->flags, 1, 0); wmPtr->flags |= WM_SYNC_PENDING; - ChkErr(SetWindowBounds, window, kWindowContentRgn, - &screenBounds); + [window setFrame:[window frameRectForContentRect: + screenBounds] display:YES]; wmPtr->flags &= ~WM_SYNC_PENDING; } wmPtr->flags |= WM_FULLSCREEN; } + + prevMask = [window styleMask]; + prevPres = [NSApp presentationOptions]; + [window setStyleMask: NSBorderlessWindowMask]; + [NSApp setPresentationOptions: NSApplicationPresentationAutoHideDock + | NSApplicationPresentationAutoHideMenuBar]; } else { wmPtr->flags &= ~WM_FULLSCREEN; + [NSApp setPresentationOptions: prevPres]; + [window setStyleMask: prevMask]; } + if (wasFullscreen && !(wmPtr->flags & WM_FULLSCREEN)) { - WindowAttributes oldAttributes = wmPtr->attributes; - Rect bounds = {wmPtr->configY, wmPtr->configX, - wmPtr->configY + wmPtr->yInParent + wmPtr->configHeight, - wmPtr->configX + wmPtr->xInParent + wmPtr->configWidth}; + UInt64 oldAttributes = wmPtr->attributes; + NSRect bounds = NSMakeRect(wmPtr->configX, tkMacOSXZeroScreenHeight - + (wmPtr->configY + wmPtr->yInParent + wmPtr->configHeight), + wmPtr->xInParent + wmPtr->configWidth, + wmPtr->yInParent + wmPtr->configHeight); wmPtr->attributes |= wmPtr->configAttributes & kWindowResizableAttribute; - ApplyWindowClassAttributeChanges(winPtr, window, wmPtr->macClass, - oldAttributes, 0); + ApplyWindowAttributeFlagChanges(winPtr, window, oldAttributes, + wmPtr->flags, 1, 0); wmPtr->flags |= WM_SYNC_PENDING; - ChkErr(SetWindowBounds, window, kWindowStructureRgn, &bounds); + [window setFrame:[window frameRectForContentRect:bounds] display:YES]; wmPtr->flags &= ~WM_SYNC_PENDING; } - TkMacOSXEnterExitFullscreen(winPtr, IsWindowActive(window)); return result; } -/* - *---------------------------------------------------------------------- - * - * TkMacOSXEnterExitFullscreen -- - * - * This procedure enters or exits fullscreen mode if required. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -void -TkMacOSXEnterExitFullscreen( - TkWindow *winPtr, - int active) -{ - WmInfo *wmPtr = winPtr->wmInfoPtr; - SystemUIMode mode; - SystemUIOptions options; - - GetSystemUIMode(&mode, &options); - if (wmPtr->flags & WM_FULLSCREEN && active) { - static SystemUIMode fullscreenMode = 0; - static SystemUIOptions fullscreenOptions = 0; - - if (!fullscreenMode) { - TK_IF_HI_TOOLBOX (3, - fullscreenMode = kUIModeAllSuppressed; - ) TK_ELSE_HI_TOOLBOX (3, - fullscreenMode = kUIModeAllHidden; - fullscreenOptions = kUIOptionAutoShowMenuBar; - ) TK_ENDIF - } - if (mode != fullscreenMode) { - ChkErr(SetSystemUIMode, fullscreenMode, fullscreenOptions); - } - } else { - if (mode != kUIModeNormal) { - ChkErr(SetSystemUIMode, kUIModeNormal, 0); - } - } -} /* *---------------------------------------------------------------------- * * GetMinSize -- * - * This function computes the current minWidth and minHeight values for - * a window, taking into account the possibility that they may be + * This function computes the current minWidth and minHeight values for a + * window, taking into account the possibility that they may be * defaulted. * * Results: @@ -6333,41 +6392,43 @@ GetMinSize( */ switch (wmPtr->macClass) { - case kDocumentWindowClass: - case kMovableAlertWindowClass: - case kMovableModalWindowClass: - minWidth = 72; - if (wmPtr->attributes & kWindowResizableAttribute) { - minHeight = 15; - } - if (wmPtr->attributes & kWindowToolbarButtonAttribute) { - minWidth += 29; - } - break; - case kFloatingWindowClass: - case kUtilityWindowClass: - minWidth = 59; - if (wmPtr->attributes & kWindowResizableAttribute) { - minHeight = 11; - } - if (wmPtr->attributes & kWindowSideTitlebarAttribute) { - int tmp = minWidth; - minWidth = minHeight; - minHeight = tmp; - } else if (wmPtr->attributes & kWindowToolbarButtonAttribute) { - minWidth += 29; - } - break; - default: - if (wmPtr->attributes & kWindowResizableAttribute) { - minWidth = 15; - minHeight = 15; - } - break; + case kDocumentWindowClass: + case kMovableAlertWindowClass: + case kMovableModalWindowClass: + minWidth = 72; + if (wmPtr->attributes & kWindowResizableAttribute) { + minHeight = 15; + } + if (wmPtr->attributes & kWindowToolbarButtonAttribute) { + minWidth += 29; + } + break; + case kFloatingWindowClass: + case kUtilityWindowClass: + minWidth = 59; + if (wmPtr->attributes & kWindowResizableAttribute) { + minHeight = 11; + } + if (wmPtr->attributes & kWindowSideTitlebarAttribute) { + int tmp = minWidth; + + minWidth = minHeight; + minHeight = tmp; + } else if (wmPtr->attributes & kWindowToolbarButtonAttribute) { + minWidth += 29; + } + break; + default: + if (wmPtr->attributes & kWindowResizableAttribute) { + minWidth = 15; + minHeight = 15; + } + break; } if (wmPtr->gridWin != NULL) { int base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc); + if (base < 0) { base = 0; } @@ -6393,8 +6454,8 @@ GetMinSize( * * GetMaxSize -- * - * This function computes the current maxWidth and maxHeight values for - * a window, taking into account the possibility that they may be + * This function computes the current maxWidth and maxHeight values for a + * window, taking into account the possibility that they may be * defaulted. * * Results: @@ -6418,12 +6479,13 @@ GetMaxSize( * of the window. */ { WmInfo *wmPtr = winPtr->wmInfoPtr; - Rect *maxBounds = (Rect*)(winPtr->display->screens->ext_data); + NSRect *maxBounds = (NSRect*)(winPtr->display->screens->ext_data); if (wmPtr->maxWidth > 0) { *maxWidthPtr = wmPtr->maxWidth; } else { - int maxWidth = maxBounds->right - maxBounds->left - wmPtr->xInParent; + int maxWidth = maxBounds->size.width - wmPtr->xInParent; + if (wmPtr->gridWin != NULL) { maxWidth = wmPtr->reqGridWidth + (maxWidth - winPtr->reqWidth)/wmPtr->widthInc; @@ -6433,7 +6495,8 @@ GetMaxSize( if (wmPtr->maxHeight > 0) { *maxHeightPtr = wmPtr->maxHeight; } else { - int maxHeight = maxBounds->bottom - maxBounds->top - wmPtr->yInParent; + int maxHeight = maxBounds->size.height - wmPtr->yInParent; + if (wmPtr->gridWin != NULL) { maxHeight = wmPtr->reqGridHeight + (maxHeight - winPtr->reqHeight)/wmPtr->heightInc; @@ -6441,15 +6504,13 @@ GetMaxSize( *maxHeightPtr = maxHeight; } } -#if 0 /* *---------------------------------------------------------------------- * * RemapWindows * - * Adjust parent/child relation ships of - * the given window hierarchy. + * Adjust parent/child relation ships of the given window hierarchy. * * Results: * none @@ -6459,17 +6520,22 @@ GetMaxSize( * *---------------------------------------------------------------------- */ + static void -RemapWindows(TkWindow *winPtr, MacDrawable *parentWin) +RemapWindows( + TkWindow *winPtr, + MacDrawable *parentWin) { TkWindow *childPtr; - /* Remove the OS specific window. - * It will get rebuilt when the window gets Mapped. + /* + * Remove the OS specific window. It will get rebuilt when the window gets + * Mapped. */ + if (winPtr->window != None) { MacDrawable *macWin = (MacDrawable *) winPtr->window; - macWin->grafPtr = NULL; + macWin->toplevel = parentWin->toplevel; winPtr->flags &= ~TK_MAPPED; #ifdef TK_REBUILD_TOPLEVEL @@ -6479,8 +6545,18 @@ RemapWindows(TkWindow *winPtr, MacDrawable *parentWin) /* Repeat for all the children */ for (childPtr = winPtr->childList; childPtr != NULL; - childPtr = childPtr->nextPtr) { + childPtr = childPtr->nextPtr) { RemapWindows(childPtr, (MacDrawable *) winPtr->window); } } -#endif + + + +/* + * Local Variables: + * mode: objc + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: + */ |