From ca534b5b966f1ac914eff085de36c6df2c12bd0b Mon Sep 17 00:00:00 2001 From: mia <652892+mia-0@users.noreply.github.com> Date: Mon, 25 Sep 2023 17:35:30 +0200 Subject: [PATCH] Fix compatibility with STL builds of wxWidgets (#2218) This removes the dependency on legacy wxWidgets configurations, and makes OrcaSlicer compile on STL builds. Also, the wxStringList class has been obsolete for at least 20 years, and disappeared from the documentation. Replace with wxArrayString. --- src/slic3r/GUI/ImageGrid.cpp | 12 ++++++---- src/slic3r/GUI/ImageGrid.h | 3 ++- src/slic3r/GUI/Plater.cpp | 40 +++++++++++++++++----------------- src/slic3r/GUI/Preferences.cpp | 40 +++++++++++++++++----------------- src/slic3r/Utils/OctoPrint.cpp | 4 ++-- 5 files changed, 52 insertions(+), 47 deletions(-) diff --git a/src/slic3r/GUI/ImageGrid.cpp b/src/slic3r/GUI/ImageGrid.cpp index ed34579d99b..50f16d186a8 100644 --- a/src/slic3r/GUI/ImageGrid.cpp +++ b/src/slic3r/GUI/ImageGrid.cpp @@ -623,11 +623,15 @@ void Slic3r::GUI::ImageGrid::renderContent1(wxDC &dc, wxPoint const &pt, int ind } // Draw buttons on hovered item wxRect rect{pt.x, pt.y + m_content_rect.GetBottom() - m_buttons_background.GetHeight(), m_content_rect.GetWidth(), m_buttons_background.GetHeight()}; + wxArrayString texts; if (hit) { - renderButtons(dc, {_L("Delete"), (wxChar const *) secondAction, thirdAction.IsEmpty() ? nullptr : (wxChar const *) thirdAction, nullptr}, rect, - m_hit_type == HIT_ACTION ? m_hit_item & 3 : -1, states); + texts.Add(_L("Delete")); + texts.Add(secondAction); + texts.Add(thirdAction); + renderButtons(dc, texts, rect, m_hit_type == HIT_ACTION ? m_hit_item & 3 : -1, states); } else if (!nonHoverText.IsEmpty()) { - renderButtons(dc, {(wxChar const *) nonHoverText, nullptr}, rect, -1, states); + texts.Add(nonHoverText); + renderButtons(dc, texts, rect, -1, states); } } else { dc.SetTextForeground(*wxWHITE); // time text color @@ -673,7 +677,7 @@ void Slic3r::GUI::ImageGrid::renderContent2(wxDC &dc, wxPoint const &pt, int ind renderIconText(dc, m_model_weight_icon, file.Metadata("Weight", "0g"), rect); } -void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxStringList const &texts, wxRect const &rect2, size_t hit, int states) +void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxArrayString const &texts, wxRect const &rect2, size_t hit, int states) { // Draw background { diff --git a/src/slic3r/GUI/ImageGrid.h b/src/slic3r/GUI/ImageGrid.h index 42cf8a06e53..78f970e2ef0 100644 --- a/src/slic3r/GUI/ImageGrid.h +++ b/src/slic3r/GUI/ImageGrid.h @@ -9,6 +9,7 @@ #define ImageGrid_h #include +#include #include #include "Widgets/StateColor.hpp" @@ -84,7 +85,7 @@ protected: void renderContent2(wxDC &dc, wxPoint const &pt, int index, bool hit); - void renderButtons(wxDC &dc, wxStringList const &texts, wxRect const &rect, size_t hit, int states); + void renderButtons(wxDC &dc, wxArrayString const &texts, wxRect const &rect, size_t hit, int states); void renderText(wxDC &dc, wxString const &text, wxRect const &rect, int states); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 9077ae78b86..11e25e46247 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -9240,49 +9240,49 @@ wxBoxSizer *ProjectDropDialog::create_item_checkbox(wxString title, wxWindow *pa void ProjectDropDialog::select_radio(int index) { m_action = index; - RadioSelectorList::Node *node = m_radio_group.GetFirst(); + RadioSelectorList::compatibility_iterator it = m_radio_group.GetFirst(); auto groupid = 0; - while (node) { - RadioSelector *rs = node->GetData(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_select_id == index) groupid = rs->m_groupid; - node = node->GetNext(); + it = it->GetNext(); } - node = m_radio_group.GetFirst(); - while (node) { - RadioSelector *rs = node->GetData(); + it = m_radio_group.GetFirst(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_groupid == groupid && rs->m_select_id == index) rs->m_radiobox->SetValue(true); if (rs->m_groupid == groupid && rs->m_select_id != index) rs->m_radiobox->SetValue(false); - node = node->GetNext(); + it = it->GetNext(); } } int ProjectDropDialog::get_select_radio(int groupid) { - RadioSelectorList::Node *node = m_radio_group.GetFirst(); - while (node) { - RadioSelector *rs = node->GetData(); + RadioSelectorList::compatibility_iterator it = m_radio_group.GetFirst(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_groupid == groupid && rs->m_radiobox->GetValue()) { return rs->m_select_id; } - node = node->GetNext(); + it = it->GetNext(); } return 0; } void ProjectDropDialog::on_select_radio(wxMouseEvent &event) { - RadioSelectorList::Node *node = m_radio_group.GetFirst(); + RadioSelectorList::compatibility_iterator it = m_radio_group.GetFirst(); auto groupid = 0; - while (node) { - RadioSelector *rs = node->GetData(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_radiobox->GetId() == event.GetId()) groupid = rs->m_groupid; - node = node->GetNext(); + it = it->GetNext(); } - node = m_radio_group.GetFirst(); - while (node) { - RadioSelector *rs = node->GetData(); + it = m_radio_group.GetFirst(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_groupid == groupid && rs->m_radiobox->GetId() == event.GetId()) { set_action(rs->m_select_id); rs->m_radiobox->SetValue(true); @@ -9290,7 +9290,7 @@ void ProjectDropDialog::on_select_radio(wxMouseEvent &event) if (rs->m_groupid == groupid && rs->m_radiobox->GetId() != event.GetId()) rs->m_radiobox->SetValue(false); - node = node->GetNext(); + it = it->GetNext(); } } diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 2ad70763e00..6ba807c8240 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1307,31 +1307,31 @@ wxWindow* PreferencesDialog::create_debug_page() void PreferencesDialog::on_select_radio(std::string param) { - RadioSelectorList::Node *node = m_radio_group.GetFirst(); + RadioSelectorList::compatibility_iterator it = m_radio_group.GetFirst(); auto groupid = 0; - while (node) { - RadioSelector *rs = node->GetData(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_param_name == param) groupid = rs->m_groupid; - node = node->GetNext(); + it = it->GetNext(); } - node = m_radio_group.GetFirst(); - while (node) { - RadioSelector *rs = node->GetData(); + it = m_radio_group.GetFirst(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_groupid == groupid && rs->m_param_name == param) rs->m_radiobox->SetValue(true); if (rs->m_groupid == groupid && rs->m_param_name != param) rs->m_radiobox->SetValue(false); - node = node->GetNext(); + it = it->GetNext(); } } wxString PreferencesDialog::get_select_radio(int groupid) { - RadioSelectorList::Node *node = m_radio_group.GetFirst(); - while (node) { - RadioSelector *rs = node->GetData(); + RadioSelectorList::compatibility_iterator it = m_radio_group.GetFirst(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_groupid == groupid && rs->m_radiobox->GetValue()) { return rs->m_param_name; } - node = node->GetNext(); + it = it->GetNext(); } return wxEmptyString; @@ -1339,21 +1339,21 @@ wxString PreferencesDialog::get_select_radio(int groupid) void PreferencesDialog::OnSelectRadio(wxMouseEvent &event) { - RadioSelectorList::Node *node = m_radio_group.GetFirst(); + RadioSelectorList::compatibility_iterator it = m_radio_group.GetFirst(); auto groupid = 0; - while (node) { - RadioSelector *rs = node->GetData(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_radiobox->GetId() == event.GetId()) groupid = rs->m_groupid; - node = node->GetNext(); + it = it->GetNext(); } - node = m_radio_group.GetFirst(); - while (node) { - RadioSelector *rs = node->GetData(); + it = m_radio_group.GetFirst(); + while (it) { + RadioSelector *rs = it->GetData(); if (rs->m_groupid == groupid && rs->m_radiobox->GetId() == event.GetId()) rs->m_radiobox->SetValue(true); if (rs->m_groupid == groupid && rs->m_radiobox->GetId() != event.GetId()) rs->m_radiobox->SetValue(false); - node = node->GetNext(); + it = it->GetNext(); } } diff --git a/src/slic3r/Utils/OctoPrint.cpp b/src/slic3r/Utils/OctoPrint.cpp index 1814a17a9fe..edf903e55d4 100644 --- a/src/slic3r/Utils/OctoPrint.cpp +++ b/src/slic3r/Utils/OctoPrint.cpp @@ -745,8 +745,8 @@ bool PrusaLink::get_storage(wxArrayString& storage_path, wxArrayString& storage_ const auto available = section.second.get_optional("available"); if (path && (!available || *available)) { StorageInfo si; - si.path = boost::nowide::widen(*path); - si.name = name ? boost::nowide::widen(*name) : wxString(); + si.path = wxString(*path); + si.name = name ? wxString(*name) : wxString(); // If read_only is missing, assume it is NOT read only. // si.read_only = read_only ? *read_only : false; // version without "ro" si.read_only = (read_only ? *read_only : (ro ? *ro : false));