Event click on ListIconGadget-Header
Event click on ListIconGadget-Header
How I can catch a click on the header fields of a ListIconGadget?
I found solution for the old version of the Mac implementation in PB 5.x only.
Thanks!
I found solution for the old version of the Mac implementation in PB 5.x only.
Thanks!
Re: Event click on ListIconGadget-Header
Code: Select all
EnableExplicit
#WindowID = 0
Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
ProcedureC WillDisplayCell(Object.I, Selector.I, TableView.I, Cell.I, *Column,
Row.I)
Protected Column.I
Protected CellText.S
Protected ListIconID.I
ListIconID = CocoaMessage(0, TableView, "tag")
Column = CocoaMessage(0, CocoaMessage(0, TableView, "tableColumns"),
"indexOfObject:", *Column)
CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)
CellText = GetGadgetItemText(ListIconID, Row, Column)
CocoaMessage(0, Cell, "setStringValue:$", @CellText)
EndProcedure
ProcedureC ColumnHeaderClickCallback(Object.I, Selector.I, TableView.I,
*Column)
Protected ClickedHeaderColumn.I
Protected ListIconID.I = CocoaMessage(0, TableView, "tag")
ClickedHeaderColumn = Val(PeekS(CocoaMessage(0,
CocoaMessage(0, *Column, "identifier"),
"UTF8String"), -1, #PB_UTF8))
PostEvent(#PB_Event_Gadget, #WindowID, ListIconID,
#PB_EventType_LeftClick, ClickedHeaderColumn + 1)
EndProcedure
OpenWindow(#WindowID, 200, 100, 430, 122, "Detect left click on header cell")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Name", 110)
AddGadgetColumn(0, 1, "Address",
GadgetWidth(0) - GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth) - 8)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ +
"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+ #LF$ +
"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ +
"321 Logo Drive, Mouse House, Downtown")
class_addMethod_(DelegateClass,
sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"),
@WillDisplayCell(), "v@:@@@@")
class_addMethod_(DelegateClass,
sel_registerName_("tableView:didClickTableColumn:"),
@ColumnHeaderClickCallback(), "v@:@@")
CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_LeftClick
If EventData()
Debug "Left click on header of column " + Str(EventData() - 1)
Else
Debug "Left click on row " + Str(GetGadgetState(0))
EndIf
EndIf
EndSelect
ForEver
Re: Event click on ListIconGadget-Header
Thanks, but
1. it crashes in combination with icons. I added an icon to the last entry:
LoadImage(0, ....)
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ + "321 Logo Drive, Mouse House, Downtown", ImageID(0))
2. it changes the vertical alignment of the texts. I don't know why...
In the example below, the left one is with "setDelegate" (bottom aligned texts), the right one without (top aligned texts). Strange. Why the texts are not centered aligned in both cases?
1. it crashes in combination with icons. I added an icon to the last entry:
LoadImage(0, ....)
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ + "321 Logo Drive, Mouse House, Downtown", ImageID(0))
2. it changes the vertical alignment of the texts. I don't know why...
In the example below, the left one is with "setDelegate" (bottom aligned texts), the right one without (top aligned texts). Strange. Why the texts are not centered aligned in both cases?
Code: Select all
#IMG_Hide = 0
#thumb_savesize = 50
#colors_gra = $0000FF
CreateImage(#IMG_Hide, #thumb_savesize, #thumb_savesize, 24, #colors_gra)
If StartDrawing(ImageOutput(#IMG_Hide))
Circle(#thumb_savesize / 2, #thumb_savesize / 2, #thumb_savesize / 2.5, #colors_gra - $222222)
Circle(#thumb_savesize / 2, #thumb_savesize / 2, #thumb_savesize / 2.8, #colors_gra)
Box(#thumb_savesize / 2 - 3, #thumb_savesize / 2 - 16, 6, 32, #colors_gra - $222222)
StopDrawing()
EndIf
EnableExplicit
#WindowID = 0
Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
ProcedureC WillDisplayCell(Object.I, Selector.I, TableView.I, Cell.I, *Column, Row.I)
Protected Column.I
Protected CellText.S
Protected ListIconID.I
ListIconID = CocoaMessage(0, TableView, "tag")
Column = CocoaMessage(0, CocoaMessage(0, TableView, "tableColumns"), "indexOfObject:", *Column)
CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)
CellText = GetGadgetItemText(ListIconID, Row, Column)
CocoaMessage(0, Cell, "setStringValue:$", @CellText)
EndProcedure
ProcedureC ColumnHeaderClickCallback(Object.I, Selector.I, TableView.I, *Column)
Protected ClickedHeaderColumn.I
Protected ListIconID.I = CocoaMessage(0, TableView, "tag")
ClickedHeaderColumn = Val(PeekS(CocoaMessage(0,
CocoaMessage(0, *Column, "identifier"), "UTF8String"), -1, #PB_UTF8))
PostEvent(#PB_Event_Gadget, #WindowID, ListIconID, #PB_EventType_LeftClick, ClickedHeaderColumn + 1)
EndProcedure
OpenWindow(#WindowID, 200, 100, 825, 122, "Detect left click on header cell")
ListIconGadget(0, 10, 10, 400, WindowHeight(0) - 20, "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth) - 8)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+ #LF$ + "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ + "321 Logo Drive, Mouse House, Downtown")
class_addMethod_(DelegateClass, sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"), @WillDisplayCell(), "v@:@@@@")
class_addMethod_(DelegateClass, sel_registerName_("tableView:didClickTableColumn:"), @ColumnHeaderClickCallback(), "v@:@@")
CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)
ListIconGadget(1, 415, 10, 400, WindowHeight(0) - 20, "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(1, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth) - 8)
AddGadgetItem(1, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(1, -1, "Ginger Brokeit"+ #LF$ + "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(1, -1, "Didi Foundit"+ #LF$ + "321 Logo Drive, Mouse House, Downtown")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_LeftClick
If EventData()
Debug "Left click on header of column " + Str(EventData() - 1)
Else
Debug "Left click on row " + Str(GetGadgetState(0))
EndIf
EndIf
EndSelect
ForEver
Last edited by Lebostein on Wed Feb 22, 2023 6:16 pm, edited 1 time in total.
Re: Event click on ListIconGadget-Header
PB now also uses the class PBIconTextCell for the ListIconGadget. Search for it in the forum
If "CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)" is used, this PBIconTextCell methods is overwritten and no longer works. This means that there are no more icons and no more internal processing.
If "CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)" is used, this PBIconTextCell methods is overwritten and no longer works. This means that there are no more icons and no more internal processing.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Event click on ListIconGadget-Header
I had already suspected that. As soon as you want to do something with the API, do you destroy the whole PB implementation (colors, icons, ...)? This destroys the whole concept of PB...mk-soft wrote: Wed Feb 22, 2023 6:16 pm PB now also uses the class PBIconTextCell for the ListIconGadget. Search for it in the forum
If "CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)" is used, this PBIconTextCell methods is overwritten and no longer works. This means that there are no more icons and no more internal processing.
Re: Event click on ListIconGadget-Header
I have often wished Fred to switch back to the version without his own class PBIconTextCall.
Then all our methods would work again.

Then all our methods would work again.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Event click on ListIconGadget-Header
@Lebostein,
I have taken your last code example with 2 ListIconGadgets and modified it to correctly detect the clicked header cell and clicked row in both ListIconGadgets in PB 6.00:
But unfortunately it's only some kind of hack. Like mk-soft has already explained, Fred has changed the internal cell type of ListIconGadgets to his custom PBIconTextCell and my hack uses the WillDisplayCell callback to read the content of each cell just before it is written into the cell, center the cell content vertically and write the cell content back into the cell. Therefore the icon feature of the new PBIconTextCell can't be used.
I would advise you to keep using PB 5.73 and all my old working extensions of the ListIconGadget.
I have taken your last code example with 2 ListIconGadgets and modified it to correctly detect the clicked header cell and clicked row in both ListIconGadgets in PB 6.00:
Code: Select all
EnableExplicit
#WindowID = 0
Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
Define EventGadget.I
ProcedureC WillDisplayCell(Object.I, Selector.I, TableView.I, Cell.I, *Column,
Row.I)
Protected Column.I
Protected CellText.S
Protected ListIconID.I = CocoaMessage(0, TableView, "tag")
Column = CocoaMessage(0, CocoaMessage(0, TableView, "tableColumns"),
"indexOfObject:", *Column)
CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)
CellText = GetGadgetItemText(ListIconID, Row, Column)
CocoaMessage(0, Cell, "setStringValue:$", @CellText)
EndProcedure
ProcedureC ColumnHeaderClickCallback(Object.I, Selector.I, TableView.I, *Column)
Protected ClickedHeaderColumn.I
Protected ListIconID.I = CocoaMessage(0, TableView, "tag")
ClickedHeaderColumn = Val(PeekS(CocoaMessage(0,
CocoaMessage(0, *Column, "identifier"), "UTF8String"), -1, #PB_UTF8))
PostEvent(#PB_Event_Gadget, #WindowID, ListIconID, #PB_EventType_LeftClick,
ClickedHeaderColumn + 1)
EndProcedure
OpenWindow(#WindowID, 200, 100, 825, 122, "Detect left click on header cell")
ListIconGadget(0, 10, 10, 400, WindowHeight(0) - 20, "Name", 110,
#PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0,
#PB_ListIcon_ColumnWidth) - 8)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ +
"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+ #LF$ +
"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ +
"321 Logo Drive, Mouse House, Downtown")
class_addMethod_(DelegateClass,
sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"),
@WillDisplayCell(), "v@:@@@@")
class_addMethod_(DelegateClass,
sel_registerName_("tableView:didClickTableColumn:"),
@ColumnHeaderClickCallback(), "v@:@@")
CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)
ListIconGadget(1, 415, 10, 400, WindowHeight(0) - 20, "Name", 110,
#PB_ListIcon_GridLines)
AddGadgetColumn(1, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0,
#PB_ListIcon_ColumnWidth) - 8)
AddGadgetItem(1, -1, "Harry Rannit" + #LF$ +
"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(1, -1, "Ginger Brokeit"+ #LF$ +
"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(1, -1, "Didi Foundit"+ #LF$ +
"321 Logo Drive, Mouse House, Downtown")
CocoaMessage(0, GadgetID(1), "setDelegate:", AppDelegate)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
EventGadget = EventGadget()
If (EventGadget = 0 Or EventGadget = 1) And
EventType() = #PB_EventType_LeftClick
If EventData()
Debug "Left click in ListIcon " + Str(EventGadget) +
" on header of column " + Str(EventData() - 1)
Else
Debug "Left click in ListIcon " + Str(EventGadget) +
" on row " + Str(GetGadgetState(EventGadget))
EndIf
EndIf
EndSelect
ForEver
But unfortunately it's only some kind of hack. Like mk-soft has already explained, Fred has changed the internal cell type of ListIconGadgets to his custom PBIconTextCell and my hack uses the WillDisplayCell callback to read the content of each cell just before it is written into the cell, center the cell content vertically and write the cell content back into the cell. Therefore the icon feature of the new PBIconTextCell can't be used.
I would advise you to keep using PB 5.73 and all my old working extensions of the ListIconGadget.
Re: Event click on ListIconGadget-Header
Thanks. Any idea how Fred has implemented the icon thing? I will have no choice but to rebuild it with my own code....
by the way: It is not understandable for me, why you have to refill the gadget in case of a simple query for events...
by the way: It is not understandable for me, why you have to refill the gadget in case of a simple query for events...
Re: Event click on ListIconGadget-Header
@Shardik: Strange, your code destroys some events, for example there is no event triggered if you use the arrow keys to select a new line in the gadget...
Re: Event click on ListIconGadget-Header
Event processing is unfortunately also affected by this, with these hack
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Event click on ListIconGadget-Header
It is a shame. People asking for this feature since 2003 (viewtopic.php?p=25667). And even in PB 6.01 from the year 2023, there is still no solution, apart from hacky forum workarounds (which so far do not work with QT on Linux).
Re: Event click on ListIconGadget-Header
Hello,
I don't find this post before I work on this problème. So I post my solution with setAllowsColumnSelection and SelectedColumn .
I don't find this post before I work on this problème. So I post my solution with setAllowsColumnSelection and SelectedColumn .
Code: Select all
EnableExplicit
Global quit,liste = 10 , event, Gadget
Structure Person
nom.s
prenom.s
id.i
EndStructure
Global Dim tabTries.Person(2)
tabTries(0)\nom = "Lager" : tabTries(0)\prenom = "Jules" : tabTries(0)\id = 7
tabTries(1)\nom = "Lager" : tabTries(1)\prenom = "Jérome" : tabTries(1)\id = 12
tabTries(2)\nom = "Garcia" : tabTries(2)\prenom = "Luca" : tabTries(2)\id = 2
Procedure TriAppel(Critere.s)
Define i
Debug Critere
For i = 0 To 2
Debug tabTries(i)\nom +" "+tabTries(i)\prenom
Next
Select Critere
Case "Nom"
SortStructuredArray(tabTries(), #PB_Sort_Ascending, OffsetOf(Person\nom), TypeOf(Person\nom))
Case "Prenom"
SortStructuredArray(tabTries(), #PB_Sort_Ascending, OffsetOf(Person\prenom), TypeOf(Person\prenom))
Case "Id"
SortStructuredArray(tabTries(), #PB_Sort_Ascending, OffsetOf(Person\id), TypeOf(Person\id))
EndSelect
EndProcedure
Procedure AfficheListe()
Define i
; vide la liste
For i = 0 To 2
RemoveGadgetItem(liste, 0)
Next
; lit les data
For i = 0 To 2
AddGadgetItem(liste, -1, tabTries(i)\nom + #LF$ + tabTries(i)\prenom + #LF$ + tabTries(i)\id)
Next
EndProcedure
OpenWindow(0, 200, 100, 600, 300, "Disable highlight example")
ListIconGadget(liste, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Nom", 110)
AddGadgetColumn(liste, 1, "Prenom", 100)
AddGadgetColumn(liste, 2, "Id", 100)
CocoaMessage(0, GadgetID(liste), "setAllowsColumnSelection:", #YES) ; autorise la selection de colonne
CocoaMessage(0, GadgetID(liste), "setSelectionHighlightStyle:", -1); -1 pas de surlignement / surlignement
AfficheListe()
Repeat
event = WaitWindowEvent()
Gadget = EventGadget();
Select Event
Case #PB_Event_CloseWindow
quit = 1
Case #PB_Event_Gadget
Select Gadget
Case liste ; liste
Define SelectedColumn
Select EventType()
Case #PB_EventType_LeftDoubleClick ; Edite tireur
Debug "ligne selectionnée"
Case #PB_EventType_LeftClick ; clic gauche
SelectedColumn = CocoaMessage(0, GadgetID(Liste) , "selectedColumn")
Debug SelectedColumn
If SelectedColumn = -1
Debug "Aucune colonne de sélectionnée"
CocoaMessage(0, GadgetID(liste), "setSelectionHighlightStyle:", 0); -1 pas de surlignement / surlignement
Else
Debug "colonne sélectionnée"
;selection d'une colonne > tri
CocoaMessage(0, GadgetID(liste), "setSelectionHighlightStyle:", -1); -1 pas de surlignement / surlignement
TriAppel(GetGadgetItemText(Gadget,-1,SelectedColumn)) ;Select SelectedColumn
AfficheListe()
EndIf
EndSelect
EndSelect
EndSelect
Until quit =1
IMAC 21.5 2012 Core I5 - 2.70 Ghz. 16 GB NVIDIA GeForce GT 640M 512 Mo. MacOs OCPL Sequoia 15.0
MacBook Air M1 - 8Go - Sonoma 14.1
MacBook Air M1 - 8Go - Sonoma 14.1
Re: Event click on ListIconGadget-Header
I just stumbled onto this solution today. I have been needing something like this for a long time. Seems to work great on 6.02.Bmld756 wrote: Sun Apr 23, 2023 9:05 pm Hello,
I don't find this post before I work on this problème. So I post my solution with setAllowsColumnSelection and SelectedColumn .
Thanks!!!
Phil
Re: Event click on ListIconGadget-Header
Yeah. This is a fundamental function of such gadget. I also don't understand why this is not implemented. The same is true for the alignment of the columns (left, centred, right).Kukulkan wrote: Thu Apr 13, 2023 10:09 am It is a shame. People asking for this feature since 2003 (viewtopic.php?p=25667). And even in PB 6.01 from the year 2023, there is still no solution, apart from hacky forum workarounds (which so far do not work with QT on Linux).