Fix wxRibbonToolBar::GetToolByPos() and DeleteToolByPos()

These functions didn't correctly account for the indices beyond the
first group.

Fix this and add tests for these functions to the sample.

See #23457, #23458.

(cherry picked from commit 38491111009c00714c21242c7d89616d4d77932d)
This commit is contained in:
mcorino 2023-04-18 14:33:48 +02:00 committed by Vadim Zeitlin
parent c445798fa8
commit 82017dbc81
3 changed files with 15 additions and 1 deletions

View File

@ -335,6 +335,7 @@ All (GUI):
- Fix maximum length of wxPropertyGrid editors (#23033).
- Add support for Caps/Num/Scroll Lock to wxGetKeyState() (elfmz, #23195).
- Fix wxToolBar::GetToolBitmapSize() in high DPI under non-MSW (#23222).
- Fix wxRibbonToolBar::GetToolByPos() and DeleteToolByPos() (mcorino, #23457).
wxGTK:

View File

@ -323,10 +323,21 @@ MyFrame::MyFrame()
toolbar->AddHybridTool(ID_POSITION_TOP, position_top_xpm,
"Align the ribbonbar horizontally\nat the top\nfor demonstration purposes");
toolbar->AddSeparator();
toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)),
wxRibbonToolBarToolBase* print_tool;
print_tool = toolbar->AddHybridTool(wxID_PRINT, wxArtProvider::GetBitmap(wxART_PRINT, wxART_OTHER, wxSize(16, 15)),
"This is the Print button tooltip\ndemonstrating a tooltip");
toolbar->SetRows(2, 3);
size_t tool_pos = toolbar->GetToolPos(wxID_PRINT);
if (toolbar->GetToolCount() != (tool_pos+1))
{
wxLogError("wxRibbonToolBar::GetToolPos(int) or wxRibbonToolBar::GetToolCount() is broken");
}
else if (toolbar->GetToolByPos(tool_pos) != print_tool)
{
wxLogError("wxRibbonToolBar::GetToolByPos(size_t) is broken");
}
wxRibbonPanel *selection_panel = new wxRibbonPanel(home, wxID_ANY, "Selection", wxBitmap(selection_panel_xpm));
wxRibbonButtonBar *selection = new wxRibbonButtonBar(selection_panel);
selection->AddButton(ID_SELECTION_EXPAND_V, "Expand Vertically", wxBitmap(expand_selection_v_xpm),

View File

@ -385,6 +385,7 @@ bool wxRibbonToolBar::DeleteToolByPos(size_t pos)
}
return true;
}
pos -= tool_count+1;
}
return false;
}
@ -425,6 +426,7 @@ wxRibbonToolBarToolBase* wxRibbonToolBar::GetToolByPos(size_t pos)const
{
return NULL;
}
pos -= tool_count+1;
}
return NULL;
}