#include Once "window9.bi"

Function Linescrolleditor(Byval gadget As Long, Byval numberLineScroll As Integer) As Integer
	
	Dim As GtkTextBuffer Ptr buffer 
	
	Dim As GtkTextIter iter
	
	Dim As GtkTextMark Ptr mark
	
	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 > 0 Then
		
		iCurentPos = iAdjValue \ iSingleLine

		gtk_text_buffer_get_iter_at_line_offset(buffer, @iter, iCurentPos+numberLineScroll, 0)
		
		mark = gtk_text_buffer_create_mark(buffer, NULL, @iter, 0)
		
		gtk_text_view_scroll_to_mark(edithwnd, mark, 0.0, True, 0.0, 0.0)
		
		gtk_text_buffer_delete_mark(buffer, mark)
		
		Return 1		
		
	Endif

End Function