From 152b790242e20333ef1a1c9b551a43c787993af1 Mon Sep 17 00:00:00 2001 From: oltolm Date: Fri, 30 May 2025 01:39:02 +0200 Subject: [PATCH] UI: Use wxID_ANY and wxNOT_FOUND instead of hardcoding -1 (#1581) --- src/gui/MainWindow.cpp | 74 +++++++++---------- src/gui/MemorySearcherTool.cpp | 6 +- src/gui/debugger/BreakpointWindow.cpp | 2 +- src/gui/debugger/ModuleWindow.cpp | 2 +- src/gui/debugger/SymbolCtrl.cpp | 6 +- .../DebugPPCThreadsWindow.cpp | 2 +- src/gui/wxcomponents/checkedlistctrl.h | 4 +- 7 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 2f63b460..b032a357 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -286,7 +286,7 @@ private: }; MainWindow::MainWindow() - : wxFrame(nullptr, -1, GetInitialWindowTitle(), wxDefaultPosition, wxSize(1280, 720), wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN | wxRESIZE_BORDER) + : wxFrame(nullptr, wxID_ANY, GetInitialWindowTitle(), wxDefaultPosition, wxSize(1280, 720), wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN | wxRESIZE_BORDER) { gui_initHandleContextFromWxWidgetsWindow(g_window_info.window_main, this); g_mainFrame = this; @@ -1859,7 +1859,7 @@ public: auto versionString = formatWxString(_("Cemu\nVersion {0}\nCompiled on {1}\nOriginal authors: {2}"), BUILD_VERSION_STRING, BUILD_DATE, "Exzap, Petergov"); sizer->Add(new wxStaticText(parent, wxID_ANY, versionString), wxSizerFlags().Border(wxALL, 3).Border(wxTOP, 10)); - sizer->Add(new wxHyperlinkCtrl(parent, -1, "https://cemu.info", "https://cemu.info"), wxSizerFlags().Expand().Border(wxTOP | wxBOTTOM, 3)); + sizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://cemu.info", "https://cemu.info"), wxSizerFlags().Expand().Border(wxTOP | wxBOTTOM, 3)); sizer->AddSpacer(3); sizer->Add(new wxStaticLine(parent), wxSizerFlags().Expand().Border(wxRIGHT, 4)); @@ -1879,95 +1879,95 @@ public: // zLib { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "zLib ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://www.zlib.net", "https://www.zlib.net"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "zLib ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://www.zlib.net", "https://www.zlib.net"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // wxWidgets { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "wxWidgets ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://www.wxwidgets.org/", "https://www.wxwidgets.org/"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "wxWidgets ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://www.wxwidgets.org/", "https://www.wxwidgets.org/"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // OpenSSL { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "OpenSSL ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://www.openssl.org/", "https://www.openssl.org/"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "OpenSSL ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://www.openssl.org/", "https://www.openssl.org/"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // libcurl { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "libcurl ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://curl.haxx.se/libcurl/", "https://curl.haxx.se/libcurl/"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "libcurl ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://curl.haxx.se/libcurl/", "https://curl.haxx.se/libcurl/"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // imgui { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "imgui ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://github.com/ocornut/imgui", "https://github.com/ocornut/imgui"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "imgui ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://github.com/ocornut/imgui", "https://github.com/ocornut/imgui"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // fontawesome { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "fontawesome ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://github.com/FortAwesome/Font-Awesome", "https://github.com/FortAwesome/Font-Awesome"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "fontawesome ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://github.com/FortAwesome/Font-Awesome", "https://github.com/FortAwesome/Font-Awesome"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // boost { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "boost ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://www.boost.org", "https://www.boost.org"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "boost ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://www.boost.org", "https://www.boost.org"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // libusb { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "libusb ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://libusb.info", "https://libusb.info"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "libusb ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://libusb.info", "https://libusb.info"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // icons { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "icons from "), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://icons8.com", "https://icons8.com"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "icons from "), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://icons8.com", "https://icons8.com"), 0); sizer->Add(lineSizer); } // Lato font (are we still using it?) { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "\"Lato\" font by tyPoland Lukasz Dziedzic (OFL, V1.1)"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "\"Lato\" font by tyPoland Lukasz Dziedzic (OFL, V1.1)"), 0); sizer->Add(lineSizer); } // SDL { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "SDL ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "https://github.com/libsdl-org/SDL", "https://github.com/libsdl-org/SDL"), 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "SDL ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "https://github.com/libsdl-org/SDL", "https://github.com/libsdl-org/SDL"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } // IH264 { wxSizer* lineSizer = new wxBoxSizer(wxHORIZONTAL); - lineSizer->Add(new wxStaticText(parent, -1, "Modified ih264 from Android project ("), 0); - lineSizer->Add(new wxHyperlinkCtrl(parent, -1, "Source", "https://cemu.info/oss/ih264d.zip"), 0); - lineSizer->Add(new wxStaticText(parent, -1, " "), 0); - wxHyperlinkCtrl* noticeLink = new wxHyperlinkCtrl(parent, -1, "NOTICE", ""); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, "Modified ih264 from Android project ("), 0); + lineSizer->Add(new wxHyperlinkCtrl(parent, wxID_ANY, "Source", "https://cemu.info/oss/ih264d.zip"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, " "), 0); + wxHyperlinkCtrl* noticeLink = new wxHyperlinkCtrl(parent, wxID_ANY, "NOTICE", ""); noticeLink->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& event) { fs::path tempPath = fs::temp_directory_path(); @@ -2001,7 +2001,7 @@ public: wxLaunchDefaultBrowser(wxHelper::FromUtf8(fmt::format("file:{}", _pathToUtf8(tempPath)))); }); lineSizer->Add(noticeLink, 0); - lineSizer->Add(new wxStaticText(parent, -1, ")"), 0); + lineSizer->Add(new wxStaticText(parent, wxID_ANY, ")"), 0); sizer->Add(lineSizer); } } diff --git a/src/gui/MemorySearcherTool.cpp b/src/gui/MemorySearcherTool.cpp index fadebc44..2fd60da1 100644 --- a/src/gui/MemorySearcherTool.cpp +++ b/src/gui/MemorySearcherTool.cpp @@ -393,7 +393,7 @@ void MemorySearcherTool::OnResultListClick(wxMouseEvent& event) while (true) { selectedIndex = m_listResults->GetNextItem(selectedIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (selectedIndex == -1) + if (selectedIndex == wxNOT_FOUND) break; long address = m_listResults->GetItemData(selectedIndex); @@ -684,7 +684,7 @@ void MemorySearcherTool::OnPopupClick(wxCommandEvent& event) if (event.GetId() == LIST_ENTRY_REMOVE) { const int row = m_listEntryTable->GetSelectedRow(); - if (row == -1) + if (row == wxNOT_FOUND) return; m_listEntryTable->DeleteItem(row); @@ -700,7 +700,7 @@ void MemorySearcherTool::OnItemEdited(wxDataViewEvent& event) else if (column == 3) { auto row = m_listEntryTable->GetSelectedRow(); - if (row == -1) + if (row == wxNOT_FOUND) return; auto addressText = std::string(m_listEntryTable->GetTextValue(row, 1).mbc_str()); diff --git a/src/gui/debugger/BreakpointWindow.cpp b/src/gui/debugger/BreakpointWindow.cpp index 658a51ad..141e4603 100644 --- a/src/gui/debugger/BreakpointWindow.cpp +++ b/src/gui/debugger/BreakpointWindow.cpp @@ -246,7 +246,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); - if (sel != -1) + if (sel != wxNOT_FOUND) { if (sel >= debuggerState.breakpoints.size()) return; diff --git a/src/gui/debugger/ModuleWindow.cpp b/src/gui/debugger/ModuleWindow.cpp index c24517bd..8183c40c 100644 --- a/src/gui/debugger/ModuleWindow.cpp +++ b/src/gui/debugger/ModuleWindow.cpp @@ -126,7 +126,7 @@ void ModuleWindow::OnGameLoaded() void ModuleWindow::OnLeftDClick(wxMouseEvent& event) { long selected = m_modules->GetFirstSelected(); - if (selected == -1) + if (selected == wxNOT_FOUND) return; const auto text = m_modules->GetItemText(selected, ColumnAddress); const auto address = std::stoul(text.ToStdString(), nullptr, 16); diff --git a/src/gui/debugger/SymbolCtrl.cpp b/src/gui/debugger/SymbolCtrl.cpp index aa862987..fd079d7b 100644 --- a/src/gui/debugger/SymbolCtrl.cpp +++ b/src/gui/debugger/SymbolCtrl.cpp @@ -107,7 +107,7 @@ wxString SymbolListCtrl::OnGetItemText(long item, long column) const void SymbolListCtrl::OnLeftDClick(wxListEvent& event) { long selected = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (selected == -1) + if (selected == wxNOT_FOUND) return; const auto text = GetItemText(selected, ColumnAddress); const auto address = std::stoul(text.ToStdString(), nullptr, 16); @@ -120,7 +120,7 @@ void SymbolListCtrl::OnLeftDClick(wxListEvent& event) void SymbolListCtrl::OnRightClick(wxListEvent& event) { long selected = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (selected == -1) + if (selected == wxNOT_FOUND) return; auto text = GetItemText(selected, ColumnAddress); text = "0x" + text; @@ -162,4 +162,4 @@ void SymbolListCtrl::ChangeListFilter(std::string filter) SetItemCount(visible_entries); if (visible_entries > 0) RefreshItems(GetTopItem(), std::min(visible_entries - 1, GetTopItem() + GetCountPerPage() + 1)); -} \ No newline at end of file +} diff --git a/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp b/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp index f4e5b7af..6b69b0f0 100644 --- a/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp +++ b/src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp @@ -439,7 +439,7 @@ void DebugPPCThreadsWindow::OnThreadListRightClick(wxMouseEvent& event) m_thread_list->SetItemState(itemIndex, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); long sel = m_thread_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (sel != -1) + if (sel != wxNOT_FOUND) m_thread_list->SetItemState(sel, 0, wxLIST_STATE_SELECTED); m_thread_list->SetItemState(itemIndex, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); // check if thread is still on the list of active threads diff --git a/src/gui/wxcomponents/checkedlistctrl.h b/src/gui/wxcomponents/checkedlistctrl.h index 215c0004..926c2ba7 100644 --- a/src/gui/wxcomponents/checkedlistctrl.h +++ b/src/gui/wxcomponents/checkedlistctrl.h @@ -87,7 +87,7 @@ public: wxCheckedListCtrl() : wxListCtrl(), m_imageList(16, 16, TRUE) {} - wxCheckedListCtrl(wxWindow *parent, wxWindowID id = -1, + wxCheckedListCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pt = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = wxCLC_CHECK_WHEN_SELECTING, @@ -96,7 +96,7 @@ public: : wxListCtrl(), m_imageList(16, 16, TRUE) { Create(parent, id, pt, sz, style, validator, name); } - bool Create(wxWindow *parent, wxWindowID id = -1, + bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pt = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = wxCLC_CHECK_WHEN_SELECTING,