/*
    gr_diagonal_label_options.dlg
    
*!  VERSION 1.0.1  08feb2007

*/

VERSION 10.0

INCLUDE _std_small
DEFINE _dlght 360
INCLUDE header_gr_child

DEFINE _clwd 15

HELP hlp1, view("help graph_matrix")
RESET res1

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

SCRIPT PREINIT
BEGIN
	create STRING tmp
	create ARRAY  tmpArray
	create STRING main_marginResult
END

SCRIPT POSTINIT
BEGIN
	program main_checkMarginResult
END

DIALOG main, label("Diagonal label options (matrix plot)") tabtitle("Main")
BEGIN
  TEXT     tx_dsize	_ilft	20	_wd	.,		///
	label("Label size:") right
  COMBOBOX cb_dsize	_sep	@	_cbwd	.,		///
	dropdown						/// 
	option(size)						///
	contents(textsizes)

  TEXT     tx_dclr	_ilft	_mls	_wd	.,		///
	label("Label color:") right
  COMBOBOX cb_dclr	_sep	@	_cbwd	.,		///
	dropdownlist						///
	contents(colors)					/// 
	option(color)						///
	onselchangelist(main_cl_dclr_sel)
  COLOR    cl_dclr	_cbsep	@	_clwd	., option(color)
  
  TEXT     tx_dposit	_ilft	_mls	_wd	.,		///
	label("Label placement:") right
  COMBOBOX cb_dposit	_sep	@	_cbwd	.,		///
	dropdownlist						///
	option(placement)					///
	contents(compass)
  
  TEXT     tx_djust	_ilft	_mls	_wd	.,		///
	label("Label justification:") right
  COMBOBOX cb_djust	_sep	@	_cbwd	.,		///
	dropdownlist						/// 
	option(justification)					///
	contents(justification)

  TEXT     tx_dalign	_ilft	_mls	_wd	.,		///
	label("Label alignment:") right
  COMBOBOX cb_dalign	_sep	@	_cbwd	.,		///
	dropdownlist						///
	option(alignment)					///
	contents(alignment)
  
  TEXT     tx_dorient	_ilft	_mls	_wd	.,		///
	label("Label orientation:") right
  COMBOBOX cb_dorient	_sep	@	_cbwd	.,		///
	dropdownlist 						///
	option(orientation)					///
	contents(orientation) values(orientation_values)	

  CHECKBOX ck_dbox	_lft	+35	_iwd	_ht11,		///
	groupbox						///
	label("Draw box around label (default)")		///
	onclickon(program main_dbox_on)				/// 
	onclickoff(script main_dbox_off)			///
	default(1)
	
  TEXT     tx_dbclr	_ilft	_ss	_wd	.,		///
	label("Fill color:") right 
  COMBOBOX cb_dbclr	_sep	@	_cbwd	.,		///
	dropdownlist 						///
	option(fcolor)						///
	contents(colors) onselchangelist(main_cl_dbclr_sel)
  COLOR    cl_dbclr	_cbsep	@	_clwd 	.,option(fcolor)

  TEXT     tx_dblclr	_ilft	_mls	_wd	.,		///
	label("Line color:") right
  COMBOBOX cb_dblclr	_sep	@	_cbwd	.,		///
	dropdownlist						///
	option(lcolor)						///
	contents(colors) onselchangelist(main_cl_dblclr_sel)
  COLOR    cl_dblclr	_cbsep	@	_clwd	.,option(lcolor)

  TEXT     tx_dbmargin	_ilft	_mls	_wd	.,		///
	label("Margin:") right
  COMBOBOX cb_dbmargin	_sep	@	_cbwd	.,		///
	dropdownlist						///
	option(bmargin)						///
	contents(margin)					///
	onselchange(program main_cb_dbmargin_check)
  BUTTON   bu_dbmargin	_cbsep	@	_clwd	.,		///
	label("..") tooltip("Custom margin")			///
	onpush(script main_show_dbmargin_dialog)				

  CHECKBOX ck_dnoexpand	_ilft	_ls	_ibwd	.,		///
	label("Do not expand box") option(nobexpand)

END

INCLUDE gr_orientation

LIST main_cl_dclr_sel
BEGIN
	main.cl_dclr.hide
	main.cl_dclr.show
	main.cl_dclr.hide
END

LIST main_cl_dbclr_sel
BEGIN
	main.cl_dbclr.hide
	main.cl_dbclr.show
	main.cl_dbclr.hide
END

LIST main_cl_dblclr_sel
BEGIN
	main.cl_dblclr.hide
main.cl_dblclr.show
	main.cl_dblclr.hide
END

PROGRAM main_dbox_on
BEGIN
	call main.tx_dbclr.enable
	call main.cb_dbclr.enable
	call main.cl_dbclr.enable
	call main.tx_dblclr.enable
	call main.cb_dblclr.enable
	call main.cl_dblclr.enable
	call main.tx_dbmargin.enable
	call main.cb_dbmargin.enable
	call main.bu_dbmargin.enable
	call main.ck_dnoexpand.enable
END

SCRIPT main_dbox_off
BEGIN
	main.tx_dbclr.disable
	main.cb_dbclr.disable
	main.cl_dbclr.disable
	main.tx_dblclr.disable
	main.cb_dblclr.disable
	main.cl_dblclr.disable
	main.tx_dbmargin.disable
	main.cb_dbmargin.disable
	main.bu_dbmargin.disable
	main.ck_dnoexpand.disable
END

PROGRAM main_cb_dbmargin_check
BEGIN
	if main.cb_dbmargin.iseq("custom") {
		call main.bu_dbmargin.show
	}
	else {
		call main.bu_dbmargin.hide
	}
END

SCRIPT main_show_dbmargin_dialog
BEGIN
	create CHILD gr_margin_create AS main_dbmargin_dlg
	main_dbmargin_dlg.setExitString main_marginResult
	main_dbmargin_dlg.setExitAction "program main_checkMarginResult"
END	
PROGRAM main_checkMarginResult
BEGIN
	if main_marginResult {
		call main_marginResult.tokenize tmpArray
		call tmp.setvalue "Custom margin "
		call tmp.append "(Left:"
		call tmp.append class tmpArray[1]
		call tmp.append " Right:"
		call tmp.append class tmpArray[2]
		call tmp.append " Bottom:"
		call tmp.append class tmpArray[3]
		call tmp.append " Top:"
		call tmp.append class tmpArray[4]
		call tmp.append ")"
		call tmp.withvalue main.bu_dbmargin.settooltip "@"
	}
	else {
		call main.bu_dbmargin.settooltip "Custom margin (not defined)"
	}
END

PROGRAM main_diaglab_opt
BEGIN
	beginoptions
		optionarg /hidedefault main.cb_dsize
		if !Hcc(main.cb_dclr) {
			optionarg /hidedefault main.cb_dclr
		}
		if Hcc(main.cb_dclr) {
			optionarg /quoted main.cl_dclr
		}
      		optionarg /hidedefault main.cb_dposit
      		optionarg /hidedefault main.cb_dorient
		optionarg /hidedefault main.cb_djust
      		optionarg /hidedefault main.cb_dalign
      		if !main.ck_dbox {
			put " nobox "
		}
		if main.ck_dbox {
			if !Hcc(main.cb_dbclr) {
				optionarg /hidedefault main.cb_dbclr
			}
        		if Hcc(main.cb_dbclr) {
				optionarg /quoted main.cl_dbclr
			}
			if !Hcc(main.cb_dblclr) {
				optionarg /hidedefault main.cb_dblclr
			}
			if Hcc(main.cb_dblclr) {
				optionarg /quoted main.cl_dblclr
			}
         		
			if main.cb_dbmargin.isneq("custom") {
				optionarg /hidedefault main.cb_dbmargin
			}
			else {
				if main_marginResult {
					put " bmargin("
					put main_marginResult
					put ") "
				}
			}
	 		option main.ck_dnoexpand
		}
	endoptions
END

PROGRAM command
BEGIN
/* Diagonal labels */
   	if 	  main.cb_dsize 	| main.cb_dclr	 	///
		| Hcc(main.cb_dclr)	| main.cb_dposit 	///
		| main.cb_dorient	| main.cb_djust 	///
		| main.cb_dalign	| main.cb_dbclr 	///
		| Hcc(main.cb_dbclr)	| main.cb_dblclr 	///
		| main.cb_dbmargin	| main.ck_dnoexpand	///
		| !main.ck_dbox 				///
	{
		put /program main_diaglab_opt
	}
END

