Exemple #1
0
// Overrides the function from QSyntaxHighlighter;
// gets called by QTextEditor whenever
// a block (line of text) needs to be repainted
void XHTMLHighlighter::highlightBlock(const QString &text)
{
    // By default, all block states are -1;
    // in our implementation regular text is state == 1
    if (previousBlockState() == -1) {
        setCurrentBlockState(State_Text);
    }
    // Propagate previous state; needed for state tracking
    else {
        setCurrentBlockState(previousBlockState());
    }

    if (text.isEmpty()) {
        return;
    }

    SettingsStore settings;
    m_enableSpellCheck = settings.spellCheck();

    // Run spell check over the text.
    if (m_enableSpellCheck && m_checkSpelling) {
        CheckSpelling(text);
    }

    // The order of these operations is important
    // because some states format text over previous states!
    HighlightLine(text, State_Entity);
    HighlightLine(text, State_CSS);
    HighlightLine(text, State_HTML);
    HighlightLine(text, State_CSSComment);
    HighlightLine(text, State_HTMLComment);
    HighlightLine(text, State_DOCTYPE);
}
bool CSpellChecker::CheckSpelling(LPCTSTR szWord, LPTSTR*& pSuggestions, int& nNumSuggestions)
{
	bool bResult = CheckSpelling(szWord);

	if (!bResult && m_pMySpell)
	{
#ifdef _UNICODE

	// must make the spell check calls in ANSI
	int nLen = lstrlen(szWord);
	char* szWordMulti = WideToMultiByte(szWord, nLen);

	char** pSuggestionsMulti = NULL;
	nNumSuggestions = m_pMySpell->suggest(&pSuggestionsMulti, szWordMulti);

	if (pSuggestionsMulti)
	{
		// convert back to unicode
		pSuggestions = new LPTSTR[nNumSuggestions];

		for (int nSuggest = 0; nSuggest < nNumSuggestions; nSuggest++)
		{
			nLen = strlen(pSuggestionsMulti[nSuggest]);
			pSuggestions[nSuggest] = MultiByteToWide(pSuggestionsMulti[nSuggest], nLen);
		}
	}

	delete [] szWordMulti;

#else
		nNumSuggestions = m_pMySpell->suggest(&pSuggestions, szWord);
#endif
	}

	return bResult;
}