void XMoveResizeWindow( Display *display, /* Display. */ Window window, /* Window. */ int x, int y, unsigned int width, unsigned int height) { MacDrawable *macWin = (MacDrawable *) window; display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { WindowRef w = TkMacOSXDrawableWindow(window); if (w) { Rect bounds; bounds.left = x + macWin->winPtr->wmInfoPtr->xInParent; bounds.right = bounds.left + width; bounds.top = y + macWin->winPtr->wmInfoPtr->yInParent; bounds.bottom = bounds.top + height; ChkErr(SetWindowBounds, w, kWindowContentRgn, &bounds); } } else { MoveResizeWindow(macWin); } }
Window TkpMakeWindow( TkWindow *winPtr, Window parent) { MacDrawable *macWin; /* * If this window is marked as embedded then the window structure should * have already been created in the TkpUseWindow function. */ if (Tk_IsEmbedded(winPtr)) { macWin = winPtr->privatePtr; } else { /* * Allocate sub window */ macWin = ckalloc(sizeof(MacDrawable)); if (macWin == NULL) { winPtr->privatePtr = NULL; return None; } macWin->winPtr = winPtr; winPtr->privatePtr = macWin; macWin->visRgn = NULL; macWin->aboveVisRgn = NULL; macWin->drawRgn = NULL; macWin->referenceCount = 0; macWin->flags = TK_CLIP_INVALID; macWin->view = nil; macWin->context = NULL; macWin->size = CGSizeZero; if (Tk_IsTopLevel(macWin->winPtr)) { /* * This will be set when we are mapped. */ macWin->xOff = 0; macWin->yOff = 0; macWin->toplevel = macWin; } else if (winPtr->parentPtr) { macWin->xOff = winPtr->parentPtr->privatePtr->xOff + winPtr->parentPtr->changes.border_width + winPtr->changes.x; macWin->yOff = winPtr->parentPtr->privatePtr->yOff + winPtr->parentPtr->changes.border_width + winPtr->changes.y; macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel; } macWin->toplevel->referenceCount++; } return (Window) macWin; }
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); }
static void MoveResizeWindow( MacDrawable *macWin) { int deltaX = 0, deltaY = 0, parentBorderwidth = 0; MacDrawable *macParent = NULL; CGrafPtr destPort = TkMacOSXGetDrawablePort((Drawable) macWin); /* * Find the Parent window, for an embedded window it will be its container. */ if (Tk_IsEmbedded(macWin->winPtr)) { TkWindow *contWinPtr = TkpGetOtherWindow(macWin->winPtr); if (contWinPtr) { macParent = contWinPtr->privatePtr; } else { /* * Here we should handle out of process embedding. 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. */ } } else { /* * TODO: update all xOff & yOffs */ macParent = macWin->winPtr->parentPtr->privatePtr; parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width; } if (macParent) { deltaX = macParent->xOff + parentBorderwidth + macWin->winPtr->changes.x - macWin->xOff; deltaY = macParent->yOff + parentBorderwidth + macWin->winPtr->changes.y - macWin->yOff; } if (destPort) { TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); if (macParent) { TkMacOSXInvalClipRgns((Tk_Window) macParent->winPtr); } } UpdateOffsets(macWin->winPtr, deltaX, deltaY); if (destPort) { TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); } GenerateConfigureNotify(macWin->winPtr, 0); }
void XUnmapWindow( Display *display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; XEvent event; display->request++; macWin->winPtr->flags &= ~TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr) && macWin->winPtr->wmInfoPtr->hints.initial_state!=IconicState) { /* * XXX This should be HideSheetWindow for kSheetWindowClass * XXX windows that have a wmPtr->master parent set. */ WindowRef wref = TkMacOSXDrawableWindow(window); if ((macWin->winPtr->wmInfoPtr->macClass == kSheetWindowClass) && (macWin->winPtr->wmInfoPtr->master != None)) { HideSheetWindow(wref); } else { HideWindow(wref); } } TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr); /* * 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. */ TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); } }
void XRaiseWindow( Display* display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { TkWmRestackToplevel(macWin->winPtr, Above, NULL); } else { /* TODO: this should generate damage */ } }
void XMoveWindow( Display *display, /* Display. */ Window window, /* Window. */ int x, int y) { MacDrawable *macWin = (MacDrawable *) window; display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { WindowRef w = TkMacOSXDrawableWindow(window); if (w) { ChkErr(MoveWindowStructure, w, x, y); } } else { MoveResizeWindow(macWin); } }
MacDrawable * TkMacOSXGetHostToplevel( TkWindow *winPtr) /* Tk's structure for a window. */ { TkWindow *contWinPtr, *topWinPtr; topWinPtr = winPtr->privatePtr->toplevel->winPtr; if (!Tk_IsEmbedded(topWinPtr)) { return winPtr->privatePtr->toplevel; } contWinPtr = TkpGetOtherWindow(topWinPtr); /* * TODO: Here we should handle out of process embedding. */ if (contWinPtr == NULL) { return None; } return TkMacOSXGetHostToplevel(contWinPtr); }
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); } }
void XMoveWindow( Display* display, /* Display. */ Window window, /* Window. */ int x, int y) { 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. */ 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; /* * Find the Parent window - * For an embedded window this will be its container. */ if (Tk_IsEmbedded(macWin->winPtr)) { TkWindow *contWinPtr; contWinPtr = TkpGetOtherWindow(macWin->winPtr); if (contWinPtr == NULL) { panic("XMoveWindow could not find container"); } macParent = contWinPtr->privatePtr; /* * NOTE: Here we should handle out of process embedding. */ } else { 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; /* * If macWin->winPtr is an embedded window, don't offset by its * parent's borderwidth... */ if (!Tk_IsEmbedded(macWin->winPtr)) { parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width; } else { parentBorderwidth = 0; } deltaX += macParent->xOff + parentBorderwidth + macWin->winPtr->changes.x; deltaY += macParent->yOff + parentBorderwidth + macWin->winPtr->changes.y; UpdateOffsets(macWin->winPtr, deltaX, deltaY); TkMacWinBounds(macWin->winPtr, &bounds); InvalRect(&bounds); } }
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); } }
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); } }
Window TkpMakeWindow( TkWindow *winPtr, Window parent) { MacDrawable *macWin; XEvent event; /* * If this window is marked as embedded then * the window structure should have already been * created in the TkpUseWindow function. */ if (Tk_IsEmbedded(winPtr)) { return (Window) winPtr->privatePtr; } /* * Allocate sub window */ macWin = (MacDrawable *) ckalloc(sizeof(MacDrawable)); if (macWin == NULL) { winPtr->privatePtr = NULL; return None; } macWin->winPtr = winPtr; winPtr->privatePtr = macWin; macWin->clipRgn = NewRgn(); macWin->aboveClipRgn = NewRgn(); macWin->referenceCount = 0; macWin->flags = TK_CLIP_INVALID; if (Tk_IsTopLevel(macWin->winPtr)) { /* *This will be set when we are mapped. */ macWin->portPtr = (GWorldPtr) NULL; macWin->toplevel = macWin; macWin->xOff = 0; macWin->yOff = 0; } else { macWin->portPtr = NULL; macWin->xOff = winPtr->parentPtr->privatePtr->xOff + winPtr->parentPtr->changes.border_width + winPtr->changes.x; macWin->yOff = winPtr->parentPtr->privatePtr->yOff + winPtr->parentPtr->changes.border_width + winPtr->changes.y; macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel; } macWin->toplevel->referenceCount++; /* * TODO: need general solution for visibility events. */ event.xany.serial = Tk_Display(winPtr)->request; event.xany.send_event = False; event.xany.display = Tk_Display(winPtr); event.xvisibility.type = VisibilityNotify; event.xvisibility.window = (Window) macWin;; event.xvisibility.state = VisibilityUnobscured; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); return (Window) macWin; }
void XDestroyWindow( Display *display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; WindowRef winRef; /* * 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)) { TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); if (macWin->winPtr->parentPtr != NULL) { TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); } if (macWin->visRgn) { CFRelease(macWin->visRgn); } if (macWin->aboveVisRgn) { CFRelease(macWin->aboveVisRgn); } if (macWin->toplevel->referenceCount == 0) { ckfree((char *) macWin->toplevel); } ckfree((char *) macWin); return; } /* * We are relying on the Activate Mac OS event to pass the focus away from * a window that is getting Destroyed to the Front non-floating window. BUT * we don't get activate events when a floating window is destroyed, since * the front non-floating window doesn't in fact get activated... So maybe * we can check here and if we are destroying a floating window, we can * pass the focus back to the front non-floating window... */ if (macWin->grafPtr != NULL) { TkWindow *focusPtr = TkGetFocusWin(macWin->winPtr); if (focusPtr == NULL || (focusPtr->mainPtr->winPtr == macWin->winPtr)) { winRef = TkMacOSXDrawableWindow(window); if (TkpIsWindowFloating (winRef)) { Window window = TkMacOSXGetXWindow(ActiveNonFloatingWindow()); if (window != None) { TkMacOSXGenerateFocusEvent(window, 1); } } } } if (macWin->visRgn) { CFRelease(macWin->visRgn); } if (macWin->aboveVisRgn) { CFRelease(macWin->aboveVisRgn); } /* * 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)) { WindowRef winRef = TkMacOSXDrawableWindow(window); if (winRef) { TkMacOSXWindowList *listPtr, *prevPtr; WindowGroupRef group; if (GetWindowProperty(winRef, 'Tk ', 'TsGp', sizeof(group), NULL, &group) == noErr) { TkDisplay *dispPtr = TkGetDisplayList(); ItemCount i = CountWindowGroupContents(group, kWindowGroupContentsReturnWindows); WindowRef macWin; WindowGroupRef newGroup; Window window; while (i > 0) { ChkErr(GetIndexedWindow, group, i--, 0, &macWin); if (!macWin) { continue; } window = TkMacOSXGetXWindow(macWin); newGroup = NULL; if (window != None) { TkWindow *winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window); if (winPtr && winPtr->wmInfoPtr) { newGroup = GetWindowGroupOfClass( winPtr->wmInfoPtr->macClass); } } if (!newGroup) { newGroup = GetWindowGroupOfClass(kDocumentWindowClass); } ChkErr(SetWindowGroup, macWin, newGroup); } ChkErr(SetWindowGroupOwner, group, NULL); ChkErr(ReleaseWindowGroup, group); } TkMacOSXUnregisterMacWindow(winRef); DisposeWindow(winRef); for (listPtr=tkMacOSXWindowListPtr, prevPtr=NULL; tkMacOSXWindowListPtr != NULL; prevPtr=listPtr, listPtr=listPtr->nextPtr) { if (listPtr->winPtr == macWin->winPtr) { if (prevPtr == NULL) { tkMacOSXWindowListPtr = listPtr->nextPtr; } else { prevPtr->nextPtr = listPtr->nextPtr; } ckfree((char *) listPtr); break; } } } } macWin->grafPtr = NULL; /* * Delay deletion of a toplevel data structure untill all children have * been deleted. */ if (macWin->toplevel->referenceCount == 0) { ckfree((char *) macWin->toplevel); } }
void XMapWindow( Display *display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; XEvent event; /* * 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 (!TkMacOSXHostToplevelExists(macWin->toplevel->winPtr)) { TkMacOSXMakeRealWindowExist(macWin->toplevel->winPtr); } display->request++; macWin->winPtr->flags |= TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { /* * XXX This should be ShowSheetWindow for kSheetWindowClass * XXX windows that have a wmPtr->master parent set. */ WindowRef wRef = TkMacOSXDrawableWindow(window); if ((macWin->winPtr->wmInfoPtr->macClass == kSheetWindowClass) && (macWin->winPtr->wmInfoPtr->master != None)) { ShowSheetWindow(wRef, TkMacOSXDrawableWindow( macWin->winPtr->wmInfoPtr->master)); } else { ShowWindow(wRef); } } TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr); /* * 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 { /* * Generate damage for that area of the window. */ TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); } /* * Generate VisibilityNotify events for window and all mapped children. */ event.xany.send_event = False; event.xany.display = display; event.xvisibility.type = VisibilityNotify; event.xvisibility.state = VisibilityUnobscured; NotifyVisibility(macWin->winPtr, &event); }
void TkMacUpdateClipRgn( TkWindow *winPtr) { RgnHandle rgn; int x, y; TkWindow *win2Ptr; if (winPtr == NULL) { return; } if (winPtr->privatePtr->flags & TK_CLIP_INVALID) { rgn = winPtr->privatePtr->aboveClipRgn; if (tmpRgn == NULL) { tmpRgn = NewRgn(); } /* * Start with a region defined by the window bounds. */ x = winPtr->privatePtr->xOff; y = winPtr->privatePtr->yOff; SetRectRgn(rgn, (short) x, (short) y, (short) (winPtr->changes.width + x), (short) (winPtr->changes.height + y)); /* * Clip away the area of any windows that may obscure this * window. * For a non-toplevel window, first, clip to the parents visable * clip region. * Second, clip away any siblings that are higher in the * stacking order. * For an embedded toplevel, just clip to the container's visible * clip region. Remember, we only allow one contained window * in a frame, and don't support any other widgets in the frame either. * This is not currently enforced, however. */ if (!Tk_IsTopLevel(winPtr)) { TkMacUpdateClipRgn(winPtr->parentPtr); SectRgn(rgn, winPtr->parentPtr->privatePtr->aboveClipRgn, rgn); win2Ptr = winPtr->nextPtr; while (win2Ptr != NULL) { if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) { win2Ptr = win2Ptr->nextPtr; continue; } x = win2Ptr->privatePtr->xOff; y = win2Ptr->privatePtr->yOff; SetRectRgn(tmpRgn, (short) x, (short) y, (short) (win2Ptr->changes.width + x), (short) (win2Ptr->changes.height + y)); DiffRgn(rgn, tmpRgn, rgn); win2Ptr = win2Ptr->nextPtr; } } else if (Tk_IsEmbedded(winPtr)) { TkWindow *contWinPtr; contWinPtr = TkpGetOtherWindow(winPtr); if (contWinPtr != NULL) { TkMacUpdateClipRgn(contWinPtr); SectRgn(rgn, contWinPtr->privatePtr->aboveClipRgn, rgn); } else if (gMacEmbedHandler != NULL) { gMacEmbedHandler->getClipProc((Tk_Window) winPtr, tmpRgn); SectRgn(rgn, tmpRgn, rgn); } /* * NOTE: Here we should handle out of process embedding. */ } /* * The final clip region is the aboveClip region (or visable * region) minus all the children of this window. * Alternatively, if the window is a container, we must also * subtract the region of the embedded window. */ rgn = winPtr->privatePtr->clipRgn; CopyRgn(winPtr->privatePtr->aboveClipRgn, rgn); win2Ptr = winPtr->childList; while (win2Ptr != NULL) { if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) { win2Ptr = win2Ptr->nextPtr; continue; } x = win2Ptr->privatePtr->xOff; y = win2Ptr->privatePtr->yOff; SetRectRgn(tmpRgn, (short) x, (short) y, (short) (win2Ptr->changes.width + x), (short) (win2Ptr->changes.height + y)); DiffRgn(rgn, tmpRgn, rgn); win2Ptr = win2Ptr->nextPtr; } if (Tk_IsContainer(winPtr)) { win2Ptr = TkpGetOtherWindow(winPtr); if (win2Ptr != NULL) { if (Tk_IsMapped(win2Ptr)) { x = win2Ptr->privatePtr->xOff; y = win2Ptr->privatePtr->yOff; SetRectRgn(tmpRgn, (short) x, (short) y, (short) (win2Ptr->changes.width + x), (short) (win2Ptr->changes.height + y)); DiffRgn(rgn, tmpRgn, rgn); } } /* * NOTE: Here we should handle out of process embedding. */ } winPtr->privatePtr->flags &= ~TK_CLIP_INVALID; } }
void TkMacOSXUpdateClipRgn( TkWindow *winPtr) { MacDrawable *macWin; if (winPtr == NULL) { return; } macWin = winPtr->privatePtr; if (macWin && macWin->flags & TK_CLIP_INVALID) { TkWindow *win2Ptr; if (Tk_IsMapped(winPtr)) { int rgnChanged = 0; CGRect bounds; HIMutableShapeRef rgn; /* * Start with a region defined by the window bounds. */ TkMacOSXWinCGBounds(winPtr, &bounds); rgn = TkMacOSXHIShapeCreateMutableWithRect(&bounds); /* * Clip away the area of any windows that may obscure this window. * For a non-toplevel window, first, clip to the parents visible * clip region. Second, clip away any siblings that are higher in * the stacking order. For an embedded toplevel, just clip to the * container's visible clip region. Remember, we only allow one * contained window in a frame, and don't support any other widgets * in the frame either. This is not currently enforced, however. */ if (!Tk_IsTopLevel(winPtr)) { TkMacOSXUpdateClipRgn(winPtr->parentPtr); if (winPtr->parentPtr) { ChkErr(HIShapeIntersect, winPtr->parentPtr->privatePtr->aboveVisRgn, rgn, rgn); } win2Ptr = winPtr; while ((win2Ptr = win2Ptr->nextPtr)) { if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) { continue; } TkMacOSXWinCGBounds(win2Ptr, &bounds); ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds); } } else if (Tk_IsEmbedded(winPtr)) { win2Ptr = TkpGetOtherWindow(winPtr); if (win2Ptr) { TkMacOSXUpdateClipRgn(win2Ptr); ChkErr(HIShapeIntersect, win2Ptr->privatePtr->aboveVisRgn, rgn, rgn); } else if (tkMacOSXEmbedHandler != NULL) { HIShapeRef visRgn; TkMacOSXCheckTmpQdRgnEmpty(); tkMacOSXEmbedHandler->getClipProc((Tk_Window) winPtr, tkMacOSXtmpQdRgn); visRgn = HIShapeCreateWithQDRgn(tkMacOSXtmpQdRgn); SetEmptyRgn(tkMacOSXtmpQdRgn); ChkErr(HIShapeIntersect, visRgn, rgn, rgn); } /* * TODO: Here we should handle out of process embedding. */ } else if (winPtr->wmInfoPtr->attributes & kWindowResizableAttribute) { HIViewRef growBoxView; OSErr err = HIViewFindByID(HIViewGetRoot( TkMacOSXDrawableWindow(winPtr->window)), kHIViewWindowGrowBoxID, &growBoxView); if (err == noErr) { ChkErr(HIViewGetFrame, growBoxView, &bounds); bounds = CGRectOffset(bounds, -winPtr->wmInfoPtr->xInParent, -winPtr->wmInfoPtr->yInParent); ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds); } } macWin->aboveVisRgn = HIShapeCreateCopy(rgn); /* * The final clip region is the aboveVis region (or visible region) * minus all the children of this window. If the window is a * container, we must also subtract the region of the embedded * window. */ win2Ptr = winPtr->childList; while (win2Ptr) { if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) { win2Ptr = win2Ptr->nextPtr; continue; } TkMacOSXWinCGBounds(win2Ptr, &bounds); ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds); rgnChanged = 1; win2Ptr = win2Ptr->nextPtr; } if (Tk_IsContainer(winPtr)) { win2Ptr = TkpGetOtherWindow(winPtr); if (win2Ptr) { if (Tk_IsMapped(win2Ptr)) { TkMacOSXWinCGBounds(win2Ptr, &bounds); ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds); rgnChanged = 1; } } /* * TODO: Here we should handle out of process embedding. */ } if (rgnChanged) { HIShapeRef diffRgn = HIShapeCreateDifference( macWin->aboveVisRgn, rgn); if (!HIShapeIsEmpty(diffRgn)) { macWin->visRgn = HIShapeCreateCopy(rgn); } CFRelease(diffRgn); } CFRelease(rgn); } else { /* * An unmapped window has empty clip regions to prevent any * (erroneous) drawing into it or its children from becoming * visible. [Bug 940117] */ if (!Tk_IsTopLevel(winPtr)) { TkMacOSXUpdateClipRgn(winPtr->parentPtr); } else if (Tk_IsEmbedded(winPtr)) { win2Ptr = TkpGetOtherWindow(winPtr); if (win2Ptr) { TkMacOSXUpdateClipRgn(win2Ptr); } } macWin->aboveVisRgn = TkMacOSXHIShapeCreateEmpty(); } if (!macWin->visRgn) { macWin->visRgn = HIShapeCreateCopy(macWin->aboveVisRgn); } macWin->flags &= ~TK_CLIP_INVALID; #ifdef TK_MAC_DEBUG_CLIP_REGIONS TkMacOSXDebugFlashRegion((Drawable) macWin, macWin->visRgn); #endif /* TK_MAC_DEBUG_CLIP_REGIONS */ } }