📄 tkcmds.c
字号:
case WIN_ROOTX: { Tk_GetRootCoords(tkwin, &x, &y); Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), x); break; } case WIN_ROOTY: { Tk_GetRootCoords(tkwin, &x, &y); Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), y); break; } case WIN_SCREEN: { sprintf(buf, "%d", Tk_ScreenNumber(tkwin)); Tcl_ResetResult(interp); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), Tk_DisplayName(tkwin), ".", buf, NULL); break; } case WIN_SCREENCELLS: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), CellsOfScreen(Tk_Screen(tkwin))); break; } case WIN_SCREENDEPTH: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), DefaultDepthOfScreen(Tk_Screen(tkwin))); break; } case WIN_SCREENHEIGHT: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), HeightOfScreen(Tk_Screen(tkwin))); break; } case WIN_SCREENWIDTH: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), WidthOfScreen(Tk_Screen(tkwin))); break; } case WIN_SCREENMMHEIGHT: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), HeightMMOfScreen(Tk_Screen(tkwin))); break; } case WIN_SCREENMMWIDTH: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), WidthMMOfScreen(Tk_Screen(tkwin))); break; } case WIN_SCREENVISUAL: { class = DefaultVisualOfScreen(Tk_Screen(tkwin))->class; goto visual; } case WIN_SERVER: { TkGetServerInfo(interp, tkwin); break; } case WIN_TOPLEVEL: { winPtr = GetToplevel(tkwin); if (winPtr != NULL) { Tcl_ResetResult(interp); Tcl_SetStringObj(Tcl_GetObjResult(interp), winPtr->pathName, -1); } break; } case WIN_VIEWABLE: { int viewable; viewable = 0; for ( ; ; winPtr = winPtr->parentPtr) { if ((winPtr == NULL) || !(winPtr->flags & TK_MAPPED)) { break; } if (winPtr->flags & TK_TOP_LEVEL) { viewable = 1; break; } } Tcl_ResetResult(interp); Tcl_SetBooleanObj(Tcl_GetObjResult(interp), viewable); break; } case WIN_VISUAL: { class = Tk_Visual(tkwin)->class; visual: string = TkFindStateString(visualMap, class); if (string == NULL) { string = "unknown"; } Tcl_ResetResult(interp); Tcl_SetStringObj(Tcl_GetObjResult(interp), string, -1); break; } case WIN_VISUALID: { Tcl_ResetResult(interp); sprintf(buf, "0x%x", (unsigned int) XVisualIDFromVisual(Tk_Visual(tkwin))); Tcl_SetStringObj(Tcl_GetObjResult(interp), buf, -1); break; } case WIN_VROOTHEIGHT: { Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height); Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), height); break; } case WIN_VROOTWIDTH: { Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height); Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), width); break; } case WIN_VROOTX: { Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height); Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), x); break; } case WIN_VROOTY: { Tk_GetVRootGeometry(tkwin, &x, &y, &width, &height); Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), y); break; } case WIN_WIDTH: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), Tk_Width(tkwin)); break; } case WIN_X: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), Tk_X(tkwin)); break; } case WIN_Y: { Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), Tk_Y(tkwin)); break; } /* * Uses -displayof. */ case WIN_ATOM: { skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin); if (skip < 0) { return TCL_ERROR; } if (objc - skip != 3) { Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window? name"); return TCL_ERROR; } objv += skip; string = Tcl_GetStringFromObj(objv[2], NULL); Tcl_ResetResult(interp); Tcl_SetLongObj(Tcl_GetObjResult(interp), (long) Tk_InternAtom(tkwin, string)); break; } case WIN_ATOMNAME: { char *name; long id; skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin); if (skip < 0) { return TCL_ERROR; } if (objc - skip != 3) { Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window? id"); return TCL_ERROR; } objv += skip; if (Tcl_GetLongFromObj(interp, objv[2], &id) != TCL_OK) { return TCL_ERROR; } Tcl_ResetResult(interp); name = Tk_GetAtomName(tkwin, (Atom) id); if (strcmp(name, "?bad atom?") == 0) { string = Tcl_GetStringFromObj(objv[2], NULL); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "no atom exists with id \"", string, "\"", NULL); return TCL_ERROR; } Tcl_SetStringObj(Tcl_GetObjResult(interp), name, -1); break; } case WIN_CONTAINING: { skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin); if (skip < 0) { return TCL_ERROR; } if (objc - skip != 4) { Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window? rootX rootY"); return TCL_ERROR; } objv += skip; string = Tcl_GetStringFromObj(objv[2], NULL); if (Tk_GetPixels(interp, tkwin, string, &x) != TCL_OK) { return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[3], NULL); if (Tk_GetPixels(interp, tkwin, string, &y) != TCL_OK) { return TCL_ERROR; } tkwin = Tk_CoordsToWindow(x, y, tkwin); if (tkwin != NULL) { Tcl_ResetResult(interp); Tcl_SetStringObj(Tcl_GetObjResult(interp), Tk_PathName(tkwin), -1); } break; } case WIN_INTERPS: { int result; skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin); if (skip < 0) { return TCL_ERROR; } if (objc - skip != 2) { Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window?"); return TCL_ERROR; } result = TkGetInterpNames(interp, tkwin); return result; } case WIN_PATHNAME: { int id; skip = TkGetDisplayOf(interp, objc - 2, objv + 2, &tkwin); if (skip < 0) { return TCL_ERROR; } if (objc - skip != 3) { Tcl_WrongNumArgs(interp, 2, objv, "?-displayof window? id"); return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[2 + skip], NULL); if (TkpScanWindowId(interp, string, &id) != TCL_OK) { return TCL_ERROR; } winPtr = (TkWindow *) Tk_IdToWindow(Tk_Display(tkwin), (Window) id); if ((winPtr == NULL) || (winPtr->mainPtr != ((TkWindow *) tkwin)->mainPtr)) { Tcl_ResetResult(interp); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "window id \"", string, "\" doesn't exist in this application", (char *) NULL); return TCL_ERROR; } /* * If the window is a utility window with no associated path * (such as a wrapper window or send communication window), just * return an empty string. */ tkwin = (Tk_Window) winPtr; if (Tk_PathName(tkwin) != NULL) { Tcl_ResetResult(interp); Tcl_SetStringObj(Tcl_GetObjResult(interp), Tk_PathName(tkwin), -1); } break; } /* * objv[3] is window. */ case WIN_EXISTS: { int alive; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "window"); return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[2], NULL); winPtr = (TkWindow *) Tk_NameToWindow(interp, string, tkwin); alive = 1; if ((winPtr == NULL) || (winPtr->flags & TK_ALREADY_DEAD)) { alive = 0; } Tcl_ResetResult(interp); /* clear any error msg */ Tcl_SetBooleanObj(Tcl_GetObjResult(interp), alive); break; } case WIN_FPIXELS: { double mm, pixels; if (objc != 4) { Tcl_WrongNumArgs(interp, 2, objv, "window number"); return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[2], NULL); tkwin = Tk_NameToWindow(interp, string, tkwin); if (tkwin == NULL) { return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[3], NULL); if (Tk_GetScreenMM(interp, tkwin, string, &mm) != TCL_OK) { return TCL_ERROR; } pixels = mm * WidthOfScreen(Tk_Screen(tkwin)) / WidthMMOfScreen(Tk_Screen(tkwin)); Tcl_ResetResult(interp); Tcl_SetDoubleObj(Tcl_GetObjResult(interp), pixels); break; } case WIN_PIXELS: { int pixels; if (objc != 4) { Tcl_WrongNumArgs(interp, 2, objv, "window number"); return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[2], NULL); tkwin = Tk_NameToWindow(interp, string, tkwin); if (tkwin == NULL) { return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[3], NULL); if (Tk_GetPixels(interp, tkwin, string, &pixels) != TCL_OK) { return TCL_ERROR; } Tcl_ResetResult(interp); Tcl_SetIntObj(Tcl_GetObjResult(interp), pixels); break; } case WIN_RGB: { XColor *colorPtr; if (objc != 4) { Tcl_WrongNumArgs(interp, 2, objv, "window colorName"); return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[2], NULL); tkwin = Tk_NameToWindow(interp, string, tkwin); if (tkwin == NULL) { return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[3], NULL); colorPtr = Tk_GetColor(interp, tkwin, string); if (colorPtr == NULL) { return TCL_ERROR; } sprintf(buf, "%d %d %d", colorPtr->red, colorPtr->green, colorPtr->blue); Tk_FreeColor(colorPtr); Tcl_ResetResult(interp); Tcl_SetStringObj(Tcl_GetObjResult(interp), buf, -1); break; } case WIN_VISUALSAVAILABLE: { XVisualInfo template, *visInfoPtr; int count, i; char visualIdString[16]; int includeVisualId; Tcl_Obj *strPtr; if (objc == 3) { includeVisualId = 0; } else if ((objc == 4) && (strcmp(Tcl_GetStringFromObj(objv[3], NULL), "includeids") == 0)) { includeVisualId = 1; } else { Tcl_WrongNumArgs(interp, 2, objv, "window ?includeids?"); return TCL_ERROR; } string = Tcl_GetStringFromObj(objv[2], NULL); tkwin = Tk_NameToWindow(interp, string, tkwin); if (tkwin == NULL) { return TCL_ERROR; } template.screen = Tk_ScreenNumber(tkwin); visInfoPtr = XGetVisualInfo(Tk_Display(tkwin), VisualScreenMask, &template, &count); Tcl_ResetResult(interp); if (visInfoPtr == NULL) { Tcl_SetStringObj(Tcl_GetObjResult(interp), "can't find any visuals for screen", -1); return TCL_ERROR; } for (i = 0; i < count; i++) { string = TkFindStateString(visualMap, visInfoPtr[i].class); if (string == NULL) { strcpy(buf, "unknown"); } else { sprintf(buf, "%s %d", string, visInfoPtr[i].depth); } if (includeVisualId) { sprintf(visualIdString, " 0x%x", (unsigned int) visInfoPtr[i].visualid); strcat(buf, visualIdString); } strPtr = Tcl_NewStringObj(buf, -1); Tcl_ListObjAppendElement(NULL, Tcl_GetObjResult(interp), strPtr); } XFree((char *) visInfoPtr); break; } } return TCL_OK;}/* *---------------------------------------------------------------------- * * TkGetDisplayOf -- * * Parses a "-displayof window" option for various commands. If * present, the literal "-displayof" should be in objv[0] and the * window name in objv[1]. * * Results: * The return value is 0 if the argument strings did not contain * the "-displayof" option. The return value is 2 if the * argument strings contained both the "-displayof" option and * a valid window name. Otherwise, the return value is -1 if * the window name was missing or did not specify a valid window. * * If the return value was 2, *tkwinPtr is filled with the * token for the window specified on the command line. If the * return value was -1, an error message is left in interp's * result object. * * Side effects: * None. * *---------------------------------------------------------------------- */intTkGetDisplayOf(interp, objc, objv, tkwinPtr) Tcl_Interp *interp; /* Interpreter for error reporting. */ int objc; /* Number of arguments. */ Tcl_Obj *CONST objv[]; /* Argument objects. If it is present, * "-displayof" should be in objv[0] and * objv[1] the name of a window. */ Tk_Window *tkwinPtr; /* On input, contains main window of * application associated with interp. On * output, filled with window specified as * option to "-displayof" argument, or * unmodified if "-displayof" argument was not * present. */{ char *string; int length; if (objc < 1) { return 0; } string = Tcl_GetStringFromObj(objv[0], &length); if ((length >= 2) && (strncmp(string, "-displayof", (unsigned) length) == 0)) { if (objc < 2) { Tcl_SetStringObj(Tcl_GetObjResult(interp), "value for \"-displayof\" missing", -1); return -1; } string = Tcl_GetStringFromObj(objv[1], NULL); *tkwinPtr = Tk_NameToWindow(interp, string, *tkwinPtr); if (*tkwinPtr == NULL) { return -1; } return 2; } return 0;}/* *---------------------------------------------------------------------- * * TkDeadAppCmd -- * * If an application has been deleted then all Tk commands will be * re-bound to this procedure. * * Results: * A standard Tcl error is reported to let the user know that * the application is dead. * * Side effects: * See the user documentation. * *---------------------------------------------------------------------- */ /* ARGSUSED */intTkDeadAppCmd(clientData, interp, argc, argv) ClientData clientData; /* Dummy. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ Tcl_AppendResult(interp, "can't invoke \"", argv[0], "\" command: application has been destroyed", (char *) NULL); return TCL_ERROR;}/* *---------------------------------------------------------------------- * * GetToplevel -- * * Retrieves the toplevel window which is the nearest ancestor of * of the specified window. * * Results: * Returns the toplevel window or NULL if the window has no * ancestor which is a toplevel. * * Side effects: * None. * *---------------------------------------------------------------------- */static TkWindow *GetToplevel(tkwin) Tk_Window tkwin; /* Window for which the toplevel should be * deterined. */{ TkWindow *winPtr = (TkWindow *) tkwin; while (!(winPtr->flags & TK_TOP_LEVEL)) { winPtr = winPtr->parentPtr; if (winPtr == NULL) { return NULL; } } return winPtr;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -