#ifndef	NOIDENT
#ident	"@(#)olitsampler.c	1.8	91/09/14 bin SMI"	/* olexamples:tutorial/s_sampler.c 1.33	*/
#endif

/*
 *        Copyright (C) 1986,1991  Sun Microsystems, Inc
 *                    All rights reserved.
 *          Notice of copyright on this source code 
 *          product does not indicate publication. 
 * 
 * RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by 
 * the U.S. Government is subject to restrictions as set forth 
 * in subparagraph (c)(1)(ii) of the Rights in Technical Data
 * and Computer Software Clause at DFARS 252.227-7013 (Oct. 1988) 
 * and FAR 52.227-19 (c) (June 1987).
 *
 * This file is a product of Sun Microsystems, Inc. and is
 * provided for unrestricted use provided that this legend is
 * included on all media and as a part of the software
 * program in whole or part.  Users may copy or modify this
 * file without charge, but are not authorized to license or
 * distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
 * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE
 * OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * This file is provided with no support and without any
 * obligation on the part of Sun Microsystems, Inc. to assist
 * in its use, correction, modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT
 * TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY
 * PATENTS BY THIS FILE OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any
 * lost revenue or profits or other special, indirect and
 * consequential damages, even if Sun has been advised of the
 * possibility of such damages.
 * 
 *    Sun Microsystems, Inc., 2550 Garcia Avenue,
 *    Mountain View, California 94043.
 *
 */

/*	Copyright (c) 1990 UNIX System Laboratories, Inc.	*/
/*	Copyright (c) 1988 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF     	*/
/*	UNIX System Laboratories, Inc.                     	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

/************************************************************************/
/*	OPEN LOOK WIDGET SAMPLER : prototype widgets and use of form	*/
/*									*/
/*	Copyright (c) 1989 AT&T						*/
/*	Copyright (c) 1988 Hewlett-Packard Company 			*/
/*	Copyright (c) 1988 Massachusetts Institute of Technology	*/
/************************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

/*
 * Headers required for all OPEN LOOK applications.
 */
#include <X11/Intrinsic.h>	
#include <X11/StringDefs.h>

#include <Xol/OpenLook.h>
#include <Xol/OlCursors.h>	/* GetOlQuestionCursor() */

/*
 * Headers required for creating widget instances.
 */
#include <Xol/AbbrevMenu.h>
#include <Xol/BulletinBo.h>
#include <Xol/Button.h>
#include <Xol/Caption.h>
#include <Xol/CheckBox.h>
#include <Xol/ControlAre.h>
#include <Xol/Exclusives.h>
#include <Xol/FooterPane.h>
#include <Xol/Form.h>
#include <Xol/Gauge.h>
#include <Xol/MenuButton.h>
#include <Xol/Nonexclusi.h>
#include <Xol/Notice.h>
#include <Xol/OblongButt.h>
#include <Xol/PopupWindo.h>
#include <Xol/RectButton.h>
#include <Xol/Scrollbar.h>
#include <Xol/ScrolledWi.h>
#include <Xol/ScrollingL.h>
#include <Xol/Slider.h>
#include <Xol/StaticText.h>
#include <Xol/Stub.h>
#include <Xol/TextEdit.h>
#include <Xol/TextField.h>

/*
 * Headers required for creating flat widget instances.
 */
#include <Xol/FExclusive.h>
#include <Xol/FNonexclus.h>
#include <Xol/FCheckBox.h>


/*
 * Defines
 */
#define	MAXTEXT		(1000)
#define	MAXBUF		(100)

/*
 * Ol_PointToPixel() scales to the current screen resolution.
 */
#define	N1_H_PIXEL	Ol_PointToPixel(OL_HORIZONTAL, 1) 
#define	N1_V_PIXEL	Ol_PointToPixel(OL_VERTICAL, 1)
#define	N10_H_PIXELS	Ol_PointToPixel(OL_HORIZONTAL, 10)
#define	N10_V_PIXELS	Ol_PointToPixel(OL_VERTICAL, 10)
#define	N50_H_PIXELS	Ol_PointToPixel(OL_HORIZONTAL, 50)
#define	N50_V_PIXELS	Ol_PointToPixel(OL_VERTICAL, 50)
#define	N100_H_PIXELS	Ol_PointToPixel(OL_HORIZONTAL, 100)
#define	N100_V_PIXELS	Ol_PointToPixel(OL_VERTICAL, 100)
#define	N150_H_PIXELS	Ol_PointToPixel(OL_HORIZONTAL, 150)
#define	N150_V_PIXELS	Ol_PointToPixel(OL_VERTICAL, 150)
#define	N200_H_PIXELS	Ol_PointToPixel(OL_HORIZONTAL, 200)


/*
 * Global variables
 */
static Pixel    red_pixel,
                blue_pixel,
                purple_pixel,
                green_pixel,
                yellow_pixel,
                orange_pixel,
                skyblue_pixel;

static int	i;
static Boolean 	rainbow = FALSE;

/*
 * Note: In many cases, a widget is labelled by making it the child of a
 * caption, which itself is a child of the form.
 */
static Widget   toplevel,
                controlarea,
                cabutton,
                form,
                gauge,
                abbmenu_caption,	/* caption for abbreviatedmenubutton */
                bb_caption,		/* caption for bulletinboard */
                ca_caption,		/* caption for controlarea */
                caption,		/* "True" caption */
                cb_caption,		/* caption for checkbox */
                f_caption,		/* caption for flats */
                fm_caption,		/* caption for form */
                gd_caption,		/* caption for gadgets */
                g_caption,		/* caption for gauge */
                slist_caption,		/* caption for scrollinglist */
                slider_caption,		/* caption for slider */
                te_caption,		/* caption for textedit */
                sw_caption,		/* caption for scrolledwindow */
                nonexclusives,
                nebutton2,
                nebutton3,
                noticeshell,
                noticebox,
                popupshell0,
                popupshell1,
                popupshell2,
                scrollbar,
                stub,
                footer_text;

/* 
 * Form constraint resources used for most widgets in application.
 */
static Arg	genericARGS[] = {
	{ XtNxRefName,		NULL },
	{ XtNyRefName,		NULL },
	{ XtNxOffset,		(XtArgVal)0 },	/* to be initialized below */
	{ XtNyOffset,		(XtArgVal)0 },	/* to be initialized below */
	{ XtNxAddWidth,		(XtArgVal)TRUE },
	{ XtNyAddHeight,	(XtArgVal)TRUE },
};


/* 
 * UTILITY FUNCTIONS
 */


/*
 * Function to vary value displayed in gauge widget.
 */
static void
ChangeGauge(widget)
	Widget          widget;
{
	Arg             arg;
	int             current_value;

	XtSetArg(arg, XtNsliderValue, &current_value);
	XtGetValues(widget, &arg, 1);

	current_value += 10;
	if (current_value > 100)
		current_value = 0;

	/*
	 * The following convenience routine is faster than a SetValues().
	 */
	OlSetGaugeValue(gauge, current_value);
}


/*
 * Xt and Xlib examples to give functionality to the stub widget.
 */
/* ARGSUSED1 */
static void
DrawAndPrint(widget, xevent, region)
	Widget          widget;
	XEvent*		xevent;		/* not used */
	Region          region;		/* not used */
{
	Display        *display;
	static Window   window;
	static Boolean  done1 = FALSE,
	                done2 = FALSE;
	static GC       gc[6];
	XGCValues       values;
	int             i,
	                ix5,
	                ix10,
	                coord,
	                axis,
	                finish = 180 * 64;
	static int      hpixel,
	                vpixel;
	Font            fid = (Font)0;
	char           *fontname = 
			  "*-lucida sans-bold-r-normal-sans-*-140-*-iso8859-1";
	XtGCMask        mask;

	display = XtDisplay(widget);
	window = XtWindow(widget);

	if (!done1) {
		hpixel = (int)N1_H_PIXEL;
		vpixel = (int)N1_V_PIXEL;
		if (hpixel == 0)
			hpixel = 1;
		if (vpixel == 0)
			vpixel = 1;
		done1 = TRUE;
	}
	if (rainbow) {

		values.line_width = 5 * hpixel;

		if (!done2) {
			mask = (XtGCMask)(GCForeground | GCLineWidth);

			values.foreground = red_pixel;
			gc[0] = XtGetGC(widget, mask, &values);
			values.foreground = orange_pixel;
			gc[1] = XtGetGC(widget, mask, &values);
			values.foreground = yellow_pixel;
			gc[2] = XtGetGC(widget, mask, &values);
			values.foreground = green_pixel;
			gc[3] = XtGetGC(widget, mask, &values);
			values.foreground = blue_pixel;
			gc[4] = XtGetGC(widget, mask, &values);
			values.foreground = purple_pixel;
			gc[5] = XtGetGC(widget, mask, &values);
		}
		for (i = 0; i < 6; i++) {

			ix5 = i * 5;
			ix10 = i * 10;

			axis = 95 - ix10;
			coord = ix5 + 5;

			XDrawArc(display,
				window,
				gc[i],
				coord * hpixel,
				coord * vpixel,
				(unsigned int)(axis * hpixel),
				(unsigned int)(axis * vpixel),
				0,
				finish);
		}
	} else
		XClearWindow(display, window);

	/*
	 * Get font for this screen resolution.
	 */
	fid = XLoadFont(display, fontname);

	/*
	 * If successful, label the widget.
	 */
	if (fid != (Font)0) {
		values.font = fid;
		gc[0] = XtGetGC(widget, (XtGCMask)GCFont, &values);
		XDrawString(display, window, gc[0], 5 * hpixel,
			70 * vpixel, "Stub Widget", 11);
		XtReleaseGC(stub, gc[0]);
		XUnloadFont(display, fid);
	}

	/*
	 * This function merely varies the value displayed in the gauge.
	 */
	ChangeGauge(gauge);
}


/* 
 * Function for changing the footer message.
 */
static void
FooterMessage(footer_text, buf)
	Widget          footer_text;
	char            buf[];
{
	Arg             arg;

	XtSetArg(arg, XtNstring, buf);
	XtSetValues(footer_text, &arg, 1);
}


/* 
 * Function for getting color values for the display.
 */
static void
GetColors()
{
	static char    *colors[] = {
		"purple", "blue", "green", "yellow", "orange", "red", "skyblue"
	};
	XrmValue        fromValue,
	                toValue;

	for (i = 0; i < 7; i++) {
		fromValue.size = sizeof (colors[i]);
		fromValue.addr = colors[i];
		XtConvert(toplevel, XtRString, &fromValue, XtRPixel, &toValue);

		switch (i) {
		case 0:
			purple_pixel = *((Pixel *)toValue.addr);
			break;
		case 1:
			blue_pixel = *((Pixel *)toValue.addr);
			break;
		case 2:
			green_pixel = *((Pixel *)toValue.addr);
			break;
		case 3:
			yellow_pixel = *((Pixel *)toValue.addr);
			break;
		case 4:
			orange_pixel = *((Pixel *)toValue.addr);
			break;
		case 5:
			red_pixel = *((Pixel *)toValue.addr);
			break;
		case 6:
			skyblue_pixel = *((Pixel *)toValue.addr);
			break;
		}
	}
}


/*
 * Function for positioning widgets on the form.
 *
 * Note: XtNx[y]RefName are used instead of XtNx[y]RefWidget so
 * that resources for each widget can be set in an .Xdefaults 
 * file.  In addition, this also allows specifying the placement 
 * of any widget on the form without first having to place the 
 * corresponding reference widget(s) on the form.  (This would 
 * NOT be the case with the XtNx[y]RefWidget resource).
 */
static void
SetPosition(widget, xwidget, ywidget)
	Widget          widget;
	char           *xwidget,
	               *ywidget;
{
	static int      nargs;

	if (nargs == 0)
		nargs = XtNumber(genericARGS);

	genericARGS[0].value = (XtArgVal)xwidget;
	genericARGS[1].value = (XtArgVal)ywidget;
	XtSetValues(widget, genericARGS, nargs);
}


/*
 * Function for creating a special cursor for the stub widget.
 */
static void
SetStubCursor(widget)
	Widget          widget;
{
	static Cursor   cursor;

	/*
	 * See OlCursors.c for other cursor possibilities.
	 */
	cursor = GetOlQuestionCursor(XtScreen(widget));
	XDefineCursor(XtDisplay(widget), XtWindow(widget), cursor);
}

/* 
 *  Event handler example to give functionality to the stub widget.
 */
/*ARGSUSED*/
static void
StubEventHandler(widget, closure, event, continue_to_dispatch)
	Widget          widget;			/* not used */
	XtPointer       closure;		/* not used */
	XEvent*		event;
	Boolean*	continue_to_dispatch;	/* not used */
{

	if (event->type == EnterNotify)
		FooterMessage(footer_text,
			"Pointer entered Stub widget");
	else if (event->type == LeaveNotify)
		FooterMessage(footer_text,
			"Pointer left Stub widget");
}


/* 
 * CALLBACKS FOR WIDGETS
 */


/* 
 * With this callback, each widget passes its index as 
 * client_data and thus maps to its own footerpanel message. 
 */
/*ARGSUSED*/
static void
generic_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	int             n = (int)client_data;

	switch (n) {
	case 1:
		FooterMessage(footer_text,
			"OblongButton callback");
		break;

	case 2:
	case 3:
	case 4:
		{
			char            buf[MAXBUF];

			(void) sprintf(buf,
			"[Non-]Exclusives callback for button %d",
				n - 1);
			FooterMessage(footer_text, buf);
		}
		break;
	case 5:
		FooterMessage(footer_text,
			"Properties Apply callback");
		break;
	case 6:
		FooterMessage(footer_text,
			"Properties Set Defaults callback");
		break;
	case 7:
		FooterMessage(footer_text,
			"Properties Reset callback");
		break;
	case 8:
		FooterMessage(footer_text,
			"Properties Reset To Factory callback");
		break;
	case 9:
		FooterMessage(footer_text,
			"OblongButtonGadget callback");
		break;
	case 10:
		FooterMessage(footer_text,
			"Flat widget select callback");
		break;
	}
}


/* 
 * The MenuSelect_cb callback is used by the pulldown menu
 * popup menu, and abbreviatedmenubutton widget and gadget. 
 */
/*ARGSUSED*/
static void
menuSelect_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	int             n = (int)client_data;
	char            buf[MAXBUF];

	(void) sprintf(buf, "Button %d selected", n);
	FooterMessage(footer_text, buf);
}


/*ARGSUSED2*/
static void
nonexclusives_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	Widget          parent = (Widget)client_data;

	/*
	 * If only "More" button, create "Fewer" button.
	 */
	if (widget == nebutton2 && nebutton3 == (Widget)0) {
		nebutton3 = XtCreateManagedWidget("Fewer",
			rectButtonWidgetClass, parent, NULL, 0);
		XtAddCallback(nebutton3, XtNselect,
			nonexclusives_cb, (XtPointer)nonexclusives);
		XtAddCallback(nebutton3, XtNselect,
			generic_cb, (XtPointer)4);

	}

	/*
	 * If all three buttons, delete "Fewer" button.
	 */
	else if (widget == nebutton3 && nebutton3 != (Widget)0) {
		XtDestroyWidget(nebutton3);
		nebutton3 = (Widget)0;
	}
}


/*ARGSUSED1*/
static void
notice_cb1(widget, call_date, client_data)
	Widget          widget;		/*
					 * w = emanating button: where notice
					 * does popup
					 */
	XtPointer       call_date,
	                client_data;
{
	Arg             arg;

	XtSetArg(arg, XtNemanateWidget, (XtArgVal)widget);
	XtSetValues(noticebox, &arg, 1);
	XtPopup(noticeshell, XtGrabNonexclusive);
}


/*ARGSUSED0*/
static void
notice_cb2(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	FooterMessage(footer_text, "Delete callback");
}


/*ARGSUSED*/
static void 
popup_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	XtPopup(client_data, XtGrabNone);
}


/*
 * The rainbow_cb callback is for the RAINBOW button.
 */
/*ARGSUSED*/
static void
rainbow_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	if (rainbow)
		rainbow = FALSE;
	else
		rainbow = TRUE;

	DrawAndPrint(stub, (XEvent *)NULL, (Region)NULL);
}


/* 
 * This callback is used by all three scrollbars.
 */
static void
scrollbar_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	OlScrollbarVerify
			*sbv = (OlScrollbarVerify *)call_date;
	int             n = (int)client_data;
	char            buf[MAXBUF];

	sbv->ok = TRUE;

	switch (n) {
	case 0:
		(void) sprintf(buf,
			"Form ScrollBar moved to %d%%",
			sbv->new_location);
		break;
	case 1:
		(void) sprintf(buf,
			"ScrolledWindow vertical scrollbar moved");
		break;
	case 2:
		(void) sprintf(buf,
		"ScrolledWindow horizontal scrollbar moved");
		break;
	}

	FooterMessage(footer_text, buf);

	/*
	 * Update the form's scrollbar page indicator.
	 */
	if (widget == scrollbar)
		sbv->new_page = (int)(sbv->new_location / 10) + 1;
}


/*ARGSUSED*/
static void
scrollinglist_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	OlListToken     token = (OlListToken)call_date;
	OlListItem     *selected_listitem;
	char            buf[MAXBUF];

	/*
	 * This macro identifies the item selected.
	 */
	selected_listitem = OlListItemPointer(token);

	(void) sprintf(buf,
		"ScrollingList item label %s (data stored %d)",
		selected_listitem->label, selected_listitem->user_data);
	FooterMessage(footer_text, buf);
}


/*ARGSUSED*/
static void
slider_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	OlSliderVerify *sv = (OlSliderVerify *)call_date;
	Arg             arg;

	/*
	 * Slider returns current value.
	 */
	arg.value = (XtArgVal)sv->new_location;
	XtSetArg(arg, XtNbackground, arg.value);
	XtSetValues(stub, &arg, 1);
}


/*ARGSUSED1*/
static void
textfield_cb(widget, client_data, call_date)
	Widget          widget;
	XtPointer       client_data,
	                call_date;
{
	OlTextFieldVerify
			*tfv = (OlTextFieldVerify *)call_date;
	char            buf[MAXBUF];
	Arg             arg;

	(void) sprintf(buf, "TextField User Input: %s",	tfv->string);
	FooterMessage(footer_text, buf);
}


/*
 * THE WIDGET TREE: 
 *
 * 				Toplevel 
 *				   |
 * 				Footerpanel
 *				/     \
 * 			     Form     Statictext
 *			      /
 * 			Remaining OPEN LOOK widgets, gadgets, and flats
 */


/*
 * MAIN
 */
void 
main(argc, argv)
	int             argc;
	char           *argv[];
{
	Arg             arg[10];

	/*
	 * Initialize the environment.
	 */
	{
		toplevel = OlInitialize(NULL,
			"Olitsampler",
			(XrmOptionDescRec *)NULL,
			(Cardinal)0,
			&argc,
			argv);

		/*
		 * Get colors to use later.
		 */
		GetColors();

		/*
		 * Set FORM resources for the specific screen.
		 */
		genericARGS[2].value = (XtArgVal)N10_H_PIXELS;
		genericARGS[3].value = (XtArgVal)N10_V_PIXELS;
	}

	/*
	 * Make all the widgets and then do placement on the form last.
	 */


	/*
	 * FOOTERPANEL: This will be the child of toplevel, with the FORM as
	 * the topchild and STATICTEXT as the footer child.
	 */
	{
		Widget          footerpanel;

		footerpanel = XtCreateManagedWidget("footerpanel",
			footerPanelWidgetClass, toplevel, NULL, 0);

		/*
		 * FORM: Form's caption is the top child of the footerpanel.
		 */
		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"Form"); i++;
		fm_caption = XtCreateManagedWidget("fm_caption",
			captionWidgetClass, footerpanel, arg, i);

		form = XtCreateManagedWidget("form",
			formWidgetClass, fm_caption, NULL, 0);

		/*
		 * Register help for the form, using the file "form.help"
		 */
		(void) OlRegisterHelp(OL_WIDGET_HELP, (XtPointer)form,
			"Form Widget", OL_DISK_SOURCE,
			"/usr/X/lib/tutorial/Xol/form.help");

		/*
		 * Make STATICTEXT as the footer child of the footerpanel.
		 */
		i = 0;
		XtSetArg(arg[i],
			XtNstring,
	(XtArgVal)"StaticText (read only) widget for the FooterPanel"); i++;
		footer_text = XtCreateManagedWidget("statictext",
			staticTextWidgetClass, footerpanel, arg, i);
	}


	/*
	 * All the remaining widgets will be on the form.
	 *
	 * CAPTION: to label the controlarea, latter to be created next.
	 */
	i = 0;
	XtSetArg(arg[i], XtNxResizable, (XtArgVal)TRUE); i++;
	XtSetArg(arg[i], XtNxAttachRight, (XtArgVal)TRUE); i++;
	XtSetArg(arg[i], XtNlabel, (XtArgVal)"ControlArea: "); i++;
	ca_caption = XtCreateManagedWidget("ca_caption",
		captionWidgetClass, form, arg, i);


	/*
	 * CONTROLAREA: the control area contains a popup command window,
	 * a popup property window, and an Delete button with a notice widget 
	 * which pops up when the button is selected.
	 */
	controlarea = XtCreateManagedWidget("controlarea",
		controlAreaWidgetClass, ca_caption, NULL, 0);

	/*
	 * POPUP: Used for Command Window.
	 */
	{
		Widget          widget,
		                popupca11,
		                popupca12,
		                popupbutton1;

		popupbutton1 = XtCreateManagedWidget("Command...",
			oblongButtonWidgetClass, controlarea, NULL, 0);

		/*
		 * Make the popup shell first.
		 */
		i = 0;
		XtSetArg(arg[i], XtNtitle, "OLIT Sampler: Command"); i++;
		popupshell1 = XtCreatePopupShell("popupshell1",
			popupWindowShellWidgetClass, popupbutton1, arg, i);

		/*
		 * Add callback to popup button now that we have popupshell
		 * widget ID.
		 */
		XtAddCallback(popupbutton1, XtNselect, popup_cb, popupshell1);

		/*
		 * The popup window automatically makes three children: upper
		 * and lower control areas and footer: get widget IDs to
		 * populate them.
		 */
		i = 0;
		XtSetArg(arg[i], XtNupperControlArea, &popupca11); i++;
		XtSetArg(arg[i], XtNlowerControlArea, &popupca12); i++;
		XtGetValues(popupshell1, arg, i);

		/*
		 * Populate popup upper control area.
		 *
		 * Make a caption as a label/prompt for the TEXTFIELD.
		 */
		i = 0;
		XtSetArg(arg[i], XtNlabel,
			(XtArgVal)"TextField:"); i++;
		widget = XtCreateManagedWidget("caption",
			captionWidgetClass, popupca11, arg, i);

		widget = XtCreateManagedWidget("textfield",
			textFieldWidgetClass, widget, NULL, 0);

		/*
		 * Callback to "read" user input when <return> typed.
		 */
		XtAddCallback(widget, XtNverification, textfield_cb, NULL);

		/*
		 * Populate popup lower controlarea with buttons: one must be a
		 * default.
		 */
		i = 0;
		XtSetArg(arg[i], XtNdefault, (XtArgVal)TRUE); i++;
		XtCreateManagedWidget("Option 1",
			oblongButtonWidgetClass, popupca12, arg, i);

		XtCreateManagedWidget("Option 2",
			oblongButtonWidgetClass, popupca12, NULL, 0);
		XtSetArg(arg[i], XtNstring, "Footer widget for messages"); i++;
	}


	/*
	 * POPUP: Used for Property Sheet.
	 */
	{
		Widget          exclusives,
		                widget,
		                popupca21,
		                popupbutton2;

		/*
		 * XtCallbackRec used for widget SetValues().
		 */

		static XtCallbackRec popup_applyCBR[] = {
			{ generic_cb, (XtPointer)5 },
			{ (XtCallbackProc)NULL, (XtPointer)NULL },
		};

		static XtCallbackRec popup_setdefaultsCBR[] = {
			{ generic_cb, (XtPointer)6 },
			{ (XtCallbackProc) NULL, (XtPointer)NULL },
		};

		static XtCallbackRec popup_resetCBR[] = {
			{ generic_cb, (XtPointer)7 },
			{ (XtCallbackProc) NULL, (XtPointer)NULL },
		};

		static XtCallbackRec popup_resetfactoryCBR[] = {
			{ generic_cb, (XtPointer)8 },
			{ (XtCallbackProc)NULL, (XtPointer)NULL },
		};

		popupbutton2 = XtCreateManagedWidget("Properties...",
			oblongButtonWidgetClass, controlarea, NULL, 0);

		/*
		 * Make the popup shell first: NOTE: callbacks must be set for
		 * creation of the automatic buttons. In this example, mapping
		 * is to one function but does not have to be.
		 */
		i = 0;
		XtSetArg(arg[0], XtNtitle,
			"OLIT Sampler: Properties Popup"); i++;
		XtSetArg(arg[i], XtNreset, (XtArgVal)popup_resetCBR); i++;
		XtSetArg(arg[i], XtNapply, (XtArgVal)popup_applyCBR); i++;
		XtSetArg(arg[i], XtNresetFactory,
			(XtArgVal)popup_resetfactoryCBR); i++;
		XtSetArg(arg[i], XtNsetDefaults,
			(XtArgVal)popup_setdefaultsCBR); i++;
		popupshell2 = XtCreatePopupShell("POPUPSHELL",
			popupWindowShellWidgetClass, popupbutton2, arg, i);

		/*
		 * Add callback to popup button now that we have popupshell
		 * widget ID.
		 */
		XtAddCallback(popupbutton2, XtNselect, popup_cb, popupshell2);

		/*
		 * Get widget IDs of popup children needed.  Note that lower
		 * control area ID not needed since automatic buttons are
		 * created by code above.
		 */
		i = 0;
		XtSetArg(arg[i], XtNupperControlArea, &popupca21); i++;
		XtGetValues(popupshell2, arg, i);

		/*
		 * Populate popup upper control area with EXCLUSIVES and
		 * NONEXLCUSIVES. Note that there is no need to populate popup
		 * lower controlarea.
		 */
		i = 0;
		XtSetArg(arg[i], XtNlayoutType, OL_FIXEDCOLS); i++;
		XtSetValues(popupca21, arg, i);

		widget = XtCreateManagedWidget("Exclusives: ",
			captionWidgetClass, popupca21, NULL, 0);

		i = 0;
		XtSetArg(arg[0], XtNlayoutType, (XtArgVal)OL_FIXEDROWS); i++;
		XtSetArg(arg[0], XtNmeasure, (XtArgVal)1); i++;
		exclusives = XtCreateManagedWidget("exclusives",
			exclusivesWidgetClass, widget, arg, i);

		i = 0;
		XtSetArg(arg[0], XtNlabel, (XtArgVal)"Choice 1"); i++;
		widget = XtCreateManagedWidget("rbutton",
			rectButtonWidgetClass, exclusives, arg, i);
		XtAddCallback(widget, XtNselect, generic_cb, (XtPointer)2);

		widget = XtCreateManagedWidget("Choice 2",
			rectButtonWidgetClass, exclusives, NULL, 0);
		XtAddCallback(widget, XtNselect, generic_cb, (XtPointer)3);

		widget = XtCreateManagedWidget("Choice 3",
			rectButtonWidgetClass, exclusives, NULL, 0);
		XtAddCallback(widget, XtNselect, generic_cb, (XtPointer)4);

		widget = XtCreateManagedWidget("Non-exclusives: ",
			captionWidgetClass, popupca21, NULL, 0);

		i = 0;
		XtSetArg(arg[i], XtNlayoutType, (XtArgVal) OL_FIXEDROWS); i++;
		XtSetArg(arg[i], XtNmeasure, (XtArgVal) 1); i++;
		nonexclusives = XtCreateManagedWidget("nonexclusives",
			nonexclusivesWidgetClass, widget, arg, i);

		widget = XtCreateManagedWidget("Choice 1",
			rectButtonWidgetClass, nonexclusives, NULL, 0);
		XtAddCallback(widget, XtNselect, generic_cb, (XtPointer)2);

		nebutton2 = XtCreateManagedWidget("More",
			rectButtonWidgetClass, nonexclusives, NULL, 0);
		XtAddCallback(nebutton2, XtNselect, nonexclusives_cb,
			nonexclusives);
		XtAddCallback(nebutton2, XtNselect, generic_cb, (XtPointer)3);
	}


	/*
	 * TO MAKE A MENU:
	 * 
	 * Widget Tree for creating menu:
	 *
	 *		( parent widget )
	 *			|
	 *		menubutton ( visible/mouse sensitive symbol for menu )
	 *			|
	 *		pane ( used for placement of menu button set )
	 *			|
	 *		       / \
	 *		     /	   \
	 *	        button1   button2
	 *
	 * Create a menubutton and menu with a pushpin.
	 */
	{
		static Widget   menubutton,
		                menupane,
		                widget;

		i = 0;
		XtSetArg(arg[i], XtNpushpin, (XtArgVal)OL_OUT); i++;
		XtSetArg(arg[i], XtNlabelType, (XtArgVal)OL_STRING); i++;
		XtSetArg(arg[i], XtNlabelJustify, (XtArgVal)OL_LEFT); i++;
		XtSetArg(arg[i], XtNrecomputeSize, (XtArgVal)TRUE); i++;
		menubutton = XtCreateManagedWidget("MenuButton",
			menuButtonWidgetClass, controlarea, arg, i);

		/*
		 * Get the Widget id of the menupane of the menubutton.
		 */
		i = 0;
		XtSetArg(arg[i], XtNmenuPane, (XtArgVal)&menupane); i++;
		XtGetValues(menubutton, arg, i);

		/*
		 * Make two oblongbuttons on the menupane, with select
		 * callbacks.
		 */
		widget = XtCreateManagedWidget("One",
			oblongButtonWidgetClass, menupane, NULL, 0);
		XtAddCallback(widget, XtNselect, menuSelect_cb, (XtPointer)1);

		widget = XtCreateManagedWidget("Two",
			oblongButtonWidgetClass, menupane, NULL, 0);
		XtAddCallback(widget, XtNselect, menuSelect_cb, (XtPointer)2);
	}


	/*
	 * NOTICE: attach to an EXIT button in the control area.
	 */
	{
		static Widget   noticetext;

		static Arg      noticeARGS[] = {
			{ XtNtextArea, (XtArgVal)&noticetext },
			{ XtNcontrolArea, (XtArgVal)&noticebox },
		};

		Widget          widget;

		cabutton = XtCreateManagedWidget("Delete",
			oblongButtonWidgetClass, controlarea, NULL, 0);

		/*
		 * Attach notice popup callback to "EXIT" controlarea button.
		 */
		XtAddCallback(cabutton, XtNselect, notice_cb1, NULL);

		/*
		 * Create notice popup shell.
		 */
		noticeshell = XtCreatePopupShell("notice",
			noticeShellWidgetClass, cabutton, NULL, 0);

		/*
		 * Get the widget ids of noticebox and textarea of noticebox.
		 */
		XtGetValues(noticeshell, noticeARGS, XtNumber(noticeARGS));

		/*
		 * Add text to text area of noticebox.
		 */
		i = 0;
		XtSetArg(arg[i], XtNstring,
			(XtArgVal)"Notice Widget:\n Confirm"); i++;
		XtSetValues(noticetext, arg, i);

		/*
		 * Add two buttons to noticebox.
		 *
		 * First button has an exit() callback.
		 */
		widget = XtCreateManagedWidget("Delete",
			oblongButtonWidgetClass, noticebox, NULL, 0);
		XtAddCallback(widget, XtNselect, notice_cb2, noticebox);

		/*
		 * Second button is a no-op that pops down notice widget
		 * without exiting.
		 */
		XtCreateManagedWidget("Cancel",
			oblongButtonWidgetClass, noticebox, NULL, 0);
	}


	/*
	 * CAPTION
	 */
	{
		static Widget   widget;

		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"Caption"); i++;
		caption = XtCreateManagedWidget("caption",
			captionWidgetClass, form, arg, i);

		widget = XtCreateManagedWidget("Draw Rainbow",
			oblongButtonWidgetClass, caption, NULL, 0);

		XtAddCallback(widget, XtNselect, rainbow_cb, NULL);
	}


	/*
	 * Stub WIDGET: this will be used as a drawing canvas.
	 *	 
	 * First two arguments scale widget to resolution of screen.
	 */
	i = 0;
	XtSetArg(arg[i], XtNheight, (XtArgVal)N100_V_PIXELS); i++;
	XtSetArg(arg[i], XtNwidth, (XtArgVal)N100_H_PIXELS); i++;
	XtSetArg(arg[i], XtNbackground, skyblue_pixel); i++;

	/*
	 * DrawAndPrint() will be called with an Expose event;
	 */
	XtSetArg(arg[i], XtNexpose, DrawAndPrint); i++;
	stub = XtCreateManagedWidget("stub", stubWidgetClass, form, arg, i);

	/*
	 * Add an eventhandler to track when the pointer enters and leaves the
	 * stub widget window.
	 */
	XtAddEventHandler(stub, EnterWindowMask | LeaveWindowMask,
		FALSE, StubEventHandler, (XtPointer)NULL);

	/*
	 * Set the special cursor for stub widget window below once the widget
	 * tree realized.
	 */


	/*
	 * BULLETINBOARD: with ABBREVIATEDMENUBUTTON, CHECKBOX, and TEXTEDIT
	 * widgets in it, each within a caption labelling the widget.
	 */
	{
		static char     textedit_string[] =
			"This text is in a TextEdit widget and can be edited.";

		Widget          widget,
		                bulletinboard,
		                abbmenubutton,
		                abbmenupane,
		                checkbox;

		Dimension       height,
		                yvalue,
		                xpad = (Dimension)N10_H_PIXELS,
		                ypad = (Dimension)N10_V_PIXELS;



		/*
		 * BULLETINBOARD.
		 */
		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal) OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"BulletinBoard"); i++;
		bb_caption = XtCreateManagedWidget("bb_caption",
			captionWidgetClass, form, arg, i);

		bulletinboard = XtCreateManagedWidget("bulletinboard",
			bulletinBoardWidgetClass, bb_caption, NULL, 0);

		/*
		 * Set some resources for the bulletinboard.
		 */
		i = 0;
		XtSetArg(arg[i], XtNborderWidth, (XtArgVal)2); i++;
		XtSetArg(arg[i], XtNborderColor, (XtArgVal)orange_pixel); i++;
		XtSetValues(bulletinboard, arg, i);


		/*
		 * Abbreviated Menu Button
		 */
		yvalue = ypad;

		i = 0;
		XtSetArg(arg[i], XtNx, (XtArgVal)xpad); i++;
		XtSetArg(arg[i], XtNy, (XtArgVal)yvalue); i++;
		XtSetArg(arg[i], XtNlabel,
			(XtArgVal)"AbbreviatedMenuButton: "); i++;

		abbmenu_caption = XtCreateManagedWidget("abbmenu_caption",
			captionWidgetClass, bulletinboard, arg, i);

		abbmenubutton = XtCreateManagedWidget("abbmenubutton",
			abbrevMenuButtonWidgetClass, abbmenu_caption, arg, i);

		/*
		 * Get the Widget ID of the menupane of the abbreviated menu
		 * button.
		 */
		i = 0;
		XtSetArg(arg[i], XtNmenuPane, (XtArgVal)&abbmenupane); i++;
		XtGetValues(abbmenubutton, arg, i);

		i = 0;
		widget = XtCreateManagedWidget("Button 1",
			oblongButtonWidgetClass, abbmenupane, arg, i);
		XtAddCallback(widget, XtNselect, menuSelect_cb, (XtPointer)1);

		i = 0;
		widget = XtCreateManagedWidget("Button 2",
			oblongButtonWidgetClass, abbmenupane, arg, i);
		XtAddCallback(widget, XtNselect, menuSelect_cb, (XtPointer)2);


		/*
		 * CHECKBOX.
		 */
		i = 0;
		XtSetArg(arg[i], XtNheight, &height); i++;
		XtGetValues(abbmenubutton, arg, 1);

		yvalue = yvalue + height + ypad;

		i = 0;
		XtSetArg(arg[i], XtNx, xpad); i++;
		XtSetArg(arg[i], XtNy, yvalue); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"CheckBox:"); i++;
		cb_caption = XtCreateManagedWidget("cb_caption",
			captionWidgetClass, bulletinboard, arg, i);

		i = 0;
		checkbox = XtCreateManagedWidget("Label",
			checkBoxWidgetClass, cb_caption, arg, i);


		/*
		 * TEXTEDIT WIDGET.
		 */
		i = 0;
		XtSetArg(arg[i], XtNheight, &height); i++;
		XtGetValues(checkbox, arg, 1);

		yvalue = yvalue + height + ypad;

		i = 0;
		XtSetArg(arg[i], XtNx, (XtArgVal)xpad); i++;
		XtSetArg(arg[i], XtNy, (XtArgVal)yvalue); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"TextEdit:"); i++;
		te_caption = XtCreateManagedWidget("te_caption",
			captionWidgetClass, bulletinboard, arg, i);

		i = 0;
		XtSetArg(arg[i], XtNheight, (XtArgVal)N50_V_PIXELS); i++;
		XtSetArg(arg[i], XtNwidth, (XtArgVal)N150_H_PIXELS); i++;
		XtSetArg(arg[i], XtNsourceType,
			(XtArgVal)OL_STRING_SOURCE); i++;
		XtSetArg(arg[i], XtNsource, (XtArgVal)textedit_string); i++;
		XtCreateManagedWidget("textedit", textEditWidgetClass, 
			te_caption, arg, i);
	}


	/*
	 * SCROLLINGLIST
	 */
	{
		static Widget   	scrollinglist;
		static OlListToken	(*scrollinglistADDfn)();
		static OlListItem	sl_item[10];
		
		int             	natoi;

		/*
		 * Use a caption to label the scrollinglist.
		 */
		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"ScrollingList"); i++;
		slist_caption = XtCreateManagedWidget("slist_caption",
			captionWidgetClass, form, arg, i);

		i = 0;
		XtSetArg(arg[i], XtNviewHeight, (XtArgVal)7); i++;
		scrollinglist = XtCreateManagedWidget("scrollinglist",
			scrollingListWidgetClass, slist_caption, arg, i);

		/*
		 * Get the pointer to the scrollinglist function in order to
		 * add items.
		 */
		i = 0;
		XtSetArg(arg[i], XtNapplAddItem,
			(XtArgVal)&scrollinglistADDfn); i++;
		XtGetValues(scrollinglist, arg, i);

		natoi = (int)'A';

		for (i = 0; i < 10; i++) {
			sl_item[i].label_type = (OlDefine)OL_STRING;
			
			sl_item[i].label = strcpy(XtMalloc((unsigned)7),
				"ITEM   ");
				
			((String)sl_item[i].label)[5] = natoi;
			
			sl_item[i].mnemonic = tolower(natoi++);

			/*
			 * This field is for storing any type of data desired.
			 */
			sl_item[i].user_data = (XtPointer)i;
			
			(*scrollinglistADDfn)(scrollinglist, NULL, NULL,
				sl_item[i]);
		}

		/*
		 * Callback to be invoked when user selects an item.
		 */

		XtAddCallback(scrollinglist, XtNuserMakeCurrent,
			scrollinglist_cb, NULL);
	}


	/*
	 * SCROLLED WINDOW
	 */
	{
		static Widget   scrolledwindow;
		static char     swstring[] = "This text is in a\n\
StaticText widget\n\
in a scrolled window.\n\
You can move it up\n\
and down or left\n\
and right with the\n\
two scrollbars.\n";

		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"ScrolledWindow"); i++;
		sw_caption = XtCreateManagedWidget("sw_caption",
			captionWidgetClass, form, arg, i);

		i = 0;
		XtSetArg(arg[i], XtNheight, N150_V_PIXELS); i++;
		XtSetArg(arg[i], XtNwidth, N100_H_PIXELS); i++;
		XtSetArg(arg[i], XtNvStepSize, 20); i++;
		XtSetArg(arg[i], XtNhStepSize, 20); i++;
		scrolledwindow = XtCreateManagedWidget("scrolledwindow",
			scrolledWindowWidgetClass, sw_caption, arg, i);
		XtAddCallback(scrolledwindow, XtNvSliderMoved, scrollbar_cb,
			(XtPointer) 1);
		XtAddCallback(scrolledwindow, XtNhSliderMoved, scrollbar_cb,
			(XtPointer) 2);

		/*
		 * Make a statictext widget in the scrolled window to scroll
		 * with the scrollbars.
		 */
		i = 0;
		XtSetArg(arg[i], XtNheight, N150_V_PIXELS); i++;
		XtSetArg(arg[i], XtNstring, swstring); i++;
		XtCreateManagedWidget("statictext",
			staticTextWidgetClass, scrolledwindow, arg, i);
	}


	/*
	 * SLIDER
	 *
	 * The slider will be used to change the background of the stub widget:
	 * calculate the number of colors for the screen and set the slider
	 * range from 0 to (N-1) with a granularity of 1; see the slider_cb
	 * function for the rest of the code/functionality.
	 */
	{
		Display        *display = XtDisplay(toplevel);
		int             screen = XDefaultScreen(display);
		int             n,
		                ncolors = 2;
		Widget          w;

		n = XDefaultDepth(display, screen);

		for (i = 1; i < n; i++) {
			ncolors = ncolors * 2;
		}

		ncolors = ncolors - 1;

		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"Slider"); i++;
		slider_caption = XtCreateManagedWidget("slider_caption",
			captionWidgetClass, form, arg, i);

		i = 0;
		XtSetArg(arg[i], XtNwidth, (XtArgVal)N200_H_PIXELS); i++;
		XtSetArg(arg[i], XtNorientation, (XtArgVal)OL_HORIZONTAL); i++;
		XtSetArg(arg[i], XtNsliderMax, (XtArgVal)ncolors); i++;
		XtSetArg(arg[i], XtNgranularity, (XtArgVal)1); i++;
		XtSetArg(arg[i], XtNticks, (XtArgVal)5); i++;
		XtSetArg(arg[i], XtNtickUnit, (XtArgVal)OL_SLIDERVALUE); i++;
		XtSetArg(arg[i], XtNdragCBType, (XtArgVal)OL_RELEASE); i++;
		w = XtCreateManagedWidget("slider",
			sliderWidgetClass, slider_caption, arg, i);
		XtAddCallback(w, XtNsliderMoved, slider_cb, NULL);
	}


	/*
	 * GAUGE
	 */
	i = 0;
	XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
	XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
	XtSetArg(arg[i], XtNlabel, (XtArgVal)"Gauge"); i++;
	g_caption = XtCreateManagedWidget("g_caption",
		captionWidgetClass, form, arg, i);

	i = 0;
	XtSetArg(arg[i], XtNwidth, (XtArgVal)N200_H_PIXELS); i++;
	XtSetArg(arg[i], XtNorientation, (XtArgVal)OL_HORIZONTAL); i++;
	XtSetArg(arg[i], XtNsliderMax, (XtArgVal)100); i++;
	XtSetArg(arg[i], XtNgranularity, (XtArgVal)10); i++;
	XtSetArg(arg[i], XtNticks, (XtArgVal)10); i++;
	XtSetArg(arg[i], XtNtickUnit, (XtArgVal)OL_SLIDERVALUE); i++;
	gauge = XtCreateManagedWidget("gauge", gaugeWidgetClass, g_caption,
		arg, i);


	/*
	 * GADGETS: the oblongbutton gadget and abbreviatedmenubutton gadget
	 * are displayed in a bulletinboard, the latter in a caption entitled,
	 * "Gadgets."
	 */
	{
		Widget          carea,
		                button,
		                menubutton,
		                menupane;

		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"Gadgets"); i++;
		gd_caption = XtCreateManagedWidget("gd_caption",
			captionWidgetClass, form, arg, i);

		i = 0;
		XtSetArg(arg[i], XtNborderWidth, (XtArgVal)2); i++;
		XtSetArg(arg[i], XtNborderColor, (XtArgVal)orange_pixel); i++;
		carea = XtCreateManagedWidget("controlarea",
			controlAreaWidgetClass, gd_caption, arg, i);

		i = 0;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"OblongButton"); i++;
		XtSetArg(arg[i], XtNx, (XtArgVal)N10_H_PIXELS); i++;
		XtSetArg(arg[i], XtNy, (XtArgVal)N10_V_PIXELS); i++;
		button = XtCreateManagedWidget("buttongadget",
			oblongButtonGadgetClass, carea, arg, i);
		XtAddCallback(button, XtNselect, generic_cb, (XtPointer)9);

		i = 0;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"MenuButton"); i++;
		XtSetArg(arg[i], XtNx, (XtArgVal) N100_H_PIXELS);
		XtSetArg(arg[i], XtNy, (XtArgVal) N10_V_PIXELS); i++;
		menubutton = XtCreateManagedWidget("menubutton",
			menuButtonGadgetClass, carea, arg, i);
		i = 0;
		XtSetArg(arg[i], XtNmenuPane, (XtArgVal)&menupane); i++;
		XtGetValues(menubutton, arg, i);

		i = 0;
		button = XtCreateManagedWidget("Button 1",
			oblongButtonGadgetClass, menupane, arg, i);
		XtAddCallback(button, XtNselect, menuSelect_cb, (XtPointer)1);

		i = 0;
		button = XtCreateManagedWidget("Button 2",
			oblongButtonGadgetClass, menupane, arg, i);
		XtAddCallback(button, XtNselect, menuSelect_cb, (XtPointer)2);
	}


	/*
	 * FLAT WIDGETS: the flatexclusives, flatnonexclusives, and
	 * flatcheckbox are displayed in a bulletinboard, the latter in a
	 * caption entitled, "Flat Widgets."
	 */
	{
		static String   fields1[] = {
			XtNbackground, XtNlabel, XtNselectProc, XtNclientData
		};
		typedef struct {
			XtArgVal        background;	/* item's background */
			XtArgVal        label;		/* item's label */
			XtArgVal        select;		/* ...select callback */
			XtArgVal        client_data;	/* client_data for
							 * callback */
		} FlatData1;
		static FlatData1 *items1;

		/*
		 * For flatcheckbox: note "customized" fields.
		 */
		static String   fields2[] = {
			XtNbackground,
			XtNlabel,
			XtNset,
			XtNselectProc,
			XtNclientData
		};
		typedef struct {
			XtArgVal        background;	/* item's background */
			XtArgVal        label;		/* item's label */
			XtArgVal        set;		/* item's set status */
			XtArgVal        select;		/* ... select callback */
			XtArgVal        client_data;	/* client_data for
							 * callback */
		} FlatData2;
		static FlatData2 *items2;
		
		Widget          widget,
		                carea;
		WidgetClass     class;
		int             num_subobjects = 3;
		Dimension       hspace = N10_H_PIXELS,
		                vspace = N10_V_PIXELS;

		/*
		 * For flatexclusives and flatnonexclusives: note "customized"
		 * fields.
		 */
		items1 = (FlatData1 *)XtMalloc(
			(Cardinal)(num_subobjects * sizeof (FlatData1)));

		items2 = (FlatData2 *)XtMalloc(
			(Cardinal)(num_subobjects * sizeof (FlatData2)));

		i = 0;
		XtSetArg(arg[i], XtNposition, (XtArgVal)OL_TOP); i++;
		XtSetArg(arg[i], XtNalignment, (XtArgVal)OL_CENTER); i++;
		XtSetArg(arg[i], XtNlabel, (XtArgVal)"Flat Widgets"); i++;
		f_caption = XtCreateManagedWidget("f_caption",
			captionWidgetClass, form, arg, i);

		i = 0;
		XtSetArg(arg[i], XtNborderWidth, (XtArgVal)2); i++;
		XtSetArg(arg[i], XtNborderColor, (XtArgVal)orange_pixel); i++;
		XtSetArg(arg[i], XtNhSpace, hspace); i++;
		XtSetArg(arg[i], XtNvSpace, vspace); i++;
		XtSetArg(arg[i], XtNhPad, hspace); i++;
		XtSetArg(arg[i], XtNvPad, vspace); i++;

		carea = XtCreateManagedWidget("controlarea",
			controlAreaWidgetClass, f_caption, arg, i);

		widget = XtCreateManagedWidget("Exclusives: ",
			captionWidgetClass, carea, NULL, 0);

		items1[0].background = (XtArgVal)red_pixel;
		items1[1].background = (XtArgVal)green_pixel;
		items1[2].background = (XtArgVal)blue_pixel;

		items1[0].label =
			items1[1].label =
			items1[2].label = (XtArgVal)"";

		items1[0].select =
			items1[1].select =
			items1[2].select = (XtArgVal)generic_cb;

		items1[0].client_data =
			items1[1].client_data =
			items1[2].client_data = (XtArgVal)10;

		class = flatExclusivesWidgetClass;
		i = 0;
		
		XtSetArg(arg[i], XtNitems, items1); i++;
		XtSetArg(arg[i], XtNnumItems, num_subobjects); i++;
		XtSetArg(arg[i], XtNitemFields, fields1); i++;
		XtSetArg(arg[i], XtNnumItemFields, XtNumber(fields1)); i++;
		
		XtCreateManagedWidget("flatexclusives", class, widget, arg, i);

		widget = XtCreateManagedWidget("Non-exclusives: ",
			captionWidgetClass, carea, NULL, 0);
		
		class = flatNonexclusivesWidgetClass;
		
		XtCreateManagedWidget("flatnonexclusives", class, widget, arg,
			i);

		items2[0].background = (XtArgVal)red_pixel;
		items2[1].background = (XtArgVal)green_pixel;
		items2[2].background = (XtArgVal)blue_pixel;
		
		items2[0].label = (XtArgVal)"Check Box 1";
		items2[1].label = (XtArgVal)"Check Box 2";
		items2[2].label = (XtArgVal)"Check Box 3";
		
		items2[0].set =
			items2[1].set =
			items2[2].set = (XtArgVal)TRUE;

		items2[0].select =
			items2[1].select =
			items2[2].select = (XtArgVal)generic_cb;

		items2[0].client_data =
			items2[1].client_data =
			items2[2].client_data = (XtArgVal)10;

		class = flatCheckBoxWidgetClass;
		
		XtSetArg(arg[i], XtNitems, items2); i++;
		XtSetArg(arg[i], XtNnumItems, num_subobjects); i++;
		XtSetArg(arg[i], XtNitemFields, fields2); i++;
		XtSetArg(arg[i], XtNnumItemFields, XtNumber(fields2)); i++;
		
		XtCreateManagedWidget("flatcheckbox", class, carea, arg, i);
	}


	/*
	 * SCROLLBAR: attach to the right & bottom of the form.
	 */
	{
		static Arg      scrollbarARGS[] = {
			/*
			 * Widget resources.
			 */
			{ XtNproportionLength, 10 },
			{ XtNshowPage, OL_LEFT },

			/*
			 * Form resources.
			 */
			{ XtNyResizable, (XtArgVal)TRUE },
			{ XtNyAttachBottom, (XtArgVal)TRUE },
			{ XtNxAttachRight, (XtArgVal)TRUE },
			{ XtNxVaryOffset, (XtArgVal)TRUE },
		};

		scrollbar = XtCreateManagedWidget("scrollbar",
			scrollbarWidgetClass, form, scrollbarARGS,
			XtNumber(scrollbarARGS));
		XtAddCallback(scrollbar, XtNsliderMoved, scrollbar_cb,
			(XtPointer)0);
	}


	/*
	 * Position all the widgets on the form.  Note that reference names are
	 * used. Note that 10 horizontal and vertical pixels are used in most
	 * cases; in a  few cases special values are used.
	 */
	{
		static Dimension
				width1,
		                width2;
		static Position x1,
		                x2;

		static Arg      getArgs1[] = {
			{ XtNx, (XtArgVal)&x1 },
			{ XtNwidth, (XtArgVal)&width1 }
		};

		static Arg      getArgs2[] = {
			{ XtNx, (XtArgVal)&x2 },
			{ XtNwidth, (XtArgVal)&width2 }
		};
		Arg             arg;

		genericARGS[2].value = (XtArgVal)0;
		genericARGS[3].value = (XtArgVal)0;
		SetPosition(ca_caption, "form", "form");
		
		genericARGS[2].value = (XtArgVal)N10_H_PIXELS;
		genericARGS[3].value = (XtArgVal)N10_V_PIXELS;
		SetPosition(caption, "form", "ca_caption");
		SetPosition(stub, "form", "caption");

		/*
		 * Position bulletinboard to right of caption or stub,
		 * whichever is wider.
		 */
		XtSetArg(arg, XtNwidth, &width1);
		XtGetValues(caption, &arg, 1);
		XtSetArg(arg, XtNwidth, &width2);
		XtGetValues(stub, &arg, 1);

		if (width1 > width2)
			SetPosition(bb_caption, "caption", "ca_caption");
		else
			SetPosition(bb_caption, "stub", "ca_caption");

		SetPosition(slider_caption, "form", "stub");
		SetPosition(g_caption, "form", "slider_caption");
		SetPosition(f_caption, "form", "gd_caption");
		SetPosition(slist_caption, "bb_caption", "ca_caption");
		SetPosition(sw_caption, "slist_caption", "ca_caption");

		genericARGS[2].value = (XtArgVal)(7 * N10_H_PIXELS);
		SetPosition(gd_caption, "slider_caption", "slist_caption");

		/*
		 * Position scrollbar to right of flat widgets or
		 * scrolledwindow, whichever extends further to the right of
		 * the form.
		 */
		genericARGS[2].value = (XtArgVal)N50_H_PIXELS;
		genericARGS[3].value = (XtArgVal)0;

		XtGetValues(f_caption, getArgs1, XtNumber(getArgs1));
		XtGetValues(sw_caption, getArgs2, XtNumber(getArgs2));

		width1 = width1 + (Dimension)x1;
		width2 = width2 + (Dimension)x2;

		if (width1 > width2)
			SetPosition(scrollbar, "f_caption", "ca_caption");
		else
			SetPosition(scrollbar, "sw_caption", "ca_caption");

		genericARGS[3].value = (XtArgVal)N10_V_PIXELS;
	}

	/*
	 * Realize the widget tree.
	 */
	XtRealizeWidget(toplevel);

	/*
	 * The special cursor for the stub widget can be set now that it has
	 * been realized as part of the widget tree.
	 */
	SetStubCursor(stub);

	/*
	 * Turn control over to the Xt intrinsics and OPEN LOOK.
	 */
	XtMainLoop();
	/*NOTREACHED*/
} /* main */


/* end of olitsampler.c */
