Page 1 of 1

ListIconGadget/GetGadgetState(#Gadget)

Posted: Thu Oct 22, 2015 4:47 pm
by Lima
In ListIconGadget, with Get Gadget State (#Gadget) You can know the line that the user clicked.
And knowing which column the user clicked? It's possible?
thank you

Re: ListIconGadget/GetGadgetState(#Gadget)

Posted: Thu Oct 22, 2015 6:03 pm
by RSBasic

Re: ListIconGadget/GetGadgetState(#Gadget)

Posted: Thu Oct 22, 2015 11:15 pm
by Bisonte
Or a combination of all, with PB behaviour...

3 new EventTypes :

Code: Select all

Enumeration #PB_EventType_FirstCustomValue
  #PB_EventType_HeaderChanged
  #PB_EventType_HeaderClicked
  #PB_EventType_ItemSelect
EndEnumeration
So you can check in your event-loop with

Code: Select all

EventListIconColumn()
EventListIconItem()
which item or column is create the event.
-1 means: nothing is selected. (like GetGadgetState() of a ListIconGadget() if no Item is selected)

for more see source (demo included) and ask ;)

Code: Select all

;: ============================================================================
;: #
;: #  ListIconExtras - LIE.pbi
;: #  
;: #  Windows only
;: #  George Bisonte
;: ============================================================================
;: 
EnableExplicit
;: 
;: Subclassing 
;: (edel : http://www.purebasic.fr/german/viewtopic.php?p=332497#p332497)
;{
Import ""
  GetProcAddress(hmod, s.p-ascii)
EndImport
;: 
Prototype pSetWindowSubclass(hWnd, *Proc, *ID, *RefData)
Prototype pDefSubclassProc(hWnd, uMsg, wParam, lParam)
Prototype pRemoveWindowSubclass(hWnd, *Proc, *ID)
Prototype pGetWindowSubclass(hWnd, *Proc, *ID, *RefData)
;: 
Procedure SetWindowSubclass(hWnd, *Proc, *ID, *RefData)
  Protected Comctl32 = GetModuleHandle_("Comctl32.dll")   
  Protected func.pSetWindowSubclass = GetProcAddress(Comctl32, "SetWindowSubclass")
  ProcedureReturn func(hWnd, *Proc, *Id, *RefData)
EndProcedure
Procedure DefSubclassProc(hWnd, uMsg, wParam, lParam)
  Protected Comctl32 = GetModuleHandle_("Comctl32.dll")
  Protected func.pDefSubclassProc = GetProcAddress(Comctl32, "DefSubclassProc")
  ProcedureReturn func(hWnd, uMsg, wParam, lParam)
EndProcedure
Procedure RemoveWindowSubclass(hWnd, *Proc, *ID)
  Protected Comctl32 = GetModuleHandle_("Comctl32.dll")
  Protected func.pRemoveWindowSubclass = GetProcAddress(Comctl32, "RemoveWindowSubclass")
  ProcedureReturn func(hWnd, *Proc, *Id)
EndProcedure
Procedure GetWindowSubclass(hWnd, *Proc, *ID, *RefData)
  Protected Comctl32 = GetModuleHandle_("Comctl32.dll")
  Protected func.pGetWindowSubclass = GetProcAddress(Comctl32, "GetWindowSubclass")
  ProcedureReturn func(hWnd, *Proc, *Id, *RefData)
EndProcedure
;}
;: ============================================================================
;: 
;: ListIconGadgetExtras
;: 
;: New EventTypes !
;: 
Enumeration #PB_EventType_FirstCustomValue
  #PB_EventType_HeaderChanged
  #PB_EventType_HeaderClicked
  #PB_EventType_ItemSelect
EndEnumeration
;: 
Structure struct_ListIconExtras_Datas
  Window.i
  Gadget.i
  Column.i
  Item.i
EndStructure
;: 
Procedure SubClass_ListIcon(hWnd, uMsg, wparam, lParam, id, *refData.struct_ListIconExtras_Datas)
  
  Protected *HD_NOTIFY.HD_NOTIFY
  Protected hitinfo.LVHITTESTINFO
  
  Select uMsg
    Case #WM_NCDESTROY
      RemoveWindowSubclass(hWnd, @SubClass_ListIcon(), id)
      If *refData : FreeMemory(*refData) : EndIf
      
    Case #WM_LBUTTONDOWN, #WM_RBUTTONDOWN
      hitinfo\pt\x = lparam &$FFFF ; lo order word of lparam
      hitinfo\pt\y = lparam>>16    ; hi order word of lparam
      SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, @hitInfo)
      If *refData
        If IsWindow(*refData\Window) And IsGadget(*refData\Gadget)
          *refData\Column = hitinfo\iSubItem
          *refData\Item   = hitinfo\iItem
          PostEvent(#PB_Event_Gadget, *refData\Window, *refData\Gadget, #PB_EventType_ItemSelect, *refData)
        EndIf
      EndIf
      
    Case #WM_NOTIFY
      *HD_NOTIFY = lParam
      Select *HD_NOTIFY\hdr\code
        Case #HDN_ITEMCHANGED
          If *refData
            If IsWindow(*refData\Window) And IsGadget(*refData\Gadget)
              *refData\Column = *HD_NOTIFY\iItem
              *refData\Item   = -1
              PostEvent(#PB_Event_Gadget, *refData\Window, *refData\Gadget, #PB_EventType_HeaderChanged, *refData)
            EndIf
          EndIf
          
        Case #HDN_ITEMCLICK
          If *refData
            If IsWindow(*refData\Window) And IsGadget(*refData\Gadget)
              *refData\Column = *HD_NOTIFY\iItem
              *refData\Item   = -1
              PostEvent(#PB_Event_Gadget, *refData\Window, *refData\Gadget, #PB_EventType_HeaderClicked, *refData)                
            EndIf
          EndIf
          
      EndSelect
      
  EndSelect
  
  ProcedureReturn DefSubclassProc(hWnd, uMsg, wParam, lParam)
  
EndProcedure
Procedure EventListIconItem()
  
  Protected *p.struct_ListIconExtras_Datas
  Protected Result = -1
  
  If EventType() = #PB_EventType_ItemSelect
    *p = EventData()
    If *p
      Result = *p\Item
    EndIf
  EndIf
  ProcedureReturn Result
  
EndProcedure
Procedure EventListIconColumn()
  
  Protected *p.struct_ListIconExtras_Datas
  Protected Result = -1
  
  Select EventType()
    Case #PB_EventType_HeaderChanged, #PB_EventType_HeaderClicked, #PB_EventType_ItemSelect
      
      *p = EventData()
      If *p
        Result = *p\Column
      EndIf
      
  EndSelect
  
  ProcedureReturn Result
  
EndProcedure 
;: 
Procedure EnableListIconExtras(Window, Gadget)
  
  Protected *p.struct_ListIconExtras_Datas 
  Protected Result = #False
  
  If IsWindow(Window) And IsGadget(Gadget)
    If GadgetType(Gadget) = #PB_GadgetType_ListIcon
      *p = AllocateMemory(SizeOf(struct_ListIconExtras_Datas))
      If *p
        *p\Window = Window
        *p\Gadget = Gadget
        *p\Column = -1
        *p\Item   = -1
        SetWindowSubclass(GadgetID(Gadget), @SubClass_ListIcon(), 0, *p)
        Result = #True  
      EndIf
    EndIf
  EndIf
  
  ProcedureReturn Result
  
EndProcedure
Procedure DisableListIconRedraw(Gadget, State = #True)
  
  If IsGadget(Gadget)
    If GadgetType(Gadget) = #PB_GadgetType_ListIcon
      If State
        SendMessage_(GadgetID(Gadget), #WM_SETREDRAW, #Null, #Null)
      Else
        SendMessage_(GadgetID(Gadget), #WM_SETREDRAW, 1, #Null)
      EndIf
    EndIf
  EndIf
  
EndProcedure
;: 
DisableExplicit
;: 
;: ============================================================================
;: 
;: - Demo
;: 

OpenWindow(10, 0, 0, 640, 480, "Test", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)

ListIconGadget(2, 10, 10, 620, 460, "Column 0", 120, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(2, 1, "Column 1", 100)
AddGadgetColumn(2, 2, "Column 2", 100)
DisableListIconRedraw(2)
For i = 0 To 10000
  AddGadgetItem(2, -1, "Nr. "+Str(i) + Chr(10) + Str(i) + Chr(10) + Str(i))
Next i
DisableListIconRedraw(2, #False)

EnableListIconExtras(10, 2)

Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 2
          If EventType() = #PB_EventType_HeaderClicked
            
            Debug "Click on header"
            Debug "Column " + EventListIconColumn()
            
          EndIf
          If EventType() = #PB_EventType_ItemSelect
            
            Debug "click on item"
            Debug "Column " + EventListIconColumn()
            Debug "Item " + EventListIconItem()
            
          EndIf
          If EventType() = #PB_EventType_HeaderChanged
            
            Debug "resize headerwith"
            Debug "Header " + EventListIconColumn()
            Debug "Size " + GetGadgetItemAttribute(2, #PB_Ignore, #PB_ListIcon_ColumnWidth, EventListIconColumn())
            
          EndIf          
      EndSelect
      
  EndSelect
  
ForEver

Re: ListIconGadget/GetGadgetState(#Gadget)

Posted: Mon Oct 26, 2015 11:13 am
by Lima
Thank you for your help.
But I use the demo version that has some limitations.
I thought that the PB should give information in an easy, immediate, about the 'cell' clicked. I thought that this should be obvio.But not by the way .
I do these considerations because I'm not a professional programmer.
My daily work does not include the programming. I like to program, I have some programs in another language, and it seems to me interesting the PB, I try to evaluate if it gives me what I need.

I thank you again.

Re: ListIconGadget/GetGadgetState(#Gadget)

Posted: Wed Oct 28, 2015 11:40 am
by infratec
Hi,

here I used an API free version which you can also use with the demo.
http://purebasic.fr/english/viewtopic.php?f=12&t=61261

But see the limitations which RASHAD pointed out.

Bernd

Re: ListIconGadget/GetGadgetState(#Gadget)

Posted: Fri Oct 30, 2015 4:06 pm
by Lima
It seems to be a solution.I will test and adapt to what I want.

Another question on 'ListIconGadget': it is possible to have a column with a different background color, with a different font size ... ?

Thank you very much for your help.

Re: ListIconGadget/GetGadgetState(#Gadget)

Posted: Fri Oct 30, 2015 5:00 pm
by RSBasic