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 selection not displayed in combo_box #193

Closed jimorc closed 1 year ago

jimorc commented 1 year ago

Describe the bug

With a combo_box in a vertical_layout_panel in a form, selecting an item from the drop_down list does not display the item in the combo box. If an item is selected from a combo_box that is inserted directly into the form, then the item is displayed in the combo box.

See the 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);

            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::left | anchor_styles::right | anchor_styles::bottom);
            vlp.control_layout_style(box, {size_type::auto_size, true});

            *this << box2 << vlp;
            box.anchor(anchor_styles::left | anchor_styles::right);

        }
        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 and execute the program listed above.
  2. Open the drop_down in the first combo_box and select an item.3.
  3. Check that the item is displayed when the drop_down closes.4.
  4. Repeat step 2 with the second combo_box.
  5. Note that the selected item is not displayed.

Expected Behaviour

Both combo_boxes should display the selected item.

Screenshots

N/A

Desktop (please complete the following information)

Additional context

N/A

Workaround

None

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