#include Once "window9.bi"

Function Editorgadget( iGadget As Long , x As Long , y As Long , width_ As Long , height_ As Long , sText As String = "" , style As Long = 0 , tag As Long = 0) As HWND Export
	
	Dim As HWND scroll , text_view , vbox , mainBox
	
	Dim As  GtkTextBuffer Ptr buffer
	
	Dim As ListT Ptr pListTemp
	
	Freegadget(iGadget)
	
	pGlobalTypeWindow9->OptGroup = 0 ' reset Group OptionGadget
	
	vbox = gtk_fixed_new()
	
	pListTemp = Cast(ListT Ptr,pGlobalTypeWindow9->ListWinAndContainers->findNodeFunc(Cint(pGlobalTypeWindow9->CurentHwnd)))
	
	mainBox = Cast(hwnd , pListTemp->anyTwoData)
	
	gtk_container_add (GTK_CONTAINER(mainBox), vbox)
	
	scroll = gtk_scrolled_window_new (NULL, NULL)
	
	gtk_scrolled_window_set_shadow_type(Cast(Any Ptr,scroll) , GTK_SHADOW_ETCHED_IN)
	
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC)
	
	gtk_fixed_put(GTK_FIXED(vbox), scroll, x , y)
	
	text_view = gtk_text_view_new( )
	
	pGlobalTypeWindow9->ListGadgets->addNodeSub(iGadget , Cint(text_view) , 2) 
	
	gtk_widget_set_size_request(scroll, width_, height_)	
	
	gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), True)
	
	gtk_container_add (GTK_CONTAINER (scroll), text_view)
	
	buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( text_view ) )
	
	If tag = 0 Then
	
		gtk_text_buffer_create_tag(buffer, "gui_tag_bg_fg","background", "#8EAD6F", "foreground", "#FFFFFF", NULL)

	Endif
	
	If style And ES_RIGHT Then
	
		gtk_text_view_set_justification(Cast(Any Ptr,text_view) , 1)
		
	Elseif style And ES_CENTER Then
	
		gtk_text_view_set_justification(Cast(Any Ptr,text_view) , 2)	

	Endif	
	
	If Len(sText) > 0 Then		 
		
		gtk_text_buffer_set_text( buffer, sText ,-1)
		
	Endif
	
	g_object_set_data (Cast(Any Ptr, text_view), "X_SIZE" , Cast(Any Ptr,Cint(x)))
	
	g_object_set_data (Cast(Any Ptr, text_view), "Y_SIZE" , Cast(Any Ptr,Cint(y)))
	
	g_object_set_data (Cast(Any Ptr, text_view), "W_SIZE" , Cast(Any Ptr,Cint(width_)))
	
	g_object_set_data (Cast(Any Ptr, text_view), "H_SIZE" , Cast(Any Ptr,Cint(height_)))	

	tree_add_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)
	
	Dim As Node Ptr fNode = tree_find_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)
	
	g_signal_connect(G_OBJECT(text_view), "event", G_CALLBACK (@EventsEditorAllFunc), @(fNode->x))
	
	g_signal_connect(G_OBJECT(scroll), "size-allocate", G_CALLBACK (@size_allocate_signals), @(fNode->x))

	gtk_widget_show(vBox)

	gtk_widget_show(text_view)
	
	gtk_widget_show(scroll)

	gtk_widget_modify_font(text_view, pGlobalTypeWindow9->fontCurent)
	
	Return text_view
		
End Function