highlighting menus in the menu bar on Leopard

  • Hi everyone,

    Our application supports multi-character keyboard shortcuts. Once we
    detect that the user has completed such a shortcut we dispatch the
    action assigned to the NSMenuItem as appropriate. This all still
    works just fine, except for one detail: the top-level menu that
    encompasses the activated item no longer highlights itself so the
    user has some visual feedback on which item was activated.

    Despite using NSMenu's "performActionForItemAtIndex:" we always had
    to do this highlighting manually, using the following code, which
    fails on Leopard:

    @implementation NSMenu (Additions)

    - (void) highlightInMenuBar
    {
      MenuRef ref = _NSGetCarbonMenu( self );
      MenuID menuID = (NULL == ref) ? 0 : GetMenuID( ref );
      HiliteMenu( menuID );
    }

    @end

    I know that "_NSGetCarbonMenu" is an undocumented private API, but
    actually that's not what fails on 10.5, it's the "GetMenuID" call
    that always returns zero. Does anyone know any other way to
    accomplish this highlighting?

    Thanks in advance,

    ~Martin
  • Replying to myself for the sake of the list archives...

    > Does anyone know any other way to accomplish this highlighting?

    The undocumented Objective-C methods on NSMenu and NSMenuItem were a
    dead end, but these undocumented functions ended up doing the trick:

    _NSHighlightCarbonMenu( NSMenu* menu );
    _NSUnhighlightCarbonMenu( NSMenu* menu );

    Although perhaps the best would be to set a unique temporary menu
    equivalent for the item you want to activate and use NSMenu's
    "performKeyEquivalent:", which should do the highlighting for you.

    ~Martin
previous month november 2007 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    
Go to today