473,568 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL syntax highlighting optimization

Sorry I posted this post earlier but got the name and subject the wrong way round (new to this!) so it perhaps didn't look right
Sorry for that. But please please answer if you know anything about it..
Thanks
I've got a procedure that is responsible for performing the following operations on a richtextbox
1) determining what parts of the text to forma
2) formatting specific ranges of text a specific color

I need to do this whenever the contents of the richtextbox change. The algorithm is quite fast as I have built in some speed saving optimizations, but i need to do some more, I was wondering if anybody could give me any suggestions? So far, I've coded it to
* - retrieve information about all ranges 'as of now' but only setting the format of ones that are new / only unsetting the format of ones that were there but aren't no
* - only set the format of ranges that are visible. For this, I use the message EM_GETFIRSTVISI BLELINE to get the first visible line, and the line count by dividing the height by the height of a line (got by GetTextMetrics) . But then I need to do a rescan of ranges to format on vscroll aswell as on textchange, which is a bit bad as it's slow when you scroll

I was thinking of having some sort of 'lazy updater' type thing that either runs for, say, 100 milliseconds each second, or in a different thread, to update the RTB for the ranges that are off the visible range once all the others have been done, but I can't get my head round how to handle the synchronicity with the fact that when the richtextbox's contents change, the ranges will change too. Should I consider this a thing that takes 'a long time' to happen? Or can anyone else lend a hand with the obviously huge amount of sideways thinking I'm having to do!!

It's for a syntax highlighting control, right now I'm just trying to get it to be able to parse c-style block comments, line comments and quotes (red.

Any ideas on performance in this area
Have posted to C++ groups as although I am writing the app in c# I am non too averse to turn my hand to c++

Thank

Nov 16 '05 #1
2 4734
Johnny wrote:
Sorry I posted this post earlier but got the name and subject the wrong way round (new to this!) so it perhaps didn't look right.
Sorry for that. But please please answer if you know anything about it...
Thanks!
I've got a procedure that is responsible for performing the following operations on a richtextbox:
1) determining what parts of the text to format
2) formatting specific ranges of text a specific color.

I need to do this whenever the contents of the richtextbox change. The algorithm is quite fast as I have built in some speed saving optimizations, but i need to do some more, I was wondering if anybody could give me any suggestions? So far, I've coded it to:
* - retrieve information about all ranges 'as of now' but only setting the format of ones that are new / only unsetting the format of ones that were there but aren't now
* - only set the format of ranges that are visible. For this, I use the message EM_GETFIRSTVISI BLELINE to get the first visible line, and the line count by dividing the height by the height of a line (got by GetTextMetrics) . But then I need to do a rescan of ranges to format on vscroll aswell as on textchange, which is a bit bad as it's slow when you scroll.

I was thinking of having some sort of 'lazy updater' type thing that either runs for, say, 100 milliseconds each second, or in a different thread, to update the RTB for the ranges that are off the visible range once all the others have been done, but I can't get my head round how to handle the synchronicity with the fact that when the richtextbox's contents change, the ranges will change too. Should I consider this a thing that takes 'a long time' to happen? Or can anyone else lend a hand with the obviously huge amount of sideways thinking I'm having to do!!!

It's for a syntax highlighting control, right now I'm just trying to get it to be able to parse c-style block comments, line comments and quotes (red.)

Any ideas on performance in this area?
Have posted to C++ groups as although I am writing the app in c# I am non too averse to turn my hand to c++.


Hi Johnny,

wouldn't it be easier and cheaper to take a syntax editor control?

http://www.actiprosoftware.com/Produ.../SyntaxEditor/

Cheers

Arne Janning

Nov 16 '05 #2
I tried 15 ways to get this to work and the results I produced were
never favoriable. In the end I came up with something that was just too
damn slow to be useful.

I guess you're highlighting line by line judging that you want the
lines. My version worked by using GetCharIndexFro mPosition, and putting
the top left corner of my control to get the highest visible text, and
the bottom left + line length to get the lowest visible text. I found
this to be useful. When you scrolled, key downed, or changed text, it
would highlight the visible portion. It kept track of the highest and
lowest point not highlighted, so that when you scrolled over the same
area again it wouldn't highlight it. Otherwise when the TextChanged
event fired it would change all of the text that was changed plus
everything that was on the same line as the start and end of the text.
I used the wndproc events from scrolling, and painting in my code. I
also had a second richtextbox as a buffer which made things a tiny bit
quicker. It also used regular expressions to parse everything - I don't
know if this was smart or not, but the regular expression were compiled,
and I didn't need to use any different logic for comments and quotes.

I found that using threading never quite worked the way I hoped for -
and I have never seen anybody used threading in a RichTextBox syntax
highlighter and have it work well. If you are going to continue to try
a threaded method, then I suggest you remember to use Delegates for all
the functions that access the control in your threaded method.
Otherwise you'll guy will blow up. When I tried using threads I was
able to get around a lot of problems by keeping track of what line I was
on [actually the indices of the start and end char]. My thread would
never work on that line, and just split any work before and after that
line. On the line I was working on the TextChanged Event would deal
with that.

Here's an idea. Scrap what you're doing. I've wrapped my noggin around
this guy for a while. I think my mistake was inheriting from
RichTextBox. Think about it. It has so much functiality we don't want!
What's to stop somebody from pasting an image. You can rig and rig but
you're just going to produce something that is sloppy. TextBox does
everything we want except colorize text. Well in theory it seems the
answer there is just to override the Onpaint event. No worrying about
scrolling, threading or any other crap like in our RTB methods, plus no
worrying about somebody changing the Font by pasting from Word, or
pasting an image.

Also don't be cracking nobody's work. Itain't right.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4313
by: Jay Davis | last post by:
I use xemacs and syntax highlighting for my IDE, but I'm not a big fan of the default syntax highlighting colors. For instance, in 'def fun():' both 'def' and 'fun' are the same color. I kind of like the vim colors, but what would be really useful is to find various examples of highlighting that people have used, to see which ones just look...
9
1930
by: news.microsoft.com | last post by:
Dear all, I have to do a source code editor to implement syntax hilighted with special colors , IntelliSense function. Could anybody give me some tips or links? Thanks,
4
7601
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax highlighting in C# but I have yet to find anything useful I know there are people at MS that know this stuff like the front of their hand and I know...
4
2787
by: Patrick Porter | last post by:
Arrrgh! I have tried everything (ok, not EVERYTHING) but i cant get solve the problem of getting syntax highlighting in a rich textbox. in the code below, im attempting to highlight all of the words "ax". the matches works fine, but i cant get the highlighting to work correctly. any help? thanks, patrick Private Sub...
4
2665
by: frikker | last post by:
Hello, I have an idea for a project which involves an editor that supports syntax highlighting. This would be for any language, particularly php, html, css, etc. I would like to write this program using python. It would only make sense to base this upon existing open source code. My question is there a python module or examples on how to...
2
2609
by: rockstar_ | last post by:
Hello all- I'm developing a Content Management software for my own site, and possibly package and deploy to other sites (for friends, family, etc.) The content management software is combined blog, photo, and site management tools. One the of the tools I would find INREDIBLY helpful is the ability to block out and syntax highlight code. I...
11
2278
by: Christoph Burschka | last post by:
Are there any free PHP libraries/utility functions that can color the syntax of various programming languages (eg. Java and C++)? I am posting code snippets on my site and would like to know if there is a way to easily give them syntax highlighting automatically. Thanks! -- Christoph Burschka <christoph.burschka@rwth-aachen.de>
0
2383
by: Scott | last post by:
Hi, I think I may have finally found a IDE/text editor that I like, but, it still haves one problem. Geany haves syntax highlighting, but it is not very good for Python. It only seems to have a couple different colours. One for text and another for modules/classes/ functions. Is it possible to change the syntax highlighting for Python,...
2
3139
by: PJ6 | last post by:
Years ago I looked for a text editor control that would do automatic keyword highlighting, to no avail. I found sample code to roll my own, but all of that was crap (mostly because of the way the RichTextBox base class was written, and the limitations of GDI+). I ended up coming to conclusion that I'd have to write my own in C++ to make it...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.