/*
** Generated by X-Designer 
** traverse obscured
*/
/*
**LIBS: -lXm -lXt -lX11
*/

#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>

#include <Xm/Xm.h>
#include <Xm/DialogS.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/ScrollBar.h>
#include <Xm/ScrolledW.h>
#include <stdio.h>

extern void traverse_obscured ();
extern Boolean aardvarkConverter ();
extern Boolean objStringConverter ();
Widget appshell = (Widget) NULL;
Widget form = (Widget) NULL;
Widget scrollwin = (Widget) NULL;
Widget hsb = (Widget) NULL;
Widget vsb = (Widget) NULL;
Widget rowcol = (Widget) NULL;
Widget button1 = (Widget) NULL;
Widget button2 = (Widget) NULL;
Widget button3 = (Widget) NULL;
Widget label = (Widget) NULL;

#include "XdbPrintTree.c"

void 
traverse_obscured(w, client_data, call_data)
	Widget          w;
	XtPointer       client_data;
	XtPointer       call_data;
{
	XmScrollVisible(w, ((XmTraverseObscuredCallbackStruct *)
			    call_data)->traversal_destination, 0, 0);
}


void create_appshell (display, app_name, app_argc, app_argv)
Display *display;
char *app_name;
int app_argc;
char **app_argv;
{
	Widget children[3];      /* Children to manage */
	Arg al[64];                    /* Arg List */
	register int ac = 0;           /* Arg Count */
	XmString xmstrings[16];    /* temporary storage for XmStrings */

	XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++;
	XtSetArg(al[ac], XmNtitle, "Automatic Traversal to Obscured Widgets in Scrolled Window"); ac++;
	XtSetArg(al[ac], XmNargc, app_argc); ac++;
	XtSetArg(al[ac], XmNargv, app_argv); ac++;
	appshell = XtAppCreateShell ( app_name, "XApplication", applicationShellWidgetClass, display, al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
	XtSetArg(al[ac], XmNhorizontalSpacing, 10); ac++;
	XtSetArg(al[ac], XmNverticalSpacing, 10); ac++;
	form = XmCreateForm ( appshell, "form", al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNscrollingPolicy, XmAUTOMATIC); ac++;
	scrollwin = XmCreateScrolledWindow ( form, "scrollwin", al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNhorizontalScrollBar, &hsb ); ac++;
	XtSetArg(al[ac], XmNverticalScrollBar, &vsb ); ac++;
	XtGetValues(scrollwin, al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
	rowcol = XmCreateRowColumn ( scrollwin, "rowcol", al, ac );
	ac = 0;
	button1 = XmCreatePushButton ( rowcol, "button1", al, ac );
	button2 = XmCreatePushButton ( rowcol, "button2", al, ac );
	button3 = XmCreatePushButton ( rowcol, "button3", al, ac );
	xmstrings[0] = XmStringCreateLtoR("Use arrow keys to traverse between buttons.\nTraversing to an obscured button will scroll the window to reveal it.", (XmStringCharSet)XmFONTLIST_DEFAULT_TAG);
	XtSetArg(al[ac], XmNlabelString, xmstrings[0]); ac++;
	label = XmCreateLabel ( form, "label", al, ac );
	ac = 0;
	XmStringFree ( xmstrings [ 0 ] );

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
	XtSetArg(al[ac], XmNtopWidget, label); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_NONE); ac++;
	XtSetValues ( scrollwin,al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
	XtSetValues ( label,al, ac );
	ac = 0;
	XtAddCallback (scrollwin, XmNtraverseObscuredCallback, traverse_obscured,NULL);
	children[ac++] = button1;
	children[ac++] = button2;
	children[ac++] = button3;
	XtManageChildren(children, ac);
	ac = 0;
	children[ac++] = rowcol;
	XtManageChildren(children, ac);
	ac = 0;
	XmScrolledWindowSetAreas(scrollwin, hsb, vsb, rowcol );
	children[ac++] = scrollwin;
	children[ac++] = label;
	XtManageChildren(children, ac);
	ac = 0;
	XtManageChild ( form);

	XtAddCallback(button1, XmNactivateCallback, XdbPrintTreeCB, (XtPointer)form);
}



XtAppContext app_context;
Display *display;       /*  Display             */

int main (argc,argv)
int    argc;
char            **argv;
{
	XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL );
	XtToolkitInitialize ();
	app_context = XtCreateApplicationContext ();
	display = XtOpenDisplay (app_context, NULL, argv[0], "XApplication",
	                         NULL, 0, &argc, argv);
	if (!display)
	{
	    printf("%s: can't open display, exiting...\n", argv[0]);
	    exit (-1);
	}
	create_appshell ( display, argv[0], argc, argv );
	XtRealizeWidget (appshell);
	XtAppMainLoop (app_context);
	exit (0);
}

