#Include ONCE "../Inc/Translate.bi"

Function ClassTranslate.MainEvent() As bool

	Do

		iEvent=WaitEvent()

		Select Case iEvent

			Case EventGadget

				If EventNumber = BUTTON_CONFIRM Then

					Translate(FALSE)

				EndIf

			Case  EventRbDOWN

				If EventNumber = SYSTRAY Then
					
					DisplayPopupMenu(hMenu,GlobalMouseX,GlobalMouseY)
					
				EndIf
				
				If IsMouseOver(GadgetID(EDITOR_IN)) Then
					
					ActiveGadget = EDITOR_IN
					
					DisplayPopupMenu(hMenu2,GlobalMouseX,GlobalMouseY)					
					
				ElseIf IsMouseOver(GadgetID(EDITOR_OUT)) Then
					
					ActiveGadget = EDITOR_OUT
					
					DisplayPopupMenu(hMenu2,GlobalMouseX,GlobalMouseY)				
					
				EndIf

			Case EventMenu

				Select Case EventNumber

					Case MENUCLOSE

						DeleteSysTrayIcon(SYSTRAY)

						UnregisterHotKey(hwndMain, HOTKEY)

						Return 1

					Case MENUOPENWINDOW

						HideWindow(hwndMain, FALSE)
											
					Case MENUCOPY
						
						SetClipBoardText(GetSelectTextEditorGadget(ActiveGadget))
						
					Case MENUPASTE
						
						PasteEditor(ActiveGadget,GetClipBoardText)
						
					Case MENUSELECTALL
						
						SetSelectTextEditorGadget(ActiveGadget,1,-1)

				End Select
				
			Case EventSize
				
            ResizeGadget(EDITOR_IN,,,WindowWidth(hwndMain)-35,(WindowHeight(hwndMain)-98)\2)	
            
            ResizeGadget(EDITOR_OUT,,GadgetHeight(EDITOR_IN)+58,WindowWidth(hwndMain)-35,(WindowHeight(hwndMain)-98)\2)
            
            ResizeGadget(COMBO_LANG,,GadgetHeight(EDITOR_IN)+22)	
            
            ResizeGadget(BUTTON_CONFIRM,,GadgetHeight(EDITOR_IN)+22)            
            	

			Case WM_HOTKEY

				If EventWParam = HOTKEY Then

					Translate(TRUE)

				EndIf

			Case eventclose

				HideWindow(hwndMain, TRUE)

		End Select

	Loop

End Function
