title: Closing Popup and setting button label
body: <p>I'm writing a C++ wxWidgets calculator application. I want to compress trigonometric function buttons into a single one to save on space, using what's basically a split button. If you left click on it, the current option is used. If you right click, a popup menu is opened, which contains all the buttons; when you click on one of them, it is used and the big button changes.</p>
  <p>I've been suggested to use wxComboBox and other stuff for this job, but I preferred using wxPopupTransientWindow because this way I can display the buttons in a grid, making everything - in my opinion - neater.</p>
  <p>Problem is, when I choose an option from the menu, the main button's ID changes (because when I reopen the menu the previously clicked button is light up as its ID and the big button's ID match), but the label does not. Furthermore, the popup is supposed to close itself when you left click on one of the buttons, but it does not.</p>
  <p><a href="https://i.stack.imgur.com/kiyu0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kiyu0.png" alt="My app" /></a></p>
  <p>This is the code for the custom button in the popup which is supposed to do all that stuff:</p>
  <pre><code>void expandButton::mouseReleased(wxMouseEvent&amp; evt)
  {
      if (pressed) {
          pressed = false;
          paintNow();
  
          wxWindow* mBtn = this-&gt;GetParent()-&gt;GetParent();
          mBtn-&gt;SetLabel(this-&gt;GetLabel());
          mBtn-&gt;SetId(this-&gt;GetId());
  
          this-&gt;GetParent()-&gt;Close(true);
      }
  }
  </code></pre>
  <p>This is the code for the custom button in the main frame which opens up the popup (temporary setup just to test if the whole thing is working):</p>
  <pre><code>void ikeButton::rightClick(wxMouseEvent&amp; evt) // CREA PANNELLO ESTENSIONE
  {
      if (flags &amp; EXPANDABLE)
      {
          std::vector&lt;expandMenuInfo&gt; buttons;
          buttons.push_back(expandMenuInfo(L&quot;sin&quot;, 3001));
          buttons.push_back(expandMenuInfo(L&quot;cos&quot;, 3002));
          buttons.push_back(expandMenuInfo(L&quot;tan&quot;, 3003));
          buttons.push_back(expandMenuInfo(L&quot;arcsin&quot;, 3004));
          buttons.push_back(expandMenuInfo(L&quot;arccos&quot;, 3005));
          buttons.push_back(expandMenuInfo(L&quot;arctan&quot;, 3006));
  
          wxPoint p = this-&gt;GetScreenPosition();
          size_t sz = this-&gt;GetSize().GetHeight() / 1.15;
  
          expandMenu* menu = new expandMenu(this, buttons, sz, wxPoint(
                  p.x, p.y + this-&gt;GetSize().GetHeight() + 2));
          menu-&gt;SetPosition(wxPoint(
              menu-&gt;GetPosition().x - ((menu-&gt;GetSize().GetWidth() - this-&gt;GetSize().GetWidth()) / 2),
              menu-&gt;GetPosition().y));
          menu-&gt;Popup();
      }
  }
  </code></pre>
  <p>Let me know if I need to show more code.
  This is probably a terrible way of doing this, but this is basically the first &quot;serious&quot; application I'm creating using the wxWidgets framework. Any help is appreciated.</p>