;mtest17
 $f3='-adobe-courier-bold-r-normal--12*'
 $f4='-adobe-helvetica-bold-r-normal--14*'
 $help_path = getenv('ANA_HELP') + '/'

subr help_tog
 ;4 cases, each calls a selection box
 $help_top = $option_value
 ty,'$help_top =', $help_top
 ncase $option_value
 { load_help_from_file, $help_path+'/instructions.ana_command'
 }
   help_list,0, 'built in subroutines'
   help_list,1, 'built in functions'
 { load_help_from_file, $help_path+'/instructions.sorry'
 }
 { load_help_from_file, $help_path+'/instructions.sorry'
 }
 {
 ;here we try to dismiss all the help widgets
 dismiss_ana_help
 }
 endcase

 endsubr
 ;===============================================================================
subr dismiss_ana_help
 if defined($ana_help_widget) eq 1 then xtunmanage, $ana_help_widget
 if defined($ana_help_widget2) eq 1 then xtunmanage, $ana_help_widget2
 endsubr
 ;===============================================================================
subr help_list, mode, help_topic
 if defined($ana_help_widget) eq 0 then {
 $ana_help_widget = xmdialog_form(0,0,0, 'Help Keywords')
 $ana_help_label = xmlabel($ana_help_widget, help_topic, $f4)
 $ana_help_list = xmlist($ana_help_widget, 'help_list_cb', 20, $f3, 'white')
 formvstack, $ana_help_label, xtparent($ana_help_list)
 xmattach, xtparent($ana_help_list), 0,   1,1,0,1
 } else xtunmanage, $ana_help_widget
 ;that defines the widget if it wasn't already, now fill it with
 ;requested information
 xmsetlabel, $ana_help_label, help_topic
 xmlistdeleteall, $ana_help_list
 if mode eq 0 then xmlistsubr, $ana_help_list else xmlistfunc, $ana_help_list
 xmlistselect, $ana_help_list, 1, 0
 xtmanage, $ana_help_widget
 xmposition, $ana_help_widget, 500, 400
 endsubr
 ;===============================================================================
subr load_help_from_file, name
 help_widget2	;checks if defined
 xmtexterase, $ana_help_text
 lun = get_lun()
 openr, lun, name
 s=''
 nlines = 0
 while readf(lun, s) eq 1 do { xmtextappend, $ana_help_text, s, 1  nlines+=1 }
 close, lun
 xmtextsetrowcolumnsize, $ana_help_text, nlines<30, 80
 xmtextsetposition, $ana_help_text, 0
 xtmanage, $ana_help_widget2	;just in case
 endsubr
 ;===============================================================================
subr help_widget2
 if defined($ana_help_widget2) eq 0 then {
 $ana_help_widget2 = xmdialog_form(0,0,0, 'Help Text')
 $ana_help_text = xmtext($ana_help_widget2, 6, 80, $f3,'white')
 xmattach, xtparent($ana_help_text), 0,   1,1,1,1
 xtmanage, $ana_help_widget2
 xmposition, $ana_help_widget2, 500, 500
 }
 endsubr
 ;===============================================================================
subr help_list_cb
 help_widget2	;checks if defined
 text=upper($list_item
 k = strpos(text, ' ')
 if k gt 0 then text=text(0:(k-1))

 ;ty,'choosen item = ', text
 lun = get_lun()
 openr, lun, $help_path+'/ana_subroutines.txt.desc'
 ;we read the file, checking header lines for a match to "text"
 s=''
 found_match = 0
 xmtexterase, $ana_help_text
 nlines = 1
 while readf(lun, s) eq 1 do {
  if num_elem(s) ge 1 then {
  c=s(0)
  if c ne  ' ' and c ne '*' and c ne '.' then {
  ;have a header, check for a match
  ;ty,'header: ', s
  sq = upper(s)
  k = strpos(sq, '(')  if k gt 0 then sq = sq(0:(k-1))
  k = strpos(sq, ',')  if k gt 0 then sq = sq(0:(k-1))
  if strpos(sq, text) eq 0 then {
  ;ty,'found a match'
  found_match = 1
  ;got a match, now get the header plus text and put in a text widget
  xmtextappend, $ana_help_text, s, 1
  flag = 1
  repeat {
  readf, lun, s
  c = s(0)
  if c eq ' ' or c eq '.' then {
  xmtextappend, $ana_help_text, s, 1
  nlines += 1
  } else flag = 0
  } until flag eq 0
  break
  }
  } }
 }
 ;did we actually find a match?
 if found_match eq 0 then {
 s='Nothing seems to be available on this topic.'
 nlines = 2
 xmtextappend, $ana_help_text, s, 1
 }
 xmtextsetrowcolumnsize, $ana_help_text, nlines<30, 80
 xmtextsetposition, $ana_help_text, 0
 xtmanage, $ana_help_widget2	;just in case
 close, lun
 endsubr
 ;=========================================================
subr ana_dismiss_cb
 ;dismiss the command widget and all the help widgets
 dismiss_ana_help
 if defined($ana_command_widget) eq 1 then xtunmanage, $ana_command_widget
 endsubr
 ;=========================================================
subr echo_check_cb
 !motif_echo = xmtogglegetstate($echo_check(1))
 endsubr
 ;=========================================================
func ana_command_widget(dummy)
 if defined($ana_command_widget) eq 0 then {

 ;the compile_file is supposed to operate at top level and hence the edb's
 ;are temporary and don't add to our accumulation
 compile_file, getenv('ANA_WLIB') + '/commandwidgettool.ana'

 }
 return, $ana_command_widget
 endfunc
 ;=========================================================
;main
 ;$ana_command_widget = ana_command_widget()
 ;xtmanage, b1
 ;xmposition, b1, 500, 500
 ;xtloop
 
