Page 1 of 1

[5.60] ListIconGadget Events and Actions

Posted: Fri Jul 07, 2017 7:28 am
by Yuri_D
Hello!

I faced two issues working with this gadget, maybe this is a normal behavior but...

1 - Left click on empty space of this gadget - single click removes selection marks but the #PB_EventType_LeftClick event is not triggering, it triggers only by Double Click

2 - When SetGadgetItemState() or SetGadgetState() are used to select items, the selected item state changes but it stays not marked in the list.

BRG
Yury

Re: [5.60] ListIconGadget Events and Actions

Posted: Fri Jul 07, 2017 10:09 am
by IdeasVacuum
Hello Yuri_D

Can you let us know what OS you are on and post the smallest working code snippet possible that demonstrates these two issues? ListIcon is a very popular gadget, somebody will most likely have a solution.

Re: [5.60] ListIconGadget Events and Actions

Posted: Fri Jul 07, 2017 2:41 pm
by Yuri_D
Hello!

I'm on Windows'7

Here the sample:

Code: Select all

;- [ Compiler Directives ]
EnableExplicit

;- [ Definitions ]
Enumeration FormWindow
  #frmMain
EndEnumeration

Enumeration FormGadget
  #btnSelectAll
  #btnExit
  #btnCheck
  #licFilesList
EndEnumeration

Define.i iEvent, iEventWindow, iEventGadget, iEventType, iEventMenu, iEventQuit ; Event variables
Define.i i

;- [ Procedures ]
Procedure OpenfrmMain(x = 0, y = 0, width = 400, height = 250)
  OpenWindow(#frmMain, x, y, width, height, "", #PB_Window_ScreenCentered)
  ButtonGadget(#btnSelectAll, 65, 220, 135, 25, "Select All")
  ButtonGadget(#btnExit, 345, 220, 50, 25, "Exit", #PB_Button_Default)
  ButtonGadget(#btnCheck, 205, 220, 135, 25, "Check Selection")
  ListIconGadget(#licFilesList, 5, 5, 390, 185, "Test", 370, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
EndProcedure

Procedure GetLicState( _iEventGadget.i)
  
  Protected.i _i
  
  Debug "==="
  
  For _i =0  To CountGadgetItems( _iEventGadget) -1
    Debug GetGadgetItemState( _iEventGadget, _i)
  Next
EndProcedure

;- -=[ Main ]=-
OpenfrmMain()

For i=0 To 4
  AddGadgetItem( #licFilesList, -1, "Test"+ i)
Next

Repeat ; Processing loop
  iEvent        = WindowEvent()
  iEventWindow  = EventWindow()
  iEventGadget  = EventGadget()
  iEventType    = EventType()
  iEventMenu    = EventMenu()
  
  Select iEvent
    Case #PB_Event_CloseWindow
      End
      
    Case #PB_Event_Gadget
      
      Select iEventType
        Case #PB_EventType_LeftClick
          
          Select iEventGadget
            Case #licFilesList
              GetLicState( iEventGadget)
              
          EndSelect
      EndSelect
      
      Select iEventGadget ; Gadgets w/o Event Type
        Case #btnSelectAll
          For i =0  To CountGadgetItems( #licFilesList) -1
            
            SetGadgetItemState( #licFilesList, i, #PB_ListIcon_Selected)
            
          Next
          GetLicState( #licFilesList)
          
        Case #btnCheck
          GetLicState( #licFilesList)
          
        Case #btnExit
          Break
          
      EndSelect
  EndSelect
ForEver

;- -=[ End ]=-
End

Re: [5.60] ListIconGadget Events and Actions

Posted: Fri Jul 07, 2017 2:41 pm
by Yuri_D
Hello!

I'm on Windows'7

Here the sample:

Code: Select all

;- [ Compiler Directives ]
EnableExplicit

;- [ Definitions ]
Enumeration FormWindow
  #frmMain
EndEnumeration

Enumeration FormGadget
  #btnSelectAll
  #btnExit
  #btnCheck
  #licFilesList
EndEnumeration

Define.i iEvent, iEventWindow, iEventGadget, iEventType, iEventMenu, iEventQuit ; Event variables
Define.i i

;- [ Procedures ]
Procedure OpenfrmMain(x = 0, y = 0, width = 400, height = 250)
  OpenWindow(#frmMain, x, y, width, height, "", #PB_Window_ScreenCentered)
  ButtonGadget(#btnSelectAll, 65, 220, 135, 25, "Select All")
  ButtonGadget(#btnExit, 345, 220, 50, 25, "Exit", #PB_Button_Default)
  ButtonGadget(#btnCheck, 205, 220, 135, 25, "Check Selection")
  ListIconGadget(#licFilesList, 5, 5, 390, 185, "Test", 370, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
EndProcedure

Procedure GetLicState( _iEventGadget.i)
  
  Protected.i _i
  
  Debug "==="
  
  For _i =0  To CountGadgetItems( _iEventGadget) -1
    Debug GetGadgetItemState( _iEventGadget, _i)
  Next
EndProcedure

;- -=[ Main ]=-
OpenfrmMain()

For i=0 To 4
  AddGadgetItem( #licFilesList, -1, "Test"+ i)
Next

Repeat ; Processing loop
  iEvent        = WindowEvent()
  iEventWindow  = EventWindow()
  iEventGadget  = EventGadget()
  iEventType    = EventType()
  iEventMenu    = EventMenu()
  
  Select iEvent
    Case #PB_Event_CloseWindow
      End
      
    Case #PB_Event_Gadget
      
      Select iEventType
        Case #PB_EventType_LeftClick
          
          Select iEventGadget
            Case #licFilesList
              GetLicState( iEventGadget)
              
          EndSelect
      EndSelect
      
      Select iEventGadget ; Gadgets w/o Event Type
        Case #btnSelectAll
          For i =0  To CountGadgetItems( #licFilesList) -1
            SetGadgetItemState( #licFilesList, i, #PB_ListIcon_Selected)
          Next
          SetActiveGadget( #licFilesList) ; <<<<<<<<<<<<<<< I forgot to make it active so the selection becomes invisible on my screen...
          GetLicState( #licFilesList)
          
        Case #btnCheck
          GetLicState( #licFilesList)
          
        Case #btnExit
          Break
          
      EndSelect
  EndSelect
ForEver

;- -=[ End ]=-
End

Re: [5.60] ListIconGadget Events and Actions

Posted: Fri Jul 07, 2017 3:34 pm
by IdeasVacuum
:shock: Your 2nd code snippet is working well here - Win7 x86, PB5.6

Re: [5.60] ListIconGadget Events and Actions

Posted: Fri Jul 07, 2017 4:17 pm
by Yuri_D
Try a single click on an empty space of ListIcon - no event will be triggered, try double click then)
And to get selection colored you need to keep focus on this gadget, in other case it will fade out and can't be seen on some screens (like in my case) even when a #PB_ListIcon_AlwaysShowSelection flag is used... I can repaint them myself but for this I need to have the above event working even on empty rows.

Re: [5.60] ListIconGadget Events and Actions

Posted: Fri Jul 07, 2017 5:54 pm
by IdeasVacuum
Yeah, #PB_ListIcon_AlwaysShowSelection is working - the row highlight colour is not maintained, it is replaced by another. The default on my PC is a Blue highlight, Light Grey selection. It might be that you don't see the Light Grey because of the brightness level of your monitor?

Concerning clicking the gadget but not a row, that seems to be normal behaviour. If it is not what you want, you can probably work around it using API and a WindowCallBack.

Re: [5.60] ListIconGadget Events and Actions

Posted: Sat Jul 08, 2017 12:16 pm
by Yuri_D
Yes, the selection visibility problem is because of the gray color - many customers can't see it.
Regarding the click event - I don't think that one-click event triggering by a double-click is a normal behavior and I don't want to use API to keep OS flexibility.

Re: [5.60] ListIconGadget Events and Actions

Posted: Tue Jul 11, 2017 10:38 am
by Fred
It's the intended behaviour, clicks are only trigered on items