ListIcon messages help needed

Everything else that doesn't fall into one of the other PB categories.
SpiritCode
New User
New User
Posts: 8
Joined: Sat Oct 20, 2018 10:13 pm
Location: Montreal, Quebec, Canada

ListIcon messages help needed

Post by SpiritCode »

I ran my little program in debug mode in order to test the list icon gadget messages.
When I left click it works fine I'm getting a single message but when I double click I am getting 3 messages: two left click an one double click
Is this normal or I made a mistake in my code ???
The problem is I have to detect both single and double clicks, generating separate actions for both.

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0

Global Canvas_0, ListIcon_0, Panel_0, Font_0
Global p_select=0, last_panel_no.b=10, panel_no=0, icon_select


Procedure OpenWindow_0(x = 0, y = 0, width = 1000, height = 570)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "EmLab", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  Canvas_0 = CanvasGadget(#PB_Any, 0, 0, 1000, 540,#PB_Canvas_Container)
  SetGadgetColor(Canvas_0, #PB_Gadget_BackColor, RGB(200,200,200))
  Font_0 = LoadFont(#PB_Any, "Segoe UI Semibold", 10)
     
  ListIcon_0 = ListIconGadget(#PB_Any, WindowWidth(Window_0)-200, 30, 200, 540, "", 100, #PB_ListIcon_GridLines)
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\cdplayer.ico")     
    SetGadgetAttribute(ListIcon_0, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    AddGadgetItem(ListIcon_0, 1, "Image 1", ImageID(0))
    AddGadgetItem(ListIcon_0, 2, "Image 2", ImageID(0))
    AddGadgetItem(ListIcon_0, 3, "Image 3", ImageID(0))
    ;Debug GetGadgetFont(ListIcon_0)
  EndIf 
  EnableGadgetDrop(Canvas_0, #PB_Drop_Text,  #PB_Drag_Copy)
   
  Panel_0 = PanelGadget(#PB_Any, WindowWidth(Window_0)-200, 5, 200, 25)
  SetGadgetFont(Panel_0, FontID(Font_0))
  AddGadgetItem(Panel_0, 1, "Item1")
  AddGadgetItem(Panel_0, 2, "Item2")
  AddGadgetItem(Panel_0, 3, "Item3")
  AddGadgetItem(Panel_0, -1, "Item4")
  AddGadgetItem(Panel_0, -1, "Misc")
  SetGadgetColor(Panel_0, #PB_Gadget_BackColor, RGBA(196, 217, 254, 255))
  EndProcedure
  
  Procedure Fill_Icons()
    SetGadgetAttribute(ListIcon_0, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    AddGadgetItem(ListIcon_0, 1, "Image 1", ImageID(0))
    AddGadgetItem(ListIcon_0, 2, "Image 2", ImageID(0))
    AddGadgetItem(ListIcon_0, 3, "Image 3", ImageID(0))
    ;Debug GetGadgetFont(ListIcon_0)
  EndProcedure
 
    
  
  
Procedure SizeWindowHandler()
  Debug "Evènement - Redimensionnement- de la fenêtre #" + EventWindow()
    
  ; Redimensionne le gadget pour l'adapter aux nouvelles dimensions de la fenêtre
  ;
  ResizeGadget(Canvas_0, #PB_Ignore, #PB_Ignore, WindowWidth(Window_0), WindowHeight(Window_0)-30)
  ResizeGadget(ListIcon_0, WindowWidth(Window_0)-200, #PB_Ignore, #PB_Ignore, WindowHeight(Window_0)-30)
  ResizeGadget(Panel_0, WindowWidth(Window_0)-200, #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndProcedure


Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

   ; Case #PB_Event_Menu
   ;   Select EventMenu()
    ;  EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case Canvas_0
          Select EventType()
            Case #PB_EventType_MouseWheel
              Debug "Souris Wheel" 
              Debug GetGadgetAttribute(Canvas_0, #PB_Canvas_WheelDelta)
              If GetGadgetAttribute(Canvas_0, #PB_Canvas_MouseX) > WindowWidth(Window_0)-200 ; dans la zone du panel
               ; Debug "Allo"
                p_select - GetGadgetAttribute(Canvas_0, #PB_Canvas_WheelDelta)
                If(p_select < 0)
                  p_select = 0
                Else
                  If p_select > 4
                    p_select = 4
                  EndIf
                EndIf
                
                panel_no = p_select
                SetGadgetState(Panel_0, p_select)
                Debug "Selection: " + panel_no
                If GetGadgetState(Panel_0) <> 0
                  ClearGadgetItems(ListIcon_0)
                Else
                  If CountGadgetItems(ListIcon_0) = 0
                    Fill_Icons()
                    ;last_panel_no = panel_no
                  EndIf
                EndIf
              EndIf
              
              
              ;Debug GetActiveGadget()
          EndSelect
          
        Case Panel_0
          If EventType() = #PB_EventType_Change
            panel_no = GetGadgetState(Panel_0)
            Debug "Panel Change " + panel_no
            If panel_no <> 0
              ClearGadgetItems(ListIcon_0)
            Else
              If CountGadgetItems(ListIcon_0) = 0
                Fill_Icons()
              EndIf
            EndIf
          EndIf
          
          
        Case ListIcon_0
          If EventType() = #PB_EventType_LeftDoubleClick
            Debug "Left doubleclick"
            If GetGadgetState(ListIcon_0) = -1
              Debug "No selection"
            Else
              icon_select = GetGadgetState(ListIcon_0)
              Debug "icon selection: " + icon_select + " " + GetGadgetItemText(ListIcon_0, icon_select)
            EndIf
          Else
          
          If EventType() = #PB_EventType_LeftClick
            Debug "Left click"
            If GetGadgetState(ListIcon_0) = -1
              Debug "No selection"
            Else
              icon_select = GetGadgetState(ListIcon_0)
              Debug "icon selection: " + icon_select + " " + GetGadgetItemText(ListIcon_0, icon_select)
            EndIf
          EndIf
        EndIf
        
         
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

;START
OpenWindow_0()
BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler())

Repeat
  event = WaitWindowEvent(1)
  If Not Window_0_Events(event) 
    End
  EndIf
ForEver  
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: ListIcon messages help needed

Post by PBJim »

SpiritCode wrote: Sun Nov 03, 2024 5:31 pm I ran my little program in debug mode in order to test the list icon gadget messages.
When I left click it works fine I'm getting a single message but when I double click I am getting 3 messages: two left click an one double click
Is this normal or I made a mistake in my code ???
The problem is I have to detect both single and double clicks, generating separate actions for both.
Hi SpiritCode,

Welcome to the forum. Yes, that's normal. I happen to be doing something with ListIconGadgets through a window callback and I get similar.

If you have a specific function that you need to carry out on a single-click, you need to wait briefly to see if a double-click follows it. There's a thread here, probably close to what you're doing. Look for the link in Netmaestro's post, within that thread, and you'll see a good example there.

viewtopic.php?t=25341
User avatar
HeX0R
Addict
Addict
Posts: 1204
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: ListIcon messages help needed

Post by HeX0R »

Do you really need a signal on #PB_EventType_LeftClick?
I'd better replace it by #PB_EventType_Change, because usually you don't need to know when a user clicks on an already selected item.
Single clicks on a listicon are usually only of interest, when a user changed the selected item.
SpiritCode
New User
New User
Posts: 8
Joined: Sat Oct 20, 2018 10:13 pm
Location: Montreal, Quebec, Canada

Re: ListIcon messages help needed

Post by SpiritCode »

Thank you all
HeXOR is right, I just need the #PB_EventType_Change message
gotta make sure I deselect all icons when I start.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ListIcon messages help needed

Post by jacdelad »

For deselection of all items I wouldn't rely on the messages. I would use a small loop:

Code: Select all

Count=CountGadgetItems(#MyListIcon)-1
For Counter=0 Count
  SetGadgetItemState(#MyListIcon,Counter,0)
Next
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
SpiritCode
New User
New User
Posts: 8
Joined: Sat Oct 20, 2018 10:13 pm
Location: Montreal, Quebec, Canada

Re: ListIcon messages help needed

Post by SpiritCode »

This is even shorter:

Code: Select all

SetGadgetState(ListIcon_0, -1)
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: ListIcon messages help needed

Post by BarryG »

HeX0R wrote: Mon Nov 04, 2024 10:47 amSingle clicks on a listicon are usually only of interest, when a user changed the selected item.
Maybe usually, but certainly not always. Clicking an already-selected list item can be part of an app's functionality.
Post Reply