Formatting Text Areas

BlitzPlus Forums/BlitzPlus Programming/Formatting Text Areas

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I'm having some problems with formatting text areas. I'm trying to get the program to color certain words that appear in the text area for a programming text editor. Here's the code.

Global Mainwin=CreateWindow("Mainwin",0,100,640,480,Desktop(),3)

Global SaveButt=CreateButton("Save",0,0,25,25,Mainwin,1)
SetGadgetLayout(SaveButt,1,0,1,0)
Global OpenButt=CreateButton("Open",25,0,25,25,Mainwin,1)
SetGadgetLayout(OpenButt,1,0,1,0)

Global MainArea=CreateTextArea(0,23,631,423,Mainwin,0)
SetTextAreaColor(MainArea,243,243,243,True)
tmpfont=LoadFont("Arial",14)
SetTextAreaFont MainArea,tmpfont
SetGadgetLayout(MainArea,1,1,1,1)

HotKeyEvent(28,0,$FFFF)

Repeat
	event=0
	event=WaitEvent()
	Select event
	Case $803
		Exit
	Case $FFFF
		AddTabs(MainArea)
	Case $401
		Select EventSource()
		Case MainArea
			;Stop
			LockTextArea mainarea
			FormatTextAreaText(mainarea,1,1,1,0,0)
			UnlockTextArea mainarea
			ColorText(MainArea," Xor ; And ; Or ; Not ",255,0,0)
		End Select
	Default
	End Select
Forever

HotKeyEvent(28,0,0)

Function colortext(TextArea,ColorString$,colorr,colorg,colorb)
	Strng$=TextAreaText$(textarea)
	While Instr(ColorString,";",LastFindExt+1)
		Strng$=TextAreaText$(textarea)
		NextHighLight$=Mid$(ColorString,LastFindExt+1,Instr(ColorString,";",LastFindExt+1)+LastFindExt-1)
		LastFindInt=0
		While Instr(Lower$(strng),Lower$(NextHighLight),LastFindInt+1)
			Strng$=TextAreaText$(textarea)
			LockTextArea mainarea
			FormatTextAreaText(TextArea,ColorR,ColorG,ColorB,0,Instr(Lower$(strng),Lower$(NextHighLight),LastFindInt+1)-1,Len(NextHighLight),1)
			UnlockTextArea mainarea
			LastFindInt=Instr(Strng,nexthighlight,LastFindInt+1)
		Wend
		LastFindExt=Instr(ColorString,";",LastFindExt+1)
	Wend
End Function

Function AddTabs(TextArea)
	linenum=TextAreaCursor(TextArea,2)
	lineabove$=TextAreaText(TextArea,linenum-1,linenum,2)
	I=1
	While (Mid$(lineabove,I,1) = "	") And (I < Len(lineabove))
		I=I+1
	Wend
	For J=1 To I-1
		ret$=ret$+"	"
	Next
	SetTextAreaText(TextArea,ret,TextAreaCursor(MainArea,1),0,1)
	For J=1 To I-1
		keypress(39,0,0,0)
		keypress(39,0,2,0)
	Next		
End Function


P.S. you'll need this userlib in order to run the program http://www.blitzbasic.com/codearcs/codearcs.php?code=1227.