IonicWind Software

Creative Basic => General Questions => Topic started by: tbohon on July 21, 2014, 06:30:00 PM

Title: Colorizing Text
Post by: tbohon on July 21, 2014, 06:30:00 PM
I have been trying to modify this piece of code (from Jos from way back when) to colorize the keywords in a richedit box ONLY IF they are the very first word on each line (this routine examines the entire line and colorizes them wherever it finds them).  Only one exception - when a '#' is seen the remainder of the line is colorized.  Keywords found in other than the first location are NOT to be colorized.

Colors:  regular keywords (in first position on the line) are to be BLUE and the #->end of line are to be GREEN.

And yes this is for something I'm trying to do in CB to use with my ftp engine written in <gag> C#.Net .

Going around and around in circles ... I think the change needs to be in the colorize() routine in the process looking through the lines ... but can't come up with the correct solution after multiple hours and I'm slowly going insane here  ;D

Suggestions GREATLY appreciated!!!

TIA.

Tom


'This function adjusts the colors of the keywords on the given linenum
SUB colorize(d1,ctl,linenum)
def lineStart, lineLength:int
def i,ctl,linenum,char_start:int
def p, pLine:int

' but how replace (convert) this comand to CB
lineStart = CONTROLCMD (d1, 1,char_start, linenum)
lineLength = CONTROLCMD (d1, 1, @RTGETLINELENGTH,linenum)

'uncolor the whole line, set black color
' CONTROLCMD dlg, ctl, @RTHIDESEL, 0
CONTROLCMD d1, 1, @RTSETSELECTION, lineStart, lineStart + lineLength
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)

'check the keywords one by one, if they occur on this line
FOR i=0 TO kewordCount-1
p = lineStart+1
DO
'p = RTFINDTEXT(dlg, ctl, keyword[i], p+1, lineStart + lineLength, True, True)
' i change previus line to :
p = CONTROLCMD (d1, 1, @RTFINDTEXT,keyword[i] , p+1,p+LEN(keyword[i]) )

IF p > 0
'the keyword is found at the current line. color it
CONTROLCMD d1, 1, @RTSETSELECTION, p,p+LEN(keyword[i])
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(255, 0, 0)
ENDIF

''you can also add making the text uppercase and things like that...
'CONTROLCMD dlg, ctl, @RTREPLACESEL, UCASE$(keyword[i])

UNTIL p < 0
'next two lines solve problem------------------------------------
CONTROLCMD d1, 1, @RTSETSELECTION, p,p-LEN(keyword[i])
CONTROLCMD d1, 1, @RTSETSELCOLOR, RGB(0, 0, 0)
'----------------------------------------------------------------
NEXT i
RETURN
Title: Re: Colorizing Text
Post by: LarryMc on July 21, 2014, 10:50:27 PM
I think I can help if you answer a few questions:

How is the richedit loaded? Is it one time whole file type or is it you are continuously adding lines to it?
Once the RE is loaded does the user edit it or simply view it?
What is the max number of lines you ever expect to see in the RE?

LarryMc

Edit: Are all the lines left justified or do some of the lines start off with tabs or spaces?
Title: Re: Colorizing Text
Post by: LarryMc on July 22, 2014, 07:26:02 AM
Okay
If you don't do any editing then I've got it working.

If you need editing then I need to work on it some more.
Title: Re: Colorizing Text
Post by: tbohon on July 22, 2014, 10:03:17 AM
The richedit is created once at the beginning of the program but will potentially be changed - it's being used as a script editor component so I would expect people going back to add/delete/modify lines, add comments, etc.

Usual scripts are less than, say, 300 lines long from my experience.

All the lines are left justified so that the interpreter can easily find the first token during processing.

Thanks for the help sir!
Title: Re: Colorizing Text
Post by: LarryMc on July 23, 2014, 02:11:26 AM
Attached is a complete editor program
There is a list of keywords,making sure the last element in the list is the "#"
Also, when you add your keywords adjust the
if I< 28statement and put the index number for the "#" element.
If a keyword(except for the #) is the first word on the line(regardless of tabs and preceding spaces) the keyword  colored blue,
otherwise it will be ignored.
If the line contains a # the # to the end of the line will be colored green.  This happens even if a keyword has already been colored at the beginning of the line.

Also attached is the test file I used.
Title: Re: Colorizing Text
Post by: aurelCB on July 23, 2014, 02:48:11 AM
Ahh yes ..i almost forget about that program... ;D
Title: Re: Colorizing Text
Post by: LarryMc on July 23, 2014, 04:14:24 AM
Quote from: aurelCB on July 23, 2014, 02:48:11 AM
Ahh yes ..i almost forget about that program... ;D
me too!
Title: Re: Colorizing Text
Post by: tbohon on July 24, 2014, 09:55:34 AM
Larry it's exactly what I was trying to achieve ... thank you thank you thank you!

I'm going to spend some time this morning (have a very long non-relevant conference call shortly) and study your code so I understand what you did and what I missed.

Again, I greatly appreciate the help on this!!!

Best,

Tom