home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / rtflib.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  9KB  |  287 lines

  1. /*
  2.  *    R T F L I B . H
  3.  *
  4.  *    Definitions for RTF library.
  5.  *
  6.  *  Copyright 1986-1996 Microsoft Corporation. All Rights Reserved.
  7.  */
  8.  
  9. #ifndef RTFLIB_H
  10. #define RTFLIB_H
  11.  
  12. #if defined (WIN32) && !defined (_WIN32)
  13. #define _WIN32
  14. #endif
  15.  
  16. #if defined (_WIN32)
  17. #ifndef _OBJBASE_H_
  18. #include <objbase.h>
  19. #endif
  20. #endif
  21.  
  22. #if defined (WIN16) || defined (DOS) || defined (DOS16)
  23. #ifndef _COMPOBJ_H_
  24. #include <compobj.h>
  25. #endif
  26. #endif
  27.  
  28.  
  29. /*
  30.  * RTFLIB only looks at the first cchBodyTagMax characters of the body tag.
  31.  */
  32. #define cchBodyTagMax    100
  33.  
  34. typedef struct _RTFSYNCINFO
  35. {
  36.     LONG lBodyCRC;
  37.     LONG lBodyCount;
  38.     LONG lPrefixCount;
  39.     LONG lTrailingCount;
  40.     char szBodyTag[cchBodyTagMax + 2];
  41. } RTFSYNCINFO;
  42.  
  43. // header for compressed stream
  44. typedef struct _lzfuhdr
  45. {
  46.     ULONG cbSize;        // total number of bytes following this field
  47.     ULONG cbRawSize;    // size before compression
  48.     DWORD dwMagic;        // identifies this as a compressed stream
  49.     DWORD dwCRC;        // CRC-32 of the compressed data for error checking
  50. } LZFUHDR;
  51.  
  52. // magic number that identifies the stream as a compressed stream
  53. #define dwMagicCompressedRTF 0x75465a4c
  54.  
  55. // magic number that identifies the stream as a uncompressed stream
  56. #define dwMagicUncompressedRTF 0x414c454d
  57.  
  58. // array used for CRC calculations
  59. extern const DWORD rgdwCRC[];
  60.  
  61. /* IMPORTED FUNCTIONS */
  62.  
  63. /* 
  64.  * LogInvalidCpid
  65.  *
  66.  * Imported callback function for logging code page conversion
  67.  * errors. A stub function is provided if a function is
  68.  * not provided by the project linking with RTFLIB
  69.  *
  70.  * The cpid parameter is the unsupported code page ID.
  71.  *
  72.  */
  73.  
  74. STDAPI_(void) LogInvalidCpid( ULONG cpid );
  75.  
  76.  
  77. /* MAIN RTF ROUTINES */
  78.  
  79. /*
  80.  * HrTextFromCompressedRTFStream
  81.  *
  82.  * Takes compressed RTF stream (pstmRTF) and returns a wrapper
  83.  * stream (*ppstmText) giving access to the plain text. The text
  84.  * stream supports Read and CopyTo methods.
  85.  * 
  86.  * The pointer psi must be valid until *ppstmText is released.
  87.  * It is updated as *ppstmText is read and is not accurate until
  88.  * all of the text has been read.
  89.  *
  90.  * cpid is the code page for the text stream. It can be any code page
  91.  * INCLUDING unicode. cpid=0 means current system code page. If    the
  92.  * requested code page is not supported, S_FALSE warning may be
  93.  * returned during Read or CopyTo operation.
  94.  */
  95.  
  96. STDAPI_(HRESULT) HrTextFromCompressedRTFStream(LPSTREAM pstmCompressed,
  97.             LPSTREAM FAR *ppstmText, RTFSYNCINFO FAR *psi, ULONG cpid);
  98.  
  99.  
  100. /*
  101.  * HrTextFromCompressedRTFStreamEx()
  102.  *
  103.  * Takes compressed RTF stream (pstmRTF) and returns a wrapper
  104.  * stream (*ppstmText) giving access to the plain text. The text
  105.  * stream supports Read and CopyTo methods.
  106.  * 
  107.  * The pointer psi must be valid until *ppstmText is released.
  108.  * It is updated as *ppstmText is read and is not accurate until
  109.  * all of the text has been read.
  110.  *
  111.  * rgAttachPos is an array of attachment positions. It must be 
  112.  * initialized to the current attachment positions before 
  113.  * HrTextFromCompressedRTFStreamEx() is called. 
  114.  *
  115.  * cAttach must contain the number of elements in rgAttachPos
  116.  *
  117.  * The pointer to rgAttachPos must be valid until *ppstmText is 
  118.  * released. It is updated as *ppstmText is read with the new 
  119.  * attachment positions and is not accurate until all of the text
  120.  * has been read.
  121.  *
  122.  * cpid is the code page for the text stream. It can be any code page
  123.  * INCLUDING unicode. cpid=0 means current system code page. If    the
  124.  * requested code page is not supported, S_FALSE warning may be
  125.  * returned during Read or CopyTo operation.
  126.  */
  127.  
  128. STDAPI_(HRESULT) HrTextFromCompressedRTFStreamEx( LPSTREAM pstmCompressed,
  129.             LPSTREAM FAR *ppstmText, RTFSYNCINFO FAR *psi, ULONG cpid,
  130.             ULONG cAttach, ULONG FAR *rgAttachPos );
  131.  
  132. /*
  133.  * HrRTFFromTextStream
  134.  *
  135.  * This function takes a text stream and returns a wrapper 
  136.  * stream interface that converts the text to RTF. The 
  137.  * stream wrapper is read only and only supports  
  138.  * a minimum stream interface.
  139.  *
  140.  * The pointer to rgAttachPos must be valid until *ppstmRTF is 
  141.  * released. This array is used to allow the insertion of 
  142.  * attachment tags in the RTF. 
  143.  *
  144.  * cpid is the code page for the text stream. It is used to 
  145.  * set the charset and font in the RTF. No code page conversion
  146.  * is currently done inside this function.
  147.  */
  148.  
  149. STDAPI_(HRESULT) HrRTFFromTextStream( LPSTREAM pstmText,
  150.                                         LPSTREAM *ppstmRTF,                                        
  151.                                         ULONG cpid,
  152.                                         ULONG cAttach,
  153.                                         ULONG FAR *rgAttachPos );
  154.  
  155. /*
  156.  * WrapCompressedRTFStream
  157.  *
  158.  * Takes compressed RTF stream (pstmCompressed) and returns a wrapper
  159.  * stream (*ppstmRTF) giving access to uncompressed RTF. The RTF
  160.  * stream can support both Read and Write operations, but to get
  161.  * write access the flag ulFlags must have MAPI_MODIFY bit set.
  162.  *
  163.  * This function also supports reading and writing uncompressed
  164.  * RTF through the use of the STORE_UNCOMPRESSED_RTF flag. For reading,
  165.  * uncompressed RTF streams are detected automatically and thus the 
  166.  * STORE_UNCOMPRESSED_RTF flag only has meaning if MAPI_MODIFY is set.
  167.  * If this flag is used, the data will be written in uncompressed form.
  168.  */
  169.  
  170. STDAPI_(HRESULT) WrapCompressedRTFStream(LPSTREAM pstmCompressed,
  171.             ULONG ulFlags, LPSTREAM FAR *ppstmRTF);
  172.  
  173. /*
  174.  * RTFSync
  175.  * RTFSyncCpid
  176.  *
  177.  * Perforts body and RTF synchronization.
  178.  * 
  179.  * If synchronization cannot be performed, RTF properties are removed.
  180.  * It is up to the caller to create new RTF from PR_BODY.
  181.  *
  182.  * cpid is the code page for the body property. It can be any code page
  183.  * EXCLUDING unicode. cpid=0 means current system code page. If    the
  184.  * requested code page is not supported, S_FALSE warning is returned.
  185.  * RTFSync is the same as RTFSyncCpid(cpid=0).
  186.  */
  187.  
  188. STDAPI_(HRESULT) RTFSync(LPMESSAGE lpMessage, ULONG ulFlags,
  189.             BOOL FAR *pfMessageUpdated);
  190.  
  191. STDAPI_(HRESULT) RTFSyncCpid(LPMESSAGE lpMessage, ULONG ulFlags,
  192.             BOOL FAR *pfMessageUpdated, ULONG cpid);
  193.  
  194. /* ulFlags for RTFSync */
  195. #define RTF_SYNC_RTF_CHANGED    ((ULONG) 0x00000001)
  196. #define RTF_SYNC_BODY_CHANGED    ((ULONG) 0x00000002)
  197.  
  198. /*
  199.  * ScUpdateRTFAux
  200.  *
  201.  * Calculates and updates RTF auxiliary properties.
  202.  */
  203.  
  204. STDAPI_(SCODE) ScUpdateRTFAux(LPMESSAGE lpMessage,
  205.             BOOL FAR *lpfMessageUpdated);
  206.  
  207. STDAPI_(SCODE) ScUpdateRTFAuxCpid(LPMESSAGE lpMessage,
  208.             BOOL FAR *lpfMessageUpdated, ULONG cpid);
  209.  
  210. /*
  211.  * HrAppendTextToCompressedRTF
  212.  *
  213.  * Takes a text buffer (pbText, cchText) and appends it to the compressed
  214.  * RTF property of the message (lpMessage) appying default text formatting.
  215.  *
  216.  * The text can be added either at the beginning of the message
  217.  * (RTF_APPEND_BEGIN) or at the end (RTF_APPEND_END).
  218.  * The text can be treated as a plain text (RTF_APPEND_PLAIN_TEXT)
  219.  * or as a piece of text with some RTF formatting in it
  220.  * (RTF_APPEND_RTF_TEXT).
  221.  *
  222.  * If case of RTF text, cchText is the number of plain text characters.
  223.  *
  224.  * cpid is the code page for the text stream. It should be one of
  225.  * Windows code pages EXCLUDING unicode. cpid=0 means current system
  226.  * code page. If the requested code page is not supported,
  227.  * S_FALSE warning is returned.
  228.  */
  229.  
  230. STDAPI_(HRESULT) HrAppendTextToCompressedRTF(LPMESSAGE lpMessage,
  231.             LPSTR strText, ULONG cchText, ULONG ulFlags, ULONG cpid);
  232.  
  233. /* ulFlags for HrAppendTextToCompressedRTF */
  234.     /* text properties (mutually exclusive) */
  235. #define RTF_APPEND_RTF_TEXT    ((ULONG) 0x00000001)
  236. #define RTF_APPEND_PLAIN_TEXT ((ULONG) 0x00000000)
  237.     /* append position (mutually exclusive) */
  238. #define RTF_APPEND_BEGIN ((ULONG) 0x00000002)
  239. #define RTF_APPEND_END ((ULONG) 0x00000000)
  240.  
  241. /* ATTACHMENT TABLE HANDLING ROUTINES */
  242.  
  243. /*
  244.  * ScGetAttachTable()
  245.  *
  246.  * Takes a message and returns a pointer to the set of rows in
  247.  * the attachment table (ppRowSet), the number of attachments 
  248.  * (pcAttach), and a pointer to an array of ULONGs containing
  249.  * the PR_RENDERING_POSITIONs for the attachments in sorted
  250.  * order.
  251.  *
  252.  */
  253.  
  254. STDAPI_(SCODE) ScGetAttachTable(LPMESSAGE pmsg, LPSRowSet *ppRowSet,
  255.                 UINT *pcAttach, ULONG **prgAttachPos);
  256.  
  257. /*
  258.  * ScUpdateAttachTable()
  259.  *
  260.  * Takes a message, a rowset for the attachment table, the 
  261.  * number of attachments, and an array of rendering positions
  262.  * to update the attachment table with. This function is 
  263.  * designed to be used in conjunction with ScGetAttachTable().
  264.  * The BOOLEAN pointed to by pfUpdated will be set to TRUE if
  265.  * the attachment table was modified.
  266.  *
  267.  */
  268.  
  269. STDAPI_(SCODE) ScUpdateAttachTable(LPMESSAGE pmsg, LPSRowSet pRowSet,
  270.                 UINT cAttach, ULONG *rgAttachPos, BOOL *pfUpdated);
  271.  
  272.  
  273. /* CPID CONVERSION ROUTINES */
  274.  
  275. /*
  276.  * These functions are in a separate object file (cpmap.obj),
  277.  * since on the store side they are linked into a different DLL.
  278.  */
  279.  
  280. STDAPI_(ULONG) WinCpidFromCpid (ULONG cpid);
  281. STDAPI_(ULONG) CharsetFromCpid (ULONG cpid);
  282. STDAPI_(ULONG) CpidFromCharset (ULONG charset);
  283. STDAPI_(CHAR FAR*) SzDefFontFmtFromCpid (ULONG cpid);
  284.  
  285.  
  286. #endif /* RTFLIB_H */
  287.