number true = 1, false = 0;

/* --------------- DIALOG LIBRARY TEST 1---------------------------------------------------------*/

class DialogLibraryTestClass : uiframe
{
	number change_count, action_count;

	void trackchange( object self, TagGroup tg)
	{
		change_count++;
		result("Change count: " + change_count + "\n");
	}
	
	void trackaction( object self)
	{
		TagGroup button_tags

		if ( self.DLGGetBevelButtonOn("dsimage1", button_tags) )
			result("dsimage1 is on\n")
		if ( self.DLGGetBevelButtonOn("dsimage2", button_tags) )
			result("dsimage2 is on\n")
		if ( self.DLGGetBevelButtonOn("dsimage3", button_tags) )
			result("dsimage3 is on\n")

		action_count++;
		result("Action count: " + action_count + "\n");	
	}
}

TagGroup MakeLabels()
{

	TagGroup label1 = DLGCreateLabel("Label 1");
	TagGroup label2 = DLGCreateLabel("Fixed-width Label", 20);
	TagGroup buttonslabel = DLGCreateLabel("== Buttons ==").DLGAnchor("West");

	return DLGGroupItems(label1, label2, buttonslabel);

}

TagGroup MakeButtons()
{

	TagGroup push_button1 = DLGCreatePushButton("Push Button", "trackaction").DLGSide("Left");

	image imgOn := RealImage("buttonOn", 4, 30, 30);
	imgOn = 0;

	image imgOff := RealImage("buttonOff", 4, 30, 30);
	imgOff = 100;

	Image img := IntegerImage("button", 2, true, 30, 30);
	img = 200;

	TagGroup bitmapOn = DLGCreateBitmap(imgOn);
	TagGroup bitmapOff = DLGCreateBitmap(imgOff);

	TagGroup bevelbuttonslabel = DLGCreateLabel("1-State Bevel Buttons").DLGAnchor("West");

	TagGroup bevel_button1 = DLGCreateBevelButton(bitmapOn, bitmapOff, "trackaction").DLGSide("Top");
	TagGroup bevel_button2 = DLGCreateBevelButton(imgOn, imgOff, "trackaction").DLGAnchor("West");
	TagGroup bevel_button3 = DLGCreateBevelButton(img, "trackaction").DLGAnchor("West");

	TagGroup dsbevelbuttonslabel = DLGCreateLabel("2-State Bevel Buttons").DLGAnchor("West");

	TagGroup dsbevel1 = DLGCreateDualStateBevelButton("dsimage1", bitmapOn, bitmapOff, "trackaction");
	TagGroup dsbevel2 = DLGCreateDualStateBevelButton("dsimage2", imgOn, imgOff, "trackaction");
	TagGroup dsbevel3 = DLGCreateDualStateBevelButton("dsimage3", img, "trackaction");

	TagGroup group1_items;
	TagGroup group1 = DLGCreateGroup(group1_items).DLGSide("Left");
	group1.DLGTableLayout(4, 2, 0);

	group1_items.DLGAddElement(bevelbuttonslabel);	
	group1_items.DLGAddElement(bevel_button1);	
	group1_items.DLGAddElement(bevel_button2);	
	group1_items.DLGAddElement(bevel_button3);	

	group1_items.DLGAddElement(dsbevelbuttonslabel);	
	group1_items.DLGAddElement(dsbevel1);	
	group1_items.DLGAddElement(dsbevel2);	
	group1_items.DLGAddElement(dsbevel3);	

	return DLGGroupItems(push_button1, group1);
}

TagGroup MakeFields()
{
	TagGroup realfield1 = DLGCreateRealField(0, 6, 0).DLGAnchor("East");
	realfield1.DLGChangedMethod("trackchange");
	
	TagGroup realfield2 = DLGCreateRealField(0, 6, 2, "trackchange").DLGAnchor("East");

	TagGroup intfield1 = DLGCreateIntegerField(0, 6).DLGAnchor("East");
	intfield1.DLGChangedMethod("trackchange");
	
	TagGroup intfield2 = DLGCreateIntegerField(0, 6, "trackchange").DLGAnchor("East");
	
	TagGroup strfield1 = DLGCreateStringField("string field", 24).DLGAnchor("East");
	strfield1.DLGChangedMethod("trackchange");
	
	TagGroup strfield2 = DLGCreateStringField("string field", 24, "trackchange").DLGAnchor("East");

	TagGroup group3 = DLGGroupItems(realfield1, realfield2, intfield1, intfield2);
	group3.DLGGetItems().DLGAddElement(strfield1);
	group3.DLGGetItems().DLGAddElement(strfield2);
	group3.DLGTableLayout(2, 3, 1);

	return group3;	
}

TagGroup MakeCheckBoxes()
{
	TagGroup group4_items;
	TagGroup group4 = DLGCreateGroup(group4_items);
	group4.DLGTableLayout(1, 2, 1);
	
	TagGroup checkbox1 = DLGCreateCheckBox("check box 1");
	checkbox1.DLGChangedMethod("trackchange")
	group4_items.DLGAddElement(checkbox1);
	
	TagGroup checkbox2 = DLGCreateCheckBox("check box 2", 1);
	checkbox2.DLGChangedMethod("trackchange")
	group4_items.DLGAddElement(checkbox2);

	TagGroup checkbox3 = DLGCreateCheckBox("check box 3", 0, "trackchange");
	group4_items.DLGAddElement(checkbox3);

	return group4;
}

TagGroup MakeBoxesAndRadios()
{
	TagGroup box1_items
	TagGroup box1 = DLGCreateBox("Box", box1_items)

	TagGroup radio1_items
	TagGroup radio1 = DLGCreateRadioList(radio1_items, 5);
	radio1_items.DLGAddRadioItem("option 1", 0)
	radio1_items.DLGAddRadioItem("option 2", 1)
	radio1_items.DLGAddRadioItem("option 4", 5)
	radio1_items.DLGAddRadioItem("option 3", 3)
	radio1.DLGIdentifier("Radio")
	
	box1_items.DLGAddElement(radio1);

	return box1;	
}

TagGroup MakeLists()
{
	TagGroup list1_items;
	TagGroup list1 = DLGCreateList(list1_items, "trackchange", "trackaction", 20, 2);
	list1_items.DLGAddListItem("list item 1", true);
	list1_items.DLGAddListItem("list item 2", true);
	list1_items.DLGAddListItem("list item 3", false);


	TagGroup list2_items;
	TagGroup list2 = DLGCreateList(list2_items, "trackchange", "trackaction", 20, 2);
	list2_items.DLGAddListItem("list item 1", true);
	list2_items.DLGAddListItem("list item 2", true);
	list2_items.DLGAddListItem("list item 3", false);
	list2.DLGMultipleSelect(true);

	TagGroup group = DLGGroupItems(list1, list2);
	group.DLGTableLayout(2, 1, 0);
	return group
}

TagGroup MakePopups()
{
	TagGroup popup_items;
	TagGroup popup = DLGCreatePopup(popup_items, 2, "trackchange")
	popup_items.DLGAddPopupItemEntry("Option 1");
	popup_items.DLGAddPopupItemEntry("Option 2");
	popup_items.DLGAddPopupItemEntry("Option 3");
	popup.DLGIdentifier("Popup")

	TagGroup label
	TagGroup popup2_items;
	TagGroup popup2 
	TagGroup popupgroup = DLGCreatePopup("Popup Group", label, popup2, popup2_items, 0)
	popup2_items.DLGAddPopupItemEntry("Option 1");
	popup2_items.DLGAddPopupItemEntry("Option 2");
	popup2_items.DLGAddPopupItemEntry("Option 3");
	
	TagGroup popup3, popup3_items
	TagGroup popupbox = DLGCreateBoxedPopup("Boxed Popup", popup3, popup3_items, 4)
	popup3_items.DLGAddPopupItemEntry("Option 1");
	popup3_items.DLGAddPopupItemEntry("Option 2");
	popup3_items.DLGAddPopupItemEntry("Option 3");

	TagGroup group = DLGGroupItems(popup, popupgroup, popupbox);
	group.DLGTableLayout(3,1, 0);

	return group
}

TagGroup MakePanels()
{
	Taggroup panels1_items
	TagGroup panels1 = DLGCreatePanelList(panels1_items)
	TagGroup panel11 = panels1_items.DLGAddPanel()
	panel11.DLGAddElement( DLGCreateLabel("Panel 1.1") );

	TagGroup panels2_items
	TagGroup panels2 = DLGCreatePanelList(panels2_items, 1);
	
	TagGroup panel21;
	panels2_items.DLGAddPanel( DLGCreatePanel(panel21) );
	panel21.DLGAddElement( DLGCreateLabel("Panel 2.1") );
	panels2_items.DLGAddPanel().DLGAddElement( DLGCreateLabel("Panel 2.2") );
	panels2_items.DLGAddPanel().DLGAddElement( DLGCreateLabel("Panel 2.3") );
	
	TagGroup group = DLGGroupItems(panels1, panels2);
	group.DLGTableLayout(2, 1, 0);
	return group
}

TagGroup MakeTabs()
{
	TagGroup tabs1_items
	TagGroup tabs1 = DLGCreateTabList(tabs1_items)
	TagGroup tab11 = tabs1_items.DLGAddTab("Tab 1.1")

	TagGroup tabs2_items
	TagGroup tabs2 = DLGCreateTabList(tabs2_items, 1);
	tabs2.DLGIdentifier("Tab");

	TagGroup tab21;
	tabs2_items.DLGAddTab( DLGCreateTab(tab21, "Tab 2.1") );
	tabs2_items.DLGAddTab("Tab 2.2");
	tabs2_items.DLGAddTab("Tab 2.3");
	
	TagGroup group = DLGGroupItems(tabs1, tabs2);
	group.DLGTableLayout(2, 1, 0);
	return group
}

TagGroup MakeImagePopup()
{
	Image img01 := realimage("test 1", 4, 50, 50);
	Image img02 := realimage("test 2", 4, 50, 50);
	Image img03 := realimage("test 3", 4, 50, 50);

	img01.ShowImage()
	img02.ShowImage()
	img03.ShowImage()


	TagGroup imgpup = DLGCreateImagePopup(1)	
	imgpup.DLGIdentifier("Image Popup");
	
	return imgpup;
}

TagGroup MakeProgressBar()
{
	TagGroup progress = DLGCreateProgressBar( "Progress" );
	return progress;
}

void DialogLibraryTest()
{

	//
	// CREATE TAGS
	//

	TagGroup dialog_items;	
	TagGroup dialog = DLGCreateDialog("Dialog Support", dialog_items);
	dialog.DLGPosition(100, 100, 200, 400);
	
	dialog_items.DLGAddElement( MakeLabels() );
	dialog_items.DLGAddElement( MakeButtons() );
	dialog_items.DLGAddElement( MakeFields() );
	
	TagGroup group5 = DLGGroupItems(MakeCheckBoxes(), MakeBoxesAndRadios());
	group5.DLGTableLayout(2, 1, 0);
	dialog_items.DLGAddElement( group5);

	dialog_items.DLGAddElement( MakeLists() );
	dialog_items.DLGAddElement( MakePopups() );
	dialog_items.DLGAddElement( MakePanels() );
	dialog_items.DLGAddElement( MakeTabs() );
	dialog_items.DLGAddElement( DLGCreateTextBox(60, 2, 1024) );
	dialog_items.DLGAddElement( MakeImagePopup() )

	dialog_items.DLGAddElement( MakeProgressBar() );

	//
	// DISPLAY DIALOG
	//

	object dialog_frame = alloc(DialogLibraryTestClass).init(dialog)
	dialog_frame.display("Testing Dialog Library 1");


	//
	// TEST UIFRAME DIALOG UTILITIES
	//
		
	TagGroup button_tags;
	number buttonOn = dialog_frame.DLGGetBevelButtonOn("dsimage1", button_tags); 

	if ( button_tags.TagGroupIsValid() )
	{
		number new_state;

		if ( buttonOn )
			new_state = 0;
		else
			new_state = 1;

		result("dsimage1 button state: " + buttonOn + "; changing state to: " + new_state + "\n");
		dialog_frame.DLGBevelButtonOn("dsimage1", new_state);
		result("New dsimage1 button state: " + dialog_frame.DLGGetBevelButtonOn("dsimage1", button_tags) + "\n"); 
		result("Changing dsimage1 state back...\n");	
		button_tags.DLGBevelButtonOn(buttonOn);
		result("Old state restored: " + dialog_frame.DLGGetBevelButtonOn("dsimage1", button_tags) + "\n");
	}

	number pupval;
	dialog_frame.DLGGetValue("Image Popup", pupval);
	result("Image popup value: " + pupval + "\n");


	// DLGGetNthLabel() doesn't work on image popups!!
	TagGroup imgtags = dialog_frame.LookupElement("Image Popup");
	number index = 2;
	if ( imgtags.TagGroupIsValid() )
	{
		string imglabel
		if ( imgtags.DLGGetNthLabel(index, imglabel) )
			result("Image label" + index + ": " + imglabel + "\n");
	}

	TagGroup puptags = dialog_frame.LookupElement("Popup")
	if ( puptags.taggroupisvalid() )
	{
		string label
		if ( puptags.DLGGetNthLabel(index, label) )
			result("Popup label " + index + ": " + label + "\n");
	}

	TagGroup radiotags = dialog_frame.LookupElement("Radio")
	if ( radiotags.taggroupisvalid() )
	{
		string label
		if ( radiotags.DLGGetNthLabel(index, label) )
			result("Radio label" + index + ": " + label + "\n");
	}

	TagGroup tabtags = dialog_frame.LookupElement("Tab")
	if ( tabtags.taggroupisvalid() )
	{
		string label
		if ( tabtags.DLGGetNthLabel(index, label) )
			result("Tab label" + index + ": " + label + "\n");
	}

	dialog_frame.DLGSetProgress("Progress", 25);

}

/* --------------- DIALOG LIBRARY TEST 2---------------------------------------------------------*/

TagGroup MakeButtons2()
{

	TagGroup push_button1 = DLGCreatePushButton("Push Button", "trackaction").DLGSide("Left");

	image imgOn := RealImage("buttonOn", 4, 30, 30);
	imgOn = 0;

	image imgOff := RealImage("buttonOff", 4, 30, 30);
	imgOff = 100;

	Image img := IntegerImage("button", 2, true, 30, 30);
	img = 200;

	TagGroup bitmapOn = DLGCreateBitmap(imgOn);
	TagGroup bitmapOff = DLGCreateBitmap(imgOff);

	TagGroup bevelbuttonslabel = DLGCreateLabel("1-State Bevel Buttons").DLGAnchor("West");

	TagGroup bevel_button1 = DLGCreateBevelButton(bitmapOn, bitmapOff, "trackaction").DLGSide("Top");
	TagGroup bevel_button2 = DLGCreateBevelButton(imgOn, imgOff, "trackaction").DLGAnchor("West");
	TagGroup bevel_button3 = DLGCreateBevelButton(img, "trackaction").DLGAnchor("West");

	TagGroup dsbevelbuttonslabel = DLGCreateLabel("2-State Bevel Buttons").DLGAnchor("West");

	TagGroup dsbevel1 = DLGCreateDualStateBevelButton("dsimage1", bitmapOn, bitmapOff, "trackaction");
	TagGroup dsbevel2 = DLGCreateDualStateBevelButton("dsimage2", imgOn, imgOff, "trackaction");
	TagGroup dsbevel3 = DLGCreateDualStateBevelButton("dsimage3", img, "trackaction");

	TagGroup group1 = DLGCreateGroup().DLGSide("Left");
	group1.DLGTableLayout(4, 2, 0);

	group1.DLGAddElement(bevelbuttonslabel);	
	group1.DLGAddElement(bevel_button1);	
	group1.DLGAddElement(bevel_button2);	
	group1.DLGAddElement(bevel_button3);	

	group1.DLGAddElement(dsbevelbuttonslabel);	
	group1.DLGAddElement(dsbevel1);	
	group1.DLGAddElement(dsbevel2);	
	group1.DLGAddElement(dsbevel3);	

	return DLGGroupItems(push_button1, group1);
}


TagGroup MakeCheckBoxes2()
{
	TagGroup group4 = DLGCreateGroup();
	group4.DLGTableLayout(1, 2, 1);
	
	TagGroup checkbox1 = DLGCreateCheckBox("check box 1");
	checkbox1.DLGChangedMethod("trackchange")
	group4.DLGAddElement(checkbox1);
	
	TagGroup checkbox2 = DLGCreateCheckBox("check box 2", 1);
	checkbox2.DLGChangedMethod("trackchange")
	group4.DLGAddElement(checkbox2);

	TagGroup checkbox3 = DLGCreateCheckBox("check box 3", 0, "trackchange");
	group4.DLGAddElement(checkbox3);

	return group4;
}

TagGroup MakeBoxesAndRadios2()
{
	TagGroup box1 = DLGCreateBox("Box")

	TagGroup radio1 = DLGCreateRadioList(5);
	radio1.DLGAddRadioItem("option 1", 0)
	radio1.DLGAddRadioItem("option 2", 1)
	radio1.DLGAddRadioItem("option 4", 5)
	radio1.DLGAddRadioItem("option 3", 3)
	radio1.DLGIdentifier("Radio")
	
	box1.DLGAddElement(radio1);

	return box1;	
}

TagGroup MakeLists2()
{
	TagGroup list1 = DLGCreateList( "trackchange", "trackaction", 20, 2);
	list1.DLGAddListItem("list item 1", true);
	list1.DLGAddListItem("list item 2", true);
	list1.DLGAddListItem("list item 3", false);


	TagGroup list2 = DLGCreateList("trackchange", "trackaction", 20, 2);
	list2.DLGAddListItem("list item 1", true);
	list2.DLGAddListItem("list item 2", true);
	list2.DLGAddListItem("list item 3", false);
	list2.DLGMultipleSelect(true);

	TagGroup group = DLGGroupItems(list1, list2);
	group.DLGTableLayout(2, 1, 0);
	return group
}

TagGroup MakePopups2()
{
	TagGroup popup = DLGCreatePopup(2, "trackchange")
	popup.DLGAddPopupItemEntry("Option 1");
	popup.DLGAddPopupItemEntry("Option 2");
	popup.DLGAddPopupItemEntry("Option 3");
	popup.DLGIdentifier("Popup")

	TagGroup label
	TagGroup popup2_items;
	TagGroup popup2 
	TagGroup popupgroup = DLGCreatePopup("Popup Group", label, popup2, popup2_items, 0)
	popup2.DLGAddPopupItemEntry("Option 1");
	popup2.DLGAddPopupItemEntry("Option 2");
	popup2.DLGAddPopupItemEntry("Option 3");
	
	TagGroup popup3, popup3_items
	TagGroup popupbox = DLGCreateBoxedPopup("Boxed Popup", popup3, popup3_items, 4)
	popup3.DLGAddPopupItemEntry("Option 1");
	popup3.DLGAddPopupItemEntry("Option 2");
	popup3.DLGAddPopupItemEntry("Option 3");

	TagGroup group = DLGGroupItems(popup, popupgroup, popupbox);
	group.DLGTableLayout(3,1, 0);

	return group
}

TagGroup MakePanels2()
{
	TagGroup panels1 = DLGCreatePanelList()
	TagGroup panel11 = panels1.DLGAddPanel()
	panel11.DLGAddElement( DLGCreateLabel("Panel 1.1") );

	TagGroup panels2 = DLGCreatePanelList( 1);
	
	TagGroup panel21;
	panels2.DLGAddPanel( DLGCreatePanel(panel21) );
	panel21.DLGAddElement( DLGCreateLabel("Panel 2.1") );
	panels2.DLGAddPanel().DLGAddElement( DLGCreateLabel("Panel 2.2") );
	panels2.DLGAddPanel().DLGAddElement( DLGCreateLabel("Panel 2.3") );
	
	TagGroup group = DLGGroupItems(panels1, panels2);
	group.DLGTableLayout(2, 1, 0);
	return group
}

TagGroup MakeTabs2()
{
	TagGroup tabs1 = DLGCreateTabList()
	TagGroup tab11 = tabs1.DLGAddTab("Tab 1.1")

	TagGroup tabs2 = DLGCreateTabList( 1);
	tabs2.DLGIdentifier("Tab");

	TagGroup tab21;
	tabs2.DLGAddTab( DLGCreateTab(tab21, "Tab 2.1") );
	tabs2.DLGAddTab("Tab 2.2");
	tabs2.DLGAddTab("Tab 2.3");
	
	TagGroup group = DLGGroupItems(tabs1, tabs2);
	group.DLGTableLayout(2, 1, 0);
	return group
}

void DialogLibraryTest2()
{

	//
	// CREATE TAGS
	//

	TagGroup dialog = DLGCreateDialog("Dialog Support 2");
	dialog.DLGPosition(100, 100, 200, 400);
	
	dialog.DLGAddElement( MakeLabels() );
	dialog.DLGAddElement( MakeButtons2() );
	dialog.DLGAddElement( MakeFields() );
	
	TagGroup group5 = DLGGroupItems(MakeCheckBoxes2(), MakeBoxesAndRadios2());
	group5.DLGTableLayout(2, 1, 0);
	dialog.DLGAddElement( group5);

	dialog.DLGAddElement( MakeLists2() );
	dialog.DLGAddElement( MakePopups2() );
	dialog.DLGAddElement( MakePanels2() );
	dialog.DLGAddElement( MakeTabs2() );
	dialog.DLGAddElement( DLGCreateTextBox(60, 2, 1024) );
	dialog.DLGAddElement( MakeImagePopup() )

	dialog.DLGAddElement( MakeProgressBar() );

	//
	// DISPLAY DIALOG
	//

	object dialog_frame = alloc(DialogLibraryTestClass).init(dialog)
	dialog_frame.display("Testing Dialog Library 2");


	//
	// TEST UIFRAME DIALOG UTILITIES
	//
		
	TagGroup button_tags;
	number buttonOn = dialog_frame.DLGGetBevelButtonOn("dsimage1", button_tags); 

	if ( button_tags.TagGroupIsValid() )
	{
		number new_state;

		if ( buttonOn )
			new_state = 0;
		else
			new_state = 1;

		result("dsimage1 button state: " + buttonOn + "; changing state to: " + new_state + "\n");
		dialog_frame.DLGBevelButtonOn("dsimage1", new_state);
		result("New dsimage1 button state: " + dialog_frame.DLGGetBevelButtonOn("dsimage1", button_tags) + "\n"); 
		result("Changing dsimage1 state back...\n");	
		button_tags.DLGBevelButtonOn(buttonOn);
		result("Old state restored: " + dialog_frame.DLGGetBevelButtonOn("dsimage1", button_tags) + "\n");
	}

	number pupval;
	dialog_frame.DLGGetValue("Image Popup", pupval);
	result("Image popup value: " + pupval + "\n");


	// DLGGetNthLabel() doesn't work on image popups!!
	TagGroup imgtags = dialog_frame.LookupElement("Image Popup");
	number index = 2;
	if ( imgtags.TagGroupIsValid() )
	{
		string imglabel
		if ( imgtags.DLGGetNthLabel(index, imglabel) )
			result("Image label" + index + ": " + imglabel + "\n");
	}

	TagGroup puptags = dialog_frame.LookupElement("Popup")
	if ( puptags.taggroupisvalid() )
	{
		string label
		if ( puptags.DLGGetNthLabel(index, label) )
			result("Popup label " + index + ": " + label + "\n");
	}

	TagGroup radiotags = dialog_frame.LookupElement("Radio")
	if ( radiotags.taggroupisvalid() )
	{
		string label
		if ( radiotags.DLGGetNthLabel(index, label) )
			result("Radio label" + index + ": " + label + "\n");
	}

	TagGroup tabtags = dialog_frame.LookupElement("Tab")
	if ( tabtags.taggroupisvalid() )
	{
		string label
		if ( tabtags.DLGGetNthLabel(index, label) )
			result("Tab label" + index + ": " + label + "\n");
	}

	dialog_frame.DLGSetProgress("Progress", 25);

}

/* --------------- DIALOG LIBRARY TEST 3---------------------------------------------------------*/

TagGroup RandomBitmap(number width, number height)
{
	Image bitmapImage := RGBImage( "bitmap", 4, width, height )
	number r1 = uniformrandom()*8
	number r2 = uniformrandom()*10
	bitmapImage = rgb( 128+127*sin( icol/r1 ), 128+127*cos( irow/r2 ), 0 )
	TagGroup bitmap = DLGCreateBitmap(bitmapImage)
	return bitmap
}
class DialogLibraryTest3Class : uiframe
{
	number change_count, action_count;
	number image_count

	void trackchange( object self, TagGroup tg)
	{
		change_count++;
		result("Change count: " + change_count + "\n");
	}
	
	void trackaction( object self)
	{
		TagGroup button_tags

		if ( self.DLGGetBevelButtonOn("dsimage1", button_tags) )
			result("dsimage1 is on\n")
		if ( self.DLGGetBevelButtonOn("dsimage2", button_tags) )
			result("dsimage2 is on\n")
		if ( self.DLGGetBevelButtonOn("dsimage3", button_tags) )
			result("dsimage3 is on\n")

		action_count++;
		result("Action count: " + action_count + "\n");	
	}

	// ADD
	// ADDED ELEMENTS CAN'T BE DISPLAYED
	void DoAddElement( object self)
	{
		TagGroup tg = DLGCreatePushButton("Added Button", "trackaction")
		TagGroup container 
	
		container = self.LookupElement("Box")
		if (!container.TagGroupIsValid())
			throw("Invalid container: Box")
		result("adding element\n")
		container.DLGAddElement(tg)

//		container = self.LookupElement("Panel")  // BUG BUG: can't find it
//		if (!container.TagGroupIsValid())
//			throw("Invalid container: Panel")
//		container.DLGAddElement(tg)

//		container = self.LookupElement("Tab")	// BUG BUG: can't find it
//		if (!container.TagGroupIsValid())
//			throw("Invalid container: Tab")
//		container.DLGAddElement(tg)
	}

	void DoAddLabeledItem( object self )
	{
		TagGroup container 
		
	// ADDED RADIO ITEMS CAN'T BE DISPLAYED
		container = self.LookupElement("Radio")
		if (!container.TagGroupIsValid())
			throw("Invalid container")
		container.DLGAddRadioItem("Added radio item", 5 )

		container = self.LookupElement("Popup")
		if (!container.TagGroupIsValid())
			throw("Invalid container")
		result("adding label to popup\n")
		container.DLGAddPopupItemEntry("Added Popup Entry")

		container = self.LookupElement("List")
		if (!container.TagGroupIsValid())
			throw("Invalid container")
		result("adding label to list\n")
		container.DLGAddListItem("Added List Entry", false)
	}

	// ADDED TABS CAN'T BE DISPLAYED
	void DoAddTab( object self )
	{
		TagGroup container 
		container = self.LookupElement("Tabs")
		if (!container.TagGroupIsValid())
			throw("Invalid container")
		result("adding tab\n")
		Number tcount = container.DLGGetItems().TagGroupCountTags()
		container.DLGAddTab("Added Tab" + tcount)
	}

	// ADDED PANELS CAN'T BE DISPLAYED
	void DoAddPanel( object self )
	{
		TagGroup container 
		container = self.LookupElement("Panels")
		if (!container.TagGroupIsValid())
			throw("Invalid container: Panels")
		container.TagGroupOpenBrowserWindow(0)
		result("adding panel\n")
		Number pcount = container.DLGGetItems().TagGroupCountTags()
		container.DLGAddPanel().DLGAddElement( DLGCreateLabel("Added Panel" + pcount) )
		container.DLGValue( pcount )
	}

	// ADDED BITMAPS CAN'T BE DISPLAYED
	void DoAddBitmap( object self )
	{
		TagGroup container 
		container = self.LookupElement("Graphic")
		result("adding bitmap\n")
		container.DLGAddBitmap( RandomBitmap( 100, 100 ) )
		number count = container.DLGGetItems().TagGroupCountTags()
		container.DLGValue( count - 1)
	}

	// INSERT
	// ADDED ELEMENTS CAN'T BE DISPLAYED
	void DoInsertElement( object self)
	{
		TagGroup tg = DLGCreatePushButton("Inserted Button", "trackaction")
		TagGroup container 
	
		result("Inserting element before box item 0\n")
		container = self.LookupElement("Box")
		container.DLGAddElementBefore(0, tg)

//		result("Inserting element after panel item 0\n")
//		container = self.LookupElement("Panel") // BUG BUG: can't find it
//		container.DLGAddElementAfter(0, tg)

//		result("Inserting element before tab item 99\n")
//		container = self.LookupElement("Tab")
//		container.DLGAddElementBefore(99, tg)
	}

	void DoInsertLabeledItem( object self )
	{
		TagGroup tg = DLGCreateRadioItem("Inserted Label", 0)
		TagGroup container 
		number index
		
	// ADDED RADIO ITEMS CAN'T BE DISPLAYED
		result("Inserting label before radio item 'option 2'\n")
		container = self.LookupElement("Radio")
		container.DLGGetElement("option 2", index)
		container.DLGAddElementBefore(index, tg)

		result("Inserting label before popup item 'Option 1'\n")
		container = self.LookupElement("Popup")
		container.DLGGetElement("Option 1", index)
		container.DLGAddElementBefore(index, tg)

		result("Inserting label after 'list item 2'\n")
		container = self.LookupElement("List")
		container.DLGGetElement("list item 2", index)
		container.DLGAddElementAfter(index, tg)
	}

	// ADDED TABS CAN'T BE DISPLAYED
	void DoInsertTab( object self )
	{
		TagGroup container 
		Number index
		container = self.LookupElement("Tabs")
		Number tcount = container.DLGGetItems().TagGroupCountTags()
		container.DLGGetElement("Tab 2.2", index)
		result("Inserting tab after 'Tab 2.2'\n")
		container.DLGAddElementAfter( index, DLGCreateTab("Inserted Tab" + tcount) )
	}

	// ADDED PANELS CAN'T BE DISPLAYED
	void DoInsertPanel( object self )
	{
		TagGroup container 
		container = self.LookupElement("Panels")
		if (!container.TagGroupIsValid())
			throw("Invalid container: Panels")
		Number pcount = container.DLGGetItems().TagGroupCountTags()
		TagGroup panel = DLGCreatePanel()
		panel.DLGAddElement( DLGCreateLabel("Inserted Panel" + pcount) )
		result("Inserting panel before panel item 0 and displaying panel index 1 \n")
		container.DLGAddElementBefore(0, panel)
		container.TagGroupOpenBrowserWindow(0)
		container.DLGValue( 1 )
	}

	// ADDED BITMAPS CAN'T BE DISPLAYED
	void DoInsertBitmap( object self )
	{
		TagGroup container 
		container = self.LookupElement("Graphic")
		container.DLGAddElementAfter( 0, RandomBitmap(100, 100) )
		container.DLGValue(1)
	}

	// REMOVE
	// DISPLAY WON'T UPDATE REMOVED ELEMENTS 
	void DoRemoveElement( object self)
	{
		TagGroup container 
		
		result("removing box item 0\n")
		container = self.LookupElement("Box")
		container.DLGRemoveElement(0)

//		result("removing last panel item\n")
//		container = self.LookupElement("Panel") // BUG BUG: can't find it
//		container.DLGRemoveLastElement()

//		result("removing tab item 2\n")
//		container = self.LookupElement("Tab")
//		container.DLGRemoveElement(2)
	}

	void DoRemoveLabeledItem( object self )
	{
		TagGroup container 
		
	// DISPLAY WON'T UPDATE REMOVED RADIO ITEMS
		result("removing radio item 'option 1'\n")
		container = self.LookupElement("Radio")
		container.DLGRemoveElement("option 1")

		result("removing popup item 'Option 2'\n")
		container = self.LookupElement("Popup")
		container.DLGRemoveElement("Option 2")

		result("removing 'list item 1'\n")
		container = self.LookupElement("List")
		container.DLGRemoveElement("list item 1")
	}

	// DISPLAY WON'T UPDATE REMOVED TABS
	void DoRemoveTab( object self )
	{
		TagGroup container 
		container = self.LookupElement("Tabs")
		result("removing 'Tab 2.2'\n")
		container.DLGRemoveElement("Tab 2.2")
	}

	// DISPLAY WON'T UPDATE REMOVED PANELS
	void DoRemovePanel( object self )
	{
		TagGroup container 
		container = self.LookupElement("Panels")
		result("removing last panel item\n")
		container.DLGRemoveLastElement()
		number count = container.DLGGetItems().TagGroupCountTags()
		container.DLGValue( count - 1)
	}

	void DoRemoveBitmap( object self )
	{
		TagGroup container 
		container = self.LookupElement("Graphic")
		result("removing the first bitmap \n")
		TagGroup element0 = container.DLGRemoveElement(0)
		number count = container.DLGGetItems().TagGroupCountTags()
//		container.DLGValue(count - 1) // this has no effect.
//		Container.DLGGetElement(count - 1).DLGInvalid(true)	 // this is NECESSARY for update
		element0.DLGInvalid(true)
	}

	// SET

	void DoSetElement( object self )
	{
		TagGroup container 
		container = self.LookupElement("Box")
		result("setting box element 0\n")

		TagGroup tg = DLGCreatePushButton("Replacement Button", "trackaction")
		container.DLGSetElement(0, tg)
	}

	void DoSetLabeledItem( object self )
	{
		TagGroup container 
		container = self.LookupElement("List")
		result("setting 'list item 3'\n")
		container.DLGSetElementLabel("list item 3", "replacement list item")

		container = self.LookupElement("Popup")
		result("setting last popup item\n")
		number count = container.DLGGetItems().TagGroupCountTags()
		container.DLGSetElementLabel(count - 1, "replacement list item")

	}

	void DoSetTab( object self )
	{
		TagGroup container 
		container = self.LookupElement("Tabs")
		TagGroup new_tab = DLGCreateTab("Replacement tab")
		result("setting 'Tab 2.1'\n")
		container.DLGSetElement("Tab 2.1", new_tab)
	}

	void DoSetBitmap( object self )
	{
		TagGroup container 
		container = self.LookupElement("Graphic")
		Image bitmapImage := RGBImage( "bitmap", 4, 200, 200 )
		number r1 = uniformrandom()*8
		number r2 = uniformrandom()*10
		bitmapImage = rgb( 128+127*sin( icol/r1 ), 128+127*cos( irow/r2 ), 0 )
		TagGroup bitmap = container.DLGGetElement(1)  
		result("setting bitmap 0\n")
		bitmap.DLGBitmapData(bitmapImage)
		// container.DLGValue(2)  // has no effect, it seems

	}

	// ITERATE
	void DoIterateBitmap( object self )
	{
		TagGroup container 
		container = self.LookupElement("Graphic")
		number count = container.DLGGetItems().TagGroupCountTags()

		image_count++
		if (image_count >= count)
			image_count = 0
		
		TagGroup bitmap = container.DLGGetElement(image_count)  
		result("viewing image " + image_count + "\n")
		container.DLGValue(image_count)	
//		Container.DLGInvalid(true)	// this has no effect
		Container.DLGGetElement(image_count).DLGInvalid(true)

	}
}

TagGroup MakeBoxesAndRadios3()
{
	TagGroup box1 = DLGCreateBox("Box")

	TagGroup radio1 = DLGCreateRadioList(5);
	radio1.DLGAddRadioItem("option 1", 0)
	radio1.DLGAddRadioItem("option 2", 1)
	radio1.DLGAddRadioItem("option 4", 5)
	radio1.DLGAddRadioItem("option 3", 3)
	radio1.DLGIdentifier("Radio")
	
	box1.DLGAddElement(radio1);
	box1.DLGIdentifier("Box")

	return box1;	
}

TagGroup MakeLists3()
{
	TagGroup list1 = DLGCreateList( "trackchange", "trackaction", 20, 2);
	list1.DLGAddListItem("list item 1", true);
	list1.DLGAddListItem("list item 2", true);
	list1.DLGAddListItem("list item 3", false);
	list1.DLGIdentifier("List")

	return list1

}

TagGroup MakePopups3()
{
	TagGroup popup = DLGCreatePopup(2, "trackchange")
	popup.DLGAddPopupItemEntry("Option 1");
	popup.DLGAddPopupItemEntry("Option 2");
	popup.DLGAddPopupItemEntry("Option 3");
	popup.DLGIdentifier("Popup")
	
	return popup
}

TagGroup MakePanels3()
{
	TagGroup panels2 = DLGCreatePanelList( 1);
	panels2.DLGIdentifier("Panels")
	
	TagGroup panel21 = DLGCreatePanel() 
	panel21.DLGAddElement( DLGCreateLabel("Panel 2.1") );
	panels2.DLGAddPanel( panel21 );
	panels2.DLGAddPanel().DLGAddElement( DLGCreateLabel("Panel 2.2") );
	panels2.DLGAddPanel().DLGAddElement( DLGCreateLabel("Panel 2.3") );
	panel21.DLGIdentifier("Panel")
//	panel21.TagGroupOpenBrowserWindow(0)
	panels2.DLGValue(0)
	
	return panels2
}

TagGroup MakeTabs3()
{
	TagGroup tabs2 = DLGCreateTabList( 1);
	tabs2.DLGIdentifier("Tabs");

	TagGroup tab21 = DLGCreateTab( "Tab 2.1") 
	tab21.DLGIdentifier("Tab")

	tabs2.DLGAddTab( tab21);
	tabs2.DLGAddTab("Tab 2.2");
	tabs2.DLGAddTab("Tab 2.3");
	
	return tabs2
}

TagGroup MakeGraphic()
{
	TagGroup graphic = DLGCreateGraphic(100, 100)

	TagGroup bitmap1 = RandomBitmap(100, 100)	
	Image img := RealImage("bitmap", 4, 100, 100)
	graphic.DLGAddElement( bitmap1 )
	img = icol * irow
	graphic.DLGAddBitmap( img )
	graphic.DLGValue(0)  		 // has no effect   : Initial display is always the last bitmap added
	bitmap1.DLGInvalid(true)	 // has no effect
	graphic.DLGIdentifier("Graphic")
	return graphic
}

void DialogLibraryTest3()
{
	//
	// CREATE TAGS
	//

	TagGroup dialog = DLGCreateDialog("Dialog Support 3");
	dialog.DLGPosition(100, 100, 200, 500);
	
	dialog.DLGAddElement( MakeBoxesAndRadios3() );
	dialog.DLGAddElement( DLGGroupItems( MakeLists3(), MakePopups3() ).DLGTableLayout(2, 1, 1) );
	dialog.DLGAddElement( DLGGroupItems( MakePanels3(), MakeTabs3() ).DLGTableLayout(2, 1, 1) );
	dialog.DLGAddElement( MakeGraphic() );

	TagGroup button1 = DLGCreatePushButton("Add Element*", "DoAddElement")
	TagGroup button2 = DLGCreatePushButton("Add List Item", "DoAddLabeledItem")
	TagGroup button3 = DLGCreatePushButton("Add Tab*", "DoAddTab")
	TagGroup button4 = DLGCreatePushButton("Add Panel*", "DoAddPanel")

	dialog.DLGAddElement( DLGGroupItems(button1, button2, button3, button4).DLGTableLayout(4, 1, 1) ).DLGAnchor("West")

	TagGroup button5 = DLGCreatePushButton("Insert Element*", "DoInsertElement")
	TagGroup button6 = DLGCreatePushButton("Insert List Item", "DoInsertLabeledItem")
	TagGroup button7 = DLGCreatePushButton("Insert Tab*", "DoInsertTab")
	TagGroup button8 = DLGCreatePushButton("Insert Panel*", "DoInsertPanel")

	dialog.DLGAddElement( DLGGroupItems(button5, button6, button7, button8).DLGTableLayout(4, 1, 1) ).DLGAnchor("West")

	TagGroup button9 = DLGCreatePushButton("Remove Element*", "DoRemoveElement")
	TagGroup button10 = DLGCreatePushButton("Remove List Item", "DoRemoveLabeledItem")
	TagGroup button11 = DLGCreatePushButton("Remove Tab*", "DoRemoveTab")
	TagGroup button12 = DLGCreatePushButton("Remove Panel*", "DoRemovePanel")

	dialog.DLGAddElement( DLGGroupItems(button9, button10, button11, button12).DLGTableLayout(3, 1, 1) ).DLGAnchor("West")

	TagGroup button13 = DLGCreatePushButton("Add Bitmap*", "DoAddBitmap")
	TagGroup button14 = DLGCreatePushButton("Insert Bitmap*", "DoInsertBitmap")
	TagGroup button15 = DLGCreatePushButton("Remove Bitmap", "DoRemoveBitmap")

	dialog.DLGAddElement( DLGGroupItems(button13, button14, button15).DLGTableLayout(3, 1, 1) ).DLGAnchor("West")

	TagGroup button16 = DLGCreatePushButton("Set Element*", "DoSetElement")
	TagGroup button17 = DLGCreatePushButton("Set List Item", "DoSetLabeledItem")
	TagGroup button18 = DLGCreatePushButton("Set Tab*", "DoSetTab")
	TagGroup button19 = DLGCreatePushButton("Set Bitmap", "DoSetBitmap")

	dialog.DLGAddElement( DLGGroupItems(button16, button17, button18, button19).DLGTableLayout(4, 1, 1) ).DLGAnchor("West")

	TagGroup button20 = DLGCreatePushButton("Iterate through Bitmaps", "DoIterateBitmap")
	dialog.DLGAddElement(button20)
	
	dialog.DLGAddElement(DLGCreateLabel("Buttons with * represent UNSUPPORTED FUNCTIONS"))

	//
	// DISPLAY DIALOG
	//

	object dialog_frame = alloc(DialogLibraryTest3Class).init(dialog)
	dialog_frame.display("Testing Dialog Library 3");

}


/* --------------- DIALOG LIBRARY TEST 4---------------------------------------------------------*/

void DialogLibraryTest4()
{
	//
	// CREATE TAGS
	//

	TagGroup dialog = DLGCreateDialog("Dialog Support 4");
	dialog.DLGPosition(100, 100, 200, 500);
	
	
	TagGroup panellist = DLGCreatePanelList()
	TagGroup panel = DLGCreatePanel()
	panel.DLGIdentifier("Panel1")  			// BUG BUG: LookupElement can't find this identifier
	panel.DLGAddElement( DLGCreateLabel("Hello") )
	panellist.DLGAddPanel(panel)
	panellist.DLGValue(0)
	dialog.DLGAddElement(panellist)

	//
	// DISPLAY DIALOG
	//

	object dialog_frame = alloc(DialogLibraryTestClass).init(dialog)
	dialog_frame.display("Testing Dialog Library 4");

	TagGroup container = dialog_frame.LookupElement("Panel1")
	if (!container.TagGroupIsValid() )
		throw("Invalid container: Panel1")
}
// Run Test

// DialogLibraryTest()	 // test initial dialog library
// DialogLibraryTest2()  // test new functions that hide the item_list taggroup from the programmer
 DialogLibraryTest3() 	 // test graphic and run-time dialog display update functions

// DialogLibraryTest4()	 // Test LookupElement()