Listview.GetSelection strangeness

Discuss GUI programming with the RapaGUI plugin here
Post Reply
bitRocky
Posts: 153
Joined: Fri Nov 14, 2014 6:01 pm

Listview.GetSelection strangeness

Post by bitRocky »

I have a multiselect listview and encounter some strangeness.
If I click on an entry for the first time, I get the correct entry from Listview.GetSelection, but if I then click another entry, GetSelection returns the previously clicked entry and not the entry I currently clicked on!?

If I start to select multiple entries, GetSelection returns the correct entries.
But if I then click on another entry (so all selected entries will be deselected), GetSelection returns the previously selected entries.

I know that GetSelection doesn't return the active entry if multiple entries are selected.

If I browse through the listiview by cursor keys and select/deselect some entries everything is returned correct.

Here is short example:

Code: Select all

@REQUIRE "RapaGUI"
; just some aliases
set = moai.set
get = moai.get
dom = moai.DoMethod

Function p_Active()
	t = moai.DoMethod("lv", "GetSelection")
	f$ = ""
	DebugPrint("ListItems(t) = "..ListItems(t))
	DebugPrint("t[0]     = "..IIf(ListItems(t) > 0, t[0], -1)..", isSel = "..dom("lv", "Select", t[0], "Ask"))
	DebugPrint("active   = "..get("lv", "active"))
	For Local i=0 To ListItems(t)-1
		DebugPrint("t["..i.."] = "..t[i])
		f$ = f$..dom("lv", "GetEntry", t[i])
	Next
	;Textentry
	set("strTest", "text", f$)
EndFunction

moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application>
	<window title="Test program" width="300">
		<vgroup>
			<listview id="lv" notify="active" multiselect="true" >
				<column>
					<item>0</item>
					<item>1</item>
					<item>2</item>
					<item>3</item>
					<item>4</item>
					<item>5</item>
					<item>6</item>
					<item>7</item>
					<item>8</item>
					<item>9</item>
				</column>
			</listview>
			<TextEntry id="strTest" />
		</vgroup>
	</window>
</application>
]])

InstallEventHandler({
	RapaGUI = Function(msg) If msg.id = "lv" Then Return(p_Active()) EndFunction
})

Repeat
WaitEvent
Forever
plouf
Posts: 728
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Listview.GetSelection strangeness

Post by plouf »

if i understand look ok to me check video ->https://limewire.com/d/DFb7n#AdgL7qVd19

p.s what os ?
Christos
bitRocky
Posts: 153
Joined: Fri Nov 14, 2014 6:01 pm

Re: Listview.GetSelection strangeness

Post by bitRocky »

Yeah, yours look correct.
I'm using MorphOS, seems to be only there
User avatar
airsoftsoftwair
Posts: 5975
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Listview.GetSelection strangeness

Post by airsoftsoftwair »

bitRocky wrote: Thu May 28, 2026 10:33 am I'm using MorphOS, seems to be only there
Actually the behaviour will show on all systems that use MUI. I think this might be a MUI bug because RapaGUI pretty much just returns what MUI returns. MUI's multi-select mode in listviews is a little bit weird. I think if you just click on an entry in a multi-select listview it's not really selected. In order to select an entry in a multi-select listview, you have to shift-click on it. Otherwise it will be "active" but not "selected" AFAIR. MUI is the only GUI backend which has this difference between "active" and "selected" entries but MUIM_List_NextSelected clearly says that in case there is no selected but just an active entry, the active one will be returned:
Iterate through the selected entries of a list. This method steps through the contents of a (multi select) list and returns every entry that is currently selected. When no entry is selected, but an entry is active, only the active entry will be returned.
But apparently that doesn't happen for some reason...
User avatar
airsoftsoftwair
Posts: 5975
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Listview.GetSelection strangeness

Post by airsoftsoftwair »

Thinking about it further I believe it's a MUI issue that RapaGUI cannot really work around. The problem is that you call Listview.GetSelection inside the callback for Listview.Active and apparently at that time MUI hasn't updated its internal states yet which means that Listview.GetSelection returns wrong values. To work around it, just make sure that you don't call Listview.GetSelection from within the Listview.Active event handler but after it. This can easily be achieved by just pushing the callback onto the event stack by using RunCallback(), e.g. like this:

Code: Select all

@REQUIRE "RapaGUI"
; just some aliases
set = moai.set
get = moai.get
dom = moai.DoMethod

Function p_Active()
	t = moai.DoMethod("lv", "GetSelection")
	f$ = ""
	DebugPrint("ListItems(t) = "..ListItems(t))
	DebugPrint("t[0]     = "..IIf(ListItems(t) > 0, t[0], -1)..", isSel = "..dom("lv", "Select", t[0], "Ask"))
	DebugPrint("active   = "..get("lv", "active"))
	For Local i=0 To ListItems(t)-1
		DebugPrint("t["..i.."] = "..t[i])
		f$ = f$..dom("lv", "GetEntry", t[i])
	Next
	;Textentry
	set("strTest", "text", f$)
EndFunction

moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application>
	<window title="Test program" width="300">
		<vgroup>
			<listview id="lv" notify="active" multiselect="true" >
				<column>
					<item>0</item>
					<item>1</item>
					<item>2</item>
					<item>3</item>
					<item>4</item>
					<item>5</item>
					<item>6</item>
					<item>7</item>
					<item>8</item>
					<item>9</item>
				</column>
			</listview>
			<TextEntry id="strTest" />
		</vgroup>
	</window>
</application>
]])

InstallEventHandler({
	RapaGUI = Function(msg) If msg.id = "lv" Then RunCallback(p_Active) EndFunction
})

Repeat
WaitEvent
Forever
When done like this, everything works fine here.
bitRocky
Posts: 153
Joined: Fri Nov 14, 2014 6:01 pm

Re: Listview.GetSelection strangeness

Post by bitRocky »

Cool, thanks!
I'll try it.
Post Reply