Skip to content

Commit 2eec6b4

Browse files
authored
UI: Use wxListView instead of wxListCtrl (#1584)
1 parent 3eff2d4 commit 2eec6b4

14 files changed

+61
-65
lines changed

src/gui/MemorySearcherTool.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66
#include <sstream>
77
#include <thread>
8+
#include <wx/listctrl.h>
89

910
#include "config/ActiveSettings.h"
1011
#include "gui/helpers/wxHelpers.h"
@@ -79,7 +80,7 @@ MemorySearcherTool::MemorySearcherTool(wxFrame* parent)
7980
m_gauge->Enable(false);
8081

8182
m_textEntryTable = new wxStaticText(this, wxID_ANY, _("Results"));
82-
m_listResults = new wxListCtrl(this, LIST_RESULTS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SORT_ASCENDING);
83+
m_listResults = new wxListView(this, LIST_RESULTS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SORT_ASCENDING);
8384
m_listResults->Bind(wxEVT_LEFT_DCLICK, &MemorySearcherTool::OnResultListClick, this);
8485
{
8586
wxListItem col0;
@@ -388,14 +389,8 @@ void MemorySearcherTool::OnEntryListRightClick(wxDataViewEvent& event)
388389

389390
void MemorySearcherTool::OnResultListClick(wxMouseEvent& event)
390391
{
391-
long selectedIndex = -1;
392-
393-
while (true)
392+
for (long selectedIndex = m_listResults->GetFirstSelected(); selectedIndex != wxNOT_FOUND; selectedIndex = m_listResults->GetNextSelected(selectedIndex))
394393
{
395-
selectedIndex = m_listResults->GetNextItem(selectedIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
396-
if (selectedIndex == wxNOT_FOUND)
397-
break;
398-
399394
long address = m_listResults->GetItemData(selectedIndex);
400395
auto currValue = m_listResults->GetItemText(selectedIndex, 1);
401396

src/gui/MemorySearcherTool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ wxDECLARE_EVENT_TABLE();
173173
wxComboBox* m_cbDataType;
174174
wxTextCtrl* m_textValue;
175175
wxButton *m_buttonStart, *m_buttonFilter;
176-
wxListCtrl* m_listResults;
176+
wxListView* m_listResults;
177177
wxDataViewListCtrl* m_listEntryTable;
178178
wxStaticText* m_textEntryTable;
179179
wxGauge* m_gauge;

src/gui/components/wxDownloadManagerList.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525

2626
wxDEFINE_EVENT(wxEVT_REMOVE_ENTRY, wxCommandEvent);
2727

28-
2928
wxDownloadManagerList::wxDownloadManagerList(wxWindow* parent, wxWindowID id)
30-
: wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL)
29+
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL)
3130
{
3231
AddColumns();
3332

@@ -52,7 +51,7 @@ wxDownloadManagerList::wxDownloadManagerList(wxWindow* parent, wxWindowID id)
5251

5352
boost::optional<const wxDownloadManagerList::TitleEntry&> wxDownloadManagerList::GetSelectedTitleEntry() const
5453
{
55-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
54+
const auto selection = GetFirstSelected();
5655
if (selection != wxNOT_FOUND)
5756
{
5857
const auto tmp = GetTitleEntry(selection);
@@ -65,7 +64,7 @@ boost::optional<const wxDownloadManagerList::TitleEntry&> wxDownloadManagerList:
6564

6665
boost::optional<wxDownloadManagerList::TitleEntry&> wxDownloadManagerList::GetSelectedTitleEntry()
6766
{
68-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
67+
const auto selection = GetFirstSelected();
6968
if (selection != wxNOT_FOUND)
7069
{
7170
const auto tmp = GetTitleEntry(selection);
@@ -324,7 +323,7 @@ void wxDownloadManagerList::OnContextMenu(wxContextMenuEvent& event)
324323
wxMenu menu;
325324
menu.Bind(wxEVT_COMMAND_MENU_SELECTED, &wxDownloadManagerList::OnContextMenuSelected, this);
326325

327-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
326+
const auto selection = GetFirstSelected();
328327
if (selection == wxNOT_FOUND)
329328
return;
330329

@@ -379,8 +378,8 @@ void wxDownloadManagerList::OnContextMenuSelected(wxCommandEvent& event)
379378
// still doing work
380379
if (m_context_worker.valid() && !future_is_ready(m_context_worker))
381380
return;
382-
383-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
381+
382+
const auto selection = GetFirstSelected();
384383
if (selection == wxNOT_FOUND)
385384
return;
386385

src/gui/components/wxDownloadManagerList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <utility>
1010
#include <vector>
1111

12-
class wxDownloadManagerList : public wxListCtrl
12+
class wxDownloadManagerList : public wxListView
1313
{
1414
friend class TitleManager;
1515
public:

src/gui/components/wxGameList.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <numeric>
88

9+
#include <wx/listctrl.h>
910
#include <wx/wupdlock.h>
1011
#include <wx/menu.h>
1112
#include <wx/mstream.h>
@@ -133,7 +134,7 @@ bool writeICNS(const fs::path& pngPath, const fs::path& icnsPath) {
133134
}
134135

135136
wxGameList::wxGameList(wxWindow* parent, wxWindowID id)
136-
: wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, GetStyleFlags(Style::kList)), m_style(Style::kList)
137+
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, GetStyleFlags(Style::kList)), m_style(Style::kList)
137138
{
138139
const auto& config = GetConfig();
139140

@@ -393,7 +394,7 @@ void wxGameList::SetStyle(Style style, bool save)
393394
SetWindowStyleFlag(GetStyleFlags(m_style));
394395

395396
uint64 selected_title_id = 0;
396-
auto selection = GetNextItem(wxNOT_FOUND, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
397+
auto selection = GetFirstSelected();
397398
if (selection != wxNOT_FOUND)
398399
{
399400
selected_title_id = (uint64)GetItemData(selection);
@@ -416,8 +417,8 @@ void wxGameList::SetStyle(Style style, bool save)
416417

417418
if(selection != wxNOT_FOUND)
418419
{
419-
SetItemState(selection, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
420-
EnsureVisible(selection);
420+
Select(selection);
421+
Focus(selection);
421422
}
422423

423424
if(save)
@@ -549,31 +550,29 @@ void wxGameList::OnKeyDown(wxListEvent& event)
549550
const auto item_count = GetItemCount();
550551
if (item_count > 0)
551552
{
552-
auto selection = (int)GetNextItem(wxNOT_FOUND, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
553+
auto selection = (int)GetFirstSelected();
553554
if (selection == wxNOT_FOUND)
554555
selection = 0;
555556
else
556557
selection = std::max(0, selection - GetCountPerPage());
557558

558-
SetItemState(wxNOT_FOUND, 0, wxLIST_STATE_SELECTED);
559-
SetItemState(selection, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
560-
EnsureVisible(selection);
559+
Select(selection);
560+
Focus(selection);
561561
}
562562
}
563563
else if (keycode == WXK_RIGHT)
564564
{
565565
const auto item_count = GetItemCount();
566566
if (item_count > 0)
567567
{
568-
auto selection = (int)GetNextItem(wxNOT_FOUND, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
568+
auto selection = (int)GetFirstSelected();
569569
if (selection == wxNOT_FOUND)
570570
selection = 0;
571571

572572
selection = std::min(item_count - 1, selection + GetCountPerPage());
573573

574-
SetItemState(wxNOT_FOUND, 0, wxLIST_STATE_SELECTED);
575-
SetItemState(selection, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
576-
EnsureVisible(selection);
574+
Select(selection);
575+
Focus(selection);
577576
}
578577
}
579578
}
@@ -613,7 +612,7 @@ void wxGameList::OnContextMenu(wxContextMenuEvent& event)
613612
wxMenu menu;
614613
menu.Bind(wxEVT_COMMAND_MENU_SELECTED, &wxGameList::OnContextMenuSelected, this);
615614

616-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
615+
const auto selection = GetFirstSelected();
617616
if (selection != wxNOT_FOUND)
618617
{
619618
const auto title_id = (uint64)GetItemData(selection);
@@ -1632,4 +1631,4 @@ void wxGameList::CreateShortcut(GameInfo2& gameInfo)
16321631
wxMessageBox(errorMsg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
16331632
}
16341633
}
1635-
#endif
1634+
#endif

src/gui/components/wxGameList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ wxDECLARE_EVENT(wxEVT_OPEN_GRAPHIC_PACK, wxTitleIdEvent);
3030
wxDECLARE_EVENT(wxEVT_GAMELIST_BEGIN_UPDATE, wxCommandEvent);
3131
wxDECLARE_EVENT(wxEVT_GAMELIST_END_UPDATE, wxCommandEvent);
3232

33-
class wxGameList : public wxListCtrl
33+
class wxGameList : public wxListView
3434
{
3535
friend class MainWindow;
3636
public:

src/gui/components/wxTitleManagerList.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ wxDEFINE_EVENT(wxEVT_TITLE_REMOVED, wxCommandEvent);
3838
wxDEFINE_EVENT(wxEVT_REMOVE_ENTRY, wxCommandEvent);
3939

4040
wxTitleManagerList::wxTitleManagerList(wxWindow* parent, wxWindowID id)
41-
: wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL)
41+
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL)
4242
{
4343
AddColumns();
4444

@@ -74,7 +74,7 @@ wxTitleManagerList::~wxTitleManagerList()
7474

7575
boost::optional<const wxTitleManagerList::TitleEntry&> wxTitleManagerList::GetSelectedTitleEntry() const
7676
{
77-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
77+
const auto selection = GetFirstSelected();
7878
if (selection != wxNOT_FOUND)
7979
{
8080
const auto tmp = GetTitleEntry(selection);
@@ -87,7 +87,7 @@ boost::optional<const wxTitleManagerList::TitleEntry&> wxTitleManagerList::GetSe
8787

8888
boost::optional<wxTitleManagerList::TitleEntry&> wxTitleManagerList::GetSelectedTitleEntry()
8989
{
90-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
90+
const auto selection = GetFirstSelected();
9191
if (selection != wxNOT_FOUND)
9292
{
9393
const auto tmp = GetTitleEntry(selection);
@@ -757,7 +757,7 @@ void wxTitleManagerList::OnContextMenu(wxContextMenuEvent& event)
757757
wxMenu menu;
758758
menu.Bind(wxEVT_COMMAND_MENU_SELECTED, &wxTitleManagerList::OnContextMenuSelected, this);
759759

760-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
760+
const auto selection = GetFirstSelected();
761761
if (selection == wxNOT_FOUND)
762762
return;
763763

@@ -855,8 +855,8 @@ void wxTitleManagerList::OnContextMenuSelected(wxCommandEvent& event)
855855
// still doing work
856856
if (m_context_worker.valid() && !future_is_ready(m_context_worker))
857857
return;
858-
859-
const auto selection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
858+
859+
const auto selection = GetFirstSelected();
860860
if (selection == wxNOT_FOUND)
861861
return;
862862

src/gui/components/wxTitleManagerList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <utility>
1010
#include <vector>
1111

12-
class wxTitleManagerList : public wxListCtrl
12+
class wxTitleManagerList : public wxListView
1313
{
1414
friend class TitleManager;
1515
public:

src/gui/debugger/BreakpointWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ void BreakpointWindow::OnRightDown(wxMouseEvent& event)
230230
}
231231
else
232232
{
233-
m_breakpoints->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
234-
m_breakpoints->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
233+
m_breakpoints->Focus(index);
234+
m_breakpoints->Select(index);
235235

236236
wxMenu menu;
237237
menu.Append(MENU_ID_DELETE_BP, _("Delete breakpoint"));
@@ -245,7 +245,7 @@ void BreakpointWindow::OnContextMenuClickSelected(wxCommandEvent& evt)
245245
{
246246
if (evt.GetId() == MENU_ID_DELETE_BP)
247247
{
248-
long sel = m_breakpoints->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
248+
long sel = m_breakpoints->GetFirstSelected();
249249
if (sel != wxNOT_FOUND)
250250
{
251251
if (sel >= debuggerState.breakpoints.size())

src/gui/debugger/SymbolCtrl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "gui/guiWrapper.h"
33
#include "Cafe/OS/RPL/rpl_symbol_storage.h"
44
#include "Cafe/HW/Espresso/Debugger/Debugger.h"
5+
#include <wx/listctrl.h>
56

67
enum ItemColumns
78
{
@@ -10,8 +11,7 @@ enum ItemColumns
1011
ColumnModule,
1112
};
1213

13-
SymbolListCtrl::SymbolListCtrl(wxWindow* parent, const wxWindowID& id, const wxPoint& pos, const wxSize& size) :
14-
wxListCtrl(parent, id, pos, size, wxLC_REPORT | wxLC_VIRTUAL)
14+
SymbolListCtrl::SymbolListCtrl(wxWindow* parent, const wxWindowID& id, const wxPoint& pos, const wxSize& size) : wxListView(parent, id, pos, size, wxLC_REPORT | wxLC_VIRTUAL)
1515
{
1616
wxListItem col0;
1717
col0.SetId(ColumnName);
@@ -106,7 +106,7 @@ wxString SymbolListCtrl::OnGetItemText(long item, long column) const
106106

107107
void SymbolListCtrl::OnLeftDClick(wxListEvent& event)
108108
{
109-
long selected = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
109+
long selected = GetFirstSelected();
110110
if (selected == wxNOT_FOUND)
111111
return;
112112
const auto text = GetItemText(selected, ColumnAddress);
@@ -119,7 +119,7 @@ void SymbolListCtrl::OnLeftDClick(wxListEvent& event)
119119

120120
void SymbolListCtrl::OnRightClick(wxListEvent& event)
121121
{
122-
long selected = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
122+
long selected = GetFirstSelected();
123123
if (selected == wxNOT_FOUND)
124124
return;
125125
auto text = GetItemText(selected, ColumnAddress);

src/gui/debugger/SymbolCtrl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <wx/listctrl.h>
44

5-
class SymbolListCtrl : public wxListCtrl
5+
class SymbolListCtrl : public wxListView
66
{
77
public:
88
SymbolListCtrl(wxWindow* parent, const wxWindowID& id, const wxPoint& pos, const wxSize& size);

src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <cinttypes>
1111
#include <helpers/wxHelpers.h>
12+
#include <wx/listctrl.h>
1213

1314
enum
1415
{
@@ -42,7 +43,7 @@ DebugPPCThreadsWindow::DebugPPCThreadsWindow(wxFrame& parent)
4243
wxFrame::SetBackgroundColour(*wxWHITE);
4344

4445
auto* sizer = new wxBoxSizer(wxVERTICAL);
45-
m_thread_list = new wxListCtrl(this, GPLIST_ID, wxPoint(0, 0), wxSize(930, 240), wxLC_REPORT);
46+
m_thread_list = new wxListView(this, GPLIST_ID, wxPoint(0, 0), wxSize(930, 240), wxLC_REPORT);
4647

4748
m_thread_list->SetFont(wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, "Courier New")); //wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT));
4849

@@ -169,7 +170,7 @@ void DebugPPCThreadsWindow::RefreshThreadList()
169170
wxWindowUpdateLocker lock(m_thread_list);
170171

171172
long selected_thread = 0;
172-
const int selection = m_thread_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
173+
const int selection = m_thread_list->GetFirstSelected();
173174
if (selection != wxNOT_FOUND)
174175
selected_thread = m_thread_list->GetItemData(selection);
175176

@@ -267,12 +268,15 @@ void DebugPPCThreadsWindow::RefreshThreadList()
267268

268269
m_thread_list->SetItem(i, 12, tempStr);
269270

270-
if(selected_thread != 0 && selected_thread == (long)threadItrMPTR)
271-
m_thread_list->SetItemState(i, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
272-
}
273-
srwlock_activeThreadList.UnlockWrite();
274-
__OSUnlockScheduler();
275-
}
271+
if (selected_thread != 0 && selected_thread == (long)threadItrMPTR)
272+
{
273+
m_thread_list->Select(i);
274+
m_thread_list->Focus(i);
275+
}
276+
}
277+
srwlock_activeThreadList.UnlockWrite();
278+
__OSUnlockScheduler();
279+
}
276280

277281
m_thread_list->SetScrollPos(0, scrollPos, true);
278282
}
@@ -436,12 +440,11 @@ void DebugPPCThreadsWindow::OnThreadListRightClick(wxMouseEvent& event)
436440
if (itemIndex == wxNOT_FOUND)
437441
return;
438442
// select item
439-
m_thread_list->SetItemState(itemIndex, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
440-
long sel = m_thread_list->GetNextItem(-1, wxLIST_NEXT_ALL,
441-
wxLIST_STATE_SELECTED);
443+
m_thread_list->Focus(itemIndex);
444+
long sel = m_thread_list->GetFirstSelected();
442445
if (sel != wxNOT_FOUND)
443-
m_thread_list->SetItemState(sel, 0, wxLIST_STATE_SELECTED);
444-
m_thread_list->SetItemState(itemIndex, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
446+
m_thread_list->Select(sel, false);
447+
m_thread_list->Select(itemIndex);
445448
// check if thread is still on the list of active threads
446449
MPTR threadMPTR = (MPTR)m_thread_list->GetItemData(itemIndex);
447450
__OSLockScheduler();

0 commit comments

Comments
 (0)