Page 1 of 1

[SOLVED] How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 10:10 am
by avatar
I have searched this forum for the captioned query.
Somebody said that there is a Window API for it.

Could anybody help me with example codes?

Re: How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 12:40 pm
by c4s
What about...

Code: Select all

Select WaitWindowEvent()
	Case #PB_Event_Gadget
		Select EventGadget()
			Case #ListView
				If EventType() = #PB_EventType_RightClick
					DisplayPopupMenu(#ListViewMenu, WindowID(#Window))
				EndIf

;[...]
:?:

Re: How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 2:30 pm
by avatar
Already tried
and
the PB manual says not support right-click in ListView

i am now considering recoding to change to ListIcon

Re: How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 2:55 pm
by c4s
Ah sorry I missed that.
Anyway you can make a ListIconGadget() look and behave like a ListViewGadget() so it shoulfn't be a problem.

Re: How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 3:07 pm
by ts-soft

Code: Select all

Procedure WinCB(hWnd, uMsg, wParam, lParam)
  Protected result = #PB_ProcessPureBasicEvents
  
  Select uMsg
    Case #WM_CONTEXTMENU
      If GetActiveGadget() = 0
        Debug "Contextmenu on ListView"
      EndIf
  EndSelect
  
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 270, 140, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListViewGadget(0, 10, 10, 250, 120)
  For a = 1 To 12
    AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
  Next
  SetGadgetState(0, 9)
  SetWindowCallback(@WinCB())
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf



Re: How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 4:07 pm
by skywalk
Very helpful ts-soft! :)

I was trying callback and failed on Case #WM_RBUTTONDOWN ?

srod's EasyVent works also. But, this is sufficient to allow a popup menu or some such on a simple ListView.

Re: How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 4:19 pm
by ts-soft
Is only useful on listview and editorgadget.

Re: How to get the right click event from a listview?

Posted: Wed Apr 21, 2010 11:38 pm
by donSHAYA
Does this work on all gadgets? I don't know:

Code: Select all

Procedure RightClick(#Window, #Gadget, Event)
If Event = #WM_RBUTTONDOWN
If WindowMouseX(#Window) > GadgetX(#Gadget) And WindowMouseX(#Window) < GadgetX(#Gadget) + GadgetWidth(#Gadget)
If WindowMouseY(#Window) > GadgetY(#Gadget) And WindowMouseY(#Window) < GadgetY(#Gadget) + GadgetHeight(#Gadget)
; [Bla bla bla...} or
; ProcedureReturn 1
EndIf
EndIf
EndIf

EndProcedure

#MainWin = 0
#ListViewG = 0
OpenWindow(#MainWin, #PB_Ignore, #PB_Ignore, 200, 200, "Test", #PB_Window_ScreenCentered)
ListViewGadget(#ListView, 5, 5, 100, 100)

Repeat

Evt = WaitWindowEvent()

RightClick(#MainWin, #ListViewG, Evt)

Until Evt = #PB_Event_CloseWindow

Re: How to get the right click event from a listview?

Posted: Thu Apr 22, 2010 4:20 am
by avatar
Thank you all for the input.

Re: [SOLVED] How to get the right click event from a listvie

Posted: Thu Apr 22, 2010 3:27 pm
by Shardik
Unfortunately ts-soft's example contains a bug: If your first action is a right click, this
right click will not be detected. Only after a first left mouse click all following right clicks
are reliably detected. In order to solve this problem you should compare the wParam
with the handle of the ListViewGadget to make sure that the right click occured inside the
ListViewGadget:

Code: Select all

Procedure WinCB(hWnd, uMsg, wParam, lParam)
  Protected result = #PB_ProcessPureBasicEvents
 
  Select uMsg
    Case #WM_CONTEXTMENU
      If wParam = GadgetID(0)
        Debug "Contextmenu on ListView"
      EndIf
  EndSelect

  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 270, 140, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListViewGadget(0, 10, 10, 250, 120)
  For a = 1 To 12
    AddGadgetItem (0, -1, "Item " + Str(a) + " of the Listview")
  Next
  SetGadgetState(0, 9)
  SetWindowCallback(@WinCB())
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: [SOLVED] How to get the right click event from a listvie

Posted: Thu Apr 22, 2010 3:44 pm
by ts-soft
In wParam is the hwnd, thx.
I have tested with lParam :oops: