Icon Listbox

BlitzMax Forums/MaxGUI Module/Icon Listbox

William Drescher(Posted 2008) [#1]
Is there a way to create a listbox with icons in it and the labels underneath? And is there a way for me to get which icon is selected or double-clicked?


SebHoll(Posted 2008) [#2]
I assume you mean in MaxGUI?

Is there a way to create a listbox with icons in it and the labels underneath?

Not as yet...

And is there a way for me to get which icon is selected or double-clicked?

You can do this with a standard MaxGUI listbox/treeview by processing the EVENT_GADGETSELECT and EVENT_GADGETACTION events respectively.


William Drescher(Posted 2008) [#3]
Well, right now i'm using the HTMLView gadget and just setting it to a folder for the style, but i want to be able to handle my own context menu and I would like to be able to get what icon is selected in the HTMLView.


SebHoll(Posted 2008) [#4]
I've been looking to see if it would be possible to implement such a feature into MaxGUI, and although this would be extremely easy to implement using the Windows API (through the use of the LVS_ICON window style), I can't find any information whatsoever about a similar control for Cocoa (OS X). As such, it is highly unlikely that such a style will be implemented in the future. Sorry. :-(


William Drescher(Posted 2008) [#5]
Then the question arises: Could you please tell me how to do this in Win32 with APIs?


SebHoll(Posted 2008) [#6]
Here's a quick implementation I've knocked up that should work with the new MaxGUI.Win32MaxGUIEx module only...

SuperStrict

Import MaxGUI.Win32MaxGUIEx

AppTitle = "ListBox Icon View Example"

Global wndMain:TGadget = CreateWindow( AppTitle, 100, 100, 400, 300, Null, WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS|WINDOW_RESIZABLE )
	
	Global lstItems:TGadget = CreateListBox( 0, 0, ClientWidth(wndMain), ClientHeight(wndMain), wndMain )
		SetGadgetLayout lstItems, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED
		
	Global icnToolbar:TIconStrip = LoadIconStrip( "../src/maxide/icons.PNG" )	'Let's try and steal some icons from the MaxIDE toolbar.
	
	If Not icnToolbar Then icnToolbar = LoadIconStrip( RequestFile( "Select An Icon-Strip...", "png,bmp,jpg" ) )
	If Not icnToolbar Then RuntimeError "Cannot load icon-strip!"
	
	ShowIconView( lstItems, icnToolbar )
	
	For Local i% = 0 Until icnToolbar.count
		AddGadgetItem lstItems, "Icon " + i, 0, i, "Tooltip " + i
	Next
	
	
Repeat
	Select WaitEvent()
		Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
			End
		Case EVENT_GADGETSELECT
			Print "Listbox Item Selected: " + EventData()
		Case EVENT_GADGETACTION
			Print "Listbox Item Double-Clicked: " + EventData()
	EndSelect
Forever


Function ShowIconView( pListbox:TGadget, pIconStrip:TIconStrip )
	?Win32
	Local tmpHwnd% = QueryGadget( pListbox, QUERY_HWND )
	If tmpHwnd Then
		Local tmpFlags% = GetWindowLongW( tmpHwnd, GWL_STYLE )
		tmpFlags:&~(LVS_REPORT|LVS_NOCOLUMNHEADER);tmpFlags:|LVS_ICON
		SetWindowLongW( tmpHwnd, GWL_STYLE, tmpFlags )
		If TWindowsIconStrip(pIconStrip) Then
			SendMessageW( tmpHwnd,LVM_SETIMAGELIST,LVSIL_NORMAL,TWindowsIconStrip(pIconStrip)._imagelist )
		EndIf
	EndIf
	?
EndFunction
If you replace LVS_ICON with LVS_SMALLICON in the ShowIconView() function, then you can still use SetGadgetIconStrip() to set the icon strip of the listbox.


Grisu(Posted 2008) [#7]
@Seb: See, I'm not the only one that likes Listboxes... :P