//**********************************************************
// Dialog Control - IconRadioButton
// LABPP 2022
//**********************************************************

#include "items.h"
// 
string sProcName = "IconRadioButton";

int main()
{
	cout << sProcName << "\n";

	int iarg1; double darg2; string sarg3;
	run_cpp("get_args",iarg1, darg2, sarg3);

	if (sarg3 == "Get PCG item name")
	{
		var_extern_set("PCG item name", sProcName);
		return 0;
	}


	if (sarg3 == "Help")
	{
		tsalert(-3, "Information", "",
			"");
		return 0;
	}

//	string genesis, v_type, varname, svalue, sdescription, sgroup;
//	programcodegen("get_bimmaster_cur_selected_parameter_info", genesis, v_type, varname, svalue, sdescription, sgroup);

	string prg_code_gen;
	string DialogSuffix="_DS";
	string DCName="_DCName";

	int res = ac_request("editstringdialog", "Enter Dialog Control Name", DCName);
	if (res == 1)
	{
		DCName = ac_getstrvalue();
	}
	res = ac_request("editstringdialog", "Enter Dialog Suffix", DialogSuffix);
	if (res == 1)
	{
		DialogSuffix = ac_getstrvalue();
	}
	string EditType = "IconRadioButton";
//	int iTable;
//	object("create","ts_table",iTable);
//	ts_table(iTable,"add_column",-1,"string","name");
//	ts_table(iTable,"add_row",0,"TextEdit");
//	ts_table(iTable,"add_row",0,"RealEdit");
//	ts_table(iTable,"add_row",0,"IntEdit");
//	ts_table(iTable,"add_row",0,"PosintEdit");
//	res = ac_request("EditStringListDialog", "Select Edit Type", iTable, 2);
//	if (res == 1)
//	{
//		EditType = ac_getstrvalue();
//		coutvar << EditType;
//	}
	
	string IconFilePath="IconFilePath.png";
	string ToolTipText="Tool Tip Text";
	res = ac_request("editstringdialog", "Enter Icon Filepath", IconFilePath);
	if (res == 1)
	{
		IconFilePath = ac_getstrvalue();
	}
	res = ac_request("editstringdialog", "Enter Tool Tip Text", ToolTipText);
	if (res == 1)
	{
		ToolTipText = ac_getstrvalue();
	}
	
	string EditName = "i"+EditType+DCName+DialogSuffix;
	
    prg_code_gen = "//---------------->\n\
	int	x,y,w,h,offset;\n\
	x =1; y= 1; w = 100; h = 24;\n\
	var_by_txt(\"init\", \""+EditName+"\", \"int\", \"global\",0);\n\
	object(\"create\", \"ts_dialogcontrol\", "+EditName+");\n\
	int igroup = 1;\n\
	ts_dialogcontrol("+EditName+", \"init_control\", \""+EditType+"\", iDialog"+DialogSuffix+", x, y, w, h, igroup);\n\
	ts_dialogcontrol("+EditName+", \"settooltip\", \""+ToolTipText+"\");\n\
	//ts_dialogcontrol("+EditName+", \"eventreaction\", \"Event_RadioItemChanged\",\"Event_RadioItemChanged"+DCName+DialogSuffix+"\");\n";
	prg_code_gen +="\
    string iconpath;\n\
    shell_func(\"get_path\", \"currentcppfiles\", iconpath);\n\
	ts_dialogcontrol("+EditName+", \"SetIcon\",\"+iconpath+\"\\\"+IconFilePath+\"\\\");\n\
	ts_dialogcontrol("+EditName+", \"Select\");\n";

	prg_code_gen +="\n\
// Events\n\
//int Event_RadioItemChanged"+DCName+DialogSuffix+"(int iDescr, string sDescr)\n\
//{\n\
//   if (sDescr == \""+EditName+"\"){\n\
//      bool bSelected;\n\
//      ts_dialogcontrol("+EditName+", \"IsSelected\", bSelected);\n\
//      coutvar << bSelected;\n\
//   }\n\
//}";

	var_extern_set("PCG item result", prg_code_gen);

}

//<--------
