#include ONCE "window9.bi"

function Insert_Menu(iNumberMenu as Long  ,titleMenu as HMENU , sTitle as string , iNumberSpace as Long , iFlag as Long = 0) as HMENU export
	
	dim as Long iPos

	dim as ListT ptr pListTemp
	
	dim as HMENU saveditemMenu
	
	pListTemp = cast(ListT ptr,pGlobalTypeWindow9->ListMenus->findNodeFunc(cint(iNumberSpace)))
	
	if pListTemp then
	
		saveditemMenu = cast(hwnd , pListTemp->anyTwoData)
		
		if (GTK_IS_CONTAINER(titleMenu)) then
			
			dim as GList ptr children = gtk_container_get_children(GTK_CONTAINER(titleMenu))
			
			do
				
				if children->data = saveditemMenu then
					
					exit do

				EndIf
				
				children = g_list_next(children)
				
				iPos+=1
				
				if children = 0 then 
					
					iPos = -1
					
					exit do

				EndIf
			
			loop
		
		endif
		
	else
		
		if iNumberSpace = 0 then
	
			iPos = 0
			
		else
		
			iPos = -1

		EndIf
		
	endif	
	
	dim as HMENU itemMenu = gtk_image_menu_item_new_with_label(Strptr(sTitle))
	
	gtk_menu_shell_insert (GTK_MENU_SHELL (titleMenu), itemMenu , iPos)
	
	g_object_set_data (cast(any ptr, itemMenu), "IDmenu" , cast(any ptr,cast(integer , iNumberMenu)))
	
	g_object_set_data (cast(any ptr, itemMenu), "Check" , cast(any ptr,cast(integer , 0)))
	
	pGlobalTypeWindow9->ListMenus->addNodeSub(cint(iNumberMenu), cint(itemMenu) , cint(titleMenu) )
	
	g_signal_connect_swapped (G_OBJECT (itemMenu), "activate",_
	G_CALLBACK (@EventActivateMenuSub), itemMenu)	
	
	gtk_widget_show (itemMenu)	
	
	return itemMenu
	
End Function