Hypermedia programming is by its nature complex,
partly because of the variety of content
that must be dealt with,
and partly because the graphical user
interface forms an essential part of the
hypermedia application.
In this section, we will look at
an approach to graphical interface programming
that may best be characterized
as multi-paradigm programming.
Our approach,
embodied in the hush library (Eliëns, 1994),
combines the use of C++
and the script language Tcl.
The advantage of using C++ is its
robustness. The advantage of using
scripts is, clearly, flexibility.
A multi-paradigm approach offers
the best of both worlds.
Or the worst, for that matter.
The hush
library offers an interface to the Tcl/Tk
(window programming) toolkit,
and a
number
of multimedia devices,
including real-time synthesized audio and MPEG (Motion Pictures Experts Group)
software video.
The principal contribution of the approach
embodied in hush is that it offers
a type-secure solution for connecting
script code with C++ (and vice versa).
In particular, it allows one to associate
events with actions by means of
handler objects.
In addition, the hush library
allows the programmer to employ inheritance for
the development of possibly compound
widgets.
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.
\nop{
(such as a filechooser and an MPEG video widget).
}
The hush library offers
a C++ interface to the Tcl/Tk toolkit
and its extensions.
Moreover, a program created with hush
is itself an interpreter extending the
hush interpreter.
\label{Tcl/Tk}
Tcl/Tk
The language Tcl was first presented
in [Ousterhout90].
Tcl was announced as a flexible cshell-like
language, intended to be used for developing
an X11-based toolkit.
A year later, the Tk toolkit (based on Tcl)
was presented in [Ousterhout91].
From the start Tcl/Tk has received a lot of attention,
since it provides a flexible and convenient way in which
to develop quite powerful window applications.
The Tcl language offers variables, assignment
and a procedure construct.
Also it provides a number of control constructs,
facilities for manipulating strings
and built-in primitives giving access to the underlying
operating system.
The basic Tcl language may easily be extended
by associating a function written in C
with a command name.
Arguments given to the command are passed
as strings to the function defining the command.
The Tk toolkit is an extension of Tcl
with commands to create and configure widgets
for displaying text and graphics,
and providing facilities for window management.
The Tk toolkit, and the wish interpreter
based on Tk, provides a convenient way
to program X-window based applications.
Example
\zline{\fboxwish}
\hspace*{2.5cm}
\epsfbox{hello.eps}
Scripts
-- hello world
button .b -text "Hello, world" -command {
puts stdout "hello world"
}
pack .b
slide: A Wish example
The wish program is an interpreter for executing
Tcl/Tk scripts.
As an example of a wish script, look
at the hello world program in slide [tcl-example].
The hello world script defines a button that
displays Hello, world, and prints hello world
to standard output when it is
activated by pressing the left mouse button.
The language used to write this script
is simply Tcl with the commands defined by Tk,
such as the button command (needed to create
a button) and the pack command (that is used to map
the button to the screen).
The wish program actually provides an example
of a simple application based on Tcl/Tk.
It may easily be extended to include, for example,
3D-graphics by linking the appropriate
C libraries and defining the functions making
this functionality available as (new) Tcl commands.
To define Tcl commands in C,
the programmer has to define a command
function
and declare the function
to be a command in Tcl by
invoking the {\em Tcl_CreateCommand}
function.
Creating a command is done with reference
to an interpreter, which accounts for the
first argument of {\em Tcl_CreateCommand}.
The name of the command, as may be used
in a Tcl script must be given as a second argument,
and the C/C++ function defining the command as a third argument.
Finally, when declaring a command, the address
of a structure containing client data
may be stored, which may
be (the address of) the root window, for example.
When the function is invoked
as the result of executing the Tcl command,
the client data stored at
declaration time is passed as the first
argument to the function.
Since the type ClientData is actually defined
to be , the function must first
cast the client data argument to an appropriate
type.
Evidently, casting is error-prone.
Another problem with command functions
as used in the Tcl C API is that
permanent data are possible only
in the form of client data,
global variables or static local
variables.
Both client data and global variables
are unsafe by being too visible
and static local data are simply inelegant.