Thank you for your kind words about me, Ray. But the only one justified to be designated as "MacOS Master" is Wilbert who programmed the CocoaMessage() function in Objective-C which Fred then integrated in PureBasic. This CocoaMessage() function allows other MacOS programmers to utilize the huge object oriented Cocoa framework with ease in procedural PureBasic programs!
Unfortunately your posted link is an old example using the deprecated Carbon framework (the last PureBasic version to support the Carbon framework as a subsystem was 5.11 x86). The following example uses the Cocoa framework and detects a left and right click. I have tested this example successfully on
- MacOS 10.6.8 'Snow Leopard' with PB 5.62 x86
- MacOS 10.13.4 'High Sierra' with PB 5.62 x86 and x64
Code: Select all
EnableExplicit
Define CurrentEvent.I
Define EventType.I
Define Point.NSPoint
Define SharedApplication = CocoaMessage(0, 0, "NSApplication sharedApplication")
Define View.I
OpenWindow(0, 270, 100, 270, 60, "Detect right click onto button")
ButtonGadget(0, 20, 20, 230, 25, "Click me with left or right button!")
Repeat
CurrentEvent = CocoaMessage(0, SharedApplication, "currentEvent")
If CurrentEvent
EventType = CocoaMessage(0, CurrentEvent, "type")
; ----- Check if right mosue button was clicked and released
If EventType = #NSRightMouseUp
; ----- Check if our button was clicked
CocoaMessage(@Point, CurrentEvent, "locationInWindow")
View = CocoaMessage(0, CocoaMessage(0, WindowID(0), "contentView"),
"hitTest:@", @Point)
If View = GadgetID(0)
Debug "Right click on button"
EndIf
EndIf
EndIf
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0
If EventType() = #PB_EventType_LeftClick
Debug "Left click on button"
EndIf
EndIf
EndSelect
ForEver