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

class DemoDialog : public XmDialogWindow
{
//	bool initWindowSize(int&, int&, int&, int&);

	void createContents();
	void initContents();

	void myRadioButton(XmRadioButton*);
	void myCheckBox(XmCheckBox*);
	void myEdit(XmEdit*);
	void myListBox(XmListBox*);
	void myComboBox(XmComboBox*);
	void myPushButton(XmPushButton*);
	void myQuitButton(XmPushButton*);
public:
	DemoDialog(char* name = "Demo Dialog", XmObject* parent = NULL) : XmDialogWindow(name)
	{ }

	void gnuInit()	{ setInitWindowSize(300, 300, 470, 364); DemoDialog::createContents(); DemoDialog::initContents(); }
};


// implementation ///////////////////////////////////////////////////////

#include "demodlg.C"

char* items[] = { "One", "Two", "Three", "Four", "Five", "Six", NULL };

void DemoDialog::initContents()
{
	radioButton("RadioButton1")->setCallback(this, CB(DemoDialog::myRadioButton));
	radioButton("RadioButton2")->setCallback(this, CB(DemoDialog::myRadioButton));
	radioButton("RadioButton3")->setCallback(this, CB(DemoDialog::myRadioButton));
	pushButton("PushButton")->setCallback(this, CB(DemoDialog::myPushButton));
	checkBox("CheckBox")->setCallback(this, CB(DemoDialog::myCheckBox));
	edit("Edit1")->setCallback(this, CB(DemoDialog::myEdit));
	edit("Edit2")->setCallback(this, CB(DemoDialog::myEdit));
	listBox("ListBox")->addAll(items);
	listBox("ListBox")->setCallback(this, CB(DemoDialog::myListBox));
	comboBox("ComboBox")->addAll(items);
	((XmGroupBox* )comboBox("ComboBox"))->setCallback(this, CB(DemoDialog::myComboBox));
	pushButton("QuitButton")->setCallback(this, CB(DemoDialog::myQuitButton));
}

void DemoDialog::myPushButton(XmPushButton* p)
{
	cout << "pushButton: " << p->getName() << "\n";
}

void DemoDialog::myCheckBox(XmCheckBox* b)
{
	cout << "checkBox: " << b->getName() << " state: " << b->getState() << "\n";
}

void DemoDialog::myRadioButton(XmRadioButton* r)
{
	cout << "radioButton: " << r->getName() << " selected.\n";
}

void DemoDialog::myEdit(XmEdit* e)
{
	cout << "edit: " << e->getName() << " new text: " << e->getText() << "\n";
}

void DemoDialog::myListBox(XmListBox* l)
{
	cout << "listBox: " << l->getName() << " selection: " << l->selectedItem() << " (" << l->selectedIndex() << ")\n";
	cout << "  currently selected: \n";
	char** strings = l->selectedItems();
	int* ndxs = l->selectedIndices();
	for(int i = 0; strings[i]; i++)
		cout << strings[i] << " (" << ndxs[i] << ")\n";
	cout << "\n";
}

void DemoDialog::myComboBox(XmComboBox* l)
{
	cout << "comboBox: " << l->getName() << "\n";
	cout << "current text: " << l->getText() << ".\n";
	cout << "currently selected: " << l->selectedItem() << " (" << l->selectedIndex() << ")\n";
}

void DemoDialog::myQuitButton(XmPushButton* p)
{
	exit(0);
}


// application init method ///////////////////////////////////////////

void XmApp::initialize()
{
	(new DemoDialog)->gnuInit();	// initialize();
};

