Version 2 of Tk Style Support

Updated 2003-08-05 08:47:25

TIP #48 [L1 ] provides an API to support alternative styles for Tk widgets.

This TIP was implemented in March 2002, but there is very little other than the TIP itself to document how this might be used and what further work is required. (DKF - Further work required includes documentation, application to existing widgets, and plenty of tests...)

The basis of the Tk style API is to break down the Tk widgets into elements. Elements abstract objects for which an implementation may be registered with a given style engine. A style name can be used to select a set of element implementations and thus provide an alternative look to the Tk widgets.

As the Tk code stands for 8.5a0, we have this styling API (in generic/tkStyle.c) but no elements. This makes the API pretty useless for now, so the first job is to implement a set of elements and rewrite the Tk widgets to do their drawing using elements. Once this is done, then it becomes simple to replace an element dynamically because of the design of the element search algorithm.

To illustrate we can take the Tk frame widget. We can decompose this into a highlight and a frame element. Now what we actually register is an element called 'highlight'. However, what we try to use is an element called 'Frame.highlight'. If this can't be found, then the element search algorithm trims off the first word and tries again until it runs out of bits. This permits us to provide a generic implementation, and then override it for specific widgets.

So it seems to me that we can create a generic/tkElements.c file which contains all the elements we need for the core widgets. Then we can add a win/tkElementsXP.c which provides an alternative implementation that uses the XP theming API (uxtheme.dll) to do the drawing. Then selecting the proper default style should permit switching between Tk and XP styles at wish. The same should be possible for Gtk or KDE too.

[more to come] ...