/***************************** LICENSE START ***********************************

 Copyright 2012 ECMWF and INPE. This software is distributed under the terms
 of the Apache License version 2.0. In applying this license, ECMWF does not
 waive the privileges and immunities granted to it by virtue of its status as
 an Intergovernmental Organization or submit itself to any jurisdiction.

 ***************************** LICENSE END *************************************/

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

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

#include <Xm/Xm.h>
#include <X11/StringDefs.h>
#include <Xm/DialogS.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/TextF.h>
#include <Xm/ToggleB.h>
#include <Xm/CascadeBG.h>
#include <Xm/LabelG.h>

#include <xdclass.h>

class UIGridDrawer_c: public xd_XmForm_c {
public:
	virtual void create (Widget parent, char *widget_name = NULL);
protected:
	Widget UIGridDrawer;
	Widget x_;
	Widget y_;
public:
	static void yEntryCB( Widget, XtPointer, XtPointer );
	virtual void yEntryCB( Widget, XtPointer ) = 0;
	static void xEntryCB( Widget, XtPointer, XtPointer );
	virtual void xEntryCB( Widget, XtPointer ) = 0;
	static void snapCB( Widget, XtPointer, XtPointer );
	virtual void snapCB( Widget, XtPointer ) = 0;
	static void showCB( Widget, XtPointer, XtPointer );
	virtual void showCB( Widget, XtPointer ) = 0;
	static void setCB( Widget, XtPointer, XtPointer );
	virtual void setCB( Widget, XtPointer ) = 0;
};

typedef UIGridDrawer_c *UIGridDrawer_p;

UIGridDrawer_p UIGridDrawer = (UIGridDrawer_p) NULL;

#include <X11/xpm.h>

static int _xd_initialised = 0;

typedef struct PixmapResources_s { 
	Pixmap h;
	Pixmap v;
} PixmapResources_t, *PixmapResources_p;

static PixmapResources_t pixmap_resources;

static char *h_icon [] = { 
"24 24 2 1",
". c black",
"o c #e5e5e5e5e5e5",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooo.oooooooooooooo.oooo",
"ooo.oooooooooooooooo.ooo",
"oo.oooooooooooooooooo.oo",
"o.oooooooooooooooooooo.o",
"........................",
"o.oooooooooooooooooooo.o",
"oo.oooooooooooooooooo.oo",
"ooo.oooooooooooooooo.ooo",
"oooo.oooooooooooooo.oooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo",
"oooooooooooooooooooooooo"
};

static char *v_icon [] = { 
"24 24 2 1",
". c black",
"o c #e5e5e5e5e5e5",
"ooooooooooo.oooooooooooo",
"oooooooooo...ooooooooooo",
"ooooooooo.o.o.oooooooooo",
"oooooooo.oo.oo.ooooooooo",
"ooooooo.ooo.ooo.oooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooooooo.oooooooooooo",
"ooooooo.ooo.ooo.oooooooo",
"oooooooo.oo.oo.ooooooooo",
"ooooooooo.o.o.oooooooooo",
"oooooooooo...ooooooooooo",
"ooooooooooo.oooooooooooo"
};


static void initialise_objects( Widget parent )
{
	XpmAttributes xpm_attributes;

	/* Some code to ensure that the pixmaps look OK even if the
	   color map is full or nearly so: */
	xpm_attributes.valuemask = XpmCloseness;
	xpm_attributes.closeness = 40000;
	if ( _xd_initialised ) return;
	_xd_initialised = 1;
	while ( XtParent ( parent ) )
		parent = XtParent ( parent );
	XtVaGetValues ( parent, XmNcolormap, &xpm_attributes.colormap, 
	                XmNdepth, &xpm_attributes.depth, 
	                XmNvisual, &xpm_attributes.visual, NULL);
	if ( XpmCreatePixmapFromData( XtDisplay( parent ),RootWindowOfScreen( XtScreen(parent) ) , h_icon, &pixmap_resources.h, NULL, &xpm_attributes ) != 0 )
		pixmap_resources.h = XmUNSPECIFIED_PIXMAP;
	if ( XpmCreatePixmapFromData( XtDisplay( parent ),RootWindowOfScreen( XtScreen(parent) ) , v_icon, &pixmap_resources.v, NULL, &xpm_attributes ) != 0 )
		pixmap_resources.v = XmUNSPECIFIED_PIXMAP;
}


void UIGridDrawer_c::create (Widget parent, char *widget_name)
{
	Widget children[3];      /* Children to manage */
	Arg al[64];                    /* Arg List */
	register int ac = 0;           /* Arg Count */
	Widget frame1 = (Widget)NULL;
	Widget form4 = (Widget)NULL;
	Widget rowcol6 = (Widget)NULL;
	Widget rowcol1 = (Widget)NULL;
	Widget label1 = (Widget)NULL;
	Widget optionMenu1 = (Widget)NULL;
	Widget cascade1 = (Widget)NULL;
	Widget menu1 = (Widget)NULL;
	Widget button3 = (Widget)NULL;
	Widget button2 = (Widget)NULL;
	Widget rowcol3 = (Widget)NULL;
	Widget label4 = (Widget)NULL;
	Widget optionMenu4 = (Widget)NULL;
	Widget cascade4 = (Widget)NULL;
	Widget menu4 = (Widget)NULL;
	Widget button8 = (Widget)NULL;
	Widget button7 = (Widget)NULL;
	Widget rowcol5 = (Widget)NULL;
	Widget toggle1 = (Widget)NULL;
	Widget toggle2 = (Widget)NULL;

	if ( !widget_name )
		widget_name = "Grid";

initialise_objects(parent);	XtSetArg(al[ac], XmNautoUnmanage, FALSE); ac++;
	UIGridDrawer = XmCreateForm ( parent, widget_name, al, ac );
	ac = 0;
	_xd_rootwidget = UIGridDrawer;
	XtSetArg(al[ac], XmNshadowType, XmSHADOW_IN); ac++;
	frame1 = XmCreateFrame ( UIGridDrawer, "frame1", al, ac );
	ac = 0;
	form4 = XmCreateForm ( frame1, "form4", al, ac );
	rowcol6 = XmCreateRowColumn ( form4, "rowcol6", al, ac );
	XtSetArg(al[ac], XmNnumColumns, 3); ac++;
	XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
	XtSetArg(al[ac], XmNpacking, XmPACK_TIGHT); ac++;
	XtSetArg(al[ac], XmNentryAlignment, XmALIGNMENT_CENTER); ac++;
	XtSetArg(al[ac], XmNentryVerticalAlignment, XmALIGNMENT_CENTER); ac++;
	rowcol1 = XmCreateRowColumn ( rowcol6, "rowcol1", al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
	label1 = XmCreateLabel ( rowcol1, "label1", al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNlabelPixmap, pixmap_resources.h); ac++;
	XtSetValues ( label1,al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNcolumns, 5); ac++;
	x_ = XmCreateTextField ( rowcol1, "x_", al, ac );
	ac = 0;
	optionMenu1 = XmCreateOptionMenu ( rowcol1, "menu_x_", al, ac );
	cascade1 = XmOptionButtonGadget ( optionMenu1 );
	menu1 = XmCreatePulldownMenu ( optionMenu1, "menu1", al, ac );
	button3 = XmCreatePushButton ( menu1, "%", al, ac );
	button2 = XmCreatePushButton ( menu1, "cm", al, ac );
	XtSetArg(al[ac], XmNnumColumns, 3); ac++;
	XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
	XtSetArg(al[ac], XmNentryAlignment, XmALIGNMENT_CENTER); ac++;
	XtSetArg(al[ac], XmNentryVerticalAlignment, XmALIGNMENT_CENTER); ac++;
	rowcol3 = XmCreateRowColumn ( rowcol6, "rowcol3", al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
	label4 = XmCreateLabel ( rowcol3, "label4", al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNlabelPixmap, pixmap_resources.v); ac++;
	XtSetValues ( label4,al, ac );
	ac = 0;
	XtSetArg(al[ac], XmNcolumns, 5); ac++;
	y_ = XmCreateTextField ( rowcol3, "y_", al, ac );
	ac = 0;
	optionMenu4 = XmCreateOptionMenu ( rowcol3, "meny_y_", al, ac );
	cascade4 = XmOptionButtonGadget ( optionMenu4 );
	menu4 = XmCreatePulldownMenu ( optionMenu4, "menu4", al, ac );
	button8 = XmCreatePushButton ( menu4, "%", al, ac );
	button7 = XmCreatePushButton ( menu4, "cm", al, ac );
	rowcol5 = XmCreateRowColumn ( form4, "rowcol5", al, ac );
	toggle1 = XmCreateToggleButton ( rowcol5, "Show grid", al, ac );
	toggle2 = XmCreateToggleButton ( rowcol5, "Snap to grid", al, ac );

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
	XtSetValues ( frame1,al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
	XtSetValues ( rowcol6,al, ac );
	ac = 0;

	XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
	XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
	XtSetArg(al[ac], XmNleftAttachment, XmATTACH_NONE); ac++;
	XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
	XtSetValues ( rowcol5,al, ac );
	ac = 0;
	XtAddCallback (x_, XmNactivateCallback, setCB, (XtPointer) this);
	XtAddCallback (menu1, XmNentryCallback, xEntryCB, (XtPointer) this);
	children[ac++] = button3;
	children[ac++] = button2;
	XtManageChildren(children, ac);
	ac = 0;
	XtSetArg(al[ac], XmNsubMenuId, menu1); ac++;
	XtSetValues ( cascade1, al, ac );
	ac = 0;
	children[ac++] = label1;
	children[ac++] = x_;
	children[ac++] = optionMenu1;
	XtManageChildren(children, ac);
	ac = 0;
	XtAddCallback (y_, XmNactivateCallback, setCB, (XtPointer) this);
	XtAddCallback (menu4, XmNentryCallback, yEntryCB, (XtPointer) this);
	children[ac++] = button8;
	children[ac++] = button7;
	XtManageChildren(children, ac);
	ac = 0;
	XtSetArg(al[ac], XmNsubMenuId, menu4); ac++;
	XtSetValues ( cascade4, al, ac );
	ac = 0;
	children[ac++] = label4;
	children[ac++] = y_;
	children[ac++] = optionMenu4;
	XtManageChildren(children, ac);
	ac = 0;
	children[ac++] = rowcol1;
	children[ac++] = rowcol3;
	XtManageChildren(children, ac);
	ac = 0;
	XtAddCallback (toggle1, XmNvalueChangedCallback, showCB, (XtPointer) this);
	XtAddCallback (toggle2, XmNvalueChangedCallback, snapCB, (XtPointer) this);
	children[ac++] = toggle1;
	children[ac++] = toggle2;
	XtManageChildren(children, ac);
	ac = 0;
	children[ac++] = rowcol6;
	children[ac++] = rowcol5;
	XtManageChildren(children, ac);
	ac = 0;
	children[ac++] = form4;
	XtManageChildren(children, ac);
	ac = 0;
	children[ac++] = frame1;
	XtManageChildren(children, ac);
	ac = 0;
}

void UIGridDrawer_c::yEntryCB( Widget widget, XtPointer client_data, XtPointer call_data )
{
	UIGridDrawer_p instance = (UIGridDrawer_p) client_data;
	instance->yEntryCB ( widget, call_data );
}

void UIGridDrawer_c::xEntryCB( Widget widget, XtPointer client_data, XtPointer call_data )
{
	UIGridDrawer_p instance = (UIGridDrawer_p) client_data;
	instance->xEntryCB ( widget, call_data );
}

void UIGridDrawer_c::snapCB( Widget widget, XtPointer client_data, XtPointer call_data )
{
	UIGridDrawer_p instance = (UIGridDrawer_p) client_data;
	instance->snapCB ( widget, call_data );
}

void UIGridDrawer_c::showCB( Widget widget, XtPointer client_data, XtPointer call_data )
{
	UIGridDrawer_p instance = (UIGridDrawer_p) client_data;
	instance->showCB ( widget, call_data );
}

void UIGridDrawer_c::setCB( Widget widget, XtPointer client_data, XtPointer call_data )
{
	UIGridDrawer_p instance = (UIGridDrawer_p) client_data;
	instance->setCB ( widget, call_data );
}

