#include ONCE "window9.bi"

Function ToolBarImageButton(iHwndToolBar As Integer, iButtonID As Integer, idImage  As Hbitmap, sString As String = "", _
	iPositionButton As Integer = -1, iStyle As Integer = TBSTATE_ENABLED, iStyle2 As Integer = 0 , iSizeIcon as Long = 16) As Integer Export 
	
	dim as any ptr iButton
	
	if iStyle2 = TBSTYLE_CHECK then
		
		if sString <> "" then
			
			gtk_toolbar_set_style(GTK_TOOLBAR(iHwndToolBar), GTK_TOOLBAR_BOTH)
			
			iButton = gtk_toggle_tool_button_new()
			
			gtk_tool_button_set_label(iButton , strptr(sString))
			
		ELSE
			
			gtk_toolbar_set_style(GTK_TOOLBAR(iHwndToolBar), GTK_TOOLBAR_ICONS)
			
			iButton = gtk_toggle_tool_button_new()	
			
		EndIf
		
		var img = gtk_image_new_from_pixbuf(idImage)
		
		gtk_widget_show(img)  
	
		gtk_tool_button_set_icon_widget(iButton, img)		
		
	else
	
		var img = gtk_image_new_from_pixbuf(idImage)
		
		gtk_widget_show(img)	
				
		if sString <> "" then
			
			gtk_toolbar_set_style(GTK_TOOLBAR(iHwndToolBar), GTK_TOOLBAR_BOTH)			
			
			iButton = gtk_tool_button_new(img, strptr(sString))	
			
		else
		
			gtk_toolbar_set_style(GTK_TOOLBAR(iHwndToolBar), GTK_TOOLBAR_ICONS)
			
			iButton = gtk_tool_button_new(img , "")		
			
		EndIf
		
	EndIf
	
	gtk_toolbar_insert(GTK_TOOLBAR(iHwndToolBar), iButton , iPositionButton)   
	
	tree_add_node(iButtonID,pGlobalTypeWindow9->treeNumberGadgets)
	
	Dim As Node Ptr fNode = tree_find_node(iButtonID,pGlobalTypeWindow9->treeNumberGadgets)	 
	
	g_signal_connect (G_OBJECT(iButton), "clicked", G_CALLBACK(@EventsButtonClickSub), @(fNode->x)) 
	
	pGlobalTypeWindow9->ListToolBar->addNodeSub(iButtonID, cint(iButton) , cint(iHwndToolBar))	
	
	gtk_widget_show(iButton)  
	
	select case iStyle
		
		Case TBSTATE_CHECKED
		
			gtk_toggle_tool_button_set_active (cast(any ptr, iButton) , 1)
		
		case TBSTATE_HIDDEN
		
			gtk_widget_set_visible(cast(any ptr, iButton) , FALSE)
		
		case TBSTATE_INDETERMINATE
		
			gtk_widget_set_sensitive(cast(any ptr , iButton) , FALSE)
		
	End Select	 
	
	return cint( iButton)                      
	
End Function