% \iffalse meta-comment
%
% TUDa-CI -- Corporate Design for TU Darmstadt
% ----------------------------------------------------------------------------
%
%  Copyright (C) 2018--2025 by Marei Peischl <marei@peitex.de>
%
% ============================================================================
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% 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.3c or later is part of all distributions of LaTeX
% version 2008/05/04 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is
%   Marei Peischl <tuda-ci@peitex.de>
%
% The development repository can be found at
% https://github.com/tudace/tuda_latex_templates
% Please use the issue tracker for feedback!
%
% ============================================================================
%
% \fi
%
% \iffalse% no documentation on this
% \iffalse^^A Preparation for real docstrip documentation
%<*driver>
\ProvidesFile{beamerouterthemeTUDa.dtx}
  [2025-11-13 v4.05 Outer~beamer~theme~of~tuda-ci]
\typeout{***********************************************************}
\typeout{No documentation included in this file! Please see tuda-ci.pdf for more information and DEMO-TUDaBeamer.tex/.pdf for an example of use.}
\typeout{***********************************************************}
\stop
%</driver>
%<*initialize&package>
%<@@=ptxcd>
\NeedsTeXFormat{LaTeX2e}[2022/06/01]
%<!2008>\ProvidesExplPackage{beamerouterthemeTUDa}{2025-11-13}{4.05}{Outer beamer theme of tuda-ci design of 2023}
%<2008>\ProvidesExplPackage{beamerouterthemeTUDa2008}{2025-11-13}{4.05}{Outer beamer theme of tuda-ci, compatibility for design of 2008}
%</initialize&package>
%
%<*driver>^^A Preparation for real docstrip documentation
\providecommand*{\TUDaDocDTXfiles}{beamerouterthemeTUDa.dtx}
\input{tuda-ci.dtx}
%</driver>
% \fi
%
% \changes{v4.00}{2025-01-26}{Converted to DTX file}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \DescribeKey{\beamerframe}{\bgcolor}
%
%
% \DescribeKey{\beamerframe}{\uppercase}
%
%
% \DescribeMacro{\setupTUDaFrame}
%
%
% \DescribeKey{\beamerframe}{\bgcolor}

%
% \MaybeStop{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
%<*initialize>
% \fi
%    \begin{macrocode}
\PassOptionsToPackage{paper=slide}{tudarules}
\RequirePackage{tudarules}
\bool_if_exist:NF \l_ptxcd_tmpa_bool {\bool_new:N \l_ptxcd_tmpa_bool}
\dim_new:N \l_@@_beamer_extraindent_dim
\dim_new:N {\g_@@_beamer_sep_dim}
\dim_gset:Nn \g_@@_beamer_sep_dim {.3\c_ptxcd_logoheight_dim}
\dim_new:N \g_@@_beamer_logosep_dim
\dim_gset:Nn \g_@@_beamer_logosep_dim{2mm}
\cs_if_exist:NF \g_@@_colorframetitle_bool {\bool_new:N \g_@@_colorframetitle_bool}
\keys_define:nn {ptxcd/beamer/outer} {
  logo .bool_gset:N = \g_ptxcd_headlinelogo_bool,
  logo .default:n =true,
  logo .initial:n =true,
%<main>  colorframetitle .code:n = \msg_warning:nnn {tudabeamer} {option-removed} {colorframetitle},
%<*2008>
  colorframetitle .choices:nn = {true, false} {
    \use:c {bool_gset_ \l_keys_choice_tl :N} \g_@@_colorframetitle_bool
    \cs_if_exist_use:N  \_@@_setup_frametitle_color:
  },
  colorframetitle .default:n = true,
%    \end{macrocode}
% \iffalse
%</2008>
% \fi
%    \begin{macrocode}
  centerframetitle
%<main>     .code:n = \msg_warning:nnn {tudabeamer} {option-removed},
%    \end{macrocode}
% \iffalse
%<*2008>
% \fi
%    \begin{macrocode}
    .bool_gset:N = \g_ptxcd_centerframetitle_bool,
  centerframetitle .initial:n = false,
  centerframetitle .default:n = true,
%    \end{macrocode}
% \iffalse
%</2008>
% \fi
%    \begin{macrocode}
  framebgcolor
%<main>    .code:n = \msg_warning:nnn {tudabeamer} {option-removed} {framebgcolor},
%    \end{macrocode}
% \iffalse
%<*2008>
% \fi
%    \begin{macrocode}
    .choice:,
  framebgcolor / reset .code:n =
    \_@@_reset_framebgcolor:
  ,
  framebgcolor / unknown .code:n = {
    \_@@_set_framebgcolor:n {#1}
  },
%    \end{macrocode}
% \iffalse
%</2008>
% \fi
%    \begin{macrocode}
  singleframebgcolor .code:n =
%<main>    \msg_warning:nnn {tudabeamer} {option-removed} {singleframebgcolor},
%<*2008>
    \cs_gset_eq:Nc \_@@_save_background_canvas: {beamer@thcbg@normal~text}
    \keys_set:nn {ptxcd/beamer/outer} {
      framebgcolor = #1
    },
%    \end{macrocode}
% \iffalse
%</2008>
% \fi
%    \begin{macrocode}
  headsepline
%<main>    .code:n = \msg_warning:nnn {tudabeamer} {option-removed} {headsepline},
%<*2008>
    .bool_gset:N = \g_ptxcd_headsepline_bool,
  headsepline .initial:n = true,
  headsepline .default:n = true,
%    \end{macrocode}
% \iffalse
%</2008>
%<*main>
% \fi
%    \begin{macrocode}
  extendedspace .bool_gset:N = \g_@@_extended_space_bool,
  headrule .bool_gset:N = \g_@@_headrule_bool,
  uppercase-frametitle .bool_gset:N = \g_@@_uppercase_frametitle_bool,
  uppercase-frametitle .default:n = true,
  uppercase-frametitle .initial:n = true,
%</main>
%    \end{macrocode}
% \iffalse
%</initialize>
%<*body>
% \fi
% General options
%    \begin{macrocode}
%<gobble>}
%    \end{macrocode}
% \iffalse
%<*main>
% \fi
% \begin{key}{beamerframe}{uppercase}
%    \begin{macrocode}
\define@key{beamerframe}{uppercase}{
  \keys_set:nn {ptxcd/beamer/outer} {
    uppercase-frametitle=#1
  }
}
%    \end{macrocode}
% \iffalse
%</main>
% \fi
% \end{key}
% \begin{key}{beamerframe}{bgcolor}
% \iffalse
%<*2008>
% \fi
%    \begin{macrocode}
\define@key{beamerframe}{bgcolor}{
  \keys_set:nn {ptxcd/beamer/outer} {
    singleframebgcolor=#1
  }
}
%    \end{macrocode}
% \end{key}
%
%    \begin{macrocode}
\cs_new:Nn \_@@_reset_framebgcolor: {
  \cs_gset_eq:cN {beamer@thcbg@normal~text} \_@@_save_background_canvas:
  \cs_undefine:N \_@@_save_background_canvas:
}

\cs_new:Nn \_@@_set_framebgcolor:n {
    \cs_if_exist:cTF {\string\color@#1}
    {\setbeamercolor{normal~text}{bg=#1}}
    {\setbeamercolor{normal~text}{bg=TUDa-#1}}
}

\BeforeBeginEnvironment{frame}{
  \cs_if_exist:NT \_@@_save_background_canvas: {
  \_@@_reset_framebgcolor:
  }
}
%    \end{macrocode}
% \iffalse
%</2008>
% \fi
%    \begin{macrocode}
\ProcessKeyOptions[ptxcd/beamer/outer]
\mode<presentation>
\RequirePackage{graphicx}
%    \end{macrocode}
% \iffalse
%<*2008>
% \fi
%    \begin{macrocode}
\bool_if:NT \g_@@_colorframetitle_bool

  {\dim_set:Nn \l_@@_beamer_extraindent_dim {\g_@@_beamer_logosep_dim}}
%    \end{macrocode}
% \iffalse
%</2008>
% \fi
%    \begin{macrocode}
\setbeamersize{

  text~margin~left=\dim_eval:n {
%<main>  \paperwidth/34
%<2008>  \g_@@_beamer_sep_dim+\l_@@_beamer_extraindent_dim
},
  text~margin~right=\dim_eval:n {
%<main>  \paperwidth/38
%<2008>  \g_@@_beamer_sep_dim+\l_@@_beamer_extraindent_dim
  }
}
\cs_new:Nn \_@@_beamer_linewidth: {\dim_eval:n {\paperwidth-\beamer@leftmargin-\beamer@rightmargin}}
%    \end{macrocode}
%Logo
%
%    \begin{macrocode}
\box_new:N \g_@@_logo_box
\hbox_gset:Nn \g_@@_logo_box {%
%<main>  \raisebox{\dim_eval:n {-\height+.33\c_ptxcd_logoheight_dim}}
%<2008>  \makebox[\_@@_logowidth:][l]
    {\_@@_insert_logo:}%
}
% \begin{macro}{\logo}
%    \begin{macrocode}
\RenewDocumentCommand{\logo}{sm}{
\IfBooleanTF{#1}{
\setbeamertemplate{logo}{\resizebox{!}{.06\beamer@paperheight}{\mbox{#2}}}
}{
\setbeamertemplate{logo}{#2}
}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\setupTUDaFrame}
%    \begin{macrocode}
\newcommand*{\setupTUDaFrame}[1]{
  \keys_set:nn {ptxcd/beamer/outer} {#1}
%<2008>  \ptxcd_setup_frame:
}
%    \end{macrocode}
% \end{macro}
% \iffalse
%<*main>
% \fi
%    \begin{macrocode}
\defbeamertemplate*{footline}{TUDa2023}{
  \begin{beamercolorbox}[leftskip=\beamer@leftmargin,rightskip=\beamer@rightmargin]{footline}
  \usebeamerfont{footline}
  \rlap{\insertshortdate}
  \hfill
  \makebox[0pt][c]{
    \bool_set_false:N \l_ptxcd_separate_bool
    \clist_map_variable:nNn {department, institute, author} \l_tmpa_tl {
      \tl_if_empty:cF {beamer@short\l_tmpa_tl} {
        \bool_if:NTF \l_ptxcd_separate_bool
           {\usebeamertemplate{footline~sep}}
          {\bool_set_true:N  \l_ptxcd_separate_bool}
        \use:c {insertshort\l_tmpa_tl}
      }
    }
  }
  \hfill
  \llap{\insertframenumber}
  \par\vspace{-\dp\strutbox}
  \end{beamercolorbox}
  \skip_vertical:n {\dimexpr\paperheight/32-\dp\strutbox}
}
\setbeamertemplate{footline~sep}{\space\smash{\rule[-.5\dp\strutbox]{.25pt}{\ht\strutbox}}\space}
\defbeamertemplate*{headline}{TUDa2023}{
  \bool_if:NT \g_@@_headrule_bool {
    \cs_if_exist:NF \ptxcd_beamer_headrule {
      \ptxcd_makeheadrule[color=identbarcolor,width=\paperwidth]{ptxcd_beamer_headrule}
    }
    \ptxcd_beamer_headrule\par\nointerlineskip
  }
  \bool_if:NTF \g_@@_extended_space_bool {
    \bool_if:NTF \g_@@_headrule_bool {
      \skip_vertical:n {\dim_eval:n {+\paperheight/38}}
      \strut
    } {
      \skip_vertical:n {\dim_eval:n {\paperheight/16}}
    }
  }{
    \skip_vertical:n {\dimexpr\paperheight/38}
    \hspace*{\beamer@leftmargin}\rlap{\usebeamertemplate***{title~in~head/foot}}
  }
  \hspace*{\fill}
  \bool_if:NT \g_ptxcd_headlinelogo_bool  {
  %partnerlogo
  \bool_if:NT \g_@@_extended_space_bool \smash {
    \raisebox{\dimexpr-\height+\ht\strutbox}{
      \box_use:N \g_@@_partnerlogo_box
    }
  }
  \skip_horizontal:n {\dimexpr\paperheight/38}
  %logo
  \bool_if:NTF \g_@@_headrule_bool {
    \raisebox{2mm}[0pt][0pt]{\setlength{\fboxsep}{\z@}\colorbox{white}{\rule{\z@}{\dim_eval:n {\box_ht:N \g_@@_logo_box+\box_ht:N \ptxcd_beamer_headrule_box + \box_dp:N \ptxcd_beamer_headrule_box+1pt}}\box_use:N \g_@@_logo_box}}
      \hspace*{10pt}
  } {
    \bool_if:NT \g_@@_extended_space_bool \smash {\box_use:N \g_@@_logo_box}
    \hspace*{.7pt}
  }
  }
  \par
}
\setbeamertemplate{title~in~head/foot}{
  \bool_set_false:N \l_ptxcd_separate_bool
  \tl_if_empty:NF {\beamer@shorttitle} {
    \bool_set_true:N \l_ptxcd_separate_bool
    \text_uppercase:n {\beamer@shorttitle}
  }
  \tl_if_empty:NF {\beamer@shortauthor} {
    \bool_if:NT \l_ptxcd_separate_bool {
      \space/\space
    }
    \text_uppercase:n {\beamer@shortauthor}
  }
}
\defbeamertemplate*{sidebar~right}{TUDa2023}{
  \bool_if:NT \g_ptxcd_headlinelogo_bool  {
    \vspace{\c_ptxcd_logoheight_dim}
    \llap{\box_use:N \g_@@_sublogo_box}
  }
}
\defbeamertemplate*{frametitle}{TUDa2023}[1][left]{%
  \nointerlineskip%
  \bool_if:NF \g_@@_extended_space_bool
    {\vskip.55ex}
  \begin{beamercolorbox}[
    wd=\dim_eval:n {\bool_if:NT \g_@@_extended_space_bool {-\box_wd:N \g_@@_logo_box } \box_if_empty:NF \g_@@_sublogo_box {-\box_wd:N \g_@@_sublogo_box - 1em}+ \textwidth},
    ]{frametitle}
      \usebeamerfont{frametitle}%
      \if@tempswa\else\csname beamer@fte#1\endcsname\fi%
      \vphantom{Ü}
      \bool_if:NT \g_@@_uppercase_frametitle_bool \text_uppercase:n {\insertframetitle}\strut
      \par%
      {%
        \ifx\insertframesubtitle\@empty%
        \else%
        {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\strut\text_uppercase:n {\insertframesubtitle}\strut\par}%
        \fi
      }%
      \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}
  \vskip.5ex
}
%    \end{macrocode}
%
%
%    \begin{macrocode}
\mode
<all>
%    \end{macrocode}
% \iffalse
%</main>
%</body>
%</package>
% \fi
%
% \Finale
% \fi^^A No documentation on this
\endinput
