ListIconGadget - capture header click {FIXED}

Just starting out? Need help? Post your questions and find answers here.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

ListIconGadget - capture header click {FIXED}

Post by kinglestat »

When making a ListViewGadget, the header is clickakble, but no message arrives to EventGadget. I'm sure its a common question...looked in forums, but didnt find a solution. Is there a platform independent solution as the code I am writing needs to run on linux besides Windows.
Last edited by kinglestat on Thu Nov 29, 2007 8:56 pm, edited 1 time in total.
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Do you mean a ListIcon gadget?

If so, then the only solution I know is Windows only.
I may look like a mule, but I'm not a complete ass.
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 »

If it isn't listed as a supported EventType for the gadget, there isn't going to be a one-snippet-fits-all solution across platforms. I can give you code to do it in Windows if you can use that but you would have to write a CompilerIf block and find some Linux code to go in there with it, then you're set. But until the event goes native, that's the best there will be.
BERESHEIT
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

srod: ListViewGadget

netmaestro:
OK, I will do as you suggest if you will be so kind

cheers
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Re: ListViewGadget - capture header click

Post by Derek »

kinglestat wrote:When making a ListViewGadget, the header is clickakble
What is the header?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Aye, I've never seen a header on a ListView gadget. I must be having a bad day! :)
I may look like a mule, but I'm not a complete ass.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

Code: Select all

#result = 1

ListIconGadget(#result, 10, 10, 255, 305, "", 20, #PB_ListIcon_CheckBoxes|#PB_ListIcon_MultiSelect|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect )
AddGadgetColumn(#result,2,"Field 1",150)
AddGadgetColumn(#result,3,"Field 2 ",80)
What appears at the very top of the listview I am calling Header. I'm not sure whats the technical term for it
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

srod wrote:Do you mean a ListIcon gadget?
:? :wink:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah the confusion is that a Windows ListView control (not gadget) equates to a PB LIstIcon whilst a Windows ListBox control equates to a PB ListView gadget.

Because you were talking about cross-platform then I took your use of a ListView to refer to a PB ListView (not a Windows one).

In PB terms then you are talking about a ListIcon.

Sorted.

There are plenty of examples in the forums about detecting header clicks (I've posted a couple myself). Search for ListIcon though or 'Header' etc.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I may look like a mule, but I'm not a complete ass.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

My bad
I apologize for the confusion
I'm a bit tired
And now I realize why I didnt find anything

Thanks for the help, once again
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
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 »

Here's how I'd do it:

Code: Select all

CompilerIf #PB_OS_Windows 
  #WM_CUSTOM_LVH_RBUTTONDOWN = #WM_APP + 1 
  #WM_CUSTOM_LVH_RBUTTONUP   = #WM_APP + 2 
  #WM_CUSTOM_LVH_LBUTTONDOWN = #WM_APP + 3 
  #WM_CUSTOM_LVH_LBUTTONUP   = #WM_APP + 4 

  Procedure HitTest(hwnd, lparam)
    hti.hd_hittestinfo 
    hti\pt\x = lparam&$FFFF 
    hti\pt\y = lparam>>16 
    SendMessage_(hwnd, #HDM_HITTEST,0,@hti) 
    ProcedureReturn hti\iItem
  EndProcedure
  
  Procedure LV_HeaderCallBack(hwnd, msg, wparam, lparam) 
    Protected oldproc = GetProp_(hwnd, "oldproc") 
    Protected topwindow = GetProp_(hwnd, "topwindow")
    Select msg 
      Case #WM_NCDESTROY 
        RemoveProp_(hwnd, "oldproc") 
        RemoveProp_(hwnd, "topwindow") 
      Case #WM_RBUTTONUP 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_RBUTTONUP,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
      Case #WM_RBUTTONDOWN 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_RBUTTONDOWN,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
     Case #WM_LBUTTONDOWN 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_LBUTTONDOWN,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
      Case #WM_LBUTTONUP 
        PostMessage_(topwindow,#WM_CUSTOM_LVH_LBUTTONUP,GetDlgCtrlID_(GetParent_(hwnd)),HitTest(hwnd,lparam)) 
    EndSelect 
    ProcedureReturn CallWindowProc_(oldproc,hwnd,msg,wparam,lparam)  
  EndProcedure 
CompilerElse 
  ; Linux code 
CompilerEndIf 

OpenWindow(0,0,0,320,240,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
ListIconGadget(33,0,0,320,240,"Column 0",100) 
AddGadgetColumn(33,1,"Column 1",215) 

CompilerIf #PB_OS_Windows 
  header = SendMessage_(GadgetID(33),#LVM_GETHEADER,0,0) 
  oldproc = SetWindowLong_(header,#GWL_WNDPROC, @LV_HeaderCallBack()) 
  SetProp_(header, "oldproc", oldproc) 
  SetProp_(header, "topwindow", WindowID(0)) 
CompilerElse #PB_OS_Linux 
  ; linux code 
CompilerEndIf 

Repeat 
  ev = WaitWindowEvent() 
  Select ev  
    CompilerIf #PB_OS_Windows 
      Case #WM_CUSTOM_LVH_LBUTTONDOWN 
        Debug "Left Button down for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
      Case #WM_CUSTOM_LVH_LBUTTONUP 
        Debug "Left Button up for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
      Case #WM_CUSTOM_LVH_RBUTTONDOWN 
        Debug "Right Button down for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
      Case #WM_CUSTOM_LVH_RBUTTONUP 
        Debug "Right Button up for header item "+Str(EventlParam()) +" of ListIcon "+Str(EventwParam()) 
    CompilerElse #PB_OS_Linux 
      ; Linux code 
    CompilerEndIf 
    ; more event tests 
  EndSelect 
Until ev = #WM_CLOSE
Last edited by netmaestro on Fri Nov 30, 2007 4:30 am, edited 1 time in total.
BERESHEIT
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

thanks netmaestro
saved by the bell
I was tacking the wrong wind
I like the approach as its easier to make the diff linux/windows stuff
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
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 »

Fixed a bug in the posted code where the #gadget was being reported incorrectly, also streamlined the code a bit.
BERESHEIT
Post Reply