Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disableInternalMouseEvents flag in Component #1470

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions modules/juce_gui_basics/components/juce_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,16 @@ void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
}

void Component::setDisableInternalMouseEvents(bool disableInternalMouseEvents) noexcept
{
flags.disableInternalMouseEventsFlag = disableInternalMouseEvents;
}

bool Component::getDisableInternalMouseEvents() const noexcept
{
return flags.disableInternalMouseEventsFlag;
}

bool Component::contains (Point<int> point)
{
return contains (point.toFloat());
Expand Down Expand Up @@ -2107,7 +2117,7 @@ void Component::internalMouseEnter (MouseInputSource source, Point<float> relati
false);

HierarchyChecker checker (this, me);
mouseEnter (me);
if(!flags.disableInternalMouseEventsFlag) mouseEnter (me);

flags.cachedMouseInsideComponent = true;

Expand Down Expand Up @@ -2144,7 +2154,7 @@ void Component::internalMouseExit (MouseInputSource source, Point<float> relativ
false);

HierarchyChecker checker (this, me);
mouseExit (me);
if (!flags.disableInternalMouseEventsFlag) mouseExit (me);

if (checker.shouldBailOut())
return;
Expand Down Expand Up @@ -2211,7 +2221,7 @@ void Component::internalMouseDown (MouseInputSource source,
if (flags.repaintOnMouseActivityFlag)
repaint();

mouseDown (me);
if (!flags.disableInternalMouseEventsFlag) mouseDown (me);

if (checker.shouldBailOut())
return;
Expand Down Expand Up @@ -2250,7 +2260,7 @@ void Component::internalMouseUp (MouseInputSource source,
if (flags.repaintOnMouseActivityFlag)
repaint();

mouseUp (me);
if (!flags.disableInternalMouseEventsFlag) mouseUp (me);

if (checker.shouldBailOut())
return;
Expand All @@ -2267,7 +2277,7 @@ void Component::internalMouseUp (MouseInputSource source,
if (me.getNumberOfClicks() >= 2)
{
if (checker.nearestNonNullParent() == this)
mouseDoubleClick (checker.eventWithNearestParent());
if (!flags.disableInternalMouseEventsFlag) mouseDoubleClick (checker.eventWithNearestParent());

if (checker.shouldBailOut())
return;
Expand All @@ -2294,7 +2304,7 @@ void Component::internalMouseDrag (MouseInputSource source, const detail::Pointe

HierarchyChecker checker (this, me);

mouseDrag (me);
if (!flags.disableInternalMouseEventsFlag) mouseDrag (me);

if (checker.shouldBailOut())
return;
Expand Down Expand Up @@ -2328,7 +2338,7 @@ void Component::internalMouseMove (MouseInputSource source, Point<float> relativ

HierarchyChecker checker (this, me);

mouseMove (me);
if (!flags.disableInternalMouseEventsFlag) mouseMove (me);

if (checker.shouldBailOut())
return;
Expand Down
17 changes: 17 additions & 0 deletions modules/juce_gui_basics/components/juce_Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,22 @@ class JUCE_API Component : public MouseListener
bool& allowsClicksOnChildComponents) const noexcept;


/**
* Disables internal mouse events for this component.

This method allows you to disable the internal event callback of mouse events for the component.
When disabled, the component will only call events from its listeners.

@see getDisableInternalMouseEvents
*/
void setDisableInternalMouseEvents(bool disableInternalMouseEvents) noexcept;

/** Retrieves the current state of the disable internal mouse events flags.

@see setDisableInternalMouseEvents
*/
bool getDisableInternalMouseEvents() const noexcept;

/** Returns true if a given point lies within this component or one of its children.

Never override this method! Use hitTest to create custom hit regions.
Expand Down Expand Up @@ -2660,6 +2676,7 @@ class JUCE_API Component : public MouseListener
bool opaqueFlag : 1;
bool ignoresMouseClicksFlag : 1;
bool allowChildMouseClicksFlag : 1;
bool disableInternalMouseEventsFlag : 1;
bool wantsKeyboardFocusFlag : 1;
bool isFocusContainerFlag : 1;
bool isKeyboardFocusContainerFlag : 1;
Expand Down