1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6#include "nsISupports.idl"
7
8interface nsIEditor;
9interface nsITextServicesFilter;
10interface nsIEditorSpellCheckCallback;
11
12[scriptable, uuid(a171c25f-e4a8-4d08-adef-b797e6377bdc)]
13interface nsIEditorSpellCheck : nsISupports
14{
15
16 /**
17   * Returns true if we can enable spellchecking. If there are no available
18   * dictionaries, this will return false.
19   */
20  boolean       canSpellCheck();
21
22  /**
23   * Turns on the spell checker for the given editor. enableSelectionChecking
24   * set means that we only want to check the current selection in the editor,
25   * (this controls the behavior of GetNextMisspelledWord). For spellchecking
26   * clients with no modal UI (such as inline spellcheckers), this flag doesn't
27   * matter.  Initialization is asynchronous and is not complete until the given
28   * callback is called.
29   */
30  void          InitSpellChecker(in nsIEditor editor, in boolean enableSelectionChecking,
31                                 [optional] in nsIEditorSpellCheckCallback callback);
32
33  /**
34   * When interactively spell checking the document, this will return the
35   * value of the next word that is misspelled. This also computes the
36   * suggestions which you can get by calling GetSuggestedWord.
37   *
38   * @see nsISpellChecker::GetNextMisspelledWord
39   */
40  AString       GetNextMisspelledWord();
41
42  /**
43   * Used to get suggestions for the last word that was checked and found to
44   * be misspelled. The first call will give you the first (best) suggestion.
45   * Subsequent calls will iterate through all the suggestions, allowing you
46   * to build a list. When there are no more suggestions, an empty string
47   * (not a null pointer) will be returned.
48   *
49   * @see nsISpellChecker::GetSuggestedWord
50   */
51  AString       GetSuggestedWord();
52
53  /**
54   * Check a given word. In spite of the name, this function checks the word
55   * you give it, returning true if the word is misspelled. If the word is
56   * misspelled, it will compute the suggestions which you can get from
57   * GetSuggestedWord().
58   *
59   * @see nsISpellChecker::CheckCurrentWord
60   */
61  boolean       CheckCurrentWord(in AString suggestedWord);
62
63  /**
64   * Use when modally checking the document to replace a word.
65   *
66   * @see nsISpellChecker::CheckCurrentWord
67   */
68  void          ReplaceWord(in AString misspelledWord, in AString replaceWord, in boolean allOccurrences);
69
70  /**
71   * @see nsISpellChecker::IgnoreAll
72   */
73  void          IgnoreWordAllOccurrences(in AString word);
74
75  /**
76   * Fills an internal list of words added to the personal dictionary. These
77   * words can be retrieved using GetPersonalDictionaryWord()
78   *
79   * @see nsISpellChecker::GetPersonalDictionary
80   * @see GetPersonalDictionaryWord
81   */
82  void          GetPersonalDictionary();
83
84  /**
85   * Used after you call GetPersonalDictionary() to iterate through all the
86   * words added to the personal dictionary. Will return the empty string when
87   * there are no more words.
88   */
89  AString       GetPersonalDictionaryWord();
90
91  /**
92   * Adds a word to the current personal dictionary.
93   *
94   * @see nsISpellChecker::AddWordToDictionary
95   */
96  void          AddWordToDictionary(in AString word);
97
98  /**
99   * Removes a word from the current personal dictionary.
100   *
101   * @see nsISpellChecker::RemoveWordFromPersonalDictionary
102   */
103  void          RemoveWordFromDictionary(in AString word);
104
105  /**
106   * Retrieves a list of the currently available dictionaries. The strings will
107   * typically be language IDs, like "en-US".
108   *
109   * @see mozISpellCheckingEngine::GetDictionaryList
110   */
111  void          GetDictionaryList([array, size_is(count)] out wstring dictionaryList, out uint32_t count);
112
113  /**
114   * @see nsISpellChecker::GetCurrentDictionary
115   */
116  AString       GetCurrentDictionary();
117
118  /**
119   * @see nsISpellChecker::SetCurrentDictionary
120   */
121  void          SetCurrentDictionary(in AString dictionary);
122
123  /**
124   * Call this to free up the spell checking object. It will also save the
125   * current selected language as the default for future use.
126   *
127   * If you have called CanSpellCheck but not InitSpellChecker, you can still
128   * call this function to clear the cached spell check object, and no
129   * preference saving will happen.
130   */
131  void          UninitSpellChecker();
132
133  /**
134   * Used to filter the content (for example, to skip blockquotes in email from
135   * spellchecking. Call this before calling InitSpellChecker; calling it
136   * after initialization will have no effect.
137   *
138   * @see nsITextServicesDocument::setFilter
139   */
140  void          setFilter(in nsITextServicesFilter filter);
141
142  /**
143   * Like CheckCurrentWord, checks the word you give it, returning true if it's
144   * misspelled. This is faster than CheckCurrentWord because it does not
145   * compute any suggestions.
146   *
147   * Watch out: this does not clear any suggestions left over from previous
148   * calls to CheckCurrentWord, so there may be suggestions, but they will be
149   * invalid.
150   */
151  boolean       CheckCurrentWordNoSuggest(in AString suggestedWord);
152
153  /**
154   * Update the dictionary in use to be sure it corresponds to what the editor
155   * needs.  The update is asynchronous and is not complete until the given
156   * callback is called.
157   */
158  void          UpdateCurrentDictionary([optional] in nsIEditorSpellCheckCallback callback);
159
160};
161
162[scriptable, function, uuid(5f0a4bab-8538-4074-89d3-2f0e866a1c0b)]
163interface nsIEditorSpellCheckCallback : nsISupports
164{
165  void editorSpellCheckDone();
166};
167