\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#204: Virtual Events for Keyboard Traversal}
\date{June 21, 2004}
\author{Joe English}
\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 \#204}&\textbf{Virtual Events for Keyboard Traversal}\\\hline
Author&

Joe English \tipmail{jenglish}{users.sourceforge.net}
\\
Created&Monday, \(\text{21}^{\text{st}}\) June 2004\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.5 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

Proposes using two new virtual events, \textbf{\tiplangle{}\tiplangle{}TraverseIn\tiprangle{}\tiprangle{}} and \textbf{\tiplangle{}\tiplangle{}TraverseOut\tiprangle{}\tiprangle{}}, to notify widgets of keyboard navigation events.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Certain widgets need to perform some action when they receive and/or lose keyboard focus because of keyboard traversal. For example, tabbing into an Entry or Spinbox widget selects the widget contents.

This cannot be done with a \tiplangle{}FocusIn\tiprangle{} binding, since widgets may receive \tiplangle{}FocusIn\tiprangle{} events for reasons other than keyboard traversal.

Tk currently implements this feature with special-case logic that checks the target window's widget class in the \textit{tk::TabToWindow} procedure. The drawback to this approach is that it only works for the built-in widgets; third party widget sets like BWidget[\url{http://tcllib.sf.net/}], IWidgets[\url{http://sf.net/projects/incrtcl/}], and Tile[\url{http://tktable.sf.net/tile/}] must implement their own workarounds.

\section{Proposal}

Change the standard Tk bindings for \tiplangle{}Key-Tab\tiprangle{} and \tiplangle{}Shift-Key-Tab\tiprangle{} to do the following:
\begin{itemize}
\item{}
Send a \textbf{\tiplangle{}\tiplangle{}TraverseOut\tiprangle{}\tiprangle{}} virtual event to the current focus window, if any;
\item{}
Set the focus to the new window;
\item{}
Send a \textbf{\tiplangle{}\tiplangle{}TraverseIn\tiprangle{}\tiprangle{}} virtual event to the new window.
\end{itemize}

Additionally, move the current code to handle traversal to Entry and Spinbox widgets from \textit{tk::TabToWindow} to class bindings.

\section{Implementation}

See Tk Patch \#976928[\url{http://sourceforge.net/support/tracker.php?aid=976928}].

The BWidget package has used an identical scheme since version 1.7; see Tcllib bug \#720032[\url{http://sourceforge.net/support/tracker.php?aid=720032}] for details.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
