%D \module
%D   [      file=s-mod-02,
%D        version=very-old,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Documentation Screen Environment,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This module looks like crap, is not documented, will
%D change, and used to be called modu-*.tex.

% Macro's

\usemodule[mod-00]

% todo: internationalize + setups

\setuphead[paragraaf][expansion=command]

\def\complexmodule[#1]% redefined
  {\startglobal % i.v.m. \bgroup in \startdocumentation
   \getparameters[Module][#1]
   \stopglobal  % i.v.m. \bgroup in \startdocumentation
   \section{\Modulesubtitle}
   \WriteLists}

\def\stopmodule % redefined
  {\page
   \determineregistercharacteristics
     [index]
     [criterium=section]
   \ifutilitydone
     \pagereference
       [index]
     \placeregister
       [index]
       [balance=yes,
        indicator=no,
        criterium=section]
   \fi}

\let\ComposeLists=\relax

\newcounter\ModuleNumber

\newwrite\BatchFile \openout\BatchFile=\jobname.bat

\def\WriteBatchFile
  {\doglobal\increment\ModuleNumber
%    \immediate\write\BatchFile{call modu-run \FileName\space \ModuleNumber}}
%    \immediate\write\BatchFile{texmfstart texutil --modu \FileName}}
   \immediate\write\BatchFile{texmfstart texexec --pdf --modu \FileName}}

\newif\ifProcessingPublic

\def\WriteLists
  {\writetolist[FileNames] {}{\FileName}
   \writetolist[GroupItems]{}{\GroupItem}}

\def\moduletitle{}

\def\TypeZeroModule#1%
  {\section{[to be extracted: #1]}
   {\em This module is not yet split off.}
   \WriteLists}

\def\TypeOneModule#1%
  {\section{[to be documented: #1]}
   {\em This module is not yet fully documented.}
   \WriteLists}

\def\TypeTwoModule#1%
  {\ifProcessingPublic
     \readfile{#1.ted}{}{}%
     \WriteBatchFile
   \else
     \section{[not yet public: #1]}
     {\em This module is documented but not yet public.}
     \WriteLists
   \fi}

\def\TypeThreeModule#1%
  {\readfile{#1.ted}{}{}%
   \WriteBatchFile}

\def\processmodule#1#2%
  {\page
   \bgroup
   \def\FileName{#1}
   \setupreferencing[prefix=#1]
   \useexternaldocument[PaperVersion][#1][]
   \aftersplitstring#1\at-\to\GroupItem
   \ComposeLists
   \ifcase#2
     \TypeZeroModule{#1}
   \or
     \TypeOneModule{#1}
   \or
     \TypeTwoModule{#1}
   \or
     \TypeThreeModule{#1}
   \fi
   \page
   \setupreferencing[prefix=]
   \egroup}

\def\ModuleGroup#1#2%
  {\page
   \let\Modulefile=\empty
   \setupreferencing[prefix=#1]
   \def\FileGroup{#1}
   \writetolist[FileGroups]{}{\FileGroup}
   \chapter[content]{#2}
   \MakeListOfItems
   \MakeListOfNames
   \MakeListOfGroups
   \placecontent[criterium=chapter,level=section]}

% Layout

\setupbodyfont
  [9pt]

\setuppapersize
  [S6][S6]

\setuplayout
  [backspace=72.5pt,
   leftmargin=50pt,
   leftmargindistance=12.5pt,
   rightmargin=0pt,
   rightedge=80pt,
   rightedgedistance=10pt,
   leftedge=0pt,
   width=430pt,
   topspace=10pt,
   header=0pt,
   footer=30pt,
   bottomdistance=10pt,
   bottom=15pt,
   height=410pt,
   style=\ss]

\setuptyping
  [palet=colorpretty]

\setupsetup
  [reference=3]

\definecolor [AchtergrondKleur] [s=.6]
\definecolor [ButtonKleur]      [r=.2,g=.2,b=.6]
\definecolor [TekstKleur]       [r=.6,g=.2,b=.2]

\definecolor [colorprettyone]   [r=.6,g=.0,b=.0]  % red
\definecolor [colorprettytwo]   [r=.0,g=.6,b=.0]  % green
\definecolor [colorprettythree] [r=.0,g=.0,b=.6]  % blue
\definecolor [colorprettyfour]  [r=.6,g=.6,b=.0]  % yellow

\setupinteraction
  [state=start,
   page=yes,
   contrastcolor=,
   menu=on,
   color=]

\setupbackgrounds
  [page]
  [background=color,
   backgroundcolor=AchtergrondKleur,
   offset=2.5pt]  % this offset influences the menus!

\setupbackgrounds
  [text,footer]
  [text,leftmargin]
  [background=color,
   backgroundcolor=white]

\setupsubpagenumber
  [way=bysection,
   state=start]

\setupinteractionbar
  [frame=off,
   offset=0pt,
   height=fit]

\setupwhitespace
  [big]

\setuptyping
  [typing]
  [option=color]

\setuptyping
  [definition]
  [option=color]

\setuptyping
  [file]
  [option=color]

\setuppagenumbering
  [alternative=singlesided,
   way=bysection,
   state=none]

\setupinmargin
  [location=left]

\setupheads
  [alternative=inmargin]

\setuphead
  [chapter]
  [style=\ssc,
   page=right]

\setuphead
  [section]
  [style=\ssb,
   page=right]

\setuplist
  [chapter]
  [style=bold,
   after=\blank]

\setupcontent
  [width=2em]

\setupindex
  [balance=yes,
   indicator=no]

\setupcolors
  [state=start]

\def\TitelBlad#1%
  {\startstandardmakeup
     \definefont[GrootFont] [SansBold at 72pt]
     \definefont[MiddelFont][Sans at 32pt]
     \definefont[KleinFont] [Sans at 24pt]
     \startcolor[AchtergrondKleur]
     \vskip12pt
     \midaligned{\GrootFont\setstrut\strut    Con\TeX t}
     \vskip24pt
     \midaligned{\MiddelFont\setstrut\strut   #1}
     \vskip24pt
     \midaligned{\KleinFont\setstrut\strut    Hans Hagen}
     \vfilll
     \midaligned{\KleinFont\setstrut\strut    PRAGMA ADE}
     \vskip24pt
     \midaligned{\KleinFont\setstrut\strut    www.pragma-ade.com --- \currentdate}
     \vskip12pt
     \stopcolor
   \stopstandardmakeup}

\def\ColofonBlad
  {\startmode[atpragma]
   \page
   \bgroup
     \def\PragmaHoogte {\makeupheight}
     \def\PragmaBreedte{\textwidth}
     \def\PragmaKopwit {\topspace}
     \def\PragmaRugwit {\backspace}
     \def\PragmaMarge  {0pt}
     \PragmaLijnentrue
     \PlaatsPragmaLogo[ADE]
     \vfill
     todo: colofon
     \startnarrower[3*middle]
     This is the official documentation of \CONTEXT\ version
     \referraldate, a \TEX\ macropackage developed by J.~Hagen
     \& A.F.~Otten, who both hold the copyrights.
     \stopnarrower
     \vfill
     \page
   \egroup
   \stopmode}

\def\ColofonBlad
  {}

\newbox\ListOfItems
\newbox\ListOfGroups
\newbox\ListOfNames

\definelist[FileNames]   \def\FileName  {}
\definelist[FileGroups]  \def\FileGroup {}
\definelist[GroupItems]  \def\GroupItem {}

\setuplist
  [FileNames,FileGroups,FileGroups]
  [expansion=yes,
   pagenumber=no,
   style=\ss\bf]

\setuplist
  [FileNames]
  [command=\FileNameEntry,
   after=\endgraf,
   alternative=none] % horizontal

\setuplist
  [FileGroups]
  [command=\FileGroupEntry,
   after=\hss,
   alternative=horizontal]

\def\FileNameEntry#1#2#3%
  {\strut\hbox{#2}\endgraf}

\def\FileGroupEntry#1#2#3%
  {\strut\hbox{#2}\endgraf}

\def\MakeListOfItems
  {\setbox\ListOfItems=\vbox
     {\ss\bf
      \placelist[GroupItems][color=ButtonKleur,contrastcolor=white,criterium=chapter]}}

\def\MakeListOfNames
  {\setbox\ListOfNames=\vbox
     {\hsize\rightedgewidth
      \ss\bf\setupinterlinespace
      \startsimplecolumns[distance=10pt]
        \placelist[FileNames][color=ButtonKleur,contrastcolor=white,criterium=chapter]
      \stopsimplecolumns}}

\def\MakeListOfGroups
  {\setbox\ListOfGroups=\hbox to \textwidth
     {\ss\bf
      \setupinteraction[color=ButtonKleur]%
      \placelist[FileGroups][color=ButtonKleur,contrastcolor=white,criterium=all]\unskip\unskip}}

\setbox\ListOfGroups=\hbox{}

%\setupfootertexts
%  [rand]
%  []
%  [{\interactiebalk[variant=g]}]

\setupinteractionmenu
  [right,bottom]
  [state=start,
   frame=off,
   color=AchtergrondKleur,
   contrastcolor=white,
   style=\ss\bf,
   height=15pt,
   offset=0pt,
   inbetween=\vskip5pt,
   background=color,
   backgroundcolor=ButtonKleur]

\startinteractionmenu[right]
  \boxofsize \vbox \textheight \footerdistance \footerheight 5pt
    \bgroup
      \copy\ListOfNames
      \vfill
      \but [\FileGroup:content]  local contents \\
      \but [\FileName:index]     local register \\
      \but [PaperVersion::begin] paper version  \\
      \but [content]             main contents  \\
      \but [index]               main register  \\
      \but [PreviousJump]        previous jump  \\
      \but [CloseDocument]       close document \\
      \unskip
    \egroup
\stopinteractionmenu

\startinteractionmenu[bottom]
  \unhcopy\ListOfGroups
\stopinteractionmenu

\def\placemoduleregister
  {\startbackmatter
   \setupsubpagenumber[reset]
   \title[-:index]{Register}
   \placeregister[index]
   \stopbackmatter}

\def\placemodulecontent
  {\startfrontmatter
   \title[-:content]{Contents}
   \setupinteractionbar[state=stop]
   \placecontent[criterium=text,level=chapter]
   \stopfrontmatter}

\setupcontent
  [pagenumber=no,
   level=chapter,
   interaction=all,
   style=,
   before=,
   after=]

\setupfootertexts
  [margin]
  [\tt\Modulefile]
  []

\setupfootertexts
  [text]
  [chapter][chapter]

\setupindex
  [symbol=1]

\setuptolerance
  [verytolerant]

\endinput
