[4.40x86b5] SetGadgetItemState() causes event

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

[4.40x86b5] SetGadgetItemState() causes event

Post by WilliamL »

If I select a line of the ListViewGadget() using SetGadgetItemState() I get a WaitWindowEvent(). In fact, it appears that I get two events the first is a #PB_Event_Gadget of the eventtype=0 (#PB_EventType_LeftClick?) then the second is another #PB_Event_Gadget with a eventtype=#PB_EventType_Change. Why does SetGadgetItemState() trigger a #PB_EventType_LeftClick?

Code: Select all

OpenWindow(0, 100, 100, 300, 200, "ListView") 
ListViewGadget(0, 100, 50, 100, 100, #PB_ListView_MultiSelect) 
AddGadgetItem(0, -1, "Item 1") 
AddGadgetItem(0, -1, "Item 2") 
AddGadgetItem(0, -1, "Item 3") 
AddGadgetItem(0, -1, "Item 4") 
SetGadgetItemState(0,1,1) ; rem out and no events!

Repeat
    event=WaitWindowEvent()
    Select event
    Case #PB_Event_Gadget
        ;assume gadget is #0
        Debug "new Event="+Str(event)+"  EventType()="+Str(EventType())
        Select EventType()
        Case #PB_EventType_Change;#PB_EventType_LeftClick;,768 ; 768 works for deselecting line
            Debug "Line clicked on = "+Str(GetGadgetState(0))
            For x=0 To 3
                Debug "  Item "+Str(x)+" = "+Str(GetGadgetItemState(0,x))
            Next
        EndSelect
    EndSelect
Until event = #PB_Event_CloseWindow
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: [4.40x86b5] SetGadgetItemState() causes event

Post by WilliamL »

Maybe it would be more to the point to tell you what I am doing.

I want to click on a listview line to 'edit' the line (closes the window) or use a menu command to highlight several lines. The way it works now, when I use the menu command, I get the highlighting ok but it is followed with 'editing' the line which closes the listview window and ruins the whole effect. As I've got it working now, I use the menu command and then after highlighting the lines I have to do While WindowEvent():Wend to keep the 'editing' from kicking-in... well, it works.

Code: Select all

OpenWindow(0, 100, 100, 300, 200, "ListView") 
ListViewGadget(0, 100, 50, 100, 100, #PB_ListView_MultiSelect) 
AddGadgetItem(0, -1, "Item 1") 
AddGadgetItem(0, -1, "Item 2") 
AddGadgetItem(0, -1, "Item 3") 
AddGadgetItem(0, -1, "Item 4") 
SetGadgetItemState(0,1,1) ; rem out and no events!

Repeat
    event=WaitWindowEvent()
    Select event
    Case #PB_Event_Gadget
        ;assume gadget is #0
        Debug "new Event="+Str(event)+"  EventType()="+Str(EventType())
        Select EventType()
        Case #PB_EventType_Change;#PB_EventType_LeftClick;,768 ; 768 works for deselecting line
            Debug "Line clicked on = "+Str(GetGadgetState(0))
            For x=0 To 3
                Debug "  Item "+Str(x)+" = "+Str(GetGadgetItemState(0,x))
            Next
        Case #PB_EventType_LeftClick
            Debug "Left click = "+Str(GetGadgetState(0))
        Case #PB_EventType_LeftDoubleClick
            Debug "Double click = "+Str(GetGadgetState(0))
        EndSelect
        Debug "____"
    EndSelect
Until event = #PB_Event_CloseWindow
(later)
I've also noticed that, if only one line is selected and you #PB_EventType_LeftDoubleClick on a line then GetGadgetState() will give the line number but if more than one line is selected then GetGadgetState() always gives a -1. It would be useful to have the #PB_EventType_LeftDoubleClick give you the line that you are clicking on.
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
Post Reply