#include <stream.h>
#include <stdlib.h>
#include <xmObject.h>

class TestWindow : public XmWindow
{
	bool initWindowSize(int&, int&, int& w, int& h)		{ w = 500; h = 400; return(TRUE); }
public:
	TestWindow();

	void initialize();

	void myMenuItem(char*);
	void myPushButton(void*);
	void testToolbars(char*);

	void openNext(void*);
	void close(void*);

	void quit(void*);
};


void XmApp::initialize()
{
	(new TestWindow)->initialize();
};

typedef void (*procptr)();


TestWindow::TestWindow() : XmWindow("Test")
{
}

void TestWindow::initialize()
{
	XmDropdownMenu* m = createDropdownMenu();

	m->addLabels("&File", "&Edit", "&Misc", "&Test", NULL);

	m->setCurrentLabel("File");
	m->addItems(Entry("&Open", (XmObject* )NULL, (cbProc )&TestWindow::openNext),
				Entry("&Close", (XmObject* )NULL, (cbProc )&TestWindow::close), NULLENTRY);

	m->addSeparator();
	m->addItems(Entry("E&xit", (XmObject* )NULL, (cbProc )&TestWindow::quit), NULLENTRY);

	m->setCurrentLabel("Misc");
	m->addItems(Entry("&Everything", (XmObject* )NULL, (cbProc )&TestWindow::myMenuItem),
				Entry("&Hello", (XmObject* )NULL, (cbProc )&TestWindow::myMenuItem), NULLENTRY);

	m->setCurrentLabel("Test");
	m->addItems(Entry("&lBar", (XmObject* )NULL, (cbProc )&TestWindow::testToolbars),
				Entry("&rBar", (XmObject* )NULL, (cbProc )&TestWindow::testToolbars),
				Entry("&tBar", (XmObject* )NULL, (cbProc )&TestWindow::testToolbars),
				Entry("&bBar", (XmObject* )NULL, (cbProc )&TestWindow::testToolbars),
				Entry("&statusBar", (XmObject* )NULL, (cbProc )&TestWindow::testToolbars), NULLENTRY);

	addSubpane(Edit, "TestEdit");	// , "My Test Edit");

	XmToolBar* tb;

	tb = addToolbar(XmSleft);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon1.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon2.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon3.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb = addToolbar(XmSright);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon1.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon2.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon3.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb = addToolbar(XmStop);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon1.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon2.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon3.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb = addToolbar(XmSbottom);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon1.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon2.gif"))), this, (cbProc )&TestWindow::myPushButton);
	tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon3.gif"))), this, (cbProc )&TestWindow::myPushButton);
/*
	XmStatusBar* stb = createStatusBar();
	stb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon4.gif"))), this, (cbProc )&TestWindow::myPushButton);
	stb->setMessage("idle...");
*/
}

void TestWindow::myMenuItem(char* n)
{
	cerr << hex(long(this)) << " / menu item: " << n << " selected.\n";
}

void TestWindow::myPushButton(void*)
{
	cerr << "button pressed...\n";
}

void TestWindow::testToolbars(char* n)
{
	cerr << hex(long(this)) << " testing: " << n << " .\n";

	xmStyle which = 0;

	switch(*n)
	{	case 'l':
		which = XmSleft;
		break;
		case 'r':
		which = XmSright;
		break;
		case 't':
		which = XmStop;
		break;
		case 'b':
		which = XmSbottom;
		break;
	}
	if(which)
	{	XmToolBar* tb;
		if(tb = toolbar(which))
		{	removeToolbar(tb);
			delete tb;
		}
		else
		{	tb = addToolbar(which);
			tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon1.gif"))), this, (cbProc )&TestWindow::myMenuItem, CB_OBJ_NAME);
			tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon2.gif"))), this, (cbProc )&TestWindow::myPushButton);
			tb->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon3.gif"))), this, (cbProc )&TestWindow::myPushButton);
		}
	}
/*
	else
	{	if(!getStatusBar()->remove("&Push"))
			getStatusBar()->add(((new XmPushButton("&Push"))->setImage(getRuntimeImage("icon4.gif"))), this, (cbProc )&TestWindow::myPushButton);
	}
*/
}


void TestWindow::openNext(void*)
{
	(new TestWindow)->open();
}

void TestWindow::close(void*)
{
	destroyOnDelete();
	delete this;
}

void TestWindow::quit(void*)
{
	exit(0);
}




