home *** CD-ROM | disk | FTP | other *** search
- /*
- File: IText.h
-
- Contains: Routines for manipulating ITexts.
-
- Owned by: Vincent Lo
-
- Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 6/6/96 jpa T10020: Added InitIText to initialize local
- ODIText vars.
- <3> 5/24/96 jpa 1.1MRD: pragma internal
- <2> 5/1/96 JA Force 68k alignment of TradITextData.
- [1213332]
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _ITEXT_
- #define _ITEXT_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
-
- typedef short ODScriptCode;
- typedef short ODLangCode;
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- // ODTradIText: This is the format of the data stored in an IText whose
- // format is kODTradMacintosh.
-
- struct ODTradITextDataHeader {
- ODScriptCode theScriptCode;
- ODLangCode theLangCode;
- };
- typedef struct ODTradITextDataHeader ODTradITextDataHeader;
-
- struct ODTradITextData {
- ODScriptCode theScriptCode;
- ODLangCode theLangCode;
- char theText[1]; // Variable length array!
- };
- typedef struct ODTradITextData ODTradITextData;
-
- #define kSizeOfODTradITextData 4
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #ifdef _OD_IMPL_SHARE_UTILS_
- #pragma import on
- #elif defined(PRAGMA_INTERNAL_SUPPORTED)
- #pragma internal on
- #endif
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- ODIText* CreateITextCString(ODScriptCode, ODLangCode, char* text);
- ODIText* CreateITextPString(ODScriptCode, ODLangCode, StringPtr text);
- ODIText* CreateITextClear( ODScriptCode, ODLangCode, ODSize stringLength );
- ODIText* CreateITextWLen(ODScriptCode, ODLangCode, ODUByte* text,
- ODSize textLength );
- // For text that is neither a C string or a Pascal string.
-
- ODIText* InitIText( ODIText* );
- // Used to setup ODIText structs not allocated from heap.
- // Buffer will be set to NULL! Use SetBufferSize, SetStringLength, etc.
-
- ODIText* SetITextBufferSize( ODIText*, ODSize bufferSize, ODBoolean preserveContents );
- // Low level operation to set byte-array buffer size directly.
- // If input is NULL, will create & return a new ODIText.
-
- ODIText* CopyIText(ODIText* original);
- // Allocates and returns an exact copy of the IText passed in.
- ODIText CopyITextStruct(ODIText* original);
-
- void SetITextScriptCode(ODIText*, ODScriptCode);
- ODScriptCode GetITextScriptCode(ODIText*);
-
- void SetITextLangCode(ODIText*, ODLangCode);
- ODLangCode GetITextLangCode(ODIText*);
-
- ODIText* SetITextStringLength( ODIText*, ODSize length, ODBoolean preserveText );
- // If NULL is passed in, allocates & returns a new ODIText.
-
- ODULong GetITextStringLength(ODIText*);
- char* GetITextPtr( ODIText* );
- // Returns ptr to raw text without allocating any memory.
-
- void SetITextCString(ODIText*, char* text);
- void SetITextPString(ODIText*, StringPtr text);
- void SetITextText(ODIText*, ODUByte* text, ODSize textLength);
-
- char* GetITextCString(ODIText*, char *cstring);
- StringPtr GetITextPString(ODIText*, Str255 pstring);
- // If a string is passed in, it copies the text there and returns a ptr to it.
- // If a NULL string is passed, it allocates a new string and returns it.
-
-
- void DisposeIText(ODIText* iText);
- void DisposeITextStruct(ODIText iText);
-
- /*
- DisposeITextStruct is a macro instead of a function so it can take a
- different parameter type than DisposeIText(), and still set the disposed
- pointer field of the structure to null.
- DisposeIText() must never be called on a IText structure;
- DisposeIText() disposes the structure which is usually a disaster.
-
- See BArray.h for another example of this.
- */
-
- #define DisposeITextStruct(iText) \
- do{ \
- if ((iText).text._buffer != kODNULL) { \
- ODDisposePtr((iText).text._buffer); \
- (iText).text._buffer = kODNULL; \
- } \
- (iText).text._length = 0; \
- (iText).text._maximum = 0; \
- }while(0)
-
- #ifdef __cplusplus
- } // closes extern "C" block
-
- // Overloaded variants for convenience:
- inline ODIText* CreateIText(ODScriptCode s, ODLangCode l, char* text)
- {return CreateITextCString(s,l,text);}
- inline ODIText* CreateIText(ODScriptCode s, ODLangCode l, StringPtr text)
- {return CreateITextPString(s,l,text);}
- inline ODIText* CreateIText(ODScriptCode s, ODLangCode l, ODSize stringLength )
- {return CreateITextClear(s,l,stringLength);}
- inline ODIText* CreateIText(ODSize textLength)
- {return SetITextStringLength(kODNULL,textLength,kODFalse);}
- inline ODIText* CreateIText(ODScriptCode scriptCode, ODLangCode langCode,
- ODUByte* text, ODSize textLength)
- {return CreateITextWLen(scriptCode, langCode, text, textLength );}
-
- inline void SetITextString(ODIText* i, char* text)
- {SetITextCString(i,text);}
- inline void SetITextString(ODIText* i, StringPtr text)
- {SetITextPString(i,text);}
- inline char* GetITextString(ODIText* i, char* text)
- {return GetITextCString(i,text);}
- inline StringPtr GetITextString(ODIText* i, StringPtr text)
- {return GetITextPString(i,text);}
- inline char* GetCStringFromIText(ODIText* iText)
- {return GetITextCString(iText,(char*)kODNULL);}
- inline StringPtr GetPStringFromIText(ODIText* iText)
- {return GetITextPString(iText,(StringPtr)kODNULL);}
- #endif /*__cplusplus*/
-
- #ifdef _OD_IMPL_SHARE_UTILS_
- #pragma import off
- #elif defined(PRAGMA_INTERNAL_SUPPORTED)
- #pragma internal reset
- #endif
-
- #endif /*_ITEXT_*/
-