Page 1 of 1

Right click on Editor

Posted: Thu May 02, 2024 5:20 am
by es_91
It is still not possible to perform and catch a right click event on an EditorGadget....

PB_EventType_RightClick

Re: Right click on Editor

Posted: Thu May 02, 2024 6:37 am
by BarryG

Re: Right click on Editor

Posted: Wed May 29, 2024 2:40 pm
by flashbob
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

Posted: Wed May 29, 2024 3:28 pm
by mk-soft
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


Re: Right click on Editor

Posted: Wed May 29, 2024 4:18 pm
by Axolotl
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.

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