#include Once "window9.bi"

Private Function w9CallEvents Cdecl(p As gpointer) As gboolean
	
	Static iIndex As Long
	
	If iIndex < 1005 Then
		
		iIndex+=1
		
		Return True
		
	Else
		
		iIndex = 0
		
		Return False
		
	Endif
	
End Function

Function Waitevent() As Long Export
	
	Static iFlagIdle As Long
	
	If pGlobalTypeWindow9->indexEvent Andalso iFlagIdle = 0 Then
		
		g_idle_add (@w9CallEvents, Cast(Any Ptr , 0))
		
		iFlagIdle = 1
		
	Endif
	
	gtk_main_iteration()
	
	If pGlobalTypeWindow9->indexEvent > 0 Then	
		
		Dim As Long iCurEvent = pGlobalTypeWindow9->DIMSTOREEVENT(0).event_
		
		Select Case iCurEvent
				
			Case Eventmove
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w
				
				pGlobalTypeWindow9->indexEvent-=1	
				
				Function = Eventmove
				
			Case Eventgadget
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w				
				
				pGlobalTypeWindow9->Eventnumber = pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumber
				
				pGlobalTypeWindow9->iIndexColumnListView = pGlobalTypeWindow9->DIMSTOREEVENT(0).param1
				
				If Getclassgadget(Id_in_number(pGlobalTypeWindow9->Eventhwnd)) = 19 Then
					
					GetItemSubItemListView(pGlobalTypeWindow9->Eventhwnd)
					
				Endif				
				
				pGlobalTypeWindow9->indexEvent-=1	
				
				Function = Eventgadget
				
			Case Eventmenu
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w				
				
				pGlobalTypeWindow9->Eventnumber = pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumber
				
				pGlobalTypeWindow9->indexEvent-=1	
				
				Function = Eventmenu										
				
			Case Eventmousemove
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w
				
				pGlobalTypeWindow9->Eventkey = pGlobalTypeWindow9->DIMSTOREEVENT(0).param1
				
				pGlobalTypeWindow9->Mousex = Loword(pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumber)
				
				pGlobalTypeWindow9->Mousey = Hiword(pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumber)
				
				pGlobalTypeWindow9->indexEvent-=1		
				
				Function = Eventmousemove
				
			Case Eventmousewheel
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w
				
				pGlobalTypeWindow9->Eventkey = pGlobalTypeWindow9->DIMSTOREEVENT(0).param1
				
				pGlobalTypeWindow9->indexEvent-=1
				
				Function = Eventmousewheel					
				
			Case Eventactivate
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w
				
				pGlobalTypeWindow9->indexEvent-=1	
				
				Function = Eventactivate
				
			Case Eventsize
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w
				
				pGlobalTypeWindow9->indexEvent-=1		
				
				Function = Eventsize
				
			Case Eventkeydown , Eventkeyup
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w
				
				pGlobalTypeWindow9->Eventkey = pGlobalTypeWindow9->DIMSTOREEVENT(0).param1
				
				pGlobalTypeWindow9->EventKeyHardware = pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumber
				
				pGlobalTypeWindow9->indexEvent-=1	
				
				Function = iCurEvent
				
			Case Eventlbdown , Eventrbdown , Eventmbdown , Eventlbup , 	Eventrbup , Eventmbup ,	Eventdblclick
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w
				
				pGlobalTypeWindow9->Eventkey = pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumber
				
				pGlobalTypeWindow9->Mousex = Loword(pGlobalTypeWindow9->DIMSTOREEVENT(0).param1)
				
				pGlobalTypeWindow9->Mousey = Hiword(pGlobalTypeWindow9->DIMSTOREEVENT(0).param1)
				
				Dim As Long iNumber = Id_in_number(pGlobalTypeWindow9->Eventhwnd)
				
				Dim As Long iCl = Getclassgadget(iNumber)
				
				If iCl = 19 Then
					
					pGlobalTypeWindow9->Eventnumberlistview = pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumberlistview
					
					pGlobalTypeWindow9->Eventnumber = pGlobalTypeWindow9->Eventnumberlistview
					
					GetItemSubItemListView(pGlobalTypeWindow9->Eventhwnd)
					
					Flagkeylistview(pGlobalTypeWindow9->Eventkey)
					
				Elseif iCl = 20 Then
					
					pGlobalTypeWindow9->Eventnumbertreeview = pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumbertreeview
					
				Elseif iCl = 25 Orelse iCl = 26 Orelse iCl = 22 Then	
					
					pGlobalTypeWindow9->Eventnumber = iNumber
					
				Else
					
					pGlobalTypeWindow9->Eventnumberlistview = 0
					
					pGlobalTypeWindow9->Eventnumbertreeview = 0
					
					pGlobalTypeWindow9->Eventnumber = 0
					
				Endif
				
				pGlobalTypeWindow9->indexEvent-=1				
				
				Function = iCurEvent
				
			Case Eventtimer
				
				pGlobalTypeWindow9->Eventnumber = pGlobalTypeWindow9->DIMSTOREEVENT(0).Eventnumber
				
				pGlobalTypeWindow9->indexEvent-=1	
				
				Function = Eventtimer					
				
			Case Eventclose		
				
				pGlobalTypeWindow9->Eventhwnd = pGlobalTypeWindow9->DIMSTOREEVENT(0).w 
				
				pGlobalTypeWindow9->indexEvent-=1	
				
				Function = Eventclose																
				
		End Select
		
		For i As Long = 0 To pGlobalTypeWindow9->indexEvent
			
			pGlobalTypeWindow9->DIMSTOREEVENT(i).w = pGlobalTypeWindow9->DIMSTOREEVENT(i+1).w
			
			pGlobalTypeWindow9->DIMSTOREEVENT(i).Eventnumber = pGlobalTypeWindow9->DIMSTOREEVENT(i+1).Eventnumber
			
			pGlobalTypeWindow9->DIMSTOREEVENT(i).Eventnumberlistview = pGlobalTypeWindow9->DIMSTOREEVENT(i+1).Eventnumberlistview
			
			pGlobalTypeWindow9->DIMSTOREEVENT(i).Eventnumbertreeview = pGlobalTypeWindow9->DIMSTOREEVENT(i+1).Eventnumbertreeview
			
			pGlobalTypeWindow9->DIMSTOREEVENT(i).param1 = pGlobalTypeWindow9->DIMSTOREEVENT(i+1).param1
			
			pGlobalTypeWindow9->DIMSTOREEVENT(i).event_ = pGlobalTypeWindow9->DIMSTOREEVENT(i+1).event_
			
		Next
		
	Else
		
		iFlagIdle = 0
		
	Endif			
	
End Function