%D \module
%D   [       file=page-mak, % copied from main-001,
%D        version=1997.03.31,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Simple MakeUp,
%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.

\writestatus{loading}{Context Page Macros / MakeUp}

\unprotect 

%D \macros 
%D   {definemakeup, setupmakeup, startmakeup}
%D 
%D A makeup is a separate page, like a title page or colofon.
%D There is one standard makeup page, but you can define more
%D if needed. 
%D 
%D \starttypen 
%D \startstandardmakeup
%D   My Fancy Title 
%D \stopstandardmakeup
%D \stoptypen 
%D 
%D The associated commands are: 
%D 
%D \showsetup{\y!definemakeup}
%D \showsetup{\y!setupmakeup}
%D \showsetup{\y!startmakeup}

\def\definemakeup
  {\dodoubleargument\dodefinemakeup}

\def\dodefinemakeup[#1][#2]%
  {\getparameters
     [\??do#1]%
     [\c!breedte=\zetbreedte,
      \c!hoogte=\teksthoogte,
      \c!voffset=\!!zeropoint,
      \c!hoffset=\!!zeropoint,
      \c!commandos=,
      \c!pagina=\v!rechts,
      \c!dubbelzijdig=\v!leeg,
      \c!voor=,
      \c!boven=\vss,
      \c!onder=\vss,
      \c!na=,
      \c!onderstatus=\v!normaal,
      \c!bovenstatus=\v!normaal,
      \c!tekststatus=\v!normaal,
      \c!hoofdstatus=\v!stop,
      \c!voetstatus=\v!stop,
      \c!paginastatus=\v!stop,
      \c!kleur=,
      \c!uitlijnen=,
      #2]%
   \setvalue{\e!start#1\e!opmaak}{\startmakeup[#1]}%
   \setvalue{\e!stop #1\e!opmaak}{\stopmakeup}}

\def\setupmakeup
  {\dodoubleargument\dosetupmakeup}

\def\dosetupmakeup[#1]%
  {\getparameters[\??do#1]}

%D This will save us some 375 bytes in the format file. 

\def\makeupparameter#1{\getvalue{\??do\currentmakeup#1}}

%D The \type{\start}||\type{\stop} macros are used for both
%D the direct and indirect way. The parameterless call will 
%D build a simple box. 

\newtoks\everymakeup 

\appendtoks \postponemarks \to \everymakeup 

\let\currentmakeup\empty

\def\startmakeup
  {\dodoubleempty\dostartmakeup}

\def\dostartmakeup[#1][#2]%
  {\bgroup
   \edef\currentmakeup{#1}%
   \the\everymakeup
   \iffirstargument
     \setupmakeup[\currentmakeup][#2]%
     \let\stopmakeup\dodostopmakeup
     \expandafter   \dodostartmakeup
   \else
     \let\stopmakeup\donostopmakeup
     \expandafter   \donostartmakeup
   \fi}

%D The simple case: 

\def\donostartmakeup
  {\pagina
   \setupheader[\c!status=\v!leeg]%
   \setupfooter[\c!status=\v!leeg]%
   \setsystemmode\v!opmaak
   \vbox to \teksthoogte\bgroup\hsize\tekstbreedte}

\def\donostopmakeup
  {\egroup
   \flushmarks % new, here, else empty pages 
   \pagina
   \egroup}

%D The normal one: 

\newbox\makeupbox 

\def\dodostartmakeup
  {\doifvaluesomething{\??do\currentmakeup\c!pagina}
     {\ExpandFirstAfter\pagina[\makeupparameter\c!pagina]}%
   \soortpagina[\currentmakeup]%
   \setsystemmode\v!opmaak
   \setupmakeuplayout
   \makeupparameter\c!commandos
   \startregistercolor[\makeupparameter\c!kleur]%
   \global\setbox\makeupbox\vbox to \makeupparameter\c!hoogte
     \bgroup
       \forgetall 
       \hsize\makeupparameter\c!breedte
       \doifsomething{\makeupparameter\c!uitlijnen}
         {\setupalign[\makeupparameter\c!uitlijnen]}%
       \makeupparameter\c!boven}

\def\dodostopmakeup
  {\endgraf
   \makeupparameter\c!onder
   \egroup
   \flushmarks % new, here, else empty pages 
\stopregistercolor
   \doflushmakeup
   \egroup
   \calculatehsizes
   \calculatevsizes}

%D Selective page processing is handled here. (Why?)

\def\doflushmakeup
  {\ifverwerken
     \ifgeselecteerd
       \doshipoutmakeup
     \fi
   \else
     \ifgeselecteerd \else
       \doshipoutmakeup
     \fi
   \fi
   \ifselecteren
     \global\geselecteerdfalse
   \fi}

\def\doshipoutmakeup
  {\pushmacro\@@pnstatus % new 
   \makeupparameter\c!voor   
   \vbox{\hbox{\color[\makeupparameter\c!kleur]{\box\makeupbox}}}%
   \stelpaginanummerin[\c!status=\makeupparameter\c!paginastatus]% 
   \setupmakeuplayout
   \pagina
   \makeupparameter\c!na
   \relax % voor fi 
   \ifdubbelzijdig \ifodd\realpageno\else
     \processaction
       [\makeupparameter\c!dubbelzijdig]
       [  \v!ja=>\null
                 \pagina,
               % \verlaagpaginanummer, % new 
        \v!leeg=>\setupmakeuplayout
                 \global\pagebodyornamentsfalse 
                 \null\pagina]%
               % \verlaagpaginanummer]% % new 
   \fi \fi
 % \verlaagpaginanummer % new 
   \popmacro\@@pnstatus} % new 

%D The text surrounding the main body text can be influenced
%D by setting their associated status variables. The
%D connection between them is made by the following macro 

 
\def\setupmakeuplayout
  {\setupfooter[\c!status=\makeupparameter\c!voetstatus ]%
   \setupheader[\c!status=\makeupparameter\c!hoofdstatus]%
   \setuptext  [\c!status=\makeupparameter\c!tekststatus]%
   \setupbottom[\c!status=\makeupparameter\c!onderstatus]%
   \setuptop   [\c!status=\makeupparameter\c!bovenstatus]%
   % this is needed, but no \setuplayout here; fails in texexec --fig=c
   \recalculatelayout} 

%D The standard page template is defined as follows: 

\definemakeup
  [\v!standaard]
  [\c!breedte=\zetbreedte,
   \c!hoogte=\teksthoogte,
   \c!voffset=\!!zeropoint,
   \c!hoffset=\!!zeropoint,
   \c!pagina=\v!rechts,
   \c!dubbelzijdig=\v!leeg]

\protect \endinput 
