Non-Contextual Popup Menus using NSPopupButtonCell and attachPopupWithFrame or performClickWithFrame

  • Reading through the documentation regarding contextual popup menus, Apple
    notes that the prefered method of popping up a non-contextual menu is using
    an NSPopupButtonCell and using the attachPopupWithFrame:inView method.

    After attempting this on my own with little luck, and browing Google, I
    found that others had issues with using attachPopupWithFrame:inView, and
    suggested to use performClickWithFrame:inView instead.  Specifically, when
    using the former, no menu appears at all.  With the latter, the menu pops
    up, but it does not appear at the position of the mouse pointer.  Instead,
    the menu appears to popup at roughtly the right horizontal position on
    screen, but always at the bottom edge of the view.

    The particular situation I have is an NSTextView that is subclassed, which
    occasionally includes text formated as a link with a custom-handled link
    object.  When the link is clicked, a menu is generated based on the details
    of the link and popped up.

    Is there any way to have this menu pop up at the position of the mouse
    pointer?  Has anyone had success using attachPopupWithFrame:inView rather
    than performClickWithFrame:inView?

    Any help would be greatly appreciated!

    Thanks,
    Oliver Kurek
  • On Jan 8, 2008, at 6:52 AM, Oliver Kurek wrote:

    > Reading through the documentation regarding contextual popup menus,
    > Apple
    > notes that the prefered method of popping up a non-contextual menu
    > is using
    > an NSPopupButtonCell and using the attachPopupWithFrame:inView method.
    >
    > After attempting this on my own with little luck, and browing
    > Google, I
    > found that others had issues with using
    > attachPopupWithFrame:inView, and
    > suggested to use performClickWithFrame:inView instead.
    > Specifically, when
    > using the former, no menu appears at all.  With the latter, the
    > menu pops
    > up, but it does not appear at the position of the mouse pointer.
    > Instead,
    > the menu appears to popup at roughtly the right horizontal position on
    > screen, but always at the bottom edge of the view.
    >
    > The particular situation I have is an NSTextView that is
    > subclassed, which
    > occasionally includes text formated as a link with a custom-handled
    > link
    > object.  When the link is clicked, a menu is generated based on the
    > details
    > of the link and popped up.
    >
    > Is there any way to have this menu pop up at the position of the mouse
    > pointer?  Has anyone had success using attachPopupWithFrame:inView
    > rather
    > than performClickWithFrame:inView?
    >
    > Any help would be greatly appreciated!

    Hi Oliver,

    With performClickWithFrame: inView:, the menu will pop up as if a
    popup button were positioned within the frame parameter, interpreted
    as a rect within the bounds coordinate space of the given view.  To
    pop up a menu where the user clicked, pass a 1x1 rect whose origin is
    the location of the event within the bounds of your view, as the
    frame parameter.

    I hope that's clear,
    -Peter
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today