Preserving window position in Interface Builder - cocoa

Is there a way to preserve window position in Interface Builder? Every time I reopen a nib file, the MainWindow.xib window finds its way back to the top left of the screen, behind the window containing the interface I'm laying out. Moving it back to where I had it before every time is starting to get on my nerves. Seems like there should be an easy way to do this, but if there is I haven't been able to find it.
Thanks!

Interface Builder does not save window location/size on a per-nib basis, but it does automatically remember the size and position of the last nib window and uses that when opening future nib files. For example, if I open up nib file A, change its window's position, and then quit IB, then open up nib file B, its nib window shows up with the same location/size I had set for nib file A.
However, it appears that Interface Builder also cascades multiple windows down and to the right slightly when you open them up, so that a second nib file's window doesn't appear directly on top of one that's already open - makes sense. The problem appears to be that if you have a nib window positioned all the way at the bottom of the screen, so there's not enough room to open the next nib window, it results in the window being placed all the way at the top of the screen. Then of course once that happens, IB remembers that window position as the default, so subsequent windows also get opened at the top of the screen.
So, the "solution" is a) file an enhancement request on Bug Reporter to remember per-nib window positions :-), and b) in the meantime be careful about positioning your windows too close to the bottom of the screen.

Related

Can I prevent NSDocument from saving window positions?

I've looked through the NSDocuments docs but can't see any methods for controlling whether window positions are saved. But if I move a window before quitting, that position overrides the window position set in IB.
In your XIB file, select the window. You should see the options on the right of the screen.
The "Restorable" check box should be what you're looking for. I haven't tried this in a document based application but I'm pretty sure it's the same here.

OS X Lion: Fullscreen NSWindow Bait & Switch

I currently have a NSWindow that allows for full screen. The window has a video player and a playlist below it. When the user goes fullscreen, I want to get rid of the playlist and just show the video.
My first thoughts for doing this is to swap out the window when I detect a fullscreen entry point. I have found that I can detect this with the following:
- (void)windowWillEnterFullScreen:(NSNotification *)notification
{
NSLog(#"My window is going fullscreen");
}
But I have been unable to figure out how to swap out the window for a new one at this point. One option I haven't yet attempted would be to modify all of the resizing flags of the video and hide the other components but I'm not certain if this would be the best solution.
Does anyone have any suggestions on a better way for doing this?
Why do you want to swap the window? Just manipulate the views in the window.
Just remove the playlist from your view when you go fullscreen with -removeFromSuperview and then resize the video view so that it fills your window.
Make sure you hold a reference to the view as an ivar somewhere, because otherwise the view will be deallocated. You can then use that reference to add the view back when the window exits full-screen mode.

Cocoa/Objective-C - Child window with text input without main window becoming inactive

I have a need to spawn a window that will hover just above my main window in a cocoa application. I want this main window to allow the user to enter some text in an input box. All is well until the text input box actually gains focus. The main window becomes "deactivated." This window is borderless and is a slightly custom shape -- its more like a hover card than anything else, I suppose.
Basically, I'd like this thing to work almost exactly like Spotlight (Apple + Space) -- you can enter text, but this is such an an ancillary operation that in the context of the greater UX, you don't want the jarring effect of the main window graying out (becoming inactive). You'll notice when you have some application open and in-focus, spotlight will not cause the window of that application to become inactive.
This problem arises because text input seems to REQUIRE that the child window become the key window (it will not let you place the cursor in the text input field). When it becomes key, the main window becomes inactive.
So far I've tried:
Subclassing NSWindow for my main application and overriding isKeyWindow such that it only loses key when the application is no longer the users focus (as opposed to the window). This had the unintended effect of colliding with key status of the child window and having very strange effects on the keyboard input (some keys are not captured, like delete)
Creating a view instead of a window. Doesn't work because of this problem -- you cannot draw over a Webkit WebView these days.
Anybody Cocoa/OSX wizards have any ideas? I've become a little obsessed with this one. An itch I can't scratch.
Edit: have also tried overriding the following on the child window. When clicked, the window makes the main application window become inactive.
- (BOOL)canBecomeKeyWindow {
return YES;
}
- (BOOL)canBecomeMainWindow {
return NO;
}
Edit 2:
After screwing about with NSMenu for a while, I scrapped that approach. It seems I found something, however. In NSPanel there is a window style mask called:
NSNonactivatingPanelMask
The panel can receive keyboard input without activating the owning application.
Valid only for an instance of NSPanel or its subclasses; not valid for a window.
Trying this out now...
Edit 3: NSNonactivatingPanelMask did not do the trick. No ideas.
What you want is a window that can become the key window but which cannot become the main window. You could implement such a class yourself, but this is basically what NSPanel is for, so you might try that first.
I think this can help you:
[self.childWindow makeKeyAndOrderFront:self];

Dynamically removing and attaching the border on a nswindow

How do I go about adding/removing the window border after it has been created? the window was already designed in interface builder and I would prefer to avoid writing the window purely in code as I am still a long ways before i can say i am experienced with objective-c/cocoa.
Example Program:
a single window with the border initially, a button on it. If you click the button once it makes the boarder disappear and if you click it again then the boarder reappears.
Thanks
As far as I can tell, you can't. You might be able to fake it by taking the content view out of one window and making it be the content view of another window.

MainMenu.xib with dispositioned main window

Each time I create any type of cocoa project (document-based, with core-data and/or spotlight importer) and open MainMenu.xib, I get a warning sign in bottom right object palette window corner saying that window is out of screen bounds. Why is this so? Any remedy?
I get a warning sign in bottom right object palette window corner saying that window is out of screen bounds. Why is this so?
Because the window falls at least partially outside the screen bounds.
Any remedy?
Put it completely within the screen bounds. Select the window and use the Content Size & Position section of the Size (⌘3) inspector to move it.
Simply dragging the window by its title bar will not help, since that position is only for display in IB; it doesn't affect the window that will appear in your app, which is what the warning is about. You need to use the Size inspector.
I once had a similar problem when I had a second monitor connected to my MBP.
When the second monitor was set to a low resolution (I think it was 1024x768), Interface Builder came up with that particular warning. (Although the window did fit between the main menu and the Dock).

Resources