Page 1 of 1
EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 10:21 am
by marcoagpinto
Hello!
I noticed some time ago that in EditorGadgets one can't right-click to select copy/cut/paste.
Is there a special flag for it, or is it a bug?
Thanks!
Kind regards,
>Marco A.G.Pinto
---------------
Re: EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 11:34 am
by IdeasVacuum
Hi Marco
You need to define your own pop-up menu for that task:
http://www.purebasic.fr/english/viewtop ... 13&t=56027
Re: EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 2:07 pm
by marcoagpinto
Buaaaaaaaa... I want to cry.... even the forum EditorGadget allows the popup menu... how can it need me to code it for PB?

Re: EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 3:15 pm
by Shardik
All in all it's not so difficult although it requires a window callback (or to subclass the Editor Gadget) and therefore is not cross-platform and only works on Windows. I even used PostEvent() to generate a #PB_EventType_RightClick that can be detected as a right click in your main event loop:
Code: Select all
EnableExplicit
Define EditorID.I
Define WindowID.I
Enumeration MenuItems
#MenuCut
#MenuCopy
#MenuPaste
EndEnumeration
Procedure WindowCallback(WindowHandle.I, Msg.I, WParam.I, LParam.I)
Shared EditorID.I
Shared WindowID.I
If Msg = #WM_CONTEXTMENU
If WParam = GadgetID(EditorID)
PostEvent(#PB_Event_Gadget, WindowID, EditorID, #PB_EventType_RightClick)
EndIf
ProcedureReturn 0
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
WindowID = OpenWindow(#PB_Any, 100, 100, 300, 190, "Display context menu on right click")
SetWindowCallback(@WindowCallback(), WindowID)
EditorID = EditorGadget(#PB_Any, 10, 10, 280, 170)
; ----- Create popup menu
If CreatePopupMenu(0)
MenuItem(#MenuCut, "Cut")
MenuItem(#MenuCopy, "Copy")
MenuItem(#MenuPaste, "Paste")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
Case #MenuCut
SendMessage_(GadgetID(EditorID), #WM_CUT, 0, 0)
Case #MenuCopy
SendMessage_(GadgetID(EditorID), #WM_COPY, 0, 0)
Case #MenuPaste
SendMessage_(GadgetID(EditorID), #WM_PASTE, 0, 0)
EndSelect
Case #PB_Event_Gadget
If EventGadget() = EditorID
If EventType() = #PB_EventType_RightClick
DisplayPopupMenu(0, WindowID(WindowID))
EndIf
EndIf
EndSelect
ForEver
Re: EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 5:50 pm
by RASHAD
Simplify things for windows
Code: Select all
OpenWindow(0, 100, 100, 300, 190, "Display context menu on right click", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 280, 170)
; ----- Create popup menu
If CreatePopupMenu(0)
MenuItem(1, "Cut")
MenuItem(2, "Copy")
MenuItem(3, "Paste")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
Case 1
SendMessage_(GadgetID(0), #WM_CUT, 0, 0)
Case 2
SendMessage_(GadgetID(0), #WM_COPY, 0, 0)
Case 3
SendMessage_(GadgetID(0), #WM_PASTE, 0, 0)
EndSelect
Case #WM_RBUTTONDOWN
DisplayPopupMenu(0, WindowID(0))
EndSelect
ForEver
Re: EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 6:30 pm
by Shardik
Nice one RASHAD, much shorter and easier. But you still have to add a check whether it was the EditorGadget which was right-clicked. In your current example there will also be displayed a context menu when when right-clicking beneath the EditorGadget (or on other gadgets in a form with several gadgets)...

Code: Select all
Case #WM_RBUTTONDOWN
If EventGadget() = 0
DisplayPopupMenu(0, WindowID(0))
EndIf
Re: EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 7:50 pm
by Shardik
marcoagpinto wrote:Buaaaaaaaa... I want to cry.... even the forum EditorGadget allows the popup menu... how can it need me to code it for PB?

It's only a little bit more complicated in Windows! In Linux and MacOS X it works automagically as you would expect...
I have taken RASHAD's example and set the Windows specific stuff in CompilerIf...CompilerEnd blocks. Then I have tested the following example successfully with PB 5.31 on these operating systems:
- Kubuntu 14.04 x64
- MacOS X 10.6.8 (Snow Leopard)
- Windows 7 SP1 x64
In the following snapshots you can see that the context menus on Linux and MacOS X differ from our simple Windows popup menu by offering further selectable options.
Kubuntu 14.04:
MacOS X 10.6.8:
Windows 7:
Code: Select all
OpenWindow(0, 100, 100, 300, 190, "Display context menu on right click")
EditorGadget(0, 10, 10, 280, 170)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If CreatePopupMenu(0)
MenuItem(0, "Cut")
MenuItem(1, "Copy")
MenuItem(2, "Paste")
EndIf
CompilerEndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Case #PB_Event_Menu
Select EventMenu()
Case 0
SendMessage_(GadgetID(0), #WM_CUT, 0, 0)
Case 1
SendMessage_(GadgetID(0), #WM_COPY, 0, 0)
Case 2
SendMessage_(GadgetID(0), #WM_PASTE, 0, 0)
EndSelect
Case #WM_RBUTTONDOWN
If EventGadget() = 0
DisplayPopupMenu(0, WindowID(0))
EndIf
CompilerEndIf
EndSelect
ForEver
Re: EditorGadget bug (copy/cut/paste)?
Posted: Tue Sep 08, 2015 10:28 pm
by marcoagpinto
Can't Fred code it into PB?
Thanks!