home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11619 < prev    next >
Encoding:
Text File  |  1992-07-27  |  3.1 KB  |  97 lines

  1. Organization: Senior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
  2. Path: sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!er1p+
  3. Newsgroups: comp.lang.c++
  4. Message-ID: <MeR3L4e00XQGISKrgK@andrew.cmu.edu>
  5. Date: Mon, 27 Jul 1992 13:43:32 -0400 
  6. From: Erik Riedel <er1p+@andrew.cmu.edu>
  7. Subject: Re: C++ and XtAddEventHandler()
  8. In-Reply-To: <1992Jul20.134344.17048@nuscc.nus.sg>
  9. Lines: 86
  10.  
  11.  
  12. Excerpts from netnews.comp.lang.c++: 20-Jul-92 C++ and
  13. XtAddEventHandler() by zhaocuie@iscs.nus.sg 
  14. >I'm using C++ to develop a GUI builder based on Motif, Xt, and X11.
  15. >Now I'm facing some problems. I need to call an Xt convienent function
  16. >        XtAddEventHandler(_w, event_mask, nonmaskable, proc, client_data)
  17. >to popup Motif popup menus. I wrote the codes as follows:
  18. >        void Simple::pop() {
  19. >                        ......
  20. >                        XtAddEventHandler(_w,
  21. >                                          ButtonPressMask,
  22. >                                          False,
  23. >                                          &Simple::postItEventHandler,
  24. >                                          (XtPointer) this);
  25. >                        ......
  26. >                           }
  27. >        void Simple::postItEventHandler(Widget, XtPointer clientData, XtPointe
  28. >r)
  29. >                        {
  30. >                                Simple *obj = (Simple *) clientData;
  31. >                                obj -> postIt();
  32. >                        }
  33. >        void Simple::postIt() {
  34. >                        .......
  35. >                          }
  36. >It does not work. The compiler said:
  37. >        error: bad argument 4 type for XtAddEventHandler(): void (*) (Widget,
  38. >        XtPointer, XtPointer) (XtEventHandler expected)
  39. >That means the type of the last argument of XtAddEventHandler() is not
  40. >properly.
  41. >Do you know how to call this function properly? Can anyone help me?
  42.  
  43. I don't know if you've already gotten a response (a quick look ahead in
  44. the captions shows you didn't, I'm a little behind in my new-group
  45. reading).
  46.  
  47. I have also been working on a C++/Motif GUI.  I have been using a public
  48. domain package called Widget Wrapper Library for most of the project
  49. (available as WWL-1.2 on export.lcs.mit.edu for instance).  I allows the
  50. encapsulation of widgets as C++ classes and makes the code considerably
  51. clearer (with a small overhead payment).  It allows callback functions
  52. to be member functions on Classes.  To solve your problem directly
  53. however we have a macro:
  54.  
  55. #define DECLARE_METHOD_ENTRY_F(f,t,m,ca) \
  56. void f(Widget ww,caddr_t c1,caddr_t c2){((t *)c1)->m(ww,(ca) c2) ; }
  57.  
  58. which can be used as follws:
  59.  
  60. DECLARE_METHOD_ENTRY_F (map_input_cb,Map,input_cb,XEvent *)
  61.  
  62. ...
  63.  
  64. XtAddEventHandler(view_widget, ButtonPressMask, FALSE, (XtEventHandler)
  65. map_input_cb, (XtPointer) this)
  66. ...
  67.  
  68. given the class:
  69.  
  70. class Map
  71. {
  72. public:
  73.     void input_cb(Widget w,XEvent *cb);
  74. }
  75.  
  76. ----
  77. The WWL code would reduce this to something like:
  78.  
  79. view_widget.SetInputCallback(this, (WWL_FUN)&Map::input_cb);
  80. ----
  81.  
  82. Hope this helps.
  83.  
  84. Erik Riedel
  85. GEMS Project
  86. Carnegie Mellon University (riedel@cmu.edu)
  87. Massachusetts Institute of Technology (riedel@athena.mit.edu)
  88.  
  89.  
  90.  
  91.  
  92.