The code example for
CreatePopupMenu() in PB's help file contains the Windows API
constant #WM_RButtonDown and therefore doesn't work in PB's Linux and MacOS
versions. I therefore modified that code example for
Linux:
Code: Select all
ProcedureC RightClickHandler(*Event.GdkEventButton, *UserData, *DestroyNotify)
If *Event\type = #GDK_BUTTON_PRESS
If *Event\button = 3 ; Right mouse button?
DisplayPopupMenu(0, WindowID(0)) ; Display the popup-menu if yes
EndIf
EndIf
gtk_main_do_event_(*Event)
EndProcedure
If OpenWindow(0, 200, 200, 200, 120, "Popup-Menu Example")
gdk_event_handler_set_(@RightClickHandler(), 0, 0)
If CreatePopupMenu(0) ; creation of the pop-up menu begins...
MenuItem(1, "Open") ; You can use all commands for creating a menu
MenuItem(2, "Save") ; just like in a normal menu...
MenuItem(3, "Save as")
MenuItem(4, "Quit")
MenuBar()
OpenSubMenu("Recent files")
MenuItem(5, "PureBasic.exe")
MenuItem(6, "Test.txt")
CloseSubMenu()
EndIf
Repeat
Select WaitWindowEvent() ; check for window events
Case #PB_Event_Menu ; an item of the popup-menu was clicked
Select EventMenu() ; get the clicked menu item...
Case 1 : Debug "Menu: Open"
Case 2 : Debug "Menu: Save"
Case 3 : Debug "Menu: Save as"
Case 4 : Quit = 1
Case 5 : Debug "Menu: PureBasic.exe"
Case 6 : Debug "Menu: Text.txt"
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
And this is the modified code example for
MacOS:
Code: Select all
#kEventClassWindow = $77696E64 ; 'wind'
#kEventWindowContextualMenuSelect = 78
Structure EventTypeSpec
EventClass.L
EventKind.L
EndStructure
ProcedureC RightClickHandler(*NextEventHandler, Event.L, UserData.L)
DisplayPopupMenu(0, WindowID(0)) ; now display the popup-menu
EndProcedure
Dim EventTypes.EventTypeSpec(0)
If OpenWindow(0, 200, 200, 200, 120, "Popup-Menu Example")
EventTypes(0)\EventClass = #kEventClassWindow
EventTypes(0)\EventKind = #kEventWindowContextualMenuSelect
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), NewEventHandlerUPP_(@RightClickHandler()), 1, @EventTypes(), 0, 0)
If CreatePopupMenu(0) ; creation of the pop-up menu begins...
MenuItem(1, "Open") ; You can use all commands for creating a menu
MenuItem(2, "Save") ; just like in a normal menu...
MenuItem(3, "Save as")
MenuItem(4, "Quit")
MenuBar()
OpenSubMenu("Recent files")
MenuItem(5, "PureBasic.exe")
MenuItem(6, "Test.txt")
CloseSubMenu()
EndIf
Repeat
Select WaitWindowEvent() ; check for window events
Case #PB_Event_Menu ; an item of the popup-menu was clicked
Select EventMenu() ; get the clicked menu item...
Case 1 : Debug "Menu: Open"
Case 2 : Debug "Menu: Save"
Case 3 : Debug "Menu: Save as"
Case 4 : Quit = 1
Case 5 : Debug "Menu: PureBasic.exe"
Case 6 : Debug "Menu: Text.txt"
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf