\fslide{eps-drawtool}{ The drawtool interface}{ \epsfbox{drawtool.eps} } In this section we will look at the realization of simple drawing tool. The example illustrates how to use the hush library widgets, and serves to illustrate in particular how handlers may be attached to widgets, either by declaration or by inheritance, and how to construct compound widgets. Our approach may be considered object-oriented, in the sense that each component of the user interface is defined by a class derived from a widget class. It must be pointed out beforehand that the main difficulty in defining compound or mega widgets is not the construction of the components themselves, but delegating the configuration and binding instructions to the appropriate components. Section new shows how a compound widget defined in C++ may be made to correspond to a widget command that may be used in a Tcl script. Ideally, defining a new widget includes both the definition of a C++ class interface and the definition of the corresponding Tcl command. Our drawing tool consists of a tablet, which is a canvas with scrollbars to allow for a large size canvas of which only a part is displayed, a {\em menu_bar}, having a File and an Edit menu, and a toolbox, which is a collection of buttons for selecting from among the drawing facilities. In addition, a help facility is offered. See slide eps-drawtool.
class application : public session {\c{\fbox{application}}
public: application(int argc, char* argv[]) : session(argc,argv,"drawtool") {} void main(kit* tk, int argc, char* argv[]) { widget* root = tk->root(); frame* f = new frame(root,".frame"); tablet* c = new tablet(f); toolbox* b = new toolbox(root,c); menubar* m = new menu_bar(f,c,b); tk->pack(m)->pack(c); tk->pack(b,"-side left")->pack(f,"-side right"); } };