%D \module
%D   [       file=page-inf,   % moved from page-ini
%D        version=2011.12.07, % 2000.10.20,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Tracing Info,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%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 / Tracing Info}

% this needs a real cleanup .. will be a more detailed list

\unprotect

\installcorenamespace{layoutinfo}

\newtoks\everyresetversion
\newtoks\everysetupversion

\let\currentversioninfo\empty

\unexpanded\def\setupversion
  {\dosingleargument\page_info_setup}

\let\version\setupversion

\let\page_info_add_to_box\gobbleoneargument

\def\page_info_setup[#1]%
  {\the\everyresetversion
   \ifcsname\??layoutinfo#1\endcsname
     \edef\currentversioninfo{#1}%
     \let\page_info_add_to_box\page_info_add_to_box_indeed
   \else
     \let\currentversioninfo\empty
     \let\page_info_add_to_box\gobbleoneargument
   \fi
   \the\everysetupversion}

\unexpanded\def\page_info_place_info % at the bottom of the page
  {\csname\??layoutinfo\currentversioninfo\endcsname}

\unexpanded\def\installversioninfo#1#2%
  {\setvalue{\??layoutinfo#1}{#2}}

\unexpanded\def\includeversioninfo#1%
  {\csname\??layoutinfo#1\endcsname}

\installversioninfo\v!concept
  {\vskip6\points
   \hbox to \makeupwidth
     {\infofont
      \v!concept:\space\currentdate
      \hss
      \page_adapts_status_info}}

\installversioninfo\v!file
  {\vskip6\points
   \hbox to \makeupwidth
     {\infofont
      \getmessage\m!system{27}:\space\currentdate\space
      \donefalse
      \ifx\currentproject  \empty \else \space\v!project  :\space\currentproject  \space \donetrue \fi
      \ifx\currentproduct  \empty \else \space\v!product  :\space\currentproduct  \space \donetrue \fi
      \ifx\currentcomponent\empty \else \space\v!component:\space\currentcomponent\space \donetrue \fi
      \ifdone                     \else \space\v!file     :\space\jobname         \space           \fi
      \hss
      \page_adapts_status_info}}

\installversioninfo\v!temporary
  {\includeversioninfo\v!file}

\appendtoks
    \overfullrule\zeropoint
\to \everyresetversion

\appendtoks
    \ifx\currentversioninfo\v!temporary
        \overfullrule5\points
    \fi
\to \everysetupversion

\newbox\b_page_versions

\def\page_info_add_to_box_indeed#1%
  {\scratchdimen\wd#1%
   \setbox\b_page_versions\vbox to \ht#1%
     {\vfill
      \settexthoffset
      \hsize\dimexpr\scratchdimen-2\texthoffset\relax
      \hskip\texthoffset % brrrr
      \vbox to \zeropoint{\vss\page_info_place_info}%
      \vskip\bodyfontsize}%
   \dp\b_page_versions\zeropoint
   \wd\b_page_versions\scratchdimen
   \setbox#1\hbox{\box#1\hskip-\scratchdimen\box\b_page_versions}}

\setupversion % resets
  [\v!final]

\protect \endinput
