home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / IText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  4.5 KB  |  148 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        IText.h
  3.  
  4.     Contains:    Routines for manipulating ITexts.
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #ifndef _ITEXT_
  13. #define _ITEXT_
  14.  
  15. #ifndef _ODTYPES_
  16. #include "ODTypes.h"
  17. #endif
  18.  
  19.  
  20. typedef short ODScriptCode; 
  21. typedef short ODLangCode;
  22.  
  23.  
  24. // ODTradIText: This is the format of the data stored in an IText whose
  25. // format is kODTradMacintosh.
  26.  
  27. struct ODTradITextDataHeader {
  28.     ODScriptCode theScriptCode;
  29.     ODLangCode     theLangCode;
  30. };
  31. typedef struct ODTradITextDataHeader ODTradITextDataHeader;
  32.  
  33. struct ODTradITextData {
  34.     ODScriptCode theScriptCode;
  35.     ODLangCode     theLangCode;
  36.     char         theText[1];        // Variable length array!
  37. };
  38. typedef struct ODTradITextData ODTradITextData;
  39.  
  40. #define kSizeOfODTradITextData    4
  41.  
  42.  
  43. #ifdef _OD_IMPL_SHARE_UTILS_
  44. #pragma import on
  45. #endif
  46.  
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50.  
  51.  
  52. ODIText*    CreateITextCString(ODScriptCode, ODLangCode, char* text);
  53. ODIText*    CreateITextPString(ODScriptCode, ODLangCode, StringPtr text);
  54. ODIText*    CreateITextClear(  ODScriptCode, ODLangCode, ODSize stringLength );
  55. ODIText*    CreateITextWLen(ODScriptCode, ODLangCode, ODUByte* text,
  56.                         ODSize textLength );
  57.     // For text that is neither a C string or a Pascal string.
  58.  
  59. ODIText*    SetITextBufferSize( ODIText*, ODSize bufferSize, ODBoolean preserveContents );
  60.     // Low level operation to set byte-array buffer size directly.
  61.     // If input is NULL, will create & return a new ODIText.
  62.     
  63. ODIText*    CopyIText(ODIText* original);
  64.     // Allocates and returns an exact copy of the IText passed in.
  65. ODIText        CopyITextStruct(ODIText* original);
  66.  
  67. void        SetITextScriptCode(ODIText*, ODScriptCode);
  68. ODScriptCode GetITextScriptCode(ODIText*);
  69.  
  70. void        SetITextLangCode(ODIText*, ODLangCode);
  71. ODLangCode    GetITextLangCode(ODIText*);
  72.  
  73. ODIText*    SetITextStringLength( ODIText*, ODSize length, ODBoolean preserveText );
  74.     // If NULL is passed in, allocates & returns a new ODIText.
  75.  
  76. ODULong        GetITextStringLength(ODIText*);
  77. char*        GetITextPtr( ODIText* );
  78.     // Returns ptr to raw text without allocating any memory.
  79.  
  80. void        SetITextCString(ODIText*, char* text);
  81. void        SetITextPString(ODIText*, StringPtr text);
  82. void        SetITextText(ODIText*, ODUByte* text, ODSize textLength);
  83.  
  84. char*        GetITextCString(ODIText*, char *cstring);
  85. StringPtr    GetITextPString(ODIText*, Str255 pstring);
  86.     // If a string is passed in, it copies the text there and returns a ptr to it.
  87.     // If a NULL string is passed, it allocates a new string and returns it.
  88.  
  89.  
  90. void        DisposeIText(ODIText* iText);
  91. void        DisposeITextStruct(ODIText iText);
  92.  
  93. /* 
  94.     DisposeITextStruct is a macro instead of a function so it can take a
  95.     different parameter type than DisposeIText(), and still set the disposed
  96.     pointer field of the structure to null.
  97.     DisposeIText() must never be called on a IText structure;
  98.     DisposeIText() disposes the structure which is usually a disaster.
  99.  
  100.     See BArray.h for another example of this.
  101. */
  102.  
  103. #define    DisposeITextStruct(iText)        \
  104.     do{                                            \
  105.         if ((iText).text._buffer != kODNULL) {        \
  106.             ODDisposePtr((iText).text._buffer);    \
  107.             (iText).text._buffer = kODNULL;        \
  108.         }                                        \
  109.         (iText).text._length = 0;                    \
  110.         (iText).text._maximum = 0;                    \
  111.     }while(0)
  112.  
  113. #ifdef __cplusplus
  114.     } // closes extern "C" block
  115.     
  116.     // Overloaded variants for convenience:
  117.     inline ODIText*    CreateIText(ODScriptCode s, ODLangCode l, char* text)
  118.                         {return CreateITextCString(s,l,text);}
  119.     inline ODIText*    CreateIText(ODScriptCode s, ODLangCode l, StringPtr text)
  120.                         {return CreateITextPString(s,l,text);}
  121.     inline ODIText*    CreateIText(ODScriptCode s, ODLangCode l, ODSize stringLength )
  122.                         {return CreateITextClear(s,l,stringLength);}
  123.     inline ODIText*    CreateIText(ODSize textLength)
  124.                         {return SetITextStringLength(kODNULL,textLength,kODFalse);}
  125.     inline ODIText*    CreateIText(ODScriptCode scriptCode, ODLangCode langCode,
  126.                         ODUByte* text, ODSize textLength)
  127.                         {return CreateITextWLen(scriptCode, langCode, text, textLength );}
  128.  
  129.     inline void        SetITextString(ODIText* i, char* text)
  130.                         {SetITextCString(i,text);}
  131.     inline void        SetITextString(ODIText* i, StringPtr text)
  132.                         {SetITextPString(i,text);}
  133.     inline char*    GetITextString(ODIText* i, char* text)
  134.                         {return GetITextCString(i,text);}
  135.     inline StringPtr GetITextString(ODIText* i, StringPtr text)
  136.                         {return GetITextPString(i,text);}
  137.     inline char*    GetCStringFromIText(ODIText* iText)
  138.                         {return GetITextCString(iText,(char*)kODNULL);}
  139.     inline StringPtr GetPStringFromIText(ODIText* iText)
  140.                         {return GetITextPString(iText,(StringPtr)kODNULL);}
  141. #endif /*__cplusplus*/
  142.  
  143. #ifdef _OD_IMPL_SHARE_UTILS_
  144. #pragma import off
  145. #endif
  146.  
  147. #endif    /*_ITEXT_*/
  148.