From 39394c1167057439fa67fd1e23f5ffcc569d84a9 Mon Sep 17 00:00:00 2001 From: das Date: Tue, 11 Apr 2006 12:05:16 +0000 Subject: * macosx/tkMacOSXDialog.c (Tk_MessageBoxObjCmd): added standard Escape key binding for msgbox cancel buttons [Patch 1193614], whitespace. --- ChangeLog | 3 + changes | 4 +- macosx/tkMacOSXDialog.c | 1516 ++++++++++++++++++++++++----------------------- 3 files changed, 769 insertions(+), 754 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2171c1f..1ef227a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ * changes: added latest aqua bug fixes. + * macosx/tkMacOSXDialog.c (Tk_MessageBoxObjCmd): added standard Escape + key binding for msgbox cancel buttons [Patch 1193614], whitespace. + * macosx/tkMacOSXCarbonEvents.c: handle kEventCommandUpdateStatus * macosx/tkMacOSXEvent.c: carbon event to dynamically enable the 'Preferences' app menu item when proc [::tk::mac::ShowPreferences] diff --git a/changes b/changes index 3293266..590c5b2 100644 --- a/changes +++ b/changes @@ -2,7 +2,7 @@ This file summarizes all changes made to Tk since version 1.0 was released on March 13, 1991. Changes that aren't backward compatible are marked specially. -RCS: @(#) $Id: changes,v 1.64.2.34 2006/04/11 10:23:34 das Exp $ +RCS: @(#) $Id: changes,v 1.64.2.35 2006/04/11 12:05:18 das Exp $ 3/16/91 (bug fix) Modified tkWindow.c to remove Tk's Tcl commands from the interpreter when the main window is deleted (otherwise there will @@ -5922,6 +5922,8 @@ accept the color names "Black" and "White" (porter) 2006-04-11 (bug fix)[700316] Aqua: enable 'Preferences' app menu item (steffen) +2006-04-11 (bug fix)[1193614] Aqua: tk_messageBox escape key binding (steffen) + 2006-04-11 (enhancement)[1105284] Aqua: call ::tk::mac::* procs for all registered applevents (steffen) diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 1f7100c..51d62b9 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.10 2006/03/28 02:44:13 das Exp $ + * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.11 2006/04/11 12:05:18 das Exp $ */ #include "tkMacOSXInt.h" @@ -63,26 +63,26 @@ typedef struct { } CallbackUserData; -static OSStatus AlertHandler _ANSI_ARGS_(( EventHandlerCallRef callRef, - EventRef eventRef, void *userData )); -static Boolean MatchOneType _ANSI_ARGS_((StringPtr fileNamePtr, OSType fileType, - OpenFileData *myofdPtr, FileFilter *filterPtr)); -static pascal Boolean OpenFileFilterProc(AEDesc* theItem, void* info, - NavCallBackUserData callBackUD, - NavFilterModes filterMode ); +static OSStatus AlertHandler(EventHandlerCallRef callRef, + EventRef eventRef, void *userData); +static Boolean MatchOneType(StringPtr fileNamePtr, OSType fileType, + OpenFileData *myofdPtr, FileFilter *filterPtr); +static pascal Boolean OpenFileFilterProc(AEDesc* theItem, void* info, + NavCallBackUserData callBackUD, + NavFilterModes filterMode); static pascal void OpenEventProc(NavEventCallbackMessage callBackSelector, - NavCBRecPtr callBackParms, - NavCallBackUserData callBackUD ); + NavCBRecPtr callBackParms, + NavCallBackUserData callBackUD); static void InitFileDialogs(); static int NavServicesGetFile(Tcl_Interp *interp, OpenFileData *ofd, - AEDesc *initialDescPtr, - char *initialFile, AEDescList *selectDescPtr, - CFStringRef title, CFStringRef message, int multiple, int isOpen); + AEDesc *initialDescPtr, + char *initialFile, AEDescList *selectDescPtr, + CFStringRef title, CFStringRef message, int multiple, int isOpen); static int HandleInitialDirectory (Tcl_Interp *interp, - char *initialFile, char *initialDir, - FSRef *dirRef, - AEDescList *selectDescPtr, - AEDesc *dirDescPtr); + char *initialFile, char *initialDir, + FSRef *dirRef, + AEDescList *selectDescPtr, + AEDesc *dirDescPtr); /* * Have we initialized the file dialog subsystem @@ -131,106 +131,106 @@ Tk_ChooseColorObjCmd( static int inited = 0; static RGBColor in; static CONST char *optionStrings[] = { - "-initialcolor", "-parent", "-title", NULL + "-initialcolor", "-parent", "-title", NULL }; enum options { - COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE + COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE }; if (inited == 0) { - /* - * 'in' stores the last color picked. The next time the color dialog - * pops up, the last color will remain in the dialog. - */ - - in.red = 0xffff; - in.green = 0xffff; - in.blue = 0xffff; - inited = 1; + /* + * 'in' stores the last color picked. The next time the color dialog + * pops up, the last color will remain in the dialog. + */ + + in.red = 0xffff; + in.green = 0xffff; + in.blue = 0xffff; + inited = 1; } - + parent = (Tk_Window) clientData; title = "Choose a color:"; picked = 0; - + for (i = 1; i < objc; i += 2) { - int index; - char *option, *value; - - if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings, "option", - TCL_EXACT, &index) != TCL_OK) { - return TCL_ERROR; - } - if (i + 1 == objc) { - option = Tcl_GetStringFromObj(objv[i], NULL); - Tcl_AppendResult(interp, "value for \"", option, "\" missing", - (char *) NULL); - return TCL_ERROR; - } - value = Tcl_GetStringFromObj(objv[i + 1], NULL); - - switch ((enum options) index) { - case COLOR_INITIAL: { - XColor *colorPtr; - - colorPtr = Tk_GetColor(interp, parent, value); - if (colorPtr == NULL) { - return TCL_ERROR; - } - in.red = colorPtr->red; - in.green = colorPtr->green; - in.blue = colorPtr->blue; - Tk_FreeColor(colorPtr); - break; - } - case COLOR_PARENT: { - parent = Tk_NameToWindow(interp, value, parent); - if (parent == NULL) { - return TCL_ERROR; - } - break; - } - case COLOR_TITLE: { - title = value; - break; - } - } + int index; + char *option, *value; + + if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings, "option", + TCL_EXACT, &index) != TCL_OK) { + return TCL_ERROR; + } + if (i + 1 == objc) { + option = Tcl_GetStringFromObj(objv[i], NULL); + Tcl_AppendResult(interp, "value for \"", option, "\" missing", + (char *) NULL); + return TCL_ERROR; + } + value = Tcl_GetStringFromObj(objv[i + 1], NULL); + + switch ((enum options) index) { + case COLOR_INITIAL: { + XColor *colorPtr; + + colorPtr = Tk_GetColor(interp, parent, value); + if (colorPtr == NULL) { + return TCL_ERROR; + } + in.red = colorPtr->red; + in.green = colorPtr->green; + in.blue = colorPtr->blue; + Tk_FreeColor(colorPtr); + break; + } + case COLOR_PARENT: { + parent = Tk_NameToWindow(interp, value, parent); + if (parent == NULL) { + return TCL_ERROR; + } + break; + } + case COLOR_TITLE: { + title = value; + break; + } + } } - + cpinfo.theColor.profile = 0L; cpinfo.theColor.color.rgb.red = in.red; cpinfo.theColor.color.rgb.green = in.green; cpinfo.theColor.color.rgb.blue = in.blue; cpinfo.dstProfile = 0L; - cpinfo.flags = kColorPickerCanModifyPalette - | kColorPickerCanAnimatePalette; + cpinfo.flags = kColorPickerCanModifyPalette + | kColorPickerCanAnimatePalette; cpinfo.placeWhere = kDeepestColorScreen; cpinfo.pickerType = 0L; cpinfo.eventProc = NULL; cpinfo.colorProc = NULL; cpinfo.colorProcData = 0; - + /* This doesn't seem to actually set the title! */ - Tcl_UtfToExternal(NULL, NULL, title, -1, 0, NULL, - StrBody(cpinfo.prompt), 255, &srcRead, &dstWrote, NULL); + Tcl_UtfToExternal(NULL, NULL, title, -1, 0, NULL, + StrBody(cpinfo.prompt), 255, &srcRead, &dstWrote, NULL); StrLength(cpinfo.prompt) = (unsigned char) dstWrote; if ((PickColor(&cpinfo) == noErr) && (cpinfo.newColorChosen != 0)) { - in.red = cpinfo.theColor.color.rgb.red; - in.green = cpinfo.theColor.color.rgb.green; - in.blue = cpinfo.theColor.color.rgb.blue; - picked = 1; + in.red = cpinfo.theColor.color.rgb.red; + in.green = cpinfo.theColor.color.rgb.green; + in.blue = cpinfo.theColor.color.rgb.blue; + picked = 1; } - + if (picked != 0) { - char result[32]; + char result[32]; - sprintf(result, "#%02x%02x%02x", in.red >> 8, in.green >> 8, - in.blue >> 8); - Tcl_AppendResult(interp, result, NULL); + sprintf(result, "#%02x%02x%02x", in.red >> 8, in.green >> 8, + in.blue >> 8); + Tcl_AppendResult(interp, result, NULL); } - + return TCL_OK; } @@ -268,22 +268,22 @@ Tk_GetOpenFileObjCmd( AEDescList selectDesc = {typeNull, NULL}; char *initialFile = NULL, *initialDir = NULL; static CONST char *openOptionStrings[] = { - "-defaultextension", "-filetypes", - "-initialdir", "-initialfile", - "-message", "-multiple", - "-parent", "-title", NULL + "-defaultextension", "-filetypes", + "-initialdir", "-initialfile", + "-message", "-multiple", + "-parent", "-title", NULL }; enum openOptions { - OPEN_DEFAULT, OPEN_FILETYPES, - OPEN_INITDIR, OPEN_INITFILE, - OPEN_MESSAGE, OPEN_MULTIPLE, - OPEN_PARENT, OPEN_TITLE + OPEN_DEFAULT, OPEN_FILETYPES, + OPEN_INITDIR, OPEN_INITFILE, + OPEN_MESSAGE, OPEN_MULTIPLE, + OPEN_PARENT, OPEN_TITLE }; - + if (!fileDlgInited) { - InitFileDialogs(); + InitFileDialogs(); } - + result = TCL_ERROR; parent = (Tk_Window) clientData; multiple = false; @@ -297,95 +297,94 @@ Tk_GetOpenFileObjCmd( ofd.usePopup = 1; for (i = 1; i < objc; i += 2) { - char *choice; - int index, choiceLen; - char *string; - - if (Tcl_GetIndexFromObj(interp, objv[i], openOptionStrings, "option", - TCL_EXACT, &index) != TCL_OK) { - result = TCL_ERROR; - goto end; - } - if (i + 1 == objc) { - string = Tcl_GetStringFromObj(objv[i], NULL); - Tcl_AppendResult(interp, "value for \"", string, "\" missing", - (char *) NULL); - result = TCL_ERROR; - goto end; - } - - switch (index) { - case OPEN_DEFAULT: - break; - case OPEN_FILETYPES: - choice = Tcl_GetStringFromObj(objv[i + 1], NULL); - if (TkGetFileFilters(interp, &ofd.fl, choice, 0) - != TCL_OK) { - result = TCL_ERROR; - goto end; - } - break; - case OPEN_INITDIR: - initialDir = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + char *choice; + int index, choiceLen; + char *string; + + if (Tcl_GetIndexFromObj(interp, objv[i], openOptionStrings, "option", + TCL_EXACT, &index) != TCL_OK) { + result = TCL_ERROR; + goto end; + } + if (i + 1 == objc) { + string = Tcl_GetStringFromObj(objv[i], NULL); + Tcl_AppendResult(interp, "value for \"", string, "\" missing", + (char *) NULL); + result = TCL_ERROR; + goto end; + } + + switch (index) { + case OPEN_DEFAULT: + break; + case OPEN_FILETYPES: + choice = Tcl_GetStringFromObj(objv[i + 1], NULL); + if (TkGetFileFilters(interp, &ofd.fl, choice, 0) != TCL_OK) { + result = TCL_ERROR; + goto end; + } + break; + case OPEN_INITDIR: + initialDir = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); /* empty strings should be like no selection given */ if (choiceLen == 0) { initialDir = NULL; } - break; - case OPEN_INITFILE: - initialFile = Tcl_GetStringFromObj(objv[i + 1], NULL); + break; + case OPEN_INITFILE: + initialFile = Tcl_GetStringFromObj(objv[i + 1], NULL); /* empty strings should be like no selection given */ if (choiceLen == 0) { initialFile = NULL; } - break; - case OPEN_MESSAGE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); - break; - case OPEN_MULTIPLE: - if (Tcl_GetBooleanFromObj(interp, objv[i + 1], &multiple) - != TCL_OK) { - result = TCL_ERROR; - goto end; - } - break; - case OPEN_PARENT: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, parent); - if (parent == NULL) { - result = TCL_ERROR; - goto end; - } - break; - case OPEN_TITLE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); - break; - } + break; + case OPEN_MESSAGE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, + kCFStringEncodingUTF8, false); + break; + case OPEN_MULTIPLE: + if (Tcl_GetBooleanFromObj(interp, objv[i + 1], &multiple) + != TCL_OK) { + result = TCL_ERROR; + goto end; + } + break; + case OPEN_PARENT: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + parent = Tk_NameToWindow(interp, choice, parent); + if (parent == NULL) { + result = TCL_ERROR; + goto end; + } + break; + case OPEN_TITLE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, + kCFStringEncodingUTF8, false); + break; + } } if (HandleInitialDirectory(interp, initialFile, initialDir, &dirRef, - &selectDesc, &initialDesc) != TCL_OK) { - result = TCL_ERROR; - goto end; + &selectDesc, &initialDesc) != TCL_OK) { + result = TCL_ERROR; + goto end; } - + if (initialDesc.descriptorType == typeFSRef) { - initialPtr = &initialDesc; + initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, - NULL, &selectDesc, title, message, multiple, OPEN_FILE); + NULL, &selectDesc, title, message, multiple, OPEN_FILE); end: TkFreeFileFilters(&ofd.fl); AEDisposeDesc(&initialDesc); AEDisposeDesc(&selectDesc); if (title != NULL) { - CFRelease(title); + CFRelease(title); } if (message != NULL) { - CFRelease(message); + CFRelease(message); } - + return result; } @@ -421,16 +420,16 @@ Tk_GetSaveFileObjCmd( CFStringRef title, message; OpenFileData ofd; static CONST char *saveOptionStrings[] = { - "-defaultextension", "-filetypes", "-initialdir", "-initialfile", - "-message", "-parent", "-title", NULL + "-defaultextension", "-filetypes", "-initialdir", "-initialfile", + "-message", "-parent", "-title", NULL }; enum saveOptions { - SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE, - SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE + SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE, + SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE }; if (!fileDlgInited) { - InitFileDialogs(); + InitFileDialogs(); } result = TCL_ERROR; @@ -439,79 +438,79 @@ Tk_GetSaveFileObjCmd( message = NULL; for (i = 1; i < objc; i += 2) { - char *choice; - int index, choiceLen; - char *string; - - if (Tcl_GetIndexFromObj(interp, objv[i], saveOptionStrings, "option", - TCL_EXACT, &index) != TCL_OK) { - return TCL_ERROR; - } - if (i + 1 == objc) { - string = Tcl_GetStringFromObj(objv[i], NULL); - Tcl_AppendResult(interp, "value for \"", string, "\" missing", - (char *) NULL); - return TCL_ERROR; - } - switch (index) { - case SAVE_DEFAULT: - break; - case SAVE_FILETYPES: - /* Currently unimplemented - what would we do here anyway? */ - break; - case SAVE_INITDIR: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + char *choice; + int index, choiceLen; + char *string; + + if (Tcl_GetIndexFromObj(interp, objv[i], saveOptionStrings, "option", + TCL_EXACT, &index) != TCL_OK) { + return TCL_ERROR; + } + if (i + 1 == objc) { + string = Tcl_GetStringFromObj(objv[i], NULL); + Tcl_AppendResult(interp, "value for \"", string, "\" missing", + (char *) NULL); + return TCL_ERROR; + } + switch (index) { + case SAVE_DEFAULT: + break; + case SAVE_FILETYPES: + /* Currently unimplemented - what would we do here anyway? */ + break; + case SAVE_INITDIR: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); /* empty strings should be like no selection given */ if (choiceLen && - HandleInitialDirectory(interp, NULL, choice, &dirRef, + HandleInitialDirectory(interp, NULL, choice, &dirRef, NULL, &initialDesc) != TCL_OK) { result = TCL_ERROR; goto end; } - break; - case SAVE_INITFILE: - initialFile = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + break; + case SAVE_INITFILE: + initialFile = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); /* empty strings should be like no selection given */ if (choiceLen == 0) { initialFile = NULL; } - break; - case SAVE_MESSAGE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); - break; - case SAVE_PARENT: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, parent); - if (parent == NULL) { - result = TCL_ERROR; - goto end; - } - break; - case SAVE_TITLE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); - break; - } + break; + case SAVE_MESSAGE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, + kCFStringEncodingUTF8, false); + break; + case SAVE_PARENT: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + parent = Tk_NameToWindow(interp, choice, parent); + if (parent == NULL) { + result = TCL_ERROR; + goto end; + } + break; + case SAVE_TITLE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, + kCFStringEncodingUTF8, false); + break; + } } TkInitFileFilters(&ofd.fl); ofd.usePopup = 0; if (initialDesc.descriptorType == typeFSRef) { - initialPtr = &initialDesc; + initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, initialFile, NULL, - title, message, false, SAVE_FILE); + title, message, false, SAVE_FILE); end: AEDisposeDesc(&initialDesc); if (title != NULL) { - CFRelease(title); + CFRelease(title); } if (message != NULL) { - CFRelease(message); + CFRelease(message); } return result; @@ -522,8 +521,8 @@ Tk_GetSaveFileObjCmd( * * Tk_ChooseDirectoryObjCmd -- * - * This procedure implements the "tk_chooseDirectory" dialog box - * for the Windows platform. See the user documentation for details + * This procedure implements the "tk_chooseDirectory" dialog box + * for the Windows platform. See the user documentation for details * on what it does. * * Results: @@ -559,11 +558,11 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) }; if (!NavServicesAvailable()) { - return TCL_ERROR; + return TCL_ERROR; } if (!fileDlgInited) { - InitFileDialogs(); + InitFileDialogs(); } result = TCL_ERROR; parent = (Tk_Window) clientData; @@ -571,69 +570,69 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) message = NULL; for (i = 1; i < objc; i += 2) { - char *choice; - int index, choiceLen; - char *string; - - if (Tcl_GetIndexFromObj(interp, objv[i], chooseOptionStrings, "option", - TCL_EXACT, &index) != TCL_OK) { - return TCL_ERROR; - } - if (i + 1 == objc) { - string = Tcl_GetStringFromObj(objv[i], NULL); - Tcl_AppendResult(interp, "value for \"", string, "\" missing", - (char *) NULL); - return TCL_ERROR; - } - switch (index) { - case CHOOSE_INITDIR: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + char *choice; + int index, choiceLen; + char *string; + + if (Tcl_GetIndexFromObj(interp, objv[i], chooseOptionStrings, "option", + TCL_EXACT, &index) != TCL_OK) { + return TCL_ERROR; + } + if (i + 1 == objc) { + string = Tcl_GetStringFromObj(objv[i], NULL); + Tcl_AppendResult(interp, "value for \"", string, "\" missing", + (char *) NULL); + return TCL_ERROR; + } + switch (index) { + case CHOOSE_INITDIR: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); if (choiceLen && HandleInitialDirectory(interp, NULL, choice, &dirRef, NULL, &initialDesc) != TCL_OK) { - result = TCL_ERROR; - goto end; - } - break; - case CHOOSE_MESSAGE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); - break; - case CHOOSE_PARENT: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, parent); - if (parent == NULL) { - result = TCL_ERROR; - goto end; - } - break; - case CHOOSE_TITLE: - choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); - break; - } + result = TCL_ERROR; + goto end; + } + break; + case CHOOSE_MESSAGE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, + kCFStringEncodingUTF8, false); + break; + case CHOOSE_PARENT: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + parent = Tk_NameToWindow(interp, choice, parent); + if (parent == NULL) { + result = TCL_ERROR; + goto end; + } + break; + case CHOOSE_TITLE: + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, + kCFStringEncodingUTF8, false); + break; + } } TkInitFileFilters(&ofd.fl); ofd.usePopup = 0; if (initialDesc.descriptorType == typeFSRef) { - initialPtr = &initialDesc; + initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, NULL, - title, message, false, CHOOSE_FOLDER); + title, message, false, CHOOSE_FOLDER); end: AEDisposeDesc(&initialDesc); if (title != NULL) { - CFRelease(title); + CFRelease(title); } if (message != NULL) { - CFRelease(message); + CFRelease(message); } - + return result; } @@ -642,7 +641,7 @@ HandleInitialDirectory ( Tcl_Interp *interp, char *initialFile, char *initialDir, - FSRef *dirRef, + FSRef *dirRef, AEDescList *selectDescPtr, AEDesc *dirDescPtr) { @@ -653,59 +652,59 @@ HandleInitialDirectory ( int result = TCL_OK; if (initialDir != NULL) { - dirName = Tcl_TranslateFileName(interp, initialDir, &ds); - if (dirName == NULL) { - return TCL_ERROR; - } - - err = FSPathMakeRef((unsigned char*) dirName, - dirRef, &isDirectory); - - if (err != noErr) { - Tcl_AppendResult(interp, "bad directory \"", - initialDir, "\"", NULL); - result = TCL_ERROR; - goto end; - } - if (!isDirectory) { - Tcl_AppendResult(interp, "-intialdir \"", - initialDir, " is a file, not a directory.\"", NULL); - result = TCL_ERROR; - goto end; - } - - AECreateDesc(typeFSRef, dirRef, sizeof(*dirRef), dirDescPtr); + dirName = Tcl_TranslateFileName(interp, initialDir, &ds); + if (dirName == NULL) { + return TCL_ERROR; + } + + err = FSPathMakeRef((unsigned char*) dirName, + dirRef, &isDirectory); + + if (err != noErr) { + Tcl_AppendResult(interp, "bad directory \"", + initialDir, "\"", NULL); + result = TCL_ERROR; + goto end; + } + if (!isDirectory) { + Tcl_AppendResult(interp, "-intialdir \"", + initialDir, " is a file, not a directory.\"", NULL); + result = TCL_ERROR; + goto end; + } + + AECreateDesc(typeFSRef, dirRef, sizeof(*dirRef), dirDescPtr); } if (initialFile != NULL && selectDescPtr != NULL) { - FSRef fileRef; - AEDesc fileDesc; - char *namePtr; - - if (initialDir != NULL) { - Tcl_DStringAppend(&ds, "/", 1); - Tcl_DStringAppend(&ds, initialFile, -1); - namePtr = Tcl_DStringValue(&ds); - } else { - namePtr = initialFile; - } - - AECreateList(NULL, 0, false, selectDescPtr); - - err = FSPathMakeRef((unsigned char*) namePtr, &fileRef, &isDirectory); - if (err != noErr) { - Tcl_AppendResult(interp, "bad initialfile \"", initialFile, - "\" file does not exist.", NULL); - return TCL_ERROR; - } - AECreateDesc(typeFSRef, &fileRef, sizeof(fileRef), &fileDesc); - AEPutDesc(selectDescPtr, 1, &fileDesc); - AEDisposeDesc(&fileDesc); + FSRef fileRef; + AEDesc fileDesc; + char *namePtr; + + if (initialDir != NULL) { + Tcl_DStringAppend(&ds, "/", 1); + Tcl_DStringAppend(&ds, initialFile, -1); + namePtr = Tcl_DStringValue(&ds); + } else { + namePtr = initialFile; + } + + AECreateList(NULL, 0, false, selectDescPtr); + + err = FSPathMakeRef((unsigned char*) namePtr, &fileRef, &isDirectory); + if (err != noErr) { + Tcl_AppendResult(interp, "bad initialfile \"", initialFile, + "\" file does not exist.", NULL); + return TCL_ERROR; + } + AECreateDesc(typeFSRef, &fileRef, sizeof(fileRef), &fileDesc); + AEPutDesc(selectDescPtr, 1, &fileDesc); + AEDisposeDesc(&fileDesc); } end: if (dirName != NULL) { - Tcl_DStringFree(&ds); + Tcl_DStringFree(&ds); } return result; } @@ -740,126 +739,126 @@ NavServicesGetFile( err = NavGetDefaultDialogCreationOptions(&diagOptions); if (err!=noErr) { - return TCL_ERROR; + return TCL_ERROR; } diagOptions.location.h = -1; diagOptions.location.v = -1; - diagOptions.optionFlags = kNavDontAutoTranslate - + kNavDontAddTranslateItems; + diagOptions.optionFlags = kNavDontAutoTranslate + + kNavDontAddTranslateItems; if (multiple) { - diagOptions.optionFlags += kNavAllowMultipleFiles; + diagOptions.optionFlags += kNavAllowMultipleFiles; } diagOptions.modality = kWindowModalityAppModal; if (ofdPtr != NULL && ofdPtr->usePopup) { - FileFilter *filterPtr; + FileFilter *filterPtr; - filterPtr = ofdPtr->fl.filters; - if (filterPtr == NULL) { - ofdPtr->usePopup = 0; - } + filterPtr = ofdPtr->fl.filters; + if (filterPtr == NULL) { + ofdPtr->usePopup = 0; + } } if (ofdPtr != NULL && ofdPtr->usePopup) { - FileFilter *filterPtr; - int index = 0; - ofdPtr->curType = 0; - - menuItemNames = (CFStringRef *)ckalloc(ofdPtr->fl.numFilters - * sizeof(CFStringRef)); - - for (filterPtr = ofdPtr->fl.filters; filterPtr != NULL; - filterPtr = filterPtr->next, index++) { - menuItemNames[index] = CFStringCreateWithCString(NULL, - filterPtr->name, kCFStringEncodingUTF8); - } - diagOptions.popupExtension = CFArrayCreate(NULL, - (const void **) menuItemNames, ofdPtr->fl.numFilters, NULL); + FileFilter *filterPtr; + int index = 0; + ofdPtr->curType = 0; + + menuItemNames = (CFStringRef *)ckalloc(ofdPtr->fl.numFilters + * sizeof(CFStringRef)); + + for (filterPtr = ofdPtr->fl.filters; filterPtr != NULL; + filterPtr = filterPtr->next, index++) { + menuItemNames[index] = CFStringCreateWithCString(NULL, + filterPtr->name, kCFStringEncodingUTF8); + } + diagOptions.popupExtension = CFArrayCreate(NULL, + (const void **) menuItemNames, ofdPtr->fl.numFilters, NULL); } else { - diagOptions.optionFlags += kNavNoTypePopup; - diagOptions.popupExtension = NULL; + diagOptions.optionFlags += kNavNoTypePopup; + diagOptions.popupExtension = NULL; } /* * This is required to allow App packages to be selectable in the * file dialogs... */ - + diagOptions.optionFlags += kNavSupportPackages; - + diagOptions.clientName = CFStringCreateWithCString(NULL, "Wish", kCFStringEncodingUTF8); diagOptions.message = message; diagOptions.windowTitle = title; if (initialFile) { - diagOptions.saveFileName = CFStringCreateWithCString(NULL, - initialFile, kCFStringEncodingUTF8); + diagOptions.saveFileName = CFStringCreateWithCString(NULL, + initialFile, kCFStringEncodingUTF8); } else { - diagOptions.saveFileName = NULL; + diagOptions.saveFileName = NULL; } - + diagOptions.actionButtonLabel = NULL; diagOptions.cancelButtonLabel = NULL; diagOptions.preferenceKey = 0; - - /* + + /* * Now process the selection list. We have to use the popupExtension * to fill the menu. */ - + if (isOpen == OPEN_FILE) { - err = NavCreateGetFileDialog(&diagOptions, - NULL, - openFileEventUPP, - NULL, - openFileFilterUPP, - ofdPtr, - &dialogRef); - if (err != noErr) { + err = NavCreateGetFileDialog(&diagOptions, + NULL, + openFileEventUPP, + NULL, + openFileFilterUPP, + ofdPtr, + &dialogRef); + if (err != noErr) { #ifdef TK_MAC_DEBUG - fprintf(stderr,"NavCreateGetFileDialog failed, %d\n", err ); + fprintf(stderr,"NavCreateGetFileDialog failed, %d\n", err); #endif - dialogRef = NULL; - } + dialogRef = NULL; + } } else if (isOpen == SAVE_FILE) { - err = NavCreatePutFileDialog(&diagOptions, 'TEXT', 'WIsH', - openFileEventUPP, NULL, &dialogRef); - if (err!=noErr){ + err = NavCreatePutFileDialog(&diagOptions, 'TEXT', 'WIsH', + openFileEventUPP, NULL, &dialogRef); + if (err!=noErr){ #ifdef TK_MAC_DEBUG - fprintf(stderr,"NavCreatePutFileDialog failed, %d\n", err ); + fprintf(stderr,"NavCreatePutFileDialog failed, %d\n", err); #endif - dialogRef = NULL; - } + dialogRef = NULL; + } } else if (isOpen == CHOOSE_FOLDER) { - err = NavCreateChooseFolderDialog(&diagOptions, openFileEventUPP, - openFileFilterUPP, NULL, &dialogRef); - if (err!=noErr){ + err = NavCreateChooseFolderDialog(&diagOptions, openFileEventUPP, + openFileFilterUPP, NULL, &dialogRef); + if (err!=noErr){ #ifdef TK_MAC_DEBUG - fprintf(stderr,"NavCreateChooseFolderDialog failed, %d\n", err ); + fprintf(stderr,"NavCreateChooseFolderDialog failed, %d\n", err); #endif - dialogRef = NULL; - } + dialogRef = NULL; + } } if (dialogRef) { - if (initialDescPtr != NULL) { - NavCustomControl (dialogRef, kNavCtlSetLocation, initialDescPtr); - } - if ((selectDescPtr != NULL) - && (selectDescPtr->descriptorType != typeNull)) { - NavCustomControl(dialogRef, kNavCtlSetSelection, selectDescPtr); - } - - if ((err = NavDialogRun(dialogRef)) != noErr ){ + if (initialDescPtr != NULL) { + NavCustomControl (dialogRef, kNavCtlSetLocation, initialDescPtr); + } + if ((selectDescPtr != NULL) + && (selectDescPtr->descriptorType != typeNull)) { + NavCustomControl(dialogRef, kNavCtlSetSelection, selectDescPtr); + } + + if ((err = NavDialogRun(dialogRef)) != noErr){ #ifdef TK_MAC_DEBUG - fprintf(stderr,"NavDialogRun failed, %d\n", err ); + fprintf(stderr,"NavDialogRun failed, %d\n", err); #endif - } else { - if ((err = NavDialogGetReply(dialogRef, &theReply)) != noErr) { + } else { + if ((err = NavDialogGetReply(dialogRef, &theReply)) != noErr) { #ifdef TK_MAC_DEBUG - fprintf(stderr,"NavGetReply failed, %d\n", err ); + fprintf(stderr,"NavGetReply failed, %d\n", err); #endif - } - } + } + } } /* @@ -867,246 +866,246 @@ NavServicesGetFile( * item, not a list. So only build a list if multiple is true... */ if (err == noErr) { - if (multiple) { - theResult = Tcl_NewListObj(0, NULL); - } else { - theResult = Tcl_NewObj(); - } - if (!theResult) { - err = memFullErr; - } + if (multiple) { + theResult = Tcl_NewListObj(0, NULL); + } else { + theResult = Tcl_NewObj(); + } + if (!theResult) { + err = memFullErr; + } } if (theReply.validRecord && err == noErr) { - AEDesc resultDesc; - long count; - FSRef fsRef; - char pathPtr[1024]; - int pathValid = 0; - err = AECountItems(&theReply.selection, &count); - if (err == noErr) { - long i; - for (i = 1; i <= count; i++ ) { - err = AEGetNthDesc(&theReply.selection, - i, typeFSRef, NULL, &resultDesc); - pathValid = 0; - if (err == noErr) { - if ((err = AEGetDescData(&resultDesc, &fsRef, sizeof(fsRef))) - != noErr ) { + AEDesc resultDesc; + long count; + FSRef fsRef; + char pathPtr[1024]; + int pathValid = 0; + err = AECountItems(&theReply.selection, &count); + if (err == noErr) { + long i; + for (i = 1; i <= count; i++) { + err = AEGetNthDesc(&theReply.selection, + i, typeFSRef, NULL, &resultDesc); + pathValid = 0; + if (err == noErr) { + if ((err = AEGetDescData(&resultDesc, &fsRef, sizeof(fsRef))) + != noErr) { #ifdef TK_MAC_DEBUG - fprintf(stderr,"AEGetDescData failed %d\n", err ); + fprintf(stderr,"AEGetDescData failed %d\n", err); #endif - } else { - if ((err = FSRefMakePath(&fsRef, (unsigned char*) pathPtr, 1024))) { + } else { + if ((err = FSRefMakePath(&fsRef, (unsigned char*) pathPtr, 1024))) { #ifdef TK_MAC_DEBUG - fprintf(stderr,"FSRefMakePath failed, %d\n", err ); + fprintf(stderr,"FSRefMakePath failed, %d\n", err); #endif - } else { - if (isOpen == SAVE_FILE) { - CFStringRef saveNameRef; - char saveName [1024]; - if ((saveNameRef = NavDialogGetSaveFileName(dialogRef))) { - if (CFStringGetCString(saveNameRef, saveName, - 1024, kCFStringEncodingUTF8)) { - if (strlen(pathPtr) + strlen(saveName) < 1023) { - strcat(pathPtr, "/"); - strcat(pathPtr, saveName); - pathValid = 1; - } else { + } else { + if (isOpen == SAVE_FILE) { + CFStringRef saveNameRef; + char saveName [1024]; + if ((saveNameRef = NavDialogGetSaveFileName(dialogRef))) { + if (CFStringGetCString(saveNameRef, saveName, + 1024, kCFStringEncodingUTF8)) { + if (strlen(pathPtr) + strlen(saveName) < 1023) { + strcat(pathPtr, "/"); + strcat(pathPtr, saveName); + pathValid = 1; + } else { #ifdef TK_MAC_DEBUG - fprintf(stderr, "Path name too long\n"); + fprintf(stderr, "Path name too long\n"); #endif - } - } else { + } + } else { #ifdef TK_MAC_DEBUG - fprintf(stderr, "CFStringGetCString failed\n"); + fprintf(stderr, "CFStringGetCString failed\n"); #endif - } - } else { + } + } else { #ifdef TK_MAC_DEBUG - fprintf(stderr, "NavDialogGetSaveFileName failed\n"); + fprintf(stderr, "NavDialogGetSaveFileName failed\n"); #endif - } - } else { - pathValid = 1; - } - if (pathValid) { - if (multiple) { - Tcl_ListObjAppendElement(interp, theResult, - Tcl_NewStringObj(pathPtr, -1)); - } else { - Tcl_SetStringObj(theResult, pathPtr, -1); - } - } - } - } - AEDisposeDesc(&resultDesc); - } - } - } - err = NavDisposeReply(&theReply); - Tcl_SetObjResult(interp, theResult); - result = TCL_OK; + } + } else { + pathValid = 1; + } + if (pathValid) { + if (multiple) { + Tcl_ListObjAppendElement(interp, theResult, + Tcl_NewStringObj(pathPtr, -1)); + } else { + Tcl_SetStringObj(theResult, pathPtr, -1); + } + } + } + } + AEDisposeDesc(&resultDesc); + } + } + } + err = NavDisposeReply(&theReply); + Tcl_SetObjResult(interp, theResult); + result = TCL_OK; } else if (err == userCanceledErr) { - result = TCL_OK; + result = TCL_OK; } else { - result = TCL_ERROR; + result = TCL_ERROR; } - - /* + + /* * Clean up any allocated strings - * dispose of things in reverse order of creation + * dispose of things in reverse order of creation */ - + if (diagOptions.windowTitle) { - CFRelease(diagOptions.windowTitle); + CFRelease(diagOptions.windowTitle); } if (diagOptions.saveFileName) { - CFRelease(diagOptions.saveFileName); + CFRelease(diagOptions.saveFileName); } if (diagOptions.message) { - CFRelease(diagOptions.message); + CFRelease(diagOptions.message); } if (diagOptions.clientName) { - CFRelease(diagOptions.clientName); + CFRelease(diagOptions.clientName); } - /* - * dispose of the CFArray diagOptions.popupExtension + /* + * dispose of the CFArray diagOptions.popupExtension */ - + if (menuItemNames) { - int i; - for (i = 0;i < ofdPtr->fl.numFilters; i++) { - CFRelease(menuItemNames[i]); - } - ckfree((void *)menuItemNames); + int i; + for (i = 0;i < ofdPtr->fl.numFilters; i++) { + CFRelease(menuItemNames[i]); + } + ckfree((void *)menuItemNames); } if (diagOptions.popupExtension != NULL) { - CFRelease(diagOptions.popupExtension); + CFRelease(diagOptions.popupExtension); } - + return result; } -static pascal Boolean -OpenFileFilterProc( +static pascal Boolean +OpenFileFilterProc( AEDesc* theItem, void* info, NavCallBackUserData callBackUD, - NavFilterModes filterMode ) + NavFilterModes filterMode) { OpenFileData *ofdPtr = (OpenFileData *) callBackUD; - + if (!ofdPtr || !ofdPtr->usePopup) { - return true; + return true; } else { - if (ofdPtr->fl.numFilters == 0) { - return true; - } else { - if ((theItem->descriptorType == typeFSS) - || (theItem->descriptorType = typeFSRef)) { - NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo *) info; - char fileName[256]; - int result; - - if ( !theInfo->isFolder ) { - OSType fileType; - StringPtr fileNamePtr; - Tcl_DString fileNameDString; - int i; - FileFilter *filterPtr; - - fileType = - theInfo->fileAndFolder.fileInfo.finderInfo.fdType; - Tcl_DStringInit (&fileNameDString); - - if (theItem->descriptorType == typeFSS) { - int len; - fileNamePtr = (((FSSpec *) *theItem->dataHandle)->name); - len = fileNamePtr[0]; - strncpy(fileName, (char*) fileNamePtr + 1, len); - fileName[len] = '\0'; - fileNamePtr = (unsigned char*) fileName; - - } else if ((theItem->descriptorType = typeFSRef)) { - OSStatus err; - FSRef *theRef = (FSRef *) *theItem->dataHandle; - HFSUniStr255 uniFileName; - err = FSGetCatalogInfo (theRef, kFSCatInfoNone, NULL, - &uniFileName, NULL, NULL); - - if (err == noErr) { - Tcl_UniCharToUtfDString ( - (Tcl_UniChar *) uniFileName.unicode, - uniFileName.length, - &fileNameDString); - fileNamePtr = (unsigned char*) Tcl_DStringValue(&fileNameDString); - } else { - fileNamePtr = NULL; - } - } - if (ofdPtr->usePopup) { - i = ofdPtr->curType; - for (filterPtr = ofdPtr->fl.filters; - filterPtr && i > 0; i--) { - filterPtr = filterPtr->next; - } - if (filterPtr) { - result = MatchOneType(fileNamePtr, fileType, - ofdPtr, filterPtr); - } else { - result = false; - } - } else { - /* - * We are not using the popup menu. In this case, the - * file is considered matched if it matches any of - * the file filters. - */ - - result = UNMATCHED; - for (filterPtr = ofdPtr->fl.filters; filterPtr; - filterPtr = filterPtr->next) { - if (MatchOneType(fileNamePtr, fileType, - ofdPtr, filterPtr) == MATCHED) { - result = MATCHED; - break; - } - } - } - - Tcl_DStringFree (&fileNameDString); - return (result == MATCHED); - } else { - return true; - } - } - } - - return true; + if (ofdPtr->fl.numFilters == 0) { + return true; + } else { + if ((theItem->descriptorType == typeFSS) + || (theItem->descriptorType = typeFSRef)) { + NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo *) info; + char fileName[256]; + int result; + + if (!theInfo->isFolder) { + OSType fileType; + StringPtr fileNamePtr; + Tcl_DString fileNameDString; + int i; + FileFilter *filterPtr; + + fileType = + theInfo->fileAndFolder.fileInfo.finderInfo.fdType; + Tcl_DStringInit (&fileNameDString); + + if (theItem->descriptorType == typeFSS) { + int len; + fileNamePtr = (((FSSpec *) *theItem->dataHandle)->name); + len = fileNamePtr[0]; + strncpy(fileName, (char*) fileNamePtr + 1, len); + fileName[len] = '\0'; + fileNamePtr = (unsigned char*) fileName; + + } else if ((theItem->descriptorType = typeFSRef)) { + OSStatus err; + FSRef *theRef = (FSRef *) *theItem->dataHandle; + HFSUniStr255 uniFileName; + err = FSGetCatalogInfo (theRef, kFSCatInfoNone, NULL, + &uniFileName, NULL, NULL); + + if (err == noErr) { + Tcl_UniCharToUtfDString ( + (Tcl_UniChar *) uniFileName.unicode, + uniFileName.length, + &fileNameDString); + fileNamePtr = (unsigned char*) Tcl_DStringValue(&fileNameDString); + } else { + fileNamePtr = NULL; + } + } + if (ofdPtr->usePopup) { + i = ofdPtr->curType; + for (filterPtr = ofdPtr->fl.filters; + filterPtr && i > 0; i--) { + filterPtr = filterPtr->next; + } + if (filterPtr) { + result = MatchOneType(fileNamePtr, fileType, + ofdPtr, filterPtr); + } else { + result = false; + } + } else { + /* + * We are not using the popup menu. In this case, the + * file is considered matched if it matches any of + * the file filters. + */ + + result = UNMATCHED; + for (filterPtr = ofdPtr->fl.filters; filterPtr; + filterPtr = filterPtr->next) { + if (MatchOneType(fileNamePtr, fileType, + ofdPtr, filterPtr) == MATCHED) { + result = MATCHED; + break; + } + } + } + + Tcl_DStringFree (&fileNameDString); + return (result == MATCHED); + } else { + return true; + } + } + } + + return true; } } -pascal void +pascal void OpenEventProc( NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParams, - NavCallBackUserData callBackUD ) + NavCallBackUserData callBackUD) { NavMenuItemSpec *chosenItem; OpenFileData *ofd = (OpenFileData *) callBackUD; static SInt32 otherEvent = ~(kNavCBCustomize|kNavCBStart|kNavCBTerminate - |kNavCBNewLocation|kNavCBShowDesktop|kNavCBSelectEntry|kNavCBAccept - |kNavCBCancel|kNavCBAdjustPreview); - + |kNavCBNewLocation|kNavCBShowDesktop|kNavCBSelectEntry|kNavCBAccept + |kNavCBCancel|kNavCBAdjustPreview); + if (callBackSelector == kNavCBPopupMenuSelect) { - chosenItem = (NavMenuItemSpec *) callBackParams->eventData.eventDataParms.param; - ofd->curType = chosenItem->menuType; - } else if (callBackSelector == kNavCBAdjustRect - || (callBackSelector & otherEvent) != 0) { - while (Tcl_DoOneEvent(TCL_IDLE_EVENTS - | TCL_DONT_WAIT - | TCL_WINDOW_EVENTS)) { - /* Empty Body */ - } + chosenItem = (NavMenuItemSpec *) callBackParams->eventData.eventDataParms.param; + ofd->curType = chosenItem->menuType; + } else if (callBackSelector == kNavCBAdjustRect + || (callBackSelector & otherEvent) != 0) { + while (Tcl_DoOneEvent(TCL_IDLE_EVENTS + | TCL_DONT_WAIT + | TCL_WINDOW_EVENTS)) { + /* Empty Body */ + } } } @@ -1130,10 +1129,10 @@ OpenEventProc( static Boolean MatchOneType( StringPtr fileNamePtr, /* Name of the file */ - OSType fileType, /* Type of the file, 0 means there was no specified type. */ + OSType fileType, /* Type of the file, 0 means there was no specified type. */ OpenFileData * ofdPtr, /* Information about this file dialog */ FileFilter * filterPtr) /* Match the file described by pb against - * this filter */ + * this filter */ { FileFilterClause * clausePtr; @@ -1154,77 +1153,77 @@ MatchOneType( * considered an error. */ - for (clausePtr = filterPtr->clauses; clausePtr; - clausePtr = clausePtr->next) { - int macMatched = 0; - int globMatched = 0; - GlobPattern * globPtr; - MacFileType * mfPtr; - - if (clausePtr->patterns == NULL) { - globMatched = 1; - } - if (clausePtr->macTypes == NULL) { - macMatched = 1; - } - - for (globPtr = clausePtr->patterns; globPtr; - globPtr = globPtr->next) { - char *q, *ext; - - if (fileNamePtr == NULL) { - continue; - } - ext = globPtr->pattern; - - if (ext[0] == '\0') { - /* - * We don't want any extensions: OK if the filename doesn't - * have "." in it - */ - - for (q = (char*) fileNamePtr; *q; q++) { - if (*q == '.') { - goto glob_unmatched; - } - } - goto glob_matched; - } - - if (Tcl_StringMatch((char*) fileNamePtr, ext)) { - goto glob_matched; - } else { - goto glob_unmatched; - } - - glob_unmatched: - continue; - - glob_matched: - globMatched = 1; - break; - } - - for (mfPtr = clausePtr->macTypes; mfPtr; mfPtr = mfPtr->next) { - if (fileType == mfPtr->type) { - macMatched = 1; - break; - } - } - - /* - * On Mac OS X, it is not uncommon for files to have NO + for (clausePtr = filterPtr->clauses; clausePtr; + clausePtr = clausePtr->next) { + int macMatched = 0; + int globMatched = 0; + GlobPattern * globPtr; + MacFileType * mfPtr; + + if (clausePtr->patterns == NULL) { + globMatched = 1; + } + if (clausePtr->macTypes == NULL) { + macMatched = 1; + } + + for (globPtr = clausePtr->patterns; globPtr; + globPtr = globPtr->next) { + char *q, *ext; + + if (fileNamePtr == NULL) { + continue; + } + ext = globPtr->pattern; + + if (ext[0] == '\0') { + /* + * We don't want any extensions: OK if the filename doesn't + * have "." in it + */ + + for (q = (char*) fileNamePtr; *q; q++) { + if (*q == '.') { + goto glob_unmatched; + } + } + goto glob_matched; + } + + if (Tcl_StringMatch((char*) fileNamePtr, ext)) { + goto glob_matched; + } else { + goto glob_unmatched; + } + + glob_unmatched: + continue; + + glob_matched: + globMatched = 1; + break; + } + + for (mfPtr = clausePtr->macTypes; mfPtr; mfPtr = mfPtr->next) { + if (fileType == mfPtr->type) { + macMatched = 1; + break; + } + } + + /* + * On Mac OS X, it is not uncommon for files to have NO * file type. But folks with Tcl code on Classic MacOS pretty * much assume that a generic file will have type TEXT. So * if we were strict about matching types when the source file * had NO type set, they would have to add another rule always * with no fileType. To avoid that, we pass the macMatch side - * of the test if no fileType is set. - */ + * of the test if no fileType is set. + */ - if (globMatched && (macMatched || (fileType == 0))) { - return MATCHED; - } + if (globMatched && (macMatched || (fileType == 0))) { + return MATCHED; + } } return UNMATCHED; @@ -1247,28 +1246,28 @@ MatchOneType( *---------------------------------------------------------------------- */ -void +void TkAboutDlg() { DialogPtr aboutDlog; WindowRef windowRef; short itemHit = -9; - + aboutDlog = GetNewDialog(128, NULL, (void *) (-1)); - + if (!aboutDlog) { - return; + return; } - + windowRef = GetDialogWindow(aboutDlog); SelectWindow(windowRef); - + while (itemHit != 1) { - ModalDialog( NULL, &itemHit); + ModalDialog(NULL, &itemHit); } DisposeDialog(aboutDlog); aboutDlog = NULL; - + SelectWindow(ActiveNonFloatingWindow()); return; @@ -1315,30 +1314,30 @@ Tk_MessageBoxObjCmd( int i; int indexDefaultOption = 0; int result = TCL_OK; - + static CONST char *movableAlertStrings[] = { - "-default", /* "-detail", */ "-icon", - "-message", "-parent", + "-default",/* "-detail",*/ "-icon", + "-message", "-parent", "-title", "-type", (char *)NULL }; static CONST char *movableTypeStrings[] = { "abortretryignore", "ok", - "okcancel", "retrycancel", - "yesno", "yesnocancel", + "okcancel", "retrycancel", + "yesno", "yesnocancel", (char *)NULL }; static CONST char *movableButtonStrings[] = { - "abort", "retry", "ignore", - "ok", "cancel", "yes", "no", + "abort", "retry", "ignore", + "ok", "cancel", "yes", "no", (char *)NULL }; static CONST char *movableIconStrings[] = { - "error", "info", "question", "warning", + "error", "info", "question", "warning", (char *)NULL }; enum movableAlertOptions { - ALERT_DEFAULT, /* ALERT_DETAIL, */ ALERT_ICON, + ALERT_DEFAULT,/* ALERT_DETAIL,*/ ALERT_ICON, ALERT_MESSAGE, ALERT_PARENT, ALERT_TITLE, ALERT_TYPE }; @@ -1348,34 +1347,34 @@ Tk_MessageBoxObjCmd( TYPE_YESNO, TYPE_YESNOCANCEL }; enum movableButtonOptions { - TEXT_ABORT, TEXT_RETRY, TEXT_IGNORE, + TEXT_ABORT, TEXT_RETRY, TEXT_IGNORE, TEXT_OK, TEXT_CANCEL, TEXT_YES, TEXT_NO }; enum movableIconOptions { ICON_ERROR, ICON_INFO, ICON_QUESTION, ICON_WARNING }; - + /* * Need to map from 'movableButtonStrings' and its corresponding integer index, * to the native button index, which is 1, 2, 3, from right to left. * This is necessary to do for each separate '-type' of button sets. */ - + short buttonIndexAndTypeToNativeButtonIndex[][7] = { /* abort retry ignore ok cancel yes no */ - {1, 2, 3, 0, 0, 0, 0}, /* abortretryignore */ + {1, 2, 3, 0, 0, 0, 0}, /* abortretryignore */ {0, 0, 0, 1, 0, 0, 0}, /* ok */ {0, 0, 0, 1, 2, 0, 0}, /* okcancel */ {0, 1, 0, 0, 2, 0, 0}, /* retrycancel */ {0, 0, 0, 0, 0, 1, 2}, /* yesno */ - {0, 0, 0, 0, 3, 1, 2}, /* yesnocancel */ + {0, 0, 0, 0, 3, 1, 2}, /* yesnocancel */ }; - + /* * Need also the inverse mapping, from native button (1, 2, 3) to the * descriptive button text string index. */ - + short nativeButtonIndexAndTypeToButtonIndex[][4] = { {-1, 0, 1, 2}, /* abortretryignore */ {-1, 3, 0, 0}, /* ok */ @@ -1384,54 +1383,57 @@ Tk_MessageBoxObjCmd( {-1, 5, 6, 0}, /* yesno */ {-1, 5, 6, 4}, /* yesnocancel */ }; - + alertType = kAlertPlainAlert; typeIndex = TYPE_OK; - - GetStandardAlertDefaultParams( ¶mCFStringRec, kStdCFStringAlertVersionOne ); + + GetStandardAlertDefaultParams(¶mCFStringRec, kStdCFStringAlertVersionOne); paramCFStringRec.movable = true; paramCFStringRec.helpButton = false; paramCFStringRec.defaultButton = kAlertStdAlertOKButton; - + paramCFStringRec.cancelButton = kAlertStdAlertCancelButton; + for (i = 1; i < objc; i += 2) { int iconIndex; char *string; - - if (Tcl_GetIndexFromObj( interp, objv[i], movableAlertStrings, "option", - TCL_EXACT, &index ) != TCL_OK) { + + if (Tcl_GetIndexFromObj(interp, objv[i], movableAlertStrings, "option", + TCL_EXACT, &index) != TCL_OK) { result = TCL_ERROR; goto end; } if (i + 1 == objc) { - string = Tcl_GetStringFromObj( objv[i], NULL ); - Tcl_AppendResult(interp, "value for \"", string, "\" missing", + string = Tcl_GetStringFromObj(objv[i], NULL); + Tcl_AppendResult(interp, "value for \"", string, "\" missing", (char *) NULL); result = TCL_ERROR; goto end; } - + switch (index) { - + case ALERT_DEFAULT: - - /* - * Need to postpone processing of this option until we are + + /* + * Need to postpone processing of this option until we are * sure to know the '-type' as well. */ - + haveDefaultOption = true; indexDefaultOption = i; break; - -/* case ALERT_DETAIL: - str = Tcl_GetStringFromObj( objv[i + 1], NULL ); - finemessageTextCF = CFStringCreateWithCString( NULL, str, kCFStringEncodingUTF8 ); + +/* + case ALERT_DETAIL: + str = Tcl_GetStringFromObj(objv[i + 1], NULL); + finemessageTextCF = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8); break; -*/ +*/ + case ALERT_ICON: /* not sure about UTF translation here... */ - if (Tcl_GetIndexFromObj( interp, objv[i + 1], movableIconStrings, - "value", TCL_EXACT, &iconIndex ) != TCL_OK) { + if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableIconStrings, + "value", TCL_EXACT, &iconIndex) != TCL_OK) { result = TCL_ERROR; goto end; } @@ -1450,29 +1452,29 @@ Tk_MessageBoxObjCmd( break; } break; - + case ALERT_MESSAGE: - str = Tcl_GetStringFromObj( objv[i + 1], NULL ); - messageTextCF = CFStringCreateWithCString( NULL, str, kCFStringEncodingUTF8 ); + str = Tcl_GetStringFromObj(objv[i + 1], NULL); + messageTextCF = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8); break; - + case ALERT_PARENT: - str = Tcl_GetStringFromObj( objv[i + 1], NULL ); - tkwin = Tk_NameToWindow( interp, str, tkwin ); + str = Tcl_GetStringFromObj(objv[i + 1], NULL); + tkwin = Tk_NameToWindow(interp, str, tkwin); if (tkwin == NULL) { result = TCL_ERROR; goto end; } haveParentOption = true; break; - + case ALERT_TITLE: break; - + case ALERT_TYPE: /* not sure about UTF translation here... */ - if (Tcl_GetIndexFromObj( interp, objv[i + 1], movableTypeStrings, - "value", TCL_EXACT, &typeIndex ) != TCL_OK) { + if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableTypeStrings, + "value", TCL_EXACT, &typeIndex) != TCL_OK) { result = TCL_ERROR; goto end; } @@ -1481,6 +1483,7 @@ Tk_MessageBoxObjCmd( paramCFStringRec.defaultText = CFSTR("Abort"); paramCFStringRec.cancelText = CFSTR("Retry"); paramCFStringRec.otherText = CFSTR("Ignore"); + paramCFStringRec.cancelButton = kAlertStdAlertOtherButton; break; case TYPE_OK: paramCFStringRec.defaultText = CFSTR("OK"); @@ -1501,44 +1504,44 @@ Tk_MessageBoxObjCmd( paramCFStringRec.defaultText = CFSTR("Yes"); paramCFStringRec.cancelText = CFSTR("No"); paramCFStringRec.otherText = CFSTR("Cancel"); + paramCFStringRec.cancelButton = kAlertStdAlertOtherButton; break; } break; } - } - - if (haveDefaultOption) { - + } + + if (haveDefaultOption) { + /* * Any '-default' option needs to know the '-type' option, which is why * we do this here. */ - - str = Tcl_GetStringFromObj( objv[indexDefaultOption + 1], NULL ); - if (Tcl_GetIndexFromObj( interp, objv[indexDefaultOption + 1], - movableButtonStrings, "value", TCL_EXACT, - &defaultButtonIndex ) != TCL_OK) { + + str = Tcl_GetStringFromObj(objv[indexDefaultOption + 1], NULL); + if (Tcl_GetIndexFromObj(interp, objv[indexDefaultOption + 1], + movableButtonStrings, "value", TCL_EXACT, + &defaultButtonIndex) != TCL_OK) { result = TCL_ERROR; goto end; } - + /* Need to map from "ok" etc. to 1, 2, 3, right to left. */ - - defaultNativeButtonIndex = + + defaultNativeButtonIndex = buttonIndexAndTypeToNativeButtonIndex[typeIndex][defaultButtonIndex]; if (defaultNativeButtonIndex == 0) { - Tcl_SetObjResult( interp, - Tcl_NewStringObj( "Illegel default option", -1 )); + Tcl_SetObjResult(interp, + Tcl_NewStringObj("Illegal default option", -1)); result = TCL_ERROR; goto end; } - paramCFStringRec.defaultButton = defaultNativeButtonIndex; + paramCFStringRec.defaultButton = defaultNativeButtonIndex; } - SetThemeCursor( kThemeArrowCursor ); - + SetThemeCursor(kThemeArrowCursor); + if (haveParentOption) { TkWindow *winPtr; - MacDrawable *macWin; WindowRef windowRef; EventTargetRef notifyTarget; EventHandlerUPP handler; @@ -1546,67 +1549,74 @@ Tk_MessageBoxObjCmd( const EventTypeSpec kEvents[] = { {kEventClassCommand, kEventProcessCommand} }; - + winPtr = (TkWindow *) tkwin; - + /* * Create the underlying Mac window for this Tk window. */ - - macWin = (MacDrawable *) winPtr->window; - windowRef = GetWindowFromPort( TkMacOSXGetDrawablePort((Drawable) macWin) ); - notifyTarget = GetWindowEventTarget( windowRef ); - osError = CreateStandardSheet( alertType, messageTextCF, + + windowRef = GetWindowFromPort( + TkMacOSXGetDrawablePort(Tk_WindowId(tkwin))); + notifyTarget = GetWindowEventTarget(windowRef); + osError = CreateStandardSheet(alertType, messageTextCF, finemessageTextCF, ¶mCFStringRec, - notifyTarget, &dialogRef ); + notifyTarget, &dialogRef); if(osError != noErr) { result = TCL_ERROR; goto end; } data.windowRef = windowRef; data.buttonIndex = 1; - handler = NewEventHandlerUPP( AlertHandler ); - InstallEventHandler(notifyTarget, handler, - GetEventTypeCount(kEvents), - kEvents, &data, NULL ); - osError = ShowSheetWindow( GetDialogWindow(dialogRef), windowRef ); + handler = NewEventHandlerUPP(AlertHandler); + InstallEventHandler(notifyTarget, handler, + GetEventTypeCount(kEvents), + kEvents, &data, NULL); + osError = ShowSheetWindow(GetDialogWindow(dialogRef), windowRef); if(osError != noErr) { result = TCL_ERROR; goto end; } - osError = RunAppModalLoopForWindow( windowRef ); - + osError = RunAppModalLoopForWindow(windowRef); + if (osError != noErr) { + result = TCL_ERROR; + goto end; + } itemHit = data.buttonIndex; - DisposeEventHandlerUPP( handler ); + DisposeEventHandlerUPP(handler); } else { - osError = CreateStandardAlert( alertType, messageTextCF, - finemessageTextCF, ¶mCFStringRec, &dialogRef ); + osError = CreateStandardAlert(alertType, messageTextCF, + finemessageTextCF, ¶mCFStringRec, &dialogRef); if(osError != noErr) { result = TCL_ERROR; goto end; } - osError = RunStandardAlert( dialogRef, NULL, &itemHit ); - } + osError = RunStandardAlert(dialogRef, NULL, &itemHit); + if (osError != noErr) { + result = TCL_ERROR; + goto end; + } + } if(osError == noErr) { int ind; - + /* * Map 'itemHit' (1, 2, 3) to descriptive text string. */ - + ind = nativeButtonIndexAndTypeToButtonIndex[typeIndex][itemHit]; - Tcl_SetObjResult( interp, - Tcl_NewStringObj( movableButtonStrings[ind], -1 )); + Tcl_SetObjResult(interp, + Tcl_NewStringObj(movableButtonStrings[ind], -1)); } else { result = TCL_ERROR; } - + end: if (finemessageTextCF != NULL) { - CFRelease( finemessageTextCF ); + CFRelease(finemessageTextCF); } if (messageTextCF != NULL) { - CFRelease( messageTextCF ); + CFRelease(messageTextCF); } return result; } @@ -1628,14 +1638,14 @@ Tk_MessageBoxObjCmd( */ static OSStatus -AlertHandler( EventHandlerCallRef callRef, EventRef eventRef, void *userData ) +AlertHandler(EventHandlerCallRef callRef, EventRef eventRef, void *userData) { OSStatus result = eventNotHandledErr; HICommand cmd; CallbackUserData *dataPtr = (CallbackUserData *) userData; - - GetEventParameter( eventRef, kEventParamDirectObject, typeHICommand, - NULL, sizeof(cmd), NULL, &cmd ); + + GetEventParameter(eventRef, kEventParamDirectObject, typeHICommand, + NULL, sizeof(cmd), NULL, &cmd); switch (cmd.commandID) { case kHICommandOK: dataPtr->buttonIndex = 1; @@ -1651,7 +1661,7 @@ AlertHandler( EventHandlerCallRef callRef, EventRef eventRef, void *userData ) break; } if (result == noErr) { - result = QuitAppModalLoopForWindow( dataPtr->windowRef ); + result = QuitAppModalLoopForWindow(dataPtr->windowRef); } return result; } -- cgit v0.12