;;; pagelist.mhtml: -*- Meta-HTML -*-  DESCRIPTIVE TEXT.
;;;
;;;  Copyright (c) 1996 Universal Access
;;;  Author: Henry Minsky
;;;
;;; Macros for creating auto-navigation bars for a sequence of pages.
;;; 
;;; Usage: 
;;; <def-pagelist set-name>
;;;  <defpage url pretty-name [prev] [next]>
;;; </def-page-sequence>

;;; Save the index of this page
<defun defpage url pretty-name >
  <set-var url=<make-absolute-path <get-var url>>>
  <li><a href="<get-var url>"><get-var pretty-name></a><p>
  <set-var pages::<get-var url>=<get-var pages::counter>>
  <set-var pages::sequence[<get-var pages::counter>]="<get-var url>">
  <increment pages::counter>
</defun>

<defun defpage-hidden url pretty-name >
  <set-var url=<make-absolute-path <get-var url>>>
  <set-var pages::<get-var url>=<get-var pages::counter>>
  <set-var pages::sequence[<get-var pages::counter>]="<get-var url>">
  <increment pages::counter>
</defun>

<defun make-absolute-path path>
  <if <not <string-eq <substring <get-var path> 0 1> />>
      <set-var newurl =
	<concat <get-var mhtml::url-to-dir> /
		<get-var path>>>
    <set-var newurl=<get-var path>>>
  <get-var newurl>
</defun>

<defun use-pagelist name>
  <set-var pages::pagelist-name=<get-session-var <get-var name>>>
  <alist-to-package <get-var pages::pagelist-name> pages>
</defun>

<defun prev-page>
  <get-var pages::sequence[<sub <get-var pages::<get-var mhtml::full-url>> 1>]>
</defun>

<defun next-page>
  <get-var pages::sequence[<add <get-var pages::<get-var mhtml::full-url>> 1>]>
</defun>

<defun parent-page>
  <get-var pages::parent-page>
</defun>

<defun pagelist-control-panel prev up next>
  <center>
    <table border=0 width=80%>
      <tr>
	<th width="30%">
	<concat <a href="<prev-page>">
		<img src="<get-var mhtml::url-to-top>/images/lmarrow.gif"
		 border=0>
		<br><get-var prev>
		</a>>
	</th>
	<th>
	<if <not <string-eq <parent-page> <get-var mhtml::current-url>>>
	    <concat <a href="<parent-page>">
		    <img src="<get-var mhtml::url-to-top>/images/umarrow.gif"
		     border=0>
		    <br><get-var up>
		    </a>>
	  <prog
	    <set-var x=<subst-in-string <parent-page> "/[^/]+/[^/]+$" "">>
	    <concat <a href="<get-var x>/">
		    <img src="<get-var mhtml::url-to-top>/images/umarrow.gif"
			 border=0>
		    <br><get-var up>
		    </a>>>>
	</th>
	<th width="30%">
	<concat <a href="<next-page>">
		<img src="<get-var mhtml::url-to-top>/images/rmarrow.gif"
		     border=0>
		<br><get-var next>
		</a>>
	</th>
      </tr>
      </table>
    <b><tt>
    <font size=+4><get-var pages::<get-var mhtml::current-doc>></font>
    </tt></b>
  </center>
</defun>

<defmacro def-pagelist name>
  <set-var pages::counter=1 pages::parent-page=<get-var mhtml::full-url>>
  <dl>
  <dd>
  %body
  </dl>
  <set-session-var <get-var name>=<package-to-alist pages>>
</defmacro>
