\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#154: Add Named Colors to Tk}
\date{September 03, 2003}
\author{Damon Courtney}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#154}&\textbf{Add Named Colors to Tk}\\\hline
Author&

Damon Courtney \tipmail{damon}{unreality.com}
\\
Created&Wednesday, \(\text{3}^{\text{rd}}\) September 2003\\
Type&Project\\
Tcl Version&\(8.7\)\\
State&Draft\\
Vote&Pending\\
Version&\tipversion$Revision: 1.26 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes the addition of a \textbf{color} command at the Tk level to allow developers to create named colors as they can already do with both fonts and images.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Named fonts and images go a long way toward making Tk able to modify a lot of options on a global scale simply by adjusting a single item. Tk already simulates some version of named colors on Windows with the use of values like \textit{SystemButtonFace} and \textit{SystemWindowFrame}. These color names map to values pre-defined in Windows. On UNIX, we have to kind of fake these things around.

With the addition of named colors, we can simply define default colors in UNIX that correspond to existing named colors on Windows. So, we could create \textit{SystemButtonFace} as a named color on UNIX, and any Windows program using those color names would port to UNIX without a change.

\section{Implementation}

I propose the introduction of a new command, \textbf{color}:

\begin{quote}
\textbf{color} \textit{option} ?\textit{arg ...}?
\end{quote}

This will have six subcommands.

The \textbf{create} subcommand creates a new named color.

\begin{quote}
\textbf{color create} \textit{colorName} ?\textit{option ...}?
\end{quote}

Supported options (see below for full description) are:
\begin{description}
\item[-color]
The main color associated with this named color.
\item[-dark1]
The low-light color associated with this named color.
\item[-light1]
The high-light color associated with this named color.
\end{description}

The \textbf{cget} subcommand retrieves an option associated with a named color

\begin{quote}
\textbf{color cget} \textit{colorName option}
\end{quote}

The \textbf{configure} subcommand sets an option (or options) associted with a named color, or retrieves information about all the options associated with that named color (following the standard Tk pattern for cget/configure.)

\begin{quote}
\textbf{color configure} \textit{colorName} ?\textit{option ...}?
\end{quote}

The \textbf{exists} subcommand determines if a named color exists.

\begin{quote}
\textbf{color exists} \textit{colorName}
\end{quote}

The \textbf{names} subcommand returns a list of all named colors, including those created by Tk. The optional glob-style \textit{pattern} allows only some colors to be returned.

\begin{quote}
\textbf{color names} ?\textit{pattern}?
\end{quote}

The \textbf{delete} subcommand deletes a named color.

\begin{quote}
\textbf{color delete} \textit{colorName}
\end{quote}

\subsection{Options}

The \textbf{-color} option specifies any acceptable color in Tk as the color to use. The \textbf{-light1} and \textbf{-dark1} options specify the border shadings to use for this color when it is used as a border. They are named with a 1 because I think in the future we will end up with more levels of shading. Windows already has two levels, we just ignore the second one.

Beyond the color command, we need to implement a default set of standard colors that will exist across all platforms. As proposed by some, I think these should be named Tk*. The current list (reflected in the Windows color list) would be:
\begingroup\small\begin{verbatim}
TkButtonFace
TkButtonText
TkDisabledText
TkHighlight
TkHighlightText
TkMenu
TkMenuText
TkScrollbar
TkWindow
TkWindowFrame
TkWindowText
\end{verbatim}
\endgroup

If there are others, I'm not sure what they are. This list can easily be expanded over time as most of them will be created at the Tcl-level.

As part of this TIP, the core widgets should also be modified to use the new Tk* named colors as their defaults for all platforms. The named colors will still be created from system defaults on each system. The UNIX colors will most likely come from whatever comes out of \cite{tip172}.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#172]{tip172}
David N. Welton,
\emph{Improve UNIX Tk Look and Feel},
on-line at \url{http://purl.org/tcl/tip/172.html}
\end{thebibliography}
\end{document}
