\ProvidesPackage{xxcolor}[2003/10/24 ver 0.1]
\NeedsTeXFormat{LaTeX2e}[1995/12/01]

% Copyright 2003 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt.

\RequirePackage[override]{xcolor}


% Command \colorhook
%
% Description:
%
% This command will be called before a color is used. The color that
% will be used is called @hookcolor. By changing the @hookcolor, that
% color can be transformed before its being used.
%
% Examples:
%
% \def\colorhook{\colorlet{@hookcolor}{@hookcolor!50!white}}

\def\colorhook{}


%
%
% Internals
%
%
\let\XXC@origdeclaredcolor=\XC@declaredcolor
\def\XC@undeclaredcolor[#1]#2{%
  \definecolor{@hookcolor}{#1}{#2}%
  \XXC@applycolorhook%
  \set@color\ignorespaces}
\def\XC@declaredcolor#1{%
  \colorlet{@hookcolor}{#1}%
  \XXC@applycolorhook%
  \set@color\ignorespaces}
\def\XXC@applycolorhook{%
  \XXC@origdeclaredcolor{@hookcolor}% for logging purposes
  \colorhook%
  \expandafter\let\expandafter\current@color%
    \csname\string\color@ @hookcolor\endcsname}
\let\@undeclaredcolor\XC@undeclaredcolor
\let\@declaredcolor\XC@declaredcolor

% ``Quiet'' version of definecolor
\def\XC@definecolor#1#2#3{%
  \@ifundefined{color@#2}%
    {\c@lor@error{model `#2'}}%
    {\csname color@#2\expandafter\endcsname
       \csname\string\color @#1\endcsname{#3}}}

   
\def\colorhook{\edef\XXC@args{{@hookcolor}{@hookcolor\colorcurrentmixin}}\expandafter\colorlet\XXC@args}
\def\pgfalternateextension{\colorcurrentmixin}


\def\globalcolorlet#1{%
  \@ifnextchar [{\@globalcolorlet{#1}}{\@globalcolorlet{#1}[]}}
\def\@globalcolorlet#1[#2]#3{%
  \XC@colorlet{#1}[#2]{#3}%
  \@namelet{XXC@tmp}{\string\color @#1}%
  \def\XXC@@glet{\global\let}%
  \expandafter\XXC@@glet\csname\string\color @#1\endcsname=\XXC@tmp%
  \@namelet{XXC@tmp}{\string\xcolor @#1}%
  \expandafter\XXC@@glet\csname\string\xcolor @#1\endcsname=\XXC@tmp}

% Environment colormixin
%  
% #1 = full xcolor specification after the first ! ("white" may not be
%      omitted)
%
% Description:
%
% Inside the environment, all colors get the specified mixin. May be
% nested. 
%
% Examples:
%
% \color{red}This is red.
% \begin{colormixin}{25!black}
%   This is dark red. 
%   \color{blue}
%   This is dark blue.
% \end{colormixin}
% This is normal red once more.

\newenvironment{colormixin}[1]%
{\edef\colorcurrentmixin{!#1\colorcurrentmixin}\color{.}}{}
\def\colorcurrentmixin{}

% needed, so that \normalcolor can be used in preamble
\let\default@color\current@color

\endinput

