#include ONCE "window9.bi"

Function ToolBarStandardButton(iHwndToolBar As Integer, iButtonID As Integer, iIndexImage  As Integer, sString As String = "", _
	iPositionButton As Integer = -1, iStyle As Integer = TBSTATE_ENABLED, iStyle2 As Integer = 0) As Integer Export 

#ifndef __USE_GTK3__
	
	dim iIndexIm(14) as zstring ptr = {@GTK_STOCK_CUT , @GTK_STOCK_COPY , @GTK_STOCK_PASTE , @GTK_STOCK_UNDO , @GTK_STOCK_REDO ,_
	@GTK_STOCK_DELETE , @GTK_STOCK_NEW , @GTK_STOCK_OPEN , @GTK_STOCK_SAVE , @GTK_STOCK_PRINT_PREVIEW , _
	@GTK_STOCK_PROPERTIES , @GTK_STOCK_HELP , @GTK_STOCK_FIND , @GTK_STOCK_FIND_AND_REPLACE , @GTK_STOCK_PRINT}
	
	dim as any ptr iButton
	
	dim pStr as zstring ptr 
	
	if iIndexImage >= 0 andalso iIndexImage <= 14 then
		
		pStr = iIndexIm(iIndexImage)
		
	EndIf
	
	if iStyle2 = TBSTYLE_CHECK then
		
		iButton = gtk_toggle_tool_button_new_from_stock(pStr)
		
	else
		
		iButton = gtk_tool_button_new_from_stock(pStr)
		
	EndIf
	
#else

	dim iIndexIm(14) as GtkStock = {GTK_STOCK_CUT , GTK_STOCK_COPY , GTK_STOCK_PASTE , GTK_STOCK_UNDO , GTK_STOCK_REDO ,_
	GTK_STOCK_DELETE , GTK_STOCK_NEW , GTK_STOCK_OPEN , GTK_STOCK_SAVE , GTK_STOCK_PRINT_PREVIEW , _
	GTK_STOCK_PROPERTIES , GTK_STOCK_HELP , GTK_STOCK_FIND , GTK_STOCK_FIND_AND_REPLACE , GTK_STOCK_PRINT}
	
	dim as any ptr iButton

	dim pStr as GtkStock
	
	if iIndexImage >= 0 andalso iIndexImage <= 14 then
		
		pStr = iIndexIm(iIndexImage)
		
	EndIf
	
	if iStyle2 = TBSTYLE_CHECK then
		
		iButton = gtk_toggle_tool_button_new_from_stock(pStr)
		
	else
		
		iButton = gtk_tool_button_new_from_stock(pStr)
		
	EndIf


#endif	
	
	if sString <> "" then
		
		gtk_toolbar_set_style(GTK_TOOLBAR(iHwndToolBar), GTK_TOOLBAR_BOTH)
		
		gtk_tool_button_set_label(iButton , strptr(sString))
		
	else
		
		gtk_tool_button_set_label(iButton , "")
		
	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