#include Once "window9.bi"

Sub Freegadget (iGadget As Long) Export
	
	Dim As ListT Ptr pTemp = pGlobalTypeWindow9->ListGadgets->findNodeFunc(iGadget)
	
	If pTemp <> 0 Then
		
		Dim As hwnd pWidget = Cast(hwnd,pTemp->anyTwoData)
		
		If GTK_IS_WIDGET(pWidget) Then
			
			Dim As hwnd Parent = gtk_widget_get_parent(pWidget)
			
			Select Case pTemp->anyThreeData
					' 1 - buttongadget
					' 2 - editorgadget
					' 3 - ButtonImageGadget	
					' 4 - ImageGadget
					' 5 - TextGadget
					' 6 - StringGadget
					' 7 - SpinGadget
					' 8 - CalendarGadget
					' 9 - CheckBoxGadget
					' 10 - OptionGadget
					' 11 - HyperLinkGadget
					' 12 - TrackBarGadget
					' 13 - ComboBoxGadget
					' 14 - ComboBoxImageGadget
					' 15 - ListBoxGadget
					' 16 - GroupGadget
					' 17 - WebGadget
					' 18 - ProgressBarGadget
					' 19 - ListViewGadget
					' 20 - TreeViewGadget
					' 21 - ContainerGadget
					' 22 - PanelGadget
					' 23 - ScrollBarGadget
					' 24 - GadgetToolTip
					' 25 - SysTray
					' 26 - OpenGlGadget
					' 27 - StatusBarGadget
					' 28 - PannedGadget
					
				Case 1 , 3 , 6 ,  8 , 9 , 10 , 13 , 14 , 16 , 22 , 23 , 26 , 28
					
					gtk_widget_destroy(Parent)
					
				Case 2 , 11 , 15 , 19 
					
					Parent = gtk_widget_get_parent(Parent)
					
					gtk_widget_destroy(Parent)	
					
				Case 4 
					
					Dim As ListT Ptr pListTemp = pGlobalTypeWindow9->ListWinAndContainers->findNodeFunc(Cint(pWidget))
					
					Dim As Any Ptr SavedImage = Cast(Any Ptr,pListTemp->anyTwoData)
					
					g_object_unref (gtk_image_get_pixbuf(SavedImage))				
					
					pGlobalTypeWindow9->ListWinAndContainers->removeNodeSub(Cint(pWidget))
					
					gtk_widget_destroy(Parent)
					
				Case 5
					
					If g_object_get_data(G_OBJECT(pWidget), "notify") Then
						
						Parent = gtk_widget_get_parent(Parent)
						
						gtk_widget_destroy(Parent)	
						
					Else
						
						gtk_widget_destroy(Parent)
						
					Endif					
					
				Case 7 , 12  , 18
					
					pGlobalTypeWindow9->ListRangeForSliders->removeNodeSub(Cint(iGadget))
					
					gtk_widget_destroy(Parent)
					
				Case 17
					
					#ifdef __USE_GTK3__
					
					gtk_widget_destroy(Parent)
					
					#else
					
					Parent = gtk_widget_get_parent(Parent)
					
					gtk_widget_destroy(Parent)					
					
					#endif
					
				Case 20	
					
					Dim As Any Ptr model = gtk_tree_view_get_model(Cast(Any Ptr,pWidget))
					
					Dim As LinList Ptr imglist = Cast(Any Ptr, g_object_get_data (Cast(Any Ptr,model), "tree_img_list"))
					
					imglist->removeList(imglist)
					
					Parent = gtk_widget_get_parent(Parent)
					
					gtk_widget_destroy(Parent)
					
				Case 21
					
					Dim As ListT Ptr pListTemp = pGlobalTypeWindow9->ListWinAndContainers->findNodeFunc(Cint(pWidget))
					
					pGlobalTypeWindow9->ListWinAndContainers->removeNodeSub(Cint(pWidget))
					
					gtk_widget_destroy(Parent)
					
				Case 27
					
					'#ifndef __USE_GTK3__ 
					
					disconnect(pWidget)
					
					gtk_widget_destroy(Parent)
					
					'#endif
					
			End Select
			
		Endif
		
		pGlobalTypeWindow9->ListGadgets->removeNodeSub(Cint(iGadget))
		
	Endif
	
End Sub