home *** CD-ROM | disk | FTP | other *** search
- Organization: Senior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
- Path: sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!er1p+
- Newsgroups: comp.lang.c++
- Message-ID: <MeR3L4e00XQGISKrgK@andrew.cmu.edu>
- Date: Mon, 27 Jul 1992 13:43:32 -0400
- From: Erik Riedel <er1p+@andrew.cmu.edu>
- Subject: Re: C++ and XtAddEventHandler()
- In-Reply-To: <1992Jul20.134344.17048@nuscc.nus.sg>
- Lines: 86
-
-
- Excerpts from netnews.comp.lang.c++: 20-Jul-92 C++ and
- XtAddEventHandler() by zhaocuie@iscs.nus.sg
- >I'm using C++ to develop a GUI builder based on Motif, Xt, and X11.
- >Now I'm facing some problems. I need to call an Xt convienent function
- > XtAddEventHandler(_w, event_mask, nonmaskable, proc, client_data)
- >to popup Motif popup menus. I wrote the codes as follows:
- >
- > void Simple::pop() {
- > ......
- > XtAddEventHandler(_w,
- > ButtonPressMask,
- > False,
- > &Simple::postItEventHandler,
- > (XtPointer) this);
- > ......
- > }
- >
- > void Simple::postItEventHandler(Widget, XtPointer clientData, XtPointe
- >r)
- > {
- > Simple *obj = (Simple *) clientData;
- > obj -> postIt();
- > }
- >
- > void Simple::postIt() {
- > .......
- > }
- >
- >It does not work. The compiler said:
- > error: bad argument 4 type for XtAddEventHandler(): void (*) (Widget,
- > XtPointer, XtPointer) (XtEventHandler expected)
- >That means the type of the last argument of XtAddEventHandler() is not
- >properly.
- >Do you know how to call this function properly? Can anyone help me?
- >
-
- I don't know if you've already gotten a response (a quick look ahead in
- the captions shows you didn't, I'm a little behind in my new-group
- reading).
-
- I have also been working on a C++/Motif GUI. I have been using a public
- domain package called Widget Wrapper Library for most of the project
- (available as WWL-1.2 on export.lcs.mit.edu for instance). I allows the
- encapsulation of widgets as C++ classes and makes the code considerably
- clearer (with a small overhead payment). It allows callback functions
- to be member functions on Classes. To solve your problem directly
- however we have a macro:
-
- #define DECLARE_METHOD_ENTRY_F(f,t,m,ca) \
- void f(Widget ww,caddr_t c1,caddr_t c2){((t *)c1)->m(ww,(ca) c2) ; }
-
- which can be used as follws:
-
- DECLARE_METHOD_ENTRY_F (map_input_cb,Map,input_cb,XEvent *)
-
- ...
-
- XtAddEventHandler(view_widget, ButtonPressMask, FALSE, (XtEventHandler)
- map_input_cb, (XtPointer) this)
- ...
-
- given the class:
-
- class Map
- {
- public:
- void input_cb(Widget w,XEvent *cb);
- }
-
- ----
- The WWL code would reduce this to something like:
-
- view_widget.SetInputCallback(this, (WWL_FUN)&Map::input_cb);
- ----
-
- Hope this helps.
-
- Erik Riedel
- GEMS Project
- Carnegie Mellon University (riedel@cmu.edu)
- Massachusetts Institute of Technology (riedel@athena.mit.edu)
-
-
-
-
-