\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#108: Summary of Changes to Generic Tcl/Tk Code to Enable Mac OS X Port}
\date{August 29, 2002}
\author{Jim Ingham}
\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 \#108}&\textbf{Summary of Changes to Generic Tcl/Tk Code to Enable Mac OS X Port}\\\hline
Author&

Jim Ingham \tipmail{jingham}{apple.com}
\\
Created&Thursday, \(\text{29}^{\text{th}}\) August 2002\\
Type&Informative\\
State&Final\\
Vote&No voting\\
Version&\tipversion$Revision: 1.2 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

The submission of the changes to generic Tcl/Tk necessary for the Mac OS X port was discussed on the Tcl Core mailing list. In light of the very minor changes to shared code involved, and to facilitate including the port in the 8.4 release, it was decided that we would not hold a formal vote. This informational TIP is offered to summarize the work done, however, and to maintain a more complete record.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{What Changes are Required for the Mac OS X Port?}

These fall into two parts: macosx only changes, and changes that effect generic code.

The Mac OS X-only changes again fall into two parts. On the one hand, we introduced new macosx directories to the Tcl and Tk trees, at the same level as the win, unix and mac directories. At present, the \textit{tcl/macosx} directory only contains one \textit{.c} file and a project file. The \textit{tk/macosx} directory is much more substantial. This set of changes manifestly only effects this port, and since something is better than nothing, should be uncontroversial.

The other Mac OS X-only part is the addition of Mac OS X specific elements to the \textit{.decls} files. This should also be uncontroversial, though I had to add some slightly non-trivial code to the \textit{genStubs.tcl} file to handle the fact that Tk loosely uses ``unix'' to mean ``X11'', which for Mac OS X is not the case.

The Tcl side of Mac OS X is clearly unix, but the same Tcl can in fact be used with X11 (there is a native X Server in quite common use on Mac OS X) and with the Aqua based Tk port.

In the end, however, the stubs generated for the generic, mac, win \& X11 parts of Tcl/Tk are the same, and there is just some extra logic for the aqua part, so the result effects only Mac OS X code.

The generic code changes are quite small --- a testament to the design of the Tcl/Tk porting layers.
\begin{enumerate}
\item{}
We changed the \textit{configure.in}, \textit{Makefile.in} and \textit{tcl.m4} to handle building Tcl in a the Framework form that is common on Mac OS X.
\setcounter{enumi}{1}
\item{}
I added a bit of code (conditionalized to Mac OS X) to \textit{tclUnixInit.c} (in the \textit{TclpSetVariables} function) to support looking for script files embedded in the Mac OS X Framework bundle. This fits the Mac OS X model better than putting files in \textit{/usr/local} or such-like.
\setcounter{enumi}{2}
\item{}
I added a few more elements to the \textit{notifierProcPtr}. For the aqua Tk, we need to swap the Unix notifier with our own, and so we needed more control over the notifier than was allowed. This change has no effect if you don't use it, however.
\setcounter{enumi}{3}
\item{}
I added a function, \textit{TkGetFirstTextLayout}, which gets the run of text up the the first wrap. I have to get this because the Mac OS X button control doesn't like a newline in the button text. It is a private function, however, so it doesn't cause any incompatibilities.
\setcounter{enumi}{4}
\item{}
We had to change various places in the Tk script code and the demos where the implicit assumption was made that [string equal \$tcl\_platform(platform) ``unix''] meant you were using X11. To this end, we will add a \textit{windowingsystem} subcommand to the \textit{tk} command, and then using it to replace the cases where \textit{tcl\_platform} was being erroneously checked. This command will return ``x11'' for an X11 server, ``aqua'' for the native Mac OS X window manager, ``win32'' for Windows, and ``classic'' for Classic MacOS.
\end{enumerate}

\section{Reference Implementation}

The reference implementation is on the \textit{macosx-8-4-branch} in the SourceForge CVS repository.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

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