RMB on ListIconGadget header

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

RMB on ListIconGadget header

Post by blueznl »

I haven't been programming much lately, but now need to change a few very old tools, and want to add a bit of GUI to them.

I'm not in the mood to write my own kind of Gridgadget (yet :-) ) and trying to limit myself to PureBasic (so no external libraries). I probably could build it using the CanvasGadget, and might do so at a later date, but for now I first need to establish a kind of proof-of-concept.

So, I looked to repurpose the LIstIconGadget, and it does most of the things I need it to do, except two things...

1. How to detect an RMB on the header? (To offer sorting.)
2. Is there a way to discern between single and double click? (It's pretty annoying an LMB is always fired before and after a doubleclik.)

On a completely unrelated side note, Happy New Year!
Last edited by blueznl on Sat Dec 31, 2022 6:32 pm, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Axolotl
Addict
Addict
Posts: 802
Joined: Wed Dec 31, 2008 3:36 pm

Re: RMB on ListIconGadget header

Post by Axolotl »

maybe this is something you are looking for

Code: Select all

; =================================================================
;
;        Author:       Shardik  
;          Date:       January 27th, 2015
;       Explain:       Get ListIconGadget column
;           
; Typical Usage:
;
;     File Name:      Get Column Info.pb    
; =================================================================
Enumeration
  #MainForm
EndEnumeration

Enumeration Gadget
  #MyListIcon
EndEnumeration


Procedure OnListIconCLick(WindowID, message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents 
  
  Select message
    Case #WM_NOTIFY
      *nmITEM.NMITEMACTIVATE = lParam
      Select *nmITEM\hdr\code
          
        Case #LVN_COLUMNCLICK ;/ HeaderClick
          If *nmITEM\hdr\hwndFrom = GadgetID(#MyListIcon) ;/ ListIconGadget
            Debug " header col = " + Str(*nmITEM\iSubItem)
            Result = #True
          EndIf
          
        Case #NM_CLICK ;/ CellClick (Your question)
          If *nmITEM\hdr\hwndFrom = GadgetID(#MyListIcon) ;/ ListIconGadget
            Debug "row = " + Str(*nmITEM\iItem) + ", col = "+Str(*nmITEM\iSubItem) + ", content = "+ GetGadgetItemText(#MyListIcon, *nmITEM\iItem,*nmITEM\iSubItem)
            Result = #True
          EndIf
          
        Case #NM_DBLCLK 
          Debug "left doubleclick"
          ;Your code
          
        Case #NM_RCLICK
          Debug "right click"
          ;Your code
          
        Case #NM_RDBLCLK
          Debug "right doubleclick"
          ;Your code
          
      EndSelect
  EndSelect
  ProcedureReturn Result 
EndProcedure

Procedure Start()
  Protected n, Buffer.s
  
  OpenWindow(#MainForm, 0, 0, 500, 500, "Listicon gadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  SetWindowCallback(@OnListIconCLick(), #MainForm)
  
  ListIconGadget(#MyListIcon, 10, 10, 480, 400, "Col 0", 100, #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#MyListIcon, 1, "Col 1", 100)
  AddGadgetColumn(#MyListIcon, 2, "Col 2", 100)
  
  For n=0 To 10
    Buffer = "Item " + Str(n) + Chr(10) + "Result Col 1=" + Str(n)  + Chr(10) + "Result Col 2=" + Str(n)
    AddGadgetItem(#MyListIcon, -1, Buffer)
  Next

  Repeat : Until WaitWindowEvent(10) = #PB_Event_CloseWindow
EndProcedure

Start()
Happy New Year!
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: RMB on ListIconGadget header

Post by blueznl »

Ah, yes. I could use a callback. Hmmm... I might be lazy and (ab)use a popup menu for now. It's still a proof of concept, and the GUI elements are just to quickly test the code. (Some boring analysis of a certain type of report.)

But I might use this if it ever leaves the proto stage, so thanks!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: RMB on ListIconGadget header

Post by RASHAD »

Subclassing ListIcon Header
RMB on header only
No interference with Licon

Code: Select all

Global oldCB,hi.LVHITTESTINFO

Procedure headerCB(hWnd, uMsg, wParam, lParam)
  result = CallWindowProc_(oldCB, hWnd, uMsg, wParam, lParam)
  Select uMsg      
    Case #WM_LBUTTONUP
      GetCursorPos_(@p.POINT)
      ScreenToClient_(GadgetID(0), p)
      hi\pt\x = p\x
      hi\pt\y = p\y  
      SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST,0,@hi)
      Debug "LMB : " +Str(hi\iSubItem)
          
    Case #WM_RBUTTONUP 
      GetCursorPos_(@p.POINT)
      ScreenToClient_(GadgetID(0), p)
      hi\pt\x = p\x
      hi\pt\y = p\y  
      SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST,0,@hi)
      Debug "RMB : " +Str(hi\iSubItem)
      
    Case #WM_LBUTTONDBLCLK 
      GetCursorPos_(@p.POINT)
      ScreenToClient_(GadgetID(0), p)
      hi\pt\x = p\x
      hi\pt\y = p\y  
      SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST,0,@hi)
      Debug "LMB DCLICK : " +Str(hi\iSubItem)
      
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(5,0,0,640,480,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ListIcon = ListIconGadget(0,10,10,620,460,"",0,#PB_ListIcon_GridLines)
header = SendMessage_(GadgetID(0),#LVM_GETHEADER,0,0)
AddGadgetColumn(0,1,"Column 1",210)
AddGadgetColumn(0,2,"Column 2",200)
AddGadgetColumn(0,3,"Column 3",200)
For i = 1 To 16
  linestr.s = LSet(Str(i),3," ")
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3")
Next
oldCB = SetWindowLongPtr_(header, #GWL_WNDPROC, @headerCB())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Menu      
      Select EventMenu() 
      EndSelect
  EndSelect
  
Until Quit = 1

Egypt my love
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: RMB on ListIconGadget header

Post by mk-soft »

If you still need GridGadget, there is a very good one from Said. I have carried out the last updates.

Link: Said's Canvas based Grid gadget
Link: Last updates from me on Github
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
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: RMB on ListIconGadget header

Post by blueznl »

Thanks! I'll have a look at that as well. For now I'm mostly working on a proof of concept.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: RMB on ListIconGadget header

Post by blueznl »

RASHAD wrote: Sat Dec 31, 2022 6:41 pm Global oldCB,hi.LVHITTESTINFO
@RASHAD

Does hi.LVHITTESTINFO need to be a global?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: RMB on ListIconGadget header

Post by RASHAD »

Egypt my love
Post Reply