#include Once "window9.bi"

Function calculate_real_tab_width(text_view As hwnd,  tab_size As guint) As GINT

	Dim As PangoLayout Ptr layout
	
	Dim As String tab_string
	
	Dim As gint tab_width

	If tab_size = 0 Then Return tab_size = 4

	tab_string = Space(tab_size)
	
	layout = gtk_widget_create_pango_layout(text_view, Strptr(tab_string))
	
	If (layout <> NULL) Then
		
		pango_layout_get_pixel_size(layout, @tab_width, NULL)
		
		g_object_unref(G_OBJECT(layout))
		
	Else
	
		tab_width = -1
		
	Endif	

	Return tab_width

End Function

Sub Settabstopseditor(Byval gadget As Long, Byval TabWidth As Integer=0)
	
	Dim As Any Ptr tv = Gadgetid(gadget)
	
	Dim As PangoTabArray Ptr pta
	
	pta = pango_tab_array_new_with_positions (1, True, PANGO_TAB_LEFT, TabWidth)
	
	pango_tab_array_set_tab(pta, 0, PANGO_TAB_LEFT,_
		calculate_real_tab_width(tv, TabWidth))
		
	gtk_text_view_set_tabs(tv , pta)
	
	pango_tab_array_free(pta)
	
End Sub