gdykes@batcomputer.tn.cornell.edu (Gene Dykes) (01/04/89)
I would appreciate comments on the following problem and my solution to it: I have a widget layout manager that parses a grammar that describes a widget tree. It is no trouble to specify resources in this grammar, because widgets use string "handles" for the resources. Thus, an entry in the grammar might look like this: foreground "blue" But I would also like to specify "actions" in this grammar, one type of which is to call a widget's public function. The problem is that widgets don't have any handles defined for public functions; the client has to call the public function directly by its true name. Consider the following grammar line: XtFormDoLayout (Form "form1", Boolean "True") This describes a call to a public function of the Xaw "Form" widget. The layout manager can construct the arguments from the text, but it has no handle on the address of the function to call. There are two solutions to this problem. The first is to hardwire a table of tags and functions into the manager. This is, of course, not very desirable. My solution is to require widgets with public functions that desire to be "nice" widgets to return a list of tags and function addresses as the value of a resource (I chose "XtNpublicFunctions"). It's fairly trivial to add this to widgets contributed from other sources, but it seems that perhaps it should have some kind of official blessing :-) or condemnation :-(. -- Gene Dykes, gdykes@tcgould.tn.cornell.edu
swick@ATHENA.MIT.EDU (Ralph R. Swick) (01/04/89)
Date: 3 Jan 89 18:10:38 GMT From: gdykes@tcgould.tn.cornell.edu (Gene Dykes) My solution is to require widgets with public functions that desire to be "nice" widgets to return a list of tags and function addresses as the value of a resource (I chose "XtNpublicFunctions"). This is certainly a viable approach. If you were concerned about the extra space in each widget instance you could implement this as a virtual resource with a get_values_hook procedure. An alternative is to encourage widgets to implement an action proc corresponding to each public function and register them in the class actions list.