📄 tkmacsubwindows.c
字号:
/* * tkMacSubwindows.c -- * * Implements subwindows for the macintosh version of Tk. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * * SCCS: @(#) tkMacSubwindows.c 1.81 97/10/29 11:46:54 */#include "tkInt.h"#include "X.h"#include "Xlib.h"#include <stdio.h>#include <Windows.h>#include <QDOffscreen.h>#include "tkMacInt.h"/* * Temporary region that can be reused. */static RgnHandle tmpRgn = NULL;static void UpdateOffsets _ANSI_ARGS_((TkWindow *winPtr, int deltaX, int deltaY));void tkMacMoveWindow _ANSI_ARGS_((WindowRef window, int x, int y));/* *---------------------------------------------------------------------- * * XDestroyWindow -- * * Dealocates the given X Window. * * Results: * The window id is returned. * * Side effects: * None. * *---------------------------------------------------------------------- */void XDestroyWindow( Display* display, /* Display. */ Window window) /* Window. */{ MacDrawable *macWin = (MacDrawable *) window; GWorldPtr destPort; /* * Remove any dangling pointers that may exist if * the window we are deleting is being tracked by * the grab code. */ TkPointerDeadWindow(macWin->winPtr); macWin->toplevel->referenceCount--; if (Tk_IsTopLevel(macWin->winPtr)) { DisposeRgn(macWin->clipRgn); DisposeRgn(macWin->aboveClipRgn); /* * Delete the Mac window and remove it from the windowTable. * The window could be NULL if the window was never mapped. * However, we don't do this for embedded windows, they don't * go in the window list, and they do not own their portPtr's. */ if (!(Tk_IsEmbedded(macWin->winPtr))) { destPort = TkMacGetDrawablePort(window); if (destPort != NULL) { TkMacWindowList *listPtr, *prevPtr; TkMacUnregisterMacWindow(destPort); DisposeWindow((WindowRef) destPort); for (listPtr = tkMacWindowListPtr, prevPtr = NULL; tkMacWindowListPtr != NULL; prevPtr = listPtr, listPtr = listPtr->nextPtr) { if (listPtr->winPtr == macWin->winPtr) { if (prevPtr == NULL) { tkMacWindowListPtr = listPtr->nextPtr; } else { prevPtr->nextPtr = listPtr->nextPtr; } ckfree((char *) listPtr); break; } } } } macWin->portPtr = NULL; /* * Delay deletion of a toplevel data structure untill all * children have been deleted. */ if (macWin->toplevel->referenceCount == 0) { ckfree((char *) macWin->toplevel); } } else { destPort = TkMacGetDrawablePort(window); if (destPort != NULL) { SetGWorld(destPort, NULL); TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW); } if (macWin->winPtr->parentPtr != NULL) { TkMacInvalClipRgns(macWin->winPtr->parentPtr); } DisposeRgn(macWin->clipRgn); DisposeRgn(macWin->aboveClipRgn); if (macWin->toplevel->referenceCount == 0) { ckfree((char *) macWin->toplevel); } ckfree((char *) macWin); }}/* *---------------------------------------------------------------------- * * XMapWindow -- * * Map the given X Window to the screen. See X window documentation * for more details. * * Results: * None. * * Side effects: * The subwindow or toplevel may appear on the screen. * *---------------------------------------------------------------------- */void XMapWindow( Display* display, /* Display. */ Window window) /* Window. */{ MacDrawable *macWin = (MacDrawable *) window; XEvent event; GWorldPtr destPort; /* * Under certain situations it's possible for this function to be * called before the toplevel window it's associated with has actually * been mapped. In that case we need to create the real Macintosh * window now as this function as well as other X functions assume that * the portPtr is valid. */ if (!TkMacHostToplevelExists(macWin->toplevel->winPtr)) { TkMacMakeRealWindowExist(macWin->toplevel->winPtr); } destPort = TkMacGetDrawablePort(window); display->request++; macWin->winPtr->flags |= TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { ShowWindow((WindowRef) destPort); } /* * We only need to send the MapNotify event * for toplevel windows. */ event.xany.serial = display->request; event.xany.send_event = False; event.xany.display = display; event.xmap.window = window; event.xmap.type = MapNotify; event.xmap.event = window; event.xmap.override_redirect = macWin->winPtr->atts.override_redirect; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); } else { TkMacInvalClipRgns(macWin->winPtr->parentPtr); } /* * Generate damage for that area of the window */ SetGWorld(destPort, NULL); TkMacUpdateClipRgn(macWin->winPtr); TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW);}/* *---------------------------------------------------------------------- * * XUnmapWindow -- * * Unmap the given X Window to the screen. See X window * documentation for more details. * * Results: * None. * * Side effects: * The subwindow or toplevel may be removed from the screen. * *---------------------------------------------------------------------- */void XUnmapWindow( Display* display, /* Display. */ Window window) /* Window. */{ MacDrawable *macWin = (MacDrawable *) window; XEvent event; GWorldPtr destPort; destPort = TkMacGetDrawablePort(window); display->request++; macWin->winPtr->flags &= ~TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { HideWindow((WindowRef) destPort); } /* * We only need to send the UnmapNotify event * for toplevel windows. */ event.xany.serial = display->request; event.xany.send_event = False; event.xany.display = display; event.xunmap.type = UnmapNotify; event.xunmap.window = window; event.xunmap.event = window; event.xunmap.from_configure = false; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); } else { /* * Generate damage for that area of the window. */ SetGWorld(destPort, NULL); TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW); /* TODO: may not be valid */ TkMacInvalClipRgns(macWin->winPtr->parentPtr); }}/* *---------------------------------------------------------------------- * * XResizeWindow -- * * Resize a given X window. See X windows documentation for * further details. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */void XResizeWindow( Display* display, /* Display. */ Window window, /* Window. */ unsigned int width, unsigned int height){ MacDrawable *macWin = (MacDrawable *) window; GWorldPtr destPort; destPort = TkMacGetDrawablePort(window); if (destPort == NULL) { return; } display->request++; SetPort((GrafPtr) destPort); if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { /* * NOTE: we are not adding the new space to the update * region. It is currently assumed that Tk will need * to completely redraw anway. */ SizeWindow((WindowRef) destPort, (short) width, (short) height, false); TkMacInvalidateWindow(macWin, TK_WINDOW_ONLY); TkMacInvalClipRgns(macWin->winPtr); } else { int deltaX, deltaY; /* * Find the Parent window - * For an embedded window this will be its container. */ TkWindow *contWinPtr; contWinPtr = TkpGetOtherWindow(macWin->winPtr); if (contWinPtr != NULL) { MacDrawable *macParent = contWinPtr->privatePtr; TkMacInvalClipRgns(macParent->winPtr); TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW); deltaX = macParent->xOff + macWin->winPtr->changes.x - macWin->xOff; deltaY = macParent->yOff + macWin->winPtr->changes.y - macWin->yOff; UpdateOffsets(macWin->winPtr, deltaX, deltaY); } else { /* * This is the case where we are embedded in * another app. At this point, we are assuming that * the changes.x,y is not maintained, if you need * the info get it from Tk_GetRootCoords, * and that the toplevel sits at 0,0 when it is drawn. */ TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW); UpdateOffsets(macWin->winPtr, 0, 0); } } } else { /* TODO: update all xOff & yOffs */ int deltaX, deltaY, parentBorderwidth; MacDrawable *macParent = macWin->winPtr->parentPtr->privatePtr; if (macParent == NULL) { return; /* TODO: Probably should be a panic */ } TkMacInvalClipRgns(macParent->winPtr); TkMacInvalidateWindow(macWin, TK_PARENT_WINDOW); deltaX = - macWin->xOff; deltaY = - macWin->yOff; parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width; deltaX += macParent->xOff + parentBorderwidth + macWin->winPtr->changes.x; deltaY += macParent->yOff + parentBorderwidth + macWin->winPtr->changes.y; UpdateOffsets(macWin->winPtr, deltaX, deltaY); }}/* *---------------------------------------------------------------------- * * XMoveResizeWindow -- * * Move or resize a given X window. See X windows documentation * for further details. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */void XMoveResizeWindow( Display* display, /* Display. */ Window window, /* Window. */ int x, int y, unsigned int width, unsigned int height){ MacDrawable *macWin = (MacDrawable *) window; GWorldPtr destPort; destPort = TkMacGetDrawablePort(window); if (destPort == NULL) { return; } SetPort((GrafPtr) destPort); if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { /* * NOTE: we are not adding the new space to the update * region. It is currently assumed that Tk will need * to completely redraw anway. */ SizeWindow((WindowRef) destPort, (short) width, (short) height, false); tkMacMoveWindow((WindowRef) destPort, x, y); /* TODO: is the following right? */ TkMacInvalidateWindow(macWin, TK_WINDOW_ONLY); TkMacInvalClipRgns(macWin->winPtr); } else { int deltaX, deltaY, parentBorderwidth; Rect bounds; MacDrawable *macParent;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -