Hi Jerry,
On Apr 24, 2009, at 5:41 AM, Jerry Krinock wrote:
I'm creating an NSPopUpButtonCell programatically.
To show the menu I invoke -[NSPopUpButtonCell
performClickWithFrame:inView:]. It works -- however after the menu
has popped up, been clicked and dismissed,
- Timers in the main thread stop firing
- Keyboard equivalents fail silently
Operation does not return to normal until the user clicks another
control TWICE. It seems to me that the UI is "sleeping" and that
the first click is necessary to "wake" it.
Is there a name for this state when the UI is "sleeping"? Maybe if
I knew that I could research how to fix it. Of course, a fix would
be appreciated too :)
This has to do with run loop modes. Check out the documentation on
run loops, their various modes, and what they're used for at http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html
While menus are open, the run loop runs in
NSEventTrackingRunLoopMode. This is normally desirable - you don't
want, say, an important dialog to pop up right before you choose Close
Window. This run loop mode is also used, for example, when dragging a
slider or when you click (but don't release) on a button.
When you explicitly add a timer or source to a run loop, you have the
opportunity to specify a mode. If you specify
NSEventTrackingRunLoopMode, then your timer will be active during menu
tracking. You can add it to multiple modes.
I guessed that the popup menu may still be "tracking" the mouse
(although I don't really know what that means). However, invoking -
cancelTracking does not help.
I would expect cancelTracking to close the menu. Hopefully that's
what you saw!
Also, invoking -attachPopUpWithFrame:inView: before
performClickWithFrame:: does not help either. (I've never been able
to find an explanation of what -attachPopUpWithFrame:inView: is
supposed to do. As far as I can see it's a no-op.)
This method is mainly a holdover from NeXT menus, and isn't good for
much. If you want to pop up a popup button, you can use either
performClick: or trackMouse:inRect:ofView:untilMouseUp:
-Peter
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com