''XML export/import

#Include Once "inc/Visual_WX-C_Designer.bi"
#Include Once "inc/xmlparse.bas" 'nice lightweight xml parser made by nemored

Declare Sub writemenu( ByVal menu As VWX_Menu Ptr, xml_start As String, xml_end As String, ByRef idcount As Integer, ByRef menucount As Integer, ByVal indent As String )
Declare Sub parseText( text As String, current As xmlWidget )

''
'' Exports form
''
Sub xmlexport(ByVal filename As String)
	Dim As VWX_Widget Ptr widget
	Dim As Integer i, j, idcount = 1
	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 xml_start = "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>" + NEWLINE + _
							  "<resource xmlns=""http://www.wxwindows.org/wxxrc"" version=""2.5.3.0"">" + NEWLINE
	
	Dim As String xml_end = "</resource>" + NEWLINE
	
	
	'Frame
	Dim As wxSize Ptr mysize, mysize2
	mysize = wxSize(-1, -1)
	mysize2 = wxSize(-1, -1)
	wxWindow_GetPosition(proj, mysize)
	wxWindow_GetSize(proj, mysize2)
	xml_start += "	<object class=""wxFrame"" name=""" + "wx_frame" + """>" + NEWLINE
	xml_start += "		<pos>" + Str(wxSize_GetWidth(mysize)) + "," + Str(wxSize_GetHeight(mysize)) + "</pos>" + NEWLINE
	xml_start += "		<size>" + Str(wxSize_GetWidth(mysize2)) + "," + Str(wxSize_GetHeight(mysize2)) + "</size>" + NEWLINE
	xml_start += "		<title>" + wxString_to_fbstring(wxWindow_GetTitle(proj)) + "</title>" + NEWLINE
	If (wxFrame_IsMaximized(proj)) Then
		xml_start += "		<style>wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX</style>" + NEWLINE
		xml_start += "		<maximized>1</maximized>" + NEWLINE
	Else
		xml_start += "		<style>wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER</style>" + NEWLINE
	EndIf
	xml_end = "	</object>" + NEWLINE + xml_end
	
	
	'Icon
	If app.icon <> "" Then
		xml_start += "		<object class=""wxIcon"" name=""" + "wx_icon" + """>" + NEWLINE
		xml_start += "			<bitmap>" + app.icon + "</bitmap>" + NEWLINE
		xml_start += "		</object>" + NEWLINE
	EndIf
	
	
	'Panel
	xml_start += "		<object class=""wxPanel"" name=""" + "wx_panel" + """>" + NEWLINE
	
	
	widget = Cast(VWX_Widget Ptr, listGetFirstNode( @widgetlist ))
	While ( widget <> NULL )
		
		Select Case widget->kind
			Case VWX_WIDGET_stattext
				xml_start += "			<object class=""wxStaticText"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<label>" + widget->label + "</label>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_button
				xml_start += "			<object class=""wxButton"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<label>" + widget->label + "</label>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_togglebutton
				xml_start += "			<object class=""wxToggleButton"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<label>" + widget->label + "</label>" + NEWLINE
				xml_start += "				<checked>" + Str( wxToggleButton_GetValue( widget->self ) ) + "</checked>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_bmpbutton
				xml_start += "			<object class=""wxBitmapButton"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<bitmap>" + widget->label + "</bitmap>" + NEWLINE
				xml_start += "				<style>wxBU_AUTODRAW</style>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_image
				xml_start += "			<object class=""wxStaticBitmap"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<bitmap>" + widget->label + "</bitmap>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_checkbox
				xml_start += "			<object class=""wxCheckBox"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<label>" + widget->label + "</label>" + NEWLINE
				xml_start += "				<checked>" + Str(wxCheckBox_GetValue( widget->self )) + "</checked>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_choice
				xml_start += "			<object class=""wxChoice"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "				<content>" + NEWLINE
				For j = 0 To wxChoice_GetCount(widget->self) - 1
					xml_start += "					<item>" + wxString_to_fbstring(wxChoice_GetString(widget->self, j)) + "</item>" + NEWLINE
				Next
				xml_start += "				</content>" + NEWLINE
				xml_start += "				<selection>" + Str(wxChoice_GetSelection(widget->self)) + "</selection>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_combo
				xml_start += "			<object class=""wxComboBox"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<value>" + Mid(widget->label, 1, InStr(widget->label, !"\r") - 1) + "</value>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "				<content>" + NEWLINE
				For j = 1 To wxChoice_GetCount(widget->self) - 1
					xml_start += "					<item>" + wxString_to_fbstring(wxChoice_GetString(widget->self, j)) + "</item>" + NEWLINE
				Next
				xml_start += "				</content>" + NEWLINE
				'xml_start += "				<selection>" + str(wxChoice_GetSelection(widget->self)) + "</selection>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_textctrl
				xml_start += "			<object class=""wxTextCtrl"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<value>" + widget->label + "</value>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_spinctrl
				xml_start += "			<object class=""wxSpinCtrl"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<value>" + Str(wxSpinCtrl_GetValue(widget->self)) + "</value>" + NEWLINE
				xml_start += "				<min>" + Str(wxSpinCtrl_GetMin(widget->self)) + "</min>" + NEWLINE
				xml_start += "				<max>" + Str(wxSpinCtrl_GetMax(widget->self)) + "</max>" + NEWLINE
				xml_start += "				<style>wxSP_ARROW_KEYS</style>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_richtext
				xml_start += "			<object class=""wxTextCtrl"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<value>" + widget->label + "</value>" + NEWLINE
				xml_start += "				<style>wxTE_PROCESS_ENTER Or wxTE_MULTILINE Or wxTE_Rich Or wxTE_RICH2</style>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_gauge
				xml_start += "			<object class=""wxGauge"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<range>" + Str(wxGauge_GetRange(widget->self)) + "</range>" + NEWLINE
				xml_start += "				<value>" + Str(wxGauge_GetValue(widget->self)) + "</value>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_radio
				xml_start += "			<object class=""wxRadioBox"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<label>" + Mid(widget->label, 1, InStr(widget->label, !"\r") - 1) + "</label>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "				<style>wxHORIZONTAL</style>" + NEWLINE
				xml_start += "				<content>" + NEWLINE
				For j = 0 To wxRadioBox_GetCount(widget->self) - 1
					xml_start += "					<item>" + wxString_to_fbstring(wxRadioBox_GetString(widget->self, j)) + "</item>" + NEWLINE
				Next
				xml_start += "				</content>" + NEWLINE
				xml_start += "				<selection>" + Str( wxRadioBox_GetSelection( widget->self ) ) + "</selection>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_list
				xml_start += "			<object class=""wxListBox"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "				<content>" + NEWLINE
				For j = 0 To wxListbox_GetCount(widget->self) - 1
					xml_start += "					<item>" + wxString_to_fbstring(wxListBox_GetSingleString(widget->self, j)) + "</item>" + NEWLINE
				Next
				xml_start += "				</content>" + NEWLINE
				xml_start += "				<selection>" + Str(wxListBox_GetSelection( widget->self )) + "</selection>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_staticbox
				xml_start += "			<object class=""wxStaticBox"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<label>" + widget->label + "</label>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_slider
				xml_start += "			<object class=""wxSlider"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<value>" + Str( wxSlider_GetValue( widget->self ) ) + "</value>" + NEWLINE
				xml_start += "				<min>" + Str( wxSlider_GetMin( widget->self ) ) + "</min>" + NEWLINE
				xml_start += "				<max>" + Str( wxSlider_GetMax( widget->self ) ) + "</max>" + NEWLINE
				xml_start += "				<style>0 Or wxSL_LABELS</style>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_staticline
				xml_start += "			<object class=""wxStaticLine"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_spinbutton
				xml_start += "			<object class=""wxSpinButton"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_calendar
				xml_start += "			<object class=""wxCalendar"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
			Case VWX_WIDGET_checklistbox
				xml_start += "			<object class=""wxCheckListBox"" name=""" + widget->Name + """>" + NEWLINE
				xml_start += "				<pos>" + Str(wxSize_GetWidth(widget->position)) + "," + Str(wxSize_GetHeight(widget->position)) + "</pos>" + NEWLINE
				xml_start += "				<size>" + Str(wxSize_GetWidth(widget->size)) + "," + Str(wxSize_GetHeight(widget->size)) + "</size>" + NEWLINE
				xml_start += "				<content>" + NEWLINE
				For j = 0 To wxListbox_GetCount(widget->self) - 1
					xml_start += "					<item checked=""" + Str(wxCheckListBox_IsChecked( widget->self, j )) + """>" + wxString_to_fbstring(wxListBox_GetSingleString(widget->self, j)) + "</item>" + NEWLINE
				Next
				xml_start += "				</content>" + NEWLINE
				xml_start += "				<selection>" + Str(wxListBox_GetSelection( widget->self )) + "</selection>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
			
		End Select
		
		widget = Cast(VWX_Widget Ptr, listGetNextNode( Cast(TLISTNODE Ptr, widget) ))
		
	Wend
	
	'Panel
	xml_start += "		</object>" + NEWLINE
	
	
	
	''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
		
		xml_start += "		<object class=""wxMenuBar"" name=""wx_menubar"">" + 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, xml_start, xml_end, idcount, menucount, "	" )
			EndIf
			curmenu = Cast(VWX_Menu Ptr, listGetNextNode( Cast(TLISTNODE Ptr, curmenu) ))
		Wend
		
		xml_start += "		</object>" + NEWLINE
		
	EndIf
	
	
	If wxMenuBase_IsChecked( menu2, menu_toolbar ) Then
		
		xml_start += "		<object class=""wxToolBar"">" + NEWLINE
		xml_start += "			<style>wxHORIZONTAL Or wxTB_TEXT Or wxTB_FLAT</style>" + NEWLINE
		For i = 1 To wxToolBar_GetToolsCount( wxFrame_GetToolbar( proj ) )
			If get_toolbardata( i - 1, 1 ) <> "" Then
				xml_start += "			<object class=""tool"">" + NEWLINE
				xml_start += "				<label>" + get_toolbardata( i - 1, 0 ) + "</label>" + NEWLINE
				xml_start += "				<bitmap>" + str_replace(SEPARATOR + SEPARATOR, SEPARATOR, get_toolbardata( i - 1, 1 )) + "</bitmap>" + NEWLINE
				xml_start += "				<longhelp>" + get_toolbardata( i - 1, 2 ) + "</longhelp>" + NEWLINE
				xml_start += "			</object>" + NEWLINE
				idcount += 1
			Else
				'xml_start += "			<object class=""separator""/>" + NEWLINE
				xml_start += "			<object class=""separator""></object>" + NEWLINE
			EndIf
		Next
		
		xml_start += "		</object>" + NEWLINE
		
	EndIf
	
	Put #FF, , xml_start
	Put #FF, , xml_end
	
	Close #FF
	
End Sub

''
'' Emits the code for menus
''
Private Sub writemenu( ByVal menu As VWX_Menu Ptr, xml_start As String, xml_end 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
	xml_start += indent + "		<object class=""wxMenu"" name=""" + menuname + """>" + NEWLINE
	xml_start += indent + "			<label>" + menu->Name + "</label>" + NEWLINE
	xml_start += indent + "			<style>0</style>" + 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, xml_start, xml_end, idcount, menucount, indent + "	" )
				Else
					xml_start += indent + "			<object class=""wxMenuItem"" name=""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """>" + NEWLINE
					xml_start += indent + "				<label>" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + "</label>" + NEWLINE
					xml_start += indent + "			</object>" + NEWLINE
				EndIf
				idcount += 1
			Case wxITEM_CHECK
				xml_start += indent + "			<object class=""wxMenuItem"" name=""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """>" + NEWLINE
				xml_start += indent + "				<label>" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + "</label>" + NEWLINE
				xml_start += indent + "				<checkable>1</checkable>" + NEWLINE
				xml_start += indent + "			</object>" + NEWLINE
				idcount += 1
			Case wxITEM_RADIO
				xml_start += indent + "			<object class=""wxMenuItem"" name=""" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + """>" + NEWLINE
				xml_start += indent + "				<label>" + wxString_to_fbstring( wxMenuItem_GetText( curmenuitem->self ) ) + "</label>" + NEWLINE
				xml_start += indent + "				<radio>1</radio>" + NEWLINE
				xml_start += indent + "			</object>" + NEWLINE
				idcount += 1
			Case wxITEM_SEPARATOR
				'xml_start += indent + "			<object class=""separator""/>" + NEWLINE
				xml_start += indent + "			<object class=""separator""></object>" + NEWLINE
		End Select
		
		curmenuitem = Cast(VWX_Menuitem Ptr, listGetNextNode( Cast(TLISTNODE Ptr, curmenuitem) ))
	Wend
	
	xml_start += indent + "		</object>" + NEWLINE
	
End Sub

''
'' Imports a form
''
Sub xmlimport(ByVal filename As String)
	
	Dim As String xmlText, temp
	Dim As Integer FF = FreeFile
	Open filename For Input As #FF
		Do While Not Eof(FF)
			Line Input #FF, temp
			xmlText &= temp
		Loop
	Close #FF
	
	Dim As xmlWidget xmlApp
	xmlApp.self = "wxApp"
	parseText(xmlText, xmlApp)
	
End Sub

Sub parseText( text As String, current As xmlWidget )
	
	Static As Integer menuLevel 'needed to match an item to its menu
	Dim As xmlWidget tempWidget
	Dim As TypXML xml = xmlParse(text)
	
	Select Case xml.tag
		Case "resource"
			If xml.GetAttr("version") <> "2.5.3.0" Then
				'wxMsgBox(wx_frame, "This could bring problems.", "Wrong resource version.", wxOK, wxSize(150, 50))
			EndIf
			
			If xml.inhalt <> "" Then
				parseText(xml.inhalt, current)
			Else
				'Print "resource is empty!", current.parentkind, current.kind
			EndIf
			
			If xml.rest <> "" Then
				'Print "more than one resource!", current.parentkind, current.kind
				'wxMsgBox(wx_frame, "Cannot handle more than one resource.", "Too many resources.", wxOK, wxSize(150, 50))
			EndIf
			
		Case "object"
			Dim As xmlWidget newObject
			newObject.parent = current.self
			newObject.parentkind = current.kind
			newObject.self = xml.GetAttr("name")
			newObject.kind = xml.GetAttr("class")
			
			'this objects have to be there before any children are generated!
			If newObject.kind = "wxToolBar" Then
				'Print "ToolBar: " & newObject.kind, newObject.parentkind
				newObject.style = "wxHORIZONTAL Or wxTB_TEXT Or wxTB_FLAT"
				make_toolbar( proj, @newObject )
				wxMenuBase_Check( menu2, menu_toolbar, TRUE )
			ElseIf newObject.kind = "wxMenuBar" Then
				'Print "MenuBar: " & newObject.kind, newObject.parentkind
				'menu_makemenu( 0, 0 ) 'isn't important here
			ElseIf newObject.kind = "wxMenu" Then
				If newobject.parentkind = "wxMenuBar" Then
					'Print "Menu: " & newObject.kind, newObject.parentkind
					menuLevel += 1
					Dim As Integer Ptr hack = Callocate( 21, 4 )
					Dim As String tempLabel
					For i As Integer = InStr(xml.inhalt, "<label>") + 7 To InStr(xml.inhalt, "</label>") - 1
						tempLabel += Chr(xml.inhalt[i - 1])
					Next
					Dim As ZString Ptr tmp = StrPtr(tempLabel)
					hack[1] = Cast(Integer, tmp)
					menu_makemenu( hack, 0 )
					DeAllocate hack 'bad hack to generate an event with a specific varname
				ElseIf newObject.parentkind = "wxMenu" Then
					'submenu
					'Print "Menu: " & current.kind, current.parentkind
					Dim As Integer Ptr hack = Callocate( 21, 4 )
					hack[5] = 4 + (menuLevel-1)*7'id_div
					Dim As String tempLabel
					For i As Integer = InStr(xml.inhalt, "<label>") + 7 To InStr(xml.inhalt, "</label>") - 1
						tempLabel += Chr(xml.inhalt[i - 1])
					Next
					Dim As ZString Ptr tmp = StrPtr(tempLabel)
					hack[1] = Cast(Integer, tmp)
					menu_change( hack, 0 )
					DeAllocate hack 'bad hack to generate an event with a specific ID and varname
					menuLevel += 1
				Else
					'Print "????" 'shouldn't happen
				EndIf
			EndIf
			
			If xml.inhalt <> "" Then
				parseText(xml.inhalt, newObject)
			Else
				'empty objects
				Dim As String sep = xml.GetAttr("class")
				'only separators should be empty
				If sep = "separator" Then
					If newObject.parentkind = "wxToolBar" Then
						'toolbarseparator
						add_separator( proj )
					Else
						'menuseparator
						'Print "Menu: " & current.kind, current.parentkind
						Dim As Integer Ptr hack = Callocate( 21, 4 )
						hack[5] = 3 + (menuLevel-1)*7'id_div
						menu_change( hack, 0 )
						DeAllocate hack 'bad hack to generate an event with a specific ID!!!
					EndIf
				Else
					'Print "object is empty!", current.parentkind, current.kind
				EndIf
			EndIf
			
			If xml.rest <> "" Then
				parseText(xml.rest, current)
			Else
				'If current.kind = "wxFrame" Then
				'	wxWindow_SetSize( proj, wxSize_GetWidth(current.position), wxSize_GetHeight(current.position), wxSize_GetWidth(current.size), wxSize_GetHeight(current.size), wxSIZE_AUTO )
				'	wxWindow_SetTitle( proj, current.title )
				'	app.title = current.title
				'EndIf
			EndIf
			
		Case Else
			'widget properties
			Select Case xml.tag
				Case "size"
					Dim As Integer found = InStr(xml.inhalt, ",")
					current.size = wxSize( ValInt(Left(xml.inhalt, found - 1)), ValInt(Right(xml.inhalt, Len(xml.inhalt) - found)) )
					
				Case "pos"
					Dim As Integer found = InStr(xml.inhalt, ",")
					current.position = wxSize( ValInt(Left(xml.inhalt, found - 1)), ValInt(Right(xml.inhalt, Len(xml.inhalt) - found)) )
					
				Case "style"
					'Dim As String tmp = xml.inhalt
					'tmp = str_replace( "|", " Or ", tmp )
					'tmp = str_replace( "||", " OrElse ", tmp )
					'tmp = str_replace( "&", " And ", tmp )
					'tmp = str_replace( "&&", " AndAlso ", tmp )
					'tmp = str_replace( "^", " Xor ", tmp )
					'current.style = tmp
					current.style = xml.inhalt 'styles will be ignored so far
					
				Case "title"
					current.title = xml.inhalt
					
				Case "value"
					current.value = xml.inhalt
					
				Case "label"
					current.label = xml.inhalt
					
				Case "checked"
					If xml.inhalt = "0" Then
						current.checked = FALSE
					Else
						current.checked = TRUE
					EndIf
					
				Case "bitmap"
					current.bitmap = xml.inhalt
					
				Case "content"
					Dim As String curParKind = current.parentkind
					current.parentkind = "content"
					parseText(xml.inhalt, current)
					current.parentkind = curParKind
					
				Case "item"
					Dim As String checked = xml.GetAttr("checked")
					current.item &= xml.inhalt & !"\r"
					
					If checked <> "" Then
						current.checked_item &= checked & !"\r"
					EndIf
					
				Case "selection"
					current.selection = ValInt(xml.inhalt)
					
				Case "range"
					current.range = ValInt(xml.inhalt)
					
				Case "min"
					current.min = ValInt(xml.inhalt)
					
				Case "max"
					current.max = ValInt(xml.inhalt)
					
				Case "checkable"
					If ValInt(xml.inhalt) <> 0 Then
						current.checkable = TRUE
					EndIf
					
				Case "radio"
					If ValInt(xml.inhalt) <> 0 Then
						current.radio = TRUE
					EndIf
					
				Case "longhelp"
					current.longhelp = xml.inhalt
					
				Case "maximized"
					wxFrame_Maximize( proj, TRUE )
					
				Case ""
					'Print "<*empty*>", current.parentkind, current.kind
					
				Case Else
					wxMsgBox(wx_frame, "Will ignore this: """ & xml.tag & """", "Unknown tag.", wxOK, wxSize(150, 50))
					
			End Select
			
			If xml.rest <> "" Then
				parseText(xml.rest, current)
			Else
				If current.kind = "wxFrame" Then
					wxWindow_SetSize( proj, wxSize_GetWidth(current.position), wxSize_GetHeight(current.position), wxSize_GetWidth(current.size), wxSize_GetHeight(current.size), wxSIZE_AUTO )
					wxWindow_SetTitle( proj, current.title )
					app.title = current.title
					
				ElseIf current.kind = "wxIcon" Then
					app.icon = current.bitmap
					
				EndIf
				
				If current.parentkind = "wxPanel" Then
					'Print "Tool: " & current.kind, current.parentkind
					newXmlTool( current )
					
				ElseIf current.parentkind = "wxToolBar" Then
					'Print "ToolBar-Tool: " & current.kind, current.parentkind
					If current.kind = "tool" Then
						add_to_toolbar( proj, @current )
					ElseIf current.kind = "separator" Then
						add_separator( proj )
					Else
						'Print "unknown toolbartool" 'shouldn't happen
					EndIf
					
				ElseIf current.parentkind = "wxMenu" Then
					If current.kind = "wxMenuItem" Then
						'Print "Menu: " & current.kind, current.parentkind, current.label
						Dim As Integer Ptr hack = Callocate( 21, 4 )
						If current.checkable = TRUE Then
							hack[5] = 1 + (menuLevel-1)*7'id_div
						ElseIf current.radio = TRUE Then
							hack[5] = 2 + (menuLevel-1)*7'id_div
						Else
							hack[5] = 0 + (menuLevel-1)*7'id_div
						EndIf
						Dim As ZString Ptr tmp = StrPtr(current.self)
						hack[1] = Cast(Integer, tmp)
						menu_change( hack, 0 )
						DeAllocate hack 'bad hack to generate an event with a specific ID and varname
					EndIf
					
				ElseIf current.parentkind = "separator" Then
					'Print "MenuSeparator: " & current.kind, current.parentkind 'shouldn't happen
					
				Else
					If current.parentkind = "" Then
						'Print "empty parentkind", current.parentkind, current.kind
					EndIf
					
				EndIf
				
			EndIf
			
	End Select
	
End Sub
