DrawableButton not showing the correct image

I'm using Windows 8.1/VS2012

I've no idea when this happened exactly, but I just noticed that my DrawableButtons aren't drawn correctly.
The button is set to setClickingTogglesState(true). If I click the button (with the mouse), it would behave normally, but will only update its image after I move the mouse outside of the button's area. 

To reproduce, take a clean juce repository (tip) and go to juce_demo, widgets demo and replace the lines 479-481

DrawableImage down;
down.setImage (ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize));
down.setOverlayColour (Colours::black.withAlpha (0.3f));


DrawableImage down;
down.setImage (ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize));
down.setOverlayColour (Colours::purple);
DrawableImage* d2 = new DrawableImage(down);
DrawableImage* d3 = new DrawableImage(down);
DrawableImage* d4 = new DrawableImage(down);
DrawableImage* d5 = new DrawableImage(down);
DrawableImage* d6 = new DrawableImage(down);

And replace line 494:

db->setImages (&normal, &over, &down);

With this:

db->setImages (d5, d6, &down, nullptr, d2, d3, d4);

Paste for the lazy: http://tny.cz/09d36e65


Now notice how this button behaves:

Click it, then move the mouse somewhere else. You'll notice the mouseExit forces it to refresh, and display the correct image.

I don't know how to fix it, but adding the call 'sendStateMessage();' in juce_button::312 (between the setToggle and the sendClickMessage seem to fix it, but probably not in a good way :) I was just messing with it.

Oh, and manual triggerClick works just fine.

Thanks - should be fixed now!

As always - thanks for the quick fix!

Apparently this is not quite resolved.

Now the clickMessage is sent twice!

Probably because of the sendNofitication flag in the setToggleState in juce_button.cpp:internalClickCallback (311)

How about this:

void Button::internalClickCallback (const ModifierKeys& modifiers)
    if (clickTogglesState)
        setToggleState (radioGroupId != 0 || ! lastToggleState, sendNotification);
        sendClickMessage (modifiers);


Ah yes, good idea, thanks!

All good now - thanks!