Page 1 of 1
ListIconGadget - capture header click {FIXED}
Posted: Thu Nov 29, 2007 7:39 pm
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.
Posted: Thu Nov 29, 2007 7:58 pm
by srod
Do you mean a ListIcon gadget?
If so, then the only solution I know is Windows only.
Posted: Thu Nov 29, 2007 8:01 pm
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.
Posted: Thu Nov 29, 2007 8:27 pm
by kinglestat
srod: ListViewGadget
netmaestro:
OK, I will do as you suggest if you will be so kind
cheers
Re: ListViewGadget - capture header click
Posted: Thu Nov 29, 2007 8:31 pm
by Derek
kinglestat wrote:When making a ListViewGadget, the header is clickakble
What is the
header?
Posted: Thu Nov 29, 2007 8:36 pm
by srod
Aye, I've never seen a header on a ListView gadget. I must be having a bad day!

Posted: Thu Nov 29, 2007 8:43 pm
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
Posted: Thu Nov 29, 2007 8:46 pm
by Derek
srod wrote:Do you mean a ListIcon gadget?

Posted: Thu Nov 29, 2007 8:47 pm
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.
Posted: Thu Nov 29, 2007 8:49 pm
by srod
Posted: Thu Nov 29, 2007 8:51 pm
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
Posted: Thu Nov 29, 2007 9:00 pm
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
Posted: Thu Nov 29, 2007 9:17 pm
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
Posted: Fri Nov 30, 2007 4:31 am
by netmaestro
Fixed a bug in the posted code where the #gadget was being reported incorrectly, also streamlined the code a bit.