…but my title bar still has the maximis(z)e button active:
On Windows, things behave as I’d expect, but under macOS, I can’t find a way to disable this behavior – there are resize limits specified for the app that are being ignored here (I’m assuming because setBounds() is being called directly, which I know isn’t affected by resize limits).
Adding: if you use the DocumentWindow, there is another enum flag in the constructor specifically for which buttons to use:
requiredButtons
specifies which of the buttons (close, minimise, maximise) should be shown on the title bar. This value is a bitwise combination of values from the TitleBarButtons enum.
Note that it can be “allButtons” to get them all. You can change this later with the setTitleBarButtonsRequired() method, which can also specify where they are positioned.
Right, that’s my puzzlement – I’m setting the style flags here to zero, which on Windows successfully disables all three buttons. On macOS, I’ve stepped down into the guts of the ComponentPeer code for macOS, and it looks like the maximise flag is completely ignored?
static unsigned int getNSWindowStyleMask (const int flags) noexcept
{
unsigned int style = (flags & windowHasTitleBar) != 0 ? NSWindowStyleMaskTitled
: NSWindowStyleMaskBorderless;
if ((flags & windowHasMinimiseButton) != 0) style |= NSWindowStyleMaskMiniaturizable;
if ((flags & windowHasCloseButton) != 0) style |= NSWindowStyleMaskClosable;
if ((flags & windowIsResizable) != 0) style |= NSWindowStyleMaskResizable;
return style;
}
…so we go more deeply into the component peer code to the point where we’re creating and initializing the NSWindow that our component uses, and looking up the valid values of NSWindowStyleMask on the Apple developer website, we note that there’s no style flag present to affect this fullscreen/maximize behavior, so not a JUCE problem, a macOS design that makes me harrumph.
Since my app is designed to have a maximum size, I guess that the approach to take here is:
When we’re on the mac
In my main component’s paint() method, look to see if the local bounds are larger than the current max size as set by the last call to setResizeLimits()
If so, fill the bounds in a bg color, and then make sure that my component is actually drawn into a new rect at the maximum size, centered within the window bounds.
Better ideas (not including ‘redesign the UI to work at arbitrary sizes’), anyone?
The buttons on the Window’s title bar are actually accessible through some Objective-c code. I have a routine which show/hides those buttons.
The void* view pointer is retrieved by calling getPeer()->getNativeHandle().
I mean, shouldn’t this “just work” in JUCE without a native workaround? It sounds like a big bug or oversight for some of the desktop option flags to simply not work…
Hi, this bug still seems to be present. I’m trying to disable the maximise button in my MacOS app, but the following leaves all three showing: MainWindow::MainWindow() : DocumentWindow(..., ..., DocumentWindow::TitleBarButtons::minimiseButton | DocumentWindow::TitleBarButtons::closeButton)
Including just DocumentWindow::TitleBarButtons::closeButton hides the minimise button only, and vice versa, so it seems the maximise flag is the only problem.
The same happens if I use setTitleBarButtonsRequired() in the constructor.
The ‘zoom’ button will now be disabled for non-resizable windows. The ‘maximize’ flag for the document window now controls whether the window is able to enter true full-screen mode.
In testing, this seemed a lot more intuitive than the current behaviour. Hopefully you’ll agree!
Thank you @reuk, that is huge improvement in window behavior. Just tested those changes out here. Blocking full-screen mode is a sufficient fix for my purposes.
I’ll mention two things that might still be patched up a bit, though neither one is pressing for me:
The docs for DocumentWindow::setTitleBarButtonsRequired say the requiredButtons flags will determine which buttons will be shown on the title bar. Since this is not the actual behavior (on macOS anyways) maybe that could be amended.
The maximiseButtonPressed callback is still not getting called, regardless of the setting of the maximize flag.