%D \module
%D   [       file=page-not,
%D        version=2002.4.16,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Footnotes, 
%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 / Footnotes}

%D Terrible hacks: we need to share save/restore 

%D We've moved some footnote handling to a separate page 
%D module. The macros below are used in the single and multi
%D column page handlers and permit mixed usage of column and 
%D page notes. 

\unprotect 

\installbackupinsertion\footins

\def\checkbegincolumnfootnotes % should happen inside otr 
  {\ifcleverfootnotes
     \doflushnotes
     \saveinsertionbox\footins
   \else
     \eraseinsertionbackup\footins
   \fi
   \saveinsertiondata\footins
   \checknotes}

\def\checkendcolumnfootnotes
  {\restoreinsertiondata\footins % maybe better just \checknotes 
   \ifcleverfootnotes
     \restoreinsertionbox\footins
   \fi}

\def\checksinglecolumnfootnotes
  {\checknotes} % njet : \restoreinsertiondata\footins

\def\columnfootins % expands to an insert number 
  {\ifcleverfootnotes
     \backupinsertion\footins
   \else
     \footins
   \fi}

% wrong place 

\newdimen\totalinsertionheight

\def\settotalinsertionheight
  {\totalinsertionheight\zeropoint
   \addinsertionheight\topins       \to\totalinsertionheight
   \addinsertionheight\botins       \to\totalinsertionheight
   \addinsertionheight\columnfootins\to\totalinsertionheight}

% idem 

\def\enablenotes
  {\global\count\footins1000
   \global\skip\footins1\baselineskip\relax}

\def\disablenotes
  {\global\count\footins\zerocount
   \global\skip\footins \zeropoint}

% also 

%\def\flushsavedcolumnfootnotes
%  {\insert\footins{\unvbox\OTRSETsavedfootnotes}}
%
%\def\savecolumnfootnotes
%  {\global\setbox\OTRSETsavedfootnotes\vbox
%       {\unvbox\OTRSETsavedfootnotes\box\footins}}

\newbox\savednotes

\def\flushsavednotes
  {\ifvoid\savednotes\else
     \insert\footins{\unvbox\savednotes}%
   \fi}

\def\savenotes
  {\global\setbox\savednotes\vbox
     {\ifvoid\savednotes\else\unvbox\savednotes\fi
      \box\footins}}

% hm 

\installbackupinsertion\footins

\def\checkbegincolumnfootnotes % should happen inside otr 
  {\ifcleverfootnotes
     \doflushnotes
     \saveinsertionbox\footins
   \else
     \eraseinsertionbackup\footins
   \fi
   \saveinsertiondata\footins
   \checknotes}

\def\checkendcolumnfootnotes
  {\restoreinsertiondata\footins
   \ifcleverfootnotes
     \restoreinsertionbox\footins
   \fi}
 
\protect \endinput 
