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

  1. /* -*- Mode: C++; tab-width: 8; 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.  *  
  21.  *
  22.  ***************************************************************************
  23.  *  spellchk.h
  24.  *  Public header file for the Spell Checker library.
  25.  ****************************************************************************/
  26.  
  27. #ifndef _SPELLCHK_H_
  28. #define _SPELLCHK_H_
  29.  
  30. /* In WIN16 DLL exported functions require __loadds keywords for the DS
  31.  * register to be set to the DLL's data-segment value and restored on return
  32.  * from the function.
  33.  */
  34. #ifdef WINDOWS
  35. #define SCAPI __loadds
  36. #elif defined(WIN32)
  37. #define SCAPI __cdecl
  38. #else
  39. #define SCAPI
  40. #endif
  41.  
  42. #ifdef MAC
  43. #include <Files.h>
  44. #endif
  45.  
  46. /* Language and Dialect codes.  */
  47.  
  48. #define L_AFRIKAANS     101
  49. #define L_CATALAN       102
  50. #define L_CZECH         103
  51. #define L_DANISH        104
  52. #define L_DUTCH         105
  53. #define L_ENGLISH       106
  54. #define L_FINNISH       107
  55. #define L_FRENCH        108
  56. #define L_GERMAN        109
  57. #define L_GREEK         110
  58. #define L_HUNGARIAN     111
  59. #define L_ITALIAN       112
  60. #define L_NORWEGIAN     113
  61. #define L_POLISH        114
  62. #define L_PORTUGUESE    115
  63. #define L_RUSSIAN       116
  64. #define L_SPANISH       117
  65. #define L_SWEDISH       118
  66.  
  67.  
  68. #define D_DEFAULT       0xFFFF
  69. #define D_AUS_ENGLISH   0x1001
  70. #define D_US_ENGLISH    0x1010
  71. #define D_UK_ENGLISH    0x1100
  72. #define D_DOPPEL        0x2001     /* German */
  73. #define D_SCHARFES      0x2010
  74. #define D_BRAZILIAN     0x4001     /* Portuguese */
  75. #define D_EUROPEAN      0x4010
  76. #define D_BOKMAL        0x8001     /* Norwegian */
  77. #define D_NYNORSK       0x8010
  78.  
  79.  
  80. /* ISpellChecker - This class specifies the interface to the Spell Checker. A client
  81.  * application instatiates a spell checker object using the exported function SC_Create().
  82.  * The client application then performs spell checking using the member functions of this
  83.  * class. The spell checker object is destroyed by using the exported function SC_Destroy().
  84.  */
  85.  
  86. class ISpellChecker
  87. {
  88. public:
  89.     /* Needs to be called by the client app once before calling any other functions.
  90.      * Return:  0 = success, non-zero = error
  91.      */ 
  92. #ifdef MAC
  93.     virtual int SCAPI Initialize(int LangCode, int DialectCode, 
  94.                                  FSSpec *DbPath, FSSpec *PersonalDbFile) = 0;
  95. #else
  96.     virtual int SCAPI Initialize(int LangCode, int DialectCode, 
  97.                                  const char *DbPath, const char *PersonalDbFile) = 0;
  98. #endif
  99.  
  100.     /* Functions to set and get the current language and dialect settings.
  101.      * Returns: 0 = success, non-zero = failure
  102.      */
  103.     virtual int SCAPI SetCurrentLanguage(int LangCode, int DialectCode) = 0;
  104.     virtual int SCAPI GetCurrentLanguage(int &LangCode, int &DialectCode) = 0;
  105.  
  106.     /* Get the list of dictionaries available */
  107.     virtual int SCAPI GetNumOfDictionaries() = 0;
  108.     /* Get the language and dialect id for an available dictionary.
  109.      * Index = 0-based index into the list of available dictionaries.
  110.      * Returns: 0 = success, non-zero = failure.
  111.      */
  112.     virtual int SCAPI GetDictionaryLanguage(int Index, int &LangCode, int &DialectCode) = 0;
  113.  
  114.     /* Called by the client application to initialize a buffer for spell checking.
  115.      * It returns immediately without parsing the buffer. The client controls parsing of
  116.      * the buffer by calling GetNextMisspelledWord() and SetNewBuf().
  117.      * Return:  0 = success, non-zero = error
  118.      */
  119.     virtual int SCAPI SetBuf(const char *pBuf) = 0;
  120.  
  121.     /* Initialize a buffer with selection */
  122.     virtual int SCAPI SetBuf(const char *pBuf, unsigned long SelStart, unsigned long SelEnd) = 0;
  123.  
  124.     /* Replace the current mispelled word with a new word */
  125.     virtual int SCAPI ReplaceMisspelledWord(const char *NewWord, int AllInstances) = 0;
  126.  
  127.     /* Get the size of the current buffer */
  128.     virtual unsigned long SCAPI GetBufSize() = 0;
  129.  
  130.     /* Copy the current buffer */
  131.     virtual int SCAPI GetBuf(char *pBuf, unsigned long BufSize) = 0;
  132.  
  133.     /* Called by the client application to parse the buffer and return the next misspelled
  134.      * word in the buffer.
  135.      * Return:  0 = found a misspelled word.
  136.      *              *Offset = Offset of the word from the beginning of the buffer
  137.      *              *Len = Length of the word
  138.      *          non-zero = no more misspelled word
  139.      */
  140.     virtual int SCAPI GetNextMisspelledWord(unsigned long &Offset, unsigned long &Len) = 0;
  141.  
  142.     /* The orginal buffer was changed by the client.
  143.      * ReparseFromStart = 1 - reparse the new buffer from the beginning
  144.      *                  = 0 - parse from the last offset into the original buffer
  145.      */
  146.     virtual void SCAPI SetNewBuf(const char *pBuf, int ReparseFromStart) = 0;
  147.  
  148.     /* Called by the client application to spell check a work.
  149.      * Return:    1 = valid word, 0 = not in dictionary
  150.      */
  151.     virtual int SCAPI CheckWord(const char *pWord) = 0;
  152.  
  153.     /* Get the number of possible alternatives found in the dictionary for the input word. */
  154.     virtual int SCAPI GetNumAlternatives(const char *pWord) = 0;
  155.  
  156.     /* Get an alternative string. The "Index" is zero based.
  157.      * Return:  0 = success, -1 = error(bad Index), 
  158.      *          +ve value = BufSize too small, size needed
  159.      */
  160.     virtual int SCAPI GetAlternative(int Index, char *pBuf, unsigned int BufSize) = 0;
  161.  
  162.     /* The following functions interact with the personal database */
  163.  
  164.     /* Add a word to the personal dictionary */
  165.     virtual int SCAPI AddWordToPersonalDictionary(const char *pWord) = 0;
  166.  
  167.     /* Remove a word from the personal dictionary */
  168.     virtual int SCAPI RemoveWordFromPersonalDictionary(const char *pWord) = 0;
  169.  
  170.     /* Ignore all references to a word in the current session */
  171.     virtual int SCAPI IgnoreWord(const char *pWord) = 0;
  172.  
  173.     /* GetFirstPersonalDictionaryWord & GetNextPersonalDictionaryWord
  174.      * These functions retrieve words in the personal dictionary
  175.      * Returns:    0   = success, pBuf contains the next word
  176.      *          -1  = no more words 
  177.      *          +ve = required buffer size. Size passed is too small.
  178.      */
  179.     virtual int SCAPI GetFirstPersonalDictionaryWord(char *pBuf, int BufSize) = 0;
  180.     virtual int SCAPI GetNextPersonalDictionaryWord(char *pBuf, int BufSize) = 0;
  181.  
  182.     /* Resets the contents of the personal dictionary */
  183.     virtual int SCAPI ResetPersonalDictionary() = 0;
  184.  
  185.     /* destructor */
  186.     virtual ~ISpellChecker() {};
  187. };
  188.  
  189. /* Exported library functions to create and destroy ISpellChecker objects. */
  190.  
  191. extern "C" 
  192. {
  193.  
  194. ISpellChecker * SCAPI SC_Create();
  195. void SCAPI SC_Destroy(ISpellChecker *pSpellChecker);
  196.  
  197. }
  198.  
  199. #endif
  200.