% Package for Unified Process Methodology's extensions
%
% Copyright (c) 2006-2025 Stephane GALLAND <galland@arakhne.org>
% 
% 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.
%

\global\edef\upm@package@ext@ver{2025/04/20}

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{upmethodology-extension}[\upm@package@ext@ver]

\RequirePackage{upmethodology-p-common}

%----------------------------------------
% TEST MACROS
%----------------------------------------
\long\def\Ifdefined#1#2{\@ifundefined{upmext@extension@value@#1}{}{#2}}
\long\def\Ifelsedefined#1#2#3{\@ifundefined{upmext@extension@value@#1}{#3}{#2}}
\long\def\Ifundefined#1#2{\@ifundefined{upmext@extension@value@#1}{#2}{}}
\long\def\Ifelseundefined#1#2#3{\@ifundefined{upmext@extension@value@#1}{#2}{#3}}

%----------------------------------------
% EXTENSION MANAGEMENT
%----------------------------------------

\newif\ifupm@extension@savealllang\upm@extension@savealllangtrue

\newcommand{\Get}[1]{\@nameuse{upmext@extension@value@#1}}
\newcommand{\GetLang}[2]{\@nameuse{upmext@extension@value@#1@#2}}
\newcommand{\SetLangDefault}[3]{%
	\@namedef{upmext@extension@value@#1@#2}{#3}%
	\@namedef{upmext@extension@value@#2}{#3}%
}

\newcommand{\upm@extension@Set}[3][\upmcurrentlang]{%
	% PREDEFINED FRONT PAGE
	\ifthenelse{\equal{#2}{frontpage}}{%
		\gdef\upmext@extension@value@frontpage{#3}%
		\global\let\upmext@extension@value@frontpage@custom\relax%
	}{%			
	% CUSTOM BACK PAGE
	\ifthenelse{\equal{#2}{backpage}}{%
		\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
			\gdef\upmext@extension@value@backpage{#3}%
		}{}%
	}{%			
	% CUSTOM FRONT PAGE
	\ifthenelse{\equal{#2}{cfrontpage}}{%
		\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
			\gdef\upmext@extension@value@frontpage{custom}%
			\gdef\upmext@extension@value@frontpage@custom{#3}%
		}{}%
	}{%			
		\ifthenelse{\equal{#2}{cfrontpage2}}{%
			\gdef\upmext@extension@value@frontpage@custom@second{#3}%
		}{%
			\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
				\message{*** define the extension value #2 ****}%
				\global\@namedef{upmext@extension@value@#2}{#3}%
				}{}%
			\ifupm@extension@savealllang%
				\global\@namedef{upmext@extension@value@#2@#1}{#3}%
			\fi
		}%
	}}}%
}
\let\Set\upm@extension@Set

\newcommand{\Append}[3][\upmcurrentlang]{%
	\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
		\message{*** append to extension value #2 ****}%
		\expandafter\expandafter\expandafter\global\expandafter\protected@edef\csname upmext@extension@value@#2\endcsname{\@nameuse{upmext@extension@value@#2}\xspace#3}%
	}{}%
	%\ifupm@extension@savealllang%
	%	\global\expandafter\g@addto@macro\csname upmext@extension@value@#2#1\endcsname{#3}%
	%\fi
}

\newcommand{\Unset}[2][\upmcurrentlang]{%
	\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
		\message{*** undefine the extension value #2 ****}%
		\global\expandafter\let\csname upmext@extension@value@#2\endcsname\@undefined%
		\ifupm@extension@savealllang%
			\global\expandafter\let\csname upmext@extension@value@#2@#1\endcsname\@undefined%
		\fi%
	}{}%
}

\newcommand{\DeclareCopyright}[5][\upmcurrentlang]{%
	\ifthenelse{\equal{\upmcurrentlang}{#1}}{%
		\Set{copyright}{Copyright {(c)} #3 #4.}%
		\message{*** style extension #2, \Get{copyright} ****}%
		\Set{trademarks}{#5}%
	}{}%
}

\newlength{\upmext@tmp@putx}
\def\Put(#1,#2){%
	\setlength{\upmext@tmp@putx}{#1\unitlength}%
	\if@twoside\ifodd\c@page\else\addtolength{\upmext@tmp@putx}{28\unitlength}\fi\fi%
	\put(\strip@pt\upmext@tmp@putx,#2)}

%-----
% Use the specified extension
%\UseExtension{extension_name}
\newcommand{\UseExtension}[1]{%
	\message{**** including upm extension #1 (upmext-#1.cfg) ****}%
	\input{upmext-#1.cfg}%
}

%------------
% Default declarations
\Set{frontillustrationsize}{1}
\Set{watermarksize}{1}
\Unset{publisher}
\Unset{copyrighter}
\Unset{printedin}

\endinput
