/*
** Generated by X-Designer
*/
/*
**LIBS: -lXm -lXt -lX11
*/

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>

#include <Xm/Xm.h>
#include <Xm/RepType.h>
#include <X11/StringDefs.h>
#include <Xm/DialogS.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/MessageB.h>
#include <Xm/PushB.h>
#include <Xm/TextF.h>
#include <Xm/SeparatoG.h>


#include "TextColors.h"

#ifndef   _NO_PROTO
extern void text_modify_verify(Widget, XtPointer, XtPointer) ;
#else  /* _NO_PROTO */
extern void text_modify_verify() ;
#endif /* _NO_PROTO */
#ifndef   _NO_PROTO
extern void text_activate(Widget, XtPointer, XtPointer) ;
#else  /* _NO_PROTO */
extern void text_activate() ;
#endif /* _NO_PROTO */
#ifndef   _NO_PROTO
extern void text_losing_focus(Widget, XtPointer, XtPointer) ;
#else  /* _NO_PROTO */
extern void text_losing_focus() ;
#endif /* _NO_PROTO */
#ifndef   _NO_PROTO
extern void exit_callback(Widget, XtPointer, XtPointer) ;
#else  /* _NO_PROTO */
extern void exit_callback() ;
#endif /* _NO_PROTO */

Widget shell = (Widget) NULL;
Widget dialog_template = (Widget) NULL;
Widget form = (Widget) NULL;


static int _xd_initialised = 0 ;

typedef struct PixelResources_s { 
	Pixel TextInsertForeground;
	Pixel TextInsertBackground;
	Pixel TextNormalBackground;
	Pixel TextNormalForeground;
} PixelResources_t, *PixelResources_p;

static PixelResources_t pixel_resources;

static XtResource pixel_resources_defn[] = {
	{
		"TextInsertForeground", XmCColor, XmRPixel,
		sizeof (Pixel), XtOffset(PixelResources_p, TextInsertForeground),
		XtRString, "Red"
	},
	{
		"TextInsertBackground", XmCColor, XmRPixel,
		sizeof (Pixel), XtOffset(PixelResources_p, TextInsertBackground),
		XtRString, "Yellow"
	},
	{
		"TextNormalBackground", XmCColor, XmRPixel,
		sizeof (Pixel), XtOffset(PixelResources_p, TextNormalBackground),
		XtRString, "GhostWhite"
	},
	{
		"TextNormalForeground", XmCColor, XmRPixel,
		sizeof (Pixel), XtOffset(PixelResources_p, TextNormalForeground),
		XtRString, "Black"
	},
};


#ifndef   _NO_PROTO
Pixel xdGetTextInsertForegroundColorObject(void)
#else  /* _NO_PROTO */
Pixel xdGetTextInsertForegroundColorObject()
#endif /* _NO_PROTO */
{
	return pixel_resources.TextInsertForeground ;
}


#ifndef   _NO_PROTO
Pixel xdGetTextInsertBackgroundColorObject(void)
#else  /* _NO_PROTO */
Pixel xdGetTextInsertBackgroundColorObject()
#endif /* _NO_PROTO */
{
	return pixel_resources.TextInsertBackground ;
}


#ifndef   _NO_PROTO
Pixel xdGetTextNormalBackgroundColorObject(void)
#else  /* _NO_PROTO */
Pixel xdGetTextNormalBackgroundColorObject()
#endif /* _NO_PROTO */
{
	return pixel_resources.TextNormalBackground ;
}


#ifndef   _NO_PROTO
Pixel xdGetTextNormalForegroundColorObject(void)
#else  /* _NO_PROTO */
Pixel xdGetTextNormalForegroundColorObject()
#endif /* _NO_PROTO */
{
	return pixel_resources.TextNormalForeground ;
}


static void initialise_objects(Widget parent)
{

	if (_xd_initialised) {
		return ;
	}

	_xd_initialised = 1;

	while (XtParent(parent)) {
		parent = XtParent(parent);
	}

	if (DefaultDepthOfScreen(DefaultScreenOfDisplay(XtDisplay(parent))) != 1) {
	XtGetApplicationResources(parent, &pixel_resources, pixel_resources_defn, XtNumber(pixel_resources_defn), (ArgList)0, 0);
	}
}


void create_shell (Display *display, char *app_name, int app_argc, char **app_argv)
{
	Widget children[4];      /* Children to manage */
	Arg al[64];                    /* Arg List */
	register int ac = 0;           /* Arg Count */
	XrmValue from_value, to_value; /* For resource conversion */
	XtPointer tmp_value;             /* ditto */
	XmString xmstrings[16];    /* temporary storage for XmStrings */
	Widget label1 = (Widget)NULL;
	Widget text1 = (Widget)NULL;
	Widget label2 = (Widget)NULL;
	Widget text2 = (Widget)NULL;
	Widget button1 = (Widget)NULL;

	XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++;
	XtSetArg(al[ac], XmNtitle, "Text Colors"); ac++;
	XtSetArg(al[ac], XmNargc, app_argc); ac++;
	XtSetArg(al[ac], XmNargv, app_argv); ac++;
	shell = XtAppCreateShell ( app_name, (char *) "TextColors", applicationShellWidgetClass, display, al, ac );

	ac = 0;
	initialise_objects ( shell );
	XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
	XtSetArg(al[ac], XmNdialogType, XmDIALOG_TEMPLATE); ac++;
	dialog_template = XmCreateMessageBox ( shell, (char *) "dialog_template", al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
	form = XmCreateForm ( dialog_template, (char *) "form", al, ac );
	ac = 0;
	label1 = XmCreateLabel ( form, (char *) "label1", al, ac );
	XtSetArg(al[ac], XmNforeground, pixel_resources.TextNormalForeground); ac++;
	XtSetArg(al[ac], XmNbackground, pixel_resources.TextNormalBackground); ac++;
	text1 = XmCreateTextField ( form, (char *) "text1", al, ac );
	ac = 0;
	label2 = XmCreateLabel ( form, (char *) "label2", al, ac );
	XtSetArg(al[ac], XmNforeground, pixel_resources.TextNormalForeground); ac++;
	XtSetArg(al[ac], XmNbackground, pixel_resources.TextNormalBackground); ac++;
	text2 = XmCreateTextField ( form, (char *) "text2", al, ac );
	ac = 0;
	xmstrings[0] = XmStringCreateLtoR ( "Exit", (XmStringCharSet)XmFONTLIST_DEFAULT_TAG );
	XtSetArg(al[ac], XmNlabelString, xmstrings[0]); ac++;
	button1 = XmCreatePushButton ( dialog_template, (char *) "button1", al, ac );
	ac = 0;
	XmStringFree ( xmstrings [ 0 ] );


	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); ac++;
	XtSetArg(al[ac], XmNtopOffset, 0); ac++;
	XtSetArg(al[ac], XmNtopWidget, text1); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); ac++;
	XtSetArg(al[ac], XmNbottomOffset, 0); ac++;
	XtSetArg(al[ac], XmNbottomWidget, text1); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNleftOffset, 5); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_WIDGET); ac++;
	XtSetArg(al[ac], XmNrightOffset, 5); ac++;
	XtSetArg(al[ac], XmNrightWidget, text1); ac++;
	XtSetValues ( label1,al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNtopOffset, 5); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
	XtSetArg(al[ac], XmNleftPosition, 35); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNrightOffset, 5); ac++;
	XtSetValues ( text1,al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); ac++;
	XtSetArg(al[ac], XmNtopOffset, 0); ac++;
	XtSetArg(al[ac], XmNtopWidget, text2); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); ac++;
	XtSetArg(al[ac], XmNbottomOffset, 0); ac++;
	XtSetArg(al[ac], XmNbottomWidget, text2); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNleftOffset, 5); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_WIDGET); ac++;
	XtSetArg(al[ac], XmNrightOffset, 5); ac++;
	XtSetArg(al[ac], XmNrightWidget, text2); ac++;
	XtSetValues ( label2,al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
	XtSetArg(al[ac], XmNtopOffset, 5); ac++;
	XtSetArg(al[ac], XmNtopWidget, text1); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
	XtSetArg(al[ac], XmNleftPosition, 35); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNrightOffset, 5); ac++;
	XtSetValues ( text2,al, ac );
	ac = 0;
	if (text1)
		XtAddCallback( text1, XmNmodifyVerifyCallback, text_modify_verify, (XtPointer) 0 );
	if (text1)
		XtAddCallback( text1, XmNactivateCallback, text_activate, (XtPointer) 0 );
	if (text1)
		XtAddCallback( text1, XmNlosingFocusCallback, text_losing_focus, (XtPointer) 0 );
	if (text2)
		XtAddCallback( text2, XmNmodifyVerifyCallback, text_modify_verify, (XtPointer) 0 );
	if (text2)
		XtAddCallback( text2, XmNactivateCallback, text_activate, (XtPointer) 0 );
	if (text2)
		XtAddCallback( text2, XmNlosingFocusCallback, text_losing_focus, (XtPointer) 0 );
	if ((children[ac] = label1) != (Widget) 0) { ac++; }
	if ((children[ac] = text1) != (Widget) 0) { ac++; }
	if ((children[ac] = label2) != (Widget) 0) { ac++; }
	if ((children[ac] = text2) != (Widget) 0) { ac++; }
	if (ac > 0) { XtManageChildren(children, ac); }
	ac = 0;
	if (button1)
		XtAddCallback( button1, XmNactivateCallback, exit_callback, (XtPointer) 0 );
	if ((children[ac] = form) != (Widget) 0) { ac++; }
	if ((children[ac] = button1) != (Widget) 0) { ac++; }
	if (ac > 0) { XtManageChildren(children, ac); }
	ac = 0;
	if (dialog_template != (Widget) 0) { XtManageChild ( dialog_template); }
}


/* Global Declarations */

XtAppContext app_context = (XtAppContext) 0 ;
Display     *display     = (Display *)    0 ;

int main(int argc, char **argv)
{

	/* Enable Localisation of the Application */

	XtSetLanguageProc((XtAppContext) 0, (XtLanguageProc) 0, (XtPointer) 0) ;

	/* Initialise the X Toolkit */

	XtToolkitInitialize ();

	/* Create a Global Application Context */

	app_context = XtCreateApplicationContext ();

	/* Open the Display */

	display = XtOpenDisplay(app_context, (String) 0, argv[0], "TextColors",
	                       (XrmOptionDescRec *) 0, 0,
	                       &argc, argv);
	if (display == (Display *) 0) {
		printf("%s: can't open display, exiting...\n", argv[0]);
		exit (-1);
	}

	/* This converter is not registered internally by Motif */

	XmRepTypeInstallTearOffModelConverter();

	/* Call the Create Procedures for the Dialogs in the Application */

	create_shell ( display, argv[0], argc, argv );

	/* Display the Primary Application Shell */

	XtRealizeWidget (shell);

	/* Entering X Main Loop... */

	XtAppMainLoop (app_context);

	/* NOTREACHED */

	exit (0);
}

