Tracktion / choc

A collection of header only classes, permissively licensed, to provide basic useful tasks with the bare-minimum of dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable the window close button?

daveboulden opened this issue · comments

Is there a way to disable the window close button of choc_DesktopWindow?

I have a situation where I need to be able to disable or intercept it for compatibility within the host program that my software runs within. Currently, using the OS-level close button crashes the host program.

I've not attempted to add that functionality, but there are ways on each platform to implement it. I'm too busy to look into it, but if you wanted to have a shot, I could review the code. It's not difficult to do, just requires a bit of time for research and testing.

That's a very kind offer, thank you. I'll give that a go.

I have implemented this in a clone of the repo here:

https://github.com/daveboulden/choc

I have implemented an extra function setClosable (bool b) to disable the Close button after the instantiation of the window. The changes are in /gui/choc_DesktopWindow.h.

Under MacOS the Close button is disabled and appears as an empty grey button. There is one caveat, though: the setResizable() function specifically enables the Close button and so could possibly be changed to get the styleMask first and then set the NSWindowStyleMaskClosable flag accordingly as I have done in setClosable() so that it ndoesn't overwrite any changes made using setClosable() but that may possibly require a default styleMask to be set initially.

Windows doesn't support removing just the Close button (you either have the three Min/Max/Close buttons or none at all), so instead I set a Boolean variable and use that to effectively intercept the close message in wndProc().

I do not have an environment to easily test the implementation of setClosable() under Linux, but it seems GTK has some very specific and easily identifiable code for manipulating the window, so I am pretty sure the code should be right for this.

@julianstorer It would be great if you could review this when you have a spare moment.

Thanks, I've added a couple of comments..

Thanks Julian... where do I find those comments? (I have looked but can't work out where they are)

I added them to the commit in your repo

I've solved the issue on Windows. The Close button has to be disabled via the underlying system menu rather than the window style. I've done a new commit with those changes in place.

great, I'll take a look asap

Did you get a chance to take a look? Would it be easier if I created a Pull Request?

Sorry, have been busy, but yes, either a PR or just a diff that shows your changes against the latest version would be helpful

No problem. I have synced all latest changes into my fork and issued a Pull Request. All changes are in choc_DesktopWindow.h.

Don't know if you spotted it, but I added this last week - will close this issue now