Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0c9458084a
Fetching contributors…

Cannot retrieve contributors at this time

6624 lines (6048 sloc) 188.461 kb
/*
* 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.
*
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
* 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.
*/
#include "tkMacOSXPrivate.h"
#include "tkScrollbar.h"
#include "tkMacOSXWm.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"
/*
#ifdef TK_MAC_DEBUG
#define TK_MAC_DEBUG_WINDOWS
#endif
*/
/*
* 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_TITLEPATH, WMATT_TOPMOST, WMATT_TRANSPARENT,
_WMATT_LAST_ATTRIBUTE
} WmAttribute;
static const char *const WmAttributeNames[] = {
"-alpha", "-fullscreen", "-modified", "-notify",
"-titlepath", "-topmost", "-transparent",
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.
*/
static int wmTracing = 0;
/*
* 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 */
NULL, /* lostSlaveProc */
};
/*
* The following keeps state for Aqua dock icon bounce notification.
*/
static int tkMacOSXWmAttrNotifyVal = 0;
/*
* Hash table for Mac Window -> TkWindow mapping.
*/
static Tcl_HashTable windowTable;
static int windowHashInit = false;
/*
* Forward declarations for procedures defined in this file:
*/
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 = 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(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.
*
* Results:
* None.
*
* Side effects:
* A WmInfo structure gets allocated and initialized.
*
*----------------------------------------------------------------------
*/
void
TkWmNewWindow(
TkWindow *winPtr) /* Newly-created top-level window. */
{
WmInfo *wmPtr = ckalloc(sizeof(WmInfo));
wmPtr->winPtr = winPtr;
wmPtr->reparent = None;
wmPtr->titleUid = NULL;
wmPtr->iconName = NULL;
wmPtr->master = None;
wmPtr->hints.flags = InputHint | StateHint;
wmPtr->hints.input = True;
wmPtr->hints.initial_state = NormalState;
wmPtr->hints.icon_pixmap = None;
wmPtr->hints.icon_window = None;
wmPtr->hints.icon_x = wmPtr->hints.icon_y = 0;
wmPtr->hints.icon_mask = None;
wmPtr->hints.window_group = None;
wmPtr->leaderName = NULL;
wmPtr->masterWindowName = NULL;
wmPtr->icon = NULL;
wmPtr->iconFor = NULL;
wmPtr->sizeHintsFlags = 0;
wmPtr->minWidth = wmPtr->minHeight = 1;
wmPtr->maxWidth = 0;
wmPtr->maxHeight = 0;
wmPtr->gridWin = NULL;
wmPtr->widthInc = wmPtr->heightInc = 1;
wmPtr->minAspect.x = wmPtr->minAspect.y = 1;
wmPtr->maxAspect.x = wmPtr->maxAspect.y = 1;
wmPtr->reqGridWidth = wmPtr->reqGridHeight = -1;
wmPtr->gravity = NorthWestGravity;
wmPtr->width = -1;
wmPtr->height = -1;
wmPtr->x = winPtr->changes.x;
wmPtr->y = winPtr->changes.y;
wmPtr->parentWidth = winPtr->changes.width
+ 2*winPtr->changes.border_width;
wmPtr->parentHeight = winPtr->changes.height
+ 2*winPtr->changes.border_width;
wmPtr->xInParent = 0;
wmPtr->yInParent = 0;
wmPtr->cmapList = NULL;
wmPtr->cmapCount = 0;
wmPtr->configX = 0;
wmPtr->configY = 0;
wmPtr->configWidth = -1;
wmPtr->configHeight = -1;
wmPtr->vRoot = None;
wmPtr->protPtr = NULL;
wmPtr->commandObj = NULL;
wmPtr->clientMachine = NULL;
wmPtr->flags = WM_NEVER_MAPPED;
wmPtr->macClass = kDocumentWindowClass;
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_CreateEventHandler((Tk_Window) winPtr, StructureNotifyMask,
TopLevelEventProc, winPtr);
/*
* Arrange for geometry requests to be reflected from the window to the
* window manager.
*/
Tk_ManageGeometry((Tk_Window) winPtr, &wmMgrType, (ClientData) 0);
}
/*
*----------------------------------------------------------------------
*
* 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.
*
* 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).
*
*----------------------------------------------------------------------
*/
void
TkWmMapWindow(
TkWindow *winPtr) /* Top-level window that's about to be
* mapped. */
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
if (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.
*/
if (wmPtr->titleUid == NULL) {
wmPtr->titleUid = winPtr->nameUid;
}
if (!Tk_IsEmbedded(winPtr)) {
TkSetWMName(winPtr, wmPtr->titleUid);
}
TkWmSetClass(winPtr);
if (wmPtr->iconName != NULL) {
XSetIconName(winPtr->display, winPtr->window, wmPtr->iconName);
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
}
if (wmPtr->hints.initial_state == WithdrawnState) {
return;
}
/*
* TODO: we need to display a window if it's iconic on creation.
*/
if (wmPtr->hints.initial_state == IconicState) {
return;
}
/*
* Update geometry information.
*/
wmPtr->flags |= WM_ABOUT_TO_MAP;
if (wmPtr->flags & WM_UPDATE_PENDING) {
Tk_CancelIdleCall(UpdateGeometryInfo, winPtr);
}
UpdateGeometryInfo(winPtr);
wmPtr->flags &= ~WM_ABOUT_TO_MAP;
/*
* Map the window.
*/
XMapWindow(winPtr->display, winPtr->window);
}
/*
*----------------------------------------------------------------------
*
* TkWmUnmapWindow --
*
* This procedure is invoked to unmap a top-level window. On the
* Macintosh all we do is call XUnmapWindow.
*
* Results:
* None.
*
* Side effects:
* Unmaps the window.
*
*----------------------------------------------------------------------
*/
void
TkWmUnmapWindow(
TkWindow *winPtr) /* Top-level window that's about to be
* mapped. */
{
XUnmapWindow(winPtr->display, winPtr->window);
}
/*
*----------------------------------------------------------------------
*
* 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.
*
* Results:
* None.
*
* Side effects:
* The WmInfo structure for winPtr gets freed up.
*
*----------------------------------------------------------------------
*/
void
TkWmDeadWindow(
TkWindow *winPtr) /* Top-level window that's being deleted. */
{
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);
}
if (wmPtr->hints.flags & IconMaskHint) {
Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_mask);
}
if (wmPtr->iconName != NULL) {
ckfree(wmPtr->iconName);
}
if (wmPtr->leaderName != NULL) {
ckfree(wmPtr->leaderName);
}
if (wmPtr->masterWindowName != NULL) {
ckfree(wmPtr->masterWindowName);
}
if (wmPtr->icon != NULL) {
wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
wmPtr2->iconFor = NULL;
}
if (wmPtr->iconFor != NULL) {
wmPtr2 = ((TkWindow *) wmPtr->iconFor)->wmInfoPtr;
wmPtr2->icon = NULL;
wmPtr2->hints.flags &= ~IconWindowHint;
}
while (wmPtr->protPtr != NULL) {
ProtocolHandler *protPtr = wmPtr->protPtr;
wmPtr->protPtr = protPtr->nextPtr;
Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
}
if (wmPtr->commandObj != NULL) {
Tcl_DecrRefCount(wmPtr->commandObj);
}
if (wmPtr->clientMachine != NULL) {
ckfree(wmPtr->clientMachine);
}
if (wmPtr->flags & WM_UPDATE_PENDING) {
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(wmPtr);
winPtr->wmInfoPtr = NULL;
}
/*
*----------------------------------------------------------------------
*
* 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.
*
* Results:
* None.
*
* Side effects:
* A window property may get updated.
*
*----------------------------------------------------------------------
*/
void
TkWmSetClass(
TkWindow *winPtr) /* Newly-created top-level window. */
{
return;
}
/*
*----------------------------------------------------------------------
*
* Tk_WmObjCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
int
Tk_WmObjCmd(
ClientData clientData, /* Main window associated with interpreter. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tk_Window tkwin = (Tk_Window) clientData;
static const char *const optionStrings[] = {
"aspect", "attributes", "client", "colormapwindows",
"command", "deiconify", "focusmodel", "forget",
"frame", "geometry", "grid", "group",
"iconbitmap", "iconify", "iconmask", "iconname",
"iconphoto", "iconposition", "iconwindow",
"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_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_POSITIONFROM, WMOPT_PROTOCOL, WMOPT_RESIZABLE, WMOPT_SIZEFROM,
WMOPT_STACKORDER, WMOPT_STATE, WMOPT_TITLE, WMOPT_TRANSIENT,
WMOPT_WITHDRAW };
int index, length;
char *argv1;
TkWindow *winPtr;
if (objc < 2) {
wrongNumArgs:
Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
return TCL_ERROR;
}
argv1 = Tcl_GetStringFromObj(objv[1], &length);
if ((argv1[0] == 't') && (strncmp(argv1, "tracing", length) == 0)
&& (length >= 3)) {
if ((objc != 2) && (objc != 3)) {
Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
return TCL_ERROR;
}
if (objc == 2) {
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(wmTracing));
return TCL_OK;
}
return Tcl_GetBooleanFromObj(interp, objv[2], &wmTracing);
}
if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0,
&index) != TCL_OK) {
return TCL_ERROR;
}
if (objc < 3) {
goto wrongNumArgs;
}
if (TkGetWindowFromObj(interp, tkwin, objv[2], (Tk_Window *) &winPtr)
!= TCL_OK) {
return TCL_ERROR;
}
if (!Tk_IsTopLevel(winPtr)
&& (index != WMOPT_MANAGE) && (index != WMOPT_FORGET)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"window \"%s\" isn't a top-level window", winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "LOOKUP", "TOPLEVEL", winPtr->pathName,
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);
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 */
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* WmAspectCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmAspectCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int numer1, denom1, numer2, denom2;
if ((objc != 3) && (objc != 7)) {
Tcl_WrongNumArgs(interp, 2, objv,
"window ?minNumer minDenom maxNumer maxDenom?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->sizeHintsFlags & PAspect) {
Tcl_Obj *results[4];
results[0] = Tcl_NewIntObj(wmPtr->minAspect.x);
results[1] = Tcl_NewIntObj(wmPtr->minAspect.y);
results[2] = Tcl_NewIntObj(wmPtr->maxAspect.x);
results[3] = Tcl_NewIntObj(wmPtr->maxAspect.y);
Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
}
return TCL_OK;
}
if (*Tcl_GetString(objv[3]) == '\0') {
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)) {
return TCL_ERROR;
}
if ((numer1 <= 0) || (denom1 <= 0) || (numer2 <= 0) ||
(denom2 <= 0)) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"aspect number can't be <= 0", -1));
Tcl_SetErrorCode(interp, "TK", "WM", "ASPECT", NULL);
return TCL_ERROR;
}
wmPtr->minAspect.x = numer1;
wmPtr->minAspect.y = denom1;
wmPtr->maxAspect.x = numer2;
wmPtr->maxAspect.y = denom2;
wmPtr->sizeHintsFlags |= PAspect;
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
WmUpdateGeom(wmPtr, winPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmSetAttribute --
*
* 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.
*
*----------------------------------------------------------------------
*/
static int
WmSetAttribute(
TkWindow *winPtr, /* Toplevel to work with */
NSWindow *macWindow,
Tcl_Interp *interp, /* Current interpreter */
WmAttribute attribute, /* Code of attribute to set */
Tcl_Obj *value) /* New value */
{
WmInfo *wmPtr = winPtr->wmInfoPtr;
int boolean;
switch (attribute) {
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;
}
[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;
}
}
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;
if (request >= 0) {
[NSApp cancelUserAttentionRequest:request];
request = -1;
}
if (boolean) {
request = [NSApp requestUserAttention:NSCriticalRequest];
}
tkMacOSXWmAttrNotifyVal = boolean;
}
break;
case WMATT_TITLEPATH: {
const char *path = Tcl_FSGetNativePath(value);
NSString *filename = @"";
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;
}
ApplyWindowAttributeFlagChanges(winPtr, macWindow,
wmPtr->attributes, oldFlags, 1, 0);
}
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;
}
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;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmGetAttribute --
*
* Helper routine for WmAttributesCmd. Returns the current value of the
* specified attribute.
*
*----------------------------------------------------------------------
*/
static Tcl_Obj *
WmGetAttribute(
TkWindow *winPtr, /* Toplevel to work with */
NSWindow *macWindow,
WmAttribute attribute) /* Code of attribute to get */
{
Tcl_Obj *result = NULL;
WmInfo *wmPtr = winPtr->wmInfoPtr;
switch (attribute) {
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;
}
/*
*----------------------------------------------------------------------
*
* WmAttributesCmd --
*
* This procedure is invoked to process the "wm attributes" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmAttributesCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int attribute = 0;
NSWindow *macWindow;
if (winPtr->window == None) {
Tk_MakeWindowExist((Tk_Window) winPtr);
}
if (!TkMacOSXHostToplevelExists(winPtr)) {
TkMacOSXMakeRealWindowExist(winPtr);
}
macWindow = TkMacOSXDrawableWindow(winPtr->window);
if (objc == 3) { /* wm attributes $win */
Tcl_Obj *result = Tcl_NewObj();
for (attribute = 0; attribute < _WMATT_LAST_ATTRIBUTE; ++attribute) {
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(WmAttributeNames[attribute], -1));
Tcl_ListObjAppendElement(NULL, result,
WmGetAttribute(winPtr, macWindow, attribute));
}
Tcl_SetObjResult(interp, result);
} else if (objc == 4) { /* wm attributes $win -attribute */
if (Tcl_GetIndexFromObj(interp, objv[3], WmAttributeNames,
"attribute", 0, &attribute) != TCL_OK) {
return TCL_ERROR;
}
Tcl_SetObjResult(interp, WmGetAttribute(winPtr, macWindow, attribute));
} else if ((objc - 3) % 2 == 0) { /* wm attributes $win -att value... */
int i;
for (i = 3; i < objc; i += 2) {
if (Tcl_GetIndexFromObj(interp, objv[i], WmAttributeNames,
"attribute", 0, &attribute) != TCL_OK) {
return TCL_ERROR;
}
if (WmSetAttribute(winPtr, macWindow, interp, attribute, objv[i+1])
!= TCL_OK) {
return TCL_ERROR;
}
}
} else {
Tcl_WrongNumArgs(interp, 2, objv, "window ?-attribute ?value ...??");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmClientCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmClientCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
char *argv3;
int length;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?name?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->clientMachine != NULL) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj(wmPtr->clientMachine, -1));
}
return TCL_OK;
}
argv3 = Tcl_GetStringFromObj(objv[3], &length);
if (argv3[0] == 0) {
if (wmPtr->clientMachine != NULL) {
ckfree(wmPtr->clientMachine);
wmPtr->clientMachine = NULL;
}
return TCL_OK;
}
if (wmPtr->clientMachine != NULL) {
ckfree(wmPtr->clientMachine);
}
wmPtr->clientMachine = ckalloc(length + 1);
strcpy(wmPtr->clientMachine, argv3);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmColormapwindowsCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmColormapwindowsCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
TkWindow **cmapList, *winPtr2;
int i, windowObjc, gotToplevel = 0;
Tcl_Obj **windowObjv, *resultObj;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?windowList?");
return TCL_ERROR;
}
if (objc == 3) {
Tk_MakeWindowExist((Tk_Window) winPtr);
resultObj = Tcl_NewObj();
for (i = 0; i < wmPtr->cmapCount; i++) {
if ((i == (wmPtr->cmapCount-1))
&& (wmPtr->flags & WM_ADDED_TOPLEVEL_COLORMAP)) {
break;
}
Tcl_ListObjAppendElement(NULL, resultObj,
TkNewWindowObj((Tk_Window) wmPtr->cmapList[i]));
}
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
}
if (Tcl_ListObjGetElements(interp, objv[3], &windowObjc, &windowObjv)
!= TCL_OK) {
return TCL_ERROR;
}
cmapList = ckalloc((windowObjc+1) * sizeof(TkWindow*));
for (i = 0; i < windowObjc; i++) {
if (TkGetWindowFromObj(interp, tkwin, windowObjv[i],
(Tk_Window *) &winPtr2) != TCL_OK) {
ckfree(cmapList);
return TCL_ERROR;
}
if (winPtr2 == winPtr) {
gotToplevel = 1;
}
if (winPtr2->window == None) {
Tk_MakeWindowExist((Tk_Window) winPtr2);
}
cmapList[i] = winPtr2;
}
if (!gotToplevel) {
wmPtr->flags |= WM_ADDED_TOPLEVEL_COLORMAP;
cmapList[windowObjc] = winPtr;
windowObjc++;
} else {
wmPtr->flags &= ~WM_ADDED_TOPLEVEL_COLORMAP;
}
wmPtr->flags |= WM_COLORMAPS_EXPLICIT;
if (wmPtr->cmapList != NULL) {
ckfree(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.
*/
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmCommandCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmCommandCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int len;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?value?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->commandObj != NULL) {
Tcl_SetObjResult(interp, wmPtr->commandObj);
}
return TCL_OK;
}
if (Tcl_GetString(objv[3])[0] == 0) {
if (wmPtr->commandObj != NULL) {
Tcl_DecrRefCount(wmPtr->commandObj);
wmPtr->commandObj = NULL;
}
return TCL_OK;
}
if (Tcl_ListObjLength(interp, objv[3], &len) != TCL_OK) {
return TCL_ERROR;
}
if (wmPtr->commandObj != NULL) {
Tcl_DecrRefCount(wmPtr->commandObj);
}
wmPtr->commandObj = Tcl_DuplicateObj(objv[3]);
Tcl_IncrRefCount(wmPtr->commandObj);
Tcl_InvalidateStringRep(wmPtr->commandObj);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmDeiconifyCmd --
*
* This procedure is invoked to process the "wm deiconify" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmDeiconifyCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "window");
return TCL_ERROR;
}
if (wmPtr->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't deiconify %s: it is an icon for %s",
Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
Tcl_SetErrorCode(interp, "TK", "WM", "DEICONIFY", "ICON", NULL);
return TCL_ERROR;
} else if (winPtr->flags & TK_EMBEDDED) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't deiconify %s: it is an embedded window",
winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "DEICONIFY", "EMBEDDED", NULL);
return TCL_ERROR;
}
TkpWmSetState(winPtr, TkMacOSXIsWindowZoomed(winPtr) ?
ZoomState : NormalState);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmFocusmodelCmd --
*
* This procedure is invoked to process the "wm focusmodel" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmFocusmodelCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
static const char *const optionStrings[] = {
"active", "passive", NULL };
enum options {
OPT_ACTIVE, OPT_PASSIVE };
int index;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?active|passive?");
return TCL_ERROR;
}
if (objc == 3) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
wmPtr->hints.input ? "passive" : "active", -1));
return TCL_OK;
}
if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
&index) != TCL_OK) {
return TCL_ERROR;
}
if (index == OPT_ACTIVE) {
wmPtr->hints.input = False;
} else { /* OPT_PASSIVE */
wmPtr->hints.input = True;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmForgetCmd --
*
* This procedure is invoked to process the "wm forget" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
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. */
{
register Tk_Window frameWin = (Tk_Window) winPtr;
if (Tk_IsTopLevel(frameWin)) {
MacDrawable *macWin;
Tk_MakeWindowExist(winPtr);
Tk_MakeWindowExist(winPtr->parentPtr);
macWin = (MacDrawable *) winPtr->window;
TkFocusJoin(winPtr);
Tk_UnmapWindow(frameWin);
macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel;
macWin->flags &= ~TK_HOST_EXISTS;
TkWmDeadWindow(winPtr);
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.
*/
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmFrameCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmFrameCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
Window window;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "window");
return TCL_ERROR;
}
window = wmPtr->reparent;
if (window == None) {
window = Tk_WindowId((Tk_Window) winPtr);
}
Tcl_SetObjResult(interp, Tcl_ObjPrintf("0x%x", (unsigned) window));
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmGeometryCmd --
*
* This procedure is invoked to process the "wm geometry" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmGeometryCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
char xSign, ySign;
int width, height;
char *argv3;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?newGeometry?");
return TCL_ERROR;
}
if (objc == 3) {
xSign = (wmPtr->flags & WM_NEGATIVE_X) ? '-' : '+';
ySign = (wmPtr->flags & WM_NEGATIVE_Y) ? '-' : '+';
if (wmPtr->gridWin != NULL) {
width = wmPtr->reqGridWidth + (winPtr->changes.width
- winPtr->reqWidth)/wmPtr->widthInc;
height = wmPtr->reqGridHeight + (winPtr->changes.height
- winPtr->reqHeight)/wmPtr->heightInc;
} else {
width = winPtr->changes.width;
height = winPtr->changes.height;
}
Tcl_SetObjResult(interp, Tcl_ObjPrintf("%dx%d%c%d%c%d",
width, height, xSign, wmPtr->x, ySign, wmPtr->y));
return TCL_OK;
}
argv3 = Tcl_GetString(objv[3]);
if (*argv3 == '\0') {
wmPtr->width = -1;
wmPtr->height = -1;
WmUpdateGeom(wmPtr, winPtr);
return TCL_OK;
}
return ParseGeometry(interp, argv3, winPtr);
}
/*
*----------------------------------------------------------------------
*
* WmGridCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmGridCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int reqWidth, reqHeight, widthInc, heightInc;
char *errorMsg;
if ((objc != 3) && (objc != 7)) {
Tcl_WrongNumArgs(interp, 2, objv,
"window ?baseWidth baseHeight widthInc heightInc?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->sizeHintsFlags & PBaseSize) {
Tcl_Obj *results[4];
results[0] = Tcl_NewIntObj(wmPtr->reqGridWidth);
results[1] = Tcl_NewIntObj(wmPtr->reqGridHeight);
results[2] = Tcl_NewIntObj(wmPtr->widthInc);
results[3] = Tcl_NewIntObj(wmPtr->heightInc);
Tcl_SetObjResult(interp, Tcl_NewListObj(4, results));
}
return TCL_OK;
}
if (*Tcl_GetString(objv[3]) == '\0') {
/*
* Turn off gridding and reset the width and height to make sense as
* ungridded numbers.
*/
wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
if (wmPtr->width != -1) {
wmPtr->width = winPtr->reqWidth + (wmPtr->width
- wmPtr->reqGridWidth)*wmPtr->widthInc;
wmPtr->height = winPtr->reqHeight + (wmPtr->height
- wmPtr->reqGridHeight)*wmPtr->heightInc;
}
wmPtr->widthInc = 1;
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)) {
return TCL_ERROR;
}
if (reqWidth < 0) {
errorMsg = "baseWidth can't be < 0";
goto error;
} else if (reqHeight < 0) {
errorMsg = "baseHeight can't be < 0";
goto error;
} else if (widthInc <= 0) {
errorMsg = "widthInc can't be <= 0";
goto error;
} else if (heightInc <= 0) {
errorMsg = "heightInc can't be <= 0";
goto error;
}
Tk_SetGrid((Tk_Window) winPtr, reqWidth, reqHeight, widthInc,
heightInc);
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
WmUpdateGeom(wmPtr, winPtr);
return TCL_OK;
error:
Tcl_SetObjResult(interp, Tcl_NewStringObj(errorMsg, -1));
Tcl_SetErrorCode(interp, "TK", "WM", "GRID", NULL);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* WmGroupCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmGroupCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
Tk_Window tkwin2;
char *argv3;
int length;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->hints.flags & WindowGroupHint) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(wmPtr->leaderName, -1));
}
return TCL_OK;
}
argv3 = Tcl_GetStringFromObj(objv[3], &length);
if (*argv3 == '\0') {
wmPtr->hints.flags &= ~WindowGroupHint;
if (wmPtr->leaderName != NULL) {
ckfree(wmPtr->leaderName);
}
wmPtr->leaderName = NULL;
} else {
if (TkGetWindowFromObj(interp, tkwin, objv[3], &tkwin2) != TCL_OK) {
return TCL_ERROR;
}
Tk_MakeWindowExist(tkwin2);
if (wmPtr->leaderName != NULL) {
ckfree(wmPtr->leaderName);
}
wmPtr->hints.window_group = Tk_WindowId(tkwin2);
wmPtr->hints.flags |= WindowGroupHint;
wmPtr->leaderName = ckalloc(length + 1);
strcpy(wmPtr->leaderName, argv3);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmIconbitmapCmd --
*
* This procedure is invoked to process the "wm iconbitmap" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmIconbitmapCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
Pixmap pixmap;
char *str;
int len;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->hints.flags & IconPixmapHint) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
Tk_NameOfBitmap(winPtr->display,wmPtr->hints.icon_pixmap),
-1));
}
return TCL_OK;
}
str = Tcl_GetStringFromObj(objv[3], &len);
if (winPtr->window == None) {
Tk_MakeWindowExist((Tk_Window) winPtr);
}
if (!TkMacOSXHostToplevelExists(winPtr)) {
TkMacOSXMakeRealWindowExist(winPtr);
}
if (WmSetAttribute(winPtr, TkMacOSXDrawableWindow(winPtr->window), interp,
WMATT_TITLEPATH, objv[3]) == TCL_OK) {
if (!len) {
if (wmPtr->hints.icon_pixmap != None) {
Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
wmPtr->hints.icon_pixmap = None;
}
wmPtr->hints.flags &= ~IconPixmapHint;
}
} else {
pixmap = Tk_GetBitmap(interp, (Tk_Window) winPtr, Tk_GetUid(str));
if (pixmap == None) {
return TCL_ERROR;
}
wmPtr->hints.icon_pixmap = pixmap;
wmPtr->hints.flags |= IconPixmapHint;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmIconifyCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmIconifyCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "window");
return TCL_ERROR;
}
if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't iconify \"%s\": override-redirect flag is set",
winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "OVERRIDE_REDIRECT",
NULL);
return TCL_ERROR;
} else if (wmPtr->master != None) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't iconify \"%s\": it is a transient", winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "TRANSIENT", NULL);
return TCL_ERROR;
} else if (wmPtr->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't iconify %s: it is an icon for %s",
winPtr->pathName, Tk_PathName(wmPtr->iconFor)));
Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "ICON", NULL);
return TCL_ERROR;
} else if (winPtr->flags & TK_EMBEDDED) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't iconify %s: it is an embedded window",
winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "ICONIFY", "EMBEDDED", NULL);
return TCL_ERROR;
}
TkpWmSetState(winPtr, IconicState);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmIconmaskCmd --
*
* This procedure is invoked to process the "wm iconmask" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmIconmaskCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
Pixmap pixmap;
char *argv3;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?bitmap?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->hints.flags & IconMaskHint) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
Tk_NameOfBitmap(winPtr->display, wmPtr->hints.icon_mask),
-1));
}
return TCL_OK;
}
argv3 = Tcl_GetString(objv[3]);
if (*argv3 == '\0') {
if (wmPtr->hints.icon_mask != None) {
Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_mask);
}
wmPtr->hints.flags &= ~IconMaskHint;
} else {
pixmap = Tk_GetBitmap(interp, tkwin, argv3);
if (pixmap == None) {
return TCL_ERROR;
}
wmPtr->hints.icon_mask = pixmap;
wmPtr->hints.flags |= IconMaskHint;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmIconnameCmd --
*
* This procedure is invoked to process the "wm iconname" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmIconnameCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
const char *argv3;
int length;
if (objc > 4) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?newName?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->iconName != NULL) {
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;
}
/*
*----------------------------------------------------------------------
*
* 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.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmIconphotoCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tk_PhotoHandle photo;
int i, width, height, isDefault = 0;
if (objc < 4) {
Tcl_WrongNumArgs(interp, 2, objv,
"window ?-default? image1 ?image2 ...?");
return TCL_ERROR;
}
if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) {
isDefault = 1;
if (objc == 4) {
Tcl_WrongNumArgs(interp, 2, objv,
"window ?-default? image1 ?image2 ...?");
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) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't use \"%s\" as iconphoto: not a photo image",
Tcl_GetString(objv[i])));
Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL);
return TCL_ERROR;
}
Tk_PhotoGetSize(photo, &width, &height);
}
/*
* TODO: This requires implementation for OS X, but we silently return for
* now.
*/
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmIconpositionCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmIconpositionCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int x, y;
if ((objc != 3) && (objc != 5)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?x y?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->hints.flags & IconPositionHint) {
Tcl_Obj *results[2];
results[0] = Tcl_NewIntObj(wmPtr->hints.icon_x);
results[1] = Tcl_NewIntObj(wmPtr->hints.icon_y);
Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
}
return TCL_OK;
}
if (*Tcl_GetString(objv[3]) == '\0') {
wmPtr->hints.flags &= ~IconPositionHint;
} else {
if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
|| (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)){
return TCL_ERROR;
}
wmPtr->hints.icon_x = x;
wmPtr->hints.icon_y = y;
wmPtr->hints.flags |= IconPositionHint;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmIconwindowCmd --
*
* This procedure is invoked to process the "wm iconwindow" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmIconwindowCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
Tk_Window tkwin2;
WmInfo *wmPtr2;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?pathName?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->icon != NULL) {
Tcl_SetObjResult(interp, TkNewWindowObj(wmPtr->icon));
}
return TCL_OK;
}
if (*Tcl_GetString(objv[3]) == '\0') {
wmPtr->hints.flags &= ~IconWindowHint;
if (wmPtr->icon != NULL) {
wmPtr2 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
wmPtr2->iconFor = NULL;
wmPtr2->hints.initial_state = WithdrawnState;
}
wmPtr->icon = NULL;
} else {
if (TkGetWindowFromObj(interp, tkwin, objv[3], &tkwin2) != TCL_OK) {
return TCL_ERROR;
}
if (!Tk_IsTopLevel(tkwin2)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't use %s as icon window: not at top level",
Tk_PathName(tkwin2)));
Tcl_SetErrorCode(interp, "TK", "WM", "ICONWINDOW", "TOPLEVEL",
NULL);
return TCL_ERROR;
}
wmPtr2 = ((TkWindow *) tkwin2)->wmInfoPtr;
if (wmPtr2->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"%s is already an icon for %s",
Tcl_GetString(objv[3]), Tk_PathName(wmPtr2->iconFor)));
Tcl_SetErrorCode(interp, "TK", "WM", "ICONWINDOW", "ICON", NULL);
return TCL_ERROR;
}
if (wmPtr->icon != NULL) {
WmInfo *wmPtr3 = ((TkWindow *) wmPtr->icon)->wmInfoPtr;
wmPtr3->iconFor = NULL;
}
Tk_MakeWindowExist(tkwin2);
wmPtr->hints.icon_window = Tk_WindowId(tkwin2);
wmPtr->hints.flags |= IconWindowHint;
wmPtr->icon = tkwin2;
wmPtr2->iconFor = (Tk_Window) winPtr;
if (!(wmPtr2->flags & WM_NEVER_MAPPED)) {
/*
* Don't have iconwindows on the Mac. We just withdraw.
*/
Tk_UnmapWindow(tkwin2);
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmManageCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmManageCmd(
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. */
{
register Tk_Window frameWin = (Tk_Window) winPtr;
register WmInfo *wmPtr = winPtr->wmInfoPtr;
if (!Tk_IsTopLevel(frameWin)) {
MacDrawable *macWin = (MacDrawable *) winPtr->window;
if (!Tk_IsManageable(frameWin)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"window \"%s\" is not manageable: must be a"
" frame, labelframe or toplevel",
Tk_PathName(frameWin)));
Tcl_SetErrorCode(interp, "TK", "WM", "MANAGE", NULL);
return TCL_ERROR;
}
TkFocusSplit(winPtr);
Tk_UnmapWindow(frameWin);
if (wmPtr == NULL) {
TkWmNewWindow(winPtr);
if (winPtr->window == None) {
Tk_MakeWindowExist((Tk_Window) winPtr);
macWin = (MacDrawable *) winPtr->window;
}
TkWmMapWindow(winPtr);
Tk_UnmapWindow(frameWin);
}
wmPtr = winPtr->wmInfoPtr;
winPtr->flags &= ~TK_MAPPED;
macWin->toplevel = macWin;
RemapWindows(winPtr, macWin);
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;
}
/*
*----------------------------------------------------------------------
*
* WmMaxsizeCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmMaxsizeCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int width, height;
if ((objc != 3) && (objc != 5)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
return TCL_ERROR;
}
if (objc == 3) {
Tcl_Obj *results[2];
GetMaxSize(winPtr, &width, &height);
results[0] = Tcl_NewIntObj(width);
results[1] = Tcl_NewIntObj(height);
Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
return TCL_OK;
}
if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
|| (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
return TCL_ERROR;
}
wmPtr->maxWidth = width;
wmPtr->maxHeight = height;
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
WmUpdateGeom(wmPtr, winPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmMinsizeCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmMinsizeCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int width, height;
if ((objc != 3) && (objc != 5)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
return TCL_ERROR;
}
if (objc == 3) {
Tcl_Obj *results[2];
GetMinSize(winPtr, &width, &height);
results[0] = Tcl_NewIntObj(width);
results[1] = Tcl_NewIntObj(height);
Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
return TCL_OK;
}
if ((Tcl_GetIntFromObj(interp, objv[3], &width) != TCL_OK)
|| (Tcl_GetIntFromObj(interp, objv[4], &height) != TCL_OK)) {
return TCL_ERROR;
}
wmPtr->minWidth = width;
wmPtr->minHeight = height;
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
WmUpdateGeom(wmPtr, winPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmOverrideredirectCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmOverrideredirectCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int boolean;
XSetWindowAttributes atts;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?boolean?");
return TCL_ERROR;
}
if (objc == 3) {
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
Tk_Attributes((Tk_Window) winPtr)->override_redirect));
return TCL_OK;
}
if (Tcl_GetBooleanFromObj(interp, objv[3], &boolean) != TCL_OK) {
return TCL_ERROR;
}
atts.override_redirect = (boolean) ? True : False;
Tk_ChangeWindowAttributes((Tk_Window) winPtr, CWOverrideRedirect, &atts);
ApplyMasterOverrideChanges(winPtr, NULL);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmPositionfromCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmPositionfromCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
static const char *const optionStrings[] = {
"program", "user", NULL };
enum options {
OPT_PROGRAM, OPT_USER };
int index;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?user/program?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->sizeHintsFlags & USPosition) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("user", -1));
} else if (wmPtr->sizeHintsFlags & PPosition) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("program", -1));
}
return TCL_OK;
}
if (*Tcl_GetString(objv[3]) == '\0') {
wmPtr->sizeHintsFlags &= ~(USPosition|PPosition);
} else {
if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
&index) != TCL_OK) {
return TCL_ERROR;
}
if (index == OPT_USER) {
wmPtr->sizeHintsFlags &= ~PPosition;
wmPtr->sizeHintsFlags |= USPosition;
} else {
wmPtr->sizeHintsFlags &= ~USPosition;
wmPtr->sizeHintsFlags |= PPosition;
}
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
WmUpdateGeom(wmPtr, winPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmProtocolCmd --
*
* This procedure is invoked to process the "wm protocol" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmProtocolCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
register ProtocolHandler *protPtr, *prevPtr;
Atom protocol;
char *cmd;
int cmdLength;
Tcl_Obj *resultObj;
if ((objc < 3) || (objc > 5)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?name? ?command?");
return TCL_ERROR;
}
if (objc == 3) {
/*
* Return a list of all defined protocols for the window.
*/
resultObj = Tcl_NewObj();
for (protPtr = wmPtr->protPtr; protPtr != NULL;
protPtr = protPtr->nextPtr) {
Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
Tk_GetAtomName((Tk_Window)winPtr, protPtr->protocol),-1));
}
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
}
protocol = Tk_InternAtom((Tk_Window) winPtr, Tcl_GetString(objv[3]));
if (objc == 4) {
/*
* Return the command to handle a given protocol.
*/
for (protPtr = wmPtr->protPtr; protPtr != NULL;
protPtr = protPtr->nextPtr) {
if (protPtr->protocol == protocol) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj(protPtr->command, -1));
return TCL_OK;
}
}
return TCL_OK;
}
/*
* 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;
prevPtr = protPtr, protPtr = protPtr->nextPtr) {
if (protPtr->protocol == protocol) {
if (prevPtr == NULL) {
wmPtr->protPtr = protPtr->nextPtr;
} else {
prevPtr->nextPtr = protPtr->nextPtr;
}
Tcl_EventuallyFree(protPtr, TCL_DYNAMIC);
break;
}
}
cmd = Tcl_GetStringFromObj(objv[4], &cmdLength);
if (cmdLength > 0) {
protPtr = ckalloc(HANDLER_SIZE(cmdLength));
protPtr->protocol = protocol;
protPtr->nextPtr = wmPtr->protPtr;
wmPtr->protPtr = protPtr;
protPtr->interp = interp;
strcpy(protPtr->command, cmd);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmResizableCmd --
*
* This procedure is invoked to process the "wm resizable" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmResizableCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
int width, height;
UInt64 oldAttributes = wmPtr->attributes;
int oldFlags = wmPtr->flags;
if ((objc != 3) && (objc != 5)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
return TCL_ERROR;
}
if (objc == 3) {
Tcl_Obj *results[2];
results[0] = Tcl_NewBooleanObj(!(wmPtr->flags & WM_WIDTH_NOT_RESIZABLE));
results[1] = Tcl_NewBooleanObj(!(wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE));
Tcl_SetObjResult(interp, Tcl_NewListObj(2, results));
return TCL_OK;
}
if ((Tcl_GetBooleanFromObj(interp, objv[3], &width) != TCL_OK)
|| (Tcl_GetBooleanFromObj(interp, objv[4], &height) != TCL_OK)) {
return TCL_ERROR;
}
if (width) {
wmPtr->flags &= ~WM_WIDTH_NOT_RESIZABLE;
wmPtr->attributes |= kWindowHorizontalZoomAttribute;
} else {
wmPtr->flags |= WM_WIDTH_NOT_RESIZABLE;
wmPtr->attributes &= ~kWindowHorizontalZoomAttribute;
}
if (height) {
wmPtr->flags &= ~WM_HEIGHT_NOT_RESIZABLE;
wmPtr->attributes |= kWindowVerticalZoomAttribute;
} else {
wmPtr->flags |= WM_HEIGHT_NOT_RESIZABLE;
wmPtr->attributes &= ~kWindowVerticalZoomAttribute;
}
if (width || height) {
wmPtr->attributes |= kWindowResizableAttribute;
} else {
wmPtr->attributes &= ~kWindowResizableAttribute;
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
if (wmPtr->scrollWinPtr != NULL) {
TkScrollbarEventuallyRedraw((TkScrollbar *)
wmPtr->scrollWinPtr->instanceData);
}
WmUpdateGeom(wmPtr, winPtr);
ApplyWindowAttributeFlagChanges(winPtr, NULL, oldAttributes, oldFlags, 1,0);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmSizefromCmd --
*
* This procedure is invoked to process the "wm sizefrom" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmSizefromCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
static const char *const optionStrings[] = {
"program", "user", NULL };
enum options {
OPT_PROGRAM, OPT_USER };
int index;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?user|program?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->sizeHintsFlags & USSize) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("user", -1));
} else if (wmPtr->sizeHintsFlags & PSize) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("program", -1));
}
return TCL_OK;
}
if (*Tcl_GetString(objv[3]) == '\0') {
wmPtr->sizeHintsFlags &= ~(USSize|PSize);
} else {
if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
&index) != TCL_OK) {
return TCL_ERROR;
}
if (index == OPT_USER) {
wmPtr->sizeHintsFlags &= ~PSize;
wmPtr->sizeHintsFlags |= USSize;
} else { /* OPT_PROGRAM */
wmPtr->sizeHintsFlags &= ~USSize;
wmPtr->sizeHintsFlags |= PSize;
}
}
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
WmUpdateGeom(wmPtr, winPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmStackorderCmd --
*
* This procedure is invoked to process the "wm stackorder" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmStackorderCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
TkWindow **windows, **windowPtr;
static const char *const optionStrings[] = {
"isabove", "isbelow", NULL
};
enum options {
OPT_ISABOVE, OPT_ISBELOW
};
Tcl_Obj *resultObj;
int index;
if ((objc != 3) && (objc != 5)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?isabove|isbelow window?");
return TCL_ERROR;
}
if (objc == 3) {
windows = TkWmStackorderToplevel(winPtr);
if (windows == NULL) {
Tcl_Panic("TkWmStackorderToplevel failed");
}
resultObj = Tcl_NewObj();
for (windowPtr = windows; *windowPtr ; windowPtr++) {
Tcl_ListObjAppendElement(NULL, resultObj,
TkNewWindowObj((Tk_Window) *windowPtr));
}
Tcl_SetObjResult(interp, resultObj);
ckfree(windows);
return TCL_OK;
} else {
TkWindow *winPtr2;
int index1 = -1, index2 = -1, result;
if (TkGetWindowFromObj(interp, tkwin, objv[4], (Tk_Window *) &winPtr2)
!= TCL_OK) {
return TCL_ERROR;
}
if (!Tk_IsTopLevel(winPtr2)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"window \"%s\" isn't a top-level window",
winPtr2->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "STACK", "TOPLEVEL", NULL);
return TCL_ERROR;
}
if (!Tk_IsMapped(winPtr)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"window \"%s\" isn't mapped", winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "STACK", "MAPPED", NULL);
return TCL_ERROR;
} else if (!Tk_IsMapped(winPtr2)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"window \"%s\" isn't mapped", winPtr2->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "STACK", "MAPPED", NULL);
return TCL_ERROR;
}
/*
* 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_SetObjResult(interp, Tcl_NewStringObj(
"TkWmStackorderToplevel failed", -1));
Tcl_SetErrorCode(interp, "TK", "WM", "STACK", "FAIL", NULL);
return TCL_ERROR;
}
for (windowPtr = windows; *windowPtr ; windowPtr++) {
if (*windowPtr == winPtr) {
index1 = windowPtr - windows;
}
if (*windowPtr == winPtr2) {
index2 = windowPtr - windows;
}
}
if (index1 == -1) {
Tcl_Panic("winPtr window not found");
} else if (index2 == -1) {
Tcl_Panic("winPtr2 window not found");
}
ckfree(windows);
if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
&index) != TCL_OK) {
return TCL_ERROR;
}
if (index == OPT_ISABOVE) {
result = index1 > index2;
} else { /* OPT_ISBELOW */
result = index1 < index2;
}
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(result));
return TCL_OK;
}
}
/*
*----------------------------------------------------------------------
*
* WmStateCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmStateCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
static const char *const optionStrings[] = {
"normal", "iconic", "withdrawn", "zoomed", NULL };
enum options {
OPT_NORMAL, OPT_ICONIC, OPT_WITHDRAWN, OPT_ZOOMED };
int index;
if ((objc < 3) || (objc > 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?state?");
return TCL_ERROR;
}
if (objc == 4) {
if (wmPtr->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't change state of %s: it is an icon for %s",
Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "ICON", NULL);
return TCL_ERROR;
}
if (winPtr->flags & TK_EMBEDDED) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't change state of %s: it is an embedded window",
winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "EMBEDDED", NULL);
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[3], optionStrings, "argument", 0,
&index) != TCL_OK) {
return TCL_ERROR;
}
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
*/
} else if (index == OPT_ICONIC) {
if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't iconify \"%s\": override-redirect flag is set",
winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "STATE",
"OVERRIDE_REDIRECT", NULL);
return TCL_ERROR;
}
if (wmPtr->master != None) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't iconify \"%s\": it is a transient",
winPtr->pathName));
Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "TRANSIENT",
NULL);
return TCL_ERROR;
}
TkpWmSetState(winPtr, IconicState);
} else if (index == OPT_WITHDRAWN) {
TkpWmSetState(winPtr, WithdrawnState);
} else { /* OPT_ZOOMED */
TkpWmSetState(winPtr, ZoomState);
}
} else if (wmPtr->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("icon", -1));
} 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_SetObjResult(interp, Tcl_NewStringObj("normal", -1));
break;
case IconicState:
Tcl_SetObjResult(interp, Tcl_NewStringObj("iconic", -1));
break;
case WithdrawnState:
Tcl_SetObjResult(interp, Tcl_NewStringObj("withdrawn", -1));
break;
case ZoomState:
Tcl_SetObjResult(interp, Tcl_NewStringObj("zoomed", -1));
break;
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmTitleCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmTitleCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
char *argv3;
int length;
if (objc > 4) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?newTitle?");
return TCL_ERROR;
}
if (objc == 3) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
wmPtr->titleUid ? wmPtr->titleUid : winPtr->nameUid, -1));
return TCL_OK;
}
argv3 = Tcl_GetStringFromObj(objv[3], &length);
wmPtr->titleUid = Tk_GetUid(argv3);
if (!(wmPtr->flags & WM_NEVER_MAPPED) && !Tk_IsEmbedded(winPtr)) {
TkSetWMName(winPtr, wmPtr->titleUid);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmTransientCmd --
*
* This procedure is invoked to process the "wm transient" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmTransientCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
Tk_Window master;
WmInfo *wmPtr2;
char *masterWindowName;
int length;
if ((objc != 3) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?master?");
return TCL_ERROR;
}
if (objc == 3) {
if (wmPtr->master != None) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj(wmPtr->masterWindowName, -1));
}
return TCL_OK;
}
if (Tcl_GetString(objv[3])[0] == '\0') {
wmPtr->master = None;
if (wmPtr->masterWindowName != NULL) {
ckfree(wmPtr->masterWindowName);
}
wmPtr->masterWindowName = NULL;
} else {
if (TkGetWindowFromObj(interp, tkwin, objv[3], &master) != TCL_OK) {
return TCL_ERROR;
}
Tk_MakeWindowExist(master);
if (wmPtr->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't make \"%s\" a transient: it is an icon for %s",
Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
return TCL_ERROR;
}
wmPtr2 = ((TkWindow *) master)->wmInfoPtr;
/* Under some circumstances, wmPtr2 is NULL here */
if (wmPtr2 != NULL && wmPtr2->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't make \"%s\" a master: it is an icon for %s",
Tcl_GetString(objv[3]), Tk_PathName(wmPtr2->iconFor)));
Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
return TCL_ERROR;
}
if ((TkWindow *) master == winPtr) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't make \"%s\" its own master", Tk_PathName(winPtr)));
Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "SELF", NULL);
return TCL_ERROR;
}
wmPtr->master = Tk_WindowId(master);
masterWindowName = Tcl_GetStringFromObj(objv[3], &length);
if (wmPtr->masterWindowName != NULL) {
ckfree(wmPtr->masterWindowName);
}
wmPtr->masterWindowName = ckalloc(length+1);
strcpy(wmPtr->masterWindowName, masterWindowName);
}
ApplyMasterOverrideChanges(winPtr, NULL);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WmWithdrawCmd --
*
* This procedure is invoked to process the "wm withdraw" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
static int
WmWithdrawCmd(
Tk_Window tkwin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel to work with */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
register WmInfo *wmPtr = winPtr->wmInfoPtr;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "window");
return TCL_ERROR;
}
if (wmPtr->iconFor != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"can't withdraw %s: it is an icon for %s",
Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
Tcl_SetErrorCode(interp, "TK", "WM", "WITHDRAW", "ICON", NULL);
return TCL_ERROR;
}
TkpWmSetState(winPtr, WithdrawnState);
return TCL_OK;
}
/*
* Invoked by those wm subcommands that affect geometry.
* Schedules a geometry update.
*/
static void
WmUpdateGeom(
WmInfo *wmPtr,
TkWindow *winPtr)
{
if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
wmPtr->flags |= WM_UPDATE_PENDING;
}
}
/*
*----------------------------------------------------------------------
*
* 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.
*
* 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.
*
*----------------------------------------------------------------------
*/
void
Tk_SetGrid(
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. */
{
TkWindow *winPtr = (TkWindow *) tkwin;
WmInfo *wmPtr;
/*
* Ensure widthInc and heightInc are greater than 0
*/
if (widthInc <= 0) {
widthInc = 1;
}
if (heightInc <= 0) {
heightInc = 1;
}
/*
* Find the top-level window for tkwin, plus the window manager
* information.
*/
while (!(winPtr->flags & TK_TOP_LEVEL)) {
winPtr = winPtr->parentPtr;
}
wmPtr = winPtr->wmInfoPtr;
if ((wmPtr->gridWin != NULL) && (wmPtr->gridWin != tkwin)) {
return;
}
if ((wmPtr->reqGridWidth == reqWidth)
&& (wmPtr->reqGridHeight == reqHeight)
&& (wmPtr->widthInc == widthInc)
&& (wmPtr->heightInc == heightInc)
&& ((wmPtr->sizeHintsFlags & (PBaseSize|PResizeInc))
== (PBaseSize|PResizeInc))) {
return;
}
/*
* 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)) {
wmPtr->width = -1;
wmPtr->height = -1;
}
/*
* Set the new gridding information, and start the process of passing all
* of this information to the window manager.
*/
wmPtr->gridWin = tkwin;
wmPtr->reqGridWidth = reqWidth;
wmPtr->reqGridHeight = reqHeight;
wmPtr->widthInc = widthInc;
wmPtr->heightInc = heightInc;
wmPtr->sizeHintsFlags |= PBaseSize|PResizeInc;
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
wmPtr->flags |= WM_UPDATE_PENDING;
}
}
/*
*----------------------------------------------------------------------
*
* Tk_UnsetGrid --
*
* 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.
*
*----------------------------------------------------------------------
*/
void
Tk_UnsetGrid(
Tk_Window tkwin) /* Token for window that is currently
* controlling gridding. */
{
TkWindow *winPtr = (TkWindow *) tkwin;
WmInfo *wmPtr;
/*
* Find the top-level window for tkwin, plus the window manager
* information.
*/
while (!(winPtr->flags & TK_TOP_LEVEL)) {
winPtr = winPtr->parentPtr;
}
wmPtr = winPtr->wmInfoPtr;
if (tkwin != wmPtr->gridWin) {
return;
}
wmPtr->gridWin = NULL;
wmPtr->sizeHintsFlags &= ~(PBaseSize|PResizeInc);
if (wmPtr->width != -1) {
wmPtr->width = winPtr->reqWidth + (wmPtr->width
- wmPtr->reqGridWidth)*wmPtr->widthInc;
wmPtr->height = winPtr->reqHeight + (wmPtr->height
- wmPtr->reqGridHeight)*wmPtr->heightInc;
}
wmPtr->widthInc = 1;
wmPtr->heightInc = 1;
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
wmPtr->flags |= WM_UPDATE_PENDING;
}
}
/*
*----------------------------------------------------------------------
*
* TopLevelEventProc --
*
* This procedure is invoked when a top-level (or other externally-
* managed window) is restructured in any way.
*
* Results:
* None.
*
* Side effects:
* Tk's internal data structures for the window get modified to reflect
* the structural change.
*
*----------------------------------------------------------------------
*/
static void
TopLevelEventProc(
ClientData clientData, /* Window for which event occurred. */
XEvent *eventPtr) /* Event that just happened. */
{
TkWindow *winPtr = clientData;
winPtr->wmInfoPtr->flags |= WM_VROOT_OFFSET_STALE;
if (eventPtr->type == DestroyNotify) {
if (!(winPtr->flags & TK_ALREADY_DEAD)) {
/*
* A top-level window was deleted externally (e.g., by the window
* manager). This is probably not a good thing, but cleanup as
* best we can. The error handler is needed because
* Tk_DestroyWindow will try to destroy the window, but of course
* it's already gone.
*/
Tk_ErrorHandler handler = Tk_CreateErrorHandler(winPtr->display,
-1, -1, -1, NULL, NULL);
Tk_DestroyWindow((Tk_Window) winPtr);
Tk_DeleteErrorHandler(handler);
}
if (wmTracing) {
TkMacOSXDbgMsg("TopLevelEventProc: %s deleted", winPtr->pathName);
}
} else if (eventPtr->type == ReparentNotify) {
Tcl_Panic("recieved unwanted reparent event");
}
}
/*
*----------------------------------------------------------------------
*
* TopLevelReqProc --
*
* 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).
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
static void
TopLevelReqProc(
ClientData dummy, /* Not used. */
Tk_Window tkwin) /* Information about window. */
{
TkWindow *winPtr = (TkWindow *) tkwin;
WmInfo *wmPtr;
wmPtr = winPtr->wmInfoPtr;
wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
Tcl_DoWhenIdle(UpdateGeometryInfo, winPtr);
wmPtr->flags |= WM_UPDATE_PENDING;
}
}
/*
*----------------------------------------------------------------------
*
* 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.
*
* Results:
* None.
*
* Side effects:
* The window's size and location may change, unless the WM prevents that
* from happening.
*
*----------------------------------------------------------------------
*/
static void
UpdateGeometryInfo(
ClientData clientData) /* Pointer to the window's record. */
{
TkWindow *winPtr = clientData;
WmInfo *wmPtr = winPtr->wmInfoPtr;
int x, y, width, height, min, max;
wmPtr->flags &= ~WM_UPDATE_PENDING;
if (wmPtr->flags & WM_FULLSCREEN) {
return;
}
/*
* 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) {
width = winPtr->reqWidth;
} else if (wmPtr->gridWin != NULL) {
width = winPtr->reqWidth
+ (wmPtr->width - wmPtr->reqGridWidth)*wmPtr->widthInc;
} else {
width = wmPtr->width;
}
if (width <= 0) {
width = 1;
}
/*
* Account for window max/min width
*/