📄 tkconfig.c
字号:
break; case TK_CONFIG_CAP_STYLE: uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value); if (Tk_GetCapStyle(interp, uid, (int *) ptr) != TCL_OK) { return TCL_ERROR; } break; case TK_CONFIG_JOIN_STYLE: uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value); if (Tk_GetJoinStyle(interp, uid, (int *) ptr) != TCL_OK) { return TCL_ERROR; } break; case TK_CONFIG_PIXELS: if (Tk_GetPixels(interp, tkwin, value, (int *) ptr) != TCL_OK) { return TCL_ERROR; } break; case TK_CONFIG_MM: if (Tk_GetScreenMM(interp, tkwin, value, (double *) ptr) != TCL_OK) { return TCL_ERROR; } break; case TK_CONFIG_WINDOW: { Tk_Window tkwin2; if (nullValue) { tkwin2 = NULL; } else { tkwin2 = Tk_NameToWindow(interp, value, tkwin); if (tkwin2 == NULL) { return TCL_ERROR; } } *((Tk_Window *) ptr) = tkwin2; break; } case TK_CONFIG_CUSTOM: if ((*specPtr->customPtr->parseProc)( specPtr->customPtr->clientData, interp, tkwin, value, widgRec, specPtr->offset) != TCL_OK) { return TCL_ERROR; } break; default: { sprintf(interp->result, "bad config table: unknown type %d", specPtr->type); return TCL_ERROR; } } specPtr++; } while ((specPtr->argvName == NULL) && (specPtr->type != TK_CONFIG_END)); return TCL_OK;}/* *-------------------------------------------------------------- * * Tk_ConfigureInfo -- * * Return information about the configuration options * for a window, and their current values. * * Results: * Always returns TCL_OK. Interp->result will be modified * hold a description of either a single configuration option * available for "widgRec" via "specs", or all the configuration * options available. In the "all" case, the result will * available for "widgRec" via "specs". The result will * be a list, each of whose entries describes one option. * Each entry will itself be a list containing the option's * name for use on command lines, database name, database * class, default value, and current value (empty string * if none). For options that are synonyms, the list will * contain only two values: name and synonym name. If the * "name" argument is non-NULL, then the only information * returned is that for the named argument (i.e. the corresponding * entry in the overall list is returned). * * Side effects: * None. * *-------------------------------------------------------------- */intTk_ConfigureInfo(interp, tkwin, specs, widgRec, argvName, flags) Tcl_Interp *interp; /* Interpreter for error reporting. */ Tk_Window tkwin; /* Window corresponding to widgRec. */ Tk_ConfigSpec *specs; /* Describes legal options. */ char *widgRec; /* Record whose fields contain current * values for options. */ char *argvName; /* If non-NULL, indicates a single option * whose info is to be returned. Otherwise * info is returned for all options. */ int flags; /* Used to specify additional flags * that must be present in config specs * for them to be considered. */{ register Tk_ConfigSpec *specPtr; int needFlags, hateFlags; char *list; char *leader = "{"; needFlags = flags & ~(TK_CONFIG_USER_BIT - 1); if (Tk_Depth(tkwin) <= 1) { hateFlags = TK_CONFIG_COLOR_ONLY; } else { hateFlags = TK_CONFIG_MONO_ONLY; } /* * If information is only wanted for a single configuration * spec, then handle that one spec specially. */ Tcl_SetResult(interp, (char *) NULL, TCL_STATIC); if (argvName != NULL) { specPtr = FindConfigSpec(interp, specs, argvName, needFlags, hateFlags); if (specPtr == NULL) { return TCL_ERROR; } interp->result = FormatConfigInfo(interp, tkwin, specPtr, widgRec); interp->freeProc = TCL_DYNAMIC; return TCL_OK; } /* * Loop through all the specs, creating a big list with all * their information. */ for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) { if ((argvName != NULL) && (specPtr->argvName != argvName)) { continue; } if (((specPtr->specFlags & needFlags) != needFlags) || (specPtr->specFlags & hateFlags)) { continue; } if (specPtr->argvName == NULL) { continue; } list = FormatConfigInfo(interp, tkwin, specPtr, widgRec); Tcl_AppendResult(interp, leader, list, "}", (char *) NULL); ckfree(list); leader = " {"; } return TCL_OK;}/* *-------------------------------------------------------------- * * FormatConfigInfo -- * * Create a valid Tcl list holding the configuration information * for a single configuration option. * * Results: * A Tcl list, dynamically allocated. The caller is expected to * arrange for this list to be freed eventually. * * Side effects: * Memory is allocated. * *-------------------------------------------------------------- */static char *FormatConfigInfo(interp, tkwin, specPtr, widgRec) Tcl_Interp *interp; /* Interpreter to use for things * like floating-point precision. */ Tk_Window tkwin; /* Window corresponding to widget. */ register Tk_ConfigSpec *specPtr; /* Pointer to information describing * option. */ char *widgRec; /* Pointer to record holding current * values of info for widget. */{ char *argv[6], *result; char buffer[200]; Tcl_FreeProc *freeProc = (Tcl_FreeProc *) NULL; argv[0] = specPtr->argvName; argv[1] = specPtr->dbName; argv[2] = specPtr->dbClass; argv[3] = specPtr->defValue; if (specPtr->type == TK_CONFIG_SYNONYM) { return Tcl_Merge(2, argv); } argv[4] = FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer, &freeProc); if (argv[1] == NULL) { argv[1] = ""; } if (argv[2] == NULL) { argv[2] = ""; } if (argv[3] == NULL) { argv[3] = ""; } if (argv[4] == NULL) { argv[4] = ""; } result = Tcl_Merge(5, argv); if (freeProc != NULL) { if ((freeProc == TCL_DYNAMIC) || (freeProc == (Tcl_FreeProc *) free)) { ckfree(argv[4]); } else { (*freeProc)(argv[4]); } } return result;}/* *---------------------------------------------------------------------- * * FormatConfigValue -- * * This procedure formats the current value of a configuration * option. * * Results: * The return value is the formatted value of the option given * by specPtr and widgRec. If the value is static, so that it * need not be freed, *freeProcPtr will be set to NULL; otherwise * *freeProcPtr will be set to the address of a procedure to * free the result, and the caller must invoke this procedure * when it is finished with the result. * * Side effects: * None. * *---------------------------------------------------------------------- */static char *FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer, freeProcPtr) Tcl_Interp *interp; /* Interpreter for use in real conversions. */ Tk_Window tkwin; /* Window corresponding to widget. */ Tk_ConfigSpec *specPtr; /* Pointer to information describing option. * Must not point to a synonym option. */ char *widgRec; /* Pointer to record holding current * values of info for widget. */ char *buffer; /* Static buffer to use for small values. * Must have at least 200 bytes of storage. */ Tcl_FreeProc **freeProcPtr; /* Pointer to word to fill in with address * of procedure to free the result, or NULL * if result is static. */{ char *ptr, *result; *freeProcPtr = NULL; ptr = widgRec + specPtr->offset; result = ""; switch (specPtr->type) { case TK_CONFIG_BOOLEAN: if (*((int *) ptr) == 0) { result = "0"; } else { result = "1"; } break; case TK_CONFIG_INT: sprintf(buffer, "%d", *((int *) ptr)); result = buffer; break; case TK_CONFIG_DOUBLE: Tcl_PrintDouble(interp, *((double *) ptr), buffer); result = buffer; break; case TK_CONFIG_STRING: result = (*(char **) ptr); if (result == NULL) { result = ""; } break; case TK_CONFIG_UID: { Tk_Uid uid = *((Tk_Uid *) ptr); if (uid != NULL) { result = uid; } break; } case TK_CONFIG_COLOR: { XColor *colorPtr = *((XColor **) ptr); if (colorPtr != NULL) { result = Tk_NameOfColor(colorPtr); } break; } case TK_CONFIG_FONT: { Tk_Font tkfont = *((Tk_Font *) ptr); if (tkfont != NULL) { result = Tk_NameOfFont(tkfont); } break; } case TK_CONFIG_BITMAP: { Pixmap pixmap = *((Pixmap *) ptr); if (pixmap != None) { result = Tk_NameOfBitmap(Tk_Display(tkwin), pixmap); } break; } case TK_CONFIG_BORDER: { Tk_3DBorder border = *((Tk_3DBorder *) ptr); if (border != NULL) { result = Tk_NameOf3DBorder(border); } break; } case TK_CONFIG_RELIEF: result = Tk_NameOfRelief(*((int *) ptr)); break; case TK_CONFIG_CURSOR: case TK_CONFIG_ACTIVE_CURSOR: { Tk_Cursor cursor = *((Tk_Cursor *) ptr); if (cursor != None) { result = Tk_NameOfCursor(Tk_Display(tkwin), cursor); } break; } case TK_CONFIG_JUSTIFY: result = Tk_NameOfJustify(*((Tk_Justify *) ptr)); break; case TK_CONFIG_ANCHOR: result = Tk_NameOfAnchor(*((Tk_Anchor *) ptr)); break; case TK_CONFIG_CAP_STYLE: result = Tk_NameOfCapStyle(*((int *) ptr)); break; case TK_CONFIG_JOIN_STYLE: result = Tk_NameOfJoinStyle(*((int *) ptr)); break; case TK_CONFIG_PIXELS: sprintf(buffer, "%d", *((int *) ptr)); result = buffer; break; case TK_CONFIG_MM: Tcl_PrintDouble(interp, *((double *) ptr), buffer); result = buffer; break; case TK_CONFIG_WINDOW: { Tk_Window tkwin; tkwin = *((Tk_Window *) ptr); if (tkwin != NULL) { result = Tk_PathName(tkwin); } break; } case TK_CONFIG_CUSTOM: result = (*specPtr->customPtr->printProc)( specPtr->customPtr->clientData, tkwin, widgRec, specPtr->offset, freeProcPtr); break; default: result = "?? unknown type ??"; } return result;}/* *---------------------------------------------------------------------- * * Tk_ConfigureValue -- * * This procedure returns the current value of a configuration * option for a widget. * * Results: * The return value is a standard Tcl completion code (TCL_OK or * TCL_ERROR). Interp->result will be set to hold either the value * of the option given by argvName (if TCL_OK is returned) or * an error message (if TCL_ERROR is returned). * * Side effects: * None. * *---------------------------------------------------------------------- */intTk_ConfigureValue(interp, tkwin, specs, widgRec, argvName, flags) Tcl_Interp *interp; /* Interpreter for error reporting. */ Tk_Window tkwin; /* Window corresponding to widgRec. */ Tk_ConfigSpec *specs; /* Describes legal options. */ char *widgRec; /* Record whose fields contain current * values for options. */ char *argvName; /* Gives the command-line name for the * option whose value is to be returned. */ int flags; /* Used to specify additional flags * that must be present in config specs * for them to be considered. */{ Tk_ConfigSpec *specPtr; int needFlags, hateFlags; needFlags = flags & ~(TK_CONFIG_USER_BIT - 1); if (Tk_Depth(tkwin) <= 1) { hateFlags = TK_CONFIG_COLOR_ONLY; } else { hateFlags = TK_CONFIG_MONO_ONLY; } specPtr = FindConfigSpec(interp, specs, argvName, needFlags, hateFlags); if (specPtr == NULL) { return TCL_ERROR; } interp->result = FormatConfigValue(interp, tkwin, specPtr, widgRec, interp->result, &interp->freeProc); return TCL_OK;}/* *---------------------------------------------------------------------- * * Tk_FreeOptions -- * * Free up all resources associated with configuration options. * * Results: * None. * * Side effects: * Any resource in widgRec that is controlled by a configuration * option (e.g. a Tk_3DBorder or XColor) is freed in the appropriate * fashion. * *---------------------------------------------------------------------- */ /* ARGSUSED */voidTk_FreeOptions(specs, widgRec, display, needFlags) Tk_ConfigSpec *specs; /* Describes legal options. */ char *widgRec; /* Record whose fields contain current * values for options. */ Display *display; /* X display; needed for freeing some * resources. */ int needFlags; /* Used to specify additional flags * that must be present in config specs * for them to be considered. */{ register Tk_ConfigSpec *specPtr; char *ptr; for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) { if ((specPtr->specFlags & needFlags) != needFlags) { continue; } ptr = widgRec + specPtr->offset; switch (specPtr->type) { case TK_CONFIG_STRING: if (*((char **) ptr) != NULL) { ckfree(*((char **) ptr)); *((char **) ptr) = NULL; } break; case TK_CONFIG_COLOR: if (*((XColor **) ptr) != NULL) { Tk_FreeColor(*((XColor **) ptr)); *((XColor **) ptr) = NULL; } break; case TK_CONFIG_FONT: Tk_FreeFont(*((Tk_Font *) ptr)); *((Tk_Font *) ptr) = NULL; break; case TK_CONFIG_BITMAP: if (*((Pixmap *) ptr) != None) { Tk_FreeBitmap(display, *((Pixmap *) ptr)); *((Pixmap *) ptr) = None; } break; case TK_CONFIG_BORDER: if (*((Tk_3DBorder *) ptr) != NULL) { Tk_Free3DBorder(*((Tk_3DBorder *) ptr)); *((Tk_3DBorder *) ptr) = NULL; } break; case TK_CONFIG_CURSOR: case TK_CONFIG_ACTIVE_CURSOR: if (*((Tk_Cursor *) ptr) != None) { Tk_FreeCursor(display, *((Tk_Cursor *) ptr)); *((Tk_Cursor *) ptr) = None; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -