!
! Test LIST2 Flashing Badly (Bug 1339)
!
! Author:  J. Helton
! Version: $Id: test_list2_flashing.mm,v 1.2 2009/05/26 21:56:07 jwb Exp $
!

startmacro
  switch DEBUG dbg GET DEF=FALSE  SDEF=TRUE
  env get pid mpid
  env get user muser
  env get home mhome
  
  fname statfile HOME statmon_^{muser}_^{mpid} tmp aux
  
  set s:name "xxx"
  timex now d:dtim
  set d:arch 1.0
  set i:ffts 1k
  set i:favg 2
  set i:sel 1
  set i:sel2 1
  set i:stat 100k
  
  file open/d/n ctag ^statfile{sr=(name/2a,dtim/sd,arch/sd,ffts/si,favg/si,sel/si,sel2/si,stat/si)}
  file close ctag
  
  call initStatFile
  
  pipe init
  
    panel/setup/controls=gc
    
    list2/msgid=MAIN/id=listid/poll=2/base=0/nice/legacy ^statfile AUTOSELECT=FALSE
    set reg.panel.panes.listid.title "(U) list2 flashing test"
    
    gcontrol label lblExit "Exit"
    gcontrol button btn_exit "" "Exit" /state /nc=1
    
    invoke ,, this.setTimers(1)
    set this.timer(0,1.0)
    
  pipe run
  pipe wait
  pipe off
  
endmacro

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
procedure processMessage m:msg

  if msg.name eqs "TIMER" then
    if ^msg.info eq 0 then
      call updateStatus
    endif
  elseif msg.name eqs "BTN_EXIT" then
    stop
  endif
  
return

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
procedure updateStatus

  if (dbg) then say "*************UpdateStatus***************"
  file open/d/w cttag ^statfile
  
    calc/quiet d:ffts ^ffts 1k +
    calc/quiet i:favg ^favg 1 +
    calc/quiet i:sel ^sel 1 +
    
    if name eqs "xxx" then
      set s:name "yyy"
    else
      set s:name "xxx"
    endif
    
    if ffts gt 100k then
      res d:ffts 1k
    endif
    
    if favg gt 200 then
      res i:favg 2
    endif
    
    if sel gt 100 then
      res i:sel 1
      res i:sel2 1
    endif
    
    do count 0 11 1
    
      timex now d:dtim
      table updatetab create {name="^name",dtim=^dtim,ffts=^ffts,favg=^favg,sel=^sel,sel2=^sel2,stat=^stat}
      if (dbg) then res updatetab
      invoke ,, cttag.setData(^count,^updatetab)
      
    enddo
    
  file close cttag
    
return
    
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
procedure initStatFile

  file open/d/w cttag ^statfile
  
  do count 0 11 1
  
    timex now d:timeNow
    
    table inittab create {NAME="INIT",DTIM=^timeNow,ARCH="-1.0",FFTS="16384",FAVG="10",SEL="0",SEL2="0",STAT="1"}
    invoke ,, cttag.setData(^count,^{inittab})
    
  enddo
  
  file close cttag
  
return