diff options
Diffstat (limited to 'generic/tkOldConfig.c')
-rw-r--r-- | generic/tkOldConfig.c | 114 |
1 files changed, 68 insertions, 46 deletions
diff --git a/generic/tkOldConfig.c b/generic/tkOldConfig.c index 08c95f2..23259ec 100644 --- a/generic/tkOldConfig.c +++ b/generic/tkOldConfig.c @@ -5,8 +5,8 @@ * FOR BACKWARD COMPATIBILITY; THE NEW CONFIGURATION PACKAGE SHOULD BE * USED FOR NEW PROJECTS. * - * Copyright (c) 1990-1994 The Regents of the University of California. - * Copyright (c) 1994-1997 Sun Microsystems, Inc. + * Copyright © 1990-1994 The Regents of the University of California. + * Copyright © 1994-1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -14,6 +14,16 @@ #include "tkInt.h" +/* + * Values for "flags" field of Tk_ConfigSpec structures. Be sure to coordinate + * these values with those defined in tk.h (TK_CONFIG_COLOR_ONLY, etc.) There + * must not be overlap! + */ + +#ifndef TK_CONFIG_OPTION_SPECIFIED +# define TK_CONFIG_OPTION_SPECIFIED (1 << 4) +#endif + #ifdef _WIN32 #include "tkWinInt.h" #endif @@ -24,18 +34,18 @@ static int DoConfig(Tcl_Interp *interp, Tk_Window tkwin, Tk_ConfigSpec *specPtr, Tk_Uid value, - int valueIsUid, char *widgRec); + int valueIsUid, void *widgRec); static Tk_ConfigSpec * FindConfigSpec(Tcl_Interp *interp, Tk_ConfigSpec *specs, const char *argvName, int needFlags, int hateFlags); static char * FormatConfigInfo(Tcl_Interp *interp, Tk_Window tkwin, - const Tk_ConfigSpec *specPtr, char *widgRec); + const Tk_ConfigSpec *specPtr, void *widgRec); static const char * FormatConfigValue(Tcl_Interp *interp, Tk_Window tkwin, - const Tk_ConfigSpec *specPtr, char *widgRec, + const Tk_ConfigSpec *specPtr, void *widgRec, char *buffer, Tcl_FreeProc **freeProcPtr); static Tk_ConfigSpec * GetCachedSpecs(Tcl_Interp *interp, const Tk_ConfigSpec *staticSpecs); -static void DeleteSpecCacheTable(ClientData clientData, +static void DeleteSpecCacheTable(void *clientData, Tcl_Interp *interp); /* @@ -66,9 +76,9 @@ Tk_ConfigureWidget( Tk_Window tkwin, /* Window containing widget (needed to set up * X resources). */ const Tk_ConfigSpec *specs, /* Describes legal options. */ - int argc, /* Number of elements in argv. */ + Tcl_Size argc, /* Number of elements in argv. */ const char **argv, /* Command-line options. */ - char *widgRec, /* Record whose fields are to be modified. + void *widgRec, /* Record whose fields are to be modified. * Values must be properly initialized. */ int flags) /* Used to specify additional flags that must * be present in config specs for them to be @@ -88,8 +98,8 @@ Tk_ConfigureWidget( * we're on our way out of the application */ - Tcl_SetObjResult(interp, Tcl_NewStringObj("NULL main window", -1)); - Tcl_SetErrorCode(interp, "TK", "NO_MAIN_WINDOW", NULL); + Tcl_SetObjResult(interp, Tcl_NewStringObj("NULL main window", TCL_INDEX_NONE)); + Tcl_SetErrorCode(interp, "TK", "NO_MAIN_WINDOW", (char *)NULL); return TCL_ERROR; } @@ -121,7 +131,11 @@ Tk_ConfigureWidget( if (flags & TK_CONFIG_OBJS) { arg = Tcl_GetString((Tcl_Obj *) *argv); } else { +#if defined(TK_NO_DEPRECATED) || (TK_MAJOR_VERSION > 8) + Tcl_Panic("Flag TK_CONFIG_OBJS is mandatory"); +#else arg = *argv; +#endif } specPtr = FindConfigSpec(interp, staticSpecs, arg, needFlags, hateFlags); if (specPtr == NULL) { @@ -135,13 +149,17 @@ Tk_ConfigureWidget( if (argc < 2) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "value for \"%s\" missing", arg)); - Tcl_SetErrorCode(interp, "TK", "VALUE_MISSING", NULL); + Tcl_SetErrorCode(interp, "TK", "VALUE_MISSING", (char *)NULL); return TCL_ERROR; } if (flags & TK_CONFIG_OBJS) { arg = Tcl_GetString((Tcl_Obj *) argv[1]); } else { +#if defined(TK_NO_DEPRECATED) || (TK_MAJOR_VERSION > 8) + Tcl_Panic("Flag TK_CONFIG_OBJS is mandatory"); +#else arg = argv[1]; +#endif } if (DoConfig(interp, tkwin, specPtr, arg, 0, widgRec) != TCL_OK) { Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( @@ -265,7 +283,7 @@ FindConfigSpec( if (matchPtr != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "ambiguous option \"%s\"", argvName)); - Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName,NULL); + Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName, (char *)NULL); return NULL; } matchPtr = specPtr; @@ -274,7 +292,7 @@ FindConfigSpec( if (matchPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "unknown option \"%s\"", argvName)); - Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName, NULL); + Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName, (char *)NULL); return NULL; } @@ -292,7 +310,7 @@ FindConfigSpec( "couldn't find synonym for option \"%s\"", argvName)); Tcl_SetErrorCode(interp, "TK", "LOOKUP", "OPTION", argvName, - NULL); + (char *)NULL); return NULL; } if ((specPtr->dbName == matchPtr->dbName) @@ -333,15 +351,15 @@ DoConfig( Tk_Uid value, /* Value to use to fill in widgRec. */ int valueIsUid, /* Non-zero means value is a Tk_Uid; zero * means it's an ordinary string. */ - char *widgRec) /* Record whose fields are to be modified. + void *widgRec) /* Record whose fields are to be modified. * Values must be properly initialized. */ { - char *ptr; + void *ptr; Tk_Uid uid; int nullValue; nullValue = 0; - if ((*value == 0) && (specPtr->specFlags & (TK_CONFIG_NULL_OK|32 /* TCL_NULL_OK */))) { + if ((*value == 0) && (specPtr->specFlags & (TK_CONFIG_NULL_OK|TCL_NULL_OK|1))) { nullValue = 1; } @@ -349,20 +367,20 @@ DoConfig( if (specPtr->offset < 0) { break; } - ptr = widgRec + specPtr->offset; + ptr = (char *)widgRec + specPtr->offset; switch (specPtr->type) { case TK_CONFIG_BOOLEAN: - if (Tcl_GetBoolean(interp, value, (int *) ptr) != TCL_OK) { + if (Tcl_GetBoolean(interp, value, (int *)ptr) != TCL_OK) { return TCL_ERROR; } break; case TK_CONFIG_INT: - if (Tcl_GetInt(interp, value, (int *) ptr) != TCL_OK) { + if (Tcl_GetInt(interp, value, (int *)ptr) != TCL_OK) { return TCL_ERROR; } break; case TK_CONFIG_DOUBLE: - if (Tcl_GetDouble(interp, value, (double *) ptr) != TCL_OK) { + if (Tcl_GetDouble(interp, value, (double *)ptr) != TCL_OK) { return TCL_ERROR; } break; @@ -464,7 +482,7 @@ DoConfig( } case TK_CONFIG_RELIEF: uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value); - if (Tk_GetRelief(interp, uid, (int *) ptr) != TCL_OK) { + if (Tk_GetRelief(interp, uid, (int *)ptr) != TCL_OK) { return TCL_ERROR; } break; @@ -505,24 +523,26 @@ DoConfig( break; case TK_CONFIG_CAP_STYLE: uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value); - if (Tk_GetCapStyle(interp, uid, (int *) ptr) != TCL_OK) { + 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) { + 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) + if (nullValue) { + *(int *)ptr = INT_MIN; + } else 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) { + if (Tk_GetScreenMM(interp, tkwin, value, (double *)ptr) != TCL_OK) { return TCL_ERROR; } break; @@ -542,14 +562,14 @@ DoConfig( } case TK_CONFIG_CUSTOM: if (specPtr->customPtr->parseProc(specPtr->customPtr->clientData, - interp, tkwin, value, widgRec, specPtr->offset)!=TCL_OK) { + interp, tkwin, value, (char *)widgRec, specPtr->offset)!=TCL_OK) { return TCL_ERROR; } break; default: Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad config table: unknown type %d", specPtr->type)); - Tcl_SetErrorCode(interp, "TK", "BAD_CONFIG", NULL); + Tcl_SetErrorCode(interp, "TK", "BAD_CONFIG", (char *)NULL); return TCL_ERROR; } specPtr++; @@ -590,7 +610,7 @@ Tk_ConfigureInfo( Tcl_Interp *interp, /* Interpreter for error reporting. */ Tk_Window tkwin, /* Window corresponding to widgRec. */ const Tk_ConfigSpec *specs, /* Describes legal options. */ - char *widgRec, /* Record whose fields contain current values + void *widgRec, /* Record whose fields contain current values * for options. */ const char *argvName, /* If non-NULL, indicates a single option * whose info is to be returned. Otherwise @@ -630,7 +650,7 @@ Tk_ConfigureInfo( return TCL_ERROR; } list = FormatConfigInfo(interp, tkwin, specPtr, widgRec); - Tcl_SetObjResult(interp, Tcl_NewStringObj(list, -1)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(list, TCL_INDEX_NONE)); ckfree(list); return TCL_OK; } @@ -652,7 +672,7 @@ Tk_ConfigureInfo( continue; } list = FormatConfigInfo(interp, tkwin, specPtr, widgRec); - Tcl_AppendResult(interp, leader, list, "}", NULL); + Tcl_AppendResult(interp, leader, list, "}", (char *)NULL); ckfree(list); leader = " {"; } @@ -685,7 +705,7 @@ FormatConfigInfo( const Tk_ConfigSpec *specPtr, /* Pointer to information describing * option. */ - char *widgRec) /* Pointer to record holding current values of + void *widgRec) /* Pointer to record holding current values of * info for widget. */ { const char *argv[6]; @@ -717,9 +737,9 @@ FormatConfigInfo( result = Tcl_Merge(5, argv); if (freeProc != NULL) { if (freeProc == TCL_DYNAMIC) { - ckfree((char *) argv[4]); + ckfree((char *)argv[4]); } else { - freeProc((char *) argv[4]); + freeProc((char *)argv[4]); } } return result; @@ -751,7 +771,7 @@ FormatConfigValue( Tk_Window tkwin, /* Window corresponding to widget. */ const Tk_ConfigSpec *specPtr, /* Pointer to information describing option. * Must not point to a synonym option. */ - char *widgRec, /* Pointer to record holding current values of + void *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. */ @@ -766,7 +786,7 @@ FormatConfigValue( if (specPtr->offset < 0) { return NULL; } - ptr = widgRec + specPtr->offset; + ptr = (char *)widgRec + specPtr->offset; result = ""; switch (specPtr->type) { case TK_CONFIG_BOOLEAN: @@ -855,8 +875,10 @@ FormatConfigValue( result = Tk_NameOfJoinStyle(*((int *)ptr)); break; case TK_CONFIG_PIXELS: - snprintf(buffer, 200, "%d", *((int *)ptr)); - result = buffer; + if ((*(int *)ptr != INT_MIN) || !(specPtr->specFlags & (TK_CONFIG_NULL_OK|TCL_NULL_OK|1))) { + snprintf(buffer, 200, "%d", *((int *)ptr)); + result = buffer; + } break; case TK_CONFIG_MM: Tcl_PrintDouble(interp, *((double *)ptr), buffer); @@ -871,7 +893,7 @@ FormatConfigValue( } case TK_CONFIG_CUSTOM: result = specPtr->customPtr->printProc(specPtr->customPtr->clientData, - tkwin, widgRec, specPtr->offset, freeProcPtr); + tkwin, (char *)widgRec, specPtr->offset, freeProcPtr); break; default: result = "?? unknown type ??"; @@ -904,7 +926,7 @@ Tk_ConfigureValue( Tcl_Interp *interp, /* Interpreter for error reporting. */ Tk_Window tkwin, /* Window corresponding to widgRec. */ const Tk_ConfigSpec *specs, /* Describes legal options. */ - char *widgRec, /* Record whose fields contain current values + void *widgRec, /* Record whose fields contain current values * for options. */ const char *argvName, /* Gives the command-line name for the option * whose value is to be returned. */ @@ -937,12 +959,12 @@ Tk_ConfigureValue( } result = FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer, &freeProc); - Tcl_SetObjResult(interp, Tcl_NewStringObj(result, -1)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(result, TCL_INDEX_NONE)); if (freeProc != NULL) { if (freeProc == TCL_DYNAMIC) { - ckfree((char *) result); + ckfree((char *)result); } else { - freeProc((char *) result); + freeProc((char *)result); } } return TCL_OK; @@ -972,7 +994,7 @@ Tk_ConfigureValue( void Tk_FreeOptions( const Tk_ConfigSpec *specs, /* Describes legal options. */ - char *widgRec, /* Record whose fields contain current values + void *widgRec, /* Record whose fields contain current values * for options. */ Display *display, /* X display; needed for freeing some * resources. */ @@ -990,7 +1012,7 @@ Tk_FreeOptions( if (specPtr->offset < 0) { continue; } - ptr = widgRec + specPtr->offset; + ptr = (char *)widgRec + specPtr->offset; switch (specPtr->type) { case TK_CONFIG_STRING: if (*((char **) ptr) != NULL) { @@ -1156,7 +1178,7 @@ GetCachedSpecs( static void DeleteSpecCacheTable( - ClientData clientData, + void *clientData, TCL_UNUSED(Tcl_Interp *)) { Tcl_HashTable *tablePtr = (Tcl_HashTable *)clientData; |