void Highlighter::DoSetIndications(cbEditor* ctrl)const { cbStyledTextCtrl *stc = ctrl->GetLeftSplitViewControl(); //Returns a pointer to the left (or top) split-view cbStyledTextCtrl. This function always returns a valid pointer. cbStyledTextCtrl *stcr =ctrl->GetRightSplitViewControl(); if (m_AlreadyChecked && m_OldCtrl == ctrl) { if ( m_InvalidatedRangesStart.GetCount() == 0) return; } else { //clear: m_InvalidatedRangesStart.Clear(); m_InvalidatedRangesEnd.Clear(); //add whole document m_InvalidatedRangesStart.Add(0); m_InvalidatedRangesEnd.Add(stc->GetLength()); } m_AlreadyChecked = true; // Set Styling: stc->SetIndicatorCurrent(GetIndicator()); //if(stc->SelectionIsRectangle() || (stcr && stcr->SelectionIsRectangle())) return; if (m_OldCtrl != ctrl) { stc->IndicatorSetStyle(GetIndicator(), wxSCI_INDIC_HIGHLIGHT); stc->IndicatorSetForeground(GetIndicator(), GetIndicatorColor() ); #ifndef wxHAVE_RAW_BITMAP // If wxWidgets is build without rawbitmap-support, the indicators become opaque // and hide the text, so we show them under the text. // Not enabled as default, because the readability is a little bit worse. stc->IndicatorSetUnder(theIndicator,true); #endif } if (stcr) { if (m_OldCtrl != ctrl) { stcr->SetIndicatorCurrent(GetIndicator()); stcr->IndicatorSetStyle(GetIndicator(), wxSCI_INDIC_HIGHLIGHT); stcr->IndicatorSetForeground(GetIndicator(), GetIndicatorColor() ); #ifndef wxHAVE_RAW_BITMAP stcr->IndicatorSetUnder(theIndicator,true); #endif } } m_OldCtrl = ctrl; ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("editor")); int flag = 0; if (cfg->ReadBool(_T("/highlight_occurrence/case_sensitive_permanently"), true)) flag |= wxSCI_FIND_MATCHCASE; if (cfg->ReadBool(_T("/highlight_occurrence/whole_word_permanently"), true)) flag |= wxSCI_FIND_WHOLEWORD; for (int i = 0; i < (int)m_InvalidatedRangesStart.GetCount(); i++) { int start = m_InvalidatedRangesStart[i]; int end = m_InvalidatedRangesEnd[i]; //bound: if (start < 0) start = 0; if (end < 0) end = 0; if (start >= stc->GetLength()) start = stc->GetLength() - 1; if (end > stc->GetLength()) end = stc->GetLength(); if (start != end) { //remove styling: stc->IndicatorClearRange(start, end - start); for (std::set<wxString>::iterator it = m_Texts.begin(); it != m_Texts.end(); it++ ) { wxString text = *it; // search for occurrences int startpos = start; int endpos = end; int lengthFound = 0; // we need this to work properly with multibyte characters for ( int pos = stc->FindText(startpos, endpos, text, flag, &lengthFound); pos != wxSCI_INVALID_POSITION ; pos = stc->FindText(pos+=text.Len(), endpos, text, flag, &lengthFound) ) { stc->IndicatorFillRange(pos, lengthFound); } } } } m_InvalidatedRangesStart.Clear(); m_InvalidatedRangesEnd.Clear(); }
void OnlineSpellChecker::DoSetIndications(cbEditor* ctrl)const { //Returns a pointer to the left (or top) split-view cbStyledTextCtrl. This function always returns a valid pointer. cbStyledTextCtrl *stc = ctrl->GetLeftSplitViewControl(); cbStyledTextCtrl *stcr =ctrl->GetRightSplitViewControl(); // whatever the current state is, we've already done it once if ( alreadychecked && oldctrl == ctrl ) { if (m_invalidatedRangesStart.GetCount() == 0) return; } else { //clear: m_invalidatedRangesStart.Clear(); m_invalidatedRangesEnd.Clear(); //add whole document m_invalidatedRangesStart.Add(0); m_invalidatedRangesEnd.Add(stc->GetLength()); } alreadychecked = true; oldctrl = ctrl; // Set Styling: stc->SetIndicatorCurrent(GetIndicator()); stc->IndicatorSetStyle(GetIndicator(), wxSCI_INDIC_SQUIGGLE); stc->IndicatorSetForeground(GetIndicator(), GetIndicatorColor() ); #ifndef wxHAVE_RAW_BITMAP // If wxWidgets is build without rawbitmap-support, the indicators become opaque // and hide the text, so we show them under the text. // Not enabled as default, because the readability is a little bit worse. stc->IndicatorSetUnder(GetIndicator(),true); #endif if ( stcr ) { stcr->IndicatorSetStyle(GetIndicator(), wxSCI_INDIC_SQUIGGLE); stcr->IndicatorSetForeground(GetIndicator(), GetIndicatorColor() ); #ifndef wxHAVE_RAW_BITMAP stcr->IndicatorSetUnder(GetIndicator(),true); #endif } // Manager::Get()->GetLogManager()->Log(wxT("OSC: update regions")); for (int i = 0; i < (int)m_invalidatedRangesStart.GetCount(); i++) { int start = m_invalidatedRangesStart[i]; int end = m_invalidatedRangesEnd[i]; //bound: if (start < 0) start = 0; if (end < 0) end = 0; if (start >= stc->GetLength()) start = stc->GetLength() - 1; if (end > stc->GetLength()) end = stc->GetLength(); if (start != end) { //remove styling: stc->IndicatorClearRange(start, end - start); int wordstart = start; int wordend = wordstart; for( int pos = wordstart ; pos < end ; ) { wxString lang = Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageName(ctrl->GetLanguage() ); wxChar ch = stc->GetCharAt(pos); // treat chars which don't have the correct style as whitespace: bool isEscape = SpellCheckHelper::IsEscapeSequenceStart(ch, lang, stc->GetStyleAt(pos)); if ( isEscape || SpellCheckHelper::IsWhiteSpace(ch) || !m_pSpellHelper->HasStyleToBeChecked(lang, stc->GetStyleAt(pos))) { if (wordstart != wordend) DissectWordAndCheck(stc, wordstart, wordend); pos++; if ( isEscape ) pos++; wordstart = pos; wordend = pos; } else { pos++; wordend = pos; } } if (wordstart != wordend) { wxString lang = Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageName(ctrl->GetLanguage() ); if ( m_pSpellHelper->HasStyleToBeChecked(lang, stc->GetStyleAt(wordstart)) ) { DissectWordAndCheck(stc, wordstart, wordend); } } } } m_invalidatedRangesStart.Clear(); m_invalidatedRangesEnd.Clear(); }