/*
  misstable INCLUDE file

*!  VERSION 1.0.4  12apr2011

*/

  GROUPBOX gb_miss	_lft	_top	_iwd	_ht8,			///
	label("Missing values")
  RADIO	rb_summ		_indent	_ss	_inwd	.,			///
	label("Report counts")						///
	onclickon("program main_summ_on")				///
	first								///
	option("summarize")
  RADIO	rb_pat		@	_ss	@	.,			///
	label("Report pattern")						///
	onclickon("program main_pat_on")				///
	option("patterns")
  RADIO	rb_tree		@	_ss	@	.,			///
	label("Present a tree view of the pattern")			///
	onclickon("program main_tree_on")				///
	option("tree")
  RADIO	rb_nested	@	_ss	@	.,			///
	label("List the nesting rules that describe the pattern")	///
	onclickon("program main_nest_on")				///
	last								///
	option("nested")

  TEXT tx_vars		_lft	_xls	_cwd1	.,			///
	label("Variables:")
  VARLIST vl_vars	@	_ss	_iwd	.,			///
	label("Variables")

  CHECKBOX ck_all	_lft	_ls	_iwd	.,			///
	option(all)							///
	label("Show all variables")
  DEFINE holdy @y
  CHECKBOX ck_zero	@	_ms	@	.,			///
	option(showzeros)						///
	label("Show zeros in table")
  CHECKBOX ck_generate	@	_ls	@	_ht6h,			///
	groupbox							///
	onclickon("script main_generate_on")				///
	onclickoff("script main_generate_off")				///
	label("Generate missing-value indicators")
  TEXT tx_generate	_indent	_ss	_inwd	.,			///
	label("Variable stub:")
  EDIT ed_generate	@	_ss	_vnwd	.,			///
	label("Variable stub")
  CHECKBOX ck_gen_exok	@	_ls	_ibwd	.,			///
	option(exok)							///
	label("Treat extended missing values as nonmissing")

  CHECKBOX ck_asis	_lft	holdy	_iwd	.,			///
	option(asis)							///
	label("Use variables in order given")
  CHECKBOX ck_freq	@	_ms	@	.,			///
	option(frequency)						///
	label("Report frequencies instead of percentages")
  CHECKBOX ck_exok	@	_ms	@	.,			///
	option(exok)							///
	onclickon("main.ck_exmiss.disable")				///
	onclickoff("main.ck_exmiss.enable")				///
	label("Treat extended missing values as nonmissing")
  CHECKBOX ck_repl	@	_ms	@	.,			///
	option(replace)							///
	label("Replace dataset in memory with dataset of patterns")
  CHECKBOX ck_clear	@	_ms	@	.,			///
	option(clear)							///
	label("Replace unsaved data in memory with dataset of patterns")
  CHECKBOX ck_bypat	@	_ms	@	.,			///
	option(bypatterns)						///
	label("Order table by pattern rather than frequency")
  CHECKBOX ck_exmiss	@	_ms	@	.,			///
	option(exmiss)							///
	onclickon("main.ck_exok.disable")				///
	onclickoff("main.ck_exok.enable")				///
	label("Treat extended missing values as missing")
  SPINNER sp_m		@	_ls	_en7wd	.,			///
	default(0)							///
	min(0)								///
	max(100000)							///
	option(m)							///
	label("Dataset to run mi misstable on")
  TEXT tx_m		_en7sep	@	220	.,			///
	label("Dataset to run mi misstable on")
END

PROGRAM main_summ_on
BEGIN
	call main.ck_all.show
	call main.ck_zero.show
	if !isMI {
		call main.ck_generate.show
		call main.tx_generate.show
		call main.ed_generate.show
		call main.ck_gen_exok.show
		if main.ck_generate {
			call script main_generate_on
		}
		else {
			call script main_generate_off
		}
	}
	else {
		call main.ck_generate.hide
		call main.tx_generate.hide
		call main.ed_generate.hide
		call main.ck_gen_exok.hide
	}
	call main.ck_asis.hide
	call main.ck_freq.hide
	call main.ck_exok.hide
	call main.ck_repl.hide
	call main.ck_clear.hide
	call main.ck_bypat.hide

	call main.ck_exmiss.hide
	call main.sp_m.hide
	call main.tx_m.hide
END

PROGRAM main_pat_on
BEGIN
	call main.ck_all.hide
	call main.ck_zero.hide
	call main.ck_generate.hide
	call main.tx_generate.hide
	call main.ed_generate.hide
	call main.ck_gen_exok.hide

	call main.ck_asis.show
	call main.ck_freq.show
	call main.ck_exok.show
	call main.ck_exok.setposition . 230
	call main.ck_repl.show
	call main.ck_clear.show
	call main.ck_bypat.show
	if isMI {
		call main.ck_exmiss.show
		call main.ck_exmiss.setposition . 255
		call main.ck_repl.setposition . 280
		call main.ck_clear.setposition . 305
		call main.ck_bypat.setposition . 330
		call main.sp_m.show
		call main.sp_m.setposition . 360
		call main.tx_m.show
		call main.tx_m.setposition . 360
	}
	else {
		call main.ck_exmiss.hide
		call main.sp_m.hide
		call main.tx_m.hide
	}
END

PROGRAM main_tree_on
BEGIN
	call main.ck_all.hide
	call main.ck_zero.hide
	call main.ck_generate.hide
	call main.tx_generate.hide
	call main.ed_generate.hide
	call main.ck_gen_exok.hide

	call main.ck_asis.show
	call main.ck_freq.show
	call main.ck_exok.show
	call main.ck_exok.setposition . 230
	call main.ck_repl.hide
	call main.ck_clear.hide
	call main.ck_bypat.hide

	if isMI {
		call main.ck_exmiss.show
		call main.ck_exmiss.setposition . 255
		call main.sp_m.show
		call main.sp_m.setposition . 280
		call main.tx_m.show
		call main.tx_m.setposition . 280
	}
	else {
		call main.ck_exmiss.hide
		call main.sp_m.hide
		call main.tx_m.hide
	}
END

PROGRAM main_nest_on
BEGIN
	call main.ck_all.hide
	call main.ck_zero.hide
	call main.ck_generate.hide
	call main.tx_generate.hide
	call main.ed_generate.hide
	call main.ck_gen_exok.hide

	call main.ck_asis.hide
	call main.ck_freq.hide
	call main.ck_exok.show
	call main.ck_exok.setposition . 180
	call main.ck_repl.hide
	call main.ck_clear.hide
	call main.ck_bypat.hide

	if isMI {
		call main.ck_exmiss.show
		call main.ck_exmiss.setposition . 205
		call main.sp_m.show
		call main.sp_m.setposition . 235
		call main.tx_m.show
		call main.tx_m.setposition . 235
	}
	else {
		call main.ck_exmiss.hide
		call main.sp_m.hide
		call main.tx_m.hide
	}
END

SCRIPT main_generate_on
BEGIN
	main.tx_generate.enable
	main.ed_generate.enable
	main.ck_gen_exok.enable
END

SCRIPT main_generate_off
BEGIN
	main.tx_generate.disable
	main.ed_generate.disable
	main.ck_gen_exok.disable
END

INCLUDE ifin

PROGRAM main_generate_output
BEGIN
	put main.ed_generate
	if main.ck_gen_exok {
		put ", "
		option main.ck_gen_exok
	}
END

PROGRAM command
BEGIN
	if isMI {
		put "mi "
	}
	put "misstable "
	option radio(main rb_summ rb_pat rb_tree rb_nested)
	varlist [main.vl_vars]
	put " " /program ifin_output
	beginoptions
		if main.ck_generate {
			require main.ed_generate
			put " generate("
			put /program main_generate_output
			put ")"
		}
		option main.ck_all
		option main.ck_zero
		option main.ck_asis
		option main.ck_freq
		option main.ck_exok
		option main.ck_repl
		option main.ck_clear
		option main.ck_bypat
		option main.ck_exmiss
		optionarg /hidedefault main.sp_m
	endoptions
END

