''Code emitter

#Include Once "inc/Visual_WX-C_Designer.bi"

Declare Sub writemenu( ByVal menu As VWX_Menu Ptr, framedec As String, eventsubs As String, ByRef idcount As Integer, ByRef menucount As Integer, ByVal indent As String )

''
'' Emits code
''
Sub emitcode(ByVal filename As String)
	Dim As VWX_Widget Ptr widget
	Dim As Integer i, j, idcount = 1
	Static As Integer bbtncounter = 0 ' bitmapbutton-helper
	Dim As Integer FF
	
	'Delete everything
	FF = FreeFile
	Open filename For Output As #FF
	Close #FF
	
	FF = FreeFile
	Open filename For Binary As #FF
	
	Dim As String preprocessors = "#Include ""wx-c 0.9.2/wx.bi""" + NEWLINE + NEWLINE
	
	Dim As String shareds = NEWLINE + "Dim Shared As wxApp Ptr wx_app" + NEWLINE + _
							"Dim Shared As wxFrame Ptr wx_frame" + NEWLINE + _
							"Dim Shared As wxPanel Ptr wx_panel" + NEWLINE + NEWLINE
							
	Dim As String initsub = "Function App_OnInit WXCALL ( ) As wxBool" + NEWLINE + "	" + NEWLINE + _
							"	wx_frame = wxFrame_ctor( )" + NEWLINE
							
	Dim As String subs =	"	wxWindow_Show( wx_frame, 1 )" + NEWLINE + _
							"	wxApp_OnInit( wx_app )" + NEWLINE + _
							"	Return 1" + NEWLINE + "	" + NEWLINE + _
							"End Function" + NEWLINE + NEWLINE + _
							"Function App_OnExit WXCALL ( ) As wxInt" + NEWLINE + "	" + NEWLINE + _
							"	Return wxApp_OnExit( wx_app )" + NEWLINE + "	" + NEWLINE + _
							"End Function" + NEWLINE + NEWLINE
							
	Dim As String mainpart = NEWLINE + "''main" + NEWLINE + _
							"wx_app = wxApp_ctor( )" + NEWLINE + _
							"wxApp_RegisterVirtual ( wx_app, @App_OnInit, @App_OnExit )" + NEWLINE + _
							"wxApp_Run(0, 0)" + NEWLINE
							
	Dim As String addHandler' = "	wxImage_InitAllHandlers( )"
	
	''declares go here
	
	Dim As String declares = "Declare Function App_OnInit WXCALL ( ) As wxBool" + NEWLINE + _
							 "Declare Function App_OnExit WXCALL ( ) As wxInt" + NEWLINE + NEWLINE
	
	widget = Cast(VWX_Widget Ptr, listGetFirstNode( @widgetlist ))
	While widget <> NULL
		
		If widget->events( UBound( widget->events ) ) = 1 Then
			declares += "Declare Sub " + widget->Name + "_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As wxInt )" + NEWLINE
		EndIf
		
		widget = Cast(VWX_Widget Ptr, listGetNextNode( Cast(TLISTNODE Ptr, widget) ))
		
	Wend
	
	If listGetFirstNode( @menulist ) <> NULL Or wxMenuBase_IsChecked( menu2, menu_toolbar ) Then
		
		declares += "Declare Sub menuhandler WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As wxInt )" + NEWLINE
		
	EndIf
	
	
	Dim As wxSize Ptr mysize, mysize2
	mysize = wxSize(-1, -1)
	mysize2 = wxSize(-1, -1)
	wxWindow_GetPosition(proj, mysize)
	wxWindow_GetSize(proj, mysize2)
	Dim As String temp
	Dim As String framedec = "	wxFrame_Create( wx_frame, WX_NULL, -1, wxString_ctorUTF8("""
	temp = wxString_to_fbstring(wxWindow_GetTitle(proj))
	framedec += temp
	framedec += """), " + Str(wxSize_GetWidth(mysize)) + ", " + Str(wxSize_GetHeight(mysize)) + ", " + Str(wxSize_GetWidth(mysize2)) + ", " + Str(wxSize_GetHeight(mysize2)) + ", "
	If (wxFrame_IsMaximized(proj)) Then
		framedec += "wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX, WX_NULL )" + NEWLINE + "	wxFrame_Maximize( wx_frame, WX_TRUE )" + NEWLINE
	Else
		framedec += "wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER, WX_NULL )" + NEWLINE
	EndIf
	
	framedec += "	wx_panel = wxPanel_ctor2( wx_frame, -1, -1, -1, -1, -1, 0, WX_NULL )" + NEWLINE + "	" + NEWLINE
	
	
	'Icon
	If app.icon <> "" Then
		framedec += "	'' Application Icon" + NEWLINE + _
					"	Dim As wxIcon Ptr wx_icon" + NEWLINE + _
					"	Dim As wxBitmap Ptr iconImage" + NEWLINE + _
					"	wx_icon = wxIcon_ctor( )" + NEWLINE + _
					"	iconImage = wxBitmap_ctor( )" + NEWLINE
		framedec += "	wxBitmap_LoadFile( iconImage, wxString_ctorUTF8(""" + app.icon + """), " + get_pictureTypeString(get_pictureType(app.icon)) + " )" + NEWLINE + _
					"	wxIcon_CopyFromBitmap( wx_icon, iconImage )" + NEWLINE + _
					"	wxFrame_SetIcon( wx_frame, wx_icon )" + NEWLINE + "	" + NEWLINE
		
		If get_pictureTypeString(get_pictureType(app.icon)) <> "wxBITMAP_TYPE_BMP" Then
			addHandler = "	wxImage_InitAllHandlers( )" + NEWLINE + "	" + NEWLINE
		EndIf
	EndIf
	
	
	widget = Cast(VWX_Widget Ptr, listGetFirstNode( @widgetlist ))
	While ( widget <> NULL )
		
		framedec += "	''" + NEWLINE + "	'' create widget " + widget->Name + NEWLINE + "	''" + NEWLINE
		
		Select Case widget->kind
			Case VWX_WIDGET_stattext
				framedec += "	Dim As wxStaticText Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxStaticText_ctor( )" + NEWLINE
				framedec += "	wxStaticText_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + str_replace(NEWLINE , NEWLINE, str_replace(SEPARATOR, SEPARATOR + SEPARATOR, widget->label)) + """), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0 )" + NEWLINE + "	" + NEWLINE
			
			Case VWX_WIDGET_button
				framedec += "	Dim As wxButton Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxButton_ctor( )" + NEWLINE
				framedec += "	wxButton_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + str_replace(NEWLINE, NEWLINE, str_replace(SEPARATOR, SEPARATOR + SEPARATOR, widget->label)) + """), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
			
			Case VWX_WIDGET_togglebutton
				framedec += "	Dim As wxToggleButton Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxToggleButton_ctor( )" + NEWLINE
				framedec += "	wxToggleButton_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + str_replace(NEWLINE, NEWLINE, str_replace(SEPARATOR, SEPARATOR + SEPARATOR, widget->label)) + """), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxToggleButton_GetValue( widget->self ) <> 0 Then
					framedec += "	wxToggleButton_SetValue( " + widget->Name + ", " + Str( wxToggleButton_GetValue( widget->self ) ) + " )" + NEWLINE + "	" + NEWLINE
				EndIf
			
			Case VWX_WIDGET_bmpbutton
				If bbtncounter = 0 Then
					shareds += "Dim Shared As wxBitmapButton Ptr bmpbuttons( " + Str(bmpbuttoncounter( 0 )) + " )" + NEWLINE + NEWLINE
				EndIf
				
				framedec += "	Dim As wxBitmap Ptr pic" + widget->Name + NEWLINE + _
							"	Dim As wxBitmapButton Ptr " + widget->Name + NEWLINE + "	" + NEWLINE + _
							"	pic" + widget->Name + " = wxBitmap_ctor( )" + NEWLINE + _
							"	wxBitmap_LoadFile( pic" + widget->Name + ", wxString_ctorUTF8(""" + getRelPath(widget->label) + """), " + get_pictureTypeString(get_pictureType(widget->label)) + " )" + NEWLINE + _
							"	" + widget->Name + " = wxBitmapButton_ctor( )" + NEWLINE + "	" + NEWLINE
				framedec += "	wxBitmapButton_RegisterVirtual( " + widget->Name + ", Cast(Virtual_OnSetBitmap, @" + widget->Name + "_cb) )" + NEWLINE + _
							"	bmpbuttons( " + Str(bbtncounter) + " ) = " + widget->Name + NEWLINE + "	" + NEWLINE
				framedec += "	wxBitmapButton_Create( " + widget->Name + ", wx_panel, -1, pic" + widget->Name + ", " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", wxBU_AUTODRAW, 0, 0 )" + NEWLINE + _
							"	wxWindow_SetBackgroundColour( " + widget->Name + ", wxColour_ctorByParts( 255, 255, 255 ) )" + NEWLINE + "	" + NEWLINE
				
				If get_pictureTypeString(get_pictureType(widget->label)) <> "wxBITMAP_TYPE_BMP" Then
					addHandler = "	wxImage_InitAllHandlers( )" + NEWLINE + "	" + NEWLINE
				EndIf
				
				declares += "Declare Sub " + widget->Name + "_cb( )" + NEWLINE
				subs += "Sub " + widget->Name + "_cb( )" + NEWLINE + _
						"	wxBitmapButton_OnSetBitmap( bmpbuttons( " + Str(bbtncounter) + " ) )" + NEWLINE + _
						"End Sub" + NEWLINE + NEWLINE
				bbtncounter += 1
			
			Case VWX_WIDGET_image
				framedec += "	Dim As wxBitmap Ptr pic" + widget->Name + NEWLINE + _
							"	Dim As wxStaticBitmap Ptr " + widget->Name + NEWLINE + "	" + NEWLINE + _
							"	pic" + widget->Name + " = wxBitmap_ctor( )" + NEWLINE + _
							"	" + widget->Name + " = wxStaticBitmap_ctor( )" + NEWLINE + "	" + NEWLINE
				framedec += "	wxBitmap_LoadFile( pic" + widget->Name + ", wxString_ctorUTF8(""" + getRelPath(widget->label) + """), " + get_pictureTypeString(get_pictureType(widget->label)) + " )" + NEWLINE + _
							"	wxStaticBitmap_Create( " + widget->Name + ", wx_panel, -1, pic" + widget->Name + ", " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0 )" + NEWLINE + "	" + NEWLINE
				
				If get_pictureTypeString(get_pictureType(widget->label)) <> "wxBITMAP_TYPE_BMP" Then
					addHandler = "	wxImage_InitAllHandlers( )" + NEWLINE + "	" + NEWLINE
				EndIf
			
			Case VWX_WIDGET_checkbox
				framedec += "	Dim As wxCheckBox Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxCheckBox_ctor( )" + NEWLINE
				framedec += "	wxCheckBox_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + str_replace(NEWLINE, NEWLINE, str_replace(SEPARATOR, SEPARATOR + SEPARATOR, widget->label)) + """), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxCheckbox_GetValue( widget->self ) <> 0 Then
					framedec += "	wxCheckBox_SetValue( " + widget->Name + ", " + Str( wxCheckbox_GetValue( widget->self ) ) + " )" + NEWLINE + "	" + NEWLINE
				EndIf
			
			Case VWX_WIDGET_choice
				Dim As String mystr
				framedec += "	Dim As wxArrayString Ptr " + widget->Name + "_str" + NEWLINE
				framedec += "	" + widget->Name + "_str = wxArrayString_ctor( )" + NEWLINE
				For j = 0 To wxChoice_GetCount(widget->self) - 1
					mystr = wxString_to_fbstring(wxChoice_GetString(widget->self, j))
					framedec += "	wxArrayString_Add( " + widget->Name + "_str, wxString_ctorUTF8( """ + str_replace(SEPARATOR, SEPARATOR + SEPARATOR, mystr)+""" ) )" + NEWLINE
				Next
				framedec += "	Dim As wxChoice Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxChoice_ctor( )" + NEWLINE + _
							"	wxChoice_Create( " + widget->Name + ", wx_panel, -1, " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", " + widget->Name + "_str, 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxChoice_GetSelection( widget->self ) <> 0 Then
					framedec += "	wxControlWithItems_SetSelection( " + widget->Name + ", " + Str(wxChoice_GetSelection(widget->self)) + " )" + NEWLINE +  "	" + NEWLINE
				EndIf
			
			Case VWX_WIDGET_combo
				Dim As String mystr
				framedec += "	Dim As wxArrayString Ptr " + widget->Name + "_str" + NEWLINE
				framedec += "	" + widget->Name + "_str = wxArrayString_ctor( )" + NEWLINE
				For j = 1 To wxChoice_GetCount(widget->self) - 1
					mystr = wxString_to_fbstring(wxChoice_GetString(widget->self, j))
					framedec += "	wxArrayString_Add( " + widget->Name + "_str, wxString_ctorUTF8( """ + str_replace(SEPARATOR, SEPARATOR + SEPARATOR, mystr) + """ ) )" + NEWLINE
				Next
				framedec += "	Dim As wxComboBox Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxComboBox_ctor( )" + NEWLINE +_
							"	wxComboBox_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + Mid(widget->label, 1, InStr(widget->label, !"\r") - 1) + """), wxPoint_ctor( " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + " ), wxSize_ctor( " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) +  " ), " + widget->Name + "_str, 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxChoice_GetSelection( widget->self ) <> 0 Then
					framedec += "	wxControlWithItems_SetSelection( " + widget->Name + ", " + Str(wxChoice_GetSelection(widget->self) - 1) + " )" + NEWLINE +  "	" + NEWLINE
				EndIf
			
        	Case VWX_WIDGET_textctrl
				framedec += "	Dim As wxTextCtrl Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxTextCtrl_ctor( )" + NEWLINE
				framedec += "	wxTextCtrl_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + str_replace(NEWLINE, NEWLINE,str_replace(SEPARATOR, SEPARATOR + SEPARATOR, widget->label)) + """), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_spinctrl
				framedec += "	Dim As wxSpinCtrl Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxSpinCtrl_ctor( )" + NEWLINE
				framedec += "	wxSpinCtrl_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""""), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", wxSP_ARROW_KEYS, " + Str(wxSpinCtrl_GetMin(widget->self)) + ", " + Str(wxSpinCtrl_GetMax(widget->self)) + ", " + Str(wxSpinCtrl_GetValue(widget->self)) + ", 0 )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_richtext
				framedec += "	Dim As wxTextCtrl Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxTextCtrl_ctor( )" + NEWLINE
				framedec += "	wxTextCtrl_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + str_replace(NEWLINE, NEWLINE,str_replace(SEPARATOR, SEPARATOR + SEPARATOR, widget->label)) + """), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", wxTE_PROCESS_ENTER Or wxTE_MULTILINE Or wxTE_Rich Or wxTE_RICH2, 0, 0 )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_gauge
				framedec += "	Dim As wxGauge Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxGauge_ctor( )" + NEWLINE
				framedec += "	wxGauge_Create( " + widget->Name + ", wx_panel, -1, " + Str(wxGauge_GetRange(widget->self)) + ", " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxGauge_GetValue( widget->self ) <> 0 Then
					framedec += "	wxGauge_SetValue( " + widget->Name + ", " + Str( wxGauge_GetValue( widget->self ) ) + " )" + NEWLINE + "	" + NEWLINE
				EndIf
			
        	Case VWX_WIDGET_radio
				Dim As String mystr
				framedec += "	Dim As wxArrayString Ptr " + widget->Name + "_str" + NEWLINE
				framedec += "	" + widget->Name + "_str = wxArrayString_ctor( )" + NEWLINE
				For j = 0 To wxRadioBox_GetCount(widget->self) - 1
					mystr = wxString_to_fbstring(wxRadiobox_GetString(widget->self, j))
					framedec += "	wxArrayString_Add( " + widget->Name + "_str, wxString_ctorUTF8( """ + str_replace(SEPARATOR, SEPARATOR + SEPARATOR, mystr) + """ ) )" + NEWLINE
				Next
				framedec += "	Dim As wxRadioBox Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxRadioBox_ctor( )" + NEWLINE + _
							"	wxRadioBox_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + Mid(widget->label, 1, InStr(widget->label, !"\r") - 1) + """), wxPoint_ctor( " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + " ), wxSize_ctor( " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + " ), " + widget->Name + "_str, 0, wxHORIZONTAL, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxRadioBox_GetSelection( widget->self ) <> 0 Then
					framedec += "	wxRadioBox_SetSelection( " + widget->Name + ", " + Str( wxRadioBox_GetSelection( widget->self ) ) + " )" + NEWLINE + "	" + NEWLINE
				EndIf
			
        	Case VWX_WIDGET_list
				Dim As String mystr
				framedec += "	Dim As wxArrayString Ptr " + widget->Name + "_str" + NEWLINE
				framedec += "	" + widget->Name + "_str = wxArrayString_ctor( )" + NEWLINE
				For j = 0 To wxListbox_GetCount(widget->self) - 1
					mystr = wxString_to_fbstring(wxListbox_GetSingleString(widget->self, j))
					framedec += "	wxArrayString_Add( " + widget->Name + "_str, wxString_ctorUTF8( """ + str_replace(SEPARATOR, SEPARATOR + SEPARATOR, mystr) + """ ) )" + NEWLINE
				Next
				framedec += "	Dim As wxListBox Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxListBox_ctor( )" + NEWLINE + _
							"	wxListBox_Create( " + widget->Name + ", wx_panel, -1, wxPoint_ctor( " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + " ), wxSize_ctor( " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + " ), " + widget->Name + "_str, 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxListBox_GetSelection( widget->self ) <> 0 Then
					framedec += "	wxListBox_SetSelection( " + widget->Name + ", " + Str(wxListBox_GetSelection( widget->self )) + ", WX_TRUE )" + NEWLINE + "	" + NEWLINE
				EndIf
			
        	Case VWX_WIDGET_staticbox
				framedec += "	Dim As wxStaticBox Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxStaticBox_ctor( )" + NEWLINE
				framedec += "	wxStaticBox_Create( " + widget->Name + ", wx_panel, -1, wxString_ctorUTF8(""" + str_replace(NEWLINE, NEWLINE, str_replace(SEPARATOR, SEPARATOR + SEPARATOR, widget->label)) + """), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0 )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_slider
				framedec += "	Dim As wxSlider Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxSlider_ctor( )" + NEWLINE
				framedec += "	wxSlider_Create( " + widget->Name + ", wx_panel, -1, " + Str(wxSlider_GetValue(widget->self)) + ", " + Str(wxSlider_GetMin(widget->self)) + ", " + Str(wxSlider_GetMax(widget->self)) + ", " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0 Or wxSL_LABELS, 0, 0 )" + NEWLINE
				framedec += "	wxSlider_SetValue( " + widget->Name + ", " + Str( wxSlider_GetValue( widget->self ) ) + " )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_staticline
				framedec += "	Dim As wxStaticLine Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxStaticLine_ctor( )" + NEWLINE
				framedec += "	wxStaticLine_Create( " + widget->Name + ", wx_panel, -1, " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0 )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_spinbutton
				framedec += "	Dim As wxSpinButton Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxSpinButton_ctor( )" + NEWLINE
				framedec += "	wxSpinButton_Create( " + widget->Name + ", wx_panel, -1, " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0 )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_calendar
				framedec += "	Dim As wxCalendarCtrl Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxCalendarCtrl_ctor( )" + NEWLINE
				framedec += "	wxCalendarCtrl_Create( " + widget->Name + ", wx_panel, -1, wxDateTime_ctor( ), " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + ", " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + ", 0, 0 )" + NEWLINE + "	" + NEWLINE
			
        	Case VWX_WIDGET_checklistbox
				Dim As String mystr
				framedec += "	Dim As wxArrayString Ptr " + widget->Name + "_str" + NEWLINE
				framedec += "	" + widget->Name + "_str = wxArrayString_ctor( )" + NEWLINE
				For j = 0 To wxListbox_GetCount(widget->self) - 1
					mystr = wxString_to_fbstring(wxListbox_GetSingleString(widget->self, j))
					framedec += "	wxArrayString_Add( " + widget->Name + "_str, wxString_ctorUTF8( """ + str_replace(SEPARATOR, SEPARATOR + SEPARATOR, mystr) + """ ) )" + NEWLINE
				Next
				framedec += "	Dim As wxListBox Ptr " + widget->Name + NEWLINE + _
							"	" + widget->Name + " = wxCheckListBox_ctor2( wx_panel, -1, wxPoint_ctor( " + Str(wxSize_GetWidth(widget->position)) + ", " + Str(wxSize_GetHeight(widget->position)) + " ), wxSize_ctor( " + Str(wxSize_GetWidth(widget->size)) + ", " + Str(wxSize_GetHeight(widget->size)) + " ), " + widget->Name + "_str, 0, 0, 0 )" + NEWLINE + "	" + NEWLINE
				If wxListBox_GetSelection( widget->self ) <> 0 Then
					framedec += "	wxListBox_SetSelection( " + widget->Name + ", " + Str(wxListBox_GetSelection( widget->self )) + ", WX_TRUE )" + NEWLINE + "	" + NEWLINE
				EndIf
				For j = 0 To wxListbox_GetCount(widget->self) - 1
					If wxCheckListBox_IsChecked( widget->self, j ) <> 0 Then
						framedec += "	wxCheckListBox_Check( " + widget->Name + ", " + Str(j) + ", WX_TRUE )" + NEWLINE
					EndIf
				Next
				framedec += "	" + NEWLINE
			
        End Select
		
		If widget->events( UBound( widget->events ) ) = 1 Then
			framedec += "	wxEvtHandler_Proxy( " + widget->Name + ", Cast(EventListener, @" + widget->Name + "_event) )" + NEWLINE
			For i = 0 To UBound( widget->events ) - 1
				If widget->events( i ) = 1 Then
					framedec += "	wxEvtHandler_Connect( " + widget->Name + ", " + *events( i ) + "( ), -1, -1, 0 )" + NEWLINE
				EndIf
			Next
		EndIf
		
		framedec += "	" + NEWLINE
	
		widget = Cast(VWX_Widget Ptr, listGetNextNode( Cast(TLISTNODE Ptr, widget) ))
		
    Wend
	
	'event subs go here
	
	Dim As String eventsubs = ""
	
	widget = Cast(VWX_Widget Ptr, listGetFirstNode( @widgetlist ))
	While widget <> NULL
		
		If widget->events( UBound( widget->events ) ) = 1 Then
			eventsubs += "Sub " + widget->Name + "_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As wxInt )" + NEWLINE + "	" + NEWLINE + _
					  	 "	Select Case wxEvent_GetEventType( event )" + NEWLINE
			For i = 0 To UBound( widget->events ) - 1
				If widget->events( i ) = 1 Then
					eventsubs += "		Case " + *events( i ) + NEWLINE + _
								 "			''stuff" + NEWLINE + "			" + NEWLINE
				EndIf
			Next
			eventsubs += "	End Select" + NEWLINE + _
						 "	" + NEWLINE + "End Sub" + NEWLINE + NEWLINE
		EndIf
		
		widget = Cast(VWX_Widget Ptr, listGetNextNode( Cast(TLISTNODE Ptr, widget) ))
		
	Wend
	
	If listGetFirstNode( @menulist ) <> NULL Then
		
		framedec += "	" + NEWLINE + "	'' create menus" + NEWLINE + _
					"	Dim As wxMenuBar Ptr wx_menubar" + NEWLINE + _
					"	wx_menubar = wxMenuBar_ctor( )" + NEWLINE + "	" + NEWLINE
		eventsubs += "Sub menuhandler WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As wxInt )" + NEWLINE + "	" + NEWLINE + _
					 "	Select Case wxEvent_GetId( event )" + NEWLINE
		
		Dim As VWX_Menu Ptr curmenu
		Dim As VWX_Menuitem Ptr curmenuitem
		Dim As Integer menucount, tmpmenucount
		curmenu = Cast(VWX_Menu Ptr, listGetFirstNode( @menulist ))
		While curmenu <> NULL
			If curmenu->position > -1 Then
				tmpmenucount = menucount
				writemenu( curmenu, framedec, eventsubs, idcount, menucount, "	" )
				framedec += "	wxMenuBar_Append( wx_menubar, wx_menu" + Str( tmpmenucount ) + ", wxString_ctorUTF8(""" + curmenu->name + """) )" + NEWLINE
			EndIf
			curmenu = Cast(VWX_Menu Ptr, listGetNextNode( Cast(TLISTNODE Ptr, curmenu) ))
		Wend
		framedec += "	wxFrame_SetMenuBar(wx_frame, wx_menubar)" + NEWLINE + "	" + NEWLINE + "	" + NEWLINE
		
	EndIf
	
	
	If wxMenuBase_IsChecked( menu2, menu_toolbar ) Then
		
		If listGetFirstNode( @menulist ) = NULL Then
			eventsubs += "Sub menuhandler WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As wxInt )" + NEWLINE + "	" + NEWLINE + _
						 "	Select Case wxEvent_GetId( event )" + NEWLINE
		EndIf
		framedec += "	" + NEWLINE
		framedec += "	wxFrame_CreateToolbar( wx_frame, wxHORIZONTAL Or wxTB_TEXT Or wxTB_FLAT, -1, 0 )" + NEWLINE
		For i = 1 To wxToolBar_GetToolsCount( wxFrame_GetToolbar( proj ) )
			If get_toolbardata( i - 1, 1 ) <> "" Then
				framedec += "	Dim As wxBitmap Ptr toolBarBitmap" + Str( idcount ) + " = wxBitmap_ctor( )" + NEWLINE + _
							"	wxBitmap_LoadFile( toolBarBitmap" + Str( idcount ) + ", wxString_ctorUTF8(""" + str_replace(SEPARATOR + SEPARATOR, SEPARATOR, get_toolbardata( i - 1, 1 )) + """), " + get_pictureTypeString(get_pictureType(str_replace(SEPARATOR + SEPARATOR, SEPARATOR, get_toolbardata( i - 1, 1 )))) + " )" + NEWLINE
				framedec += "	wxToolBar_AddTool2( wxFrame_GetToolbar( wx_frame ), " + Str( idcount ) + ", _" + NEWLINE + _
							"						wxString_ctorUTF8(""" + get_toolbardata( i - 1, 0 ) + """), _" + NEWLINE + _
							"						toolBarBitmap" + Str( idcount ) + ", _" + NEWLINE + _
							"						wxString_ctorUTF8(""" + get_toolbardata( i - 1, 2 ) + """), _" + NEWLINE + _
							!"\t\t\t\t\t\t0 )" + NEWLINE
							If get_pictureTypeString(get_pictureType(get_toolbardata( i - 1, 1 ))) <> "wxBITMAP_TYPE_BMP" Then
								addHandler = "	wxImage_InitAllHandlers( )" + NEWLINE + "	" + NEWLINE
							EndIf
				eventsubs += "		Case " + Str( idcount ) + NEWLINE + _
							 "			'' stuff for toolbar button #" + Str( idcount ) + NEWLINE + "			" + NEWLINE
				idcount += 1
			Else
				framedec += "	wxToolBar_AddSeparator( wxFrame_GetToolBar( wx_frame ) )" + NEWLINE
			EndIf
		Next
		framedec += "	wxToolBar_Realize( wxFrame_GetToolbar( wx_frame ) )" + NEWLINE
		framedec += "	" + NEWLINE
	EndIf
	
	If wxMenuBase_IsChecked( menu2, menu_toolbar ) Or listGetFirstNode( @menulist ) <> NULL Then
		eventsubs += "	End Select" + NEWLINE + "	" + NEWLINE + _
					 "End Sub" + NEWLINE + NEWLINE
		framedec +=  "	wxEvtHandler_Proxy( wx_frame, Cast(EventListener, @menuhandler) )" + NEWLINE + _
					 "	wxEvtHandler_Connect( wx_frame, wxEvent_EVT_COMMAND_MENU_SELECTED( ), -1, -1, 0 )" + NEWLINE + "	" + NEWLINE
		framedec += "	" + NEWLINE
	EndIf
	
	Put #FF, , preprocessors
	Put #FF, , declares
	Put #FF, , shareds
	Put #FF, , initsub
	Put #FF, , addHandler
	Put #FF, , framedec
	Put #FF, , subs
	If Len(eventsubs) Then
		Put #FF, , eventsubs
	EndIf
	Put #FF, , mainpart
	
	Close #FF
	
	
	If app.additionalOutput Then
		#If Defined(__FB_LINUX__) '' additional output of an filename.sh for linux
			FF = FreeFile
			Open Left(filename, InStrRev(filename, ".") - 1) & ".sh" For Output As #FF
				Print #FF, "#! /bin/bash" + NEWLINE + "export LD_LIBRARY_PATH=""./lib""" + NEWLINE + "./""" & filename & """"
			Close #FF
		#ElseIf Defined(__FB_WIN32__) '' manifest + RC for windowsstyle
			FF = FreeFile
			Open Left(filename, InStrRev(filename, ".") - 1) & ".exe.xml" For Output As #FF
				Print #FF, "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>"
				Print #FF, "<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">"
				Print #FF, "	<assemblyIdentity"
				Print #FF, "	version=""1.0.0.0"""
				Print #FF, "	processorArchitecture=""X86"""
				Print #FF, "	name=""CompanyName.ProductName.YourApp"""
				Print #FF, "	type=""win32"""
				Print #FF, "	/>"
				Print #FF, "	<description>Your application description here.</description>"
				Print #FF, "	<dependency>"
				Print #FF, "		<dependentAssembly>"
				Print #FF, "			<assemblyIdentity"
				Print #FF, "			type=""win32"""
				Print #FF, "			name=""Microsoft.Windows.Common-Controls"""
				Print #FF, "			version=""6.0.0.0"""
				Print #FF, "			processorArchitecture=""X86"""
				Print #FF, "			publicKeyToken=""6595b64144ccf1df"""
				Print #FF, "			language=""*"""
				Print #FF, "			/>"
				Print #FF, "		</dependentAssembly>"
				Print #FF, "	</dependency>"
				Print #FF, "</assembly>"
			Close #FF
			
			FF = FreeFile
			Open Left(filename, InStrRev(filename, ".") - 1) & ".rc" For Output As #FF
				Print #FF, "#define MANIFEST 24" + NEWLINE + NEWLINE + "1 MANIFEST """ + Left(filename, InStrRev(filename, ".") - 1) + ".exe.xml"""
				If app.icon <> "" And get_pictureTypeString(get_pictureType(app.icon)) = "wxBITMAP_TYPE_ICO" Then
					Print #FF, "FB_PROGRAM_ICON ICON """ & app.icon & """"
				EndIf
			Close #FF
		#EndIf
	EndIf
	
	bbtncounter = 0
	
End Sub

''
'' Emits the code for menus
''
Private Sub writemenu( ByVal menu As VWX_Menu Ptr, framedec As String, eventsubs As String, ByRef idcount As Integer, ByRef menucount As Integer, ByVal indent As String )
	
	Dim As String menuname
	menuname = "wx_menu" + Str( menucount )
	menucount += 1
	framedec += indent + NEWLINE
	framedec += indent + "'' menu """ + menu->name + """" + NEWLINE + _
				indent + "Dim As wxMenu Ptr " + menuname + NEWLINE + _
				indent + menuname + " = wxMenu_ctor( wxString_ctorUTF8(""""), 0 )" + NEWLINE
	Dim As VWX_Menuitem Ptr curmenuitem
	curmenuitem = Cast(VWX_Menuitem Ptr, listGetFirstNode( @menu->items ))
	
	While curmenuitem <> NULL
		Select Case wxMenuItem_GetKind( curmenuitem->self )
			Case wxITEM_NORMAL
				If ( curmenuitem->submenu <> NULL ) Then
					Dim As Integer tmpmenucount
					tmpmenucount = menucount
					writemenu( curmenuitem->submenu, framedec, eventsubs, idcount, menucount, indent + "	" )
					framedec += indent + NEWLINE
					framedec += indent + "wxMenuBase_AppendSubMenu( " + menuname + ", " + Str( idcount ) + ", wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """), wx_menu" + Str( tmpmenucount ) + ", wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """) )" + NEWLINE
				Else
					framedec += indent + "wxMenuBase_Append( " + menuname + ", " + Str( idcount ) + ", wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """), wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """), 0 )" + NEWLINE
					eventsubs += "		Case " + Str( idcount ) + NEWLINE + _
								 "			'' stuff for selecting item " + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + " from menu " + menu->Name + " goes here" + NEWLINE + "			" + NEWLINE
				EndIf
				idcount += 1
			Case wxITEM_CHECK
				framedec += indent + "wxMenuBase_AppendCheckItem( " + menuname + ", " + Str( idcount ) + ", wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """), wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """) )" + NEWLINE
				eventsubs += "		Case " + Str( idcount ) + NEWLINE + _
							 "			'' stuff for selecting check item " + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + " from menu " + menu->Name + " goes here" + NEWLINE + "			" + NEWLINE
				idcount += 1
			Case wxITEM_RADIO
				framedec += indent + "wxMenuBase_AppendRadioItem( " + menuname + ", " + Str( idcount ) + ", wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """), wxString_ctorUTF8(""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """) )" + NEWLINE
				eventsubs += "		Case " + Str( idcount ) + NEWLINE + _
							 "			'' stuff for selecting radio item " + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + " from menu " + menu->Name + " goes here" + NEWLINE + "			" + NEWLINE
				idcount += 1
			Case wxITEM_SEPARATOR
				framedec += indent + "wxMenuBase_AppendSeparator( " + menuname + " )" + NEWLINE
		End Select
		
		curmenuitem = Cast(VWX_Menuitem Ptr, listGetNextNode( Cast(TLISTNODE Ptr, curmenuitem) ))
	Wend
	
End Sub
