summaryrefslogtreecommitdiffstats
path: root/win/tkWinDialog.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2005-08-10 22:02:21 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2005-08-10 22:02:21 (GMT)
commitc8d989f48e69bfff4d7cb7214f8f4539e303fd7c (patch)
tree9d4e60b064aa3377d392ff30035da3ba8ba121ae /win/tkWinDialog.c
parentaac661624dd68998883977d90169ef67424e6b7e (diff)
downloadtk-c8d989f48e69bfff4d7cb7214f8f4539e303fd7c.zip
tk-c8d989f48e69bfff4d7cb7214f8f4539e303fd7c.tar.gz
tk-c8d989f48e69bfff4d7cb7214f8f4539e303fd7c.tar.bz2
Getting more systematic about style
Also start removing _ANSI_ARGS_; the core's required ANSI C for a while now Also fix [Bug 1252702]; size_t doesn't mix with Tcl_GetStringFromObj
Diffstat (limited to 'win/tkWinDialog.c')
-rw-r--r--win/tkWinDialog.c1652
1 files changed, 834 insertions, 818 deletions
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index f794174..4d56b69 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -5,29 +5,30 @@
*
* Copyright (c) 1996-1997 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinDialog.c,v 1.37 2004/12/20 10:34:21 vincentdarley Exp $
+ * RCS: @(#) $Id: tkWinDialog.c,v 1.38 2005/08/10 22:02:22 dkf Exp $
*
*/
#include "tkWinInt.h"
#include "tkFileFilter.h"
-#include <commdlg.h> /* includes common dialog functionality */
+#include <commdlg.h> /* includes common dialog functionality */
#ifdef _MSC_VER
# pragma comment (lib, "comdlg32.lib")
#endif
-#include <dlgs.h> /* includes common dialog template defines */
-#include <cderr.h> /* includes the common dialog error codes */
+#include <dlgs.h> /* includes common dialog template defines */
+#include <cderr.h> /* includes the common dialog error codes */
/*
* This controls the use of the new style tk_chooseDirectory dialog.
*/
+
#define USE_NEW_CHOOSEDIR 1
#ifdef USE_NEW_CHOOSEDIR
-#include <shlobj.h> /* includes SHBrowseForFolder */
+#include <shlobj.h> /* includes SHBrowseForFolder */
#ifdef _MSC_VER
# pragma comment (lib, "shell32.lib")
#endif
@@ -36,47 +37,50 @@
#ifndef BIF_EDITBOX
#define BIF_EDITBOX 0x10
#endif
+
#ifndef BIF_VALIDATE
#define BIF_VALIDATE 0x0020
#endif
+
#ifndef BFFM_VALIDATEFAILED
#ifdef UNICODE
#define BFFM_VALIDATEFAILED 4
#else
#define BFFM_VALIDATEFAILED 3
#endif
-#endif
+#endif /* BFFM_VALIDATEFAILED */
/*
- * The following structure is used by the new Tk_ChooseDirectoryObjCmd
- * to pass data between it and its callback. Unqiue to Winodws platform.
+ * The following structure is used by the new Tk_ChooseDirectoryObjCmd to pass
+ * data between it and its callback. Unqiue to Winodws platform.
*/
+
typedef struct ChooseDirData {
- TCHAR utfInitDir[MAX_PATH]; /* Initial folder to use */
- TCHAR utfRetDir[MAX_PATH]; /* Returned folder to use */
+ TCHAR utfInitDir[MAX_PATH]; /* Initial folder to use */
+ TCHAR utfRetDir[MAX_PATH]; /* Returned folder to use */
Tcl_Interp *interp;
- int mustExist; /* true if file must exist to return from
- * callback */
+ int mustExist; /* True if file must exist to return from
+ * callback */
} CHOOSEDIRDATA;
#endif
-typedef struct ThreadSpecificData {
- int debugFlag; /* Flags whether we should output debugging
- * information while displaying a builtin
- * dialog. */
- Tcl_Interp *debugInterp; /* Interpreter to used for debugging. */
- UINT WM_LBSELCHANGED; /* Holds a registered windows event used for
- * communicating between the Directory
- * Chooser dialog and its hook proc. */
- HHOOK hMsgBoxHook; /* Hook proc for tk_messageBox and the */
- HICON hSmallIcon; /* icons used by a parent to be used in */
- HICON hBigIcon; /* the message box */
+typedef struct ThreadSpecificData {
+ int debugFlag; /* Flags whether we should output debugging
+ * information while displaying a builtin
+ * dialog. */
+ Tcl_Interp *debugInterp; /* Interpreter to used for debugging. */
+ UINT WM_LBSELCHANGED; /* Holds a registered windows event used for
+ * communicating between the Directory Chooser
+ * dialog and its hook proc. */
+ HHOOK hMsgBoxHook; /* Hook proc for tk_messageBox and the */
+ HICON hSmallIcon; /* icons used by a parent to be used in */
+ HICON hBigIcon; /* the message box */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
/*
- * The following structures are used by Tk_MessageBoxCmd() to parse
- * arguments and return results.
+ * The following structures are used by Tk_MessageBoxCmd() to parse arguments
+ * and return results.
*/
static const TkStateMap iconMap[] = {
@@ -86,10 +90,10 @@ static const TkStateMap iconMap[] = {
{MB_ICONWARNING, "warning"},
{-1, NULL}
};
-
+
static const TkStateMap typeMap[] = {
{MB_ABORTRETRYIGNORE, "abortretryignore"},
- {MB_OK, "ok"},
+ {MB_OK, "ok"},
{MB_OKCANCEL, "okcancel"},
{MB_RETRYCANCEL, "retrycancel"},
{MB_YESNO, "yesno"},
@@ -114,72 +118,73 @@ static const int buttonFlagMap[] = {
static const struct {int type; int btnIds[3];} allowedTypes[] = {
{MB_ABORTRETRYIGNORE, {IDABORT, IDRETRY, IDIGNORE}},
- {MB_OK, {IDOK, -1, -1 }},
- {MB_OKCANCEL, {IDOK, IDCANCEL, -1 }},
- {MB_RETRYCANCEL, {IDRETRY, IDCANCEL, -1 }},
- {MB_YESNO, {IDYES, IDNO, -1 }},
- {MB_YESNOCANCEL, {IDYES, IDNO, IDCANCEL}}
+ {MB_OK, {IDOK, -1, -1 }},
+ {MB_OKCANCEL, {IDOK, IDCANCEL, -1 }},
+ {MB_RETRYCANCEL, {IDRETRY, IDCANCEL, -1 }},
+ {MB_YESNO, {IDYES, IDNO, -1 }},
+ {MB_YESNOCANCEL, {IDYES, IDNO, IDCANCEL}}
};
#define NUM_TYPES (sizeof(allowedTypes) / sizeof(allowedTypes[0]))
/*
- * The value of TK_MULTI_MAX_PATH dictactes how many files can
- * be retrieved with tk_get*File -multiple 1. It must be allocated
- * on the stack, so make it large enough but not too large. -- hobbs
- * The data is stored as <dir>\0<file1>\0<file2>\0...<fileN>\0\0.
- * MAX_PATH == 260 on Win2K/NT, so *40 is ~10K.
+ * The value of TK_MULTI_MAX_PATH dictactes how many files can be retrieved
+ * with tk_get*File -multiple 1. It must be allocated on the stack, so make it
+ * large enough but not too large. - hobbs
+ *
+ * The data is stored as <dir>\0<file1>\0<file2>\0...<fileN>\0\0. Since
+ * MAX_PATH == 260 on Win2K/NT, *40 is ~10Kbytes.
*/
#define TK_MULTI_MAX_PATH (MAX_PATH*40)
/*
* The following structure is used to pass information between the directory
- * chooser procedure, Tk_ChooseDirectoryObjCmd(), and its dialog hook proc.
+ * chooser function, Tk_ChooseDirectoryObjCmd(), and its dialog hook proc.
*/
typedef struct ChooseDir {
- Tcl_Interp *interp; /* Interp, used only if debug is turned on,
+ Tcl_Interp *interp; /* Interp, used only if debug is turned on,
* for setting the "tk_dialog" variable. */
int lastCtrl; /* Used by hook proc to keep track of last
- * control that had input focus, so when OK
- * is pressed we know whether to browse a
- * new directory or return. */
- int lastIdx; /* Last item that was selected in directory
+ * control that had input focus, so when OK is
+ * pressed we know whether to browse a new
+ * directory or return. */
+ int lastIdx; /* Last item that was selected in directory
* browser listbox. */
- TCHAR path[MAX_PATH]; /* On return from choose directory dialog,
- * holds the selected path. Cannot return
+ TCHAR path[MAX_PATH]; /* On return from choose directory dialog,
+ * holds the selected path. Cannot return
* selected path in ofnPtr->lpstrFile because
- * the default dialog proc stores a '\0' in
- * it, since, of course, no _file_ was
+ * the default dialog proc stores a '\0' in
+ * it, since, of course, no _file_ was
* selected. */
OPENFILENAME *ofnPtr; /* pointer to the OFN structure */
} ChooseDir;
/*
- * Definitions of procedures used only in this file.
+ * Definitions of functions used only in this file.
*/
#ifdef USE_NEW_CHOOSEDIR
static UINT APIENTRY ChooseDirectoryValidateProc(HWND hdlg, UINT uMsg,
LPARAM wParam, LPARAM lParam);
#else
-static UINT APIENTRY ChooseDirectoryHookProc(HWND hdlg, UINT uMsg,
+static UINT APIENTRY ChooseDirectoryHookProc(HWND hdlg, UINT uMsg,
WPARAM wParam, LPARAM lParam);
#endif
static UINT CALLBACK ColorDlgHookProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
-static int GetFileNameA(ClientData clientData,
- Tcl_Interp *interp, int objc,
+static int GetFileNameA(ClientData clientData,
+ Tcl_Interp *interp, int objc,
Tcl_Obj *CONST objv[], int isOpen);
-static int GetFileNameW(ClientData clientData,
- Tcl_Interp *interp, int objc,
+static int GetFileNameW(ClientData clientData,
+ Tcl_Interp *interp, int objc,
Tcl_Obj *CONST objv[], int isOpen);
-static int MakeFilter(Tcl_Interp *interp, Tcl_Obj *valuePtr,
+static int MakeFilter(Tcl_Interp *interp, Tcl_Obj *valuePtr,
Tcl_DString *dsPtr);
-static UINT APIENTRY OFNHookProc(HWND hdlg, UINT uMsg, WPARAM wParam,
+static UINT APIENTRY OFNHookProc(HWND hdlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
-static UINT APIENTRY OFNHookProcW(HWND hdlg, UINT uMsg, WPARAM wParam,
+static UINT APIENTRY OFNHookProcW(HWND hdlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
static LRESULT CALLBACK MsgBoxCBTProc(int nCode, WPARAM wParam, LPARAM lParam);
static void SetTkDialog(ClientData clientData);
@@ -189,24 +194,23 @@ static void SetTkDialog(ClientData clientData);
*
* EatSpuriousMessageBugFix --
*
- * In the file open/save dialog, double clicking on a list item
- * causes the dialog box to close, but an unwanted WM_LBUTTONUP
- * message is sent to the window underneath. If the window underneath
- * happens to be a windows control (eg a button) then it will be
- * activated by accident.
- *
- * This problem does not occur in dialog boxes, because windows
- * must do some special processing to solve the problem. (separate
- * message processing functions are used to cope with keyboard
- * navigation of controls.)
- *
- * Here is one solution. After returning, we poll the message queue
- * for 1/4s looking for WM_LBUTTON up messages. If we see one it's
- * consumed. If we get a WM_LBUTTONDOWN message, then we exit early,
- * since the user must be doing something new. This fix only works
- * for the current application, so the problem will still occur if
- * the open dialog happens to be over another applications button.
- * However this is a fairly rare occurrance.
+ * In the file open/save dialog, double clicking on a list item causes
+ * the dialog box to close, but an unwanted WM_LBUTTONUP message is sent
+ * to the window underneath. If the window underneath happens to be a
+ * windows control (eg a button) then it will be activated by accident.
+ *
+ * This problem does not occur in dialog boxes, because windows must do
+ * some special processing to solve the problem. (separate message
+ * processing functions are used to cope with keyboard navigation of
+ * controls.)
+ *
+ * Here is one solution. After returning, we poll the message queue for
+ * 1/4s looking for WM_LBUTTON up messages. If we see one it's consumed.
+ * If we get a WM_LBUTTONDOWN message, then we exit early, since the user
+ * must be doing something new. This fix only works for the current
+ * application, so the problem will still occur if the open dialog
+ * happens to be over another applications button. However this is a
+ * fairly rare occurrance.
*
* Results:
* None.
@@ -217,15 +221,16 @@ static void SetTkDialog(ClientData clientData);
*-------------------------------------------------------------------------
*/
-static void EatSpuriousMessageBugFix( void )
+static void EatSpuriousMessageBugFix(void)
{
MSG msg;
DWORD nTime = GetTickCount() + 250;
- while( GetTickCount() < nTime )
- {
- if( PeekMessage(&msg,0,WM_LBUTTONDOWN,WM_LBUTTONDOWN,PM_NOREMOVE) )
+
+ while (GetTickCount() < nTime) {
+ if (PeekMessage(&msg, 0, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_NOREMOVE)){
break;
- PeekMessage(&msg,0,WM_LBUTTONUP,WM_LBUTTONUP,PM_REMOVE);
+ }
+ PeekMessage(&msg, 0, WM_LBUTTONUP, WM_LBUTTONUP, PM_REMOVE);
}
}
@@ -235,8 +240,8 @@ static void EatSpuriousMessageBugFix( void )
* TkWinDialogDebug --
*
* Function to turn on/off debugging support for common dialogs under
- * windows. The variable "tk_debug" is set to the identifier of the
- * dialog window when the modal dialog window pops up and it is safe to
+ * windows. The variable "tk_debug" is set to the identifier of the
+ * dialog window when the modal dialog window pops up and it is safe to
* send messages to the dialog.
*
* Results:
@@ -248,12 +253,12 @@ static void EatSpuriousMessageBugFix( void )
*-------------------------------------------------------------------------
*/
-void
+void
TkWinDialogDebug(
int debug)
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
tsdPtr->debugFlag = debug;
}
@@ -263,15 +268,14 @@ TkWinDialogDebug(
*
* Tk_ChooseColorObjCmd --
*
- * This procedure implements the color dialog box for the Windows
- * platform. See the user documentation for details on what it
- * does.
+ * This function implements the color dialog box for the Windows
+ * platform. See the user documentation for details on what it does.
*
* Results:
* See user documentation.
*
* Side effects:
- * A dialog window is created the first time this procedure is called.
+ * A dialog window is created the first time this function is called.
* This window is not destroyed and will be reused the next time the
* application invokes the "tk_chooseColor" command.
*
@@ -302,11 +306,12 @@ Tk_ChooseColorObjCmd(clientData, interp, objc, objv)
result = TCL_OK;
if (inited == 0) {
/*
- * dwCustColors stores the custom color which the user can
- * modify. We store these colors in a static array so that the next
- * time the color dialog pops up, the same set of custom colors
- * remain in the dialog.
+ * dwCustColors stores the custom color which the user can modify. We
+ * store these colors in a static array so that the next time the
+ * color dialog pops up, the same set of custom colors remain in the
+ * dialog.
*/
+
for (i = 0; i < 16; i++) {
dwCustColors[i] = RGB(255-i * 10, i, i * 10);
}
@@ -318,7 +323,7 @@ Tk_ChooseColorObjCmd(clientData, interp, objc, objv)
parent = tkwin;
chooseColor.lStructSize = sizeof(CHOOSECOLOR);
- chooseColor.hwndOwner = NULL;
+ chooseColor.hwndOwner = NULL;
chooseColor.hInstance = NULL;
chooseColor.rgbResult = oldColor;
chooseColor.lpCustColors = dwCustColors;
@@ -340,36 +345,34 @@ Tk_ChooseColorObjCmd(clientData, interp, objc, objv)
return TCL_ERROR;
}
if (i + 1 == objc) {
- string = Tcl_GetStringFromObj(optionPtr, NULL);
- Tcl_AppendResult(interp, "value for \"", string, "\" missing",
+ string = Tcl_GetString(optionPtr);
+ Tcl_AppendResult(interp, "value for \"", string, "\" missing",
(char *) NULL);
return TCL_ERROR;
}
- string = Tcl_GetStringFromObj(valuePtr, NULL);
+ string = Tcl_GetString(valuePtr);
switch ((enum options) index) {
- case COLOR_INITIAL: {
- XColor *colorPtr;
+ case COLOR_INITIAL: {
+ XColor *colorPtr;
- colorPtr = Tk_GetColor(interp, tkwin, string);
- if (colorPtr == NULL) {
- return TCL_ERROR;
- }
- chooseColor.rgbResult = RGB(colorPtr->red / 0x100,
- colorPtr->green / 0x100, colorPtr->blue / 0x100);
- break;
- }
- case COLOR_PARENT: {
- parent = Tk_NameToWindow(interp, string, tkwin);
- if (parent == NULL) {
- return TCL_ERROR;
- }
- break;
+ colorPtr = Tk_GetColor(interp, tkwin, string);
+ if (colorPtr == NULL) {
+ return TCL_ERROR;
}
- case COLOR_TITLE: {
- chooseColor.lCustData = (LPARAM) string;
- break;
+ chooseColor.rgbResult = RGB(colorPtr->red / 0x100,
+ colorPtr->green / 0x100, colorPtr->blue / 0x100);
+ break;
+ }
+ case COLOR_PARENT:
+ parent = Tk_NameToWindow(interp, string, tkwin);
+ if (parent == NULL) {
+ return TCL_ERROR;
}
+ break;
+ case COLOR_TITLE:
+ chooseColor.lCustData = (LPARAM) string;
+ break;
}
}
@@ -377,16 +380,17 @@ Tk_ChooseColorObjCmd(clientData, interp, objc, objv)
chooseColor.hwndOwner = NULL;
hWnd = Tk_GetHWND(Tk_WindowId(parent));
chooseColor.hwndOwner = hWnd;
-
+
oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
winCode = ChooseColor(&chooseColor);
(void) Tcl_SetServiceMode(oldMode);
/*
- * Ensure that hWnd is enabled, because it can happen that we
- * have updated the wrapper of the parent, which causes us to
- * leave this child disabled (Windows loses sync).
+ * Ensure that hWnd is enabled, because it can happen that we have updated
+ * the wrapper of the parent, which causes us to leave this child disabled
+ * (Windows loses sync).
*/
+
EnableWindow(hWnd, 1);
/*
@@ -407,10 +411,10 @@ Tk_ChooseColorObjCmd(clientData, interp, objc, objv)
char color[100];
sprintf(color, "#%02x%02x%02x",
- GetRValue(chooseColor.rgbResult),
- GetGValue(chooseColor.rgbResult),
+ GetRValue(chooseColor.rgbResult),
+ GetGValue(chooseColor.rgbResult),
GetBValue(chooseColor.rgbResult));
- Tcl_AppendResult(interp, color, NULL);
+ Tcl_AppendResult(interp, color, NULL);
oldColor = chooseColor.rgbResult;
result = TCL_OK;
}
@@ -423,12 +427,12 @@ Tk_ChooseColorObjCmd(clientData, interp, objc, objv)
*
* ColorDlgHookProc --
*
- * Provides special handling of messages for the Color common dialog
- * box. Used to set the title when the dialog first appears.
+ * Provides special handling of messages for the Color common dialog box.
+ * Used to set the title when the dialog first appears.
*
* Results:
- * The return value is 0 if the default dialog box procedure should
- * handle the message, non-zero otherwise.
+ * The return value is 0 if the default dialog box function should handle
+ * the message, non-zero otherwise.
*
* Side effects:
* Changes the title of the dialog window.
@@ -436,39 +440,38 @@ Tk_ChooseColorObjCmd(clientData, interp, objc, objv)
*----------------------------------------------------------------------
*/
-static UINT CALLBACK
+static UINT CALLBACK
ColorDlgHookProc(hDlg, uMsg, wParam, lParam)
HWND hDlg; /* Handle to the color dialog. */
UINT uMsg; /* Type of message. */
WPARAM wParam; /* First message parameter. */
LPARAM lParam; /* Second message parameter. */
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
switch (uMsg) {
- case WM_INITDIALOG: {
- const char *title;
- CHOOSECOLOR *ccPtr;
- Tcl_DString ds;
+ case WM_INITDIALOG: {
+ const char *title;
+ CHOOSECOLOR *ccPtr;
+ Tcl_DString ds;
- /*
- * Set the title string of the dialog.
- */
+ /*
+ * Set the title string of the dialog.
+ */
- ccPtr = (CHOOSECOLOR *) lParam;
- title = (const char *) ccPtr->lCustData;
- if ((title != NULL) && (title[0] != '\0')) {
- (*tkWinProcs->setWindowText)(hDlg,
- Tcl_WinUtfToTChar(title, -1, &ds));
- Tcl_DStringFree(&ds);
- }
- if (tsdPtr->debugFlag) {
- tsdPtr->debugInterp = (Tcl_Interp *) ccPtr->lpTemplateName;
- Tcl_DoWhenIdle(SetTkDialog, (ClientData) hDlg);
- }
- return TRUE;
+ ccPtr = (CHOOSECOLOR *) lParam;
+ title = (const char *) ccPtr->lCustData;
+ if ((title != NULL) && (title[0] != '\0')) {
+ (*tkWinProcs->setWindowText)(hDlg,Tcl_WinUtfToTChar(title,-1,&ds));
+ Tcl_DStringFree(&ds);
+ }
+ if (tsdPtr->debugFlag) {
+ tsdPtr->debugInterp = (Tcl_Interp *) ccPtr->lpTemplateName;
+ Tcl_DoWhenIdle(SetTkDialog, (ClientData) hDlg);
}
+ return TRUE;
+ }
}
return FALSE;
}
@@ -478,15 +481,14 @@ ColorDlgHookProc(hDlg, uMsg, wParam, lParam)
*
* Tk_GetOpenFileCmd --
*
- * This procedure implements the "open file" dialog box for the
- * Windows platform. See the user documentation for details on what
- * it does.
+ * This function implements the "open file" dialog box for the Windows
+ * platform. See the user documentation for details on what it does.
*
* Results:
* See user documentation.
*
* Side effects:
- * A dialog window is created the first this procedure is called.
+ * A dialog window is created the first this function is called.
*
*----------------------------------------------------------------------
*/
@@ -552,14 +554,14 @@ Tk_GetSaveFileObjCmd(clientData, interp, objc, objv)
*----------------------------------------------------------------------
*/
-static int
+static int
GetFileNameW(clientData, interp, objc, objv, open)
ClientData clientData; /* Main window associated with interpreter. */
Tcl_Interp *interp; /* Current interpreter. */
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument objects. */
- int open; /* 1 to call GetOpenFileName(), 0 to
- * call GetSaveFileName(). */
+ int open; /* 1 to call GetOpenFileName(), 0 to call
+ * GetSaveFileName(). */
{
OPENFILENAMEW ofn;
WCHAR file[TK_MULTI_MAX_PATH];
@@ -570,8 +572,8 @@ GetFileNameW(clientData, interp, objc, objv, open)
Tcl_DString utfFilterString, utfDirString;
Tcl_DString extString, filterString, dirString, titleString;
Tcl_Encoding unicodeEncoding = TkWinGetUnicodeEncoding();
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
static CONST char *saveOptionStrings[] = {
"-defaultextension", "-filetypes", "-initialdir", "-initialfile",
"-parent", "-title", NULL
@@ -619,81 +621,76 @@ GetFileNameW(clientData, interp, objc, objv, open)
"option", 0, &index) != TCL_OK) {
goto end;
}
+
/*
* We want to maximize code sharing between the open and save file
* dialog implementations; in particular, the switch statement below.
* We use different sets of option strings from the GetIndexFromObj
- * call above, but a single enumeration for both. The save file
- * dialog doesn't support -multiple, but it falls in the middle of
- * the enumeration. Ultimately, this means that when the index found
- * by GetIndexFromObj is >= FILE_MULTIPLE, when doing a save file
- * dialog, we have to increment the index, so that it matches the
- * open file dialog enumeration.
+ * call above, but a single enumeration for both. The save file dialog
+ * doesn't support -multiple, but it falls in the middle of the
+ * enumeration. Ultimately, this means that when the index found by
+ * GetIndexFromObj is >= FILE_MULTIPLE, when doing a save file dialog,
+ * we have to increment the index, so that it matches the open file
+ * dialog enumeration.
*/
+
if (!open && index >= FILE_MULTIPLE) {
index++;
}
if (i + 1 == objc) {
- string = Tcl_GetStringFromObj(optionPtr, NULL);
- Tcl_AppendResult(interp, "value for \"", string, "\" missing",
+ string = Tcl_GetString(optionPtr);
+ Tcl_AppendResult(interp, "value for \"", string, "\" missing",
(char *) NULL);
goto end;
}
- string = Tcl_GetStringFromObj(valuePtr, NULL);
+ string = Tcl_GetString(valuePtr);
switch ((enum options) index) {
- case FILE_DEFAULT: {
- if (string[0] == '.') {
- string++;
- }
- extension = string;
- break;
+ case FILE_DEFAULT:
+ if (string[0] == '.') {
+ string++;
}
- case FILE_TYPES: {
- Tcl_DStringFree(&utfFilterString);
- if (MakeFilter(interp, valuePtr, &utfFilterString) != TCL_OK) {
- goto end;
- }
- filter = Tcl_DStringValue(&utfFilterString);
- break;
+ extension = string;
+ break;
+ case FILE_TYPES:
+ Tcl_DStringFree(&utfFilterString);
+ if (MakeFilter(interp, valuePtr, &utfFilterString) != TCL_OK) {
+ goto end;
}
- case FILE_INITDIR: {
- Tcl_DStringFree(&utfDirString);
- if (Tcl_TranslateFileName(interp, string,
- &utfDirString) == NULL) {
- goto end;
- }
- break;
+ filter = Tcl_DStringValue(&utfFilterString);
+ break;
+ case FILE_INITDIR:
+ Tcl_DStringFree(&utfDirString);
+ if (Tcl_TranslateFileName(interp, string,
+ &utfDirString) == NULL) {
+ goto end;
}
- case FILE_INITFILE: {
- Tcl_DString ds;
+ break;
+ case FILE_INITFILE: {
+ Tcl_DString ds;
- if (Tcl_TranslateFileName(interp, string, &ds) == NULL) {
- goto end;
- }
- Tcl_UtfToExternal(NULL, unicodeEncoding, Tcl_DStringValue(&ds),
- Tcl_DStringLength(&ds), 0, NULL, (char *) file,
- sizeof(file), NULL, NULL, NULL);
- break;
+ if (Tcl_TranslateFileName(interp, string, &ds) == NULL) {
+ goto end;
}
- case FILE_MULTIPLE: {
- if (Tcl_GetBooleanFromObj(interp, valuePtr,
- &multi) != TCL_OK) {
- return TCL_ERROR;
- }
- break;
- }
- case FILE_PARENT: {
- tkwin = Tk_NameToWindow(interp, string, tkwin);
- if (tkwin == NULL) {
- goto end;
- }
- break;
+ Tcl_UtfToExternal(NULL, unicodeEncoding, Tcl_DStringValue(&ds),
+ Tcl_DStringLength(&ds), 0, NULL, (char *) file,
+ sizeof(file), NULL, NULL, NULL);
+ break;
+ }
+ case FILE_MULTIPLE:
+ if (Tcl_GetBooleanFromObj(interp, valuePtr, &multi) != TCL_OK) {
+ return TCL_ERROR;
}
- case FILE_TITLE: {
- title = string;
- break;
+ break;
+ case FILE_PARENT:
+ tkwin = Tk_NameToWindow(interp, string, tkwin);
+ if (tkwin == NULL) {
+ goto end;
}
+ break;
+ case FILE_TITLE:
+ title = string;
+ break;
}
}
@@ -707,21 +704,19 @@ GetFileNameW(clientData, interp, objc, objv, open)
hWnd = Tk_GetHWND(Tk_WindowId(tkwin));
ZeroMemory(&ofn, sizeof(OPENFILENAMEW));
- ofn.lStructSize = sizeof(OPENFILENAMEW);
- ofn.hwndOwner = hWnd;
+ ofn.lStructSize = sizeof(OPENFILENAMEW);
+ ofn.hwndOwner = hWnd;
#ifdef _WIN64
- ofn.hInstance = (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner,
- GWLP_HINSTANCE);
+ ofn.hInstance = (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner,GWLP_HINSTANCE);
#else
- ofn.hInstance = (HINSTANCE) GetWindowLong(ofn.hwndOwner,
- GWL_HINSTANCE);
+ ofn.hInstance = (HINSTANCE) GetWindowLong(ofn.hwndOwner, GWL_HINSTANCE);
#endif
- ofn.lpstrFile = (WCHAR *) file;
- ofn.nMaxFile = TK_MULTI_MAX_PATH;
- ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST
- | OFN_NOCHANGEDIR | OFN_EXPLORER;
- ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProcW;
- ofn.lCustData = (LPARAM) interp;
+ ofn.lpstrFile = (WCHAR *) file;
+ ofn.nMaxFile = TK_MULTI_MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR
+ | OFN_EXPLORER;
+ ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProcW;
+ ofn.lCustData = (LPARAM) interp;
if (open != 0) {
ofn.Flags |= OFN_FILEMUSTEXIST;
@@ -753,10 +748,10 @@ GetFileNameW(clientData, interp, objc, objv, open)
Tcl_DStringLength(&utfDirString), &dirString);
} else {
/*
- * NT 5.0 changed the meaning of lpstrInitialDir, so we have
- * to ensure that we set the [pwd] if the user didn't specify
- * anything else.
+ * NT 5.0 changed the meaning of lpstrInitialDir, so we have to ensure
+ * that we set the [pwd] if the user didn't specify anything else.
*/
+
Tcl_DString cwd;
Tcl_DStringFree(&utfDirString);
@@ -791,10 +786,11 @@ GetFileNameW(clientData, interp, objc, objv, open)
EatSpuriousMessageBugFix();
/*
- * Ensure that hWnd is enabled, because it can happen that we
- * have updated the wrapper of the parent, which causes us to
- * leave this child disabled (Windows loses sync).
+ * Ensure that hWnd is enabled, because it can happen that we have updated
+ * the wrapper of the parent, which causes us to leave this child disabled
+ * (Windows loses sync).
*/
+
EnableWindow(hWnd, 1);
/*
@@ -810,12 +806,12 @@ GetFileNameW(clientData, interp, objc, objv, open)
if (winCode != 0) {
if (ofn.Flags & OFN_ALLOWMULTISELECT) {
- /*
- * The result in custData->szFile contains many items,
- * separated with null characters. It is terminated with
- * two nulls in a row. The first element is the directory
- * path.
+ /*
+ * The result in custData->szFile contains many items, separated
+ * with null characters. It is terminated with two nulls in a row.
+ * The first element is the directory path.
*/
+
char *dir;
char *p;
char *file;
@@ -831,13 +827,17 @@ GetFileNameW(clientData, interp, objc, objv, open)
files = ofn.lpstrFile;
Tcl_ExternalToUtfDString(unicodeEncoding, (char *) files, -1, &ds);
- /* Get directory */
+ /*
+ * Get directory.
+ */
+
dir = Tcl_DStringValue(&ds);
for (p = dir; p && *p; p++) {
/*
* Change the pathname to the Tcl "normalized" pathname, where
* back slashes are used instead of forward slashes
*/
+
if (*p == '\\') {
*p = '/';
}
@@ -868,10 +868,12 @@ GetFileNameW(clientData, interp, objc, objv, open)
Tcl_DStringFree(&filename);
}
}
+
if (count == 0) {
/*
* Only one file was returned.
*/
+
Tcl_ListObjAppendElement(interp, returnList,
Tcl_NewStringObj(dir, -1));
}
@@ -881,7 +883,7 @@ GetFileNameW(clientData, interp, objc, objv, open)
} else {
char *p;
Tcl_DString ds;
-
+
Tcl_ExternalToUtfDString(unicodeEncoding,
(char *) ofn.lpstrFile, -1, &ds);
for (p = Tcl_DStringValue(&ds); *p != '\0'; p++) {
@@ -902,25 +904,26 @@ GetFileNameW(clientData, interp, objc, objv, open)
* Use the CommDlgExtendedError() function to retrieve the error code.
* This function can return one of about two dozen codes; most of
* these indicate some sort of gross system failure (insufficient
- * memory, bad window handles, etc.). Most of the error codes will be
+ * memory, bad window handles, etc.). Most of the error codes will be
* ignored; as we find we want more specific error messages for
* particular errors, we can extend the code as needed.
*
- * We could also check for FNERR_BUFFERTOOSMALL, but we can't
- * really do anything about it when it happens.
+ * We could also check for FNERR_BUFFERTOOSMALL, but we can't really
+ * do anything about it when it happens.
*/
if (CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
char *p;
Tcl_DString ds;
-
+
Tcl_ExternalToUtfDString(unicodeEncoding,
(char *) ofn.lpstrFile, -1, &ds);
for (p = Tcl_DStringValue(&ds); *p != '\0'; p++) {
/*
- * Change the pathname to the Tcl "normalized" pathname,
- * where back slashes are used instead of forward slashes
+ * Change the pathname to the Tcl "normalized" pathname, where
+ * back slashes are used instead of forward slashes
*/
+
if (*p == '\\') {
*p = '/';
}
@@ -932,7 +935,7 @@ GetFileNameW(clientData, interp, objc, objv, open)
result = TCL_OK;
}
}
-
+
if (ofn.lpstrTitle != NULL) {
Tcl_DStringFree(&titleString);
}
@@ -944,7 +947,7 @@ GetFileNameW(clientData, interp, objc, objv, open)
Tcl_DStringFree(&extString);
}
- end:
+ end:
Tcl_DStringFree(&utfDirString);
Tcl_DStringFree(&utfFilterString);
@@ -956,9 +959,8 @@ GetFileNameW(clientData, interp, objc, objv, open)
*
* OFNHookProcW --
*
- * Hook procedure called only if debugging is turned on. Sets
- * the "tk_dialog" variable when the dialog is ready to receive
- * messages.
+ * Hook function called only if debugging is turned on. Sets the
+ * "tk_dialog" variable when the dialog is ready to receive messages.
*
* Results:
* Returns 0 to allow default processing of messages to occur.
@@ -969,15 +971,15 @@ GetFileNameW(clientData, interp, objc, objv, open)
*-------------------------------------------------------------------------
*/
-static UINT APIENTRY
+static UINT APIENTRY
OFNHookProcW(
- HWND hdlg, // handle to child dialog window
- UINT uMsg, // message identifier
- WPARAM wParam, // message parameter
- LPARAM lParam) // message parameter
+ HWND hdlg, /* Handle to child dialog window. */
+ UINT uMsg, /* Message identifier */
+ WPARAM wParam, /* Message parameter */
+ LPARAM lParam) /* Message parameter */
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
OPENFILENAMEW *ofnPtr;
if (uMsg == WM_INITDIALOG) {
@@ -988,16 +990,15 @@ OFNHookProcW(
#endif
} else if (uMsg == WM_WINDOWPOSCHANGED) {
/*
- * This message is delivered at the right time to enable Tk
- * to set the debug information. Unhooks itself so it
- * won't set the debug information every time it gets a
- * WM_WINDOWPOSCHANGED message.
+ * This message is delivered at the right time to enable Tk to set the
+ * debug information. Unhooks itself so it won't set the debug
+ * information every time it gets a WM_WINDOWPOSCHANGED message.
*/
#ifdef _WIN64
- ofnPtr = (OPENFILENAMEW *) GetWindowLongPtr(hdlg, GWLP_USERDATA);
+ ofnPtr = (OPENFILENAMEW *) GetWindowLongPtr(hdlg, GWLP_USERDATA);
#else
- ofnPtr = (OPENFILENAMEW *) GetWindowLong(hdlg, GWL_USERDATA);
+ ofnPtr = (OPENFILENAMEW *) GetWindowLong(hdlg, GWL_USERDATA);
#endif
if (ofnPtr != NULL) {
hdlg = GetParent(hdlg);
@@ -1029,14 +1030,14 @@ OFNHookProcW(
*----------------------------------------------------------------------
*/
-static int
+static int
GetFileNameA(clientData, interp, objc, objv, open)
ClientData clientData; /* Main window associated with interpreter. */
Tcl_Interp *interp; /* Current interpreter. */
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument objects. */
- int open; /* 1 to call GetOpenFileName(), 0 to
- * call GetSaveFileName(). */
+ int open; /* 1 to call GetOpenFileName(), 0 to call
+ * GetSaveFileName(). */
{
OPENFILENAME ofn;
TCHAR file[TK_MULTI_MAX_PATH], savePath[MAX_PATH];
@@ -1046,8 +1047,8 @@ GetFileNameA(clientData, interp, objc, objv, open)
HWND hWnd;
Tcl_DString utfFilterString, utfDirString;
Tcl_DString extString, filterString, dirString, titleString;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
static CONST char *saveOptionStrings[] = {
"-defaultextension", "-filetypes", "-initialdir", "-initialfile",
"-parent", "-title", NULL
@@ -1095,81 +1096,75 @@ GetFileNameA(clientData, interp, objc, objv, open)
"option", 0, &index) != TCL_OK) {
goto end;
}
+
/*
* We want to maximize code sharing between the open and save file
* dialog implementations; in particular, the switch statement below.
* We use different sets of option strings from the GetIndexFromObj
- * call above, but a single enumeration for both. The save file
- * dialog doesn't support -multiple, but it falls in the middle of
- * the enumeration. Ultimately, this means that when the index found
- * by GetIndexFromObj is >= FILE_MULTIPLE, when doing a save file
- * dialog, we have to increment the index, so that it matches the
- * open file dialog enumeration.
+ * call above, but a single enumeration for both. The save file dialog
+ * doesn't support -multiple, but it falls in the middle of the
+ * enumeration. Ultimately, this means that when the index found by
+ * GetIndexFromObj is >= FILE_MULTIPLE, when doing a save file dialog,
+ * we have to increment the index, so that it matches the open file
+ * dialog enumeration.
*/
+
if (!open && index >= FILE_MULTIPLE) {
index++;
}
if (i + 1 == objc) {
- string = Tcl_GetStringFromObj(optionPtr, NULL);
- Tcl_AppendResult(interp, "value for \"", string, "\" missing",
+ string = Tcl_GetString(optionPtr);
+ Tcl_AppendResult(interp, "value for \"", string, "\" missing",
(char *) NULL);
goto end;
}
- string = Tcl_GetStringFromObj(valuePtr, NULL);
+ string = Tcl_GetString(valuePtr);
switch ((enum options) index) {
- case FILE_DEFAULT: {
- if (string[0] == '.') {
- string++;
- }
- extension = string;
- break;
+ case FILE_DEFAULT:
+ if (string[0] == '.') {
+ string++;
}
- case FILE_TYPES: {
- Tcl_DStringFree(&utfFilterString);
- if (MakeFilter(interp, valuePtr, &utfFilterString) != TCL_OK) {
- goto end;
- }
- filter = Tcl_DStringValue(&utfFilterString);
- break;
+ extension = string;
+ break;
+ case FILE_TYPES:
+ Tcl_DStringFree(&utfFilterString);
+ if (MakeFilter(interp, valuePtr, &utfFilterString) != TCL_OK) {
+ goto end;
}
- case FILE_INITDIR: {
- Tcl_DStringFree(&utfDirString);
- if (Tcl_TranslateFileName(interp, string,
- &utfDirString) == NULL) {
- goto end;
- }
- break;
+ filter = Tcl_DStringValue(&utfFilterString);
+ break;
+ case FILE_INITDIR:
+ Tcl_DStringFree(&utfDirString);
+ if (Tcl_TranslateFileName(interp, string, &utfDirString) == NULL) {
+ goto end;
}
- case FILE_INITFILE: {
- Tcl_DString ds;
+ break;
+ case FILE_INITFILE: {
+ Tcl_DString ds;
- if (Tcl_TranslateFileName(interp, string, &ds) == NULL) {
- goto end;
- }
- Tcl_UtfToExternal(NULL, NULL, Tcl_DStringValue(&ds),
- Tcl_DStringLength(&ds), 0, NULL, (char *) file,
- sizeof(file), NULL, NULL, NULL);
- break;
+ if (Tcl_TranslateFileName(interp, string, &ds) == NULL) {
+ goto end;
}
- case FILE_MULTIPLE: {
- if (Tcl_GetBooleanFromObj(interp, valuePtr,
- &multi) != TCL_OK) {
- return TCL_ERROR;
- }
- break;
- }
- case FILE_PARENT: {
- tkwin = Tk_NameToWindow(interp, string, tkwin);
- if (tkwin == NULL) {
- goto end;
- }
- break;
+ Tcl_UtfToExternal(NULL, NULL, Tcl_DStringValue(&ds),
+ Tcl_DStringLength(&ds), 0, NULL, (char *) file,
+ sizeof(file), NULL, NULL, NULL);
+ break;
+ }
+ case FILE_MULTIPLE:
+ if (Tcl_GetBooleanFromObj(interp, valuePtr, &multi) != TCL_OK) {
+ return TCL_ERROR;
}
- case FILE_TITLE: {
- title = string;
- break;
+ break;
+ case FILE_PARENT:
+ tkwin = Tk_NameToWindow(interp, string, tkwin);
+ if (tkwin == NULL) {
+ goto end;
}
+ break;
+ case FILE_TITLE:
+ title = string;
+ break;
}
}
@@ -1182,33 +1177,31 @@ GetFileNameA(clientData, interp, objc, objv, open)
Tk_MakeWindowExist(tkwin);
hWnd = Tk_GetHWND(Tk_WindowId(tkwin));
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = hWnd;
+ ofn.lStructSize = sizeof(ofn);
+ ofn.hwndOwner = hWnd;
#ifdef _WIN64
- ofn.hInstance = (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner,
- GWLP_HINSTANCE);
+ ofn.hInstance = (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner,GWLP_HINSTANCE);
#else
- ofn.hInstance = (HINSTANCE) GetWindowLong(ofn.hwndOwner,
- GWL_HINSTANCE);
+ ofn.hInstance = (HINSTANCE) GetWindowLong(ofn.hwndOwner, GWL_HINSTANCE);
#endif
- ofn.lpstrFilter = NULL;
- ofn.lpstrCustomFilter = NULL;
- ofn.nMaxCustFilter = 0;
- ofn.nFilterIndex = 0;
- ofn.lpstrFile = (LPTSTR) file;
- ofn.nMaxFile = TK_MULTI_MAX_PATH;
- ofn.lpstrFileTitle = NULL;
- ofn.nMaxFileTitle = 0;
- ofn.lpstrInitialDir = NULL;
- ofn.lpstrTitle = NULL;
- ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST
- | OFN_NOCHANGEDIR | OFN_EXPLORER;
- ofn.nFileOffset = 0;
- ofn.nFileExtension = 0;
- ofn.lpstrDefExt = NULL;
- ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProc;
- ofn.lCustData = (LPARAM) interp;
- ofn.lpTemplateName = NULL;
+ ofn.lpstrFilter = NULL;
+ ofn.lpstrCustomFilter = NULL;
+ ofn.nMaxCustFilter = 0;
+ ofn.nFilterIndex = 0;
+ ofn.lpstrFile = (LPTSTR) file;
+ ofn.nMaxFile = TK_MULTI_MAX_PATH;
+ ofn.lpstrFileTitle = NULL;
+ ofn.nMaxFileTitle = 0;
+ ofn.lpstrInitialDir = NULL;
+ ofn.lpstrTitle = NULL;
+ ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR
+ | OFN_EXPLORER;
+ ofn.nFileOffset = 0;
+ ofn.nFileExtension = 0;
+ ofn.lpstrDefExt = NULL;
+ ofn.lpfnHook = (LPOFNHOOKPROC) OFNHookProc;
+ ofn.lCustData = (LPARAM) interp;
+ ofn.lpTemplateName = NULL;
if (open != 0) {
ofn.Flags |= OFN_FILEMUSTEXIST;
@@ -1237,10 +1230,10 @@ GetFileNameA(clientData, interp, objc, objv, open)
Tcl_DStringLength(&utfDirString), &dirString);
} else {
/*
- * NT 5.0 changed the meaning of lpstrInitialDir, so we have
- * to ensure that we set the [pwd] if the user didn't specify
- * anything else.
+ * NT 5.0 changed the meaning of lpstrInitialDir, so we have to ensure
+ * that we set the [pwd] if the user didn't specify anything else.
*/
+
Tcl_DString cwd;
Tcl_DStringFree(&utfDirString);
@@ -1277,10 +1270,11 @@ GetFileNameA(clientData, interp, objc, objv, open)
SetCurrentDirectory(savePath);
/*
- * Ensure that hWnd is enabled, because it can happen that we
- * have updated the wrapper of the parent, which causes us to
- * leave this child disabled (Windows loses sync).
+ * Ensure that hWnd is enabled, because it can happen that we have updated
+ * the wrapper of the parent, which causes us to leave this child disabled
+ * (Windows loses sync).
*/
+
EnableWindow(hWnd, 1);
/*
@@ -1296,12 +1290,12 @@ GetFileNameA(clientData, interp, objc, objv, open)
if (winCode != 0) {
if (ofn.Flags & OFN_ALLOWMULTISELECT) {
- /*
- * The result in custData->szFile contains many items,
- * separated with null characters. It is terminated with
- * two nulls in a row. The first element is the directory
- * path.
+ /*
+ * The result in custData->szFile contains many items, separated
+ * with null characters. It is terminated with two nulls in a row.
+ * The first element is the directory path.
*/
+
char *dir;
char *p;
char *file;
@@ -1317,13 +1311,17 @@ GetFileNameA(clientData, interp, objc, objv, open)
files = ofn.lpstrFile;
Tcl_ExternalToUtfDString(NULL, (char *) files, -1, &ds);
- /* Get directory */
+ /*
+ * Get directory.
+ */
+
dir = Tcl_DStringValue(&ds);
for (p = dir; p && *p; p++) {
/*
* Change the pathname to the Tcl "normalized" pathname, where
* back slashes are used instead of forward slashes
*/
+
if (*p == '\\') {
*p = '/';
}
@@ -1358,6 +1356,7 @@ GetFileNameA(clientData, interp, objc, objv, open)
/*
* Only one file was returned.
*/
+
Tcl_ListObjAppendElement(interp, returnList,
Tcl_NewStringObj(dir, -1));
}
@@ -1374,6 +1373,7 @@ GetFileNameA(clientData, interp, objc, objv, open)
* Change the pathname to the Tcl "normalized" pathname, where
* back slashes are used instead of forward slashes
*/
+
if (*p == '\\') {
*p = '/';
}
@@ -1387,13 +1387,14 @@ GetFileNameA(clientData, interp, objc, objv, open)
* Use the CommDlgExtendedError() function to retrieve the error code.
* This function can return one of about two dozen codes; most of
* these indicate some sort of gross system failure (insufficient
- * memory, bad window handles, etc.). Most of the error codes will be
- * ignored;; as we find we want specific error messages for particular
+ * memory, bad window handles, etc.) Most of the error codes will be
+ * ignored; as we find we want specific error messages for particular
* errors, we can extend the code as needed.
*
- * We could also check for FNERR_BUFFERTOOSMALL, but we can't
- * really do anything about it when it happens.
+ * We could also check for FNERR_BUFFERTOOSMALL, but we can't really
+ * do anything about it when it happens.
*/
+
if (CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
char *p;
Tcl_DString ds;
@@ -1401,9 +1402,10 @@ GetFileNameA(clientData, interp, objc, objv, open)
Tcl_ExternalToUtfDString(NULL, (char *) ofn.lpstrFile, -1, &ds);
for (p = Tcl_DStringValue(&ds); *p != '\0'; p++) {
/*
- * Change the pathname to the Tcl "normalized" pathname,
- * where back slashes are used instead of forward slashes
+ * Change the pathname to the Tcl "normalized" pathname, where
+ * back slashes are used instead of forward slashes
*/
+
if (*p == '\\') {
*p = '/';
}
@@ -1427,7 +1429,7 @@ GetFileNameA(clientData, interp, objc, objv, open)
Tcl_DStringFree(&extString);
}
- end:
+ end:
Tcl_DStringFree(&utfDirString);
Tcl_DStringFree(&utfFilterString);
@@ -1439,9 +1441,8 @@ GetFileNameA(clientData, interp, objc, objv, open)
*
* OFNHookProc --
*
- * Hook procedure called only if debugging is turned on. Sets
- * the "tk_dialog" variable when the dialog is ready to receive
- * messages.
+ * Hook function called only if debugging is turned on. Sets the
+ * "tk_dialog" variable when the dialog is ready to receive messages.
*
* Results:
* Returns 0 to allow default processing of messages to occur.
@@ -1452,15 +1453,15 @@ GetFileNameA(clientData, interp, objc, objv, open)
*-------------------------------------------------------------------------
*/
-static UINT APIENTRY
+static UINT APIENTRY
OFNHookProc(
- HWND hdlg, // handle to child dialog window
- UINT uMsg, // message identifier
- WPARAM wParam, // message parameter
- LPARAM lParam) // message parameter
+ HWND hdlg, /* handle to child dialog window */
+ UINT uMsg, /* message identifier */
+ WPARAM wParam, /* message parameter */
+ LPARAM lParam) /* message parameter */
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
OPENFILENAME *ofnPtr;
if (uMsg == WM_INITDIALOG) {
@@ -1471,17 +1472,16 @@ OFNHookProc(
#endif
} else if (uMsg == WM_WINDOWPOSCHANGED) {
/*
- * This message is delivered at the right time to both
- * old-style and explorer-style hook procs to enable Tk
- * to set the debug information. Unhooks itself so it
- * won't set the debug information every time it gets a
- * WM_WINDOWPOSCHANGED message.
+ * This message is delivered at the right time to both old-style and
+ * explorer-style hook procs to enable Tk to set the debug
+ * information. Unhooks itself so it won't set the debug information
+ * every time it gets a WM_WINDOWPOSCHANGED message.
*/
#ifdef _WIN64
- ofnPtr = (OPENFILENAME *) GetWindowLongPtr(hdlg, GWLP_USERDATA);
+ ofnPtr = (OPENFILENAME *) GetWindowLongPtr(hdlg, GWLP_USERDATA);
#else
- ofnPtr = (OPENFILENAME *) GetWindowLong(hdlg, GWL_USERDATA);
+ ofnPtr = (OPENFILENAME *) GetWindowLong(hdlg, GWL_USERDATA);
#endif
if (ofnPtr != NULL) {
if (ofnPtr->Flags & OFN_EXPLORER) {
@@ -1505,7 +1505,7 @@ OFNHookProc(
* MakeFilter --
*
* Allocate a buffer to store the filters in a format understood by
- * Windows
+ * Windows.
*
* Results:
* A standard TCL return value.
@@ -1515,8 +1515,9 @@ OFNHookProc(
*
*----------------------------------------------------------------------
*/
-static int
-MakeFilter(interp, valuePtr, dsPtr)
+
+static int
+MakeFilter(interp, valuePtr, dsPtr)
Tcl_Interp *interp; /* Current interpreter. */
Tcl_Obj *valuePtr; /* Value of the -filetypes option */
Tcl_DString *dsPtr; /* Filled with windows filter string. */
@@ -1553,15 +1554,17 @@ MakeFilter(interp, valuePtr, dsPtr)
} else {
int len;
+
if (valuePtr == NULL) {
len = 0;
} else {
CONST char* string = Tcl_GetStringFromObj(valuePtr, &len);
}
-
- /* We format the filetype into a string understood by Windows:
- * {"Text Documents" {.doc .txt} {TEXT}} becomes
- * "Text Documents (*.doc,*.txt)\0*.doc;*.txt\0"
+
+ /*
+ * We format the filetype into a string understood by Windows: {"Text
+ * Documents" {.doc .txt} {TEXT}} becomes "Text Documents
+ * (*.doc,*.txt)\0*.doc;*.txt\0"
*
* See the Windows OPENFILENAME manual page for details on the filter
* string format.
@@ -1571,16 +1574,18 @@ MakeFilter(interp, valuePtr, dsPtr)
* Since we may only add asterisks (*) to the filter, we need at most
* twice the size of the string to format the filter
*/
+
filterStr = ckalloc((unsigned int) len * 3);
for (filterPtr = flist.filters, p = filterStr; filterPtr;
- filterPtr = filterPtr->next) {
+ filterPtr = filterPtr->next) {
char *sep;
FileFilterClause *clausePtr;
/*
- * First, put in the name of the file type
+ * First, put in the name of the file type.
*/
+
strcpy(p, filterPtr->name);
p+= strlen(filterPtr->name);
*p++ = ' ';
@@ -1588,24 +1593,24 @@ MakeFilter(interp, valuePtr, dsPtr)
for (pass = 1; pass <= 2; pass++) {
/*
- * In the first pass, we format the extensions in the
- * name field. In the second pass, we format the extensions in
- * the filter pattern field
+ * In the first pass, we format the extensions in the name
+ * field. In the second pass, we format the extensions in the
+ * filter pattern field
*/
+
sep = "";
for (clausePtr=filterPtr->clauses;clausePtr;
- clausePtr=clausePtr->next) {
+ clausePtr=clausePtr->next) {
GlobPattern *globPtr;
-
for (globPtr=clausePtr->patterns; globPtr;
globPtr=globPtr->next) {
strcpy(p, sep);
- p+= strlen(sep);
+ p += strlen(sep);
strcpy(p, globPtr->pattern);
- p+= strlen(globPtr->pattern);
+ p += strlen(globPtr->pattern);
- if (pass==1) {
+ if (pass == 1) {
sep = ",";
} else {
sep = ";";
@@ -1613,11 +1618,9 @@ MakeFilter(interp, valuePtr, dsPtr)
}
}
if (pass == 1) {
- if (pass == 1) {
- *p ++ = ')';
- }
+ *p ++ = ')';
}
- *p ++ = '\0';
+ *p++ = '\0';
}
}
@@ -1625,6 +1628,7 @@ MakeFilter(interp, valuePtr, dsPtr)
* Windows requires the filter string to be ended by two NULL
* characters.
*/
+
*p++ = '\0';
*p = '\0';
}
@@ -1642,77 +1646,78 @@ MakeFilter(interp, valuePtr, dsPtr)
*
* Tk_ChooseDirectoryObjCmd --
*
- * This procedure implements the "tk_chooseDirectory" dialog box
- * for the Windows platform. See the user documentation for details
- * on what it does. Uses the newer SHBrowseForFolder explorer type
- * interface.
+ * This function implements the "tk_chooseDirectory" dialog box for the
+ * Windows platform. See the user documentation for details on what it
+ * does. Uses the newer SHBrowseForFolder explorer type interface.
*
* Results:
- * See user documentation.
+ * See user documentation.
*
* Side effects:
- * A modal dialog window is created. Tcl_SetServiceMode() is
- * called to allow background events to be processed
+ * A modal dialog window is created. Tcl_SetServiceMode() is called to
+ * allow background events to be processed
*
*----------------------------------------------------------------------
-
-The procedure tk_chooseDirectory pops up a dialog box for the user to
-select a directory. The following option-value pairs are possible as
-command line arguments:
-
--initialdir dirname
-
-Specifies that the directories in directory should be displayed when the
-dialog pops up. If this parameter is not specified, then the directories
-in the current working directory are displayed. If the parameter specifies
-a relative path, the return value will convert the relative path to an
-absolute path. This option may not always work on the Macintosh. This is
-not a bug. Rather, the General Controls control panel on the Mac allows
-the end user to override the application default directory.
-
--parent window
-
-Makes window the logical parent of the dialog. The dialog is displayed on
-top of its parent window.
-
--title titleString
-
-Specifies a string to display as the title of the dialog box. If this
-option is not specified, then a default title will be displayed.
-
--mustexist boolean
-
-Specifies whether the user may specify non-existant directories. If this
-parameter is true, then the user may only select directories that already
-exist. The default value is false.
-
-New Behaviour:
-
-- If mustexist = 0 and a user entered folder does not exist, a prompt will
- pop-up asking if the user wants another chance to change it. The old
- dialog just returned the bogus entry. On mustexist = 1, the entries MUST
- exist before exiting the box with OK.
-
- Bugs:
-
-- If valid abs directory name is entered into the entry box and Enter
- pressed, the box will close returning the name. This is inconsistent when
- entering relative names or names with forward slashes, which are
- invalidated then corrected in the callback. After correction, the box is
- held open to allow further modification by the user.
-
-- Not sure how to implement localization of message prompts.
-
-- -title is really -message.
-ToDo:
-- Fix bugs.
-- test to see what platforms this really works on. May require v4.71
- of shell32.dll everywhere (what is standard?).
*
+ * The function tk_chooseDirectory pops up a dialog box for the user to select
+ * a directory. The following option-value pairs are possible as command line
+ * arguments:
+ *
+ * -initialdir dirname
+ *
+ * Specifies that the directories in directory should be displayed when the
+ * dialog pops up. If this parameter is not specified, then the directories in
+ * the current working directory are displayed. If the parameter specifies a
+ * relative path, the return value will convert the relative path to an
+ * absolute path. This option may not always work on the Macintosh. This is
+ * not a bug. Rather, the General Controls control panel on the Mac allows the
+ * end user to override the application default directory.
+ *
+ * -parent window
+ *
+ * Makes window the logical parent of the dialog. The dialog is displayed on
+ * top of its parent window.
+ *
+ * -title titleString
+ *
+ * Specifies a string to display as the title of the dialog box. If this
+ * option is not specified, then a default title will be displayed.
+ *
+ * -mustexist boolean
+ *
+ * Specifies whether the user may specify non-existant directories. If this
+ * parameter is true, then the user may only select directories that already
+ * exist. The default value is false.
+ *
+ * New Behaviour:
+ *
+ * - If mustexist = 0 and a user entered folder does not exist, a prompt will
+ * pop-up asking if the user wants another chance to change it. The old
+ * dialog just returned the bogus entry. On mustexist = 1, the entries MUST
+ * exist before exiting the box with OK.
+ *
+ * Bugs:
+ *
+ * - If valid abs directory name is entered into the entry box and Enter
+ * pressed, the box will close returning the name. This is inconsistent when
+ * entering relative names or names with forward slashes, which are
+ * invalidated then corrected in the callback. After correction, the box is
+ * held open to allow further modification by the user.
+ *
+ * - Not sure how to implement localization of message prompts.
+ *
+ * - -title is really -message.
+ * ToDo:
+ * - Fix bugs.
+ * - test to see what platforms this really works on. May require v4.71 of
+ * shell32.dll everywhere (what is standard?).
+ *
+ *----------------------------------------------------------------------
*/
+
int
Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
- ClientData clientData; /* Main window associated with interpreter. */
+ ClientData clientData; /* Main window associated with interpreter. */
Tcl_Interp *interp; /* Current interpreter. */
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument objects. */
@@ -1731,81 +1736,81 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
Tcl_DString titleString; /* UTF Title */
Tcl_DString initDirString; /* Initial directory */
static CONST char *optionStrings[] = {
- "-initialdir", "-mustexist", "-parent", "-title", (char *) NULL
+ "-initialdir", "-mustexist", "-parent", "-title", (char *) NULL
};
enum options {
- DIR_INITIAL, DIR_EXIST, DIR_PARENT, FILE_TITLE
+ DIR_INITIAL, DIR_EXIST, DIR_PARENT, FILE_TITLE
};
/*
* Initialize
*/
- result = TCL_ERROR;
- path[0] = '\0';
- utfTitle = NULL;
+
+ result = TCL_ERROR;
+ path[0] = '\0';
+ utfTitle = NULL;
ZeroMemory(&cdCBData, sizeof(CHOOSEDIRDATA));
- cdCBData.interp = interp;
+ cdCBData.interp = interp;
tkwin = (Tk_Window) clientData;
+
/*
* Process the command line options
*/
+
for (i = 1; i < objc; i += 2) {
- int index;
- char *string;
- Tcl_Obj *optionPtr, *valuePtr;
-
- optionPtr = objv[i];
- valuePtr = objv[i + 1];
-
- if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings, "option",
- 0, &index) != TCL_OK) {
- goto cleanup;
- }
- if (i + 1 == objc) {
- string = Tcl_GetStringFromObj(optionPtr, NULL);
- Tcl_AppendResult(interp, "value for \"", string, "\" missing",
- (char *) NULL);
- goto cleanup;
- }
+ int index;
+ char *string;
+ Tcl_Obj *optionPtr, *valuePtr;
+
+ optionPtr = objv[i];
+ valuePtr = objv[i + 1];
+
+ if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings, "option", 0,
+ &index) != TCL_OK) {
+ goto cleanup;
+ }
+ if (i + 1 == objc) {
+ string = Tcl_GetString(optionPtr);
+ Tcl_AppendResult(interp, "value for \"", string, "\" missing",
+ (char *) NULL);
+ goto cleanup;
+ }
string = Tcl_GetString(valuePtr);
- switch ((enum options) index) {
- case DIR_INITIAL: {
- if (Tcl_TranslateFileName(interp, string,
- &initDirString) == NULL) {
- goto cleanup;
- }
- string = Tcl_DStringValue(&initDirString);
- /*
- * Convert possible relative path to full path to keep
- * dialog happy
- */
- GetFullPathName(string, MAX_PATH, saveDir, NULL);
- lstrcpyn(cdCBData.utfInitDir, saveDir, MAX_PATH);
- Tcl_DStringFree(&initDirString);
- break;
- }
- case DIR_EXIST: {
- if (Tcl_GetBooleanFromObj(interp, valuePtr,
- &cdCBData.mustExist) != TCL_OK) {
- goto cleanup;
- }
- break;
- }
- case DIR_PARENT: {
- tkwin = Tk_NameToWindow(interp, string, tkwin);
- if (tkwin == NULL) {
- goto cleanup;
- }
- break;
- }
- case FILE_TITLE: {
- utfTitle = string;
- break;
- }
- }
+ switch ((enum options) index) {
+ case DIR_INITIAL:
+ if (Tcl_TranslateFileName(interp,string,&initDirString) == NULL) {
+ goto cleanup;
+ }
+ string = Tcl_DStringValue(&initDirString);
+
+ /*
+ * Convert possible relative path to full path to keep dialog
+ * happy.
+ */
+
+ GetFullPathName(string, MAX_PATH, saveDir, NULL);
+ lstrcpyn(cdCBData.utfInitDir, saveDir, MAX_PATH);
+ Tcl_DStringFree(&initDirString);
+ break;
+ case DIR_EXIST:
+ if (Tcl_GetBooleanFromObj(interp, valuePtr,
+ &cdCBData.mustExist) != TCL_OK) {
+ goto cleanup;
+ }
+ break;
+ case DIR_PARENT:
+ tkwin = Tk_NameToWindow(interp, string, tkwin);
+ if (tkwin == NULL) {
+ goto cleanup;
+ }
+ break;
+ case FILE_TITLE:
+ utfTitle = string;
+ break;
+ }
}
/*
@@ -1819,44 +1824,50 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
* Setup the parameters used by SHBrowseForFolder
*/
- bInfo.hwndOwner = hWnd;
+ bInfo.hwndOwner = hWnd;
bInfo.pszDisplayName = path;
- bInfo.pidlRoot = NULL;
+ bInfo.pidlRoot = NULL;
if (lstrlen(cdCBData.utfInitDir) == 0) {
- GetCurrentDirectory(MAX_PATH, cdCBData.utfInitDir);
+ GetCurrentDirectory(MAX_PATH, cdCBData.utfInitDir);
}
bInfo.lParam = (LPARAM) &cdCBData;
if (utfTitle != NULL) {
- Tcl_UtfToExternalDString(NULL, utfTitle, -1, &titleString);
- bInfo.lpszTitle = (LPTSTR) Tcl_DStringValue(&titleString);
+ Tcl_UtfToExternalDString(NULL, utfTitle, -1, &titleString);
+ bInfo.lpszTitle = (LPTSTR) Tcl_DStringValue(&titleString);
} else {
- bInfo.lpszTitle = "Please choose a directory, then select OK.";
+ bInfo.lpszTitle = "Please choose a directory, then select OK.";
}
/*
* Set flags to add edit box (needs 4.71 Shell DLLs), status text line,
* validate edit box and
*/
- bInfo.ulFlags = BIF_EDITBOX | BIF_STATUSTEXT | BIF_RETURNFSANCESTORS
- | BIF_VALIDATE;
+
+ bInfo.ulFlags = BIF_EDITBOX | BIF_STATUSTEXT | BIF_RETURNFSANCESTORS
+ | BIF_VALIDATE;
/*
* Callback to handle events
*/
- bInfo.lpfn = (BFFCALLBACK) ChooseDirectoryValidateProc;
+
+ bInfo.lpfn = (BFFCALLBACK) ChooseDirectoryValidateProc;
/*
- * Display dialog in background and process result.
- * We look to give the user a chance to change their mind
- * on an invalid folder if mustexist is 0;
+ * Display dialog in background and process result. We look to give the
+ * user a chance to change their mind on an invalid folder if mustexist is
+ * 0;
*/
oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
GetCurrentDirectory(MAX_PATH, saveDir);
if (SHGetMalloc(&pMalloc) == NOERROR) {
pidl = SHBrowseForFolder(&bInfo);
- /* Null for cancel button or invalid dir, otherwise valid*/
+
+ /*
+ * Null for cancel button or invalid dir, otherwise valid.
+ */
+
if (pidl != NULL) {
if (!SHGetPathFromIDList(pidl, path)) {
Tcl_SetResult(interp, "Error: Not a file system folder\n",
@@ -1872,38 +1883,40 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
Tcl_SetServiceMode(oldMode);
/*
- * Ensure that hWnd is enabled, because it can happen that we
- * have updated the wrapper of the parent, which causes us to
- * leave this child disabled (Windows loses sync).
+ * Ensure that hWnd is enabled, because it can happen that we have updated
+ * the wrapper of the parent, which causes us to leave this child disabled
+ * (Windows loses sync).
*/
+
EnableWindow(hWnd, 1);
/*
- * Change the pathname to the Tcl "normalized" pathname, where
- * back slashes are used instead of forward slashes
+ * Change the pathname to the Tcl "normalized" pathname, where back
+ * slashes are used instead of forward slashes
*/
+
Tcl_ResetResult(interp);
if (*path) {
- char *p;
- Tcl_DString ds;
+ char *p;
+ Tcl_DString ds;
- Tcl_ExternalToUtfDString(NULL, (char *) path, -1, &ds);
- for (p = Tcl_DStringValue(&ds); *p != '\0'; p++) {
- if (*p == '\\') {
- *p = '/';
- }
- }
- Tcl_AppendResult(interp, Tcl_DStringValue(&ds), NULL);
- Tcl_DStringFree(&ds);
+ Tcl_ExternalToUtfDString(NULL, (char *) path, -1, &ds);
+ for (p = Tcl_DStringValue(&ds); *p != '\0'; p++) {
+ if (*p == '\\') {
+ *p = '/';
+ }
+ }
+ Tcl_AppendResult(interp, Tcl_DStringValue(&ds), NULL);
+ Tcl_DStringFree(&ds);
}
result = TCL_OK;
if (utfTitle != NULL) {
- Tcl_DStringFree(&titleString);
+ Tcl_DStringFree(&titleString);
}
- cleanup:
+ cleanup:
return result;
}
@@ -1912,15 +1925,17 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
*
* ChooseDirectoryValidateProc --
*
- * Hook procedure called by the explorer ChooseDirectory dialog when events
- * occur. It is used to validate the text entry the user may have entered.
+ * Hook function called by the explorer ChooseDirectory dialog when
+ * events occur. It is used to validate the text entry the user may have
+ * entered.
*
* Results:
- * Returns 0 to allow default processing of message, or 1 to
- * tell default dialog procedure not to close.
+ * Returns 0 to allow default processing of message, or 1 to
+ * tell default dialog function not to close.
*
*----------------------------------------------------------------------
*/
+
static UINT APIENTRY
ChooseDirectoryValidateProc (
HWND hwnd,
@@ -1933,7 +1948,7 @@ ChooseDirectoryValidateProc (
Tcl_DString initDirString;
char string[MAX_PATH];
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
chooseDirSharedData = (CHOOSEDIRDATA *)lpData;
@@ -1944,120 +1959,123 @@ ChooseDirectoryValidateProc (
#endif
if (tsdPtr->debugFlag) {
- tsdPtr->debugInterp = (Tcl_Interp *) chooseDirSharedData->interp;
- Tcl_DoWhenIdle(SetTkDialog, (ClientData) hwnd);
+ tsdPtr->debugInterp = (Tcl_Interp *) chooseDirSharedData->interp;
+ Tcl_DoWhenIdle(SetTkDialog, (ClientData) hwnd);
}
chooseDirSharedData->utfRetDir[0] = '\0';
switch (message) {
- case BFFM_VALIDATEFAILED:
- /*
- * First save and check to see if it is a valid path name, if
- * so then make that path the one shown in the
- * window. Otherwise, it failed the check and should be treated
- * as such. Use Set/GetCurrentDirectory which allows relative
- * path names and names with forward slashes. Use
- * Tcl_TranslateFileName to make sure names like ~ are
- * converted correctly.
- */
- Tcl_TranslateFileName(chooseDirSharedData->interp,
- (char *)lParam, &initDirString);
- lstrcpyn (string, Tcl_DStringValue(&initDirString), MAX_PATH);
- Tcl_DStringFree(&initDirString);
-
- if (SetCurrentDirectory((char *)string) == 0) {
- LPTSTR lpFilePart[MAX_PATH];
- /*
- * Get the full path name to the user entry,
- * at this point it doesn't exist so see if
- * it is supposed to. Otherwise just return it.
- */
- GetFullPathName(string, MAX_PATH,
- chooseDirSharedData->utfRetDir, /*unused*/ lpFilePart);
- if (chooseDirSharedData->mustExist) {
- /*
- * User HAS to select a valid directory.
- */
- wsprintf(selDir, TEXT("Directory '%.200s' does not exist,\nplease select or enter an existing directory."), chooseDirSharedData->utfRetDir);
- MessageBox(NULL, selDir, NULL, MB_ICONEXCLAMATION|MB_OK);
- return 1;
- }
- } else {
- /*
- * Changed to new folder OK, return immediatly with the
- * current directory in utfRetDir.
- */
- GetCurrentDirectory(MAX_PATH, chooseDirSharedData->utfRetDir);
- return 0;
- }
- return 0;
-
- case BFFM_SELCHANGED:
- /*
- * Set the status window to the currently selected path.
- * And enable the OK button if a file system folder, otherwise
- * disable the OK button for things like server names.
- * perhaps a new switch -enablenonfolders can be used to allow
- * non folders to be selected.
- *
- * Not called when user changes edit box directly.
- */
-
- if (SHGetPathFromIDList((LPITEMIDLIST) lParam, selDir)) {
- SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) selDir);
- // enable the OK button
- SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
- SetCurrentDirectory(selDir);
- } else {
- // disable the OK button
- SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 0);
- }
- UpdateWindow(hwnd);
- return 1;
-
- case BFFM_INITIALIZED: {
- /*
- * Directory browser intializing - tell it where to start from,
- * user specified parameter.
- */
- char *initDir = chooseDirSharedData->utfInitDir;
-
- SetCurrentDirectory(initDir);
- if (*initDir == '\\') {
+ case BFFM_VALIDATEFAILED:
+ /*
+ * First save and check to see if it is a valid path name, if so then
+ * make that path the one shown in the window. Otherwise, it failed
+ * the check and should be treated as such. Use
+ * Set/GetCurrentDirectory which allows relative path names and names
+ * with forward slashes. Use Tcl_TranslateFileName to make sure names
+ * like ~ are converted correctly.
+ */
+
+ Tcl_TranslateFileName(chooseDirSharedData->interp,
+ (char *)lParam, &initDirString);
+ lstrcpyn (string, Tcl_DStringValue(&initDirString), MAX_PATH);
+ Tcl_DStringFree(&initDirString);
+
+ if (SetCurrentDirectory((char *)string) == 0) {
+ LPTSTR lpFilePart[MAX_PATH];
+
+ /*
+ * Get the full path name to the user entry, at this point it
+ * doesn't exist so see if it is supposed to. Otherwise just
+ * return it.
+ */
+
+ GetFullPathName(string, MAX_PATH,
+ chooseDirSharedData->utfRetDir, /*unused*/ lpFilePart);
+ if (chooseDirSharedData->mustExist) {
/*
- * BFFM_SETSELECTION only understands UNC paths as pidls,
- * so convert path to pidl using IShellFolder interface.
+ * User HAS to select a valid directory.
*/
- LPMALLOC pMalloc;
- LPSHELLFOLDER psfFolder;
-
- if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
- if (SUCCEEDED(SHGetDesktopFolder(&psfFolder))) {
- LPITEMIDLIST pidlMain;
- ULONG ulCount, ulAttr;
- Tcl_DString ds;
-
- Tcl_UtfToExternalDString(TkWinGetUnicodeEncoding(),
- initDir, -1, &ds);
- if (SUCCEEDED(psfFolder->lpVtbl->ParseDisplayName(
- psfFolder, hwnd, NULL,
- (WCHAR *) Tcl_DStringValue(&ds),
- &ulCount, &pidlMain, &ulAttr))
- && (pidlMain != NULL)) {
- SendMessage(hwnd, BFFM_SETSELECTION, FALSE,
- (LPARAM)pidlMain);
- pMalloc->lpVtbl->Free(pMalloc, pidlMain);
- }
- psfFolder->lpVtbl->Release(psfFolder);
- Tcl_DStringFree(&ds);
+
+ wsprintf(selDir, TEXT("Directory '%.200s' does not exist,\nplease select or enter an existing directory."), chooseDirSharedData->utfRetDir);
+ MessageBox(NULL, selDir, NULL, MB_ICONEXCLAMATION|MB_OK);
+ return 1;
+ }
+ } else {
+ /*
+ * Changed to new folder OK, return immediatly with the
+ * current directory in utfRetDir.
+ */
+ GetCurrentDirectory(MAX_PATH, chooseDirSharedData->utfRetDir);
+ return 0;
+ }
+ return 0;
+
+ case BFFM_SELCHANGED:
+ /*
+ * Set the status window to the currently selected path. And enable
+ * the OK button if a file system folder, otherwise disable the OK
+ * button for things like server names. Perhaps a new switch
+ * -enablenonfolders can be used to allow non folders to be selected.
+ *
+ * Not called when user changes edit box directly.
+ */
+
+ if (SHGetPathFromIDList((LPITEMIDLIST) lParam, selDir)) {
+ SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM) selDir);
+ // enable the OK button
+ SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
+ SetCurrentDirectory(selDir);
+ } else {
+ // disable the OK button
+ SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 0);
+ }
+ UpdateWindow(hwnd);
+ return 1;
+
+ case BFFM_INITIALIZED: {
+ /*
+ * Directory browser intializing - tell it where to start from, user
+ * specified parameter.
+ */
+
+ char *initDir = chooseDirSharedData->utfInitDir;
+
+ SetCurrentDirectory(initDir);
+ if (*initDir == '\\') {
+ /*
+ * BFFM_SETSELECTION only understands UNC paths as pidls,
+ * so convert path to pidl using IShellFolder interface.
+ */
+
+ LPMALLOC pMalloc;
+ LPSHELLFOLDER psfFolder;
+
+ if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
+ if (SUCCEEDED(SHGetDesktopFolder(&psfFolder))) {
+ LPITEMIDLIST pidlMain;
+ ULONG ulCount, ulAttr;
+ Tcl_DString ds;
+
+ Tcl_UtfToExternalDString(TkWinGetUnicodeEncoding(),
+ initDir, -1, &ds);
+ if (SUCCEEDED(psfFolder->lpVtbl->ParseDisplayName(
+ psfFolder, hwnd, NULL, (WCHAR *)
+ Tcl_DStringValue(&ds), &ulCount,&pidlMain,&ulAttr))
+ && (pidlMain != NULL)) {
+ SendMessage(hwnd, BFFM_SETSELECTION, FALSE,
+ (LPARAM)pidlMain);
+ pMalloc->lpVtbl->Free(pMalloc, pidlMain);
}
- pMalloc->lpVtbl->Release(pMalloc);
+ psfFolder->lpVtbl->Release(psfFolder);
+ Tcl_DStringFree(&ds);
}
- } else {
- SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)initDir);
+ pMalloc->lpVtbl->Release(pMalloc);
}
- SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
- break;
+ } else {
+ SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)initDir);
}
+ SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
+ break;
+ }
}
return 0;
@@ -2068,16 +2086,16 @@ ChooseDirectoryValidateProc (
*
* Tk_ChooseDirectoryObjCmd --
*
- * This procedure implements the "tk_chooseDirectory" dialog box
- * for the Windows platform. See the user documentation for details
- * on what it does.
+ * This function implements the "tk_chooseDirectory" dialog box for the
+ * Windows platform. See the user documentation for details on what it
+ * does.
*
* Results:
* See user documentation.
*
* Side effects:
- * A modal dialog window is created. Tcl_SetServiceMode() is
- * called to allow background events to be processed
+ * A modal dialog window is created. Tcl_SetServiceMode() is called to
+ * allow background events to be processed
*
*----------------------------------------------------------------------
*/
@@ -2098,8 +2116,8 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
char *utfTitle;
Tcl_DString utfDirString;
Tcl_DString titleString, dirString;
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
static CONST char *optionStrings[] = {
"-initialdir", "-mustexist", "-parent", "-title",
NULL
@@ -2109,9 +2127,9 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
};
if (tsdPtr->WM_LBSELCHANGED == 0) {
- tsdPtr->WM_LBSELCHANGED = RegisterWindowMessage(LBSELCHSTRING);
+ tsdPtr->WM_LBSELCHANGED = RegisterWindowMessage(LBSELCHSTRING);
}
-
+
result = TCL_ERROR;
path[0] = '\0';
@@ -2128,44 +2146,39 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
optionPtr = objv[i];
valuePtr = objv[i + 1];
- if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings, "option",
- 0, &index) != TCL_OK) {
+ if (Tcl_GetIndexFromObj(interp, optionPtr, optionStrings, "option", 0,
+ &index) != TCL_OK) {
goto cleanup;
}
if (i + 1 == objc) {
- string = Tcl_GetStringFromObj(optionPtr, NULL);
- Tcl_AppendResult(interp, "value for \"", string, "\" missing",
+ string = Tcl_GetString(optionPtr);
+ Tcl_AppendResult(interp, "value for \"", string, "\" missing",
(char *) NULL);
goto cleanup;
}
- string = Tcl_GetStringFromObj(valuePtr, NULL);
+ string = Tcl_GetString(valuePtr);
switch ((enum options) index) {
- case DIR_INITIAL: {
- Tcl_DStringFree(&utfDirString);
- if (Tcl_TranslateFileName(interp, string,
- &utfDirString) == NULL) {
- goto cleanup;
- }
- break;
- }
- case DIR_EXIST: {
- if (Tcl_GetBooleanFromObj(interp, valuePtr, &mustExist) != TCL_OK) {
- goto cleanup;
- }
- break;
+ case DIR_INITIAL:
+ Tcl_DStringFree(&utfDirString);
+ if (Tcl_TranslateFileName(interp, string, &utfDirString) == NULL) {
+ goto cleanup;
}
- case DIR_PARENT: {
- tkwin = Tk_NameToWindow(interp, string, tkwin);
- if (tkwin == NULL) {
- goto cleanup;
- }
- break;
+ break;
+ case DIR_EXIST:
+ if (Tcl_GetBooleanFromObj(interp,valuePtr,&mustExist) != TCL_OK) {
+ goto cleanup;
}
- case FILE_TITLE: {
- utfTitle = string;
- break;
+ break;
+ case DIR_PARENT:
+ tkwin = Tk_NameToWindow(interp, string, tkwin);
+ if (tkwin == NULL) {
+ goto cleanup;
}
+ break;
+ case FILE_TITLE:
+ utfTitle = string;
+ break;
}
}
@@ -2175,43 +2188,40 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
cd.interp = interp;
cd.ofnPtr = &ofn;
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = hWnd;
+ ofn.lStructSize = sizeof(ofn);
+ ofn.hwndOwner = hWnd;
#ifdef _WIN64
- ofn.hInstance = (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner,
- GWLP_HINSTANCE);
+ ofn.hInstance = (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner,GWLP_HINSTANCE);
#else
- ofn.hInstance = (HINSTANCE) GetWindowLong(ofn.hwndOwner,
- GWL_HINSTANCE);
+ ofn.hInstance = (HINSTANCE) GetWindowLong(ofn.hwndOwner, GWL_HINSTANCE);
#endif
- ofn.lpstrFilter = NULL;
- ofn.lpstrCustomFilter = NULL;
- ofn.nMaxCustFilter = 0;
- ofn.nFilterIndex = 0;
- ofn.lpstrFile = NULL; //(TCHAR *) path;
- ofn.nMaxFile = MAX_PATH;
- ofn.lpstrFileTitle = NULL;
- ofn.nMaxFileTitle = 0;
- ofn.lpstrInitialDir = NULL;
- ofn.lpstrTitle = NULL;
- ofn.Flags = OFN_HIDEREADONLY
- | OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
- ofn.nFileOffset = 0;
- ofn.nFileExtension = 0;
- ofn.lpstrDefExt = NULL;
- ofn.lCustData = (LPARAM) &cd;
- ofn.lpfnHook = (LPOFNHOOKPROC) ChooseDirectoryHookProc;
- ofn.lpTemplateName = MAKEINTRESOURCE(FILEOPENORD);
+ ofn.lpstrFilter = NULL;
+ ofn.lpstrCustomFilter = NULL;
+ ofn.nMaxCustFilter = 0;
+ ofn.nFilterIndex = 0;
+ ofn.lpstrFile = NULL; //(TCHAR *) path;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.lpstrFileTitle = NULL;
+ ofn.nMaxFileTitle = 0;
+ ofn.lpstrInitialDir = NULL;
+ ofn.lpstrTitle = NULL;
+ ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
+ ofn.nFileOffset = 0;
+ ofn.nFileExtension = 0;
+ ofn.lpstrDefExt = NULL;
+ ofn.lCustData = (LPARAM) &cd;
+ ofn.lpfnHook = (LPOFNHOOKPROC) ChooseDirectoryHookProc;
+ ofn.lpTemplateName = MAKEINTRESOURCE(FILEOPENORD);
if (Tcl_DStringValue(&utfDirString)[0] != '\0') {
- Tcl_UtfToExternalDString(NULL, Tcl_DStringValue(&utfDirString),
+ Tcl_UtfToExternalDString(NULL, Tcl_DStringValue(&utfDirString),
Tcl_DStringLength(&utfDirString), &dirString);
} else {
/*
- * NT 5.0 changed the meaning of lpstrInitialDir, so we have
- * to ensure that we set the [pwd] if the user didn't specify
- * anything else.
+ * NT 5.0 changed the meaning of lpstrInitialDir, so we have to ensure
+ * that we set the [pwd] if the user didn't specify anything else.
*/
+
Tcl_DString cwd;
Tcl_DStringFree(&utfDirString);
@@ -2236,10 +2246,10 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
}
/*
- * Display dialog. The choose directory dialog doesn't preserve the
+ * Display dialog. The choose directory dialog doesn't preserve the
* current directory, so it must be saved and restored here.
*/
-
+
GetCurrentDirectory(MAX_PATH, savePath);
mode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
code = GetOpenFileName(&ofn);
@@ -2247,17 +2257,18 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
SetCurrentDirectory(savePath);
/*
- * Ensure that hWnd is enabled, because it can happen that we
- * have updated the wrapper of the parent, which causes us to
- * leave this child disabled (Windows loses sync).
+ * Ensure that hWnd is enabled, because it can happen that we have updated
+ * the wrapper of the parent, which causes us to leave this child disabled
+ * (Windows loses sync).
*/
+
EnableWindow(hWnd, 1);
Tcl_ResetResult(interp);
if (code != 0) {
/*
- * Change the pathname to the Tcl "normalized" pathname, where
- * back slashes are used instead of forward slashes
+ * Change the pathname to the Tcl "normalized" pathname, where back
+ * slashes are used instead of forward slashes
*/
char *p;
@@ -2281,7 +2292,7 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
}
result = TCL_OK;
- cleanup:
+ cleanup:
Tcl_DStringFree(&utfDirString);
return result;
@@ -2292,35 +2303,33 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv)
*
* ChooseDirectoryHookProc --
*
- * Hook procedure called by the ChooseDirectory dialog to modify
- * its default behavior. The ChooseDirectory dialog is really an
- * OpenFile dialog with certain controls rearranged and certain
- * behaviors changed. For instance, typing a name in the
- * ChooseDirectory dialog selects a directory, rather than
- * selecting a file.
+ * Hook function called by the ChooseDirectory dialog to modify its
+ * default behavior. The ChooseDirectory dialog is really an OpenFile
+ * dialog with certain controls rearranged and certain behaviors changed.
+ * For instance, typing a name in the ChooseDirectory dialog selects a
+ * directory, rather than selecting a file.
*
* Results:
- * Returns 0 to allow default processing of message, or 1 to
- * tell default dialog procedure not to process the message.
+ * Returns 0 to allow default processing of message, or 1 to tell default
+ * dialog function not to process the message.
*
* Side effects:
- * A dialog window is created the first this procedure is called.
- * This window is not destroyed and will be reused the next time
- * the application invokes the "tk_getOpenFile" or
- * "tk_getSaveFile" command.
+ * A dialog window is created the first this function is called. This
+ * window is not destroyed and will be reused the next time the
+ * application invokes the "tk_getOpenFile" or "tk_getSaveFile" command.
*
*----------------------------------------------------------------------
*/
-static UINT APIENTRY
+static UINT APIENTRY
ChooseDirectoryHookProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
OPENFILENAME *ofnPtr;
ChooseDir *cdPtr;
@@ -2353,7 +2362,7 @@ ChooseDirectoryHookProc(
/*
* GWL_USERDATA keeps track of cdPtr.
*/
-
+
#ifdef _WIN64
cdPtr = (ChooseDir *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
#else
@@ -2366,15 +2375,15 @@ ChooseDirectoryHookProc(
if (message == tsdPtr->WM_LBSELCHANGED) {
/*
- * Called when double-clicking on directory.
- * If directory wasn't already open, browse that directory.
- * If directory was already open, return selected directory.
+ * Called when double-clicking on directory. If directory wasn't
+ * already open, browse that directory. If directory was already open,
+ * return selected directory.
*/
int idCtrl, thisItem;
idCtrl = (int) wParam;
- thisItem = LOWORD(lParam);
+ thisItem = LOWORD(lParam);
GetCurrentDirectory(MAX_PATH, cdPtr->path);
if (idCtrl == lst2) {
@@ -2404,18 +2413,17 @@ ChooseDirectoryHookProc(
}
/*
- * Dialogs also get the message that OK was clicked when Enter
- * is pressed in some other control. Find out what window
- * we were really in when we got the supposed "OK", because the
- * behavior is different.
+ * Dialogs also get the message that OK was clicked when Enter is
+ * pressed in some other control. Find out what window we were really
+ * in when we got the supposed "OK", because the behavior is
+ * different.
*/
if (cdPtr->lastCtrl == edt10) {
/*
- * Hit Enter or clicked OK while typing a directory name in the
- * edit control.
- * If it's a new name, try to go to that directory.
- * If the name hasn't changed since last time, return selected
+ * Hit Enter or clicked OK while typing a directory name in the
+ * edit control. If it's a new name, try to go to that directory.
+ * If the name hasn't changed since last time, return selected
* directory.
*/
@@ -2436,7 +2444,7 @@ ChooseDirectoryHookProc(
if (ofnPtr->Flags & OFN_PATHMUSTEXIST) {
/*
- * Directory must exist. Complain, then rehighlight text.
+ * Directory must exist. Complain, then rehighlight text.
*/
wsprintf(tmp, _T("Cannot change directory to \"%.200s\"."),
@@ -2444,46 +2452,45 @@ ChooseDirectoryHookProc(
MessageBox(hwnd, tmp, NULL, MB_OK);
SendDlgItemMessage(hwnd, edt10, EM_SETSEL, 0, -1);
return 0;
- }
+ }
if (changed) {
/*
* Directory was invalid, but we want to keep displaying
- * this name. Don't update the listbox that displays the
+ * this name. Don't update the listbox that displays the
* current directory heirarchy, or it'll erase the name.
*/
-
+
SendDlgItemMessage(hwnd, edt10, EM_SETSEL, 0, -1);
return 0;
}
}
if (changed == 0) {
/*
- * Name hasn't changed since the last time we hit return
- * or double-clicked on a directory, so return this.
+ * Name hasn't changed since the last time we hit return or
+ * double-clicked on a directory, so return this.
*/
EndDialog(hwnd, IDOK);
return 1;
}
-
+
cdPtr->lastCtrl = IDOK;
/*
- * The following is the magic code, determined by running
- * Spy++ on some other directory chooser, that it takes to
- * get this dialog to update the listbox to display the
- * current directory.
+ * The following is the magic code, determined by running Spy++ on
+ * some other directory chooser, that it takes to get this dialog
+ * to update the listbox to display the current directory.
*/
SetDlgItemText(hwnd, edt1, cdPtr->path);
- SendMessage(hwnd, WM_COMMAND, (WPARAM) MAKELONG(cmb2, 0x8003),
+ SendMessage(hwnd, WM_COMMAND, (WPARAM) MAKELONG(cmb2, 0x8003),
(LPARAM) GetDlgItem(hwnd, cmb2));
return 0;
} else if (idCtrl == lst2) {
/*
- * Enter key was pressed while in listbox.
- * If it's a new directory, allow default behavior to open dir.
- * If the directory hasn't changed, return selected directory.
+ * Enter key was pressed while in listbox. If it's a new
+ * directory, allow default behavior to open dir. If the directory
+ * hasn't changed, return selected directory.
*/
int thisItem;
@@ -2495,9 +2502,9 @@ ChooseDirectoryHookProc(
return 1;
}
} else if (idCtrl == IDOK) {
- /*
+ /*
* The OK button was clicked. Return the value currently selected
- * in the entry.
+ * in the entry.
*/
GetCurrentDirectory(MAX_PATH, cdPtr->path);
@@ -2514,15 +2521,14 @@ ChooseDirectoryHookProc(
*
* Tk_MessageBoxObjCmd --
*
- * This procedure implements the MessageBox window for the
- * Windows platform. See the user documentation for details on what
- * it does.
+ * This function implements the MessageBox window for the Windows
+ * platform. See the user documentation for details on what it does.
*
* Results:
* See user documentation.
*
* Side effects:
- * None. The MessageBox window will be destroy before this procedure
+ * None. The MessageBox window will be destroy before this function
* returns.
*
*----------------------------------------------------------------------
@@ -2551,18 +2557,18 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
MSG_DEFAULT, MSG_DETAIL, MSG_ICON, MSG_MESSAGE,
MSG_PARENT, MSG_TITLE, MSG_TYPE
};
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
tkwin = (Tk_Window) clientData;
- defaultBtn = -1;
- detail = NULL;
- icon = MB_ICONINFORMATION;
- message = NULL;
- parent = tkwin;
- title = NULL;
- type = MB_OK;
+ defaultBtn = -1;
+ detail = NULL;
+ icon = MB_ICONINFORMATION;
+ message = NULL;
+ parent = tkwin;
+ title = NULL;
+ type = MB_OK;
for (i = 1; i < objc; i += 2) {
int index;
@@ -2577,16 +2583,16 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
return TCL_ERROR;
}
if (i + 1 == objc) {
- string = Tcl_GetStringFromObj(optionPtr, NULL);
- Tcl_AppendResult(interp, "value for \"", string, "\" missing",
+ string = Tcl_GetString(optionPtr);
+ Tcl_AppendResult(interp, "value for \"", string, "\" missing",
(char *) NULL);
return TCL_ERROR;
}
- string = Tcl_GetStringFromObj(valuePtr, NULL);
+ string = Tcl_GetString(valuePtr);
switch ((enum options) index) {
- case MSG_DEFAULT:
- defaultBtn = TkFindStateNumObj(interp, optionPtr, buttonMap,
+ case MSG_DEFAULT:
+ defaultBtn = TkFindStateNumObj(interp, optionPtr, buttonMap,
valuePtr);
if (defaultBtn < 0) {
return TCL_ERROR;
@@ -2608,7 +2614,7 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
message = string;
break;
- case MSG_PARENT:
+ case MSG_PARENT:
parent = Tk_NameToWindow(interp, string, tkwin);
if (parent == NULL) {
return TCL_ERROR;
@@ -2625,13 +2631,12 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
return TCL_ERROR;
}
break;
-
}
}
Tk_MakeWindowExist(parent);
hWnd = Tk_GetHWND(Tk_WindowId(parent));
-
+
flags = 0;
if (defaultBtn >= 0) {
int defaultBtnIdx;
@@ -2649,7 +2654,7 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
}
if (defaultBtnIdx < 0) {
Tcl_AppendResult(interp, "invalid default button \"",
- TkFindStateString(buttonMap, defaultBtn),
+ TkFindStateString(buttonMap, defaultBtn),
"\"", NULL);
return TCL_ERROR;
}
@@ -2683,13 +2688,14 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
/*
- * MessageBoxW exists for all platforms. Use it to allow unicode
- * error message to be displayed correctly where possible by the OS.
+ * MessageBoxW exists for all platforms. Use it to allow unicode error
+ * message to be displayed correctly where possible by the OS.
*
- * In order to have the parent window icon reflected in a MessageBox,
- * we have to create a hook that will trigger when the MessageBox is
- * being created.
+ * In order to have the parent window icon reflected in a MessageBox, we
+ * have to create a hook that will trigger when the MessageBox is being
+ * created.
*/
+
tsdPtr->hSmallIcon = TkWinGetIcon(parent, ICON_SMALL);
tsdPtr->hBigIcon = TkWinGetIcon(parent, ICON_BIG);
tsdPtr->hMsgBoxHook = SetWindowsHookEx(WH_CBT, MsgBoxCBTProc, NULL,
@@ -2700,10 +2706,11 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
(void) Tcl_SetServiceMode(oldMode);
/*
- * Ensure that hWnd is enabled, because it can happen that we
- * have updated the wrapper of the parent, which causes us to
- * leave this child disabled (Windows loses sync).
+ * Ensure that hWnd is enabled, because it can happen that we have updated
+ * the wrapper of the parent, which causes us to leave this child disabled
+ * (Windows loses sync).
*/
+
EnableWindow(hWnd, 1);
Tcl_DStringFree(&messageString);
@@ -2716,41 +2723,50 @@ Tk_MessageBoxObjCmd(clientData, interp, objc, objv)
static LRESULT CALLBACK
MsgBoxCBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
if (nCode == HCBT_CREATEWND) {
/*
- * Window owned by our task is being created. Since the hook is
+ * Window owned by our task is being created. Since the hook is
* installed just before the MessageBox call and removed after the
- * MessageBox call, the window being created is either the message
- * box or one of its controls. Check that the class is WC_DIALOG
- * to ensure that it's the one we want.
+ * MessageBox call, the window being created is either the message box
+ * or one of its controls. Check that the class is WC_DIALOG to ensure
+ * that it's the one we want.
*/
+
LPCBT_CREATEWND lpcbtcreate = (LPCBT_CREATEWND)lParam;
if (WC_DIALOG == lpcbtcreate->lpcs->lpszClass) {
HWND hwnd = (HWND) wParam;
SendMessage(hwnd, WM_SETICON, ICON_SMALL,
(LPARAM) tsdPtr->hSmallIcon);
- SendMessage(hwnd, WM_SETICON, ICON_BIG,
- (LPARAM) tsdPtr->hBigIcon);
+ SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) tsdPtr->hBigIcon);
}
}
/*
* Call the next hook proc, if there is one
*/
+
return CallNextHookEx(tsdPtr->hMsgBoxHook, nCode, wParam, lParam);
}
-static void
+static void
SetTkDialog(ClientData clientData)
{
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
char buf[32];
sprintf(buf, "0x%p", (HWND) clientData);
Tcl_SetVar(tsdPtr->debugInterp, "tk_dialog", buf, TCL_GLOBAL_ONLY);
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * End:
+ */