1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
Copyright (C) 2006-2010 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
struct NativeDictionary : public Dictionary
{
CComPtr<ISpellChecker> m_speller;
NativeDictionary(const wchar_t *wszLanguage) :
Dictionary(wszLanguage, 0)
{
if (auto *p = wcschr(language, '-'))
*p = '_';
g_plugin.m_spellFactory->CreateSpellChecker(wszLanguage, &m_speller);
if (!GetInfo())
if (auto *p = wcschr(full_name, '_'))
*p = '-';
}
virtual ~NativeDictionary()
{
}
// Return TRUE if the word is correct
virtual BOOL spell(const wchar_t *word)
{
CComPtr<IEnumSpellingError> error;
if (FAILED(m_speller->Check(word, &error)))
return FALSE;
CComPtr<ISpellingError> err;
if (FAILED(error->Next(&err)))
return FALSE;
return err == nullptr;
}
// Return a list of suggestions to a word
virtual Suggestions suggest(const wchar_t *word)
{
Suggestions ret;
CComPtr<IEnumString> suggestions;
if (SUCCEEDED(m_speller->Suggest(word, &suggestions))) {
wchar_t *ws;
ULONG fetched;
while (true) {
suggestions->Next(1, &ws, &fetched);
if (fetched == 0)
break;
ret.push_back(ws);
}
}
return ret;
}
// Return a list of auto suggestions to a word
// You have to free the list AND each item
virtual wchar_t* autoSuggestOne(const wchar_t * word)
{
CComPtr<IEnumString> suggestions;
if (SUCCEEDED(m_speller->Suggest(word, &suggestions))) {
wchar_t *ws;
ULONG fetched;
suggestions->Next(1, &ws, &fetched);
if (fetched) {
wchar_t *p = (wchar_t *)malloc(sizeof(wchar_t) * (mir_wstrlen(ws) + 1));
mir_wstrcpy(p, ws);
return p;
}
}
return nullptr;
}
// Return TRUE if the char is a word char
virtual BOOL isWordChar(wchar_t c)
{
if (c == 0)
return FALSE;
return iswalpha(c);
}
// Assert that all needed data is loaded
virtual void load()
{
}
virtual BOOL isLoaded()
{
return TRUE;
}
// Add a word to the user custom dict
virtual void addWord(const wchar_t *word)
{
m_speller->Add(word);
}
// Add a word to the list of ignored words
virtual void ignoreWord(const wchar_t * word)
{
m_speller->Ignore(word);
}
};
// Return a list of avaible languages
void GetNativeDictionaries(OBJLIST<Dictionary> &dicts)
{
CComPtr<IEnumString> ptr;
g_plugin.m_spellFactory->get_SupportedLanguages(&ptr);
ULONG fetched;
wchar_t *ws;
while (true) {
ptr->Next(1, &ws, &fetched);
if (fetched == 0)
break;
auto *pNew = new NativeDictionary(ws);
if (!mir_wstrcmpi(ws, pNew->full_name))
delete pNew;
else
dicts.insert(pNew);
}
}
|