Tk_SetOptions(3tk)
β¨ Tk_SetOptions β part 1 β¨
okay so bestie, welcome to Tk_SetOptions(3tk), the Tk Library Procedures page that runs the whole configuration-options department. this is part 1 of 4, so hydrate, get comfy, and let's go π
π NAME π
this page is the whole girl squad, and every single one of them is here to process configuration options:
Tk_CreateOptionTableTk_DeleteOptionTableTk_InitOptionsTk_SetOptionsTk_FreeSavedOptionsTk_RestoreSavedOptionsTk_GetOptionValueTk_GetOptionInfoTk_FreeConfigOptionsTk_Offset
that's the roster. ten icons. no cap. π
πΈ SYNOPSIS πΈ
the vibe check, verbatim, don't touch a character:
#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)
int
Tk_Offset(type, field)
π ARGUMENTS π
every parameter, explained like we're texting at 2am. all of them. yes, all of them. π«Ά
Tcl_Interp *interp(in) β a Tcl interpreter. most of these procedures only use it to hand back error messages, and if it'sNULLthen likeβ¦ no error messages get returned at all, silence, nothing. but forTk_CreateOptionTablethe value cannot beNULLβ it tells you which interpreter the option table is gonna live in.const Tk_OptionSpec *templatePtr(in) β points to an array of static info describing the configuration options that are supported. it's what you build aTk_OptionTableout of. β οΈ and the info it points to has to exist for the entire lifetime of theTk_OptionTableβ so don't you dare free that memory early, bestie.Tk_OptionTable optionTable(in) β the token for an option table. it must have come from a previous call toTk_CreateOptionTable, no improvising.char *recordPtr(in/out) β points to the structure where the values of the configuration options are stored. procedures likeTk_SetOptionsmodify the fields of this record, and procedures likeTk_GetOptionValueread them.Tk_Window tkwin(in) β for options likeTK_OPTION_COLOR, this tells you the window the option will be used in. if theoptionTableuses no window-dependent options, you can totally pass aNULLvalue here and it's fine.int objc(in) β the number of values inobjv.Tcl_Obj *const *objv(in) β command-line arguments for setting configuring options.Tk_SavedOptions *savePtr(out) β if it's notNULL, the structure it points to gets filled in with the old values of any options that were modified, and those old values get restored automatically if an error happens insideTk_SetOptions. it's giving built-in safety net β¨int *maskPtr(out) β if it's notNULL, the word it points to gets filled in with the bit-wise OR of thetypeMaskfields for the options that were modified.Tk_SavedOptions *savedPtr(in/out) β points to a structure that was previously filled in byTk_SetOptionswith the 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 info comes back for all the options. but 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.
that's part 1 done and dusted π¦ more parts incoming, don't go anywhere
β¨ DESCRIPTION β¨
okay bestie, so these procedures? They handle most of the details of parsing configuration options β like the ones Tk widgets have. You hand them a description of what options are supported, and they take care of all the parsing and storing into a C structure that's chained to the widget or object. They were designed primarily for widgets in Tk, but they can also be used for other kinds of objects that have configuration options. In the rest of this manual page, βwidgetβ will be used to refer to the object whose options are being managed; in practice the object may not actually be a widget. The term βwidget recordβ is used to refer to the C-level structure in which information about a particular widget or object is stored. π
Note that the easiest way to learn how to use these procedures is to look at a working example. In Tk, the simplest example is the code that implements the button family of widgets, which is in tkButton.c. Other examples are in tkSquare.c and tkMenu.c. literally go peek at those files, iykyk.
In order to use these procedures, the code that implements the widget must contain a static array of Tk_OptionSpec structures. This is a template that describes the various options supported by that class of widget; there is a separate template for each kind of widget. The template contains information such as the name of each option, its type, its default value, and where the value of the option is stored in the widget record. See TEMPLATES below for more detail. π
In order to process configuration options efficiently, the static template must be augmented with additional information that is available only at runtime. The procedure Tk_CreateOptionTable creates this dynamic information from the template and returns a Tk_OptionTable token that describes both the static and dynamic information. All of the other procedures, such as Tk_SetOptions, take a Tk_OptionTable token as argument. Typically, Tk_CreateOptionTable is called the first time that a widget of a particular class is created and the resulting Tk_OptionTable is used in the future for all widgets of that class. A Tk_OptionTable may be used only in a single interpreter, given by the interp argument to Tk_CreateOptionTable. When an option table is no longer needed Tk_DeleteOptionTable should be called to free all of its resources. All of the option tables for a Tcl interpreter are freed automatically if the interpreter is deleted. so like, one interpreter per table, periodt.
Tk_InitOptions is invoked when a new widget is created to set the default values. Tk_InitOptions is passed a token for an option table (optionTable) and a pointer to a widget record (recordPtr), which is the C structure that holds information about this widget. Tk_InitOptions uses the information in the option table to choose an appropriate default for each option, then it stores the default value directly into the widget record, overwriting any information that was already present in the widget record. Tk_InitOptions normally returns TCL_OK. If an error occurred while setting the default values (e.g., because a default value was erroneous) then TCL_ERROR is returned and an error message is left in interp's result if interp is not NULL. For any widget's configuration option that has TK_OPTION_DONT_SET_DEFAULT set in its flags field, the above initialization is fully skipped, see below. not me skipping the default when that flag is set π.
Tk_SetOptions is invoked to modify configuration options based on information specified in a Tcl command. The command might be one that creates a new widget, or a command that modifies options on an existing widget. The objc and objv arguments describe the values of the arguments from the Tcl command. 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 of the option conforms to the type in optionTable, and stores the value of the option into the widget record given by recordPtr. Tk_SetOptions normally returns TCL_OK. If an error occurred (such as 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. even number of objects, bestie, don't come at me with an odd one π.
Tk_SetOptions has two additional features. First, if the maskPtr argument is not NULL then it points to an integer value that is filled in with information about the options that were modified. For each option in the template passed to Tk_CreateOptionTable there is a typeMask field. The bits of this field are defined by the code that implements the widget; for example, each bit might correspond to a particular configuration option. Alternatively, bits might be used functionally. For example, 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 geometry of the widget must 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 this information to optimize itself so that, for example, it does not redisplay the widget if the modified options do not affect the widget's appearance. the way that maskPtr lets you skip unnecessary redraws? iconic.
The second additional feature of Tk_SetOptions has to do with 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 occur either while processing options in Tk_SetOptions or later in the caller. In many cases the caller does additional processing after Tk_SetOptions returns; for example, it might use an option value to set a trace on a variable and may detect an error if the variable is an array instead of a scalar. Error recovery is enabled by passing in a non-NULL value for the savePtr argument to Tk_SetOptions; this 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 information about the old values of any options modified by the procedure. If Tk_SetOptions returns successfully, the caller uses the structure in one of two ways. If the caller completes its processing of the new options without any errors, then it must pass the structure to Tk_FreeSavedOptions so that 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 will copy the old values back into the widget record and free the new values. If Tk_SetOptions detects an error then it automatically restores any options that had already been modified and leaves *savePtr in an empty state: the caller need not call either Tk_FreeSavedOptions or Tk_RestoreSavedOptions. If the savePtr argument to Tk_SetOptions is NULL then Tk_SetOptions frees each old option value immediately when it sets a new value for the option. In this case, if an error occurs in the third option, the old values for the first two options cannot be restored.
π¨ bestie, real talk: if savePtr is NULL, those old values get freed on the spot, so if the third option errors out, the first two are gone gone. no take-backs. π
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 lookup the option and extract its value from the widget record pointed to by recordPtr, then it 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. just hand over the current value, no drama.
Tk_GetOptionInfo returns information about configuration options in a form suitable for configure widget commands. If the namePtr argument is not NULL, it points to an object that gives 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 information 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 namePtr is NULL 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 namePtr is non-NULL and 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. five elements when you name one, list-of-lists when you don't, and synonyms get special treatment β it's giving configure-core energy β¨
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. clean up after yourself, bestie, no leaked options.
The Tk_Offset macro is provided as a safe way of generating the objOffset and internalOffset values for entries in Tk_OptionSpec structures. It takes two arguments: the name of a type of record, and the name of a field in that record. It returns the byte offset of the named field in records of the given type. safe offset math so you don't have to hardcode byte positions, 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 literally the blueprint of every config option a widget class supports π each structure in that array = one configuration option, and it looks like this:
typedef struct {
Tk_OptionType type;
const char *optionName;
const char *dbName;
const char *dbClass;
const char *defValue;
int objOffset;
int internalOffset;
int flags;
const void *clientData;
int typeMask;
} Tk_OptionSpec;
let's go field by field bestie, no skipping π«Ά
typeβ tells you what kind of option this is (likeTK_OPTION_COLORfor a color value, orTK_OPTION_INTfor an integer value). this is the field that decides how the value gets parsed (more on that in a sec).optionNameβ the string like-fontor-bg. it's the name used for the option in Tcl commands and the one passed to procedures through theobjcornamePtrarguments.dbNameanddbClassβ these are whatTk_InitOptionsuses to look up a default value for this option in the option database. and ifdbNameisNULL? thenTk_InitOptionsjust doesn't touch the option database for this option, periodt.defValueβ the default value for this configuration option, used when the option database didn't give you one.objOffsetandinternalOffsetβ these say where to stash the value of this option inside the widget record (again, more below π). and ngl, you should always generate these with theTk_Offsetmacro. always.flagsβ extra info that controls how this configuration option gets processed (details below β¨).clientDataβ extra type-specific data that certain types need. for example, forTK_OPTION_COLORtypes,clientDatais a string giving the default value to use on monochrome displays. the type descriptions below will fill you in.typeMaskβ the last one!Tk_SetOptionsuses this to hand back info about which options were modified. see the description ofTk_SetOptionsabove for the deets.
so when Tk_InitOptions and Tk_SetOptions store an option's value into the widget record, they've got two ways to do it:
- if the
objOffsetfield of theTk_OptionSpecis greater than or equal to zero, the value gets stored as a(Tcl_Obj *)at the spot in the widget record given byobjOffset. - if the
internalOffsetfield of theTk_OptionSpecis greater than or equal to zero, the value gets stored in a type-specific internal form at the spot given byinternalOffset. like, if the option's type isTK_OPTION_INTthen the internal form is an integer. - if either
objOffsetorinternalOffsetis negative, the value just isn't stored in that form.
and the rule: at least one of the offsets must be greater than or equal to zero. you can't skip both, bestie, that's not a vibe π
the flags field is one or more bits ORed together. here's what's supported:
TK_OPTION_NULL_OKβ if this bit is set for an option, then an empty string is accepted as the value, and the resulting internal form is aNULLpointer, a zero value, orNone, depending on the type of the option. if the flag is not set, empty strings = errors π.TK_OPTION_NULL_OKis typically used to let a feature be turned off entirely β like setting a cursor value toNoneso a window just inherits its parent's cursor. heads up tho: not all option types support theTK_OPTION_NULL_OKflag; for the ones that do, the descriptions below will say so explicitly.TK_OPTION_DONT_SET_DEFAULTβ if this bit is set for an option, then no default value gets set inTk_InitOptionsfor this option. neither the option database, nor any system default value, noroptionTableis used to give this option a default value. instead it's assumed that the caller already supplied a default value in the widget code. so like, you're on your own and that's the point π
the type field of each Tk_OptionSpec structure determines how to parse the value of that configuration option. the legal values for type, and what each one actually does, are described below. and if the type needs a tkwin value passed into procedures like Tk_SetOptions, or if it uses the clientData field of the Tk_OptionSpec, it's called out explicitly; if it's not mentioned, the type needs neither tkwin nor clientData.
β¨ the option types β¨
TK_OPTION_ANCHORβ the value must be a standard anchor position such asneorcenter. the internal form is aTk_Anchorvalue, like the onesTk_GetAnchorFromObjreturns.TK_OPTION_BITMAPβ the value must be a standard Tk bitmap name. the internal form is aPixmaptoken like the onesTk_AllocBitmapFromObjreturns. this option type needstkwinsupplied 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 isn't used, info about the original value of this option will be lost. πTK_OPTION_BORDERβ the value must be a standard color name such asredor#ff8080. the internal form is aTk_3DBordertoken like the onesTk_Alloc3DBorderFromObjreturns. this option type needstkwinsupplied 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 onesTk_AllocColorFromObjreturns. this option type needstkwinsupplied 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 onesTk_AllocCursorFromObjreturns. this option type needstkwinsupplied to procedures such asTk_SetOptions, and when the option is set, the cursor for the window is changed by callingXDefineCursor. it also supports theTK_OPTION_NULL_OKflag.TK_OPTION_CUSTOMβ this one 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 the whole story. main character energy tbh π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 to zero.TK_OPTION_ENDβ marks the end of the template. there must be aTk_OptionSpecstructure with typeTK_OPTION_ENDat the end of every template, no exceptions. and 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 is what lets common options be shared by several widget classes.TK_OPTION_FONTβ the value must be a standard font name such asTimes 16. the internal form is aTk_Fonthandle like the onesTk_AllocFontFromObjreturns. this option type needstkwinsupplied 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(so like,0and0xprefixes can be used to specify octal or hexadecimal numbers, respectively). the internal form is a Cintvalue.TK_OPTION_JUSTIFYβ the value must be a standard justification value such asleft. the internal form is aTk_Justify, like the valuesTk_GetJustifyFromObjreturns.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 valuesTk_GetPixelsFromObjreturns. note that if theobjOffsetfield isn't used, info 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 must be standard relief such asraised. the internal form is an integer relief value such asTK_RELIEF_RAISED. this option type supports theTK_OPTION_NULL_OKflag; if aNULLvalue is set, the internal representation is set toTK_RELIEF_NULL.TK_OPTION_STRINGβ the value may be any string. the internal form is a(char *)pointer that points to a dynamically allocated copy of the value. this option type supports theTK_OPTION_NULL_OKflag.TK_OPTION_STRING_TABLEβ for this type,clientDatais a pointer to an array of strings suitable for passing toTcl_GetIndexFromObj. the value must be one of the strings in the table, or a unique abbreviation of one of the strings. the internal form is an integer giving the index into the table of the matching string, like the return value fromTcl_GetStringFromObj. this option type supports theTK_OPTION_NULL_OKflag; if aNULLvalue is set, the internal representation is set to-1.TK_OPTION_SYNONYMβ this type gives you alternative names for an option (for example,-bgis often used as a synonym for-background). theclientDatafield is a string giving the name of another option in the same table. whenever the synonym option is used, the info from the other option gets used instead. so cute, so efficient πTK_OPTION_WINDOWβ the value must be a window path name. the internal form is aTk_Windowtoken for the window. this option type needstkwinsupplied to procedures such asTk_SetOptions(so it can identify the application), and it supports theTK_OPTION_NULL_OKflag.
ποΈ STORAGE MANAGEMENT ISSUES β¨
ok so listen bestie, this is the part where Tk is literally doing the most for you π
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 of the storage allocation and resource management stuff for that field. Like, all of it. You don't gotta lift a finger π«Ά
When the value of an option changes, Tk_SetOptions (or Tk_FreeSavedOptions) will automatically free any resources tied to the old value β think Tk_Fonts for TK_OPTION_FONT options, or dynamically allocated memory for TK_OPTION_STRING options. Auto-cleanup, no cap π§Ήβ¨
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. It's giving shared custody, honestly.
When the widget is deleted, Tk_FreeConfigOptions should be invoked β it'll free the resources for all options and decrement the reference counts for any objects.
β οΈ But heads up queen: the widget code is responsible for storingNULLorNonein all pointer and token fields before invokingTk_InitOptions. This is needed to allow proper cleanup in the rare case where an error occurs inTk_InitOptions. Don't skip this, fr fr π
π¦ OBJOFFSET VS. INTERNALOFFSET πΈ
okay so in most cases it's simplest to use the internalOffset field of a Tk_OptionSpec structure and not the objOffset field. Why? Because it makes the internal form of the value immediately available to the widget code, so the value doesn't have to be extracted from an object every single time it's used. Convenience, periodt π
However β and this is the plot twist β there are two cases where the objOffset field is actually useful:
- The first case is for
TK_OPTION_PIXELSoptions. Here the internal form is an integer pixel value that is valid only for a particular screen. If the value of the option is retrieved, it'll be returned as a simple number. For example, after the command.b configure -borderwidth 2m, the command.b configure -borderwidthmight return7, which is the integer pixel value corresponding to2m. Unfortunately, this loses the original screen-independent value π Thus forTK_OPTION_PIXELSoptions it's better to use theobjOffsetfield. In this case the original value of the option is retained in the object and can be returned when the option is retrieved. In most cases it's convenient to use theinternalOffsetfield as well, so that the integer value is immediately available for use in the widget code (alternatively,Tk_GetPixelsFromObjcan be used to extract the integer value from the object whenever it's needed). Note that the problem of losing information on retrievals exists only forTK_OPTION_PIXELSoptions. - The second reason to use the
objOffsetfield is in order to implement new types of options not supported by these procedures. To implement a new type of option, you can useTK_OPTION_STRINGas the type in theTk_OptionSpecstructure and set theobjOffsetfield but not theinternalOffsetfield. Then, after callingTk_SetOptions, convert the object to internal form yourself. DIY icon behaviour β¨
π Ttk widgets do not support theinternalOffsetmachinery. Option values of Ttk widgets are always stored as(Tcl_Obj *), meaning that theobjOffsetfield must be used. No exceptions, bestie.
π CUSTOM OPTION TYPES π§
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 Tk_ObjCustomOption {
const char *name;
Tk_CustomOptionSetProc *setProc;
Tk_CustomOptionGetProc *getProc;
Tk_CustomOptionRestoreProc *restoreProc;
Tk_CustomOptionFreeProc *freeProc;
ClientData clientData;
} Tk_ObjCustomOption;
typedef int Tk_CustomOptionSetProc(
ClientData clientData,
Tcl_Interp *interp,
Tk_Window tkwin,
Tcl_Obj **valuePtr,
char *recordPtr,
int internalOffset,
char *saveInternalPtr,
int flags);
typedef Tcl_Obj *Tk_CustomOptionGetProc(
ClientData clientData,
Tk_Window tkwin,
char *recordPtr,
int internalOffset);
typedef void Tk_CustomOptionRestoreProc(
ClientData clientData,
Tk_Window tkwin,
char *internalPtr,
char *saveInternalPtr);
typedef void Tk_CustomOptionFreeProc(
ClientData 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're invoked. The clientData value typically points to a structure containing information that's needed by the procedures when they're parsing and printing options. RestoreProc and freeProc may be NULL, indicating that no function should be called for those operations. (so valid, so optional π
)
β¨ 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
clientDataargument is a copy of theclientDatafield in theTk_ObjCustomOptionstructure. Tkwinis a copy of thetkwinargument toTk_GetOptionValueorTk_GetOptionInfo.RecordPtris a pointer to the beginning of the widget record to query.InternalOffsetis 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. no cap, that's the whole job π«‘
π the restoreProc procedure
The restoreProc procedure is invoked by Tk_RestoreSavedOptions to restore a previously saved internal representation of a custom option value.
- The
clientDataargument is a copy of theclientDatafield in theTk_ObjCustomOptionstructure. Tkwinis a copy of thetkwinargument toTk_GetOptionValueorTk_GetOptionInfo.InternalPtris a pointer to the location where internal representation of the option value is stored.SaveInternalPtris 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. (cleanup is somebody else's problem, iconic π
)
π 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
clientDataargument is a copy of theclientDatafield in theTk_ObjCustomOptionstructure. Tkwinis a copy of thetkwinargument toTk_GetOptionValueorTk_GetOptionInfo.InternalPtris 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. bye bye memory, you were real π§Ήβ¨
π₯ KEYWORDS π₯
anchorbitmapbooleanbordercolorconfiguration optioncursordoublefontintegerjustifypixelsreliefscreen distancesynonym
okay bestie that's the whole thing, you made it to the end π«Άβ¨ go forth and configure your widgets, you absolute icon π
this one's from Tk 8.1, page Tk_SetOptions(3tk) β stay slay, stay saved-options-safe, mwah ππ
π¦ where this page comes from
- debian trixie: tk8.6-doc 8.6.16-1
- ubuntu questing: tk8.6-doc 8.6.17-1
- ubuntu resolute: tk8.6-doc 8.6.17-1build1
- ubuntu stonking: tk8.6-doc 8.6.18-1
- Copyright (c) 1998 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms