Scintilla TextArea replacement (WIP)

BlitzMax Forums/MaxGUI Module/Scintilla TextArea replacement (WIP)

klepto2(Posted 2009) [#1]
Hi, maybe some of you remember my posted linenumbering screen in the maxide CE thread. Well why to reinvent the wheel if there are alternatives :)


Screen:



it works exactly like the Textarea gadget but also offers everything scintilla does plus a Blitzmax lexer ;)

Currently i'm in the final stage, so next week i will have a download ready :)


[Edit]
Direct Download : http://code.google.com/p/scintillabmx/downloads/list
SVN : http://scintillabmx.googlecode.com/svn/trunk/
Latest Version: Revision 9 http://scintillabmx.googlecode.com/files/ScintillaRev9.zip
[/Edit]


Ked(Posted 2009) [#2]
Looks good!

Cross-platform?


degac(Posted 2009) [#3]
From the home page of Scintilla's project I read
A free source code editing component for Win32 and GTK+
...so no cross-platform unfortunately.


See my post below, Ked pointed me to the 'truh' (...or - in another way - I need to read carefully all the text...)


Ked(Posted 2009) [#4]
From the home page of Scintilla's project I read <Insert Quote Here> ...so no cross-platform unfortunately.

Actually, I heard from Brucey that it runs on Mac also.

EDIT: Also, here:
Version 1.74 runs natively on OS X.

Also on the front page of Scintilla's project. :)


degac(Posted 2009) [#5]

Also, here:
Version 1.74 runs natively on OS X.

Also on the front page of Scintilla's project. :)


Oh!!! This is a GOOD news!
Thank you!


Ked(Posted 2009) [#6]
Glad I could help.


JoshK(Posted 2009) [#7]
It's next week now.


Grisu(Posted 2009) [#8]
Linenumbering for the default ide would be great...


Ked(Posted 2009) [#9]
It's next week now.

?


klepto2(Posted 2009) [#10]
Hi, sorry for the delay. I was on a small boat trip.

Currently it is win only. It would be really nice if it goes multiplattform but as I don't have a mac and as far as i know it only works via gtk on linux I need to find others to built it into maxgui for those plattforms.

A short status report:

Scintilla Version used: 1.79 + modified Blitzbasic Lexer to support Blitzmax
TextArea compatibility: 99% just printing isn't working at the moment
Added Event_GADGETACTION to return an event containing Scintilla Notification Data.

The code will be available next week. (Maybe via GoogleCode)

thx for the feedback :)


xlsior(Posted 2009) [#11]
Oooooooh. Interesting!


JoshK(Posted 2009) [#12]
Want.


klepto2(Posted 2009) [#13]
Hi

A first Version is now available here :

http://code.google.com/p/scintillabmx/

Today I will add SVN support and tidy up some things in the code.

The TScintillaGadget extends TWindowsGadget and is compatible to the TextArea gadget delivered by maxgui. It currently lacks of printing support as well as the event handling isn't managed like the original one. Currently there is only 1 event fired : EVENT_GADGETACTION which contains a TScintillaNotification object in the extra field.

And a small proof of concept image ;) MaxIDECE with Scintilla:




xlsior(Posted 2009) [#14]
Very interesting... Would love to see this in the community IDE.

Did notice one small bug: If you collapse a function at the very end of the source, it still keeps the 'end function' line visible, but when you collapse a function elsewhere those do disappear.


JoshK(Posted 2009) [#15]
Does anyone know how to disable the antialiasing? It does not look good in a code editor.


JoshK(Posted 2009) [#16]
I think it's just due to the weird Blitz color scheme.

Here is my sample:



jsp(Posted 2009) [#17]
This looks really nice.
Nevertheless it crashes here when i run the sample.bmx and copy paste several times some text(wanted to get some text in to see how fast the highlight works).
It just says process complete. :(
Only once it stopped at the WaitEvent() command, but i can't reproduce it. The crash itself was always reproducable after some copy and paste. With bigger text i had the feeling it was earlier.


xlsior(Posted 2009) [#18]
I also got an 'application stopped responding' error after expanding/collapsing a bunch of the nodes. :-/


JoshK(Posted 2009) [#19]
Are you using any callbacks with the lexer DLL? That could cause problems if not handled correctly.


Mark Tiffany(Posted 2009) [#20]
Nice one - I presume it's just a case of calling a new CreateScintillaTextArea first, then use all existing commands?

If so, very happy to add it is an optional (and probably default for windows) option into CE IDE code, like with turning on gtk or not.


klepto2(Posted 2009) [#21]
@Mark:
That is exactly the way to do. Due to its nature of being an extended TWindowsGadget you can use it with just replacing CreateTextArea with CreateScintillaArea. To get the highlighting cast it to TScintillaGadget and the you can access the additional options. It takes around 20 lines of code
to get it to work with linenumbers, folding and highlighting.

@Josh:
There are no callbacks, everything is handled via messaging.

@All:
the random crashes may be caused by a last minute fix I have done and scintilla hardly unforgives wrong parameters like wrong charpositions.


JoshK(Posted 2009) [#22]
This is one of the coolest things I have ever seen for MaxGUI. Maybe I will make my own code editor.


klepto2(Posted 2009) [#23]
hi, revision 4 is up and includes the following changes:

-The scintilla events(notifications) must now be handled by the user completely. eg previously MARGIN_CLICK was handled in the control.
-The internal eventsystem is now is handled like the standard textarea
eg: Eventfilter for Keys, GadgetMenu behaviour.
-several bugs fixed
-wrong selection
-ctd on folding (hopefully)
-and some other things



TODO:
-testing some behaviour doesn't work like the standard textarea. Notified in maxides manual undo/redo
-implement an easier communication system with scintilla
eg: instead of textarea.SendEditor(SCI_UNDO) it should be textarea.Undo()
- bug fixes ;)


xlsior(Posted 2009) [#24]
hi, revision 4 is up and includes the following changes:


Up where?

http://code.google.com/p/scintillabmx/downloads/list still shows that it was last uploaded 3 days ago...

EDIT: Nevermind, the SVN branch appears to contain the REV 4.


klepto2(Posted 2009) [#25]
thx, for the hint :)

I've edited the first post to include the link to the download and the SVN repo.


JoshK(Posted 2009) [#26]
In Windows XP this crashes as soon as it builds when the debugger is off. If the debugger is on, it crashes if the first thing I do is click on one of the fold nodes to collapse a section of code. I am using your sample code, with the latest version downloaded via SVN.


SebHoll(Posted 2009) [#27]
Just had a quick look and this is looking nice.

Have just tidied up the first few lines of TScintillaGadget which you might like to commit:

Type TScintillaGadget Extends TWindowsGadget
	
	Field _oldSelPos% , _oldSelLen% = 0
	Field readonly:Byte = False
	Field numbers:Byte = False
	Global _pagemargin# = 0.5
	
	Function Create:TScintillaGadget(x:Int = 0 , y:Int = 0 , w:Int = - 1 , h:Int = - 1 , group:TGadget = Null, style:Int = 0)
		
		If w = -1 Then w = ClientWidth(group)-x
		If h = -1 Then h = ClientHeight(group)-y
		Return New TScintillaGadget.Initialize(x,y,w,h,group,style)
		
	End Function
	
	Method Initialize:TScintillaGadget(x:Int, y:Int, w:Int, h:Int, group:TGadget, style:Int)
	
		Local	wstyle:Int, hwnd:Int, parent:Int
		
		Self.style = style
		wstyle=WS_CHILD|WS_TABSTOP|WS_CLIPSIBLINGS
		parent=group.query(QUERY_HWND_CLIENT)
		hwnd=CreateWindowExW(0,"Scintilla","",wstyle,0,0,0,0,parent,0,GetModuleHandleW(Null),Null)				
		Register GADGET_TEXTAREA,hwnd
		
		_SetParent group
		SetShape(x,y,w,h)
		SetShow(True)
		Sensitize()
		
		SendEditor (SCI_SETMODEVENTMASK , SC_MODEVENTMASKALL)
		
		Return Self		
		
	EndMethod



klepto2(Posted 2009) [#28]
thx will look it later after work :)


klepto2(Posted 2009) [#29]
@SebHoll: thx, I have commited the changes.

I have also disabled the autolist(intellisense) function as well as the single undostep approach. Tested on a XP virtual machine without crashing.

Feedback highly needed :) especially from XP users.


thx in advance


jsp(Posted 2009) [#30]
I just checked out the latest changes and it works quite good (XP SP2).

I can now paste 100.000 lines of code without problems and also the highlight is very fast (2 sec. On my machine).

It didn't crash at all for me during testing. Only one thing I noticed which is may not a bug, but I didn't expect: When you highlight some text and your cursor is above or underneath those lines and you press the right mouse button to get the popup menu, it clears your selection. The selection stays when you right click on the highlighted lines!

And I found some debugstop concerning font handling...

Is it possible to add the Rem – End Rem to the folding?


JoshK(Posted 2009) [#31]
With your latest upload, the sample program no longer crashes when I click on the open/close nodes on the left side. I am testing on WinXP with SP3.


Bremer(Posted 2009) [#32]
This would be very nice for either the official IDE or the CE. I took at look at making a module like this but gave up after a while, glad to see someone staying the distance because scintilla would really improve the current freely available blitzmax IDEs.


xlsior(Posted 2009) [#33]
No kidding...


klepto2(Posted 2009) [#34]
Thx for the feedback and help to find the bug.

Hopefully the bug is fixed :) new Revision up and also a new
download package containing the actual source + dll.

http://scintillabmx.googlecode.com/files/ScintillaRev9.zip

thx again.


EOF(Posted 2009) [#35]
Very nice work so far Klepto!!

Couple of things:

1)
Ctrl + A to select all the code brings up the command box (With the command "SuperStrict" showing)
The box appears very high above the main window (depending how far down in the code you are)

What control do you have over this command box?
Can you, for instance, change things so that the box only appears after 3 chars have been entered?

The reason I ask, I see many instances of the text box flickering as I type stuff in. Try ======== for example

In fact, the popup box is somewhat annoying (sorry)
Try this for example:

Where you have False; in the code example:

> Position the cursor after the ;
> Press backspace to delete the ;
> The popup box appears showing False

Now its not easy to close this box. RETURN and ESCAPE both fail
I have to click away from the line(!)


2)
Switching from INSERT mode to OVERTYPE mode turns the cursor into a tiny underscore which changes size according to the character at the cursor position. Can this change to a thicker version of the standard INSERT mode cursor character instead?

3)
Can Function keys be detected under Scintilla?
For example, pressing F1 over a command to get help(?)


klepto2(Posted 2009) [#36]
1)
The 'command' window is just an experimantal demonstration in the sample. You can handle the appeariance as you wish. eg Filter the keywords, provide field types etc.

2) need to check out this by myself ;)

3) yes, take a look at the filter function. the gadget throws the same events as the standard textarea + one additional where the scintilla messages can be handled.

also keep in mind that this is still work in progress and a lot of things need to be sorted out in the next days/weeks.


EOF(Posted 2009) [#37]
Klepto

How's things looking regarding the font changing?
I tried it with the sample code commenting out the DebugStop but it hangs the demo

Also, how do you control what parts of the code are foldable?
In other words, how do you say to Scintilla, "ok, any lines starting with Function are foldable"

How easy would it be to adapt the code to C++ / Java where {} are foldable for instance?
I see there are tons of options in there. Looks like Scintilla is really flexible

By the way I have adapted the SAMPLE code here so that you can load other Blitz code samples (for testing Scintilla with):



klepto2(Posted 2009) [#38]
Hi Jim,

thx for the feedback.
Now Step by Step ;)

1. Font Changing works, depends if you use a modified maxgui (the release candidate on the top of this forum with my FontRequest modification). The reason for the hang is simple : I have a forgotten a Debugstop within the SetFont Method ;)

2. Scintilla is flexible thats right, but on some parts it isn't that flexible. Scintilla is based on custom lexers for each language which are normally included directly in the dll. It is also possible to import plugin dlls via runtime and use these.

the Blitzmax lexer for instance is located in the c++ src file: lexbasic.cxx

There you have this function:


There you can add the regions you want. But you need to recompile Scintilla with VS or mingw.

There are a lot of other languages already implemented. For details take a look in Scintilla_consts.bmx. For nearly every language there is are also defined constants for eg function or comments etc.

For everything else you need to look at this point: http://www.scintilla.org/ScintillaDoc.html


REDi(Posted 2009) [#39]
Excellent work klepto2, scintilla's working great and so is your lexer!

quick tip, how to use the direct function messaging...
Type TScintillaGadget Extends TWindowsGadget

	Field SendMessageDirect:Int(directPointer:Int,msg:Int,wp:Int,lp:Int)
	Field SCI_DIRECTPOINTER:Int
...

	Method Initialize:TScintillaGadget(x:Int, y:Int, w:Int, h:Int, group:TGadget, style:Int)
...

		hwnd=CreateWindowExW(0,"Scintilla","",wstyle,0,0,0,0,parent,0,GetModuleHandleW(Null),Null)
		SendMessageDirect = Byte Ptr(SendMessageW(hwnd, SCI_GETDIRECTFUNCTION, 0, 0))
		SCI_DIRECTPOINTER = SendMessageW(hwnd, SCI_GETDIRECTPOINTER, 0, 0)
...

	Method SendEditor:Int(Msg:Int , wParam:Int = 0 , lParam:Int = 0)
		Return SendMessageDirect(SCI_DIRECTPOINTER, msg, wparam, lParam)
	End Method


Just spent a while and got this statically built into a module, if you want the codes klepto :)


klepto2(Posted 2009) [#40]
thx ready. I already know this code (well not exactly the same code). I didn't know this works also with the windows version. Maybe this is one step to have the scintilla multiplattform (Cocoa, GTK and Win).

Currently I'm just using the sendmessage system provided by windows.

I think for a real crossplattform solution it might be the best to add a complete new control instead of having a textarea simulation module to get the full power of scintilla.

What do you guys think about this?

Also currently i'm using the dll, would it be possible to just compile the src code of scintilla directly with bmx and link it? That would make later shipping on multiple plattforms a lot easier.


thx in advance


JoshK(Posted 2009) [#41]
This no longer works with MaxGUI 1.34.


klepto2(Posted 2009) [#42]
thx Leadwerks. I'm already working on this issue. Maybe SebHoll can jump into this and tell me what has changed in maxgui so it breaks my code.


klepto2(Posted 2009) [#43]
Good News :)

Problem with the new maxgui has been solved and i have uploaded a new Version.

The main change in this release is that the control is 'splitted' into 2 parts:
- the control itself
- and a scintilla interface

you get the scintilla interface by eg: textarea.GetScintilla()

I have decided to do this because code may be a bit cleaner and i can have the same names as scintilla has without colliding with maxgui names.

The lib is also prepared to be a module in the future, so you may notice a lot of documentation within the Tscintilla Type.

But now have fun :) and post any bug you find.

http://scintillabmx.googlecode.com/files/ScintillaBMX.zip

PS: This release is a new structured version and not currently not in the SVN.


JoshK(Posted 2009) [#44]
Here's another shot of this excellent code in action. I want to see this incorporated into the BlitzMax IDE!!!




slenkar(Posted 2009) [#45]
looks good man


xlsior(Posted 2009) [#46]
Scintilla in the IDE really would be very nice... Code folding is really the major feature that the IDE is missing in my book.


klepto2(Posted 2009) [#47]
Hi guys.

Just a small progressreport:

- some minor fixes done
- around 50% of the scintilla messages are wrapped and documented
- started a Helper Class with various functions to help using scintilla

and now I have a special surprise:
(big thx to YellowRider)



You can guess yourself what this image means :)

As soon as everything is stable i will recreate the subversion and upload a new Version. No ETA yet but it should not be that far away.


plash(Posted 2009) [#48]
You can guess yourself what this image means :)
It means there is still no Linux version?

I hate FLTK :(


Ked(Posted 2009) [#49]
I got really excited when I saw the Mac screenshot! Now just to settle the Linux problem...


Difference(Posted 2009) [#50]
Looking good! OS X version is much appreciated.


theHand(Posted 2009) [#51]
After you have all of this working well, why not take a look at wxScintilla?
I thought so.


xlsior(Posted 2009) [#52]
After you have all of this working well, why not take a look at wxScintilla?


Brucey already has a wxScintilla mod as part of this wxwidgets framework.

Unfortunately the entire wx-framework is massive though -- I'd greatly prefer a non-wx implementation like Klepto's myself.


outsider(Posted 2009) [#53]
Hi,
can you make MaxIDE CE + Scintilla .exe program? It's looks nice, but I don't have MaxGUI :/.


klepto2(Posted 2009) [#54]
I will do as soon as I have time and have a stable enough version.

currently I don't have much time for coding private things so everything takes longer till it is finished.


outsider(Posted 2009) [#55]
Thank you klepto2 :)


xlsior(Posted 2010) [#56]
Any more progress on this?


ima747(Posted 2010) [#57]
another bump, I would kill for an updated CE edition with depth markers let alone collapsing...


TomToad(Posted 2010) [#58]
I tried compiling the sample.bmx and I am getting an error "Overriding method differs by type " on line 49 of ScintillaCtrl.bmx. Tried Rev9 as well as the SVN versions.


ker2x(Posted 2010) [#59]
Is this project dead ?
I'm still wondering if i should use Brucey's wxMax (it include a scintilla module) or this module with MaxGUI.


TomToad(Posted 2010) [#60]
That's what I'm wondering as well. I tried wxMax version of Scintilla, but I can't seem to get it to work. This looks like it would be a better solution for me, but doesn't seem to want to compile, possibly due to changes in MaxGUI.


klepto2(Posted 2010) [#61]
Sorry for the delay.

I have uploaded a 1.41 compatible Version at googlecode.

http://code.google.com/p/scintillabmx/downloads/list

I hope this helps you.

Unfortunatly the project is nearly dead. I don't have time to maintain it and i have also moved to other languages. But i will try to get it at least to a final and stable version (adding missing methods etc.).


popcade(Posted 2010) [#62]
Hi, klepto

Would you mind release the Console Module source? this mod is really useful but I can't get it work on BMax 1.41....

Last edited 2010


TomToad(Posted 2010) [#63]
Klepto,

Thanks a lot. Works great. I did notice a little bug in the sample though. When you type Superstrict on the first line, the autocomplete pops up and the Enter key will not be accepted. You need to either press the space key or click on the autocomplete. Won't be a big problem for me since I don't need the autocomplete anyway.


MOBii(Posted 2014) [#64]
Love you klepto2 I just got the: sample advanced.bmx to work, and start replace the TGadget textarea to Scintilla in my project now!
Only this is a reason why to buy BlitzMax, I am indeed very exited <3


MOBii(Posted 2014) [#65]
I have 2 questions:

Question 1:
How can I turn Character representations OFF?
http://www.scintilla.org/ScintillaDoc.html#CharacterRepresentations

Question 2:
I seen Scintilla as mod:
Import wx.wxScintilla
Import wx.wxFrame
Where can I download wx.wxScintilla?

https://code.google.com/p/scintillabmx/downloads/list

I use the no module .rar
https://code.google.com/p/scintillabmx/downloads/detail?name=Scintilla.rar&can=2&q=
Scintilla bmx 1.41 compatible (Import only / no module)


Derron(Posted 2014) [#66]
wx - like in wxMAX (a wrapper for wxWidgets).


bye
Ron


Dabhand(Posted 2014) [#67]
I built an editor using wxMax... It was monkey at a typewriter setup, but it worked fine... So, just in case you want a reference, you'll find the code here...

http://sourceforge.net/p/bamboobasic/code/ci/master/tree/Editors/Win/Editor/

Dabz


JoshK(Posted 2014) [#68]
I'm using this in Leadwerks now, including the Linux build, and it's really good.