tkMacOSXWm.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:176k
- /*
- * 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, Apple Computer, Inc.
- * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net>
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: tkMacOSXWm.c,v 1.7.2.46 2007/12/18 18:21:31 das Exp $
- */
- #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
- */
- /*
- * 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 *WmAttributeNames[] = {
- "-alpha", "-fullscreen", "-modified",/* "-notify",*/
- "-titlepath", "-topmost", "-transparent",
- NULL
- };
- /*
- * This is a list of all of the toplevels that have been mapped so far. It is
- * used by the menu code to inval windows that were damaged by menus, and will
- * eventually also be used to keep track of floating windows.
- */
- TkMacOSXWindowList *tkMacOSXWindowListPtr = NULL;
- /*
- * The variable below is used to enable or disable tracing in this
- * module. If tracing is enabled, then information is printed on
- * standard output about interesting interactions with the window
- * manager.
- */
- 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 */
- (Tk_GeomLostSlaveProc *) NULL, /* lostSlaveProc */
- };
- /*
- * The following keeps state for Aqua dock icon bounce notification.
- */
- #if 0
- static int tkMacOSXWmAttrNotifyVal = 0;
- #endif
- /*
- * Hash table for Mac Window -> TkWindow mapping.
- */
- static Tcl_HashTable windowTable;
- static int windowHashInit = false;
- /*
- * Forward declarations for procedures defined in this file:
- */
- static void InitialWindowBounds(TkWindow *winPtr, WindowRef macWindow,
- Rect *geometry);
- static int ParseGeometry(Tcl_Interp *interp, char *string, TkWindow *winPtr);
- static void TopLevelEventProc(ClientData clientData, XEvent *eventPtr);
- static void WmStackorderToplevelWrapperMap(TkWindow *winPtr, Display *display,
- Tcl_HashTable *table);
- static void UpdateGeometryInfo(ClientData clientData);
- static void UpdateSizeHints(TkWindow *winPtr);
- static void UpdateVRootGeometry(WmInfo *wmPtr);
- static int WmAspectCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmAttributesCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmClientCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmColormapwindowsCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmCommandCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmDeiconifyCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmFocusmodelCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- #if 0
- static int WmForgetCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- #endif
- static int WmFrameCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmGeometryCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmGridCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmGroupCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmIconbitmapCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmIconifyCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmIconmaskCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmIconnameCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmIconphotoCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmIconpositionCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmIconwindowCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- #if 0
- static int WmManageCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- #endif
- static int WmMaxsizeCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmMinsizeCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmOverrideredirectCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmPositionfromCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmProtocolCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmResizableCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmSizefromCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmStackorderCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmStateCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmTitleCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static int WmTransientCmd(Tk_Window tkwin, TkWindow *winPtr,
- Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
- static int WmWithdrawCmd(Tk_Window tkwin, TkWindow *winPtr, Tcl_Interp *interp,
- int objc, Tcl_Obj *const objv[]);
- static void WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr);
- static int WmWinStyle(Tcl_Interp *interp, TkWindow *winPtr, int objc,
- Tcl_Obj * const objv[]);
- static void ApplyWindowClassAttributeChanges(TkWindow *winPtr,
- WindowRef macWindow, WindowClass oldClass,
- WindowAttributes oldAttributes, int create);
- static void ApplyMasterOverrideChanges(TkWindow *winPtr, WindowRef macWindow);
- static WindowGroupRef WmGetWindowGroup(TkWindow *winPtr);
- static void GetMinSize(TkWindow *winPtr, int *minWidthPtr, int *minHeightPtr);
- static void GetMaxSize(TkWindow *winPtr, int *maxWidthPtr, int *maxHeightPtr);
- #if 0
- static void RemapWindows(TkWindow *winPtr, MacDrawable *parentWin);
- #endif
- /*
- *----------------------------------------------------------------------
- *
- * 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;
- wmPtr = (WmInfo *) 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->cmdArgv = NULL;
- wmPtr->clientMachine = NULL;
- wmPtr->flags = WM_NEVER_MAPPED;
- wmPtr->style = -1;
- wmPtr->macClass = kDocumentWindowClass;
- wmPtr->attributes = kWindowStandardDocumentAttributes
- | kWindowLiveResizeAttribute;
- wmPtr->scrollWinPtr = NULL;
- 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, (ClientData) 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) {
- wmPtr->flags &= ~WM_NEVER_MAPPED;
- /*
- * Create the underlying Mac window for this Tk window.
- */
- if (!TkMacOSXHostToplevelExists(winPtr)) {
- TkMacOSXMakeRealWindowExist(winPtr);
- }
- /*
- * 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, (ClientData) winPtr);
- }
- UpdateGeometryInfo((ClientData) 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;
- WmInfo *wmPtr2;
- if (wmPtr == NULL) {
- return;
- }
- 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->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;
- protPtr = wmPtr->protPtr;
- wmPtr->protPtr = protPtr->nextPtr;
- Tcl_EventuallyFree((ClientData) protPtr, TCL_DYNAMIC);
- }
- if (wmPtr->cmdArgv != NULL) {
- ckfree((char *) wmPtr->cmdArgv);
- }
- if (wmPtr->clientMachine != NULL) {
- ckfree((char *) wmPtr->clientMachine);
- }
- if (wmPtr->flags & WM_UPDATE_PENDING) {
- Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr);
- }
- ckfree((char *) 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 *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_SetResult(interp, ((wmTracing) ? "on" : "off"), TCL_STATIC);
- 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)
- #if 0
- && (index != WMOPT_MANAGE) && (index != WMOPT_FORGET)
- #endif
- ) {
- Tcl_AppendResult(interp, "window "", winPtr->pathName,
- "" isn't a top-level window", NULL);
- return TCL_ERROR;
- }
- switch ((enum options) index) {
- case WMOPT_ASPECT:
- return WmAspectCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ATTRIBUTES:
- return WmAttributesCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_CLIENT:
- return WmClientCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_COLORMAPWINDOWS:
- return WmColormapwindowsCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_COMMAND:
- return WmCommandCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_DEICONIFY:
- return WmDeiconifyCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_FOCUSMODEL:
- return WmFocusmodelCmd(tkwin, winPtr, interp, objc, objv);
- #if 0
- case WMOPT_FORGET:
- return WmForgetCmd(tkwin, winPtr, interp, objc, objv);
- #endif
- case WMOPT_FRAME:
- return WmFrameCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_GEOMETRY:
- return WmGeometryCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_GRID:
- return WmGridCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_GROUP:
- return WmGroupCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONBITMAP:
- return WmIconbitmapCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONIFY:
- return WmIconifyCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONMASK:
- return WmIconmaskCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONNAME:
- return WmIconnameCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONPHOTO:
- return WmIconphotoCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONPOSITION:
- return WmIconpositionCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_ICONWINDOW:
- return WmIconwindowCmd(tkwin, winPtr, interp, objc, objv);
- #if 0
- case WMOPT_MANAGE:
- return WmManageCmd(tkwin, winPtr, interp, objc, objv);
- #endif
- case WMOPT_MAXSIZE:
- return WmMaxsizeCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_MINSIZE:
- return WmMinsizeCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_OVERRIDEREDIRECT:
- return WmOverrideredirectCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_POSITIONFROM:
- return WmPositionfromCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_PROTOCOL:
- return WmProtocolCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_RESIZABLE:
- return WmResizableCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_SIZEFROM:
- return WmSizefromCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_STACKORDER:
- return WmStackorderCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_STATE:
- return WmStateCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_TITLE:
- return WmTitleCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_TRANSIENT:
- return WmTransientCmd(tkwin, winPtr, interp, objc, objv);
- case WMOPT_WITHDRAW:
- return WmWithdrawCmd(tkwin, winPtr, interp, objc, objv);
- }
- /* 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) {
- char buf[TCL_INTEGER_SPACE * 4];
- sprintf(buf, "%d %d %d %d", wmPtr->minAspect.x,
- wmPtr->minAspect.y, wmPtr->maxAspect.x,
- wmPtr->maxAspect.y);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- 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_SetResult(interp, "aspect number can't be <= 0",
- TCL_STATIC);
- 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 */
- WindowRef 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;
- }
- ChkErr(SetWindowAlpha, macWindow, 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 != IsWindowModified(macWindow)) {
- ChkErr(SetWindowModified, macWindow, boolean);
- }
- break;
- #if 0
- case WMATT_NOTIFY:
- if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
- return TCL_ERROR;
- }
- if (boolean == !tkMacOSXWmAttrNotifyVal) {
- static NMRec notifyRec;
- if (boolean) {
- bzero(¬ifyRec, sizeof(notifyRec));
- notifyRec.qType = nmType;
- notifyRec.nmMark = 1;
- ChkErr(NMInstall, ¬ifyRec);
- } else {
- ChkErr(NMRemove, ¬ifyRec);
- }
- tkMacOSXWmAttrNotifyVal = boolean;
- }
- break;
- #endif
- case WMATT_TITLEPATH: {
- const char *path;
- OSStatus err;
- path = Tcl_FSGetNativePath(value);
- if (path && *path) {
- FSRef ref;
- Boolean d;
- err = ChkErr(FSPathMakeRef, (const unsigned char*) path, &ref,
- &d);
- if (err == noErr) {
- TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef,
- err = ChkErr(HIWindowSetProxyFSRef, macWindow, &ref);
- ) TK_ELSE_MAC_OS_X (4,
- AliasHandle alias;
- err = ChkErr(FSNewAlias, NULL, &ref, &alias);
- if (err == noErr) {
- err = ChkErr(SetWindowProxyAlias, macWindow,
- alias);
- DisposeHandle((Handle) alias);
- }
- ) TK_ENDIF
- }
- } else {
- int len;
- Tcl_GetStringFromObj(value, &len);
- if (!len) {
- err = ChkErr(RemoveWindowProxy, macWindow);
- } else {
- err = fnfErr;
- }
- }
- if (err != noErr) {
- return TCL_ERROR;
- }
- break;
- }
- case WMATT_TOPMOST: {
- if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
- return TCL_ERROR;
- }
- if (boolean != ((wmPtr->flags & WM_TOPMOST) != 0)) {
- WindowGroupRef group;
- if (boolean) {
- wmPtr->flags |= WM_TOPMOST;
- } else {
- wmPtr->flags &= ~WM_TOPMOST;
- }
- group = WmGetWindowGroup(winPtr);
- if (group && group != GetWindowGroup(macWindow)) {
- ChkErr(SetWindowGroup, macWindow, group);
- }
- }
- break;
- }
- case WMATT_TRANSPARENT:
- if (Tcl_GetBooleanFromObj(interp, value, &boolean) != TCL_OK) {
- return TCL_ERROR;
- }
- if (boolean != ((wmPtr->flags & WM_TRANSPARENT) != 0)) {
- WindowAttributes oldAttributes = wmPtr->attributes;
- if (boolean) {
- wmPtr->flags |= WM_TRANSPARENT;
- wmPtr->attributes |= kWindowNoShadowAttribute;
- TK_IF_MAC_OS_X_API (3, HIWindowChangeFeatures,
- UInt32 features;
- ChkErr(GetWindowFeatures, macWindow, &features);
- if (features & kWindowIsOpaque) {
- ChkErr(HIWindowChangeFeatures, macWindow, 0,
- kWindowIsOpaque);
- }
- ) TK_ENDIF
- } else {
- wmPtr->flags &= ~WM_TRANSPARENT;
- wmPtr->attributes &= ~kWindowNoShadowAttribute;
- }
- ApplyWindowClassAttributeChanges(winPtr, macWindow,
- wmPtr->macClass, oldAttributes, 1);
- ChkErr(ReshapeCustomWindow, macWindow);
- TkMacOSXInvalidateWindow((MacDrawable *)(winPtr->window),
- TK_PARENT_WINDOW);
- }
- 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 */
- WindowRef macWindow,
- WmAttribute attribute) /* Code of attribute to get */
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- Tcl_Obj *result = NULL;
- switch (attribute) {
- case WMATT_ALPHA: {
- float fval = 1.0;
- ChkErr(GetWindowAlpha, macWindow, &fval);
- result = Tcl_NewDoubleObj(fval);
- break;
- }
- case WMATT_FULLSCREEN:
- result = Tcl_NewBooleanObj(wmPtr->flags & WM_FULLSCREEN);
- break;
- case WMATT_MODIFIED:
- result = Tcl_NewBooleanObj(IsWindowModified(macWindow));
- break;
- #if 0
- case WMATT_NOTIFY:
- result = Tcl_NewBooleanObj(tkMacOSXWmAttrNotifyVal);
- break;
- #endif
- case WMATT_TITLEPATH: {
- FSRef ref;
- UInt8 path[PATH_MAX+1];
- OSStatus err;
- TK_IF_MAC_OS_X_API (4, HIWindowSetProxyFSRef,
- err = ChkErr(HIWindowGetProxyFSRef, macWindow, &ref);
- ) TK_ELSE_MAC_OS_X (4,
- Boolean wasChanged;
- AliasHandle alias;
- err = ChkErr(GetWindowProxyAlias, macWindow, &alias);
- if (err == noErr) {
- err = ChkErr(FSResolveAlias, NULL, alias, &ref,
- &wasChanged);
- }
- ) TK_ENDIF
- if (err == noErr) {
- err = ChkErr(FSRefMakePath, &ref, path, PATH_MAX);
- }
- if (err != noErr) {
- *path = 0;
- }
- result = Tcl_NewStringObj((char*) path, -1);
- break;
- }
- case WMATT_TOPMOST:
- result = Tcl_NewBooleanObj(wmPtr->flags & WM_TOPMOST);
- break;
- case WMATT_TRANSPARENT:
- result = Tcl_NewBooleanObj(wmPtr->flags & WM_TRANSPARENT);
- break;
- case _WMATT_LAST_ATTRIBUTE:
- default:
- break;
- }
- 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;
- WindowRef 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_NewListObj(0,0);
- for (attribute = 0; attribute < _WMATT_LAST_ATTRIBUTE; ++attribute) {
- Tcl_ListObjAppendElement(interp, result,
- Tcl_NewStringObj(WmAttributeNames[attribute], -1));
- Tcl_ListObjAppendElement(interp, 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_SetResult(interp, wmPtr->clientMachine, TCL_STATIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- if (argv3[0] == 0) {
- if (wmPtr->clientMachine != NULL) {
- ckfree((char *) wmPtr->clientMachine);
- wmPtr->clientMachine = NULL;
- }
- return TCL_OK;
- }
- if (wmPtr->clientMachine != NULL) {
- ckfree((char *) wmPtr->clientMachine);
- }
- wmPtr->clientMachine = (char *)
- ckalloc((unsigned) (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;
- TkWindow *winPtr2;
- int i, windowObjc, gotToplevel = 0;
- Tcl_Obj **windowObjv;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?windowList?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- Tk_MakeWindowExist((Tk_Window) winPtr);
- for (i = 0; i < wmPtr->cmapCount; i++) {
- if ((i == (wmPtr->cmapCount-1))
- && (wmPtr->flags & WM_ADDED_TOPLEVEL_COLORMAP)) {
- break;
- }
- Tcl_AppendElement(interp, wmPtr->cmapList[i]->pathName);
- }
- return TCL_OK;
- }
- if (Tcl_ListObjGetElements(interp, objv[3], &windowObjc, &windowObjv)
- != TCL_OK) {
- return TCL_ERROR;
- }
- cmapList = (TkWindow **) ckalloc((unsigned)
- ((windowObjc+1)*sizeof(TkWindow*)));
- for (i = 0; i < windowObjc; i++) {
- if (TkGetWindowFromObj(interp, tkwin, windowObjv[i],
- (Tk_Window *) &winPtr2) != TCL_OK)
- {
- ckfree((char *) 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((char *)wmPtr->cmapList);
- }
- wmPtr->cmapList = cmapList;
- wmPtr->cmapCount = windowObjc;
- /*
- * On the Macintosh all of this is just an excercise
- * in compatability as we don't support colormaps. If
- * we did they would be installed here.
- */
- 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;
- char *argv3;
- int cmdArgc;
- const char **cmdArgv;
- if ((objc != 3) && (objc != 4)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?value?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- if (wmPtr->cmdArgv != NULL) {
- Tcl_SetResult(interp,
- Tcl_Merge(wmPtr->cmdArgc, wmPtr->cmdArgv),
- TCL_DYNAMIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetString(objv[3]);
- if (argv3[0] == 0) {
- if (wmPtr->cmdArgv != NULL) {
- ckfree((char *) wmPtr->cmdArgv);
- wmPtr->cmdArgv = NULL;
- }
- return TCL_OK;
- }
- if (Tcl_SplitList(interp, argv3, &cmdArgc, &cmdArgv) != TCL_OK) {
- return TCL_ERROR;
- }
- if (wmPtr->cmdArgv != NULL) {
- ckfree((char *) wmPtr->cmdArgv);
- }
- wmPtr->cmdArgc = cmdArgc;
- wmPtr->cmdArgv = cmdArgv;
- 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_AppendResult(interp, "can't deiconify ", Tcl_GetString(objv[2]),
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor), NULL);
- return TCL_ERROR;
- }
- if (winPtr->flags & TK_EMBEDDED) {
- Tcl_AppendResult(interp, "can't deiconify ", winPtr->pathName,
- ": it is an embedded window", 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 *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_SetResult(interp, (wmPtr->hints.input ? "passive" : "active"),
- TCL_STATIC);
- 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;
- }
- #if 0
- /*
- *----------------------------------------------------------------------
- *
- * 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(tkwin, winPtr, interp, objc, objv)
- Tk_Window tkwin; /* Main window of the application. */
- TkWindow *winPtr; /* Toplevel or Frame to work with */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj *CONST objv[]; /* Argument objects. */
- {
- #if 1
- Tcl_AppendResult(interp, "wm forget is not yet supported", (char*)NULL);
- return TCL_ERROR;
- #else
- register Tk_Window frameWin = (Tk_Window)winPtr;
- char *oldClass = (char*)Tk_Class(frameWin);
- if (Tk_IsTopLevel(frameWin)) {
- MacDrawable *macWin = (MacDrawable *) winPtr->window;
- CGrafPtr destPort = TkMacOSXGetDrawablePort(winPtr->window);
- TkFocusJoin(winPtr);
- Tk_UnmapWindow(frameWin);
- if (destPort != NULL) {
- WindowRef winRef;
- winRef = GetWindowFromPort(destPort);
- TkMacOSXUnregisterMacWindow(winRef);
- DisposeWindow(winRef);
- }
- macWin->grafPtr = NULL;
- macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel;
- macWin->flags &= ~TK_HOST_EXISTS;
- RemapWindows(winPtr, macWin);
- TkWmDeadWindow(winPtr);
- winPtr->flags &= ~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED);
- TkMapTopFrame(frameWin);
- } else {
- /* Already not managed by wm - ignore it */
- }
- return TCL_OK;
- #endif
- }
- #endif
- /*
- *----------------------------------------------------------------------
- *
- * WmFrameCmd --
- *
- * This procedure is invoked to process the "wm frame" Tcl command.
- * See the user documentation for details on what it does.
- *
- * 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;
- char buf[TCL_INTEGER_SPACE];
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "window");
- return TCL_ERROR;
- }
- window = wmPtr->reparent;
- if (window == None) {
- window = Tk_WindowId((Tk_Window) winPtr);
- }
- sprintf(buf, "0x%x", (unsigned int) window);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- 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) {
- char buf[16 + TCL_INTEGER_SPACE * 4];
- 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;
- }
- sprintf(buf, "%dx%d%c%d%c%d", width, height, xSign, wmPtr->x,
- ySign, wmPtr->y);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- return TCL_OK;
- }
- argv3 = Tcl_GetString(objv[3]);
- if (*argv3 == ' ') {
- 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;
- 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) {
- char buf[TCL_INTEGER_SPACE * 4];
- sprintf(buf, "%d %d %d %d", wmPtr->reqGridWidth,
- wmPtr->reqGridHeight, wmPtr->widthInc,
- wmPtr->heightInc);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- /*
- * 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) {
- Tcl_SetResult(interp, "baseWidth can't be < 0", TCL_STATIC);
- return TCL_ERROR;
- }
- if (reqHeight < 0) {
- Tcl_SetResult(interp, "baseHeight can't be < 0", TCL_STATIC);
- return TCL_ERROR;
- }
- if (widthInc <= 0) {
- Tcl_SetResult(interp, "widthInc can't be <= 0", TCL_STATIC);
- return TCL_ERROR;
- }
- if (heightInc <= 0) {
- Tcl_SetResult(interp, "heightInc can't be <= 0", TCL_STATIC);
- return TCL_ERROR;
- }
- Tk_SetGrid((Tk_Window) winPtr, reqWidth, reqHeight, widthInc,
- heightInc);
- }
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- WmUpdateGeom(wmPtr, winPtr);
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * 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_SetResult(interp, wmPtr->leaderName, TCL_STATIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- if (*argv3 == ' ') {
- 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((unsigned) (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_SetResult(interp, (char*)Tk_NameOfBitmap(winPtr->display,
- wmPtr->hints.icon_pixmap), TCL_STATIC);
- }
- 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_AppendResult(interp, "can't iconify "", winPtr->pathName,
- "": override-redirect flag is set", NULL);
- return TCL_ERROR;
- }
- if (wmPtr->master != None) {
- Tcl_AppendResult(interp, "can't iconify "", winPtr->pathName,
- "": it is a transient", NULL);
- return TCL_ERROR;
- }
- if (wmPtr->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't iconify ", winPtr->pathName,
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor), NULL);
- return TCL_ERROR;
- }
- if (winPtr->flags & TK_EMBEDDED) {
- Tcl_AppendResult(interp, "can't iconify ", winPtr->pathName,
- ": it is an embedded window", 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_SetResult(interp,
- (char*)Tk_NameOfBitmap(winPtr->display,
- wmPtr->hints.icon_mask), TCL_STATIC);
- }
- return TCL_OK;
- }
- argv3 = Tcl_GetString(objv[3]);
- if (*argv3 == ' ') {
- 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) {
- Tcl_SetResult(interp,
- (char*)((wmPtr->iconName != NULL) ?
- wmPtr->iconName : ""), TCL_STATIC);
- return TCL_OK;
- } else {
- if (wmPtr->iconName != NULL) {
- ckfree((char *) wmPtr->iconName);
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- wmPtr->iconName = ckalloc((unsigned) (length + 1));
- strcpy(wmPtr->iconName, argv3);
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- XSetIconName(winPtr->display, winPtr->window, wmPtr->iconName);
- }
- }
- 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_AppendResult(interp, "can't use "", Tcl_GetString(objv[i]),
- "" as iconphoto: not a photo image", NULL);
- return TCL_ERROR;
- }
- Tk_PhotoGetSize(photo, &width, &height);
- }
- /*
- * 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) {
- char buf[TCL_INTEGER_SPACE * 2];
- sprintf(buf, "%d %d", wmPtr->hints.icon_x,
- wmPtr->hints.icon_y);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- 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_SetResult(interp, Tk_PathName(wmPtr->icon), TCL_STATIC);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- 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_AppendResult(interp, "can't use ", Tcl_GetString(objv[3]),
- " as icon window: not at top level", NULL);
- return TCL_ERROR;
- }
- wmPtr2 = ((TkWindow *) tkwin2)->wmInfoPtr;
- if (wmPtr2->iconFor != NULL) {
- Tcl_AppendResult(interp, Tcl_GetString(objv[3]),
- " is already an icon for ",
- Tk_PathName(wmPtr2->iconFor), 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;
- }
- #if 0
- /*
- *----------------------------------------------------------------------
- *
- * 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. */
- {
- #if 1
- Tcl_AppendResult(interp, "wm manage is not yet supported", (char*)NULL);
- return TCL_ERROR;
- #else
- register Tk_Window frameWin = (Tk_Window)winPtr;
- register WmInfo *wmPtr = winPtr->wmInfoPtr;
- char *oldClass = (char*)Tk_Class(frameWin);
- if (!Tk_IsTopLevel(frameWin)) {
- MacDrawable *macWin = (MacDrawable *) winPtr->window;
- 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->grafPtr = NULL;
- 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;
- #endif
- }
- #endif
- /*
- *----------------------------------------------------------------------
- *
- * 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) {
- char buf[TCL_INTEGER_SPACE * 2];
- GetMaxSize(winPtr, &width, &height);
- sprintf(buf, "%d %d", width, height);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- 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) {
- char buf[TCL_INTEGER_SPACE * 2];
- GetMinSize(winPtr, &width, &height);
- sprintf(buf, "%d %d", width, height);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- 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_SetBooleanObj(Tcl_GetObjResult(interp),
- 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 *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_SetResult(interp, "user", TCL_STATIC);
- } else if (wmPtr->sizeHintsFlags & PPosition) {
- Tcl_SetResult(interp, "program", TCL_STATIC);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- 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;
- 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.
- */
- for (protPtr = wmPtr->protPtr; protPtr != NULL;
- protPtr = protPtr->nextPtr) {
- Tcl_AppendElement(interp,
- Tk_GetAtomName((Tk_Window) winPtr, protPtr->protocol));
- }
- 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_SetResult(interp, protPtr->command, TCL_STATIC);
- 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((ClientData) protPtr, TCL_DYNAMIC);
- break;
- }
- }
- cmd = Tcl_GetStringFromObj(objv[4], &cmdLength);
- if (cmdLength > 0) {
- protPtr = (ProtocolHandler *) 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;
- WindowAttributes oldAttributes = wmPtr->attributes;
- if ((objc != 3) && (objc != 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?width height?");
- return TCL_ERROR;
- }
- if (objc == 3) {
- char buf[TCL_INTEGER_SPACE * 2];
- sprintf(buf, "%d %d",
- (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) ? 0 : 1,
- (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) ? 0 : 1);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- 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);
- ApplyWindowClassAttributeChanges(winPtr, NULL, wmPtr->macClass,
- oldAttributes, 1);
- 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 *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_SetResult(interp, "user", TCL_STATIC);
- } else if (wmPtr->sizeHintsFlags & PSize) {
- Tcl_SetResult(interp, "program", TCL_STATIC);
- }
- return TCL_OK;
- }
- if (*Tcl_GetString(objv[3]) == ' ') {
- 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, **window_ptr;
- static const char *optionStrings[] = {
- "isabove", "isbelow", NULL };
- enum options {
- OPT_ISABOVE, OPT_ISBELOW };
- 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");
- } else {
- for (window_ptr = windows; *window_ptr ; window_ptr++) {
- Tcl_AppendElement(interp, (*window_ptr)->pathName);
- }
- ckfree((char *) windows);
- return TCL_OK;
- }
- } else {
- TkWindow *winPtr2;
- int index1=-1, index2=-1, result;
- if (TkGetWindowFromObj(interp, tkwin, objv[4], (Tk_Window *) &winPtr2)
- != TCL_OK) {
- return TCL_ERROR;
- }
- if (!Tk_IsTopLevel(winPtr2)) {
- Tcl_AppendResult(interp, "window "", winPtr2->pathName,
- "" isn't a top-level window", NULL);
- return TCL_ERROR;
- }
- if (!Tk_IsMapped(winPtr)) {
- Tcl_AppendResult(interp, "window "", winPtr->pathName,
- "" isn't mapped", NULL);
- return TCL_ERROR;
- }
- if (!Tk_IsMapped(winPtr2)) {
- Tcl_AppendResult(interp, "window "", winPtr2->pathName,
- "" isn't 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_AppendResult(interp, "TkWmStackorderToplevel failed", NULL);
- return TCL_ERROR;
- } else {
- for (window_ptr = windows; *window_ptr ; window_ptr++) {
- if (*window_ptr == winPtr)
- index1 = (window_ptr - windows);
- if (*window_ptr == winPtr2)
- index2 = (window_ptr - windows);
- }
- if (index1 == -1)
- Tcl_Panic("winPtr window not found");
- if (index2 == -1)
- Tcl_Panic("winPtr2 window not found");
- ckfree((char *) windows);
- }
- 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_SetIntObj(Tcl_GetObjResult(interp), result);
- return TCL_OK;
- }
- 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 *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_AppendResult(interp, "can't change state of ",
- Tcl_GetString(objv[2]), ": it is an icon for ",
- Tk_PathName(wmPtr->iconFor), NULL);
- return TCL_ERROR;
- }
- if (winPtr->flags & TK_EMBEDDED) {
- Tcl_AppendResult(interp, "can't change state of ",
- winPtr->pathName, ": it is an embedded window", 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_AppendResult(interp, "can't iconify "", winPtr->pathName,
- "": override-redirect flag is set", NULL);
- return TCL_ERROR;
- }
- if (wmPtr->master != None) {
- Tcl_AppendResult(interp, "can't iconify "", winPtr->pathName,
- "": it is a 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_SetResult(interp, "icon", TCL_STATIC);
- } else {
- if (wmPtr->hints.initial_state == NormalState ||
- wmPtr->hints.initial_state == ZoomState) {
- wmPtr->hints.initial_state = (TkMacOSXIsWindowZoomed(winPtr) ?
- ZoomState : NormalState);
- }
- switch (wmPtr->hints.initial_state) {
- case NormalState:
- Tcl_SetResult(interp, "normal", TCL_STATIC);
- break;
- case IconicState:
- Tcl_SetResult(interp, "iconic", TCL_STATIC);
- break;
- case WithdrawnState:
- Tcl_SetResult(interp, "withdrawn", TCL_STATIC);
- break;
- case ZoomState:
- Tcl_SetResult(interp, "zoomed", TCL_STATIC);
- break;
- }
- }
- }
- 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_SetResult(interp, (char *)((wmPtr->titleUid != NULL) ?
- wmPtr->titleUid : winPtr->nameUid), TCL_STATIC);
- 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 *argv3;
- 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_SetResult(interp, wmPtr->masterWindowName, TCL_STATIC);
- }
- return TCL_OK;
- }
- if (Tcl_GetString(objv[3])[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_AppendResult(interp, "can't make "", Tcl_GetString(objv[2]),
- "" a transient: it is an icon for ",
- Tk_PathName(wmPtr->iconFor), NULL);
- return TCL_ERROR;
- }
- wmPtr2 = ((TkWindow *) master)->wmInfoPtr;
- /* Under some circumstances, wmPtr2 is NULL here */
- if (wmPtr2 != NULL && wmPtr2->iconFor != NULL) {
- Tcl_AppendResult(interp, "can't make "", Tcl_GetString(objv[3]),
- "" a master: it is an icon for ",
- Tk_PathName(wmPtr2->iconFor), NULL);
- return TCL_ERROR;
- }
- if ((TkWindow *) master == winPtr) {
- Tcl_AppendResult(interp, "can't make "", Tk_PathName(winPtr),
- "" its own master", NULL);
- return TCL_ERROR;
- }
- argv3 = Tcl_GetStringFromObj(objv[3], &length);
- wmPtr->master = Tk_WindowId(master);
- wmPtr->masterWindowName = ckalloc((unsigned) length+1);
- strcpy(wmPtr->masterWindowName, argv3);
- }
- 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_AppendResult(interp, "can't withdraw ", Tcl_GetString(objv[2]),
- ": it is an icon for ", Tk_PathName(wmPtr->iconFor), 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(wmPtr, winPtr)
- WmInfo *wmPtr;
- TkWindow *winPtr;
- {
- if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
- Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) 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, (ClientData) 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, (ClientData) 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 = (TkWindow *) 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