News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Technicolor for script kiddies :)

Started by hutch--, December 03, 2006, 01:51:19 AM

Previous topic - Next topic

hutch--

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]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zooba

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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

trodon

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 :(

PBrennick

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]
The GeneSys Project is available from:
The Repository or My crappy website

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ToutEnMasm

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





hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php