listicongadget Column header detect

Windows specific forum
Andy72
User
User
Posts: 11
Joined: Fri Jun 02, 2006 8:25 am
Location: New Zealand

listicongadget Column header detect

Post by Andy72 »

I know this may be a case of RTFM but I have been having trouble figuring out how to detect which column header has been clicked on when using the listicongadget?

Cheers

Andrewr
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Here's one way :

Code: Select all

Procedure.l WinProc(hWnd, uMsg, wParam, lParam) 
  Protected *nml.NM_LISTVIEW 
  result = #PB_ProcessPureBasicEvents 
  Select uMsg 
    Case #WM_NOTIFY 
      *nml = lParam 
      Select *nml\hdr\code 
        Case #LVN_COLUMNCLICK 
          Debug "Header item "+Str(*nml\iSubItem)+" clicked!" 
      EndSelect 
  EndSelect 
  ProcedureReturn result 
EndProcedure 


If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    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 PureBasic Road, BigTown, CodeCity")
    SetWindowCallback(@WinProc())
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
EndIf
I may look like a mule, but I'm not a complete ass.
Andy72
User
User
Posts: 11
Joined: Fri Jun 02, 2006 8:25 am
Location: New Zealand

Post by Andy72 »

Thanks, I'll give it a go.
I was afraid using windows callback may be the only way, so dose this mean if you were trying to do it in lynix your stuffed? (just a question as I did post this in the windows section :wink: ), Only ask because I seen posts from 2003 asking similar questions?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You are indeed stuffed as far as Linux goes! :wink:

What you need to do is find some code which works in Linux and then use conditional compilation to include the correct code depending on which platform the application is being compiled on etc.
I may look like a mule, but I'm not a complete ass.
Andy72
User
User
Posts: 11
Joined: Fri Jun 02, 2006 8:25 am
Location: New Zealand

Post by Andy72 »

Thanks Srod,
added the code and its exacatly what I needed, I often find the code you post has helped me out of many coding problems.

cheers mate :D

andrewr
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome. :)
I may look like a mule, but I'm not a complete ass.
rdority
User
User
Posts: 34
Joined: Mon Mar 30, 2009 10:46 pm
Location: Vancouver, BC

thanks, what if Panel_0 stops working?

Post by rdority »

Hi,

At first I just wanted to say Thanks you guys!!

I tried the above code snippet and it works pretty well.

Couple things:

1) Any idea why the very first time I click on any column header it seems to be ignored? I have to click one more time and after that I only have to click once on each column header and it works great! But that very first click just doesn't do a thing...

2) Now the Tabs / Panel gadget seems to be failing altogether. It has the standard name of Panel_0 and works fine so long as I comment out the above code. But then I don't have column header click detection so it's a bit of a trade off it seems.

Either I get column header click notifications (and then Panel_0 fails) or I can have Panel_0 back if I forfeit having the Windows call back that makes the header click notifiers kick in.

Anyone have a recommendation for dealing with this side effect?

Thanks!!
Roark
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You can use a subclass as an alternative to a window callback, this way you can find the click message in your PB event loop. Also, it won't interfere with your panel gadget.

Code: Select all

#HEADERCLICKED = #WM_APP + 1 

Procedure HeaderProc(hwnd, msg, wparam, lparam) 
  
  oldproc = GetProp_(hwnd, "oldproc") 
  Select msg 
    Case #WM_NCDESTROY 
      RemoveProp_(hwnd, "oldproc") 
      
    Case #WM_LBUTTONUP 
      With hd_hti.HD_HITTESTINFO 
        \pt\x=lparam&$FFFF 
        \pt\y=lparam>>16 
      EndWith 
      SendMessage_(hwnd, #HDM_HITTEST,0,hd_hti) 
      If hd_hti\flags & #HHT_NOWHERE=0 And hd_hti\flags&#HHT_ONDIVIDER=0 And hd_hti\iItem>=0
        PostMessage_(WindowID(0),#HEADERCLICKED, hd_hti\iItem, GetDlgCtrlID_(GetParent_(hwnd))) 
      EndIf 
      
  EndSelect 
  
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam) 
EndProcedure 


If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection) 
    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 PureBasic Road, BigTown, CodeCity") 
    
    header = SendMessage_(GadgetID(0),#LVM_GETHEADER,0,0) 
    SetProp_(header, "oldproc", SetWindowLongPtr_(header,#GWL_WNDPROC,@HeaderProc())) 
    
    Repeat 
      Event = WaitWindowEvent() 
      Select Event 
        Case #HEADERCLICKED 
          button = EventwParam() 
          gadget = EventlParam() 
          Debug "Header button " + Str(button) + " clicked on gadget# "+Str(gadget) 
      EndSelect 
    Until Event = #PB_Event_CloseWindow 
EndIf 
Last edited by netmaestro on Wed Apr 22, 2009 11:55 am, edited 1 time in total.
BERESHEIT
rdority
User
User
Posts: 34
Joined: Mon Mar 30, 2009 10:46 pm
Location: Vancouver, BC

thanks netmaestro

Post by rdority »

Thanks netmaestro,

It can be a lonely world out there so it's always nice to feel like other PB enthusiasts are around and willing to share. Thanks for sharing as often as you do. Your code snippets are often just the trick that is needed to solve the problem at hand.

I only now was able to open t his message or I would have responded to thank you earlier, but the link in the email that arrived was slightly garbled. Fortunately I was eventually able to piece things together to figure out what the link should be to read your helpful response!

I'll let you know if I have any other questions on this topic but I suspect this code snippet you were kind enough to provide will be all that is needed.

Cheers,
Roark
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You're most welcome rdority. I made a small change to stop the subclass from sending an unneeded message when a header button was pressed, the mouse dragged off the button and released.
BERESHEIT
rdority
User
User
Posts: 34
Joined: Mon Mar 30, 2009 10:46 pm
Location: Vancouver, BC

Listicon Gadget, finer details

Post by rdority »

:idea:

Well netmaestro, all I can say is you certainly pay attention to some of the finer details and.. you rock! :)

I tried implementing your fix into the program and it works. Not only that, I managed to have it working on several listicon gadgets!

Mille Grazie,
Roark
Post Reply