new Mac file-dialog support only for 10.5 and up

svn: r12652
This commit is contained in:
Matthew Flatt 2008-11-30 18:26:25 +00:00
parent 67f29daee5
commit 3b89976e37

View File

@ -6,38 +6,46 @@
void wx_set_nav_file_types(NavDialogRef dlg, int cnt, char **exts, char *def_ext)
{
if (cnt) {
id pool = [[NSAutoreleasePool alloc] init];
id *objs;
int i, j, allow_others = 0;
NSArray *a;
NSSavePanel *sp = (NSSavePanel *)dlg;
SInt32 versionMajor, versionMinor;
for (i = 0; i < cnt; i++) {
if (!strcmp(exts[i], "*"))
allow_others = 1;
}
objs = (id *)malloc(sizeof(id) * (1 + (cnt - allow_others)));
j = 0;
objs[j++] = [[NSString alloc] initWithUTF8String: def_ext];
for (i = 0; i < cnt; i++) {
if (strcmp(exts[i], "*"))
objs[j++] = [[NSString alloc] initWithUTF8String: exts[i]];
}
a = [NSArray arrayWithObjects:objs count:j];
Gestalt(gestaltSystemVersionMajor, &versionMajor);
Gestalt(gestaltSystemVersionMinor, &versionMinor);
if ((versionMajor >= 10)
&& (versionMinor >= 5)) {
if (cnt) {
id pool = [[NSAutoreleasePool alloc] init];
id *objs;
int i, j, allow_others = 0;
NSArray *a;
NSSavePanel *sp = (NSSavePanel *)dlg;
[sp setAllowedFileTypes:a];
[sp setCanSelectHiddenExtension:TRUE];
if (!allow_others)
[sp setAllowsOtherFileTypes:FALSE];
for (i = 0; i < cnt; i++) {
if (!strcmp(exts[i], "*"))
allow_others = 1;
}
for (i = 0; i < j; i++) {
[objs[i] release];
}
free(objs);
objs = (id *)malloc(sizeof(id) * (1 + (cnt - allow_others)));
j = 0;
objs[j++] = [[NSString alloc] initWithUTF8String: def_ext];
for (i = 0; i < cnt; i++) {
if (strcmp(exts[i], "*"))
objs[j++] = [[NSString alloc] initWithUTF8String: exts[i]];
}
a = [NSArray arrayWithObjects:objs count:j];
[pool release];
[sp setAllowedFileTypes:a];
[sp setCanSelectHiddenExtension:TRUE];
if (!allow_others)
[sp setAllowsOtherFileTypes:FALSE];
for (i = 0; i < j; i++) {
[objs[i] release];
}
free(objs);
[pool release];
}
}
}