TextArea Tweak(Win32) FirstVisibleLine

BlitzMax Forums/BlitzMax Module Tweaks/TextArea Tweak(Win32) FirstVisibleLine

klepto2(Posted 2006) [#1]
Hi, as seen from this post: http://www.blitzbasic.com/Community/posts.php?topic=57269 I needed a Function, that returns the first visible line in a textarea gadget. As I'm surely not allowed to post the full source of the Win32Gui Driver i will post detailed the changes I've made.

All changes are related to this Folder: /mod/brl.mod/win32maxgui/win32gui

First step:
Edit the 'Win32textarea2.cpp' (for versions before 1.18 use the 'Win32textarea.cpp')

Add this to the file:
int Win32TextArea::firstVisible(){
	return SendMessage( _gadget.hwnd(),EM_GETFIRSTVISIBLELINE,0,0);
}

Second Step:
Edit the 'Win32textarea.h'
change:
int		findChar( int lin );
	int		findLine( int chr );

to:
int		findChar( int lin );
	int		findLine( int chr );
	int		firstVisible();

Step 3:
Change to the folder '/mod/brl.mod/win32maxgui/gui'
Open : 'Win32textarea2.cpp'
Add this:
int 		bbGetFirstVisibleLine( BBTextArea *t){
	t->debug();
	return t->firstVisible();
}

Step 4:
Open 'Win32TextArea.h'
and change:
virtual int		findLine( int pos )=0;
	virtual int		findChar( int lin )=0;

to:
virtual int		findLine( int pos )=0;
	virtual int		findChar( int lin )=0;
	virtual	int		firstVisible()=0;

and change:
void		bbUnlockTextArea( BBTextArea *t );
};

to:
void		bbUnlockTextArea( BBTextArea *t );
int			bbGetFirstVisibleLine( BBTextArea *t );
};


Now it is time to edit the 'win32gui.bmx' in '/mod/brl.mod/win32maxgui/'

2 changes:
First:
Add this at line: 219
Function bbGetFirstVisibleLine( textArea )


and second:
Add this method after the 'texarea commands' in line : 781
Method GetFirstVisible()
			Return bbGetFirstVisibleLine(handle)
	End Method


Last change is applied to the gadget.bmx in 'mod/brl.mod/MaxGui.mod'
Add this at line 488
Method GetFirstVisible()
	End Method


Rebuild modules and you could now get the First visible line:
like this:
' createtextarea.bmx

Strict 

Local window:TGadget
Local textarea:TGadget

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

textarea=CreateTextArea(0,0,ClientWidth(window),ClientHeight(window)/2,window)
SetGadgetLayout textarea,1,1,1,1
SetGadgetText textarea,"a textarea gadget~none line~nandanother"
ActivateGadget textarea

SelectTextAreaText textarea,1,1,TEXTAREA_LINES

Print TextAreaCursor(textarea,TEXTAREA_LINES) 
Print TextAreaSelLen(textarea,TEXTAREA_LINES) 

While WaitEvent()
	SetStatusText(window,TextArea.GetFirstVisible()) 'magic ;)
	Print CurrentEvent.ToString()+" "+EventSourceHandle()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_APPTERMINATE
			End
	End Select
Wend


I hope I haven' forget something, else let me know.
I haven't build in the procedural Function for this, but this should be fairly easy for everyone ;)

PS: Would be nice if this would make it to the official Mod.


skidracer(Posted 2006) [#2]
Hi Benjamin,

I'm not sure if you read it but there is a section at the end of the MaxGUI overview (tutorials section off the BlitzMax help's home page) that includes the following advice:

The cross platform nature of MaxGUI means there are implications for those wishing to extend functionality by taking advantage of platform specific features that have no logical equivalent on other platforms.

Those wishing to do so are encouraged to implement such features in separate modules rather than making odifications to the BRL modules which are intended only to support the core cross platform MaxGUI functionality.


So it is preferred you implement such platform specific features with standalone functions such as the following:

' createtextarea.bmx

Strict 

Local window:TGadget
Local textarea:TGadget

Function TextAreaFirstVisibleLine(textarea:TGadget)
	Local hwnd=QueryGadget(textarea,QUERY_HWND)
	If hwnd Return SendMessageA(hwnd,EM_GETFIRSTVISIBLELINE,0,0)
End Function

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

textarea=CreateTextArea(0,0,ClientWidth(window),ClientHeight(window)/2,window)
SetGadgetLayout textarea,1,1,1,1
SetGadgetText textarea,"a textarea gadget~none line~nandanother"
ActivateGadget textarea

SelectTextAreaText textarea,1,1,TEXTAREA_LINES

Print TextAreaCursor(textarea,TEXTAREA_LINES) 
Print TextAreaSelLen(textarea,TEXTAREA_LINES) 

While WaitEvent()

	SetStatusText(window,TextAreaFirstVisibleLine(textarea)) 'magic ;)
	
	Print CurrentEvent.ToString()+" "+EventSourceHandle()
	
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_APPTERMINATE
			End
	End Select
Wend



klepto2(Posted 2006) [#3]
Sorry, seems I have overread this. Sounds logical. Then i will
write an extendend Textarea module ;).
But about my second question: It should be possible to catch the ScrollEvents on every Version (PC,MAC and Linux) or isn't this featured by the other libs?


skidracer(Posted 2006) [#4]
I replied to you email with hopefully a fix for your scrollevent patch and will be looking into best solution for you.


klepto2(Posted 2006) [#5]
thx, again