#include Once "window9.bi"

Function Buttonimagegadget(iGadget As Long , x As Long , y As Long , width_ As Long , height_ As Long , image As Hbitmap , style As Long = 0) As HWND Export
	
	Dim As HWND button , vBox , mainBox
	
	Dim As ListT Ptr pListTemp

	Freegadget(iGadget)
	
	pGlobalTypeWindow9->OptGroup = 0 ' reset Group OptionGadget
	
	pListTemp = Cast(ListT Ptr,pGlobalTypeWindow9->ListWinAndContainers->findNodeFunc(Cint(pGlobalTypeWindow9->CurentHwnd)))
	
	mainBox = Cast(hwnd , pListTemp->anyTwoData)	

	vbox = gtk_fixed_new()

	gtk_container_add (GTK_CONTAINER(mainBox), vbox)
	
	If style = FB_BS_PUSHLIKE Then
	
		button = gtk_toggle_button_new()
		
	Else
	
		button = gtk_button_new()	

	Endif
	
	pGlobalTypeWindow9->ListGadgets->addNodeSub(iGadget , Cint(button) ,  3)

	gtk_widget_set_size_request(button, width_, height_)
	
	gtk_fixed_put(GTK_FIXED(vbox), button, x , y)
	
	If image <> 0 Then	
		
		Dim As GdkPixbuf Ptr  pix2
		
		Dim As gint wIm ,hIm , xTemp  , yTemp , wTemp , hTemp 
		
		wIm = gdk_pixbuf_get_width(image)

		hIm = gdk_pixbuf_get_height(image)
		
		If (wIm + 10) >  width_ Then
	
			wTemp = width_ - 10
			
			xTemp = wIm\2 - wTemp\2
			
		Else 
		
			wTemp = wIm	
			
			xTemp = 0

		Endif
		
		If (hIm + 10) >  height_ Then
	
			hTemp = height_ - 10
			
			yTemp = hIm\2 - hTemp\2
			
		Else 
		
			hTemp = hIm	
			
			yTemp = 0

		Endif
		
		pix2 = gdk_pixbuf_new_subpixbuf ( image , xTemp , yTemp , wTemp , hTemp)
		
		Dim As Any Ptr imTemp  = gtk_image_new_from_pixbuf(pix2)
		
		g_object_unref (pix2)
		
		gtk_button_set_image(Cast(Any Ptr,button),imTemp)
		
	Endif
	
	g_object_set_data (Cast(Any Ptr, button), "BITMAP" , Cast(Any Ptr,image))	
	
	tree_add_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)
	
	Dim As Node Ptr fNode = tree_find_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)
	
	g_object_set_data (Cast(Any Ptr, button), "X_SIZE" , Cast(Any Ptr,Cint(x)))
	
	g_object_set_data (Cast(Any Ptr, button), "Y_SIZE" , Cast(Any Ptr,Cint(y)))
	
	g_object_set_data (Cast(Any Ptr, button), "W_SIZE" , Cast(Any Ptr,Cint(width_)))
	
	g_object_set_data (Cast(Any Ptr, button), "H_SIZE" , Cast(Any Ptr,Cint(height_)))		

	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK (@EventsButtonClickSub), @(fNode->x))
	
	g_signal_connect(G_OBJECT(button), "size-allocate", G_CALLBACK (@size_allocate_signals), @(fNode->x))
	
	gtk_widget_show(vBox)

	gtk_widget_show(button)
	
	Return button
	
End Function
