home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / windows / openloo / 3640 < prev    next >
Encoding:
Text File  |  1992-08-29  |  3.9 KB  |  91 lines

  1. Newsgroups: comp.windows.open-look
  2. Path: sparky!uunet!mcsun!sunic!liuida!isy!isy.liu.se!svan
  3. From: svan@isy.liu.se (Jonas Svanberg)
  4. Subject: Re: Q: C++ and callback problems.
  5. Message-ID: <1992Aug28.161556.17176@isy.liu.se>
  6. Sender: news@isy.liu.se (Lord of the News)
  7. Reply-To: svan@isy.liu.se
  8. Organization: Linkoping University
  9. References: <BtoEBG.Gq7@solbourne.com>
  10. Date: Fri, 28 Aug 1992 16:15:56 GMT
  11. Lines: 78
  12.  
  13. > In article Gq7@solbourne.com, imp@solbourne.com (Warner Losh) writes:
  14. > If you really want to use member function callbacks (especially
  15. > virtuals), you should be using a C++ based toolkit.  It makes life so
  16. > much easier.  There are some commercial ones, plus some freely
  17. > distributable ones.  They make your life much simpler than trying to
  18. > kludge around the problem in a C based toolkit.
  19.  
  20. > Warner
  21.  
  22. > P.S.  You all should realize that I'm slightly biased on this issue. :-) 
  23. > -- 
  24. > Warner Losh        imp@Solbourne.COM
  25. > I've almost finished my brute force solution to subtlety.
  26.  
  27. How then do these toolkits handle callbacks/events?
  28.  
  29. As I see things there are only two ways. Suppose we want to create a
  30. Button. A Button is probably configurable in many sorts of ways:
  31. position, looks, colour and more. *BUT* it is when you want to 
  32. configure the way it respondes to a pushdown the trouble begins: 
  33.  
  34. 1) Cloning & modifying.
  35.    You create a Button-object and then modifies it by
  36.    registering your c-style callbackfunction.
  37.    The callback *HAS* to be a static memberfunction or an
  38.    ordinary c-style function (possibly a friend). The only 
  39.    other way I can think of is that a callback itself is an 
  40.    object with a method "exec" or whatever. That just pushes 
  41.    the problem further down the road.
  42.    The irritating part about this is that your toolkit probably
  43.    has information of both the callback and the object that
  44.    wants it and *still* you can't be called back the 
  45.    proper way. C++ just can't offer a portable way to implement 
  46.    such direct callbacks. Why has Borland C++ for Windows extended 
  47.    their language just to handle callbacks from Windows?
  48.  
  49. 2) Creating a new class.
  50.    You create a new Button-derived class where you redefine
  51.    the default buttonPressed-method (virtual). This won't do.
  52.    Probably one has a number of buttons in an application and
  53.    each press will trig some different action. It's a bore
  54.    to create one new class for every button, and if you create
  55.    a reusable Button-derived-class you have the same problem: 
  56.    How to distribute the pushdownevent to the right handler. You
  57.    can't put all handlers inside the button can you?
  58.  
  59. What I really would like is:
  60.  
  61.    To have the possibility to make calls to a memberfunction of
  62.    an object without having to know that objects particular class.
  63.    A sort of blindcall. But this feature could be made safe
  64.    enough. (That is: impossible to fail such a call as long as one
  65.    doesn't use explicit typecasts and the object still exists). It 
  66.    would probably be a first-order object/wrapper: pointer-to-member-
  67.    -of-specifik-type.
  68.    Such a wrapper can be used as an ordinary functionpointer when
  69.    calling but it can't be possible to (implicitely) cast it to one.
  70.    Though the reversed casting should be possible. A function
  71.    which takes a wrapper as an argument should also be able to
  72.    take an ordinary functionpointer as long as the parameter-
  73.    profile is the same. The resulting wrapper could be thought
  74.    of as a membercall to the global environment. 
  75.    Care must be taken when handling such wrappers since they
  76.    just like pointers could be obsolete.
  77.    
  78. All this was thought of when constructing C++ but of some strange 
  79. reason it wasn't included.
  80.  
  81.  
  82. Anybody agree?
  83.  
  84. --------------------------------------------------------------
  85.  Jonas Svanberg
  86.  Department of Electrical Engineering
  87.  Link÷ping University
  88.  S-581 83 Link÷ping, Sweden             Email: svan@isy.liu.se
  89. --------------------------------------------------------------
  90.  
  91.