Next: The ConstructWidget Method Up: Tix Object Oriented Previous: The InitWidgetRec Method


Chaining Methods

The above implementation is not sufficient because our TixArrowButton class is derived from TixPrimitive. The class derivation in Tix is basically an is-a relationship: TixArrowButton is a TixPrimitive. TixPrimitive defines the method tixPrimitive:InitWidgetRec which sets up the instance variables of every instance of TixPrimitive. Since an instance of TixArrowButton is also an instance of TixPrimitive, we need to make sure that the instance variables defined by TixPrimitive are also properly initialized. The technique of calling a method defined in a superclass is called the chaining of a method.

The tixChainMethod command will automatically find a superclass that defines the method we want to chain and calls this method for us. For example:

proc tixArrowButton:InitWidgetRec {w} {
    upvar #0 $w data

    tixChainMethod $w InitWidgetRec
    set data(count) 0
Notice the order of the arguments for tixChainMethod: the name of the instance, $w, is passed before the method we want to chain, InitWidgetRec.