Hello all,

Executive summary: I have an NSTextField in an NSPanel which, under certain circumstances, doesn't receive mouseDowns anymore. Specifically, this happens after I end editing with Enter (instead of Tab)

Background: I am using NSPanel to make a "tool window" for my app. This window contains a few buttons, sliders, and an NSTextField. I wanted this window to avoid becoming key, so that the user can select a new tool on this window without her main window losing focus and her having to select it again. I managed to get the right behavior by overriding canBecomeKeyWindow and returning NO. All buttons and sliders were fully operable this way.

Until I added an NSTextField, which obviously needs its containing window to be the key window to work. I couldn't get this combination of requirements implemented successfully, so I solved it partially by making my own textfield and panel subclasses; when the textfield gets a mouseDown, I send a "focusRequested" message to its panel, which then sets a boolean ivar, like so:

- (BOOL)canBecomeKeyWindow {
        return m_focusRequested;
}

- (void)requestFocus {
        m_focusRequested = YES;
}

- (void)resignFocus {
        m_focusRequested = NO;
}

In the textfield, when it gets a textDidEndEditing message, I send "resignFocus" to the panel. This works.

But: if I cause editing to end by pressing the Enter key (instead of Tab), and then give another window the focus, clicking on the textfield doesn't cause a mouseDown to be receive anymore. The contents of the textfield stay selected (the focus ring is, of course, gone). Therefore, my panel keeps returning NO from canBecomeKeyWindow because it never got a focusRequested message.

Apologies for the long post, but I wanted to make sure I'm approaching this the right way.

I also overrode acceptsFirstMouse in my textfield, returning YES, but that doesn't make a difference.

Thanks for any insights,
regards,
Sander

_______________________________________________

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

Reply via email to