It is currently Thu May 23, 2013 11:09 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: ButtonGadget and Right Click
PostPosted: Mon Oct 31, 2011 8:19 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 640
Location: Cologne, Germany
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:
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

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
 
 Post subject: Re: ButtonGadget and Right Click
PostPosted: Mon Oct 31, 2011 5:08 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 849
Location: Seattle, USA
Would this help?

_________________
MacBook Pro/Retina, OSX 10.8.3 Mountain Lion, PB-5.11x64


Top
 Profile  
 
 Post subject: Re: ButtonGadget and Right Click
PostPosted: Mon Oct 31, 2011 5:43 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 640
Location: Cologne, Germany
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

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
 
 Post subject: Re: ButtonGadget and Right Click
PostPosted: Mon Oct 31, 2011 6:40 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 814
Location: Germany
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:
#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


Top
 Profile  
 
 Post subject: Re: ButtonGadget and Right Click
PostPosted: Mon Oct 31, 2011 6:48 pm 
Offline
Addict
Addict

Joined: Tue May 06, 2003 5:07 pm
Posts: 2258
Location: UK
Works fine on Lion.


Top
 Profile  
 
 Post subject: Re: ButtonGadget and Right Click
PostPosted: Mon Oct 31, 2011 10:32 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 640
Location: Cologne, Germany
Hey Shardik,

nice work. Runs smoothly :-)
Thanks!

_________________
Regards,
JamiroKwai

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye