From 95fc05c4b143e413f10ddc9cb14e4d322cca5e94 Mon Sep 17 00:00:00 2001 From: ericm Date: Fri, 29 Sep 2000 17:55:30 +0000 Subject: * generic/tkTest.c: Fixed tests to use updated API. * doc/SetOptions.3: * generic/tk.h: * generic/tkConfig.c: Changed interface for Tk_CustomOptionSetProc and Tk_CustomOptionGetProc; these now take a pointer to the start of the widget record, and an integer offset to the slot for the option value, instead of just a pointer to the slot. This allows more sophisticated options to do interesting things based on other data in the widget record. --- ChangeLog | 13 +++++++++++++ doc/SetOptions.3 | 39 +++++++++++++++++++++++---------------- generic/tk.h | 8 ++++---- generic/tkConfig.c | 8 +++++--- generic/tkTest.c | 33 +++++++++++++++++++-------------- 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index efc06dc..dc54921 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2000-09-29 Eric Melski + + * generic/tkTest.c: Fixed tests to use updated API. + + * doc/SetOptions.3: + * generic/tk.h: + * generic/tkConfig.c: Changed interface for Tk_CustomOptionSetProc + and Tk_CustomOptionGetProc; these now take a pointer to the start + of the widget record, and an integer offset to the slot for the + option value, instead of just a pointer to the slot. This allows + more sophisticated options to do interesting things based on other + data in the widget record. + 2000-09-17 Eric Melski * generic/tk.h: Added declaration of Tk_ObjCustomOption structure, diff --git a/doc/SetOptions.3 b/doc/SetOptions.3 index bef4ed5..7bb8e51 100644 --- a/doc/SetOptions.3 +++ b/doc/SetOptions.3 @@ -4,7 +4,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: SetOptions.3,v 1.6 2000/09/17 21:02:39 ericm Exp $ +'\" RCS: @(#) $Id: SetOptions.3,v 1.7 2000/09/29 17:55:30 ericm Exp $ '\" .so man.macros .TH Tk_SetOptions 3 8.1 Tk "Tk Library Procedures" @@ -527,14 +527,16 @@ typedef int Tk_CustomOptionSetProc( Tcl_Interp *\fIinterp\fR, Tk_Window \fItkwin\fR, Tcl_Obj **\fIvaluePtr\fR, - char *\fIinternalPtr\fR, + char *\fIrecordPtr\fR, + int \fIinternalOffset\fR, char *\fIsaveInternalPtr\fR, int \fIflags\fR); typedef Tcl_Obj *Tk_CustomOptionGetProc( ClientData \fIclientData\fR, Tk_Window \fItkwin\fR, - char *\fIinternalPtr\fR); + char *\fIrecordPtr\fR, + int \fIinternalOffset\fR); typedef void Tk_CustomOptionRestoreProc( ClientData \fIclientData\fR, @@ -581,15 +583,17 @@ stored at the objOffset for the option. \fISetProc\fR may modify the value if necessary; for example, \fIsetProc\fR may change the value to NULL to support the TK_OPTION_NULL_OK flag. .TP -\fIinternalPtr\fR -A pointer to the internal storage allocated for the option -in the widget record. The value referenced by \fIinternalPtr\fR -should be set to the internal representation of the new option value. +\fIrecordPtr\fR +A pointer to the start of the widget record to modify. +.TP +\fIinternalOffset\fR +Offset in bytes from the start of the widget record to the location +where the internal representation of the option value is to be placed. .TP \fIsaveInternalPtr\fR A pointer to storage allocated in a Tk_SavedOptions structure for the internal representation of the original option value. Before setting -\fIinternalPtr\fR to its new value, \fIsetProc\fR should set the value +the option to its new value, \fIsetProc\fR should set the value referenced by \fIsaveInternalPtr\fR to the original value of the option in order to support \fBTk_RestoreSavedOptions\fR. .TP @@ -608,10 +612,12 @@ The \fIgetProc\fR procedure is invoked by \fBTk_GetOptionValue\fR and internal representation of an option. The \fIclientData\fR argument is a copy of the \fIclientData\fR field in the Tk_ObjCustomOption structure. \fITkwin\fR is a copy of the \fItkwin\fR argument to -\fBTk_GetOptionValue\fR or \fBTk_GetOptionInfo\fR. \fIInternalPtr\fR -is a pointer to the internal representation of the option value. -\fIGetProc\fR must return a pointer to a Tcl_Obj representing the -value of the option. +\fBTk_GetOptionValue\fR or \fBTk_GetOptionInfo\fR. \fIRecordPtr\fR +is a pointer to the beginning of the widget record to query. +\fIInternalOffset\fR is the offset in bytes from the beginning of the +widget record to the location where the internal representation of the +option value is stored. \fIGetProc\fR must return a pointer to a +Tcl_Obj representing the value of the option. .PP The \fIrestoreProc\fR procedure is invoked by \fBTk_RestoreSavedOptions\fR to restore a previously saved internal @@ -619,7 +625,8 @@ representation of a custom option value. The \fIclientData\fR argument is a copy of the \fIclientData\fR field in the Tk_ObjCustomOption structure. \fITkwin\fR is a copy of the \fItkwin\fR argument to \fBTk_GetOptionValue\fR or \fBTk_GetOptionInfo\fR. \fIInternalPtr\fR -is a pointer to the internal representation of the option value. +is a pointer to the location where internal representation of the +option value is stored. \fISaveInternalPtr\fR is a pointer to the saved value. \fIRestoreProc\fR must copy the value from \fIsaveInternalPtr\fR to \fIinternalPtr\fR to restore the value. \fIRestoreProc\fR need not @@ -633,9 +640,9 @@ internal representation of a custom option. The \fIclientData\fR argument is a copy of the \fIclientData\fR field in the Tk_ObjCustomOption structure. \fITkwin\fR is a copy of the \fItkwin\fR argument to \fBTk_GetOptionValue\fR or \fBTk_GetOptionInfo\fR. \fIInternalPtr\fR -is a pointer to the internal representation of the option value. -The \fIfreeProc\fR must free any storage associated with the option. -\fIFreeProc\fR has no return value. +is a pointer to the location where the internal representation of the +option value is stored. The \fIfreeProc\fR must free any storage +associated with the option. \fIFreeProc\fR has no return value. .SH KEYWORDS diff --git a/generic/tk.h b/generic/tk.h index bbecf6a..e372b3c 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tk.h,v 1.50 2000/09/17 21:02:39 ericm Exp $ + * RCS: @(#) $Id: tk.h,v 1.51 2000/09/29 17:55:31 ericm Exp $ */ #ifndef _TK @@ -212,10 +212,10 @@ typedef struct Tk_OptionSpec { */ typedef int (Tk_CustomOptionSetProc) _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj **value, - char *internalPtr, char *saveInternalPtr, int flags)); + Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj **value, char *widgRec, + int offset, char *saveInternalPtr, int flags)); typedef Tcl_Obj *(Tk_CustomOptionGetProc) _ANSI_ARGS_((ClientData clientData, - Tk_Window tkwin, char *internalPtr)); + Tk_Window tkwin, char *widgRec, int offset)); typedef void (Tk_CustomOptionRestoreProc) _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin, char *internalPtr, char *saveInternalPtr)); typedef void (Tk_CustomOptionFreeProc) _ANSI_ARGS_((ClientData clientData, diff --git a/generic/tkConfig.c b/generic/tkConfig.c index 116a271..ad64aaf 100644 --- a/generic/tkConfig.c +++ b/generic/tkConfig.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkConfig.c,v 1.11 2000/09/17 21:02:39 ericm Exp $ + * RCS: @(#) $Id: tkConfig.c,v 1.12 2000/09/29 17:55:31 ericm Exp $ */ /* @@ -918,7 +918,8 @@ DoObjConfig(interp, recordPtr, optionPtr, valuePtr, tkwin, savedOptionPtr) case TK_OPTION_CUSTOM: { Tk_ObjCustomOption *custom = optionPtr->extra.custom; if (custom->setProc(custom->clientData, interp, tkwin, - &valuePtr, (char *)internalPtr, (char *)oldInternalPtr, + &valuePtr, recordPtr, optionPtr->specPtr->internalOffset, + (char *)oldInternalPtr, optionPtr->specPtr->flags) != TCL_OK) { return TCL_ERROR; } @@ -1939,7 +1940,8 @@ GetObjectForOption(recordPtr, optionPtr, tkwin) } case TK_OPTION_CUSTOM: { Tk_ObjCustomOption *custom = optionPtr->extra.custom; - objPtr = custom->getProc(custom->clientData, tkwin, internalPtr); + objPtr = custom->getProc(custom->clientData, tkwin, recordPtr, + optionPtr->specPtr->internalOffset); break; } default: { diff --git a/generic/tkTest.c b/generic/tkTest.c index b7a5652..891e7f6 100644 --- a/generic/tkTest.c +++ b/generic/tkTest.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkTest.c,v 1.13 2000/09/17 21:02:40 ericm Exp $ + * RCS: @(#) $Id: tkTest.c,v 1.14 2000/09/29 17:55:31 ericm Exp $ */ #include "tkInt.h" @@ -190,10 +190,10 @@ static int TestobjconfigObjCmd _ANSI_ARGS_((ClientData dummy, Tcl_Obj * CONST objv[])); static int CustomOptionSet _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, - Tcl_Obj **value, char *internalPtr, + Tcl_Obj **value, char *recordPtr, int internalOffset, char *saveInternalPtr, int flags)); static Tcl_Obj *CustomOptionGet _ANSI_ARGS_((ClientData clientData, - Tk_Window tkwin, char *internalPtr)); + Tk_Window tkwin, char *recordPtr, int internalOffset)); static void CustomOptionRestore _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin, char *internalPtr, char *saveInternalPtr)); @@ -2440,20 +2440,28 @@ TestwrapperCmd(clientData, interp, argc, argv) */ static int -CustomOptionSet(clientData,interp, tkwin, value, internalPtr, +CustomOptionSet(clientData,interp, tkwin, value, recordPtr, internalOffset, saveInternalPtr, flags) ClientData clientData; Tcl_Interp *interp; Tk_Window tkwin; Tcl_Obj **value; - char *internalPtr; + char *recordPtr; + int internalOffset; char *saveInternalPtr; int flags; { int objEmpty, length; - char *new, *string; + char *new, *string, *internalPtr; objEmpty = 0; + + if (internalOffset >= 0) { + internalPtr = recordPtr + internalOffset; + } else { + internalPtr = NULL; + } + /* * See if the object is empty. */ @@ -2473,11 +2481,7 @@ CustomOptionSet(clientData,interp, tkwin, value, internalPtr, } else { string = Tcl_GetStringFromObj((*value), &length); Tcl_UtfToUpper(string); - if (objEmpty) { - Tcl_SetResult(interp, "expected good value, got \"\"", TCL_STATIC); - return TCL_ERROR; - } - if (strncmp(string, "BAD", (size_t)length) == 0) { + if (strcmp(string, "BAD") == 0) { Tcl_SetResult(interp, "expected good value, got \"BAD\"", TCL_STATIC); return TCL_ERROR; @@ -2499,12 +2503,13 @@ CustomOptionSet(clientData,interp, tkwin, value, internalPtr, } static Tcl_Obj * -CustomOptionGet(clientData, tkwin, internalPtr) +CustomOptionGet(clientData, tkwin, recordPtr, internalOffset) ClientData clientData; Tk_Window tkwin; - char *internalPtr; + char *recordPtr; + int internalOffset; { - return (Tcl_NewStringObj(*(char **)internalPtr, -1)); + return (Tcl_NewStringObj(*(char **)(recordPtr + internalOffset), -1)); } static void -- cgit v0.12