Incorrect button state after PopupMenu::showAt()


#1

If the user clicks within the button to dismiss a popup menu that was created and displayed in response to clicked(), the popup menu is properly dismissed but the button does not go back into the buttonOver state. This test application demonstrates the problem. To see it, click the button to pop the menu and then click the button again to dismiss it. Result: The menu will be dismissed but the button will be blue, indicating buttonNormal, when it should be green, indicating buttonOver.

#include "juce.h"

struct PopupButton : Button
{
  PopupButton() : Button(String::empty)
  {
    setTriggeredOnMouseDown (true);
  }
  void paintButton (Graphics& g, bool over, bool down)
  {
    Colour c;
    if (down)
      c=Colours::red;
    else if (over)
      c=Colours::green;
    else
      c=Colours::blue;
    g.setColour (c);
    g.fillAll();
    g.setColour (Colours::black);
    g.drawRect (getLocalBounds(), 1);
  }
  void clicked ()
  {
    PopupMenu m;
    m.addItem (1, "Juce!");
    m.addSeparator ();
    m.addItem (2, "Test");
    m.showAt (this);
  }
};

struct Panel : Component
{
  PopupButton b;
  Panel()
  {
    b.setBounds (224, 64, 64, 40);
    addAndMakeVisible (&b);
  }
  void paint (Graphics& g)
  {
    Rectangle<int> b = getLocalBounds();
    g.setColour( Colours::grey );
    g.fillAll();
  }
};

struct MainWindow
  : DocumentWindow
  , Button::Listener
{
  MainWindow()
  : DocumentWindow (JUCE_T("Test")
  , Colours::black
  , DocumentWindow::allButtons
  , true )
  {
    Panel* p = new Panel;
    p->setSize( 512, 384 );
    setContentComponent (p, true, true);
    centreWithSize (getWidth(), getHeight());
    setVisible( true );
  }
  ~MainWindow() {}

  void buttonClicked (Button* button)
  {
    Component* c = getContentComponent()->getChildComponent(1);
    c->setVisible (true);
    c->setTopLeftPosition (64, 64);
  }

  void closeButtonPressed() { JUCEApplication::quit(); }
};

struct MainApp : JUCEApplication
{
  MainApp() : mainWindow(0) { s_app=this; }
  ~MainApp() { s_app=0; }
  static MainApp& GetInstance() { return *s_app; }
  const String getApplicationName() { return JUCE_T("JuceTest"); }
  const String getApplicationVersion() { return JUCE_T("0.1.0"); }
  bool moreThanOneInstanceAllowed() { return true; }
  void anotherInstanceStarted (const String& commandLine) {}

  void initialise (const String& commandLine)
  {
    mainWindow = new MainWindow;
  }

  void shutdown()
  {
    delete mainWindow;
  }

  static MainApp* s_app;
  MainWindow* mainWindow;
};

MainApp* MainApp::s_app = 0;

START_JUCE_APPLICATION (MainApp)

#2

Works ok on my mac. Are you on a pc?


#3

Yes.


#4

Ah well, hardly a showstopper, but I’ll take a look next time I’m doing some PC debugging.