/*
  gr_ed__titles.idlg

*!  VERSION 1.0.0  11dec2006

*/

SCRIPT titles_PREINIT
BEGIN
	create STRING child__MESSAGE
	create STRING unused

	create STRING title_text
	create STRING stitle_text
	create STRING caption_text
	create STRING note_text
	program get_title_defaults
END

SCRIPT titles_POSTINIT
BEGIN
	program initialize_titles
END

DIALOG titles, tabtitle("Titles")
BEGIN
  TEXT     tx_title	_lft	_top	_iwd	.,		///
	label("Title:")
  EDIT     ed_title	@	_ss	_lw80	.
  BUTTON   bu_title	_rj80	@	80	.,		///
	label("Properties") onpush(script show_title_dialog)

  TEXT     tx_stitle	_lft	_ls	_iwd	.,		///
	label("Subtitle:")
  EDIT     ed_stitle	@	_ss	_lw80	.
  BUTTON   bu_stitle	_rj80	@	80	.,		///
	label("Properties") onpush(script show_stitle_dialog)

  TEXT     tx_caption	_lft	_ls	_iwd	.,		///
	label("Caption:")
  EDIT     ed_caption	@	_ss	_lw80	.
  BUTTON   bu_caption	_rj80	@	80	.,		///
	label("Properties") onpush(script show_caption_dialog)

  TEXT     tx_note	_lft	_ls	_iwd	.,		///
	label("Note:")
  EDIT     ed_note	@	_ss	_lw80	.
  BUTTON   bu_note	_rj80	@	80	.,		///
	label("Properties") onpush(script show_note_dialog)
END

SCRIPT show_title_dialog
BEGIN
	child__MESSAGE.setvalue class G.value
	child__MESSAGE.append ".title"
	create CHILD gr_ed_textbox AS title_dialog, allowsubmit
	title_dialog.settitle "Title properties"
	title_dialog.setExitAction "script show_title_defaults"
	title_dialog.setExitString unused
END
SCRIPT show_stitle_dialog
BEGIN
	child__MESSAGE.setvalue class G.value
	child__MESSAGE.append ".subtitle"
	create CHILD gr_ed_textbox AS stitle_dialog, allowsubmit
	stitle_dialog.settitle "Subtitle properties"
	stitle_dialog.setExitAction "script show_title_defaults"
	stitle_dialog.setExitString unused
END
SCRIPT show_caption_dialog
BEGIN
	child__MESSAGE.setvalue class G.value
	child__MESSAGE.append ".caption"
	create CHILD gr_ed_textbox AS caption_dialog, allowsubmit
	caption_dialog.settitle "Caption properties"
	caption_dialog.setExitAction "script show_title_defaults"
	caption_dialog.setExitString unused
END
SCRIPT show_note_dialog
BEGIN
	child__MESSAGE.setvalue class G.value
	child__MESSAGE.append ".note"
	create CHILD gr_ed_textbox AS note_dialog, allowsubmit
	note_dialog.settitle "Note properties"
	note_dialog.setExitAction "script show_title_defaults"
	note_dialog.setExitString unused
END

SCRIPT show_title_defaults
BEGIN
	program get_title_defaults
	program initialize_titles
END

PROGRAM get_title_defaults
BEGIN
	call G.withvalue title_text.storeClsArrayToQuotedStr @.title.text
	call title_text.withvalue titles.ed_title.setdefault `"@"'

	call G.withvalue stitle_text.storeClsArrayToQuotedStr @.subtitle.text
	call stitle_text.withvalue titles.ed_stitle.setdefault `"@"'

	call G.withvalue caption_text.storeClsArrayToQuotedStr @.caption.text
	call caption_text.withvalue titles.ed_caption.setdefault `"@"'

	call G.withvalue note_text.storeClsArrayToQuotedStr @.note.text
	call note_text.withvalue titles.ed_note.setdefault `"@"'
END

PROGRAM initialize_titles
BEGIN
	call title_text.withvalue titles.ed_title.setvalue `"@"'
	call stitle_text.withvalue titles.ed_stitle.setvalue `"@"'
	call caption_text.withvalue titles.ed_caption.setvalue `"@"'
	call note_text.withvalue titles.ed_note.setvalue `"@"'
END

PROGRAM titles_trimTitle
BEGIN
	put titles.ed_title
END

PROGRAM titles_trimStitle
BEGIN
	put titles.ed_stitle
END

PROGRAM titles_trimCaption
BEGIN
	put titles.ed_caption
END

PROGRAM titles_trimNote
BEGIN
	put titles.ed_note
END	

PROGRAM titles_output
BEGIN
	call program get_title_defaults
	if ! titles.ed_title.isdefault() {
		put "_gm_dlg_edits"
		beginoptions
			put " object(" G ".title) "
			put "setstrarray(text "
			put /program titles_trimTitle
			put ")  nodraw "
		endoptions
		stata hidden queue
	}
	if ! titles.ed_stitle.isdefault() {
		put "_gm_dlg_edits"
		beginoptions
			put " object(" G ".subtitle) "
			put "setstrarray(text "
			put /program titles_trimStitle
			put ")  nodraw "
		endoptions
		stata hidden queue
	}
	if ! titles.ed_caption.isdefault() {
		put "_gm_dlg_edits"
		beginoptions
			put " object(" G ".caption) "
			put "setstrarray(text "
			put /program titles_trimCaption
			put ")  nodraw "
		endoptions
		stata hidden queue
	}
	if ! titles.ed_note.isdefault() {
		put "_gm_dlg_edits"
		beginoptions
			put " object(" G ".note) "
			put "setstrarray(text "
			put /program titles_trimNote
			put ")  nodraw "
		endoptions
		stata hidden queue
	}
END
