Menu in cocoa

Discussion in 'Mac Programming' started by jonnyboy0, Feb 8, 2010.

  1. jonnyboy0 macrumors newbie

    jonnyboy0

    Joined:
    Dec 6, 2009
    #1
    Hey

    Well at the moment im experimenting with cocoa & have came to a halt with an idea i had... I have created a menu in cocoa & want to make it appear when i press a certain 2 buttons or when i hold a button n click the mouse...

    The menu currently holds links to webpage favs & has a function to add more links to the menu... I am also currently trying to add more functions such as screenshots, copy n paste etc etc... I plan to use this menu for personal use, but when finished would kindly upload it for others to use also :))

    As i am freshly new to programming on a mac, i am still learning and would like to know if this is possible :? I have ver.1 of the menu almost complete & would really like to have it appear on click, sooo your help will be much appreciated thnx...



    Jonny...
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    NSPopUpButton does this automatically, but if you want more control you can use the various popUpXXX methods in NSMenu (look at the documentation).
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    I assumed (especially from the functions described) that the OP wants to be able to have his menu pop up whenever the special combo is clicked regardless of the current/key application...
     
  4. jonnyboy0 thread starter macrumors newbie

    jonnyboy0

    Joined:
    Dec 6, 2009
    #4
    Yes thats exactly what im trying to do...
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Well that's going to be very hard indeed.

    Edit: or not depending on the compatibility you want/need.

    Snow Leopard only (relatively easy if you understand blocks): addGlobalMonitorForEventsMatchingMask:handler:

    Older OS included: CGEventTap (search yourself). This seems to be difficult to get working correctly...
     
  6. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #6
    Or you could just lock it in place as the first responder (probably through subclassing the window if you need to determine what the next responder should be), then have it pass any keystrokes that are not of interest on to the next responder.
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    That won't work in the situations I described: when the OPs app is not foremost. The solution he wants is to capture the events whenever any app has focus...
     

Share This Page