Tk_SetOptions(3)
bestie, welcome to Tk_SetOptions(3) from the Tk Library Procedures π
β¨ we're doing configuration-option processing today and it's lowkey giving "group project but make it C" β but don't worry, the facts are all here and they're iconic.
β¨ NAME β¨
Okay so these functions are literally the whole configuration-option friend group, and they all process configuration options π«Ά:
Tk_CreateOptionTableTk_DeleteOptionTableTk_InitOptionsTk_SetOptionsTk_FreeSavedOptionsTk_RestoreSavedOptionsTk_GetOptionValueTk_GetOptionInfoTk_FreeConfigOptions
πΈ SYNOPSIS πΈ
#include <tk.h>
Tk_OptionTable
Tk_CreateOptionTable(interp, templatePtr)
Tk_DeleteOptionTable(optionTable)
int
Tk_InitOptions(interp, recordPtr, optionTable, tkwin)
int
Tk_SetOptions(interp, recordPtr, optionTable, objc, objv, tkwin, savePtr, maskPtr)
Tk_FreeSavedOptions(savedPtr)
Tk_RestoreSavedOptions(savedPtr)
Tcl_Obj *
Tk_GetOptionValue(interp, recordPtr, optionTable, namePtr, tkwin)
Tcl_Obj *
Tk_GetOptionInfo(interp, recordPtr, optionTable, namePtr, tkwin)
Tk_FreeConfigOptions(recordPtr, optionTable, tkwin)
π ARGUMENTS π
Tcl_Interp *interp (in)β a Tcl interpreter π most of these procedures use it only for returning error messages, so if it'sNULLthen no error messages get returned, periodt. But forTk_CreateOptionTablethe value cannot beNULLβ it gives the interpreter in which the option table will be used.const Tk_OptionSpec *templatePtr (in)β points to an array of static information describing the configuration options that are supported. It's used to build aTk_OptionTable. Big caveat bestie: the information pointed to by this argument must exist for the lifetime of theTk_OptionTableπTk_OptionTable optionTable (in)β token for an option table. It must have been returned by a previous call toTk_CreateOptionTableβ¨void *recordPtr (in/out)β points to the structure where values of configuration options are stored. Fields of this record are modified by procedures such asTk_SetOptionsand read by procedures such asTk_GetOptionValueπ¦Tk_Window tkwin (in)β for options such asTK_OPTION_COLOR, this argument indicates the window in which the option will be used. IfoptionTableuses no window-dependent options, then aNULLvalue may be supplied for this argument πTcl_Size objc (in)β number of values inobjvπ’Tcl_Obj *const *objv (in)β command-line arguments for setting configuring options πTk_SavedOptions *savePtr (out)β if notNULL, the structure pointed to by this argument is filled in with the old values of any options that were modified, and old values are restored automatically if an error occurs inTk_SetOptionsππint *maskPtr (out)β if notNULL, the word pointed to bymaskPtris filled in with the bit-wise OR of thetypeMaskfields for the options that were modified πTk_SavedOptions *savedPtr (in/out)β points to a structure previously filled in byTk_SetOptionswith old values of modified options πTcl_Obj *namePtr (in)β the value of this object is the name of a particular option. IfNULLis passed toTk_GetOptionInfothen information is returned for all options. It must not beNULLwhenTk_GetOptionValueis called βtype name type (in)β the name of the type of a record π§field name field (in)β the name of a field in records of typetypeπΈ
β¨ DESCRIPTION β¨
Okay bestie, so these procedures are literally the whole backstage crew for parsing configuration options β think the options on Tk widgets. You hand them a description of which options are supported, and they handle all the tedious little details: parsing the options, checking them, and stuffing their values into a C structure that belongs to the widget or object. They were designed mainly for widgets in Tk, but ngl they work for other kinds of objects that have configuration options too. In the rest of this manual page, βwidgetβ refers to whatever object's options are being managed β in practice it might not actually be a widget, no cap. And βwidget recordβ means the C-level structure where all the info about a particular widget or object lives. π
Small heads-up, bestie: the easiest way to learn how to use these procedures is literally to look at a working example. In Tk, the simplest one is the code that implements the button family of widgets, which is intkButton.c. Other examples live intkSquare.candtkMenu.c. Go peek, it's giving tutorial energy. π
So to use these procedures, the code that implements the widget has to contain a static array of Tk_OptionSpec structures. That array is a template describing the various options supported by that class of widget β and yes, there's a separate template for each kind of widget. The template holds things like the name of each option, its type, its default value, and where the option's value gets stored in the widget record. More deets in TEMPLATES below. π¦
Now, to process configuration options efficiently, that static template has to get augmented with extra info that's only available at runtime. Enter Tk_CreateOptionTable β it creates this dynamic info from the template and returns a Tk_OptionTable token describing both the static and the dynamic info. All the other procedures, like Tk_SetOptions, take a Tk_OptionTable token as an argument. Typically Tk_CreateOptionTable gets called the first time a widget of a particular class is created, and the resulting Tk_OptionTable is reused for all widgets of that class forever after. β¨
β οΈ Important vibe check: aTk_OptionTablemay be used only in a single interpreter, given by theinterpargument toTk_CreateOptionTable.
When an option table is no longer needed, call Tk_DeleteOptionTable to free all of its resources. And if the interpreter itself gets deleted, all the option tables for that Tcl interpreter are freed automatically. Slay, no memory leaks. π«Ά
Tk_InitOptions gets invoked when a new widget is created, to set the default values. It's passed a token for an option table (optionTable) and a pointer to a widget record (recordPtr) β that's the C structure holding info about this widget. Tk_InitOptions uses the info in the option table to pick an appropriate default for each option, then stores that default value directly into the widget record, overwriting any info that was already chilling there. Tk_InitOptions normally returns TCL_OK. But if an error happened while setting the default values (like, say, a default value was erroneous π), then TCL_ERROR is returned and an error message is left in interp's result β but only if interp isn't NULL. And for any widget's configuration option that has TK_OPTION_DONT_SET_DEFAULT set in its flags field, the whole initialization above is fully skipped. See below, bestie. π
Tk_SetOptions gets invoked to modify configuration options based on info specified in a Tcl command. That command might be one that creates a new widget, or one that modifies options on an existing widget. The objc and objv arguments describe the values of the arguments from the Tcl command. And listen: objv must contain an even number of objects β the first object of each pair gives the name of an option, and the second object gives the new value for that option. Tk_SetOptions looks up each name in optionTable, checks that the new value conforms to the type in optionTable, and stores the option's value into the widget record given by recordPtr. Tk_SetOptions normally returns TCL_OK. If an error occurred (like an unknown option name or an illegal option value), then TCL_ERROR is returned and an error message is left in interp's result if interp is not NULL. π
Tk_SetOptions has two extra features, and honestly? They ate. π₯
Feature one: if the maskPtr argument isn't NULL, then it points to an integer value that gets filled in with info about which options were modified. For each option in the template passed to Tk_CreateOptionTable, there's a typeMask field. The bits of that field are defined by the code that implements the widget β for example, each bit might correspond to a particular configuration option. Or, alternatively, bits might be used functionally. Like, one bit might be used for redisplay: all options that affect the widget's display, such that changing the option requires the widget to be redisplayed, might have that bit set. Another bit might indicate that the widget's geometry has to be recomputed, and so on. Tk_SetOptions OR's together the typeMask fields from all the options that were modified and returns this value at *maskPtr. The caller can then use that info to optimize itself β so, for example, it doesn't redisplay the widget if the modified options don't affect the widget's appearance. Efficiency icon behaviour, honestly. β
Feature two: this one's about error recovery. If an error occurs while processing configuration options, this feature makes it possible to restore all the configuration options to their previous values. Errors can happen either while processing options in Tk_SetOptions or later, in the caller. In many cases the caller does extra processing after Tk_SetOptions returns β for example, it might use an option value to set a trace on a variable and detect an error if the variable is an array instead of a scalar. Error recovery gets enabled by passing a non-NULL value for the savePtr argument to Tk_SetOptions; that should be a pointer to an uninitialized Tk_SavedOptions structure on the caller's stack. Tk_SetOptions overwrites the structure pointed to by savePtr with info about the old values of any options modified by the procedure.
If Tk_SetOptions returns successfully, the caller uses that structure in one of two ways:
- If the caller finishes processing the new options without any errors, then it must pass the structure to
Tk_FreeSavedOptionsso the old values can be freed. - If the caller detects an error in its processing of the new options, then it should pass the structure to
Tk_RestoreSavedOptions, which copies the old values back into the widget record and frees the new values.
If Tk_SetOptions itself detects an error, then it automatically restores any options that had already been modified and leaves *savePtr in an empty state β so the caller doesn't need to call either Tk_FreeSavedOptions or Tk_RestoreSavedOptions. π§
π But if thesavePtrargument toTk_SetOptionsisNULL, thenTk_SetOptionsfrees each old option value immediately when it sets a new value for that option. In that case, if an error occurs in the third option, the old values for the first two options cannot be restored. So likeβ¦ choose wisely, bestie.
Tk_GetOptionValue returns the current value of a configuration option for a particular widget. The namePtr argument contains the name of an option; Tk_GetOptionValue uses optionTable to look up the option and extract its value from the widget record pointed to by recordPtr, then returns an object containing that value. If an error occurs (e.g., because namePtr contains an unknown option name), then NULL is returned and an error message is left in interp's result unless interp is NULL. πΈ
Tk_GetOptionInfo returns info about configuration options in a form suitable for configure widget commands. If the namePtr argument is not NULL, it points to an object giving the name of a configuration option; Tk_GetOptionInfo returns an object containing a list with five elements, which are:
- the name of the option,
- the name and class used for the option in the option database,
- the default value for the option,
- and the current value for the option.
If the namePtr argument is NULL, then Tk_GetOptionInfo returns info about all options in the form of a list of lists; each sublist describes one option. π
Synonym options are handled differently depending on whether namePtr is NULL:
- If
namePtrisNULL, then the sublist for each synonym option has only two elements, which are the name of the option and the name of the other option that it refers to. - If
namePtris non-NULLand names a synonym option, then the object returned is the five-element list for the other option that the synonym refers to.
If an error occurs (e.g., because namePtr contains an unknown option name), then NULL is returned and an error message is left in interp's result unless interp is NULL. π
Tk_FreeConfigOptions must be invoked when a widget is deleted. It frees all of the resources associated with any of the configuration options defined in recordPtr by optionTable. Cleanup queen behaviour, we love to see it. ππ
π TEMPLATES π
okay so the array of Tk_OptionSpec structures that you pass to Tk_CreateOptionTable through its templatePtr argument β that's the thing that describes all the configuration options a particular class of widgets supports. Every single structure describes one configuration option, and it's got these fields:
typedef struct {
Tk_OptionType type;
const char *optionName;
const char *dbName;
const char *dbClass;
const char *defValue;
Tcl_Size objOffset;
Tcl_Size internalOffset;
int flags;
const void *clientData;
int typeMask;
} Tk_OptionSpec;
let me walk you through it bestie, field by field π«Ά
typeβ says what kind of configuration option this is (likeTK_OPTION_COLORfor a color value, orTK_OPTION_INTfor an integer value). The type determines how the value of the option gets parsed (more on that below, don't worry).optionNameβ a string like-fontor-bg. It's the name used for the option in Tcl commands, and it's what gets passed to procedures via theobjcornamePtrarguments.dbNameanddbClassβ these two are used byTk_InitOptionsto look up a default value for this option in the option database. And heads up: ifdbNameisNULLthen the option database is not used byTk_InitOptionsfor this option.defValueβ the default value for this configuration option, for when no value was specified in the option database.objOffsetandinternalOffsetβ where to store the value of this option in the widget records (again, more below). And these should always be generated with theoffsetofmacro, no cap.flagsβ extra info that controls the processing of this configuration option (details below β¨).clientDataβ extra type-specific data that certain types need. For instance, forTK_OPTION_COLORtypes,clientDatais a string giving the default value to use on monochrome displays. Check the descriptions of the different types below for the deets.typeMaskβ the last field! It's used byTk_SetOptionsto return info about which options were actually modified. See the description ofTk_SetOptionsabove for that one.
So when Tk_InitOptions and Tk_SetOptions store the value of an option into the widget record, they've got two whole ways to do it, and it's giving choose-your-own-adventure:
- If the
objOffsetfield of theTk_OptionSpecis greater than or equal to zero, then the value of the option is stored as a(Tcl_Obj *)at the location in the widget record given byobjOffset. - If the
internalOffsetfield of theTk_OptionSpecis greater than or equal to zero, then the value of the option is stored in a type-specific internal form at the location in the widget record given byinternalOffset. Like, if the option's type isTK_OPTION_INTthen the internal form is an integer. - If the
objOffsetorinternalOffsetfield is negative, then the value is not stored in that form.
β οΈ At least one of the offsets must be greater than or equal to zero. That's not optional, bestie.
πΈ the flags field πΈ
The flags field is one or more bits ORed together. These are the flags that are supported:
TK_OPTION_NULL_OKβ if this bit is set for an option, then an empty string is accepted as the value for the option, and the resulting internal form will be aNULLpointer, a zero value, orNone, depending on the type of the option. If the flag is not set, then empty strings result in errors π.TK_OPTION_NULL_OKis typically used to let a feature be turned off entirely β e.g. set a cursor value toNoneso that a window simply inherits its parent's cursor. Not all option types support theTK_OPTION_NULL_OKflag; for the ones that do, there's an explicit indication of that fact in the descriptions below. iykyk.TK_OPTION_DONT_SET_DEFAULTβ if this bit is set for an option, then no default value will be set inTk_InitOptionsfor this option. Neither the option database, nor any system default value, noroptionTableare used to give a default value to this option. Instead it's assumed that the caller already supplied a default value in the widget code. main character energy: you're on your own.TK_OPTION_ENUM_VARβ if this value is set for an option, then it indicates that theinternalOffsetpoints to anenumvariable in stead of anintvariable. Only useful in combination withTK_OPTION_STRING_TABLE,TK_OPTION_BOOLEAN,TK_OPTION_ANCHOR,TK_OPTION_JUSTIFY, orTK_OPTION_ANCHOR.TK_OPTION_VAR(type)β if this value is set for an option, then it indicates that theinternalOffsetpoints to a type variable in stead of anintvariable. Only useful in combination withTK_OPTION_STRING_TABLEorTK_OPTION_BOOLEAN, or asTK_OPTION_VAR(Tcl_Size)withTK_OPTION_INT.
The type field of each Tk_OptionSpec structure determines how to parse the value of that configuration option. The legal values for type, and the corresponding actions, are described below π
. If the type requires a tkwin value to be passed into procedures like Tk_SetOptions, or if it uses the clientData field of the Tk_OptionSpec, then it's indicated explicitly; if it's not mentioned, the type requires neither tkwin nor clientData.
β¨ the types, one by one β¨
TK_OPTION_ANCHORβ the value must be a standard anchor position such asneorcenter. The internal form is aTk_Anchorvalue like the ones returned byTk_GetAnchorFromObj. This option type supports theTK_OPTION_NULL_OKflag; if the empty string is specified as the value for the option, the integer relief value is set toTK_ANCHOR_NULL.TK_OPTION_BITMAPβ the value must be a standard Tk bitmap name. The internal form is aPixmaptoken like the ones returned byTk_AllocBitmapFromObj. This option type requirestkwinto be supplied to procedures such asTk_SetOptions, and it supports theTK_OPTION_NULL_OKflag.TK_OPTION_BOOLEANβ the value must be a standard boolean value such astrueorno. The internal form is an integer with value0or1. Note that if theobjOffsetfield is not used, information about the original value of this option will be lost π. This option type supports theTK_OPTION_NULL_OKflag; if aNULLvalue is set, the internal representation is set to-1.TK_OPTION_BORDERβ the value must be a standard color name such asredor#ff8080. The internal form is aTk_3DBordertoken like the ones returned byTk_Alloc3DBorderFromObj. This option type requirestkwinto be supplied to procedures such asTk_SetOptions, and it supports theTK_OPTION_NULL_OKflag.TK_OPTION_COLORβ the value must be a standard color name such asredor#ff8080. The internal form is an(XColor *)token like the ones returned byTk_AllocColorFromObj. This option type requirestkwinto be supplied to procedures such asTk_SetOptions, and it supports theTK_OPTION_NULL_OKflag.TK_OPTION_CURSORβ the value must be a standard cursor name such ascrossor@foo. The internal form is aTk_Cursortoken like the ones returned byTk_AllocCursorFromObj. This option type requirestkwinto be supplied to procedures such asTk_SetOptions, and when the option is set the cursor for the window is changed by callingXDefineCursor. This option type also supports theTK_OPTION_NULL_OKflag.TK_OPTION_CUSTOMβ this option lets applications define new option types π. TheclientDatafield of the entry points to a structure defining the new option type. See the section CUSTOM OPTION TYPES below for details.TK_OPTION_DOUBLEβ the string value must be a floating-point number in the format accepted bystrtol. The internal form is a Cdoublevalue. This option type supports theTK_OPTION_NULL_OKflag; if aNULLvalue is set, the internal representation is set toNaN.TK_OPTION_ENDβ marks the end of the template. There must be aTk_OptionSpecstructure with typeTK_OPTION_ENDat the end of each template, periodt. If theclientDatafield of this structure is notNULL, then it points to an additional array ofTk_OptionSpec's, which is itself terminated by anotherTK_OPTION_ENDentry. Templates may be chained arbitrarily deeply β this feature lets common options be shared by several widget classes. iconic tbh.TK_OPTION_FONTβ the value must be a standard font name such asTimes 16. The internal form is aTk_Fonthandle like the ones returned byTk_AllocFontFromObj. This option type requirestkwinto be supplied to procedures such asTk_SetOptions, and it supports theTK_OPTION_NULL_OKflag.TK_OPTION_INTβ the string value must be an integer in the format accepted bystrtol(e.g.0and0xprefixes may be used to specify octal or hexadecimal numbers, respectively). The internal form is a Cintvalue. This option type supports theTK_OPTION_NULL_OKflag; if aNULLvalue is set, the internal representation is set toINT_MIN.TK_OPTION_INDEXβ the string value must be an index in the format accepted byTcl_GetIntForIndex()or the empty string. The internal form is a Cintvalue. If the string starts with-, the internal representation will be set toINT_MIN. If the string has the formend-???, then the result will be a negative number:-1stands forend,-2stands forend-1and so on. This option type supports theTK_OPTION_NULL_OKflag; if aNULLvalue is set, the internal representation is set toINT_MIN.TK_OPTION_JUSTIFYβ the value must be a standard justification value such asleft. The internal form is aTk_Justifylike the values returned byTk_GetJustifyFromObj. This option type supports theTK_OPTION_NULL_OKflag; if the empty string is specified as the value for the option, the integer relief value is set toTK_JUSTIFY_NULL.TK_OPTION_PIXELSβ the value must specify a screen distance such as2ior6.4. The internal form is an integer value giving a distance in pixels, like the values returned byTk_GetPixelsFromObj. Note that if theobjOffsetfield is not used, information about the original value of this option will be lost π. See OBJOFFSET VS. INTERNALOFFSET below for details. This option type supports theTK_OPTION_NULL_OKflag; if aNULLvalue is set, the internal representation is set toINT_MIN.
π
TK_OPTION_RELIEF
The value has to be a standard relief, bestie β think raised. The internal form is an integer relief value like TK_RELIEF_RAISED. This type is down with the TK_OPTION_NULL_OK flag, and if you set a NULL value, the internal representation gets set to TK_RELIEF_NULL. Slay.
β¨ TK_OPTION_STRING
Honestly the most chill type β the value can be literally any string. The internal form is a (char *) pointer pointing at a dynamically allocated copy of the value. Also supports the TK_OPTION_NULL_OK flag. π
π¦ TK_OPTION_STRING_TABLE
For this one, clientData is a pointer to an array of strings, all set up nicely for passing to Tcl_GetIndexFromObj. The value has to be one of the strings in that table, or a unique abbreviation of one of them (iykyk). The internal form is an integer giving the index into the table of the matching string, like the return value from Tcl_GetStringFromObj. Supports TK_OPTION_NULL_OK too β and if a NULL value is set, the internal representation becomes -1.
π§ TK_OPTION_SYNONYM
This type is literally just for giving an option alternate names (classic example: -bg is often used as a synonym for -background). The clientData field is a string giving the name of another option in the same table, and whenever the synonym gets used, the info from that other option is used instead. Iconic behaviour, no notes.
π TK_OPTION_WINDOW
The value must be a window path name. The internal form is a Tk_Window token for that window. This type requires tkwin to be supplied to procedures like Tk_SetOptions (that's how it identifies the application), and yeah β it supports the TK_OPTION_NULL_OK flag.
π STORAGE MANAGEMENT ISSUES
Okay so this part is important, listen up π«Ά
If a field of a widget record has its offset stored in the objOffset or internalOffset field of a Tk_OptionSpec structure, then the procedures described here will handle all the storage allocation and resource management drama for that field. When the value of an option changes, Tk_SetOptions (or Tk_FreeSavedOptions) will automatically free whatever resources were tied to the old value β like Tk_Fonts for TK_OPTION_FONT options, or the dynamically allocated memory for TK_OPTION_STRING options. Zero manual cleanup required, we love to see it.
For an option stored as an object using the objOffset field of a Tk_OptionSpec, the widget record shares the object pointed to by the objv value from the call to Tk_SetOptions. The reference count for that object gets incremented when a pointer to it is stored in the widget record, and decremented when the option is modified. When the widget gets deleted, you should invoke Tk_FreeConfigOptions β it'll free the resources for all options and decrement reference counts for any objects.
But heads up bestie: the widget code is responsible for storing NULL or None in all pointer and token fields before invokingTk_InitOptions. This is required so proper cleanup can happen in the rare case where an error occurs inTk_InitOptions. Don't skip this step, fr fr. π
π OBJOFFSET VS. INTERNALOFFSET
In most cases it's simplest to use the internalOffset field of a Tk_OptionSpec structure and not the objOffset field. That way the internal form of the value is immediately available to the widget code, so you don't have to extract it from an object every single time you use it. Efficient queen behaviour. π
But there are two cases where the objOffset field is actually useful:
Case one: TK_OPTION_PIXELS options. Here the internal form is an integer pixel value that's only valid for a particular screen. If you retrieve the option's value, it comes back as a simple number. For example, after the command .b configure -borderwidth 2m, the command .b configure -borderwidth might return 7, which is the integer pixel value corresponding to 2m. Unfortunately that loses the original screen-independent value. So for TK_OPTION_PIXELS options it's better to use the objOffset field β the original value of the option stays in the object and can be returned when you retrieve it.
It might seem convenient to use the internalOffset field as well, so the integer value is immediately available in the widget code. But if scaling is involved, internalOffset won't change value when the scaling changes. So it's better to always use Tk_GetPixelsFromObj to extract the integer value from the object whenever it's needed. Note that the losing-information-on-retrieval problem exists only for TK_OPTION_PIXELS options. π
Case two: implementing new types of options that these procedures don't support. To do that, use TK_OPTION_STRING as the type in the Tk_OptionSpec structure and set the objOffset field but not the internalOffset field. Then, after calling Tk_SetOptions, convert the object to internal form yourself. DIY era. π οΈ
Also lowkey crucial: Ttk widgets do not support theinternalOffsetmachinery. Option values of Ttk widgets are always stored as(Tcl_Obj *), which means theobjOffsetfield must be used. No exceptions. πΈ
β¨ CUSTOM OPTION TYPES β¨
okay so bestie, here's the actual glow-up path: applications can extend the built-in configuration types with additional configuration types by writing procedures to parse, print, free, and restore saved copies of the type and creating a structure pointing to those procedures:
typedef struct {
const char *name;
Tk_CustomOptionSetProc *setProc;
Tk_CustomOptionGetProc *getProc;
Tk_CustomOptionRestoreProc *restoreProc;
Tk_CustomOptionFreeProc *freeProc;
void *clientData;
} Tk_ObjCustomOption;
typedef int Tk_CustomOptionSetProc(
void *clientData,
Tcl_Interp *interp,
Tk_Window tkwin,
Tcl_Obj **valuePtr,
char *recordPtr,
Tcl_Size internalOffset,
char *saveInternalPtr,
int flags);
typedef Tcl_Obj *Tk_CustomOptionGetProc(
void *clientData,
Tk_Window tkwin,
char *recordPtr,
Tcl_Size internalOffset);
typedef void Tk_CustomOptionRestoreProc(
void *clientData,
Tk_Window tkwin,
char *internalPtr,
char *saveInternalPtr);
typedef void Tk_CustomOptionFreeProc(
void *clientData,
Tk_Window tkwin,
char *internalPtr);
The Tk_ObjCustomOption structure contains six fields: a name for the custom option type; pointers to the four procedures; and a clientData value to be passed to those procedures when they are invoked. The clientData value typically points to a structure containing information that is needed by the procedures when they are parsing and printing options. restoreProc and freeProc may be NULL, indicating that no function should be called for those operations.
π οΈ the setProc procedure π οΈ
The setProc procedure is invoked by Tk_SetOptions to convert a Tcl_Obj into an internal representation and store the resulting value in the widget record. The arguments are:
clientDataβ a copy of theclientDatafield in theTk_ObjCustomOptionstructure.interpβ a pointer to a Tcl interpreter, used for error reporting.Tkwinβ a copy of thetkwinargument toTk_SetOptions.valuePtrβ a pointer to a reference to aTcl_Objdescribing the new value for the option; it could have been specified explicitly in the call toTk_SetOptionsor it could come from the option database or a default. If theobjOffsetfor the option is non-negative (the option value is stored as a(Tcl_Obj *)in the widget record), theTcl_Objpointer referenced byvaluePtris the pointer that will be stored at theobjOffsetfor the option.SetProcmay modify the value if necessary; for example,setProcmay change the value toNULLto support theTK_OPTION_NULL_OKflag.recordPtrβ a pointer to the start of the widget record to modify.internalOffsetβ 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.saveInternalPtrβ a pointer to storage allocated in aTk_SavedOptionsstructure for the internal representation of the original option value. Before setting the option to its new value,setProcshould set the value referenced bysaveInternalPtrto the original value of the option in order to supportTk_RestoreSavedOptions.flagsβ a copy of theflagsfield in theTk_OptionSpecstructure for the option.
SetProc returns a standard Tcl result: TCL_OK to indicate successful processing, or TCL_ERROR to indicate a failure of any kind. An error message may be left in the Tcl interpreter given by interp in the case of an error.
π¦ the getProc procedure π¦
The getProc procedure is invoked by Tk_GetOptionValue and Tk_GetOptionInfo to retrieve a Tcl_Obj representation of the internal representation of an option. The clientData argument is a copy of the clientData field in the Tk_ObjCustomOption structure. Tkwin is a copy of the tkwin argument to Tk_GetOptionValue or Tk_GetOptionInfo. RecordPtr is a pointer to the beginning of the widget record to query. InternalOffset 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. GetProc must return a pointer to a Tcl_Obj representing the value of the option.
π the restoreProc procedure π
The restoreProc procedure is invoked by Tk_RestoreSavedOptions to restore a previously saved internal representation of a custom option value. The clientData argument is a copy of the clientData field in the Tk_ObjCustomOption structure. Tkwin is a copy of the tkwin argument to Tk_GetOptionValue or Tk_GetOptionInfo. InternalPtr is a pointer to the location where internal representation of the option value is stored. SaveInternalPtr is a pointer to the saved value. RestoreProc must copy the value from saveInternalPtr to internalPtr to restore the value. RestoreProc need not free any memory associated with either internalPtr or saveInternalPtr; freeProc will be invoked to free that memory if necessary. RestoreProc has no return value.
π
the freeProc procedure π
The freeProc procedure is invoked by Tk_SetOptions and Tk_FreeSavedOptions to free any storage allocated for the internal representation of a custom option. The clientData argument is a copy of the clientData field in the Tk_ObjCustomOption structure. Tkwin is a copy of the tkwin argument to Tk_GetOptionValue or Tk_GetOptionInfo. InternalPtr is a pointer to the location where the internal representation of the option value is stored. The freeProc must free any storage associated with the option. FreeProc has no return value.
π§ KEYWORDS π§
the keyword lineup is literally: anchor, bitmap, boolean, border, color, configuration option, cursor, double, font, integer, justify, pixels, relief, screen distance, synonym.
okay that's the whole page, bestie π source/version: Tk 8.1; page: Tk_SetOptions(3); date: literally not in the footer, so no cap. go customize iconically β¨π«Άπ
π¦ where this page comes from
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- fedora 43: tk-devel 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk-devel 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk-devel 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk-devel 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- Copyright (c) 1998 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms