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 XMapWindow( Display* display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; XEvent event; CGrafPtr 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 (!TkMacOSXHostToplevelExists(macWin->toplevel->winPtr)) { TkMacOSXMakeRealWindowExist(macWin->toplevel->winPtr); } destPort = TkMacOSXGetDrawablePort (window); display->request++; macWin->winPtr->flags |= TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { ShowWindow(GetWindowFromPort(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 { TkMacOSXInvalClipRgns(macWin->winPtr->parentPtr); } /* * Generate damage for that area of the window */ SetGWorld (destPort, NULL); TkMacOSXUpdateClipRgn(macWin->winPtr); TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); }
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 XUnmapWindow( Display* display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; XEvent event; CGrafPtr destPort; destPort = TkMacOSXGetDrawablePort(window); display->request++; macWin->winPtr->flags &= ~TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { HideWindow(GetWindowFromPort(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); TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); /* TODO: may not be valid */ TkMacOSXInvalClipRgns(macWin->winPtr->parentPtr); } }
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 XMoveWindow( Display* display, /* Display. */ Window window, /* Window. */ int x, int y) { MacDrawable *macWin = (MacDrawable *) window; CGrafPtr destPort; destPort = TkMacOSXGetDrawablePort(window); if (destPort == NULL) { return; } SetPort( 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. */ MoveWindowStructure( GetWindowFromPort(destPort), x, y); /* TODO: is the following right? */ TkMacOSXInvalidateWindow(macWin, TK_WINDOW_ONLY); TkMacOSXInvalClipRgns(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 */ } } TkMacOSXInvalClipRgns(macParent->winPtr); TkMacOSXInvalidateWindow(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); TkMacOSXWinBounds(macWin->winPtr, &bounds); InvalWindowRect(GetWindowFromPort(destPort),&bounds); } }
void XDestroyWindow( Display* display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; CGrafPtr 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 = TkMacOSXGetDrawablePort(window); if (destPort != NULL) { TkMacOSXWindowList *listPtr, *prevPtr; WindowRef winRef; winRef = GetWindowFromPort(destPort); 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); } } else { CGrafPtr destPort; destPort = TkMacOSXGetDrawablePort(window); if (destPort != NULL) { SetGWorld(destPort, NULL); TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); } if (macWin->winPtr->parentPtr != NULL) { TkMacOSXInvalClipRgns(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; CGrafPtr destPort; destPort = TkMacOSXGetDrawablePort(window); if (destPort == NULL) { return; } display->request++; SetPort( 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(GetWindowFromPort(destPort), (short) width, (short) height, false); TkMacOSXInvalidateWindow(macWin, TK_WINDOW_ONLY); TkMacOSXInvalClipRgns(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; TkMacOSXInvalClipRgns(macParent->winPtr); TkMacOSXInvalidateWindow(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. */ TkMacOSXInvalidateWindow(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 */ } TkMacOSXInvalClipRgns(macParent->winPtr); TkMacOSXInvalidateWindow(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); } }