Mac Window Resize Control

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
289
12
In XCode 8.3.3 the only way I can find to make an NSWindow resizable is to include a Window Resize NSControl in the .xib. This is the green button in the top left corner of a window. I want my application not to be a full-screen app. It makes sense for this application to be able to zoom to the window's maximum size if it's resized to a smaller size, but I want to disable the Window Resize Control if the window's at its maximum size. I can access the window's frame by overriding the functions:

Code:
-(void) userResizedWindow: (NSNotification *) note
and
-(void) windowDidResize: (NSNotification *) note
But I can't figure out how to get a pointer to the window's Window Resize NSControl. How could I do this? I'm using Objective C.

There is an NSWindowButton class in the documentation declared as an enum to allow access to the window buttons but I can't figure out how to use these ints to get an NSControl *.
 
Last edited:

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
289
12
Because I had an NSWindow* in the method
Code:
- (void) windowControllerDidLoadNib:(NSWindowController *) aController
I also called
Code:
[docWindow setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
It doesn't make any difference. If the window has a maximum size, hitting the button with the window at less than the maximum size will maximize the window but the button will stay green. The iTunes store wouldn't sell my app because hitting the green button (which the reviewer thinks is a full-screen button) didn't make a document window go to full-screen mode. I had to argue with them at great length and file an appeal to explain that for this Cocoa multiple-document application I didn't want the documents to be full-screen. This is why I want to inactivate the window resize button if the doc window is at its maximum size. To do this I need a pointer to the Window Resize NSControl. I have figured how to do this EXCEPT for how to get a pointer to the NSControl.

As far as I can tell, the window will only be resizable if it has a resize control in the .xib.
 

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
289
12
It looks like you can get this control and disable it like this:
Code:
NSArray * accessoryViews = [window titlebarAccessoryViewControllers];
    NSControl * windowResizeControl = [accessoryViews objectAtIndex: NSWindowFullScreenButton];
    [windowResizeControl setEnabled: NO];
[doublepost=1503008775][/doublepost]
It looks like you can get this control and disable it like this:
Code:
NSArray * accessoryViews = [window titlebarAccessoryViewControllers];
    NSControl * windowResizeControl = [accessoryViews objectAtIndex: NSWindowFullScreenButton];
    [windowResizeControl setEnabled: NO];
This logs an error. You would have to get the array initialized with the controls.
 
  • Like
Reactions: AphoticD

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
289
12
It looks like you can get this control and disable it like this:
Code:
NSArray * accessoryViews = [window titlebarAccessoryViewControllers];
    NSControl * windowResizeControl = [accessoryViews objectAtIndex: NSWindowFullScreenButton];
    [windowResizeControl setEnabled: NO];
[doublepost=1503008775][/doublepost]
This logs an error. You would have to get the array initialized with the controls.
[doublepost=1503018546][/doublepost]Setting the full screen attribute in the .xib to none makes the button go back to a zoom button. This will solve the problem for now. Still I'm wondering about how to get a pointer to the control. Apple seems to want me not to.
 

AphoticD

macrumors 68000
Feb 17, 2017
1,916
2,534
Australia
[doublepost=1503018546][/doublepost]Setting the full screen attribute in the .xib to none makes the button go back to a zoom button. This will solve the problem for now. Still I'm wondering about how to get a pointer to the control. Apple seems to want me not to.
Programmatically, this would do the same as setting the Full Screen attribute in IB to None:
Code:
[window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenNone]
Have you seen any apps which enable/disable the zoom button while running? It must be locked out for a reason.
 

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
289
12
I figured out how to get the window’s zoom button:
Code:
NSButton * zoomButton = [window standardWindowButton: (NSWindowButton)NSWindowZoomButton];
I was trying to use the enumerated constant NSWindowFullScreenButton. It works if you use NSWindowZoomButton instead. It’s possible that because my window full-screen attribute is set to none that it required NSWindowZoomButton instead of NSWindowFullScreenButton.

No errors are logged but calling
Code:
[zoomButton setEnabled: NO];
in the - (void)windowControllerDidLoadNib:(NSWindowController *) aController;
method doesn’t disable it.

Also XCode/Interface Builder isn't honoring my minimum size, using a bigger minimum height and width than what I have in the .xib.
 

Similar threads

Register on MacRumors! This sidebar will go away, and you'll see fewer ads.