wxScintilla - max highlighing

BlitzMax Modules Forums/Brucey's Modules/wxScintilla - max highlighing

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I've only got as far as creating the skeleton lexer (copied from another one), which should give some basic highlighting.
But... I haven't actually tried it yet :-p

However, I am using highlighting with my SQL app, and it's working great.

Here are some code snippets I'm using to get it working, based on wxCodeGen generating the basic stuff :

The codegen block:
		txtEditor = New wxScintilla.Create(m_panel1, wxID_ANY)

		txtEditor.SetUseTabs( True )
		txtEditor.SetTabWidth( 4 )
		txtEditor.SetIndent( 4 )
		txtEditor.SetTabIndents( True )
		txtEditor.SetBackSpaceUnIndents( True )
		txtEditor.SetViewEOL( False )
		txtEditor.SetViewWhiteSpace( False )
		txtEditor.SetMarginWidth( 2, 0 )
		txtEditor.SetIndentationGuides( False )
		txtEditor.SetMarginWidth( 1, 0 )
		txtEditor.SetMarginType( 0, wxSCI_MARGIN_NUMBER )
		txtEditor.SetMarginWidth( 0, txtEditor.TextWidth( wxSCI_STYLE_LINENUMBER, "_99999" ) )
		txtEditor.MarkerDefine( wxSCI_MARKNUM_FOLDER, wxSCI_MARK_BOXPLUS )
		txtEditor.MarkerSetBackground( wxSCI_MARKNUM_FOLDER, New wxColour.CreateNamedColour( "BLACK" ) )
		txtEditor.MarkerSetForeground( wxSCI_MARKNUM_FOLDER, New wxColour.CreateNamedColour( "WHITE" ) )
		txtEditor.MarkerDefine( wxSCI_MARKNUM_FOLDEROPEN, wxSCI_MARK_BOXMINUS )
		txtEditor.MarkerSetBackground( wxSCI_MARKNUM_FOLDEROPEN, New wxColour.CreateNamedColour( "BLACK" ) )
		txtEditor.MarkerSetForeground( wxSCI_MARKNUM_FOLDEROPEN, New wxColour.CreateNamedColour( "WHITE" ) )
		txtEditor.MarkerDefine( wxSCI_MARKNUM_FOLDERSUB, wxSCI_MARK_EMPTY )
		txtEditor.MarkerDefine( wxSCI_MARKNUM_FOLDEREND, wxSCI_MARK_BOXPLUS )
		txtEditor.MarkerSetBackground( wxSCI_MARKNUM_FOLDEREND, New wxColour.CreateNamedColour( "BLACK" ) )
		txtEditor.MarkerSetForeground( wxSCI_MARKNUM_FOLDEREND, New wxColour.CreateNamedColour( "WHITE" ) )
		txtEditor.MarkerDefine( wxSCI_MARKNUM_FOLDEROPENMID, wxSCI_MARK_BOXMINUS )
		txtEditor.MarkerSetBackground( wxSCI_MARKNUM_FOLDEROPENMID, New wxColour.CreateNamedColour( "BLACK" ) )
		txtEditor.MarkerSetForeground( wxSCI_MARKNUM_FOLDEROPENMID, New wxColour.CreateNamedColour( "WHITE" ) )
		txtEditor.MarkerDefine( wxSCI_MARKNUM_FOLDERMIDTAIL, wxSCI_MARK_EMPTY )
		txtEditor.MarkerDefine( wxSCI_MARKNUM_FOLDERTAIL, wxSCI_MARK_EMPTY )
		txtEditor.SetSelBackground( True, wxSystemSettings.GetColour( wxSYS_COLOUR_HIGHLIGHT ) )
		txtEditor.SetSelForeground( True, wxSystemSettings.GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) )


Keywords (a loooong string) :
Const SQL_KEYWORDS:String = "absolute action add admin after aggregate " + ..
	"alias all allocate alter and any are array as asc " + ..
.. etc


Some implementation :
		Local font:wxFont = New wxFont.CreateWithAttribs(10, wxTELETYPE, wxNORMAL, wxNORMAL)
		
		txtEditor.SetLexer(wxSCI_LEX_SQL)
		txtEditor.SetKeywords(0, SQL_KEYWORDS)

		txtEditor.StyleSetFontFont(wxSCI_STYLE_DEFAULT, font)

		txtEditor.StyleClearAll()

		txtEditor.StyleSetForeground( wxSCI_SQL_COMMENT, New wxColour.Create(0, 200, 0))
		txtEditor.StyleSetForeground( wxSCI_SQL_COMMENTLINE, New wxColour.Create(0, 200, 0))
		txtEditor.StyleSetForeground( wxSCI_SQL_COMMENTDOC, New wxColour.Create(0, 200, 0))
		txtEditor.StyleSetForeground( wxSCI_SQL_NUMBER, New wxColour.Create(180, 0, 180))
		
		txtEditor.StyleSetForeground( wxSCI_SQL_WORD, New wxColour.Create(0, 0, 200))
		'txtEditor.StyleSetBold(wxSCI_SQL_WORD, True)
		
		txtEditor.StyleSetForeground( wxSCI_SQL_STRING, New wxColour.Create(180, 0, 0))


These two lines :
txtEditor.SetLexer(wxSCI_LEX_SQL)
txtEditor.SetKeywords(0, SQL_KEYWORDS)

are important. They tell wxScintilla what lexer to use, and give it the keywords to colour.

That's about as far as I've gone with it to date. It's a big, complicated beast, extremely powerful, but with lots to get your head around.

The developers say you should look at the SciTE source, which they say is a reference implementation of Scintilla. Which is all very well if you can work out what's going on!

Perhaps we can all work it out together ;-)