How to detect mouse wheel in a ListIconGadget?

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

How to detect mouse wheel in a ListIconGadget?

Post by marcoagpinto »

Hello!

I am using virtual ListIconGadgets (no vertical bar) in my Hunspell tool "Proofing Tool GUI".

I noticed the other day that we can have a shortcut also for the mouse wheel.

If I use the shortcut, how do I detect that the user used the mouse wheel over the gadget and if it scrolled up or down?

Thank you in advance!

Kind regards,

EDIT: Virtual ListIconGadget means that I may have 10000s of entries but I only show a few at a time.
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: How to detect mouse wheel in a ListIconGadget?

Post by CELTIC88 »

hi :)

Code: Select all

;By Celtic88 (c) 2017
;More info about Virtual List-View:https://msdn.microsoft.com/en-us/library/windows/desktop/bb774735(v=vs.85).aspx#Virtual_ListView_Style

Procedure.s RandomString(len=10)
  Protected Ranstr.s,oklm
  For oklm=1 To len
    Ranstr + Chr(Random(90,64))
  Next
  ProcedureReturn Ranstr
EndProcedure

Global Dim ItemInfo.s(1,100000)
Global LvHwnd

Structure NMLVSCROLL
  hdr.NMHDR;NMHDR structure that contains information about a LVN_ENDSCROLL or a LVN_BEGINSCROLL notification code.
  dx.l     ;Value of type int that specifies in pixels the horizontal position where a scrolling operation should begin or end.
  dy.l     ;Value of type int that specifies in pixels the vertical position where a scrolling operation should begin or end.
EndStructure

Procedure WinCallback(hWnd, uMsg, WParam, LParam) 
  Protected *pNMLVSCROLL.NMLVSCROLL
  Select uMsg
    Case #WM_NOTIFY
      Protected *tNMHDR.NMHDR = LParam
      Select *tNMHDR\hwndFrom
        Case LvHwnd
          Select *tNMHDR\code
            Case #LVN_BEGINSCROLL
              *pNMLVSCROLL = LParam
              Debug " #LVN_BEGINSCROLL : x = " + Str(*pNMLVSCROLL\dx) + " y= " + Str(*pNMLVSCROLL\dy)
              
            Case #LVN_ENDSCROLL
              *pNMLVSCROLL = LParam
              Debug " #LVN_ENDSCROLL : x = " + Str(*pNMLVSCROLL\dx) + " y= " + Str(*pNMLVSCROLL\dy)
              
            Case #LVN_GETDISPINFO
              Protected *tNMLVDISPINFO.NMLVDISPINFO = LParam
              With *tNMLVDISPINFO
                If \item\mask & #LVIF_TEXT
                  \item\pszText = @ItemInfo(\item\iSubItem,\item\iItem)
                  \item\cchTextMax = Len(ItemInfo(\item\iSubItem,\item\iItem))
                EndIf
              EndWith
          EndSelect
      EndSelect
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 

If OpenWindow(0, 100, 100, 500, 600, "Test Virtual List-View", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 490, 590, "Nom", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection|#LVS_OWNERDATA)
  LvHwnd = GadgetID(0)
  AddGadgetColumn(0, 1, "Adresse", 250)
  
  SetWindowCallback(@WinCallback(),0)
  
  Debug "preparing list.."
  itemCount = 10000
  For u=0 To itemCount-1
    For ii=0 To 1
      ItemInfo(ii,u) =  Str(u) + " " + RandomString(5)
    Next
  Next
  Debug "End preparing list.."
  
  SendMessage_( LvHwnd, #LVM_SETITEMCOUNT, itemCount, 0 )
  
  Repeat
    Evenement = WaitWindowEvent()
  Until Evenement = #PB_Event_CloseWindow
EndIf

interested in Cybersecurity..
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: How to detect mouse wheel in a ListIconGadget?

Post by marcoagpinto »

Guys, tomorrow I will try to write some code to show what I am after.

Thanks!
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: How to detect mouse wheel in a ListIconGadget?

Post by marcoagpinto »

This is what I had in mind:

Code: Select all

OpenWindow(0,10,10,500,500,"Testing")

ListIconGadget(1,4,20-5,15+10+40+40+30+15+600-20+10+5+4+4+4-300-10-5-5-2,300-30+5+40,"#",30+40+10+5,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_CheckBoxes)
AddGadgetColumn(1,1,"Words",100+10+20+20+10)
AddGadgetColumn(1,2,"Tags",150+5+15)

For f=1 To 10
  AddGadgetItem(1,-1,"Line #"+Str(f)+#LF$+"blah"+#LF$+"The vertical scroll gadget will be virtual")
Next f

; Keyboard shortcuts
AddKeyboardShortcut(0,#PB_Shortcut_Scroll,1000)

Repeat
  
  event=WaitWindowEvent()
  
    ; Shortcut for mouse-wheel
    If event=#PB_Event_Menu And EventMenu()=1000
      Debug "MOUSE-WHEEL pressed"
    EndIf  
  
ForEver
But the mouse wheel isn't detected.

I wanted to show in this example 10 items at the time.

I need to be able to detect if the mouse wheel is rotated, the gadget where it happened and if it was scroll up or down.

Also, it must work with all OSes.

Thank you!
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: How to detect mouse wheel in a ListIconGadget?

Post by Dude »

#PB_Shortcut_Scroll means the "Scroll Lock" key; not scrolling of the mouse or anything else.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to detect mouse wheel in a ListIconGadget?

Post by TI-994A »

marcoagpinto wrote:I wanted to show in this example 10 items at the time.

I need to be able to detect if the mouse wheel is rotated, the gadget where it happened and if it was scroll up or down.

Also, it must work with all OSes.
If I understand correctly, this is perhaps what you had in mind:

Code: Select all

Declare populateList(g, start)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
lFlags = #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_CheckBoxes
mainWin = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 500, 300, "MouseWheel Example", wFlags)
mainCanvas = CanvasGadget(#PB_Any, 0, 0, 500, 300, #PB_Canvas_Keyboard | #PB_Canvas_Container)
mainList = ListIconGadget(#PB_Any, 0, 0, 490, 300, "#", 100, lFlags)
CloseGadgetList()

StartDrawing(CanvasOutput(mainCanvas))
  Box(0, 0, 500, 300, RGB(200, 200, 200))
StopDrawing()
AddGadgetColumn(mainList, 1, "Words", 180)
AddGadgetColumn(mainList, 2, "Tags", 180)
populateList(mainList, 1)
;DisableGadget(mainList, 1)   ;list is always scrollable but not selectable
SetActiveGadget(mainCanvas)
listCount = 1

MessageRequester("MouseWheel Example", "Click on the GREY area before scrolling.")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case mainCanvas
          Select EventType()
            Case #PB_EventType_MouseWheel
              delta = GetGadgetAttribute(EventGadget(), #PB_Canvas_WheelDelta)
              If delta = 1
                If listCount > 1
                  listCount - 10
                  update = #True
                EndIf
              ElseIf delta < 0
                listCount + 10
                update = #True
              EndIf                  
              If update
                update = #False
                populateList(mainList, listCount)
              EndIf
          EndSelect
      EndSelect
  EndSelect
Until appQuit = 1 

Procedure populateList(g, start)
  ClearGadgetItems(g)
  For populate = start To start + 9
    AddGadgetItem(g, -1, "Line #" + Str(populate) + #LF$ + 
                         "Dummy Text " + Str(populate)  + #LF$ + 
                         "More dummy text " + Str(populate) )
  Next
EndProcedure
The mousewheel is detected, the scroll is virtual, and it's presumably cross-platform.

However, the drawback is that you'd either have to disable the list (which would render it unselectable), or click on the canvas (grey area) each time before scrolling.

Just a simple workaround. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: How to detect mouse wheel in a ListIconGadget?

Post by marcoagpinto »

Anyway, my two cents:
http://www.purebasic.fr/english/viewtop ... 49#p516649

If there is a ScrollBarGadget, it should also accept mouse scroll built-in.
Post Reply