void OpenUserDataRec::EventProcCBStart(NavCBRecPtr ioParams) { if (!m_defaultLocation.empty()) { // Set default location for the modern Navigation APIs // Apple Technical Q&A 1151 FSRef theFile; wxMacPathToFSRef(m_defaultLocation, &theFile); AEDesc theLocation = { typeNull, NULL }; if (noErr == ::AECreateDesc(typeFSRef, &theFile, sizeof(FSRef), &theLocation)) ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation); } if( m_extensions.GetCount() > 0 ) { NavMenuItemSpec menuItem; memset( &menuItem, 0, sizeof(menuItem) ); menuItem.version = kNavMenuItemSpecVersion; menuItem.menuType = m_currentfilter; ::NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &menuItem); } if (m_dialog->GetExtraControl()) { m_controlAdded = true; ControlRef ref = m_dialog->GetExtraControl()->GetPeer()->GetControlRef(); NavCustomControl(ioParams->context, kNavCtlAddControl, ref); } }
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 ) ; } } } } }
void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) { OSStatus err = noErr; FSRef fsRef; wxMacPathToFSRef( path , &fsRef ); err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, spec, NULL); verify_noerr( err ); }
long wxExecute(const wxString& command, int flags, wxProcess *WXUNUSED(handler)) { wxASSERT_MSG( flags == wxEXEC_ASYNC, wxT("wxExecute: Only wxEXEC_ASYNC is supported") ); FSRef fsRef ; OSErr err = noErr ; err = wxMacPathToFSRef( command , &fsRef ) ; if ( noErr == err ) { err = LSOpenFSRef( &fsRef , NULL ) ; } // 0 means execution failed. Returning non-zero is a PID, but not // on Mac where PIDs are 64 bits and won't fit in a long, so we // return a dummy value for now. return ( err == noErr ) ? -1 : 0; }
static pascal void NavEventProc( NavEventCallbackMessage inSelector, NavCBRecPtr ioParams, NavCallBackUserData ioUserData ) { wxDirDialog * data = ( wxDirDialog *) ioUserData ; if ( inSelector == kNavCBStart ) { if (data && !data->GetPath().empty() ) { // Set default location for the modern Navigation APIs // Apple Technical Q&A 1151 FSRef theFile; wxMacPathToFSRef(data->GetPath(), &theFile); AEDesc theLocation = { typeNull, NULL }; if (noErr == ::AECreateDesc(typeFSRef, &theFile, sizeof(FSRef), &theLocation)) ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation); } } }
std::unique_ptr<ImportFileHandle> QTImportPlugin::Open(const wxString & Filename) { OSErr err; FSRef inRef; Movie theMovie = NULL; Handle dataRef = NULL; OSType dataRefType = 0; short resID = 0; #if defined(__WXMAC__) err = wxMacPathToFSRef(Filename, &inRef); #else // LLL: This will not work for pathnames with Unicode characters...find // another method. err = FSPathMakeRef((UInt8 *)OSFILENAME(Filename), &inRef, NULL); #endif if (err != noErr) { return nullptr; } err = QTNewDataReferenceFromFSRef(&inRef, 0, &dataRef, &dataRefType); if (err != noErr) { return nullptr; } // instantiate the movie err = NewMovieFromDataRef(&theMovie, newMovieActive | newMovieDontAskUnresolvedDataRefs, &resID, dataRef, dataRefType); DisposeHandle(dataRef); if (err != noErr) { return nullptr; } return std::make_unique<QTImportFileHandle>(Filename, theMovie); }
void MolDisplayWin::WriteQTMovie(wxString & filepath) { //Create a QuickTime movie using the standard animation codecs with normal quality, and //temporal compression. The final file is flattened for cross platform compatability QTExport * QTOptions = new QTExport(this); //setup controls for the current data if (MainData->GetNumFrames() > 1) { //default to frame animation QTOptions->SetMovieChoice(0); } else { QTOptions->EnableFrameMovie(false); } if (MainData->cFrame->GetNumberNormalModes() <= 0) { QTOptions->EnableModeMovie(false); } if (QTOptions->ShowModal() != wxID_OK) { //user cancelled the operation QTOptions->Destroy(); return; } //retrieve the value of each option int MovieType = QTOptions->GetMovieChoice(); bool IncludeEPlot = QTOptions->AddEnergyPlot(); int compressorChoice = QTOptions->GetCompressorChoice(); int keyFrameRate = QTOptions->GetKeyFrameRate(); if (keyFrameRate < 0) keyFrameRate = 0; QTOptions->Destroy(); CodecType mCodec; switch (compressorChoice) { case 0: mCodec = kCinepakCodecType; break; case 1: mCodec = kGraphicsCodecType; break; case 2: mCodec = kAnimationCodecType; break; case 3: default: mCodec = kMPEG4VisualCodecType; } OSStatus s; OSErr myErr = myErr; FSSpec targetSpec; //ugh I need to get an FSSpec to hand to quicktime, but these calls only seem to work if //the file already exists... const char * t = filepath.mb_str(wxConvUTF8); FILE * temp = fopen(t, "wb"); fclose(temp); #ifdef __WXOSX_COCOA__ //This function is not found in the wxCocoa implementation, it is probably possible to work around it //Otherwise the code appears to link and run currently. However, it is probably better to redue the //code to use the Cocoa qtKit framework rather than the old Carbon QT library. //This path is not tested as the current Cocoa code does not properly support the extended save dialog. // void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) { OSStatus err = noErr; FSRef fsRef; wxMacPathToFSRef( filepath , &fsRef ); err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &targetSpec, NULL); verify_noerr( err ); } #else wxMacFilename2FSSpec(filepath, &targetSpec); #endif Movie theMovie = NULL; FSSpec tempSpec = targetSpec; strcpy((char *) &(tempSpec.name[1]), "MacMolPlt8933tempMovie"); tempSpec.name[0] = 22; BeginOperation(); ProgressInd->ChangeText("Creating movie..."); myErr = EnterMovies(); //initialize the quicktime manager if (myErr != noErr) { FinishOperation(); MessageAlert("Error initializing QuickTime!"); return; } //Create the movie file and initialize file data //Use Quicktime creator code 'TVOD' instead of simpletext 'ttxt' short resRefNum = 0; short resId = 0; myErr = CreateMovieFile(&tempSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resRefNum, &theMovie); if (myErr != noErr) { MessageAlert("Error creating movie file!"); } else { bool KillEPlot = false; int width, height, savedEPlotWidth, savedEPlotHeight; glCanvas->GetClientSize(&width, &height); Rect lDisplayRect={0,0,0,0}; lDisplayRect.right = width; lDisplayRect.bottom = height; Rect gRect = lDisplayRect; Rect EPlotRect = lDisplayRect; //If we are including an energy plot add space for it here if (IncludeEPlot && (MovieType == 0)) { EPlotRect.left = EPlotRect.right; EPlotRect.right = EPlotRect.left + height; if (!energyPlotWindow) { energyPlotWindow = new EnergyPlotDialog(this); KillEPlot = true; } else { energyPlotWindow->GetSize(&savedEPlotWidth, &savedEPlotHeight); } gRect.right += height; width += height; energyPlotWindow->Show(false); energyPlotWindow->SetSize(height, height); energyPlotWindow->Update(); //This is needed to initialise the window if we just created it } LocalToGlobal ((Point *) &(gRect.top)); LocalToGlobal ((Point *) &(gRect.bottom)); WindowRef TempWindow; s = CreateNewWindow(kDocumentWindowClass, kWindowNoAttributes, &gRect, &TempWindow); if (s == noErr) { //Create the video track Track theTrack = NewMovieTrack (theMovie, FixRatio(width,1), FixRatio(height,1), kNoVolume); if ((noErr == GetMoviesError())&&theTrack) { Media theMedia = NewTrackMedia (theTrack, VideoMediaType, 60, // Video Time Scale NULL, 0); if ((noErr == GetMoviesError())&&theMedia) { myErr = BeginMediaEdits (theMedia); if (myErr == noErr) { //create the actual movie frames GWorldPtr lgWorld=NULL; if (! NewGWorld (&lgWorld, 0, &gRect, (CTabHandle) NULL, (GDHandle) NULL, (GWorldFlags) (pixPurge + useTempMem))) { long MaxCompressedSize; ImageSequence seqID; ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(4); PixMapHandle myPixMap = GetPortPixMap(lgWorld); LockPixels (myPixMap); myErr = CompressSequenceBegin(&seqID, myPixMap, NULL, &gRect, &gRect, 0, mCodec, bestCompressionCodec, codecNormalQuality, codecNormalQuality, keyFrameRate, NULL, codecFlagUpdatePreviousComp, imageDesc); GetMaxCompressionSize (myPixMap, &gRect, 0, codecNormalQuality, mCodec, (CompressorComponent) anyCodec, &MaxCompressedSize); Handle Buffer = TempNewHandle(MaxCompressedSize, &myErr); if (!Buffer) Buffer = NewHandle(MaxCompressedSize); if (Buffer) { qtData myqtData = {theMedia, imageDesc, seqID, lDisplayRect, gRect}; if (MovieType == 0) { CreateFrameMovie(lgWorld, Buffer, myqtData, IncludeEPlot); } else { CreateModeMovie(lgWorld, Buffer, myqtData); } DisposeHandle(Buffer); } myErr = CDSequenceEnd(seqID); if (lgWorld != NULL) DisposeGWorld (lgWorld); if (imageDesc) DisposeHandle((Handle) imageDesc); } myErr = EndMediaEdits (theMedia); } myErr = InsertMediaIntoTrack (theTrack, 0,/* track start time */ 0, /* media start time */ GetMediaDuration (theMedia), FixRatio(1,1)); } myErr = AddMovieResource (theMovie, resRefNum, &resId, NULL); } if (resRefNum) { //Create the actual file as a flat data fork so it can be placed on the www ProgressInd->ChangeText("Flattening movieÉ"); FlattenMovie(theMovie, flattenAddMovieToDataFork, &targetSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resId, NULL); CloseMovieFile (resRefNum); } DisposeWindow(TempWindow); } DisposeMovie (theMovie); DeleteMovieFile (&tempSpec); //delete the temp file after disposing of the movie if (energyPlotWindow) { if (KillEPlot) { delete energyPlotWindow; energyPlotWindow = NULL; } else { energyPlotWindow->SetSize(savedEPlotWidth, savedEPlotHeight); energyPlotWindow->FrameChanged(); energyPlotWindow->Show(true); } } } ExitMovies(); //Close out quicktime as we are done with it for now FinishOperation(); }
bool wxDirData::Read(wxString *filename) { wxString result; OSStatus err = noErr ; if ( NULL == m_iterator ) { FSRef dirRef; err = wxMacPathToFSRef( m_dirname , &dirRef ) ; if ( err == noErr ) { err = FSOpenIterator(&dirRef, kFSIterateFlat, &m_iterator); } if ( err ) { Close() ; return false ; } } wxString name ; wxString lowerfilespec = m_filespec.Lower(); while( noErr == err ) { HFSUniStr255 uniname ; FSRef fileRef; FSCatalogInfo catalogInfo; ItemCount fetched = 0; err = FSGetCatalogInfoBulk( m_iterator, 1, &fetched, NULL, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo , &catalogInfo , &fileRef, NULL, &uniname ); // expected error codes if ( errFSNoMoreItems == err ) return false ; if ( afpAccessDenied == err ) return false ; if ( noErr != err ) break ; name = wxMacHFSUniStrToString( &uniname ) ; wxString lowername = name.Lower(); if ( ( name == wxT(".") || name == wxT("..") ) && !(m_flags & wxDIR_DOTDOT) ) continue; if ( ( name[0U] == '.' ) && !(m_flags & wxDIR_HIDDEN ) ) continue ; if ( (((FileInfo*)&catalogInfo.finderInfo)->finderFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN ) ) continue ; // its a dir and we don't want it if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) && !(m_flags & wxDIR_DIRS) ) continue ; // its a file but we don't want it if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0 && !(m_flags & wxDIR_FILES ) ) continue ; if ( m_filespec.empty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") ) { } else if ( !wxMatchWild(lowerfilespec, lowername , false) ) { continue ; } break ; } if ( err != noErr ) { return false ; } *filename = name ; return true; }