Skip to content

Commit 2775cbe

Browse files
committed
Add disableInternalMouseEvents flag in Component
1 parent 0ea1af0 commit 2775cbe

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

modules/juce_gui_basics/components/juce_Component.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,16 @@ void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
10731073
allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
10741074
}
10751075

1076+
void Component::setDisableInternalMouseEvents(bool disableInternalMouseEvents) noexcept
1077+
{
1078+
flags.disableInternalMouseEventsFlag = disableInternalMouseEvents;
1079+
}
1080+
1081+
bool Component::getDisableInternalMouseEvents() const noexcept
1082+
{
1083+
return flags.disableInternalMouseEventsFlag;
1084+
}
1085+
10761086
bool Component::contains (Point<int> point)
10771087
{
10781088
return contains (point.toFloat());
@@ -2107,7 +2117,7 @@ void Component::internalMouseEnter (MouseInputSource source, Point<float> relati
21072117
false);
21082118

21092119
HierarchyChecker checker (this, me);
2110-
mouseEnter (me);
2120+
if(!flags.disableInternalMouseEventsFlag) mouseEnter (me);
21112121

21122122
flags.cachedMouseInsideComponent = true;
21132123

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

21462156
HierarchyChecker checker (this, me);
2147-
mouseExit (me);
2157+
if (!flags.disableInternalMouseEventsFlag) mouseExit (me);
21482158

21492159
if (checker.shouldBailOut())
21502160
return;
@@ -2211,7 +2221,7 @@ void Component::internalMouseDown (MouseInputSource source,
22112221
if (flags.repaintOnMouseActivityFlag)
22122222
repaint();
22132223

2214-
mouseDown (me);
2224+
if (!flags.disableInternalMouseEventsFlag) mouseDown (me);
22152225

22162226
if (checker.shouldBailOut())
22172227
return;
@@ -2250,7 +2260,7 @@ void Component::internalMouseUp (MouseInputSource source,
22502260
if (flags.repaintOnMouseActivityFlag)
22512261
repaint();
22522262

2253-
mouseUp (me);
2263+
if (!flags.disableInternalMouseEventsFlag) mouseUp (me);
22542264

22552265
if (checker.shouldBailOut())
22562266
return;
@@ -2267,7 +2277,7 @@ void Component::internalMouseUp (MouseInputSource source,
22672277
if (me.getNumberOfClicks() >= 2)
22682278
{
22692279
if (checker.nearestNonNullParent() == this)
2270-
mouseDoubleClick (checker.eventWithNearestParent());
2280+
if (!flags.disableInternalMouseEventsFlag) mouseDoubleClick (checker.eventWithNearestParent());
22712281

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

22952305
HierarchyChecker checker (this, me);
22962306

2297-
mouseDrag (me);
2307+
if (!flags.disableInternalMouseEventsFlag) mouseDrag (me);
22982308

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

23292339
HierarchyChecker checker (this, me);
23302340

2331-
mouseMove (me);
2341+
if (!flags.disableInternalMouseEventsFlag) mouseMove (me);
23322342

23332343
if (checker.shouldBailOut())
23342344
return;

modules/juce_gui_basics/components/juce_Component.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,22 @@ class JUCE_API Component : public MouseListener
987987
bool& allowsClicksOnChildComponents) const noexcept;
988988

989989

990+
/**
991+
* Disables internal mouse events for this component.
992+
993+
This method allows you to disable the internal event callback of mouse events for the component.
994+
When disabled, the component will only call events from its listeners.
995+
996+
@see getDisableInternalMouseEvents
997+
*/
998+
void setDisableInternalMouseEvents(bool disableInternalMouseEvents) noexcept;
999+
1000+
/** Retrieves the current state of the disable internal mouse events flags.
1001+
1002+
@see setDisableInternalMouseEvents
1003+
*/
1004+
bool getDisableInternalMouseEvents() const noexcept;
1005+
9901006
/** Returns true if a given point lies within this component or one of its children.
9911007
9921008
Never override this method! Use hitTest to create custom hit regions.
@@ -2660,6 +2676,7 @@ class JUCE_API Component : public MouseListener
26602676
bool opaqueFlag : 1;
26612677
bool ignoresMouseClicksFlag : 1;
26622678
bool allowChildMouseClicksFlag : 1;
2679+
bool disableInternalMouseEventsFlag : 1;
26632680
bool wantsKeyboardFocusFlag : 1;
26642681
bool isFocusContainerFlag : 1;
26652682
bool isKeyboardFocusContainerFlag : 1;

0 commit comments

Comments
 (0)