Next: Using Tix with Up: Declaring and Using Previous: Initialization of Public

 

Public Variable Configuration Methods

After a widget instance is created, the user can assign new values to the public variables using the configure method. For example, the following code changes the -direction variable of the .arr instance to n.

.arr configure -direction n

In order for configuration to work, you have to define a configuration method that does what the programmer expects. The configuration method of a public variable is invoked whenever the user calls the configure method to change the value of this variable. The name of a configuration method must be the name of the public variable prefixed by the creation command of the class and :config. For example, the name configuration method for the -direction variable of the TixArrowButton class is tixArrowButton:config-direction. The following code implements this method:

proc tixArrowButton:config-direction \
        {w value} {
    upvar #0 $w data

    $data(w:button) config \
        -bitmap @$value.xbm
}

Notice that when tixArrowButton:config-direction is called, the value parameter contains the new value of the -direction variable but data(-direction) contains the old value. This is useful when the configuration method needs to check the previous value of the variable before taking in the new value.

If a type checker is defined for a variable, it will be called before the configuration method is called. Therefore, the configuration method can assume that the type of the value parameter is got is always correct.

If you do not need to override the value, you don't need to return anything from the configuration method. In this case, the Tix Intrinsics will assign the new value to the instance variable for you.

For efficiency reasons, the configuration methods are not called during the intialization of the public variables. If you want to force the configuration method to be called for a particular public variable, you can specify it in the -forcecall section of the class declaration. In the following example, we force the configuration method of the -direction variable to be called during intialization:

-forcecall {
    -direction
}


http://tix.sourceforge.net