/*
  sg__text.dlg

*!  VERSION 1.0.2  21jul2011

*/

VERSION 12.0
MODAL

INCLUDE _std_msmall
DEFINE _dlght 360
INCLUDE header_sem_ed

DEFINE _clwd	15
DEFINE _wd	130
DEFINE _sep	+135
DEFINE _wd2	120
DEFINE _sep2	+125
DEFINE _cbwd	120
DEFINE _cbsep	+125

INCLUDE sg__common_output		/* routines necessary for output */

SCRIPT PREINIT
BEGIN
	script sg__common_output_init 	/* initialize output globals */

	create STRING OBJ
	program setupOBJECT

	create STRING sTemp
	create DOUBLE dTemp

END

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

SCRIPT text_PREINIT
BEGIN
	create STRING sText
	create STRING sXpos
	create STRING sYpos
	create STRING sSize
	create STRING sColor
	create STRING sFace
	create STRING sJust
	create STRING sAngle
	create BOOLEAN bBold
	create BOOLEAN bItalic
	create STRING sFormat
	
	text.ed_text.disable

	program text_get_defaults
END

SCRIPT text_POSTINIT
BEGIN
	program text_initialize_controls
END

PROGRAM text_get_defaults
BEGIN
	call sText.setvalue class .__SEMG.dbsettings.text
	call sText.withvalue text.ed_text.setdefault "@"

	call sXpos.setvalue class .__SEMG.dbsettings.x
	call sXpos.withvalue text.ed_xpos.setdefault "@"

	call sYpos.setvalue class .__SEMG.dbsettings.y
	call sYpos.withvalue text.ed_ypos.setdefault "@"

	call sSize.setvalue class .__SEMG.dbsettings.textstyle_size
	call sSize.withvalue text.cb_fsize.setdefault "@"

	call sColor.setvalue class .__SEMG.dbsettings.textstyle_color
	call sColor.withvalue text.cb_fcolor.setdefault "@"

	call sFace.setvalue class .__SEMG.dbsettings.textstyle_face
	call sFace.withvalue text.cb_fface.setdefault "@"
	
	call sJust.setvalue class .__SEMG.dbsettings.textstyle_justification
	call sJust.withvalue text.cb_just.setdefault "@"

	call sAngle.setvalue class .__SEMG.dbsettings.textstyle_angle
	call sAngle.withvalue text.cb_angle.setdefault "@"

	call sTemp.setvalue class .__SEMG.dbsettings.textstyle_bold
	if (sTemp.iseq("yes")) {
		call bBold.settrue
		call text.ck_bold.setdefault 1
	}
	else {
		call bBold.setfalse
		call text.ck_bold.setdefault 0
	}

	call sTemp.setvalue class .__SEMG.dbsettings.textstyle_italic
	if (sTemp.iseq("yes")) {
		call bItalic.settrue
		call text.ck_italic.setdefault 1
	}
	else {
		call bItalic.setfalse
		call text.ck_italic.setdefault 0
	}

	call sFormat.setvalue class .__SEMG.dbsettings.textstyle_fmt
	call sFormat.withvalue text.ed_fmt.setdefault "@"
END

PROGRAM text_initialize_controls
BEGIN
	call text.ed_text.setvalue class sText.value
	call text.ed_xpos.setvalue class sXpos.value
	call text.ed_ypos.setvalue class sYpos.value
	call text.cb_fsize.setvalue class sSize.value
	call text.cb_fcolor.setvalue class sColor.value
	call text.cb_fface.setvalue class sFace.value
	call text.cb_just.setvalue class sJust.value
	call text.cb_angle.setvalue class sAngle.value

	if (bBold) {
		call text.ck_bold.seton
	}
	else {
		call text.ck_bold.setoff
	}
	if (bItalic) {
		call text.ck_italic.seton
	}
	else {
		call text.ck_italic.setoff
	}
	
	call text.ed_fmt.setvalue class sFormat.value
END

PROGRAM edit_text
BEGIN
	put "_sedi showdialog " OBJ " sg__textedit"
	stata hidden
END

PROGRAM ON_DOTPROMPT
BEGIN
	call sText.setvalue class .__SEMG.dbsettings.text
	call sText.withvalue text.ed_text.setdefault "@"
	
	call text.ed_text.setvalue class sText.value
END

DIALOG text, label("Modify text") tabtitle("Text")
BEGIN
  EDIT     ed_text		_lft	_top	_lw100	., nomemory
  BUTTON   bu_edit		_rj100	@	100	.,		///
	label("Modify text...") onpush(program edit_text)
  GROUPBOX gb_pos		_lft	+30	_iwd	55,		///
	label("Position") 
  TEXT     tx_xpos		80	_ss	25	.,		///
	label("x:") right 
  EDIT     ed_xpos		+30	@	75	., nomemory
  TEXT     tx_ypos		+80	@	25	.,		///
	label("y:") right 
  EDIT     ed_ypos		+30	@	75	., nomemory

  GROUPBOX gb_appearance	_lft	+45	_iwd	_ht21,		///
	label("Appearance")

  TEXT     tx_fsize		_ilft	_ss	_wd	.,		///
	label("Size:") right
  COMBOBOX cb_fsize		_sep	@	80	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.pointsize)		///
	values(.__SEM_STYLES.pointsize)
  TEXT     tx_fsize_m		+85	@	50	.,		///
	label("( pt. )")

  TEXT     tx_fcolor		_ilft	_mls	_wd	.,		///
	label("Font color:") right
  COMBOBOX cb_fcolor		_sep	@	_cbwd	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.color)			///
	values(.__SEM_STYLES.color)

  TEXT     tx_fface		_ilft	_mls	_wd	.,		///
	label("Font face:") right
  COMBOBOX cb_fface		_sep	@	_cbwd	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.face)			///
	values(.__SEM_STYLES.face)

  TEXT     tx_just		_ilft	_mls	_wd	.,		///
	label("Justification:") right
  COMBOBOX cb_just		_sep	@	80	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.justification)		///
	values(.__SEM_STYLES.justification)

  TEXT     tx_angle		_ilft	_mls	_wd	.,		///
	label("Angle:") right
  COMBOBOX cb_angle		_sep	@	80	., nomemory	///
	dropdown contents(.__SEM_STYLES_LABEL.angle)			///
	values(.__SEM_STYLES.angle)
DEFINE x @x
  TEXT     tx_angle_m		+85	@	50	.,		///
	label("( deg. )")
	
  CHECKBOX ck_bold		x	_mls	60	., nomemory	///
	label("Bold") 
  CHECKBOX ck_italic		+65	@	_wd	., nomemory	///
	label("Italic") 

  FRAME    fr_fmt		_ilft	+30	_ibwd	1,

  TEXT     tx_fmt		_ilft	+15	195	.,		///
  	label("Format for numeric substitutions:") right
  EDIT     ed_fmt		+200	@	125	., nomemory	///
	option(format)
  BUTTON   bu_fmt		+130	@	20	.,		///
	label("...") onpush(script text_GetFormat)			///
	tooltip("Create display format")
END

SCRIPT text_GetFormat
BEGIN
	create STRING textFormat
	create CHILD format_chooser
	format_chooser.setExitString textFormat
	format_chooser.setExitAction "text.ed_fmt.setvalue class textFormat.value"
END

PROGRAM text_output
BEGIN
	call program text_get_defaults

	if ! text.ed_text.isdefault() {
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue class text.ed_text.value
		call sg__DESCPT.setvalue "edit text"
		put /program sg__do_output_sub
	}
	
	if ! text.ed_xpos.isdefault() {
		call dTemp.setvalue class text.ed_xpos.value
		call sTemp.setvalue class text.ed_xpos.value
		if (!dTemp & dTemp.isneq(0) & sTemp.isneq("<multiple>")) {
			stopbox stop ///
			`""x" contains a nonnumeric value."'
		}
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "pos[1]"
		call sg__ARG_01.setvalue class text.ed_xpos.value
		put /program sg__do_output_sub
	}

	if ! text.ed_ypos.isdefault() {
		call dTemp.setvalue class text.ed_ypos.value
		call sTemp.setvalue class text.ed_ypos.value
		if (!dTemp & dTemp.isneq(0) & sTemp.isneq("<multiple>")) {
			stopbox stop ///
			`""y" contains a nonnumeric value."'
		}
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "pos[2]"
		call sg__ARG_01.setvalue class text.ed_ypos.value
		put /program sg__do_output_sub
	}

	if ! text.cb_fsize.isdefault() {
		call dTemp.setvalue class text.cb_fsize.value
		call sTemp.setvalue class text.cb_fsize.value
		if (!dTemp & dTemp.isneq(0) & sTemp.isneq("<multiple>")) {
			stopbox stop ///
			`""Size" contains a nonnumeric value."'
		}
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.size"
		call sg__ARG_01.setvalue class text.cb_fsize.value
		call sg__DESCPT.setvalue "set font size"
		put /program sg__do_output_sub
	}

	if ! text.cb_fcolor.isdefault() {
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.color"
		call sg__ARG_01.setvalue class text.cb_fcolor.value
		put /program sg__do_output_sub
	}

	if ! text.cb_fface.isdefault() {
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.face"
		call sg__ARG_01.setvalue class text.cb_fface.value
		put /program sg__do_output_sub
	}

	if ! text.cb_just.isdefault() {
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.justification"
		call sg__ARG_01.setvalue class text.cb_just.value
		put /program sg__do_output_sub
	}

	if ! text.cb_angle.isdefault() {
		call dTemp.setvalue class text.cb_angle.value
		call sTemp.setvalue class text.cb_angle.value
		if (!dTemp & dTemp.isneq(0) & sTemp.isneq("<multiple>")) {
			stopbox stop ///
			`""Angle" contains a nonnumeric value."'
		}
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.angle"
		call sg__ARG_01.setvalue class text.cb_angle.value
		put /program sg__do_output_sub
	}

	if (!text.ck_bold.isdefault()) {
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.bold"
		if text.ck_bold {
			call sg__ARG_01.setvalue "yes"
		}
		else {
			call sg__ARG_01.setvalue "no"
		}
		put /program sg__do_output_sub
	}

	if (!text.ck_italic.isdefault()) {
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.italic"
		if text.ck_italic {
			call sg__ARG_01.setvalue "yes"
		}
		else {
			call sg__ARG_01.setvalue "no"
		}
		put /program sg__do_output_sub
	}

	if ! text.ed_fmt.isdefault() {
		call sg__PARAM2.setvalue "SetStyleSelected"
		call sg__ARG_00.setvalue "textstyle.fmt"
		call sg__ARG_01.setvalue class text.ed_fmt.value
		put /program sg__do_output_sub
	}
END

/*****************************************************************************/

PROGRAM command
BEGIN
	call sg__PARAM1.setvalue class OBJ.value
	
	call sg__PARAM2.setvalue "BeginSet"
	call sg__DESCPT.setvalue "change text settings"
	put /program sg__do_output_sub
	
	put /program text_output

	call sg__PARAM2.setvalue "EndSet"
	call sg__DESCPT.setvalue "change text settings"
	put /program sg__do_output_sub


	call sg__PARAM1.setvalue class OBJ.value
	call sg__PARAM2.setvalue "UpdateDlg"
	call sg__ARG_00.setvalue "text"
	put /program sg__do_output_sub

	call sg__PARAM1.setvalue class OBJ.value
	call sg__PARAM2.setvalue "Reselect"
	put /program sg__do_output_sub
END
