tkMacOSXWm.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:176k
- * 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, (Tk_ErrorProc *) NULL, (ClientData) 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, (ClientData) 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 = (TkWindow *) clientData;
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- int x, y, width, height, min, max;
- unsigned long serial;
- 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
- */
- if (wmPtr->gridWin != NULL) {
- min = winPtr->reqWidth
- + (wmPtr->minWidth - wmPtr->reqGridWidth)*wmPtr->widthInc;
- if (wmPtr->maxWidth > 0) {
- max = winPtr->reqWidth
- + (wmPtr->maxWidth - wmPtr->reqGridWidth)*wmPtr->widthInc;
- } else {
- max = 0;
- }
- } else {
- min = wmPtr->minWidth;
- max = wmPtr->maxWidth;
- }
- if (width < min) {
- width = min;
- } else if ((max > 0) && (width > max)) {
- width = max;
- }
- if (wmPtr->height == -1) {
- height = winPtr->reqHeight;
- } else if (wmPtr->gridWin != NULL) {
- height = winPtr->reqHeight
- + (wmPtr->height - wmPtr->reqGridHeight)*wmPtr->heightInc;
- } else {
- height = wmPtr->height;
- }
- if (height <= 0) {
- height = 1;
- }
- /*
- * Account for window max/min height
- */
- if (wmPtr->gridWin != NULL) {
- min = winPtr->reqHeight
- + (wmPtr->minHeight - wmPtr->reqGridHeight)*wmPtr->heightInc;
- if (wmPtr->maxHeight > 0) {
- max = winPtr->reqHeight
- + (wmPtr->maxHeight-wmPtr->reqGridHeight)*wmPtr->heightInc;
- } else {
- max = 0;
- }
- } else {
- min = wmPtr->minHeight;
- max = wmPtr->maxHeight;
- }
- if (height < min) {
- height = min;
- } else if ((max > 0) && (height > max)) {
- height = max;
- }
- /*
- * Compute the new position for the upper-left pixel of the window's
- * decorative frame. This is tricky, because we need to include the
- * border widths supplied by a reparented parent in this calculation,
- * but can't use the parent's current overall size since that may
- * change as a result of this code.
- */
- if (wmPtr->flags & WM_NEGATIVE_X) {
- x = wmPtr->vRootWidth - wmPtr->x
- - (width + (wmPtr->parentWidth - winPtr->changes.width));
- } else {
- x = wmPtr->x;
- }
- if (wmPtr->flags & WM_NEGATIVE_Y) {
- y = wmPtr->vRootHeight - wmPtr->y
- - (height + (wmPtr->parentHeight - winPtr->changes.height));
- } else {
- y = wmPtr->y;
- }
- /*
- * If the window's size is going to change and the window is
- * supposed to not be resizable by the user, then we have to
- * update the size hints. There may also be a size-hint-update
- * request pending from somewhere else, too.
- */
- if (((width != winPtr->changes.width)
- || (height != winPtr->changes.height))
- && (wmPtr->gridWin == NULL)
- && ((wmPtr->sizeHintsFlags & (PMinSize|PMaxSize)) == 0)) {
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- }
- if (wmPtr->flags & WM_UPDATE_SIZE_HINTS) {
- UpdateSizeHints(winPtr);
- }
- /*
- * Reconfigure the window if it isn't already configured correctly.
- * A few tricky points:
- *
- * 1. If the window is embedded and the container is also in this
- * process, don't actually reconfigure the window; just pass the
- * desired size on to the container. Also, zero out any position
- * information, since embedded windows are not allowed to move.
- * 2. Sometimes the window manager will give us a different size
- * than we asked for (e.g. mwm has a minimum size for windows), so
- * base the size check on what we *asked for* last time, not what we
- * got.
- * 3. Don't move window unless a new position has been requested for
- * it. This is because of "features" in some window managers (e.g.
- * twm, as of 4/24/91) where they don't interpret coordinates
- * according to ICCCM. Moving a window to its current location may
- * cause it to shift position on the screen.
- */
- if (Tk_IsEmbedded(winPtr)) {
- TkWindow *contWinPtr = TkpGetOtherWindow(winPtr);
- /*
- * TODO: Here we should handle out of process embedding.
- */
- if (contWinPtr != NULL) {
- /*
- * This window is embedded and the container is also in this
- * process, so we don't need to do anything special about the
- * geometry, except to make sure that the desired size is known
- * by the container. Also, zero out any position information,
- * since embedded windows are not allowed to move.
- */
- wmPtr->x = wmPtr->y = 0;
- wmPtr->flags &= ~(WM_NEGATIVE_X|WM_NEGATIVE_Y);
- Tk_GeometryRequest((Tk_Window) contWinPtr, width, height);
- }
- return;
- }
- serial = NextRequest(winPtr->display);
- if (wmPtr->flags & WM_MOVE_PENDING) {
- wmPtr->configWidth = width;
- wmPtr->configHeight = height;
- if (wmTracing) {
- TkMacOSXDbgMsg("Moving to %d %d, resizing to %d x %d", x, y,
- width, height);
- }
- wmPtr->flags |= WM_SYNC_PENDING;
- XMoveResizeWindow(winPtr->display, winPtr->window, x, y,
- (unsigned) width, (unsigned) height);
- wmPtr->flags &= ~WM_SYNC_PENDING;
- } else if ((width != wmPtr->configWidth)
- || (height != wmPtr->configHeight)) {
- wmPtr->configWidth = width;
- wmPtr->configHeight = height;
- if (wmTracing) {
- TkMacOSXDbgMsg("Resizing to %d x %dn", width, height);
- }
- wmPtr->flags |= WM_SYNC_PENDING;
- XResizeWindow(winPtr->display, winPtr->window, (unsigned) width,
- (unsigned) height);
- wmPtr->flags &= ~WM_SYNC_PENDING;
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * UpdateSizeHints --
- *
- * This procedure is called to update the window manager's
- * size hints information from the information in a WmInfo
- * structure.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Properties get changed for winPtr.
- *
- *----------------------------------------------------------------------
- */
- static void
- UpdateSizeHints(
- TkWindow *winPtr)
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- wmPtr->flags &= ~WM_UPDATE_SIZE_HINTS;
- return;
- }
- /*
- *----------------------------------------------------------------------
- *
- * ParseGeometry --
- *
- * This procedure parses a geometry string and updates
- * information used to control the geometry of a top-level
- * window.
- *
- * Results:
- * A standard Tcl return value, plus an error message in
- * the interp's result if an error occurs.
- *
- * Side effects:
- * The size and/or location of winPtr may change.
- *
- *----------------------------------------------------------------------
- */
- static int
- ParseGeometry(
- Tcl_Interp *interp, /* Used for error reporting. */
- char *string, /* String containing new geometry. Has the
- * standard form "=wxh+x+y". */
- TkWindow *winPtr) /* Pointer to top-level window whose
- * geometry is to be changed. */
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- int x, y, width, height, flags;
- char *end;
- char *p = string;
- /*
- * The leading "=" is optional.
- */
- if (*p == '=') {
- p++;
- }
- /*
- * Parse the width and height, if they are present. Don't
- * actually update any of the fields of wmPtr until we've
- * successfully parsed the entire geometry string.
- */
- width = wmPtr->width;
- height = wmPtr->height;
- x = wmPtr->x;
- y = wmPtr->y;
- flags = wmPtr->flags;
- if (isdigit(UCHAR(*p))) {
- width = strtoul(p, &end, 10);
- p = end;
- if (*p != 'x') {
- goto error;
- }
- p++;
- if (!isdigit(UCHAR(*p))) {
- goto error;
- }
- height = strtoul(p, &end, 10);
- p = end;
- }
- /*
- * Parse the X and Y coordinates, if they are present.
- */
- if (*p != ' ') {
- flags &= ~(WM_NEGATIVE_X | WM_NEGATIVE_Y);
- if (*p == '-') {
- flags |= WM_NEGATIVE_X;
- } else if (*p != '+') {
- goto error;
- }
- p++;
- if (!isdigit(UCHAR(*p)) && (*p != '-')) {
- goto error;
- }
- x = strtol(p, &end, 10);
- p = end;
- if (*p == '-') {
- flags |= WM_NEGATIVE_Y;
- } else if (*p != '+') {
- goto error;
- }
- p++;
- if (!isdigit(UCHAR(*p)) && (*p != '-')) {
- goto error;
- }
- y = strtol(p, &end, 10);
- if (*end != ' ') {
- goto error;
- }
- /*
- * Assume that the geometry information came from the user,
- * unless an explicit source has been specified. Otherwise
- * most window managers assume that the size hints were
- * program-specified and they ignore them.
- */
- if ((wmPtr->sizeHintsFlags & (USPosition|PPosition)) == 0) {
- wmPtr->sizeHintsFlags |= USPosition;
- flags |= WM_UPDATE_SIZE_HINTS;
- }
- }
- /*
- * Everything was parsed OK. Update the fields of *wmPtr and
- * arrange for the appropriate information to be percolated out
- * to the window manager at the next idle moment.
- */
- wmPtr->width = width;
- wmPtr->height = height;
- if ((x != wmPtr->x) || (y != wmPtr->y)
- || ((flags & (WM_NEGATIVE_X|WM_NEGATIVE_Y))
- != (wmPtr->flags & (WM_NEGATIVE_X|WM_NEGATIVE_Y)))) {
- if (wmPtr->flags & WM_FULLSCREEN) {
- wmPtr->configX = x;
- wmPtr->configY = y;
- } else {
- wmPtr->x = x;
- wmPtr->y = y;
- }
- flags |= WM_MOVE_PENDING;
- }
- wmPtr->flags = flags;
- if (!(wmPtr->flags & (WM_UPDATE_PENDING|WM_NEVER_MAPPED))) {
- Tcl_DoWhenIdle(UpdateGeometryInfo, (ClientData) winPtr);
- wmPtr->flags |= WM_UPDATE_PENDING;
- }
- return TCL_OK;
- error:
- Tcl_AppendResult(interp, "bad geometry specifier "", string, """, NULL);
- return TCL_ERROR;
- }
- /*
- *----------------------------------------------------------------------
- *
- * Tk_GetRootCoords --
- *
- * Given a token for a window, this procedure traces through the
- * window's lineage to find the (virtual) root-window coordinates
- * corresponding to point (0,0) in the window.
- *
- * Results:
- * The locations pointed to by xPtr and yPtr are filled in with
- * the root coordinates of the (0,0) point in tkwin. If a virtual
- * root window is in effect for the window, then the coordinates
- * in the virtual root are returned.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- void
- Tk_GetRootCoords(
- Tk_Window tkwin, /* Token for window. */
- int *xPtr, /* Where to store x-displacement of (0,0). */
- int *yPtr) /* Where to store y-displacement of (0,0). */
- {
- int x, y;
- TkWindow *winPtr = (TkWindow *) tkwin;
- /*
- * Search back through this window's parents all the way to a
- * top-level window, combining the offsets of each window within
- * its parent.
- */
- x = y = 0;
- while (1) {
- x += winPtr->changes.x + winPtr->changes.border_width;
- y += winPtr->changes.y + winPtr->changes.border_width;
- if (winPtr->flags & TK_TOP_LEVEL) {
- if (!(Tk_IsEmbedded(winPtr))) {
- x += winPtr->wmInfoPtr->xInParent;
- y += winPtr->wmInfoPtr->yInParent;
- break;
- } else {
- TkWindow *otherPtr = TkpGetOtherWindow(winPtr);
- if (otherPtr != NULL) {
- /*
- * The container window is in the same application.
- * Query its coordinates.
- */
- winPtr = otherPtr;
- /*
- * Remember to offset by the container window here,
- * since at the end of this if branch, we will
- * pop out to the container's parent...
- */
- x += winPtr->changes.x + winPtr->changes.border_width;
- y += winPtr->changes.y + winPtr->changes.border_width;
- } else {
- Point theOffset;
- if (tkMacOSXEmbedHandler->getOffsetProc != NULL) {
- /*
- * We do not require that the changes.x & changes.y for
- * a non-Tk master window be kept up to date. So we
- * first subtract off the possibly bogus values that
- * have been added on at the top of this pass through
- * the loop, and then call out to the getOffsetProc to
- * give us the correct offset.
- */
- x -= winPtr->changes.x + winPtr->changes.border_width;
- y -= winPtr->changes.y + winPtr->changes.border_width;
- tkMacOSXEmbedHandler->getOffsetProc((Tk_Window) winPtr,
- &theOffset);
- x += theOffset.h;
- y += theOffset.v;
- }
- break;
- }
- }
- }
- winPtr = winPtr->parentPtr;
- }
- *xPtr = x;
- *yPtr = y;
- }
- /*
- *----------------------------------------------------------------------
- *
- * Tk_CoordsToWindow --
- *
- * This is a Macintosh specific implementation of this function.
- * Given the root coordinates of a point, this procedure returns
- * the token for the top-most window covering that point, if
- * there exists such a window in this application.
- *
- * Results:
- * The return result is either a token for the window corresponding
- * to rootX and rootY, or else NULL to indicate that there is no such
- * window.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- Tk_Window
- Tk_CoordsToWindow(
- int rootX, int rootY, /* Coordinates of point in root window. If
- * a virtual-root window manager is in use,
- * these coordinates refer to the virtual
- * root, not the real root. */
- Tk_Window tkwin) /* Token for any window in application;
- * used to identify the display. */
- {
- WindowPtr whichWin;
- Point where;
- Window rootChild;
- TkWindow *winPtr, *childPtr;
- TkWindow *nextPtr; /* Coordinates of highest child found so
- * far that contains point. */
- int x, y; /* Coordinates in winPtr. */
- int tmpx, tmpy, bd;
- TkDisplay *dispPtr;
- /*
- * Step 1: find the top-level window that contains the desired point.
- */
- where.h = rootX;
- where.v = rootY;
- FindWindow(where, &whichWin);
- if (whichWin == NULL) {
- return NULL;
- }
- rootChild = TkMacOSXGetXWindow(whichWin);
- dispPtr = TkGetDisplayList();
- winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, rootChild);
- if (winPtr == NULL) {
- return NULL;
- }
- /*
- * Step 2: work down through the hierarchy underneath this window.
- * At each level, scan through all the children to find the highest
- * one in the stacking order that contains the point. Then repeat
- * the whole process on that child.
- */
- x = rootX - winPtr->wmInfoPtr->xInParent;
- y = rootY - winPtr->wmInfoPtr->yInParent;
- while (1) {
- x -= winPtr->changes.x;
- y -= winPtr->changes.y;
- nextPtr = NULL;
- /*
- * Container windows cannot have children. So if it is a container,
- * look there, otherwise inspect the children.
- */
- if (Tk_IsContainer(winPtr)) {
- childPtr = TkpGetOtherWindow(winPtr);
- if (childPtr != NULL) {
- if (Tk_IsMapped(childPtr)) {
- tmpx = x - childPtr->changes.x;
- tmpy = y - childPtr->changes.y;
- bd = childPtr->changes.border_width;
- if ((tmpx >= -bd) && (tmpy >= -bd)
- && (tmpx < (childPtr->changes.width + bd))
- && (tmpy < (childPtr->changes.height + bd))) {
- nextPtr = childPtr;
- }
- }
- }
- /*
- * TODO: Here we should handle out of process embedding.
- */
- } else {
- for (childPtr = winPtr->childList; childPtr != NULL;
- childPtr = childPtr->nextPtr) {
- if (!Tk_IsMapped(childPtr) ||
- (childPtr->flags & TK_TOP_LEVEL)) {
- continue;
- }
- tmpx = x - childPtr->changes.x;
- tmpy = y - childPtr->changes.y;
- bd = childPtr->changes.border_width;
- if ((tmpx >= -bd) && (tmpy >= -bd)
- && (tmpx < (childPtr->changes.width + bd))
- && (tmpy < (childPtr->changes.height + bd))) {
- nextPtr = childPtr;
- }
- }
- }
- if (nextPtr == NULL) {
- break;
- }
- winPtr = nextPtr;
- }
- return (Tk_Window) winPtr;
- }
- /*
- *----------------------------------------------------------------------
- *
- * Tk_TopCoordsToWindow --
- *
- * Given a Tk Window, and coordinates of a point relative to that window
- * this procedure returns the top-most child of the window (excluding
- * toplevels) covering that point, if there exists such a window in this
- * application.
- * It also sets newX, and newY to the coords of the point relative to the
- * window returned.
- *
- * Results:
- * The return result is either a token for the window corresponding
- * to rootX and rootY, or else NULL to indicate that there is no such
- * window. newX and newY are also set to the coords of the point relative
- * to the returned window.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- Tk_Window
- Tk_TopCoordsToWindow(
- Tk_Window tkwin, /* Token for a Tk Window which defines the;
- * coordinates for rootX & rootY */
- int rootX, int rootY, /* Coordinates of a point in tkWin. */
- int *newX, int *newY) /* Coordinates of point in the upperMost child
- * of tkWin containing (rootX,rootY) */
- {
- TkWindow *winPtr, *childPtr;
- TkWindow *nextPtr; /* Coordinates of highest child found so
- * far that contains point. */
- int x, y; /* Coordinates in winPtr. */
- Window *children; /* Children of winPtr, or NULL. */
- winPtr = (TkWindow *) tkwin;
- x = rootX;
- y = rootY;
- while (1) {
- nextPtr = NULL;
- children = NULL;
- /*
- * Container windows cannot have children. So if it is a container,
- * look there, otherwise inspect the children.
- */
- if (Tk_IsContainer(winPtr)) {
- childPtr = TkpGetOtherWindow(winPtr);
- if (childPtr != NULL) {
- if (Tk_IsMapped(childPtr) &&
- x > childPtr->changes.x &&
- x < childPtr->changes.x + childPtr->changes.width &&
- y > childPtr->changes.y &&
- y < childPtr->changes.y + childPtr->changes.height) {
- nextPtr = childPtr;
- }
- }
- /*
- * TODO: Here we should handle out of process embedding.
- */
- } else {
- for (childPtr = winPtr->childList; childPtr != NULL;
- childPtr = childPtr->nextPtr) {
- if (!Tk_IsMapped(childPtr) ||
- (childPtr->flags & TK_TOP_LEVEL)) {
- continue;
- }
- if (x < childPtr->changes.x || y < childPtr->changes.y) {
- continue;
- }
- if (x > childPtr->changes.x + childPtr->changes.width ||
- y > childPtr->changes.y + childPtr->changes.height) {
- continue;
- }
- nextPtr = childPtr;
- }
- }
- if (nextPtr == NULL) {
- break;
- }
- winPtr = nextPtr;
- x -= winPtr->changes.x;
- y -= winPtr->changes.y;
- }
- *newX = x;
- *newY = y;
- return (Tk_Window) winPtr;
- }
- /*
- *----------------------------------------------------------------------
- *
- * UpdateVRootGeometry --
- *
- * This procedure is called to update all the virtual root
- * geometry information in wmPtr.
- *
- * Results:
- * None.
- *
- * Side effects:
- * The vRootX, vRootY, vRootWidth, and vRootHeight fields in
- * wmPtr are filled with the most up-to-date information.
- *
- *----------------------------------------------------------------------
- */
- static void
- UpdateVRootGeometry(
- WmInfo *wmPtr) /* Window manager information to be
- * updated. The wmPtr->vRoot field must
- * be valid. */
- {
- TkWindow *winPtr = wmPtr->winPtr;
- unsigned int bd, dummy;
- Window dummy2;
- Status status;
- Tk_ErrorHandler handler;
- /*
- * If this isn't a virtual-root window manager, just return information
- * about the screen.
- */
- wmPtr->flags &= ~WM_VROOT_OFFSET_STALE;
- if (wmPtr->vRoot == None) {
- noVRoot:
- wmPtr->vRootX = wmPtr->vRootY = 0;
- wmPtr->vRootWidth = DisplayWidth(winPtr->display, winPtr->screenNum);
- wmPtr->vRootHeight = DisplayHeight(winPtr->display, winPtr->screenNum);
- return;
- }
- /*
- * Refresh the virtual root information if it's out of date.
- */
- handler = Tk_CreateErrorHandler(winPtr->display, -1, -1, -1,
- (Tk_ErrorProc *) NULL, (ClientData) NULL);
- status = XGetGeometry(winPtr->display, wmPtr->vRoot,
- &dummy2, &wmPtr->vRootX, &wmPtr->vRootY,
- &wmPtr->vRootWidth, &wmPtr->vRootHeight, &bd, &dummy);
- if (wmTracing) {
- TkMacOSXDbgMsg("x = %d, y = %d, width = %d, height = %d, status = %d",
- wmPtr->vRootX, wmPtr->vRootY, wmPtr->vRootWidth,
- wmPtr->vRootHeight, status);
- }
- Tk_DeleteErrorHandler(handler);
- if (status == 0) {
- /*
- * The virtual root is gone! Pretend that it never existed.
- */
- wmPtr->vRoot = None;
- goto noVRoot;
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * Tk_GetVRootGeometry --
- *
- * This procedure returns information about the virtual root
- * window corresponding to a particular Tk window.
- *
- * Results:
- * The values at xPtr, yPtr, widthPtr, and heightPtr are set
- * with the offset and dimensions of the root window corresponding
- * to tkwin. If tkwin is being managed by a virtual root window
- * manager these values correspond to the virtual root window being
- * used for tkwin; otherwise the offsets will be 0 and the
- * dimensions will be those of the screen.
- *
- * Side effects:
- * Vroot window information is refreshed if it is out of date.
- *
- *----------------------------------------------------------------------
- */
- void
- Tk_GetVRootGeometry(
- Tk_Window tkwin, /* Window whose virtual root is to be
- * queried. */
- int *xPtr, int *yPtr, /* Store x and y offsets of virtual root
- * here. */
- int *widthPtr, /* Store dimensions of virtual root here. */
- int *heightPtr)
- {
- WmInfo *wmPtr;
- TkWindow *winPtr = (TkWindow *) tkwin;
- /*
- * Find the top-level window for tkwin, and locate the window manager
- * information for that window.
- */
- while (!(winPtr->flags & TK_TOP_LEVEL)) {
- winPtr = winPtr->parentPtr;
- }
- wmPtr = winPtr->wmInfoPtr;
- /*
- * Make sure that the geometry information is up-to-date, then copy
- * it out to the caller.
- */
- if (wmPtr->flags & WM_VROOT_OFFSET_STALE) {
- UpdateVRootGeometry(wmPtr);
- }
- *xPtr = wmPtr->vRootX;
- *yPtr = wmPtr->vRootY;
- *widthPtr = wmPtr->vRootWidth;
- *heightPtr = wmPtr->vRootHeight;
- }
- /*
- *----------------------------------------------------------------------
- *
- * Tk_MoveToplevelWindow --
- *
- * This procedure is called instead of Tk_MoveWindow to adjust
- * the x-y location of a top-level window. It delays the actual
- * move to a later time and keeps window-manager information
- * up-to-date with the move
- *
- * Results:
- * None.
- *
- * Side effects:
- * The window is eventually moved so that its upper-left corner
- * (actually, the upper-left corner of the window's decorative
- * frame, if there is one) is at (x,y).
- *
- *----------------------------------------------------------------------
- */
- void
- Tk_MoveToplevelWindow(
- Tk_Window tkwin, /* Window to move. */
- int x, int y) /* New location for window (within
- * parent). */
- {
- TkWindow *winPtr = (TkWindow *) tkwin;
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- if (!(winPtr->flags & TK_TOP_LEVEL)) {
- Tcl_Panic("Tk_MoveToplevelWindow called with non-toplevel window");
- }
- wmPtr->x = x;
- wmPtr->y = y;
- wmPtr->flags |= WM_MOVE_PENDING;
- wmPtr->flags &= ~(WM_NEGATIVE_X|WM_NEGATIVE_Y);
- if ((wmPtr->sizeHintsFlags & (USPosition|PPosition)) == 0) {
- wmPtr->sizeHintsFlags |= USPosition;
- wmPtr->flags |= WM_UPDATE_SIZE_HINTS;
- }
- /*
- * If the window has already been mapped, must bring its geometry
- * up-to-date immediately, otherwise an event might arrive from the
- * server that would overwrite wmPtr->x and wmPtr->y and lose the
- * new position.
- */
- if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
- if (wmPtr->flags & WM_UPDATE_PENDING) {
- Tk_CancelIdleCall(UpdateGeometryInfo, (ClientData) winPtr);
- }
- UpdateGeometryInfo((ClientData) winPtr);
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkWmRestackToplevel --
- *
- * This procedure restacks a top-level window.
- *
- * Results:
- * None.
- *
- * Side effects:
- * WinPtr gets restacked as specified by aboveBelow and otherPtr.
- * This procedure doesn't return until the restack has taken
- * effect and the ConfigureNotify event for it has been received.
- *
- *----------------------------------------------------------------------
- */
- void
- TkWmRestackToplevel(
- TkWindow *winPtr, /* Window to restack. */
- int aboveBelow, /* Gives relative position for restacking;
- * must be Above or Below. */
- TkWindow *otherPtr) /* Window relative to which to restack;
- * if NULL, then winPtr gets restacked
- * above or below *all* siblings. */
- {
- WmInfo *wmPtr;
- WindowRef macWindow, otherMacWindow, frontWindow, tmpWindow;
- wmPtr = winPtr->wmInfoPtr;
- /*
- * Get the mac window. Make sure it exists & is mapped.
- */
- if (winPtr->window == None) {
- Tk_MakeWindowExist((Tk_Window) winPtr);
- }
- if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
- /*
- * Can't set stacking order properly until the window is on the
- * screen (mapping it may give it a reparent window), so make sure
- * it's on the screen.
- */
- TkWmMapWindow(winPtr);
- }
- macWindow = TkMacOSXDrawableWindow(winPtr->window);
- /*
- * Get the window in which a raise or lower is in relation to.
- */
- if (otherPtr != NULL) {
- if (otherPtr->window == None) {
- Tk_MakeWindowExist((Tk_Window) otherPtr);
- }
- if (otherPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) {
- TkWmMapWindow(otherPtr);
- }
- otherMacWindow = TkMacOSXDrawableWindow(otherPtr->window);
- } else {
- otherMacWindow = NULL;
- }
- frontWindow = ActiveNonFloatingWindow();
- if (aboveBelow == Above) {
- if (macWindow == frontWindow) {
- /*
- * Do nothing - it's already at the top.
- */
- } else if (otherMacWindow == frontWindow || otherMacWindow == NULL) {
- /*
- * Raise the window to the top. If the window is visible then
- * we also make it the active window.
- */
- if (wmPtr->hints.initial_state == WithdrawnState) {
- BringToFront(macWindow);
- } else {
- SelectWindow(macWindow);
- }
- } else {
- /*
- * Find the window to be above. (Front window will actually be the
- * window to be behind.) Front window is NULL if no other windows.
- */
- while (frontWindow != NULL &&
- (tmpWindow=GetNextWindow(frontWindow)) != otherMacWindow) {
- frontWindow = tmpWindow;
- }
- if (frontWindow != NULL) {
- SendBehind(macWindow, frontWindow);
- }
- }
- } else {
- /*
- * Send behind. If it was in front find another window to make active.
- */
- if (macWindow == frontWindow) {
- tmpWindow = GetNextWindow(macWindow);
- if (tmpWindow != NULL) {
- SelectWindow(tmpWindow);
- }
- }
- SendBehind(macWindow, otherMacWindow);
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkWmAddToColormapWindows --
- *
- * This procedure is called to add a given window to the
- * WM_COLORMAP_WINDOWS property for its top-level, if it
- * isn't already there. It is invoked by the Tk code that
- * creates a new colormap, in order to make sure that colormap
- * information is propagated to the window manager by default.
- *
- * Results:
- * None.
- *
- * Side effects:
- * WinPtr's window gets added to the WM_COLORMAP_WINDOWS
- * property of its nearest top-level ancestor, unless the
- * colormaps have been set explicitly with the
- * "wm colormapwindows" command.
- *
- *----------------------------------------------------------------------
- */
- void
- TkWmAddToColormapWindows(
- TkWindow *winPtr) /* Window with a non-default colormap.
- * Should not be a top-level window. */
- {
- TkWindow *topPtr;
- TkWindow **oldPtr, **newPtr;
- int count, i;
- if (winPtr->window == None) {
- return;
- }
- for (topPtr = winPtr->parentPtr; ; topPtr = topPtr->parentPtr) {
- if (topPtr == NULL) {
- /*
- * Window is being deleted. Skip the whole operation.
- */
- return;
- }
- if (topPtr->flags & TK_TOP_LEVEL) {
- break;
- }
- }
- if (topPtr->wmInfoPtr->flags & WM_COLORMAPS_EXPLICIT) {
- return;
- }
- /*
- * Make sure that the window isn't already in the list.
- */
- count = topPtr->wmInfoPtr->cmapCount;
- oldPtr = topPtr->wmInfoPtr->cmapList;
- for (i = 0; i < count; i++) {
- if (oldPtr[i] == winPtr) {
- return;
- }
- }
- /*
- * Make a new bigger array and use it to reset the property.
- * Automatically add the toplevel itself as the last element
- * of the list.
- */
- newPtr = (TkWindow **) ckalloc((unsigned) ((count+2)*sizeof(TkWindow*)));
- if (count > 0) {
- memcpy(newPtr, oldPtr, count * sizeof(TkWindow*));
- }
- if (count == 0) {
- count++;
- }
- newPtr[count-1] = winPtr;
- newPtr[count] = topPtr;
- if (oldPtr != NULL) {
- ckfree((char *) oldPtr);
- }
- topPtr->wmInfoPtr->cmapList = newPtr;
- topPtr->wmInfoPtr->cmapCount = count+1;
- /*
- * On the Macintosh all of this is just an excercise
- * in compatability as we don't support colormaps. If
- * we did they would be installed here.
- */
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkWmRemoveFromColormapWindows --
- *
- * This procedure is called to remove a given window from the
- * WM_COLORMAP_WINDOWS property for its top-level. It is invoked
- * when windows are deleted.
- *
- * Results:
- * None.
- *
- * Side effects:
- * WinPtr's window gets removed from the WM_COLORMAP_WINDOWS
- * property of its nearest top-level ancestor, unless the
- * top-level itself is being deleted too.
- *
- *----------------------------------------------------------------------
- */
- void
- TkWmRemoveFromColormapWindows(
- TkWindow *winPtr) /* Window that may be present in
- * WM_COLORMAP_WINDOWS property for its
- * top-level. Should not be a top-level
- * window. */
- {
- TkWindow *topPtr, **oldPtr;
- int count, i, j;
- for (topPtr = winPtr->parentPtr; ; topPtr = topPtr->parentPtr) {
- if (topPtr == NULL) {
- /*
- * Ancestors have been deleted, so skip the whole operation.
- * Seems like this can't ever happen?
- */
- return;
- }
- if (topPtr->flags & TK_TOP_LEVEL) {
- break;
- }
- }
- if (topPtr->flags & TK_ALREADY_DEAD) {
- /*
- * Top-level is being deleted, so there's no need to cleanup
- * the WM_COLORMAP_WINDOWS property.
- */
- return;
- }
- /*
- * Find the window and slide the following ones down to cover
- * it up.
- */
- count = topPtr->wmInfoPtr->cmapCount;
- oldPtr = topPtr->wmInfoPtr->cmapList;
- for (i = 0; i < count; i++) {
- if (oldPtr[i] == winPtr) {
- for (j = i ; j < count-1; j++) {
- oldPtr[j] = oldPtr[j+1];
- }
- topPtr->wmInfoPtr->cmapCount = count - 1;
- break;
- }
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkGetPointerCoords --
- *
- * Fetch the position of the mouse pointer.
- *
- * Results:
- * *xPtr and *yPtr are filled in with the (virtual) root coordinates
- * of the mouse pointer for tkwin's display. If the pointer isn't
- * on tkwin's screen, then -1 values are returned for both
- * coordinates. The argument tkwin must be a toplevel window.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- void
- TkGetPointerCoords(
- Tk_Window tkwin, /* Toplevel window that identifies screen
- * on which lookup is to be done. */
- int *xPtr, int *yPtr) /* Store pointer coordinates here. */
- {
- XQueryPointer(NULL, None, NULL, NULL, xPtr, yPtr, NULL, NULL, NULL);
- }
- /*
- *----------------------------------------------------------------------
- *
- * InitialWindowBounds --
- *
- * This function calculates the initial bounds for a new Mac
- * toplevel window. Unless the geometry is specified by the user
- * this code will auto place the windows in a cascade diagonially
- * across the main monitor of the Mac.
- *
- * Results:
- * The bounds are returned in geometry.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- static void
- InitialWindowBounds(
- TkWindow *winPtr, /* Window to get initial bounds for. */
- WindowRef macWindow,
- Rect *geometry) /* On return the initial bounds. */
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- if (!(wmPtr->sizeHintsFlags & (USPosition | PPosition))) {
- WindowRef parent;
- parent = GetFrontWindowOfClass(wmPtr->macClass, false);
- if (parent && parent == macWindow) {
- parent = GetNextWindowOfClass(parent, wmPtr->macClass, false);
- }
- if (parent && parent != macWindow) {
- Rect bounds;
- ChkErr(RepositionWindow, macWindow, parent,
- kWindowCascadeOnParentWindowScreen);
- ChkErr(GetWindowBounds, macWindow, kWindowStructureRgn, &bounds);
- wmPtr->x = bounds.left;
- wmPtr->y = bounds.top;
- } else {
- static SInt16 menuBarHeight = 0;
- if (!menuBarHeight) {
- ChkErr(GetThemeMenuBarHeight, &menuBarHeight);
- }
- wmPtr->x = 5;
- wmPtr->y = menuBarHeight + 5;
- }
- }
- geometry->left = wmPtr->x;
- geometry->top = wmPtr->y;
- geometry->right = wmPtr->x + winPtr->changes.width;
- geometry->bottom = wmPtr->y + winPtr->changes.height;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXResizable --
- *
- * This function determines if the passed in window is part of
- * a toplevel window that is resizable. If the window is
- * resizable in the x, y or both directions, true is returned.
- *
- * Results:
- * True if resizable, false otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- int
- TkMacOSXResizable(
- TkWindow *winPtr) /* Tk window or NULL. */
- {
- WmInfo *wmPtr;
- if (winPtr == NULL) {
- return false;
- }
- while (winPtr->wmInfoPtr == NULL) {
- winPtr = winPtr->parentPtr;
- }
- wmPtr = winPtr->wmInfoPtr;
- if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
- (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
- return false;
- } else {
- return true;
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXGrowToplevel --
- *
- * The function is invoked when the user clicks in the grow region
- * of a Tk window. The function will handle the dragging
- * procedure and not return until completed. Finally, the function
- * may place information Tk's event queue is the window was resized.
- *
- * Results:
- * True if events were placed on event queue, false otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- int
- TkMacOSXGrowToplevel(
- WindowRef whichWindow,
- Point start)
- {
- Point where = start;
- TkDisplay *dispPtr;
- Rect portRect;
- CGrafPtr destPort = GetWindowPort(whichWindow);
- QDGlobalToLocalPoint(destPort, &where);
- GetPortBounds(destPort, &portRect);
- if (where.h > (portRect.right - 16) &&
- where.v > (portRect.bottom - 16)) {
- Window window;
- TkWindow *winPtr;
- WmInfo *wmPtr;
- int minWidth, minHeight, maxWidth, maxHeight;
- Rect limits, bounds, *maxBounds;
- Boolean resizeResult;
- window = TkMacOSXGetXWindow(whichWindow);
- dispPtr = TkGetDisplayList();
- winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window);
- wmPtr = winPtr->wmInfoPtr;
- maxBounds = (Rect*)(dispPtr->display->screens->ext_data);
- if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
- (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
- return false;
- }
- GetMinSize(winPtr, &minWidth, &minHeight);
- GetMaxSize(winPtr, &maxWidth, &maxHeight);
- if (wmPtr->gridWin != NULL) {
- int base = winPtr->reqWidth - (wmPtr->reqGridWidth
- * wmPtr->widthInc);
- if (base < 0) {
- base = 0;
- }
- limits.left = base + (minWidth * wmPtr->widthInc);
- limits.right = base + (maxWidth * wmPtr->widthInc);
- base = winPtr->reqHeight - (wmPtr->reqGridHeight
- * wmPtr->heightInc);
- if (base < 0) {
- base = 0;
- }
- limits.top = base + (minHeight * wmPtr->heightInc);
- limits.bottom = base + (maxHeight * wmPtr->heightInc);
- } else {
- limits.left = minWidth;
- limits.right = maxWidth;
- limits.top = minHeight;
- limits.bottom = maxHeight;
- }
- if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) {
- limits.left = limits.right = winPtr->changes.width;
- }
- if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
- limits.top = limits.bottom = winPtr->changes.height;
- }
- if (PtInRect(start, maxBounds)) {
- Rect strBounds, strWidths, limitBounds;
- ChkErr(GetWindowBounds, whichWindow, kWindowStructureRgn,
- &strBounds);
- ChkErr(GetWindowStructureWidths, whichWindow, &strWidths);
- limitBounds.left = limits.left + (strBounds.left + strWidths.left);
- limitBounds.right = limits.right +
- (strBounds.left + strWidths.left + strWidths.right);
- limitBounds.top = limits.top + (strBounds.top + strWidths.top);
- limitBounds.bottom = limits.bottom +
- (strBounds.top + strWidths.top + strWidths.bottom);
- if (limitBounds.left < maxBounds->left) {
- limitBounds.left = maxBounds->left;
- }
- if (limitBounds.right > maxBounds->right) {
- limitBounds.right = maxBounds->right;
- }
- if (limitBounds.top < maxBounds->top) {
- limitBounds.top = maxBounds->top;
- }
- if (limitBounds.bottom > maxBounds->bottom) {
- limitBounds.bottom = maxBounds->bottom;
- }
- limits.left = limitBounds.left - (strBounds.left + strWidths.left);
- limits.right = limitBounds.right -
- (strBounds.left + strWidths.left + strWidths.right);
- limits.top = limitBounds.top - (strBounds.top + strWidths.top);
- limits.bottom = limitBounds.bottom -
- (strBounds.top + strWidths.top + strWidths.bottom);
- }
- TkMacOSXTrackingLoop(1);
- resizeResult = ResizeWindow(whichWindow, start, &limits, &bounds);
- TkMacOSXTrackingLoop(0);
- if (resizeResult) {
- return true;
- }
- }
- return false;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkSetWMName --
- *
- * Set the title for a toplevel window. If the window is embedded,
- * do not change the window title.
- *
- * Results:
- * None.
- *
- * Side effects:
- * The title of the window is changed.
- *
- *----------------------------------------------------------------------
- */
- void
- TkSetWMName(
- TkWindow *winPtr,
- Tk_Uid titleUid)
- {
- CFStringRef title;
- if (Tk_IsEmbedded(winPtr)) {
- return;
- }
- title = CFStringCreateWithBytes(NULL, (const unsigned char*) titleUid,
- strlen(titleUid), kCFStringEncodingUTF8, false);
- if (title) {
- WindowRef macWin = TkMacOSXDrawableWindow(winPtr->window);
- SetWindowTitleWithCFString(macWin, title);
- CFRelease(title);
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkGetTransientMaster --
- *
- * If the passed window has the TRANSIENT_FOR property set this
- * will return the master window. Otherwise it will return None.
- *
- * Results:
- * The master window or None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- Window
- TkGetTransientMaster(
- TkWindow *winPtr)
- {
- if (winPtr->wmInfoPtr != NULL) {
- return winPtr->wmInfoPtr->master;
- }
- return None;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXGetXWindow --
- *
- * Returns the X window Id associated with the given WindowRef.
- *
- * Results:
- * The window id is returned. None is returned if not a Tk window.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- Window
- TkMacOSXGetXWindow(
- WindowRef macWinPtr)
- {
- Tcl_HashEntry *hPtr;
- if ((macWinPtr == NULL) || !windowHashInit) {
- return None;
- }
- hPtr = Tcl_FindHashEntry(&windowTable, (char *) macWinPtr);
- if (hPtr == NULL) {
- return None;
- }
- return (Window) Tcl_GetHashValue(hPtr);
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXIsWindowZoomed --
- *
- * Ask Carbon if the given window is in the zoomed out state.
- * Because dragging & growing a window can change the Carbon
- * zoom state, we cannot rely on wmInfoPtr->hints.initial_state
- * for this information.
- *
- * Results:
- * True if window is zoomed out, false otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- MODULE_SCOPE int
- TkMacOSXIsWindowZoomed(
- TkWindow *winPtr)
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- int maxWidth, maxHeight;
- Point idealSize;
- if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
- (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
- return false;
- }
- GetMaxSize(winPtr, &maxWidth, &maxHeight);
- if (wmPtr->gridWin != NULL) {
- int base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc);
- if (base < 0) {
- base = 0;
- }
- maxWidth = base + (maxWidth * wmPtr->widthInc);
- base = winPtr->reqHeight - (wmPtr->reqGridHeight * wmPtr->heightInc);
- if (base < 0) {
- base = 0;
- }
- maxHeight = base + (maxHeight * wmPtr->heightInc);
- }
- if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) {
- idealSize.h = winPtr->changes.width;
- } else {
- idealSize.h = maxWidth;
- }
- if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
- idealSize.v = winPtr->changes.height;
- } else {
- idealSize.v = maxHeight;
- }
- return IsWindowInStandardState(TkMacOSXDrawableWindow(winPtr->window),
- &idealSize, NULL);
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXZoomToplevel --
- *
- * The function is invoked when the user clicks in the zoom region
- * of a Tk window or when the window state is set/unset to "zoomed"
- * manually. If the window is to be zoomed (in or out), the window
- * size is changed and events are generated to let Tk know what
- * happened.
- *
- * Results:
- * True if events were placed on event queue, false otherwise.
- *
- * Side effects:
- * The window may be resized & events placed on Tk's queue.
- *
- *----------------------------------------------------------------------
- */
- int
- TkMacOSXZoomToplevel(
- WindowRef whichWindow, /* The Macintosh window to zoom. */
- short zoomPart) /* Either inZoomIn or inZoomOut */
- {
- Window window;
- TkDisplay *dispPtr;
- TkWindow *winPtr;
- WmInfo *wmPtr;
- Point idealSize;
- int maxWidth, maxHeight;
- OSStatus err;
- window = TkMacOSXGetXWindow(whichWindow);
- dispPtr = TkGetDisplayList();
- winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window);
- wmPtr = winPtr->wmInfoPtr;
- if ((wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) &&
- (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE)) {
- return false;
- }
- GetMaxSize(winPtr, &maxWidth, &maxHeight);
- if (wmPtr->gridWin != NULL) {
- int base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc);
- if (base < 0) {
- base = 0;
- }
- maxWidth = base + (maxWidth * wmPtr->widthInc);
- base = winPtr->reqHeight - (wmPtr->reqGridHeight * wmPtr->heightInc);
- if (base < 0) {
- base = 0;
- }
- maxHeight = base + (maxHeight * wmPtr->heightInc);
- }
- if (wmPtr->flags & WM_WIDTH_NOT_RESIZABLE) {
- idealSize.h = winPtr->changes.width;
- } else {
- idealSize.h = maxWidth;
- }
- if (wmPtr->flags & WM_HEIGHT_NOT_RESIZABLE) {
- idealSize.v = winPtr->changes.height;
- } else {
- idealSize.v = maxHeight;
- }
- /* Do nothing if already in desired zoom state */
- if (!IsWindowInStandardState(whichWindow, &idealSize, NULL) ==
- (zoomPart == inZoomIn)) {
- return false;
- }
- err = ChkErr(ZoomWindowIdeal, whichWindow, zoomPart, &idealSize);
- if (err == noErr) {
- wmPtr->hints.initial_state =
- (zoomPart == inZoomIn ? NormalState : ZoomState);
- return true;
- } else {
- return false;
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkUnsupported1Cmd --
- *
- * This procedure is invoked to process the
- * "::tk::unsupported::MacWindowStyle" Tcl command.
- * This command allows you to set the style of decoration
- * for a Macintosh window.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * Changes the style of a new Mac window.
- *
- *----------------------------------------------------------------------
- */
- /* ARGSUSED */
- int
- TkUnsupported1ObjCmd(
- ClientData clientData, /* Main window associated with
- * interpreter. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj * const objv[]) /* Argument objects. */
- {
- static const char *subcmds[] = {
- "style", NULL
- };
- enum SubCmds {
- TKMWS_STYLE
- };
- Tk_Window tkwin = (Tk_Window) clientData;
- TkWindow *winPtr;
- int index;
- if (objc < 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?");
- return TCL_ERROR;
- }
- winPtr = (TkWindow *) Tk_NameToWindow(interp,
- Tcl_GetString(objv[2]), tkwin);
- if (winPtr == NULL) {
- return TCL_ERROR;
- }
- if (!(winPtr->flags & TK_TOP_LEVEL)) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "window "", winPtr->pathName,
- "" isn't a top-level window", NULL);
- return TCL_ERROR;
- }
- if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option",
- 0, &index) != TCL_OK) {
- return TCL_ERROR;
- }
- if (((enum SubCmds) index) == TKMWS_STYLE) {
- if ((objc < 3) || (objc > 5)) {
- Tcl_WrongNumArgs(interp, 2, objv, "window ?class attributes?");
- return TCL_ERROR;
- }
- return WmWinStyle(interp, winPtr, objc, objv);
- }
- /* won't be reached */
- return TCL_ERROR;
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmWinStyle --
- *
- * This procedure is invoked to process the
- * "::tk::unsupported::MacWindowStyle style" subcommand.
- * This command allows you to set the style of decoration
- * for a Macintosh window.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * Changes the style of a new Mac window.
- *
- *----------------------------------------------------------------------
- */
- static int
- WmWinStyle(
- Tcl_Interp *interp, /* Current interpreter. */
- TkWindow *winPtr, /* Window to be manipulated. */
- int objc, /* Number of arguments. */
- Tcl_Obj * const objv[]) /* Argument objects. */
- {
- struct StrIntMap {
- const char *strValue;
- UInt32 intValue;
- };
- static const struct StrIntMap styleMap[] = {
- { "documentProc", documentProc },
- { "noGrowDocProc", documentProc },
- { "dBoxProc", dBoxProc },
- { "plainDBox", plainDBox },
- { "altDBoxProc", altDBoxProc },
- { "movableDBoxProc", movableDBoxProc },
- { "zoomDocProc", zoomDocProc },
- { "zoomNoGrow", zoomNoGrow },
- { "floatProc", floatGrowProc },
- { "floatGrowProc", floatGrowProc },
- { "floatZoomProc", floatZoomGrowProc },
- { "floatZoomGrowProc", floatZoomGrowProc },
- { "floatSideProc", floatSideGrowProc },
- { "floatSideGrowProc", floatSideGrowProc },
- { "floatSideZoomProc", floatSideZoomGrowProc },
- { "floatSideZoomGrowProc", floatSideZoomGrowProc },
- { NULL, 0 }
- };
- static const struct StrIntMap classMap[] = {
- { "alert", kAlertWindowClass },
- { "moveableAlert", kMovableAlertWindowClass },
- { "modal", kModalWindowClass },
- { "moveableModal", kMovableModalWindowClass },
- { "floating", kFloatingWindowClass },
- { "document", kDocumentWindowClass },
- { "utility", kUtilityWindowClass },
- { "help", kHelpWindowClass },
- { "sheet", kSheetWindowClass },
- { "toolbar", kToolbarWindowClass },
- { "plain", kPlainWindowClass },
- { "overlay", kOverlayWindowClass },
- { "sheetAlert", kSheetAlertWindowClass },
- { "altPlain", kAltPlainWindowClass },
- { "simple", kSimpleWindowClass },
- { "drawer", kDrawerWindowClass },
- { NULL, 0 }
- };
- static const struct StrIntMap compositeAttrMap[] = {
- { "none", kWindowNoAttributes },
- { "standardDocument", kWindowStandardDocumentAttributes },
- { "standardFloating", kWindowStandardFloatingAttributes },
- { "fullZoom", kWindowFullZoomAttribute },
- { NULL, 0 }
- };
- static const struct StrIntMap attrMap[] = {
- { "closeBox", kWindowCloseBoxAttribute },
- { "horizontalZoom", kWindowHorizontalZoomAttribute },
- { "verticalZoom", kWindowVerticalZoomAttribute },
- { "collapseBox", kWindowCollapseBoxAttribute },
- { "resizable", kWindowResizableAttribute },
- { "sideTitlebar", kWindowSideTitlebarAttribute },
- { "toolbarButton", kWindowToolbarButtonAttribute },
- { "unifiedTitleAndToolbar", kWindowUnifiedTitleAndToolbarAttribute },
- { "metal", kWindowMetalAttribute },
- { "noTitleBar", kWindowNoTitleBarAttribute },
- { "texturedSquareCorners", kWindowTexturedSquareCornersAttribute },
- { "metalNoContentSeparator", kWindowMetalNoContentSeparatorAttribute },
- { "doesNotCycle", kWindowDoesNotCycleAttribute },
- { "noUpdates", kWindowNoUpdatesAttribute },
- { "noActivates", kWindowNoActivatesAttribute },
- { "opaqueForEvents", kWindowOpaqueForEventsAttribute },
- { "noShadow", kWindowNoShadowAttribute },
- { "hideOnSuspend", kWindowHideOnSuspendAttribute },
- { "hideOnFullScreen", kWindowHideOnFullScreenAttribute },
- { "inWindowMenu", kWindowInWindowMenuAttribute },
- { "liveResize", kWindowLiveResizeAttribute },
- { "ignoreClicks", kWindowIgnoreClicksAttribute },
- { "noConstrain", kWindowNoConstrainAttribute },
- { NULL, 0 }
- };
- int index, i;
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- if (objc == 3) {
- if (wmPtr->style != -1) {
- for (i = 0; styleMap[i].strValue != NULL; i++) {
- if (wmPtr->style == (short)(styleMap[i].intValue)) {
- Tcl_SetObjResult(interp,
- Tcl_NewStringObj(styleMap[i].strValue, -1));
- return TCL_OK;
- }
- }
- Tcl_Panic("invalid style");
- } else {
- Tcl_Obj *attributeList, *newResult = NULL;
- WindowAttributes attributes;
- for (i = 0; classMap[i].strValue != NULL; i++) {
- if (wmPtr->macClass == classMap[i].intValue) {
- newResult = Tcl_NewStringObj(classMap[i].strValue, -1);
- break;
- }
- }
- if (newResult == NULL) {
- Tcl_Panic("invalid class");
- }
- attributeList = Tcl_NewListObj(0, NULL);
- attributes = wmPtr->attributes;
- for (i = 0; compositeAttrMap[i].strValue != NULL; i++) {
- UInt32 intValue = compositeAttrMap[i].intValue;
- if (intValue && (attributes & intValue) == intValue) {
- Tcl_ListObjAppendElement(interp, attributeList,
- Tcl_NewStringObj(compositeAttrMap[i].strValue,
- -1));
- attributes &= ~intValue;
- break;
- }
- }
- for (i = 0; attrMap[i].strValue != NULL; i++) {
- if (attributes & attrMap[i].intValue) {
- Tcl_ListObjAppendElement(interp, attributeList,
- Tcl_NewStringObj(attrMap[i].strValue, -1));
- }
- }
- Tcl_ListObjAppendElement(interp, newResult, attributeList);
- Tcl_SetObjResult(interp, newResult);
- }
- } else if (objc == 4) {
- if (Tcl_GetIndexFromObjStruct(interp, objv[3], styleMap,
- sizeof(struct StrIntMap), "style", 0, &index) != TCL_OK) {
- return TCL_ERROR;
- }
- wmPtr->style = styleMap[index].intValue;
- } else if (objc == 5) {
- int attrObjc;
- Tcl_Obj **attrObjv = NULL;
- WindowClass oldClass = wmPtr->macClass;
- WindowAttributes oldAttributes = wmPtr->attributes;
- if (Tcl_GetIndexFromObjStruct(interp, objv[3], classMap,
- sizeof(struct StrIntMap), "class", 0, &index) != TCL_OK) {
- goto badClassAttrs;
- }
- wmPtr->macClass = classMap[index].intValue;
- if (!IsValidWindowClass(wmPtr->macClass)) {
- goto badClassAttrs;
- }
- if (Tcl_ListObjGetElements(interp, objv[4], &attrObjc, &attrObjv)
- != TCL_OK) {
- goto badClassAttrs;
- }
- wmPtr->attributes = kWindowNoAttributes;
- for (i = 0; i < attrObjc; i++) {
- if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i],
- compositeAttrMap, sizeof(struct StrIntMap),
- "attribute", 0, &index) == TCL_OK) {
- wmPtr->attributes |= compositeAttrMap[index].intValue;
- } else if (Tcl_GetIndexFromObjStruct(interp, attrObjv[i],
- attrMap, sizeof(struct StrIntMap),
- "attribute", 0, &index) == TCL_OK) {
- Tcl_ResetResult(interp);
- wmPtr->attributes |= attrMap[index].intValue;
- } else {
- goto badClassAttrs;
- }
- }
- ApplyWindowClassAttributeChanges(winPtr, NULL, oldClass, oldAttributes,
- 0);
- wmPtr->style = -1;
- return TCL_OK;
- badClassAttrs:
- wmPtr->macClass = oldClass;
- wmPtr->attributes = oldAttributes;
- return TCL_ERROR;
- }
- return TCL_OK;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkpMakeMenuWindow --
- *
- * Configure the window to be either a undecorated pull-down
- * (or pop-up) menu, or as a toplevel floating menu (palette).
- *
- * Results:
- * None.
- *
- * Side effects:
- * Changes the style bit used to create a new Mac toplevel.
- *
- *----------------------------------------------------------------------
- */
- void
- TkpMakeMenuWindow(
- Tk_Window tkwin, /* New window. */
- int transient) /* 1 means menu is only posted briefly as
- * a popup or pulldown or cascade. 0 means
- * menu is always visible, e.g. as a
- * floating menu. */
- {
- TkWindow *winPtr = (TkWindow *) tkwin;
- if (transient) {
- winPtr->wmInfoPtr->macClass = kSimpleWindowClass;
- winPtr->wmInfoPtr->attributes = kWindowNoActivatesAttribute;
- } else {
- winPtr->wmInfoPtr->macClass = kFloatingWindowClass;
- winPtr->wmInfoPtr->attributes = kWindowStandardFloatingAttributes;
- winPtr->wmInfoPtr->flags |= WM_WIDTH_NOT_RESIZABLE;
- winPtr->wmInfoPtr->flags |= WM_HEIGHT_NOT_RESIZABLE;
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXMakeRealWindowExist --
- *
- * This function finally creates the real Macintosh window that
- * the Mac actually understands.
- *
- * Results:
- * None.
- *
- * Side effects:
- * A new Macintosh toplevel is created.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacOSXMakeRealWindowExist(
- TkWindow *winPtr) /* Tk window. */
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- WindowRef newWindow = NULL;
- ControlRef rootControl = NULL;
- MacDrawable *macWin;
- Rect initialBounds = {42, 0, 43, 1}, geometry, strWidths;
- short structureW, structureH;
- TkMacOSXWindowList *listPtr;
- OSStatus err;
- if (TkMacOSXHostToplevelExists(winPtr)) {
- return;
- }
- macWin = (MacDrawable *) winPtr->window;
- /*
- * If this is embedded, make sure its container's toplevel exists,
- * then return...
- */
- if (Tk_IsEmbedded(winPtr)) {
- TkWindow *contWinPtr = TkpGetOtherWindow(winPtr);
- if (contWinPtr != NULL) {
- TkMacOSXMakeRealWindowExist(
- contWinPtr->privatePtr->toplevel->winPtr);
- macWin->flags |= TK_HOST_EXISTS;
- return;
- }
- if (tkMacOSXEmbedHandler == NULL) {
- Tcl_Panic("TkMacOSXMakeRealWindowExist could not find container");
- }
- if (tkMacOSXEmbedHandler->containerExistProc &&
- tkMacOSXEmbedHandler->containerExistProc((Tk_Window) winPtr) !=
- TCL_OK) {
- Tcl_Panic("ContainerExistProc could not make container");
- }
- return;
- /*
- * TODO: Here we should handle out of process embedding.
- */
- }
- if (wmPtr->style == -1) {
- if (!IsValidWindowClass(wmPtr->macClass)) {
- TkMacOSXDbgMsg("Invalid window class: %ld", wmPtr->macClass);
- wmPtr->macClass = kPlainWindowClass;
- }
- wmPtr->attributes = (wmPtr->attributes | kWindowAsyncDragAttribute) &
- GetAvailableWindowAttributes(wmPtr->macClass);
- err = ChkErr(CreateNewWindow, wmPtr->macClass, wmPtr->attributes,
- &initialBounds, &newWindow);
- if (err != noErr) {
- newWindow = NULL;
- }
- } else {
- TkMacOSXDbgMsg("Window creation via NewCWindow API is deprecated, "
- "use a window class instead of style %d", wmPtr->style);
- newWindow = NewCWindow(NULL, &initialBounds, "p", false,
- wmPtr->style, (WindowRef) -1, true, 0);
- }
- if (newWindow == NULL) {
- Tcl_Panic("couldn't allocate new Mac window");
- }
- ChkErr(GetWindowStructureWidths, newWindow, &strWidths);
- if (wmPtr->macClass == kFloatingWindowClass) {
- /*
- * Workaround GetWindowStructureWidths() Carbon bug:
- */
-
- strWidths.top = 16;
- }
- wmPtr->xInParent = strWidths.left;
- wmPtr->yInParent = strWidths.top;
- structureW = strWidths.left + strWidths.right;
- structureH = strWidths.top + strWidths.bottom;
- wmPtr->parentWidth = winPtr->changes.width + structureW;
- wmPtr->parentHeight = winPtr->changes.height + structureH;
- InitialWindowBounds(winPtr, newWindow, &geometry);
- geometry.right += structureW;
- geometry.bottom += structureH;
- ChkErr(SetWindowBounds, newWindow, kWindowStructureRgn, &geometry);
- TkMacOSXInstallWindowCarbonEventHandler(NULL, newWindow);
- if (ChkErr(CreateRootControl, newWindow, &rootControl) != noErr ) {
- Tcl_Panic("couldn't create root control for new Mac window");
- }
- if (wmPtr->attributes & kWindowResizableAttribute) {
- HIViewRef growBoxView;
- err = HIViewFindByID(HIViewGetRoot(newWindow),
- kHIViewWindowGrowBoxID, &growBoxView);
- if (err == noErr && !HIGrowBoxViewIsTransparent(growBoxView)) {
- ChkErr(HIGrowBoxViewSetTransparent, growBoxView, true);
- }
- }
- /*
- * Add this window to the list of toplevel windows.
- */
- listPtr = (TkMacOSXWindowList *) ckalloc(sizeof(TkMacOSXWindowList));
- listPtr->nextPtr = tkMacOSXWindowListPtr;
- listPtr->winPtr = winPtr;
- tkMacOSXWindowListPtr = listPtr;
- macWin->grafPtr = GetWindowPort(newWindow);
- macWin->rootControl = rootControl;
- if (wmPtr->master != None || winPtr->atts.override_redirect) {
- ApplyMasterOverrideChanges(winPtr, newWindow);
- }
- SetWindowModified(newWindow, false);
- TkMacOSXRegisterOffScreenWindow((Window) macWin, (GWorldPtr) newWindow);
- macWin->flags |= TK_HOST_EXISTS;
- ChkErr(GetWindowClass, newWindow, &(wmPtr->macClass));
- ChkErr(GetWindowAttributes, newWindow, &(wmPtr->attributes));
- #ifdef TK_MAC_DEBUG_WINDOWS
- TkMacOSXInitNamedDebugSymbol(HIToolbox, void, DebugPrintWindow, WindowRef);
- if (DebugPrintWindow) {
- DebugPrintWindow(newWindow);
- }
- #endif /* TK_MAC_DEBUG_WINDOWS */
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXRegisterOffScreenWindow --
- *
- * This function adds the passed in Off Screen Port to the
- * hash table that maps Mac windows to root X windows.
- *
- * Results:
- * None.
- *
- * Side effects:
- * An entry is added to the windowTable hash table.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacOSXRegisterOffScreenWindow(
- Window window, /* Window structure. */
- GWorldPtr portPtr) /* Pointer to a Mac GWorld. */
- {
- Tcl_HashEntry *valueHashPtr;
- int isNew;
- if (!windowHashInit) {
- Tcl_InitHashTable(&windowTable, TCL_ONE_WORD_KEYS);
- windowHashInit = true;
- }
- valueHashPtr = Tcl_CreateHashEntry(&windowTable, (char *) portPtr, &isNew);
- if (!isNew) {
- Tcl_Panic("Same macintosh window allocated twice!");
- }
- Tcl_SetHashValue(valueHashPtr, window);
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXUnregisterMacWindow --
- *
- * Given a macintosh port window, this function removes the
- * association between this window and the root X window that
- * Tk cares about.
- *
- * Results:
- * None.
- *
- * Side effects:
- * An entry is removed from the windowTable hash table.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacOSXUnregisterMacWindow(
- WindowRef macWinPtr) /* Reference to a Mac Window */
- {
- Tcl_HashEntry *entryPtr;
- if (!windowHashInit) {
- Tcl_Panic("TkMacOSXUnregisterMacWindow: unmapping before inited");
- }
- entryPtr = Tcl_FindHashEntry(&windowTable,(char *) macWinPtr);
- if (!entryPtr) {
- TkMacOSXDbgMsg("Failed to find window %08x", (int) macWinPtr);
- } else {
- Tcl_DeleteHashEntry(entryPtr);
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXSetScrollbarGrow --
- *
- * Sets a flag for a toplevel window indicating that the passed
- * Tk scrollbar window will display the grow region for the
- * toplevel window.
- *
- * Results:
- * None.
- *
- * Side effects:
- * A flag is set int windows toplevel parent.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacOSXSetScrollbarGrow(
- TkWindow *winPtr, /* Tk scrollbar window. */
- int flag) /* Boolean value true or false. */
- {
- if (flag) {
- winPtr->privatePtr->toplevel->flags |= TK_SCROLLBAR_GROW;
- winPtr->privatePtr->toplevel->winPtr->wmInfoPtr->scrollWinPtr = winPtr;
- } else if (winPtr->privatePtr->toplevel->winPtr->wmInfoPtr->scrollWinPtr
- == winPtr) {
- winPtr->privatePtr->toplevel->flags &= ~TK_SCROLLBAR_GROW;
- winPtr->privatePtr->toplevel->winPtr->wmInfoPtr->scrollWinPtr = NULL;
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkWmFocusToplevel --
- *
- * This is a utility procedure invoked by focus-management code. It
- * exists because of the extra wrapper windows that exist under
- * Unix; its job is to map from wrapper windows to the
- * corresponding toplevel windows. On PCs and Macs there are no
- * wrapper windows so no mapping is necessary; this procedure just
- * determines whether a window is a toplevel or not.
- *
- * Results:
- * If winPtr is a toplevel window, returns the pointer to the
- * window; otherwise returns NULL.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- TkWindow *
- TkWmFocusToplevel(
- TkWindow *winPtr) /* Window that received a focus-related
- * event. */
- {
- if (!(winPtr->flags & TK_TOP_LEVEL)) {
- return NULL;
- }
- return winPtr;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkpGetWrapperWindow --
- *
- * This is a utility procedure invoked by focus-management code. It
- * maps to the wrapper for a top-level, which is just the same
- * as the top-level on Macs and PCs.
- *
- * Results:
- * If winPtr is a toplevel window, returns the pointer to the
- * window; otherwise returns NULL.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- TkWindow *
- TkpGetWrapperWindow(
- TkWindow *winPtr) /* Window that received a focus-related
- * event. */
- {
- if (!(winPtr->flags & TK_TOP_LEVEL)) {
- return NULL;
- }
- return winPtr;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkpWmSetState --
- *
- * Sets the window manager state for the wrapper window of a
- * given toplevel window.
- *
- * Results:
- * None.
- *
- * Side effects:
- * May maximize, minimize, restore, or withdraw a window.
- *
- *----------------------------------------------------------------------
- */
- void
- TkpWmSetState(winPtr, state)
- TkWindow *winPtr; /* Toplevel window to operate on. */
- int state; /* One of IconicState, ZoomState, NormalState,
- * or WithdrawnState. */
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- WindowRef macWin;
- wmPtr->hints.initial_state = state;
- if (wmPtr->flags & WM_NEVER_MAPPED) {
- return;
- }
- macWin = TkMacOSXDrawableWindow(winPtr->window);
- if (state == WithdrawnState) {
- Tk_UnmapWindow((Tk_Window) winPtr);
- } else if (state == IconicState) {
- /*
- * The window always gets unmapped. If we can show the
- * icon version of the window we also collapse it.
- */
- if (IsWindowCollapsable(macWin) && !IsWindowCollapsed(macWin)) {
- CollapseWindow(macWin, true);
- }
- Tk_UnmapWindow((Tk_Window) winPtr);
- } else if (state == NormalState) {
- Tk_MapWindow((Tk_Window) winPtr);
- if (IsWindowCollapsable(macWin) && IsWindowCollapsed(macWin)) {
- CollapseWindow(macWin, false);
- }
- TkMacOSXZoomToplevel(macWin, inZoomIn);
- } else if (state == ZoomState) {
- Tk_MapWindow((Tk_Window) winPtr);
- if (IsWindowCollapsable(macWin) && IsWindowCollapsed(macWin)) {
- CollapseWindow(macWin, false);
- }
- TkMacOSXZoomToplevel(macWin, inZoomOut);
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkpIsWindowFloating --
- *
- * Returns 1 if a window is floating, 0 otherwise.
- *
- * Results:
- * 1 or 0 depending on window's floating attribute.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- int
- TkpIsWindowFloating(
- WindowRef wRef)
- {
- WindowClass class;
- if (wRef == NULL) {
- return 0;
- }
- GetWindowClass(wRef, &class);
- return (class == kFloatingWindowClass);
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXWindowClass --
- *
- * Returns OS X window class of window
- *
- * Results:
- * 1 or 0 depending on window's floating attribute.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- MODULE_SCOPE WindowClass
- TkMacOSXWindowClass(
- TkWindow *winPtr)
- {
- return winPtr->wmInfoPtr->macClass;
- }
- /*
- *--------------------------------------------------------------
- *
- * TkMacOSXWindowOffset --
- *
- * Determines the x and y offset from the orgin of the toplevel
- * window dressing (the structure region, ie. title bar) and the
- * orgin of the content area.
- *
- * Results:
- * The x & y offset in pixels.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacOSXWindowOffset(
- WindowRef wRef,
- int *xOffset,
- int *yOffset)
- {
- Window window;
- TkDisplay *dispPtr;
- TkWindow *winPtr;
- window = TkMacOSXGetXWindow(wRef);
- dispPtr = TkGetDisplayList();
- winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window);
- *xOffset = winPtr->wmInfoPtr->xInParent;
- *yOffset = winPtr->wmInfoPtr->yInParent;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkpGetMS --
- *
- * Return a relative time in milliseconds. It doesn't matter
- * when the epoch was.
- *
- * Results:
- * Number of milliseconds.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- unsigned long
- TkpGetMS(void)
- {
- Tcl_Time now;
- Tcl_GetTime(&now);
- return (long) now.sec * 1000 + now.usec / 1000;
- }
- /*
- *----------------------------------------------------------------------
- *
- * XSetInputFocus --
- *
- * Change the focus window for the application.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- void
- XSetInputFocus(
- Display* display,
- Window focus,
- int revert_to,
- Time time)
- {
- /*
- * Don't need to do a thing. Tk manages the focus for us.
- */
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkpChangeFocus --
- *
- * This procedure is a stub on the Mac because we always own the
- * focus if we are a front most application.
- *
- * Results:
- * The return value is the serial number of the command that
- * changed the focus. It may be needed by the caller to filter
- * out focus change events that were queued before the command.
- * If the procedure doesn't actually change the focus then
- * it returns 0.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- int
- TkpChangeFocus(winPtr, force)
- TkWindow *winPtr; /* Window that is to receive the X focus. */
- int force; /* Non-zero means claim the focus even
- * if it didn't originally belong to
- * topLevelPtr's application. */
- {
- /*
- * We don't really need to do anything on the Mac. Tk will
- * keep all this state for us.
- */
- if (winPtr->atts.override_redirect) {
- return 0;
- }
- /*
- * Remember the current serial number for the X server and issue
- * a dummy server request. This marks the position at which we
- * changed the focus, so we can distinguish FocusIn and FocusOut
- * events on either side of the mark.
- */
- return NextRequest(winPtr->display);
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmStackorderToplevelWrapperMap --
- *
- * This procedure will create a table that maps the reparent wrapper
- * X id for a toplevel to the TkWindow structure that is wraps.
- * Tk keeps track of a mapping from the window X id to the TkWindow
- * structure but that does us no good here since we only get the X
- * id of the wrapper window. Only those toplevel windows that are
- * mapped have a position in the stacking order.
- *
- *
- * Results:
- * None.
- *
- * Side effects:
- * Adds entries to the passed hashtable.
- *
- *----------------------------------------------------------------------
- */
- static void
- WmStackorderToplevelWrapperMap(
- TkWindow *winPtr, /* TkWindow to recurse on */
- Display *display, /* X display of parent window */
- Tcl_HashTable *table) /* Maps mac window to TkWindow */
- {
- TkWindow *childPtr;
- Tcl_HashEntry *hPtr;
- WindowRef macWindow;
- int newEntry;
- if (Tk_IsMapped(winPtr) && Tk_IsTopLevel(winPtr)
- && (winPtr->display == display)) {
- macWindow = TkMacOSXDrawableWindow(winPtr->window);
- hPtr = Tcl_CreateHashEntry(table,
- (const char *) macWindow, &newEntry);
- Tcl_SetHashValue(hPtr, winPtr);
- }
- for (childPtr = winPtr->childList; childPtr != NULL;
- childPtr = childPtr->nextPtr) {
- WmStackorderToplevelWrapperMap(childPtr, display, table);
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkWmStackorderToplevel --
- *
- * This procedure returns the stack order of toplevel windows.
- *
- * Results:
- * An array of pointers to tk window objects in stacking order
- * or else NULL if there was an error.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- TkWindow **
- TkWmStackorderToplevel(parentPtr)
- TkWindow *parentPtr; /* Parent toplevel window. */
- {
- WindowRef frontWindow;
- TkWindow *childWinPtr, **windows, **window_ptr;
- Tcl_HashTable table;
- Tcl_HashEntry *hPtr;
- Tcl_HashSearch search;
- /*
- * Map mac windows to a TkWindow of the wrapped toplevel.
- */
- Tcl_InitHashTable(&table, TCL_ONE_WORD_KEYS);
- WmStackorderToplevelWrapperMap(parentPtr, parentPtr->display, &table);
- windows = (TkWindow **) ckalloc((table.numEntries+1)
- * sizeof(TkWindow *));
- /*
- * Special cases: If zero or one toplevels were mapped
- * there is no need to enumerate Windows.
- */
- switch (table.numEntries) {
- case 0:
- windows[0] = NULL;
- goto done;
- case 1:
- hPtr = Tcl_FirstHashEntry(&table, &search);
- windows[0] = (TkWindow *) Tcl_GetHashValue(hPtr);
- windows[1] = NULL;
- goto done;
- }
- frontWindow = GetFrontWindowOfClass(kAllWindowClasses, false);
- if (frontWindow == NULL) {
- ckfree((char *) windows);
- windows = NULL;
- } else {
- window_ptr = windows + table.numEntries;
- *window_ptr-- = NULL;
- while (frontWindow != NULL) {
- hPtr = Tcl_FindHashEntry(&table, (char *) frontWindow);
- if (hPtr != NULL) {
- childWinPtr = (TkWindow *) Tcl_GetHashValue(hPtr);
- *window_ptr-- = childWinPtr;
- }
- frontWindow = GetNextWindow(frontWindow);
- }
- if (window_ptr != (windows-1))
- Tcl_Panic("num matched toplevel windows does not equal num "
- "children");
- }
- done:
- Tcl_DeleteHashTable(&table);
- return windows;
- }
- /*
- *----------------------------------------------------------------------
- *
- * ApplyWindowClassAttributeChanges --
- *
- * This procedure applies carbon window class and attribute changes.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- static void
- ApplyWindowClassAttributeChanges(
- TkWindow *winPtr,
- WindowRef macWindow,
- WindowClass oldClass,
- WindowAttributes oldAttributes,
- int create)
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- WindowAttributes newAttributes = wmPtr->attributes |
- kWindowAsyncDragAttribute;
- if (wmPtr->macClass != oldClass || newAttributes != oldAttributes) {
- Rect strWidths;
- if (!macWindow) {
- if (winPtr->window == None) {
- if (create) {
- Tk_MakeWindowExist((Tk_Window) winPtr);
- } else {
- return;
- }
- }
- if (!TkMacOSXHostToplevelExists(winPtr)) {
- if (create) {
- TkMacOSXMakeRealWindowExist(winPtr);
- } else {
- return;
- }
- }
- macWindow = TkMacOSXDrawableWindow(winPtr->window);
- }
- if (wmPtr->macClass != oldClass) {
- TK_IF_MAC_OS_X_API (4, HIWindowChangeClass,
- ChkErr(HIWindowChangeClass, macWindow, wmPtr->macClass);
- ) TK_ENDIF
- ChkErr(GetWindowClass, macWindow, &(wmPtr->macClass));
- }
- if (newAttributes != oldAttributes) {
- newAttributes &= GetAvailableWindowAttributes(wmPtr->macClass);
- ChkErr(ChangeWindowAttributes, macWindow,
- newAttributes & (newAttributes ^ oldAttributes),
- oldAttributes & (newAttributes ^ oldAttributes));
- }
- ChkErr(GetWindowAttributes, macWindow, &(wmPtr->attributes));
- if ((wmPtr->attributes ^ oldAttributes) & kWindowResizableAttribute) {
- if (wmPtr->attributes & kWindowResizableAttribute) {
- HIViewRef growBoxView;
- OSStatus err = HIViewFindByID(HIViewGetRoot(macWindow),
- kHIViewWindowGrowBoxID, &growBoxView);
- if (err == noErr && !HIGrowBoxViewIsTransparent(growBoxView)) {
- ChkErr(HIGrowBoxViewSetTransparent, growBoxView, true);
- }
- }
- TkMacOSXInvalClipRgns((Tk_Window) winPtr);
- TkMacOSXInvalidateWindow((MacDrawable *)(winPtr->window),
- TK_PARENT_WINDOW);
- }
- /*
- * The change of window class/attributes might have changed the window
- * structure widths:
- */
- GetWindowStructureWidths(macWindow, &strWidths);
- wmPtr->xInParent = strWidths.left;
- wmPtr->yInParent = strWidths.top;
- wmPtr->parentWidth = winPtr->changes.width + strWidths.left
- + strWidths.right;
- wmPtr->parentHeight = winPtr->changes.height + strWidths.top
- + strWidths.bottom;
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * ApplyMasterOverrideChanges --
- *
- * This procedure applies changes to override_redirect or master.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- static void
- ApplyMasterOverrideChanges(
- TkWindow *winPtr,
- WindowRef macWindow)
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- WindowClass oldClass = wmPtr->macClass;
- WindowAttributes oldAttributes = wmPtr->attributes;
- /*
- * FIX: We need an UpdateWrapper equivalent to make this 100% correct
- */
- if (winPtr->atts.override_redirect) {
- if (oldClass == kDocumentWindowClass) {
- wmPtr->macClass = kSimpleWindowClass;
- wmPtr->attributes = kWindowNoAttributes;
- }
- wmPtr->attributes |= kWindowNoActivatesAttribute;
- } else {
- if (oldClass == kSimpleWindowClass &&
- oldAttributes == kWindowNoActivatesAttribute) {
- wmPtr->macClass = kDocumentWindowClass;
- wmPtr->attributes = kWindowStandardDocumentAttributes
- | kWindowLiveResizeAttribute;
- }
- wmPtr->attributes &= ~kWindowNoActivatesAttribute;
- }
- if (!macWindow && winPtr->window != None &&
- TkMacOSXHostToplevelExists(winPtr)) {
- macWindow = TkMacOSXDrawableWindow(winPtr->window);
- }
- if (macWindow) {
- WindowGroupRef group;
- ApplyWindowClassAttributeChanges(winPtr, macWindow, oldClass,
- oldAttributes, 0);
- if (winPtr->atts.override_redirect && wmPtr->master != None) {
- wmPtr->flags |= WM_TOPMOST;
- } else {
- wmPtr->flags &= ~WM_TOPMOST;
- }
- group = WmGetWindowGroup(winPtr);
- if (group && group != GetWindowGroup(macWindow)) {
- ChkErr(SetWindowGroup, macWindow, group);
- }
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * WmGetWindowGroup --
- *
- * Gets the window group a toplevel should be placed in.
- *
- * Results:
- * A WindowGroupRef.
- *
- * Side effects:
- * A transient window group for the master (if any) may be created.
- *
- *----------------------------------------------------------------------
- */
- static WindowGroupRef
- WmGetWindowGroup(
- TkWindow *winPtr)
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- WindowGroupRef group = NULL;
- if (wmPtr->flags & WM_TOPMOST) {
- group = GetWindowGroupOfClass(kUtilityWindowClass);
- } else if (wmPtr->master != None) {
- TkDisplay *dispPtr = TkGetDisplayList();
- TkWindow *masterWinPtr = (TkWindow *)Tk_IdToWindow(dispPtr->display,
- wmPtr->master);
-
- if (masterWinPtr && masterWinPtr->window != None &&
- TkMacOSXHostToplevelExists(masterWinPtr)) {
- WindowRef masterMacWin =
- TkMacOSXDrawableWindow(masterWinPtr->window);
- if (masterMacWin && GetWindowProperty(masterMacWin, 'Tk ', 'TsGp',
- sizeof(group), NULL, &group) != noErr) {
- ChkErr(CreateWindowGroup, 0, &group);
- if (group) {
- ChkErr(SetWindowGroupParent, group,
- GetWindowGroup(masterMacWin));
- ChkErr(SetWindowGroupOwner, group, masterMacWin);
- ChkErr(SetWindowProperty, masterMacWin, 'Tk ', 'TsGp',
- sizeof(group), &group);
- }
- }
- }
- }
- if (!group) {
- group = GetWindowGroupOfClass(wmPtr->macClass);
- }
- return group;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXMakeFullscreen --
- *
- * This procedure sets a fullscreen window to the size of the screen.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- int
- TkMacOSXMakeFullscreen(
- TkWindow *winPtr,
- WindowRef window,
- int fullscreen,
- Tcl_Interp *interp)
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- int result = TCL_OK, wasFullscreen = (wmPtr->flags & WM_FULLSCREEN);
- if (fullscreen) {
- int screenWidth = WidthOfScreen(Tk_Screen(winPtr));
- int screenHeight = HeightOfScreen(Tk_Screen(winPtr));
- /*
- * Check max width and height if set by the user.
- */
- if ((wmPtr->maxWidth > 0 && wmPtr->maxWidth < screenWidth)
- || (wmPtr->maxHeight > 0 && wmPtr->maxHeight < screenHeight)) {
- if (interp) {
- Tcl_AppendResult(interp,
- "can't set fullscreen attribute for "",
- winPtr->pathName,
- "": max width/height is too small", NULL);
- }
- result = TCL_ERROR;
- wmPtr->flags &= ~WM_FULLSCREEN;
- } else {
- Rect bounds, screenBounds = {0, 0, screenHeight, screenWidth};
- ChkErr(GetWindowBounds, window, kWindowContentRgn, &bounds);
- if (!EqualRect(&bounds, &screenBounds)) {
- if (!wasFullscreen) {
- wmPtr->configX = wmPtr->x;
- wmPtr->configY = wmPtr->y;
- wmPtr->configAttributes = wmPtr->attributes;
- wmPtr->attributes &= ~kWindowResizableAttribute;
- ApplyWindowClassAttributeChanges(winPtr, window,
- wmPtr->macClass, wmPtr->configAttributes, 0);
- }
- wmPtr->flags |= WM_SYNC_PENDING;
- ChkErr(SetWindowBounds, window, kWindowContentRgn,
- &screenBounds);
- wmPtr->flags &= ~WM_SYNC_PENDING;
- }
- wmPtr->flags |= WM_FULLSCREEN;
- }
- } else {
- wmPtr->flags &= ~WM_FULLSCREEN;
- }
- if (wasFullscreen && !(wmPtr->flags & WM_FULLSCREEN)) {
- WindowAttributes oldAttributes = wmPtr->attributes;
- Rect bounds = {wmPtr->configY, wmPtr->configX,
- wmPtr->configY + wmPtr->yInParent + wmPtr->configHeight,
- wmPtr->configX + wmPtr->xInParent + wmPtr->configWidth};
- wmPtr->attributes |= wmPtr->configAttributes &
- kWindowResizableAttribute;
- ApplyWindowClassAttributeChanges(winPtr, window, wmPtr->macClass,
- oldAttributes, 0);
- wmPtr->flags |= WM_SYNC_PENDING;
- ChkErr(SetWindowBounds, window, kWindowStructureRgn, &bounds);
- wmPtr->flags &= ~WM_SYNC_PENDING;
- }
- TkMacOSXEnterExitFullscreen(winPtr, IsWindowActive(window));
- return result;
- }
- /*
- *----------------------------------------------------------------------
- *
- * TkMacOSXEnterExitFullscreen --
- *
- * This procedure enters or exits fullscreen mode if required.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- void
- TkMacOSXEnterExitFullscreen(
- TkWindow *winPtr,
- int active)
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- SystemUIMode mode;
- SystemUIOptions options;
- GetSystemUIMode(&mode, &options);
- if (wmPtr->flags & WM_FULLSCREEN && active) {
- static SystemUIMode fullscreenMode = 0;
- static SystemUIOptions fullscreenOptions = 0;
- if (!fullscreenMode) {
- TK_IF_HI_TOOLBOX (3,
- fullscreenMode = kUIModeAllSuppressed;
- ) TK_ELSE_HI_TOOLBOX (3,
- fullscreenMode = kUIModeAllHidden;
- fullscreenOptions = kUIOptionAutoShowMenuBar;
- ) TK_ENDIF
- }
- if (mode != fullscreenMode) {
- ChkErr(SetSystemUIMode, fullscreenMode, fullscreenOptions);
- }
- } else {
- if (mode != kUIModeNormal) {
- ChkErr(SetSystemUIMode, kUIModeNormal, 0);
- }
- }
- }
- /*
- *----------------------------------------------------------------------
- *
- * GetMinSize --
- *
- * This function computes the current minWidth and minHeight values for
- * a window, taking into account the possibility that they may be
- * defaulted.
- *
- * Results:
- * The values at *minWidthPtr and *minHeightPtr are filled in with the
- * minimum allowable dimensions of wmPtr's window, in grid units. If the
- * requested minimum is smaller than the system required minimum, then
- * this function computes the smallest size that will satisfy both the
- * system and the grid constraints.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- static void
- GetMinSize(
- TkWindow *winPtr, /* Toplevel window to operate on. */
- int *minWidthPtr, /* Where to store the current minimum width of
- * the window. */
- int *minHeightPtr) /* Where to store the current minimum height
- * of the window. */
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- int minWidth = 1, minHeight = 1;
- /*
- * Compute the minimum width & height by taking the default client size and
- * rounding it up to the nearest grid unit. Return the greater of the
- * default minimum and the specified minimum.
- */
- switch (wmPtr->macClass) {
- case kDocumentWindowClass:
- case kMovableAlertWindowClass:
- case kMovableModalWindowClass:
- minWidth = 72;
- if (wmPtr->attributes & kWindowResizableAttribute) {
- minHeight = 15;
- }
- if (wmPtr->attributes & kWindowToolbarButtonAttribute) {
- minWidth += 29;
- }
- break;
- case kFloatingWindowClass:
- case kUtilityWindowClass:
- minWidth = 59;
- if (wmPtr->attributes & kWindowResizableAttribute) {
- minHeight = 11;
- }
- if (wmPtr->attributes & kWindowSideTitlebarAttribute) {
- int tmp = minWidth;
- minWidth = minHeight;
- minHeight = tmp;
- } else if (wmPtr->attributes & kWindowToolbarButtonAttribute) {
- minWidth += 29;
- }
- break;
- default:
- if (wmPtr->attributes & kWindowResizableAttribute) {
- minWidth = 15;
- minHeight = 15;
- }
- break;
- }
- if (wmPtr->gridWin != NULL) {
- int base = winPtr->reqWidth - (wmPtr->reqGridWidth * wmPtr->widthInc);
- if (base < 0) {
- base = 0;
- }
- minWidth = ((minWidth - base) + wmPtr->widthInc-1)/wmPtr->widthInc;
- base = winPtr->reqHeight - (wmPtr->reqGridHeight * wmPtr->heightInc);
- if (base < 0) {
- base = 0;
- }
- minHeight = ((minHeight - base) + wmPtr->heightInc-1)/wmPtr->heightInc;
- }
- if (minWidth < wmPtr->minWidth) {
- minWidth = wmPtr->minWidth;
- }
- if (minHeight < wmPtr->minHeight) {
- minHeight = wmPtr->minHeight;
- }
- *minWidthPtr = minWidth;
- *minHeightPtr = minHeight;
- }
- /*
- *----------------------------------------------------------------------
- *
- * GetMaxSize --
- *
- * This function computes the current maxWidth and maxHeight values for
- * a window, taking into account the possibility that they may be
- * defaulted.
- *
- * Results:
- * The values at *maxWidthPtr and *maxHeightPtr are filled in with the
- * maximum allowable dimensions of wmPtr's window, in grid units. If no
- * maximum has been specified for the window, then this function computes
- * the largest sizes that will fit on the screen.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
- static void
- GetMaxSize(
- TkWindow *winPtr, /* Toplevel window to operate on. */
- int *maxWidthPtr, /* Where to store the current maximum width of
- * the window. */
- int *maxHeightPtr) /* Where to store the current maximum height
- * of the window. */
- {
- WmInfo *wmPtr = winPtr->wmInfoPtr;
- Rect *maxBounds = (Rect*)(winPtr->display->screens->ext_data);
- if (wmPtr->maxWidth > 0) {
- *maxWidthPtr = wmPtr->maxWidth;
- } else {
- int maxWidth = maxBounds->right - maxBounds->left - wmPtr->xInParent;
- if (wmPtr->gridWin != NULL) {
- maxWidth = wmPtr->reqGridWidth
- + (maxWidth - winPtr->reqWidth)/wmPtr->widthInc;
- }
- *maxWidthPtr = maxWidth;
- }
- if (wmPtr->maxHeight > 0) {
- *maxHeightPtr = wmPtr->maxHeight;
- } else {
- int maxHeight = maxBounds->bottom - maxBounds->top - wmPtr->yInParent;
- if (wmPtr->gridWin != NULL) {
- maxHeight = wmPtr->reqGridHeight
- + (maxHeight - winPtr->reqHeight)/wmPtr->heightInc;
- }
- *maxHeightPtr = maxHeight;
- }
- }
- #if 0
- /*
- *----------------------------------------------------------------------
- *
- * RemapWindows
- *
- * Adjust parent/child relation ships of
- * the given window hierarchy.
- *
- * Results:
- * none
- *
- * Side effects:
- * keeps windowing system (X11) happy
- *
- *----------------------------------------------------------------------
- */
- static void
- RemapWindows(TkWindow *winPtr, MacDrawable *parentWin)
- {
- TkWindow *childPtr;
- /* Remove the OS specific window.
- * It will get rebuilt when the window gets Mapped.
- */
- if (winPtr->window != None) {
- MacDrawable *macWin = (MacDrawable *) winPtr->window;
- macWin->grafPtr = NULL;
- macWin->toplevel = parentWin->toplevel;
- winPtr->flags &= ~TK_MAPPED;
- #ifdef TK_REBUILD_TOPLEVEL
- winPtr->flags |= TK_REBUILD_TOPLEVEL;
- #endif
- }
- /* Repeat for all the children */
- for (childPtr = winPtr->childList; childPtr != NULL;
- childPtr = childPtr->nextPtr) {
- RemapWindows(childPtr, (MacDrawable *) winPtr->window);
- }
- }
- #endif