Subclassing NSButton to capture mouseUp and mouseDown events but retain the drawing methods of NSButtons super class.
My goal is as stated above, to subclass NSButton and to have it perform it's regular super class functionality whilst allowing me to override mouseDown and mouseUp and send it back to the action with the NSEvent so the button code can then examine what type of even occurred and respond respectively.
As I experimented with the NSButton sub class, I noticed that when you override the mouseDown as below:
override open func mouseDown(with event: NSEvent)
{
super.mouseDown(with: event)
// call the target with left button down
_ = target?.perform(action, with: event)
}
What appears to be happening is the the super.mouseDown captures the mouse events and subsequently your sub class of NSButton will not receive the appropriate mouseUp event.
Seeing as that is how things are working, I simply did an override of mouseDown and mouseUp without calling any of the Super Class functions. This indeed provides an even for mouseDown and mouseUp. I forward the event to the action and let the action code process which event has occurred and everything is fine. The only caveat is that the default behavior for the button state is not occurring. The button will stay in it's original non-selected state. If I change the state and force an update to the button, one would think it would draw the button in it's selected state. This does not happen hence why I am writing for some assistance.
I would love to be able to have the default drawing behavior of NSButton mouseDown event occur. Is there a way to set a property of NSButton aka it's state and force a redraw? I can't seem to be able to do this. If there is no way to do this, then I will be forced to draw the buttons content in it's selected state some how via overriding the draw method.
Any help would be appreciated.