% $Id: authortitle-ibid.cbx,v 0.9e 2010/10/09 16:39:36 lehman beta $

\ProvidesFile{authortitle-ibid.cbx}
[\abx@cbxid $Id: authortitle-ibid.cbx,v 0.9e 2010/10/09 16:39:36 lehman beta $]

\ExecuteBibliographyOptions{ibidtracker=constrict,pagetracker,autocite=footnote}
\providecommand*{\mkibid}[1]{#1}
\newbool{cbx:parens}
\newbool{cbx:loccit}

\DeclareBibliographyOption{ibidpage}[true]{%
  \ifstrequal{#1}{true}
    {\ExecuteBibliographyOptions{loccittracker=constrict}}
    {\ExecuteBibliographyOptions{loccittracker=false}}}

\newbibmacro*{cite}{%
  \global\boolfalse{cbx:loccit}%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
       {\usebibmacro{cite:ibid}}
       {\ifnameundef{labelname}
	  {}
	  {\printnames{labelname}%
           \setunit{\nametitledelim}}%
	\usebibmacro{cite:title}}}%
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{citetitle}{%
  \global\boolfalse{cbx:loccit}%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
       {\usebibmacro{cite:ibid}}
       {\usebibmacro{cite:title}}}%
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{textcite}{%
  \global\boolfalse{cbx:loccit}%
  \ifnameundef{labelname}
    {}
    {\printnames{labelname}%
     \setunit{%
       \global\booltrue{cbx:parens}%
       \addspace\bibopenparen}}%
  \ifnumequal{\value{citecount}}{1}
    {\usebibmacro{prenote}}
    {}%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
       {\usebibmacro{cite:ibid}}
       {\usebibmacro{cite:title}}}%
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{cite:title}{%
  \printtext[bibhyperref]{%
    \printfield[citetitle]{labeltitle}}}

\newbibmacro*{cite:shorthand}{%
  \printtext[bibhyperref]{\printfield{shorthand}}}

\newbibmacro*{cite:ibid}{%
  \printtext[bibhyperref]{\bibstring[\mkibid]{ibidem}}%
  \ifloccit
    {\global\booltrue{cbx:loccit}}
    {}}

\newbibmacro*{cite:postnote}{%
  \ifbool{cbx:loccit}
    {}
    {\usebibmacro{postnote}}}

\newbibmacro*{textcite:postnote}{%
  \ifthenelse{\iffieldundef{postnote}\OR\boolean{cbx:loccit}}
    {\ifbool{cbx:parens}
       {\bibcloseparen}
       {}}
    {\ifbool{cbx:parens}
       {\postnotedelim}
       {\addspace\bibopenparen}%
     \printfield{postnote}\bibcloseparen}}

\DeclareCiteCommand{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand*{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citetitle}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand*{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citetitle}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\boolfalse{cbx:parens}}
     {}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

\endinput
