I like this question. Here is one possible answer using a little JavaScript to handle the “mousedown” and “mouseup” events.
The long press is set to 3 seconds, which you can change in the onMouseDown() procedure.
For fun, after pressing and holding for 3 seconds, the code displays a window showing information about the current item.
Code: Select all
EnableExplicit
Enumeration
#timer
#toolTip
EndEnumeration
Global currentItem
Procedure onClose()
If EventWindow() = #toolTip
CloseWindow(#toolTip)
EndIf
EndProcedure
; Cancel timer after 3 seconds
Procedure onMouseLongpress()
Protected buffer.s
Debug "Item " + Str(currentItem) + " Longpress"
RemoveWindowTimer(0, #timer)
; Show record
buffer = "<b>" + GetGadgetItemText(0, currentItem, 0) + "</b>" + "<br>" + GetGadgetItemText(0, currentItem, 1)
OpenWindow(#toolTip, WindowX(0) + 100, WindowY(0) + 100 , 400, 200, "Information")
TextGadget(#PB_Any, 10, 10, 380, 180, buffer)
BindEvent(#PB_Event_CloseWindow, @onClose(), #toolTip)
EndProcedure
; Remove timer if mouse up
; Remove current selection
Procedure onMouseUp()
If currentItem <> -1
Debug "Item " + Str(currentItem) + " Mouse Up"
EndIf
RemoveWindowTimer(0, #timer)
SetGadgetState(0, -1)
EndProcedure
; Add timer if mouse down
Procedure onMouseDown()
currentItem = GetGadgetState(0)
If currentItem <> -1
Debug "Item " + currentItem + " Mouse Down : Wait longpress 3 seconds"
; Add timer 3 seconds
AddWindowTimer(0, #timer, 3000)
BindEvent(#PB_Event_Timer, @onMouseLongpress())
If IsWindow(#toolTip)
CloseWindow(#toolTip)
EndIf
EndIf
EndProcedure
If OpenWindow(0, 100, 100, 300, 120, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 90, "Name", 100)
AddGadgetColumn(0, 1, "Address", 250)
AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 SpiderBasic Road, BigTown, CodeCity")
; Add JavaScript mousedown and mouseup events
EnableJS
addEventListener("mousedown", f_onmousedown)
addEventListener("mouseup", f_onmouseup)
DisableJS
EndIf
It was fun
