// Don't use this function, it won't work in 10.5 (Leopard) and up OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec) { FSRef fsref; OSErr ret = qt_mac_create_fsref(file, &fsref); if (ret == noErr) ret = FSGetCatalogInfo(&fsref, kFSCatInfoNone, 0, 0, spec, 0); return ret; }
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) { ATSFontContainerRef handle; OSStatus e; if(fnt->data.isEmpty()) { #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { extern OSErr qt_mac_create_fsref(const QString &, FSRef *); // qglobal.cpp FSRef ref; if(qt_mac_create_fsref(fnt->fileName, &ref) != noErr) return; ATSFontActivateFromFileReference(&ref, kATSFontContextLocal, kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle); } else #endif { extern Q_CORE_EXPORT OSErr qt_mac_create_fsspec(const QString &, FSSpec *); // global.cpp FSSpec spec; if(qt_mac_create_fsspec(fnt->fileName, &spec) != noErr) return; e = ATSFontActivateFromFileSpecification(&spec, kATSFontContextLocal, kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle); } } else { e = ATSFontActivateFromMemory((void *)fnt->data.constData(), fnt->data.size(), kATSFontContextLocal, kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle); fnt->data = QByteArray(); } if(e != noErr) return; ItemCount fontCount = 0; e = ATSFontFindFromContainer(handle, kATSOptionFlagsDefault, 0, 0, &fontCount); if(e != noErr) return; QVarLengthArray<ATSFontRef> containedFonts(fontCount); e = ATSFontFindFromContainer(handle, kATSOptionFlagsDefault, fontCount, containedFonts.data(), &fontCount); if(e != noErr) return; fnt->families.clear(); for(int i = 0; i < containedFonts.size(); ++i) { QCFString family; ATSFontGetName(containedFonts[i], kATSOptionFlagsDefault, &family); fnt->families.append(family); } fnt->handle = handle; }
QString Q3FileDialog::macGetSaveFileName(const QString &start, const QString &filter, QString *, QWidget *parent, const char* /*name*/, const QString& caption, QString *selectedFilter) { OSErr err; QString retstr; NavDialogCreationOptions options; NavGetDefaultDialogCreationOptions(&options); static const int w = 450, h = 350; options.optionFlags |= kNavDontConfirmReplacement; options.modality = kWindowModalityAppModal; options.location.h = options.location.v = -1; QString workingDir; QString initialSelection; if (!start.isEmpty()) { Q3UrlOperator u(encodeFileName(start)); if (u.isLocalFile() && QFileInfo(u.path()).isDir()) { workingDir = start; } else { if (u.isLocalFile()) { QFileInfo fi(u.dirPath()); if (fi.exists()) { workingDir = u.dirPath(); initialSelection = u.fileName(); } } else { workingDir = u.toString(); } } if (!initialSelection.isEmpty()) options.saveFileName = CFStringCreateWithCharacters(0, (UniChar *)initialSelection.unicode(), initialSelection.length()); } if(!caption.isEmpty()) options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(), caption.length()); if(parent && parent->isVisible()) { Qt::WindowType wt = parent->window()->windowType(); if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) { options.modality = kWindowModalityWindowModal; options.parentWindow = qt_mac_window_for(parent); } else { parent = parent->window(); QString s = parent->windowTitle(); options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length()); options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2); options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2); QRect r = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber(parent)); if(options.location.h + w > r.right()) options.location.h -= (options.location.h + w) - r.right() + 10; if(options.location.v + h > r.bottom()) options.location.v -= (options.location.v + h) - r.bottom() + 10; } } else if(QWidget *p = qApp->mainWidget()) { static int last_screen = -1; int scr = QApplication::desktop()->screenNumber(p); if(last_screen != scr) { QRect r = QApplication::desktop()->screenGeometry(scr); options.location.h = (r.x() + (r.width() / 2)) - (w / 2); options.location.v = (r.y() + (r.height() / 2)) - (h / 2); } } QList<qt_mac_filter_name*> filts = makeFiltersList(filter); qt_mac_nav_filter_type t; t.index = 0; t.filts = &filts; if(filts.count() > 1) { int i = 0; CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count()); for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) { QString rg = (*it)->description; arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length()); } options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL); } NavDialogRef dlg; if(NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(), (void *) (filts.isEmpty() ? NULL : &t), &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstr; } if (!workingDir.isEmpty()) { FSRef fsref; if (qt_mac_create_fsref(workingDir, &fsref) == noErr) { AEDesc desc; if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr) NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc); } } NavDialogRun(dlg); if (selectedFilter) { NavMenuItemSpec navSpec; bzero(&navSpec, sizeof(NavMenuItemSpec)); qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0); for (int i = 0; i < filts.count(); ++i) { const qt_mac_filter_name *filter = filts.at(i); if (sel_filt_name->description == filter->description && sel_filt_name->regxp == filter->regxp && sel_filt_name->filter == filter->filter) { navSpec.menuType = i; break; } } NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec); } if(options.modality == kWindowModalityWindowModal) { //simulate modality QWidget modal_widg(parent, __FILE__ "__modal_dlg", Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder); modal_widg.createWinId(); QApplicationPrivate::enterModal(&modal_widg); while(g_nav_blocking) qApp->processEvents(QEventLoop::WaitForMoreEvents); QApplicationPrivate::leaveModal(&modal_widg); } if(NavDialogGetUserAction(dlg) != kNavUserActionSaveAs) { NavDialogDispose(dlg); return retstr; } NavReplyRecord ret; NavDialogGetReply(dlg, &ret); NavDialogDispose(dlg); long count; err = AECountItems(&(ret.selection), &count); if(!ret.validRecord || err != noErr || !count) { NavDisposeReply(&ret); return retstr; } AEKeyword keyword; DescType type; Size size; FSRef ref; err = AEGetNthPtr(&(ret.selection), 1, typeFSRef, &keyword, &type, &ref, sizeof(ref), &size); if(err == noErr) { if(!str_buffer) { qAddPostRoutine(cleanup_str_buffer); str_buffer = (UInt8 *)malloc(1024); } FSRefMakePath(&ref, str_buffer, 1024); retstr = QString::fromUtf8((const char *)str_buffer); //now filename CFStringGetCString(ret.saveFileName, (char *)str_buffer, 1024, kCFStringEncodingUTF8); retstr += QLatin1Char('/') + QString::fromUtf8((const char *)str_buffer); } NavDisposeReply(&ret); if(selectedFilter) *selectedFilter = filts.at(t.index)->filter; while (!filts.isEmpty()) delete filts.takeFirst(); return retstr; }
QStringList Q3FileDialog::macGetOpenFileNames(const QString &filter, QString *pwd, QWidget *parent, const char* /*name*/, const QString& caption, QString *selectedFilter, bool multi, bool directory) { OSErr err; QStringList retstrl; NavDialogCreationOptions options; NavGetDefaultDialogCreationOptions(&options); options.modality = kWindowModalityAppModal; options.optionFlags |= kNavDontConfirmReplacement | kNavSupportPackages; if (!multi) options.optionFlags &= ~kNavAllowMultipleFiles; if(!caption.isEmpty()) options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(), caption.length()); static const int w = 450, h = 350; options.location.h = options.location.v = -1; if(parent && parent->isVisible()) { Qt::WindowType wt = parent->window()->windowType(); if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) { options.modality = kWindowModalityWindowModal; options.parentWindow = qt_mac_window_for(parent); } else { parent = parent->window(); QString s = parent->windowTitle(); options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length()); options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2); options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2); QRect r = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber(parent)); if(options.location.h + w > r.right()) options.location.h -= (options.location.h + w) - r.right() + 10; if(options.location.v + h > r.bottom()) options.location.v -= (options.location.v + h) - r.bottom() + 10; } } else if(QWidget *p = qApp->mainWidget()) { static int last_screen = -1; int scr = QApplication::desktop()->screenNumber(p); if(last_screen != scr) { QRect r = QApplication::desktop()->screenGeometry(scr); options.location.h = (r.x() + (r.width() / 2)) - (w / 2); options.location.v = (r.y() + (r.height() / 2)) - (h / 2); } } QList<qt_mac_filter_name*> filts = makeFiltersList(filter); qt_mac_nav_filter_type t; t.index = 0; t.filts = &filts; if(filts.count() > 1) { int i = 0; CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count()); for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) { QString rg = (*it)->description; arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length()); } options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL); } NavDialogRef dlg; if(directory) { if(NavCreateChooseFolderDialog(&options, make_navProcUPP(), NULL, NULL, &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstrl; } } else { if(NavCreateGetFileDialog(&options, NULL, make_navProcUPP(), NULL, make_navFilterUPP(), (void *) (filts.isEmpty() ? NULL : &t), &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstrl; } } if(pwd && !pwd->isEmpty()) { FSRef fsref; if(qt_mac_create_fsref(*pwd, &fsref) == noErr) { AEDesc desc; if(AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr) NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc); } } NavDialogRun(dlg); if (selectedFilter) { NavMenuItemSpec navSpec; bzero(&navSpec, sizeof(NavMenuItemSpec)); qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0); for (int i = 0; i < filts.count(); ++i) { const qt_mac_filter_name *filter = filts.at(i); if (sel_filt_name->description == filter->description && sel_filt_name->regxp == filter->regxp && sel_filt_name->filter == filter->filter) { navSpec.menuType = i; break; } } NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec); } if(options.modality == kWindowModalityWindowModal) { //simulate modality QWidget modal_widg(parent, __FILE__ "__modal_dlg", Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder); modal_widg.createWinId(); QApplicationPrivate::enterModal(&modal_widg); while(g_nav_blocking) qApp->processEvents(QEventLoop::WaitForMoreEvents); QApplicationPrivate::leaveModal(&modal_widg); } if(!(NavDialogGetUserAction(dlg) & (kNavUserActionOpen | kNavUserActionChoose | kNavUserActionNewFolder))) { NavDialogDispose(dlg); return retstrl; } NavReplyRecord ret; NavDialogGetReply(dlg, &ret); NavDialogDispose(dlg); long count; err = AECountItems(&(ret.selection), &count); if(!ret.validRecord || err != noErr || !count) { NavDisposeReply(&ret); return retstrl; } for(long index = 1; index <= count; index++) { FSRef ref; err = AEGetNthPtr(&(ret.selection), index, typeFSRef, 0, 0, &ref, sizeof(ref), 0); if(err != noErr) break; if(!str_buffer) { qAddPostRoutine(cleanup_str_buffer); str_buffer = (UInt8 *)malloc(1024); } FSRefMakePath(&ref, str_buffer, 1024); retstrl.append(QString::fromUtf8((const char *)str_buffer)); } NavDisposeReply(&ret); if(selectedFilter) *selectedFilter = filts.at(t.index)->filter; while (!filts.isEmpty()) delete filts.takeFirst(); return retstrl; }
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) { ATSFontContainerRef handle; OSStatus e = noErr; if(fnt->data.isEmpty()) { #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { extern OSErr qt_mac_create_fsref(const QString &, FSRef *); // qglobal.cpp FSRef ref; if(qt_mac_create_fsref(fnt->fileName, &ref) != noErr) return; ATSFontActivateFromFileReference(&ref, kATSFontContextLocal, kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle); } else #endif { #ifndef Q_WS_MAC64 extern Q_CORE_EXPORT OSErr qt_mac_create_fsspec(const QString &, FSSpec *); // global.cpp FSSpec spec; if(qt_mac_create_fsspec(fnt->fileName, &spec) != noErr) return; e = ATSFontActivateFromFileSpecification(&spec, kATSFontContextLocal, kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle); #endif } } else { e = ATSFontActivateFromMemory((void *)fnt->data.constData(), fnt->data.size(), kATSFontContextLocal, kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle); fnt->data = QByteArray(); } if(e != noErr) return; ItemCount fontCount = 0; e = ATSFontFindFromContainer(handle, kATSOptionFlagsDefault, 0, 0, &fontCount); if(e != noErr) return; QVarLengthArray<ATSFontRef> containedFonts(fontCount); e = ATSFontFindFromContainer(handle, kATSOptionFlagsDefault, fontCount, containedFonts.data(), &fontCount); if(e != noErr) return; fnt->families.clear(); #if defined(QT_MAC_USE_COCOA) // Make sure that the family name set on the font matches what // kCTFontFamilyNameAttribute returns in initializeDb(). // So far the best solution seems find the installed font // using CoreText and get the family name from it. // (ATSFontFamilyGetName appears to be the correct API, but also // returns the font display name.) for(int i = 0; i < containedFonts.size(); ++i) { QCFString fontPostScriptName; ATSFontGetPostScriptName(containedFonts[i], kATSOptionFlagsDefault, &fontPostScriptName); QCFType<CTFontDescriptorRef> font = CTFontDescriptorCreateWithNameAndSize(fontPostScriptName, 14); QCFString familyName = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute); fnt->families.append(familyName); } #else for(int i = 0; i < containedFonts.size(); ++i) { QCFString family; ATSFontGetName(containedFonts[i], kATSOptionFlagsDefault, &family); fnt->families.append(family); } #endif fnt->handle = handle; }
QString qt_mac_get_save_file_name(const QFileDialogArgs &args, QString *pwd, QString *selectedFilter) { QWidget *parent = args.parent; OSErr err; QString retstr; NavDialogCreationOptions options; NavGetDefaultDialogCreationOptions(&options); static const int w = 450, h = 350; if (args.options & QFileDialog::DontConfirmOverwrite) options.optionFlags |= kNavDontConfirmReplacement; options.modality = kWindowModalityAppModal; options.location.h = options.location.v = -1; if (!args.directory.isEmpty()) options.saveFileName = QCFString::toCFStringRef(args.selection); if (!args.caption.isEmpty()) options.windowTitle = QCFString::toCFStringRef(args.caption); if (parent && parent->isVisible()) { WindowClass wclass; GetWindowClass(qt_mac_window_for(parent), &wclass); if (!(args.options & QFileDialog::DontUseSheet) && (wclass == kDocumentWindowClass || wclass == kFloatingWindowClass || wclass == kMovableModalWindowClass)) { options.modality = kWindowModalityWindowModal; options.parentWindow = qt_mac_window_for(parent); // The parent needs to be active for the sheet to get keyboard focus. if (!parent->isActiveWindow()) parent->activateWindow(); } else { parent = parent->window(); QString s = parent->windowTitle(); options.clientName = CFStringCreateWithCharacters(0, (UniChar *)s.unicode(), s.length()); options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2); options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2); QRect r = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber(parent)); if (options.location.h + w > r.right()) options.location.h -= (options.location.h + w) - r.right() + 10; if (options.location.v + h > r.bottom()) options.location.v -= (options.location.v + h) - r.bottom() + 10; } #if 0 } else if (QWidget *p = qApp->mainWidget()) { static int last_screen = -1; int scr = QApplication::desktop()->screenNumber(p); if (last_screen != scr) { QRect r = QApplication::desktop()->screenGeometry(scr); options.location.h = (r.x() + (r.width() / 2)) - (w / 2); options.location.v = (r.y() + (r.height() / 2)) - (h / 2); } #endif } QList<qt_mac_filter_name*> filts = qt_mac_make_filters_list(args.filter); qt_mac_nav_filter_type t; t.saveDialog = true; t.index = 0; t.filts = &filts; if (filts.count() > 1) { int i = 0; CFStringRef *arr = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef) * filts.count())); for (QList<qt_mac_filter_name*>::const_iterator it = filts.constBegin(); it != filts.constEnd(); ++it) arr[i++] = QCFString::toCFStringRef((*it)->description); options.popupExtension = CFArrayCreate(0, reinterpret_cast<const void **>(arr), filts.count(), 0); } NavDialogRef dlg; if (NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(), static_cast<void *>(filts.isEmpty() ? 0 : &t), &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstr; } if (pwd && !pwd->isEmpty()) { FSRef fsref; if (qt_mac_create_fsref(*pwd, &fsref) == noErr) { AEDesc desc; if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr) NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc); } } NavDialogRun(dlg); if (selectedFilter) { NavMenuItemSpec navSpec; bzero(&navSpec, sizeof(NavMenuItemSpec)); qt_mac_filter_name *sel_filt_name = qt_mac_make_filters_list(*selectedFilter).at(0); for (int i = 0; i < filts.count(); ++i) { const qt_mac_filter_name *filter = filts.at(i); if (sel_filt_name->description == filter->description && sel_filt_name->regxp == filter->regxp && sel_filt_name->filter == filter->filter) { navSpec.menuType = i; break; } } NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec); } if (options.modality == kWindowModalityWindowModal) { //simulate modality QWidget modal_widg(parent, Qt::Sheet); modal_widg.createWinId(); QApplicationPrivate::enterModal(&modal_widg); while (g_nav_blocking) qApp->processEvents(QEventLoop::WaitForMoreEvents); QApplicationPrivate::leaveModal(&modal_widg); } if (NavDialogGetUserAction(dlg) != kNavUserActionSaveAs) { NavDialogDispose(dlg); return retstr; } NavReplyRecord ret; NavDialogGetReply(dlg, &ret); NavDialogDispose(dlg); long count; err = AECountItems(&(ret.selection), &count); if (!ret.validRecord || err != noErr || !count) { NavDisposeReply(&ret); return retstr; } AEKeyword keyword; DescType type; Size size; FSRef ref; err = AEGetNthPtr(&(ret.selection), 1, typeFSRef, &keyword, &type, &ref, sizeof(ref), &size); if (err == noErr) { if (!str_buffer) { qAddPostRoutine(cleanup_str_buffer); str_buffer = (UInt8 *)malloc(1024); } FSRefMakePath(&ref, str_buffer, 1024); retstr = QString::fromUtf8((const char *)str_buffer); //now filename CFStringGetCString(ret.saveFileName, (char *)str_buffer, 1024, kCFStringEncodingUTF8); retstr += QLatin1String("/") + QString::fromUtf8((const char *)str_buffer); } NavDisposeReply(&ret); if (selectedFilter) *selectedFilter = filts.at(t.index)->filter; while (!filts.isEmpty()) delete filts.takeFirst(); return retstr; }
QStringList qt_mac_get_open_file_names(const QFileDialogArgs &args, QString *pwd, QString *selectedFilter) { QWidget *parent = args.parent; OSErr err; QStringList retstrl; NavDialogCreationOptions options; NavGetDefaultDialogCreationOptions(&options); options.modality = kWindowModalityAppModal; options.optionFlags |= kNavSupportPackages; if (args.options & QFileDialog::DontConfirmOverwrite) options.optionFlags |= kNavDontConfirmReplacement; if (args.mode != QFileDialog::ExistingFiles) options.optionFlags &= ~kNavAllowMultipleFiles; if (!args.caption.isEmpty()) options.windowTitle = QCFString::toCFStringRef(args.caption); static const int w = 450, h = 350; options.location.h = options.location.v = -1; if (parent && parent->isVisible()) { WindowClass wclass; GetWindowClass(qt_mac_window_for(parent), &wclass); if (!(args.options & QFileDialog::DontUseSheet) && (wclass == kDocumentWindowClass || wclass == kFloatingWindowClass || wclass == kMovableModalWindowClass)) { options.modality = kWindowModalityWindowModal; options.parentWindow = qt_mac_window_for(parent); } else { parent = parent->window(); QString s = parent->windowTitle(); options.clientName = QCFString::toCFStringRef(s); options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2); options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2); QRect r = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber(parent)); const int border = 10; if (options.location.h + w > r.right()) options.location.h -= (options.location.h + w) - r.right() + border; if (options.location.v + h > r.bottom()) options.location.v -= (options.location.v + h) - r.bottom() + border; if (options.location.h < r.left()) options.location.h = r.left() + border; if (options.location.v < r.top()) options.location.v = r.top() + border; } #if 0 } else if (QWidget *p = qApp->mainWidget()) { static int last_screen = -1; int scr = QApplication::desktop()->screenNumber(p); if (last_screen != scr) { QRect r = QApplication::desktop()->screenGeometry(scr); options.location.h = (r.x() + (r.width() / 2)) - (w / 2); options.location.v = (r.y() + (r.height() / 2)) - (h / 2); } #endif } QList<qt_mac_filter_name*> filts = qt_mac_make_filters_list(args.filter); qt_mac_nav_filter_type t; t.saveDialog = false; t.index = 0; t.filts = &filts; if (filts.count() > 1) { int i = 0; CFStringRef *arr = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef) * filts.count())); for (QList<qt_mac_filter_name*>::const_iterator it = filts.constBegin(); it != filts.constEnd(); ++it) arr[i++] = QCFString::toCFStringRef((*it)->description); options.popupExtension = CFArrayCreate(0, reinterpret_cast<const void **>(arr), filts.count(), 0); } NavDialogRef dlg; if (args.mode == QFileDialog::DirectoryOnly || args.mode == QFileDialog::Directory) { if (NavCreateChooseFolderDialog(&options, make_navProcUPP(), 0, 0, &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstrl; } } else { if (NavCreateGetFileDialog(&options, 0, make_navProcUPP(), 0, make_navFilterUPP(), (void *) (filts.isEmpty() ? 0 : &t), &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstrl; } } if (pwd && !pwd->isEmpty()) { FSRef fsref; if (qt_mac_create_fsref(*pwd, &fsref) == noErr) { AEDesc desc; if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr) NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc); } } NavDialogRun(dlg); if (selectedFilter) { NavMenuItemSpec navSpec; bzero(&navSpec, sizeof(NavMenuItemSpec)); qt_mac_filter_name *sel_filt_name = qt_mac_make_filters_list(*selectedFilter).at(0); for (int i = 0; i < filts.count(); ++i) { const qt_mac_filter_name *filter = filts.at(i); if (sel_filt_name->description == filter->description && sel_filt_name->regxp == filter->regxp && sel_filt_name->filter == filter->filter) { navSpec.menuType = i; break; } } NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec); } if (options.modality == kWindowModalityWindowModal) { //simulate modality QWidget modal_widg(parent, Qt::Sheet); modal_widg.createWinId(); QApplicationPrivate::enterModal(&modal_widg); while (g_nav_blocking) qApp->processEvents(QEventLoop::WaitForMoreEvents); QApplicationPrivate::leaveModal(&modal_widg); } if (!(NavDialogGetUserAction(dlg) & (kNavUserActionOpen | kNavUserActionChoose | kNavUserActionNewFolder))) { NavDialogDispose(dlg); return retstrl; } NavReplyRecord ret; NavDialogGetReply(dlg, &ret); NavDialogDispose(dlg); long count; err = AECountItems(&(ret.selection), &count); if (!ret.validRecord || err != noErr || !count) { NavDisposeReply(&ret); return retstrl; } for (long index = 1; index <= count; index++) { FSRef ref; err = AEGetNthPtr(&(ret.selection), index, typeFSRef, 0, 0, &ref, sizeof(ref), 0); if (err != noErr) break; if (!str_buffer) { qAddPostRoutine(cleanup_str_buffer); str_buffer = (UInt8 *)malloc(1024); } FSRefMakePath(&ref, str_buffer, 1024); retstrl.append(QString::fromUtf8((const char *)str_buffer)); } NavDisposeReply(&ret); if (selectedFilter) *selectedFilter = filts.at(t.index)->filter; while (!filts.isEmpty()) delete filts.takeFirst(); return retstrl; }