''
'' Initializer functions (order as called)
''

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

''
'' Generates a new list
''
Sub init_list( )
	
	listNew( @widgetlist, VWX_WIDGETLIST_INITNODES, Len( VWX_Widget ) )
	listNew( @menulist, VWX_WIDGETLIST_INITNODES, Len( VWX_Menu ) )
	
End Sub

''
'' Creates the menu on top of the designer
''
Sub init_menus( )
	Dim menub1 As wxMenuBar Ptr
	Dim menu1 As wxMenu Ptr
	Dim savemenu As wxMenu Ptr
	Dim tempitem As wxMenuItem Ptr
	Dim tempitem2 As wxMenuItem Ptr
	menub1 = wxMenuBar( )
	menu1 = wxMenu( 0, 0 )
	menu2 = wxMenu( 0, 0 )
	menu3 = wxMenu( 0, 0 )
	gridmenu = wxMenu( 0, 0 )
	savemenu = wxMenu( 0, 0 )
	
	tempitem = wxMenuItem( menu1, menu_import, "&Import Form", "Save current layout", 0, 0 )
	wxMenuItem_SetBitmap( tempitem, wxBitmap_ctorByName( "images/import.png", wxBITMAP_TYPE_PNG ) )
	wxMenuBase_AppendItem( menu1, tempitem )
	
	tempitem = wxMenuItem( menu1, menu_save, "&Save", "Save current layout", 0, savemenu )
	wxMenuItem_SetBitmap( tempitem, wxBitmap_ctorByName( "images/save.png", wxBITMAP_TYPE_PNG ) )
	wxMenuBase_AppendItem( menu1, tempitem )
	
		tempitem2 = wxMenuItem( savemenu, menu_export, "&Form export", "Export form", 0, 0 )
		wxMenuItem_SetBitmap( tempitem2, wxBitmap_ctorByName( "images/export.png", wxBITMAP_TYPE_PNG ) )
		wxMenuBase_AppendItem( savemenu, tempitem2 )
		tempitem2 = wxMenuItem( savemenu, menu_save, "&Code export", "Output code", 0, 0 )
		wxMenuItem_SetBitmap( tempitem2, wxBitmap_ctorByName( "images/save.png", wxBITMAP_TYPE_PNG ) )
		wxMenuBase_AppendItem( savemenu, tempitem2 )
	
	
	tempitem = wxMenuItem( menu1, -1, "&Grid size", "Change the snap-to-grid size", 0, gridmenu )
	wxMenuItem_SetBitmap( tempitem, wxBitmap_ctorByName( "images/grid.png", wxBITMAP_TYPE_PNG ) )
	wxMenuBase_AppendItem( menu1, tempitem )
	
		'wxMenuBase_AppendSubMenu( menu1, -1, "&Grid size", gridmenu, "Change the snap-to-grid size" )
		wxMenuBase_AppendRadioItem( gridmenu, menu_grid1x1, "&1x1", "Grid size of 1 by 1" )
		wxMenuBase_AppendRadioItem( gridmenu, menu_grid5x5, "&5x5", "Grid size of 5 by 5" )
		wxMenuBase_AppendRadioItem( gridmenu, menu_grid10x10, "1&0x10", "Grid size of 10 by 10" )
		wxMenuBase_Check( gridmenu, menu_grid10x10, TRUE )
		wxMenuBase_AppendSeparator( gridmenu )
		wxMenuBase_AppendCheckItem( gridmenu, menu_gridoff, "Grid &On", "Toggle grid on / off" )
		wxMenuBase_Check( gridmenu, menu_gridoff, IIf( gridon, TRUE, FALSE ) )
	
	wxMenuBase_AppendSeparator( menu1 )
	
	tempitem = wxMenuItem( menu1, menu_exit, "E&xit", "Quit Visual WX-C Designer", 0, 0 )
	wxMenuItem_SetBitmap( tempitem, wxBitmap_ctorByName( "images/close.png", wxBITMAP_TYPE_PNG ) )
	wxMenuBase_AppendItem( menu1, tempitem )
	'wxMenuBase_Append( menu1, menu_exit, "E&xit", "Quit Visual WX-C Designer", 0 )
	
	wxMenuBar_Append( menub1, menu1, "&File" )
	
	tempitem = wxMenuItem( menu2, menu_create, "&Add menu", "Add a menu", 0, 0 )
	wxMenuBase_AppendItem( menu2, tempitem )
	
	tempitem = wxMenuItem( menu2, menu_toolbar, "&Enable toolbar", "Add a toolbar", wxITEM_CHECK, 0 )
	wxMenuBase_AppendItem( menu2, tempitem )
	
	tempitem = wxMenuItem( menu2, menu_addtotoolbar, "Add item to &toolbar", "Add to the toolbar", 0, 0 )
	wxMenuBase_AppendItem( menu2, tempitem )
	wxMenuBase_Enable( menu2, menu_addtotoolbar, FALSE )
	
	tempitem = wxMenuItem( menu2, menu_septoolbar, "Add &separator to toolbar", "Add to the toolbar", 0, 0 )
	wxMenuBase_AppendItem( menu2, tempitem )
	wxMenuBase_Enable( menu2, menu_septoolbar, FALSE )
	
	wxMenuBar_Append( menub1, menu2, "&Tools" )
	
	tempitem = wxMenuItem( menu3, propertyDialog, "&Change properties", "Change properties", 0, 0 )
	wxMenuBase_AppendItem( menu3, tempitem )
	
	wxMenuBar_Append( menub1, menu3, "&Properties" )
	
	
	wxFrame_SetMenuBar( wx_frame, menub1 )
	wxEvtHandler_Connect( wx_frame, wxEvent_EVT_COMMAND_MENU_SELECTED(), -1, -1, 0 )
	
End Sub

''
'' Creates tool buttons
''
Sub init_tools()
	Dim As ZString * 32 bmptb(0 To VXW_TOOLS - 1) => { "Cursor.bmp", _
		"StatText.bmp", "Button.bmp", "ToggleButton.bmp", "BitmapButton.bmp", "Image.bmp", "CheckBox.bmp", "Choice.bmp", "Combo.bmp", _
		"TextCtrl.bmp"	  , "SpinCtrl.bmp", "RichText.bmp", "Gauge.bmp" , "Radio.bmp" , "List.bmp", "StaticBox.bmp", "Slider.bmp", "StaticLine.bmp", "SpinButton.bmp", "Calendar.bmp", "CheckListBox.bmp" }
	
	Dim As Integer idtb(0 To VXW_TOOLS - 1) => { tool_notool, _
		tool_stattext, tool_button, tool_togglebutton, tool_bmpbutton, tool_image, tool_checkbox, tool_choice, tool_combo, _
		tool_textctrl	, tool_spinctrl, tool_richtext, tool_gauge , tool_radio , tool_list, tool_staticbox, tool_slider, tool_staticline, tool_spinbutton, tool_calendar, tool_checklistbox }
	
	Const BUTTON_WIDTH = 24		
	
	Dim As Integer i, x, y
	
	x = -1
	y = 22
	For i = 0 To VXW_TOOLS - 1
		create_bmpbutton( idtb(i), bmptb(i), wx_frame, x, y )
		
		If ( x = -1 ) Then
			x = BUTTON_WIDTH
		Else
			x += BUTTON_WIDTH
		EndIf
		
		If ( x = BUTTON_WIDTH * 8 ) Then
				x = -1
				y += BUTTON_WIDTH
		EndIf
	Next
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''First Button  -  Last Button
	wxEvtHandler_Connect( wx_frame, wxEvent_EVT_COMMAND_BUTTON_CLICKED(), tool_FIRSTID + 1, tool_LASTID - 1, 0 )
	
	'menu_on = wxButton( )
	'wxButton_Create( menu_on, wx_frame, menu_on, "Create Menu", wxSize( 10, 60 ), wxSize( -1, -1 ), 0, 0, 0 )
	
	'wxEvtHandler_Proxy( menu_on, @menu_makemenu )
	'wxEvtHandler_Connect( menu_on, wxEvent_EVT_COMMAND_BUTTON_CLICKED(), -1, -1, 0 )
	
End Sub

''
'' Init buttons and propertylist + icon
''
Sub initpropdiag()
	Dim As wxListItem Ptr col1, col2
	
	mylist = wxListCtrl( )
	wxListCtrl_Create( mylist, wx_frame, -1, wxSize(4, 334), wxSize( 185, 211 ), wxLC_REPORT Or wxLC_SINGLE_SEL Or wxLC_HRULES Or wxLC_VRULES Or wxLC_EDIT_LABELS, 0, 0 )
	wxEvtHandler_proxy( mylist, Cast(EventListener, @listevent) )
	wxEvtHandler_Connect( mylist, wxEvent_EVT_COMMAND_LIST_ITEM_RIGHT_CLICK(), -1, -1, 0 )
	wxEvtHandler_Connect( mylist, wxEvent_EVT_COMMAND_LIST_END_LABEL_EDIT(), -1, -1, 0 )
	
	col1 = wxListItem( )
	wxListItem_SetAlign( col1, wxLIST_FORMAT_LEFT )
	wxListItem_SetText( col1, "Value" )
	wxListItem_SetWidth( col1, 110 )
	wxListCtrl_InsertColumn( mylist, 0, col1 )
	
	col2 = wxListItem( )
	wxListItem_SetAlign( col2, wxLIST_FORMAT_LEFT Or wxLC_EDIT_LABELS )
	wxListItem_SetText( col2, "Property" )
	wxListItem_SetWidth( col2, 70 )
	wxListCtrl_InsertColumn( mylist, 1, col2 )
	
	
	wxWindow_Enable( mylist, FALSE )
	
	delbut = wxButton( )
	wxButton_Create( delbut, wx_frame, -1, "Delete", wxSize( 60, 250 ), wxSize( -1, -1 ), 0, 0, 0 )
	wxWindow_Enable( delbut, FALSE )
	
	evntbut = wxButton( )
	wxButton_Create( evntbut, wx_frame, -1, "Events", wxSize( 60, 272 ), wxSize( -1, -1 ), 0, 0, 0 )
	wxWindow_Enable( evntbut, FALSE )
	
	updbut = wxButton( )
	wxButton_Create( updbut, wx_frame, -1, "Update", wxSize( 60, 294 ), wxSize( -1, -1 ), 0, 0, 0 )
	wxWindow_Enable( updbut, FALSE )
	
	wxEvtHandler_proxy( delbut, Cast(EventListener, @delbut_clicked) )
	wxEvtHandler_Connect( delbut, wxEvent_EVT_COMMAND_BUTTON_CLICKED(), -1, -1, 0 )
	
	wxEvtHandler_proxy( evntbut, Cast(EventListener, @evntbut_clicked) )
	wxEvtHandler_Connect( evntbut, wxEvent_EVT_COMMAND_BUTTON_CLICKED(), -1, -1, 0 )
	
	wxEvtHandler_proxy( updbut, Cast(EventListener, @propevent) )
	wxEvtHandler_Connect( updbut, wxEvent_EVT_COMMAND_BUTTON_CLICKED(), -1, -1, 0 )
	
	
	'Icon
	Dim As wxIcon Ptr frameIcon = wxIcon( )
	Dim As wxBitmap Ptr iconImage = wxBitmap( )
	wxBitmap_LoadFile( iconImage, "images/icon.ico", wxBITMAP_TYPE_ICO )
	wxIcon_CopyFromBitmap( frameIcon, iconImage )
	wxFrame_SetIcon( wx_frame, frameIcon )
	wxFrame_SetIcon( proj, frameIcon )
	
	
	
	'Show current tool
	toolText = wxTextCtrl( )
	wxTextCtrl_Create( toolText, wx_frame, -1, "No tool selected", wxSize( 1, -1 ), wxSize( 25 * 8 - 10, -1 ), wxTE_READONLY Or wxTE_CENTRE, 0, 0 )
	curtool = tool_notool
	
End Sub

''
'' Inits the grid-background
''
Sub init_grid( )
	
	gridparts( 0 ) = wxImage_ctorByName( "images/sq1.bmp", wxBITMAP_TYPE_BMP )
	gridparts( 1 ) = wxImage_ctorByName( "images/sq2.bmp", wxBITMAP_TYPE_BMP )
	gridparts( 2 ) = wxImage_ctorByName( "images/sq3.bmp", wxBITMAP_TYPE_BMP )
	gridparts( 3 ) = wxImage_ctorByName( "images/sq4.bmp", wxBITMAP_TYPE_BMP )
	redrawgrid( TRUE )
	
End Sub

''
'' Inits all inits
''
Sub init( )
	
	init_list( )
	
	init_menus( )
	init_tools( )
	initpropdiag( )
	
	init_grid( )
	
End Sub
