[comp.windows.x] Problem with C++ and passing member functions to action translations

jmellby@m2.csc.ti.com (John Mellby) (02/07/91)

I have a problem with C++ and X/Motif interactions.  We have a class which
is designed to create a widget and interact with the widget to do something
on the screen.  The goal is for each instance of the class to create its
widget and set things up so that when various buttons are pushed, or
other user actions performed, the widget gets this event and can handle it.

Our first approach was to register callbacks as class member functions.
(As has been discussed in the C++ group, this meant we had to declare
these functions as static, and pass a pointer to the class instance
in the "client_data" from the callback.)

This worked until we realized that there were not callback lists for all the
user actions we wanted to handle.  (We eventually want to do this in
general for a number of different kinds of widgets.)  As I understand it,
each widget type only has a fixed set of callback types.
(I know, UTLS, but we don't have access to the Motif widget source.  We only
have a binary lisence.)

I see three approaches (looking through Douglas Young's X ... with Xt/Motif
book).

1. Putting an action into the translation table.
Problem: this only lets the function get called with a few strings
as parameters (what is the purpose of this anyway?) and because of the
problem passing C++ member functions (which have an implicit "this"
pointer) I lost the class instance I want to act on.
I might be able to keep a table mapping widgets to the class instances
which create them, but this is a horrible kludge!

2. Use Callbacks
Problem: stated above; there aren't (I think) callbacks defined for
all the user actions I want to handle.

3. Create Event Handlers.
I haven't done this before, and some sources (Dan Heller and Adrian Nye's
tutorial: "Programming X, Part I: The Xt Toolkit") suggest that
event handlers are inflexible and should not be used if possible.

Can anyone make any suggestions?

Our system is:
Sun Sparcstation 1+, SunOS 4.1, X11R4, OSF/Motif 1.0.3 (From ICS),
cfront 2.1
We wrote our own include files to translate the X includes to ANSI C/C++.

John R. Mellby                       Texas Instruments
jmellby@skvax1.ti.com                P.O.Box 869305, MS 8513
                                     Plano, Texas, 75266
(214)517-5370                       (214)575-6774
***********************************************
* "telephone companies are not stupid,        *
* at least for large values of ``stupid.''"   *
*               -- Mr. Protocol, Mark O'Brien *
***********************************************