From 2eec6b44c3ec62374913ba9bfe847c2d395714bc Mon Sep 17 00:00:00 2001 From: oltolm Date: Tue, 10 Jun 2025 08:15:25 +0200 Subject: [PATCH] UI: Use wxListView instead of wxListCtrl (#1584) --- src/gui/MemorySearcherTool.cpp | 11 ++----- src/gui/MemorySearcherTool.h | 2 +- src/gui/components/wxDownloadManagerList.cpp | 13 ++++----- src/gui/components/wxDownloadManagerList.h | 2 +- src/gui/components/wxGameList.cpp | 27 +++++++++-------- src/gui/components/wxGameList.h | 2 +- src/gui/components/wxTitleManagerList.cpp | 12 ++++---- src/gui/components/wxTitleManagerList.h | 2 +- src/gui/debugger/BreakpointWindow.cpp | 6 ++-- src/gui/debugger/SymbolCtrl.cpp | 8 ++--- src/gui/debugger/SymbolCtrl.h | 2 +- .../DebugPPCThreadsWindow.cpp | 29 ++++++++++--------- .../PPCThreadsViewer/DebugPPCThreadsWindow.h | 4 +-- src/gui/wxcomponents/checkedlistctrl.h | 6 ++-- 14 files changed, 61 insertions(+), 65 deletions(-) diff --git a/src/gui/MemorySearcherTool.cpp b/src/gui/MemorySearcherTool.cpp index 2fd60da1..8506c591 100644 --- a/src/gui/MemorySearcherTool.cpp +++ b/src/gui/MemorySearcherTool.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "config/ActiveSettings.h" #include "gui/helpers/wxHelpers.h" @@ -79,7 +80,7 @@ MemorySearcherTool::MemorySearcherTool(wxFrame* parent) m_gauge->Enable(false); m_textEntryTable = new wxStaticText(this, wxID_ANY, _("Results")); - m_listResults = new wxListCtrl(this, LIST_RESULTS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SORT_ASCENDING); + m_listResults = new wxListView(this, LIST_RESULTS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SORT_ASCENDING); m_listResults->Bind(wxEVT_LEFT_DCLICK, &MemorySearcherTool::OnResultListClick, this); { wxListItem col0; @@ -388,14 +389,8 @@ void MemorySearcherTool::OnEntryListRightClick(wxDataViewEvent& event) void MemorySearcherTool::OnResultListClick(wxMouseEvent& event) { - long selectedIndex = -1; - - while (true) + for (long selectedIndex = m_listResults->GetFirstSelected(); selectedIndex != wxNOT_FOUND; selectedIndex = m_listResults->GetNextSelected(selectedIndex)) { - selectedIndex = m_listResults->GetNextItem(selectedIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (selectedIndex == wxNOT_FOUND) - break; - long address = m_listResults->GetItemData(selectedIndex); auto currValue = m_listResults->GetItemText(selectedIndex, 1); diff --git a/src/gui/MemorySearcherTool.h b/src/gui/MemorySearcherTool.h index 78b5cb77..27e7d27d 100644 --- a/src/gui/MemorySearcherTool.h +++ b/src/gui/MemorySearcherTool.h @@ -173,7 +173,7 @@ wxDECLARE_EVENT_TABLE(); wxComboBox* m_cbDataType; wxTextCtrl* m_textValue; wxButton *m_buttonStart, *m_buttonFilter; - wxListCtrl* m_listResults; + wxListView* m_listResults; wxDataViewListCtrl* m_listEntryTable; wxStaticText* m_textEntryTable; wxGauge* m_gauge; diff --git a/src/gui/components/wxDownloadManagerList.cpp b/src/gui/components/wxDownloadManagerList.cpp index 14bf5cbe..fc63155d 100644 --- a/src/gui/components/wxDownloadManagerList.cpp +++ b/src/gui/components/wxDownloadManagerList.cpp @@ -25,9 +25,8 @@ wxDEFINE_EVENT(wxEVT_REMOVE_ENTRY, wxCommandEvent); - wxDownloadManagerList::wxDownloadManagerList(wxWindow* parent, wxWindowID id) - : wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL) + : wxListView(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL) { AddColumns(); @@ -52,7 +51,7 @@ wxDownloadManagerList::wxDownloadManagerList(wxWindow* parent, wxWindowID id) boost::optional wxDownloadManagerList::GetSelectedTitleEntry() const { - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const auto selection = GetFirstSelected(); if (selection != wxNOT_FOUND) { const auto tmp = GetTitleEntry(selection); @@ -65,7 +64,7 @@ boost::optional wxDownloadManagerList: boost::optional wxDownloadManagerList::GetSelectedTitleEntry() { - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const auto selection = GetFirstSelected(); if (selection != wxNOT_FOUND) { const auto tmp = GetTitleEntry(selection); @@ -324,7 +323,7 @@ void wxDownloadManagerList::OnContextMenu(wxContextMenuEvent& event) wxMenu menu; menu.Bind(wxEVT_COMMAND_MENU_SELECTED, &wxDownloadManagerList::OnContextMenuSelected, this); - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const auto selection = GetFirstSelected(); if (selection == wxNOT_FOUND) return; @@ -379,8 +378,8 @@ void wxDownloadManagerList::OnContextMenuSelected(wxCommandEvent& event) // still doing work if (m_context_worker.valid() && !future_is_ready(m_context_worker)) return; - - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + + const auto selection = GetFirstSelected(); if (selection == wxNOT_FOUND) return; diff --git a/src/gui/components/wxDownloadManagerList.h b/src/gui/components/wxDownloadManagerList.h index 3a6b853a..6723056a 100644 --- a/src/gui/components/wxDownloadManagerList.h +++ b/src/gui/components/wxDownloadManagerList.h @@ -9,7 +9,7 @@ #include #include -class wxDownloadManagerList : public wxListCtrl +class wxDownloadManagerList : public wxListView { friend class TitleManager; public: diff --git a/src/gui/components/wxGameList.cpp b/src/gui/components/wxGameList.cpp index 95711fef..4901e2d4 100644 --- a/src/gui/components/wxGameList.cpp +++ b/src/gui/components/wxGameList.cpp @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -133,7 +134,7 @@ bool writeICNS(const fs::path& pngPath, const fs::path& icnsPath) { } wxGameList::wxGameList(wxWindow* parent, wxWindowID id) - : wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, GetStyleFlags(Style::kList)), m_style(Style::kList) + : wxListView(parent, id, wxDefaultPosition, wxDefaultSize, GetStyleFlags(Style::kList)), m_style(Style::kList) { const auto& config = GetConfig(); @@ -393,7 +394,7 @@ void wxGameList::SetStyle(Style style, bool save) SetWindowStyleFlag(GetStyleFlags(m_style)); uint64 selected_title_id = 0; - auto selection = GetNextItem(wxNOT_FOUND, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + auto selection = GetFirstSelected(); if (selection != wxNOT_FOUND) { selected_title_id = (uint64)GetItemData(selection); @@ -416,8 +417,8 @@ void wxGameList::SetStyle(Style style, bool save) if(selection != wxNOT_FOUND) { - SetItemState(selection, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED); - EnsureVisible(selection); + Select(selection); + Focus(selection); } if(save) @@ -549,15 +550,14 @@ void wxGameList::OnKeyDown(wxListEvent& event) const auto item_count = GetItemCount(); if (item_count > 0) { - auto selection = (int)GetNextItem(wxNOT_FOUND, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + auto selection = (int)GetFirstSelected(); if (selection == wxNOT_FOUND) selection = 0; else selection = std::max(0, selection - GetCountPerPage()); - SetItemState(wxNOT_FOUND, 0, wxLIST_STATE_SELECTED); - SetItemState(selection, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED); - EnsureVisible(selection); + Select(selection); + Focus(selection); } } else if (keycode == WXK_RIGHT) @@ -565,15 +565,14 @@ void wxGameList::OnKeyDown(wxListEvent& event) const auto item_count = GetItemCount(); if (item_count > 0) { - auto selection = (int)GetNextItem(wxNOT_FOUND, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + auto selection = (int)GetFirstSelected(); if (selection == wxNOT_FOUND) selection = 0; selection = std::min(item_count - 1, selection + GetCountPerPage()); - SetItemState(wxNOT_FOUND, 0, wxLIST_STATE_SELECTED); - SetItemState(selection, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED); - EnsureVisible(selection); + Select(selection); + Focus(selection); } } } @@ -613,7 +612,7 @@ void wxGameList::OnContextMenu(wxContextMenuEvent& event) wxMenu menu; menu.Bind(wxEVT_COMMAND_MENU_SELECTED, &wxGameList::OnContextMenuSelected, this); - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const auto selection = GetFirstSelected(); if (selection != wxNOT_FOUND) { const auto title_id = (uint64)GetItemData(selection); @@ -1632,4 +1631,4 @@ void wxGameList::CreateShortcut(GameInfo2& gameInfo) wxMessageBox(errorMsg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); } } -#endif \ No newline at end of file +#endif diff --git a/src/gui/components/wxGameList.h b/src/gui/components/wxGameList.h index a6bfa7f7..698f1294 100644 --- a/src/gui/components/wxGameList.h +++ b/src/gui/components/wxGameList.h @@ -30,7 +30,7 @@ wxDECLARE_EVENT(wxEVT_OPEN_GRAPHIC_PACK, wxTitleIdEvent); wxDECLARE_EVENT(wxEVT_GAMELIST_BEGIN_UPDATE, wxCommandEvent); wxDECLARE_EVENT(wxEVT_GAMELIST_END_UPDATE, wxCommandEvent); -class wxGameList : public wxListCtrl +class wxGameList : public wxListView { friend class MainWindow; public: diff --git a/src/gui/components/wxTitleManagerList.cpp b/src/gui/components/wxTitleManagerList.cpp index c0bf5778..2752ddda 100644 --- a/src/gui/components/wxTitleManagerList.cpp +++ b/src/gui/components/wxTitleManagerList.cpp @@ -38,7 +38,7 @@ wxDEFINE_EVENT(wxEVT_TITLE_REMOVED, wxCommandEvent); wxDEFINE_EVENT(wxEVT_REMOVE_ENTRY, wxCommandEvent); wxTitleManagerList::wxTitleManagerList(wxWindow* parent, wxWindowID id) - : wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL) + : wxListView(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL) { AddColumns(); @@ -74,7 +74,7 @@ wxTitleManagerList::~wxTitleManagerList() boost::optional wxTitleManagerList::GetSelectedTitleEntry() const { - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const auto selection = GetFirstSelected(); if (selection != wxNOT_FOUND) { const auto tmp = GetTitleEntry(selection); @@ -87,7 +87,7 @@ boost::optional wxTitleManagerList::GetSe boost::optional wxTitleManagerList::GetSelectedTitleEntry() { - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const auto selection = GetFirstSelected(); if (selection != wxNOT_FOUND) { const auto tmp = GetTitleEntry(selection); @@ -757,7 +757,7 @@ void wxTitleManagerList::OnContextMenu(wxContextMenuEvent& event) wxMenu menu; menu.Bind(wxEVT_COMMAND_MENU_SELECTED, &wxTitleManagerList::OnContextMenuSelected, this); - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const auto selection = GetFirstSelected(); if (selection == wxNOT_FOUND) return; @@ -855,8 +855,8 @@ void wxTitleManagerList::OnContextMenuSelected(wxCommandEvent& event) // still doing work if (m_context_worker.valid() && !future_is_ready(m_context_worker)) return; - - const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + + const auto selection = GetFirstSelected(); if (selection == wxNOT_FOUND) return; diff --git a/src/gui/components/wxTitleManagerList.h b/src/gui/components/wxTitleManagerList.h index 2780a9ce..8057bdd8 100644 --- a/src/gui/components/wxTitleManagerList.h +++ b/src/gui/components/wxTitleManagerList.h @@ -9,7 +9,7 @@ #include #include -class wxTitleManagerList : public wxListCtrl +class wxTitleManagerList : public wxListView { friend class TitleManager; public: diff --git a/src/gui/debugger/BreakpointWindow.cpp b/src/gui/debugger/BreakpointWindow.cpp index 141e4603..c693477d 100644 --- a/src/gui/debugger/BreakpointWindow.cpp +++ b/src/gui/debugger/BreakpointWindow.cpp @@ -230,8 +230,8 @@ void BreakpointWindow::OnRightDown(wxMouseEvent& event) } else { - m_breakpoints->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); - m_breakpoints->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + m_breakpoints->Focus(index); + m_breakpoints->Select(index); wxMenu menu; menu.Append(MENU_ID_DELETE_BP, _("Delete breakpoint")); @@ -245,7 +245,7 @@ void BreakpointWindow::OnContextMenuClickSelected(wxCommandEvent& evt) { if (evt.GetId() == MENU_ID_DELETE_BP) { - long sel = m_breakpoints->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + long sel = m_breakpoints->GetFirstSelected(); if (sel != wxNOT_FOUND) { if (sel >= debuggerState.breakpoints.size()) diff --git a/src/gui/debugger/SymbolCtrl.cpp b/src/gui/debugger/SymbolCtrl.cpp index fd079d7b..57cc96f6 100644 --- a/src/gui/debugger/SymbolCtrl.cpp +++ b/src/gui/debugger/SymbolCtrl.cpp @@ -2,6 +2,7 @@ #include "gui/guiWrapper.h" #include "Cafe/OS/RPL/rpl_symbol_storage.h" #include "Cafe/HW/Espresso/Debugger/Debugger.h" +#include enum ItemColumns { @@ -10,8 +11,7 @@ enum ItemColumns ColumnModule, }; -SymbolListCtrl::SymbolListCtrl(wxWindow* parent, const wxWindowID& id, const wxPoint& pos, const wxSize& size) : - wxListCtrl(parent, id, pos, size, wxLC_REPORT | wxLC_VIRTUAL) +SymbolListCtrl::SymbolListCtrl(wxWindow* parent, const wxWindowID& id, const wxPoint& pos, const wxSize& size) : wxListView(parent, id, pos, size, wxLC_REPORT | wxLC_VIRTUAL) { wxListItem col0; col0.SetId(ColumnName); @@ -106,7 +106,7 @@ wxString SymbolListCtrl::OnGetItemText(long item, long column) const void SymbolListCtrl::OnLeftDClick(wxListEvent& event) { - long selected = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + long selected = GetFirstSelected(); if (selected == wxNOT_FOUND) return; const auto text = GetItemText(selected, ColumnAddress); @@ -119,7 +119,7 @@ void SymbolListCtrl::OnLeftDClick(wxListEvent& event) void SymbolListCtrl::OnRightClick(wxListEvent& event) { - long selected = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + long selected = GetFirstSelected(); if (selected == wxNOT_FOUND) return; auto text = GetItemText(selected, ColumnAddress); diff --git a/src/gui/debugger/SymbolCtrl.h b/src/gui/debugger/SymbolCtrl.h index 81ccd326..8a0161bd 100644 --- a/src/gui/debugger/SymbolCtrl.h +++ b/src/gui/debugger/SymbolCtrl.h @@ -2,7 +2,7 @@ #include -class SymbolListCtrl : public wxListCtrl +class SymbolListCtrl : public wxListView { public: SymbolListCtrl(wxWindow* parent, const wxWindowID& id, const wxPoint& pos, const wxSize& size); diff --git a/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp b/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp index 6b69b0f0..0669321c 100644 --- a/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp +++ b/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp @@ -9,6 +9,7 @@ #include #include +#include enum { @@ -42,7 +43,7 @@ DebugPPCThreadsWindow::DebugPPCThreadsWindow(wxFrame& parent) wxFrame::SetBackgroundColour(*wxWHITE); auto* sizer = new wxBoxSizer(wxVERTICAL); - m_thread_list = new wxListCtrl(this, GPLIST_ID, wxPoint(0, 0), wxSize(930, 240), wxLC_REPORT); + m_thread_list = new wxListView(this, GPLIST_ID, wxPoint(0, 0), wxSize(930, 240), wxLC_REPORT); m_thread_list->SetFont(wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, "Courier New")); //wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT)); @@ -169,7 +170,7 @@ void DebugPPCThreadsWindow::RefreshThreadList() wxWindowUpdateLocker lock(m_thread_list); long selected_thread = 0; - const int selection = m_thread_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + const int selection = m_thread_list->GetFirstSelected(); if (selection != wxNOT_FOUND) selected_thread = m_thread_list->GetItemData(selection); @@ -267,12 +268,15 @@ void DebugPPCThreadsWindow::RefreshThreadList() m_thread_list->SetItem(i, 12, tempStr); - if(selected_thread != 0 && selected_thread == (long)threadItrMPTR) - m_thread_list->SetItemState(i, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED); - } - srwlock_activeThreadList.UnlockWrite(); - __OSUnlockScheduler(); - } + if (selected_thread != 0 && selected_thread == (long)threadItrMPTR) + { + m_thread_list->Select(i); + m_thread_list->Focus(i); + } + } + srwlock_activeThreadList.UnlockWrite(); + __OSUnlockScheduler(); + } m_thread_list->SetScrollPos(0, scrollPos, true); } @@ -436,12 +440,11 @@ void DebugPPCThreadsWindow::OnThreadListRightClick(wxMouseEvent& event) if (itemIndex == wxNOT_FOUND) return; // select item - m_thread_list->SetItemState(itemIndex, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); - long sel = m_thread_list->GetNextItem(-1, wxLIST_NEXT_ALL, - wxLIST_STATE_SELECTED); + m_thread_list->Focus(itemIndex); + long sel = m_thread_list->GetFirstSelected(); if (sel != wxNOT_FOUND) - m_thread_list->SetItemState(sel, 0, wxLIST_STATE_SELECTED); - m_thread_list->SetItemState(itemIndex, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + m_thread_list->Select(sel, false); + m_thread_list->Select(itemIndex); // check if thread is still on the list of active threads MPTR threadMPTR = (MPTR)m_thread_list->GetItemData(itemIndex); __OSLockScheduler(); diff --git a/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.h b/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.h index 649780c5..f6dc9060 100644 --- a/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.h +++ b/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.h @@ -23,7 +23,7 @@ private: void PresentProfileResults(OSThread_t* thread, const std::unordered_map& samples); void DumpStackTrace(struct OSThread_t* thread); - wxListCtrl* m_thread_list; + wxListView* m_thread_list; wxCheckBox* m_auto_refresh; wxTimer* m_timer; @@ -32,4 +32,4 @@ private: wxDECLARE_EVENT_TABLE(); -}; \ No newline at end of file +}; diff --git a/src/gui/wxcomponents/checkedlistctrl.h b/src/gui/wxcomponents/checkedlistctrl.h index 926c2ba7..e09536f9 100644 --- a/src/gui/wxcomponents/checkedlistctrl.h +++ b/src/gui/wxcomponents/checkedlistctrl.h @@ -72,7 +72,7 @@ DECLARE_EXPORTED_EVENT_TYPE(WXEXPORT, wxEVT_COMMAND_LIST_ITEM_UNCHECKED, -1); //! This is the class which performs all transactions with the server. //! It uses the wxSocket facilities. -class wxCheckedListCtrl : public wxListCtrl +class wxCheckedListCtrl : public wxListView { protected: @@ -85,7 +85,7 @@ protected: public: wxCheckedListCtrl() - : wxListCtrl(), m_imageList(16, 16, TRUE) {} + : wxListView(), m_imageList(16, 16, TRUE) {} wxCheckedListCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pt = wxDefaultPosition, @@ -93,7 +93,7 @@ public: long style = wxCLC_CHECK_WHEN_SELECTING, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxListCtrlNameStr) - : wxListCtrl(), m_imageList(16, 16, TRUE) + : wxListView(), m_imageList(16, 16, TRUE) { Create(parent, id, pt, sz, style, validator, name); } bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,