%%
%% This is file `ocgtools.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ocgtools.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2010 by Robert Marik <marik@mendelu.cz>
%% 
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.2 of this license
%% or (at your option) any later version.  The latest version of this
%% license is in:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% and version 1.2 or later is part of all distributions of LaTeX version
%% 1999/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{ocgtools}
    [2010/04/01 v0.5 ocgtools.dtx  file]
\def\ocgtools@msg{If message does not disappear after a short time, the
  author either did not compile the \LaTeX{} file three times, or your
  PDF viewer does not support OCG. Use Adobe Reader!}

\def\ocgtextstart{\color{blue}}
\def\ocgtextend{}
\ifx\definecolor\undefined\RequirePackage{color}\fi
\ifx\href\undefined\RequirePackage[pdftex]{hyperref}\fi
\definecolor{ocgpaper}{rgb}{1,1,0.2}
\definecolor{ocgbg}{rgb}{0,0,0}
\RequirePackage{graphicx}
\RequirePackage{pifont}
\RequirePackage{ocg}

\def\ocgclosechar{\ding{56}}
\RequirePackage{atbegshi}
\RequirePackage[pdftex]{eforms}
\newif\if@ocgtools@transparent\@ocgtools@transparentfalse
\DeclareOption{transparent}{\@ocgtools@transparenttrue}
\newif\if@ocgtools@insertvisible\@ocgtools@insertvisiblefalse
\def\ocgtools@initialvisibility{0}
\DeclareOption{insertvisible}{\@ocgtools@insertvisibletrue
   \def\ocgtools@initialvisibility{1}}
\newif\ifocg@hide@button\ocg@hide@buttontrue
\DeclareOption{nobutton}{\ocg@hide@buttonfalse}
\newif\ifocgtools@noocg\ocgtools@noocgfalse
\DeclareOption{noocg}{\ocgtools@noocgtrue}
\def\ocgtools@progressmsg{\lower \layerVshift\hbox to 0 pt{ %space
  \textField[\V{OCGtools: processing OCG's ...}\BG{1}
  \textColor{1 0 0} \textSize{10}]%
{ocgtoolsmsg}{6cm}{20pt}\hss}}%
\DeclareOption{noprogressmsg}{\let\ocgtools@progressmsg\relax}
\newif\if@ocgtools@minimouseover \@ocgtools@minimouseoverfalse
\DeclareOption{minimouseover}{\@ocgtools@minimouseovertrue}
\newif\if@ocgtools@mouseover \@ocgtools@mouseoverfalse
\DeclareOption{mouseover}{\@ocgtools@mouseovertrue \@ocgtools@minimouseovertrue}
\newif\if@ocgtools@pageclose \@ocgtools@pageclosetrue
\DeclareOption{nopageclose}{\@ocgtools@pageclosefalse}
\ProcessOptions
\edef\ocgtools@pdfpageattr{
/AA << /O << /S /JavaScript /JS
  (
  try{
   var temp = ocgtoolsOCGs.length;
   \if@ocgtools@pageclose
   for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
     {
      ocgtoolsOCGs[i].state = false;
     }
   \fi
  }
  catch (e){
    app.focusRectg = false;
    var iniocgtoolsOCGs = this.getOCGs();
    var ocgtoolsOCGs = [];
    for(var i=0; iniocgtoolsOCGs && i<iniocgtoolsOCGs.length;i++)
     {
     if(iniocgtoolsOCGs[i].name.substr(0,8) == "ocgtools")
        {
          ocgtoolsOCGs.push(iniocgtoolsOCGs[i]);
          \if@ocgtools@insertvisible
          iniocgtoolsOCGs[i].state=false;
          \fi
        }
     }
    iniocgtoolsOCGs[0].state=true;
    iniocgtoolsOCGs[0].state=false;
    \ifx\ocgtools@progressmsg\relax\relax\else
    this.getField("ocgtoolsmsg").hidden=true;
    \fi
    }
    \ifocg@hide@button
     this.getField("OcgtoolsBtn.HideButton.main").hidden = true;
    \fi
    )
    >> >>
}

\expandafter\global\expandafter\pdfpageattr\expandafter{\ocgtools@pdfpageattr}

\def\ocgtools@transparent{}
\if@ocgtools@transparent
\RequirePackage{transparent} \def\ocgtools@transparent{\transparent{0.4}}
\fi
\newif\ifocg@minitext@left
\newif\ifocg@minitext@bottom
\newcount\ocgtools@layercount
\newskip\ocgtools@left@skip
\newskip\ocgtools@bottom@skip
\newdimen\ocgtools@maxheight
\newdimen\ocgtools@maxwidth
\newdimen\layerHshift \layerHshift=0pt
\newdimen\layerVshift \layerVshift=0pt
\ifx\@Rightmargin\undefined\else
  \layerVshift=3pt
\fi
\ifx\PDFSCR@Warning\undefined\else
  \layerVshift=\@Bottommargin
\fi

\newtoks\ocgtools@layer@toks
\ocgtools@layer@toks{}
\newbox\ocgtools@box@a
\newbox\ocgtools@box@b
\newif\ifocg@page@contains@layer
\def\ocgtools@one{1}
\let\ocgtools@shipoutstart@hook\relax
\let\ocgtools@shipoutend@hook\relax
\AtBeginShipout{%
\setbox\AtBeginShipoutBox=\hbox{%
\ocgtools@shipoutstart@hook
\hbox to 0 pt{\box\AtBeginShipoutBox\hss}\kern -1in\kern \layerHshift
\ocg@page@contains@layerfalse
\lower \layerVshift \hbox{\the\ocgtools@layer@toks}%
\ifocg@page@contains@layer
  \vbox to 0 pt{\kern -\paperheight \kern\layerVshift\hbox to 0 pt{\ocgtools@HideBtn\hss}\vss}%
\fi
\xdef\ocgtools@currpage{\thepage}%
\ifx\ocgtools@currpage\ocgtools@one
\ocgtools@progressmsg
\fi
\hss \ocgtools@shipoutend@hook%
\kern 1in \kern -\layerHshift%
}%
}
\def\ocgtools@HideBtn{\pushButton[\W{0}\BG{}\S{S}\BC{}\H{N}\F{\FHidden}\A{\JS{
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         ocgtoolsOCGs[i].state = false;
         }
         \ifocg@hide@button this.getField("OcgtoolsBtn.HideButton").hidden = true; \fi
       }}]{OcgtoolsBtn.HideButton.main}{\paperwidth}{\paperheight}}
\newcommand\ocgtools@HideMiniLayer[1]
{\setbox\ocgtools@box@a=\hbox{{\color{red}\ocgclosechar}}%
\hbox to \wd\ocgtools@box@a%
{\hbox{{\color{red}\ocgclosechar}}\hss%
\hbox{\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
\F{\FHidden}\A{\JS{
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = false;
         }
         this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden = true;
       }}]%
     {OcgtoolsBtn.HideButton.mini.#1}{\wd\ocgtools@box@a}{\ht\ocgtools@box@a}}}}
\newcommand\ocgtools@HideLayers[1]{%
\setbox\ocgtools@box@a=\hbox{{\color{red}\ocgclosechar}}%
\hbox to \wd\ocgtools@box@a%
{\hbox{{\color{red}\ocgclosechar}}\hss%
\hbox{\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
\F{\FHidden}\A{\JS{
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         ocgtoolsOCGs[i].state = false;
         }
         \ifocg@hide@button
         this.getField("OcgtoolsBtn.HideButton.main").hidden = true;
         \fi
       }}]%
     {OcgtoolsBtn.HideButton.corner.#1}{\wd\ocgtools@box@a}{\ht\ocgtools@box@a}}}}
\newcommand{\ocgtools@ToggleLayer}[2]{%
  % #1: layer name,
  % #2: link text
  \leavevmode%
  \pdfstartlink user {
    /Subtype /Link
    /Border [0 0 0]%
    /H /N
    /A <<
      /S/JavaScript
      /JS (
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = !ocgtoolsOCGs[i].state;
         else
         ocgtoolsOCGs[i].state = false;
         }
         \ifocg@hide@button this.getField("OcgtoolsBtn.HideButton.main").hidden = false;\fi
         this.getField("OcgtoolsBtn.HideButton.corner").hidden = false;
         this.getField("OcgtoolsBtn.HideButton.corner.#1").setFocus();
      )
    >>
  }#2%
    \if@ocgtools@mouseover
  \hbox to 0 pt{\hss\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
  \A{\JS{
        var OpenedByMouseEnter#1=false;
        \ifocg@hide@button this.getField("OcgtoolsBtn.HideButton.main").hidden = false;\fi
        this.getField("OcgtoolsBtn.HideButton.corner").hidden = false;
        this.getField("OcgtoolsBtn.HideButton.corner.#1").setFocus();
        }}
  \AA{\AAMouseEnter{\JS{         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         var OpenedByMouseEnter#1=true;
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = true;
         else
         ocgtoolsOCGs[i].state = false;
         }
         }}
  \AAMouseExit{\JS{
        if (OpenedByMouseEnter#1)
         {for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = false;
         }}
         }}}]
    {OcgtoolsBtn.MaxiButton.#1}{8pt}{8pt}}%
  \fi
  \pdfendlink%
}

\newcommand{\ocgtools@ToggleMiniLayer}[2]{%
  % #1: layer name,
  % #2: link text
  \leavevmode%
  \pdfstartlink user {
    /Subtype /Link
    /Border [0 0 0]%
    /H /N
    /A <<
      /S/JavaScript
      /JS (
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = !ocgtoolsOCGs[i].state;
         }
         this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden =
         !this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden;
         if (!this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden)
           {this.getField("OcgtoolsBtn.HideButton.mini.#1").setFocus();}
      )
    >>
  }#2%
  \if@ocgtools@minimouseover
  \hbox to 0 pt{\hss\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
  \A{\JS{
    var OpenedByMouseEnter#1=false;
    this.getField("OcgtoolsBtn.HideButton.mini.#1").setFocus();
   }}
  \AA{\AAMouseEnter{\JS{for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         var OpenedByMouseEnter#1=true;
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = true;
         }
         this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden = false;
         }}
  \AAMouseExit{\JS{
       if (OpenedByMouseEnter#1)
       {
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = false;
         }
         this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden = true;
       }
       }}}]
    {OcgtoolsBtn.MiniButton.#1}{8pt}{8pt}}%
  \fi
  \pdfendlink%
}

\newwrite\posHandle
\def\posFile{\jobname.pos}
\def\posOpen{\openout\posHandle=\posFile}
\def\posClose{\closeout\posHandle}
\ifocgtools@noocg
\else
\AtBeginDocument{\InputIfFileExists{\posFile}{}{}%
\ocgtools@maxheight=0.9\paperheight
\ocgtools@maxwidth=0.9\paperwidth
\expandafter\global\expandafter\def\csname ocgtools@textcontent@0\endcsname
{{\color{red}\bfseries\ocgtools@msg}}
\expandafter\ocgtools@layer@toks\expandafter{\the\ocgtools@layer@toks
\ocg@place@text{0}{1}{5cm}}
\posOpen}
\AtEndDocument{\posClose}
\fi

\newcommand\ocgpicture[2][]{%
\global\advance\ocgtools@layercount by 1%
\ocgtools@ToggleLayer{\the\ocgtools@layercount}%
{\leavevmode\includegraphics[#1]{#2}}%
\expandafter\write\expandafter\posHandle\expandafter{%
\expandafter\string\expandafter\ocgtoolsplacepicture\expandafter{%
\the\ocgtools@layercount}{\thepage}{#2}}%
}

\newcommand\ocgtext[3][0pt]{%
\global\advance\ocgtools@layercount by 1%
\ocgtools@ToggleLayer{\the\ocgtools@layercount}%
{\leavevmode{\ocgtextstart #2\ocgtextend}}%
\expandafter\write\expandafter\posHandle\expandafter{%
\expandafter\string\expandafter\ocgtoolsplacetext\expandafter{%
\the\ocgtools@layercount}{\thepage}{#1}}%
\expandafter\global\expandafter\def
\csname ocgtools@textcontent@\the\ocgtools@layercount\endcsname{#3}%
}

\newcommand\ocgminitextlt[3][0pt]{%
\ocg@minitext@lefttrue\do@ocg@minitext{#1}{#2}{#3}{lt}}%
\newcommand\ocgminitextrt[3][0pt]{%
\ocg@minitext@leftfalse\do@ocg@minitext{#1}{#2}{#3}{rt}}%
\newcommand\ocgminitextlb[3][0pt]{%
\ocg@minitext@lefttrue\do@ocg@minitext{#1}{#2}{#3}{lb}}%
\newcommand\ocgminitextrb[3][0pt]{%
\ocg@minitext@leftfalse\do@ocg@minitext{#1}{#2}{#3}{rb}}%
\let\ocgminitext\ocgminitextrt

\long\def\do@ocg@minitext#1#2#3#4{%
\global\advance\ocgtools@layercount by 1\relax%
\leavevmode
\ifocg@minitext@left
  \vbox to 0 pt{\kern 0.5\baselineskip\hbox to 0 pt{\hss\pdfsavepos}\vss}%
\fi
\ocgtools@ToggleMiniLayer{\the\ocgtools@layercount}%
{{\ocgtextstart #2\ocgtextend}}%
\ifocg@minitext@left\else\pdfsavepos\fi
\expandafter\write\expandafter\posHandle\expandafter{%
\expandafter\string\expandafter\ocgtoolsplaceminitext\expandafter
{\the\ocgtools@layercount}{\thepage}{\the\pdflastxpos}%
{\the\pdflastypos}{}{#1}{#4}}%
\expandafter\global\expandafter\def
\csname ocgtools@minitextcontent@\the\ocgtools@layercount\endcsname{#3}%
}%

\newcommand\ocgtoolsplacepicture[3]{%
\expandafter\global\expandafter\ocgtools@layer@toks\expandafter
{\the\ocgtools@layer@toks \ocg@place@picture{#1}{#2}{#3}}}

\newcommand\ocgtoolsplacetext[3]{%
\expandafter\global\expandafter\ocgtools@layer@toks\expandafter
{\the\ocgtools@layer@toks\ocg@place@text{#1}{#2}{#3}}}

\newcommand\ocgtoolsplaceminitext[7]{%
\expandafter\global\expandafter\ocgtools@layer@toks\expandafter
{\the\ocgtools@layer@toks \ocg@place@minitext{#1}{#2}{#3}{#4}{#5}{#6}{#7}}}

\def\ocg@place@picture#1#2#3{\def\tempnuma{#2}\edef\tempnumb{\thepage}%
\ifx\tempnumb\tempnuma
  \global\ocg@page@contains@layertrue
  \vbox to 0 pt{\vss\hbox to 0pt%
    {\hbox{\begin{ocg}{ocgtools#1}{ocgtools#1}{\ocgtools@initialvisibility}%
          \ocgtools@drawpicture{#3}{#1}\end{ocg}}\hss}}%
\fi}

\def\ocg@place@text#1#2#3{\def\tempnuma{#2}\edef\tempnumb{\thepage}%
\ifx\tempnumb\tempnuma
  \global\ocg@page@contains@layertrue
  \vbox to 0 pt{\vss\hbox to 0 pt{\hbox{%
    \begin{ocg}{ocgtools#1}{ocgtools#1}{\ocgtools@initialvisibility}%
      \ocgtools@drawtext{#3}{\csname ocgtools@textcontent@#1\endcsname}{#1}%
    \end{ocg}}\hss}}%
\fi}

\long\def\ocg@place@minitext#1#2#3#4#5#6#7{%
\def\tempnuma{#2}\edef\tempnumb{\thepage}%
\def\ocg@placement{#7}%
\def\ocg@rb{rb}\def\ocg@lb{lb}\def\ocg@rt{rt}\def\ocg@lt{lt}%
\ocg@minitext@leftfalse\ocg@minitext@bottomfalse
\ifx\ocg@placement\ocg@lb
  \ocg@minitext@lefttrue\ocg@minitext@bottomtrue
\fi
\ifx\ocg@placement\ocg@rb
  \ocg@minitext@leftfalse\ocg@minitext@bottomtrue\fi
\ifx\ocg@placement\ocg@lt
  \ocg@minitext@lefttrue\ocg@minitext@bottomfalse
\fi
\ifx\tempnumb\tempnuma
  \ocgtools@left@skip=#3sp minus #3sp%
  \ocgtools@bottom@skip=#4sp%
  \setbox\ocgtools@box@a=\hbox{\begin{ocg}{ocgtools#1}{ocgtools#1}{\ocgtools@initialvisibility}%
  \ocgtools@drawminitext{#6}{\csname ocgtools@minitextcontent@#1\endcsname}{#1}
  \end{ocg}}%
  \ifocg@minitext@left
    \ifdim \ocgtools@left@skip>\wd\ocgtools@box@a
      \advance \ocgtools@left@skip by -\wd\ocgtools@box@a plus 0 pt minus -\wd\ocgtools@box@a
    \else
      \ocgtools@left@skip=0pt\relax
    \fi
  \fi
  \ifocg@minitext@bottom
    \advance \ocgtools@bottom@skip by -\ht\ocgtools@box@a
  \fi
  \hbox to 0 pt{\hbox to \paperwidth{\hskip \ocgtools@left@skip
  \vbox to 0 pt{\vss
  \vbox to \paperheight{\vskip 0 pt plus 1 fill
  \box\ocgtools@box@a\vskip \ocgtools@bottom@skip}
  }%
  \hskip 0 pt plus 1 fill}\hss}%
\fi
}

\def\ocgtools@drawpicture#1#2{\vbox to \paperheight{\vbox to 0 pt{{%
\ocgtools@transparent\color{ocgbg}%
\hrule width \paperwidth height \paperheight}\vss}\vss
\hbox to \paperwidth{\hss
\setbox\ocgtools@box@a=\hbox{\includegraphics[height=\ocgtools@maxheight]{#1}}%
\ifdim\wd\ocgtools@box@a>\ocgtools@maxwidth
  \includegraphics[width=\ocgtools@maxwidth]{#1}\else \box\ocgtools@box@a
\fi
\hss}%
\vss
\hbox to \paperwidth {\hss\ocgtools@HideLayers{#2}}}}

\newdimen\ocg@textdimen

\long\def\ocgtools@drawtext#1#2#3{\vbox to \paperheight{%
\vbox to 0 pt{{\ocgtools@transparent\color{ocgbg}%
\hrule width \paperwidth height \paperheight}\vss}\vss\hbox to \paperwidth
{\hss
\ocg@textdimen=#1
\ifdim\ocg@textdimen=0pt
  \setbox\ocgtools@box@a=\hbox{\colorbox{ocgpaper}{#2}}%
\else
  \setbox\ocgtools@box@a=\hbox{\colorbox{ocgpaper}%
    {\vbox{\hsize=#1\relax\rightskip 0 pt plus 1 fil\relax #2}}}%
\fi
\setbox\ocgtools@box@b\hbox{\resizebox{!}{\ocgtools@maxheight}{\copy\ocgtools@box@a}}%
\ifdim\wd\ocgtools@box@b>\ocgtools@maxwidth
  \resizebox{\ocgtools@maxwidth}{!}{\box\ocgtools@box@a}
\else
  \box\ocgtools@box@b
\fi
\hss}%
\vss
\hbox to \paperwidth {\hss\ocgtools@HideLayers{#3}}}}

\def\ocg@empty{}

\newcommand\ocgtools@drawminitext[3]{\ocg@textdimen=#1
\ifdim\ocg@textdimen=0pt
  \setbox\ocgtools@box@a=\hbox{\colorbox{ocgpaper}{#2\ }}%
\else  \setbox\ocgtools@box@a=\hbox{\colorbox{ocgpaper}%
  {\vbox{\hsize=#1\relax\rightskip 0 pt plus 1 fil\relax #2}}}%
\fi
\def\temp{#3}%
\ifx\temp\ocg@empty
\box\ocgtools@box@a
\else
\hbox{\copy\ocgtools@box@a\raise\ht\ocgtools@box@a
\vbox to 0 pt{\hbox to 0 pt{\hss
\ocgtools@HideMiniLayer{#3}}\vss}}%
\fi
}

\ifocgtools@noocg
  \renewcommand\ocgpicture[2][]{\leavevmode\includegraphics[#1]{#2}}
  \renewcommand\ocgtext[3][0pt]{\leavevmode #2}
  \long\def\do@ocg@minitext#1#2#3#4{\leavevmode #2}%
  \renewcommand\ocgtoolsplacepicture[3]{}
  \renewcommand\ocgtoolsplacetext[3]{}
  \renewcommand\ocgtoolsplaceminitext[7]{}
\fi

\endinput
%%
%% End of file `ocgtools.sty'.
