Allow adding and deleting notebook tabs in the AUI sample

This is useful for testing that wxAuiNotebook updates correctly when
this is done.
This commit is contained in:
Vadim Zeitlin 2023-12-24 02:26:39 +01:00
parent 99434fa005
commit 550849b786

View file

@ -24,6 +24,7 @@
#include "wx/dataobj.h"
#include "wx/dcclient.h"
#include "wx/bmpbuttn.h"
#include "wx/log.h"
#include "wx/menu.h"
#include "wx/toolbar.h"
#include "wx/statusbr.h"
@ -98,6 +99,8 @@ class MyFrame : public wxFrame
ID_NotebookArtSimple,
ID_NotebookAlignTop,
ID_NotebookAlignBottom,
ID_NotebookNewTab,
ID_NotebookDeleteTab,
ID_SampleItem,
@ -158,6 +161,9 @@ private:
void OnNotebookFlag(wxCommandEvent& evt);
void OnUpdateUI(wxUpdateUIEvent& evt);
void OnNotebookNewTab(wxCommandEvent& evt);
void OnNotebookDeleteTab(wxCommandEvent& evt);
void OnPaneClose(wxAuiManagerEvent& evt);
private:
@ -605,6 +611,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_NotebookArtSimple, MyFrame::OnNotebookFlag)
EVT_MENU(ID_NotebookAlignTop, MyFrame::OnTabAlignment)
EVT_MENU(ID_NotebookAlignBottom, MyFrame::OnTabAlignment)
EVT_MENU(ID_NotebookNewTab, MyFrame::OnNotebookNewTab)
EVT_MENU(ID_NotebookDeleteTab, MyFrame::OnNotebookDeleteTab)
EVT_MENU(ID_NoGradient, MyFrame::OnGradient)
EVT_MENU(ID_VerticalGradient, MyFrame::OnGradient)
EVT_MENU(ID_HorizontalGradient, MyFrame::OnGradient)
@ -733,6 +741,9 @@ MyFrame::MyFrame(wxWindow* parent,
notebook_menu->AppendCheckItem(ID_NotebookScrollButtons, _("Scroll Buttons Visible"));
notebook_menu->AppendCheckItem(ID_NotebookWindowList, _("Window List Button Visible"));
notebook_menu->AppendCheckItem(ID_NotebookTabFixedWidth, _("Fixed-width Tabs"));
notebook_menu->AppendSeparator();
notebook_menu->Append(ID_NotebookNewTab, _("Add a &New Tab"));
notebook_menu->Append(ID_NotebookDeleteTab, _("&Delete Last Tab"));
m_perspectives_menu = new wxMenu;
m_perspectives_menu->Append(ID_CreatePerspective, _("Create Perspective"));
@ -1300,6 +1311,36 @@ void MyFrame::OnUpdateUI(wxUpdateUIEvent& event)
}
}
void MyFrame::OnNotebookNewTab(wxCommandEvent& WXUNUSED(evt))
{
auto* const book =
wxCheckCast<wxAuiNotebook>(m_mgr.GetPane("notebook_content").window);
book->AddPage(new wxTextCtrl(book, wxID_ANY, "New Tab",
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxNO_BORDER),
wxString::Format("Tab %zu", book->GetPageCount() + 1),
true /* select */);
}
void MyFrame::OnNotebookDeleteTab(wxCommandEvent& WXUNUSED(evt))
{
auto* const book =
wxCheckCast<wxAuiNotebook>(m_mgr.GetPane("notebook_content").window);
auto numPages = book->GetPageCount();
if ( !numPages )
{
wxLogWarning("No pages to delete.");
return;
}
book->DeletePage(numPages - 1);
}
void MyFrame::OnPaneClose(wxAuiManagerEvent& evt)
{
if (evt.pane->name == "test10")