home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / intl_csi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.4 KB  |  370 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. /* intl_csi.h */
  21.  
  22. #ifndef INTL_CSI_H
  23. #define INTL_CSI_H
  24. /*
  25. Using the i18n Character-Set-Information (CSI) accessor functions:
  26. 1) include the header file
  27.  
  28.   #include "intl_csi.h"
  29.  
  30. 2) get the i18n CSI object (generally from MWContext)
  31.  
  32.   INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(context);
  33.  
  34. 3) access (read/set) the data element
  35.  
  36.   int16 doc_csid = INTL_GetCSIDocCSID(csi);
  37.   INTL_SetCSIDocCSID(csi, new_doc_csid);
  38.  
  39.   int16 win_csid = INTL_GetCSIWinCSID(csi);
  40.   INTL_SetCSIWinCSID(csi, new_win_csid);
  41.  
  42.   char *mime_name = INTL_GetCSIMimeCharset(csi);
  43.   INTL_SetCSIMimeCharset(csi, new_mime_charset);
  44.  
  45.   int16 relayout_flag = INTL_GetCSIRelayoutFlag(csi);
  46.   INTL_SetCSIRelayoutFlag(csi, new_relayout_flag);
  47.  
  48. */
  49.  
  50. XP_BEGIN_PROTOS
  51.  
  52. #include "ntypes.h"
  53. #include "libi18n.h"
  54.  
  55. /**
  56.  * Cookie for INTL_CSIInfo.
  57.  * 
  58.  * This is a Magic Cookie to validate the pointer to INTL_CSIInfo in MWContext.
  59.  * 
  60.  */
  61. #define INTL_TAG  0x494E544C  
  62.  
  63. /**@name Character Set Information (CSI) */
  64. /*@{*/
  65. /**
  66.  * Allocate a new charset info object, and clear it with zeroes.
  67.  *
  68.  * @return The new charset info object
  69.  * @see INTL_CSIInitialize, INTL_CSIDestroy
  70.  */
  71. PUBLIC INTL_CharSetInfo INTL_CSICreate(void);
  72.  
  73. /**
  74.  * Frees the given charset info object.
  75.  *
  76.  * @param obj  Specifies the charset info object
  77.  * @see INTL_CSICreate
  78.  */
  79. PUBLIC void INTL_CSIDestroy(
  80.     INTL_CharSetInfo obj
  81. );
  82.  
  83. /**
  84.  * Sets all the charset info object fields to initial values.
  85.  *
  86.  * The override, HTTP, HTML META, document and window charset IDs are all set
  87.  * to CS_DEFAULT. The MIME charset is set to NULL. The relayout flag is set
  88.  * to METACHARSET_NONE.
  89.  *
  90.  * @param obj  Specifies the charset info object
  91.  * @see INTL_CSIInitialize
  92.  */
  93. PUBLIC void INTL_CSIReset(
  94.     INTL_CharSetInfo obj
  95. );
  96.  
  97. /**
  98.  * Initializes the charset info object.
  99.  *
  100.  * <UL>
  101.  * <LI>
  102.  * If the given is_metacharset_reload argument is FALSE, INTL_CSIReset is
  103.  * called, passing the given charset info object.
  104.  *
  105.  * <LI>
  106.  * If the given is_metacharset_reload argument is TRUE, the charset info
  107.  * object's relayout flag is set to METACHARSET_RELAYOUTDONE.
  108.  *
  109.  * <LI>
  110.  * Otherwise, if the override charset ID is previously set in this object, 
  111.  * it is set in the document charset ID field.
  112.  *
  113.  * <LI>
  114.  * Otherwise, if the given HTTP charset is known, it is set in the HTTP
  115.  * charset field.
  116.  *
  117.  * <LI>
  118.  * Otherwise, the document charset ID field is set to the given
  119.  * defaultDocCharSetID, unless the type is mail/news, in which case CS_DEFAULT
  120.  * is used. This is because the META charset in mail/news is sometimes wrong.
  121.  *
  122.  * <LI>
  123.  * Finally, the window charset ID is set, based on the document charset ID.
  124.  * </UL>
  125.  *
  126.  * @param obj  Specifies the charset info object
  127.  * @param is_metacharset_reload TRUE if it is currently reloading because 
  128.  *                              the layout code found HTML META charset.
  129.  *                              FALSE otherwise.
  130.  * @param http_charset Specifies the charset name if it is presented in 
  131.  *                     HTTP Content-Type header
  132.  * @param type Specifies the context type
  133.  * @param defaultDocCharSetID Specifies the default document charset ID.
  134.  * @see
  135.  */
  136. PUBLIC void INTL_CSIInitialize(
  137.     INTL_CharSetInfo obj,
  138.     XP_Bool is_metacharset_reload, 
  139.     char *http_charset,
  140.     int type,
  141.     uint16 defaultDocCharSetID
  142. );
  143.  
  144. /**
  145.  * Sets HTML META charset info in the given charset info object.
  146.  *
  147.  * <UL>
  148.  * <LI>
  149.  * If the given charset is unknown, this function returns. 
  150.  * 
  151.  * <LI>
  152.  * If the given context type is mail or news, this function returns, 
  153.  * since mail/news sometimes has wrong HTML META charsets.
  154.  *
  155.  * <LI>
  156.  * If the relayout flag is set to something other than METACHARSET_NONE, this
  157.  * function returns, to avoid setting the META charset more than once.
  158.  *
  159.  * <LI>
  160.  * Otherwise, the HTML META charset field is set, and the relayout flag is
  161.  * set to METACHARSET_HASCHARSET. 
  162.  * If the previous document charset was known,
  163.  * and was different from the new META charset, the relayout flag is set to
  164.  * METACHARSET_REQUESTRELAYOUT. 
  165.  * The window charset ID is also checked against the new one. 
  166.  * If they are different, the relayout flag is set to
  167.  * METACHARSET_REQUESTRELAYOUT.
  168.  * </UL>
  169.  *
  170.  * @param obj  Specifies the charset info object
  171.  * @param charset_tag  Specifies the HTML META charset
  172.  * @param type         Specifies the context type
  173.  * @see INTL_GetCSIMetaDocCSID, INTL_GetCSIRelayoutFlag
  174.  */
  175. PUBLIC void INTL_CSIReportMetaCharsetTag(
  176.     INTL_CharSetInfo obj,
  177.     char *charset_tag,
  178.     int type
  179. );
  180.  
  181. /**
  182.  * Returns the context's charset info object.
  183.  *
  184.  * @param context  Specifies the context
  185.  * @return The context's charset info object
  186.  * @see INTL_CSICreate
  187.  */
  188. PUBLIC INTL_CharSetInfo LO_GetDocumentCharacterSetInfo(
  189.     MWContext *context
  190. );
  191.  
  192. /**
  193.  * Returns the document charset ID of the given charset info object.
  194.  *
  195.  * @param obj  Specifies the charset info object
  196.  * @return The document charset ID
  197.  * @see INTL_SetCSIDocCSID
  198.  */
  199. PUBLIC int16 INTL_GetCSIDocCSID(
  200.     INTL_CharSetInfo obj
  201. );
  202.  
  203. /**
  204.  * Sets the document charset ID field of the given charset info object.
  205.  *
  206.  * The document charset ID field is only set if the higher precedence fields
  207.  * (override, HTTP and META) are all set to CS_DEFAULT.
  208.  *
  209.  * @param obj         Specifies the charset info object
  210.  * @param docCharSetID  Specifies the document charset ID
  211.  * @see INTL_GetCSIDocCSID
  212.  */
  213. PUBLIC void INTL_SetCSIDocCSID(
  214.     INTL_CharSetInfo obj,
  215.     int16 docCharSetID
  216. );
  217.  
  218. /**
  219.  * Returns the override document charset ID of the given charset info object.
  220.  *
  221.  * @param obj  Specifies the charset info object
  222.  * @return The override document charset ID
  223.  * @see INTL_SetCSIOverrideDocCSID
  224.  */
  225. PUBLIC int16 INTL_GetCSIOverrideDocCSID(
  226.     INTL_CharSetInfo obj
  227. );
  228.  
  229. /**
  230.  * Sets the override document charset ID of the given charset info object.
  231.  *
  232.  * @param obj         Specifies the charset info object
  233.  * @param overrideDocCharSetID  Specifies the override document charset ID
  234.  * @see INTL_GetCSIOverrideDocCSID
  235.  */
  236. PUBLIC void INTL_SetCSIOverrideDocCSID(
  237.     INTL_CharSetInfo obj,
  238.     int16 overrideDocCharSetID
  239. );
  240.  
  241. /**
  242.  * Returns the HTML META document charset ID of the given charset info object.
  243.  *
  244.  * @param obj  Specifies the charset info object
  245.  * @return The HTML META document charset ID
  246.  * @see INTL_SetCSIMetaDocCSID
  247.  */
  248. PUBLIC int16 INTL_GetCSIMetaDocCSID(
  249.     INTL_CharSetInfo obj
  250. );
  251.  
  252. /**
  253.  * Sets the HTML META document charset ID of the given charset info object.
  254.  *
  255.  * The HTML META document charset ID field is only set if the higher precedence
  256.  * fields (override and HTTP) are all set to CS_DEFAULT.
  257.  *
  258.  * @param obj         Specifies the charset info object
  259.  * @param metaCharSetID  Specifies the HTML META document charset ID
  260.  * @see INTL_GetCSIMetaDocCSID
  261.  */
  262. PUBLIC void INTL_SetCSIMetaDocCSID(
  263.     INTL_CharSetInfo obj,
  264.     int16 metaCharSetID
  265. );
  266.  
  267. /**
  268.  * Returns the HTTP document charset ID of the given charset info object.
  269.  *
  270.  * @param obj  Specifies the charset info object
  271.  * @return The HTTP document charset ID
  272.  * @see INTL_SetCSIHTTPDocCSID
  273.  */
  274. PUBLIC int16 INTL_GetCSIHTTPDocCSID(
  275.     INTL_CharSetInfo obj
  276. );
  277.  
  278. /**
  279.  * Sets the HTTP document charset ID of the given charset info object.
  280.  *
  281.  * The HTTP document charset ID field is only set if the higher precedence
  282.  * field (override) is set to CS_DEFAULT.
  283.  *
  284.  * @param obj         Specifies the charset info object
  285.  * @param httpDocCharSetID  Specifies the HTTP document charset ID
  286.  * @see INTL_GetCSIHTTPDocCSID
  287.  */
  288. PUBLIC void INTL_SetCSIHTTPDocCSID(
  289.     INTL_CharSetInfo obj,
  290.     int16 httpDocCharSetID
  291. );
  292.  
  293. /**
  294.  * Returns the window charset ID of the given charset info object.
  295.  *
  296.  * @param obj  Specifies the charset info object
  297.  * @return The window charset ID
  298.  * @see INTL_SetCSIWinCSID
  299.  */
  300. PUBLIC int16 INTL_GetCSIWinCSID(
  301.     INTL_CharSetInfo obj
  302. );
  303.  
  304. /**
  305.  * Sets the window charset ID field of the given charset info object.
  306.  *
  307.  * @param obj         Specifies the charset info object
  308.  * @param winCharSetID  Specifies the window charset ID
  309.  * @see INTL_GetCSIWinCSID
  310.  */
  311. PUBLIC void INTL_SetCSIWinCSID(
  312.     INTL_CharSetInfo obj,
  313.     int16 winCharSetID
  314. );
  315.  
  316. /**
  317.  * Returns the MIME charset field of the given charset info object.
  318.  *
  319.  * @param obj  Specifies the charset info object
  320.  * @return The MIME charset
  321.  * @see INTL_SetCSIMimeCharset
  322.  */
  323. PUBLIC char *INTL_GetCSIMimeCharset(
  324.     INTL_CharSetInfo obj
  325. );
  326.  
  327. /**
  328.  * Sets the MIME charset field of the given charset info object.
  329.  *
  330.  * If the charset info object already contains a pointer to a MIME charset,
  331.  * that charset is freed. Then the given charset is copied, and the copy is
  332.  * converted to lower case. The copy is then set in the MIME charset field.
  333.  *
  334.  * @param obj         Specifies the charset info object
  335.  * @param mime_charset  Specifies the MIME charset
  336.  * @see INTL_GetCSIMimeCharset
  337.  */
  338. PUBLIC void INTL_SetCSIMimeCharset(
  339.     INTL_CharSetInfo obj,
  340.     char *mime_charset
  341. );
  342.  
  343. /**
  344.  * Returns the relayout field of the given charset info object.
  345.  *
  346.  * @param obj  Specifies the charset info object
  347.  * @return The relayout field
  348.  * @see INTL_SetCSIRelayoutFlag
  349.  */
  350. PUBLIC int16 INTL_GetCSIRelayoutFlag(
  351.     INTL_CharSetInfo obj
  352. );
  353.  
  354. /**
  355.  * Sets the relayout field of the given charset info object.
  356.  *
  357.  * @param obj         Specifies the charset info object
  358.  * @param relayout  Specifies the relayout field
  359.  * @see INTL_GetCSIRelayoutFlag
  360.  */
  361. PUBLIC void INTL_SetCSIRelayoutFlag(
  362.     INTL_CharSetInfo obj,
  363.     int16 relayout
  364. );
  365. /*@}*/
  366.  
  367. XP_END_PROTOS
  368.  
  369. #endif /* INTL_CSI_H */
  370.