tracking mouse state outside of a view

  • I'm implementing a custom NSView to use as the view of a NSStatusItem.

    The custom view can hold an image and/or a title, just like the
    standard NSStatusItem does.

    I can detect left/right mouse-down/up clicks in this NSView. When I
    detect a mouse down in my custom view, I set the state such that when
    I draw the custom view, I can draw it with the highlight background
    color and change the foreground text to white, to emulate what the
    standard NSStatusItem does.

    However, I don't know how to get notified when the mouse is clicked
    elsewhere. In a normal NSStatusItem, if it's displaying a menu, when
    the user clicks the mouse anywhere else, such as in a Window or menu,
    etc, the menu displayed for the NSStatusItem is dismissed, and the
    highlighting goes back to normal.

    Right now, the only way I can detect this end-of-menu tracking is
    when I click back in my custom view, but obviously this isn't going
    to help me.

    So how do I find out if the mouse gets clicked elsewhere when I'm in
    the "drawing highlight" state, so I can go back to "drawing
    unhighlighted" state.

    Thanks,

    Rob Ross, Lead Software Engineer
    E! Networks
    ---------------------------------------------------
    "Beware of he who would deny you access to information, for in his
    heart he dreams himself your master." -- Commissioner Pravin Lal
  • Am 17.10.2006 um 22:21 schrieb Rob Ross:
    > Right now, the only way I can detect this end-of-menu tracking is
    > when I click back in my custom view, but obviously this isn't going
    > to help me.
    >
    > So how do I find out if the mouse gets clicked elsewhere when I'm
    > in the "drawing highlight" state, so I can go back to "drawing
    > unhighlighted" state.

      How are you displaying your menu? Usually, a menu should close
    automatically (it will even send you a
    NSMenuDidEndTrackingNotification once it's finished tracking, is that
    what you're looking for?). If what you're doing is not a real menu,
    you could probably create a transparent borderless overlay window
    that will catch the click so you can hide your fake menu.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
previous month october 2006 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