📄 tktest.c
字号:
* window for a menubar. * * Results: * A standard Tcl result. * * Side effects: * Changes menubar related stuff. * *---------------------------------------------------------------------- */ /* ARGSUSED */static intTestmenubarCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{#ifdef __UNIX__ Tk_Window mainwin = (Tk_Window) clientData; Tk_Window tkwin, menubar; if (argc < 2) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], " option ?arg ...?\"", (char *) NULL); return TCL_ERROR; } if (strcmp(argv[1], "window") == 0) { if (argc != 4) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], "window toplevel menubar\"", (char *) NULL); return TCL_ERROR; } tkwin = Tk_NameToWindow(interp, argv[2], mainwin); if (tkwin == NULL) { return TCL_ERROR; } if (argv[3][0] == 0) { TkUnixSetMenubar(tkwin, NULL); } else { menubar = Tk_NameToWindow(interp, argv[3], mainwin); if (menubar == NULL) { return TCL_ERROR; } TkUnixSetMenubar(tkwin, menubar); } } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be window", (char *) NULL); return TCL_ERROR; } return TCL_OK;#else interp->result = "testmenubar is supported only under Unix"; return TCL_ERROR;#endif}/* *---------------------------------------------------------------------- * * TestmetricsCmd -- * * This procedure implements the testmetrics command. It provides * a way to determine the size of various widget components. * * Results: * A standard Tcl result. * * Side effects: * None. * *---------------------------------------------------------------------- */#ifdef __WIN32__static intTestmetricsCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ char buf[200]; if (argc < 2) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], " option ?arg ...?\"", (char *) NULL); return TCL_ERROR; } if (strcmp(argv[1], "cyvscroll") == 0) { sprintf(buf, "%d", GetSystemMetrics(SM_CYVSCROLL)); Tcl_AppendResult(interp, buf, (char *) NULL); } else if (strcmp(argv[1], "cxhscroll") == 0) { sprintf(buf, "%d", GetSystemMetrics(SM_CXHSCROLL)); Tcl_AppendResult(interp, buf, (char *) NULL); } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be cxhscroll or cyvscroll", (char *) NULL); return TCL_ERROR; } return TCL_OK;}#endif#ifdef MAC_TCLstatic intTestmetricsCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ Tk_Window tkwin = (Tk_Window) clientData; TkWindow *winPtr; char buf[200]; if (argc != 3) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], " option window\"", (char *) NULL); return TCL_ERROR; } winPtr = (TkWindow *) Tk_NameToWindow(interp, argv[2], tkwin); if (winPtr == NULL) { return TCL_ERROR; } if (strcmp(argv[1], "cyvscroll") == 0) { sprintf(buf, "%d", ((TkScrollbar *) winPtr->instanceData)->width); Tcl_AppendResult(interp, buf, (char *) NULL); } else if (strcmp(argv[1], "cxhscroll") == 0) { sprintf(buf, "%d", ((TkScrollbar *) winPtr->instanceData)->width); Tcl_AppendResult(interp, buf, (char *) NULL); } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be cxhscroll or cyvscroll", (char *) NULL); return TCL_ERROR; } return TCL_OK;}#endif/* *---------------------------------------------------------------------- * * TestpropCmd -- * * This procedure implements the "testprop" command. It fetches * and prints the value of a property on a window. * * Results: * A standard Tcl result. * * Side effects: * None. * *---------------------------------------------------------------------- */ /* ARGSUSED */static intTestpropCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ Tk_Window mainwin = (Tk_Window) clientData; int result, actualFormat; unsigned long bytesAfter, length, value; Atom actualType, propName; char *property, *p, *end; Window w; char buffer[30]; if (argc != 3) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], " window property\"", (char *) NULL); return TCL_ERROR; } w = strtoul(argv[1], &end, 0); propName = Tk_InternAtom(mainwin, argv[2]); property = NULL; result = XGetWindowProperty(Tk_Display(mainwin), w, propName, 0, 100000, False, AnyPropertyType, &actualType, &actualFormat, &length, &bytesAfter, (unsigned char **) &property); if ((result == Success) && (actualType != None)) { if ((actualFormat == 8) && (actualType == XA_STRING)) { for (p = property; ((unsigned long)(p-property)) < length; p++) { if (*p == 0) { *p = '\n'; } } Tcl_SetResult(interp, property, TCL_VOLATILE); } else { for (p = property; length > 0; length--) { if (actualFormat == 32) { value = *((long *) p); p += sizeof(long); } else if (actualFormat == 16) { value = 0xffff & (*((short *) p)); p += sizeof(short); } else { value = 0xff & *p; p += 1; } sprintf(buffer, "0x%lx", value); Tcl_AppendElement(interp, buffer); } } } if (property != NULL) { XFree(property); } return TCL_OK;}/* *---------------------------------------------------------------------- * * TestsendCmd -- * * This procedure implements the "testsend" command. It provides * a set of functions for testing the "send" command and support * procedure in tkSend.c. * * Results: * A standard Tcl result. * * Side effects: * Depends on option; see below. * *---------------------------------------------------------------------- */ /* ARGSUSED */static intTestsendCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ TkWindow *winPtr = (TkWindow *) clientData; if (argc < 2) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], " option ?arg ...?\"", (char *) NULL); return TCL_ERROR; }#if !(defined(__WIN32__) || defined(MAC_TCL)) if (strcmp(argv[1], "bogus") == 0) { XChangeProperty(winPtr->dispPtr->display, RootWindow(winPtr->dispPtr->display, 0), winPtr->dispPtr->registryProperty, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "This is bogus information", 6); } else if (strcmp(argv[1], "prop") == 0) { int result, actualFormat; unsigned long length, bytesAfter; Atom actualType, propName; char *property, *p, *end; Window w; if ((argc != 4) && (argc != 5)) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], " prop window name ?value ?\"", (char *) NULL); return TCL_ERROR; } if (strcmp(argv[2], "root") == 0) { w = RootWindow(winPtr->dispPtr->display, 0); } else if (strcmp(argv[2], "comm") == 0) { w = Tk_WindowId(winPtr->dispPtr->commTkwin); } else { w = strtoul(argv[2], &end, 0); } propName = Tk_InternAtom((Tk_Window) winPtr, argv[3]); if (argc == 4) { property = NULL; result = XGetWindowProperty(winPtr->dispPtr->display, w, propName, 0, 100000, False, XA_STRING, &actualType, &actualFormat, &length, &bytesAfter, (unsigned char **) &property); if ((result == Success) && (actualType != None) && (actualFormat == 8) && (actualType == XA_STRING)) { for (p = property; (p-property) < length; p++) { if (*p == 0) { *p = '\n'; } } Tcl_SetResult(interp, property, TCL_VOLATILE); } if (property != NULL) { XFree(property); } } else { if (argv[4][0] == 0) { XDeleteProperty(winPtr->dispPtr->display, w, propName); } else { for (p = argv[4]; *p != 0; p++) { if (*p == '\n') { *p = 0; } } XChangeProperty(winPtr->dispPtr->display, w, propName, XA_STRING, 8, PropModeReplace, (unsigned char *) argv[4], p-argv[4]); } } } else if (strcmp(argv[1], "serial") == 0) { sprintf(interp->result, "%d", tkSendSerial+1); } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be bogus, prop, or serial", (char *) NULL); return TCL_ERROR; }#endif return TCL_OK;}#if !(defined(__WIN32__) || defined(MAC_TCL))/* *---------------------------------------------------------------------- * * TestwrapperCmd -- * * This procedure implements the "testwrapper" command. It * provides a way from Tcl to determine the extra window Tk adds * in between the toplevel window and the window decorations. * * Results: * A standard Tcl result. * * Side effects: * None. * *---------------------------------------------------------------------- */ /* ARGSUSED */static intTestwrapperCmd(clientData, interp, argc, argv) ClientData clientData; /* Main window for application. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ TkWindow *winPtr, *wrapperPtr; Tk_Window tkwin; if (argc != 2) { Tcl_AppendResult(interp, "wrong # args; must be \"", argv[0], " window\"", (char *) NULL); return TCL_ERROR; } tkwin = (Tk_Window) clientData; winPtr = (TkWindow *) Tk_NameToWindow(interp, argv[1], tkwin); if (winPtr == NULL) { return TCL_ERROR; } wrapperPtr = TkpGetWrapperWindow(winPtr); if (wrapperPtr != NULL) { TkpPrintWindowId(interp->result, Tk_WindowId(wrapperPtr)); } return TCL_OK;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -