/*
  fmt_coef_table_reporting.dlg

*! VERSION 1.0.3  28sep2010

*/

VERSION 12.0

INCLUDE _std_large
DEFINE _dlght 140
DEFINE _dlgwd 470
INCLUDE header
HELP hlp1, view("help cformat")
RESET res1

PROGRAM PREINIT_PROGRAM
BEGIN
	call create STRING outstr
	call outstr.setvalue ""

	if __MESSAGE.iseq("-cformat_only-") {
		call script main_enable_cformat
	}
END

DIALOG main, label("Format settings for coefficient tables")		///
	tabtitle("Main")
BEGIN
  TEXT tx_cformat		160	_top	90	.,		///
	center								///
	label("Coef/SE/CI") 
  TEXT tx_pformat		260	@	@	.,		///
	center								///
	label("p-value") 
  TEXT tx_sformat		360	@	@	.,		///
	center								///
	label("Test statistic") 

DEFINE x1 10
DEFINE x2 160
DEFINE x3 260
DEFINE x4 360

DEFINE x_c1 190
DEFINE x_c2 290
DEFINE x_c3 390

DEFINE label_w 160
DEFINE col_w 90
  
  TEXT tx_decimal		x1	_ss	label_w	.,		///
	label("Decimal format") 
  COMBOBOX cb_cformat		x2	@	col_w	.,		///
	dropdown							///
	contents(cformat_list)						///
	values(cformat_list_values)					///
	default("Default")						///
	error(`"Decimal format for "Coef/SE/CI" is incorrect"')
  COMBOBOX cb_pformat		x3	@	@	.,		///
	dropdown							///
	contents(pformat_list)						///
	values(pformat_list_values)					///
	default("Default")						///
	error(`"Decimal format for "p-value" is incorrect"')
  COMBOBOX cb_sformat		x4	@	@	.,		///
	dropdown							///
	contents(sformat_list)						///
	values(sformat_list_values)					///
	default("Default")						///
	error(`"Decimal format for "Test statistic" is incorrect"')
  
  TEXT tx_euro			x1	_ms	label_w	.,		///
	label("European commas/decimals") 
  CHECKBOX ck_euro_cf		x_c1	@	col_w	.,		///
	label("") 
  CHECKBOX ck_euro_pf		x_c2	@	@	.,		///
	label("") 
  CHECKBOX ck_euro_sf		x_c3	@	@	.,		///
	label("") 
 
  TEXT tx_comma			x1	_ms	label_w	.,		///
	label("Commas in numeric output") 
  CHECKBOX ck_comma_cf		x_c1	@	col_w	.,		///
	label("") 
  CHECKBOX ck_comma_pf		x_c2	@	@	.,		///
	label("") 
  CHECKBOX ck_comma_sf		x_c3	@	@	.,		///
	label("") 

  TEXT tx_pad			x1	_ms	label_w	.,		///
	label("Pad with leading zeros") 
  CHECKBOX ck_pad_cf		x_c1	@	col_w	.,		///
	label("") 
  CHECKBOX ck_pad_pf		x_c2	@	@	.,		///
	label("") 
  CHECKBOX ck_pad_sf		x_c3	@	@	.,		///
	label("") 
END

SCRIPT main_enable_cformat
BEGIN
	main.tx_cformat.enable
	main.tx_pformat.disable
	main.tx_sformat.disable
	main.cb_cformat.enable
	main.cb_pformat.disable
	main.cb_sformat.disable
	main.ck_euro_cf.enable
	main.ck_euro_pf.disable
	main.ck_euro_sf.disable
	main.ck_comma_cf.enable
	main.ck_comma_pf.disable
	main.ck_comma_sf.disable
	main.ck_pad_cf.enable
	main.ck_pad_pf.disable
	main.ck_pad_sf.disable
END

LIST cformat_list
BEGIN
	"Default"
	"0 decimals"
	"1 decimals"
	"2 decimals"
	"3 decimals"
	"4 decimals"
	"5 decimals"
END

LIST cformat_list_values
BEGIN
	d
	0
	1
	2
	3
	4
	5
END

LIST pformat_list
BEGIN
	"Default"
	"0 decimals"
	"1 decimals"
	"2 decimals"
	"3 decimals"
	"4 decimals"
END

LIST pformat_list_values
BEGIN
	d
	0
	1
	2
	3
	4
END

LIST sformat_list
BEGIN
	"Default"
	"0 decimals"
	"1 decimals"
	"2 decimals"
	"3 decimals"
END

LIST sformat_list_values
BEGIN
	d
	0
	1
	2
	3
END

PROGRAM cformat_output
BEGIN
	call outstr.setvalue "%"
	if main.ck_pad_cf & main.ck_pad_cf.isenabled() {
		call outstr.append "0"
	}
	call outstr.append "9"
	if main.ck_euro_cf & main.ck_euro_cf.isenabled() {
		call outstr.append ","
	}
	else {
		call outstr.append "."
	}
	if main.cb_cformat.iseq("d") {
		call outstr.append "0g"
	}
	else {
		call outstr.append class main.cb_cformat.value
		call outstr.append "f"
	}
	if main.ck_comma_cf & main.ck_comma_cf.isenabled() {
		call outstr.append "c"
	}
	put outstr
END

PROGRAM pformat_output
BEGIN
	call outstr.setvalue "%"
	if main.ck_pad_pf & main.ck_pad_pf.isenabled() {
		call outstr.append "0"
	}
	call outstr.append "5"
	if main.ck_euro_pf & main.ck_euro_pf.isenabled() {
		call outstr.append ","
	}
	else {
		call outstr.append "."
	}
	if main.cb_pformat.iseq("d") {
		call outstr.append "0g"
	}
	else {
		call outstr.append class main.cb_pformat.value
		call outstr.append "f"
	}
	if main.ck_comma_pf & main.ck_comma_pf.isenabled() {
		call outstr.append "c"
	}
	put outstr
END

PROGRAM sformat_output
BEGIN
	call outstr.setvalue "%"
	if main.ck_pad_sf & main.ck_pad_sf.isenabled() {
		call outstr.append "0"
	}
	call outstr.append "8"
	if main.ck_euro_sf & main.ck_euro_sf.isenabled() {
		call outstr.append ","
	}
	else {
		call outstr.append "."
	}
	if main.cb_sformat.iseq("d") {
		call outstr.append "0g"
	}
	else {
		call outstr.append class main.cb_sformat.value
		call outstr.append "f"
	}	
	if main.ck_comma_sf & main.ck_comma_sf.isenabled() {
		call outstr.append "c"
	}
	put outstr
END

PROGRAM command
BEGIN
	if !main.cb_cformat.iseq("d") | main.ck_euro_cf |		///
		main.ck_comma_cf | main.ck_pad_cf {
		put " cformat("
		put /program cformat_output
		put ")"
	}
	if !main.cb_pformat.iseq("d") | main.ck_euro_pf |		///
		main.ck_comma_pf | main.ck_pad_pf {
		put " pformat("
		put /program pformat_output
		put ")"
	}
	if !main.cb_sformat.iseq("d") | main.ck_euro_sf |		///
		main.ck_comma_sf | main.ck_pad_sf {
		put " sformat("
		put /program sformat_output
		put ")"
	}
END
