Tracktion / choc

A collection of header only classes, permissively licensed, to provide basic useful tasks with the bare-minimum of dependencies.
Other
543 stars 49 forks source link

Disable the window close button? #38

Closed daveboulden closed 7 months ago

daveboulden commented 10 months ago

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.

julianstorer commented 10 months ago

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.

daveboulden commented 10 months ago

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

daveboulden commented 8 months ago

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.

julianstorer commented 8 months ago

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

daveboulden commented 8 months ago

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

julianstorer commented 8 months ago

I added them to the commit in your repo

daveboulden commented 8 months ago

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.

julianstorer commented 8 months ago

great, I'll take a look asap

daveboulden commented 8 months ago

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

julianstorer commented 8 months ago

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

daveboulden commented 8 months ago

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

julianstorer commented 7 months ago

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