debugger: fix breakpoints window right-click being offset

This commit is contained in:
Crementif 2026-02-23 17:06:59 +01:00
parent ceb9771a5c
commit 3ee166101a

View File

@ -32,7 +32,7 @@ BreakpointWindow::BreakpointWindow(DebuggerWindow2& parent, const wxPoint& main_
wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL);
m_breakpoints = new wxListView(this, wxID_ANY); m_breakpoints = new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
m_breakpoints->EnableCheckBoxes(true); m_breakpoints->EnableCheckBoxes(true);
wxListItem col0; wxListItem col0;
@ -162,10 +162,12 @@ void BreakpointWindow::OnBreakpointToggled(wxListEvent& event)
void BreakpointWindow::OnLeftDClick(wxMouseEvent& event) void BreakpointWindow::OnLeftDClick(wxMouseEvent& event)
{ {
const auto position = event.GetPosition(); const auto position = event.GetPosition();
const sint32 index = (position.y / m_breakpoints->GetCharHeight()) - 2; int flags = 0;
if (index < 0 || index >= m_breakpoints->GetItemCount()) const long index = m_breakpoints->HitTest(position, flags);
if (index == wxNOT_FOUND)
return; return;
sint32 x = position.x; sint32 x = position.x;
const auto enabled_width = m_breakpoints->GetColumnWidth(ColumnEnabled); const auto enabled_width = m_breakpoints->GetColumnWidth(ColumnEnabled);
if (x <= enabled_width) if (x <= enabled_width)
@ -173,7 +175,7 @@ void BreakpointWindow::OnLeftDClick(wxMouseEvent& event)
x -= enabled_width; x -= enabled_width;
const auto address_width = m_breakpoints->GetColumnWidth(ColumnAddress); const auto address_width = m_breakpoints->GetColumnWidth(ColumnAddress);
if(x <= address_width) if (x <= address_width)
{ {
const auto item = m_breakpoints->GetItemText(index, ColumnAddress); const auto item = m_breakpoints->GetItemText(index, ColumnAddress);
const auto address = std::stoul(item.ToStdString(), nullptr, 16); const auto address = std::stoul(item.ToStdString(), nullptr, 16);
@ -183,13 +185,13 @@ void BreakpointWindow::OnLeftDClick(wxMouseEvent& event)
} }
x -= address_width; x -= address_width;
const auto type_width = m_breakpoints->GetColumnWidth(ColumnType); const auto type_width = m_breakpoints->GetColumnWidth(ColumnType);
if (x <= type_width) if (x <= type_width)
return; return;
x -= type_width; x -= type_width;
const auto comment_width = m_breakpoints->GetColumnWidth(ColumnComment); const auto comment_width = m_breakpoints->GetColumnWidth(ColumnComment);
if(x <= comment_width) if (x <= comment_width)
{ {
if (index >= debuggerState.breakpoints.size()) if (index >= debuggerState.breakpoints.size())
return; return;
@ -213,9 +215,9 @@ void BreakpointWindow::OnLeftDClick(wxMouseEvent& event)
void BreakpointWindow::OnRightDown(wxMouseEvent& event) void BreakpointWindow::OnRightDown(wxMouseEvent& event)
{ {
const auto position = event.GetPosition(); int flags = 0;
const sint32 index = (position.y / m_breakpoints->GetCharHeight()) - 2; const long index = m_breakpoints->HitTest(event.GetPosition(), flags);
if (index < 0 || index >= m_breakpoints->GetItemCount()) if (index == wxNOT_FOUND || index < 0 || index >= m_breakpoints->GetItemCount())
{ {
wxMenu menu; wxMenu menu;
menu.Append(MENU_ID_CREATE_CODE_BP_EXECUTION, _("Create execution breakpoint")); menu.Append(MENU_ID_CREATE_CODE_BP_EXECUTION, _("Create execution breakpoint"));
@ -244,19 +246,16 @@ void BreakpointWindow::OnContextMenuClickSelected(wxCommandEvent& evt)
if (evt.GetId() == MENU_ID_DELETE_BP) if (evt.GetId() == MENU_ID_DELETE_BP)
{ {
long sel = m_breakpoints->GetFirstSelected(); long sel = m_breakpoints->GetFirstSelected();
if (sel != wxNOT_FOUND) if (sel == wxNOT_FOUND || sel < 0 || sel >= m_breakpoints->GetItemCount())
{ return;
if (sel >= debuggerState.breakpoints.size())
return;
auto it = debuggerState.breakpoints.begin(); auto it = debuggerState.breakpoints.begin();
std::advance(it, sel); std::advance(it, sel);
debugger_deleteBreakpoint(*it); debugger_deleteBreakpoint(*it);
wxCommandEvent evt(wxEVT_BREAKPOINT_CHANGE); wxCommandEvent evt(wxEVT_BREAKPOINT_CHANGE);
wxPostEvent(this->m_parent, evt); wxPostEvent(this->m_parent, evt);
}
} }
} }