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
737 stars 58 forks source link

[BUG] xtd.forms - combo_box in vertical_layout_panel fires drop_down and drop_down_closed events twice #192

Closed jimorc closed 1 year ago

jimorc commented 1 year ago

Describe the bug

When a combo_box is placed inside vertical_layout_panel and that panel is placed inside a form, opening the combo_box list fires the drop_down event twice. Closing the drop_down list causes the drop_down_closed event to be fired twice. If a combo_box is placed directly into a form, then the events are fired only once.

See the sample program below:

#include <xtd/xtd>
#include <iostream>

using namespace xtd;
using namespace xtd::forms;

class form1 : public form
{
    public:
        form1()
        {
            box2.drop_down_style(combo_box_style::drop_down_list);
            box2.items().push_back_range({"Item 3", "Item 4"});
            box2.drop_down += xtd::event_handler(
            *this, &form1::on_device_combo_box_drop_down);
            box2.drop_down_closed += xtd::event_handler(
            *this, &form1::on_device_combo_box_drop_down_closed);
            box2.location({0, 0});

            box.drop_down_style(combo_box_style::drop_down_list);
            box.items().push_back_range({"Item 1", "Item 2"});
            box.drop_down += xtd::event_handler(
            *this, &form1::on_device_combo_box_drop_down);
            box.drop_down_closed += xtd::event_handler(
            *this, &form1::on_device_combo_box_drop_down_closed);

            vlp.location({0, 30});
            vlp << box;
            vlp.anchor(anchor_styles::all);
            vlp.control_layout_style(box, {size_type::auto_size, true});

            *this << box2 << vlp;

        }
        void on_device_combo_box_drop_down(object& sender, const xtd::event_args& e)
        {
            std::cout << "In drop_down\n";
        }
        void on_device_combo_box_drop_down_closed(object& sender,
            const xtd::event_args& e)
        {
            std::cout << "In drop_down_closed\n";
        }
    private:
        combo_box box2;
        vertical_layout_panel vlp;
        combo_box box;
};
int main()
{
    form1 f;
    application::run(f);
    return EXIT_SUCCESS;
}

To Reproduce

Steps to reproduce the behavior:

  1. Build the program above and execute it.
  2. Open the first combo_box and select an item
  3. See the output: "In drop_down" is printed once, followed by "In drop_down_closed".
  4. Repeat with the second combo_box.
  5. see the output: "In drop_down" is printed twice followed by "In drop_down_closed" twice

Expected behaviour

In step 5, above, "In drop_down" should be printed once, followed by "In drop_down_closed" once.

Screenshots

N/A

Desktop (please complete the following information)

Additional context N/A

Workaround None satisfactory.

gammasoft71 commented 1 year ago

The problem seems to occur when the layout_style expanded parameter is set to true. I'll do some research as soon as possible.

gammasoft71 commented 1 year ago

The issue is fixed.

Remarks

On macOS if the height of the combo_box is greater than 32 pixels, macOS does not draw the combo_box correctly. This will result in a display error between the border and the text of the control (see the print screen below).

When you run an application that uses a combo_box with a height greater than 32 pixels, macOS displays the following message:

"This application is trying to draw a very large combo box, 32 points tall. Vertically resizable combo boxes are not supported, but it happens that 10.4 and previous drew something that looked kind of sort of okay. The art in 10.5 does not break up in a way that supports that drawing. This application should be revised to stop using large combo boxes. This warning will appear once per app launch."

image

gammasoft71 commented 1 year ago

Commit https://github.com/gammasoft71/xtd/commit/cb74b29d39f367141d1b4c6c4a968d476d6c286f