The MASM Forum Archive 2004 to 2012

Project Support Forums => MASM32 => Topic started by: hutch-- on December 03, 2006, 01:51:19 AM

Title: Technicolor for script kiddies :)
Post by: hutch-- on December 03, 2006, 01:51:19 AM
I am working on a test piece at the moment to provide technicolor (syntax colouring) for a rich edit control. The example works OK on small to medium sized files but is far too slow on any large file. The technique breaks down to two methods, one for typing directly into the editor which is easily fast enough and the second for loading files which is far too slow.

For the file load operation I make a copy in memory of the edit control content, then scan it with a dedicated algo to get the start and finish location of each word, pass it to a subroutine which calls a hash table that stores word classes which in turn works out the colour for each word and sets the colour using two API calls. It is the two API calls that are very slow.


        SendMessage hEdit,%EM_EXSETSEL,0,VarPtr(cr)
        SendMessage hEdit,%EM_SETCHARFORMAT,%SCF_SELECTION,VarPtr(cfm)


I have tested the algo without the two calls and the scan is more or less instantaneous but as soon as the two API calls are included, the speed drops down to the very slow level.

I have had a reasonable rat through Ewayne's editor that provides syntax colouring and it is easily fast enough but I have yet to decypher how it works.

Any hint on this one would be most appreciated.

[attachment deleted by admin]
Title: Re: Technicolor for script kiddies :)
Post by: zooba on December 03, 2006, 05:21:34 AM
Have you tried doing a conversion to RTF text and using EM_SETTEXTEX? The documentation is a bit hazy on this but it may work for an on-load algorithm, if not an on-the-fly one.

When loading files I found that lines wouldn't be coloured until the insertion point moved to that line - by design or bug?

EM_SETCHARFORMAT has a flag to do the selected word, though by that point you've already got all the info about the word you need to do it manually, and it probably won't remove an API call anyway.

Looks nice - is this a candidate for QE or is it too heavy for that?

Cheers,

Zooba :U
Title: Re: Technicolor for script kiddies :)
Post by: hutch-- on December 03, 2006, 07:44:19 AM
I was running it with the WORD flag but it made no difference, its probably an OS version difference with the edit control, on my win2k everything ends up coloured on load.

I have fished out Iczelion's old example where his design does JIT with the text being displayed but I can't get it to build at the moment. Crashes on ShowWindow() which does not make sense.

I don't want to massacre QE as its good at what it does but sooner or later I must code up a syntax colouring editor. This much, I am happy with the hash table, I added most of the win32 equates with the keywords file now being over 1 meg and it does not slow down at all. I now have it colouring equates and macros as well.
Title: Re: Technicolor for script kiddies :)
Post by: trodon on December 03, 2006, 02:06:56 PM
hi hutch--, i like collors ;)
btw i was tested on my winxp sp2, amd 1,7ghz and 512 mb of ram
tryed to open file keywords.txt and i need couple min to open this file :(
Title: Re: Technicolor for script kiddies :)
Post by: PBrennick on December 04, 2006, 10:47:10 AM
Hutch,
I attach a working copy of Iczelion's example of syntax coloring. It builds and does not crash on my machine.

Paul


[attachment deleted by admin]
Title: Re: Technicolor for script kiddies :)
Post by: hutch-- on December 04, 2006, 10:50:22 AM
Thanks but was not the type of test I was after, the keywords.txt file is aleady loaded by the test editor on startup, parsed and loaded into a hash table and it is then used to test words in the text body.

The two API calls are far too slow so I am looking at another technique at the moment that appears to be much faster. I just have to finishe decyphering it and removing the technique from the linked list it uses.
Title: Re: Technicolor for script kiddies :)
Post by: hutch-- on December 04, 2006, 10:51:59 AM
Thanks Paul but I already have it. I have cleaned it up, fixed some of the errors in it and will see if I can use the technique he designed once I can extract it from the linked list he used.
Title: Re: Technicolor for script kiddies :)
Post by: ToutEnMasm on December 04, 2006, 02:32:17 PM
Hello,
a simple sample of syntax Hilight
Quote
   ;--------- The string must be visible on the screen ------------------
   ;-xHcontrole, richedit handle
         Local hdc:DWORD
         Local rect:RECT
         local TrouveText:FINDTEXTEX
         Local  charrange:CHARRANGE   
   invoke GetDC,xHcontrole
   mov hdc,eax
   mov TrouveText.chrg.cpMin,0
   mov TrouveText.chrg.cpMax,-1
   mov TrouveText.lpstrText,offset string
   invoke SendMessage,xHcontrole,EM_FINDTEXTEX,1,addr TrouveText ;
   mov edx,eax
   invoke SendMessage,xHcontrole,EM_POSFROMCHAR,addr rect,edx   
   invoke SetTextColor,hdc,000000FFh      ;red
   invoke DrawText,hdc,addr string,-1,addr rect,0      ;TrouveText.chrgText
   invoke ReleaseDC,xHcontrole,hdc   

Search is fast but only of what is on the screen.There is a search for each words.
Iczelion sample use stack to have a list of words,not very good.
                           ToutEnMasm




Title: Re: Technicolor for script kiddies :)
Post by: hutch-- on December 04, 2006, 03:17:49 PM
Gratsie,

That looks useful.  :U