''Previews for new widgets on the application-window

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

''holds the temp icons for bitmapbuttons
Dim Shared As wxBitmapButton Ptr tempBmpButtons( )
Dim Shared As wxBitmapButton Ptr tempBmpIDButtons( )
Dim Shared As wxBitmapButton Ptr currentButton

''
'' 
''
'Private Function new_stattext ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxStaticText Ptr statictext
'	Dim As wxPanel Ptr statback
'	'Dim As wxTextCtrl Ptr textctrl
'	
'	'textctrl = labeldiag( "Label?" )
'	'label = wxString_mb_str( wxTextCtrl_GetValue( textctrl ) )
'	'If *label = "" Then
'	'	return NULL
'	'EndIf
'	
'	lab = "stattext" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	statback = wxPanel( )
'	
'	wxPanel_Create( statback, projpn, Cast(wxWindowID, widget), size, wxSize( -1, -1 ), 0, 0 )
'	
'	statictext = wxStaticText( )
'	
'	wxStaticText_Create( statictext, statback, Cast(wxWindowID, widget), *label, wxSize( 0, 0 ), wxSize( -1, -1 ), 0, 0 )
'	
'	Dim As wxSize Ptr tmpsize
'	tmpsize = wxSize( -1, -1 )
'	wxWindow_GetBestSize( statictext, tmpsize )
'	wxWindow_SetSize3( statback, tmpsize )
'	'wxObject_dtor( tmpsize )
'	
'	widget->kind 		= VWX_WIDGET_stattext
'	widget->position	= size
'	widget->size 		= wxSize( -1, -1 )
'	widget->label 		= *label
'	widget->self 		= statictext
'	widget->Name 		= "stattext" + Str( cnt )
'	
'	cnt += 1
'	
'	wxEvtHandler_proxy( statback, Cast(EventListener, @event_projframe) )
'	wxEvtHandler_Connect( statback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
'	wxEvtHandler_Connect( statback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
'	wxEvtHandler_Connect( statback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
'	
'	Return widget
'	
'End Function
Private Function new_stattext ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxStaticText Ptr statictext
	Dim As wxPanel Ptr statback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	statback = wxPanel( )
	statictext = wxStaticText( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_stattext
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= statictext
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_stattext
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "stattext" + Str( cnt )
		widget->self		= statictext
		widget->Name		= "stattext" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxPanel_Create( statback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	wxStaticText_Create( statictext, statback, Cast(wxWindowID, widget), widget->label, wxSize( 0, 0 ), widget->size, widget->style, 0 )
	
	If xml = 0 Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( statictext, tmpsize )
		wxWindow_SetSize3( statback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	wxEvtHandler_proxy( statback, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( statback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
	wxEvtHandler_Connect( statback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
	wxEvtHandler_Connect( statback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_button ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxButton Ptr button
'	'Dim As wxTextCtrl Ptr textctrl
'	
'	'textctrl = labeldiag( "Label?" )
'	'label = wxString_mb_str( wxTextCtrl_GetValue( textctrl ) )
'	'If *label = "" Then
'	'	return NULL
'	'EndIf
'	
'	lab = "button" + Str(cnt)
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	button = wxButton( )
'	
'	Dim As Integer textlines = str_count( NEWLINE, *label ) + 1 'wxTextCtrl_GetNumberOfLines(textctrl)
'	
'	wxButton_Create( button, projpn, Cast(wxWindowID, widget), *label, size, _
'					 wxSize( -1, 24 - 9 + textlines * 13 - 4 ), 0, 0, 0 )
'	
'	widget->kind		= VWX_WIDGET_button
'	widget->position	= size
'	widget->size		= wxSize( -1, 24 - 9 + textlines * 13 - 4 )
'	widget->label 		= *label
'	widget->self 		= button
'	widget->Name		= "button" + Str(cnt)
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_button ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxButton Ptr button
	Dim As Integer textlines
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	button = wxButton( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_button
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= button
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		textlines = str_count( NEWLINE, widget->label ) + 1
		
		widget->kind		= VWX_WIDGET_button
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, 24 - 9 + textlines * 13 - 4 )
		widget->label		= "button" + Str( cnt )
		widget->self		= button
		widget->Name		= "button" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxButton_Create( button, widget->parent, Cast(wxWindowID, widget), widget->label, widget->position, widget->size, widget->style, 0, 0 )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_togglebutton ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxToggleButton Ptr togglebutton
'	
'	lab = "togglebutton" + Str(cnt)
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	togglebutton = wxToggleButton( )
'	
'	Dim As Integer textlines = str_count( NEWLINE, *label ) + 1
'	
'	wxToggleButton_Create( togglebutton, projpn, Cast(wxWindowID, widget), *label, size, _
'					 		wxSize( -1, 24 - 9 + textlines * 13 - 4 ), 0, 0, 0 )
'	
'	widget->kind		= VWX_WIDGET_togglebutton
'	widget->position	= size
'	widget->size		= wxSize( -1, 24 - 9 + textlines * 13 - 4 )
'	widget->label 		= *label
'	widget->self 		= togglebutton
'	widget->Name		= "togglebutton" + Str(cnt)
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_togglebutton ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxToggleButton Ptr togglebutton
	Dim As Integer textlines
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	togglebutton = wxToggleButton( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_togglebutton
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= togglebutton
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		textlines = str_count( NEWLINE, widget->label ) + 1
		
		widget->kind		= VWX_WIDGET_togglebutton
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, 24 - 9 + textlines * 13 - 4 )
		widget->label		= "togglebutton" + Str( cnt )
		widget->self		= togglebutton
		widget->Name		= "togglebutton" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxToggleButton_Create( togglebutton, widget->parent, Cast(wxWindowID, widget), widget->label, widget->position, widget->size, widget->style, 0, 0 )
	
	If xml <> 0 Then
		wxToggleButton_SetValue( togglebutton, IIf(xml->checked, TRUE, FALSE) )
	EndIf
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
Sub bmpbutton_cbdummy( )
	
	Dim As wxBitmapButton Ptr bmpbutton
	
	bmpbutton = wxBitmapButton( )
	
	For i As Integer = 0 To UBound(tempBmpButtons)
		If tempBmpIDButtons(i) = wxWindow_GetId(currentButton) Then
			bmpbutton = Cast(Any Ptr, Cast(Integer, tempBmpButtons(i)))
		EndIf
	Next
	
	wxBitmapButton_OnSetBitmap( bmpbutton )
	
End Sub

''
'' 
''
'Private Function new_bmpbutton ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	'get picture for bitmapbutton
'	Dim As String picture = get_picture( )
'	If ( picture = "" ) Then
'		Return 0
'	EndIf
'	
'	Dim As Integer pictureType = get_pictureType( picture )
'	
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	'Dim As String lab
'	Dim As wxBitmap Ptr picbmpbutton
'	Dim As wxBitmapButton Ptr bmpbutton
'	
'	'lab = "bmpbutton" + Str(cnt)
'	label = StrPtr( picture )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	picbmpbutton = wxBitmap( )
'	wxBitmap_LoadFile( picbmpbutton, picture, pictureType )
'	
'	bmpbutton = wxBitmapButton( )
'	
'	wxBitmapButton_RegisterVirtual( bmpbutton, Cast(Virtual_OnSetBitmap, @bmpbutton_cbdummy) )
'	
'	ReDim Preserve tempBmpButtons( cnt + 1 )
'	tempBmpButtons( cnt ) = bmpbutton
'	
'	wxBitmapButton_Create( bmpbutton, projpn, Cast(wxWindowID, widget), picbmpbutton, size, wxSize( -1, -1 ), -1, 0, 0 )
'	wxWindow_SetBackgroundColour( bmpbutton, wxColour_ctorByParts( 255, 255, 255 ) )
'	
'	
'	widget->kind		= VWX_WIDGET_bmpbutton
'	widget->position	= size
'	widget->size		= wxSize( -1, -1 )
'	widget->label 		= *label
'	widget->self 		= bmpbutton
'	widget->Name		= "bmpbutton" + Str(cnt)
'	
'	cnt += 1
'	bmpbuttoncounter( 1 )
'	
'	wxEvtHandler_proxy( bmpbutton, Cast(EventListener, @event_projframe) )
'	wxEvtHandler_Connect( bmpbutton, wxEvent_EVT_ENTER_WINDOW(), cnt, -1, 0 )
'	
'	Return widget
'	
'End Function
Private Function new_bmpbutton ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Dim As String picture
	
	If xml = 0 Then
		'get picture for bitmapbutton
		picture = get_picture( )
		If ( picture = "" ) Then
			Return 0
		EndIf
	Else
		picture = xml->bitmap
	EndIf
	
	
	Dim As Integer pictureType = get_pictureType( picture )
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxBitmap Ptr picbmpbutton
	Dim As wxBitmapButton Ptr bmpbutton
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	picbmpbutton = wxBitmap( )
	wxBitmap_LoadFile( picbmpbutton, picture, pictureType )
	bmpbutton = wxBitmapButton( )
	currentButton = bmpbutton
	
	wxBitmapButton_RegisterVirtual( bmpbutton, Cast(Virtual_OnSetBitmap, @bmpbutton_cbdummy) )
	
	ReDim Preserve tempBmpButtons( cnt + 1 )
	ReDim Preserve tempBmpIDButtons( cnt + 1 )
	tempBmpButtons( cnt ) = bmpbutton
	tempBmpIDButtons( cnt ) = widget
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_bmpbutton
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->bitmap
		widget->self		= bmpbutton
		widget->Name		= xml->self
		widget->style		= -1'xml->style
	Else
		widget->kind		= VWX_WIDGET_bmpbutton
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= picture
		widget->self		= bmpbutton
		widget->Name		= "bmpbutton" + Str( cnt )
		widget->style		= -1
	EndIf
	
	wxBitmapButton_Create( bmpbutton, widget->parent, Cast(wxWindowID, widget), picbmpbutton, widget->position, widget->size, widget->style, 0, 0 )
	wxWindow_SetBackgroundColour( bmpbutton, wxColour_ctorByParts( 255, 255, 255 ) )
	
	cnt += 1
	bmpbuttoncounter( 1 )
	
	wxEvtHandler_proxy( bmpbutton, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( bmpbutton, wxEvent_EVT_ENTER_WINDOW(), Cast(wxWindowID, widget), -1, 0 )
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_image ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	'get picture for bitmapbutton
'	Dim As String picture = get_picture( )
'	If ( picture = "" ) Then
'		Return 0
'	EndIf
'	
'	Dim As Integer pictureType = get_pictureType( picture )
'	
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	'Dim As String lab
'	Dim As wxBitmap Ptr picimage
'	Dim As wxStaticBitmap Ptr image
'	
'	'lab = "image" + Str(cnt)
'	label = StrPtr( picture )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	
'	picimage = wxBitmap( )
'	wxBitmap_LoadFile( picimage, picture, pictureType )
'	
'	image = wxStaticBitmap( )
'	wxStaticBitmap_Create( image, projpn, Cast(wxWindowID, widget), picimage, size, wxSize( -1, -1 ), 0, 0 )
'	
'	
'	widget->kind		= VWX_WIDGET_image
'	widget->position	= size
'	widget->size		= wxSize( -1, -1 )
'	widget->label 		= *label
'	widget->self 		= image
'	widget->Name		= "image" + Str(cnt)
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_image ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Dim As String picture
	
	If xml = 0 Then
		'get picture for bitmap
		picture = get_picture( )
		If ( picture = "" ) Then
			Return 0
		EndIf
	Else
		picture = xml->bitmap
	EndIf
	
	Dim As Integer pictureType = get_pictureType( picture )
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxBitmap Ptr picimage
	Dim As wxStaticBitmap Ptr image
	Dim As wxPanel Ptr iback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	picimage = wxBitmap( )
	wxBitmap_LoadFile( picimage, picture, pictureType )
	image = wxStaticBitmap( )
	iback = wxPanel( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_image
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->bitmap
		widget->self		= image
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_image
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= picture
		widget->self		= image
		widget->Name		= "image" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxPanel_Create( iback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	wxStaticBitmap_Create( image, iback, Cast(wxWindowID, widget), picimage, wxSize( 0, 0 ), widget->size, widget->style, 0 )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_checkbox ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxCheckBox Ptr checkbox
'	
'	lab = "checkbox" + Str(cnt)
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	checkbox = wxCheckBox( )
'	wxCheckBox_Create( checkbox, projpn, Cast(wxWindowID, widget), *label, size, wxSize( -1, -1 ), 0, 0, 0 )
'	
'	
'	
'	widget->kind		= VWX_WIDGET_checkbox
'	widget->position	= size
'	widget->size		= wxSize( -1, -1 )
'	widget->label 		= *label
'	widget->self 		= checkbox
'	widget->Name		= "checkbox" + Str(cnt)
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_checkbox ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxCheckBox Ptr checkbox
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	checkbox = wxCheckBox( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_checkbox
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= checkbox
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_checkbox
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "checkbox" + Str( cnt )
		widget->self		= checkbox
		widget->Name		= "checkbox" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxCheckBox_Create( checkbox, widget->parent, Cast(wxWindowID, widget), widget->label, widget->position, widget->size, widget->style, 0, 0 )
	
	If xml <> 0 Then
		wxCheckBox_SetValue( checkbox, IIf(xml->checked, TRUE, FALSE) )
	EndIf
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function get_choices ( ByVal tehstr As ZString Ptr, _
'							  choicestb() As ZString Ptr ) As Integer
'	
'	Dim As Integer i
'	Dim As Integer choices = str_count( NEWLINE, *tehstr ) + 1 'wxTextCtrl_GetNumberOfLines( textctrl )
'	Dim As String mahstr( 0 To choices-1 )
'	
'	ReDim choicestb( 0 To choices - 1 )
'	
'	For i = 0 To choices - 1
'		mahstr( i ) = str_getline( *tehstr, i )
'		choicestb(i) = StrPtr( mahstr( i ) )
'	Next
'	
'	Print choices
'	
'	Return choices
'	
'End Function

''
'' 
''
'Private Function new_choice ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxChoice Ptr choice
'	'Dim As wxTextCtrl Ptr textctrl
'	
'	'textctrl = labeldiag( "Choices?" )
'	'label = wxString_mb_str( wxTextCtrl_GetValue( textctrl ) )
'	'If *label = "" Then
'	'	return NULL
'	'EndIf
'	
'	lab = "choice" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	Dim As Integer choices = 1
'	ReDim As ZString Ptr choicestb(0)
'	Dim As String temps = "choice" + Str( cnt )
'	'choices = get_choices( textctrl, choicestb() )
'	choicestb( 0 ) = StrPtr( temps )
'	
'	choice = wxChoice( )
'	
'	wxChoice_Create( choice, projpn, Cast(Integer, widget), size, wxSize(-1, -1), choices, @choicestb(0), 0, 0, 0)
'	wxChoice_SetSelection( choice, 0 )
'	
'	widget->kind		= VWX_WIDGET_choice
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= choice
'	widget->Name		= "choice" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_choice ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxChoice Ptr choice
	Dim As wxPanel Ptr choiceback
	Dim As Integer choices
	ReDim As ZString Ptr choicestb( 0 )
	ReDim As String temps( 0 )
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	choiceback = wxPanel( )
	choice = wxChoice( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_choice
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label + xml->item
		widget->self		= choice
		widget->Name		= xml->self
		'widget->style		= xml->style
		
		Dim As String items = xml->item
		Dim As Integer found
		
		found = InStr(items, !"\r")
		While found
			temps( choices ) = Left(items, found - 1)
			items = Right(items, Len(items) - found )
			choicestb( choices ) = StrPtr( temps( choices ) )
			choices += 1
			ReDim Preserve temps( choices )
			ReDim Preserve choicestb( choices )
			found = InStr(items, !"\r")
		Wend
	Else
		widget->kind		= VWX_WIDGET_choice
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "choice" + Str( cnt )
		widget->self		= choice
		widget->Name		= "choice" + Str( cnt )
		widget->style		= 0
		
		choices = 1
		ReDim Preserve temps( choices )
		ReDim Preserve choicestb( choices )
		temps( 0 ) = "choice" + Str( cnt )
		'choices = get_choices( textctrl, choicestb() )
		choicestb( 0 ) = StrPtr( temps( 0 ) )
	EndIf
	
	wxPanel_Create( choiceback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	wxChoice_Create( choice, choiceback, Cast(Integer, widget), wxSize( 0, 0 ), widget->size, choices, @choicestb( 0 ), widget->style, 0, 0)
	wxChoice_SetSelection( choice, IIf(xml = 0, 0, xml->selection) )
	
	If xml = 0 Or (xml <> 0 AndAlso (wxSize_GetWidth(xml->size) = -1 And wxSize_GetHeight(xml->size) = -1)) Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( choice, tmpsize )
		wxWindow_SetSize3( choiceback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_combo ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxChoice Ptr choice
'	'Dim As wxTextCtrl Ptr textctrl
'	
'	'textctrl = labeldiag( "Choices? (1st=label)" )
'	'label = wxString_mb_str( wxTextCtrl_GetValue( textctrl ) )
'	'If *label = "" Then
'	'	return NULL
'	'EndIf
'	
'	lab = "combo" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	Dim As Integer choices = 1
'	ReDim As ZString Ptr choicestb(0)
'	Dim As String temps = "combo" + Str( cnt )
'	'choices = get_choices( textctrl, choicestb() )
'	choicestb( 0 ) = StrPtr( temps )
'	
'	'choice = wxComboBox( )
'	choice = wxChoice( )
'	
'	'wxComboBox_Create( choice, projpn, Cast(Integer, widget), choicestb(0), size, wxSize( -1, -1 ), choices, @choicestb(0), 0, 0, 0 )
'	wxChoice_Create( choice, projpn, Cast(Integer, widget), size, wxSize(-1, -1), choices, @choicestb(0), 0, 0, 0)
'	wxChoice_SetSelection( choice, 0 )
'	
'	widget->kind		= VWX_WIDGET_combo
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= choice
'	widget->Name		= "combo" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_combo ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxChoice Ptr choice
	Dim As wxPanel Ptr choiceback
	Dim As Integer choices
	ReDim As ZString Ptr choicestb( 0 )
	ReDim As String temps( 0 )
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	choiceback = wxPanel( )
	'choice = wxComboBox( )
	choice = wxChoice( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_combo
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->value + !"\r" + xml->item
		widget->self		= choice
		widget->Name		= xml->self
		'widget->style		= xml->style
		
		Dim As String items = widget->label
		Dim As Integer found
		
		found = InStr(items, !"\r")
		While found
			temps( choices ) = Left(items, found - 1)
			items = Right(items, Len(items) - found )
			choicestb( choices ) = StrPtr( temps( choices ) )
			choices += 1
			ReDim Preserve temps( choices )
			ReDim Preserve choicestb( choices )
			found = InStr(items, !"\r")
		Wend
	Else
		widget->kind		= VWX_WIDGET_combo
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "combo" + Str( cnt )
		widget->self		= choice
		widget->Name		= "combo" + Str( cnt )
		widget->style		= 0
		
		choices = 1
		ReDim Preserve temps( choices )
		ReDim Preserve choicestb( choices )
		temps( 0 ) = "combo" + Str( cnt )
		choicestb( 0 ) = StrPtr( temps( 0 ) )
	EndIf
	
	wxPanel_Create( choiceback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	'wxComboBox_Create( choice, choiceback, Cast(Integer, widget), choicestb(0), wxSize( 0, 0 ), widget->size, choices, @choicestb(0), widget->style, 0, 0 )
	wxChoice_Create( choice, choiceback, Cast(Integer, widget), wxSize( 0, 0 ), widget->size, choices, @choicestb( 0 ), widget->style, 0, 0)
	wxChoice_SetSelection( choice, IIf(xml = 0, 0, xml->selection + 1) )
	
	If xml = 0 Or (xml <> 0 AndAlso (wxSize_GetWidth(xml->size) = -1 And wxSize_GetHeight(xml->size) = -1)) Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( choice, tmpsize )
		wxWindow_SetSize3( choiceback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_textctrl ( ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxTextCtrl Ptr textctrl
'	
'	lab = "textctrl" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	textctrl = wxTextCtrl( )
'	
'	wxTextCtrl_Create( textctrl, projpn, Cast(wxWindowID, widget), *label, size, wxSize(-1, -1), 0, 0, 0 )
'	
'	
'	widget->kind		= VWX_WIDGET_textctrl
'	widget->position	= size
'	widget->size		= wxSize( -1, -1 )
'	widget->label		= *label
'	widget->self		= textctrl
'	widget->Name		= "textctrl" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_textctrl ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxTextCtrl Ptr textctrl
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	textctrl = wxTextCtrl( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_textctrl
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->value
		widget->self		= textctrl
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_textctrl
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "textctrl" + Str( cnt )
		widget->self		= textctrl
		widget->Name		= "textctrl" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxTextCtrl_Create( textctrl, widget->parent, Cast(wxWindowID, widget), widget->label, widget->position, widget->size, widget->style, 0, 0 )
	wxTextCtrl_SetEditable( textctrl, FALSE )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_spinctrl ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxSpinCtrl Ptr spinctrl
'	Dim As wxPanel Ptr scback
'	
'	lab = "spinctrl" + Str(cnt)
'	label = StrPtr(lab)'StrPtr( "0" )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	scback = wxPanel( )
'	wxPanel_Create( scback, projpn, Cast(wxWindowID, widget), size, wxSize( -1, -1 ), 0, 0 )
'	
'	spinctrl = wxSpinCtrl( )
'	wxSpinCtrl_Create( spinctrl, scback, Cast(wxWindowID, widget), StrPtr("0"), wxSize( 1, 1 ), wxSize( -1, -1 ), wxSP_ARROW_KEYS, 0, 100, 0, 0 )
'	'wxWindow_Disable( spinctrl )
'	wxTextCtrl_SetEditable( spinctrl, FALSE )
'	
'	Dim As wxSize Ptr tmpsize
'	tmpsize = wxSize( -1, -1 )
'	wxWindow_GetBestSize( spinctrl, tmpsize )
'	wxWindow_SetSize3( scback, tmpsize )
'	
'	widget->kind		= VWX_WIDGET_spinctrl
'	widget->position	= size
'	widget->size		= wxSize( -1, -1 )
'	widget->label 		= *label
'	widget->self 		= spinctrl
'	widget->Name		= "spinctrl" + Str(cnt)
'	
'	cnt += 1
'	
'	wxEvtHandler_proxy( scback, Cast(EventListener, @event_projframe) )
'	wxEvtHandler_Connect( scback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
'	wxEvtHandler_Connect( scback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
'	wxEvtHandler_Connect( scback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
'	
'	Return widget
'	
'End Function
Private Function new_spinctrl ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxSpinCtrl Ptr spinctrl
	Dim As wxPanel Ptr scback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	scback = wxPanel( )
	spinctrl = wxSpinCtrl( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_spinctrl
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= spinctrl
		widget->Name		= xml->self
		widget->style		= wxSP_ARROW_KEYS'xml->style
	Else
		widget->kind		= VWX_WIDGET_spinctrl
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "spinctrl" + Str( cnt )
		widget->self		= spinctrl
		widget->Name		= "spinctrl" + Str( cnt )
		widget->style		= wxSP_ARROW_KEYS
	EndIf
	
	wxPanel_Create( scback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	
	If xml = 0 Then
		wxSpinCtrl_Create( spinctrl, scback, Cast(wxWindowID, widget), StrPtr( "0" ), wxSize( 0, 0 ), widget->size, widget->style, 0, 100, 0, 0 )
	Else
		wxSpinCtrl_Create( spinctrl, scback, Cast(wxWindowID, widget), xml->value, wxSize( 0, 0 ), widget->size, widget->style, xml->min, xml->max, ValInt( xml->value ), 0 )
	EndIf
	
	#If Defined(__FB_WIN32__)
		wxWindow_Disable( spinctrl ) 'better grip if disabled
	#EndIf
	
	If xml = 0 Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( spinctrl, tmpsize )
		wxWindow_SetSize3( scback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	wxEvtHandler_proxy( scback, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( scback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
	wxEvtHandler_Connect( scback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
	wxEvtHandler_Connect( scback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_richtext ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxTextCtrl Ptr richtext
'	
'	lab = "richtext" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	richtext = wxTextCtrl( )
'	
'	wxTextCtrl_Create( richtext, projpn, Cast(wxWindowID, widget), *label, size, wxSize(-1, -1), wxTE_PROCESS_ENTER Or wxTE_MULTILINE Or wxTE_Rich Or wxTE_RICH2, 0, 0 )
'	
'	
'	widget->kind		= VWX_WIDGET_richtext
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= richtext
'	widget->Name		= "richtext" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_richtext ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxTextCtrl Ptr richtext
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	richtext = wxTextCtrl( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_richtext
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->value
		widget->self		= richtext
		widget->Name		= xml->self
		widget->style		= wxTE_PROCESS_ENTER Or wxTE_MULTILINE Or wxTE_Rich Or wxTE_RICH2'xml->style
	Else
		widget->kind		= VWX_WIDGET_richtext
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "richtext" + Str( cnt )
		widget->self		= richtext
		widget->Name		= "richtext" + Str( cnt )
		widget->style		= wxTE_PROCESS_ENTER Or wxTE_MULTILINE Or wxTE_Rich Or wxTE_RICH2
	EndIf
	
	wxTextCtrl_Create( richtext, widget->parent, Cast(wxWindowID, widget), widget->label, widget->position, widget->size, widget->style, 0, 0 )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_gauge ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As wxGauge Ptr gauge
'	'Dim As wxTextCtrl Ptr textctrl
'	Dim As wxPanel Ptr gback
'	
'	'textctrl = labeldiag( "Max value?" )
'	'label = wxString_mb_str( wxTextCtrl_GetValue( textctrl ) )
'	'If *label = "" Rhen
'	'	return NULL
'	'EndIf
'	Dim As String lab = "gauge" + Str( cnt )
'	label = StrPtr(lab)'StrPtr( "100" )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	gback = wxPanel( )
'	
'	wxPanel_Create( gback, projpn, Cast(wxWindowID, widget), size, wxSize( -1, -1 ), 0, 0 )
'	
'	gauge = wxGauge( )
'	
'	wxGauge_Create( gauge, gback, Cast(wxWindowID, widget), Val( *label ), wxSize( 0, 0 ), wxSize( -1, -1 ), 0, 0, 0)
'	wxGauge_SetRange( gauge, 100 )
'	
'	Dim As wxSize Ptr tmpsize
'	tmpsize = wxSize( -1, -1 )
'	wxWindow_GetBestSize( gauge, tmpsize )
'	wxWindow_SetSize3( gback, tmpsize )
'	'wxObject_dtor( tmpsize )
'	
'	widget->kind		= VWX_WIDGET_gauge
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= gauge
'	widget->Name		= "gauge" + Str( cnt )
'	
'	cnt += 1
'	
'	wxEvtHandler_proxy( gback, Cast(EventListener, @event_projframe) )
'	wxEvtHandler_Connect( gback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
'	wxEvtHandler_Connect( gback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
'	wxEvtHandler_Connect( gback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
'	
'	Return widget
'	
'End Function
Private Function new_gauge ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxGauge Ptr gauge
	Dim As wxPanel Ptr gback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	gback = wxPanel( )
	gauge = wxGauge( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_gauge
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= gauge
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_gauge
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "gauge" + Str( cnt )
		widget->self		= gauge
		widget->Name		= "gauge" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxPanel_Create( gback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	
	If xml = 0 Then
		wxGauge_Create( gauge, gback, Cast(wxWindowID, widget), 100 , wxSize( 0, 0 ), widget->size, widget->style, 0, 0)
	Else
		wxGauge_Create( gauge, gback, Cast(wxWindowID, widget), xml->range, wxSize( 0, 0 ), widget->size, widget->style, 0, 0)
		wxGauge_SetValue( gauge, ValInt( xml->value ) )
	EndIf
	
	If xml = 0 Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( gauge, tmpsize )
		wxWindow_SetSize3( gback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	wxEvtHandler_proxy( gback, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( gback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
	wxEvtHandler_Connect( gback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
	wxEvtHandler_Connect( gback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_radiobox ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxRadioBox Ptr radiobox
'	'Dim As wxTextCtrl Ptr textctrl
'	Dim As wxPanel Ptr rback
'	
'	'textctrl = labeldiag( "Choices (1st=label)?" )
'	'label = wxString_mb_str( wxTextCtrl_GetValue( textctrl ) )
'	'If *label = "" Then
'	'	return NULL
'	'EndIf
'	
'	
'	lab = "radio" + Str( cnt ) + !"\r" /'NEWLINE'/ + "choice1" + !"\r" /'NEWLINE'/ + "choice2"
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	Dim As Integer choices = 3
'	ReDim As ZString Ptr choicestb(3)
'	Dim As String temps = "radio" + Str( cnt )
'	choicestb( 0 ) = StrPtr( temps )
'	choicestb( 1 ) = StrPtr( "choice1" )
'	choicestb( 2 ) = StrPtr( "choice2" )
'	
'	'If we want to move radioboxes, then we need a panel
'	rback = wxPanel( )
'	
'	wxPanel_Create( rback, projpn, Cast(wxWindowID, widget), size, wxSize( -1, -1 ), 0, 0 )
'	
'	radiobox = wxRadioBox( )
'	
'	wxRadioBox_Create( radiobox, rback, Cast(Integer, widget), choicestb(0), wxSize( 0, 0 ), wxSize(-1, -1), choices - 1, @choicestb(1), 0, 0, 0, 0 )
'	wxRadioBox_SetSelection( radiobox, 0 )
'	
'	Dim As wxSize Ptr tmpsize
'	tmpsize = wxSize( -1, -1 )
'	wxWindow_GetBestSize( radiobox, tmpsize )
'	wxWindow_SetSize3( rback, tmpsize )
'	'wxObject_dtor( tmpsize )
'	
'	widget->kind		= VWX_WIDGET_radio
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= radiobox
'	widget->Name		= "radio" + Str( cnt )
'	
'	cnt += 1
'	
'	wxEvtHandler_proxy( rback, Cast(EventListener, @event_projframe) )
'	wxEvtHandler_Connect( rback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
'	wxEvtHandler_Connect( rback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
'	wxEvtHandler_Connect( rback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
'	'wxEvtHandler_proxy( radiobox, Cast(EventListener, @event_projframe) )
'	'wxEvtHandler_Connect( radiobox, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
'	'wxEvtHandler_Connect( radiobox, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
'	'wxEvtHandler_Connect( radiobox, wxEvent_EVT_MOTION( ), -1, -1, 0 )
'	
'	Return widget
'	
'End Function
Private Function new_radiobox ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxRadioBox Ptr radiobox
	Dim As wxPanel Ptr rback
	Dim As Integer choices
	ReDim As ZString Ptr choicestb( 0 )
	ReDim As String temps( 0 )
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	rback = wxPanel( )
	radiobox = wxRadioBox( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_radio
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label + !"\r" + xml->item
		widget->self		= radiobox
		widget->Name		= xml->self
		widget->style		= wxHORIZONTAL'xml->style
		
		Dim As String items = widget->label
		Dim As Integer found
		
		found = InStr(items, !"\r")
		While found
			temps( choices ) = Left(items, found - 1)
			items = Right(items, Len(items) - found )
			choicestb( choices ) = StrPtr( temps( choices ) )
			choices += 1
			ReDim Preserve temps( choices )
			ReDim Preserve choicestb( choices )
			found = InStr(items, !"\r")
		Wend
	Else
		widget->kind		= VWX_WIDGET_radio
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "radio" + Str( cnt ) + !"\r" + "choice1" + !"\r" + "choice2"
		widget->self		= radiobox
		widget->Name		= "radio" + Str( cnt )
		widget->style		= wxHORIZONTAL
		
		choices = 3
		ReDim Preserve temps( 1 )
		ReDim Preserve choicestb( choices )
		temps( 0 ) = "radio" + Str( cnt )
		choicestb( 0 ) = StrPtr( temps( 0 ) )
		choicestb( 1 ) = StrPtr( "choice1" )
		choicestb( 2 ) = StrPtr( "choice2" )
	EndIf
	
	'If we want to move radioboxes, then we need a panel
	wxPanel_Create( rback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	wxRadioBox_Create( radiobox, rback, Cast(Integer, widget), choicestb( 0 ), wxSize( 0, 0 ), widget->size, choices - 1, @choicestb( 1 ), 0, widget->style, 0, 0 )
	wxRadioBox_SetSelection( radiobox, IIf(xml = 0, 0, xml->selection) )
	
	If xml = 0 Or (xml <> 0 AndAlso (wxSize_GetWidth(xml->size) = -1 And wxSize_GetHeight(xml->size) = -1)) Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( radiobox, tmpsize )
		wxWindow_SetSize3( rback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	wxEvtHandler_proxy( rback, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( rback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
	wxEvtHandler_Connect( rback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
	wxEvtHandler_Connect( rback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_listbox ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxListBox Ptr listbox
'	'Dim As wxTextCtrl Ptr textctrl
'	
'	'textctrl = labeldiag( "Choices?" )
'	'label = wxString_mb_str( wxTextCtrl_GetValue( textctrl ) )
'	'If *label = "" Then
'	'	return NULL
'	'EndIf
'	
'	lab = "list" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	Dim As Integer choices = 1
'	ReDim As ZString Ptr choicestb(0)
'	Dim As String temps = "list" + Str( cnt )
'	'choices = get_choices( textctrl, choicestb() )
'	choicestb( 0 ) = StrPtr( temps )
'	
'	listbox = wxListBox( )
'	
'	wxListBox_Create( listbox, projpn, Cast(wxWindowID, widget), size, wxSize(-1, -1), choices, @choicestb(0), 0, 0, 0 )
'	wxListBox_SetSelection( listbox, 0, TRUE )
'	
'	widget->kind		= VWX_WIDGET_list
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= listbox
'	widget->Name		= "list" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_listbox ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxListBox Ptr listbox
	Dim As Integer choices
	ReDim As ZString Ptr choicestb( 0 )
	ReDim As String temps( 0 )
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	listbox = wxListBox( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_list
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label + xml->item
		widget->self		= listbox
		widget->Name		= xml->self
		'widget->style		= xml->style
		
		Dim As String items = xml->item
		Dim As Integer found
		
		found = InStr(items, !"\r")
		While found
			temps( choices ) = Left(items, found - 1)
			items = Right(items, Len(items) - found )
			choicestb( choices ) = StrPtr( temps( choices ) )
			choices += 1
			ReDim Preserve temps( choices )
			ReDim Preserve choicestb( choices )
			found = InStr(items, !"\r")
		Wend
	Else
		widget->kind		= VWX_WIDGET_list
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "list" + Str( cnt )
		widget->self		= listbox
		widget->Name		= "list" + Str( cnt )
		widget->style		= 0
		
		
		temps( choices ) = "list" + Str( cnt )
		choicestb( choices ) = StrPtr( temps( choices ) )
		choices += 1
	EndIf
	
	wxListBox_Create( listbox, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, choices, @choicestb( 0 ), widget->style, 0, 0 )
	wxListBox_SetSelection( listbox, IIf(xml = 0, 0, xml->selection), TRUE )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_staticbox ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxStaticBox Ptr staticbox
'	
'	lab = "staticbox" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	
'	staticbox = wxStaticBox( )
'	wxStaticBox_Create( staticbox, projpn, Cast(wxWindowID, widget), *label, size, wxSize(-1, -1), 0, 0 )
'	
'	
'	widget->kind		= VWX_WIDGET_staticbox
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= staticbox
'	widget->Name		= "staticbox" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_staticbox ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxStaticBox Ptr staticbox
	Dim As wxPanel Ptr sbback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	staticbox = wxStaticBox( )
	sbback = wxPanel( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_staticbox
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= staticbox
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_staticbox
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( 70, 20 )'wxSize( -1, -1 )
		widget->label		= "staticbox" + Str( cnt )
		widget->self		= staticbox
		widget->Name		= "staticbox" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxPanel_Create( sbback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	wxStaticBox_Create( staticbox, sbback, Cast(wxWindowID, widget), widget->label, wxSize( 0, 0 ), widget->size, widget->style, 0 )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_slider ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxSlider Ptr slider
'	Dim As wxPanel Ptr slback
'	
'	lab = "slider" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	slback = wxPanel( )
'	wxPanel_Create( slback, projpn, Cast(wxWindowID, widget), size, wxSize( -1, -1 ), 0, 0 )
'	
'	slider = wxSlider( )
'	wxSlider_Create( slider, slback, Cast(wxWindowID, widget), 0, 0, Val(*label), wxSize( 0, 0 ), wxSize(-1, -1), 0 Or wxSL_LABELS, 0, 0 )
'	'wxSlider_Create( slider, projpn, Cast(wxWindowID, widget), 0, 0, 100, size, wxSize(-1, -1), 0 Or wxSL_LABELS, 0, 0 )
'	
'	Dim As wxSize Ptr tmpsize
'	tmpsize = wxSize( -1, -1 )
'	wxWindow_GetBestSize( slider, tmpsize )
'	wxWindow_SetSize3( slback, tmpsize )
'	'wxObject_dtor( tmpsize )
'
'	
'	widget->kind		= VWX_WIDGET_slider
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= slider
'	widget->Name		= "slider" + Str( cnt )
'	
'	cnt += 1
'	
'	wxEvtHandler_proxy( slback, Cast(EventListener, @event_projframe) )
'	wxEvtHandler_Connect( slback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
'	wxEvtHandler_Connect( slback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
'	wxEvtHandler_Connect( slback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
'	
'	Return widget
'	
'End Function
Private Function new_slider ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxSlider Ptr slider
	Dim As wxPanel Ptr slback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	slback = wxPanel( )
	slider = wxSlider( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_slider
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= slider
		widget->Name		= xml->self
		widget->style		= 0 Or wxSL_LABELS'xml->style
	Else
		widget->kind		= VWX_WIDGET_slider
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "slider" + Str( cnt )
		widget->self		= slider
		widget->Name		= "slider" + Str( cnt )
		widget->style		= 0 Or wxSL_LABELS
	EndIf
	
	wxPanel_Create( slback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	
	If xml = 0 Then
		wxSlider_Create( slider, slback, Cast(wxWindowID, widget), 0, 0, 100, wxSize( 0, 0 ), widget->size, widget->style, 0, 0 )
	Else
		wxSlider_Create( slider, slback, Cast(wxWindowID, widget), ValInt( xml->value ), xml->min, xml->max, wxSize( 0, 0 ), widget->size, widget->style, 0, 0 )
	EndIf
	
	If xml = 0 Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( slider, tmpsize )
		wxWindow_SetSize3( slback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	wxEvtHandler_proxy( slback, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( slback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
	wxEvtHandler_Connect( slback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
	wxEvtHandler_Connect( slback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_staticline ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxStaticLine Ptr staticline
'	
'	lab = "staticline" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	
'	staticline = wxStaticLine( )
'	wxStaticLine_Create( staticline, projpn, Cast(wxWindowID, widget), size, wxSize(20, 1), 0, 0 )
'	
'	
'	widget->kind		= VWX_WIDGET_staticline
'	widget->position	= size
'	widget->size		= wxSize(20, 1)
'	widget->label		= *label
'	widget->self		= staticline
'	widget->Name		= "staticline" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_staticline ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxStaticLine Ptr staticline
	Dim As wxPanel Ptr slback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	staticline = wxStaticLine( )
	slback = wxPanel( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_staticline
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= staticline
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_staticline
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( 20, 1 )
		widget->label		= "staticline" + Str( cnt )
		widget->self		= staticline
		widget->Name		= "staticline" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxPanel_Create( slback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	wxStaticLine_Create( staticline, slback, Cast(wxWindowID, widget), wxSize( 0, 0 ), widget->size, widget->style, 0 )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_spinbutton ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxSpinButton Ptr spinbutton
'	
'	lab = "spinbutton" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	
'	spinbutton = wxSpinButton( )
'	wxSpinButton_Create( spinbutton, projpn, Cast(wxWindowID, widget), size, wxSize(-1, -1), 0, 0 )
'	
'	
'	widget->kind		= VWX_WIDGET_spinbutton
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= spinbutton
'	widget->Name		= "spinbutton" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_spinbutton ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxSpinButton Ptr spinbutton
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	spinbutton = wxSpinButton( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_spinbutton
		widget->parent	  	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= spinbutton
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_spinbutton
		widget->parent	 	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "spinbutton" + Str( cnt )
		widget->self		= spinbutton
		widget->Name		= "spinbutton" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxSpinButton_Create( spinbutton, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, widget->style, 0 )
	
	cnt += 1
	
	Return widget
	
End Function

''
'' 
''
'Private Function new_calendar ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_Widget Ptr
'	
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxCalendarCtrl Ptr calendar
'	Dim As wxPanel Ptr cback
'	
'	lab = "calendar" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	
'	cback = wxPanel( )
'	wxPanel_Create( cback, projpn, Cast(wxWindowID, widget), size, wxSize( -1, -1 ), 0, 0 )
'	
'	
'	calendar = wxCalendarCtrl( )
'	'wxCalendarCtrl_Create( calendar, projpn, Cast(wxWindowID, widget), wxDateTime(), size, wxSize( -1, -1 ), 0, 0 )
'	wxCalendarCtrl_Create( calendar, cback, Cast(wxWindowID, widget), wxDateTime(), wxSize( 0, 0 ), wxSize( -1, -1 ), 0, 0 )
'	
'	Dim As wxSize Ptr tmpsize
'	tmpsize = wxSize( -1, -1 )
'	wxWindow_GetBestSize( calendar, tmpsize )
'	wxWindow_SetSize3( cback, tmpsize )
'	
'	widget->kind		= VWX_WIDGET_calendar
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= calendar
'	widget->Name		= "calendar" + Str( cnt )
'	
'	cnt += 1
'	
'	wxEvtHandler_proxy( cback, Cast(EventListener, @event_projframe) )
'	wxEvtHandler_Connect( cback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
'	wxEvtHandler_Connect( cback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
'	wxEvtHandler_Connect( cback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
'	
'	Return widget
'	
'End Function
Private Function new_calendar ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxCalendarCtrl Ptr calendar
	Dim As wxPanel Ptr cback
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	cback = wxPanel( )
	calendar = wxCalendarCtrl( )
	
	If xml <> 0 Then
		widget->kind		= VWX_WIDGET_calendar
		widget->parent	  	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label
		widget->self		= calendar
		widget->Name		= xml->self
		'widget->style		= xml->style
	Else
		widget->kind		= VWX_WIDGET_calendar
		widget->parent	  	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "calendar" + Str( cnt )
		widget->self		= calendar
		widget->Name		= "calendar" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxPanel_Create( cback, widget->parent, Cast(wxWindowID, widget), widget->position, widget->size, 0, 0 )
	wxCalendarCtrl_Create( calendar, cback, Cast(wxWindowID, widget), wxDateTime(), wxSize( 0, 0 ), widget->size, widget->style, 0 )
	
	If xml = 0 Then
		Dim As wxSize Ptr tmpsize
		tmpsize = wxSize( -1, -1 )
		wxWindow_GetBestSize( calendar, tmpsize )
		wxWindow_SetSize3( cback, tmpsize )
		wxSize_dtor( tmpsize )
	EndIf
	
	cnt += 1
	
	wxEvtHandler_proxy( cback, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( cback, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
	wxEvtHandler_Connect( cback, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
	wxEvtHandler_Connect( cback, wxEvent_EVT_MOTION( ), -1, -1, 0 )
	
	Return widget
	
End Function

''
''
''
'Private Function new_checklistbox ( ByVal parent As Any Ptr, ByVal size As wxSize Ptr ) As VWX_WIDGET Ptr
'	Static As Integer cnt = 0
'	Dim As VWX_Widget Ptr widget
'	Dim As ZString Ptr label
'	Dim As String lab
'	Dim As wxListBox Ptr checklistbox
'	
'	lab = "checklistbox" + Str( cnt )
'	label = StrPtr( lab )
'	
'	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
'	
'	Dim As Integer choices = 1
'	ReDim As ZString Ptr choicestb(0)
'	Dim As String temps = "checklistbox" + Str( cnt )
'	choicestb( 0 ) = StrPtr( temps )
'	
'	checklistbox = wxListBox( )
'	
'	checklistbox = wxCheckListBox_ctor2( projpn, Cast(wxWindowID, widget), size, wxSize( -1, -1 ), choices, @choicestb( 0 ), 0, 0, 0 )
'	
'	widget->kind		= VWX_WIDGET_checklistbox
'	widget->position	= size
'	widget->size		= wxSize(-1, -1)
'	widget->label		= *label
'	widget->self		= checklistbox
'	widget->Name		= "checklistbox" + Str( cnt )
'	
'	cnt += 1
'	
'	Return widget
'	
'End Function
Private Function new_checklistbox ( ByVal parent As Any Ptr, ByVal position As wxSize Ptr, ByVal xml As xmlWidget Ptr = 0 ) As VWX_Widget Ptr
	
	Static As Integer cnt = 0
	Dim As VWX_Widget Ptr widget
	Dim As wxListBox Ptr checklistbox
	Dim As Integer choices
	ReDim As ZString Ptr choicestb( 0 )
	ReDim As String temps( 0 )
	
	widget = Cast(VWX_Widget Ptr, listNewNode( @widgetlist ))
	checklistbox = wxListBox( )
	
	If xml <> 0 Then
		Dim As String items = xml->item
		Dim As Integer found, checked_index
		
		found = InStr(items, !"\r")
		While found
			temps( choices ) = Left(items, found - 1)
			items = Right(items, Len(items) - found )
			choicestb( choices ) = StrPtr( temps( choices ) )
			choices += 1
			ReDim Preserve temps( choices )
			ReDim Preserve choicestb( choices )
			found = InStr(items, !"\r")
		Wend
		
		'checklistbox = wxCheckListBox_ctor2( parent, Cast(wxWindowID, widget), position, xml->size, choices, @choicestb( 0 ), xml->style, 0, 0 )
		checklistbox = wxCheckListBox_ctor2( parent, Cast(wxWindowID, widget), position, xml->size, choices, @choicestb( 0 ), 0, 0, 0 )
		
		widget->kind		= VWX_WIDGET_checklistbox
		widget->parent	  	= parent
		widget->position	= position
		widget->size		= xml->size
		widget->label		= xml->label + xml->item
		widget->self		= checklistbox
		widget->Name		= xml->self
		'widget->style		= xml->style
		
		found = InStr(xml->checked_item, !"\r")
		While found
			If Left(xml->checked_item, found - 1) <> "0" Then
				wxCheckListBox_Check( checklistbox, checked_index, TRUE )
			EndIf
			xml->checked_item = Right(xml->checked_item, Len(xml->checked_item) - found )
			found = InStr(xml->checked_item, !"\r")
			checked_index += 1
		Wend
	Else
		temps( choices ) = "checklistbox" + Str( cnt )
		choicestb( choices ) = StrPtr( temps( choices ) )
		choices += 1
		
		checklistbox = wxCheckListBox_ctor2( parent, Cast(wxWindowID, widget), position, wxSize( -1, -1 ), choices, @choicestb( 0 ), 0, 0, 0 )
		
		widget->kind		= VWX_WIDGET_checklistbox
		widget->parent	  	= parent
		widget->position	= position
		widget->size		= wxSize( -1, -1 )
		widget->label		= "checklistbox" + Str( cnt )
		widget->self		= checklistbox
		widget->Name		= "checklistbox" + Str( cnt )
		widget->style		= 0
	EndIf
	
	wxListBox_SetSelection( checklistbox, IIf(xml = 0, 0, xml->selection), TRUE )
	
	cnt += 1
	
	Return widget
	
End Function

''
''
''
Sub event_projframe (ByVal event As wxEvent Ptr, ByVal iListener As Long)
	Static As VWX_Widget Ptr dragging
	Dim As VWX_Widget Ptr widget
	Dim As wxSize Ptr size, sizepos
	Static As Integer hitx, hity, hasfocus
	
	'Static As Integer e1, e2, e3, e4, e5, e6, e7
	'If e1 + e2 + e3 + e4 + e5 + e6 + e7 = 0 Then
	'	Cls
	'EndIf
	'
	'Select Case wxEvent_GetEventType( event )
	'	Case wxEvent_EVT_ERASE_BACKGROUND( )
	'		e1 += 1
	'		Locate 1
	'		Print "wxEvent_EVT_ERASE_BACKGROUND"; e1; wxEvent_GetId( event ); wxEvent_GetEventObject( event ); Timer
	'	Case wxEvent_EVT_SIZE( )
	'		e2 += 1
	'		Locate 2
	'		Print "wxEvent_EVT_SIZE"; e2; wxEvent_GetId( event ); wxEvent_GetEventObject( event ); Timer
	'	Case wxEvent_EVT_PAINT( )
	'		e3 += 1
	'		Locate 3
	'		Print "wxEvent_EVT_PAINT"; e3; wxEvent_GetId( event ); wxEvent_GetEventObject( event ); Timer
	'	Case wxEvent_EVT_LEFT_UP( )
	'		e4 += 1
	'		Locate 4
	'		Print "wxEvent_EVT_LEFT_UP"; e4; wxEvent_GetId( event ); wxEvent_GetEventObject( event ); Timer
	'	Case wxEvent_EVT_LEFT_DOWN( )
	'		e5 += 1
	'		Locate 5
	'		Print "wxEvent_EVT_LEFT_DOWN"; e5; wxEvent_GetId( event ); wxEvent_GetEventObject( event ); Timer
	'	Case wxEvent_EVT_MOTION( )
	'		e6 += 1
	'		Locate 6
	'		Print "wxEvent_EVT_MOTION"; e6; wxEvent_GetId( event ); wxEvent_GetEventObject( event ); Timer
	'	Case wxEvent_EVT_CHAR( )
	'		e7 += 1
	'		Locate 7
	'		Print "wxEvent_EVT_CHAR"; e7; wxEvent_GetId( event ); wxEvent_GetEventObject( event ); Timer
	'End Select
	
	If ( wxEvent_GetEventType(event) = wxEvent_EVT_ERASE_BACKGROUND() ) Then
		If ( gridon = FALSE ) Then
			wxEvent_Skip( event, TRUE )
		EndIf
		Exit Sub
	EndIf
	
	'resize projpanel
	If ( wxEvent_GetEventType(event) = wxEvent_EVT_SIZE() ) Then
		If ( gridon ) Then
			redrawgrid( TRUE )
		EndIf
		If selected = 0 Then
			updateframelist( )
		EndIf
		wxEvent_Skip( event, TRUE )
	EndIf
	
	'repaint it
	If ( wxEvent_GetEventType(event) = wxEvent_EVT_PAINT() ) Then
		If ( gridon ) Then
			redrawgrid( )
			redrawwidgets( )
		EndIf
		wxEvent_Skip( event, TRUE )
	EndIf
	
	'left mousebutton released and tool selected
	If ( wxEvent_GetEventType(event) = wxEvent_EVT_LEFT_UP() ) And (curtool >= tool_notool) Then
		wxEvent_Skip( event, TRUE )
		''widget selected
		If dragging <> NULL Then
			'If wxWindow_GetParent( dragging->self ) = projpn Then
				wxWindow_ReleaseMouse( projpn )
			'	Print "freed:"; dragging->self
			'Else
			'	wxWindow_ReleaseMouse( wxWindow_GetParent( dragging->self ) )
			'	Print "freed:"; wxWindow_GetParent( dragging->self )
			'EndIf
			dragging = NULL
			Exit Sub
		EndIf
		
		''
		If boxsel > -1 Then
			wxWindow_ReleaseMouse( boxes( boxsel ) )
			boxsel = -1
			Exit Sub
		EndIf
		
		''
		size = wxSize( -1, -1 )
		wxMouseEvent_GetPosition( event, size )
		wxSize_SetWidth( size, (wxSize_GetWidth( size ) \ gridsize) * gridsize )
		wxSize_SetHeight( size, (wxSize_GetHeight( size ) \ gridsize) * gridsize )
		
		'set new widget
		Select Case curtool
			Case tool_stattext
				widget = new_stattext( projpn, size )
			Case tool_button
				widget = new_button( projpn, size )
			Case tool_togglebutton
				widget = new_togglebutton( projpn, size )
			Case tool_bmpbutton
				widget = new_bmpbutton( projpn, size )
			Case tool_image
				widget = new_image( projpn, size )
			Case tool_checkbox
				widget = new_checkbox( projpn, size )
			Case tool_choice
				widget = new_choice( projpn, size )
			Case tool_combo
				widget = new_combo( projpn, size )
			Case tool_textctrl
				widget = new_textctrl( projpn, size )
			Case tool_spinctrl
				widget = new_spinctrl( projpn, size )
			Case tool_richtext
				widget = new_richtext( projpn, size )
			Case tool_gauge
				widget = new_gauge( projpn, size )
			Case tool_radio
				widget = new_radiobox( projpn, size )
			Case tool_list
				widget = new_listbox( projpn, size )
			Case tool_staticbox
				widget = new_staticbox( projpn, size )
			Case tool_slider
				widget = new_slider( projpn, size )
			Case tool_staticline
				widget = new_staticline( projpn, size )
			Case tool_spinbutton
				widget = new_spinbutton( projpn, size )
			Case tool_calendar
				widget = new_calendar( projpn, size )
			Case tool_checklistbox
				widget = new_checklistbox( projpn, size )
			Case Else
				widget = NULL
		End Select
		
		If widget = NULL Then
			'Exit Sub
		Else
			''generate propertylist for new widget
			updatelist( widget )
			
			wxEvtHandler_proxy( widget->self, Cast(EventListener, @event_projframe) )
			wxEvtHandler_Connect( widget->self, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
			wxEvtHandler_Connect( widget->self, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
			wxEvtHandler_Connect( widget->self, wxEvent_EVT_MOTION( ), -1, -1, 0 )
			wxEvtHandler_Connect( widget->self, wxEvent_EVT_LEFT_DCLICK( ), -1, -1, 0 )
			wxEvtHandler_Connect( widget->self, wxEvent_EVT_CHAR( ), -1, -1, 0 )
			
			selected = widget
			wxWindow_Raise( widget->self )
			boxes_draw( widget->self )
		EndIf
		
	EndIf
	
	'left mousebutton pressed
	If wxEvent_GetEventType( event ) = wxEvent_EVT_LEFT_DOWN() Then
		'it's the projpanel
		If wxEvent_GetEventObject( event ) = projpn Then
		'	Dim As Byte Ptr hittest
		'	Dim As wxSize Ptr _size
		'	_size = wxSize( -1, -1 )
		'	wxMouseEvent_LogicalPosition( event, wxWindowDC_ctor2( proj ), _size )
		'	wxWindow_HitTest( Cast( VWX_Widget Ptr, listGetFirstNode( @widgetlist ) )->self, _size, @hittest )
		'	Locate 10
		'	Print hittest, *( @hittest + 1 ), *( @hittest + 2 )
		'	Print wxSize_GetWidth( _size ), wxSize_GetHeight( _size )
			
			If curtool = tool_notool Then
				selected = 0
				boxes_hide( )
				updateframelist( )
			EndIf
			
			Exit Sub
			
		Else
			
			'get selected widget
			dragging = Cast(VWX_Widget Ptr, wxEvent_GetId( event ))
			
		EndIf
		
		size = wxSize( -1, -1 )
		wxMouseEvent_GetPosition( event, size )
		hitx = wxSize_GetWidth( size )
		hity = wxSize_GetHeight( size )
		boxes_draw( wxEvent_GetEventObject( event ) )
		selected = dragging
		widget_tofront( dragging )
		updatelist( selected )
		wxEvent_Skip( event, FALSE )
		wxWindow_CaptureMouse( projpn )
		'Print "cap:"; wxEvent_GetEventObject( event ), dragging->self
		
	EndIf
	
	'If wxEvent_GetEventType( event ) = wxEvent_EVT_LEFT_DOWN( ) Then
	'	wxEvent_Skip( event, FALSE )
	'EndIf
	
	'resize widget - box is selected
	If (wxEvent_GetEventType( event ) = wxEvent_EVT_MOTION()) And (boxsel > -1) Then
		resizewidget( event, 0 )
		Exit Sub
	EndIf
	
	'widget moved
	If wxEvent_GetEventType( event ) = wxEvent_EVT_MOTION() And dragging <> NULL Then
		
		Dim As Integer oldx1, oldy1, oldx2, oldy2, newx1, newy1, newx2, newy2
		Dim As Any Ptr teh_obj, size2
		
		If wxWindow_GetParent( dragging->self ) = projpn Then
			teh_obj = dragging->self
		Else
			teh_obj = wxWindow_GetParent( dragging->self )
		EndIf
	
		oldx1 = wxSize_GetWidth(selected->position)
		oldy1 = wxSize_GetHeight(selected->position)
		oldx2 = wxSize_GetWidth(selected->size)
		oldy2 = wxSize_GetHeight(selected->size)
		
		If wxEvent_GetEventObject(event) = projpn Then
			size = wxSize( -1, -1)
			wxMouseEvent_GetPosition( event, size )
			wxWindow_Move( teh_obj, _
						   ((wxSize_GetWidth( size ) - hitx) \ gridsize) * gridsize, _
						   ((wxSize_GetHeight( size ) - hity) \ gridsize) * gridsize, 0 )
			
		Else
			size = wxSize( -1, -1 )
			wxWindow_GetPosition( wxEvent_GetEventObject( event ), size )
			If wxWindow_GetParent( wxEvent_GetEventObject( event ) ) <> projpn Then
				size2 = wxSize( -1, -1 )
				wxWindow_GetPosition( wxWindow_GetParent( wxEvent_GetEventObject( event ) ), size )
				wxSize_SetWidth( size, wxSize_GetWidth( size ) + wxSize_GetWidth( size2 ) )
				wxSize_SetHeight( size, wxSize_GetHeight( size ) + wxSize_GetHeight( size2 ) )
			EndIf
			
			sizepos = wxSize( -1, -1 )
			wxMouseEvent_GetPosition( event, sizepos )
			
			wxSize_SetHeight( sizepos, wxSize_GetHeight( sizepos ) + wxSize_GetHeight( size ) )
			wxSize_SetWidth( sizepos, wxSize_GetWidth( sizepos ) + wxSize_GetWidth( size ) )
			
			wxWindow_Move( teh_obj, _
						   ((wxSize_GetWidth( sizepos ) - hitx) \ gridsize) * gridsize, _
						   ((wxSize_GetHeight( sizepos ) - hity) \ gridsize) * gridsize, 0 )
		EndIf
		
		wxWindow_GetPosition( teh_obj, dragging->position )
		
		boxes_draw( dragging->self )
		
		newx1 = wxSize_GetWidth(selected->position)
		newy1 = wxSize_GetHeight(selected->position)
		newx2 = wxSize_GetWidth(selected->size)
		newy2 = wxSize_GetHeight(selected->size)
		
		If (oldx1 <> newx1 Or oldy1 <> newy1 Or oldx2 <> newx2 Or oldy2 <> newy2) Then
			wxListCtrl_SetItemText(mylist, 2, Str(newx1))
			wxListCtrl_SetItemText(mylist, 3, Str(newy1))
			wxListCtrl_SetItemText(mylist, 4, Str(newx2))
			wxListCtrl_SetItemText(mylist, 5, Str(newy2))
			wxWindow_Update(mylist)
			
			widget_redraw( dragging )
			'redrawgrid( )
			
		EndIf
	EndIf
	
	'Key clicked
	If wxEvent_GetEventType(event) = wxEvent_EVT_CHAR() Then
		If (wxKeyEvent_GetKeyCode(event) = WXK_DELETE) And (selected <> NULL) Then
			widget_delete( selected )
		'ElseIf wxKeyEvent_GetKeyCode( event ) = WXK_ESCAPE Then
		'	End
		EndIf
	EndIf
	
	'BitmapButton Helper
	If wxEvent_GetEventType(event) = wxEvent_EVT_ENTER_WINDOW() Then
		currentButton = wxEvent_GetEventObject(event)
		wxEvent_Skip( event, TRUE )
	EndIf
	
End Sub

''
'' XML toolmaker
''
Sub newXmlTool ( ByVal tool As xmlWidget )
	
	Dim As VWX_Widget Ptr widget
	
	Dim As String display
	Select Case tool.kind
		Case "wxStaticText"
			curtool = tool_stattext
			display = "StatText"
			widget = new_stattext( projpn, tool.position, @tool )
		Case "wxButton"
			curtool = tool_button
			display = "Button"
			widget = new_button( projpn, tool.position, @tool )
		Case "wxToggleButton"
			curtool = tool_togglebutton
			display = "ToggleButton"
			widget = new_togglebutton( projpn, tool.position, @tool )
		Case "wxBitmapButton"
			curtool = tool_bmpbutton
			display = "BitmapButton"
			widget = new_bmpbutton( projpn, tool.position, @tool )
		Case "wxStaticBitmap"
			curtool = tool_image
			display = "Image"
			widget = new_image( projpn, tool.position, @tool )
		Case "wxCheckBox"
			curtool = tool_checkbox
			display = "CheckBox"
			widget = new_checkbox( projpn, tool.position, @tool )
		Case "wxChoice"
			curtool = tool_choice
			display = "Choice"
			widget = new_choice( projpn, tool.position, @tool )
		Case "wxComboBox"
			curtool = tool_combo
			display = "Combo"
			widget = new_combo( projpn, tool.position, @tool )
		Case "wxTextCtrl"
			If tool.style = "" Then
				curtool = tool_textctrl
				display = "TextCtrl"
				widget = new_textctrl( projpn, tool.position, @tool )
			Else
				curtool = tool_richtext
				display = "RichText"
				widget = new_richtext( projpn, tool.position, @tool )
			EndIf
		Case "wxSpinCtrl"
			curtool = tool_spinctrl
			display = "SpinCtrl"
			widget = new_spinctrl( projpn, tool.position, @tool )
		Case "wxGauge"
			curtool = tool_gauge
			display = "Gauge"
			widget = new_gauge( projpn, tool.position, @tool )
		Case "wxRadioBox"
			curtool = tool_radio
			display = "Radio"
			widget = new_radiobox( projpn, tool.position, @tool )
		Case "wxListBox"
			curtool = tool_list
			display = "List"
			widget = new_listbox( projpn, tool.position, @tool )
		Case "wxStaticBox"
			curtool = tool_staticbox
			display = "StaticBox"
			widget = new_staticbox( projpn, tool.position, @tool )
		Case "wxSlider"
			curtool = tool_slider
			display = "Slider"
			widget = new_slider( projpn, tool.position, @tool )
		Case "wxStaticLine"
			curtool = tool_staticline
			display = "StaticLine"
			widget = new_staticline( projpn, tool.position, @tool )
		Case "wxSpinButton"
			curtool = tool_spinbutton
			display = "SpinButton"
			widget = new_spinbutton( projpn, tool.position, @tool )
		Case "wxCalendar"
			curtool = tool_calendar
			display = "Calendar"
			widget = new_calendar( projpn, tool.position, @tool )
		Case "wxCheckListBox"
			curtool = tool_checklistbox
			display = "CheckListBox"
			widget = new_checklistbox( projpn, tool.position, @tool )
		Case Else
			curtool = tool_notool
			display = "No tool selected"
	End Select
	
	
	updatelist( widget )
	wxEvtHandler_proxy( widget->self, Cast(EventListener, @event_projframe) )
	wxEvtHandler_Connect( widget->self, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
	wxEvtHandler_Connect( widget->self, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
	wxEvtHandler_Connect( widget->self, wxEvent_EVT_MOTION( ), -1, -1, 0 )
	wxEvtHandler_Connect( widget->self, wxEvent_EVT_LEFT_DCLICK( ), -1, -1, 0 )
	wxEvtHandler_Connect( widget->self, wxEvent_EVT_CHAR( ), -1, -1, 0 )
	
	
	selected = widget
	wxWindow_Raise( widget->self )
	boxes_draw( widget->self )
	
	wxTextCtrl_SetValue(toolText, StrPtr(display))
	
End Sub
