#include once "inc/wx.bi"

const BUTTON_START_ID = 1
const BUTTON_STOP_ID  = 2
const TIMER_ID        = 3

Dim Shared As _wxApp        Ptr App
Dim Shared As _wxFrame      Ptr Frame
Dim Shared As _wxTimer      Ptr Ticker
Dim Shared As _wxButton     Ptr ButtonStart
Dim Shared As _wxButton     Ptr ButtonStop
Dim Shared as _wxStaticText Ptr StaticText
Sub EventListener APICALL(event As _wxEvent Ptr,iListener as wxInt)
  static as wxInt nTicks = 0
  select case wxEvent_GetId(event)
  case BUTTON_START_ID
    wxWindow_Enable(ButtonStart,WX_FALSE)
    wxWindow_Enable(ButtonStop ,WX_TRUE)
    wxTimer_Start(Ticker,20)
  case BUTTON_STOP_ID
    wxTimer_Stop(Ticker)
    wxWindow_Enable(ButtonStop ,WX_FALSE)
    wxWindow_Enable(ButtonStart,WX_TRUE)
  case TIMER_ID
    nticks+=1
    wxWindow_SetLabel(StaticText, wxString("number of ticks = " & nTicks))
  end select
End Sub

function App_OnInit APICALL( ) as wxBool
  Frame = wxFrame_ctor( )
  wxFrame_Create(Frame,,,wxString("test for wxTimer"), _
                 ,, 390, 390, _
                 wxFRAME_DEFAULT_STYLE Or  wxCLOSE_BOX _
                 Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER)
                 
  Dim As _wxPanel Ptr Panel = wxPanel_ctor2(Frame)

  ButtonStart = wxButton_ctor()
  wxButton_Create(Buttonstart, Panel, BUTTON_START_ID, wxString("start"), 10, 10)
  
  wxEvtHandler_proxy(ButtonStart, @EventListener)
  wxEvtHandler_Connect(ButtonStart, wxEvent_EVT_COMMAND_BUTTON_CLICKED())

  ButtonStop = wxButton_ctor()
  wxButton_Create(ButtonStop, Panel, BUTTON_STOP_ID, wxString("stop"),  10, 40)
  wxWindow_Enable(ButtonStop,WX_FALSE)

  wxEvtHandler_proxy(ButtonStop, @EventListener)
  wxEvtHandler_Connect(ButtonStop, wxEvent_EVT_COMMAND_BUTTON_CLICKED())

  StaticText = wxStaticText_ctor()
  wxStaticText_Create(StaticText, Panel,,wxString("nTicks"),10,70)
  
  Ticker = wxTimer_ctor(Frame,TIMER_ID)
  wxEvtHandler_proxy(Frame, @EventListener)
  wxEvtHandler_Connect(Frame, wxEvent_EVT_TIMER())

  wxWindow_Show(Frame, 1 )
  
  return wxApp_OnInit(App)
End function

function App_OnExit APICALL as wxInt
  return wxApp_OnExit(App )
End function

''main
App = wxApp_ctor()
wxApp_RegisterVirtual App, @App_OnInit, @App_OnExit
wxApp_Run()
 

