Next: The ConstructWidget Method Up: Standard Initialization Methods Previous: Chaining Methods

 

The tixChainMethod call 

The above implementation of tixArrowButton:InitWidgetRec is correct but it may be cumbersome if we want to switch superclasses. For example, suppose we want to create a new base class TixArrowWidget, which presumably defines common attributes of any class that have arrows in them. Then, instead of deriving TixArrowButton directly from TixPrimitive, we decide to derive TixArrowButton from TixArrowWidget, which is in turn derived from TixPrimitive:

tixWidgetClass tixArrowWidget {
-superclass tixPrimitive
...
}
tixWidgetClass tixArrowButton {
-superclass tixArrowWidget
...
}

Now we would need to change all the method chaining calls in TixArrowButton from:

tixPrimitive:SomeMethod

to:

tixArrowWidget:SomeMethod

This may be a lot of work because you may have chained methods in many places in the original implementation of TixArrowButton.

The tixChainMethod command solves this problem. It will automatically find a superclass that defines the method we want to chain and calls this method for us. For example, the following is a better implementation of tixArrowButton:InitWidgetRec that uses tixChainMethod to avoid calling tixPrimitive:InitWidgetRec directly:

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. In general, if the method we want to chain has $1+n$arguments:

proc tixPrimitive:MethodToChain {w arg1 arg2 ... argn} {
...
}

We call it with the arguments in the following order

tixChainMethod $w MethodToChain $arg1 $arg2 ... $argn

We'll come back to more detailed discussion of tixChainMethod shortly. For the time being, let's take it for granted that tixChainMethod must be used in the three standard initialization methods: InitWidgetRec, ConstructWidget and SetBindings


http://tix.sourceforge.net