Page 1 of 1

listicongadget Column header detect

Posted: Tue Nov 13, 2007 11:35 pm
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

Posted: Wed Nov 14, 2007 12:13 am
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

Posted: Wed Nov 14, 2007 12:30 am
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?

Posted: Wed Nov 14, 2007 12:34 am
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.

Posted: Wed Nov 14, 2007 12:55 am
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

Posted: Wed Nov 14, 2007 12:58 am
by srod
You're welcome. :)

thanks, what if Panel_0 stops working?

Posted: Tue Apr 21, 2009 10:06 pm
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

Posted: Tue Apr 21, 2009 11:49 pm
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 

thanks netmaestro

Posted: Wed Apr 22, 2009 4:54 am
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

Posted: Wed Apr 22, 2009 11:56 am
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.

Listicon Gadget, finer details

Posted: Wed Apr 22, 2009 5:09 pm
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