home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / spellcli.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.3 KB  |  271 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. #ifndef _SPELLCLI_H
  20. #define _SPELLCLI_H
  21.  
  22. #include "spellchk.h"            // spell checker library public header file
  23. // the dialog box & string resources are in edtrcdll DLL
  24. #include "edtrcdll\src\resource.h"
  25.  
  26. /**************************************************************************
  27.  * Public classes and functions.
  28.  **************************************************************************/
  29.  
  30. // forward declaration of the dialog box class
  31. class CSpellCheckerDlg;
  32. class CPersonalDictionaryDlg;
  33.  
  34. class CSpellCheckerClient
  35. {
  36. public:
  37.     CSpellCheckerClient(CWnd *pParentWnd); 
  38.     ~CSpellCheckerClient();
  39.  
  40.     // Starts checking the document for spelling errors.
  41.     // Returns: 0 = success, non-zero = failure
  42.     int ProcessDocument();
  43.  
  44. protected:
  45.     // Functions to be provided by the derived classes
  46.     virtual XP_HUGE_CHAR_PTR GetBuffer() = 0;
  47.     virtual BOOL GetSelection(int32 &SelStart, int32 &SelEnd) = 0;
  48.     virtual char *GetFirstError() = 0;
  49.     virtual char *GetNextError() = 0;
  50.     virtual void ReplaceHilitedText(const char *NewText, int AllInstances) = 0;
  51.     virtual void IgnoreHilitedText(int AllInstances) = 0;
  52.     virtual void RemoveAllErrorHilites() {};
  53.  
  54.     // Displays the modal personal dictionary dialog box
  55.     void ShowPersonalDictionaryDlg(CWnd *pParent = NULL);
  56.  
  57.     // Restarts checking the document. Called by the dialog box when the
  58.     // user changes the default language.
  59.     int ReprocessDocument();
  60.  
  61. protected:
  62.     HINSTANCE               m_hSpellCheckerDll;
  63.     CWnd                    *m_pParentWnd;
  64.     ISpellChecker            *m_pSpellChecker;
  65.     CPersonalDictionaryDlg  *m_pDictionaryDlg;
  66.     int32                   m_BufferSize;
  67.     int32                   m_SelStart, m_SelEnd;
  68.  
  69.     static int              m_InstanceCount;
  70.  
  71.     friend class CSpellCheckerDlg;
  72.     friend class CHtmlSpellChecker;
  73.     friend class CPlainTextSpellChecker;
  74. };
  75.  
  76. class CHtmlSpellChecker : public CSpellCheckerClient
  77. {
  78. public:
  79.     CHtmlSpellChecker(MWContext *pMWContext, CNetscapeEditView *pHtmlView); 
  80.  
  81.     // Starts checking the document for spelling errors.
  82.     // Returns: 0 = success, non-zero = failure
  83.     int ProcessDocument() {return CSpellCheckerClient::ProcessDocument(); };
  84.  
  85. protected:
  86.     // Implementation of base class virtuals.
  87.     XP_HUGE_CHAR_PTR GetBuffer();
  88.     BOOL GetSelection(int32 &SelStart, int32 &SelEnd);
  89.     char *GetFirstError();
  90.     char *GetNextError();
  91.     void ReplaceHilitedText(const char *NewText, int AllInstances);
  92.     void IgnoreHilitedText(int AllInstances);
  93.     void RemoveAllErrorHilites();
  94.  
  95. private:
  96.     MWContext           *m_pMWContext;
  97.     CNetscapeEditView   *m_pView;
  98. };
  99.  
  100. class CPlainTextSpellChecker : public CSpellCheckerClient
  101. {
  102. public:
  103.     CPlainTextSpellChecker(CEdit *pTextView); 
  104.  
  105.     // Starts checking the document for spelling errors.
  106.     // Returns: 0 = success, non-zero = failure
  107.     int ProcessDocument() {return CSpellCheckerClient::ProcessDocument(); };
  108.  
  109. protected:
  110.     // Implentation of base class virtuals.
  111.     XP_HUGE_CHAR_PTR GetBuffer();
  112.     BOOL GetSelection(int32 &SelStart, int32 &SelEnd);
  113.     char *GetFirstError();
  114.     char *GetNextError();
  115.     void ReplaceHilitedText(const char *NewText, int AllInstances);
  116.     void IgnoreHilitedText(int AllInstances);
  117.  
  118. private:
  119.     CEdit   *m_pTextView;
  120. };
  121.  
  122.  
  123. /**************************************************************************
  124.  * Dialog box implementation classes
  125.  **************************************************************************/
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CSpellCheckerDlg dialog
  129.  
  130. class CSpellCheckerDlg : public CDialog
  131. {
  132. // Construction
  133. public:
  134.     CSpellCheckerDlg(ISpellChecker *pSpellChecker, CSpellCheckerClient *pClient, CWnd* pParent = NULL);
  135.  
  136. // Dialog Data
  137.     //{{AFX_DATA(CSpellDlg)
  138.     enum { IDD = IDD_SPELL_CHECKER };
  139.     CListBox    m_SuggestionsListBox;
  140.     //}}AFX_DATA
  141.  
  142. // Overrides
  143.     // ClassWizard generated virtual function overrides
  144.     //{{AFX_VIRTUAL(CSpellCheckerDlg)
  145.     protected:
  146.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  147.     //}}AFX_VIRTUAL
  148.  
  149. // Implementation
  150. protected:
  151.     // Generated message map functions
  152.     //{{AFX_MSG(CSpellCheckerDlg)
  153.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  154.     virtual BOOL OnInitDialog();
  155.     virtual void OnCancel();
  156.     afx_msg void OnChange();
  157.     afx_msg void OnIgnore();
  158.     afx_msg void OnChangeNewWord();
  159.     afx_msg void OnSetFocusNewWord();
  160.     afx_msg void OnSetFocusSuggestions();
  161.     afx_msg void OnSelChangeSuggestions();
  162.     afx_msg void OnIgnoreAll();
  163.     afx_msg void OnChangeAll();
  164.     afx_msg void OnAdd();
  165.     afx_msg void OnEditDictionary();
  166.     afx_msg void OnSelendokLanguage();
  167.     afx_msg void OnHelp();
  168.     afx_msg void OnCheckWord();
  169.     //}}AFX_MSG
  170. #ifdef XP_WIN32
  171.     afx_msg BOOL OnHelpInfo(HELPINFO *);
  172. #endif
  173.     void CommonOnChange(BOOL ChangeAll);
  174.  
  175.     afx_msg LRESULT OnSetInitialFocus(WPARAM wParam, LPARAM lParam);
  176.  
  177.     DECLARE_MESSAGE_MAP()
  178.  
  179. private:
  180.     ISpellChecker    *m_pSpellChecker;
  181.     CSpellCheckerClient    *m_pClient;
  182.     CString         m_MisspelledWord;
  183.  
  184.     // Resource switcher object: It switches the default resource handle to the 
  185.     // editorXX.dll, cause that's where the dialog box resource is. 
  186.     CEditorResourceSwitcher m_DlgResource;
  187.  
  188.     // strings loaded from the resource DLL
  189.     CString         m_strChange, m_strChangeAll, m_strDelete,
  190.                     m_strDeleteAll, m_strNoSuggestions,
  191.                     m_strStop, m_strDone, m_strCorrectSpelling;
  192.  
  193.     // The new word, either entered in the edit field or selected in 
  194.     // the Suggestions listbox.
  195.     CString         m_NewWord;
  196.     int             m_NumSuggestions;
  197.  
  198.     void SetAlternatives();
  199.     void GetFirstError();
  200.     void GetNextError();
  201.     void ProcessError(char *pMisspelledWord);
  202.     void InitLanguageList();
  203.     void ChangeState();
  204.     void UpdateChangeButton();
  205.  
  206. #ifdef XP_WIN16
  207.     // Win16 MFC 1.52 version of GetDlgItemText does not take a CString
  208.     void GetDlgItemText( int nID, CString& rString ) const
  209.             { GetDlgItem(nID)->GetWindowText(rString); }
  210. #endif  
  211. };
  212.  
  213. /////////////////////////////////////////////////////////////////////////////
  214. // CPersonalDictionaryDlg dialog
  215.  
  216. class CPersonalDictionaryDlg : public CDialog
  217. {
  218. // Construction
  219. public:
  220.     CPersonalDictionaryDlg(ISpellChecker *pSpellChecker, CWnd* pParent=NULL);
  221.  
  222. // Dialog Data
  223.     //{{AFX_DATA(CPersonalDictionaryDlg)
  224.     enum { IDD = IDD_CUSTOM_DICTIONARY };
  225.     CListBox    m_WordList;
  226.     //}}AFX_DATA
  227.  
  228. // Overrides
  229.     // ClassWizard generated virtual function overrides
  230.     //{{AFX_VIRTUAL(CSpellCheckerDlg)
  231.     virtual BOOL OnInitDialog();
  232.     protected:
  233.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  234.     //}}AFX_VIRTUAL
  235.     virtual void OnOK();
  236.  
  237. // Implementation
  238. protected:
  239.     // Generated message map functions
  240.     //{{AFX_MSG(CSpellCheckerDlg)
  241.     //}}AFX_MSG
  242.  
  243.     afx_msg void OnAddWord();
  244.     afx_msg void OnReplaceWord();
  245.     afx_msg void OnRemoveWord();
  246.     afx_msg void OnSelChangeWordList();
  247.     afx_msg void EnableButtons();
  248.     afx_msg void OnHelp();
  249. #ifdef XP_WIN32
  250.     afx_msg BOOL OnHelpInfo(HELPINFO *);
  251. #endif
  252.  
  253.     DECLARE_MESSAGE_MAP()
  254.  
  255. private:
  256.     ISpellChecker    *m_pSpellChecker;
  257.  
  258.     // Resource switcher object: It switches the default resource handle to the 
  259.     // editorXX.dll, cause that's where the dialog box resource is. 
  260.     CEditorResourceSwitcher m_DlgResource;
  261.  
  262. #ifdef XP_WIN16
  263.     // Win16 MFC 1.52 version of GetDlgItemText does not take a CString
  264.     void GetDlgItemText( int nID, CString& rString ) const
  265.             { GetDlgItem(nID)->GetWindowText(rString); }
  266. #endif  
  267.  
  268. };
  269.  
  270. #endif
  271.