/*
    gr_titles.idlg

*!  VERSION 1.0.2  23apr2007
    	
	// SCRIPTS and PROGRAMS for external use
	   * SCRIPT gr_titles_setByNote
	   * SCRIPT gr_titles_disable
	   * SCRIPT gr_titles_enable
	   * SCRIPT gr_titles_setLegend_on
	   * SCRIPT gr_titles_setByoptsContext_on
	   * SCRIPT gr_titles_setByoptsContext_off
	   * SCRIPT gr_titles_setByContext_on
	   * SCRIPT gr_titles_setByContext_off
	   * SCRIPT gr_titles_setByOutput_on	
	   	// Same as gr_titles_setByContext_on but does not show the button
	   	//   for subgraph options
	   * SCRIPT gr_titles_setByOutput_off
	   	// Same as gr_titles_setByContext_off but does not hide the button
	   	//   for subgraph options. (it should already be off)
	   
*/

SCRIPT gr_titles_setByNote
BEGIN
	titles.tx_note1.setlabel `"Note: the "Titles" tab on the main dialog can be used to affect the"'
	titles.tx_note2.setlabel `"titles of the individual graphs."'
	titles.tx_note1.show
	titles.tx_note2.show
END

SCRIPT gr_titles_setByoptsContext_on
BEGIN
	titles_isByoptsContext.settrue
	titles.bu_stitle_with_by.show
END
SCRIPT gr_titles_setByoptsContext_off
BEGIN
	titles_isByoptsContext.setfalse
	titles.bu_stitle_with_by.hide
END

SCRIPT gr_titles_setByContext_on
BEGIN
	titles_isByContext.settrue
	titles.bu_stitle_with_by.show
END
SCRIPT gr_titles_setByContext_off
BEGIN
	titles_isByContext.setfalse
	titles.bu_stitle_with_by.hide
END

SCRIPT gr_titles_setByOutput_on
BEGIN
	titles_isByContext.settrue
END
SCRIPT gr_titles_setByOutput_off
BEGIN
	titles_isByContext.setfalse
END

SCRIPT gr_titles_setLegend_on
BEGIN
	titles_isLegendTitle.settrue
END

SCRIPT gr_titles_disable
BEGIN
	titles.tx_title.disable
	titles.ed_title.disable
	titles.bu_title.disable
	titles.tx_stitle.disable
	titles.ed_stitle.disable
	titles.bu_stitle.disable
	titles.tx_caption.disable
	titles.ed_caption.disable
	titles.bu_caption.disable
	titles.tx_note.disable
	titles.ed_note.disable
	titles.bu_note.disable
	titles.tx_note1.disable
	titles.tx_note2.disable
	titles.bu_stitle_with_by.disable
END

SCRIPT gr_titles_enable
BEGIN
	titles.tx_title.enable
	titles.ed_title.enable
	titles.bu_title.enable
	titles.tx_stitle.enable
	titles.ed_stitle.enable
	titles.bu_stitle.enable
	titles.tx_caption.enable
	titles.ed_caption.enable
	titles.bu_caption.enable
	titles.tx_note.enable
	titles.ed_note.enable
	titles.bu_note.enable
	titles.tx_note1.enable
	titles.tx_note2.enable
	titles.bu_stitle_with_by.enable
END

SCRIPT titles_PREINIT
BEGIN
	create BOOLEAN titles_isLegendTitle
	create STRING titleResults
	create STRING stitleResults
	create STRING captionResults
	create STRING noteResults
	create STRING stitleByResults
	create BOOLEAN titles_isByContext
	create BOOLEAN titles_isByoptsContext
	create BOOLEAN _gr_titles_hasOutput
	titles.tx_note1.hide
	titles.tx_note2.hide
	titles.bu_stitle_with_by.hide
END
SCRIPT titles_POSTINIT
BEGIN
	program title_checkTitleResults
	program stitle_checkTitleResults
	program caption_checkTitleResults
	program note_checkTitleResults
	program stitle_by_checkTitleResults
END

DIALOG titles, tabtitle("Titles")
BEGIN
  TEXT     tx_title	_lft	_top	_lw80	.,	///
	label("Title:")
  EDIT	   ed_title	@	_ss	@	.,
  BUTTON   bu_title	_slw80	@	80	.,	///
	label("Properties")				///
	onpush(program get_title_options)		///
	tooltip("Title properties")
  	
  TEXT     tx_stitle	_lft	_ls	_lw80	.,	///
	label("Subtitle:")
  EDIT	   ed_stitle	@	_ss	@	.,
  BUTTON   bu_stitle	_slw80	@	80	.,	///
	label("Properties")				///
	onpush(program get_stitle_options)		///
	tooltip("Subtitle properties")
  	
  TEXT     tx_caption	_lft	_ls	_lw80	.,	///
	label("Caption:")
  EDIT	   ed_caption	@	_ss	@	.,
  BUTTON   bu_caption	_slw80	@	80	.,	///
	label("Properties")				///
	onpush(program get_caption_options)		///
	tooltip("Caption properties")
  	
  TEXT     tx_note	_lft	_ls	_lw80	.,	///
	label("Note:")
  EDIT	   ed_note	@	_ss	@	.,
  BUTTON   bu_note	_slw80	@	80	.,	///
	label("Properties")				///
	onpush(program get_note_options)		///
	tooltip("Note properties")

  BUTTON   bu_stitle_with_by _lft +35	150	.,	///
	label("Subgraph title properties ")		///
	onpush(program get_stitle_by_options)		///
	tooltip("Properties that affect the title of each subgraph")
  TEXT     tx_note1	_lft	@	_iwd	.,
  TEXT     tx_note2	@	+15	@	.,
END

PROGRAM get_title_options
BEGIN
	call create CHILD gr_title_options AS title, allowsubmit
	call title.setExitString titleResults
	call title.settitle "Title properties"
	call title.setExitAction "program title_checkTitleResults"
	call title.setSubmitAction "program title_titleSubmit"
	if titles_isLegendTitle {
		call title.callthru "script gr_title_options_setLegend_on"
	}
END
PROGRAM title_checkTitleResults
BEGIN
	if titleResults.iseq("") {
		call titles.bu_title.setlabel "Properties  "
	}
	if ! titleResults.iseq("") {
		call titles.bu_title.setlabel "Properties *"
	}
END
PROGRAM title_titleSubmit
BEGIN
	call program title_checkTitleResults
	call Submit
END

PROGRAM get_stitle_options
BEGIN
	call create CHILD gr_title_options AS stitle, allowsubmit
	call stitle.setExitString stitleResults
	call stitle.settitle "Subtitle properties"
	call stitle.setExitAction "program stitle_checkTitleResults"
	call stitle.setSubmitAction "program stitle_titleSubmit"
	if titles_isLegendTitle {
		call stitle.callthru "script gr_title_options_setLegend_on"
	}
END
PROGRAM stitle_checkTitleResults
BEGIN
	if stitleResults.iseq("") {
		call titles.bu_stitle.setlabel "Properties  "
	}
	if ! stitleResults.iseq("") {
		call titles.bu_stitle.setlabel "Properties *"
	}
END
PROGRAM stitle_titleSubmit
BEGIN
	call program stitle_checkTitleResults
	call Submit
END

PROGRAM get_caption_options
BEGIN
	call create CHILD gr_title_options AS caption, allowsubmit
	call caption.setExitString captionResults
	call caption.settitle "Caption properties"
	call caption.setExitAction "program caption_checkTitleResults"
	call caption.setSubmitAction "program caption_titleSubmit"
	if titles_isLegendTitle {
		call caption.callthru "script gr_title_options_setLegend_on"
	}
END
PROGRAM caption_checkTitleResults
BEGIN
	if captionResults.iseq("") {
		call titles.bu_caption.setlabel "Properties  "
	}
	if ! captionResults.iseq("") {
		call titles.bu_caption.setlabel "Properties *"
	}
END
PROGRAM caption_titleSubmit
BEGIN
	call program caption_checkTitleResults
	call Submit
END

PROGRAM get_note_options
BEGIN
	call create CHILD gr_title_options AS note, allowsubmit
	call note.setExitString noteResults
	call note.settitle "Note properties"
	call note.setExitAction "program note_checkTitleResults"
	call note.setSubmitAction "program note_titleSubmit"
	if titles_isLegendTitle {
		call note.callthru "script gr_title_options_setLegend_on"
	}
END
PROGRAM note_checkTitleResults
BEGIN
	if noteResults.iseq("") {
		call titles.bu_note.setlabel "Properties  "
	}
	if ! noteResults.iseq("") {
		call titles.bu_note.setlabel "Properties *"
	}
END
PROGRAM note_titleSubmit
BEGIN
	call program note_checkTitleResults
	call Submit
END

PROGRAM get_stitle_by_options
BEGIN
	call create CHILD gr_title_options AS stitle_by, allowsubmit
	call stitle_by.setExitString stitleByResults
	call stitle_by.settitle "Subgraph title properties"
	call stitle_by.setExitAction "program stitle_by_checkTitleResults"
	call stitle_by.setSubmitAction "program stitle_by_titleSubmit"
END
PROGRAM stitle_by_checkTitleResults
BEGIN
	if stitleByResults.iseq("") {
		call titles.bu_stitle_with_by.setlabel "Subgraph title properties  "
	}
	if ! stitleByResults.iseq("") {
		call titles.bu_stitle_with_by.setlabel "Subgraph title properties *"
	}
END
PROGRAM stitle_by_titleSubmit
BEGIN
	call program stitle_by_checkTitleResults
	call Submit
END

PROGRAM title_output_work
BEGIN
	put titles.ed_title
	beginoptions
		put titleResults
	endoptions
END
PROGRAM stitle_output_work
BEGIN
	put titles.ed_stitle
	beginoptions
		put stitleResults
	endoptions
END
PROGRAM caption_output_work
BEGIN
	put titles.ed_caption
	beginoptions
		put captionResults
	endoptions
END
PROGRAM note_output_work
BEGIN
	put titles.ed_note
	beginoptions
		put noteResults
	endoptions
END
PROGRAM stitle_by_output_work
BEGIN
	beginoptions
		put stitleByResults
	endoptions
END

PROGRAM gr_titles_output_wrk
BEGIN
	if ((titles.ed_title & titles.ed_title.isenabled()) 	///
		| (titleResults.isneq("") & ! H(titles.bu_title))) {
		put " title("
		put /program title_output_work
		put ") "
		call _gr_titles_hasOutput.settrue
	}
	if ((titles.ed_stitle & titles.ed_stitle.isenabled()) 	///
		| (stitleResults.isneq("") & ! H(titles.bu_stitle))) {
		put " subtitle("
		put /program stitle_output_work
		put ") "
		call _gr_titles_hasOutput.settrue
	}
	if ((titles.ed_caption & titles.ed_caption.isenabled())	///
		| (captionResults.isneq("") & ! H(titles.bu_caption))) {
		put " caption("
		put /program caption_output_work
		put ") "
		call _gr_titles_hasOutput.settrue
	}
	if ((titles.ed_note & titles.ed_note.isenabled())	///
		| (noteResults.isneq("") & ! H(titles.bu_note))) {
		put " note("
		put /program note_output_work
		put ") "
		call _gr_titles_hasOutput.settrue
	}
END

PROGRAM gr_titles_output
BEGIN
	// check for output
	call _gr_titles_hasOutput.setfalse
	call program gr_titles_output_wrk
	
	if _gr_titles_hasOutput {
		if titles_isByoptsContext | titles_isByContext {
			if titles_isByoptsContext {
				put " byopts("
			}
			else {
				put " by(, "
			}
			put /program gr_titles_output_wrk
			put ") "
		}
		else {
			put /program gr_titles_output_wrk
		}
	}
	if stitleByResults & ! H(titles.bu_stitle_with_by) {
		put " subtitle("
		put /program stitle_by_output_work
		put ") "
	}
END
