wxScintilla Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

wxScintilla

Post by lowjoel » 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:

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

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Sat Oct 29, 2005 8:20 am

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
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Sat Oct 29, 2005 8:35 am

isnt the SQL lexer predefined?

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Sat Oct 29, 2005 8:44 am

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
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Sat Oct 29, 2005 8:46 am

its built into wxScintilla, i thought...

wxuser
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Feb 25, 2005 5:45 am
Location: India

Post by wxuser » Sat Oct 29, 2005 11:08 am

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

Post Reply