!the tutorial driver
var={ name=temp }
var={ name=calc value="| bc -l" }

! set npage to the total number of pages
var={ name=npage value=19 }

! this is the table of contents; you can reorder pages by changing it
var={ name=p1  value=home }
var={ name=p2  value=what }
var={ name=p3  value=hello }
var={ name=p4  value=objects }
var={ name=p5  value=actions }
var={ name=p6  value=attributes }
var={ name=p7  value=tests }
var={ name=p8  value=more }
var={ name=p9  value=box }
var={ name=p10 value=variable }
var={ name=p11 value=startup }
var={ name=p12 value=timer }
var={ name=p13 value=pipe }
var={ name=p14 value=utilities }
var={ name=p15 value=advanced }
var={ name=p16 value=math }
var={ name=p17 value=loop }
var={ name=p18 value=dynamic }
var={ name=p19 value=tutorscript }

! box of buttons across the top
hbox={ borderWidth=0

  ! quit
  button={ name=quit label=QUIT action=QUIT }

  ! return to page 1
  button={ name=homeb label="Home" 
	action="ASSIGN page 1" 
  }

  ! see script for this page
  button={ name=scriptb label="See script for this page" 
	action="EVAL xtpanel -var myfile $$p$(page) -file viewer &" 
  }

  ! go back a page
  button={ name=back label="<--" 
	action="ASSIGN temp `echo $(page)-1 $calc`"
	test={ condition=" test $temp -lt 1 "
	       true={ action="ASSIGN page $npage" }
	       false={ action="ASSIGN page $temp" }
	     }
  }

  ! go forward a page
  button={ name=fwd label="-->" 
	action="ASSIGN temp `echo $(page)+1 $calc`"
	test={ condition=" test $temp -gt $npage "
	       true={ action="ASSIGN page 1" }
	       false={ action="ASSIGN page $temp" }
	     }
  }

  ! a menubutton to go directly to a page
  menubutton={ name=menu
        label="Menu-->"
        action="ASSIGN page $val"
        item={ label="Home" value=1 }
        item={ label="What is xtpanel?" value=2 }
        item={ label="Hello world example" value=3 }
        item={ label="Xtpanel objects" value=4 }
        item={ label="Actions" value=5 }
        item={ label="Object attributes" value=6 }
        item={ label="More xtpanel objects" value=8 }
        item={ label="Useful utilities" value=14 }
        item={ label="Advanced topics" value=15 }
  }
}

! page actions make the old page invisible, the new one visible
var={ name=oldpage value=1 }
var={ name=page value=1 
   action="EVAL ASSIGN temp $$p$oldpage"
   action="SET $temp visible false" 
   ! create the page if it hasn't been created yet.
   action="EVAL ASSIGN temp $$load$page"
   test={ condition="test $temp -eq 0"
	  true={ action="ASSIGN icreate $page" }
	}
   action="EVAL ASSIGN temp $$p$val"
   action="SET $temp visible true"
   action="ASSIGN oldpage $val"
}

! this is the form where the current page is displayed
form={ height=500 width=800 }

! do loop to create flags that indicate if a page needs to be created
var={ name=iload
  test={ condition="test $iload -le $npage"
	 true={ action="CREATE window1 var={ name=load$iload 
					   value=0 }"
 		action="ASSIGN iload `echo $iload + 1 $calc`"
	      }
       }
}

! create one page
var={ name=icreate
  action="EVAL ASSIGN temp $$p$icreate"
  test={ condition="test $icreate -le $npage"
	 true={ action="CREATE form1 box={ borderWidth=0 name=$temp 
					   x=0 y=0
					   visible=false }"
		action="CREATE $temp `cat $temp`" 
		action="ASSIGN load$icreate 1"
	      }
       }
}

! startup creates the page flags, then creates page1, then makes it visible
startup={
  action="ASSIGN iload 1"
  action="ASSIGN icreate 1"
  action="ASSIGN page 1"
}
