static void qt_mac_filedialog_event_proc(const NavEventCallbackMessage msg, NavCBRecPtr p, NavCallBackUserData myd) { switch(msg) { case kNavCBPopupMenuSelect: { qt_mac_nav_filter_type *t = (qt_mac_nav_filter_type *)myd; NavMenuItemSpec *s = (NavMenuItemSpec*)p->eventData.eventDataParms.param; t->index = s->menuType; if (t->saveDialog) { QString base = QCFString::toQString(NavDialogGetSaveFileName(p->context)); QFileInfo fi(base); base = fi.completeBaseName(); qt_mac_filter_name *fn = t->filts->at(t->index); QStringList reg = fn->regxp.split(QLatin1String(";"), QString::SkipEmptyParts); QString r = reg.first(); r = r.right(r.length()-1); // Strip the * base += r; //"." + QString::number(s->menuType); NavDialogSetSaveFileName(p->context, QCFString::toCFStringRef(base)); } #ifdef DEBUG_FILEDIALOG_FILTERS qDebug("QFileDialog:%d - Selected a filter: %ld", __LINE__, s->menuType); #endif break; } case kNavCBStart: g_nav_blocking=true; break; case kNavCBUserAction: g_nav_blocking=false; break; } }
void OpenUserDataRec::EventProcCBPopupMenuSelect(NavCBRecPtr ioParams) { NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ; const size_t numFilters = m_extensions.GetCount(); if ( menu->menuType < numFilters ) { m_currentfilter = menu->menuType ; if ( m_saveMode ) { int i = menu->menuType ; // isolate the first extension string wxString firstExtension = m_extensions[i].BeforeFirst('|').BeforeFirst(';'); wxString extension = firstExtension.AfterLast('.') ; wxString sfilename ; wxCFStringRef cfString( wxCFRetain( NavDialogGetSaveFileName( ioParams->context ) ) ); sfilename = cfString.AsString() ; int pos = sfilename.Find('.', true) ; if ( pos != wxNOT_FOUND && extension != wxT("*") ) { sfilename = sfilename.Left(pos+1)+extension ; cfString = wxCFStringRef( sfilename , wxFONTENCODING_DEFAULT ) ; NavDialogSetSaveFileName( ioParams->context , cfString ) ; } } } }
static pascal void NavEventProc( NavEventCallbackMessage inSelector, NavCBRecPtr ioParams, NavCallBackUserData ioUserData ) { OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ; if (inSelector == kNavCBEvent) { } else if ( inSelector == kNavCBStart ) { if (data && !(data->defaultLocation).empty()) { // Set default location for the modern Navigation APIs // Apple Technical Q&A 1151 FSRef theFile; wxMacPathToFSRef(data->defaultLocation, &theFile); AEDesc theLocation = { typeNull, NULL }; if (noErr == ::AECreateDesc(typeFSRef, &theFile, sizeof(FSRef), &theLocation)) ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation); } if( data->extensions.GetCount() > 0 ) { NavMenuItemSpec menuItem; memset( &menuItem, 0, sizeof(menuItem) ); menuItem.version = kNavMenuItemSpecVersion; menuItem.menuType = data->currentfilter; ::NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &menuItem); } } else if ( inSelector == kNavCBPopupMenuSelect ) { NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ; const size_t numFilters = data->extensions.GetCount(); if ( menu->menuType < numFilters ) { data->currentfilter = menu->menuType ; if ( data->saveMode ) { int i = menu->menuType ; wxString extension = data->extensions[i].AfterLast('.') ; wxString sfilename ; wxMacCFStringHolder cfString( NavDialogGetSaveFileName( ioParams->context ) , false ); sfilename = cfString.AsString() ; int pos = sfilename.Find('.', true) ; if ( pos != wxNOT_FOUND && extension != wxT("*") ) { sfilename = sfilename.Left(pos+1)+extension ; cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ; NavDialogSetSaveFileName( ioParams->context , cfString ) ; } } } } }
OSStatus LLFilePicker::doNavSaveDialog(ESaveFilter filter, const std::string& filename) { OSStatus error = noErr; NavDialogRef navRef = NULL; NavReplyRecord navReply; memset(&navReply, 0, sizeof(navReply)); // Setup the type, creator, and extension OSType type, creator; CFStringRef extension = NULL; switch (filter) { case FFSAVE_WAV: type = 'WAVE'; creator = 'TVOD'; extension = CFSTR(".wav"); break; case FFSAVE_TGA: type = 'TPIC'; creator = 'prvw'; extension = CFSTR(".tga"); break; case FFSAVE_BMP: type = 'BMPf'; creator = 'prvw'; extension = CFSTR(".bmp"); break; case FFSAVE_JPEG: type = 'JPEG'; creator = 'prvw'; extension = CFSTR(".jpeg"); break; case FFSAVE_PNG: type = 'PNG '; creator = 'prvw'; extension = CFSTR(".png"); break; case FFSAVE_AVI: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(".mov"); break; case FFSAVE_ANIM: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(".xaf"); break; #ifdef _CORY_TESTING case FFSAVE_GEOMETRY: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(".slg"); break; #endif case FFSAVE_RAW: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(".raw"); break; case FFSAVE_J2C: type = '\?\?\?\?'; creator = 'prvw'; extension = CFSTR(".j2c"); break; case FFSAVE_ALL: default: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(""); break; } // Create the dialog error = NavCreatePutFileDialog(&mNavOptions, type, creator, NULL, NULL, &navRef); if (error == noErr) { CFStringRef nameString = NULL; bool hasExtension = true; // Create a CFString of the initial file name if (!filename.empty()) nameString = CFStringCreateWithCString(NULL, filename.c_str(), kCFStringEncodingUTF8); else nameString = CFSTR("Untitled"); // Add the extension if one was not provided if (nameString && !CFStringHasSuffix(nameString, extension)) { CFStringRef tempString = nameString; hasExtension = false; nameString = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%@"), tempString, extension); CFRelease(tempString); } // Set the name in the dialog if (nameString) { error = NavDialogSetSaveFileName(navRef, nameString); CFRelease(nameString); } else { error = paramErr; } } gViewerWindow->mWindow->beforeDialog(); // Run the dialog if (error == noErr) error = NavDialogRun(navRef); gViewerWindow->mWindow->afterDialog(); if (error == noErr) error = NavDialogGetReply(navRef, &navReply); if (navRef) NavDialogDispose(navRef); if (error == noErr && navReply.validRecord) { SInt32 count = 0; // AE indexes are 1 based... error = AECountItems(&navReply.selection, &count); if (count > 0) { // Get the FSRef to the containing folder FSRef fsRef; AEKeyword theAEKeyword; DescType typeCode; Size actualSize = 0; memset(&fsRef, 0, sizeof(fsRef)); error = AEGetNthPtr(&navReply.selection, 1, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); if (error == noErr) { char path[PATH_MAX]; /*Flawfinder: ignore*/ char newFileName[SINGLE_FILENAME_BUFFER_SIZE]; /*Flawfinder: ignore*/ error = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX); if (error == noErr) { if (CFStringGetCString(navReply.saveFileName, newFileName, sizeof(newFileName), kCFStringEncodingUTF8)) { mFiles.push_back(std::string(path) + "/" + std::string(newFileName)); } else { error = paramErr; } } else { error = paramErr; } } } } return error; }
static pascal void NavEventProc( NavEventCallbackMessage inSelector, NavCBRecPtr ioParams, NavCallBackUserData ioUserData ) { OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ; if (inSelector == kNavCBEvent) { #if TARGET_CARBON #else wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event); #endif } else if ( inSelector == kNavCBStart ) { #if TARGET_CARBON if (data && !(data->defaultLocation).IsEmpty()) { // Set default location for the modern Navigation APIs // Apple Technical Q&A 1151 FSSpec theFSSpec; wxMacFilename2FSSpec(data->defaultLocation, &theFSSpec); AEDesc theLocation = {typeNull, NULL}; if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation)) ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation); } #else if ( data->menuitems ) NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &(*data->menuitems)[data->currentfilter]); #endif } else if ( inSelector == kNavCBPopupMenuSelect ) { NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ; #if TARGET_CARBON #else if ( menu->menuCreator == 'WXNG' ) #endif { data->currentfilter = menu->menuType ; if ( data->saveMode ) { int i = menu->menuType ; wxString extension = data->extensions[i].AfterLast('.') ; extension.MakeLower() ; wxString sfilename ; #if TARGET_CARBON wxMacCFStringHolder cfString( NavDialogGetSaveFileName( ioParams->context ) , false ); sfilename = cfString.AsString() ; #else Str255 filename ; // get the current filename NavCustomControl(ioParams->context, kNavCtlGetEditFileName, &filename); sfilename = wxMacMakeStringFromPascal( filename ) ; #endif int pos = sfilename.Find('.', true) ; if ( pos != wxNOT_FOUND ) { sfilename = sfilename.Left(pos+1)+extension ; #if TARGET_CARBON cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ; NavDialogSetSaveFileName( ioParams->context , cfString ) ; #else wxMacStringToPascal( sfilename , filename ) ; NavCustomControl(ioParams->context, kNavCtlSetEditFileName, &filename); #endif } } } } }
static void HandleCustomMouseDown(NavCBRecPtr callBackParms, CustomData *data) { EventRecord *evt = callBackParms->eventData.eventDataParms.event; Point where = evt->where; GlobalToLocal(&where); ControlRef control = FindControlUnderMouse(where, callBackParms->window, NULL); if (control != NULL) { ControlID cid; GetControlID(control, &cid); HandleControlClick(control, where, evt->modifiers, (ControlActionUPP)-1L); if (cid.signature == kCustom) { switch (cid.id) { case kChoice: { MenuRef menu; UInt32 v; menu = GetControlPopupMenuRef(control); v = GetControl32BitValue(control) - 1; const size_t numFilters = data->extensions.GetCount(); if (v < numFilters) { data->currentfilter = v; if (data->saveMode) { int i = data->currentfilter; wxString extension = data->extensions[i].AfterLast('.') ; extension.MakeLower() ; wxString sfilename ; wxMacCFStringHolder cfString(NavDialogGetSaveFileName(callBackParms->context), false); sfilename = cfString.AsString() ; #if 0 int pos = sfilename.Find('.', true) ; if (pos != wxNOT_FOUND) { sfilename = sfilename.Left(pos + 1) + extension; cfString.Assign(sfilename, wxFONTENCODING_DEFAULT); NavDialogSetSaveFileName(callBackParms->context, cfString); } #endif } NavCustomControl(callBackParms->context, kNavCtlBrowserRedraw, NULL); } break; } case kButton: { data->me->ClickButton(GetControl32BitValue(data->choice) - 1); break; } } } } }