\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#238: Fire Event when Widget Created}
\date{January 25, 2005}
\author{Gerald W. Lester}
\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 \#238}&\textbf{Fire Event when Widget Created}\\\hline
Author&

Gerald W. Lester \tipmail{Gerald.Lester}{cox.net}
\\
Created&Tuesday, \(\text{25}^{\text{th}}\) January 2005\\
Type&Project\\
Tcl Version&\(8.7\)\\
State&Draft\\
Vote&Pending\\
Version&\tipversion$Revision: 1.7 $\\
Keywords&Tk\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP arranged for a new virtual event to be fired every time a widget is created. This allows class bindings to automatically discover new widget instances and act on their creation.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

It would be useful if it was possible to set an event on class bindings to allow custom code to be run when a widget of a particular class is created.

Note that the standard X11 \tiplangle{}Create\tiprangle{} event is not quite suitable, because that is delivered to the X11 parent of the widget, which is not Tk in the case of toplevel windows.

\section{Proposal}

It is proposed that the virtual event \tiplangle{}\tiplangle{}Create\tiprangle{}\tiprangle{} be sent to every widget upon the creation of its actual underlying window (i.e. as part of \textbf{Tk\_MakeWindowExist}). Note that this is the earliest at which an event can actually be delivered to the widget; before that, doing \textbf{event generate} to the widget just creates an event that gets discarded.

\subsection{Example}
\begingroup\small\begin{verbatim}
% bind Toplevel <<Create>> {
    puts stdout {New toplevel called {%W} was created!}
}
% toplevel .foo
New toplevel called {.foo} was created!
\end{verbatim}
\endgroup

\subsection{Proposed C API Changes}

No changes would be requried, this change is for the Tcl layer API.

\section{Reference Implementation}

A reference implementation does \textit{not} yet exist.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

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