Page 1 of 1

wxScintilla

Posted: Sat Oct 29, 2005 5:04 am
by lowjoel
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:

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);
	}
}
Miraculously, syntax highlighting never occurs

Posted: Sat Oct 29, 2005 8:20 am
by Jorg
Have you tried modifying an existing lexer ? I created one for wxCRP syntax highlighting and took the C++/H lexer as base for my own highlight.

Also make sure you have keywords defined in groups else the lexer does not know what to color what (which styles)..

- Jorgen

Posted: Sat Oct 29, 2005 8:35 am
by lowjoel
isnt the SQL lexer predefined?

Posted: Sat Oct 29, 2005 8:44 am
by Jorg
SQL?

I was talking about wxCRP.. :roll: or were you talking about SQL? anyway that would not be such a hard lexer I guess to write

- Jorgen

Posted: Sat Oct 29, 2005 8:46 am
by lowjoel
its built into wxScintilla, i thought...

Posted: Sat Oct 29, 2005 11:08 am
by wxuser
I am confused on what you are trying to do here.

If you are trying to add a new lexer, doing it in scintilla and updating wxScintilla is a better option. If you are trying to use a prebuilt lexer (yes SQL lexer is already there) for highlighting and folding, see prefs.cpp of sample app.

hope this helps

deez