%D \module
%D   [      file=s-mod-00,
%D        version=very-old,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Documentation Base 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.

% todo:
%
% file inclusions -> hyperlinks

\mainlanguage[en] % better not here

\usemodule[eenheid]

\enableactivediscretionaries \newprettytrue

\unprotect

% beter:
%
% group    -> title
% title    -> category
% subtitle -> subtitle

% herzien ivm fonts

% nog eens \interface \\ \\ verder doorvoeren

\def\resetmodule%
  {\getrawparameters
     [Module]
     [       file=\jobname,
          version={\currentdate[\v!jaar,{.},\v!maand,{.},\v!dag]},
           system=\CONTEXT,
            title=,
         subtitle=,
           author=Hans Hagen,
             date=\currentdate,
        copyright={PRAGMA / Hans Hagen \& Ton Otten},
      suggestions=]}

\resetmodule

\def\dostartmodule[#1]%
  {\newcounter\ParagraphNumber
   \resetmodule
   \getrawparameters[Module][type=tex,#1]}

\def\startmodule%
  {\dosingleempty\dostartmodule}

\def\complexmodule[#1]%
  {\startglobal % i.v.m. \bgroup in \startdocumentation
   \getrawparameters[Module][#1]
   \stopglobal  % i.v.m. \bgroup in \startdocumentation
   \moduletitel}

\def\stopmodule%
  {\pagina
   \plaatsregister
     [\v!index]
     [\c!balanceren=\v!ja,
      \c!aanduiding=\v!nee,
      \c!criterium=\v!tekst]}

\def\simplemodule#1%
  {\type{#1}}

\definecomplexorsimple\module

% \startmode[atpragma]
%
%   \def\TitelPagina#1% can be done more efficient
%     {\startMPrun
%         mpgraph := #1 ;
%         input mp-cont ;
%      \stopMPrun
%      \externalfigure
%        [\bufferprefix mprun.#1]
%        [\c!hoogte=\vsize,
%         \c!breedte=\hsize]}
%
%   \defineoverlay[titelpagina][\TitelPagina{512}]
%
% \stopmode

\startuseMPgraphic{titlepage}

  width  := PaperWidth ;
  height := PaperHeight ;

  color local_red, local_white, local_blue ;

  local_white := white ;

  local_blue := local_white randomized (.6,.8) ;
  local_red  := local_white randomized (.3,.4) ;

  u := width/400 ;

  def a_module (expr dx, dy) =
    picture p ; p := image
      ( ddy := 0 ; sx := 60u ;
        for i=1 upto (4 randomized 2) :
          sy := 7u randomized 3u ;
          fill unitsquare xyscaled(sx,sy) shifted (0,ddy)
            withcolor local_red ;
          ddy := ddy + sy + 4u ;
        endfor ) ;
    p := p shifted (dx,dy) shifted - center p ;
    fill boundingbox p enlarged 8u withcolor local_white ;
    fill boundingbox p enlarged 4u withcolor local_blue ;
    draw p ;
  enddef ;

  set_grid(width, height, width/15, height/15) ;
  forever:
    if new_on_grid(uniformdeviate width,uniformdeviate height):
      a_module(dx,dy) ;
    fi ;
    exitif grid_full ;
  endfor ;

  clip currentpicture to unitsquare xyscaled(width,height) ;
\stopuseMPgraphic

\defineoverlay
  [titelpagina]
  [\useMPgraphic{titlepage}]

% When run at \PRAGMA, we use a slightly different graphic,
% so that we can recognize an original. Users are not
% supposed to mimick this feature.

\doifmode{atpragma}{\readfile{s-mod-04.tex}{}{}}

\defineframed
  [TitleFrame]
  [\c!achtergrond=\v!kleur,
   \c!achtergrondkleur=wit,
   \c!uitlijnen=\v!rechts,
   \c!offset=12pt,
   \c!strut=\v!nee,
   \c!kader=\v!uit,
   \c!onder=]

\definelayout
  [titlepage]
  [\c!rugwit=0pt,
   \c!kopwit=0pt,
   \c!hoofd=0pt,
   \c!voet=0pt,
   \c!hoogte=\v!midden,
   \c!breedte=\v!midden]

\def\moduletitel%
  {\setuplayout[titlepage]
   \ifx\ModuleNumber\undefined \else
     \ifnum\ModuleNumber<10
       \edef\ModuleNumber{00\ModuleNumber}
     \else\ifnum\ModuleNumber<100
       \edef\ModuleNumber{0\ModuleNumber}
     \fi\fi
     \setupbackgrounds
       [\v!pagina]
       [\c!achtergrond=titelpagina]
   \fi
   \startmakeup[\v!standaard][\c!hoofdstatus=\v!geen,\c!voetstatus=\v!geen]
     \switchtobodyfont[14.4pt,ss]
     \bgroup
       \def\CONTEXT {Con\kern-.15em\TeX t}
       \def\TEXUTIL {\TeX Util}
       \def\PPCHTEX {PPCH\TeX}
       \def\METAPOST{MetaPost}
       \hfill
         {\definedfont[SansBold at 96pt]\setstrut
          \TitleFrame{\Modulesystem}}
       \vfill
       \definetabulate[temp][|l|l|]%
       \switchtobodyfont[17.3pt,ss]
       \hfill
         {\bf\setstrut
          \TitleFrame
            {\insidefloattrue\setuptabulate[\c!voor=,\c!na=]%
             \starttemp
               \doifsomething{\Moduletitle}
                 {\NC title \EQ \Moduletitle \NC\NR}%
               \doifsomething{\Modulesubtitle}
                 {\NC subtitle \EQ \Modulesubtitle \NC\NR}%
               \doifsomething{\Moduleauthor}
                 {\NC author \EQ \Moduleauthor \NC\NR}%
                  \NC date \EQ \currentdate \NC\NR
              %\doifsomething{\Modulesuggestions} % todo: generates space
              %  {\NC suggestions \NC \Modulesuggestions \NC\NR}%
             \stoptemp}}
     \egroup
   \stopmakeup
   \ifx\ModuleNumber\undefined \else
     \setupbackgrounds
       [\v!pagina]
       [\c!achtergrond=]
   \fi
   \setuplayout}

\let\stopdocumentation=\relax

\def\startdocumentation%
  {\bgroup
   \doglobal\newcounter\NOfMarginLines
   \def\stopdocumentation{\par\egroup}}

\newif\ifcompressdefinitions

\def\startcompressdefinitions {\global\compressdefinitionstrue}
\def\stopcompressdefinitions  {\global\compressdefinitionsfalse}

\gdef\CompressDefinitions%
  {\ifcompressdefinitions
     \switchtobodyfont[\v!klein]%
   \fi}

\startnotmode[nocode]

  \definetyping
    [definition]

  \setuptyping
    [definition]
    [\c!voor={\pagina[\v!voorkeur]}\blanko\PresetParagraphNumber\CompressDefinitions,
     \c!na=\ResetParagraphNumber\blanko,
     \c!optie=\Moduletype]

\stopnotmode

\startmode[nocode]

% \definieerbuffer[definition] % ignore

  \long\def\startdefinition#1\stopdefinition{}

\stopmode

\definetyping [PL]  [\c!optie=PL, \c!marge=\v!standaard]
\definetyping [JV]  [\c!optie=JV, \c!marge=\v!standaard]
\definetyping [MP]  [\c!optie=MP, \c!marge=\v!standaard]
\definetyping [TEX] [\c!optie=TEX,\c!marge=\v!standaard]

\setuptyping [\v!typen]   [\c!marge=\v!standaard]
\setuptyping [\v!file]    [\c!marge=\v!standaard]
\setuptyping [definition] [\c!marge=0pt]

\newcounter\NOfMarginLines
\newcounter\ParagraphNumber

\def\ResetParagraphNumber%
  {\egroup}

\def\PresetParagraphNumber%
  {\bgroup
   \xdef\NOfTextLines%
     {\the\prevgraf}%
   \doglobal\decrement\NOfMarginLines
   \doglobal\increment\ParagraphNumber
   \message{.}%
   \gdef\ShowParagraphNumber%
     {\llap{\slx\ParagraphNumber\hskip\linkermargeafstand}}%
   \gdef\ShowParagraphNumberA%
     {\ifnum\NOfMarginLines>\NOfTextLines\relax
        \doglobal\increment\NOfTextLines
      \else
        \ShowParagraphNumber
        \global\let\ShowParagraphNumberA=\relax
        \global\let\ShowParagraphNumberB=\ShowParagraphNumber
        \doglobal\newcounter\NOfMarginLines
      \fi}%
   \gdef\ShowParagraphNumberB%
     {}%
   \EveryLine
     {\ShowParagraphNumberA}%
   \EveryPar
     {\vadjust{\nobreak}%
      \ShowParagraphNumberB}}

\EveryPar % skip one
  {\EveryPar
     {\doglobal\newcounter\NOfMarginLines}}

\def\dodomargeaanduidingen[#1]#2%
  {\def\docommando##1%
     {\indent\hbox
        {\ifx#2\relax
           \index{##1}%
         \else
           \index{#2{##1}}%
         \fi
         #2{\doboundtext{##1}{\linkermargebreedte}{..}}}%
       \doglobal\increment\NOfMarginLines
       \endgraf}%
   \processcommalist[#1]\docommando}

\def\margeaanduidingen#1[#2]%
  {\def\domargeaanduidingen##1##2%
     {\margetitel[#2]%
        {\switchtobodyfont[\v!klein]%
         \doglobal\newcounter\NOfMarginLines
         \dodomargeaanduidingen[##1]#1%
         \scratchcounter=\NOfMarginLines
         \multiply\scratchcounter by 10
         \divide\scratchcounter by 12
         \advance\scratchcounter by 1
         \xdef\NOfMarginLines{\the\scratchcounter}%
         \processcommalist[##2]\index}}%
   \dodoublegroupempty\domargeaanduidingen}

\def\complexmacros{\margeaanduidingen\tex  }
\def\complexextras{\margeaanduidingen\relax}

\def\complexelements%
  {\margeaanduidingen\someelement}

\def\someelement#1{\type{<#1>}}

\definecomplexorsimpleempty\macros
\definecomplexorsimpleempty\extras
\definecomplexorsimpleempty\elements

\def\showelements{\dodoubleempty\doshowelements}

\def\doshowelements[#1][#2]
  {\bgroup
   \processXMLbuffer
   \typebuffer
   \setupcolors[\c!status=\v!stop]
   \showXSDcomponent[#1][#2]
   \egroup}

% \macros{a,b}
% \macros{a,b}{b}
% \macros[a]{a,b}{b}

% weg ermee

\definieeralineas [interface] [\c!n=2]
\stelalineasin    [interface] [1] [\c!breedte=4cm]

\def\startvoorbeeld{\par\startsmaller}
\def\stopvoorbeeld {\stopsmaller}

\gdef\VisualizeLastSpace%
  {\ifdim\lastskip>0pt\unskip\tttf\char32\fi}
\gdef\ShowHeadText#1%
  {\tttf#1\VL\headtext{#1}\VisualizeLastSpace}%
\gdef\ShowLabelText#1%
  {\tttf#1\VL\labeltext{#1}\VisualizeLastSpace}

\startbuffer[lang-a]
\starttabel[|l|l|]
  \HL
  \VL \bf head key  \VL \bf current value \VL\SR
  \HL
  \VL \ShowHeadText \v!afkortingen        \VL\FR
  \VL \ShowHeadText \v!eenheden           \VL\MR
  \VL \ShowHeadText \v!figuren            \VL\MR
  \VL \ShowHeadText \v!grafieken          \VL\MR
  \VL \ShowHeadText \v!index              \VL\MR
  \VL \ShowHeadText \v!inhoud             \VL\MR
  \VL \ShowHeadText \v!intermezzos        \VL\MR
  \VL \ShowHeadText \v!logos              \VL\MR
  \VL \ShowHeadText \v!tabellen           \VL\LR
  \HL
\stoptabel
\stopbuffer

\startbuffer[lang-b]
\starttabel[|l|l|]
  \HL
  \VL \bf label key  \VL \bf current value      \VL\SR
  \HL
  \VL \ShowLabelText \v!tabel                   \VL\FR
  \VL \ShowLabelText \v!figuur                  \VL\MR
  \VL \ShowLabelText \v!intermezzo              \VL\MR
  \VL \ShowLabelText \v!grafiek                 \VL\MR
  \VL \ShowLabelText \v!hoofdstuk               \VL\MR
  \VL \ShowLabelText \v!paragraaf               \VL\MR
  \VL \ShowLabelText {\v!sub\v!paragraaf}       \VL\MR
  \VL \ShowLabelText {\v!sub\v!sub\v!paragraaf} \VL\MR
  \VL \ShowLabelText \v!bijlage                 \VL\MR
  \VL \ShowLabelText \v!deel                    \VL\MR
  \VL \ShowLabelText \v!regel                   \VL\MR
  \VL \ShowLabelText \v!regels                  \VL\LR
  \HL
\stoptabel
\stopbuffer

\startbuffer[lang-c]
\starttabel[|l|l|]
  \HL
  \VL \bf label key  \VL \bf current value \VL\SR
  \HL
  \VL \ShowLabelText \v!january            \VL\FR
  \VL \ShowLabelText \v!february            \VL\MR
  \VL \ShowLabelText \v!march              \VL\MR
  \VL \ShowLabelText \v!april              \VL\MR
  \VL \ShowLabelText \v!may                \VL\MR
  \VL \ShowLabelText \v!june               \VL\MR
  \VL \ShowLabelText \v!july               \VL\MR
  \VL \ShowLabelText \v!august             \VL\MR
  \VL \ShowLabelText \v!september          \VL\MR
  \VL \ShowLabelText \v!october            \VL\MR
  \VL \ShowLabelText \v!november           \VL\MR
  \VL \ShowLabelText \v!december           \VL\LR
  \HL
\stoptabel
\stopbuffer

\startbuffer[lang-d]
\starttabel[|l|l|]
  \HL
  \VL \bf label key  \VL \bf current value \VL\SR
  \HL
  \VL \ShowLabelText \v!sunday             \VL\FR
  \VL \ShowLabelText \v!monday             \VL\MR
  \VL \ShowLabelText \v!tuesday            \VL\MR
  \VL \ShowLabelText \v!wednesday          \VL\MR
  \VL \ShowLabelText \v!thursday           \VL\MR
  \VL \ShowLabelText \v!friday             \VL\MR
  \VL \ShowLabelText \v!saturday           \VL\MR
  \HL
\stoptabel
\stopbuffer

\gdef\ShowTextsValues [#1] [#2]
  {\vbox\bgroup
   \language[#1]%
   \setbox0=\hbox to \hsize{\hss\bfb#2 language defaults\hss}
   \dp0=0pt
   \box0
   \vskip1em
   \hrule
   \vskip2em
   \halign
     {\hss##\hss&##\hskip1em&\hss##\hss\cr
      $\vcenter{\haalbuffer[lang-a]}$&&$\vcenter{\haalbuffer[lang-b]}$\cr
      \noalign{\vskip1em}
      $\vcenter{\haalbuffer[lang-c]}$&&$\vcenter{\haalbuffer[lang-d]}$\cr}%
   \egroup}

\gdef\ShowLanguageValues [#1] [#2] #3 #4
  {\hbox to \hsize
     {\hss
      \vbox
        \bgroup
        \language[#1]%
        \let\normalbar=|
        \starttabel[||||]
        \HL
        \VL \THREE{\bf subsentence symbol and quotes} \VL\SR
        \HL
        \VL \citaat{#3 #4} \VL \citeer{#2} \VL \let|=\normalbar |<||<|#3|>|#4|>| \VL\SR
        \VL \citaat{#3 #4} \VL \citeer{#2} \VL |<||<|#3|>|#4|>| \VL\SR
        \HL
        \stoptabel
        \egroup
      \hss}}

\gdef\doShowAllLanguageValues [#1] [#2] #3 #4
  {\vbox
     {\ShowTextsValues [#1] [#2]
      \vskip2em
      \ShowLanguageValues  [#1] [#2] #3 #4 }
   \protect
   \pagina}

\gdef\ShowAllLanguageValues%
  {\pagina
   \unprotect
   \doShowAllLanguageValues}

\protect

%D Command references:

\input setupa
\input setupb

\unprotect

\def\showsetup%
  {\doglobal\newcounter\CurrentArgument
   \setup}

\setupframedtexts
  [setuptext]
  [\c!achtergrond=\v!raster,
   \c!kader=\v!uit]

\protect \endinput
