wxListCtrl

BlitzMax Modules Forums/Brucey's Modules/wxListCtrl

I have stripped back Bruceys sample ListCtrl to just the parts i want.
I am not sure why
Method InsertItemInReportView(i:Int)
needs to be in a seperate type.
anyone got a simple explanation?

cheers
glenn

'
' wxListCtrl sample
'
' From the C++ sample by Julian Smart
'
' BlitzMax port by Bruce A Henderson
'
SuperStrict

Framework wx.wxApp
Import wx.wxListCtrl
Import wx.wxFrame
Import wx.wxPanel
Import wx.wxSystemSettings
Import wx.wxMouseEvent

Const LIST_CTRL:Int = 1000

' number of items in list/report view
Const NUM_ITEMS:Int = 30

' number of items in icon/small icon view
Const NUM_ICONS:Int = 9

New MyApp.run()

Type MyApp Extends wxApp

	Method OnInit:Int()
	
		wxImage.AddHandler( New wxXPMHandler ) ' for Mac/Win32 (it is default on Linux)

		Local frame:MyFrame = MyFrame(New MyFrame.Create(, , "wxListCtrl Test"))

		frame.show()
		
		SetTopWindow(frame)
	
		Return True
	
	End Method

End Type

Type MyFrame Extends wxFrame

	Field panel:wxPanel
	Field listCtrl:MyListCtrl

	Method OnInit()
		DoConnections()
	
		If wxSystemSettings.GetScreenType() > wxSYS_SCREEN_SMALL Then
			SetSize(450, 340)
		End If

		panel = New wxPanel.Create(Self, wxID_ANY)

		RecreateList(wxLC_REPORT | wxLC_SINGLE_SEL)

	End Method
	
	Method DoConnections()

	End Method

	' recreate the list control with the New flags
	Method RecreateList(flags:Int, withText:Int = True)

		If listCtrl Then
			listCtrl.Free()
		End If

		listCtrl = MyListCtrl(New MyListCtrl.Create(panel, LIST_CTRL, ,, ,, flags | wxSUNKEN_BORDER | wxLC_EDIT_LABELS))
		
		Select flags & wxLC_MASK_TYPE
			
			Case wxLC_REPORT
				If flags & wxLC_VIRTUAL Then
				Else
					InitWithReportItems()
				End If
			
			Default
				'wxFAIL_MSG( _T("unknown listctrl mode") );
		End Select
		
		
		DoSize()
	End Method
	
	Method DoSize()

		Local w:Int, h:Int
		GetClientSize(w, h)
		Local y:Int = (2 * h) / 3
		listCtrl.SetDimensions(0, 0, w, y)

	End Method

	Method InitWithReportItems()

		' note that under MSW For SetColumnWidth() To work we need To create the
		' items with images initially even If we specify dummy image id
		Local itemCol:wxListItem = New wxListItem.Create()
		itemCol.SetText("Column 1")
		itemCol.SetImage(-1)
		listCtrl.InsertColumnItem(0, itemCol)
		
		itemCol.SetText("Column 2")
		itemCol.SetAlign(wxLIST_FORMAT_CENTRE)
		listCtrl.InsertColumnItem(1, itemCol)
		
		itemCol.SetText("Column 3")
		itemCol.SetAlign(wxLIST_FORMAT_RIGHT)
		listCtrl.InsertColumnItem(2, itemCol)
		
		' To speed up inserting we hide the control temporarily
		listCtrl.Hide()
		
		For Local i:Int = 0 Until NUM_ITEMS
			listCtrl.InsertItemInReportView(i)
		Next
		
		listCtrl.Show()
		
		' we leave all mask fields To 0 And only change the colour
		Local item:wxListItem = New wxListItem.Create()
		item.SetId(0)
		item.SetTextColour(wxRED())
		listCtrl.SetItem( item )
		
		item.SetId(2)
		item.SetTextColour(wxGREEN())
		listCtrl.SetItem( item )
		
		item.SetId(4)
		item.SetTextColour(wxLIGHT_GREY())
		item.SetFont(wxITALIC_FONT())
		item.SetBackgroundColour(wxRED())
		listCtrl.SetItem( item );
		
		listCtrl.SetTextColour(wxBLUE())
		
		listCtrl.SetColumnWidth( 0, wxLIST_AUTOSIZE )
		listCtrl.SetColumnWidth( 1, wxLIST_AUTOSIZE )
		listCtrl.SetColumnWidth( 2, wxLIST_AUTOSIZE )
		
		' Set images in columns
		listCtrl.SetItemColumnImage(1, 1, 0)
		
		Local info:wxListItem = New wxListItem.Create()
		info.SetImage(0)
		info.SetId(3)
		info.SetColumn(2)
		listCtrl.SetItem(info)
		
		' test SetItemFont too
		listCtrl.SetItemFont(0, wxITALIC_FONT())
	End Method
End Type



Type MyListCtrl Extends wxListCtrl

	Method OnInit()
	End Method

	Method InsertItemInReportView(i:Int)
		Local buf:String = "This is item " + i
		Local tmp:Int = InsertImageStringItem(i, buf, 0)
		
		buf = "Col 1, item " + i
		SetStringItem(tmp, 1, buf)
		
		buf = "Item " + i + " in column 2"
		SetStringItem(tmp, 2, buf)
	End Method

End Type