TIP:		432
Title:		Support for New Windows File Dialogs in Vista and Later
Version:	$Revision: 1.4 $
Author:		Ashok P. Nadkarni <apnmbx-wits@yahoo.com>
State:		Final
Type:		Project
Vote:		Done
Created:	20-Sep-2014
Post-History:	
Tcl-Version:	8.6.3

~ Abstract

This TIP proposes changing the '''tk_getOpenFile''', '''tk_getSaveFile''' and
'''tk_chooseDirectory''' dialog box commands to display the new style file
dialogs available on newer Windows versions.

~ 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:

 * They do not support the new features, such as breadcrumbs, enhanced
   navigation etc.
   
 * 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.

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

~ Proposed Changes

The proposal will result in the '''tk_getOpenFile''', '''tk_getSaveFile''' and
'''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.

~~ Incompatible changes

If the '''-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.

~ 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.

~ Discussion

 * The change in behaviour when '''-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).

 * 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 '''-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.

 * The new implementation calls '''CoInitialize''' to initialize COM. It is
   not clear when, and if, '''CoUnInitialize''' needs to be called. In fact,
   as documented in MSDN, even the '''SHBrowseForFolder''' call used by the
   current 8.6 code requires a prior call to '''CoInitialize''' which Tcl does
   not do.  Need discussion on whether Tcl should always call
   '''CoInitialize''' at thread startup and '''CoUnInitialize''' at thread
   shutdown.

~ Copyright

This document has been placed in the public domain.
