home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:20057 comp.std.c++:2140
- Path: sparky!uunet!cimshop!davidm
- From: davidm@consilium.com (David S. Masterson)
- Newsgroups: comp.lang.c++,comp.std.c++
- Subject: Re: Callbacks -- suggested approaches??
- Message-ID: <DAVIDM.93Jan28111030@consilium.com>
- Date: 28 Jan 93 19:10:29 GMT
- References: <DAVIDM.93Jan25171343@consilium.com> <1k41efINN2oj@darkstar.UCSC.EDU>
- Sender: root@cimshop.UUCP
- Organization: Consilium Inc., Mountain View, California
- Lines: 47
- In-reply-to: spencer@cats.ucsc.edu's message of 26 Jan 93 18:55:11 GMT
- X-Posting-Software: GNUS 3.13 [ NNTP-based News Reader for GNU Emacs ]
-
- >>>>> On 26 Jan 93 18:55:11 GMT, spencer@cats.ucsc.edu (Michael Spencer) said:
-
- > WIDGET CALLBACKS
-
- > Widgets which use callbacks are similarly easy. XSimple widgets attach their
- > own callback and pass to it a reference to a coder written Procedure. The
- > callback calls the Procedure and passes to it a Choice object which contains
- > the data needed to respond to the event. For example, to activate a popup
- > dialog widget:
-
- > PopupYesno (parent, "Do it ?", YesnoProc); // evoke popup
- > void YesnoProc (Choice chose) // coder written to handle event
- > {
- > if (chose.flag)
- > // do something
- > else
- > // do something else
- > }
-
- > The coder written YesnoProc() defines what occurs based on the user's
- > election. Choice is an object (declared in XUTILS.H) which will hold any
- > information generated by any callback or event handler.
-
- > BUT, the coder need not become involved in the sordid details of adding the
- > callback to the widget or extracting the relevant information from the
- > returned callback struct. That is done automatically and the relevant
- > information is passed via the Choice data members.
-
- An interesting variation on the X-windows approach. However, I see a few
- (what I would call) holes in what you've shown above:
-
- 1. I assume PopupYesno is an object. If so, why isn't YesnoProc() a member
- function of the object? Wouldn't that help for maintenance?
-
- 2. Your Choice object appears to carry a type flag. Couldn't things be done
- virtually and eliminate this flag?
-
- 3. What if the information generated for a callback is not of type Choice?
- --
- ====================================================================
- David Masterson Consilium, Inc.
- (415) 691-6311 640 Clyde Ct.
- davidm@consilium.com Mtn. View, CA 94043
- ====================================================================
- "I'll put an end to the idea that a woman's body belongs to her . . . the
- practice of abortion shall be exterminated with a strong hand."
- -- Adolf Hitler, _Mein Kampf_
-