@begin(header)
author: ackerman@ics.uci.edu
show_author: ShowNone
author_organization: MIT
expiration_date: 07/03/93
last_modifier: ackerman@ics.uci.edu
last_mod_date: 07/03/91
mod_num: 1
@end(header)
@begin(M)
Subject: Re: application design question 
From: Chris D. Peterson 


> Currently, the canvas is implemented as a Label widget (because labels
> are simple, and their size is easily controllable).  I add an event
> handler for the canvas which processes button, motion, enter/leave, and 
> exposure events.  The canvas and the control panel are children of a
> Form widget.  Basically, a plain window would be sufficient for the
> purpose of drawing.

> My question is: Is there a better/easier/cleaner way to implement the canvas?
> Any advice is welcome -- thanks!

Okay, you asked for it :-)

There are two methods of implementing something like this, one is to
do what you have done, that is to take and existing widget and hack it
up with a few XLib calls of your own, and thus make it do what you
want.  This approach, while not very clean and pretty does have the
advantage of being much easier to implement, you need not understand
any widget programming to get the behavior that you desire.  The
disadvantage is that the code that handles this is not usually very
self contatined, and unless you are very careful you will lose may of
the advantages that the toolkit gives you, such as well segmented user
interface objects, geometry management,and easy user customization.
Subclassability, of course, is now impossible.

The other way to approach this is to write your own widget to do the
job.  What most people fail to realize is that application writers are
encouraged to write their own custom widgets for their applications.
This approach will get you all of the nice features of Xt, and allow
you to seperate all the Xlib calls into the body of the widget itself.
This make testing of this chunk of code much simplier, as it can be
extracted into its own text program with ease.  If you are willing to
tackel widget programming then I would strongly urge you to try this
approach.

Some specific comments on your particular problem:

If you choose to stay with your current approach then you will save
some code by using the core widget rather than the label widget, It
appears that you are using none of the things that the label widget
provides above those provided by core, so you may want to just use
core instead.  The class name for core is "widgetClass".  Another
thing that you may want to look at is using application defined action
routines rather than the XtAddEventHandler interface that you are
currently using.  This will allow the user to change the event
bindings for the action. (e.g.  S/he would rather draw with button 3
down instead of button 1).
@end(M)
					




