#include Once "window9.bi"

Function Getfirstvisiblelineeditor(Byval gadget As Long) As Integer
	
	Dim As GtkTextBuffer Ptr buffer
	
	Dim  As GtkAdjustment Ptr pVertAdj
	
	Dim As Long iAdjValue , iUpper , iSingleLine , iCurentPos
	
	Dim As Long iCountItems
	
	Dim As Any Ptr edithwnd = Gadgetid(gadget)

	buffer = gtk_text_view_get_buffer(edithwnd)
	
	iCountItems = gtk_text_buffer_get_line_count (buffer)
	
	If iCountItems = 0 Then iCountItems = 1
	
	#ifdef __USE_GTK3__
		
		pVertAdj = gtk_scrollable_get_vadjustment(edithwnd)
		
	#else
	
		pVertAdj = gtk_text_view_get_vadjustment(edithwnd)
		
	#endif
	
	iAdjValue = gtk_adjustment_get_value(pVertAdj)

	iUpper = gtk_adjustment_get_upper(pVertAdj)

	iSingleLine = iUpper/iCountItems

	If iSingleLine Then
		
		iCurentPos = iAdjValue \ iSingleLine
		
	Endif

	Return iCurentPos	
	
End Function