Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
fileStuff.c
// Quickdraw 3D sample code |
// |
// Nick Thompson, AppleLink: DEVSUPPORT (devsupport@applelink.apple.com) |
// |
// ©1994-5 Apple Computer Inc., All Rights Reserved |
#include "QD3D.h" |
#include "QD3DGroup.h" |
#include "QD3DIO.h" |
#include "QD3DStorage.h" |
#include "QD3DView.h" |
#include <StandardFile.h> |
#include "FileStuff.h" |
void WriteGroupToFile( TQ3FileObject file, TQ3GroupObject theData, TQ3ViewObject theView) |
{ |
TQ3GroupPosition gPos; |
TQ3Object object; |
TQ3SharedObject viewHints; |
TQ3ViewStatus fileStatus; |
if (Q3File_OpenWrite(file, kQ3FileModeNormal | kQ3FileModeText) == kQ3Success ) |
{ |
Q3View_StartWriting(theView, file); |
if (theView == NULL) |
viewHints = NULL; |
else |
viewHints = Q3ViewHints_New(theView); |
if (viewHints != NULL) |
{ |
if (Q3Object_Submit(viewHints, theView) == kQ3Failure) |
{ |
Q3File_Cancel(file); |
return; |
} |
} |
do { |
if (theData != NULL) |
{ |
TQ3Status status; |
status = Q3Group_GetFirstPosition(theData, &gPos); |
while (gPos != NULL && status == kQ3Success) |
{ |
Q3Group_GetPositionObject(theData, gPos, &object); |
status = Q3Object_Submit(object, theView); |
Q3Object_Dispose(object); |
if (status != kQ3Failure) |
{ |
Q3Group_GetNextPosition(theData, &gPos); |
} |
} |
} |
} while ((fileStatus = Q3View_EndWriting(theView)) == kQ3ViewStatusRetraverse); |
if( Q3File_Close(file) == kQ3Failure ) { |
return; |
} |
} |
return ; |
} |
Boolean WriteFile(TQ3GroupObject theData, TQ3ViewObject theView ) |
{ |
Str255 thePrompt = "\pGimmie a file:", theName = "\pMetafile.3mf"; |
StandardFileReply theReply; |
OSErr theResult; |
long length; |
char *bufPtr; |
short myRefNum ; |
StandardPutFile( (ConstStr255Param) &thePrompt, (ConstStr255Param) &theName, &theReply); |
if (theReply.sfGood) { |
if (!theReply.sfReplacing) { |
if ((theResult = FSpCreate(&theReply.sfFile, '????', 'TEXT', theReply.sfScript)) != noErr) { |
SysBeep(1); |
return(false); |
} |
} |
} |
if( theData ) { |
TQ3StorageObject storage; |
TQ3FileObject fd; |
storage = Q3FSSpecStorage_New( &theReply.sfFile ); |
if (storage == NULL) |
goto bail; |
fd = Q3File_New(); |
if (fd == nil) |
goto bail; |
Q3File_SetStorage(fd, storage); |
Q3Object_Dispose(storage); |
WriteGroupToFile( fd, theData, theView ) ; |
Q3Object_Dispose(fd); |
} |
return(noErr); |
bail: |
return(fnOpnErr); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14