Window Resize Control

Discussion in 'Mac Programming' started by Senor Cuete, Aug 16, 2017.

  1. Senor Cuete, Aug 16, 2017
    Last edited: Aug 16, 2017

    Senor Cuete macrumors regular

    Joined:
    Nov 9, 2011
    #1
    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 *.
     
  2. AphoticD macrumors 6502a

    AphoticD

    Joined:
    Feb 17, 2017
    Location:
    Queensland, Australia
    #2
  3. Senor Cuete thread starter macrumors regular

    Joined:
    Nov 9, 2011
    #3
    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.
     
  4. Senor Cuete thread starter macrumors regular

    Joined:
    Nov 9, 2011
    #4
    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];
    --- Post Merged, Aug 17, 2017 ---
    This logs an error. You would have to get the array initialized with the controls.
     
  5. Senor Cuete thread starter macrumors regular

    Joined:
    Nov 9, 2011
    #5
    --- Post Merged, Aug 17, 2017 ---
    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.
     
  6. AphoticD macrumors 6502a

    AphoticD

    Joined:
    Feb 17, 2017
    Location:
    Queensland, Australia
    #6
    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.
     
  7. Senor Cuete thread starter macrumors regular

    Joined:
    Nov 9, 2011
    #7
    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.
     

Share This Page