Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Wrapper] Scintilla Wrapper v1.4.2.4


  • Please log in to reply
122 replies to this topic
RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010
------------[Scintilla Wrapper v1.4.2.4]----------------------------------
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!
AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012
Finally, been waiting for this, I'm using the old Scintilla wrapper(SCI.ahk). I'll definitely check this out. Thanks!

Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012
The "3-add_intab.ahk" is not working for me, the second tab is empty.

  • Guests
  • Last active:
  • Joined: --
thanks you very much for this wrapper! 8-)

RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010

The "3-add_intab.ahk" is not working for me, the second tab is empty.


It is working as intended. I made it so that one tab was empty and one had the control.
Actually faking it, since Im just showing/hiding the control...

:p

thanks you very much for this wrapper! 8-)


No problem man, everything to make my life and other people's lives easier :)
AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

It is working as intended. I made it so that one tab was empty and one had the control.
Actually faking it, since Im just showing/hiding the control...


Oh..great! Thanks, now I can continue my project with the help of your wrapper. Many thanks again, looking forward to the updates.

  • Guests
  • Last active:
  • Joined: --

Advanced Highlighting Example[/size] [Thanks to random @Guest for the idea]

Thanks, just what I was looking for, I'll start playing around with it. Good work.
8-) Posted Image

  • Guests
  • Last active:
  • Joined: --
BUG Report #1 In example 8-lex_advancedhighlight.ahk you will get an error from line 416 in SCI.ahk if the text you search for has a . % \ / ^ # @ etc in it, because of the line above doesn't check for these:
if (instr(var, a_space) || instr(var, "`n") || instr(var, "-")) ; if it has spaces or newlines
if you change that to something like if (RegExMatch(var,"i)[a `n-\.%,(\\\/]=&^")) it will solve it but you need to add all other forbidden chars to it []{};:, etc as well ....

  • Guests
  • Last active:
  • Joined: --
No idea how the stray "a" got in there above but should be something like if (RegExMatch(var,"i)[ `n-\.%,(\\\/=&^]")) of course :oops:

RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010
Thank you very much @Guest!

that regex makes sure that the thing is a valid variable name, which i was planning to fix at some point but got distracted with scintilla structs. :D

I am glad you did this!
AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

  • Guests
  • Last active:
  • Joined: --
Look forward to more documentation :D

RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010
In this version all scintilla variables are super-global by default (will see if it will stay that way, but for now i like the simplicity it brings to my coding).

no need to put quotation marks around them anymore:

sci.SetLexer(SCLEX_CONTAINER)
sci.SetStyling(10, STYLE_DEFAULT)


instead of:

sci.SetLexer("SCLEX_CONTAINER")
sci.SetStyling(10, "STYLE_DEFAULT")


And I added the super-global variable unused which you can use for some of the scintilla functions that have parameters which are not used. I put it there for clarity because sci.SetText(0,"text") might be confusing since some functions like sci.AddText() require the first parameter to be the length of the text.

So for readability: sci.SetText(unused, "text") is way clearer than sci.SetText(0,"text") or even sci.SetText(false, "text").

Scintilla Wrapper v1.4.2.2
Date: Mon Oct 22 12:50:00 2012 +0200


Changes:

+ Add onMessage notify example
+ Add classes that emulate scintilla structures
+ Add notify functionality for use with OnMessage()
+ Add option to use function by id and not by name

e.g. sci.2268(true) or sci.SetWrapMode(true)
Both would do the same thing. Shorter code vs Readability, you choose.
- Remove scintilla variables from __SCI()
- Remove __Add() function msgHandler parameter


* Change move all scintilla variables to super-global namespace
^ Update examples


! Fix __SCI() check for valid variable name
! Fix sciObj.Add to store handle in __SCI() function


Todo:

+ Add support for messages that use structures
+ Add Documentation


AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

hoppfrosch
  • Members
  • 399 posts
  • Last active: Feb 26 2016 05:31 AM
  • Joined: 25 Jan 2006

The "3-add_intab.ahk" is not working for me, the second tab is empty.

It is working as intended. I made it so that one tab was empty and one had the control.
Actually faking it, since Im just showing/hiding the control...
:p


Not quite - running example with AHK 1.1.8.01 Unicode 64bit on Win7 SP1 64bit BOTH TABS ARE EMPTY... :(

Also with example 9-ntf_basicnotification.ahk no tooltip is shown (within same environment as above) ...

RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010

Not quite - running example with AHK 1.1.8.01 Unicode 64bit on Win7 SP1 64bit BOTH TABS ARE EMPTY... :(

Also with example 9-ntf_basicnotification.ahk no tooltip is shown (within same environment as above) ...


You only mentioned having troubles with examples #3 and #9. Are all other examples working fine?
AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

hoppfrosch
  • Members
  • 399 posts
  • Last active: Feb 26 2016 05:31 AM
  • Joined: 25 Jan 2006
As far as I can judge yet, they seem to work fine ...