Re: Set focus on NSView in an NSMenuItem
Re: Set focus on NSView in an NSMenuItem
- Subject: Re: Set focus on NSView in an NSMenuItem
- From: Lieven Dekeyser <email@hidden>
- Date: Fri, 15 Feb 2008 13:55:47 +0100
On 06 Feb 2008, at 11:38, Pierre Bernard wrote:
Hi Ron!
It appears that both work. I guess it depends on whether you add the
semi-colon to the selector or not.
The timer was only a wild idea on how to work around the original
problem with the window's field editor. I got the timer to work, but
it does not solve the original problem.
I had the same problem and I solved it more or less with the following
approach:
- use a custom view for the NSStatusItem. Using the standard setMenu
approach, all sorts of redrawing and focus issues occur.
- when a mouse click occurs in the NSStatusItem's view, I bring the
application to front using [NSApp activateIgnoringOtherApps:YES]
(because the application isn't necessarily the frontmost application
when the NSStatusItem is clicked) and start a timer to fire after 0.01
seconds
- In the timer action, I pop up the menu, which causes the delegate
method menuWillOpen to be called.
- When the menu is being opened, I call [[self window]
makeFirstResponder:textField] in the viewDidMoveToWindow method of the
NSMenuItem's view (a custom view with a text field in it)
- in menuWillOpen and menuDidClose I redraw the NSStatusItem's view
using -drawStatusBarBackgroundInRect:withHighlight:
So to recap, I needed:
- A custom view for the NSStatusItem which fakes the standard view
- A custom view for the NSMenuItem that tries to make the text field
the first responder
- All sorts of dirty hacks just to make sure the menu isn't popped up
before the view is able to get focus
As I said, this solves the problem "more or less". There are still
redrawing issues, especially when the menu is longer than the screen
height. But at least the view gets focus. And I think I might be able
to solve the redrawing issues by calling needsDisplay after every
event in the textfield, but still..
Surely, there must be a better way to do this? I'm not sure these
hacks will continue to work..
Apple?
--Lieven
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden