/*
  gr_ed_refine.dlg

*!  VERSION 1.0.0  05dec2006

*/

VERSION 10.0
MODAL

INCLUDE _std_vsmall
DEFINE _dlght 250
INCLUDE header_gr_ed

DEFINE _clwd	15
DEFINE _wd	110
DEFINE _sep	+115
DEFINE _cbwd	130
DEFINE _cbsep	+135

SCRIPT PREINIT
BEGIN
	create STRING G
	program setupGOBJECT

	create DOUBLE axisvalue
	create STRING color
	create STRING rgb
	create STRING width
	create STRING pattern
	create DOUBLE extendlow
	create DOUBLE extendhigh
	create DOUBLE drawview

	create DOUBLE index
	create STRING tmp

	program get_defaults
END

SCRIPT POSTINIT
BEGIN
	program initialize_controls
END

PROGRAM setupGOBJECT
BEGIN
	if ! __MESSAGE {
		stopbox stop 	///
			"An unexpected error has occurred." "Object not found."
		exit 198
	}
	call G.setvalue class __MESSAGE.value
END

DIALOG main, title("Reference line properties") tabtitle("Main")
BEGIN
  GROUPBOX gb_prop	_lft	_top	_iwd	_ht16,		///
	label("Reference line properties")
  TEXT     tx_value	_ilft	_ss	_wd	.,		///
	label("Value:") right
  EDIT     ed_value	_sep	@	_cbwd	.,		///
	numonly

  TEXT     tx_clr	_ilft	_mls	_wd	.,		///
	label("Color:") right
  COMBOBOX cb_clr	_sep	@	_cbwd	.,		///
	dropdownlist contents(_colors) 				///
	onselchangelist(main_cl_clr_sel)
  COLOR    cl_clr	_cbsep	@	_clwd	.,

  TEXT     tx_width	_ilft	_mls	_wd	.,		///
	label("Width:") right
  COMBOBOX cb_width	_sep	@	_cbwd	.,		///
	dropdown 						///
	contents(_linewidths)

  TEXT     tx_pattern	_ilft	_mls	_wd	.,		///
	label("Pattern:") right
  COMBOBOX cb_pattern	_sep	@	_cbwd	.,		///
	dropdownlist						///
	contents(_linepatterns)

  CHECKBOX ck_low	@	_ls	@	.,		///
	label("Extend low")
  CHECKBOX ck_high	@	+22	@	.,		///
	label("Extend high")

  CHECKBOX ck_hide	_lft	+45	_iwd	.,		///
	label("Hide reference line")
END

LIST main_cl_clr_sel
BEGIN
	main.cl_clr.show
	main.cl_clr.hide
END

PROGRAM get_defaults
BEGIN
	call G.withvalue axisvalue.setvalue class @.z
	call main.ed_value.setdefault class axisvalue.value

	call G.withvalue index.setvalue class @.style.linestyle.color.styledex
	call index.withvalue color.setstring class .__STYLES.color[@]
	call main.cb_clr.setdefault class color.value
	
	call G.withvalue rgb.setstring class @.style.linestyle.color.rgb
	call main.cl_clr.setdefault class rgb.value

	call G.withvalue index.setvalue class @.style.linestyle.width.styledex
	call index.withvalue width.setstring class .__STYLES.linewidth[@]
	if ! width {
		call G.withvalue width.setvalue class @.style.linestyle.width.val
	}
	call main.cb_width.setdefault class width.value

	call G.withvalue index.setvalue class @.style.linestyle.pattern.styledex
	call index.withvalue pattern.setstring class .__STYLES.linepattern[@]
	call main.cb_pattern.setdefault class pattern.value

	call G.withvalue extendlow.setvalue class @.style.extend_low.istrue
	if extendlow {
		call main.ck_low.setdefault 1
	}
	else {
		call main.ck_low.setdefault 0
	}
	
	call G.withvalue extendhigh.setvalue class @.style.extend_high.istrue
	if extendhigh {
		call main.ck_high.setdefault 1
	}
	else {
		call main.ck_high.setdefault 0
	}

	call G.withvalue drawview.setvalue class @.draw_view.istrue
	if drawview {
		call main.ck_hide.setdefault 0
	}
	else {
		call main.ck_hide.setdefault 1
	}
END

PROGRAM initialize_controls
BEGIN
	call main.ed_value.setvalue class axisvalue.value

	if color {
		call main.cb_clr.setvalue class color.value
	}
	if ! color {
		call main.cb_clr.setvalue "custom"
	}
	call main.cl_clr.setvalue class rgb.value

	call main.cb_width.setvalue class width.value
	call main.cb_pattern.setvalue class pattern.value

	if extendlow {
		call main.ck_low.seton
	}
	else {
		call main.ck_low.setoff
	}

	if extendhigh {
		call main.ck_high.seton
	}
	else {
		call main.ck_high.setoff
	}

	if drawview {
		call main.ck_hide.setoff
	}
	else {
		call main.ck_hide.seton
	}
END

PROGRAM command
BEGIN
	call program get_defaults
	put "_gm_dlg_edits"
	beginoptions
		put " object(" G ") "
		if ! main.ed_value.isdefault() {
			put "set(z " main.ed_value ") "
		}
		if ! main.cl_clr.isvisible() & ! main.cb_clr.isdefault() {
			put "style(linestyle(color(" 
			put main.cb_clr 
			put "))) "
		}
		if main.cl_clr.isvisible() & ! main.cl_clr.isdefault() {
			put "style(linestyle(color("   `"""'
			put main.cl_clr
			put `"""'
			put "))) "
		}
		if ! main.cb_width.isdefault() {
			put "style(linestyle(width("
			put main.cb_width
			put "))) "
		}
		if ! main.cb_pattern.isdefault() {
			put "style(linestyle(pattern("
			put main.cb_pattern
			put "))) "
		}
		if ! main.ck_low.isdefault() {
			if main.ck_low {
				put "style(extend_low("
				put "yes"
				put ")) "
			}
			else {
				put "style(extend_low("
				put "no"
				put ")) "
			}
		}
		if ! main.ck_high.isdefault() {
			if main.ck_high {
				put "style(extend_high("
				put "yes"
				put ")) "
			}
			else {
				put "style(extend_high("
				put "no"
				put ")) "
			}
		}
		if ! main.ck_hide.isdefault() {
			if main.ck_hide {
				put "set(draw_view no) "
			}
			else {
				put "set(draw_view yes) "
			}
		}
		put " epilog(_gedi toolbar refline " G ")"
	endoptions
	stata hidden queue
END
