gammasoft71 / xtd

Free open-source modern C++17 / C++20 framework to create console, GUI (forms like WinForms) and unit test applications and libraries on Microsoft Windows, Apple macOS and Linux.
https://gammasoft71.github.io/xtd
MIT License
779 stars 59 forks source link

[BUG] xtd.forms - combo_box::drop_down raised twice when combo_box inside a layout_panel which is inside another layout_panel #202

Closed jimorc closed 1 year ago

jimorc commented 1 year ago

Describe the bug

In the program listing below, a combo_box is placed inside a vertical_layout_panel. That panel is placed inside another vertical_layout_panel. When the dropdown list is opened, the drop_down event is raised twice.

If the combo_box is inside a vertical_layout_panel which is NOT placed inside a second layout_panel, then the event is raised once.

#include <xtd/xtd>

using namespace xtd;
using namespace xtd::forms;

class form1 : public form {
  public:
    form1() {
      box_.drop_down += event_handler(*this, &form1::box_drop_down);
      vlp_ << box_;
      vlp2_ << vlp_;
      *this << vlp2_;
    }
    void box_drop_down(object& sender, const event_args& e)
    {
      box_.items().clear();
      box_.items().push_back({"Item 1"});
      box_.selected_index(0);
      std::cout << "dropped down\n";
    }
  private:
    vertical_layout_panel vlp_;
    vertical_layout_panel vlp2_;
    combo_box box_;
};

int main()
{
  application::run(form1 {} );
}

To Reproduce

Steps to reproduce the behavior:

  1. Build and execute the program.
  2. Open the dropdown list. Note that "dropped down" is printed twice.
  3. Modify program so that only one vertical_layout_panel is used.
  4. Open the dropdown list. "dropped down" is printed once.

Expected behaviour

The drop_down event should only be raised once.

Screenshots

N/A

Desktop (please complete the following information)

Workaround

None

jimorc commented 1 year ago

Further to this, if the second layout_panel is placed inside a third vertical_layout_panel, the event is still only raised twice.

gammasoft71 commented 1 year ago

Indeed, it is the propagation of events in the wxWidgets backend, which is a problem. I put a filter to suppress this propagation of events. But after rereading the documentation of wxWidgets, I realize that this is not the right way to do it.

I'm going to make a POC to check the right way to block this propagation. If this one is conclusive, I will correct the events in xtd.