Skip to content

Commit

Permalink
Add disableInternalMouseEvents flag in Component
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Nov 13, 2024
1 parent 0ea1af0 commit 2775cbe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
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

0 comments on commit 2775cbe

Please sign in to comment.