[comp.sources.x] v03i081: Xcu -- widget set from Cornell University, Part05/12

argv@island.uu.net (Dan Heller) (04/26/89)

Submitted-by: Gene Dykes <gdykes@tcgould.tn.cornell.edu>
Posting-number: Volume 3, Issue 81
Archive-name: xcu/part05

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of archive 5 (of 12)."
# Contents:  examples/xtbl/tst5 man/CuWlm.man src/CuTblP.h
#   src/CuWlm.c.aa
# Wrapped by argv@island on Mon Apr 24 15:41:40 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'examples/xtbl/tst5' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'examples/xtbl/tst5'\"
else
echo shar: Extracting \"'examples/xtbl/tst5'\" \(28 characters\)
sed "s/^X//" >'examples/xtbl/tst5' <<'END_OF_FILE'
Xlnl(,);
Xc s c, c c ^
X^ c s.

END_OF_FILE
echo shar: NEWLINE appended to \"'examples/xtbl/tst5'\"
if test 29 -ne `wc -c <'examples/xtbl/tst5'`; then
    echo shar: \"'examples/xtbl/tst5'\" unpacked with wrong size!
fi
# end of 'examples/xtbl/tst5'
fi
if test -f 'man/CuWlm.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'man/CuWlm.man'\"
else
echo shar: Extracting \"'man/CuWlm.man'\" \(20799 characters\)
sed "s/^X//" >'man/CuWlm.man' <<'END_OF_FILE'
X.TH CuWlm 3X "\fBCornell University Widget Set\fR"
X.ad b
X.de}F    
X.ds)H Program of Computer Graphics
X.ev1
X.}E
X.if\\n()s 'sp |\\n(.pu-1v-1p
X.if\\n()t 'sp |\\n(.pu-3v
X.ifn 'sp |\\n(.pu-4v
X.tl\\*()H- % -\\*(]W
X'bp
X.ev
X..
X.SH NAME
XCuWlm \- A Widget Layout Manager
X.ne 6
X.SH CLASS HIERARCHY
X\ 
X.br
XCore / Composite / CuWlm
X
X.ne 6
X.SH NEW RESOURCES
X\ 
X.br
X.TS
Xallbox tab(;);
Xc s s s.
XCuTbl Resources
X.T&
XlB lB lB lB.
XName;Type;Default;Description
X_
X.T&
XlB l l l.
XXtNfile;String;NULL;file containing layout description
X.TE
X
X.ne 6
X.SH OVERVIEW
X\ 
X.br
XThe \fBCuWlm\fR widget layout manager
Xis a container for a collection of widgets.
XIts basic function is to permit a user to specify the hierarchical layout
Xof widgets with a grammar.  The \fBCuWlm\fR
Xparses this grammar and generates a widget tree.
XThe grammar also contains notations for "directives" which provide a
Xmechanism for widgets in a tree to send messages to each other.
XPublic functions of the
X\fBCuWlm\fR allow it to intercept callbacks from the widget to the client,
Xpermitting the \fBCuWlm\fR to be
Xtreated as a device that can be
Xqueried in request, event, or sample modes.
XOther public functions allow the client to specify program variables that
Xcan be modified by the \fBCuWlm\fR without the need for a client
Xcallback routine.
X.sp
XWith the layout grammar and public functions taken together,
Xuse of the \fBCuWlm\fR permits the programmer to create complex menu
Xsemantics with virtually no client involvement.
X
X.ne 6
X.SH USAGE
X\ 
X.br
XThe \fBCuWlm\fR widget is instanced just as one would normally instance
Xany other widget.  It in turn will instantiate the remainder of the widget
Xtree.  Although \fBCuWlm\fR can find just about everything it needs to know
Xfrom the widgets themselves, it needs a client routine to tell it what
Xthe WidgetClass pointers are that correspond to the class names given in
Xthe description language.  This routine, \fBmake_tag_class_list()\fR, can
Xbe automatically generated from the description language.   See wlc(3X).
XThe compiled description language is contained in a file with a ".wc"
Xextension.
X
X.ne 6
X.SH PUBLIC FUNCTIONS
X\ 
X.br
XThere are three kinds of public functions:\ \ \ association, device, and convenience.
X.ne 6
X.sp
X.ce
X.ps +2
X\fBAssociation Functions\fR
X.ps -2
X.sp
XThe client can make useful associations with the widget callbacks via
Xthe \fBCuWlm\fR public functions.
XThese associations are of two kinds: those that link widget
Xcallbacks with client procedures, and those that link widget callbacks
Xwith actions on client variables.
XThe \fBCuWlm\fR can have these associations executed directly or it can take note
Xof their execution and generate what will be termed "\fIWEvents\fR".
XIt is \fIWEvents\fR that enable directives to be processed and for the \fBCuWlm\fR
Xto be treated as an input device.
X
XIn all the association functions,
Xthe second argument determines whether a \fIWEvent\fR is
Xgenerated, and whether or not sampling is enabled.
XA null argument indicates that \fIWEvents\fR are enabled and sampling is
Xdisabled.
X\fBCuWlmBypass\fR and \fBCuWlmSampling\fR may be or'd into the second argument
Xto override the respective defaults.
X(\fBCuWlmEvents\fR and \fBCuWlmNoSampling\fR may be used instead of a null
Xargument to explicitly state the default action.)
X.sp
X.ne 6
Xvoid CuWlmAddCallback
X.in +6
X.TS
Xl l.
X(	 
XCuWlmWidget	widget_id,
XCuWlmConnectionType	connection_type,
XString	widget_class,
XString	widget_name,
XString	callback_name,
XXtCallbackProc	callback_proc,
Xcaddr_t	client_data
X)	 
X.TE
X.in -6
X.sp
X.in +3
X\fBCuWlm\fR adds the client callback to the callback list specified
Xby the String 3-tuple.
X.in -3
X
X.sp
X.ne 6
Xvoid CuWlmGetFloat
X.in +6
X.TS
Xl l.
X(	 
XCuWlmWidget	widget_id,
XCuWlmConnectionType	connection_type,
XString	widget_class,
XString	widget_name,
XString	callback_name,
Xfloat	*target,
X)	 
X.TE
X.in -6
X.sp
X.in +3
X\fBCuWlm\fR adds its own callback procedure to the callback list specified
Xby the String 3-tuple.
XWhen the procedure is called,
Xit stores the floating point value contained in call_data at the target address.
X.in -3
X
X.sp
X.ne 6
XCuWlmGetInt(), CuWlmGetBoolean(), and CuWlmGetString()
Xoperate in the same fashion as CuWlmGetFloat().
X
X.sp
X.ne 6
Xvoid CuWlmSetFloat
X.in +6
X.TS
Xl l.
X(	 
XCuWlmWidget	widget_id,
XCuWlmConnectionType	connection_type,
XString	widget_class,
XString	widget_name,
XString	callback_name,
Xfloat	*target,
Xfloat	value
X)	 
X.TE
X.in -6
X.sp
X.in +3
X\fBCuWlm\fR adds its own callback procedure to the callback list specified
Xby the String 3-tuple.
XWhen the procedure is called,
Xit stores the floating point value at the target address.
X.in -3
X
X.sp
X.ne 6
XCuWlmSetInt(), CuWlmSetBoolean(), and CuWlmSetString()
Xoperate in the same fashion as CuWlmSetFloat().
X
X.sp
X.ne 6
Xvoid CuWlmScan
X.in +6
X.TS
Xl l.
X(	 
XCuWlmWidget	widget_id,
XCuWlmConnectionType	connection_type,
XString	widget_class,
XString	widget_name,
XString	callback_name,
XString	format,
Xcaddr_t	arg1, arg2, ..., arg20
X)	 
X.TE
X.in -6
X.sp
X.in +3
X\fBCuWlm\fR adds its own callback procedure to the callback list specified
Xby the String 3-tuple.
XWhen the procedure is called,
Xit uses the call_data as an argument to a sscanf():
X.sp
X.in +5
Xsscanf (call_data, format, arg1, arg2, ..., arg20) ;
X.in -5
X.sp
XIn other words, call_data is taken to be a string with ascii-encoded values,
Xwhich are decoded according to the format and stored in the list of targets.
X.sp
X.in -3
X
X.ne 6
X.ce
X.ps +2
X\fBDevice Functions\fR
X.ps -2
X.sp
XThe \fBCuWlm\fR can be treated as an input device with three modes:
Xsample, request, and event.
XSample mode is primarily a method by which the state of a client
Xcan be initialized.
XRequest and event modes depend on the state of the queue in which \fIWEvents\fR
Xare stored.
X.sp
X.ne 6
X\fBvoid CuWlmRequest (CuWlmWidget)\fR
X.sp
X.in +3
XThis function blocks until a \fIWEvent\fR is available in the queue.
X.in -3
X.sp
X.ne 6
X\fBBoolean CuWlmEvent (CuWlmWidget)\fR
X.sp
X.in +3
XThis function checks to see if a \fIWEvent\fR is in the queue.
XIf there is, it executes this event and returns True;
Xif not, it immediately returns False.
X.in -3
X.sp
X.ne 6
X\fBvoid CuWlmSample (CuWlmWidget)\fR
X.sp
X.in +3
XThis function activates every \fIWEvent\fR for which sampling has been enabled.
XIf sampling has been enabled on a \fIWEvent\fR arising from a widget callback,
Xsampling is accomplished by \fBCuWlm\fR calling the procedure tagged "Sample"
Xin the widget's XtNprocedureList.
XThis procedure has two arguments: the widget id and the callback name.
XWhen called this procedure should activate the specified callback
Xwith the appropriate current value of call_data.
X.in -3
X
X.sp
X.ne 6
X.ce
X.ps +2
X\fBConvenience Functions\fR
X.ps -2
X.sp
X.ne 6
XWidget CuWlmInquireWidget
X.in +6
X.TS
Xl l.
X(	 
XCuWlmWidget	widget_id,
XString	widget_class,
XString	widget_name
X)	 
X.TE
X.in -6
X.sp
X.in +3
XThe widget id of the corresponding widget is returned.
XThis permits the client to access the widgets directly without 
X\fBCuWlm\fR mediation.
X.in -3
X
X.sp
X.ne 6
Xvoid CuWlmSetValue
X.in +6
X.TS
Xl l.
X(	 
XCuWlmWidget	widget_id,
XString	widget_class,
XString	widget_name,
XString	resource_name,
XString	resource_value
X)	 
X.TE
X.in -6
X.sp
X.in +3
XThis routine performs an XtSetValues() on the designated widget with
Xthe specified resource name and resource value.
X.in -3
X
X.sp
X.ne 6
Xvoid CuWlmGetValue
X.in +6
X.TS
Xl l.
X(	 
XCuWlmWidget	widget_id,
XString	widget_class,
XString	widget_name,
XString	resource_name,
Xcaddr_t	target_address
X)	 
X.TE
X.in -6
X.sp
X.in +3
XThis routine performs an XtGetValues() on the designated widget with
Xthe specified resource name and has the returned value stored at the
Xsupplied address.
X.in -3
X
X.ne 6
X.SH THE WIDGET LAYOUT DESCRIPTION LANGUAGE (WLDL)
X\ 
X.br
XSimply, the language is:
X.sp
X.in +10
X\fIwidget_class\fR
X.in +5
X.br
X{
X.br
X default_resource ...
X.br
X widget_resource ...
X.br
X wlm_directive ...
X.br
X child ...
X.br
X}
X.in -5
X.in -10
X.sp
XResources, directives, and children are optional and 
Xmay appear in any order within the
Xwidget body, but a likely convention is to put all items of the same kind
Xtogether and then put the four groups in the order shown above.
X.sp
XIn the following examples, \fBbold\fR indicates keywords in the grammar,
X\fIitalics\fR indicate strings which are to be substituted by the programmer,
Xand words in regular font indicate sample substitutions.
X.sp
X.ps +2
X.ce
X\fBWidget Resources\fR
X.ps -2
X.sp
XWidget resources are specified as:
X.sp
X.in +5
X\fIresource_name\fR \fB"\fIresource_value\fB"\fR
X.sp
XborderWidth \fB"\fR5\fB"\fR
X.br
Xlabel \fB"\fREXIT\fB"\fR
X.in -5
X.sp
X\fIresource_name\fR is the same string that the widget uses, and 
X\fIresource_value\fR is the string representation of the value.
XThe \fBCuWlm\fR is somewhat lenient about the strings
Xit accepts as resource names.
XFor example, if the widget has defined the resource name for border color as:
X.sp
X.in +5
X#define XtNborderColor "borderColor"
X.in -5
X.sp
Xthen the strictly proper string to use is "borderColor", but the
X\fBCuWlm\fR will also convert "border_color" and "XtNborderColor"
Xto the proper string.
X.sp
XWhite space is significant within the quotes, and newlines may be embedded
Xwith an actual newline character or the two character sequence "\\n".
XA backslash newline sequence is ignored.
XNeedless to say, there must exist an appropriate converter from the string
Xrepresentation to 
Xthe actual resource representation type.
X.sp
X.ps +2
X.ce
X\fBDefault Resources\fR
X.ps -2
X.sp
XDefault resources can be used to modify the resource database for all widgets
Xin the tree rooted at the widget in which the declaration appears.
XThese resources are specified by an incomplete resource specification
Xthat begins with an asterisk.
XE.g.,
X.sp
X.in +5
X\fB*\fIincomplete_specification \fB"\fIresource_value\fB"\fR
X.sp
X\fB*\fRBackground \fB"\fRpink\fB"\fR
X.in -5
X.sp
Xwill cause the default background for widgets in the subtree to be pink,
Xoverriding the default established at Toolkit initialization time.
X.sp
X.ps +2
X.ce
X\fBCuWlm Directives\fR
X.ps -2
X.sp
X\fBCuWlm\fR directives have two closely related forms, depending on whether
Xthe inter-widget communication is performed by XtSetValues() or by
Xcalling a public function of a widget.
XTo modify a widget resource, the directive is of the form:
X.sp
X.in +5
X\fBif \fIcallback_name \fB(\fItrigger\fB)\fR
X.in +2
X.br
X\fBXtSetValues\ \ \ (\fItarget_widget\fB,\ \ \ \fIresource_name
X \fB"\fRresource_value\fB"\fB)\fR
X.in -2
X.in -5
X.sp
X.in +5
X\fBif \fRcallback \fB(\fRInt \fB"\fR10\fB"\fR \fB==\fR x\fB)\fR
X.in +2
X.br
X\fBXtSetValues\ \ \ (\fRLabel\ \ \ \fB"\fRlabel0\fB",
X\ \ \ \fRlabel\fB\ \ \ "\fRValue: 10\fB")\fR
X.in -2
X.in -5
X.sp
XThe resource_name and the resource_value may be optionally separated by
Xa comma, so that it looks like the true XtSetValues().
X.sp
XA \fBCuWlm\fR
Xcallback routine is registered with the specified callback list of the current
Xwidget.  When this routine is activated, the trigger is examined, and if it
Xis True, XtSetValues() is called for the target widget and resource.
XThe trigger is zero or more logically separated comparisons of the form:
X.sp
X.in +5
X\fIcall_data_representation\fR\ \ \ \fB"\fR\fIcall_data_value\fR\fB"\fR
X\ \ \ \fIcomparison_operator\fR\ \ \ \fIcall_data_variable\fR
X.in -5
X.sp
XThe order of the operands of the comparison_operator may be reversed.
XIn the example above,
Xthe trigger is True when the call_data of the widget callback
Xhas the value 10.
XThe call_data may be somewhat more complicated than a single value.
XFor example, if a an array of floats is returned,
Xthen the following might be entered as the trigger:
X.sp
X.in +5
Xx[0]\ \ \ 
X\fB==\fR\ \ \ 
XFloat \fB"\fR1\fB"\fR\ \ \
X\ \ \ \fB&&\fR\ \ \
Xx[1]
X\ \ \ 
X\fB<=\fR
X\ \ \ 
XFloat \fB"\fR3.14159\fB"\fR
X.in -5
X.sp
XThe name "x" in these examples is arbitrary, but some name is required.
XThe comparison operators are "==", "!=", "<", "<=", ">", and ">=".
XThe logical operators at present consist only of "&&", and no parenthetical
Xgrouping is recognized.
X.sp
XIf there is a null trigger, then it is always True.
X.sp
XTo call a widget's public function, the directive is of the form:
X.sp
X.in +5
X\fBif\fR\ \ \ \fIcallback_name\ \ \ \fB(\fItrigger\fB)
X.in +3
X.br
X\fIfunction_name\ \ \ \fB(\fItarget_widget\fB,\ \ \ \fIarguments\fB)\fR
X.in -3
X.in -5
X.sp
X.in +5
X\fBif\fR\ \ \ \fIsetCallback\ \ \ \fB(\fRString\fB "\fRcmd0\fB"\ \ \ \fB==\ \ \ \fRx\fB)\fR
X.in +3
X.br
X\fICuDeckRaiseWidget\ \ \ \fB(\fRCuDeck\fB "\fRmenu_deck\fB",
X\ \ \ \fRCuCommand \fB"\fRdraw_cmd\fB")\fR
X.in -3
X.in -5
X.sp
XIf there are no arguments, there is no comma following the target widget.
X.sp
XSince the X Toolkit provides no mechanism for getting a handle on functions
Xwith names as it does for resources, widgets which are to be targets of
Xpublic function directives must have an
X"XtNprocedureList" resource which has as its value a null-terminated XtProcedureList of name/procedure pairs at widget initialization time.
XXtProcedureList is typedef'd as follows:
X.in +5
Xtypedef struct
X.br
X.in +3
X{
X.br
XString name ;
X.br
XXtProc procedure ;
X.br
X} XtProcedureList ;
X.in -3
X.in -8
X
X.bp
X.SH EXAMPLE
X\ 
X.br
X.mk 1
X.DS
X.in -3
X    Layout Description
X.ps -1
X.vs -1
X.sp
X  1 CuWlm
X  2   {
X  3   CuTbl
X  4    {
X  5    *Background "yellow"
X  6
X  7    equal_columns  "True"
X  8    formatString   "padding(10);\\nc c\\n c\\n c\\n c c c."
X  9
X 10    CuCommand  {
X 11         name "INPUT"
X 12         if callback ()
X 13             CuDeckRaiseWidget (CuDeck "pages", CuLabel "PAGE0")
X 14         if callback ()
X 15             XtSetValues (CuCommand "one", label "1")
X 16         }
X 17
X 18    CuCommand  {
X 19         name "OUTPUT"
X 20         if callback ()
X 21             CuDeckRaiseWidget (CuDeck "pages", CuLabel "PAGE1")
X 22         if callback ()
X 23             XtSetValues (CuCommand "one", label "ONE")
X 24         }
X 25
X 26    CuDeck {
X 27         name     "pages"
X 28         if callback (CuLabel "PAGE0" == x[0])
X 29             CuDeckRaiseWidget (CuDeck "pots", CuLabel "INPUT RANGE")
X 30         if callback (CuLabel "PAGE1" == x[0])
X 31             CuDeckRaiseWidget (CuDeck "pots", CuLabel "OUTPUT RANGE")
X 32         CuLabel { name "PAGE0" }
X 33         CuLabel { name "PAGE1" }
X 34         }
X 35
X 36    CuDeck {
X 37     name "pots"
X 38         CuLabel { name "INPUT RANGE" }
X 39         CuLabel { name "OUTPUT RANGE" }
X 40         }
X 41
X 42    CuCommand { name "one"  label "1"  callback "fac" }
X 43    CuCommand { name "two"  label "2"  callback "fac" }
X 44    CuCommand { name "four" label "4"  callback "fac" }
X 45
X 46    /* include "empty_widget" */
X 47    }
X 48  }
X.ps +1
X.vs +1
X.in +3
X.DE
X.mk 2
X.sp |\n1u
X.in +22
X    Program Fragment
X.ps -1
X.vs -1
X.sp
X|    1  XtSetArg (&wlm_arg, XtNfile, argv[1]) ;
X.br
X|    2  wlm = XtCreateManagedWidget ("wlm",
X.br
X|    3         cuWlmWidgetClass, toplevel, &wlm_arg, ONE) ;
X.br
X|    4
X.br
X|    5  CuWlmAddCallback (wlm, NULL,
X.br
X|    6         "CuDeck", "pages", "callback", "page",
X.br
X|    7         page_callback, "SUCCESS") ;
X.br
X|    8
X.br
X|    9  CuWlmSetInt (wlm, CuWlmBypass,
X.br
X|  10         "CuCommand", "one", "callback", "fac", &x, 1) ;
X.br
X|  11
X.br
X|  12  CuWlmSetInt (wlm, CuWlmBypass,
X.br
X|  13         "CuCommand", "two", "callback", "fac", &x, 2) ;
X.br
X|  14
X.br
X|  15  CuWlmSetInt (wlm, CuWlmBypass,
X.br
X|  16         "CuCommand", "four", "callback", "fac", &x, 4) ;
X.br
X|  17
X.br
X|  18  XtRealizeWidget (toplevel) ;
X.br
X|  19
X.br
X|  20  for (;;)
X.br
X|  21      {
X.br
X|  22      CuWlmRequest (wlm) ;
X.br
X|  23      }
X.in -22
X.bp
X.ps +1
X.vs +1
XNote that since \fBCuWlm\fR does not perform geometry management
Xother than to contain its
Xchild, it will usually have a geometry manager as its child.
XIn this case, the child is the
X\fBCuTbl\fR geometry manager, and it manages seven children.
X.sp
XThe first two children are \fBCuCommand\fR widgets (layout lines 10 and 18),
Xand each has two directives.
XSince the triggers are null, these directives will be executed each
Xtime there is a callback from the command widget.
XThe first directive (layout lines 12 and 20)
Xcalls a public function of the \fBCuDeck\fR widget (layout line 26)
Xwhich instructs the \fBCuDeck\fR
Xto raise a specific widget to the top of the stacking order.
XThe second directive (layout lines 14 and 22)
Xcalls \fBXtSetValues()\fR to change the text of the
Xcommand widget in line 42.
X.sp
XThe third child is a \fBCuDeck\fR widget (layout line 26).
XIt also has two directives, but the triggers (layout lines 28 and 30) are
Xdifferent, so they will fire at different times.
XThe \fBCuDeck\fR callback is made whenever the stacking order of its children
Xchanges, and it returns as its call_data an array of widgets in stacking order.
XThe triggers examine the first widget in the array, and when a match is made
Xthey call the CuDeckRaiseWidget function of the fourth child (the CuDeck in layout line
X36).
XThis illustrates that a directive can cause other directives to fire.
XAfter its directives have fired, if any, the CuDeck then makes a callback to the
Xclient.
XNotice that a client procedure called \fBpage_callback()\fR has been registered
Xwith this widget's callback list in program line 5.
X.sp
XThe \fBCuCommand\fR widgets in layout lines 42-44 have all had associations made
X(program lines 9, 12, and 15) with the client variable \fBx\fR. 
XWhenever one of these widgets makes a callback, the variable \fBx\fR is set to
Xthe value of 1, 2, or 4.
X.sp
XThe request in program line 22 will block until a callback has been made
Xto \fBpage_callback()\fR, since the other three associations have all
Xbeen instructed to bypass the production of \fIWEvents\fR.
X.sp
XTwo other elements of the WLDL are illustrated in layout line 46: comments
Xand include files.
XC style comments are recognized, and
Xan include file may appear anywhere a widget appears in the WLDL.
X.sp
XThere is, at present, one widget that is handled specially by the WLDL:
Xthe button manager widget, \fBCuBmgr\fR.
XIt is handled differently because it shares children with the geometry managers
Xin the widget tree.
XIts children have to be separately registered with it.
XBy separating the layout of buttons from the semantics of combinations of
Xbuttons, it is possible for the \fBCuBmgr\fR to manage children which are under
Xthe control of more than one geometry manager, or to have multiple \fBCuBmgr\fRs
Xthat control different children of a single geometry manager.
XThe \fBCuBmgr\fR widgets may appear as direct children of the \fBCuWlm\fR widget
Xor they may appear in the widget tree, presumably near the children, and the
X\fBCuWlm\fR will bypass them while constructing the widget tree, eventually
Xcreating them as children of the \fBCuWlm\fR.
XThe children of the \fBCuBmgr\fRs are specified with the \fBmanage\fR resource
Xname.
XThe name \fBmanage\fR is not a true resource for a \fBCuBmgr\fR, but
Xthe \fBCuWlm\fR recognizes it and uses it to find the children which it later
Xregisters with the \fBCuBmgr\fR widgets via the \fBCuBmgrManage()\fR public
Xfunction of the \fBCuBmgr\fR widget class.
XThis "resource" may have more than one value string following it, each of
Xwhich is the name of a \fBButton\fR widget for the \fBCuBmgr\fR to manage.
XMultiple children of a \fBmanage\fR may optionally be separated by commas.
XThere may also be multiple occurrences of the \fBmanage\fR resource, so any
Xof the following are among the
Xlegitimate ways to specify three children for a \fBCuBmgr\fR:
X.sp
X	\fBmanage\fR "child1" "child2" "child3"
X.sp
X	\fBmanage\fR "child1", "child2", "child3"
X.sp
X	\fBmanage\fR "child1"
X.br
X	\fBmanage\fR "child2"
X.br
X	\fBmanage\fR "child3"
X.sp
XEach child may also be followed by a value specification that will be 
Xreturned as the call_data of the \fBCuBmgr\fR.
XThe value specification consists of a colon, a representation type, and a
Xvalue.
XThe default call_data is the child widget's name, shown explicitly as follows:
X.sp
X	\fBmanage\fR "child1" : String "child1",  "child2" : String "child2"
X.sp
XA more useful example is when it is desirable for the \fBCuBmgr\fR to return
Xa numeric value, for example:
X.sp
X	\fBmanage\fR "PI" : Float "3.14159",  "2*PI" : Float "6.28318"
X.sp
XSee the \fBCuBmgr\fR manual for more information.
X.ne 6
X.SH DIAGNOSTICS
X\ 
X.br
XThe following situations cause fatal errors:
X.sp
X.in +5
X.vs -4
Xlayout description file not readable
X.sp
Xlex and yacc parsing errors (badly formed layout descriptions)
X.sp
Xa widget class was referred to in the description language that was not
Xfound in the make_tag_class_list() function.
X.sp
Xa widget name was referred to in the description language that was not
Xpresent in the description language.
X.sp
Xfirst argument to a public function is not a cuWlmWidgetClass widget.
X.br
X.vs +4
X.in -5
X
X.ne 6
X.SH FUTURE ENHANCEMENTS
X\ 
X.br
XThe trigger should be a full-fledged parenthesized expression.
X.sp
XProbably an endless list...
X
X.ne 6
X.SH AUTHOR
X\ 
X.br
XGene Dykes, \fIgwd@freedom.tn.cornell.edu\fR
X.br
XProgram of Computer Graphics, Cornell University
X

END_OF_FILE
echo shar: NEWLINE appended to \"'man/CuWlm.man'\"
echo shar: 4 control characters may be missing from \"'man/CuWlm.man'\"
if test 20800 -ne `wc -c <'man/CuWlm.man'`; then
    echo shar: \"'man/CuWlm.man'\" unpacked with wrong size!
fi
# end of 'man/CuWlm.man'
fi
if test -f 'src/CuTblP.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/CuTblP.h'\"
else
echo shar: Extracting \"'src/CuTblP.h'\" \(5741 characters\)
sed "s/^X//" >'src/CuTblP.h' <<'END_OF_FILE'
X/* CuTbl widget private definitions */
X
X#ifndef _Cu_TblP_h
X#define _Cu_TblP_h
X
X#include <stdio.h>
X#include <X11/IntrinsicP.h>
X#include <X11/StringDefs.h>
X
X#include <X11/ConstrainP.h>	/* Superclass Private Include File	*/
X#include "CuTbl.h"		/* Class Public Include File		*/
X
X/*
X * Prepare for declaring new fields added to superclass widget structure
X */
X
X#define MAX_TBL_COLS	100
X#define MAX_TBL_ROWS	100
X
Xtypedef enum { TBL_ITEM, TBL_HSPAN, TBL_VSPAN }
X	XtPrimaryType ;
X
Xtypedef enum
X	{
X	TBL_FIRST_PASS, TBL_NO_FORMAT, TBL_STRING_FORMAT, TBL_FILE_FORMAT
X	} XtFormatMode ;
X
Xtypedef struct s_item
X    {
X    XtPrimaryType primary ;/* widget or a span				*/
X    CuJustify justify ;	/* justification of  text			*/
X    CuGravity g ;	/* gravity of child				*/
X    Boolean e ;		/* equal columns in this row			*/
X    Boolean f ;		/* this column takes up the slack		*/
X    Widget pw ;		/* points to widget responsible for this item	*/
X    Cardinal pi ;	/* points to upper-left of this spanned item	*/
X    Cardinal pj ;	/* points to upper-left of this spanned item	*/
X    int	 width ;	/* save until needed by XtConfigureWidget	*/
X    int	 height ;	/* save until needed by XtConfigureWidget	*/
X    int adj_width ;	/* adjusted for spanning members		*/
X    String text ;	/* item text					*/
X    } ElementRecord ;
X
X/*
X * The new fields added to superclass widget structure
X *
X * "Int" is often used instead of "Dimension" and "Cardinal" because there is
X * frequent use of these variables in expressions involving signed arithmentic
X */
X
Xtypedef struct _CuTblPart
X    {
X    /* resources */
X    Boolean	aligned_columns ;   /* XtNalignedColumns		    */
X    Boolean	clip_on_shrink ;    /* XtNclipOnShrink			    */
X    Boolean	equal_columns ;	    /* XtNequalColumns			    */
X    Boolean	equal_rows ;	    /* XtNequalRows			    */
X    String	format_file ;	    /* Tbl description file		    */
X    String	format_string ;	    /* Tbl description string		    */
X    int	inter_width ;	    /* horizontal distance between children */
X    int	inter_height ;	    /* vertical distance between children   */
X    int	internal_width ;    /* horizontal space surrounding children*/
X    int	internal_height ;   /* vertical space surrounding children  */
X    CuResizeParticipants resize_participants ; /* what expands on resizes   */
X
X    /* private state */
X    ElementRecord *item[MAX_TBL_ROWS] ; /* stats for each matrix element    */
X    int		*r_item ;	    /* number of "items" in a row	    */
X    int		*r_height ;	    /* height of each  row		    */
X    int		rows ;		    /* number of rows in matrix		    */
X    int		cols[MAX_TBL_ROWS] ;/* number of cols in each row	    */
X    int		max_cols ;	    /* need to save for resize calculations */
X    Boolean	*equal_cols ;	    /* whether columns in this row are equal*/
X    Boolean	*vspan_status ;	    /* whether this row is vert spanned	    */
X    Boolean	initting ;	    /* whether InitLayout is active	    */
X    Boolean	force_width ;	    /* whether width has been fumped	    */
X    int		standalone_width ;  /* minimum width of table		    */
X    int		standalone_height ; /* minimum height of table		    */
X    int		typical_border ;
X    Dimension	pre_almost_width ;
X    Dimension	pre_almost_height ;
X    Dimension	new_width ;	    /* set in ETS, xfer'd to core.width in  */
X    Dimension	new_height ;        /* DoLayout                             */
X    XtFormatMode format_mode ;	    /* file or string	    		    */
X    /* needed only during parsing */
X    int		string_breaker ;
X    Cardinal	n_cols ;
X    Cardinal	data_row ;
X    ElementRecord *temp_elements ;
X    ElementRecord *null_elements ;
X    /* */
X    int		child_border_width ;
X    Pixel	child_border_color ;
X    Pixel	child_background_color ;
X    Pixel	child_foreground_color ;
X    } CuTblPart ;
X
X/*
X * The complete widget instance structure for this widget
X */
X
Xtypedef struct _CuTblRec
X    {
X    CorePart		core ;
X    CompositePart	composite ;
X    ConstraintPart	constraint ;
X    CuTblPart		tbl ;
X    } CuTblRec ;
X
X/*
X * The new fields added to superclass constraint structure
X */
X
Xtypedef struct _CuTblConstraintsPart
X    {
X    Boolean	almost_status ;
X    Boolean	differ_geometry ;
X    Boolean	fill_column; /* this widget's column will fill on sts	*/
X    int		span_width ; /* # of elements spanned			*/
X    int		span_height ;
X    int		sts_width ;  /* standalone table size			*/
X    int		sts_height ;
X    Position	ets_x ;      /* enclosed table positions		*/
X    Position	ets_y ;
X    int		ss_width ;  /* standalone size				*/
X    int		ss_height ;
X    int		ets_width ;  /* enclosed table size			*/
X    int		ets_height ;
X    Dimension	almost_width ;  /* Values returned with an Almost reply */
X    Dimension	almost_height ;
X    Position	almost_x ;
X    Position	almost_y ;
X    Widget	almost_widget ;
X    XtGeometryMask	almost_mode ;
X    } CuTblConstraintsPart ;
X
X/*
X * The complete Constraint structure
X */
X
Xtypedef struct _CuTblConstraintsRec
X    {
X    CuTblConstraintsPart	tbl ;
X    } CuTblConstraintsRec,
X      *CuTblConstraints ;
X
X/*
X * New fields added to the widget superclass class structure
X */
X
Xtypedef String (*XtTblStringProc) () ;
X
Xtypedef struct
X    {
X    XtTblStringProc interpret_string ;
X    } CuTblClassPart ;
X
X/*
X * The complete widget class structure for the widget
X */
X
Xtypedef struct _CuTblClassRec
X    {
X    CoreClassPart	core_class ;
X    CompositeClassPart	composite_class ;
X    ConstraintClassPart	constraint_class ;
X    CuTblClassPart	tbl_class ;
X    } CuTblClassRec ;
X
X/*
X * The name of a "constant" of the generic widget class structure
X */
X
Xextern CuTblClassRec cuTblClassRec ;
X
X/*
X * For each new procedure in the widget class structure, an inherit operation
X */
X
X#define XtInheritInterpretString ((XtStringProc) _XtInherit)
X
X#endif _Cu_TblP_h

END_OF_FILE
echo shar: NEWLINE appended to \"'src/CuTblP.h'\"
if test 5742 -ne `wc -c <'src/CuTblP.h'`; then
    echo shar: \"'src/CuTblP.h'\" unpacked with wrong size!
fi
# end of 'src/CuTblP.h'
fi
if test -f 'src/CuWlm.c.aa' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/CuWlm.c.aa'\"
else
echo shar: Extracting \"'src/CuWlm.c.aa'\" \(26008 characters\)
sed "s/^X//" >'src/CuWlm.c.aa' <<'END_OF_FILE'
X/* *
X * * This code is completely original.  Permission is granted to do with
X * * it as one wishes.  I disclaim any responsibility whatsoever for
X * * any bad things that may happen because of using it.
X * */
X
X/*
X * CuWlm widget
X */
X
X#include <stdio.h> /* need this for FILE */
X#include <X11/Xos.h>
X#include <sys/stat.h>
X#include <X11/IntrinsicP.h>
X#include <X11/StringDefs.h>
X#include <X11/Cardinals.h>
X#include <X11/Xresource.h>
X#include "CuBmgr.h"
X#include "CuButton.h"
X#include "CuWlmP.h"
X
Xvoid Cu_copy_ds () ;
X
X/* Private Definitions */
X
Xstatic char error_text[200] ;
X
X/*
X * resource declarations
X */
X
X#define Offset(field) XtOffset(CuWlmWidget, wlm.field)
X
Xstatic XtResource resources[] =
X{
X   {XtNfile,      XtCFile,   XtRString,  sizeof(String),
X    Offset(layout_file), XtRString,	(caddr_t) NULL}
X  ,{XtNexposeCallback, XtCCallback, XtRCallback, sizeof(caddr_t), 
X    Offset(expose_callbacks), XtRCallback, (caddr_t)NULL}
X} ;
X
X#undef Offset
X
X/* Declarations of "toolkit" calls */
X
Xstatic XtGeometryResult	GeometryManager () ;
Xstatic void		ChangeManaged () ;
Xstatic void		ClassInitialize () ;
Xstatic void		Initialize () ;
Xstatic Boolean		SetValues () ;
Xstatic void		Resize () ;
X
X/* Declarations of "private" calls */
X
Xstatic void	ReadLayout () ;
Xstatic void	read_layout () ;
Xstatic void	InitializeLayout () ;
Xextern void	make_tag_class_list () ;
Xstatic void	realize_child () ;
Xstatic void	bmgr_setup () ;
Xstatic void	bmgr_search () ;
Xstatic void	directive_setup () ;
Xstatic void	directive_search () ;
Xstatic void	wlm_central () ;
Xstatic void	add_to_widget_list () ;
Xstatic void	add_to_sample_list () ;
Xstatic void	CvtStringToWidget () ;
Xstatic void	CvtStringToProcedure () ;
Xstatic void	AddStringToWidgetConverter () ;
Xstatic void	AddStringToProcedureConverter () ;
Xstatic void	find_public_procedures () ;
Xstatic void	callback_not_found_warning () ;
Xstatic void	callback_scan () ;
Xstatic void	get_int_float_string () ;
Xstatic void	callback_set_bool () ;
Xstatic void	callback_set_float () ;
Xstatic void	callback_set_int () ;
Xstatic void	callback_set_string () ;
Xstatic void	callback_get () ;
Xstatic void	callback_indirect () ;
Xstatic void	dequeue_event () ;
Xstatic void	enqueue_event () ;
Xstatic void	create_resource_database () ;
Xstatic void	ParseCuWlmLayout () ;
Xstatic void	get_child () ;
Xstatic void	get_manage () ;
Xstatic void	get_resource () ;
Xstatic void	get_directive () ;
Xstatic int	get_int() ;
Xstatic String	get_word() ;
Xstatic String	get_string() ;
Xstatic void	my_sync() ;
X
Xstatic CuWlmArgType	convert_string_to_arg () ;
Xstatic WidgetClassList *get_widget_class_list () ;
Xstatic WidgetNameList  *get_widget_name_list () ;
Xstatic WidgetIdList    *get_widget_id_list () ;
Xstatic Widget		get_widget_id () ;
Xstatic Widget		get_callback_widget () ;
Xstatic XtProc		get_proc_list () ;
Xstatic WidgetClass	get_widget_class () ;
Xstatic String		get_resource_info () ;
X
X/*
X * Class Record Constant
X */
X
XCuWlmClassRec cuWlmClassRec =
X{
X  { /* core_class fields  */
X    /* superclass         */    (WidgetClass) &compositeClassRec,
X    /* class_name         */    "CuWlm",
X    /* widget_size        */    sizeof(CuWlmRec),
X    /* class_initialize   */    ClassInitialize,
X    /* class_part_init    */    NULL,
X    /* class_inited       */    False,
X    /* initialize         */    Initialize,
X    /* initialize_hook    */    NULL,
X    /* realize            */    XtInheritRealize,
X    /* actions            */    NULL,
X    /* num_actions        */    0,
X    /* resources          */    resources,
X    /* num_resources      */    XtNumber(resources),
X    /* xrm_class          */    NULLQUARK,
X    /* compress_motion    */    True,
X    /* compress_exposure  */    True,
X    /* compress_enterleave*/    True,
X    /* visible_interest   */    False,
X    /* destroy            */    NULL,
X    /* resize             */    Resize,
X    /* expose             */    NULL,
X    /* set_values         */    SetValues,
X    /* set_values_hook    */    NULL,
X    /* set_values_almost  */    XtInheritSetValuesAlmost,
X    /* get_values_hook    */    NULL,
X    /* accept_focus       */    NULL,
X    /* version            */    XtVersion,
X    /* callback_private   */    NULL,
X    /* tm_table           */    NULL,
X    /* query_geometry	  */	NULL,
X    /* display_accelerator*/	XtInheritDisplayAccelerator,
X    /* extension	  */	NULL,
X  },
X  { /* composite_class fields */
X    /* geometry_manager   */   GeometryManager,
X    /* change_managed     */   ChangeManaged,
X    /* insert_child       */   XtInheritInsertChild,
X    /* delete_child       */   XtInheritDeleteChild,
X    /* extension	  */   NULL,
X  },
X  { /* wlm_class fields   */
X    /* no entries   */   NULL
X  }
X} ;
X
X/*
X * Class Record Pointer
X */
X
XWidgetClass cuWlmWidgetClass = (WidgetClass) &cuWlmClassRec ;
X
X/**
X ***
X **** Toolkit Callable Procedures
X ***
X **/
X
Xstatic XrmQuark Bmgr_quark ;
X
X/***** **** *** ** * ClassInitialize * ** *** **** *****/
X
Xstatic void
XClassInitialize ()
X{
XBmgr_quark = XrmStringToQuark ("CuBmgr") ; /* one time initialization */
X
XAddStringToProcedureConverter () ; /* add a couple resource converters	  */
XCuAddStringToBmgrTypeConverter () ;
Xreturn ;
X}
X
X/***** **** *** ** * Initialize * ** *** **** *****/
X
Xstatic void
XInitialize (request, new)
X    Widget request, new ;
X{
XCuWlmWidget ww = (CuWlmWidget) new ;
X
X/*
X * allocate space for and copy resources specified by address
X */
X
Xif (ww->wlm.layout_file != NULL) 
X    Cu_copy_ds (&ww->wlm.layout_file, ww->wlm.layout_file) ;
X
X/*
X * Initialize some private non-resource fields
X */
X
Xww->wlm.sre_status = NULL ;
Xww->wlm.sampling_active = False ;
Xww->wlm.first_device = True ;
Xww->wlm.database = NULL ;
Xww->wlm.history_ptr = NULL ;
Xww->wlm.history_mode = CuWlmInactiveHistory ;
Xww->wlm.queue_ptr = NULL ;
Xww->wlm.sample_list = NULL ;
Xww->wlm.widget_class_list = NULL ;
Xww->wlm.tag_class_list = NULL ;
Xww->wlm.event_stamp = 0 ;
Xww->core.border_width = 0 ;
Xww->core.width = 1 ;
Xww->core.height = 1 ;
X
XReadLayout (ww) ;		   /* read the layout			  */
Xmake_tag_class_list (ww) ;	   /* construct a correspondence table of */
X				   /* widget class strings and pointers	  */
X				   /* (client supplies this routine)	  */
XInitializeLayout (ww) ;		   /* analyze the layout		  */
X
Xreturn ;
X}
X/***** **** *** ** * SetValues * ** *** **** *****/
X
Xstatic Boolean
XSetValues (current, request, new)
X    Widget current, request, new ;
X{
XCuWlmWidget cw = (CuWlmWidget) current ;
XCuWlmWidget nw = (CuWlmWidget) new ;
X
Xif (cw->wlm.layout_file != nw->wlm.layout_file)
X    { /* TODO if ever needed */ }
X
Xreturn False ;
X}
X
X/***** **** *** ** * ChangeManaged * ** *** **** *****/
X
X/*
X * ChangeManaged is called when there is a change in the set of children
X */
X
Xstatic void
XChangeManaged (w)
X    Widget w ;
X{
XCardinal i ;
XDimension large_width = 0 ;
XDimension large_height = 0 ;
XCuWlmWidget ww = (CuWlmWidget) w ;
X/*
X * We want our window to be the same size as our largest kid...
X */
X
Xfor (i=0;  i < ww->composite.num_children;  i++)
X    {
X    XtWidgetGeometry preferred ;
X    XtQueryGeometry (ww->composite.children[i], NULL, &preferred) ;
X    if (preferred.width + 2*preferred.border_width > large_width)
X	large_width = preferred.width + 2*preferred.border_width ;
X    if (preferred.height + 2*preferred.border_width > large_height)
X	large_height = preferred.height + 2*preferred.border_width ;
X    }
X
Xww->core.width = large_width ;
Xww->core.height = large_height ;
X
Xreturn ;
X}
X
X/***** **** *** ** * GeometryManager * ** *** **** *****/
X
Xstatic XtGeometryResult
XGeometryManager (w, req, ret)
X    Widget w ;
X    XtWidgetGeometry *req ;
X    XtWidgetGeometry *ret ;
X{
XXtGeometryResult result ;
XCuWlmWidget ww = (CuWlmWidget) w->core.parent ;
X
X/*
X * Since this is only a container class, just rubber stamp all requests...
X */
X
Xresult = XtMakeGeometryRequest ((Widget)ww, req, ret) ;
Xif (result == XtGeometryYes)
X    {
X    if (!req->request_mode & XtCWQueryOnly)
X	{
X	w->core.width = req->width ;
X	w->core.height = req->height ;
X	}
X    }
Xelse
Xif (result == XtGeometryAlmost)
X    {
X    /* We'll accept whatever compromise is offered */
X    XtMakeGeometryRequest ((Widget)ww, ret, (XtWidgetGeometry *)NULL) ;
X    if (!req->request_mode & XtCWQueryOnly)
X	{
X	w->core.width = ret->width ;
X	w->core.height = ret->height ;
X	}
X    }
X
Xreturn result ;
X}
X
X/***** **** *** ** * Resize * ** *** **** *****/
X
Xstatic void
XResize (w)
X    Widget w ;
X{
XCardinal i ;
XCuWlmWidget ww = (CuWlmWidget) w ;
X/*
X * Inform the children of the resize
X */
X
Xfor (i=0;  i < ww->composite.num_children;  i++)
X    {
X    XtResizeWidget (ww->composite.children[i], w->core.width, w->core.height,
X		    ww->composite.children[i]->core.border_width) ;
X    }
Xreturn ;
X}
X
X/**
X ***
X **** Private Procedures
X ***
X **/
X
X#define WLM_MAX_UNPUT 100
X#define WLM_MAX_CONTEXT 100
X
Xstatic String undefined_name = "wlm_undef" ;
Xstatic Cardinal counter = 0 ;
X
Xtypedef struct
X    {
X    String input_buffer ;
X    Cardinal input_pointer ;
X    char unput_buffer[WLM_MAX_UNPUT] ;
X    Cardinal unput_pointer ;
X    char context_buffer[WLM_MAX_CONTEXT] ;
X    int context_ptr ; /* must not be Cardinal */
X    Cardinal line_number ;
X    String cur_file ;
X    String file0 ;
X    } CuWlmInputRecord ;
X
Xstatic CuWlmInputRecord *layout_input ;
X
X/***** **** *** ** * ReadLayout * ** *** **** *****/
X
Xstatic void
XReadLayout (ww)
X    CuWlmWidget ww ;
X{
Xif (ww->wlm.layout_file == NULL) 
X    {
X    XtError ("CuWlm: No layout file!\n") ;
X    }
X/*
X * Layout is contained in a file.
X * We'll read the file as one big string, then parse it.
X */
X
Xlayout_input = (CuWlmInputRecord *) XtMalloc (sizeof (CuWlmInputRecord)) ;
Xread_layout (ww->wlm.layout_file, layout_input) ;
XXtFree (ww->wlm.layout_file) ;
Xww->wlm.layout_file = NULL ;
X
XParseCuWlmLayout (ww) ;
X
X/*
X * Now that we know how deep the layout is, we can allocate some space
X * for resource list entries.
X * Really do need 2 extra allocations!
X * (1 for NULL entry, and 1 for something else I can't remember right now...)
X */
X
Xww->wlm.quarks_list = (XrmQuark *) XtMalloc ((ww->wlm.max_depth+2) *
X					     sizeof (XrmQuark)) ;
Xww->wlm.bindings_list = (XrmBinding *) XtMalloc ((ww->wlm.max_depth+2) *
X						 sizeof (XrmBinding)) ;
X
Xreturn ;
X}
X
X/***** **** *** ** * read_layout * ** *** **** *****/
X
Xstatic void
Xread_layout (file, layout_input)
X    String file ;
X    CuWlmInputRecord *layout_input ;
X{
XFILE *fd ;
Xstruct stat buf ;
XString input_file ;
Xint argv_length ;
X
Xargv_length = strlen(file) ;
Xif (strcmp(&file[argv_length-3], ".wc") == 0)
X    {
X    /* This permits extensioned or extensionless input */
X    file[argv_length-3] = '\0' ;
X    argv_length -= 3 ;
X    }
Xinput_file = XtMalloc (argv_length + 4) ;
Xsprintf (input_file, "%s.wc", file) ;
X
Xfd = fopen (input_file, "r") ;
Xif (fd <= 0)
X    {
X    char *my_text = "CuWlm: Couldn't open (%s) for reading\n" ;
X    char *etext = XtMalloc (strlen(my_text) + strlen(input_file)) ;
X    sprintf (etext, my_text, input_file) ;
X    XtError (etext) ;
X    }
X
X/*
X * Find out how big the layout file is.
X * Read it in as one big chunk.
X * Initialize some useful variables
X */
X
Xfstat (fileno(fd), &buf) ;
Xlayout_input->input_buffer = XtMalloc (buf.st_size + 1) ;
Xfread (layout_input->input_buffer, (int)buf.st_size, 1, fd) ;
Xlayout_input->input_buffer[buf.st_size] = '\0' ;
X
XCu_copy_ds (&layout_input->cur_file, input_file) ; /* for error messages */
XCu_copy_ds (&layout_input->file0, input_file) ; /* for error messages */
Xlayout_input->input_pointer = 0 ;
Xlayout_input->unput_pointer = 0 ;
Xlayout_input->line_number = 1 ;
Xfclose (fd) ;
X
Xreturn ;
X}
X
X/***** **** *** ** * InitializeLayout * ** *** **** *****/
X
Xstatic void
XInitializeLayout (ww)
X    CuWlmWidget ww ;
X{
XXrmDatabase XtDefaultDB = XtDatabase(XtDisplay((Widget)ww)) ;
Xif (XtDefaultDB == NULL)
X    {
X    /*
X     * The following is to fix up some shortcomings of the Intrinsics
X     * (Actually, this is a bit clumsy, but since it works I'll leave
X     * it for now.  What should be done is if/else the XrmMergeDatabases()
X     * call with an assignment of the ww->wlm.database to dpy->db.
X     * That way this "opaque" hashbucket structure is not needed.)
X     */
X    Display *dpy ;
X    static struct _XrmHashBucketRec {
X	XrmHashBucket		next ;
X	XrmQuark		quark ;
X	XrmRepresentation	type ;
X	XrmValue		value ;
X	XrmHashTable		tables[2] ;
X	} _fudge ;
X    XrmDatabase fudge = (XrmDatabase) &_fudge ;
X    dpy = XtDisplay ((Widget)ww) ;
X    dpy->db = fudge ;
X    XtDefaultDB = fudge ;
X    }
X/*
X * Having parsed the grammar, we now convert the fetuses into children!
X * This involves numerous  passes through the child list.
X * We'll start by extracting all resource information and inserting it into
X * the default resource database.
X */
X
Xww->wlm.cur_depth = 0 ;
Xcreate_resource_database (ww, ww->wlm.child, True) ;
XXrmMergeDatabases (ww->wlm.database, &XtDefaultDB) ;
X
X/*
X * Create the widget tree...
X */
X
Xrealize_child (ww, (Widget)ww, ww->wlm.child, True) ;
X
X/*
X * Now that there exists a list of the widgets in the layout,
X * create converters for the name strings.
X */
X
XAddStringToWidgetConverter (ww) ;
X
X/*
X * Look through the list again, this time creating the Bmgr widgets.
X */
X
Xbmgr_search (ww, ww->wlm.child) ;
X
X/*
X * Find all the public procedures of the widget classes in the layout
X */
X
Xfind_public_procedures (ww) ;
X
X/*
X * Once through the list again to find all the directives
X */
X
Xdirective_search (ww, ww->wlm.child) ;
X
Xreturn ;
X}
X
X/***** **** *** ** * create_resource_database * ** *** **** *****/
X
Xstatic void
Xcreate_resource_database (ww, child, root_wlm)
X    CuWlmWidget ww ;
X    Fetus *child ;
X    Boolean root_wlm ;
X{
Xint	 i ; /* must not be Cardinal */
XXrmQuark save_quark1, save_quark2, save_quark3 ;
XXrmBinding save_binding1, save_binding2, save_binding3 ;
XCardinal save_depth ;
X
Xif (child->class_name == Bmgr_quark)
X    {
X    /*
X     * Treat BmgrWidgets specially (will be children of root_wlm)
X     * Save the resource list entries that will be demolished.
X     */
X    save_binding1 = ww->wlm.bindings_list[1] ;
X    save_binding2 = ww->wlm.bindings_list[2] ;
X    save_binding3 = ww->wlm.bindings_list[3] ;
X    save_quark1 = ww->wlm.quarks_list[1] ;
X    save_quark2 = ww->wlm.quarks_list[2] ;
X    save_quark3 = ww->wlm.quarks_list[3] ;
X    save_depth = ww->wlm.cur_depth ;
X    ww->wlm.cur_depth = 1 ;
X    }
X
X/*
X * Find out if this widget has a name.
X * If not, assign it one.
X */
X
Xchild->class = get_widget_class (ww, child->class_name) ;
X
Xfor (i=0;  i < child->n_resources;  i++)
X    if (strcmp (child->resources[i].name, "name") == 0)
X	child->widget_name = child->resources[i].value ;
X
Xif (child->widget_name == NULL)
X    {
X    String new_name = (String) XtMalloc (strlen(undefined_name)+10) ;
X    sprintf (new_name, "%s%d", undefined_name, counter) ;
X    child->widget_name = new_name ;
X    counter++ ;
X    }
X
X/*
X * Enter all specified resources in the database, except callbacks and names
X */  
X
Xww->wlm.bindings_list[ww->wlm.cur_depth] = root_wlm ?
X	XrmBindLoosely :
X	XrmBindTightly ;
Xww->wlm.quarks_list[ww->wlm.cur_depth] = root_wlm ?
X	XrmStringToQuark (ww->core.name) :
X	XrmStringToQuark (child->widget_name) ;
X
Xfor (i=0;  i < child->n_resources;  i++)
X    {
X    Resource *resource = &child->resources[i] ;
X    resource->class = get_resource_info (child->class, resource->name,
X					 CuWlmResourceInfoClass) ;
X    if ((!resource->name || strcmp (resource->name, "name") != 0) &&
X        (!resource->class || strcmp (resource->class, "Callback") != 0))
X	{
X	if (resource->context == CuWlmLocalContext)
X	    {
X	    ww->wlm.bindings_list[ww->wlm.cur_depth+1] = XrmBindTightly ;
X	    ww->wlm.quarks_list[ww->wlm.cur_depth+1] =
X		    XrmStringToQuark (resource->name) ;
X	    ww->wlm.quarks_list[ww->wlm.cur_depth+2] = NULLQUARK ;
X	    }
X	else
X	    {
X	    XrmStringToBindingQuarkList (resource->name,
X		&ww->wlm.bindings_list[ww->wlm.cur_depth+1],
X		&ww->wlm.quarks_list[ww->wlm.cur_depth+1]) ;
X	    ww->wlm.bindings_list[ww->wlm.cur_depth+1] = XrmBindLoosely ;
X	    }
X	XrmQPutStringResource (&ww->wlm.database,
X				ww->wlm.bindings_list,
X				ww->wlm.quarks_list,
X				resource->value) ;
X	}
X    }
X
Xif (child->class_name == Bmgr_quark)
X    {
X    ww->wlm.bindings_list[1] = save_binding1 ;
X    ww->wlm.bindings_list[2] = save_binding2 ;
X    ww->wlm.bindings_list[3] = save_binding3 ;
X    ww->wlm.quarks_list[1] = save_quark1 ;
X    ww->wlm.quarks_list[2] = save_quark2 ;
X    ww->wlm.quarks_list[3] = save_quark3 ;
X    ww->wlm.cur_depth = save_depth ;
X    }
X
Xif (child->class_name != Bmgr_quark)
X    ww->wlm.cur_depth++ ;
X
X/* descend the widget tree */
Xfor (i = child->n_children - 1;  i >=0;  i--)
X    create_resource_database (ww, &child->children[i], False) ;
X
Xif (child->class_name != Bmgr_quark)
X    ww->wlm.cur_depth-- ;
X
Xreturn; 
X}
X
X/***** **** *** ** * realize_child * ** *** **** *****/
X
Xstatic void
Xrealize_child (ww, parent, child, root_wlm)
X    CuWlmWidget ww ;
X    Widget parent ;
X    Fetus *child ;
X    Boolean root_wlm ;
X{
Xint	 i ; /* must not be Cardinal */
XWidget	 parent_id ;
X
X
Xif (root_wlm)
X    {
X    child->id = (Widget) ww ;
X    parent_id = child->id ;
X    }
Xelse
Xif (child->class_name == Bmgr_quark)
X    {
X    child->id = XtCreateManagedWidget 
X	(
X	child->widget_name,
X	child->class,
X	(Widget) ww,   /* Bmgr's are all children of root wlm */
X	NULL,
X	0
X	) ;
X    parent_id = parent ;
X    }
Xelse
X    {
X    child->id = XtCreateManagedWidget 
X	(
X	child->widget_name,
X	child->class,
X	parent,
X	NULL,
X	0
X	) ;
X    parent_id = child->id ;
X    }
X
Xadd_to_widget_list (ww, child) ; /* compile a list of widget class and names */
X
X/* descend the widget tree */
Xfor (i = child->n_children - 1;  i >=0;  i--)
X    realize_child (ww, parent_id, &child->children[i], False) ;
X
Xreturn; 
X}
X
X/***** **** *** ** * convert_string_to_arg * ** *** **** *****/
X
Xstatic CuWlmArgType
Xconvert_string_to_arg (ww, class, name, value, arg)
X    CuWlmWidget ww ;
X    String class ;
X    String name ;
X    String value ;
X    Arg *arg ;
X{
XXrmValue string_value ;
XXrmValue converted_value ;
X
Xstring_value.addr = (caddr_t) value ;
Xstring_value.size = strlen (string_value.addr) ;
Xif (strcmp (class, "Boolean") == 0)
X    {
X    /* KLUDGE!  Booleans seem to bomb! */
X    if (*value == 't' || *value == 'T')
X	XtSetArg (*arg, name, 1) ;
X    else
X	XtSetArg (*arg, name, 0) ;
X    return CuWlmCharArg ;
X    }
XXtConvert ((Widget)ww,  XtRString,  &string_value,
X	       class,	   &converted_value) ;
X
X
X/* TODO : This is not very portable */
Xif (strcmp(class, "String") == 0)
X    {
X    /* It's the address we're interested in */
X    XtSetArg (*arg, name, (XtArgVal)((String) converted_value.addr)) ;
X    return CuWlmStringArg ;
X    }
Xelse
Xif (strcmp(class, "Boolean") == 0)
X    {
X    /* 1 byte values */
X    XtSetArg (*arg, name, (XtArgVal) (*converted_value.addr)) ;
X    return CuWlmCharArg ;
X    }
Xelse
X    {
X    /* word values */
X    XtSetArg (*arg, name, *((XtArgVal *)converted_value.addr)) ;
X    return CuWlmArgValArg ;
X    }
X}
X
X/***** **** *** ** * add_to_widget_list * ** *** **** *****/
X
X/*
X * Here's the scoop.
X * Since there can be a variety of widget classes, an unknown number of
X * named widgets in each class, and perhaps even more than one widget
X * of the same name, there are linked lists for each, with each entry
X * pointing to the next item in the list.
X */
X
Xstatic void
Xadd_to_widget_list (ww, child)
X    CuWlmWidget ww ;
X    Fetus *child ;
X{
XWidgetClassList *class_list ;
XWidgetNameList *name_list ;
XWidgetIdList *id_list ;
XWidget w = child->id ;
X/*
X * Look up list by classname, then corename, then id#
X * Each of these calls has the side effect of adding an entry as needed
X */
Xif (child->widget_name)
X    {
X    class_list = get_widget_class_list (&ww->wlm.widget_class_list,
X					child->class_name, CuWlmAddOnNotFound) ;
X    name_list = get_widget_name_list (class_list, child->widget_name, CuWlmAddOnNotFound);
X    id_list = get_widget_id_list (name_list, w, CuWlmAddOnNotFound) ;
X    /* id_list is not used now */
X    }
X
Xreturn ;
X}
X
X/***** **** *** ** * find_public_procedures * ** *** **** *****/
X
X/*
X * Here's the scoop on public procedures.
X * Since I need to access them via a String handle, I must insist that
X * widgets associate their public procedures with a text string and 
X * return this list with a call to XtGetValues, using the resource
X * name XtNprocedureList.  I will maintain a separate list for each
X * widget class so that the names need not be unique across classes.
X * The procedure list is a null terminated array of XtProcedureList entries .
X */
X
Xstatic void
Xfind_public_procedures (ww)
X    CuWlmWidget ww ;
X{
XWidgetClassList *class_list ;
X/*
X * Cycle through the class list, ask an arbitrary representative of
X * that class what the list looks like, and enter them in the proc list.
X */
Xfor (class_list = ww->wlm.widget_class_list;
X     class_list != NULL;
X     class_list = class_list->next)
X    {
X    Arg arg ;
X    XtProcedureList *procedure_list = NULL ;
X    CuWlmProcedureList *proc_list ;
X    CuWlmProcedureList **last_ptr ;
X    Widget arbitrary = class_list->widget_name_list->widget_id_list->id ;
X
X    arg.name = XtNprocedureList ;
X    arg.value = (XtArgVal) &procedure_list ;
X    XtGetValues (arbitrary, &arg, ONE) ;
X    if (procedure_list == NULL)
X	continue ;
X    /* I must allocate space for this list here -- the arbitrary widget
X     * may be destroyed!
X     */
X    last_ptr = &class_list->proc_list ;
X    for (  ; procedure_list->name ;  procedure_list++)
X	{
X	(*last_ptr) = (CuWlmProcedureList *) XtMalloc (sizeof(CuWlmProcedureList)) ;
X	proc_list = *last_ptr ;
X	proc_list->quark = XrmStringToQuark (procedure_list->name) ;
X	proc_list->procedure = procedure_list->procedure ;
X	proc_list->next = NULL ;
X	last_ptr = &proc_list->next ;
X	}
X    }
X
Xreturn ;
X}
X
X/***** **** *** ** * get_proc_list * ** *** **** *****/
X
Xstatic XtProc
Xget_proc_list (proc_list, proc)
X    CuWlmProcedureList *proc_list ;
X    String proc ;
X{
X/*
X */
XXrmQuark quark = XrmStringToQuark (proc) ;
X
Xfor ( ;
X       proc_list != NULL;
X         proc_list = proc_list->next)
X    {
X    if (proc_list->quark == quark)
X	{
X	return proc_list->procedure ;
X	}
X    }
X
Xreturn NULL ;
X}
X
X/***** **** *** ** * get_widget_id * ** *** **** *****/
X
Xstatic Widget
Xget_widget_id (ww, class, name)
XCuWlmWidget ww ;
XString class ;
XString name ;
X{
XXrmValue     string_value ;
XXrmValue     converted_value ;
XWidget id ;
X
Xstring_value.addr = (caddr_t) name ;
Xstring_value.size = strlen (name) ;
X
XXtConvert ((Widget)ww,  XtRString, &string_value, class, &converted_value) ;
Xid = *((Widget *) converted_value.addr) ;
Xreturn id ;
X}
X
X/***** **** *** ** * get_widget_class * ** *** **** *****/
X
Xstatic WidgetClass
Xget_widget_class (ww, class_name)
X    CuWlmWidget ww ;
X    XrmQuark class_name ;
X{
XCuWlmTagClassList *list ;
X
Xfor (list = ww->wlm.tag_class_list;
X     list != NULL;
X     list = list->next)
X    {
X    if (list->quark == class_name)
X	return list->class ;
X    }
X
Xsprintf (error_text, "Widget class (%s) not found\n",
XXrmQuarkToString(class_name)) ;
XXtError (error_text) ;
Xreturn list->class ; /* Only here to shut up lint */
X}
X
X/***** **** *** ** * get_widget_class_list * ** *** **** *****/
X
Xstatic WidgetClassList *
Xget_widget_class_list (initial_list, widget_class, not_found_action)
X    WidgetClassList **initial_list ;
X    XrmQuark widget_class ;
X    CuWlmNotFoundAction not_found_action ;
X{
XWidgetClassList *widget_class_list ;
XWidgetClassList **last_ptr = initial_list ;
X
Xfor (widget_class_list = *initial_list;
X       widget_class_list != NULL;
X         widget_class_list = widget_class_list->next)
X    {
X    if (widget_class_list->quark == widget_class)
X	return widget_class_list ;
X    last_ptr = &widget_class_list->next ;
X    }
X
Xif (not_found_action == CuWlmCroakOnNotFound)
X    {
X    sprintf (error_text, "Widget class (%s) not found\n", widget_class) ;
X    XtError (error_text) ;
X    }
Xelse
Xif (not_found_action == CuWlmNullOnNotFound)
X    {
X    return NULL ;
X    }
X/* if here, no list found, so we add one */
X
Xwidget_class_list = (WidgetClassList *) XtMalloc (sizeof (WidgetClassList)) ;
Xwidget_class_list->quark = widget_class ;
Xwidget_class_list->next = NULL ;
Xwidget_class_list->widget_name_list = NULL ;
Xwidget_class_list->proc_list = NULL ;
X*last_ptr = widget_class_list ;
X
Xreturn widget_class_list ;
X}
X
X/***** **** *** ** * get_widget_name_list * ** *** **** *****/
X
Xstatic WidgetNameList *
Xget_widget_name_list (class_list, widget_name, not_found_action)
X    WidgetClassList *class_list ;
X    String widget_name ;
X    CuWlmNotFoundAction not_found_action ;
X{
XXrmQuark quark = XrmStringToQuark (widget_name) ;
XWidgetNameList *widget_name_list ;
XWidgetNameList **last_ptr = &class_list->widget_name_list ;
X
Xfor (widget_name_list = class_list->widget_name_list;
X     widget_name_list != NULL;
X     widget_name_list = widget_name_list->next)
X    {
X    if (widget_name_list->quark == quark)
X	return widget_name_list ;
X    last_ptr = &widget_name_list->next ;
X    }
X
Xif (not_found_action == CuWlmCroakOnNotFound)
X    {
X    sprintf (error_text, "Widget name (%s) not found\n", widget_name) ;
X    XtError (error_text) ;
X    }
Xelse
Xif (not_found_action == CuWlmNullOnNotFound)
X    {
X    return NULL ;
X    }
X/* if here, no list found, so we add one */
X
Xwidget_name_list = (WidgetNameList *) XtMalloc (sizeof (WidgetNameList)) ;
Xwidget_name_list->quark = quark ;
Xwidget_name_list->next = NULL ;
Xwidget_name_list->widget_id_list = NULL ;
X*last_ptr = widget_name_list ;
X
Xreturn widget_name_list ;
X}
X
X/***** **** *** ** * get_widget_id_list * ** *** **** *****/
X
Xstatic WidgetIdList *
Xget_widget_id_list (name_list, widget_id, not_found_action)
X    WidgetNameList *name_list ;
X    Widget widget_id ;
X    CuWlmNotFoundAction not_found_action ;
X{
XWidgetIdList *widget_id_list ;
XWidgetIdList **last_ptr = &name_list->widget_id_list ;
X
Xfor (widget_id_list = name_list->widget_id_list;
X     widget_id_list != NULL;
X     widget_id_list = widget_id_list->next)
X    {
X    if (widget_id_list->id == widget_id)
X	return widget_id_list ;
X    last_ptr = &widget_id_list->next ;
X    }
X
Xif (not_found_action == CuWlmCroakOnNotFound)
X    {
X    sprintf (error_text, "Widget id (%d) not found\n", widget_id) ;
X    XtError (error_text) ;

END_OF_FILE
echo shar: NEWLINE appended to \"'src/CuWlm.c.aa'\"
if test 26009 -ne `wc -c <'src/CuWlm.c.aa'`; then
    echo shar: \"'src/CuWlm.c.aa'\" unpacked with wrong size!
fi
# end of 'src/CuWlm.c.aa'
fi
echo shar: End of archive 5 \(of 12\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 12 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0