Click here to Skip to main content
15,867,704 members
Articles / Programming Languages / C#

Scintilla Text component. Speed with over 600 commands

Rate me:
Please Sign up or sign in to vote.
2.37/5 (16 votes)
13 Mar 2013CPOL12 min read 52.5K   10   20   23
Scintilla Text component

Introduction

Unless you did some assembly programming, you are left in the dark about what enormous performance your PC can put on display (loading 80 Text files < 0.5sec). With that in mind, I intended to replace edit classes I have used in projects since these edits dragged the speed of applications to an unacceptable level, were hardly complete and did not provide standard facilities either. I happened to remembered that some years ago, I came along Scintilla. Scintilla is a code editor component with source for the event, another exotic extension is desired. The editor is written in C/C++ and can be built with VS 2010 or preferably Gcc. I got way more than I was begging for! The “component” exists since 1999, has over 200 contributors and is used in at least as many projects, some you likely came across already. The license permits use in any free project or commercial product.

Versions

Since Scintilla is intended for cross platform use, there are compilations for several platforms and plenty of wrappers for God knows what available. Considering Windows, there is a GTK+ and a genuine version. Pictures below show Scintilla in action, projects where the Scintilla component were built in.

Image 1      Image 2

The wrapped Scintilla showing some facilities after reimplementation:

Image 3

Well, true, you don’t see much of the source code here. This was not the aim. From up to down: The Code Snippet manager with an opened Snippet list followed by annotations which can be colored character by character. Sizable Arrow boxes in any desired color and size, with or without closure, movable or fixed, pointing up or down, filled with information and a title if indicated. Further right a Message Tree shows up. You are familiar with that as you debug in Visual Studio. Just the handling has improved a bit. Several multicolored small triangles are dropmarkers which can be used for any purpose. Further down call tips with or without arrows and highlight facility to display messages as an additional possibility. Support for regular expressions is activated in the Find Replace Mark dialog. It can be changed, as other modes too through clicking one of the multifunction buttons in the dialog. Found text is marked in the editor if a marker (32 are available) is set and if not then the whole line gets highlighted. Margins to the left of the editor, 5 are available, each configurable in any way, display line numbers, arrow symbols for text found at locations, bookmarks and much more. Last but not least, code folding. The bluish and light green vertical lines are used here as a bar to indicate parts of the code colorable freely for all sort of purposes. That is not all yet, this displays just a subset of what is available in the editor class. Certainly, the implemented printing support is rich in facilities too and about 98 command keys (shortcuts) are assigned to functions. All together, a very rich set of facilities, really fast and easy to use. The code for all these examples, merely a couple of lines each, can be found in the project.

Overview

Image 4

Terminology

As this project is built upon C/C++ and C# sources, terms from all these languages are used interchangeably.

Implementations

As already mentioned, there are a whole variety of implementations ready for download. The ones I have found for C# are either built against Framework 2, which becomes obvious after following some confusing error messages and or lack updating. Since the completion of the last C# wrapper, 274 changes (mainly functions & parameters) took place in the editor. So it is probably time for an update since the wrapper seems not to be maintained any longer. That is understandable by its size. The aim is to have a class which can be used in the form designer, can make use of direct access to the edit itself, supports single instance besides multiple edit instances, is built against framework 4 and is quick, full of facilities and appealing. The user interface needed a complete work over. It is questionable, perhaps not even desired, if a complete implementation with reasonable overhead is ever possible since the possibilities are next to endless. The edit class is stable despite various extensions which were added over time, what can be expected after such a long time developing. This might not hold true for the wrappers. It is not exaggerated that this class leaves the most similar projects simply in the dust.

Commands

There is hardly enough space here do list the many commands that are built in. These can be found in the documentation but at least sections where commands are available.

  • Annotations
  • Auto completion
  • Background loading and saving
  • Brace highlighting
  • Call tips
  • Caret, selection, and hotspot styles
  • Cursor
  • Cut, copy and paste
  • Direct access
  • Error handling
  • Folding
  • GTK+
  • Images
  • Indicators
  • Key bindings
  • Keyboard commands
  • Lexer for syntax coloring
  • Line endings
  • Line wrapping
  • Long lines
  • Macro recording
  • Margins
  • Markers
  • Mouse capture
  • Multiple Selection and Virtual Space
  • Multiple views
  • Notifications
  • Other settings
  • Overtype
  • Popup edit menu
  • Printing
  • Scrolling and automatic scrolling
  • Searching
  • Selection and information
  • Styling
  • Tabs and Indentation Guides
  • Text retrieval and modification
  • Undo and Redo
  • User lists
  • White space
  • Zooming

Highlighters, Lexers

There are not many formats which are not supported yet. Did you hear of Hugo? Here you do! An implementation from CodeMax. It makes a lot of sense for the time being only to implement code for desired formats and thus strip some of the lexers built in.

MainLexers are available or foreseen for:

Abaqus, Ada, Apdl, Asm, Asn1, Asp, Asymptote, Au3, Avenue, Baan, Bash, Batch, Bullant, Caml, Clarion, Cmake, Conf, Cpp, CSound, Css, D, Diff, Eiffel, EiffelKW, Erlang, ErrorList, EScript, F77, Flagship, Forth, Fortran, Haskell, Html, Inno, Kix, Latex, Lisp, Lot, Lout, Lua, Magik, MakeFile, Matlab, MetaPost, Mmixal, MSSql, NNCronTab, Nsis, Octave, Opal, Pascal, Perl, Php, Pov, PowerBasic, PowerShell, Properties, PS, Python, R, Rebol, Ruby, Smalltalk, Sol, SpecMan, Spice, Sql, Tads3, Tcl, Tex, VB, VBScript, Verilog, Vhdl, Xml and Yaml.

This list has temporary value only as work on lexers is in constant progress.

Furthermore, an extension called SimpleLexers has been built in. The purpose of it is mainly coloring of code and autocomplete where terms are stored in word lists besides support for remarking. Over 300 colorizers for different languages are available. Sure this needs remarking of the ones which are not intended for use as the wrapper would get bulky avoiding it. Ok, so it’s there!

Compilation

The compilation of Scintilla under Visual Studio 2010 was complaining about several issues and did finally quit, (me too). I switched over to Gcc. A single change in the make file was needed, because I had an older version of Gcc, and there were two DLL files created in no time. Gcc version 4.7 will do. Luckily, I found the compiler already installed in an application folder on the system.

Managed versus Unmanaged Code

The Scintilla text editor is certainly unmanaged code. There is no point creating this component in managed code for various reasons. Besides .NET deals with structures in some particular ways and marshalling them is still not free of errors in every case either.

The Wrapper

The C# source for the wrapper only is well above 30’000 lines besides all forms, the editor, the lexer info and several additional files. One can get lost easily. So did the initial author of the old wrapper, me and Visual Studio on occasion. Due to the size of the project, methods and classes from ScintillaNet were reorganized, cleaned out and newly implemented. The whole low level interface for the API and user interface was composed anew or at least underwent large changes. Extensive verification of the low level interface with the C source was a necessity and thus took place. The term wrapper here is not used in the meaning of a complete encapsulation of the API, it is rather enriching the basic functionality with additional classes for comfort and reduction of code in the final project. Direct access to the whole API is kept open! This project is not for the beginner but don’t feel pushed out, go ahead! Just expect some complexity.

Target

  • Wrapping all Scintilla function calls as of version 10/22/2012 in C#
  • Creating additional properties using Scintilla editor variables
  • Building additional classes using editor functions
  • Rebuilding classes which shall be supported in the form designer
  • Build the classes under framework 4 with compatibility for further frameworks
  • Restyling of the user interface dialogs like Find, Replace, Mark and Goto
  • Extending existing user interface classes and build new ones

The Scintilla Edit can now be accessed through:

  1. Standard Windows messaging using provided constants (hard to remember)
  2. Direct messaging using provided constants (hard to remember)
  3. Direct call of public functions and assignments of public variables (overhead to trace code)
  4. The easier readable C# wrapper function which is also displayed as a hint (popup, intellisense)

Circumventing messaging and switch statements through direct accessing properties and classes (functions and variables), thus increasing the speed of the main class, looks very attractive especially as many functions just get or set values from fields in the editor directly. On a second thought, this might not be such a brilliant idea.

  • First, if the code is updated such changes will be lost.
  • Second, there are not many functions in this class which truly need speed, since the user is still by far the slowest in the game.
  • Third, .NET is fast enough for this class.
  • Fourth, if speeding up is desired, then direct accessing can be done in the target project.
  • Fifth, direct messaging, circumventing windows messaging with its slow response is implemented already and the whole editor functionality is tuned for speed.

The SimpleLexer

The wordlist limit for lexers has been pushed up, from 8 to 30, in SimpleLexer. There is a maximum of 256 styles which can be defined in Scintilla and wordlists make use of styles. This posh number has some limits in praxis. The number of entered wordlists in the SimpleLexer must not exceed 30 since wordlists use styles[wordlists.n] and style 31 is used as comment style. Having 30 wordlist available is still very extraordinary! Make sure not to enter the same definition as line or stream comment and in the wordlists as comments will dominate any styling. Define colors and attributes for styles in the lexerInfo for each info in use or globally in the init method of the simplelexer “see Classes.cs”. SimpleLexers.cs contains a description of the structure and use of simplelexer.

Remarks

Scintilla edit return values for color are of type long and cast to Int32.

For every Scintilla function which has a return value, used or not, a dominant return statement is copied from the C source into the C# wrapper function as comment. This allows verification of return values easier and faster. Direct calls of the editor in the wrapper class will return mainly integer values anyway.

Prerequisites

  • SciLexer.dll should be copied in the Windows\System32 directory to avoid error messages. In case an error message pops up saying that the SciLexer cannot be loaded into memory, then the SciLexer.dll is not copied in this directory.
  • Perhaps having MinGW and Gcc available to recompile Scintilla sources.
  • Having the complete Scintilla documentation present is mandatory!
  • Of course having the .NET framework 4 installed.
  • A bit elbow grease. Do not expect that this project in every detail is perfect.

To Do

The project took several weeks, day and night, for its reimplementation only. At the current state, last updates (changes from error reports) are not implemented yet. Having a close look at the screenshot reveals (keyboard) that a spell checker is not built in yet. Just in case you don’t feel too comfy with this or that detail, the entire source can be downloaded and altered if changing available settings don’t meet your taste.

Hints

Several lexers and highlighters exist from free projects like Notepad++ and others which can be implemented. Consider remarking or deleting lexers you do not intend to use in the class, in that case Enums.Lexer should be modified too. It is a lot easier to implement new lexers by writing or translating them in/to XML code or even entering them in the SimpleLexer. Samples can be found in the directory Configuration.Builtin or in the Scintilla documentation. The simplelexer is well documented in the source. The project contains a Documentation.txt file with much info to be aware of. Look up also any bulletin board of Scintilla or SourceForge for further info. Because of the fast number of available options, writing a configuration file for the editor to set your personal style might prove valuable.

Alterations, Extensions and Comments

In this project, hundreds of contributors were involved over time and all of them did bring up enormous resources and gusto to give you an outstanding class and its source for free. Understanding this, please do only report errors to the appropriate person after you put up an effort to solve the issue yourself, also skip other comments gracefully. Any Scintilla message board certainly will lend you a hand. Neil Hodgson, the author of Scintilla, is surprisingly quick in responding to inquiries, supportive and eager to implement valuable suggestions in the editor.

Download

Downloading the complete project certainly holds an edge. It has some size even when packed.

Warranty

There is absolute no warranty whatsoever implied or assumed. Use it at your own risk. It does a marvelous job for the authors. Copyrights and Trademarks shall belong to their respective owners. I am not going to fight over that!

License

This article, along with any associated source code and files, is licensed under COPL, not included are sources of Scintilla which are copyrighted by Neil Hodgson neilh@scintilla.org and carry their own license. Various previous contributors might have a claim for several different licenses which all due to my knowledge are open source. The whole project has changed so massively that licensing under COPL seems to be valid and/or supports the aim of every contributor.

Links

History

  • 9th March, 2013: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Philippines Philippines
Grew up in a metal processing company and did industrial HW/SW development since the birth of Intel’s 8080. Lectured IT since 1986 at several levels. Hobbies, sidesteps: Woodworking and deep sea diving. Background: ASM, C, C++. Platforms: Win, Novel, CP/M, MP/M, DOS, (Linux).

It’s not the developer’s duty to pay up for the engineer’s ignorance.

Comments and Discussions

 
QuestionThe download links are incorrect Pin
EAHMK1-May-16 4:07
professionalEAHMK1-May-16 4:07 
QuestionActionscript using scintillanet Pin
Member 1190315911-Aug-15 20:54
Member 1190315911-Aug-15 20:54 
QuestionDemo link is wrong - 404 Pin
byman642-Jun-15 3:30
byman642-Jun-15 3:30 
GeneralMy vote of 2 Pin
Manikandan1012-Jun-14 0:53
professionalManikandan1012-Jun-14 0:53 
QuestionThanks for your request almendietamor. Pin
cyprussun12-Apr-14 15:16
cyprussun12-Apr-14 15:16 
GeneralMy vote of 1 Pin
almend10-Apr-14 5:42
professionalalmend10-Apr-14 5:42 
GeneralMy vote of 1 Pin
dvptUml15-Feb-14 10:13
dvptUml15-Feb-14 10:13 
QuestionMy vote of 1 Pin
llothar13-Nov-13 8:40
llothar13-Nov-13 8:40 
QuestionA Zip Link for download Pin
cyprussun18-Mar-13 23:47
cyprussun18-Mar-13 23:47 
Questionjar_wiz, Voting for a link and not reading replies is what you do Pin
cyprussun18-Mar-13 21:42
cyprussun18-Mar-13 21:42 
AnswerRe: jar_wiz, Voting for a link and not reading replies is what you do Pin
jar_wiz18-Mar-13 21:53
jar_wiz18-Mar-13 21:53 
GeneralRe: jar_wiz, Voting for a link and not reading replies is what you do Pin
cyprussun18-Mar-13 22:38
cyprussun18-Mar-13 22:38 
GeneralRe: jar_wiz, Voting for a link and not reading replies is what you do Pin
jar_wiz19-Mar-13 11:10
jar_wiz19-Mar-13 11:10 
GeneralMy vote of 1 Pin
jar_wiz18-Mar-13 21:21
jar_wiz18-Mar-13 21:21 
QuestionPeter Villadsen Pin
cyprussun18-Mar-13 18:40
cyprussun18-Mar-13 18:40 
General[My vote of 1] would never download Pin
Peter Villadsen18-Mar-13 18:04
Peter Villadsen18-Mar-13 18:04 
QuestionNot safe Pin
cyprussun18-Mar-13 16:13
cyprussun18-Mar-13 16:13 
GeneralMy vote of 1 Pin
lyricc18-Mar-13 15:17
lyricc18-Mar-13 15:17 
GeneralDownload Pin
cyprussun18-Mar-13 14:30
cyprussun18-Mar-13 14:30 
Thank you very very much for this info DaveEchols!
In deed as I am programming very intensively you have found the week sport right away.

Hints & Links:
http://groups.google.com/group/scintilla-interest
Code:
https://docs.google.com/folder/d/0ByARMmf4l8H8empoUnk3ajhPZjA/edit?docId=0ByARMmf4l8H8dTk3YkEtZGtiajg

Should you not be happy with this, let me know immediately and suggest a convenient server.

Dave, the wrapper code only has 77'000 lines and was rewritten in 2 months. 1900 lines / day.
However, it calls the DLL in several files. Look up Annotations.cs and NativeSci.cs.
Good luck!
QuestionDownload Links Pin
DaveEchols18-Mar-13 7:20
DaveEchols18-Mar-13 7:20 
GeneralAn addenddum to the Demo Pin
cyprussun17-Mar-13 17:04
cyprussun17-Mar-13 17:04 
Question64 or 32 bit Pin
vinodajacob15-Mar-13 1:31
vinodajacob15-Mar-13 1:31 
AnswerRe: 64 or 32 bit Pin
cyprussun15-Mar-13 15:04
cyprussun15-Mar-13 15:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.