From 53d850ec3ca00a5f4d2adf7957cd1debab16b25c Mon Sep 17 00:00:00 2001 From: Randalphwa <38287198+Randalphwa@users.noreply.github.com> Date: Sun, 17 May 2026 15:41:42 -0700 Subject: [PATCH] Add a toolbar for moving back/forward The menu approach is okay for a few files, but if you want to tests like the W3C SVG HTML tests, the hundreds of files can be a pain to step forward/backward using a menu only. See #26474. --- samples/html/test/test.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/samples/html/test/test.cpp b/samples/html/test/test.cpp index 356483b3e3..8b3f3d74c4 100644 --- a/samples/html/test/test.cpp +++ b/samples/html/test/test.cpp @@ -17,6 +17,7 @@ #include "wx/wx.h" #endif +#include "wx/artprov.h" #include "wx/image.h" #include "wx/sysopt.h" #include "wx/html/htmlwin.h" @@ -89,6 +90,8 @@ public: void OnDefaultWebBrowser(wxCommandEvent& event); void OnBack(wxCommandEvent& event); void OnForward(wxCommandEvent& event); + void OnUpdateBack(wxUpdateUIEvent& event); + void OnUpdateForward(wxUpdateUIEvent& event); void OnProcessor(wxCommandEvent& event); void OnDrawCustomBg(wxCommandEvent& event); @@ -230,6 +233,19 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) SetIcon(wxIcon(sample_xpm)); +#if wxUSE_TOOLBAR + // Create a toolbar with Back and Forward navigation buttons + wxToolBar *toolbar = CreateToolBar(); + auto* toolBack = toolbar->AddTool(ID_Back, _("Go Back"), + wxArtProvider::GetBitmapBundle(wxART_GO_BACK, wxART_TOOLBAR)); + Bind(wxEVT_UPDATE_UI, &MyFrame::OnUpdateBack, this, toolBack->GetId()); + auto* toolForward = toolbar->AddTool(ID_Forward, _("Go Forward"), + wxArtProvider::GetBitmapBundle(wxART_GO_FORWARD, wxART_TOOLBAR)); + Bind(wxEVT_UPDATE_UI, &MyFrame::OnUpdateForward, this, toolForward->GetId()); + + toolbar->Realize(); +#endif // wxUSE_TOOLBAR + #if wxUSE_ACCEL // Create convenient accelerators for Back and Forward navigation wxAcceleratorEntry entries[2]; @@ -332,6 +348,16 @@ void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event)) } } +void MyFrame::OnUpdateBack(wxUpdateUIEvent& event) +{ + event.Enable(m_Html->HistoryCanBack()); +} + +void MyFrame::OnUpdateForward(wxUpdateUIEvent& event) +{ + event.Enable(m_Html->HistoryCanForward()); +} + void MyFrame::OnProcessor(wxCommandEvent& WXUNUSED(event)) { m_Processor->Enable(!m_Processor->IsEnabled());