\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwlabels}[2002/02/03 0.2]
\RequirePackage{ifthen}

\newboolean{frames}\setboolean{frames}{false}
\newboolean{landscape}\setboolean{landscape}{false}

\DeclareOption{frames}{
  \setboolean{frames}{true}
}

\DeclareOption{landscape}{
  \setboolean{landscape}{true}
}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}

\ifthenelse{\boolean{landscape}}{
\setlength{\textwidth}{29.7cm}
\setlength{\textheight}{21cm}
\setlength{\paperwidth}{29.7cm}
\setlength{\paperheight}{21cm}
\special{landscape}
}%
{
\setlength{\textwidth}{21cm}
\setlength{\textheight}{29.7cm}
\setlength{\paperwidth}{21cm}
\setlength{\paperheight}{29.7cm}
}%

\pagestyle{empty}
\setlength{\parindent}{0cm}
\setlength{\oddsidemargin}{-1in}
\setlength{\topmargin}{-1in}
\setlength{\headheight}{0cm}
\setlength{\headsep}{0cm}
\setlength{\topskip}{0.01mm}
\setlength{\footskip}{0cm}
\setlength{\parindent}{0cm}
\setlength{\parsep}{0mm}
\setlength{\lineskip}{0pt}
\setlength{\fboxsep}{5mm}
\setlength{\fboxrule}{0.01mm}

\newlength{\cardwidth}
\newlength{\cardheight}

\newcommand{\setcardsize}[2]{%
\setlength{\cardwidth}{#1}%
\setlength{\cardheight}{#2}%
}

\newcommand{\setcardperpage}[2]{
\setlength{\cardwidth}{\paperwidth}%
\setlength{\cardheight}{\paperheight}%
\divide\cardwidth #1%
\divide\cardheight #2%
}

\newlength{\cw}
\newlength{\ch}
\newlength{\bordure}

\ifthenelse{\boolean{frames}}{
%%% Frame
\newsavebox{\fmbox}
\newenvironment{lbl}{%
\setlength{\cw}{\cardwidth}%
\setlength{\ch}{\cardheight}%
\setlength{\bordure}{2\fboxsep}%
\addtolength{\bordure}{2\fboxrule}%
\begin{lrbox}{\fmbox}
\addtolength{\cw}{-1\bordure}\addtolength{\ch}{-1\bordure}%
\begin{minipage}[c][\ch][c]{\cw}%
}{%
\end{minipage}\end{lrbox}%
\framebox{\usebox{\fmbox}}%
}% end newenvironment
}{%
%%% No frame
\newenvironment{lbl}{%
\setlength{\cw}{\cardwidth}%
\setlength{\ch}{\cardheight}%
\begin{minipage}[c][\ch][c]{\cw}%
}{%
\end{minipage}%
}% end newenvironment
} %% end if frames
