void EditorColourSet::Apply(HighlightLanguage lang, cbStyledTextCtrl* control, bool isC) { if (!control) return; control->StyleClearAll(); if (lang == HL_NONE) return; // first load the default colours to all styles used by the actual lexer (ignoring some built-in styles) OptionColour* defaults = GetDefaultOption(lang); OptionSet& mset = m_Sets[lang]; control->SetLexer(mset.m_Lexers); control->SetStyleBits(control->GetStyleBitsNeeded()); if (defaults) { int countStyles = 1 << control->GetStyleBits(); // walk until countStyles, otherwise the background-colour is only set for characters, // not for empty background for (int i = 0; i <= countStyles; ++i) { if (i < 33 || (i > 39 && i < wxSCI_STYLE_MAX)) DoApplyStyle(control, i, defaults); } } // Calling StyleClearAll above clears the style for the line numbers, so we have to re-apply it. ColourManager *colours = Manager::Get()->GetColourManager(); control->StyleSetForeground(wxSCI_STYLE_LINENUMBER, colours->GetColour(wxT("editor_linenumbers_fg"))); control->StyleSetBackground(wxSCI_STYLE_LINENUMBER, colours->GetColour(wxT("editor_linenumbers_bg"))); for (unsigned int i = 0; i < mset.m_Colours.GetCount(); ++i) { OptionColour* opt = mset.m_Colours.Item(i); if (opt->isStyle) { DoApplyStyle(control, opt->value, opt); } else { if (opt->value == cbHIGHLIGHT_LINE) { control->SetCaretLineBackground(opt->back); Manager::Get()->GetConfigManager(_T("editor"))->Write(_T("/highlight_caret_line_colour"), opt->back); } else if (opt->value == cbSELECTION) { if (opt->back != wxNullColour) { control->SetSelBackground(true, opt->back); // Manager::Get()->GetConfigManager(_T("editor"))->Write(_T("/selection_colour"), opt->back); } else control->SetSelBackground(false, wxColour(0xC0, 0xC0, 0xC0)); if (opt->fore != wxNullColour) { control->SetSelForeground(true, opt->fore); // Manager::Get()->GetConfigManager(_T("editor"))->Write(_T("/selection_fgcolour"), opt->fore); } else control->SetSelForeground(false, *wxBLACK); } // else // { // control->MarkerDefine(-opt->value, 1); // control->MarkerSetBackground(-opt->value, opt->back); // } } } for (int i = 0; i <= wxSCI_KEYWORDSET_MAX; ++i) { if (!isC || i != 1) // exclude stl highlights for C control->SetKeyWords(i, mset.m_Keywords[i]); } control->Colourise(0, -1); // the *most* important part! }
void EditorColourSet::Apply(HighlightLanguage lang, cbStyledTextCtrl* control) { if (!control) return; control->StyleClearAll(); if (lang == HL_NONE) return; // first load the default colours to all styles used by the actual lexer (ignoring some built-in styles) OptionColour* defaults = GetOptionByName(lang, _T("Default")); OptionSet& mset = m_Sets[lang]; control->SetLexer(mset.m_Lexers); control->SetStyleBits(control->GetStyleBitsNeeded()); if (defaults) { int countStyles = 1 << control->GetStyleBits(); // walk until countStyles, otherwise the background-colour is only set for characters, // not for empty background for (int i = 0; i <= countStyles; ++i) { if (i < 33 || (i > 39 && i < wxSCI_STYLE_MAX)) DoApplyStyle(control, i, defaults); } } // for some strange reason, when switching styles, the line numbering changes colour // too, though we didn't ask it to... // this makes sure it stays the correct colour control->StyleSetForeground(wxSCI_STYLE_LINENUMBER, wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); for (unsigned int i = 0; i < mset.m_Colours.GetCount(); ++i) { OptionColour* opt = mset.m_Colours.Item(i); if (opt->isStyle) { DoApplyStyle(control, opt->value, opt); } else { if (opt->value == cbHIGHLIGHT_LINE) { control->SetCaretLineBackground(opt->back); Manager::Get()->GetConfigManager(_T("editor"))->Write(_T("/highlight_caret_line_colour"), opt->back); } else if (opt->value == cbSELECTION) { if (opt->back != wxNullColour) { control->SetSelBackground(true, opt->back); // Manager::Get()->GetConfigManager(_T("editor"))->Write(_T("/selection_colour"), opt->back); } else control->SetSelBackground(false, wxColour(0xC0, 0xC0, 0xC0)); if (opt->fore != wxNullColour) { control->SetSelForeground(true, opt->fore); // Manager::Get()->GetConfigManager(_T("editor"))->Write(_T("/selection_fgcolour"), opt->fore); } else control->SetSelForeground(false, *wxBLACK); } // else // { // control->MarkerDefine(-opt->value, 1); // control->MarkerSetBackground(-opt->value, opt->back); // } } } for (int i = 0; i <= wxSCI_KEYWORDSET_MAX; ++i) { control->SetKeyWords(i, mset.m_Keywords[i]); } control->Colourise(0, -1); // the *most* important part! }