wxScintilla
Posted: Sat Oct 29, 2005 5:04 am
Does anyone know how to use wxScintilla with a lexer? I tried doing it for... like nearly 8 hours... with no avail... and Otto's example really confuses me...
For people who need source code, some are copied from his e.g direct, but here it is:Miraculously, syntax highlighting never occurs
For people who need source code, some are copied from his e.g direct, but here it is:
Code: Select all
BEGIN_EVENT_TABLE(query::queryctrl, wxScintilla)
EVT_SCI_CHARADDED(wxID_ANY, query::queryctrl::OnCharAdded)
END_EVENT_TABLE()
query::queryctrl::queryctrl(wxWindow* parent, wxWindowID id, const wxString&, const wxPoint& pos, const wxSize& size, long style, const wxValidator&, const wxString& name)
: wxScintilla(parent, id, pos, size, style, name)
{
//Set the margin styles
SetMarginType (0, wxSCI_MARGIN_NUMBER);
SetMarginWidth (0, TextWidth(wxSCI_STYLE_LINENUMBER, "_99999"));
SetMarginWidth (1, 0);
SetMarginWidth (2, 0);
StyleSetForeground (wxSCI_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
//Default colours
StyleSetForeground (wxSCI_STYLE_DEFAULT, wxColour (_T("DARK GREY")));
StyleSetForeground (wxSCI_STYLE_INDENTGUIDE, wxColour (_T("DARK GREY")));
//Set the fontface of the text
wxFont font(10, wxSWISS, wxNORMAL, wxNORMAL, FALSE, wxT("Courier New"));
for (int i = 0; i < 34; i++)
{
StyleSetFont (i, font);
}
SetTabWidth (4);
SetUseTabs (true);
SetTabIndents (true);
SetBackSpaceUnIndents (true);
//And do our lexer
SetLexer(wxSCI_LEX_SQL);
}
void query::queryctrl::OnCharAdded (wxScintillaEvent &event)
{
//And do our lexer
SetLexer(wxSCI_LEX_CPP);
char chr = event.GetKey();
int currentLine = GetCurrentLine();
// Change this if support for mac files with \r is needed
if (chr == '\n')
{
int lineInd = 0;
if (currentLine > 0)
{
lineInd = GetLineIndentation(currentLine - 1);
}
if (lineInd == 0) return;
SetLineIndentation (currentLine, lineInd);
GotoPos(PositionFromLine (currentLine) + lineInd);
}
}