!******************************************************************************!
! Test display issues with subpanels
!
! @bug      2707 PANEL: Sub-panel displays incorrectly
! @author:  J Sallay / J Bauer
! @version: $Id: test_panel_subpanel.mm,v 1.1 2013/02/12 14:37:17 jwb Exp $
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  if interAct then
    set instructions "TODO: Enter test case instructions here"

   ! Create custom setups for main panel and sub panel
   res gui_setup &
     {0={TYPE=POS,X=25,Y=25,W=800,H=500},&
      1={TYPE=BORDERS,MASK=0x0000000B},&
      2={TYPE=LINE,INDEX=1,DIR=1,X=0,Y=0.5,I1=0,I2=0,FP=218},&
      3={TYPE=LINE,INDEX=2,DIR=1,X=1,Y=0.5,I1=0,I2=0,FP=50},&
      4={TYPE=LINE,INDEX=3,DIR=2,X=0.5,Y=0,I1=1,I2=2,FP=50},&
      5={TYPE=LINE,INDEX=4,DIR=2,X=0.5,Y=1,I1=1,I2=2,FP=0},&
      6={TYPE=PANE,INDEX=0,NAME=PANE0,TITLE=NULL,TH=0,IX1=1,IX2=2,IY1=3,IY2=4},&
      7={TYPE=PANE,INDEX=1,NAME=PANE1,TITLE=H1,TH=12,IX1=1,IX2=2,IY1=3,IY2=4},&
      8={TYPE=PANE,INDEX=2,NAME=PANE2,TITLE=H2,TH=12,IX1=1,IX2=2,IY1=3,IY2=4},&
     }
     
   res sub_setup &
     {0={TYPE=POS,X=70,Y=49,W=800,H=400},&
      1={TYPE=LINE,INDEX=1,DIR=1,X=0,Y=0.5,I1=0,I2=0,FP=0},&
      2={TYPE=LINE,INDEX=2,DIR=1,X=1,Y=0.5,I1=0,I2=0,FP=0},&
      3={TYPE=LINE,INDEX=3,DIR=1,X=0.5,Y=0,I1=1,I2=2,FP=0},&
      4={TYPE=LINE,INDEX=4,DIR=1,X=0.5,Y=1,I1=1,I2=2,FP=0},&
      5={TYPE=PANE,INDEX=0,NAME=PANE0,TITLE=NULL,TH=0,IX1=1,IX2=2,IY1=3,IY2=4},&
      6={TYPE=PANE,INDEX=1,NAME=A1,TITLE=S1,TH=12,IX1=1,IX2=2,IY1=3,IY2=4},&
      7={TYPE=PANE,INDEX=2,NAME=A2,TITLE=S2,TH=12,IX1=1,IX2=2,IY1=3,IY2=4},&
      8={TYPE=PANE,INDEX=3,NAME=A3,TITLE=S3,TH=12,IX1=1,IX2=2,IY1=3,IY2=4},&
     }

   res instructions "You should see a pane with five tabs. Two above (H1 and H2) and three below (S1, S2, and S3).\n\n&
                     Click on every tab.\n\n&
                     There should not be any refresh issues."


    pipe on
      ! create sample files to plot
      ramp aa
      wave bb
      wave cc ,,, triangle
      wave dd ,,, sawtooth
    
      ! use the first tsetup for the main panel
      panel/panes=win1/tsetup=gui_setup/msgid=MAIN/controls=gc/id=mainpanel
      
        gcontrol/panel=mainpanel label macro "MACRO"
        gcontrol/panel=mainpanel menu MAIN "Exit with Status = " "PASS,FAIL" /tleft
        set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}

        gcontrol/panel=mainpanel text idtext "INSTRUCTIONS" "^instructions" 24 12 /title
        
        ! have a single plot on the main panel
        plot/win=win1.pane1 aa
      
        ! define a sub-panel that exists as a tab on the main panel
        panel/id=MP2/win=win1.PANE2/panes=subwin2/tsetup=sub_setup
        
          ! put three tabs with plot on the sub panel
          plot/win=subwin2.a1 bb
          plot/win=subwin2.a2 cc
          plot/win=subwin2.a3 dd
      
    pipe off

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return
