/*
    gr_bars.idlg

*!  VERSION 1.0.0  23jan2007

*/

SCRIPT gr_bars_PREINIT
BEGIN
	create STRING gr_bars_result1
	create STRING gr_bars_result2
	create STRING gr_bars_result3
	create STRING gr_bars_result4
	create STRING gr_bars_result5
	create STRING gr_bars_result6
	create STRING gr_bars_result7
	create STRING gr_bars_result8
	create STRING gr_bars_result9
	create STRING gr_bars_result10
	create STRING gr_bars_result11
	create STRING gr_bars_result12
	create STRING gr_bars_result13
	create STRING gr_bars_result14
	create STRING gr_bars_result15
	create STRING gr_bars_result16
	
	create STRING gr_bars_labelOptResult
END

SCRIPT gr_bars_POSTINIT
BEGIN
	program gr_bars_rebuild_list
END

DIALOG gr_bars, tabtitle("Bars")
BEGIN
  GROUPBOX gb_bars	_lft	_top	_rj210	_ht18h,	///
	label("Bar properties")
  TEXT     tx_vars	_ilft	_ss	_inwd	.,	///
	label("Bars:")
  DEFINE cx @cx
  LISTBOX  lb_vars	_ilft	_ss	140	105,	///
	contents(gr_bars_barList)			///
	values(gr_bars_barList_values)			///
	ondblclick(program gr_bars_check_selection)
  BUTTON  bu_edit	+160	@	60	.,	///
	label("Edit")					///
	tooltip("Click to edit the properties of the selected item") ///
	onpush(program gr_bars_check_selection)

  TEXTBOX  tb_note1	_ilft	+120	cx	_tb3,		///
	label("The properties for each bar associated with a"	///
	"variable and statistic can be set." 			///
	"Bars that are represented in multiple categories"	///
	"will share properties.")
	
  GROUPBOX gb_labels	_lft	+65	_iwd	_ht10,	///
	label("Bar labels")
  RADIO	   rb_none	_ilft	_ss	_rj220	.,	///
	first						///
	onclickon(program gr_bars_check_labels)		///
	label("Do not label bars")
  DEFINE y @y
  RADIO    rb_bar	@	_ss	@	.,	///
	onclickon(program gr_bars_check_labels)		///
	label("Label with bar height")			///
	option(bar)
  RADIO    rb_total	@	_ss	@	.,	///
	onclickon(program gr_bars_check_labels)		///
	label("Label with total bar height")		///
	option(total)
  RADIO    rb_name	@	_ss	@	.,	///
	onclickon(program gr_bars_check_labels)		///
	label("Label with y variable name")		///
	option(name)
  RADIO    rb_group	@	_ss	@	.,	///
	last						///
	onclickon(program gr_bars_check_labels)		///
	label("Label with first grouping categories")	///
	option(group)

  BUTTON   bu_options	_irj100	y	100	.,	///
	label("Properties  ")				///
	tooltip("Bar label properties")			///
	onpush(script gr_bars_showLabelOptions)

  GROUPBOX gb_global	_rj190	_top	190	_ht18h,	///
	label("Global bar settings")
  TEXT     tx_bargap	_rj180	_mls	110	.,	///
	label("Gap between bars:") right
  EDIT	   ed_bargap	+115	@	55	.,	///
	option(bargap)
  TEXT     tx_ogap	_rj180	_mls	110	.,	///
	label("Outside gap:") right
  EDIT	   ed_ogap	+115	@	55	.,	///
	option(outergap)
  TEXT     tx_fintens	_rj180	_mls	110	.,	///
	label("Fill intensity:") right
  EDIT	   ed_fintens	+115	@	55	.,	///
	option(intensity)
  TEXT     tx_lintens	_rj180	_mls	110	.,	///
	label("Outline intensity:") right
  EDIT	   ed_lintens	+115	@	55	.,	///
	option(lintensity)
END

PROGRAM gr_bars_check_labels
BEGIN
	if gr_bars.rb_none {
		call gr_bars.bu_options.disable
	}
	else {
		call gr_bars.bu_options.enable
	}
END

SCRIPT gr_bars_showLabelOptions
BEGIN
	create CHILD gr_bar_label, allowsubmit
	gr_bar_label.setExitString gr_bars_labelOptResult
	gr_bar_label.setOkAction "program gr_bars_labelCheckResult"
	gr_bar_label.setSubmitAction "script gr_bars_labelSubmit"
END
PROGRAM gr_bars_labelCheckResult
BEGIN
	if gr_bars_labelOptResult {
		call gr_bars.bu_options.setlabel "Properties *"
	}
	else {
		call gr_bars.bu_options.setlabel "Properties  "
	}
END
SCRIPT gr_bars_labelSubmit
BEGIN
	program gr_bars_labelCheckResult
	Submit
END

LIST gr_bars_barList
BEGIN
	Bar for variable 1
	Bar for variable 2
	Bar for variable 3
	Bar for variable 4
	Bar for variable 5
	Bar for variable 6
	Bar for variable 7
	Bar for variable 8
	Bar for variable 9
	Bar for variable 10
	Bar for variable 11
	Bar for variable 12
	Bar for variable 13
	Bar for variable 14
	Bar for variable 15
	Bar for variable 16
END

LIST gr_bars_barList_values
BEGIN
	"Var 1"
	"Var 2"
	"Var 3"
	"Var 4"
	"Var 5"
	"Var 6"
	"Var 7"
	"Var 8"
	"Var 9"
	"Var 10"
	"Var 11"
	"Var 12"
	"Var 13"
	"Var 14"
	"Var 15"
	"Var 16"
END

PROGRAM gr_bars_check_selection
BEGIN
	if gr_bars.lb_vars.iseq("Var 1") {
		call script gr_bars_edit_var1
	}
	if gr_bars.lb_vars.iseq("Var 2") {
		call script gr_bars_edit_var2
	}
	if gr_bars.lb_vars.iseq("Var 3") {
		call script gr_bars_edit_var3
	}
	if gr_bars.lb_vars.iseq("Var 4") {
		call script gr_bars_edit_var4
	}
	if gr_bars.lb_vars.iseq("Var 5") {
		call script gr_bars_edit_var5
	}
	if gr_bars.lb_vars.iseq("Var 6") {
		call script gr_bars_edit_var6
	}
	if gr_bars.lb_vars.iseq("Var 7") {
		call script gr_bars_edit_var7
	}
	if gr_bars.lb_vars.iseq("Var 8") {
		call script gr_bars_edit_var8
	}
	if gr_bars.lb_vars.iseq("Var 9") {
		call script gr_bars_edit_var9
	}
	if gr_bars.lb_vars.iseq("Var 10") {
		call script gr_bars_edit_var10
	}
	if gr_bars.lb_vars.iseq("Var 11") {
		call script gr_bars_edit_var11
	}
	if gr_bars.lb_vars.iseq("Var 12") {
		call script gr_bars_edit_var12
	}
	if gr_bars.lb_vars.iseq("Var 13") {
		call script gr_bars_edit_var13
	}
	if gr_bars.lb_vars.iseq("Var 14") {
		call script gr_bars_edit_var14
	}
	if gr_bars.lb_vars.iseq("Var 15") {
		call script gr_bars_edit_var15
	}
	if gr_bars.lb_vars.iseq("Var 16") {
		call script gr_bars_edit_var16
	}
END

SCRIPT gr_bars_edit_var1
BEGIN
	create CHILD gr_bar_edit AS var1, allowsubmit
	var1.setExitString "gr_bars_result1"
	var1.setExitAction "program gr_bars_rebuild_list"
	var1.setSubmitAction "program var1_submit_done"
	var1.settitle "Bar for variable 1"
END
PROGRAM var1_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var2
BEGIN
	create CHILD gr_bar_edit AS var2, allowsubmit
	var2.setExitString "gr_bars_result2"
	var2.setExitAction "program gr_bars_rebuild_list"
	var2.setSubmitAction "program var2_submit_done"
	var2.settitle "Bar for variable 2"
END
PROGRAM var2_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var3
BEGIN
	create CHILD gr_bar_edit AS var3, allowsubmit
	var3.setExitString "gr_bars_result3"
	var3.setExitAction "program gr_bars_rebuild_list"
	var3.setSubmitAction "program var3_submit_done"
	var3.settitle "Bar for variable 3"
END
PROGRAM var3_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var4
BEGIN
	create CHILD gr_bar_edit AS var4, allowsubmit
	var4.setExitString "gr_bars_result4"
	var4.setExitAction "program gr_bars_rebuild_list"
	var4.setSubmitAction "program var4_submit_done"
	var4.settitle "Bar for variable 4"
END
PROGRAM var4_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var5
BEGIN
	create CHILD gr_bar_edit AS var5, allowsubmit
	var5.setExitString "gr_bars_result5"
	var5.setExitAction "program gr_bars_rebuild_list"
	var5.setSubmitAction "program var5_submit_done"
	var5.settitle "Bar for variable 5"
END
PROGRAM var5_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var6
BEGIN
	create CHILD gr_bar_edit AS var6, allowsubmit
	var6.setExitString "gr_bars_result6"
	var6.setExitAction "program gr_bars_rebuild_list"
	var6.setSubmitAction "program var6_submit_done"
	var6.settitle "Bar for variable 6"
END
PROGRAM var6_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var7
BEGIN
	create CHILD gr_bar_edit AS var7, allowsubmit
	var7.setExitString "gr_bars_result7"
	var7.setExitAction "program gr_bars_rebuild_list"
	var7.setSubmitAction "program var7_submit_done"
	var7.settitle "Bar for variable 7"
END
PROGRAM var7_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var8
BEGIN
	create CHILD gr_bar_edit AS var8, allowsubmit
	var8.setExitString "gr_bars_result8"
	var8.setExitAction "program gr_bars_rebuild_list"
	var8.setSubmitAction "program var8_submit_done"
	var8.settitle "Bar for variable 8"
END
PROGRAM var8_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var9
BEGIN
	create CHILD gr_bar_edit AS var9, allowsubmit
	var9.setExitString "gr_bars_result9"
	var9.setExitAction "program gr_bars_rebuild_list"
	var9.setSubmitAction "program var9_submit_done"
	var9.settitle "Bar for variable 9"
END
PROGRAM var9_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var10
BEGIN
	create CHILD gr_bar_edit AS var10, allowsubmit
	var10.setExitString "gr_bars_result10"
	var10.setExitAction "program gr_bars_rebuild_list"
	var10.setSubmitAction "program var10_submit_done"
	var10.settitle "Bar for variable 10"
END
PROGRAM var10_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var11
BEGIN
	create CHILD gr_bar_edit AS var11, allowsubmit
	var11.setExitString "gr_bars_result11"
	var11.setExitAction "program gr_bars_rebuild_list"
	var11.setSubmitAction "program var11_submit_done"
	var11.settitle "Bar for variable 11"
END
PROGRAM var11_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var12
BEGIN
	create CHILD gr_bar_edit AS var12, allowsubmit
	var12.setExitString "gr_bars_result12"
	var12.setExitAction "program gr_bars_rebuild_list"
	var12.setSubmitAction "program var12_submit_done"
	var12.settitle "Bar for variable 12"
END
PROGRAM var12_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var13
BEGIN
	create CHILD gr_bar_edit AS var13, allowsubmit
	var13.setExitString "gr_bars_result13"
	var13.setExitAction "program gr_bars_rebuild_list"
	var13.setSubmitAction "program var13_submit_done"
	var13.settitle "Bar for variable 13"
END
PROGRAM var13_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var14
BEGIN
	create CHILD gr_bar_edit AS var14, allowsubmit
	var14.setExitString "gr_bars_result14"
	var14.setExitAction "program gr_bars_rebuild_list"
	var14.setSubmitAction "program var14_submit_done"
	var14.settitle "Bar for variable 14"
END
PROGRAM var14_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var15
BEGIN
	create CHILD gr_bar_edit AS var15, allowsubmit
	var15.setExitString "gr_bars_result15"
	var15.setExitAction "program gr_bars_rebuild_list"
	var15.setSubmitAction "program var15_submit_done"
	var15.settitle "Bar for variable 15"
END
PROGRAM var15_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

SCRIPT gr_bars_edit_var16
BEGIN
	create CHILD gr_bar_edit AS var16, allowsubmit
	var16.setExitString "gr_bars_result16"
	var16.setExitAction "program gr_bars_rebuild_list"
	var16.setSubmitAction "program var16_submit_done"
	var16.settitle "Bar for variable 16"
END
PROGRAM var16_submit_done
BEGIN
	call program gr_bars_rebuild_list
	call Submit
END

PROGRAM gr_bars_rebuild_list
BEGIN
	call gr_bars_barList.Arrdropall
	
	if gr_bars_result1 {
		call gr_bars_barList.Arrpush "Bar for variable 1 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 1  "
	}
	if gr_bars_result2 {
		call gr_bars_barList.Arrpush "Bar for variable 2 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 2  "
	}
	if gr_bars_result3 {
		call gr_bars_barList.Arrpush "Bar for variable 3 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 3  "
	}
	if gr_bars_result4 {
		call gr_bars_barList.Arrpush "Bar for variable 4 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 4  "
	}
	if gr_bars_result5 {
		call gr_bars_barList.Arrpush "Bar for variable 5 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 5  "
	}
	if gr_bars_result6 {
		call gr_bars_barList.Arrpush "Bar for variable 6 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 6  "
	}
	if gr_bars_result7 {
		call gr_bars_barList.Arrpush "Bar for variable 7 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 7  "
	}
	if gr_bars_result8 {
		call gr_bars_barList.Arrpush "Bar for variable 8 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 8  "
	}
	if gr_bars_result9 {
		call gr_bars_barList.Arrpush "Bar for variable 9 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 9  "
	}
	if gr_bars_result10 {
		call gr_bars_barList.Arrpush "Bar for variable 10 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 10  "
	}
	if gr_bars_result11 {
		call gr_bars_barList.Arrpush "Bar for variable 11 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 11  "
	}
	if gr_bars_result12 {
		call gr_bars_barList.Arrpush "Bar for variable 12 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 12  "
	}
	if gr_bars_result13 {
		call gr_bars_barList.Arrpush "Bar for variable 13 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 13  "
	}
	if gr_bars_result14 {
		call gr_bars_barList.Arrpush "Bar for variable 14 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 14  "
	}
	if gr_bars_result15 {
		call gr_bars_barList.Arrpush "Bar for variable 15 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 15  "
	}
	if gr_bars_result16 {
		call gr_bars_barList.Arrpush "Bar for variable 16 *"
	}
	else {
		call gr_bars_barList.Arrpush "Bar for variable 16  "
	}
	call gr_bars.lb_vars.repopulate
END

PROGRAM gr_bars_blabel_output
BEGIN
	option gr_bars.rb_bar
	option gr_bars.rb_total
	option gr_bars.rb_name
	option gr_bars.rb_group
	beginoptions
		put gr_bars_labelOptResult
	endoptions
END

PROGRAM gr_bars_output
BEGIN
	if gr_bars_result1 {
		put "bar(1, " gr_bars_result1 ") "
	}
	if gr_bars_result2 {
		put "bar(2, " gr_bars_result2 ") "
	}
	if gr_bars_result3 {
		put "bar(3, " gr_bars_result3 ") "
	}
	if gr_bars_result4 {
		put "bar(4, " gr_bars_result4 ") "
	}
	if gr_bars_result5 {
		put "bar(5, " gr_bars_result5 ") "
	}
	if gr_bars_result6 {
		put "bar(6, " gr_bars_result6 ") "
	}
	if gr_bars_result7 {
		put "bar(7, " gr_bars_result7 ") "
	}
	if gr_bars_result8 {
		put "bar(8, " gr_bars_result8 ") "
	}
	if gr_bars_result9 {
		put "bar(9, " gr_bars_result9 ") "
	}
	if gr_bars_result10 {
		put "bar(10, " gr_bars_result10 ") "
	}
	if gr_bars_result11 {
		put "bar(11, " gr_bars_result11 ") "
	}
	if gr_bars_result12 {
		put "bar(12, " gr_bars_result12 ") "
	}
	if gr_bars_result13 {
		put "bar(13, " gr_bars_result13 ") "
	}
	if gr_bars_result14 {
		put "bar(14, " gr_bars_result14 ") "
	}
	if gr_bars_result15 {
		put "bar(15, " gr_bars_result15 ") "
	}
	if gr_bars_result16 {
		put "bar(16, " gr_bars_result16 ") "
	}
	
	optionarg gr_bars.ed_bargap
	optionarg gr_bars.ed_ogap
	optionarg gr_bars.ed_fintens
	optionarg gr_bars.ed_lintens

	if ! gr_bars.rb_none {
		put "blabel("
		put /program gr_bars_blabel_output
		put ") "
	}
END
