Right click Editor Gadget
Right click Editor Gadget
How do I detect if right click event has happened on an editor gadget? I only want the popup menu to show if the mouse is over the editor.
- BasicallyPure
- Enthusiast
- Posts: 536
- Joined: Thu Mar 24, 2011 12:40 am
- Location: Iowa, USA
Re: Right click Editor Gadget
The editor gadget does not support right click events.
If you are using windows you can generate them like this.
If you are using windows you can generate them like this.
Code: Select all
#MainWin = 0
#EdGad = 1
#PopMenu = 2
#MenuItemQuit = 3
Procedure WinCallback(hWnd, uMsg, WParam, LParam)
If WParam = #WM_RBUTTONDOWN
If GetActiveGadget() = #EdGad
PostEvent(#PB_Event_Gadget, #MainWin, #EdGad, #PB_EventType_RightClick)
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(#MainWin,0,0,800,600,"", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowColor(#MainWin,$F9F1CC)
SetWindowCallback(@WinCallback())
EditorGadget(#EdGad,10,10,600,400)
CreatePopupMenu(#PopMenu)
MenuItem(#MenuItemQuit,"Quit")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #EdGad
If EventType() = #PB_EventType_RightClick
DisplayPopupMenu(#PopMenu,WindowID(#MainWin))
EndIf
EndSelect
Case #PB_Event_Menu
If EventMenu() = #MenuItemQuit
Break
EndIf
EndSelect
ForEver
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
Until you know everything you know nothing, all you have is what you believe.
Re: Right click Editor Gadget
A cross-platform example:
http://www.purebasic.fr/english/viewtop ... 68&start=6
http://www.purebasic.fr/english/viewtop ... 68&start=6
Re: Right click Editor Gadget
Thanks for the replies. I would have thought it should be included in PureBasic. It was the first program I ever made and it was a simple one, click a button to generate some text in an editor.
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Right click Editor Gadget
Hi BasicallyPure,
thank you for the code. It works fine here on Windows 10.
However, when using it with an EditorGadget that is inside a PanelGasget, it does not work as expected: After clicking at a context menu item, the intended action does not take place, but the contect menu appears again instead. And when clicking again at the same menu item, then the intended action is performed twice, if possible -- not possible in this example with "Break", but try with
To demonstrate the issue, please see the following code, that contains only 2 additional lines.
Does anyone know how to solve the problem?
thank you for the code. It works fine here on Windows 10.
However, when using it with an EditorGadget that is inside a PanelGasget, it does not work as expected: After clicking at a context menu item, the intended action does not take place, but the contect menu appears again instead. And when clicking again at the same menu item, then the intended action is performed twice, if possible -- not possible in this example with "Break", but try with
Code: Select all
SendMessage_(GadgetID(#EdGad), #WM_PASTE, 0, 0)
Does anyone know how to solve the problem?
Code: Select all
#MainWin = 0
#EdGad = 1
#PopMenu = 2
#MenuItemQuit = 3
Procedure WinCallback(hWnd, uMsg, WParam, LParam)
If WParam = #WM_RBUTTONDOWN
If GetActiveGadget() = #EdGad
PostEvent(#PB_Event_Gadget, #MainWin, #EdGad, #PB_EventType_RightClick)
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(#MainWin,0,0,800,600,"", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowColor(#MainWin,$F9F1CC)
SetWindowCallback(@WinCallback())
PanelGadget(0, 10, 10, 600, 400) ; <= added
AddGadgetItem(0, 1, "new") ; <= added
EditorGadget(#EdGad,0,0,600,400)
CreatePopupMenu(#PopMenu)
MenuItem(#MenuItemQuit,"Quit")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #EdGad
If EventType() = #PB_EventType_RightClick
DisplayPopupMenu(#PopMenu,WindowID(#MainWin))
EndIf
EndSelect
Case #PB_Event_Menu
If EventMenu() = #MenuItemQuit
Break
EndIf
EndSelect
ForEver
Re: Right click Editor Gadget
Hi Little John, try out this solution:
Code: Select all
#MainWin = 0
#EdGad = 1
#PopMenu = 2
#MenuItemQuit = 3
Procedure EditorCallback(hwnd, msg, wparam, lparam)
Shared oldproc
Protected result = CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
If msg = #WM_RBUTTONDOWN
PostEvent(#PB_Event_Gadget, #MainWin, #EdGad, #PB_EventType_RightClick)
EndIf
ProcedureReturn result
EndProcedure
OpenWindow(#MainWin,0,0,800,600,"", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowColor(#MainWin,$F9F1CC)
PanelGadget(220, 10, 10, 600, 400) ; <= added
AddGadgetItem(220, 1, "new") ; <= added
EditorGadget(#EdGad,0,0,600,400)
oldproc = SetWindowLongPtr_(GadgetID(#EdGad), #GWL_WNDPROC, @EditorCallback())
CreatePopupMenu(#PopMenu)
MenuItem(#MenuItemQuit,"Quit")
Repeat
e = WaitWindowEvent()
Select e
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #EdGad
If EventType() = #PB_EventType_RightClick
DisplayPopupMenu(#PopMenu,WindowID(#MainWin))
EndIf
EndSelect
Case #PB_Event_Menu
If EventMenu() = #MenuItemQuit
Break
EndIf
EndSelect
Forever
Re: Right click Editor Gadget
Hi
BasicallyPure not active for long time
Try
BasicallyPure not active for long time
Try
Code: Select all
#MainWin = 0
#EdGad = 1
#PopMenu = 2
#MenuItemQuit = 3
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_CONTEXTMENU
Select wParam
Case GadgetID(#EdGad)
DisplayPopupMenu(0, WindowID(0))
EndSelect
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(#MainWin,0,0,800,600,"", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowColor(#MainWin,$F9F1CC)
SetWindowCallback(@WinCallback())
PanelGadget(0, 10, 10, 600, 400) ; <= added
AddGadgetItem(0, 1, "new") ; <= added
EditorGadget(#EdGad,0,0,600,400)
If CreatePopupMenu(0)
MenuItem(1, "Cut")
MenuItem(2, "Copy")
MenuItem(3, "Paste")
MenuBar()
OpenSubMenu("Options")
MenuItem(4, "Window...")
MenuItem(5, "Gadget...")
CloseSubMenu()
MenuBar()
MenuItem( 6, "Quit")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu() ; To see which menu has been selected
Case 1 ; Cut
SendMessage_(GadgetID(#EdGad),#WM_CUT,0,0)
Case 2 ; Copy
SendMessage_(GadgetID(#EdGad),#WM_COPY,0,0)
Case 3 ; Paste
SendMessage_(GadgetID(#EdGad),#WM_PASTE,0,0)
Case 6 ; Quit
Q = 1
EndSelect
EndSelect
Until Q = 1
Egypt my love
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Right click Editor Gadget
Hi firace and RASHAD,
both of your solutions work like a charm here!
Now I can add a context menu to my program.
THANK YOU VERY MUCH!
both of your solutions work like a charm here!
Now I can add a context menu to my program.
THANK YOU VERY MUCH!