TextArea problem..

BlitzMax Forums/BlitzMax GUI Programming/TextArea problem..

The unexpected behaviour is because of the way that the RichEdit control scrolls to character positions. Try the following:

Import MaxGui.Drivers

Strict 

Local window:TGadget
Local textarea:TGadget
Local index:TGadget 

window=CreateWindow("My Window",130,20,400,300,,15|WINDOW_ACCEPTFILES)

textarea=CreateTextArea(50,0,ClientWidth(window)-70,200,window)
index = CreateTextArea(10,0,30,200,window,TEXTAREA_READONLY)
DisableGadget index
Local hWnd = QueryGadget(index, QUERY_HWND)
SendMessageA(hWnd, EM_SHOWSCROLLBAR, SB_VERT, False)

While WaitEvent()
	Select EventID()
		Case EVENT_GADGETSELECT
			Select EventSource()
				Case textarea
					LockTextArea index
					SetTextAreaText(index,"")
					For Local loop:Int = 0 To TextAreaLine(textarea,TextAreaLen(textArea))
						AddTextAreaText index, ""+loop
						If loop = TextAreaLine(textarea,TextAreaLen(textArea)) Then Exit 
						AddTextAreaText index,"~n"
					Next
					UnlockTextArea index
					Local selectedLine:Int = TextAreaCursor(textarea,TEXTAREA_LINES)
					SelectTextAreaText(index,selectedLine,0,TEXTAREA_LINES)
					SelectTextAreaText(index,selectedLine,1,TEXTAREA_LINES)		
			End Select 
	
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_APPTERMINATE
			End
	End Select
Wend
Notice the use of the second call to SelectTextAreaText(). The first positions the cursor at the start of the line - the text area control scrolls so that the start of the concerned line is visible. The second call then selects the entire line.

As you had it before, the SelectTextAreaText() command highlights the whole line straight away. The text area controls scrolls to first point where the selection is visible - to the text area, this is right at the start of the following line.

LockTextAreaText() may improve text area performance on some platforms but isn't necessary. Just added it for good measure.

I know the explanation isn't fantastic, but there is a reason why Microsoft's Rich Text control has that behaviour, and the workaround is to select the beginning of the line first.

Hope this helps,

Seb