It is still not possible to perform and catch a right click event on an EditorGadget....
PB_EventType_RightClick
Right click on Editor
Re: Right click on Editor
https://www.purebasic.fr/english/viewtopic.php?p=517256
Been over 6 years wait so far.

Re: Right click on Editor
Perhaps this helps:
Code: Select all
EnableExplicit
Enumeration FormGadget
#myPopup
#myGadget
EndEnumeration
Procedure WndProc(hWnd, uMsg, wParam, lParam)
If uMsg = #WM_CONTEXTMENU
If wParam = GadgetID(#myGadget)
DisplayPopupMenu(#myPopup, WindowID(0),DesktopMouseX()+5, DesktopMouseY())
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0, 0, 0, 600, 400,"Right Click Edit Gadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreatePopupMenu(#myPopup)
MenuItem(0, "Menu 1")
MenuItem(1, "Menu 2")
MenuItem(2, "Menu 3")
EditorGadget(#myGadget, 10, 10, 580, 350)
SetWindowCallback(@WndProc())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Right click on Editor
Global WM_ContextMenu
Code: Select all
EnableExplicit
Enumeration #PB_EventType_FirstCustomValue
#MyEventType_ContextMenu
EndEnumeration
Enumeration FormMenu
#myPopupEdit
#myPopupList
EndEnumeration
Enumeration FormMenuItems
#myMenuEdit1
#myMenuEdit2
#myMenuEdit3
#myMenuList1
EndEnumeration
Enumeration FormGadget
#myEditGadget
#myListGadget
EndEnumeration
Procedure WndProc(hWnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_CONTEXTMENU
PostEvent(#PB_Event_Gadget, EventWindow(), GetDlgCtrlID_(wParam), #MyEventType_ContextMenu)
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(0, 0, 0, 600, 500,"Right Click Edit Gadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreatePopupMenu(#myPopupEdit)
MenuItem(#myMenuEdit1, "Menu Edit 1")
MenuItem(#myMenuEdit2, "Menu Edit 2")
MenuItem(#myMenuEdit3, "Menu Edit 3")
CreatePopupMenu(#myPopupList)
MenuItem(#myMenuList1, "Menu List 1")
EditorGadget(#myEditGadget, 10, 10, 580, 250)
ListViewGadget(#myListGadget, 10, 270, 580, 200)
SetWindowCallback(@WndProc())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #myEditGadget
Select EventType()
Case #MyEventType_ContextMenu
DisplayPopupMenu(#myPopupEdit, WindowID(0),DesktopMouseX()+5, DesktopMouseY())
EndSelect
Case #myListGadget
Select EventType()
Case #MyEventType_ContextMenu
DisplayPopupMenu(#myPopupList, WindowID(0),DesktopMouseX()+5, DesktopMouseY())
EndSelect
EndSelect
EndSelect
ForEver
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Right click on Editor
great examples guys.
We just have to bear in mind that the context menu can also be generated from the keyboard (i.e. #VK_APPS key or SHIFT+F10) and the mouse can be positioned anywhere on the screen.
I have taken the liberty of revising your example. Details can be found in the code.
We just have to bear in mind that the context menu can also be generated from the keyboard (i.e. #VK_APPS key or SHIFT+F10) and the mouse can be positioned anywhere on the screen.
I have taken the liberty of revising your example. Details can be found in the code.
Code: Select all
EnableExplicit
Enumeration #PB_EventType_FirstCustomValue
#MyEventType_ContextMenu
EndEnumeration
Enumeration FormMenu
#myPopupEdit
#myPopupList
EndEnumeration
Enumeration FormMenuItems
#myMenuEdit1
#myMenuEdit2
#myMenuEdit3
#myMenuList1
EndEnumeration
Enumeration FormGadget
#myEditGadget
#myListGadget
EndEnumeration
Procedure WndProc(hWnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_CONTEXTMENU
; !! add an additional parameter lParam (for the position)
; so we can detect if the context menu is generated from the keyboard
PostEvent(#PB_Event_Gadget, EventWindow(), GetDlgCtrlID_(wParam), #MyEventType_ContextMenu, lParam)
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure.w GET_X_LPARAM(lParam) ; return X.w (signed)
ProcedureReturn lParam
EndProcedure
Procedure.w GET_Y_LPARAM(lParam) ; return Y.w (signed)
ProcedureReturn lParam >> 16
EndProcedure
Procedure ShowPopupMenu(Menu, Window, Gadget, LParam)
Protected menupos.POINT
menupos\x = GET_X_LPARAM(LParam)
menupos\y = GET_Y_LPARAM(LParam)
If menupos\x = -1 And menupos\y = -1 ; <-- #VK_APPS key or Shift + F10 pressed
menupos\x = GadgetX(Gadget) + 16
menupos\y = GadgetY(Gadget) + 16
ClientToScreen_(WindowID(Window), @menupos) ; <-- adjust to screen coordinates
EndIf
DisplayPopupMenu(Menu, WindowID(Window), menupos\x + 5, menupos\y)
EndProcedure
OpenWindow(0, 0, 0, 600, 500,"Right Click Edit Gadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreatePopupMenu(#myPopupEdit)
MenuItem(#myMenuEdit1, "Menu Edit 1")
MenuItem(#myMenuEdit2, "Menu Edit 2")
MenuItem(#myMenuEdit3, "Menu Edit 3")
CreatePopupMenu(#myPopupList)
MenuItem(#myMenuList1, "Menu List 1")
EditorGadget(#myEditGadget, 10, 10, 580, 250)
ListViewGadget(#myListGadget, 10, 270, 580, 200)
SetWindowCallback(@WndProc())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #myEditGadget
Select EventType()
Case #MyEventType_ContextMenu
; DisplayPopupMenu(#myPopupEdit, WindowID(0),DesktopMouseX()+5, DesktopMouseY())
ShowPopupMenu(#myPopupEdit, 0, #myEditGadget, EventData()) ; EventData() is LPARAM see above !!!
EndSelect
Case #myListGadget
Select EventType()
Case #MyEventType_ContextMenu
; DisplayPopupMenu(#myPopupList, WindowID(0),DesktopMouseX()+5, DesktopMouseY())
ShowPopupMenu(#myPopupList, 0, #myListGadget, EventData()) ; EventData() is LPARAM see above !!!
EndSelect
EndSelect
EndSelect
ForEver
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).