!
!  Macro for testing the capabilities of the Messagelog primitive
!
!  @author: William Conway
!  @author: Jay Hallam
!
!
startmacro

  switch INTERACTIVE   interAct     GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  
  if interAct then

    res instructions "Select info, warning and error messages in OPTIONS.  &
                      Verify a line of the correct color is added to the message log &
                      each time you click."

    pipe init
    panel/msgid=main/setup/controls=gc
    fname label=logFile area=^{AUX.WRITE} name="temp_test_messagelog" ext="log" OPT="AUX"

    gcontrol label macro "MACRO"
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}

    gcontrol text idtext "Instructions" "^instructions" 24 12 /title
    gcontrol label macro "OPTIONS" AlwaysOpen
    gcontrol menu logAmessage "Log a Message of type:" "Info,Warning,Error" /nc=3 /tleft
    set gc.logAmessage.itemColors {INFO=WHITE,WARNING=YELLOW,ERROR=RED}

    shellgui/id=idshellgui/attach
    messagelog/id=msglog1/msgid=main/file=logFile

    res INFO 0
    res WARNING 1
    res ERROR 2

    message send msglog1 ,, LOG ,ERROR, "THIS IS AN ERROR MESSAGE"
    message send msglog1 ,, LOG ,WARNING, "THIS IS A WARNING MESSAGE"
    message send msglog1 ,, LOG ,INFO, "THIS IS AN INFO MESSAGE"

    message send msglog1 ,, LOG ,INFO, "another Informational message"
    message send msglog1 ,, LOG ,WARNING, "another Warning message"
    message send msglog1 ,, LOG ,ERROR, "another Error message"

    ! Uniquely identify any additional messages going to the logger
    res countTab {TOTAL=0,INFO=0,WARN=0,ERROR=0}

    pipe run
    pipe wait
    pipe off

    erase/all logFile

  endif
endmacro

!******************************************************************************!
procedure processMessage

  !say "Msg ^msg.name = ^msg.data "

  if msg.name eqs "MAIN"
    assert/text="^reg.main.name: user indicated" msg.data eqss "PASS"
    pipe stop


  elseif msg.name eqs "LOGAMESSAGE"
    ! Send each log message with two unique counters that let us know
    ! the order of arrival 
    res countTab.TOTAL countTab.TOTAL+1
    if msg.data eqs "INFO"
      res countTab.info countTab.info+1
      message send msglog1 ,, LOG ,INFO, "Info message ^countTab.info  ( ^countTab.TOTAL )"
      say "sent INFO message ^countTab.info "
    elseif msg.data eqs "WARNING"
      res countTab.WARN countTab.WARN+1
      message send msglog1 ,, LOG ,WARNING, "Warning message ^countTab.WARN ( ^countTab.TOTAL )"
      say "sent WARN message ^countTab.WARN "
    elseif msg.data eqs "ERROR"
      res countTab.error countTab.error+1
      message send msglog1 ,, LOG ,ERROR, "Error message ^countTab.error ( ^countTab.TOTAL )"
      say "sent ERROR message ^countTab.error "
    else 
      say "unrecognized request to log a message: msg.data = ^msg.data"
    endif

  elseif msg.fid eqss "PANEL"

  else 
    say "Unhandled message ^msg.name from ^msg.fid"
  endif
return
!******************************************************************************!
procedure close
  invoke L:xxx reg.msglog1.close()
  stop
return
!******************************************************************************!
