📄 tkcanvwind.c
字号:
winItemPtr->header.y2 = winItemPtr->header.y1 + 1; return; } /* * Compute dimensions of window. */ width = winItemPtr->width; if (width <= 0) { width = Tk_ReqWidth(winItemPtr->tkwin); if (width <= 0) { width = 1; } } height = winItemPtr->height; if (height <= 0) { height = Tk_ReqHeight(winItemPtr->tkwin); if (height <= 0) { height = 1; } } /* * Compute location of window, using anchor information. */ switch (winItemPtr->anchor) { case TK_ANCHOR_N: x -= width/2; break; case TK_ANCHOR_NE: x -= width; break; case TK_ANCHOR_E: x -= width; y -= height/2; break; case TK_ANCHOR_SE: x -= width; y -= height; break; case TK_ANCHOR_S: x -= width/2; y -= height; break; case TK_ANCHOR_SW: y -= height; break; case TK_ANCHOR_W: y -= height/2; break; case TK_ANCHOR_NW: break; case TK_ANCHOR_CENTER: x -= width/2; y -= height/2; break; } /* * Store the information in the item header. */ winItemPtr->header.x1 = x; winItemPtr->header.y1 = y; winItemPtr->header.x2 = x + width; winItemPtr->header.y2 = y + height;}/* *-------------------------------------------------------------- * * DisplayWinItem -- * * This procedure is invoked to "draw" a window item in a given * drawable. Since the window draws itself, we needn't do any * actual redisplay here. However, this procedure takes care * of actually repositioning the child window so that it occupies * the correct screen position. * * Results: * None. * * Side effects: * The child window's position may get changed. Note: this * procedure gets called both when a window needs to be displayed * and when it ceases to be visible on the screen (e.g. it was * scrolled or moved off-screen or the enclosing canvas is * unmapped). * *-------------------------------------------------------------- */static voidDisplayWinItem(canvas, itemPtr, display, drawable, regionX, regionY, regionWidth, regionHeight) Tk_Canvas canvas; /* Canvas that contains item. */ Tk_Item *itemPtr; /* Item to be displayed. */ Display *display; /* Display on which to draw item. */ Drawable drawable; /* Pixmap or window in which to draw * item. */ int regionX, regionY, regionWidth, regionHeight; /* Describes region of canvas that * must be redisplayed (not used). */{ WindowItem *winItemPtr = (WindowItem *) itemPtr; int width, height; short x, y; Tk_Window canvasTkwin = Tk_CanvasTkwin(canvas); if (winItemPtr->tkwin == NULL) { return; } Tk_CanvasWindowCoords(canvas, (double) winItemPtr->header.x1, (double) winItemPtr->header.y1, &x, &y); width = winItemPtr->header.x2 - winItemPtr->header.x1; height = winItemPtr->header.y2 - winItemPtr->header.y1; /* * If the window is completely out of the visible area of the canvas * then unmap it. This code used not to be present (why unmap the * window if it isn't visible anyway?) but this could cause the * window to suddenly reappear if the canvas window got resized. */ if (((x + width) <= 0) || ((y + height) <= 0) || (x >= Tk_Width(canvasTkwin)) || (y >= Tk_Height(canvasTkwin))) { if (canvasTkwin == Tk_Parent(winItemPtr->tkwin)) { Tk_UnmapWindow(winItemPtr->tkwin); } else { Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin); } return; } /* * Reposition and map the window (but in different ways depending * on whether the canvas is the window's parent). */ if (canvasTkwin == Tk_Parent(winItemPtr->tkwin)) { if ((x != Tk_X(winItemPtr->tkwin)) || (y != Tk_Y(winItemPtr->tkwin)) || (width != Tk_Width(winItemPtr->tkwin)) || (height != Tk_Height(winItemPtr->tkwin))) { Tk_MoveResizeWindow(winItemPtr->tkwin, x, y, width, height); } Tk_MapWindow(winItemPtr->tkwin); } else { Tk_MaintainGeometry(winItemPtr->tkwin, canvasTkwin, x, y, width, height); }}/* *-------------------------------------------------------------- * * WinItemToPoint -- * * Computes the distance from a given point to a given * rectangle, in canvas units. * * Results: * The return value is 0 if the point whose x and y coordinates * are coordPtr[0] and coordPtr[1] is inside the window. If the * point isn't inside the window then the return value is the * distance from the point to the window. * * Side effects: * None. * *-------------------------------------------------------------- */static doubleWinItemToPoint(canvas, itemPtr, pointPtr) Tk_Canvas canvas; /* Canvas containing item. */ Tk_Item *itemPtr; /* Item to check against point. */ double *pointPtr; /* Pointer to x and y coordinates. */{ WindowItem *winItemPtr = (WindowItem *) itemPtr; double x1, x2, y1, y2, xDiff, yDiff; x1 = winItemPtr->header.x1; y1 = winItemPtr->header.y1; x2 = winItemPtr->header.x2; y2 = winItemPtr->header.y2; /* * Point is outside rectangle. */ if (pointPtr[0] < x1) { xDiff = x1 - pointPtr[0]; } else if (pointPtr[0] >= x2) { xDiff = pointPtr[0] + 1 - x2; } else { xDiff = 0; } if (pointPtr[1] < y1) { yDiff = y1 - pointPtr[1]; } else if (pointPtr[1] >= y2) { yDiff = pointPtr[1] + 1 - y2; } else { yDiff = 0; } return hypot(xDiff, yDiff);}/* *-------------------------------------------------------------- * * WinItemToArea -- * * This procedure is called to determine whether an item * lies entirely inside, entirely outside, or overlapping * a given rectangle. * * Results: * -1 is returned if the item is entirely outside the area * given by rectPtr, 0 if it overlaps, and 1 if it is entirely * inside the given area. * * Side effects: * None. * *-------------------------------------------------------------- */static intWinItemToArea(canvas, itemPtr, rectPtr) Tk_Canvas canvas; /* Canvas containing item. */ Tk_Item *itemPtr; /* Item to check against rectangle. */ double *rectPtr; /* Pointer to array of four coordinates * (x1, y1, x2, y2) describing rectangular * area. */{ WindowItem *winItemPtr = (WindowItem *) itemPtr; if ((rectPtr[2] <= winItemPtr->header.x1) || (rectPtr[0] >= winItemPtr->header.x2) || (rectPtr[3] <= winItemPtr->header.y1) || (rectPtr[1] >= winItemPtr->header.y2)) { return -1; } if ((rectPtr[0] <= winItemPtr->header.x1) && (rectPtr[1] <= winItemPtr->header.y1) && (rectPtr[2] >= winItemPtr->header.x2) && (rectPtr[3] >= winItemPtr->header.y2)) { return 1; } return 0;}/* *-------------------------------------------------------------- * * ScaleWinItem -- * * This procedure is invoked to rescale a rectangle or oval * item. * * Results: * None. * * Side effects: * The rectangle or oval referred to by itemPtr is rescaled * so that the following transformation is applied to all * point coordinates: * x' = originX + scaleX*(x-originX) * y' = originY + scaleY*(y-originY) * *-------------------------------------------------------------- */static voidScaleWinItem(canvas, itemPtr, originX, originY, scaleX, scaleY) Tk_Canvas canvas; /* Canvas containing rectangle. */ Tk_Item *itemPtr; /* Rectangle to be scaled. */ double originX, originY; /* Origin about which to scale rect. */ double scaleX; /* Amount to scale in X direction. */ double scaleY; /* Amount to scale in Y direction. */{ WindowItem *winItemPtr = (WindowItem *) itemPtr; winItemPtr->x = originX + scaleX*(winItemPtr->x - originX); winItemPtr->y = originY + scaleY*(winItemPtr->y - originY); if (winItemPtr->width > 0) { winItemPtr->width = (int) (scaleX*winItemPtr->width); } if (winItemPtr->height > 0) { winItemPtr->height = (int) (scaleY*winItemPtr->height); } ComputeWindowBbox(canvas, winItemPtr);}/* *-------------------------------------------------------------- * * TranslateWinItem -- * * This procedure is called to move a rectangle or oval by a * given amount. * * Results: * None. * * Side effects: * The position of the rectangle or oval is offset by * (xDelta, yDelta), and the bounding box is updated in the * generic part of the item structure. * *-------------------------------------------------------------- */static voidTranslateWinItem(canvas, itemPtr, deltaX, deltaY) Tk_Canvas canvas; /* Canvas containing item. */ Tk_Item *itemPtr; /* Item that is being moved. */ double deltaX, deltaY; /* Amount by which item is to be * moved. */{ WindowItem *winItemPtr = (WindowItem *) itemPtr; winItemPtr->x += deltaX; winItemPtr->y += deltaY; ComputeWindowBbox(canvas, winItemPtr);}/* *-------------------------------------------------------------- * * WinItemStructureProc -- * * This procedure is invoked whenever StructureNotify events * occur for a window that's managed as part of a canvas window * item. This procudure's only purpose is to clean up when * windows are deleted. * * Results: * None. * * Side effects: * The window is disassociated from the window item when it is * deleted. * *-------------------------------------------------------------- */static voidWinItemStructureProc(clientData, eventPtr) ClientData clientData; /* Pointer to record describing window item. */ XEvent *eventPtr; /* Describes what just happened. */{ WindowItem *winItemPtr = (WindowItem *) clientData; if (eventPtr->type == DestroyNotify) { winItemPtr->tkwin = NULL; }}/* *-------------------------------------------------------------- * * WinItemRequestProc -- * * This procedure is invoked whenever a window that's associated * with a window canvas item changes its requested dimensions. * * Results: * None. * * Side effects: * The size and location on the screen of the window may change, * depending on the options specified for the window item. * *-------------------------------------------------------------- */static voidWinItemRequestProc(clientData, tkwin) ClientData clientData; /* Pointer to record for window item. */ Tk_Window tkwin; /* Window that changed its desired * size. */{ WindowItem *winItemPtr = (WindowItem *) clientData; ComputeWindowBbox(winItemPtr->canvas, winItemPtr); DisplayWinItem(winItemPtr->canvas, (Tk_Item *) winItemPtr, (Display *) NULL, (Drawable) None, 0, 0, 0, 0);}/* *-------------------------------------------------------------- * * WinItemLostSlaveProc -- * * This procedure is invoked by Tk whenever some other geometry * claims control over a slave that used to be managed by us. * * Results: * None. * * Side effects: * Forgets all canvas-related information about the slave. * *-------------------------------------------------------------- */ /* ARGSUSED */static voidWinItemLostSlaveProc(clientData, tkwin) ClientData clientData; /* WindowItem structure for slave window that * was stolen away. */ Tk_Window tkwin; /* Tk's handle for the slave window. */{ WindowItem *winItemPtr = (WindowItem *) clientData; Tk_Window canvasTkwin = Tk_CanvasTkwin(winItemPtr->canvas); Tk_DeleteEventHandler(winItemPtr->tkwin, StructureNotifyMask, WinItemStructureProc, (ClientData) winItemPtr); if (canvasTkwin != Tk_Parent(winItemPtr->tkwin)) { Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin); } Tk_UnmapWindow(winItemPtr->tkwin); winItemPtr->tkwin = NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -