home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / SpellHandler.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.1 KB  |  193 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.    SpellHandler.h -- class definition for the Spell Handler class
  20.    Created: Richard Hess <rhess@netscape.com>, 12-May-97.
  21.  */
  22.  
  23.  
  24.  
  25. #ifndef _xfe_spellhandler_h
  26. #define _xfe_spellhandler_h
  27.  
  28. #include "structs.h"
  29. #include "mozilla.h"
  30. #include "xfe.h"
  31.  
  32. class ISpellChecker;
  33.  
  34. typedef struct PRLibrary PRLibrary;
  35.  
  36. class XFE_SpellCheck;
  37.  
  38. struct xfe_lang_tag {
  39.     int  language;
  40.     int  dialect;
  41. };
  42.  
  43. struct xfe_spell_data {
  44.     ISpellChecker    *spell;
  45.     XFE_SpellCheck   *interface;
  46.     Widget            dialog;
  47.     Widget            list;
  48.     Widget            combo;
  49.     Widget            replace;
  50.     Widget            replaceAll;
  51.     Widget            check;
  52.     Widget            ignore;
  53.     Widget            ignoreAll;
  54.     Widget            learn;
  55.     Widget            stop;
  56.     Widget            status;
  57.     Widget            text;
  58.     char             *nuText;
  59.     char             *xWord;
  60.     xfe_lang_tag     *langTags;
  61.     int               langCount;
  62.     int               langIndx;
  63.     XP_Bool           inList;
  64.     XP_Bool           inCheck;
  65.     XP_Bool           isOk;
  66.     XP_Bool           isDone;
  67. };
  68.  
  69. struct xfe_spell_tag {
  70.     int               action;
  71.     xfe_spell_data   *data;
  72. };
  73.  
  74. class XFE_SpellCheck
  75. {
  76. public:
  77.     XFE_SpellCheck(ISpellChecker* spell, MWContext *context);
  78.     virtual ~XFE_SpellCheck();
  79.  
  80.     XP_Bool    ProcessError(xfe_spell_tag* tag);
  81.     XP_Bool    ProcessDocument(xfe_spell_tag* tag);
  82.  
  83.     // WARNING... [ caution needs to be applied to this one ]
  84.     //
  85.     void       resetVars();
  86.  
  87.     virtual void     IgnoreHilitedText(int AllInstances) = 0;
  88.     virtual void     RemoveAllErrorHilites() = 0;
  89.     virtual char    *GetFirstError() = 0;
  90.     virtual char    *GetNextError() = 0;
  91.     virtual char    *GetBuffer() = 0;
  92.     virtual XP_Bool  GetSelection(int32 &SelStart, int32 &SelEnd) = 0;
  93.     virtual void     ReplaceHilitedText(const char *NewText, 
  94.                                         XP_Bool AllInstances) = 0;
  95.   
  96. protected:
  97.     ISpellChecker   *m_spellChecker;
  98.     int              m_bufferSize;
  99.     int              m_xpDelta;
  100.     MWContext       *m_contextData;
  101.     char            *m_misspelledWord;
  102.     int32            m_selStart;
  103.     int32            m_selEnd;
  104.  
  105. private:
  106.  
  107. };
  108.  
  109. class XFE_HtmlSpellCheck: public XFE_SpellCheck
  110. {
  111. public:
  112.     XFE_HtmlSpellCheck(ISpellChecker *spell, MWContext *context);
  113.     virtual ~XFE_HtmlSpellCheck();
  114.  
  115.     virtual void     IgnoreHilitedText(int AllInstances);
  116.     virtual void     RemoveAllErrorHilites();
  117.     virtual char    *GetFirstError();
  118.     virtual char    *GetNextError();
  119.     virtual char    *GetBuffer();
  120.     virtual XP_Bool  GetSelection(int32 &SelStart, int32 &SelEnd);
  121.     virtual void     ReplaceHilitedText(const char *NewText, 
  122.                                         XP_Bool AllInstances);
  123.  
  124. private:
  125.  
  126. };
  127.  
  128. class XFE_TextSpellCheck: public XFE_SpellCheck
  129. {
  130. public:
  131.     XFE_TextSpellCheck(ISpellChecker *spell, MWContext *context);
  132.     virtual ~XFE_TextSpellCheck();
  133.   
  134.     virtual void     IgnoreHilitedText(int AllInstances);
  135.     virtual void     RemoveAllErrorHilites();
  136.     virtual char    *GetFirstError();
  137.     virtual char    *GetNextError();
  138.     virtual char    *GetBuffer();
  139.     virtual XP_Bool  GetSelection(int32 &SelStart, int32 &SelEnd);
  140.     virtual void     ReplaceHilitedText(const char *NewText, 
  141.                                         XP_Bool AllInstances);
  142.  
  143. private:
  144.     Widget  m_textWidget;
  145.     int     m_offset;
  146.     int     m_len;
  147.     XP_Bool m_dirty;
  148. };
  149.  
  150. #define XSP_CACHE_SIZE 8
  151.  
  152. class XFE_SpellHandler
  153. {
  154. public:
  155.     XFE_SpellHandler(MWContext *context);
  156.     virtual ~XFE_SpellHandler();
  157.  
  158.     void       PopupDialog(MWContext* context, char* eWord);
  159.     void       UpdateGUI();
  160.     void       DialogDestroyed();
  161.  
  162.     XP_Bool    ProcessDocument(MWContext* context, XP_Bool isHtml);
  163.     XP_Bool    ReprocessDocument();
  164.     XP_Bool    ProcessError(xfe_spell_tag* tag);
  165.     XP_Bool    IsActive();
  166.     XP_Bool    IsAvailable();
  167.  
  168. protected:
  169.     void       initLanguageList();
  170.     void       initSpellChecker();
  171.     void       nukeSpellChecker();
  172.     void       updateLang(int indx);
  173.     char      *getSpellCheckerDir();
  174.     char      *getPersonalDicPath();
  175.     char      *getLanguageString(int lang, int dialect);
  176.  
  177. private:
  178.     static PRLibrary* m_spellCheckerLib;
  179.     static XP_Bool   m_triedToLoad;
  180.  
  181.     XP_Bool          m_active;
  182.     xfe_spell_data   m_data;
  183.     xfe_spell_tag    m_tags[XSP_CACHE_SIZE];
  184. };
  185.  
  186. Boolean  xfe_SpellCheckerAvailable(MWContext* context);
  187. Boolean  xfe_EditorSpellCheck(MWContext* context);
  188. Boolean  xfe_TextSpellCheck(MWContext* context);
  189.  
  190. #endif /* _xfe_spellhandler_h */
  191.  
  192.  
  193.