Click here to Skip to main content
Click here to Skip to main content

Tagged as

Scintilla Text component. Speed with over 600 commands

, 13 Mar 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

     

The wrapped Scintilla showing some facilities after reimplementation:

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

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)

Share

About the Author

cyprussun

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

 
GeneralMy vote of 2 PinprofessionalManikandan1012-Jun-14 1:53 
QuestionThanks for your request almendietamor. Pinmembercyprussun12-Apr-14 16:16 
GeneralMy vote of 1 Pinmemberalmendietamor10-Apr-14 6:42 
GeneralMy vote of 1 PinmemberdvptUml15-Feb-14 11:13 
QuestionMy vote of 1 Pinmemberllothar13-Nov-13 9:40 
QuestionA Zip Link for download Pinmembercyprussun19-Mar-13 0:47 
Questionjar_wiz, Voting for a link and not reading replies is what you do Pinmembercyprussun18-Mar-13 22:42 
AnswerRe: jar_wiz, Voting for a link and not reading replies is what you do Pinmemberjar_wiz18-Mar-13 22:53 
GeneralRe: jar_wiz, Voting for a link and not reading replies is what you do Pinmembercyprussun18-Mar-13 23:38 
GeneralRe: jar_wiz, Voting for a link and not reading replies is what you do Pinmemberjar_wiz19-Mar-13 12:10 
Hi cyprussun, I don’t understand your comment to me about the github project. What project? And what do you mean that it is deprecated?
 
You definitely have issues with observing and/or following what is generally accepted as “de facto” standards that are widely practiced amongst the open-source community.
 
- Using a non-standard download service (that wants to install who knows what on a person’s PC).
 
- Using RAR to distribute source code – I can’t think of a single open-source project that does that, can you point one out?
 
- Posting answers to peoples messages in a NEW thread.
 
I managed to unrar your project. And I looked over your code.
 
- You’ve rearranged what appears to be many of the separate class files from the ScintillaNET project (scintillanet.codeplex.com) into a single file in your project “classes.cs”. (you have 60+ classes in that single file) Why would you do that? That is not generally accepted coding practice (unless it was machine generated) It makes it really difficult for anyone who has invested any time at all in ScintillaNET to tell what you have added/or changed.
 
- You have NO Readme.txt files explaining anything at all about your project. What projects did you start from, where you got the original source files from. What are the licenses? Who are the original authors? What changes did you make?
 
- You have three folders; _Doc / Resources / Scintilla duplicated in that RAR file. IF you delete those duplicates and delete the bin / obj / build files (you only needed to distribute the SciLexer.dll(s) from the www.scintilla.org site and document what version(s) along w/ the SHA1 for verification) then your ZIP file comes down to <10 meg. I can only guess that other files are probably not necessary either.
 
Yes, you can fork your own project and refactor away at it. There are times where that is warranted. But, IMHO, this would NOT seem to be one of those times.
 
If I am not mistaken, it appears to me that basically you took the ScintillaNET and made some updates and additions to it. The generally accepted way of doing this would have been to improve on the ScintillaNET (scintillanet.codeplex.com) by leaving most if not all the source files intact and only make you’re changes to the existing source code / project structure. To the point that a visual file diff compare would clearly point out what you have done to update and or improve and so on.
 
Then you could either join and give your changes back to the ScintillaNET project OR if he refused then start your own fork. Since the number of downloads to ScintillaNET is 8,570 you had potentially several thousand users that would have been interested in your changes (including me) and would possibly even contribute further changes and improvements to it. But few of them are going to be interested in a total re-arrangements of source files and source code for no apparent reason.
 
You seem to have some talent as a programmer. But if you want to have recognition / positive feedback AND if you want to contribute to the open-source community then you need to learn to follow some widely accepted “de facto” practices.
 
OK.. that’s about all I have to say about this…
GeneralMy vote of 1 Pinmemberjar_wiz18-Mar-13 22:21 
QuestionPeter Villadsen Pinmembercyprussun18-Mar-13 19:40 
General[My vote of 1] would never download PinmemberPeter Villadsen18-Mar-13 19:04 
QuestionNot safe Pinmembercyprussun18-Mar-13 17:13 
GeneralMy vote of 1 Pingrouplyricc18-Mar-13 16:17 
GeneralDownload Pinmembercyprussun18-Mar-13 15:30 
QuestionDownload Links PinmemberDaveEchols18-Mar-13 8:20 
GeneralAn addenddum to the Demo Pinmembercyprussun17-Mar-13 18:04 
Question64 or 32 bit Pinmembervinodajacob15-Mar-13 2:31 
AnswerRe: 64 or 32 bit Pinmembercyprussun15-Mar-13 16:04 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 13 Mar 2013
Article Copyright 2013 by cyprussun
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid