%
%  $Id: draftinfo.sty 2251 2011-07-14 11:58:38Z sobaniec $
%
%  Drafts info for documents DCS group
%  by Cezary Sobaniec <cezary.sobaniec@cs.put.poznan.pl>
%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{draftinfo}[2010/09/30 v0.5 Draft Info package]

\RequirePackage[absolute]{textpos}
\RequirePackage{everypage}
\RequirePackage{calc}
\RequirePackage{ifthen}
\RequirePackage{xcolor}


\definecolor{draftinfocolor}{rgb}{0.3,0.3,0.3}

\renewcommand{\title}[1]{\renewcommand{\@title}{#1}%
                         \newcommand{\drafttitle}{#1}}

\textblockorigin{0mm}{0mm}

\newcommand{\@draftinfotextleft}{}
\newcommand{\draftinfotextleft}[1]{\renewcommand{\@draftinfotextleft}{#1}}
\newcommand{\@draftinfotextright}{\textbf{\thepage}}
\newcommand{\draftinfotextright}[1]{\renewcommand{\@draftinfotextright}{#1}}

\AtBeginDocument{
  \ifthenelse{\equal{\@draftinfotextleft}{}}
    {\ifthenelse{\isundefined{\svndate}}%
      {\renewcommand{\@draftinfotextleft}{\drafttitle,~~\the\year-\two@digits{\the\month}-\two@digits{\the\day}}}
      {\renewcommand{\@draftinfotextleft}{\texttt{Revision \svnrev,~~\svndate}}}}
    {}
}

\newcommand{\draftinfo}[5]{
  \begin{textblock*}{\the\textwidth}(#1,284mm)
    \sffamily\scriptsize\noindent%
    \let\thanks=\@gobble%
    \parbox[b]{#2\textwidth}{\textcolor{draftinfocolor}{#3}}%
      \hfill\parbox[b]{#4\textwidth}{\raggedleft{}\textcolor{draftinfocolor}{#5}}
  \end{textblock*}
}

\AddEverypageHook{
  \if@twoside
    \ifthenelse{\isodd{\thepage}}
      {\draftinfo{\oddsidemargin+1in}{0.8}{\@draftinfotextleft}{0.2}{\@draftinfotextright}}
      {\draftinfo{\evensidemargin+1in}{0.2}{\@draftinfotextright}{0.8}{\@draftinfotextleft}}
  \else
    {\draftinfo{\oddsidemargin+1in}{0.8}{\@draftinfotextleft}{0.2}{\@draftinfotextright}}
  \fi
}
