#include Once "window9.bi"

Function Getlinetexteditor(iGadget As Long , iLine As Long  , iSizeBuffer As Long = 512 ) As String Export
	
	Dim As GtkTextBuffer Ptr  buffer
	
	Dim As GtkTextIter  iter1, iter2
	
	Dim As gint char_offset1  = iLine
	'
	Dim As gint char_offset2  = iLine + 1
	
	Dim As Long iLineCount

	buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( Gadgetid(iGadget) ))
	
	iLineCount = gtk_text_buffer_get_line_count (buffer)
	
	If (iLineCount - iLine) < 1 Then Return ""
	
	gtk_text_buffer_get_iter_at_line(buffer , @iter1, char_offset1)
	
	If (iLineCount - iLine)  = 1 Then
	
		gtk_text_buffer_get_end_iter(buffer , @iter2)
		
	Elseif 	(iLineCount - iLine)  > 1 Then
	
		gtk_text_buffer_get_iter_at_line(buffer , @iter2, char_offset2)

	Endif
	
	Return  Trim(*gtk_text_iter_get_text(  @iter1, @iter2  ) , Any Chr(13) & Chr(10))
	
End Function