A number of toolkits for the X11 environment with an interface to C++ do exist already. Well-known for example is the InterViews library, which offers powerful features for defining the layout of graphical user interfaces. See LVC89. However, despite the elegance of its design, InterViews is slightly cumbersome to use and lacks a number of the features and widgets needed for rapidly implementing a graphical user interface. Commercial packages for GUI (Graphical User Interface) programming in C++ are available. The disadvantage of these packages, apart from their price, is primarily that they do not offer the flexibility needed in a research environment.
A rather different approach to GUI programming has been advocated in Ousterhout91, which describes the Tcl/Tk toolkit. Tcl is a cshell-like (interpreted) script language that may be embedded in C or C++. Tk is a window and graphics toolkit based on X11, partly implemented in Tcl and partly in C. Tk offers numerous widgets, including a powerful canvas and text widget. Moreover, the Tcl scripting language allows the user to rapidly prototype rather complex graphical user interfaces by writing Tcl scripts. These scripts may be executed by using wish, the windowing shell interpreter that comes with Tk. Despite being based on Tcl, the performance of Tk (and wish) is comparable with (and in some respects even better than) C or C++ based toolkits.
The Tcl/Tk toolkit has become very popular in a rather short period of time. The popularity of Tcl/Tk is partly due to the extensibility of Tcl. New functionality, implemented in C, may easily be added by creating a new version of the wish interpreter, incorporating the additional commands. Numerous extensions to Tcl/Tk and corresponding interpreters have been made available, including extensions offering facilities for distributed programming (dp), extensions offering object oriented features ()\footnote{ may be read as a paraphrase of tcl++ in Tcl syntax. }, and extensions offering additional widgets such as a barchart and hypertext widget (blt).\footnote{ These extensions may be obtained from harbor.ecn.purdue.edu. }
The possibility of employing interpreted code and the availability of numerous widgets makes the Tcl/Tk toolkit (and its extensions) an ideal vehicle for implementing user interfaces. However, Tcl/Tk has its drawbacks as well. One problem, obviously, is to manage the large number of extensions. Ideally, there is one wish-like shell unifying the various features. Even better, one should have the opportunity to create such a shell in a simple manner. A second problem is that, when an application grows, script code will not always allow for an optimal solution. Generally, script code is not robust and may be hard to maintain. In particular, when an application contains many components not related to the user interface, efficiently compiled code may be more appropriate. For the latter problem, the obvious solution is to employ the C API (Application Programmer Interface) offered by Tcl and to create a new interpreter including the functionality needed. In a similar way, the first problem is rather easily solved by linking the appropriate libraries into an extended interpreter. Nevertheless, this is easier said than done. First of all, the C API offered for Tcl/Tk is rather demanding for the novice programmer and does not support a style of programming that is recommendable from a software engineering perspective. Secondly, although not very difficult, creating a new interpreter with additional C/C++ code is somewhat cumbersome. The hush library has been developed to address the two problems mentioned. Hush stands for hyper utility shell. The standard interpreter associated with the hush library is a shell, called hush, including a number of the available extensions of Tcl/Tk and widgets developed by ourselves (such as a filechooser and an MPEG video widget). The hush library offers a C++ interface to the Tcl/Tk toolkit and its extensions. It allows the programmer to employ the functionality of Tcl/Tk in a C++ program. Moreover, a program created with hush is itself an interpreter extending the hush interpreter (and wish). The hush library is explicitly intended to support the needs of both novice and experienced window programmers. Its C++ class interface should suffice for most applications, yet it allows for employing Tcl script code when more is demanded. The contribution of hush with respect to the Tcl/Tk toolkit is essentially that it provides a type-secure solution for connecting Tcl and C++ code. As an additional advantage, the hush library allows the programmer to employ inheritance for the development of possibly compound widgets. In particular, it provides the means to define composite widgets that behave as the standard Tk widgets. The class structure of the hush library is reminiscent to the class structure of the InterViews library. In comparison with the InterViews library, the widget class interfaces and event callbacks are significantly easier to use. Also, the hush library provides many more ready-to-use graphical interface widgets. However, hush does not offer resolution-independent graphics and provides no pre-defined classes for complex interactions. Summarizing, hush supports a multi-paradigm approach to window programming, allowing to combine the robustness of compiled C++ code with the flexibility of interpreted Tcl code. As such, it offers the best of both worlds. Or the worst, for that matter.
The material presented here requires at least some
knowledge of C++. See for example Stroustrup91.
Some familiarity
with Tcl/Tk is also helpful. See Ousterhout94.
Availability
The hush library has been in use for student programming
assignments at the Vrije Universiteit for two years.
It may be obtained by anonymous ftp from
ftp.cs.vu.nl
,
directory eliens/hush
.
You may also retrieve it via
www.cs.vu.nl/~eliens/hush/
.
Structure
In section Background,
some background information concerning Tcl/Tk is given.
Section Structure
sketches the structure of a typical
hush program
and gives an overview of the hush
class library, including the kit and session class.
Section Binding
describes how handler objects may be defined as
event callbacks.
Next, section User
presents a drawing tool application.
The application illustrates the use
of the various widget classes
and demonstrates how to construct compound
widgets.
In addition, it shows how a widget developed
in C++ may be made available
as a widget command to be used in scripts.
And finally, in section Graphics,
we will look at the facilities offered
for structured graphics and hypertext.