$APPTYPE GUI
$TYPECHECK ON
$INCLUDE "RAPIDQ.INC"
TYPE QREdit EXTENDS QRICHEDIT
RichFont AS QFONT
Syntaxes(100) AS STRING
MaxSyntax AS INTEGER
HiLightColor AS INTEGER
SUB HiLight
DIM TempStart AS INTEGER
DIM I AS INTEGER, N AS INTEGER
WITH QREdit
TempStart = .SelStart
.SelStart = 0
.SelLength = LEN(.Text)
.SelAttributes = .RichFont
FOR I = 1 TO .MaxSyntax
N = INSTR(UCASE$(.Text), UCASE$(.Syntaxes(I)))-1
WHILE N >= 0
.SelStart = N
.RichFont.AddStyles(fsBold)
.RichFont.COLOR = .HiLightColor
.SelLength = LEN(.Syntaxes(I))
.SelAttributes = .RichFont
N = INSTR(N+.SelLength, UCASE$(.Text), UCASE$(QREdit.Syntaxes(I)))-1
WEND
.SelLength = 0
.RichFont.DelStyles(fsBold)
.RichFont.COLOR = 0
.Font = .RichFont
.SelStart = TempStart
NEXT I
END WITH
END SUB
SUBI AddSyntaxes(...)
DIM I AS INTEGER
WITH QREdit
FOR I = 1 TO PARAMSTRCOUNT
.Syntaxes(I+.MaxSyntax) = PARAMSTR$(I)
NEXT
.MaxSyntax = .MaxSyntax + PARAMSTRCOUNT
END WITH
END SUBI
EVENT OnKeyUp (Key AS WORD, Shift AS INTEGER)
DIM I AS INTEGER, EndStr AS INTEGER, StartStr AS INTEGER
DIM TempStart AS INTEGER, N AS INTEGER
DIM Token AS STRING
DIM T1 AS INTEGER, T2 AS INTEGER
T1 = QREdit.SelStart
T2 = QREdit.SelLength
IF Key < 46 AND Key <> 8 THEN
EXIT EVENT
END IF
WITH QREdit
FOR I = .SelStart TO LEN(.Text)
IF MID$(.Text, I, 1) = " " OR MID$(.Text, I, 1) = CHR$(13) OR MID$(.Text, I, 1) = CHR$(10) THEN
EXIT FOR
END IF
NEXT I
EndStr = I
FOR I = .SelStart TO 1 STEP -1
IF MID$(.Text, I, 1) = " " OR MID$(.Text, I, 1) = CHR$(10) OR MID$(.Text, I, 1) = CHR$(13) THEN
EXIT FOR
END IF
NEXT I
StartStr = I+1
Token = RTRIM$(LTRIM$(MID$(.Text, StartStr, EndStr - StartStr)))
TempStart = .SelStart
.SelStart = StartStr-1
.SelLength = LEN(Token)
.SelAttributes = .RichFont
FOR I = 1 TO .MaxSyntax
IF UCASE$(Token) = UCASE$(.Syntaxes(I)) THEN
.SelStart = StartStr-1
.RichFont.AddStyles(fsBold)
.RichFont.COLOR = .HiLightColor
.SelLength = LEN(.Syntaxes(I))
.SelAttributes = .RichFont
END IF
NEXT I
.SelLength = 0
.SelStart = TempStart
.RichFont.DelStyles(fsBold)
.RichFont.COLOR = 0
.Font = .RichFont
END WITH
QREdit.SelStart = T1
QREdit.SelLength= T2
END EVENT
CONSTRUCTOR
PlainText = True
RichFont.Name = "Courier"
MaxSyntax = 0
HiLightColor = &HAA0000
Font = QREdit.RichFont
END CONSTRUCTOR
END TYPE
CREATE Form AS QFORM
CREATE RichEdit AS QREdit
Align = alClient
WordWrap = False
Clear
AddSyntaxes("PRINT", "CLS", "LOCATE", "END", "COLOR", "IF", "THEN", "ELSE")
AddStrings("'-- Syntax Hilighting", "", _
"10 CLS", _
"20 PRINT "+CHR$(34)+"Hello World!"+CHR$(34), _
"30 LOCATE 10,10", _
"40 PRINT 1+2+3", _
"50 IF RAPIDQ = GREAT THEN", _
"60 PRINT "+CHR$(34)+"Oh yeah!"+CHR$(34), _
"70 ELSE", _
"80 END", _
"90 END IF")
HiLight
END CREATE
CAPTION = "Syntax hilighting"
Center
SHOWMODAL
END CREATE
|
|