Fix of #5510: ctrlsub.cpp(231): assert "IsValid(n)" failed in GetClientData(): Invalid index passed to GetClientData()
BitmapComboBox: Use virtual OnSelect() on wxEVT_COMBO event Don't save information about preset combobox type to the evt.SetInt(). This information can be received from BitmapComboBox::get_type() now.
This commit is contained in:
parent
be7e2f2ae1
commit
89f065b57e
3 changed files with 86 additions and 79 deletions
|
@ -3336,16 +3336,14 @@ void Plater::priv::set_current_panel(wxPanel* panel)
|
||||||
|
|
||||||
void Plater::priv::on_select_preset(wxCommandEvent &evt)
|
void Plater::priv::on_select_preset(wxCommandEvent &evt)
|
||||||
{
|
{
|
||||||
auto preset_type = static_cast<Preset::Type>(evt.GetInt());
|
PlaterPresetComboBox* combo = static_cast<PlaterPresetComboBox*>(evt.GetEventObject());
|
||||||
auto *combo = static_cast<PlaterPresetComboBox*>(evt.GetEventObject());
|
Preset::Type preset_type = combo->get_type();
|
||||||
|
|
||||||
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
|
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
|
||||||
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender"),
|
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender"),
|
||||||
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
|
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
|
||||||
// So, use GetSelection() from event parameter
|
// So, use GetSelection() from event parameter
|
||||||
// But in this function we couldn't use evt.GetSelection(), because m_commandInt is used for preset_type
|
int selection = evt.GetSelection();
|
||||||
// Thus, get selection in this way:
|
|
||||||
int selection = combo->FindString(evt.GetString(), true);
|
|
||||||
|
|
||||||
auto idx = combo->get_extruder_idx();
|
auto idx = combo->get_extruder_idx();
|
||||||
|
|
||||||
|
|
|
@ -121,23 +121,26 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const
|
||||||
Bind(wxEVT_COMBOBOX_DROPDOWN, [this](wxCommandEvent&) { m_suppress_change = false; });
|
Bind(wxEVT_COMBOBOX_DROPDOWN, [this](wxCommandEvent&) { m_suppress_change = false; });
|
||||||
Bind(wxEVT_COMBOBOX_CLOSEUP, [this](wxCommandEvent&) { m_suppress_change = true; });
|
Bind(wxEVT_COMBOBOX_CLOSEUP, [this](wxCommandEvent&) { m_suppress_change = true; });
|
||||||
|
|
||||||
Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) {
|
Bind(wxEVT_COMBOBOX, &PresetComboBox::OnSelect, this);
|
||||||
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
|
}
|
||||||
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender")
|
|
||||||
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
|
|
||||||
// So, use GetSelection() from event parameter
|
|
||||||
auto selected_item = evt.GetSelection();
|
|
||||||
|
|
||||||
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
void PresetComboBox::OnSelect(wxCommandEvent& evt)
|
||||||
if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX)
|
{
|
||||||
this->SetSelection(this->m_last_selected);
|
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
|
||||||
else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty())) {
|
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender")
|
||||||
m_last_selected = selected_item;
|
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
|
||||||
on_selection_changed(selected_item);
|
// So, use GetSelection() from event parameter
|
||||||
evt.StopPropagation();
|
auto selected_item = evt.GetSelection();
|
||||||
}
|
|
||||||
evt.Skip();
|
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
||||||
});
|
if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX)
|
||||||
|
this->SetSelection(this->m_last_selected);
|
||||||
|
else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty())) {
|
||||||
|
m_last_selected = selected_item;
|
||||||
|
on_selection_changed(selected_item);
|
||||||
|
evt.StopPropagation();
|
||||||
|
}
|
||||||
|
evt.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
PresetComboBox::~PresetComboBox()
|
PresetComboBox::~PresetComboBox()
|
||||||
|
@ -602,34 +605,6 @@ void PresetComboBox::OnDrawItem(wxDC& dc,
|
||||||
PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type) :
|
PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type) :
|
||||||
PresetComboBox(parent, preset_type, wxSize(15 * wxGetApp().em_unit(), -1))
|
PresetComboBox(parent, preset_type, wxSize(15 * wxGetApp().em_unit(), -1))
|
||||||
{
|
{
|
||||||
Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &evt) {
|
|
||||||
auto selected_item = evt.GetSelection();
|
|
||||||
|
|
||||||
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
|
||||||
if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) {
|
|
||||||
this->SetSelection(this->m_last_selected);
|
|
||||||
evt.StopPropagation();
|
|
||||||
if (marker == LABEL_ITEM_WIZARD_PRINTERS)
|
|
||||||
show_add_menu();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ConfigWizard::StartPage sp = ConfigWizard::SP_WELCOME;
|
|
||||||
switch (marker) {
|
|
||||||
case LABEL_ITEM_WIZARD_FILAMENTS: sp = ConfigWizard::SP_FILAMENTS; break;
|
|
||||||
case LABEL_ITEM_WIZARD_MATERIALS: sp = ConfigWizard::SP_MATERIALS; break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
wxTheApp->CallAfter([sp]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, sp); });
|
|
||||||
}
|
|
||||||
} else if (marker == LABEL_ITEM_PHYSICAL_PRINTER || this->m_last_selected != selected_item || m_collection->current_is_dirty() ) {
|
|
||||||
this->m_last_selected = selected_item;
|
|
||||||
evt.SetInt(this->m_type);
|
|
||||||
evt.Skip();
|
|
||||||
} else {
|
|
||||||
evt.StopPropagation();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (m_type == Preset::TYPE_FILAMENT)
|
if (m_type == Preset::TYPE_FILAMENT)
|
||||||
{
|
{
|
||||||
Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &event) {
|
Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &event) {
|
||||||
|
@ -717,6 +692,35 @@ PlaterPresetComboBox::~PlaterPresetComboBox()
|
||||||
edit_btn->Destroy();
|
edit_btn->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaterPresetComboBox::OnSelect(wxCommandEvent &evt)
|
||||||
|
{
|
||||||
|
auto selected_item = evt.GetSelection();
|
||||||
|
|
||||||
|
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
||||||
|
if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) {
|
||||||
|
this->SetSelection(this->m_last_selected);
|
||||||
|
evt.StopPropagation();
|
||||||
|
if (marker == LABEL_ITEM_MARKER)
|
||||||
|
return;
|
||||||
|
if (marker == LABEL_ITEM_WIZARD_PRINTERS)
|
||||||
|
show_add_menu();
|
||||||
|
else {
|
||||||
|
ConfigWizard::StartPage sp = ConfigWizard::SP_WELCOME;
|
||||||
|
switch (marker) {
|
||||||
|
case LABEL_ITEM_WIZARD_FILAMENTS: sp = ConfigWizard::SP_FILAMENTS; break;
|
||||||
|
case LABEL_ITEM_WIZARD_MATERIALS: sp = ConfigWizard::SP_MATERIALS; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
wxTheApp->CallAfter([sp]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, sp); });
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (marker == LABEL_ITEM_PHYSICAL_PRINTER || this->m_last_selected != selected_item || m_collection->current_is_dirty())
|
||||||
|
this->m_last_selected = selected_item;
|
||||||
|
|
||||||
|
evt.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
bool PlaterPresetComboBox::switch_to_tab()
|
bool PlaterPresetComboBox::switch_to_tab()
|
||||||
{
|
{
|
||||||
Tab* tab = wxGetApp().get_tab(m_type);
|
Tab* tab = wxGetApp().get_tab(m_type);
|
||||||
|
@ -957,40 +961,42 @@ void PlaterPresetComboBox::msw_rescale()
|
||||||
TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) :
|
TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) :
|
||||||
PresetComboBox(parent, preset_type, wxSize(35 * wxGetApp().em_unit(), -1))
|
PresetComboBox(parent, preset_type, wxSize(35 * wxGetApp().em_unit(), -1))
|
||||||
{
|
{
|
||||||
Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) {
|
}
|
||||||
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
|
|
||||||
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender")
|
|
||||||
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
|
|
||||||
// So, use GetSelection() from event parameter
|
|
||||||
auto selected_item = evt.GetSelection();
|
|
||||||
|
|
||||||
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
void TabPresetComboBox::OnSelect(wxCommandEvent &evt)
|
||||||
if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX) {
|
{
|
||||||
this->SetSelection(this->m_last_selected);
|
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
|
||||||
if (marker == LABEL_ITEM_WIZARD_PRINTERS)
|
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender")
|
||||||
wxTheApp->CallAfter([this]() {
|
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
|
||||||
wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS);
|
// So, use GetSelection() from event parameter
|
||||||
|
auto selected_item = evt.GetSelection();
|
||||||
|
|
||||||
// update combobox if its parent is a PhysicalPrinterDialog
|
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
||||||
PhysicalPrinterDialog* parent = dynamic_cast<PhysicalPrinterDialog*>(this->GetParent());
|
if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX) {
|
||||||
if (parent != nullptr)
|
this->SetSelection(this->m_last_selected);
|
||||||
update();
|
if (marker == LABEL_ITEM_WIZARD_PRINTERS)
|
||||||
});
|
wxTheApp->CallAfter([this]() {
|
||||||
}
|
wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS);
|
||||||
else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty()) ) {
|
|
||||||
m_last_selected = selected_item;
|
|
||||||
on_selection_changed(selected_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
evt.StopPropagation();
|
// update combobox if its parent is a PhysicalPrinterDialog
|
||||||
|
PhysicalPrinterDialog* parent = dynamic_cast<PhysicalPrinterDialog*>(this->GetParent());
|
||||||
|
if (parent != nullptr)
|
||||||
|
update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty())) {
|
||||||
|
m_last_selected = selected_item;
|
||||||
|
on_selection_changed(selected_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
evt.StopPropagation();
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
// From the Win 2004 preset combobox lose a focus after change the preset selection
|
// From the Win 2004 preset combobox lose a focus after change the preset selection
|
||||||
// and that is why the up/down arrow doesn't work properly
|
// and that is why the up/down arrow doesn't work properly
|
||||||
// (see https://github.com/prusa3d/PrusaSlicer/issues/5531 ).
|
// (see https://github.com/prusa3d/PrusaSlicer/issues/5531 ).
|
||||||
// So, set the focus to the combobox explicitly
|
// So, set the focus to the combobox explicitly
|
||||||
this->SetFocus();
|
this->SetFocus();
|
||||||
#endif
|
#endif
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString TabPresetComboBox::get_preset_name(const Preset& preset)
|
wxString TabPresetComboBox::get_preset_name(const Preset& preset)
|
||||||
|
|
|
@ -71,6 +71,7 @@ public:
|
||||||
void show_all(bool show_all);
|
void show_all(bool show_all);
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual void msw_rescale();
|
virtual void msw_rescale();
|
||||||
|
virtual void OnSelect(wxCommandEvent& evt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::size_t Marker;
|
typedef std::size_t Marker;
|
||||||
|
@ -167,6 +168,7 @@ public:
|
||||||
wxString get_preset_name(const Preset& preset) override;
|
wxString get_preset_name(const Preset& preset) override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void msw_rescale() override;
|
void msw_rescale() override;
|
||||||
|
void OnSelect(wxCommandEvent& evt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_extruder_idx = -1;
|
int m_extruder_idx = -1;
|
||||||
|
@ -193,6 +195,7 @@ public:
|
||||||
void update() override;
|
void update() override;
|
||||||
void update_dirty();
|
void update_dirty();
|
||||||
void msw_rescale() override;
|
void msw_rescale() override;
|
||||||
|
void OnSelect(wxCommandEvent& evt) override;
|
||||||
|
|
||||||
void set_enable_all(bool enable=true) { m_enable_all = enable; }
|
void set_enable_all(bool enable=true) { m_enable_all = enable; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue