NSPanel and stopModal - how to focus on the main window again?
NSPanel and stopModal - how to focus on the main window again?
- Subject: NSPanel and stopModal - how to focus on the main window again?
- From: Keith Blount <email@hidden>
- Date: Thu, 2 Dec 2004 05:24:28 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello,
I want to use a modal panel for my app, but am having
some problems getting it working right, and I don't
understand why. The panel is used for resizing
pictures inside a text view.
This is how I start my panel - this code is contained
inside the mouseDown: method of a subclass of
NSTextView, just after checking for a double-click on
an image:
[NSApp runModalForWindow:resizePanel];
(resizePanel is a pointer to an NSPanel.)
And this is how I end my panel (this action is also
contained in the text view subclass, and connected to
a button on the panel):
- (IBAction)closeResizePanel:(id)sender
{
[resizePanel orderOut:self];
[NSApp stopModal];
}
But the problem is that once the panel closes, the
main window containing the text view does not have the
focus properly. In fact, it acts very oddly. The
selection in the text view is still blue as though it
has focus, but when you type, nothing happens. If you
then click into the text view, the text is updated.
This continues to happen until you click onto the
window itself, at which point everything returns to
normal - as though the window needs to be reminded to
work properly. Also, whilst it is acting strangely, if
you switch to another app and then back again, the
main window is not visible. You have to click into the
menu to return everything to normal (this is not a
document based app).
But if I use a sheet instead of a modal panel, like
this:
[NSApp beginSheet:resizePanel
modalForWindow:[self window]
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
- (IBAction)closeResizePanel:(id)sender
{
[resizePanel orderOut:self];
[NSApp endSheet:resizePanel returnCode:1];
}
Everything works fine - the window and NSTextView get
the focus correctly again when the sheet is closed.
The trouble is that a sheet is no good in this
situation, as it may pop up directly over the picture
that the user is trying to resize - a panel is
required so that the user can move it around and get a
good view of the image. And the panel has to be modal
because if the user is allowed to continue using the
text view, the panel may lose the reference to the
image it is resizing (because the user could move the
image).
I have tried everything I can think of to fix this -
such as doing a [[self window]
makeKeyAndOrderFront:self] in an attempt to get focus
back properly), but just cannot seem to resolve this.
If anybody could tell me what I am doing wrong, I
would be very grateful.
Many thanks,
Keith
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden