+
+void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent& event)
+{
+ static const struct EventInfo
+ {
+ wxEventType typeChanged,
+ typeChanging;
+ const wxChar *name;
+ } events[] =
+ {
+#if wxUSE_NOTEBOOK
+ {
+ wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
+ wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,
+ wxT("wxNotebook")
+ },
+#endif // wxUSE_NOTEBOOK
+#if wxUSE_LISTBOOK
+ {
+ wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,
+ wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,
+ wxT("wxListbook")
+ },
+#endif // wxUSE_LISTBOOK
+#if wxUSE_CHOICEBOOK
+ {
+ wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,
+ wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,
+ wxT("wxChoicebook")
+ },
+#endif // wxUSE_CHOICEBOOK
+#if wxUSE_TREEBOOK
+ {
+ wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED,
+ wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING,
+ wxT("wxTreebook")
+ },
+#endif // wxUSE_TREEBOOK
+#if wxUSE_TOOLBOOK
+ {
+ wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED,
+ wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING,
+ wxT("wxToolbook")
+ },
+#endif // wxUSE_TOOLBOOK
+ };
+
+
+ wxString nameEvent,
+ nameControl,
+ veto;
+ const wxEventType eventType = event.GetEventType();
+
+ // NB: can't use wxStaticCast here as wxBookCtrlBase is not in
+ // wxRTTI
+ const wxBookCtrlBase * const
+ book = static_cast<wxBookCtrlBase *>(event.GetEventObject());
+
+ for ( size_t n = 0; n < WXSIZEOF(events); n++ )
+ {
+ const EventInfo& ei = events[n];
+ if ( eventType == ei.typeChanged )
+ {
+ nameEvent = wxT("Changed");
+ }
+ else if ( eventType == ei.typeChanging )
+ {
+ const int idx = event.GetOldSelection();
+
+ if ( idx != wxNOT_FOUND &&
+ book && book->GetPageText(idx) == VETO_PAGE_NAME )
+ {
+ if ( wxMessageBox
+ (
+ wxT("Are you sure you want to leave this page?\n")
+ wxT("(This demonstrates veto-ing)"),
+ wxT("Notebook sample"),
+ wxICON_QUESTION | wxYES_NO,
+ this
+ ) != wxYES )
+ {
+ event.Veto();
+ veto = wxT(" (vetoed)");
+ }
+ }
+
+ nameEvent = wxT("Changing");
+ }
+ else // skip end of the loop
+ {
+ continue;
+ }
+
+ nameControl = ei.name;
+ break;
+ }
+
+ static int s_num = 0;
+
+ wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d, current %d%s"),
+ ++s_num,
+ nameControl.c_str(),
+ nameEvent.c_str(),
+ eventType,
+ event.GetSelection(),
+ event.GetOldSelection(),
+ book->GetSelection(),
+ veto.c_str());
+
+#if USE_LOG
+ m_text->SetInsertionPointEnd();
+#endif
+}