ButtonGadget and Right Click

Mac OSX specific forum
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

ButtonGadget and Right Click

Post by jamirokwai »

Hi there,

has andybody succeeded in fetching an eventtype of #PB_EventType_RightClick when using ButtonGadgets on the Mac?
I hoped, this snippet would display the PopUp-Menu when clicking right on the button :-(

The docs say, ButtonGadget is not supported (yet?). Hopefully, it will be soon.
Otherwise, I need to use an ImageGadget, I assume?

Code: Select all

OpenWindow(0,100,100,400,400,"TEST")
ButtonGadget(0,10,10,380,380,"CLICK ME!")

Repeat
  Event = WaitWindowEvent(25)
  Gadget = EventGadget()
  EventTyp = EventType()
  If Event = #PB_Event_Gadget
    If EventTyp = #PB_EventType_RightClick ; does not work
      If CreatePopupMenu(0)
        MenuItem(1, "test")
        DisplayPopupMenu(0,WindowID(0))
      EndIf
    EndIf
    If EventTyp = #PB_EventType_LeftClick
      End
    EndIf
  EndIf
ForEver
Regards,
JamiroKwai
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: ButtonGadget and Right Click

Post by WilliamL »

Would this help?
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: ButtonGadget and Right Click

Post by jamirokwai »

WilliamL wrote:Would this help?
No, but thanks for the hint.
The example crashes PB on OS X Lion.

I probably have to rewrite some portions and use an ImageGadget.
Regards,
JamiroKwai
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ButtonGadget and Right Click

Post by Shardik »

jamirokwai wrote:
WilliamL wrote:Would this help?
No, but thanks for the hint.
The example crashes PB on OS X Lion.

I probably have to rewrite some portions and use an ImageGadget.
WilliamL should be right. His link to my example should work for you in Lion
if you change Procedure to ProcedureC... :wink:

Nevertheless I even customized your example to detect a right mouse button
click. Unfortunately I can't test it on Lion. And I won't upgrade to Lion as long
as Rosetta can't be installed in Lion to run old PowerPC programs...:wink: :

Code: Select all

#kEventClassControl = 'cntl'
#kEventControlContextualMenuClick = 12

Structure EventTypeSpec
  EventClass.L
  EventKind.L
EndStructure

ProcedureC EventHandler(*NextEventHandler, Event.L, UserData.L)
  Shared RightMouseButtonClick.I

  RightMouseButtonClick = #True

  If *NextEventHandler
    CallNextEventHandler_(*NextEventHandler, Event)
  EndIf
EndProcedure

Define RightMouseButtonClick.I

Dim EventTypes.EventTypeSpec(1)

OpenWindow(0,100,100,400,400,"TEST")
ButtonGadget(0,10,10,380,380,"CLICK ME!")
CreatePopupMenu(0)
MenuItem(1, "Option 1")
MenuItem(2, "Option 2")
MenuItem(3, "Quit")

; ----- Install EventHandler for each Gadget that should detect right clicks

EventTypes(0)\EventClass = #kEventClassControl
EventTypes(0)\EventKind = #kEventControlContextualMenuClick
InstallEventHandler_(GetControlEventTarget_(GadgetID(0)), NewEventHandlerUPP_(@EventHandler()), 1, @EventTypes(), GadgetID(0), 0)

Repeat
  Event = WaitWindowEvent()
  Gadget = EventGadget()
  EventTyp = EventType()

  Select Event
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventTyp = #PB_EventType_LeftClick
        Break
      EndIf
    Case #PB_Event_Menu
      Select EventMenu()
        Case 1
          Debug "Menu: Option 1"
        Case 2
          Debug "Menu: Option 2"
        Case 3
          Break
      EndSelect
  EndSelect

  If RightMouseButtonClick
    DisplayPopupMenu(0, WindowID(0))
    RightMouseButtonClick = #False
  EndIf
ForEver
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: ButtonGadget and Right Click

Post by Polo »

Works fine on Lion.
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: ButtonGadget and Right Click

Post by jamirokwai »

Hey Shardik,

nice work. Runs smoothly :-)
Thanks!
Regards,
JamiroKwai
Post Reply