Xref: utzoo comp.lang.c++:5148 comp.windows.x:14446 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!gem.mps.ohio-state.edu!pacific.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucsd!ogccse!blake!keffer From: keffer@blake.acs.washington.edu (Thomas Keffer) Newsgroups: comp.lang.c++,comp.windows.x Subject: Re: using X11 with C++ callbacks Message-ID: <4126@blake.acs.washington.edu> Date: 20 Oct 89 19:01:20 GMT References: <640@sunquest.UUCP> <1948@bacchus.dec.com> Reply-To: keffer@blake.acs.washington.edu (Thomas Keffer) Organization: University of Washington, Seattle Lines: 33 In article <1948@bacchus.dec.com> haynes@gnome5.pa.dec.com (Charles Haynes) writes: >Use the "this" pointer as the client data in the X callback. Write a >generic wrapper function that takes a class pointer, and a pointer to a >method, and calls that method in that class. The method should have no >other args. Use the wrapper as the callback and the class as the client data. > This is essentially the strategy that I have followed with SunView except that I make the callback routine a static member function of the appropriate class (in my case, I have defined a ``Panel'' class that manages a window). The callback routine looks something like: void Panel::someButtonCallBack(Panel_item p, int value, Event *e) { PanelClient* this_client = panel_get(p, CLIENT_DATA); this_client->memberFunctionYouWantToCall(value); } Or something like that. Here, PanelClient is the object being maniupulated on behalf of the window. The advantage of using a static member function is to further encapsulation while giving you access to the appropriate member functions and variables. An example is available via anonymous ftp from sperm.ocean.washington.edu in file ~ftp/pub/spinup.tar.Z -Tom Keffer Rogue Wave P.O. Box 85341 Seattle Wa 98145-1341 (206) 523-5831