home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-22 | 34.2 KB | 1,219 lines |
- // ===========================================================================
- // Project : QuickDraw 3D
- // File : CustomAttribute.cp
- //
- // Authors : Robin Landsbert
- //
- // ===========================================================================
-
-
- #include "CustomAttribute.h"
- #include <QD3DIO.h>
- #include <QD3DString.h>
- #include <string.h>
-
-
- TQ3FunctionPointer HandleRecordMetaHandler ( TQ3MethodType methodType , TQ3FunctionPointer ReadData ) ;
- TQ3FunctionPointer NameMetaHandler ( TQ3MethodType methodType ) ;
- TQ3FunctionPointer FourByteMetaHandler ( TQ3MethodType methodType ) ;
- TQ3FunctionPointer DoubleMetaHandler ( TQ3MethodType methodType ) ;
- TQ3FunctionPointer UpVectorAttributeMetaHandler ( TQ3MethodType methodType ) ;
- TQ3FunctionPointer ForwardDirectionAttributeMetaHandler ( TQ3MethodType methodType ) ;
- TQ3FunctionPointer W3AnchorMetaHandler ( TQ3MethodType methodType ) ;
- TQ3FunctionPointer W3InlineMetaHandler ( TQ3MethodType methodType ) ;
- TQ3FunctionPointer WWWAnchorMetaHandler( TQ3MethodType methodType ) ;
-
- bool DoHandleReadData ( THandleRecord& theHandleRec , TQ3FileObject file ) ;
- TQ3Status HandleTraverse ( TQ3Object object , THandleRecord* data , TQ3ViewObject view ) ;
- TQ3Status HandleWrite ( const THandleRecord* object , TQ3FileObject file ) ;
-
- TQ3Status HandleCopyAdd ( const THandleRecord* fromAPIElement , THandleRecord* toInternalElement ) ;
- TQ3Status HandleCopyReplace ( const THandleRecord* fromAPIElement , THandleRecord* toInternalElement ) ;
- TQ3Status HandleCopyDuplicate ( const THandleRecord* fromInternalElement , THandleRecord* toInternalElement ) ;
- TQ3Status HandleDelete ( THandleRecord* internalElement ) ;
-
- TQ3Status FourByteTraverse ( TQ3Object object , unsigned long* data , TQ3ViewObject view ) ;
- TQ3Status FourByteWrite ( const unsigned long* data , TQ3FileObject file ) ;
- TQ3Status FourByteRead ( TQ3Object parentObject , TQ3FileObject file ) ;
- TQ3Status FourByteCopy ( const unsigned long* fromAPIElement , unsigned long* toInternalElement ) ;
-
- TQ3Status DoubleTraverse ( TQ3Object object , TQ3Float64* data , TQ3ViewObject view ) ;
- TQ3Status DoubleWrite ( const TQ3Float64* data , TQ3FileObject file ) ;
- TQ3Status DoubleRead ( TQ3SetObject attributeSet , TQ3FileObject file ) ;
- TQ3Status DoubleCopy ( const double* fromAPIElement , double* toInternalElement ) ;
-
- TQ3FunctionPointer SoundMetaHandler ( TQ3MethodType methodType ) ;
- TQ3Status SoundReadData ( TQ3SetObject parentObject , TQ3FileObject file ) ;
-
- TQ3FunctionPointer PictMetaHandler ( TQ3MethodType methodType ) ;
- TQ3Status PictReadData ( TQ3SetObject parentObject , TQ3FileObject file ) ;
-
- TQ3FunctionPointer TextMetaHandler ( TQ3MethodType methodType ) ;
- TQ3Status TextReadData ( TQ3SetObject parentObject , TQ3FileObject file ) ;
-
- TQ3FunctionPointer MovieMetaHandler ( TQ3MethodType methodType ) ;
- TQ3Status MovieReadData ( TQ3SetObject parentObject , TQ3FileObject file ) ;
-
- TQ3FunctionPointer DescriptionMetaHandler ( TQ3MethodType methodType ) ;
- TQ3Status DescriptionReadData ( TQ3SetObject parentObject , TQ3FileObject file ) ;
-
- TQ3Status HandleNameTraverse ( TQ3Object /*object*/ , TQ3Object* theStringObj , TQ3ViewObject theView ) ;
- TQ3Status HandleNameWrite ( const char* data , TQ3FileObject file ) ;
- TQ3Status HandleNameReadData ( TQ3SetObject parentObject , TQ3FileObject file ) ;
- TQ3Status HandleNameCopyAdd ( const TQ3Object* fromAPIElement , TQ3Object* toInternalElement ) ;
- TQ3Status HandleNameCopyReplace ( const TQ3Object* fromAPIElement , TQ3Object* toInternalElement ) ;
- TQ3Status HandleNameDelete ( TQ3Object* internalElement ) ;
-
- TQ3Status VectorTraverse ( TQ3Object , TQ3Vector3D* upVector , TQ3ViewObject view ) ;
- TQ3Status VectorWrite ( const TQ3Vector3D* upVector , TQ3FileObject file ) ;
- TQ3Status UpVectorAttributeReadData ( TQ3SetObject attributeSet , TQ3FileObject file ) ;
- TQ3Status ForwardDirectionAttributeReadData ( TQ3SetObject attributeSet , TQ3FileObject file ) ;
-
- TQ3Status W3AnchorTraverse ( TQ3Object , W3AnchorData* URLdata , TQ3ViewObject view ) ;
- TQ3Status W3AnchorWrite ( const W3AnchorData* URLdata , TQ3FileObject file ) ;
- TQ3Status W3AnchorReadData ( TQ3SetObject set , TQ3FileObject file ) ;
- TQ3Status W3AnchorCopyAdd ( const W3AnchorData* src , W3AnchorData* dst ) ;
- TQ3Status W3AnchorCopyReplace ( const W3AnchorData* src , W3AnchorData* dst ) ;
- TQ3Status W3AnchorDelete ( W3AnchorData* URLData ) ;
-
- TQ3Status W3InlineTraverse ( TQ3Object , W3InlineData* inlineData , TQ3ViewObject view ) ;
- TQ3Status W3InlineWrite ( const W3InlineData* inlineData , TQ3FileObject file ) ;
- TQ3Status W3InlineReadData ( TQ3SetObject set , TQ3FileObject file ) ;
- TQ3Status W3InlineCopyAdd ( const W3InlineData* src , W3InlineData* dst ) ;
- TQ3Status W3InlineCopyReplace ( const W3InlineData* src , W3InlineData* dst ) ;
- TQ3Status W3InlineDelete ( W3InlineData* src ) ;
-
- TQ3Status WWWAnchorTraverse ( TQ3Object , WWWAnchorData* wwwdata , TQ3ViewObject view ) ;
- TQ3Status WWWAnchorWrite ( const WWWAnchorData *wwwdata , TQ3FileObject file ) ;
- TQ3Status WWWAnchorReadData ( TQ3SetObject set , TQ3FileObject file ) ;
- TQ3Status WWWAnchorCopyAdd ( const WWWAnchorData* src , WWWAnchorData* dst ) ;
- TQ3Status WWWAnchorCopyReplace ( const WWWAnchorData* src , WWWAnchorData* dst ) ;
- TQ3Status WWWAnchorDelete ( WWWAnchorData* src ) ;
-
-
- // ===========================================================================
-
-
- void UnregisterCustomAttribute ( TQ3ObjectClass theClass )
- {
- Q3ObjectClass_Unregister ( theClass ) ;
- }
-
-
- TQ3ObjectClass RegisterCustomAttribute ( TQ3AttributeType theType , unsigned long theSize , TQ3MetaHandler theHandler )
- {
- TQ3ObjectClass theClass ;
- switch ( theType )
- {
- case kCustomSoundType:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Sound" , theSize , theHandler ) ;
- break ;
- case kCustomPictType:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Picture" , theSize , theHandler ) ;
- break ;
- case kCustomTextType:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Text" , theSize , theHandler ) ;
- break ;
- case kCustomMovieType:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Movie" , theSize , theHandler ) ;
- break ;
- case kLockedAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Locked" , theSize , theHandler ) ;
- break ;
- case kUnitsAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Units" , theSize , theHandler ) ;
- break ;
- case kScaleAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Scale" , theSize , theHandler ) ;
- break ;
- case kNameAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Name" , theSize , theHandler ) ;
- break ;
- case kDescriptionAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:Description" , theSize , theHandler ) ;
- break ;
- case kUpVectorAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:UpVector" , theSize , theHandler ) ;
- break ;
- case kForwardDirectionAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:ForwardVector" , theSize , theHandler ) ;
- break ;
- case kW3AnchorAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:W3Anchor" , theSize , theHandler ) ;
- break ;
- case kW3InlineAttribute:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:W3Inline" , theSize , theHandler ) ;
- break ;
- case kElementTypeWWWAnchor:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:WWWAnchor" , theSize , theHandler ) ;
- break ;
- default:
- theClass = Q3AttributeClass_Register ( theType , "Microspot:UnknownAttribute" , theSize , theHandler ) ;
- break ;
- }
- return theClass ;
- }
-
-
- TQ3FunctionPointer HandleRecordMetaHandler ( TQ3MethodType methodType , TQ3FunctionPointer ReadData )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer)HandleTraverse ;
-
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer)HandleWrite ;
-
- case kQ3MethodTypeObjectReadData:
- return ReadData ;
-
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer)HandleCopyAdd ;
-
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer)HandleCopyReplace ;
-
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer)HandleDelete ;
-
- default:
- return nil ;
- } // switch
- }
-
-
- TQ3Status HandleTraverse ( TQ3Object , THandleRecord* object , TQ3ViewObject theView )
- {
- if ( object )
- {
- if ( object->theHandle )
- {
- unsigned long theSize = GetHandleSize ( object->theHandle ) + sizeof ( long ) ; // + 4 for length
- theSize = Q3Size_Pad ( theSize ) ;
- return Q3View_SubmitWriteData ( theView , theSize , object , nil ) ;
- }
- }
- return kQ3Success ;
- }
-
-
- TQ3Status HandleWrite ( const THandleRecord* object , TQ3FileObject file )
- {
- if ( object )
- {
- if ( object->theHandle )
- {
- HLock ( object->theHandle ) ;
- unsigned long size = Q3Size_Pad ( object->theSize ) ;
- TQ3Status err = Q3Uns32_Write ( object->theSize , file ) ;
- if ( err == kQ3Success )
- err = Q3RawData_Write ( ((unsigned char*)(*object->theHandle)) , size , file ) ;
- HUnlock ( object->theHandle ) ;
- return err ;
- }
- }
- return kQ3Success ;
- }
-
-
- bool DoHandleReadData ( THandleRecord& theHandleRec , TQ3FileObject file )
- {
- if ( file == nil )
- return false ;
- TQ3Status err ;
- err = Q3Uns32_Read ( &theHandleRec.theSize , file ) ;
- if ( err == kQ3Failure )
- return false ;
-
- unsigned long size = Q3Size_Pad ( theHandleRec.theSize ) ;
- theHandleRec.theHandle = NewHandleClear ( size ) ;
- if ( theHandleRec.theHandle )
- {
- HLock ( theHandleRec.theHandle ) ;
- err = Q3RawData_Read ( ((unsigned char*)(*theHandleRec.theHandle)) , size , file ) ;
- if ( err == kQ3Failure )
- {
- DisposeHandle ( theHandleRec.theHandle ) ;
- theHandleRec.theHandle = nil ;
- theHandleRec.theSize = 0 ;
- return false ;
- }
- else
- HUnlock ( theHandleRec.theHandle ) ;
- return true ;
- }
- else
- return false ;
- }
-
-
- TQ3Status HandleCopyAdd ( const THandleRecord* fromAPIElement , THandleRecord* toInternalElement )
- {
- if ( fromAPIElement && toInternalElement )
- {
- long theSize = fromAPIElement->theSize ;
- if ( theSize )
- {
- toInternalElement->theSize = theSize ;
- unsigned long size = Q3Size_Pad ( theSize ) ;
- toInternalElement->theHandle = NewHandleClear ( size ) ;
- if (toInternalElement->theHandle)
- {
- BlockMoveData ( *(fromAPIElement->theHandle) , *(toInternalElement->theHandle) , theSize ) ;
- return kQ3Success ;
- }
- else
- return kQ3Failure ;
- }
- else
- {
- toInternalElement->theHandle = nil ;
- toInternalElement->theSize = 0 ;
- return kQ3Failure ;
- }
- }
- return kQ3Success ;
- }
-
-
- TQ3Status HandleCopyReplace ( const THandleRecord* fromAPIElement , THandleRecord* toInternalElement )
- {
- if ( fromAPIElement && toInternalElement )
- {
- if ( toInternalElement->theHandle )
- DisposeHandle ( toInternalElement->theHandle ) ;
- return HandleCopyAdd ( fromAPIElement , toInternalElement ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status HandleDelete ( THandleRecord* internalElement )
- {
- if ( internalElement )
- {
- if ( internalElement->theHandle )
- {
- DisposeHandle ( internalElement->theHandle ) ;
- internalElement->theHandle = nil ;
- }
- internalElement->theSize = 0 ;
- }
- return kQ3Success ;
- }
-
-
- //------------------------------------------------------------------------------------------------
-
- TQ3ObjectClass RegisterSoundAttribute ( void )
- {
- return RegisterCustomAttribute ( kCustomSoundType , sizeof ( THandleRecord ) , SoundMetaHandler ) ;
- }
-
-
- TQ3FunctionPointer SoundMetaHandler ( TQ3MethodType methodType )
- {
- return HandleRecordMetaHandler ( methodType , (TQ3FunctionPointer)SoundReadData ) ;
- }
-
-
- TQ3Status SoundReadData ( TQ3SetObject parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- THandleRecord theHandleRec ;
- if ( DoHandleReadData ( theHandleRec , file ) )
- return Q3AttributeSet_Add ( parentObject , kCustomSoundType , &theHandleRec ) ;
- else
- return kQ3Failure ;
- }
- return kQ3Failure ;
- }
-
- //------------------------------------------------------------------------------------------------
-
- TQ3ObjectClass RegisterPictAttribute ( void )
- {
- return RegisterCustomAttribute ( kCustomPictType , sizeof ( THandleRecord ) , PictMetaHandler ) ;
- }
-
-
- TQ3FunctionPointer PictMetaHandler ( TQ3MethodType methodType )
- {
- return HandleRecordMetaHandler ( methodType , (TQ3FunctionPointer)PictReadData ) ;
- }
-
-
- TQ3Status PictReadData ( TQ3SetObject parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- THandleRecord theHandleRec ;
- if ( DoHandleReadData ( theHandleRec , file ) )
- return Q3AttributeSet_Add ( parentObject , kCustomPictType , &theHandleRec ) ;
- else
- return kQ3Failure ;
- }
- return kQ3Failure ;
- }
-
- //------------------------------------------------------------------------------------------------
-
- TQ3ObjectClass RegisterTextAttribute ( void )
- {
- return RegisterCustomAttribute ( kCustomTextType , sizeof ( THandleRecord ) , TextMetaHandler ) ;
- }
-
-
- TQ3FunctionPointer TextMetaHandler ( TQ3MethodType methodType )
- {
- return HandleRecordMetaHandler ( methodType , (TQ3FunctionPointer)TextReadData ) ;
- }
-
-
- TQ3Status TextReadData ( TQ3SetObject parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- THandleRecord theHandleRec ;
- if ( DoHandleReadData ( theHandleRec , file ) )
- return Q3AttributeSet_Add ( parentObject , kCustomTextType , &theHandleRec ) ;
- else
- return kQ3Failure ;
- }
- return kQ3Failure ;
- }
-
- //------------------------------------------------------------------------------------------------
-
- TQ3ObjectClass RegisterMovieAttribute ( void )
- {
- return RegisterCustomAttribute ( kCustomMovieType , sizeof ( THandleRecord ) , MovieMetaHandler ) ;
- }
-
-
- TQ3FunctionPointer MovieMetaHandler ( TQ3MethodType methodType )
- {
- return HandleRecordMetaHandler ( methodType , (TQ3FunctionPointer)MovieReadData ) ;
- }
-
-
- TQ3Status MovieReadData ( TQ3SetObject parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- THandleRecord theHandleRec ;
- if ( DoHandleReadData ( theHandleRec , file ) )
- return Q3AttributeSet_Add ( parentObject , kCustomMovieType , &theHandleRec ) ;
- else
- return kQ3Failure ;
- }
- return kQ3Failure ;
- }
-
- //------------------------------------------------------------------------------------------------
-
- TQ3ObjectClass RegisterDescriptionAttribute ( void )
- {
- return RegisterCustomAttribute ( kDescriptionAttribute , sizeof ( THandleRecord ) , DescriptionMetaHandler ) ;
- }
-
-
- TQ3FunctionPointer DescriptionMetaHandler ( TQ3MethodType methodType )
- {
- return HandleRecordMetaHandler ( methodType , (TQ3FunctionPointer)DescriptionReadData ) ;
- }
-
-
- TQ3Status DescriptionReadData ( TQ3SetObject parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- THandleRecord theHandleRec ;
- if ( DoHandleReadData ( theHandleRec , file ) )
- return Q3AttributeSet_Add ( parentObject , kDescriptionAttribute , &theHandleRec ) ;
- else
- return kQ3Failure ;
- }
- return kQ3Failure ;
- }
-
- //------------------------------------------------------------------------------------------------
-
-
- TQ3FunctionPointer FourByteMetaHandler ( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer)FourByteTraverse ;
-
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer)FourByteWrite ;
-
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer)FourByteRead ;
-
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer)FourByteCopy ;
-
- default:
- return nil ;
- } // switch
- }
-
-
- TQ3Status FourByteTraverse ( TQ3Object , unsigned long* data , TQ3ViewObject view )
- {
- return Q3View_SubmitWriteData ( view , sizeof ( unsigned long ) , data , nil ) ;
- }
-
-
- TQ3Status FourByteWrite ( const unsigned long* data , TQ3FileObject file )
- {
- return Q3Uns32_Write ( *data , file ) ;
- }
-
-
- TQ3Status FourByteRead ( TQ3Object parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- unsigned long data ;
- TQ3Status err = Q3Uns32_Read ( &data , file ) ;
- if ( err == kQ3Success )
- err = Q3AttributeSet_Add ( parentObject , kLockedAttribute , &data ) ;
- return err ;
- }
- return kQ3Failure ;
- }
-
-
- TQ3Status FourByteCopy ( const unsigned long* fromAPIElement , unsigned long* toInternalElement )
- {
- if ( toInternalElement && fromAPIElement )
- *toInternalElement = *fromAPIElement ;
- return kQ3Success ;
- }
-
-
- //------------------------------------------------------------------------------------------------
-
-
- TQ3ObjectClass RegisterLockedAttribute ( void )
- {
- return RegisterCustomAttribute ( kLockedAttribute , sizeof ( long ) , FourByteMetaHandler ) ;
- }
-
-
- //------------------------------------------------------------------------------------------------
-
-
- TQ3FunctionPointer DoubleMetaHandler ( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer)DoubleTraverse ;
-
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer)DoubleWrite ;
-
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer)DoubleRead ;
-
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer)DoubleCopy ;
-
- default:
- return nil ;
- } // switch
- }
-
-
- TQ3Status DoubleTraverse ( TQ3Object , TQ3Float64* data , TQ3ViewObject view )
- {
- if ( data == nil )
- return kQ3Success ;
- return Q3View_SubmitWriteData ( view , sizeof ( TQ3Float64 ) , data , nil ) ;
- }
-
-
- TQ3Status DoubleWrite ( const TQ3Float64* data , TQ3FileObject file )
- {
- // no need to check data again as this will not be called it it is.
- return Q3Float64_Write ( *data , file ) ;
- }
-
-
- TQ3Status DoubleRead ( TQ3SetObject parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- double data ;
- TQ3Status err = Q3Float64_Read ( &data , file ) ;
- if ( err == kQ3Success )
- err = Q3AttributeSet_Add ( parentObject , kUnitsAttribute , &data ) ;
- return err;
- }
- return kQ3Failure ;
- }
-
-
- TQ3Status DoubleCopy ( const double* fromAPIElement , double* toInternalElement )
- {
- if ( toInternalElement && fromAPIElement )
- *toInternalElement = *fromAPIElement ;
- return kQ3Success ;
- }
-
-
- TQ3ObjectClass RegisterUnitsAttribute ( void )
- {
- return RegisterCustomAttribute ( kUnitsAttribute , sizeof ( TQ3Float64 ) , DoubleMetaHandler ) ;
- }
-
-
- TQ3ObjectClass RegisterScaleAttribute ( void )
- {
- return RegisterCustomAttribute ( kScaleAttribute , sizeof ( TQ3Float64 ) , DoubleMetaHandler ) ;
- }
-
-
- //------------------------------------------------------------------------------------------------
-
-
- TQ3FunctionPointer NameMetaHandler ( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer)HandleNameTraverse ;
-
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer)HandleNameWrite ;
-
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer)HandleNameReadData ;
-
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer)HandleNameCopyAdd ;
-
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer)HandleNameCopyReplace ;
-
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer)HandleNameDelete ;
-
- default:
- return nil ;
- } // switch
- }
-
-
- //------------------------------------------------------------------------------------------------
-
-
- TQ3Status HandleNameTraverse ( TQ3Object /*object*/ , TQ3Object* theStringObj , TQ3ViewObject theView )
- {
- if (*theStringObj == nil)
- return kQ3Success ;
- unsigned long length ;
- if ( Q3CString_GetLength ( *theStringObj , &length ) == kQ3Success )
- {
- char* namePtr = nil ;
- if ( Q3CString_GetString ( *theStringObj , &namePtr ) == kQ3Success )
- {
- if ( namePtr && theView )
- {
- length = Q3Size_Pad ( length + 1 ) ;
- return Q3View_SubmitWriteData ( theView , length , namePtr , NULL ) ;
- }
- }
- }
- return kQ3Failure ;
- }
-
-
- TQ3Status HandleNameWrite ( const char* data , TQ3FileObject file )
- {
- if ( data && file )
- return Q3String_Write ( data , file ) ;
- else
- return kQ3Failure ;
- }
-
-
- TQ3Status HandleNameReadData ( TQ3Object parentObject , TQ3FileObject file )
- {
- if ( parentObject && file )
- {
- Ptr data = NewPtrClear ( kQ3StringMaximumLength ) ;
- if ( data )
- {
- unsigned long length = 0 ;
- TQ3Status err = Q3String_Read ( (char*)data , &length , file ) ;
- if ( err == kQ3Success )
- {
- TQ3Object theObj = Q3CString_New ( data ) ;
- if ( theObj )
- {
- err = Q3AttributeSet_Add ( parentObject , kNameAttribute , &theObj ) ;
- Q3Object_Dispose ( theObj ) ;
- }
- else
- err = kQ3Failure ;
- }
- DisposePtr ( data ) ;
- return err ;
- }
- }
- return kQ3Failure ;
- }
-
-
- TQ3Status HandleNameCopyAdd ( const TQ3Object* fromAPIElement , TQ3Object* toInternalElement )
- {
- if ( toInternalElement && fromAPIElement )
- {
- *toInternalElement = Q3Object_Duplicate ( *fromAPIElement ) ;
- if ( *toInternalElement )
- return kQ3Success ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status HandleNameCopyReplace ( const TQ3Object* fromAPIElement , TQ3Object* toInternalElement )
- {
- if ( toInternalElement && fromAPIElement )
- {
- /*
- It is always good form to get a reference first,
- in case src and dst point to the same object
- */
- TQ3Object temp = *toInternalElement ;
- *toInternalElement = Q3Object_Duplicate ( *fromAPIElement ) ;
- Q3Object_Dispose ( temp ) ;
- if ( *toInternalElement )
- return kQ3Success ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status HandleNameDelete ( TQ3Object* internalElement )
- {
- if ( internalElement )
- return Q3Object_Dispose ( *internalElement ) ; ;
- return kQ3Success ;
- }
-
-
- TQ3ObjectClass RegisterNameAttribute ( void )
- {
- return RegisterCustomAttribute ( kNameAttribute , sizeof ( TQ3StringObject ) , NameMetaHandler ) ;
- }
-
-
- //------------------------------------------------------------------------------------------------
-
-
- TQ3Status VectorTraverse ( TQ3Object , TQ3Vector3D* upVector , TQ3ViewObject view )
- {
- if ( upVector && view )
- return Q3View_SubmitWriteData ( view , sizeof ( TQ3Vector3D ) , upVector , nil ) ;
- return kQ3Success ;
- }
-
-
- TQ3Status VectorWrite ( const TQ3Vector3D* upVector, TQ3FileObject file )
- {
- if ( upVector && file )
- return Q3Vector3D_Write(upVector, file);
- return kQ3Failure ;
- }
-
-
- TQ3Status UpVectorAttributeReadData ( TQ3SetObject attributeSet , TQ3FileObject file )
- {
- if ( attributeSet && file )
- {
- TQ3Vector3D upVector ;
- if ( Q3Vector3D_Read ( &upVector , file ) == kQ3Failure )
- return kQ3Failure ;
- return Q3Set_Add ( attributeSet , kUpVectorAttribute , &upVector ) ;
- }
- return kQ3Failure ;
- }
-
-
- TQ3FunctionPointer UpVectorAttributeMetaHandler ( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse :
- return (TQ3FunctionPointer) VectorTraverse ;
- case kQ3MethodTypeObjectWrite :
- return (TQ3FunctionPointer) VectorWrite ;
- case kQ3MethodTypeObjectReadData :
- return (TQ3FunctionPointer) UpVectorAttributeReadData ;
- default :
- return (TQ3FunctionPointer) nil ;
- }
- }
-
-
- TQ3ObjectClass RegisterUpVectorAttribute ( void )
- {
- return RegisterCustomAttribute ( kUpVectorAttribute , sizeof ( TQ3Vector3D ) , UpVectorAttributeMetaHandler ) ;
- }
-
-
- TQ3Status ForwardDirectionAttributeReadData ( TQ3SetObject attributeSet , TQ3FileObject file )
- {
- if ( attributeSet && file )
- {
- TQ3Vector3D forwardDirection ;
- if ( Q3Vector3D_Read ( &forwardDirection , file ) == kQ3Failure )
- return kQ3Failure ;
- return Q3Set_Add ( attributeSet , kForwardDirectionAttribute , &forwardDirection ) ;
- }
- return kQ3Failure ;
- }
-
-
- TQ3FunctionPointer ForwardDirectionAttributeMetaHandler ( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse :
- return (TQ3FunctionPointer) VectorTraverse ;
- case kQ3MethodTypeObjectWrite :
- return (TQ3FunctionPointer) VectorWrite ;
- case kQ3MethodTypeObjectReadData :
- return (TQ3FunctionPointer) ForwardDirectionAttributeReadData ;
- default :
- return (TQ3FunctionPointer) nil;
- }
- }
-
- TQ3ObjectClass RegisterForwardDirectionAttribute ( void )
- {
- return RegisterCustomAttribute ( kForwardDirectionAttribute , sizeof ( TQ3Vector3D ) , ForwardDirectionAttributeMetaHandler ) ;
- }
-
-
- //------------------------------------------------------------------------------------------------
- // World Wide Web Custom Attributes
- //------------------------------------------------------------------------------------------------
-
-
- TQ3Status W3AnchorTraverse ( TQ3Object , W3AnchorData* URLdata , TQ3ViewObject view )
- {
- if ( URLdata )
- {
- if ( URLdata->url == nil )
- return kQ3Success ;
-
- TQ3Size size = Q3Size_Pad ( strlen ( URLdata->url ) + 1 ) ;
- size += sizeof ( TQ3Uns32 ) ;
-
- if ( Q3View_SubmitWriteData ( view , size , URLdata , nil ) == kQ3Failure )
- return kQ3Failure ;
-
- if ( URLdata->description )
- {
- if ( Q3Object_Submit ( URLdata->description , view ) == kQ3Failure )
- return kQ3Failure ;
- }
- }
- return kQ3Success ;
- }
-
-
- TQ3Status W3AnchorWrite ( const W3AnchorData* URLdata , TQ3FileObject file )
- {
- if ( URLdata && file )
- return ( Q3String_Write ( URLdata->url , file ) == kQ3Success ) &&
- ( Q3Uns32_Write ( (unsigned long) URLdata->options , file ) == kQ3Success ) ? kQ3Success : kQ3Failure ;
- return kQ3Success ;
- }
-
-
- TQ3Status W3AnchorReadData ( TQ3SetObject set , TQ3FileObject file )
- {
- if ( set && file )
- {
- char buf [ kQ3StringMaximumLength ] ;
- W3AnchorData URLData = { nil , nil , kW3AnchorOptionNone } ;
-
- if ( Q3String_Read ( buf , nil , file ) == kQ3Failure )
- return kQ3Failure ;
-
- URLData.url = NewPtr ( strlen ( buf ) + 1 ) ;
- strcpy ( URLData.url , buf ) ;
-
- if ( Q3Uns32_Read ( (unsigned long *) &URLData.options , file ) == kQ3Failure )
- return kQ3Failure ;
-
- if ( Q3File_IsEndOfContainer ( file , NULL ) == kQ3False )
- URLData.description = Q3File_ReadObject ( file ) ;
-
- return Q3Set_Add ( set , kW3AnchorAttribute , &URLData ) ;
- }
- return kQ3Failure ;
- }
-
-
- TQ3Status W3AnchorCopyAdd ( const W3AnchorData* src , W3AnchorData* dst )
- {
- if ( src && dst )
- {
- if ( src->url == nil )
- return kQ3Failure ;
-
- long i = strlen ( src->url ) ;
- if ( i == 0 )
- return kQ3Failure ;
-
- dst->url = NewPtr ( i + 1 ) ;
- if ( dst->url == nil )
- return kQ3Failure ;
-
- strcpy ( dst->url , src->url ) ;
- if ( src->description )
- dst->description = Q3Object_Duplicate ( src->description ) ;
- else
- dst->description = nil ;
- dst->options = src->options ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status W3AnchorCopyReplace ( const W3AnchorData* src , W3AnchorData* dst )
- {
- if ( src && dst )
- {
- if ( src->url == nil )
- return kQ3Failure ;
-
- long i = strlen ( src->url ) ;
- if ( i == 0 )
- return kQ3Failure ;
- char* c = NewPtr ( i + 1 ) ;
- if ( c == nil )
- return kQ3Failure ;
- dst->url = c ;
- strcpy ( dst->url , src->url ) ;
-
- TQ3Object temp = dst->description ;
- if ( src->description )
- dst->description = Q3Object_Duplicate (src->description);
- else
- dst->description = nil ;
- if ( temp )
- Q3Object_Dispose ( temp ) ;
- dst->options = src->options ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status W3AnchorDelete ( W3AnchorData* URLData )
- {
- if ( URLData )
- {
- if ( URLData->url )
- DisposePtr ( URLData->url ) ;
- if ( URLData->description )
- Q3Object_Dispose ( URLData->description ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3FunctionPointer W3AnchorMetaHandler ( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse :
- return (TQ3FunctionPointer) W3AnchorTraverse ;
- case kQ3MethodTypeObjectWrite :
- return (TQ3FunctionPointer) W3AnchorWrite ;
- case kQ3MethodTypeObjectReadData :
- return (TQ3FunctionPointer) W3AnchorReadData ;
- case kQ3MethodTypeElementCopyAdd :
- case kQ3MethodTypeElementCopyGet :
- case kQ3MethodTypeElementCopyDuplicate :
- return (TQ3FunctionPointer) W3AnchorCopyAdd ;
- case kQ3MethodTypeElementCopyReplace :
- return (TQ3FunctionPointer) W3AnchorCopyReplace ;
- case kQ3MethodTypeElementDelete :
- return (TQ3FunctionPointer) W3AnchorDelete ;
- default :
- return (TQ3FunctionPointer) nil ;
- }
- }
-
-
- TQ3ObjectClass RegisterW3Anchor ( void )
- {
- return RegisterCustomAttribute ( kW3AnchorAttribute , sizeof ( W3AnchorData ) , W3AnchorMetaHandler ) ;
- }
-
-
- //------------------------------------------------------------------------------------------------
-
-
- TQ3Status W3InlineTraverse ( TQ3Object , W3InlineData* inlineData , TQ3ViewObject view )
- {
- if ( inlineData && view )
- {
- if ( inlineData->url == nil )
- return kQ3Success ;
- TQ3Size size = Q3Size_Pad ( strlen ( inlineData->url ) + 1 ) ;
- return Q3View_SubmitWriteData ( view , size , inlineData , nil ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status W3InlineWrite ( const W3InlineData* inlineData , TQ3FileObject file )
- {
- if ( inlineData && file )
- return Q3String_Write ( inlineData->url , file ) == kQ3Success &&
- Q3Comment_Write ( "url" , file ) == kQ3Success ? kQ3Success : kQ3Failure ;
- return kQ3Success ;
- }
-
-
- TQ3Status W3InlineReadData ( TQ3SetObject set , TQ3FileObject file )
- {
- if ( set && file )
- {
- char buf [ kQ3StringMaximumLength ] ;
- W3InlineData inlineData ;
- if ( Q3String_Read ( buf , nil , file ) == kQ3Failure )
- return kQ3Failure ;
- inlineData.url = buf ;
- return Q3Set_Add ( set , kW3InlineAttribute , &inlineData ) ;
- }
- return kQ3Failure ;
- }
-
-
- TQ3Status W3InlineCopyAdd ( const W3InlineData* src , W3InlineData* dst )
- {
- if ( src && dst )
- {
- if ( src->url == nil )
- return kQ3Failure ;
- long i = strlen ( src->url ) ;
- if ( i == 0 )
- return kQ3Failure ;
- dst->url = NewPtr ( i + 1 ) ;
- if ( dst->url == nil )
- return kQ3Failure ;
- strcpy ( dst->url , src->url ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status W3InlineCopyReplace ( const W3InlineData* src , W3InlineData* dst )
- {
- if ( src && dst )
- {
- if ( src->url == nil )
- return kQ3Failure ;
- long i = strlen ( src->url ) ;
- if ( i == 0 )
- return kQ3Failure ;
- char* c = NewPtr ( i + 1 ) ;
- if ( c == nil )
- return kQ3Failure ;
- dst->url = c ;
- strcpy ( dst->url , src->url ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status W3InlineDelete ( W3InlineData* src )
- {
- if ( src && src->url )
- DisposePtr ( src->url ) ;
- return kQ3Success ;
- }
-
-
- TQ3FunctionPointer W3InlineMetaHandler ( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse :
- return (TQ3FunctionPointer) W3InlineTraverse ;
- case kQ3MethodTypeObjectWrite :
- return (TQ3FunctionPointer) W3InlineWrite ;
- case kQ3MethodTypeObjectReadData :
- return (TQ3FunctionPointer) W3InlineReadData ;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate :
- return (TQ3FunctionPointer) W3InlineCopyAdd ;
- case kQ3MethodTypeElementCopyReplace :
- return (TQ3FunctionPointer) W3InlineCopyReplace ;
- case kQ3MethodTypeElementDelete :
- return (TQ3FunctionPointer) W3InlineDelete ;
- default :
- return (TQ3FunctionPointer) nil ;
- }
- }
-
-
- TQ3ObjectClass RegisterW3Inline ( void )
- {
- return RegisterCustomAttribute ( kW3InlineAttribute , sizeof ( W3InlineData ) , W3InlineMetaHandler ) ;
- }
-
-
- /***********************************************************************************************
- *
- * This one is obsolete. The code below will convert to the new type on reading and writing
- *
- ***********************************************************************************************/
-
- TQ3Status WWWAnchorTraverse ( TQ3Object , WWWAnchorData* wwwdata , TQ3ViewObject view )
- {
- if ( wwwdata && wwwdata->url )
- {
- TQ3Size size = Q3Size_Pad ( strlen ( wwwdata->url ) + 1 ) ;
- return Q3View_SubmitWriteData ( view , size , wwwdata , nil ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status WWWAnchorWrite ( const WWWAnchorData *wwwdata , TQ3FileObject file )
- {
- if ( wwwdata && file )
- return Q3String_Write ( wwwdata->url , file ) == kQ3Success &&
- Q3Comment_Write ( "url" , file ) == kQ3Success ? kQ3Success : kQ3Failure ;
- return kQ3Failure ;
- }
-
-
- TQ3Status WWWAnchorReadData ( TQ3SetObject set , TQ3FileObject file )
- {
- if ( set && file )
- {
- char buf [ kQ3StringMaximumLength] ;
- WWWAnchorData wwwdata ;
- W3AnchorData W3Anchor ;
-
- if ( Q3String_Read ( buf, nil , file ) == kQ3Failure )
- return kQ3Failure ;
-
- wwwdata.url = NewPtr ( strlen ( buf ) + 1 ) ;
- strcpy ( wwwdata.url, buf ) ;
-
- W3Anchor.url = NewPtr ( strlen ( buf ) + 1 ) ;
- strcpy ( W3Anchor.url , buf ) ;
-
- W3Anchor.description = nil ;
- W3Anchor.options = kW3AnchorOptionNone ;
-
- Q3Set_Add ( set , kW3AnchorAttribute , &W3Anchor ) ;
-
- return Q3Set_Add ( set , kElementTypeWWWAnchor , &wwwdata ) ;
- }
- return kQ3Failure ;
- }
-
-
- TQ3Status WWWAnchorCopyAdd ( const WWWAnchorData* src , WWWAnchorData* dst )
- {
- if ( src && dst && src->url )
- {
- long i = strlen ( src->url ) ;
- if ( i == 0 )
- return kQ3Failure ;
- dst->url = NewPtr ( i + 1 ) ;
- if ( dst->url == nil )
- return kQ3Failure ;
- strcpy ( dst->url , src->url ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status WWWAnchorCopyReplace ( const WWWAnchorData* src , WWWAnchorData* dst )
- {
- if ( src && dst && src->url )
- {
- long i = strlen ( src->url ) ;
- if ( i == 0 )
- return kQ3Failure ;
- char* c = NewPtr ( i + 1 ) ;
- if ( c == nil )
- return kQ3Failure ;
- dst->url = c ;
- strcpy ( dst->url , src->url ) ;
- }
- return kQ3Success ;
- }
-
-
- TQ3Status WWWAnchorDelete ( WWWAnchorData* src )
- {
- if ( src && src->url )
- DisposePtr ( src->url ) ;
- return kQ3Success ;
- }
-
-
- TQ3FunctionPointer WWWAnchorMetaHandler( TQ3MethodType methodType )
- {
- switch ( methodType )
- {
- case kQ3MethodTypeObjectTraverse :
- return (TQ3FunctionPointer) WWWAnchorTraverse ;
- case kQ3MethodTypeObjectWrite :
- return (TQ3FunctionPointer) WWWAnchorWrite ;
- case kQ3MethodTypeObjectReadData :
- return (TQ3FunctionPointer) WWWAnchorReadData ;
- case kQ3MethodTypeElementCopyAdd :
- case kQ3MethodTypeElementCopyGet :
- case kQ3MethodTypeElementCopyDuplicate :
- return (TQ3FunctionPointer) WWWAnchorCopyAdd ;
- case kQ3MethodTypeElementCopyReplace :
- return (TQ3FunctionPointer) WWWAnchorCopyReplace ;
- case kQ3MethodTypeElementDelete :
- return (TQ3FunctionPointer) WWWAnchorDelete ;
- default :
- return (TQ3FunctionPointer) nil ;
- }
- }
-
-
- TQ3ObjectClass RegisterWWWAnchor ( void )
- {
- return RegisterCustomAttribute ( kElementTypeWWWAnchor , sizeof ( WWWAnchorData ) , WWWAnchorMetaHandler ) ;
- }
-
-
- //------------------------------------------------------------------------------------------------
-