Download (GitHub.com)
-------------------------------------------------------------------------------
This is a wrapper for the amazing Scintilla Component. All basic functionality is there. I will be adding custom documentation soon but for now you will have to check the info on www.Scintilla.org.
I did however provide some usage examples in the download and you an check some of the most interesting below.
Important Note:
You need the Dll file to work with this wrapper. You can compile your own (if you have experience with c++) or you can use the one i compiled which has the Autohotkey Lexer included.
To download the official one go tohttp://www.scintilla.org and download SciTe. The SciLexer.dll included there is the only official compiled binary available.
This wrapper creates an object.
Syntax
sci := new scintilla(hParent, [x, y, w, h, DllPath, Styles])
Parameter Description
hParent - Hwnd of the parent control who will host the Scintilla Component
x - x position for the control (default 5)
y - y position for the control (default 5)
w - Width of the control (default 590)
h - Height of the control (default 390)
DllPath - Path to the SciLexer.dll file, if omitted the function looks for it in *a_scriptdir*
Styles - List of window style variable names separated by spaces.
The WS_ prefix for the variables is optional.
Full list of Style names can be found at
<http://msdn.microsof.../czada357.aspx>
Returns:
HWND - Component handle.
Basic Usage
#include ..\SCI.ahk #singleinstance force ;--------------------- ; This script adds a component with default values. ; If no path was specified when creating the object it expects scilexer.dll to be on the script's location. ; The default values are calculated to fit optimally on a 600x400 GUI/Control Gui +LastFound sci := new scintilla(WinExist()) Gui, show, w600 h400 return GuiClose: exitapp
Basic Highlighting Example
#include ..\SCI.ahk #singleinstance force ;--------------------- ; This is an example of how to select a Lexer located in a scintilla dll and make some basic highlighting. ; In this example we will select the AutoHotkey Lexer. Keywords are to be added manually so we will add some random words. ; ; The idea is to first select which lexer to use (specially if scilexer.dll has more than one) with SetLexer(lexNum) ; Then you can add some keywords to the keyword lists which will be colored as soon as they appear. ; Finally you can change the Font properties with StyleSetXXXX functions in this case I changed the color of the styles. Gui +LastFound sci := new scintilla(WinExist()) sci.SetWrapMode(true), sci.SetLexer(2), sci.StyleClearAll() sci.SetKeywords(0, "msgbox true another testing") sci.StyleSetBold(11, true) sci.StyleSetFore(11, 0x0000FF) ; Style No. 11 Belongs to SCE_AHK_WORD_CF in this particular lexer which is linked to the Keyword list No. 0 above. sci.SetText(unused, "Start Typing here and add some of the words from line 16`nFeel free to add more words to the list.") Gui, show, w600 h400 return GuiClose: ExitApp
Scintilla Notifications
#include ..\SCI.ahk
#singleinstance force
/*
---------------------
In this example we will catch the scintilla notifications.
For that we just have to set the variable sciObj.notify with the name of a custom function which will be called
whenever a scintilla message is sent.
There are some variables in the main object that are set by different messages. Please read the code for information on this.
*/
Gui +LastFound
sci := new scintilla(WinExist())
; Set some options
sci.SetWrapMode(true), sci.Notify := "Notify" ; The notify option tells the wrapper which function to call when WM_NOTIFY is sent
Gui, Show, w600 h400
return
GuiClose:
ExitApp
Notify(wParam, lParam, msg, hwnd, obj){
if (obj.scnCode = SCN_CHARADDED)
tooltip % chr(obj.ch) ; obj is in this case the scintilla object above. The obj.sc variable contains the latest character added to the control
return
}
For those wanting to play with the Autohotkey lexer here is some info on the styles that deal with it and an example of how to set some basic lexer highlighting colors.
AutoHotkey Lexer
val SCE_AHK_DEFAULT=0
val SCE_AHK_COMMENTLINE=1 (normal comment with semi-colon [;])
val SCE_AHK_COMMENTBLOCK=2 (block of comment with dash asterisk sequences [/* */])
val SCE_AHK_ESCAPE=3 (escape sequences with the back tick [`n `t `s])
val SCE_AHK_SYNOPERATOR=4 (these are considered syn operators: , %% [] + -= *= /= :=)
val SCE_AHK_EXPOPERATOR=5 ( these are exp<b></b>ression operators: - * ** / // ~ & << >> . () < > <= >= = == <> && ||)
val SCE_AHK_STRING=6 (quoted strings ["this is a string"])
val SCE_AHK_NUMBER=7
val SCE_AHK_IDENTIFIER=8 (whatever is enclosed in percent signs [%myvar%])
val SCE_AHK_VARREF=9 (Variable reference)
val SCE_AHK_LABEL=10 (a word followed by a colon [Label])
These here are keyword lists... you can set up the lists however you want but you have to link the list to the correct style below:
val SCE_AHK_WORD_CF=11 (Control Flow [if, else, break, continue] List)
val SCE_AHK_WORD_CMD=12 (Command [msgbox, winactivate] List)
val SCE_AHK_WORD_FN=13 (Functions [RegexMatch, Chr, Asc] List)
val SCE_AHK_WORD_DIR=14 (Directives [#noenv, #ifwinactive] List)
val SCE_AHK_WORD_KB=15 (Keyboard keys [Lbutton, Down, Up, Delete] List)
val SCE_AHK_WORD_VAR=16 (Variables [a_desktop, a_scriptdir] List)
val SCE_AHK_WORD_SP=17 (Special keywords [Byref, ahk_id] List)
val SCE_AHK_WORD_UD=18 (User Defined list)
val SCE_AHK_VARREFKW=19 (built in variables [a_desktop, a_scriptdir])
val SCE_AHK_ERROR=20 (not valid autohotkey syntax)
And this is a quick example how i set up the Autohotkey syntax in my AutoHotkey Toolkit script:
Loop, % sci.MaxIndex() ; I have an array with 5 scintilla components, this sets them all to the same Lexing values.
{
cObj := a_index
sci[cObj].SetLexer(2) ; SCLEX_AHK
sci[cObj].SetWrapMode(SC_WRAP_WORD)
; Setting up default font options
sci[cObj].StyleSetFont(STYLE_DEFAULT, "Courier New"), sci[cObj].StyleSetSize(STYLE_DEFAULT, 10)
sci[cObj].StyleSetBold(STYLE_DEFAULT, true), sci[cObj].StyleClearAll()
; Setting up the keywords:
Loop 7
{
listNum:=a_index-1
sci[cObj].SetKeywords(listNum, (listNum = 0 ? options.selectSingleNode("//LiveCode/Keywords/FlowControl").text
: listNum = 1 ? options.selectSingleNode("//LiveCode/Keywords/Commands").text
: listNum = 2 ? options.selectSingleNode("//LiveCode/Keywords/Functions").text
: listNum = 3 ? options.selectSingleNode("//LiveCode/Keywords/Directives").text
: listNum = 4 ? options.selectSingleNode("//LiveCode/Keywords/Keys").text
: listNum = 5 ? options.selectSingleNode("//LiveCode/Keywords/BuiltInVars").text
: listNum = 6 ? options.selectSingleNode("//LiveCode/Keywords/Parameters").text))
}
sci[cObj].StyleSetFore(STYLE_LINENUMBER,0x8A8A8A), sci[cObj].StyleSetBold(STYLE_LINENUMBER, false)
; Setting up AHK lexer colors:
bold := "0|1|2|4|5|6|7|8|9|17"
colors=
(LTrim Join| c
0x000000 ; SCE_AHK_DEFAULT
0x007700 ; SCE_AHK_COMMENTLINE
0x007700 ; SCE_AHK_COMMENTBLOCK
0xFF0000 ; SCE_AHK_ESCAPE
0x000080 ; SCE_AHK_SYNOPERATOR
0x000080 ; SCE_AHK_EXPOPERATOR
0xA2A2A2 ; SCE_AHK_STRING
0xFF9000 ; SCE_AHK_NUMBER
0xFF9000 ; SCE_AHK_IDENTIFIER
0xFF9000 ; SCE_AHK_VARREF
0x0000DD ; SCE_AHK_LABEL
0x0000DD ; SCE_AHK_WORD_CF
0x0000DD ; SCE_AHK_WORD_CMD
0xFF0090 ; SCE_AHK_WORD_FN
0xA50000 ; SCE_AHK_WORD_DIR
0xA2A2A2 ; SCE_AHK_WORD_KB
0xFF9000 ; SCE_AHK_WORD_VAR
0x0000DD ; SCE_AHK_WORD_SP
0x00F000 ; SCE_AHK_WORD_UD
0xFF9000 ; SCE_AHK_VARREFKW
0xFF0000 ; SCE_AHK_ERROR
)
Loop, Parse, colors, |
sci[cObj].StyleSetFore(a_index-1, a_loopfield)
Loop, Parse, bold, |
sci[cObj].StyleSetBold(a_loopfield, false)
sci[cObj].StyleSetItalic(15, true) ; SCE_AHK_WORD_KB
}
I will add more examples to the folder and a more comprehensive documentation.
This component has literally hundreds of functions so there is a LOT of work to be done still, so please post your questions here or check the documentation linked above and have fun!




