ControlRef TkMacOSXGetRootControl( Drawable drawable) { /* * will probably need to fix this up for embedding */ MacDrawable *macWin = (MacDrawable *) drawable; TkWindow *contWinPtr; if (macWin == NULL) { return NULL; } if (!(macWin->toplevel->flags & TK_EMBEDDED)) { return macWin->toplevel->rootControl; } contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); if (contWinPtr == NULL) { return NULL; } return TkMacOSXGetRootControl((Drawable) contWinPtr->privatePtr); }
GWorldPtr TkMacGetDrawablePort( Drawable drawable) { MacDrawable *macWin = (MacDrawable *) drawable; GWorldPtr resultPort = NULL; if (macWin == NULL) { return NULL; } /* * This is NULL for off-screen pixmaps. Then the portPtr * always points to the off-screen port, and we don't * have to worry about containment */ if (macWin->clipRgn == NULL) { return macWin->portPtr; } /* * If the Drawable is in an embedded window, use the Port of its container. * * TRICKY POINT: we can have cases when a toplevel is being destroyed * where the winPtr for the toplevel has been freed, but the children * are not all the way destroyed. The children will call this function * as they are being destroyed, but Tk_IsEmbedded will return garbage. * So we check the copy of the TK_EMBEDDED flag we put into the * toplevel's macWin flags. */ if (!(macWin->toplevel->flags & TK_EMBEDDED)) { return macWin->toplevel->portPtr; } else { TkWindow *contWinPtr; contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); if (contWinPtr != NULL) { resultPort = TkMacGetDrawablePort((Drawable) contWinPtr->privatePtr); } else if (gMacEmbedHandler != NULL) { resultPort = gMacEmbedHandler->getPortProc( (Tk_Window) macWin->winPtr); } if (resultPort == NULL) { panic("TkMacGetDrawablePort couldn't find container"); return NULL; } /* * NOTE: Here we should handle out of process embedding. */ } return resultPort; }
void TkMacOSXInvalClipRgns( Tk_Window tkwin) { TkWindow *winPtr = (TkWindow *) tkwin; TkWindow *childPtr; MacDrawable *macWin = winPtr->privatePtr; /* * If already marked we can stop because all descendants will also already * be marked. */ if (!macWin || macWin->flags & TK_CLIP_INVALID) { return; } macWin->flags |= TK_CLIP_INVALID; if (macWin->visRgn) { CFRelease(macWin->visRgn); macWin->visRgn = NULL; } if (macWin->aboveVisRgn) { CFRelease(macWin->aboveVisRgn); macWin->aboveVisRgn = NULL; } /* * Invalidate clip regions for all children & their descendants, unless the * child is a toplevel. */ childPtr = winPtr->childList; while (childPtr) { if (!Tk_IsTopLevel(childPtr)) { TkMacOSXInvalClipRgns((Tk_Window) childPtr); } childPtr = childPtr->nextPtr; } /* * Also, if the window is a container, mark its embedded window. */ if (Tk_IsContainer(winPtr)) { childPtr = TkpGetOtherWindow(winPtr); if (childPtr) { TkMacOSXInvalClipRgns((Tk_Window) childPtr); } /* * TODO: Here we should handle out of process embedding. */ } }
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 TkMacInvalClipRgns( TkWindow *winPtr) { TkWindow *childPtr; /* * If already marked we can stop because all * decendants will also already be marked. */ if (winPtr->privatePtr->flags & TK_CLIP_INVALID) { return; } winPtr->privatePtr->flags |= TK_CLIP_INVALID; /* * Invalidate clip regions for all children & * their decendants - unless the child is a toplevel. */ childPtr = winPtr->childList; while (childPtr != NULL) { if (!Tk_IsTopLevel(childPtr) && Tk_IsMapped(childPtr)) { TkMacInvalClipRgns(childPtr); } childPtr = childPtr->nextPtr; } /* * Also, if the window is a container, mark its embedded window */ if (Tk_IsContainer(winPtr)) { childPtr = TkpGetOtherWindow(winPtr); if (childPtr != NULL && Tk_IsMapped(childPtr)) { TkMacInvalClipRgns(childPtr); } /* * NOTE: Here we should handle out of process embedding. */ } }
static void UpdateOffsets( TkWindow *winPtr, int deltaX, int deltaY) { TkWindow *childPtr; if (winPtr->privatePtr == NULL) { /* * We haven't called Tk_MakeWindowExist for this window yet. The offset * information will be postponed and calulated at that time. (This will * usually only happen when a mapped parent is being moved but has * child windows that have yet to be mapped.) */ return; } winPtr->privatePtr->xOff += deltaX; winPtr->privatePtr->yOff += deltaY; childPtr = winPtr->childList; while (childPtr != NULL) { if (!Tk_IsTopLevel(childPtr)) { UpdateOffsets(childPtr, deltaX, deltaY); } childPtr = childPtr->nextPtr; } if (Tk_IsContainer(winPtr)) { childPtr = TkpGetOtherWindow(winPtr); if (childPtr != NULL) { UpdateOffsets(childPtr,deltaX,deltaY); } /* * TODO: Here we should handle out of process embedding. */ } }
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 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 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 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); } }
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 */ } }
CGrafPtr TkMacOSXGetDrawablePort( Drawable drawable) { MacDrawable *macWin = (MacDrawable *) drawable; CGrafPtr resultPort = NULL; if (!macWin) { return NULL; } /* * Handle toplevel windows. */ if (macWin->toplevel) { TkWindow *contWinPtr; if (!(macWin->toplevel->flags & TK_EMBEDDED)) { return macWin->toplevel->grafPtr; } /* * If the Drawable is in an embedded window, use the Port of its * container. * * TRICKY POINT: we can have cases when a toplevel is being destroyed * where the winPtr for the toplevel has been freed, but the children * are not all the way destroyed. The children will call this function * as they are being destroyed, but Tk_IsEmbedded will return garbage. * So we check the copy of the TK_EMBEDDED flag we put into the * toplevel's macWin flags. */ contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); resultPort = NULL; if (contWinPtr != NULL) { resultPort = TkMacOSXGetDrawablePort((Drawable) contWinPtr->privatePtr); } else if (tkMacOSXEmbedHandler != NULL) { resultPort = tkMacOSXEmbedHandler->getPortProc((Tk_Window) macWin->winPtr); } if (!resultPort) { /* * FIXME: So far as I can tell, the only time that this happens is * when we are tearing down an embedded child interpreter, and most * of the time, this is harmless... However, we really need to find * why the embedding loses. */ TkMacOSXDbgMsg("Couldn't find container"); } /* * TODO: Here we should handle out of process embedding. */ return resultPort; } if ((macWin->flags & TK_IS_PIXMAP) && !macWin->grafPtr) { AllocGWorld(macWin->size.width, macWin->size.height, macWin->flags & TK_IS_BW_PIXMAP, &macWin->grafPtr); } return macWin->grafPtr; }
CGrafPtr TkMacOSXGetDrawablePort( Drawable drawable) { MacDrawable *macWin = (MacDrawable *) drawable; GWorldPtr resultPort = NULL; if (macWin == NULL) { return NULL; } /* * This is NULL for off-screen pixmaps. Then the portPtr * always points to the off-screen port, and we don't * have to worry about containment */ if (macWin->clipRgn == NULL) { return macWin->grafPtr; } /* * If the Drawable is in an embedded window, use the Port of its container. * * TRICKY POINT: we can have cases when a toplevel is being destroyed * where the winPtr for the toplevel has been freed, but the children * are not all the way destroyed. The children will call this function * as they are being destroyed, but Tk_IsEmbedded will return garbage. * So we check the copy of the TK_EMBEDDED flag we put into the * toplevel's macWin flags. */ if (!(macWin->toplevel->flags & TK_EMBEDDED)) { return macWin->toplevel->grafPtr; } else { TkWindow *contWinPtr; contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); if (contWinPtr != NULL) { resultPort = TkMacOSXGetDrawablePort( (Drawable) contWinPtr->privatePtr); } else if (gMacEmbedHandler != NULL) { resultPort = gMacEmbedHandler->getPortProc( (Tk_Window) macWin->winPtr); } if (resultPort == NULL) { /* * FIXME: * * So far as I can tell, the only time that this happens is when * we are tearing down an embedded child interpreter, and most * of the time, this is harmless... However, we really need to * find why the embedding loses. */ DebugStr("\pTkMacOSXGetDrawablePort couldn't find container"); return NULL; } /* * NOTE: Here we should handle out of process embedding. */ }