''

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

''
''
''
Sub resizewidget( ByVal event As wxEvent Ptr, ByVal iListener As Long )
	Static As Integer hitx, hity
	Dim As Any Ptr anotherptr, winsizeforbox2, someptr, orgsize
	Dim As Integer oldx1, oldy1, oldx2, oldy2, newx1, newy1, newx2, newy2
	
	If wxEvent_GetEventType(event) = wxEvent_EVT_CHAR() Then
		event_projframe( event, 0 )
		Exit Sub
	EndIf
	
	If wxEvent_GetEventType(event) = wxEvent_EVT_LEFT_DOWN() Then
		boxsel = wxEvent_GetId(event) - projframe - 1
		anotherptr = wxSize(-1, -1)
		wxMouseEvent_GetPosition(event, anotherptr)
		hitx = wxSize_GetWidth(anotherptr)
		hity = wxSize_GetHeight(anotherptr)
		wxWindow_CaptureMouse( projpn )
	EndIf
	
	If (wxEvent_GetEventType( event ) = wxEvent_EVT_MOTION( )) And (boxsel > -1) Then
		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
			anotherptr = wxSize(-1, -1)
			wxMouseEvent_GetPosition(event,anotherptr)
			wxWindow_Move(boxes(boxsel), ((wxSize_GetWidth(anotherptr) - hitx) \ gridsize) * gridsize, ((wxSize_GetHeight(anotherptr) - hity) \ gridsize) * gridsize, 0)
		Else
			someptr = wxSize( -1, -1 )
			wxWindow_GetPosition( wxEvent_GetEventObject( event ), someptr )
			anotherptr = wxSize( -1, -1 )
			wxMouseEvent_GetPosition( event, anotherptr )
			wxSize_SetHeight( anotherptr, wxSize_GetHeight( anotherptr ) + wxSize_GetHeight( someptr ))
			wxSize_SetWidth( anotherptr, wxSize_GetWidth( anotherptr ) + wxSize_GetWidth( someptr ))
			wxWindow_Move( boxes( boxsel ), (( wxSize_GetWidth( anotherptr ) - hitx ) \ gridsize ) * gridsize, (( wxSize_GetHeight( anotherptr ) - hity ) \ gridsize ) * gridsize, 0 )
		EndIf
		
		anotherptr = wxSize( -1, -1 )
		winsizeforbox2 = wxSize( -1, -1 )
		orgsize = wxSize( -1, -1 )
		
		wxWindow_GetPosition( boxes(boxsel), winsizeforbox2 )
		If wxWindow_GetParent( selected->self ) = projpn Then
			wxWindow_GetPosition( selected->self, anotherptr )
		Else
			wxWindow_GetPosition( wxWindow_GetParent( selected->self ), anotherptr )
		EndIf
		wxWindow_GetSize( selected->self, orgsize )
		
		Dim As Integer must_resize = 0, temp
		If ( boxsel <> 0 And boxsel <> 2 ) Then
			wxSize_SetHeight( winsizeforbox2, wxSize_GetHeight( winsizeforbox2 ) - wxSize_GetHeight( anotherptr ))
		Else
			temp = wxSize_GetHeight( anotherptr )
			wxSize_SetHeight( anotherptr, wxSize_GetHeight( winsizeforbox2 ) + boxsize )
			wxSize_SetHeight( winsizeforbox2, -( wxSize_GetHeight( winsizeforbox2 ) + boxsize - temp ) + wxSize_GetHeight( orgsize ))
			must_resize = 1
		EndIf
		
		If ( boxsel <> 0 And boxsel <> 1 ) Then
			wxSize_SetWidth( winsizeforbox2, wxSize_GetWidth( winsizeforbox2 ) - wxSize_GetWidth( anotherptr ))
		Else
			temp = wxSize_GetWidth( anotherptr )
			wxSize_SetWidth( anotherptr, wxSize_GetWidth( winsizeforbox2 ) + boxsize )
			wxSize_SetWidth( winsizeforbox2, -( wxSize_GetWidth( winsizeforbox2 ) + boxsize - temp ) + wxSize_GetWidth( orgsize ))
			must_resize = 1
		EndIf
		
		selected->size = wxSize( wxSize_GetWidth( winsizeforbox2 ), wxSize_GetHeight( winsizeforbox2 ))
		
		wxWindow_SetSize3( selected->self, winsizeforbox2 )
		If wxWindow_GetParent( selected->self ) <> projpn Then
			wxWindow_SetSize3( wxWindow_GetParent( selected->self ), winsizeforbox2 )
		EndIf
		
		If ( must_resize = 1 ) Then
			If wxWindow_GetParent( selected->self ) <> projpn Then
				wxWindow_Move( wxWindow_GetParent( selected->self ), wxSize_GetWidth( anotherptr ), wxSize_GetHeight( anotherptr ), 0 )
			Else
				wxWindow_Move( selected->self, wxSize_GetWidth( anotherptr ), wxSize_GetHeight( anotherptr ), 0 )
			EndIf
			selected->position = wxSize( wxSize_GetWidth( anotherptr ), wxSize_GetHeight( anotherptr ))
		EndIf
		
		boxes_draw( selected->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( selected )
		EndIf
		
	EndIf
	
	If wxEvent_GetEventType( event ) = wxEvent_EVT_LEFT_UP( ) Then
		boxsel = -1
	EndIf
	
End Sub

''
''
''
Private Sub boxes_init()
	Static As Integer initialized = FALSE
	
	If ( initialized ) Then
		Exit Sub
	EndIf
	
	Dim As Integer i, id
	
	id = projframe + 1
	For i = 0 To VXW_BOXES - 1
		boxes(i) = create_bmpbutton( id, "box.bmp", projpn, 1, 1, boxsize, boxsize, 0 )
		
		wxEvtHandler_proxy( boxes(i), Cast(EventListener, @resizewidget) )
		wxEvtHandler_Connect( boxes(i), wxEvent_EVT_LEFT_DOWN( ), id, -1, 0 )
		wxEvtHandler_Connect( boxes(i), wxEvent_EVT_LEFT_UP( ), id, -1, 0 )
		wxEvtHandler_Connect( boxes(i), wxEvent_EVT_MOTION( ), id, -1, 0 )
		wxEvtHandler_Connect( boxes(i), wxEvent_EVT_CHAR( ), -1, -1, 0 )
		
		id += 1
	Next
	
	wxWindow_SetCursor( boxes(0), wxCursor_ctorById( wxCURSOR_SIZENWSE ) )
	wxWindow_SetCursor( boxes(1), wxCursor_ctorById( wxCURSOR_SIZENESW ) )
	wxWindow_SetCursor( boxes(2), wxCursor_ctorById( wxCURSOR_SIZENESW ) )
	wxWindow_SetCursor( boxes(3), wxCursor_ctorById( wxCURSOR_SIZENWSE ) )
	
	initialized = TRUE
	
End Sub

''
''
''
Sub boxes_draw( ByVal widget As Any Ptr )
	If wxWindow_GetParent( widget ) <> projpn Then
		widget = wxWindow_GetParent( widget )
	EndIf
	Dim As wxSize Ptr sizepos, size
	
	boxes_init( )
	
	sizepos = wxSize( -1, -1 )
	size = wxSize( -1, -1 )
	
	wxWindow_GetPosition( widget, sizepos )
	wxWindow_GetSize( widget, size )
	
	Dim As Integer swdt = wxSize_GetWidth( size ), _
				   shgt = wxSize_GetHeight( size ), _
				   pwdt = wxSize_GetWidth( sizepos ), _
				   phgt = wxSize_GetHeight( sizepos )
	wxWindow_Move( boxes(0), pwdt - boxsize, phgt - boxsize, 0 )
	wxWindow_Move( boxes(1), pwdt - boxsize, phgt + shgt   , 0 )
	wxWindow_Move( boxes(2), pwdt + swdt   , phgt - boxsize, 0 )
	wxWindow_Move( boxes(3), pwdt + swdt   , phgt + shgt   , 0 )
	
	
	'finally!  i found a way to keep the boxes from getting overwritten by the widget's image :)
	Dim As Integer i
	For i = 0 To VXW_BOXES - 1
		wxWindow_Refresh( boxes( i ), 1, 0 )
	Next
	
End Sub

''
''
''
Sub boxes_tofront( )

	Dim As Integer i
	For i = 0 To VXW_BOXES - 1
		wxWindow_Raise( boxes(i) )
	Next

End Sub

Sub boxes_hide( )
	
	boxes_init( )
	
	Dim As Integer i
	For i = 0 To 3
		wxWindow_Move( boxes(i), -boxsize, -boxsize, 0 )
	Next
	
End Sub
