Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!cica!gatech!bloom-beacon!BU-CS.BU.EDU!bzs From: bzs@BU-CS.BU.EDU (Barry Shein) Newsgroups: comp.windows.x Subject: A Call for Callforwards... Keywords: Xt Toolkit Message-ID: <8906260010.AA16100@bu-cs.BU.EDU> Date: 26 Jun 89 00:10:53 GMT Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 79 This all relates to the Xt Toolkit though might be applicable to other toolkits. The Xt Toolkit supports "Callback" functions: Functions defined in a user application which are called by a widget typically (though not necessarily) as a result of some XEvent. An example is a callback which is invoked when a commandwidget is pressed so the application can perform whatever corresponds to that user action. In implementing Xt widgets I have run across a need for something similar which I shall refer to as "Callforward" functions: A function called by the widget for the sole purpose of getting information from the application that the widget can not (or should not) generate for itself. An Illustrative Example: Consider a scrollbar widget with at least the functions incrementUnit and decrementUnit. In a text application this would correspond to moving the scroll region one line of text up or down. Currently there would be three ways to specify how much motion is needed to scroll one line of text (this is needed to move the slider an appropriate amount): 1. A default value. 2. A value set by the application (eg. XtincrementValue) 3. By relieving the scrollwidget entirely of this and setting the slider position on every callback. The first two work fine so long as all lines are the same height (ie. a constant value.) The last works for anything but is not the way we expect to use scrollbar widgets, more like hand-to-hand combat. A Callforward is simply an application-supplied function which the widget calls (if it exists) and expects a return value from. In this case the scrollbar widget calls the callforward passing the widget, a value indicating how much to scroll, typically one unit in this example, (this can be genericized to provide a uniform interface) and, possibly, user data (a closure.) The definition is almost identical to that of a Callback but the return type is changed from void to some generic type (eg. caddr_t). Thus, the logic for scrolling (forward) becomes: IF CALL_FORWARD_EXISTS THEN MoveSlider(CallCallforward(w,name,amount,data)) ELSE MoveSlider(incrementValue) The major differences between a callback and a callforward are that the latter returns a value and I think the ability to have a list of them (as with callbacks) is a bad idea (I don't think this community is ready for multiple-value-returns in C.) Other exemplary uses of callforwards: 1. Querying the font to use at a particular x/y position 2. Boolean requests to check legality of a particular action, such as whether or not to allow a grip to be moved any further. 3. Advice on setting dimensions within a resize request (eg. an application might want to round down or up to contain an entire object to avoid, eg, chopping a spread sheet cell.) 4. Advice within GeometryRequests. I am sure there are many other uses. Comments? -Barry Shein Software Tool & Die, Purveyors to the Trade 1330 Beacon Street, Brookline, MA 02146, (617) 739-0202 Internet: bzs@skuld.std.com UUCP: encore!xylogics!skuld!bzs or uunet!skuld!bzs