%-- id --
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{cv-ydi}[1997/12/26 v0.0 internal draft]
%-- initial --
\newif\if@color
\newcommand\Section[1]{}
%-- options declaration
\DeclareOption{color}{\@colortrue}
\DeclareOption{nocolor}{\@colorfalse}
\DeclareOption{gradhead}{\renewcommand\Section[1]{\gradheadsection{#1}}}
\DeclareOption{ulhead}{\renewcommand\Section[1]{\underlinedsection{#1}}}
\DeclareOption{gradstrip}{\AtEndOfPackage{\def\@oddhead{\gradstrip}}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
%-- options execution
\ExecuteOptions{color,ulhead}
\ProcessOptions
%-- package loading
\LoadClass{report}
\RequirePackage{pifont}         % dingbats
\RequirePackage{times}          % PS font
\RequirePackage{mathptm}        % ...even in math
\RequirePackage{pstricks}       % visual effects
\RequirePackage{gradient}       % ...more
\RequirePackage{array}
\RequirePackage{calc}
\RequirePackage{ifthen}
\RequirePackage[full]{margins}
%-- .cv.aux file
\AtEndOfClass{%
  \InputIfFileExists{\jobname.cv.aux}{}{\message{No file \jobname.cv.aux.}}%
  \newwrite\@cvaux%
  \immediate\openout\@cvaux\jobname.cv.aux%
  }%
\AtEndDocument{%
  \makeatletter
  \immediate\closeout\@cvaux%
  % check if anything changed
  \newlength{\orig@col@width}\setlength{\orig@col@width}{\col@width}%
  \input{\jobname.cv.aux}
  \ifthenelse{\lengthtest{\col@width = \orig@col@width}}{}{%
    \typeout{Warning: column width has changed}%
    \typeout{Warning: rerun latex to get it right}%
    }%
  \makeatother
  }%
%-- special commands
\AtBeginDocument{%
  \PrintHeader%
%  \ifthenelse{\lengthtest{\col@width = 0cm}}{\setlength{\col@width}{15mm}}{}%
  \immediate\write\@cvaux{\string\setlength{\string\col@width}{\the\col@width}}%
  }%


%-- main part

%== misc ==
\newcmykcolor{stripcolor}{0.3 0 0.03 0}

%== commands ==
\newcommand{\Name}[2]{
  \def\my@firstname{#1}
  \def\my@name{#2}
  \renewcommand{\Name}{\typeout{Ignoring redefinition of `Name'}}
  }
\newcommand{\Age}[1]{
  \def\my@age{#1}
  \renewcommand{\Age}{\typeout{Ignoring redefinition of `Age}}
  }
\newcommand{\Address}[1]{
  \def\my@address{#1}
  \renewcommand{\Name}{\typeout{Ignoring redefinition of `Address'}}
  }
\newcommand{\Tel}[1]{
  \def\my@tel{#1}
  \renewcommand{\Name}{\typeout{Ignoring redefinition of `Tel'}}
  }
\newcommand{\Email}[1]{
  \def\my@email{#1}
  \renewcommand{\Name}{\typeout{Ignoring redefinition of `Email'}}
  }
\newcommand{\Word}[1]{
  \def\my@word{#1}
  \renewcommand{\Name}{\typeout{Ignoring redefinition of `Word'}}
  }
\newcommand{\Title}[1]{
  \def\my@title{#1}
  \renewcommand{\Name}{\typeout{Ignoring redefinition of `Title'}}
  }

% Unused for now
\newcommand{\WWWsite}[1]{
  \def\my@wwwsite{#1}
  \renewcommand{\Name}{\typeout{Ignoring redefinition of `WWWsite'}}
  }

\newlength\abovetitlespace
\setlength\abovetitlespace{2\fill}
%
\newcommand{\PrintHeader}{
  \begin{minipage}[htbp]{6cm}
    \raggedright \noindent
    {\Large\my@firstname\ \textsc{\my@name}}%
    \@ifundefined{my@age}{}{ --- \my@age}%
    \\
    \my@address\\
    \ding{38} \my@tel\\         % could be \ding{37}, "Tel.~" or "" as well
    \@ifundefined{my@email}{}{\ding{41} \texttt{\my@email}} % could be "E-Mail~:" as well
%    \@ifundefined{my@wwwsite}{}{\texttt{\my@wwwsite}}
  \end{minipage}
  \hfill
  \@ifundefined{my@word}{}{%
    \begin{minipage}[htbp]{6cm}
      \raggedleft \noindent \sl \my@word
    \end{minipage}%
    }
  \vspace{\abovetitlespace}
  \begin{center} 
    \Huge \my@title
  \end{center}
  \vfill
  }

%== gradstrip option ==
%
\setlength{\extrarowheight}{2mm}
%
\newlength{\gradstripwidth}
\newlength{\gradstriparoundleft}
\newlength{\gradstriparoundvert}
\setlength{\gradstripwidth}{5cm}
\setlength{\gradstriparoundleft}{7mm}
\setlength{\gradstriparoundvert}{7mm}
%
\newlength{\@stripl}
\newlength{\@stripr}
\newlength{\@stript}
\newlength{\@stripb}
\newlength{\@striptenth}
%
\newcommand{\gradstrip}{
  \if@color%
    \setlength{\@stripl}{- \textwidth - ( \gradstriparoundleft - 5mm ) }
    \setlength{\@stripr}{\gradstripwidth + ( \gradstriparoundleft - 5mm ) - \textwidth}
    \setlength{\@stript}{\gradstriparoundvert}
    \setlength{\@stripb}{ - \gradstriparoundvert - \textheight}
    \setlength{\@striptenth}{0.9\gradstripwidth - \textwidth}
    \psframe[linestyle=none,%
    fillstyle=gradient,gradbegin=stripcolor,gradend=white,%
    gradangle=90,gradmidpoint=.9,gradlines=1000%
    ](\@stripl,\@stript)(\@stripr,\@stripb)
    \psframe[linestyle=none,%
    fillstyle=solid,fillcolor=white%
    ](\@striptenth,\@stript)(\@stripr,\@stripb)%
  \fi
  }


%== environments ==
%
%% a list of skills
\newenvironment{skilllist}[1]{
\item \textbf{#1}
  \begin{dinglist}{235}
    }{\end{dinglist}}
%
%% A section embedding list
\newenvironment{listsection}[2][0pt]{%
  \Section{#2}
  \begin{list}{\ding{227}}{%\setlength\itemsep{#1}%     FIXME: doesn't work !
      } }{\end{list}}
%
%% A chronologic section
%
\newif\if@inchronology%
\newlength\col@width%
\newlength\this@width%
%
% internal: write to .cv.aux file
\newcommand{\@cvaux@write}[1]{%
  \settowidth{\this@width}{#1}%
  \ifthenelse{\lengthtest{\this@width > \col@width}}{%
    \immediate\write\@cvaux{%
      \string\ifthenelse{\string\lengthtest{\string\col@width < \the\this@width}}%
      {\string\setlength{\string\col@width}{\the\this@width}}{}}%
    }{}\mbox{#1}}%
%
% Usage: \simpleevent[length]{date}{details}
\newcommand{\simpleevent}[3][]{%
  \if@inchronology%
    \ifthenelse{\equal{#1}{}}{}{\@cvaux@write{#1}\par}%
    \@cvaux@write{#2} & #3\\%
  \else
    \typeout{WARNING: ignoring simpleevent outside of chronology environment}%
  \fi
  }%
%
% Usage: \captionevent[length]{date}{caption}{details}
\newcommand{\captionevent}[4][]{%
  \if@inchronology%
    \ifthenelse{\equal{#1}{}}{}{\@cvaux@write{#1}\par}%
    \@cvaux@write{#2}\par%
    \@cvaux@write{\small #3}%
    & #4\\%
  \else
    \typeout{WARNING: ignoring captionevent outside of chronology environment}%
  \fi
  }%
%
\newlength{\@col@two}
%
\newcommand{\chronosep}{\ding{223}}
\newlength{\@chronosepwidth}
%
\newenvironment{chronology}{%
  \@inchronologytrue%
  \settowidth{\@chronosepwidth}{\chronosep}%
  \setlength{\@col@two}{\textwidth - 4\tabcolsep - \@chronosepwidth - \col@width}%
  \begin{tabular}{p{\col@width}!{\chronosep}p{\@col@two}}%
  }{%
  \end{tabular}%
  \@inchronologyfalse%
  }

%== section-like commands
%
%% a section with a gradient header
\newcommand\gradheadheight{1ex}
\newcommand\gradheadoffset{0ex}
\newlength\gradhead@top
\newcommand{\gradheadsection}[1]%
{\if@color%
  \section*{%
    \setlength\gradhead@top{\gradheadheight + \gradheadoffset}%
    \psframe[linestyle=none,linewidth=0,%
      fillstyle=gradient,gradbegin=stripcolor,gradend=white,%
      gradangle=90,gradmidpoint=.9,gradlines=5000%
      ](0,\gradheadoffset)(\linewidth,\gradhead@top)%
      % erase the bad 10%
      \psframe[fillstyle=solid,fillcolor=white,linestyle=none,linewidth=0]%
      (.9\linewidth,\gradheadoffset)(\linewidth,\gradhead@top)%
      #1%
      }%
  \else% no strip in grey mode
    \section*{#1}%
  \fi%
  }
%
%% a section with an underline till right end of paper
\newlength\underlinespacing
\setlength\underlinespacing{1pt}
\newcommand{\underlinedsection}[1]%
{\section*{#1\vspace{\underlinespacing}\hrule}}
