''

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

ReDim Shared As String toolbardata( 0, 2 )
Dim Shared As Integer numitems

''
'' 
''
Sub make_toolbar( ByVal parent As Any Ptr, ByVal xml As xmlWidget Ptr = 0 )
	
	Static As Byte toolbar_enabled
	toolbar_enabled = Not toolbar_enabled
	
	Dim As UInteger style
	If xml = 0 Then
		style = wxHORIZONTAL Or wxTB_TEXT Or wxTB_FLAT
	Else
		style = wxHORIZONTAL Or wxTB_TEXT Or wxTB_FLAT'xml->style
	EndIf
	
	If toolbar_enabled Then
		wxFrame_CreateToolBar( parent, style, -1, 0 )
	Else
		wxObject_dtor( wxFrame_GetToolBar( parent ) )
	EndIf
	
End Sub

''
'' 
''
Sub add_to_toolbar( ByVal parent As Any Ptr, ByVal xml As xmlWidget Ptr = 0 )
	
	Dim As String bmpfilename, temp1, temp2
	
	If xml = 0 Then
		'Static As Integer numitems
		
		Dim As wxFileDialog Ptr bmpfile
		bmpfile = wxFileDialog( proj, "Search file", 0, "", "Any files (*)|*.*|Bitmap files (*.bmp)|*.bmp", 0, wxSize( -1, -1 ) )
		
		'' Cancelled
		If ( wxFileDialog_ShowModal( bmpfile ) <> wxID_OK ) Then
			Exit Sub
		EndIf
		
		bmpfilename = wxString_to_fbstring( wxFileDialog_GetDirectory( bmpfile ) ) + SEPARATOR + wxString_to_fbstring( wxFileDialog_GetFilename( bmpfile ) )
		
		Dim As wxDialog Ptr myDiag
		myDiag = wxDialog( )
		wxDialog_Create( myDiag, proj, -1, "Add to the toolbar", _
						 wxSize( -1, -1 ), wxSize( 175, 150 ), _
						 wxDEFAULT_FRAME_STYLE Or wxCLOSE_BOX Xor wxRESIZE_BORDER Xor wxMAXIMIZE_BOX, _
						 0 )
		wxWindow_SetAutoLayout( myDiag, TRUE )
		Dim As wxStaticText Ptr diagtext
		diagtext = wxStaticText( )
		wxStaticText_Create( diagtext, myDiag, -1, "Label:", wxSize( 5, 5 ), wxSize( -1, -1 ), 0, 0 )
		
		Dim As wxTextCtrl Ptr widgetname
		widgetname = wxTextCtrl( )
		wxTextCtrl_Create( widgetname, myDiag, -1, 0, wxSize( 5, 20 ), wxSize( 150, -1 ), 0, 0, 0 )
		
		diagtext = wxStaticText( )
		wxStaticText_Create( diagtext, myDiag, -1, "Help String:", wxSize( 5, 45 ), wxSize( -1, -1 ), 0, 0 )
		
		Dim As wxTextCtrl Ptr helpstr
		helpstr = wxTextCtrl( )
		wxTextCtrl_Create( helpstr, myDiag, -1, 0, wxSize( 5, 60 ), wxSize( 150, -1 ), 0, 0, 0 )
		
		Dim As wxButton Ptr diagclosebutton
		diagclosebutton = wxButton( )
		wxButton_Create( diagclosebutton, myDiag, -1, "Add", wxSize( 15, 85 ), wxSize( -1, -1 ), 0, 0, 0 )
		wxEvtHandler_proxy( diagclosebutton, Cast(EventListener, @closewin) ) ''all-purpose window closer ;)
		wxEvtHandler_Connect( diagclosebutton, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )
		
		wxDialog_ShowModal( myDiag )
		
		temp1 = wxString_to_fbstring( wxTextCtrl_GetValue( widgetname ) )
		temp2 = wxString_to_fbstring( wxTextCtrl_GetValue( helpstr ) )
	Else
		temp1 = xml->label
		bmpfilename = xml->bitmap
		temp2 = xml->longhelp
	EndIf
	
	Dim As wxBitmap Ptr tempBitmap = wxBitmap( )
	wxBitmap_LoadFile( tempBitmap, bmpfilename, get_pictureType(bmpfilename) )
	
	wxToolBar_AddTool2( wxFrame_GetToolBar( parent ), -1, _
						StrPtr(temp1), _
						tempBitmap, _
						StrPtr(temp2), _
						0 )
	wxToolBar_Realize( wxFrame_GetToolBar( parent ) )
	
	toolbardata( numitems, 0 ) = temp1
	toolbardata( numitems, 1 ) = bmpfilename
	toolbardata( numitems, 2 ) = temp2
	numitems += 1
	ReDim Preserve toolbardata( numitems, 2 ) As String
	
	'wxWindow_Show(proj, 0)
	'wxFrame_Maximize(proj, 1)
	'wxFrame_Maximize(proj, 0)
	'wxWindow_Show(proj, 1)
	
End Sub

''
'' 
''
Sub add_separator( ByVal parent As Any Ptr )
	
	wxToolBar_AddSeparator( wxFrame_GetToolBar( parent ) )
	wxToolBar_Realize( wxFrame_GetToolBar( parent ) )
	
	toolbardata( numitems, 0 ) = ""
	toolbardata( numitems, 1 ) = ""
	toolbardata( numitems, 2 ) = ""
	numitems += 1
	ReDim Preserve toolbardata( numitems, 2 ) As String
	
End Sub

''
'' returns the local array data
''
Function get_toolbardata( ByVal firstidx As Integer, ByVal secondidx As Integer ) As String
	
	Return str_replace( SEPARATOR, SEPARATOR + SEPARATOR, toolbardata( firstidx, secondidx ) )
	
End Function
