Page 1 of 1

ButtonGadget and Right Click

Posted: Mon Oct 31, 2011 8:19 am
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

Re: ButtonGadget and Right Click

Posted: Mon Oct 31, 2011 5:08 pm
by WilliamL
Would this help?

Re: ButtonGadget and Right Click

Posted: Mon Oct 31, 2011 5:43 pm
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.

Re: ButtonGadget and Right Click

Posted: Mon Oct 31, 2011 6:40 pm
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

Re: ButtonGadget and Right Click

Posted: Mon Oct 31, 2011 6:48 pm
by Polo
Works fine on Lion.

Re: ButtonGadget and Right Click

Posted: Mon Oct 31, 2011 10:32 pm
by jamirokwai
Hey Shardik,

nice work. Runs smoothly :-)
Thanks!