int prFile_PutFile(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 2; PyrSlot *b = g->sp - 1; PyrSlot *c = g->sp; NavDialogOptions options; int err = NavGetDefaultDialogOptions(&options); if (err) return errFailed; options.dialogOptionFlags |= kNavNoTypePopup; options.dialogOptionFlags |= kNavDontAutoTranslate; options.dialogOptionFlags |= kNavDontAddTranslateItems; options.dialogOptionFlags |= kNavSelectDefaultLocation; options.dialogOptionFlags &= ~kNavAllowPreviews; options.dialogOptionFlags &= ~kNavAllowMultipleFiles; if (isKindOfSlot(b, class_string)) { pstringFromPyrString((PyrString*)slotRawObject(b), options.message, 256); } if (isKindOfSlot(c, class_string)) { pstringFromPyrString((PyrString*)slotRawObject(c), options.savedFileName, 256); } else { //pstrncpy(options.savedFileName, "\pUntitled", 255); } NavReplyRecord reply; err = NavPutFile(0, &reply, &options, 0, 'TEXT', 'SCjm', 0); if (err == noErr && reply.validRecord) { AEKeyword keyword; DescType actualType; Size actualSize; FSSpec fsspec; err = AEGetNthPtr(&reply.selection, 1, typeFSS, &keyword, &actualType, &fsspec, sizeof(FSSpec), &actualSize); if (err == noErr) { Str255 pathname; GetFullPathname(&fsspec, pathname); p2cstr(pathname); PyrString *string = newPyrString(g->gc, (char*)pathname, 0, true); SetObject(a, string); err = NavCompleteSave(&reply, kNavTranslateInPlace); } else { SetNil(a); } err = NavDisposeReply(&reply); } else { SetNil(a); } return errNone; }
OSErr PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing) { NavReplyRecord myReply; NavDialogOptions myDialogOptions; NavEventUPP myEventUPP = NewNavEventUPP(HandleNavEvent); OSErr myErr = noErr; if ((theFSSpecPtr == NULL) || (theIsSelected == NULL) || (theIsReplacing == NULL)) return(paramErr); // assume we are not replacing an existing file *theIsReplacing = false; *theIsSelected = false; // specify the options for the dialog box NavGetDefaultDialogOptions(&myDialogOptions); myDialogOptions.dialogOptionFlags += kNavNoTypePopup; myDialogOptions.dialogOptionFlags += kNavDontAutoTranslate; BlockMoveData(theFileName, myDialogOptions.savedFileName, theFileName[0] + 1); BlockMoveData(thePrompt, myDialogOptions.message, thePrompt[0] + 1); // prompt the user for a file myErr = NavPutFile(NULL, &myReply, &myDialogOptions, myEventUPP, MovieFileType, sigMoviePlayer, NULL); if ((myErr == noErr) && myReply.validRecord) { AEKeyword myKeyword; DescType myActualType; Size myActualSize = 0; // get the FSSpec for the selected file if (theFSSpecPtr != NULL) myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize); *theIsSelected = myReply.validRecord; if (myReply.validRecord) { *theIsReplacing = myReply.replacing; } NavDisposeReply(&myReply); } DisposeNavEventUPP(myEventUPP); return(myErr); }
void saveToPICTFile() { /* Saving a PixMap as a PICT file isn't too hard. 1. Open a Picture with the port set to the destination of #2. 2. CopyBits the PixMap onto itself or another port. (Because CopyBits is recorded in Pictures. 3. Close the picture. 4. Open the data fork for the file. 5. Write out 512 bytes of zeros followed by the contents of the Picture handle. 6. Close the file. */ PicHandle picHandle; OSErr anErr = noErr; OSType fileTypeToSave = 'PICT'; OSType creatorType = 'ogle'; NavReplyRecord reply; NavDialogOptions dialogOptions; FSSpec documentFSSpec; long inOutCount; short refNum, count; AEKeyword theKeyword; DescType actualType; unsigned char header[512]; Size actualSize; Rect tempRect1; CopyBits(GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), (BitMap*) &gPixMap, GetPortBounds(GetWindowPort(gWindow), &tempRect1), &gPixMap.bounds, srcCopy, 0L); SetPortWindowPort(gWindow); picHandle = OpenPicture(&gPixMap.bounds); CopyBits((BitMap*) &gPixMap, GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), &gPixMap.bounds, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0L); ClosePicture(); for (count = 0; count < 512; count++) header[count] = 0x00; anErr = NavGetDefaultDialogOptions(&dialogOptions); dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation; anErr = NavPutFile( nil, &reply, &dialogOptions, nil, fileTypeToSave, creatorType, nil ); if (anErr == noErr && reply.validRecord) { anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS, &theKeyword, &actualType, &documentFSSpec, sizeof(documentFSSpec), &actualSize ); if (anErr == noErr) { anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); if (anErr == dupFNErr) { anErr = FSpDelete(&documentFSSpec); anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); } // this is quick 'n' dirty or there'd be more robust handling here // write the file FSpOpenDF(&documentFSSpec, fsRdWrPerm, &refNum ); inOutCount = 512; anErr = FSWrite(refNum, &inOutCount, header); // write the header if (anErr == noErr) { inOutCount = GetHandleSize((Handle)picHandle); anErr = FSWrite(refNum,&inOutCount,*picHandle); } FSClose( refNum ); } reply.translationNeeded = false; anErr = NavCompleteSave(&reply, kNavTranslateInPlace); NavDisposeReply(&reply); } KillPicture(picHandle); }