home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / ITEXT.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  8KB  |  207 lines

  1. /*====START_GENERATED_PROLOG======================================
  2.  */
  3. /*
  4.  *   COMPONENT_NAME: odmri
  5.  *
  6.  *   CLASSES:   ITextTest
  7.  *
  8.  *   ORIGINS: 82,27
  9.  *
  10.  *
  11.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12.  *   All Rights Reserved
  13.  *   Licensed Materials - Property of IBM
  14.  *   US Government Users Restricted Rights - Use, duplication or
  15.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16.  *
  17.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23.  *   OR PERFORMANCE OF THIS SOFTWARE.
  24.  */
  25. /*====END_GENERATED_PROLOG========================================
  26.  */
  27. // @(#) 1.18 com/src/pubutils/include/IText.h, odmri, od96os2, odos29646d 9/18/96 15:15:35 [ 11/15/96 15:29:12 ]
  28. /*
  29.    File:           IText.h
  30.  
  31.    Contains:       Routines for manipulating ITexts.
  32.  
  33.    Owned by:       Vincent Lo
  34.  
  35.    Copyright:      ⌐ 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37. */
  38.  
  39. #ifndef _ITEXT_
  40. #define _ITEXT_
  41.  
  42. #ifndef _ODTYPES_
  43. #include "ODTypes.h"
  44. #endif
  45.  
  46. #ifndef _ODMVCLNK_
  47. #include <ODMvcLnk.h>
  48. #endif
  49.  
  50. typedef short ODScriptCode;
  51. typedef short ODLangCode;
  52.  
  53. #ifdef _PLATFORM_AIX_
  54. // Used in ODGetCodePageIdentifier() to represent codepages
  55. typedef enum {
  56.   kUnknown,    /* Unknown codepage */
  57.   kIBM_1046,   /* IBM-1046     */
  58.   kISO8859_6,  /* ISO8859-6    */
  59.   kISO8859_1,  /* ISO8859-1    */
  60.   kISO8859_5,  /* ISO8859-5    */
  61.   kIBM_850,    /* IBM-850      */
  62.   kIBM_eucTW,  /* IBM-eucTW    */
  63.   kISO8859_2,  /* ISO8859-2    */
  64.   kIBM_932,    /* IBM-932      */
  65.   kIBM_eucJP,  /* IBM-eucJP    */
  66.   kIBM_eucKR,  /* IBM-eucKR    */ 
  67.   kISO8859_7,  /* ISO8859-7    */
  68.   kIBM_856,    /* IBM-856      */ 
  69.   kISO8859_8,  /* ISO8859-8   */
  70.   kIBM_eucCN,  /* IBM-eucCN    */
  71.   kISO8859_9,  /* ISO8859-9    */
  72.   kUnicode,    /* Unicode      */
  73.   kUTF_8       /* UTF-8        */
  74. } ODCodePages;
  75. #endif // _PLATFORM_AIX_
  76.  
  77.  
  78. // ODTradIText: This is the format of the data stored in an IText whose
  79. // format is kODTradMacintosh.
  80.  
  81. struct ODTradITextDataHeader {
  82.    ODScriptCode theScriptCode;
  83.    ODLangCode       theLangCode;
  84. };
  85. typedef struct ODTradITextDataHeader ODTradITextDataHeader;
  86.  
  87. struct ODTradITextData {
  88.    ODScriptCode theScriptCode;
  89.    ODLangCode       theLangCode;
  90.    char             theText[1];            // Variable length array!
  91. };
  92. typedef struct ODTradITextData ODTradITextData;
  93.  
  94. #define kSizeOfODTradITextData  4
  95.  
  96.  
  97. #ifdef _OD_IMPL_SHARE_UTILS_
  98. #pragma import on
  99. #endif
  100.  
  101. #ifdef __cplusplus
  102. extern "C" {
  103. #endif
  104.  
  105.  
  106. _DLLIMPORTEXPORT_ ODIText*        CreateITextFromCharPtr(char* text);
  107. _DLLIMPORTEXPORT_ ODIText*        CreateITextCString(ODScriptCode, ODLangCode, char* text);
  108. _DLLIMPORTEXPORT_ ODIText*        CreateITextPString(ODScriptCode, ODLangCode, StringPtr text);
  109. _DLLIMPORTEXPORT_ ODIText*        CreateITextClear(  ODScriptCode, ODLangCode, ODSize stringLength );
  110. _DLLIMPORTEXPORT_ ODIText*        CreateITextWLen(ODScriptCode, ODLangCode, ODUByte* text,
  111.                   ODSize textLength );
  112.    // For text that is neither a C string or a Pascal string.
  113.  
  114. _DLLIMPORTEXPORT_ ODIText*        SetITextBufferSize( ODIText*, ODSize bufferSize, ODBoolean preserveContents );
  115.    // Low level operation to set byte-array buffer size directly.
  116.    // If input is NULL, will create & return a new ODIText.
  117.  
  118. _DLLIMPORTEXPORT_ ODIText*        CopyIText(ODIText* original);
  119.    // Allocates and returns an exact copy of the IText passed in.
  120. _DLLIMPORTEXPORT_ ODIText         CopyITextStruct(ODIText* original);
  121.  
  122. _DLLIMPORTEXPORT_ void            SetITextScriptCode(ODIText*, ODScriptCode);
  123. _DLLIMPORTEXPORT_ ODScriptCode GetITextScriptCode(ODIText*);
  124.  
  125. _DLLIMPORTEXPORT_ void            SetITextLangCode(ODIText*, ODLangCode);
  126. _DLLIMPORTEXPORT_ ODLangCode      GetITextLangCode(ODIText*);
  127.  
  128. _DLLIMPORTEXPORT_ ODIText*        SetITextStringLength( ODIText*, ODSize length, ODBoolean preserveText );
  129.    // If NULL is passed in, allocates & returns a new ODIText.
  130.  
  131. _DLLIMPORTEXPORT_ ODULong         GetITextStringLength(ODIText*);
  132. _DLLIMPORTEXPORT_ char*           GetITextPtr( ODIText* );
  133.    // Returns ptr to raw text without allocating any memory.
  134.  
  135. _DLLIMPORTEXPORT_ void            SetITextCString(ODIText*, char* text);
  136. _DLLIMPORTEXPORT_ void            SetITextPString(ODIText*, StringPtr text);
  137. _DLLIMPORTEXPORT_ void            SetITextText(ODIText*, ODUByte* text, ODSize textLength);
  138.  
  139. _DLLIMPORTEXPORT_ char*           GetITextCString(ODIText*, char *cstring);
  140. _DLLIMPORTEXPORT_ StringPtr       GetITextPString(ODIText*, Str255 pstring);
  141.    // If a string is passed in, it copies the text there and returns a ptr to it.
  142.    // If a NULL string is passed, it allocates a new string and returns it.
  143.  
  144.  
  145. _DLLIMPORTEXPORT_ void            DisposeIText(ODIText* iText);
  146. _DLLIMPORTEXPORT_ void            DisposeITextStruct(ODIText iText);
  147.  
  148. /*
  149.    DisposeITextStruct is a macro instead of a function so it can take a
  150.    different parameter type than DisposeIText(), and still set the disposed
  151.    pointer field of the structure to null.
  152.    DisposeIText() must never be called on a IText structure;
  153.    DisposeIText() disposes the structure which is usually a disaster.
  154.  
  155.    See BArray.h for another example of this.
  156. */
  157.  
  158. #define DisposeITextStruct(iText)               \
  159.    do{                                                                                     \
  160.       if ((iText).text._buffer != kODNULL) {          \
  161.          ODDisposePtr((iText).text._buffer);     \
  162.          (iText).text._buffer = kODNULL;         \
  163.       }                                                                               \
  164.       (iText).text._length = 0;                                       \
  165.       (iText).text._maximum = 0;                                      \
  166.    }while(0)
  167.  
  168. #ifdef __cplusplus
  169.    } // closes extern "C" block
  170.  
  171.    // Overloaded variants for convenience:
  172.    inline ODIText* CreateIText(ODScriptCode s, ODLangCode l, char* text)
  173.                   {return CreateITextCString(s,l,text);}
  174.    inline ODIText* CreateIText(ODScriptCode s, ODLangCode l, StringPtr text)
  175.                   {return CreateITextPString(s,l,text);}
  176.  
  177.    inline ODIText* CreateIText(ODScriptCode s, ODLangCode l, ODSize stringLength )
  178.                   {return CreateITextClear(s,l,stringLength);}
  179.    inline ODIText* CreateIText(ODSize textLength)
  180.                   {return SetITextStringLength(kODNULL,textLength,kODFalse);}
  181.    inline ODIText* CreateIText(ODScriptCode scriptCode, ODLangCode langCode,
  182.                   ODUByte* text, ODSize textLength)
  183.                   {return CreateITextWLen(scriptCode, langCode, text, textLength );}
  184.  
  185.    inline void             SetITextString(ODIText* i, char* text)
  186.                   {SetITextCString(i,text);}
  187.    inline void             SetITextString(ODIText* i, StringPtr text)
  188.                   {SetITextPString(i,text);}
  189.  
  190.    inline char*    GetITextString(ODIText* i, char* text)
  191.                   {return GetITextCString(i,text);}
  192.    inline StringPtr GetITextString(ODIText* i, StringPtr text)
  193.                   {return GetITextPString(i,text);}
  194.  
  195.    inline char*    GetCStringFromIText(ODIText* iText)
  196.                   {return GetITextCString(iText,(char*)kODNULL);}
  197.    inline StringPtr GetPStringFromIText(ODIText* iText)
  198.                   {return GetITextPString(iText,(StringPtr)kODNULL);}
  199. #endif /*__cplusplus*/
  200.  
  201.  
  202. #ifdef _OD_IMPL_SHARE_UTILS_
  203. #pragma import off
  204. #endif
  205.  
  206. #endif  /*_ITEXT_*/
  207.