/* This file is part of `checkBox'
 * Copyright (c) 1995 David Deaven
 *
 * In the following, "you" and "You" refer to any entity other than 
 * the Microsoft corporation and its subsidiaries.  All rights are
 * reserved by the author in connection with Microsoft and its
 * subsidiaries.  The Microsoft Network is explicity denied the right
 * to copy, reproduce, or transmit this software.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Author: deaven $
 * $Id: sample.c,v 1.1 1996/07/12 08:38:59 deaven Exp deaven $
 */

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Core.h>
#include <X11/Xaw/Form.h>
#include "CheckBox.h"
#include <stdio.h>

#define APPNAME "checkBox"
#define APPCLASS "CheckBox"

char *myname = "checkBox";

static Widget checkBox_widget, frame_widget;
static int quit = 0;

static void button(Widget w, XtPointer nil, XEvent *event, Boolean *dispatch)
{
	if (event->type == ButtonPress &&
	     ((XButtonEvent *)event)->button == 3) {
	    if(quit)
	      exit(1);
	    else {
	      XtDestroyWidget(checkBox_widget);
	      quit = 1;
	    }
	}
}

void main(int argc, char **argv)
{
	Widget toplevel;
	XtAppContext app;
	Display *theDisplay;
	Arg args[10];
	Cardinal n;

	myname = argv[0];

	XtToolkitInitialize();
	app = XtCreateApplicationContext();
	      
	theDisplay = XtOpenDisplay (app, NULL, APPNAME, APPCLASS, 
	  NULL, 0, &argc, argv);

	if (!theDisplay)
	{
	  printf("%s: can't open display, exiting...", APPNAME);
	  exit(0);
	}

	toplevel = XtAppCreateShell (APPNAME, APPCLASS,
		      applicationShellWidgetClass, theDisplay, NULL, 0);

	n = 0;
	frame_widget = XtCreateManagedWidget("Frame", formWidgetClass,
	  toplevel, args, n);

	n = 0;
	XtSetArg(args[n], XtNresizable, True); n++;
	checkBox_widget =
	  XtCreateManagedWidget("CheckBoxWidget", checkBoxWidgetClass,
	    frame_widget, args, n);

	XtRealizeWidget(toplevel);

	XtAddEventHandler(frame_widget, ButtonPressMask | ButtonMotionMask,
	  FALSE, button, NULL);

	printf("Use mouse button 3 twice in frame to exit.\n");

	XtAppMainLoop(app);

	exit(0);
}
