''

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

''
'' Update button handler
''
Sub propevent ( ByVal event As wxEvent Ptr, ByVal iListener As Long )
	
	If selected = NULL Then
		app.title = get_strfromlist( mylist, 1 )
		wxWindow_SetTitle( proj, StrPtr(app.title) )
		wxWindow_SetSize( proj, get_intfromlist( mylist, 2 ), get_intfromlist( mylist, 3 ), get_intfromlist( mylist, 4 ), get_intfromlist( mylist, 5 ), wxSIZE_AUTO )
		app.savePath = get_strfromlist( mylist, 6 )
		'app.icon = get_strfromlist( mylist, 7 )
		Dim As String temp = get_strfromlist( mylist, 7 )
		If temp <> "" Then
			app.icon = temp
			Dim As wxIcon Ptr frameIcon = wxIcon( )
			Dim As wxBitmap Ptr iconImage = wxBitmap( )
			wxBitmap_LoadFile( iconImage, StrPtr(app.icon), get_pictureType( app.icon ) )
			wxIcon_CopyFromBitmap( frameIcon, iconImage )
			wxFrame_SetIcon( proj, frameIcon )
		EndIf
		updateframelist( )
		Exit Sub
	EndIf
	
	selected->Name 		= get_strfromlist( mylist, 0 )
	selected->label	 	= get_strfromlist( mylist, 1 )
	selected->position  = wxSize( get_intfromlist( mylist, 2 ), get_intfromlist( mylist, 3 ) )
	selected->size 		= wxSize( get_intfromlist( mylist, 4 ), get_intfromlist( mylist, 5 ) )
	
	If wxWindow_GetParent( selected->self ) = projpn Then
		wxWindow_Move( selected->self, wxSize_GetWidth( selected->position ), wxSize_GetHeight( selected->position ), 0 )
	Else
		wxWindow_Move( wxWindow_GetParent( selected->self ), wxSize_GetWidth( selected->position ), wxSize_GetHeight( selected->position ), 0 ) 
	EndIf
	
	Dim As Integer num, i, orgnum
	
	Select Case selected->kind
		Case VWX_WIDGET_stattext
			'wxWindow_SetTitle(selected->self, StrPtr(selected->label))
			wxControl_SetLabel(selected->self, StrPtr(selected->label))
			
		Case VWX_WIDGET_button
			wxButton_SetLabel(selected->self, StrPtr(selected->label))
			
		Case VWX_WIDGET_togglebutton
			wxButton_SetLabel(selected->self, StrPtr(selected->label))
			wxToggleButton_SetValue(selected->self, Val(get_strfromlist(mylist, 6)))
			
		Case VWX_WIDGET_bmpbutton
			Dim As String picture = selected->label
			Dim As Integer pictureType = get_pictureType( picture )
			Dim As wxSize Ptr position = selected->position
			
			wxObject_dtor( selected->self )
			
			Dim As wxBitmap Ptr picbmpbutton
			picbmpbutton = wxBitmap( )
			wxBitmap_LoadFile( picbmpbutton, picture, pictureType )
			
			selected->self = wxBitmapButton( )
			wxBitmapButton_Create( selected->self, projpn, Cast(wxWindowID, selected), picbmpbutton, position, wxSize( -1, -1 ), -1, 0, 0 )
			wxWindow_SetBackgroundColour( selected->self, wxColour_ctorByParts( 255, 255, 255 ) )
			
			wxEvtHandler_proxy( selected->self, Cast(EventListener, @event_projframe) )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_ENTER_WINDOW( ), Cast(wxWindowID, selected), -1, 0 )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0 )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_MOTION( ), -1, -1, 0 )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_LEFT_DCLICK( ), -1, -1, 0 )
			
		Case VWX_WIDGET_image
			Dim As wxBitmap Ptr picimage
			picimage = wxBitmap( )
			wxBitmap_LoadFile( picimage, selected->label, get_pictureType( selected->label ) )
			
			wxStaticBitmap_SetBitmap(selected->self, picimage)
			
		Case VWX_WIDGET_checkbox
			wxControl_SetLabel(selected->self, StrPtr(selected->label))
			wxCheckBox_SetValue(selected->self, Val(get_strfromlist(mylist, 6)))
			
		Case VWX_WIDGET_textctrl
			wxTextCtrl_SetValue(selected->self, StrPtr(selected->label))
			
		Case VWX_WIDGET_spinctrl
			wxSpinCtrl_SetRange(selected->self, Val( get_strfromlist( mylist, 7 ) ), Val( get_strfromlist( mylist, 6 ) ))
			wxSpinCtrl_SetValue(selected->self, Val( get_strfromlist( mylist, 8 ) ))
			
		Case VWX_WIDGET_richtext
			wxTextCtrl_SetValue(selected->self, StrPtr(selected->label))
			
		Case VWX_WIDGET_choice
			num = wxListCtrl_GetItemCount( mylist ) - 6
			orgnum = num
			Dim As ZString Ptr thingy( num - 1 )
			selected->label = ""
			For i = 0 To num - 1
				thingy( i ) = wxString_to_zstring( wxListCtrl_GetItemText( mylist, i + 6 ) )
				selected->label += *thingy( i ) + !"\r"'NEWLINE
				If ( i = num - 1 And *thingy( i ) = "" ) Then
					num -= 1
					While *thingy( num - 1 ) = ""
						wxListCtrl_DeleteItem( mylist, num + 6 )
						num -= 1
					Wend
				EndIf
			Next
			
			wxChoice_Clear( selected->self )
			wxChoice_AppendArrayString( selected->self, num, @thingy( 0 ) )
			wxChoice_SetSelection( selected->self, 0 )
			If orgnum = num Then
				wxListCtrl_InsertTextItem( mylist, num + 6, "" )
				wxListCtrl_SetItem_By_Row_Col( mylist, num + 6, 1, "Choice " + Str( num + 1 ), 0 )
			EndIf
			
		Case VWX_WIDGET_combo
			num = wxListCtrl_GetItemCount( mylist ) - 6
			orgnum = num
			Dim As ZString Ptr thingyc( num )
			Dim As String tempstr
			tempstr = str_getline( selected->label, 0 )
			thingyc( 0 ) = StrPtr( tempstr )
			For i = 0 To num - 1
				thingyc(i + 1) = wxString_to_zstring( wxListCtrl_GetItemText( mylist, i + 6 ) )
				selected->label += !"\r" /'NEWLINE'/ + *thingyc( i + 1 )
				If (i = num - 1 And *thingyc(i + 1) = "") Then
					num -= 1
					While *thingyc(num) = ""
						wxListCtrl_DeleteItem( mylist, num + 6 )
						num -= 1
					Wend
				EndIf
			Next
			wxChoice_Clear( selected->self )
			wxChoice_AppendArrayString( selected->self, num + 1, @thingyc( 0 ) )
			wxChoice_SetSelection( selected->self, 0 )
			If orgnum = num Then
				wxListCtrl_InsertTextItem( mylist, num + 6, "" )
				wxListCtrl_SetItem_By_Row_Col( mylist, num + 6, 1, "Choice " + Str( num + 1 ), 0 )
			EndIf
			
		Case VWX_WIDGET_gauge
			wxGauge_SetRange( selected->self, Val( get_strfromlist( mylist, 6 ) ) )
			wxGauge_SetValue( selected->self, Val( get_strfromlist( mylist, 7 ) ) )
			
		Case VWX_WIDGET_radio
			num = wxListCtrl_GetItemCount( mylist ) - 6
			orgnum = num
			Dim As ZString Ptr thingyf( num )
			Dim As String tempstrf, tempforstring
			tempstrf = str_getline( selected->label, 0 )
			thingyf( 0 ) = StrPtr( tempstrf )
			For i = 0 To num - 1
				thingyf( i + 1 ) = wxString_to_zstring( wxListCtrl_GetItemText( mylist, i + 6 ) )
				selected->label += !"\r" /'NEWLINE'/ + *thingyf( i + 1 )
				If ( i = num - 1 And *thingyf( i + 1 ) = "" ) Then
					num -= 1
					While *thingyf( num ) = ""
						wxListCtrl_DeleteItem( mylist, num + 6 )
						num -= 1
					Wend
				EndIf
			Next
			If orgnum = num Then
				wxListCtrl_InsertTextItem( mylist, num + 6, "" )
				wxListCtrl_SetItem_By_Row_Col( mylist, num + 6, 1, "Choice " + Str( num + 1 ), 0 )
			EndIf
			
			Dim As wxPanel Ptr tempPanel = wxWindow_GetParent(selected->self)
			wxObject_dtor( selected->self )
			selected->self = wxRadiobox( )
			wxRadioBox_Create( selected->self, tempPanel, Cast( Integer, selected ), thingyf( 0 ), wxSize( -1, -1 ), wxSize( -1, -1 ), num, @thingyf( 1 ), 0, 0, 0, 0 )
				
			wxEvtHandler_proxy( selected->self, Cast(EventListener, @event_projframe) )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_LEFT_DOWN( ), -1, -1, 0)
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_LEFT_UP( ), -1, -1, 0 )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_MOTION( ), -1, -1, 0 )
			wxEvtHandler_Connect( selected->self, wxEvent_EVT_LEFT_DCLICK( ), -1, -1, 0 )
			  
		Case VWX_WIDGET_list
			num = wxListCtrl_GetItemCount( mylist ) - 6
			orgnum = num
			Dim As ZString Ptr thingy( num - 1 )
			selected->label = ""
			For i = 0 To num - 1
				thingy( i ) = wxString_to_zstring( wxListCtrl_GetItemText( mylist, i + 6 ) )
				selected->label += *thingy( i ) + !"\r"'NEWLINE
				If ( i = num - 1 And *thingy( i ) = "" ) Then
					num -= 1
					While *thingy( num - 1 ) = ""
						wxListCtrl_DeleteItem( mylist, num + 6 )
						num -= 1
					Wend
				EndIf
	        Next
			wxListBox_Clear( selected->self )
			wxListBox_InsertItems( selected->self, num, @thingy( 0 ), 0 )
			wxListBox_SetSelection( selected->self, 0, TRUE )
			If orgnum = num Then
				wxListCtrl_InsertTextItem( mylist, num + 6, "" )
				wxListCtrl_SetItem_By_Row_Col( mylist, num + 6, 1, "Choice " + Str( num + 1 ), 0 )
			EndIf
			
    	Case VWX_WIDGET_staticbox
			wxControl_SetLabel( selected->self, StrPtr( selected->label ) )
			
    	Case VWX_WIDGET_slider
			'wxControl_SetLabel(selected->self, StrPtr(selected->label))
			wxSlider_SetRange( selected->self, Val( get_strfromlist( mylist, 7 ) ), Val( get_strfromlist( mylist, 6 ) ) )
			wxSlider_SetValue( selected->self, Val( get_strfromlist( mylist, 8 ) ) )
			
    	Case VWX_WIDGET_staticline
			'wxControl_SetLabel(selected->self, StrPtr(selected->label))
			
    	Case VWX_WIDGET_spinbutton
			'wxControl_SetLabel(selected->self, StrPtr(selected->label))
			
    	Case VWX_WIDGET_calendar
			'wxControl_SetLabel(selected->self, StrPtr(selected->label))
			
    	Case VWX_WIDGET_checklistbox
			num = wxListCtrl_GetItemCount(mylist) - 6
			orgnum = num
			Dim As ZString Ptr thingy(num - 1)
			selected->label = ""
			For i = 0 To num - 1
				thingy(i) = wxString_to_zstring( wxListCtrl_GetItemText( mylist, i + 6 ) )
				selected->label += *thingy(i) + !"\r"'NEWLINE
				If ( i = num - 1 And *thingy(i) = "" ) Then
					num -= 1
					While *thingy(num - 1) = ""
						wxListCtrl_DeleteItem( mylist, num + 6 )
						num -= 1
					Wend
				EndIf
			Next
			wxListBox_Clear( selected->self )
			wxListBox_InsertItems( selected->self, num, @thingy(0), 0 )
			wxListBox_SetSelection( selected->self, 0, TRUE )
			If orgnum = num Then
				wxListCtrl_InsertTextItem(mylist, num + 6, "")
				wxListCtrl_SetItem_By_Row_Col(mylist, num + 6, 1, "Choice " + Str( num + 1 ), 0)
			EndIf
			
    End Select
	
	''
	Dim As wxSize Ptr bestsize = wxSize( -1 , -1 )
	wxWindow_GetBestSize( selected->self, bestsize )
	
	If wxSize_GetWidth( selected->size ) <> -1 Then
		wxSize_SetWidth( bestsize, wxSize_GetWidth( selected->size ) )
	EndIf
	
	If wxSize_GetHeight( selected->size ) <> -1 Then
		wxSize_SetHeight( bestsize, wxSize_GetHeight( selected->size ) )
	EndIf
	
	wxWindow_SetSize3( selected->self, bestsize )
	If wxWindow_GetParent( selected->self ) <> projpn Then
		wxWindow_SetSize3( wxWindow_GetParent( selected->self ), bestsize )
	EndIf
	
	''
	boxes_draw( selected->self )
	
End Sub
