From ff0fd2712751b7bcfe2562635b4f95ac7a40fb07 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 7 Nov 2013 10:19:58 +0000 Subject: [PATCH] Yet another attempt to get all the edge-cases right in Button::internalClickCallback --- modules/juce_gui_basics/buttons/juce_Button.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/juce_gui_basics/buttons/juce_Button.cpp b/modules/juce_gui_basics/buttons/juce_Button.cpp index 9eaddebf3a..cb55e6a33a 100644 --- a/modules/juce_gui_basics/buttons/juce_Button.cpp +++ b/modules/juce_gui_basics/buttons/juce_Button.cpp @@ -308,10 +308,17 @@ void Button::triggerClick() void Button::internalClickCallback (const ModifierKeys& modifiers) { if (clickTogglesState) - setToggleState (radioGroupId != 0 || ! lastToggleState, sendNotification); + { + const bool shouldBeOn = (radioGroupId != 0 || ! lastToggleState); - if (radioGroupId != 0 || ! clickTogglesState) - sendClickMessage (modifiers); + if (shouldBeOn != getToggleState()) + { + setToggleState (shouldBeOn, sendNotification); + return; + } + } + + sendClickMessage (modifiers); } void Button::flashButtonState()