TheArkive / scintilla_ahk2

Scintilla class wrapper for AHK v2
MIT License
7 stars 6 forks source link

scintilla_ahk2

Scintilla class wrapper for AHK v2

Scintilla.dll

Go to the Scintilla site to get the DLL. Here is the download page for SciTE.

Direct Links:

Pick your desired 32-bit or 64-bit version for download. Unzip and copy over the Scintilla.dll from the unzipped folder into the same folder as the script. You can of course place the DLL anywhere, but make sure you modify the class lib in Static __New() to point to the proper DLL location.

Status

On to the next phase:

I've started to dabble in C. I wrote a DLL to handle the styling routine (source is of course included - CustomLexer.c). This includes 3 functions.

The main method that uses these is: wm_messages(wParam, lParam, msg, hwnd).

There are method wrappers of the same function names that employ these DLL functions.

I've used the following file as a test (thanks to marius - aka robodesign). This script is 2.16 MB in size and loads with syntax highlighting in currently just over a second (1.078 - 1.218 secs on my machine).

Test document link (this doc is included as test-script.ahk):

https://github.com/marius-sucan/Quick-Picto-Viewer/blob/master/quick-picto-viewer.ahk

NOTE: If you use LayoutCaching, you may get occasional slower load times (up to 14 seconds on test-script.ahk according to my tests). It's a bit random, but this never seems to happen with LayoutCache disabled. LayoutCache is mostly only useful if you need smoother performance when resizing the window (ie. not maximized). You will still get smooth scrolling with LayoutCache disabled.

Documentation

Making the documentation will be a lengthy work in progress...

For now all I can give is a general outline and some guidelines:

Below I will outline major features or major parts of the script class structure.


WM_NOTIFY callback

g := Gui()
ctl := g.AddScintilla(...)
ctl.callabck := my_func

my_func(ctl, scn) {
    ...
}

ctl is the Gui Control object, the Scintilla control. scn is the SCNotification struct as a sub-class.

scn Members:

hwnd\ id\ wmmsg\ wmmsg_txt <-- added text name of wm_notify msg\ pos\ ch\ mod\ modType\ text\ textPtr\ length\ linesAdded message\ wParam\ lParam\ line\ foldLevelNow\ foldLevelPrev\ margin\ listType\ x\ y\ annotationLinesAdded\ updated\ listCompletionMethod\ characterSource


Changing font/background colors and styles.

ctl.cust.{category}.{property}

Properties are as follows unless indicated otherwise:

ctl.cust.number    - 1234 and 0x1234ABCD
ctl.cust.comment1  - ; line comments
ctl.cust.comment2  - /* block comments */
ctl.cust.string1   - "string" 
ctl.cust.string2   - 'string'
ctl.cust.punct
ctl.cust.braceH    - brace highlight on cursor event (not yet implemented)
ctl.cust.braceHBad - mismatched brace style, this changes as you edit the doc
ctl.cust.brace     - matched brace style, this changes as you edit the doc
ctl.cust.selection (props: all props of Selection object)
ctl.cust.Caret     (props: all props of Caret object)
ctl.cust.margin    - this is the number margin
ctl.cust.editor    - default text color/style/background color

NOTE: When changing editor properties, you need to call ctl.Style.ClearAll() to apply those settings.

Set property values as if you were using the Style subclass:

the old way:

ctl.Style.ID    := 32       ; specify the ID before making changes
ctl.Style.Color := 0x00FF00 ; set a property

the new way:

ctl.cust.number.Color := 0x00FF00

NOTE:  The "old way" is still necessary when changing other user-defined styles,
and when applying style settings to other margins that are NOT the typical number
margin (which is usually margin 0).  Margin 0 can still be redefined to something
else, and if you choose to do so, you will want to use the "old way" for maximum
flexibility and access to all capabilities provided by the Scintilla library. 

Margins, Styles, EOL Annotations, and Markers

For margins, styles, EOL Annotations, and Markers, set the "active ID" like so:

obj.Style.ID := 34 ; make future calls to obj.Style.* apply to style #34

obj.Margin.ID := 2 ; make future calls to obj.Margin.* apply to margin #2

obj.EOLAnn.Line := 3 ; make future calls to obj.EOLAnn.* apply to line #3

obj.Marker.num := 4 ; make future calls to obj.Marker.* apply to marker #4
                    ; NOTE: All methods in the Marker subclass also take a markerNum parameter.
                    ; If you don't specify a markerNum, then the specified num is used.

Keyword Lists

ctl.SetKeywords(list1, list2, ..., list8)

    words should be separated by a space

ctl.cust.kw1.Fore := 0xAABBCC

    kw1 - kw8 are available to set.  You can set more than just color:
        properties: Back, Fore, Font, Size, Bold, Italic, Underline

Once you set the "active ID", future calls to these sub-classes will apply to the most recently set "ID" or "Line", or "marker number" respectively.

Current Changes

2021/08/29

new features

2021/08/27

bug fixes/new features

2021/08/26

minor changes

2021/08/25

Features:

2021/08/06

2021/05/17

2021/05/11

2021/05/05

To-Do List

I plan to still add the following categories / subclasses listed below. A crossed out item indicates that category of functions has been added.