#Include "wx-c 0.9.2/wx.bi"

Declare Function App_OnInit( ) As wxBool
Declare Function App_OnExit( ) As Integer

Declare Sub textctrl0_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button0_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button1_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button2_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button3_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button4_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button5_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button6_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button7_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button8_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button9_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button10_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button11_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button12_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button13_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
Declare Sub button14_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )

Dim Shared As wxApp Ptr wx_app
Dim Shared As wxFrame Ptr wx_frame
Dim Shared As wxPanel Ptr wx_panel

Dim Shared As wxTextCtrl Ptr textctrl0

Dim Shared As Integer art
Dim Shared As String eingabe

Function loesen(art As Integer, eingabe As String) As String
	Static As Integer z
	Dim As String ausgabe
	
	If eingabe = "" Then
		If z = 0 Then
			Return "0"
		Else
			eingabe = Str(z)
		EndIf
	EndIf
	
	If z = 0 Then
		ausgabe = eingabe
	Else
		Select Case art
			Case 1
				ausgabe = Str(z + ValInt(eingabe))
			Case 2
				ausgabe = Str(z - ValInt(eingabe))
			Case 3
				ausgabe = Str(z * ValInt(eingabe))
			Case 4
				ausgabe = Str(z / ValInt(eingabe))
			Case Else
				ausgabe = eingabe
		End Select
	EndIf
	
	z = ValInt(ausgabe)
	
	Return ausgabe
	
End Function

Function App_OnInit( ) As wxBool
	
	wxImage_InitAllHandlers( )
    
    wx_frame = wxFrame_ctor( )
    wxFrame_Create( wx_frame, 0, -1, wxString_ctorUTF8("WX-C Calc"), 483, 184, 197, 279, wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER, 0 )
    wx_panel = wxPanel_ctor2( wx_frame, -1, -1, -1, -1, -1, 0, 0 )
    
    '' Application Icon
    Dim As wxIcon Ptr appIcon
    Dim As wxBitmap Ptr iconImage
    appIcon = wxIcon_ctor( )
    iconImage = wxBitmap_ctor( )
    wxBitmap_LoadFile( iconImage, wxString_ctorUTF8("media/icon.ico"), wxBITMAP_TYPE_ICO )
    wxIcon_CopyFromBitmap( appIcon, iconImage )
    wxFrame_SetIcon( wx_frame, appIcon )
    
    ''
    '' create widget textctrl0
    ''
    textctrl0 = wxTextCtrl_ctor( )
    wxTextCtrl_Create( textctrl0, wx_panel, -1, wxString_ctorUTF8("0"), 10, 10, 170, 20, wxTE_RIGHT /'Or wxTE_READONLY'/, 0, 0 )
    
    wxEvtHandler_Proxy( textctrl0, Cast(EventListener, @textctrl0_event) )
    wxEvtHandler_Connect( textctrl0, wxEvent_EVT_COMMAND_TEXT_ENTER( ), -1, -1, 0 )
    
    ''
    '' create widget button0
    ''
    Dim As wxButton Ptr button0
    button0 = wxButton_ctor( )
    wxButton_Create( button0, wx_panel, -1, wxString_ctorUTF8("0"), 70, 130, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button0, Cast(EventListener, @button0_event) )
    wxEvtHandler_Connect( button0, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button1
    ''
    Dim As wxButton Ptr button1
    button1 = wxButton_ctor( )
    wxButton_Create( button1, wx_panel, -1, wxString_ctorUTF8("1"), 10, 40, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button1, Cast(EventListener, @button1_event) )
    wxEvtHandler_Connect( button1, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button2
    ''
    Dim As wxButton Ptr button2
    button2 = wxButton_ctor( )
    wxButton_Create( button2, wx_panel, -1, wxString_ctorUTF8("2"), 70, 40, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button2, Cast(EventListener, @button2_event) )
    wxEvtHandler_Connect( button2, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button3
    ''
    Dim As wxButton Ptr button3
    button3 = wxButton_ctor( )
    wxButton_Create( button3, wx_panel, -1, wxString_ctorUTF8("3"), 130, 40, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button3, Cast(EventListener, @button3_event) )
    wxEvtHandler_Connect( button3, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button4
    ''
    Dim As wxButton Ptr button4
    button4 = wxButton_ctor( )
    wxButton_Create( button4, wx_panel, -1, wxString_ctorUTF8("4"), 10, 70, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button4, Cast(EventListener, @button4_event) )
    wxEvtHandler_Connect( button4, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button5
    ''
    Dim As wxButton Ptr button5
    button5 = wxButton_ctor( )
    wxButton_Create( button5, wx_panel, -1, wxString_ctorUTF8("5"), 70, 70, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button5, Cast(EventListener, @button5_event) )
    wxEvtHandler_Connect( button5, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button6
    ''
    Dim As wxButton Ptr button6
    button6 = wxButton_ctor( )
    wxButton_Create( button6, wx_panel, -1, wxString_ctorUTF8("6"), 130, 70, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button6, Cast(EventListener, @button6_event) )
    wxEvtHandler_Connect( button6, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button7
    ''
    Dim As wxButton Ptr button7
    button7 = wxButton_ctor( )
    wxButton_Create( button7, wx_panel, -1, wxString_ctorUTF8("7"), 10, 100, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button7, Cast(EventListener, @button7_event) )
    wxEvtHandler_Connect( button7, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button8
    ''
    Dim As wxButton Ptr button8
    button8 = wxButton_ctor( )
    wxButton_Create( button8, wx_panel, -1, wxString_ctorUTF8("8"), 70, 100, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button8, Cast(EventListener, @button8_event) )
    wxEvtHandler_Connect( button8, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button9
    ''
    Dim As wxButton Ptr button9
    button9 = wxButton_ctor( )
    wxButton_Create( button9, wx_panel, -1, wxString_ctorUTF8("9"), 130, 100, 50, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button9, Cast(EventListener, @button9_event) )
    wxEvtHandler_Connect( button9, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button10
    ''
    Dim As wxButton Ptr button10
    button10 = wxButton_ctor( )
    wxButton_Create( button10, wx_panel, -1, wxString_ctorUTF8("+"), 10, 160, 80, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button10, Cast(EventListener, @button10_event) )
    wxEvtHandler_Connect( button10, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button11
    ''
    Dim As wxButton Ptr button11
    button11 = wxButton_ctor( )
    wxButton_Create( button11, wx_panel, -1, wxString_ctorUTF8("-"), 100, 160, 80, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button11, Cast(EventListener, @button11_event) )
    wxEvtHandler_Connect( button11, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button12
    ''
    Dim As wxButton Ptr button12
    button12 = wxButton_ctor( )
    wxButton_Create( button12, wx_panel, -1, wxString_ctorUTF8("*"), 10, 190, 80, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button12, Cast(EventListener, @button12_event) )
    wxEvtHandler_Connect( button12, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button13
    ''
    Dim As wxButton Ptr button13
    button13 = wxButton_ctor( )
    wxButton_Create( button13, wx_panel, -1, wxString_ctorUTF8("/"), 100, 190, 80, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button13, Cast(EventListener, @button13_event) )
    wxEvtHandler_Connect( button13, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    ''
    '' create widget button14
    ''
    Dim As wxButton Ptr button14
    button14 = wxButton_ctor( )
    wxButton_Create( button14, wx_panel, -1, wxString_ctorUTF8("="), 10, 220, 170, 20, 0, 0, 0 )
    
    wxEvtHandler_Proxy( button14, Cast(EventListener, @button14_event) )
    wxEvtHandler_Connect( button14, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
    
    wxWindow_Show( wx_frame, 1 )
    wxApp_OnInit( wx_app )
    
    Return 1
    
End Function

Function App_OnExit( ) As Integer
    
    Return wxApp_OnExit( wx_app )
    
End Function

Sub textctrl0_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_TEXT_ENTER
            ''stuff
    End Select
    
End Sub

Sub button0_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            If eingabe <> "" Then
	            eingabe += "0"
	            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
            EndIf
    End Select
    
End Sub

Sub button1_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "1"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button2_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "2"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button3_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "3"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button4_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "4"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button5_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "5"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button6_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "6"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button7_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "7"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button8_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "8"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button9_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            eingabe += "9"
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(Str(eingabe)) )
    End Select
    
End Sub

Sub button10_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(loesen(art, eingabe)) )
            art = 1
            eingabe = ""
    End Select
    
End Sub

Sub button11_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(loesen(art, eingabe)) )
            art = 2
            eingabe = ""
    End Select
    
End Sub

Sub button12_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(loesen(art, eingabe)) )
            art = 3
            eingabe = ""
    End Select
    
End Sub

Sub button13_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(loesen(art, eingabe)) )
            art = 4
            eingabe = ""
    End Select
    
End Sub

Sub button14_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetEventType( event )
        Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
            ''stuff
            wxTextCtrl_SetValue( textctrl0, wxString_ctorUTF8(loesen(art, eingabe)) )
            art = 0
            eingabe = ""
    End Select
    
End Sub


''main
wx_app = wxApp_ctor( )
wxApp_RegisterVirtual ( wx_app, @App_OnInit, @App_OnExit )
wxApp_Run(0, 0)
End
