diff options
author | das <das> | 2007-11-09 06:26:53 (GMT) |
---|---|---|
committer | das <das> | 2007-11-09 06:26:53 (GMT) |
commit | b0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846 (patch) | |
tree | 40938979466c8caac1c03c907753bc43175304bd /macosx/tkMacOSXDialog.c | |
parent | 455d9dc4b8b50ed064729851295535018eb99449 (diff) | |
download | tk-b0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846.zip tk-b0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846.tar.gz tk-b0e3f55fe56f3f1fa4ad3cf7c63dddcfff5a9846.tar.bz2 |
Backport from HEAD of Aqua changes from 2007-10-12 to 2007-11-09
Diffstat (limited to 'macosx/tkMacOSXDialog.c')
-rw-r--r-- | macosx/tkMacOSXDialog.c | 85 |
1 files changed, 69 insertions, 16 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 86074b8..dd9a448 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -10,7 +10,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.20 2007/10/26 10:37:14 das Exp $ + * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.21 2007/11/09 06:26:55 das Exp $ */ #include "tkMacOSXPrivate.h" @@ -41,6 +41,7 @@ typedef struct _OpenFileData { FileFilterList fl; /* List of file filters. */ SInt16 curType; /* The filetype currently being listed. */ + short initialType; /* Type to use initially */ short popupItem; /* Item number of the popup in the dialog. */ short usePopup; /* True if we show the popup menu (this */ /* is an open operation and the */ @@ -84,7 +85,7 @@ static int NavServicesGetFile(Tcl_Interp *interp, OpenFileData *ofd, AEDesc *initialDescPtr, char *initialFile, AEDescList *selectDescPtr, CFStringRef title, CFStringRef message, - int multiple, int isOpen, + const char *initialType, int multiple, int isOpen, Tk_Window parent); static int HandleInitialDirectory(Tcl_Interp *interp, char *initialFile, char *initialDir, FSRef *dirRef, @@ -261,13 +262,18 @@ Tk_GetOpenFileObjCmd( AEDesc *initialPtr = NULL; AEDescList selectDesc = {typeNull, NULL}; char *initialFile = NULL, *initialDir = NULL; +#if 0 + Tcl_Obj *typeVariablePtr = NULL; +#endif + const char *initialtype = NULL; static const char *openOptionStrings[] = { "-defaultextension", "-filetypes", "-initialdir", "-initialfile", - "-message", "-multiple", "-parent", "-title", NULL + "-message", "-multiple", "-parent", "-title",/* "-typevariable",*/ NULL }; enum openOptions { OPEN_DEFAULT, OPEN_FILETYPES, OPEN_INITDIR, OPEN_INITFILE, - OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE + OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE, + /*OPEN_TYPEVARIABLE,*/ }; if (!fileDlgInited) { @@ -275,6 +281,7 @@ Tk_GetOpenFileObjCmd( } TkInitFileFilters(&ofd.fl); ofd.curType = 0; + ofd.initialType = -1; ofd.popupItem = OPEN_POPUP_ITEM; ofd.usePopup = 1; @@ -338,6 +345,11 @@ Tk_GetOpenFileObjCmd( title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, kCFStringEncodingUTF8, false); break; +#if 0 + case OPEN_TYPEVARIABLE: + typeVariablePtr = objv[i + 1]; + break; +#endif } } @@ -345,12 +357,29 @@ Tk_GetOpenFileObjCmd( &selectDesc, &initialDesc) != TCL_OK) { goto end; } - if (initialDesc.descriptorType == typeFSRef) { initialPtr = &initialDesc; } +#if 0 + if (typeVariablePtr) { + initialtype = Tcl_GetVar(interp, Tcl_GetString(typeVariablePtr), 0); + } +#endif result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, &selectDesc, - title, message, multiple, OPEN_FILE, parent); + title, message, initialtype, multiple, OPEN_FILE, parent); + +#if 0 + if (typeVariablePtr) { + FileFilter *filterPtr = ofd.fl.filters; + int i = ofd.curType; + + while (filterPtr && i-- > 0) { + filterPtr = filterPtr->next; + } + Tcl_SetVar(interp, Tcl_GetString(typeVariablePtr), filterPtr->name, 0); + } +#endif + end: TkFreeFileFilters(&ofd.fl); if (initialDesc.dataHandle) { @@ -401,11 +430,11 @@ Tk_GetSaveFileObjCmd( OpenFileData ofd; static const char *saveOptionStrings[] = { "-defaultextension", "-filetypes", "-initialdir", "-initialfile", - "-message", "-parent", "-title", NULL + "-message", "-parent", "-title",/* "-typevariable",*/ NULL }; enum saveOptions { SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE, - SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE + SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE,/* SAVE_TYPEVARIABLE,*/ }; if (!fileDlgInited) { @@ -480,7 +509,7 @@ Tk_GetSaveFileObjCmd( initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, initialFile, NULL, - title, message, false, SAVE_FILE, parent); + title, message, NULL, false, SAVE_FILE, parent); TkFreeFileFilters(&ofd.fl); end: if (initialDesc.dataHandle) { @@ -588,7 +617,7 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, NULL, title, - message, false, CHOOSE_FOLDER, parent); + message, NULL, false, CHOOSE_FOLDER, parent); TkFreeFileFilters(&ofd.fl); end: if (initialDesc.dataHandle) { @@ -737,6 +766,7 @@ NavServicesGetFile( AEDescList *selectDescPtr, CFStringRef title, CFStringRef message, + const char *initialtype, int multiple, int isOpen, Tk_Window parent) @@ -800,6 +830,9 @@ NavServicesGetFile( filterPtr = filterPtr->next, index++) { menuItemNames[index] = CFStringCreateWithCString(NULL, filterPtr->name, kCFStringEncodingUTF8); + if (initialtype && strcmp(filterPtr->name, initialtype) == 0) { + ofdPtr->initialType = index; + } } options.popupExtension = CFArrayCreate(NULL, (const void **) menuItemNames, ofdPtr->fl.numFilters, NULL); @@ -991,6 +1024,29 @@ OpenEventProc( OpenFileData *ofd = data->ofdPtr; switch (callBackSelector) { + case kNavCBStart: + if (ofd && ofd->initialType >= 0) { + /* Select initial filter */ + FileFilter *filterPtr = ofd->fl.filters; + int i = ofd->initialType; + + while (filterPtr && i-- > 0) { + filterPtr = filterPtr->next; + } + if (filterPtr) { + NavMenuItemSpec selectItem; + + selectItem.version = kNavMenuItemSpecVersion; + selectItem.menuCreator = 0; + selectItem.menuType = ofd->initialType; + selectItem.menuItemName[0] = strlen(filterPtr->name); + strncpy((char*) &selectItem.menuItemName[1], + filterPtr->name, 255); + ChkErr(NavCustomControl, callBackParams->context, + kNavCtlSelectCustomType, &selectItem); + } + } + break; case kNavCBPopupMenuSelect: ofd->curType = ((NavMenuItemSpec *) callBackParams->eventData.eventDataParms.param)->menuType; @@ -1061,7 +1117,7 @@ OpenFileFilterProc( if (!theInfo->isFolder) { OSType fileType; - StringPtr fileNamePtr; + StringPtr fileNamePtr = NULL; Tcl_DString fileNameDString; int i; FileFilter *filterPtr; @@ -1077,7 +1133,6 @@ OpenFileFilterProc( 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; @@ -1091,8 +1146,6 @@ OpenFileFilterProc( uniFileName.length, &fileNameDString); fileNamePtr = (unsigned char*) Tcl_DStringValue(&fileNameDString); - } else { - fileNamePtr = NULL; } } if (ofdPtr->usePopup) { @@ -1423,13 +1476,13 @@ Tk_MessageBoxObjCmd( indexDefaultOption = i; break; -/* +#if 0 case ALERT_DETAIL: str = Tcl_GetString(objv[i + 1]); finemessageTextCF = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8); break; -*/ +#endif case ALERT_ICON: if (Tcl_GetIndexFromObj(interp, objv[i + 1], |