コード例 #1
0
ファイル: TCommandLine.cpp プロジェクト: Mudlet/Mudlet
void TCommandLine::spellCheck()
{
    if (!mpHost->mEnableSpellCheck) {
        return;
    }

    QTextCursor oldCursor = textCursor();
    QTextCharFormat f;
    auto cred = QColor(Qt::red);
    f.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
    f.setUnderlineColor(cred);
    QTextCursor c = textCursor();
    c.select(QTextCursor::WordUnderCursor);

    if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) {
        f.setFontUnderline(true);
        c.setCharFormat(f);
    } else {
        f.setFontUnderline(false);
        c.setCharFormat(f);
    }
    setTextCursor(c);
    f.setFontUnderline(false);
    oldCursor.setCharFormat(f);
    setTextCursor(oldCursor);
}
コード例 #2
0
ファイル: TCommandLine.cpp プロジェクト: Mudlet/Mudlet
void TCommandLine::mousePressEvent(QMouseEvent* event)
{
    if (event->button() == Qt::RightButton) {
        QTextCursor c = cursorForPosition(event->pos());
        c.select(QTextCursor::WordUnderCursor);

        if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) {
            char** sl;
            mHunspellSuggestionNumber = Hunspell_suggest(mpHunspell, &sl, c.selectedText().toLatin1().data());
            auto popup = new QMenu(this);
            for (int i = 0; i < mHunspellSuggestionNumber; i++) {
                QAction* pA;
                pA = popup->addAction(sl[i]);
                connect(pA, &QAction::triggered, this, &TCommandLine::slot_popupMenu);
            }
            mpHunspellSuggestionList = sl;
            mPopupPosition = event->pos();
            popup->popup(event->globalPos());
        }

        event->accept();
        return;
    }
    QPlainTextEdit::mousePressEvent(event);
}
コード例 #3
0
ファイル: mainwindow.cpp プロジェクト: PrasadHonrao/zoggle
void allPossibleWords::missedWordsRecursion(QString word,int dice,Bools diceUsed)
{
    QTextStream out(stdout); //for debug;
    word.append(button[dice]->text());
    if(word.length() > 2) {
//        checkingSpelling.lock();
        if(Hunspell_spell(spellChecker,word.toLower().toAscii())) {
//            checkingSpelling.unlock();
            if(!(allWords.contains(word.toLower()))) {
                writingWords.lock();
                allWords << word.toLower();
                writingWords.unlock();
            }
        }
        else {
//            checkingSpelling.unlock();
        }
    }
    diceUsed.bools[dice] = true;
    for(int i=0;i<buttonLink[dice].count();i++) {
        if(!(diceUsed.bools[buttonLink[dice].at(i)])) {
            missedWordsRecursion(word,buttonLink[dice].at(i),diceUsed);
        }
    }
}
コード例 #4
0
static gchar*
lw_morphologyengine_hunspell_spellcheck (LwMorphologyEngine *engine,
                                         const gchar        *WORD)
{
    //Sanity checks
    if (engine == NULL) return NULL;
    if (engine->hunspell == NULL) return NULL;
    if (WORD == NULL) return NULL;

    if (Hunspell_spell (engine->hunspell, WORD) != 0) return NULL;

    //Delarations
    gchar **suggestions = NULL;
    GString *output = NULL;
    gint i = 0;
    gint total = 0;

    //Initializations
    total = Hunspell_suggest (engine->hunspell, &suggestions, WORD);
    output = g_string_new ("");

    if (suggestions != NULL)
    {
      for (i = 0; i < total; i++)
      {
        if (*output->str == '\0') g_string_assign (output, suggestions[i]);
        else g_string_append_printf (output, LW_MORPHOLOGY_SPELLCHECK_DELIMITOR "%s", suggestions[i]);
      }
      Hunspell_free_list (engine->hunspell, &suggestions, total); suggestions = NULL;
    }

    return g_string_free (output, total < 1);
}
コード例 #5
0
/**
 * Return boolean: 1 if spelling looks good, else zero
 */
int spellcheck_test(void * chk, const char * word)
{
	if (NULL == chk)
	{
		prt_error("Error: no spell-check handle specified!\n");
		return 0;
	}

	return Hunspell_spell((Hunhandle *)chk, word);
}
コード例 #6
0
ファイル: mainwindow.cpp プロジェクト: PrasadHonrao/zoggle
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    QTextStream out(stdout); //for debug

    ui->setupUi(this);
    setWindowTitle("Zoggle");
    gameRunning = false;
    setupDice();

    spellChecker = Hunspell_create("en_US.aff","en_US.dic");
    if(Hunspell_spell(spellChecker,"GEO")) {
        out << "GEO is a word\n";
    }
    if(Hunspell_spell(spellChecker,"geo")) {
        out << "geo is a word\n";
    }
    if(Hunspell_spell(spellChecker,"Geo")) {
        out << "Geo is a word\n";
    }

    timeRemaining = TOTAL_TIME; //in seconds;
    ui->timeBar->setMaximum(TOTAL_TIME);
    ui->timeBar->setValue(TOTAL_TIME - timeRemaining);
    ui->timeRemaining->display(timeRemaining);
    QPalette timePalette = ui->timeRemaining->palette();
    timePalette.setColor(QPalette::Foreground, QColor("green"));
    ui->timeRemaining->setPalette(timePalette);
    timePalette = ui->timeBar->palette();
    timePalette.setColor(QPalette::Highlight, QColor("green"));
    ui->timeBar->setPalette(timePalette);
    ui->calculateBar->setValue(0);
    ui->calculateBar->setEnabled(false);

    connect(ui->actionQuit,SIGNAL(triggered()),this,SLOT(close()));
    connect(ui->actionNew,SIGNAL(triggered()),this,SLOT(newGame()));
    connect(ui->newWord,SIGNAL(returnPressed()),this,SLOT(addToList()));
    ui->newWord->setFocus();
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(updateTimeRemaining()));

    //validWords->setup(button,buttonLink);
}
コード例 #7
0
ファイル: hunspell.c プロジェクト: AncientCode/HAL-old
static PyObject *
HunSpell_spell(HunSpell * self, PyObject *args)
{
	char *word;
	int retvalue;

	if (!PyArg_ParseTuple(args, "s", &word))
		return NULL;
	retvalue = Hunspell_spell(self->handle, word);

	return PyBool_FromLong(retvalue);
}
コード例 #8
0
ファイル: mainwindow.cpp プロジェクト: PrasadHonrao/zoggle
void MainWindow::addToList() {
    QTextStream out(stdout);
    if(gameRunning) {
        if(ui->newWord->text().length() > 0) {
            //            *wordList << ui->newWord->text().toUpper();
            if(ui->newWord->text().length() > 2) {
                if(Hunspell_spell(spellChecker,ui->newWord->text().toAscii())) {
                    //                out << "correct spelling\n";
                    out.flush();

                    if(validWord()) {
                        bool isNewWord = true;
                        for(int i=0;i<letterItems[ui->newWord->text().length()]->childCount();i++) {
                            if(letterItems[ui->newWord->text().length()]->child(i)->text(0) == ui->newWord->text().toLower()) {
                                isNewWord = false;
                            }
                        }
                        if(isNewWord) {
                            QTreeWidgetItem *newItem = new QTreeWidgetItem(letterItems[ui->newWord->text().length()]);
                            newItem->setText(0,ui->newWord->text().toLower());
                            ui->wordTree->scrollToItem(newItem);
                            ui->wordTree->clearSelection();
                            newItem->setSelected(true);
                        }
                    }
                    else {
                        QTreeWidgetItem *newItem = new QTreeWidgetItem(letterItems[1]);
                        newItem->setText(0,ui->newWord->text().toLower());
                        ui->wordTree->scrollToItem(newItem);
                        ui->wordTree->clearSelection();
                        newItem->setSelected(true);
                    }
                }
                else {
                    //                out << "incorrect spelling\n";
                    out.flush();
                    QTreeWidgetItem *newItem = new QTreeWidgetItem(letterItems[0]);
                    newItem->setText(0,ui->newWord->text().toLower());
                    ui->wordTree->scrollToItem(newItem);
                    ui->wordTree->clearSelection();
                    newItem->setSelected(true);
                }
            }
            ui->wordTree->expandAll();
            //            ui->wordTable->setRowCount(10);
            //            ui->wordTable->setColumnCount(1);
            //            QTableWidgetItem *newItem = new QTableWidgetItem(ui->newWord->text());
            //            ui->wordTable->setItem(1,1,newItem);
            //            wordListModel->setStringList(*wordList);
            //            ui->wordList->scrollToBottom();
            //ui->wordList->itemDelegateForRow(0)->setProperty("color",QColor(255,0,0));
        }
    }
    int score = 0;
    int words = 0;
    int lettersScore[18] = {-1,-1,0,1,1,2,3,5,8,8,8,8,8,8,8,8,8,8};
    for(int i = 0; i<18; i++) {
        if(i != 2) {
            score += letterItems[i]->childCount()*lettersScore[i];
        }
        if(i > 2) {
            words += letterItems[i]->childCount();
        }
    }
    ui->score->display(score);
    ui->numWords->display(words);
    
    ui->newWord->setText("");
    for(int i = 0;i<16;i++) {
        button[i]->setStyleSheet("* { color: black;} ");
    }
    ui->newWord->setFocus();
}
コード例 #9
0
ファイル: spelling.c プロジェクト: lunakid/PNotesz
void CheckRESpelling(HWND hEdit){
	TEXTRANGEW			trg = {0};
	wchar_t				*wpText = NULL, *wpt, *pw, *ptrW, *wpos;
	GETTEXTLENGTHEX		gtx;
	long				charCount;
	char				*pText = NULL, *p, *w, **arr;
	int					result, countSuggs = 0, len, findRes = 0;
	SUGGARRAY			suggs = {0};
	FINDTEXTEXW			ft = {0};

	__try{
		SetCursor(LoadCursor(NULL, IDC_WAIT));
		suggs.hEdit = hEdit;
		
		gtx.flags = GTL_NUMCHARS | GTL_PRECISE;
		gtx.codepage = 1200;
		charCount = SendMessageW(hEdit, EM_GETTEXTLENGTHEX, (WPARAM)&gtx, 0);
		wpText = calloc(charCount + 1, sizeof(wchar_t));

		trg.chrg.cpMin = 0;
		trg.chrg.cpMax = charCount + 1;
		trg.lpstrText = wpText;
		SendMessageW(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&trg);

		ft.chrg = trg.chrg;

		pText = calloc(charCount + 1, sizeof(char));
		WideCharToMultiByte(m_CodePage, 0, wpText, -1, pText, charCount, NULL, NULL);

		p = pText;
		pw = wpText;
		w = strtok(p, DELIMETERS);
		wpos = wcstok(pw, DELIMITERSW, &ptrW);
		while(w){
			result = Hunspell_spell(m_hh, w);
			if(result == 0){
				len = strlen(w) + 1;
				wpt = calloc(len, sizeof(wchar_t));
				MultiByteToWideChar(m_CodePage, 0, w, -1, wpt, len - 1);
				if(suggs.count == 0){
					suggs.pSuggs = calloc(1, sizeof(PSUGGESTION));
				}
				else{
					suggs.pSuggs = realloc(suggs.pSuggs, sizeof(PSUGGESTION) * (suggs.count + 1));
					suggs.pSuggs[suggs.count] = NULL;
				}
				
				ft.lpstrText = wpos;
				findRes = SendMessageW(hEdit, EM_FINDTEXTEXW, FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD, (LPARAM)&ft);

				_addSuggestion(&suggs.pSuggs[suggs.count], wpt, findRes);
				
				ft.chrg.cpMin = findRes + wcslen(wpos);

				free(wpt);
				countSuggs = Hunspell_suggest(m_hh, &arr, w);
				if(countSuggs > 0){
					for(int i = 0; i < countSuggs; i++){
						len = strlen(arr[i]) + 1;
						wpt = calloc(len, sizeof(wchar_t));
						MultiByteToWideChar(m_CodePage, 0, arr[i], -1, wpt, len - 1);
						_addSuggestion(&suggs.pSuggs[suggs.count], wpt, len);
						free(wpt);
					}
					Hunspell_free_list(m_hh, &arr, countSuggs);
				}
				suggs.count++;
			}
			w = strtok(NULL, DELIMETERS);
			wpos = wcstok(NULL, DELIMITERSW, &ptrW);
		}
	}
	__finally{
		if(pText)
			free(pText);
		if(wpText)
			free(wpText);
		SetCursor(LoadCursor(NULL, IDC_ARROW));
	}
	if(suggs.count > 0){
		DialogBoxParamW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(DLG_SPELLING), GetParent(hEdit), Spelling_DlgProc, (LPARAM)&suggs);
		free(suggs.pSuggs);
	}
	else{
		wchar_t			szBuffer[512];
		GetPrivateProfileStringW(L"options", L"1052", L"Spell checking", szBuffer, 256, g_NotePaths.CurrLanguagePath);
		MessageBoxW(GetParent(hEdit), g_Strings.SpellCheckComplete, szBuffer, MB_OK);
	}
}
コード例 #10
0
ファイル: spelling.c プロジェクト: lunakid/PNotesz
PSUGGESTION SuggestionsForRightClick(HWND hEdit, POINT pt){
	TEXTRANGEW			trg = {0}, trWord = {0};
	wchar_t				*wpText = NULL, *wpt = NULL, *pStr;
	GETTEXTLENGTHEX		gtx;
	long				i1, i2;
	char				*w = NULL, **arr;
	int					result, countSuggs = 0, len;
	LRESULT				selChar, charCount;
	PSUGGESTION			ps = NULL;

	__try{
		gtx.flags = GTL_NUMCHARS | GTL_PRECISE;
		gtx.codepage = 1200;
		charCount = SendMessageW(hEdit, EM_GETTEXTLENGTHEX, (WPARAM)&gtx, 0);
		if(charCount == 0)
			return NULL;

		wpText = calloc(charCount + 1, sizeof(wchar_t));
		trg.chrg.cpMin = 0;
		trg.chrg.cpMax = charCount + 1;
		trg.lpstrText = wpText;
		SendMessageW(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&trg);

		selChar = SendMessageW(hEdit, EM_CHARFROMPOS, 0, (LPARAM)&pt);
		if(wcschr(DELIMITERSW, wpText[selChar]))
			return NULL;

		i1 = i2 = selChar;
		while(TRUE){
			if((i1 == 0 && wcschr(DELIMITERSW, wpText[i2])) || (i1 == 0 && i2 == charCount - 1) || (wcschr(DELIMITERSW, wpText[i1]) && wcschr(DELIMITERSW, wpText[i2])) || (wcschr(DELIMITERSW, wpText[i1]) && i2 == charCount - 1)){
				break;
			}
			if(i1 > 0 && !wcschr(DELIMITERSW, wpText[i1]))
				i1--;
			if(i2 < charCount - 1 && !wcschr(DELIMITERSW, wpText[i2]))
				i2++;
		}
		
		if(i2 == charCount - 1 && !wcschr(DELIMITERSW, wpText[i2])){
			i2++;
		}

		wpt = calloc(i2 - i1 + 1, sizeof(wchar_t));
		trWord.chrg.cpMin = (i1 > 0) ? (i1 + 1) : (wcschr(DELIMITERSW, wpText[i1]) ? 1 : 0);
		trWord.chrg.cpMax = (i2 == charCount) ? ((wcschr(DELIMITERSW, wpText[i2]) && wpText[i2] != '\0') ? i2 - 1 : i2) : i2;// < charCount - 1 ? i2 - 1 : i2;
		trWord.lpstrText = wpt;
		SendMessageW(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&trWord);
		len = i2 - i1 + 1;
		w = calloc(len, sizeof(char));
		WideCharToMultiByte(m_CodePage, 0, wpt, -1, w, len - 1, NULL, NULL);

		result = Hunspell_spell(m_hh, w);
		if(result == 0){
			_addSuggestion(&ps, wpt, trWord.chrg.cpMin);
			countSuggs = Hunspell_suggest(m_hh, &arr, w);
			if(countSuggs > 0){
				for(int i = 0; i < countSuggs; i++){
					len = strlen(arr[i]) + 1;
					pStr = calloc(len, sizeof(wchar_t));
					MultiByteToWideChar(m_CodePage, 0, arr[i], -1, pStr, len);
					_addSuggestion(&ps, pStr, len);
					free(pStr);
				}
				Hunspell_free_list(m_hh, &arr, countSuggs);
			}
		}
		return ps;
	}
	__finally{
		if(wpText)
			free(wpText);
		if(wpt)
			free(wpt);
		if(w)
			free(w);
	}
	return NULL;
}
コード例 #11
0
ファイル: spelling.c プロジェクト: lunakid/PNotesz
void AutoCheckRESpelling(HWND hEdit){
	HDC					hdc;
	long				firstChar, charPos, lineIndex;
	char				*word;
	RECT				rc = {0}, rcReal = {0}, rcText = {0};
	HRGN				hRgn, hOldRgn;
	TEXTRANGEW			trg = {0};
	CHARRANGE			chrg = {0};
	wchar_t				buffer[1024 * 10], *pString = NULL, *pText = NULL, *pWord = NULL;
	int					bufferSize, counter, len;

	hdc = GetDC(hEdit);
	SetBkMode(hdc, TRANSPARENT);

	HRESULT			hr;
	ITextDocument	*pTextDocument;
	ITextRange		*pTextRange;

	LPRICHEDITOLE 	pREOle = NULL;
	SendMessageW(hEdit, EM_GETOLEINTERFACE, 0, (LPARAM)&pREOle);
	if(pREOle == NULL)
		return;
	hr = pREOle->lpVtbl->QueryInterface(pREOle, &IID_ITextDocument, (void**)&pTextDocument);
	if(!SUCCEEDED(hr)){
		return;
	}
	//get current selection
	SendMessageW(hEdit, EM_EXGETSEL, 0, (LPARAM)&chrg);
	//get textbox rectangle
	SendMessageW(hEdit, EM_GETRECT, 0, (LPARAM)&rc);
	CopyRect(&rcText, &rc);
	//get first visible character
	charPos = SendMessageW(hEdit, EM_CHARFROMPOS, 0, (LPARAM)&rc);
	//obtain line number
	lineIndex = SendMessageW(hEdit, EM_EXLINEFROMCHAR, 0, charPos);
	firstChar = SendMessageW(hEdit, EM_LINEINDEX, lineIndex, 0);
	trg.chrg.cpMin = firstChar;
	//get last visible character
	rc.left = rc.right;
	rc.top = rc.bottom;
	trg.chrg.cpMax = SendMessageW(hEdit, EM_CHARFROMPOS, 0, (LPARAM)&rc);
	CopyRect(&rcReal, &rcText);
	hRgn = CreateRectRgnIndirect(&rcReal);
	hOldRgn = SelectObject(hdc, hRgn);
	//get the visible text into buffer
	trg.lpstrText = buffer;
	counter = bufferSize = SendMessageW(hEdit, EM_GETTEXTRANGE, 0, (LPARAM)&trg);
	if(bufferSize > 0){
		pString = _wcsdup(buffer);
		pWord = pString;
		while(counter > 0){
			if(wcschr(DELIMITERSW, *pWord))
				*pWord = '\0';
			pWord++;
			counter--;
		}
		counter = bufferSize;
		pText = pString;
		while(counter > 0){
			if(*pText){
				len = wcslen(pText) + 1;
				charPos = (bufferSize - counter) + firstChar;

				if(chrg.cpMin >= charPos && chrg.cpMax <= charPos + (len - 1)){
					//do nothing
				}
				else{
					word = calloc(len, sizeof(char));
					WideCharToMultiByte(m_CodePage, 0, pText, -1, word, len, NULL, NULL);
					if(Hunspell_spell(m_hh, word) == 0){
						hr = pTextDocument->lpVtbl->Range(pTextDocument, charPos, charPos + (len - 2), &pTextRange );
						if(SUCCEEDED(hr)){
							POINT		pts[2] = {{0}, {0}};
							hr = pTextRange->lpVtbl->GetPoint(pTextRange, 32 | TA_BASELINE | TA_LEFT, &pts[0].x, &pts[0].y);
							if(SUCCEEDED(hr)){
								hr = pTextRange->lpVtbl->GetPoint(pTextRange, 0 | TA_BASELINE | TA_RIGHT, &pts[1].x, &pts[1].y);
								if(SUCCEEDED(hr)){
									MapWindowPoints(HWND_DESKTOP, hEdit, pts, 2);
									_underscoreError(pts[0].x, pts[1].x - pts[0].x, pts[0].y, hdc);
								}
							}
						}
					}
					free(word);
				}
				pText += (len - 1);
				counter -= (len - 1);
			}
			pText++;
			counter--;
		}
		free(pString);
	}
	SelectObject(hdc, hOldRgn);
	DeleteObject(hRgn);
	ReleaseDC(hEdit, hdc);
}