%%
%% This is file `interfaces-bookmark.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% interfaces.dtx  (with options: `bookmark')
%% 
%% This is a generated file.
%% 
%% interfaces : 2010/11/26 v2.4 - interfaces : interfaces with keys for other packages (FC)
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 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
%% 
%% This work consists of the main source file interfaces.dtx
%% and the derived files
%%     interfaces.sty, interfaces.pdf, interfaces.ins,
%%     interfaces-base.sty,
%%     interfaces-LaTeX.sty,
%%     interfaces-tikz.sty,
%%     interfaces-titlesec.sty,
%%     interfaces-hyperref.sty,
%%     interfaces-bookmark.sty,
%%     interfaces-hypbmsec.sty,interfaces-hypbmsec.code.tex,
%%     interfaces-fancyhdr.sty,
%%     interfaces-marks.sty,
%%     interfaces-tocloft.sty,
%%     interfaces-makecell.sty,
%%     interfaces-enumitem.sty,
%%     interfaces-truncate.sty,
%%     interfaces-appendix.sty,
%%     interfaces-embedfile.sty,
%%     interfaces-environ.sty,
%%     interfaces-umrand.sty,
%%     interfaces-scrlfile.sty,
%%     interfaces-pgfkeys.sty,
%%     interfaces-etoolbox.sty
%% 
%% interfaces: interfaces with keys for other packages (FC)
%% Copyright (C) 2010 by Florent Chervet <florent.chervet@free.fr>
%% 
\ProvidesPackage{interfaces-bookmark}
   [2010/11/15 v2.1 more control on bookmarks (FC)]
\RequirePackage{interfaces-base}
\RequirePackage{interfaces-hyperref}
\RequirePackage{refcount}
\itf@Check@Package{bookmark}
\itf@pgfkeys
\expandafter\itf@patch\expandafter\patchcmd\csname\string\bookmark\endcsname
   {\immediate\write\@mainaux}{\itf@BKM@write}
   {\PackageInfo{interfaces-bookmark}
      {Command \expandafter\string\csname\string\bookmark\endcsname\space
      successfully patched!}}
   {\PackageWarning{interfaces-bookmark}
      {Command \expandafter\string\csname\string\bookmark\endcsname\space
      could not be patched\MessageBreak
      Loading of interfaces-bookmark is canceled}%
      \endinput}
\global\let\itf@BKM@enable\@ne % 0 = disable*, 1=enable, \@M = disable
\pgfqkeys{/itf/bookmark}{%
   disable/.true=\global\let\itf@BKM@enable\@M,%
   disable/.false=\global\let\itf@BKM@enable\@ne,%
   disable*/.true=\global\let\itf@BKM@enable\z@,%
   disable*/.false=\global\let\itf@BKM@enable\@ne,%
   atend/.true=\ifnum\itf@BKM@enable>0\edef\itf@BKM@enable{\number-\itf@BKM@enable}\fi,%
   atend/.false=\ifnum\itf@BKM@enable<0\edef\itf@BKM@enable{\number-\itf@BKM@enable}\fi,%
   bold*/.true=\pgfqkeys{/itf/bookmark}{@save={bold=true}},%
   bold*/.false=\pgfqkeys{/itf/bookmark}{@save={bold=false}},%
   bold*/@blank/.code=\pgfqkeys{/itf/bookmark/@restore}{bold},%
   bold*/.blank=@blank,%
   italic*/.true=\pgfqkeys{/itf/bookmark}{@save={italic=true}},%
   italic*/.false=\pgfkeys{/itf/bookmark}{@save={italic=false}},%
   italic*/@blank/.code=\pgfqkeys{/itf/bookmark/@restore}{italic},%
   italic*/.blank=@blank,%
   color*/.code={\ifblank{#1}
      {\pgfqkeys{/itf/bookmark/@restore}{color}}
      {\pgfqkeys{/itf/bookmark}{@save={color={#1}}}}%
   },%
   @save/.code={%
      \pgfkeysifdefined{/itf/bookmark/@save/color}{}
         {\pgfkeyslet{/itf/bookmark/@save/color}\BKM@color}%
      \pgfkeysifdefined{/itf/bookmark/@save/FontStyle}{}
         {\pgfkeyslet{/itf/bookmark/@save/FontStyle}\BS@BKM@FontStyle}%
      \pgfkeysifdefined{/itf/bookmark/@save/grouplevel}{}
         {\pgfkeysEsetvalue{/itf/bookmark/@save/grouplevel}{\the\currentgrouplevel}}%
      \pgfkeysaddvalue{/itf/bookmark/*}{}{,#1}%
      \bookmarksetup{#1}%
   },%
   @restore/color/.code=%
      \pgfkeysifdefined{/itf/bookmark/@save/color}
         {\pgfkeysgetvalue{/itf/bookmark/@save/color}\BKM@color}
         {},%
   @restore/FontStyle/.code=%
      \pgfkeysifdefined{/itf/bookmark/@save/FontStyle}
         {\pgfkeysgetvalue{/itf/bookmark/@save/FontStyle}\BS@BKM@FontStyle}
         {},%
   @restore/.code={%
      \pgfkeysifdefined{/itf/bookmark/@save/color}
         {\pgfkeysgetvalue{/itf/bookmark/@save/color}\BKM@color}
         {}%
      \pgfkeysifdefined{/itf/bookmark/@save/FontStyle}
         {\pgfkeysgetvalue{/itf/bookmark/@save/FontStyle}\BS@BKM@FontStyle}
         {}%
      \pgfkeysifdefined{/itf/bookmark/@save/grouplevel}
         {% shortcut: \bookmarksetup{bold*} called inside main group (level 0)
         \ifnum\pgfkeysvalueof{/itf/bookmark/@save/grouplevel}=\z@
            \global\pgfkeyslet{/itf/bookmark/@save/FontStyle}\@undefined
            \global\pgfkeyslet{/itf/bookmark/@save/color}\@undefined
            \global\pgfkeyslet{/itf/bookmark/@save/grouplevel}\@undefined
            \global\pgfkeyslet{/itf/bookmark/*}\@undefined
            \global\let\BKM@color\BKM@color
            \global\let\BS@BKM@FontStyle\BS@BKM@FontStyle
         \else % restore after each group as needed
            \pgfkeyslet{/itf/bookmark/@save/FontStyle}\@undefined
            \pgfkeyslet{/itf/bookmark/@save/color}\@undefined
            \pgfkeyslet{/itf/bookmark/*}\@undefined
            \ifnum\currentgrouplevel>\z@
               \aftergroup\itf@BKM@restore
            \else
               \pgfkeyslet{/itf/bookmark/@save/grouplevel}\@undefined
         \fi\fi
         }
         {}%
   },%
   @restore/bold/.code={% bold is "hidden" in \BS@BKM@FontStyle
      \begingroup
         \edef\itf@tp{\bookmarkget{bold}}%
         \pgfqkeys{/itf/bookmark/@restore}{FontStyle}%
         \count@=\bookmarkget{bold}%
         \edef\itf@tp{\endgroup
            \ifnum\itf@tp=\count@
            \else \noexpand\bookmarksetup{%
                        bold\ifcase\count@ =false\fi}\fi
         }\itf@tp},%
   @restore/italic/.code={% italic is "hidden" in \BS@BKM@FontStyle
      \begingroup
         \edef\itf@tp{\bookmarkget{italic}}%
         \pgfqkeys{/itf/bookmark/@restore}{FontStyle}%
         \count@=\bookmarkget{italic}%
         \edef\itf@tp{\endgroup
            \ifnum\itf@tp=\count@
            \else \noexpand\bookmarksetup{%
                        italic\ifcase\count@ =false\fi}\fi
         }\itf@tp},%
}
\def\itf@BKM@restore{%
   \pgfkeysifdefined{/itf/bookmark/@save/grouplevel}
      {\pgfkeysalso{/itf/bookmark/@restore}}
      {}%
}% \itf@BKM@restore
%% Plug the BKM keys in the interfaces pgfkeys (not efficient but quickly written...)
\define@key{BKM}{disable}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/disable={#1}}}
\define@key{BKM}{disable*}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/disable*={#1}}}
\define@key{BKM}{bold*}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/bold*={#1}}}
\define@key{BKM}{italic*}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/italic*={#1}}}
\define@key{BKM}{color*}[]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/color*={#1}}}
\define@key{BKM}{atend}[true]{\itf@pgfkeys\pgfkeysalso{/itf/bookmark/atend={#1}}}%
\def\itf@BKM@write#1{%
   \aftergroup\itf@BKM@restore
   \ifcase\itf@BKM@enable
      \global\let\itf@BKM@enable\@ne
   \or
      \immediate\write\@mainaux{#1}%
   \else
      \ifcase -\itf@BKM@enable  % (case -0 = 0 tested before)
      \or                       % (case -1 = enable but At End)
         \let\itf@BKM@enable\@ne
         \edef\itf@tp{\immediate\write\@mainaux{#1}}%
         \expandafter\BookmarkAtEnd\expandafter{\itf@tp}%
      \fi
   \fi
}% \itf@BKM@write
%% pageref=  key for \bookmark (using refcount : \getpagerefnumber)
\def\itf@BKM@pageref[#1]{%
   \expandafter\itf@BKM@@pageref
      \csname r@#1\endcsname{#1}%
}% \itf@BKM@pageref
\def\itf@BKM@@pageref#1#2{%
   \ifx#1\relax
      \protect\G@refundefinedtrue
      \@latex@warning{%
         Hyper reference `#2' on page \thepage \space undefined
         \MessageBreak for bookmark destination page
       }%
   \fi
   \edef\BKM@page{\getrefbykeydefault{#2}{page}{1}}%
}% \itf@BKM@@pageref
\define@key{BKM}{pageref}{%
   \Hy@babelnormalise\itf@BKM@pageref[{#1}]}
%% ref=  key for \bookmark
\def\itf@BKM@ref[#1]{%
   \expandafter\itf@BKM@@ref
      \csname r@#1\endcsname{#1}%
}% \itf@BKM@ref
\def\itf@BKM@@ref#1#2{%
   \ifx#1\relax
      \protect\G@refundefinedtrue
      \@latex@warning{%
         Hyper reference `#2' on page \thepage \space undefined
         \MessageBreak for bookmark destination
       }%
      \def\BKM@dest{??}%
   \else
      \edef\BKM@dest{\expandafter\@fourthoffive#1\@empty\@empty}%
   \fi
}% \BKM@@ref
\define@key{BKM}{ref}{%
   \Hy@babelnormalise\itf@BKM@ref[{#1}]}
\endinput
%%
%% End of file `interfaces-bookmark.sty'.
