\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#432: Support for New Windows File Dialogs in Vista and Later}
\date{September 20, 2014}
\author{Ashok P. Nadkarni}
\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 \#432}&\textbf{Support for New Windows File Dialogs in Vista and Later}\\\hline
Author&

Ashok P. Nadkarni \tipmail{apnmbx-wits}{yahoo.com}
\\
Created&Saturday, \(\text{20}^{\text{th}}\) September 2014\\
Type&Project\\
Tcl Version&\(8.6.3\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.4 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes changing the \textbf{tk\_getOpenFile}, \textbf{tk\_getSaveFile} and \textbf{tk\_chooseDirectory} dialog box commands to display the new style file dialogs available on newer Windows versions.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

As of Tk 8.6.2, the above commands translate to Windows native file dialogs corresponding to the ones present in Windows XP (the earliest version of Windows supported by Tcl 8.6). Vista and later Windows systems have newer versions of these dialogs with additional features and a different look and feel. Although the older dialogs are functional on these platforms, they have the following issues:
\begin{itemize}
\item{}
They do not support the new features, such as breadcrumbs, enhanced navigation etc.
\item{}
The look and feel is dated and inconsistent not only with other native applications, but even with Tk itself since the Ttk widgets adapt to the theme for the platform.
\end{itemize}

In addition, this TIP proposes some changes to behaviour with respect to existing dialogs that would make the dialogs more consistent with Windows conventions.

\section{Proposed Changes}

The proposal will result in the \textbf{tk\_getOpenFile}, \textbf{tk\_getSaveFile} and \textbf{tk\_chooseDirectory} dialog box commands displaying the new Vista style file dialogs if available and falling back to the older style otherwise. Options to the commands and return value from the dialogs remain unchanged except as noted below.

\subsection{Incompatible changes}

If the \textbf{-initialdir} option is not specified, the new dialog will default to the default Windows mechanism for choosing the initial directory displayed. Documentation will be updated to state that the initial directory displayed when this option is not present is system dependent.

\section{Reference Implementation}

A reference implementation is available in the apn-win-filedialogs branch.

The new dialogs require a new COM interface IFileDialog. The reference implementation uses this interface if available and falls back to the old one otherwise.

\section{Discussion}
\begin{itemize}
\item{}
The change in behaviour when \textbf{-initialdir} is not specified is driven by the fact that on Windows the current working directory for a GUI program is generally the directory where the program was installed. This is almost never useful and is contrary to what the user expects which is the last directory shown by the program (even across process invocations).
\item{}
Should there be either a global setting or an option that forces the use of old style dialogs. Alternatively, should the new dialogs be only displayed if a (new) option is specified with the command. The author is not in favor of either of these but applications that have documented screenshots may wish to preserve the old dialogs. As of now, the reference implementation has a hidden option \textbf{-xpstyle} that can be used to select between old and new styles. This is present mainly to allow debugging and testing of the older dialogs on newer platforms.
\item{}
The new implementation calls \textbf{CoInitialize} to initialize COM. It is not clear when, and if, \textbf{CoUnInitialize} needs to be called. In fact, as documented in MSDN, even the \textbf{SHBrowseForFolder} call used by the current 8.6 code requires a prior call to \textbf{CoInitialize} which Tcl does not do. Need discussion on whether Tcl should always call \textbf{CoInitialize} at thread startup and \textbf{CoUnInitialize} at thread shutdown.
\end{itemize}

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

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