"onMouseUp" won't be handled. Any ideas?[VST3, VSTGUI 4.10]

I’m making a custom button that turns on when mouse entered with its L button held, or that keeps active while L button is on held.
Then mouse exited or button was released, it turns off.

But there is a problem.
When mouse entered from the out of the button with its L button held, it turns on, but then L button was released, it won’t be turned off until click it again or mouse exit. It seems “onMouseUp” isn’t working.
Why?
Could you please give me any hints, suggestions or advices?
Thank you.

Here is my rough code:

my_button.cpp

CMouseEventResult MyControl::onMouseEntered(CPoint& where, const CButtonState& buttons)
{
	if (buttons.isLeftButton())
	{
		if (value == getMin())
		{
			value = getMax();
		}
		else if (value == getMax())
		{
			value = getMin();
		}
		dragEnter = true;
		invalid();
		valueChanged();
		beginEdit();
	}
	return kMouseEventHandled;
}

CMouseEventResult MyControl::onMouseDown(CPoint& where, const CButtonState& buttons)
{
	if (buttons.isLeftButton() && dragEnter)
	{
		value = getMax();
		invalid();
		valueChanged();
	}
	return kMouseEventHandled;
}

CMouseEventResult MyControl::onMouseUp(CPoint& where, const CButtonState& buttons)
{
	if (buttons.isLeftButton())
	{
		value = getMin();
		invalid();
		valueChanged();
	}
	return kMouseEventHandled;
}

CMouseEventResult MyControl::onMouseMoved(CPoint& where, const CButtonState& buttons)
{
	if (!getViewSize().pointInside(where) && buttons.isLeftButton())
	{
		value = getMin();
		invalid();
		valueChanged();
		endEdit();
		return kMouseMoveEventHandledButDontNeedMoreEvents;
	}
	else
	{
		invalid();
		return kMouseEventHandled;
	}
	return kMouseEventHandled;
}

CMouseEventResult MyControl::onMouseExited(CPoint& where, const CButtonState& buttons)
{
	dragEnter = false;
	if (buttons.isLeftButton())
	{
		value = getMin();
		invalid();
		valueChanged();
		endEdit();
		//return kMouseMoveEventHandledButDontNeedMoreEvents;
	}
	return kMouseEventHandled;
}

CMouseEventResult MyControl::onMouseCancel()
{
	dragEnter = false;
	value = getMin();
	invalid();
	valueChanged();
	endEdit();
	return kMouseEventHandled;
}

This is a very strange use case. I don’t think that this is currently possible.
The mouse up event will be dispatched to the view where the mouse down was happening if that view handled the mouse down otherwise the mouse up event will not be dispatched to any view.

1 Like

I got it. Thank you Arne!