PDA

View Full Version : NSWindow focus




ajbrehm
Aug 27, 2008, 04:53 AM
I have an application with two XIB files.

One contains an NSWindow that is displayed when a certain menu item is clicked in the menu defined by the XIB file.

This works.

However, the new window doesn't have focus and none of the methods like makeKeyWindow etc. seem to change that fact when called. How do I change the focus to another window?

Also, how can I make an NSWindow modal?

Thanks in advance.



ajbrehm
Aug 27, 2008, 09:07 AM
Turns out there is a NSApplication runModalForWindow: method that makes an NSWindow modal. I just have to look around for my NSApplication object. main() probably created one, probably NSApp or so.

From the documentation:


runModalForWindow:

Starts a modal event loop for a given window.

- (NSInteger)runModalForWindow:(NSWindow *)aWindow
Discussion

Until the loop is broken by a stopModal, stopModalWithCode:, or abortModal message, the application won’t respond to any mouse, keyboard, or window-close events unless they’re associated with aWindow.


I still don't know how to set focus to the window though.

HiRez
Aug 27, 2008, 11:35 AM
I assume you mean makeKeyAndOrderFront? That should work. Make sure your connection is made and that the window is valid just before you try to make that call. But yes, if you started a modal window somewhere, that'll probably block it.

ajbrehm
Aug 27, 2008, 11:42 AM
I assume you mean makeKeyAndOrderFront? That should work. Make sure your connection is made and that the window is valid just before you try to make that call. But yes, if you started a modal window somewhere, that'll probably block it.

I tried makeKeyAndOrderFront but that didn't change anything. The window was in front of the other window but didn't have focus (and didn't get it from makeKeyAndOrderFront either).

The connection is made and the window is valid and I can interact with it otherwise.

ajbrehm
Aug 28, 2008, 03:40 AM
Turns out the only interaction that works is closing the window and having the delegate react to it.

I cannot write text into textfields and none of the methods to focus the window (or change its order or whatever) have any effect.

The connections between the class and the xib file are all set up.

Is there anything else I have to do?

I found a few Web pages that explain how to load a window from a second nib file but they are end when they finished explaining what I figured out myself, how to load the nib file and display the window in it. None continue explaining how to interact with the window.

The connections I defined and connected don't work. Any ideas?

kainjow
Aug 28, 2008, 04:00 AM
Is the window a borderless window, or a normal window? Can you post a screenshot? Also make sure your other window doesn't have the "Visible at launch" checkbox enabled in IB.

ajbrehm
Aug 28, 2008, 06:35 AM
Is the window a borderless window, or a normal window? Can you post a screenshot? Also make sure your other window doesn't have the "Visible at launch" checkbox enabled in IB.

I can post a screenshot later.

The other window probably has "Visible at launch" set, since it is the main window and supposed to be visible at launch.

Both windows are normal windows and can be resized and minimised.