% Copyright (c) 2013-26 Stephane GALLAND <galland@arakhne.org>
%
% UTBM logo and name are registered and owned by the
% "Universite de Technologie de Belfort-Montbeliard".
%
% UBE logo and name are registered and owned by the
% "Universite Bourgogne Europe".
%
% CIAD logo and name are registered and owned by the
% "Laboratoire Connaissance et Intelligence Artificielle Distribuées".
% 
% This program is free library; you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as
% published by the Free Software Foundation; either version 3 of the
% License, or any later version.
%
% This library is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this library; see the file COPYING.  If not,
% write to the Free Software Foundation, Inc., 59 Temple Place - Suite
% 330, Boston, MA 02111-1307, USA.
%
\ProvidesPackage{beamerouterthemeCIAD}[2026/04/20]

\mode<presentation>

\useoutertheme{default}

\pgfdeclareimage[width=.5cm]{FrenchRepublicLogo}{ciad-frenchrepublic}

\gdef\beamer@theme@ciad@outer@offsety{0}

\newlength\beamer@theme@ciad@outer@tmplength

\newlength\beamer@theme@ciad@outer@linewidth
\setlength\beamer@theme@ciad@outer@linewidth{\paperwidth}
\addtolength{\beamer@theme@ciad@outer@linewidth}{-2em}

\newlength\beamer@theme@ciad@outer@titlewidth
\setlength\beamer@theme@ciad@outer@titlewidth{\paperwidth}
\addtolength{\beamer@theme@ciad@outer@titlewidth}{-5.2em}

\newlength\beamer@theme@ciad@outer@titlewidth@plain
\setlength\beamer@theme@ciad@outer@titlewidth@plain{\textwidth}

\newlength\beamer@theme@ciad@outer@sideboxwidth
\setlength\beamer@theme@ciad@outer@sideboxwidth{6.8cm}

\newlength\beamer@theme@ciad@outer@topalignmentspan
\setlength\beamer@theme@ciad@outer@topalignmentspan{-1cm}
\newlength\beamer@theme@ciad@outer@centeralignmentspan
\setlength\beamer@theme@ciad@outer@centeralignmentspan{-.5cm}
\newlength\beamer@theme@ciad@outer@bottomalignmentspan
\setlength\beamer@theme@ciad@outer@bottomalignmentspan{0cm}

\gdef\beamer@theme@ciad@outer@valign{c}

\let\beamer@theme@ciad@outer@KV@beamerframe@t\KV@beamerframe@t
\define@key{beamerframe}{t}[true]{%
	\beamer@theme@ciad@outer@KV@beamerframe@t{#1}%
	\ifthenelse{\equal{#1}{true}}{%
		\gdef\beamer@theme@ciad@outer@valign{t}%
	}{}%
}

\let\beamer@theme@ciad@outer@KV@beamerframe@c\KV@beamerframe@c
\define@key{beamerframe}{c}[true]{%
	\beamer@theme@ciad@outer@KV@beamerframe@c{#1}%
	\ifthenelse{\equal{#1}{true}}{%
		\gdef\beamer@theme@ciad@outer@valign{c}%
	}{}%
}

\let\beamer@theme@ciad@outer@KV@beamerframe@b\KV@beamerframe@b
\define@key{beamerframe}{b}[true]{%
	\beamer@theme@ciad@outer@KV@beamerframe@b{#1}%
	\ifthenelse{\equal{#1}{true}}{%
		\gdef\beamer@theme@ciad@outer@valign{b}%
	}{}%
}

% See base definition for overriding this macro
\providecommand{\beamer@theme@ciad@outer@titlebackground}{}

% No navigation symbols
\setbeamertemplate{navigation symbols}{}

% Output the slide background and the title background
\newcommand{\beamer@theme@ciad@outer@background}{%
	\ifbeamer@theme@ciad@tableofcontentslide@background%
		% On a TOC slide
		\global\beamer@theme@ciad@tableofcontentslide@backgroundfalse%
		\begin{tikzpicture}%
			\expandafter\beamer@theme@ciad@backgroundpicture@putslidebackgroundpicture{0}{224}{\beamer@theme@ciad@tableofcontentslide@backgroundnumber}%
			\ifthenelse{\boolean{beamer@theme@ciad@frenchrepublic}}{%
				\path[fill=white](0,8.5) rectangle (0.6,7.9);%
				\path[fill=frametitle.bg] (0.6,8.5) rectangle (16,7.9);%
			}{%
				\path[fill=frametitle.bg](0,8.5) rectangle (16.6,7.9);%
			}%
			\ifthenelse{\boolean{beamer@theme@ciad@frenchrepublic}}{%
				\put(1.5,227.25){\pgfuseimage{FrenchRepublicLogo}}%
			}{}%
		\end{tikzpicture}%
	\else%
		\begin{tikzpicture}%
		\insertcurrentslidebackgroundpicture%
		\ifthenelse{\boolean{beamer@theme@ciad@frenchrepublic}}{%
			\path[fill=white](0,0) rectangle (0.6,0.60);%
			\path[fill=frametitle.bg](0.6,0) rectangle (16,0.60);%
		}{%
			\path[fill=frametitle.bg](0,0) rectangle (16.6,0.60);%
		}%
		\ifthenelse{\boolean{beamer@theme@ciad@frenchrepublic}}{%
			\put(1.5,2.5){\pgfuseimage{FrenchRepublicLogo}}%
		}{}%
		\end{tikzpicture}%
	\fi%
}

% Title page with the regular CIAD layout
\newcommand{\insertstandardciadtitlepage}{%
	\expandafter\begin{picture}(0,0)(0,\beamer@theme@ciad@outer@offsety)%
		% User left background
		\ifx\beamer@theme@ciad@titleslide@background@userpgf\relax\else%
			\put(-28.6,-142.7){\expandafter\pgfuseimage{\beamer@theme@ciad@titleslide@background@userpgf}}%
		\fi%
		% Page background
		\put(-28.6,-142.7){\expandafter\pgfuseimage{\beamer@theme@ciad@titleslide@background}}%
		% Background for the title (white and green)
		\put(171.1,-142.7){%
			\begin{tikzpicture}%
			\fill[CIADgreen](0,0) -- (0.365,1.2) -- (9,1.2) -- (9,0) -- cycle;%
			\fill[white](0.3,1.1) -- (0.45,1.6) -- (9,1.6) -- (9,1.1) -- cycle;%
			\end{tikzpicture}%
		}%
		% Right logo on the page
		\expandafter\put(\beamer@theme@ciad@titleslide@rightlogo@x,\beamer@theme@ciad@titleslide@rightlogo@y){%
			\expandafter\pgfuseimage{\beamer@theme@ciad@titleslide@rightlogo@pgf}%
		}%
		% Left picture on the page
		\ifx\beamer@theme@ciad@titleslide@leftlogo@pgf\relax\else%
			\expandafter\put(\beamer@theme@ciad@titleslide@leftlogo@x,\beamer@theme@ciad@titleslide@leftlogo@y){%
				\expandafter\pgfuseimage{\beamer@theme@ciad@titleslide@leftlogo@pgf}%
			}%
		\fi%
		% Text in white area
		\put(181,-107){%
			\parbox[c]{8.35cm}{\centering\nohyphens{%
				\usebeamercolor[fg]{text in small title area}%
				\usebeamerfont{text in small title area}%
				\ifthenelse{\equal{a\inserteventname}{a}}{%
					\@beamer@theme@ciad@wraptextformats{\insertauthor}%
				}{%
					\@beamer@theme@ciad@wraptextformats{\inserteventname}%
				}}}}%
		% Text in green area
		\put(181,-130){%
			\parbox[c]{8.35cm}{\centering\nohyphens{%
				\usebeamercolor[fg]{text in big title area}%
				{\usebeamerfont{text in big title area}\@beamer@theme@ciad@wraptextformats{\beamer@theme@ciad@conditionalfirsttailletters\inserttitle}}%
				{\usebeamerfont{subtext in big title area}%
				\ifthenelse{\equal{a\insertsubtitle}{a}}{%
					\ifthenelse{\equal{a\inserteventname}{a}}{}{%
						\\[-.5\baselineskip]\@beamer@theme@ciad@wraptextformats{\insertauthor}%
					}%
				}{%
					\\[-.1\baselineskip]\@beamer@theme@ciad@wraptextformats{\insertsubtitle}%
					\ifthenelse{\equal{a\inserteventname}{a}}{}{%
						\\[-.5\baselineskip]\@beamer@theme@ciad@wraptextformats{\insertauthor}%
					}%
				}%
				}}}}%
	\end{picture}%
}

\setbeamertemplate{title page}{%
	% By default, the regulat title page layout is used
	\insertstandardciadtitlepage%
}

% Frame with title bar
\setbeamertemplate{frametitle}{%
		\ifbeamer@plainframe%
			\begin{picture}(0,40)(0,0)%
			% Header
			\put(-23,26){\usebeamercolor[fg]{plain frametitle}%
				\parbox[c]{\beamer@theme@ciad@outer@titlewidth@plain}{%
				\nohyphens{\begin{flushleft}\large\bf\@beamer@theme@ciad@wraptextformats{\insertframetitle}%
				\ifthenelse{\equal{a\insertframesubtitle}{a}}{{}}{%
					\usebeamercolor[fg]{plain framesubtitle}\small\bf~--~\@beamer@theme@ciad@wraptextformats{\insertframesubtitle}}%
				\end{flushleft}}%
			}}%
			\end{picture}%
		\else%
			\begin{picture}(0,40)(0,0)%
			% Header
			\ifbeamer@theme@ciad@headline@empty%
				\setlength{\beamer@theme@ciad@outer@tmplength}{\beamer@theme@ciad@outer@titlewidth}%
				\addtolength{\beamer@theme@ciad@outer@tmplength}{1cm}%
				\def\@tmp{-9}%
			\else%
				\setlength{\beamer@theme@ciad@outer@tmplength}{\beamer@theme@ciad@outer@titlewidth}%
				\def\@tmp{-9}%
			\fi%
			\expandafter\put(\@tmp,29){\usebeamercolor[fg]{frametitle}%
				\parbox[c]{\beamer@theme@ciad@outer@tmplength}{%
				\nohyphens{\begin{flushleft}\scriptsize\bf\@beamer@theme@ciad@wraptextformats{%
					\setstretch{.75}%
					\insertformattedframetitle}%
				\ifthenelse{\equal{a\insertframesubtitle}{a}}{{}}{%
					\usebeamercolor[fg]{framesubtitle}\tiny\bf~--~\@beamer@theme@ciad@wraptextformats{\insertframesubtitle}}%
				\end{flushleft}}%
			}}%
			% Side note
			\ifx\beamer@theme@ciad@sidenote\relax\else%
				\put(417,-195){\rotatebox{90}{\parbox[c]{\beamer@theme@ciad@outer@sideboxwidth}{%
						\usebeamerfont{sidenote}\usebeamercolor[fg]{sidenote}%
						\beamer@theme@ciad@sidenote%
				}}}%
				\global\let\beamer@theme@ciad@sidenote\relax%
			\fi%
			% Put the background elements
			\beamer@theme@ciad@beginframe@hooks
			%
			\end{picture}%
		\fi%
		% Change the space between the header and the body of the text.
		\mbox{}%
		\ifthenelse{\equal{=\beamer@theme@ciad@outer@valign}{=t}}{%
			\vspace{\beamer@theme@ciad@outer@topalignmentspan}%
		}{%
			\ifthenelse{\equal{=\beamer@theme@ciad@outer@valign}{=c}}{%
				\vspace{\beamer@theme@ciad@outer@centeralignmentspan}%
			}{%
				\vspace{\beamer@theme@ciad@outer@bottomalignmentspan}%
			}%
		}%
	}

% Footline with the logos
\gdef\beamer@theme@ciad@outer@footline{%
	\ifbeamer@plainframe\else%
	\begin{picture}(0,25)(0,0)%
	% Foot background
	\put(0,0){%
		\begin{tikzpicture}%
		\fill[footline.bg](0,0) rectangle (16,0.6);%
		\end{tikzpicture}%
	}
	% Frame number
	\put(438,7.5){\parbox[c]{2em}{%
			{\mbox{}\hfill\usebeamercolor[fg]{footline}\tiny\insertframenumbering}%
	}}%
	% Partner logos
	\put(255,3.5){\parbox[b]{6.4cm}{\mbox{}\hfill%
			\beamer@theme@ciad@partnerlogo%
			\ifthenelse{\boolean{beamer@theme@ciad@lablogo}}{%
				\hspace{.1cm}\insertinstitutelogosinfootline{\hspace{.1cm}}%
			}{}%
	}}%
	% Left text
	\ifbeamer@theme@ciad@tableofcontentslide@footline%
		\global\beamer@theme@ciad@tableofcontentslide@footlinefalse%
		\beamer@theme@ciad@footline@foroutline%
	\else%
		\beamer@theme@ciad@footline@default%
	\fi%
	\end{picture}%
	\fi%
}

\setbeamertemplate{part page}{%
		\begin{picture}(0,0)(0,0)%
		% Page background
		\put(-28.6,-150){\pgfuseimage{partbackground}}%
		% Title
		\put(-20,-25){\usebeamercolor[fg]{maintitle}\parbox[c]{\beamer@theme@ciad@outer@linewidth}{%
			\nohyphens{\begin{raggedright}\usebeamerfont{part title}{\@beamer@theme@ciad@wraptextformats{{\beamer@theme@ciad@rsection@insertpartprefix}\beamer@partname}}%
		\end{raggedright}}}}%
		% Author
		\ifbeamer@theme@ciad@part@hasauthor%
		\put(-20,-85){\parbox[c]{\beamer@theme@ciad@outer@linewidth}{\begin{raggedright}
			{\usebeamercolor[fg]{author}\large\bf\beamer@theme@ciad@part@theauthor}
			\end{raggedright}}}%
		\fi%
		\end{picture}%
}

\newcommand{\thanksslide}{%
	\setbeamertemplate{footline}{}
	\usebackgroundtemplate{\beamer@theme@ciad@outer@background}%
	\frame{
		% Copy of the title page
		\ifthenelse{\value{@beamer@theme@ciad@finalslidelabel}=3}{%
			\gdef\beamer@theme@ciad@outer@offsety{14.4}%
			\usebeamertemplate{title page}%
			\gdef\beamer@theme@ciad@outer@offsety{0}%
		}{%
			\ifcase\value{@beamer@theme@ciad@finalslidelabel}%
				\def\beamer@theme@ciad@outer@thanks@tmp{\translate{Thanks}}%
			\or%
				\def\beamer@theme@ciad@outer@thanks@tmp{\translate{Questions}}%
			\or%
				\def\beamer@theme@ciad@outer@thanks@tmp{%
					\beamer@theme@ciad@conditionalfirsttailletters[part title fancy letter]\beamer@theme@ciad@label@finalslidelabel%
				}
			\else%
				\def\beamer@theme@ciad@outer@thanks@tmp{}%
				\errmessage{Package Beamer/CIAD: Unsupported type of message for the final slide.}%
			\fi%
			\begin{picture}(0,0)(0,0)%
				% Page background
				\put(-28.6,-150){\pgfuseimage{partbackground}}%
				% Title
				\put(-20,-25){\usebeamercolor[fg]{part title}\parbox[c]{\beamer@theme@ciad@outer@linewidth}{%
					\nohyphens{\begin{raggedright}\usebeamerfont{part title}{\@beamer@theme@ciad@wraptextformats{\beamer@theme@ciad@outer@thanks@tmp}}%
					\end{raggedright}}}}%
			\end{picture}%
		}%
	}%
	\usebackgroundtemplate{\ifbeamer@plainframe\else\beamer@theme@ciad@outer@background\fi}%
	\setbeamertemplate{footline}{\beamer@theme@ciad@outer@footline}%
}

\newcommand{\beamer@theme@ciad@outer@thanksslide}{%
	\beamer@theme@ciad@nav@advancesection%
	\xdef\beamer@theme@ciad@totalcoreframenumber{\the\c@framenumber}
	\addtocounter{section}{1}% To be sure that the 'thank' slide is not in the same section as the previous slide.
	\thanksslide%
}

\setbeamertemplate{frametitle continuation}{%
	{\smaller(\#\insertcontinuationcount)}%
}

\setbeamertemplate{framerighttitle}{%
	\putat*(250,-150){%
		\begin{tikzpicture}%
		\path[fill=righttitle.fg] (0,0) rectangle (0.03,5);%
		\end{tikzpicture}%
	}%
	\putat*(260,-80){%
		\parbox[c]{5.2cm}{%
			\nohyphens{\begin{flushleft}%
			\usebeamerfont{righttitle}\usebeamercolor[fg]{righttitle}%
			\@beamer@theme@ciad@wraptextformats{\beamer@theme@ciad@rightitleframe@text}%
			\end{flushleft}}%
		}%
	}%
}

\setbeamertemplate{frameleftlawn}{%
	\putat*(65,-198){%
		\begin{tikzpicture}%
		\path[fill=lawn.bg] (0,0) rectangle (5,7.8);%
		\end{tikzpicture}%
	}%
	\ifthenelse{\equal{a\beamer@theme@ciad@lawnframe@picture}{a}}{}{%
		\putat*(207,-198){%
			\pgfuseimage{\beamer@theme@ciad@lawnframe@picture}%
		}
	}%
}

\setbeamertemplate{framerightlawn}{%
	\putat*(192,-198){%
		\begin{tikzpicture}%
		\path[fill=lawn.bg] (0,0) rectangle (5,7.8);%
		\end{tikzpicture}%
	}%
	\ifthenelse{\equal{a\beamer@theme@ciad@lawnframe@picture}{a}}{}{%
		\putat*(-29,-198){%
			\pgfuseimage{\beamer@theme@ciad@lawnframe@picture}%
		}
	}%
}

\setbeamertemplate{frametextpicture}{%
	\ifthenelse{\equal{a\beamer@theme@ciad@textpictureframe@picture}{a}}{}{%
		\putat*(310,-140){%
			\usebeamercolor[fg]{textpicture}\expandafter\pgfuseimage{\beamer@theme@ciad@textpictureframe@picture}%
		}
	}%
	\putat*(300,-198){%
		\begin{tikzpicture}%
		\path[fill=textpicture.bg] (0,0) rectangle (5,7.8);%
		\end{tikzpicture}%
	}%
}

\gdef\beamer@theme@ciad@leftvideoframe@footer{}
\setbeamertemplate{frametextvideo}{%
	\ifthenelse{\equal{a\beamer@theme@ciad@textvideoframe@picture}{a}}{}{%
		\putat*(201,-85){%
			\usebeamercolor[fg]{textvideo}\raisebox{-.5\height}{%
				\expandafter\embeddedvideo[width=7.6cm]{\beamer@theme@ciad@textvideoframe@video}{\beamer@theme@ciad@textvideoframe@picture}
			}%
		}%
	}%
	\putat*(203,-180){%
		\begin{minipage}{7.5cm}%
			\usebeamercolor[fg]{textvideo}\centering%
			\beamer@theme@ciad@leftvideoframe@footer%
		\end{minipage}%
	}%
	\putat*(200,-198){%
		\begin{tikzpicture}%
		\path[fill=textvideo.bg] (0,0) rectangle (8,7.8);%
		\end{tikzpicture}%
	}%
}

\mode
<all>
