]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/notebook/notebook.cpp
Minor manual fixes.
[wxWidgets.git] / samples / notebook / notebook.cpp
index b69850bd96240e9ab760094d8625f80f08402d6e..cfa1b98282304e8b68f68b50e00eee27bf55f0bc 100644 (file)
@@ -1,12 +1,12 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        notebook.cpp
-// Purpose:     wxNotebook demo
+// Name:        samples/notebook/notebook.cpp
+// Purpose:     a sample demonstrating notebook usage
 // Author:      Julian Smart
-// Modified by:
+// Modified by: Dimitri Schoolwerth
 // Created:     26/10/98
 // RCS-ID:      $Id$
-// Copyright:   (c)
-// Licence:     wxWindows licence
+// Copyright:   (c) 1998-2002 wxWidgets team
+// License:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx.h".
     #include "wx/wx.h"
 #endif
 
+#include "wx/imaglist.h"
+#include "wx/artprov.h"
 #include "notebook.h"
 
-// If 1, use a dialog. Otherwise use a frame.
-#define USE_TABBED_DIALOG 0
-#if USE_TABBED_DIALOG
-MyDialog* dialog = (MyDialog *) NULL;
-#else // !USE_TABBED_DIALOG
-MyFrame*  frame = (MyFrame *) NULL;
-#endif // USE_TABBED_DIALOG
-
 IMPLEMENT_APP(MyApp)
 
 bool MyApp::OnInit()
 {
-  // Create the main window
-#if USE_TABBED_DIALOG
-  dialog = new MyDialog((wxFrame *) NULL, -1, (char *) "Notebook", wxPoint(-1, -1), wxSize(365, 390), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE);
-
-  dialog->ShowModal();
-
-  // Quit immediately the dialog has been dismissed
-  return FALSE;
-#else
-  frame = new MyFrame((wxFrame*) NULL, -1, "Notebook", wxPoint(-1, -1), wxSize(465, 390) );
-
-  // Problem with generic wxNotebook implementation whereby it doesn't size properly unless
-  // you set the size again
-#if defined(__WIN16__)
-  int width, height;
-  frame->GetSize(& width, & height);
-  frame->SetSize(-1, -1, width, height);
+    // Create the main window
+    MyFrame *frame = new MyFrame( wxT("Notebook sample") );
+
+    // Problem with generic wxNotebook implementation whereby it doesn't size
+    // properly unless you set the size again
+#if defined(__WXMOTIF__)
+    int width, height;
+    frame->GetSize(& width, & height);
+    frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height);
 #endif
 
-  return TRUE;
-#endif
+    frame->Show();
+
+    return true;
 }
 
-void MyApp::InitTabView(wxNotebook* notebook, wxPanel* window)
+wxPanel *CreateUserCreatedPage(wxBookCtrl *parent)
 {
-  m_okButton = new wxButton(window, wxID_OK, "Close", wxPoint(-1, -1), wxSize(80, 25));
-  m_cancelButton = new wxButton(window, ID_DELETE_PAGE, "&Delete page", wxPoint(-1, -1), wxSize(80, 25));
-  m_addPageButton = new wxButton(window, ID_ADD_PAGE, "&Add page", wxPoint(-1, -1), wxSize(80, 25));
-  m_insertPageButton = new wxButton(window, ID_INSERT_PAGE, "&Insert page", wxPoint(-1, -1), wxSize(80, 25));
-  m_nextPageButton = new wxButton(window, ID_NEXT_PAGE, "&Next page", wxPoint(-1, -1), wxSize(80, 25));
-  m_okButton->SetDefault();
-
-  wxLayoutConstraints *c;
-  c = new wxLayoutConstraints;
-  c->right.SameAs(window, wxRight, 4);
-  c->bottom.SameAs(window, wxBottom, 4);
-  c->height.AsIs();
-  c->width.AsIs();
-  m_addPageButton->SetConstraints(c);
-
-  c = new wxLayoutConstraints;
-  c->right.SameAs(m_addPageButton, wxLeft, 4);
-  c->bottom.SameAs(window, wxBottom, 4);
-  c->height.AsIs();
-  c->width.AsIs();
-  m_insertPageButton->SetConstraints(c);
-
-  c = new wxLayoutConstraints;
-  c->right.SameAs(m_insertPageButton, wxLeft, 4);
-  c->bottom.SameAs(window, wxBottom, 4);
-  c->height.AsIs();
-  c->width.AsIs();
-  m_nextPageButton->SetConstraints(c);
-
-  c = new wxLayoutConstraints;
-  c->right.SameAs(m_nextPageButton, wxLeft, 4);
-  c->bottom.SameAs(window, wxBottom, 4);
-  c->height.AsIs();
-  c->width.AsIs();
-  m_cancelButton->SetConstraints(c);
-
-  c = new wxLayoutConstraints;
-  c->right.SameAs(m_cancelButton, wxLeft, 4);
-  c->bottom.SameAs(window, wxBottom, 4);
-  c->height.AsIs();
-  c->width.AsIs();
-  m_okButton->SetConstraints(c);
-
-  // Add some panels
-  wxPanel *panel1 = new wxPanel(notebook, -1);
-  //  panel1->SetBackgroundColour(wxColour("RED"));
-  (void)new wxButton(panel1, -1, "Press me", wxPoint(10, 10));
-  (void)new wxTextCtrl(panel1, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
-
-  notebook->AddPage(panel1, "Cat", TRUE);
-
-  wxPanel *panel2 = new wxPanel(notebook, -1);
-  panel2->SetAutoLayout(TRUE);
-  panel2->SetBackgroundColour(wxColour("BLUE"));
-
-  wxString animals[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
-  wxRadioBox *radiobox = new wxRadioBox(panel2, -1, "Choose one",
-                                        wxDefaultPosition, wxDefaultSize, 5, animals,
-                                        2, wxRA_SPECIFY_ROWS);
-
-  c = new wxLayoutConstraints;
-  c->left.SameAs(panel2, wxLeft, 10);
-  c->top.SameAs(panel2, wxTop, 5);
-  c->height.PercentOf(panel2, wxHeight, 50);
-  c->right.SameAs(panel2, wxRight, 10);
-  radiobox->SetConstraints(c);
-
-  wxRadioBox *radiobox2 = new wxRadioBox(panel2, -1, "Choose one",
-                                         wxDefaultPosition, wxDefaultSize,
-                                         5, animals,
-                                         2, wxRA_SPECIFY_ROWS);
-
-  c = new wxLayoutConstraints;
-  c->left.SameAs(radiobox, wxLeft);
-  c->height.AsIs();
-  c->top.Below(radiobox, 5);
-  c->right.SameAs(radiobox, wxRight);
-  radiobox2->SetConstraints(c);
-
-  notebook->AddPage(panel2, "Dog");
-
-  wxPanel *panel3 = new wxPanel(notebook, -1);
-  panel3->SetBackgroundColour(wxColour("WHITE"));
-  notebook->AddPage(panel3, "Goat");
-
-  wxPanel *panel4 = new wxPanel(notebook, -1);
-  panel4->SetBackgroundColour(wxColour("YELLOW"));
-  notebook->AddPage(panel4, "Sheep");
-
-  wxPanel *panel5 = new wxPanel(notebook, -1);
-  panel5->SetBackgroundColour(wxColour("MAGENTA"));
-  (void)new wxStaticText(panel5, -1, "This page has been inserted, not added", wxPoint(10, 10) );
-  notebook->InsertPage(0, panel5, "Sheep");
-
-  notebook->SetSelection(2);
+    wxPanel *panel = new wxPanel(parent);
+
+    (void) new wxButton( panel, wxID_ANY, wxT("Button"),
+        wxPoint(10, 10), wxDefaultSize );
+
+    return panel;
 }
 
-#if USE_TABBED_DIALOG
+wxPanel *CreateRadioButtonsPage(wxBookCtrl *parent)
+{
+    wxPanel *panel = new wxPanel(parent);
 
-BEGIN_EVENT_TABLE(MyDialog, wxDialog)
-    EVT_BUTTON(wxID_OK, MyDialog::OnOK)
-    EVT_BUTTON(wxID_CANCEL, MyDialog::OnOK)
-END_EVENT_TABLE()
+    wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
+        wxT("Sabre-toothed tiger"), wxT("T Rex") };
+
+    wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"),
+        wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS);
+
+    wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
+        wxT("Another") };
+
+    wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY,
+        wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize,
+        4, computers, 0, wxRA_SPECIFY_COLS);
 
-MyDialog::MyDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
-    const wxPoint& pos, const wxSize& size, const long windowStyle):
-  wxDialog(parent, id, title, pos, size, windowStyle)
+    wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
+    sizerPanel->Add(radiobox1, 2, wxEXPAND);
+    sizerPanel->Add(radiobox2, 1, wxEXPAND);
+    panel->SetSizer(sizerPanel);
+
+    return panel;
+}
+
+wxPanel *CreateVetoPage(wxBookCtrl *parent)
 {
-    Init();
+    wxPanel *panel = new wxPanel(parent);
+
+    (void) new wxStaticText( panel, wxID_ANY,
+        wxT("This page intentionally left blank"), wxPoint(10, 10) );
+
+    return panel;
 }
 
-void MyDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
+wxPanel *CreateBigButtonPage(wxBookCtrl *parent)
 {
-    EndModal(wxID_OK);
+    wxPanel *panel = new wxPanel(parent);
+
+    wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button"));
+
+    wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
+    sizerPanel->Add(buttonBig, 1, wxEXPAND);
+    panel->SetSizer(sizerPanel);
+
+    return panel;
 }
 
-void MyDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
+
+wxPanel *CreateInsertPage(wxBookCtrl *parent)
 {
-    EndModal(wxID_CANCEL);
+    wxPanel *panel = new wxPanel(parent);
+
+    panel->SetBackgroundColour( wxColour( wxT("MAROON") ) );
+    (void) new wxStaticText( panel, wxID_ANY,
+        wxT("This page has been inserted, not added."), wxPoint(10, 10) );
+
+    return panel;
 }
 
-void MyDialog::Init()
+int GetIconIndex(wxBookCtrl* bookCtrl)
 {
-  m_notebook = new wxNotebook(this, ID_NOTEBOOK);
+    if (bookCtrl && bookCtrl->GetImageList())
+    {
+       int nImages = bookCtrl->GetImageList()->GetImageCount();
+       if (nImages > 0)
+       {
+           return bookCtrl->GetPageCount() % nImages;
+       }
+    }
 
-  wxLayoutConstraints* c = new wxLayoutConstraints;
-  c->left.SameAs(this, wxLeft, 4);
-  c->right.SameAs(this, wxRight, 4);
-  c->top.SameAs(this, wxTop, 4);
-  c->bottom.SameAs(this, wxBottom, 40);
+    return -1;
+}
 
-  m_notebook->SetConstraints(c);
+void CreateInitialPages(wxBookCtrl *parent)
+{
+    // Create and add some panels to the notebook
 
-  wxGetApp().InitTabView(m_notebook, this);
+    wxPanel *panel = CreateRadioButtonsPage(parent);
+    parent->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(parent) );
 
-  SetAutoLayout(TRUE);
-  Layout();
+    panel = CreateVetoPage(parent);
+    parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) );
 
-  Centre(wxBOTH);
-}
+    panel = CreateBigButtonPage(parent);
+    parent->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(parent) );
 
-#else // USE_TABBED_DIALOG
+    panel = CreateInsertPage(parent);
+    parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) );
 
-BEGIN_EVENT_TABLE(MyFrame, wxFrame)
-    EVT_BUTTON(wxID_OK, MyFrame::OnOK)
-    EVT_BUTTON(ID_DELETE_PAGE, MyFrame::OnDeletePage)
-    EVT_BUTTON(ID_ADD_PAGE, MyFrame::OnAddPage)
-    EVT_BUTTON(ID_INSERT_PAGE, MyFrame::OnInsertPage)
-    EVT_BUTTON(ID_NEXT_PAGE, MyFrame::OnNextPage)
-    EVT_IDLE(MyFrame::OnIdle)
-END_EVENT_TABLE()
+    parent->SetSelection(1);
+}
 
-MyFrame::MyFrame(wxFrame* parent, const wxWindowID id, const wxString& title,
-    const wxPoint& pos, const wxSize& size, const long windowStyle):
-  wxFrame(parent, id, title, pos, size, windowStyle)
+wxPanel *CreatePage(wxBookCtrl *parent, const wxString&pageName)
 {
-    m_panel = (wxPanel*) NULL;
-    m_notebook = (wxNotebook*) NULL;
-    Init();
+    if
+    (
+        pageName.Contains(INSERTED_PAGE_NAME)
+        || pageName.Contains(ADDED_PAGE_NAME)
+    )
+    {
+        return CreateUserCreatedPage(parent);
+    }
+
+    if (pageName == I_WAS_INSERTED_PAGE_NAME)
+    {
+        return CreateInsertPage(parent);
+    }
+
+    if (pageName == VETO_PAGE_NAME)
+    {
+        return CreateVetoPage(parent);
+    }
+
+    if (pageName == RADIOBUTTONS_PAGE_NAME)
+    {
+        return CreateRadioButtonsPage(parent);
+    }
+
+
+    if (pageName == MAXIMIZED_BUTTON_PAGE_NAME)
+    {
+        return CreateBigButtonPage(parent);
+    }
+
+    wxFAIL;
+
+    return (wxPanel *) NULL;
 }
 
-void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
+MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
+                 long style)
+    : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
 {
-    static size_t s_pageAdded = 0;
+    m_type = ID_BOOK_NOTEBOOK;
+    m_orient = ID_ORIENT_DEFAULT;
+    m_chkShowImages = true;
+    m_multi = false;
+
+    // menu of the sample
 
-    wxPanel *panel = new wxPanel( m_notebook, -1 );
-    (void)new wxButton( panel, -1, "Button", wxPoint( 10,10 ), wxSize(-1,-1) );
+    wxMenu *menuType = new wxMenu;
+#if wxUSE_NOTEBOOK
+    menuType->AppendRadioItem(ID_BOOK_NOTEBOOK,   wxT("&Notebook\tCtrl-1"));
+#endif
+#if wxUSE_LISTBOOK
+    menuType->AppendRadioItem(ID_BOOK_LISTBOOK,   wxT("&Listbook\tCtrl-2"));
+#endif
+#if wxUSE_CHOICEBOOK
+    menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3"));
+#endif
+
+    wxMenu *menuOrient = new wxMenu;
+    menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tCtrl-4"));
+    menuOrient->AppendRadioItem(ID_ORIENT_TOP,     wxT("&Top\tCtrl-5"));
+    menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM,  wxT("&Bottom\tCtrl-6"));
+    menuOrient->AppendRadioItem(ID_ORIENT_LEFT,    wxT("&Left\tCtrl-7"));
+    menuOrient->AppendRadioItem(ID_ORIENT_RIGHT,   wxT("&Right\tCtrl-8"));
+
+    wxMenu *menuDo = new wxMenu;
+    menuDo->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
+    menuDo->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
+    menuDo->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
+    menuDo->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
+    menuDo->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
+
+    wxMenu *menuFile = new wxMenu;
+    menuFile->Append(wxID_ANY, wxT("&Type"), menuType, wxT("Type of control"));
+    menuFile->Append(wxID_ANY, wxT("&Orientation"), menuOrient, wxT("Orientation of control"));
+    menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S"));
+    menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M"));
+    menuFile->AppendSeparator();
+    menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application"));
+    menuFile->Check(ID_SHOW_IMAGES, m_chkShowImages);
+    menuFile->Check(ID_MULTI, m_multi);
+
+    wxMenuBar *menuBar = new wxMenuBar;
+    menuBar->Append(menuFile, wxT("&File"));
+    menuBar->Append(menuDo, wxT("&Operations"));
+    SetMenuBar(menuBar);
+
+    // books creation
+
+    m_panel      = (wxPanel *)      NULL;
+#if wxUSE_NOTEBOOK
+    m_notebook   = (wxNotebook *)   NULL;
+#endif
+#if wxUSE_CHOICEBOOK
+    m_choicebook = (wxChoicebook *) NULL;
+#endif
+#if wxUSE_LISTBOOK
+    m_listbook   = (wxListbook *)   NULL;
+#endif
 
-    m_notebook->AddPage( panel, wxString::Format("Added %u", ++s_pageAdded) );
+    // create a dummy image list with a few icons
+    wxSize imageSize(32, 32);
+
+    m_imageList
+        = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() );
+
+    m_imageList->Add
+        (
+            wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)
+        );
+
+    m_imageList->Add
+        (
+            wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)
+        );
+
+    m_imageList->Add
+        (
+            wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)
+        );
+
+    m_imageList->Add
+        (
+            wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)
+        );
+
+    m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
+        wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
+
+#if USE_LOG
+    m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString,
+        wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
+
+    m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) );
+#endif // USE_LOG
+
+    // Set sizers
+    m_sizerFrame = new wxBoxSizer(wxVERTICAL);
+
+#if USE_LOG
+    m_sizerFrame->Add(m_text, 1, wxEXPAND);
+#endif // USE_LOG
+
+    RecreateBooks();
+
+    m_panel->SetSizer(m_sizerFrame);
+
+    m_sizerFrame->Fit(this);
+    m_sizerFrame->SetSizeHints(this);
+
+    Centre(wxBOTH);
 }
 
-void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
+MyFrame::~MyFrame()
 {
-    static size_t s_pageIns = 0;
+#if USE_LOG
+    delete wxLog::SetActiveTarget(m_logTargetOld);
+#endif // USE_LOG
 
-    wxPanel *panel = new wxPanel( m_notebook, -1 );
-    (void)new wxButton( panel, -1, "Button", wxPoint( 10,10 ), wxSize(-1,-1) );
+    if (m_imageList)
+    {
+        delete m_imageList;
+        m_imageList = (wxImageList *) NULL;
+    }
+}
 
-    m_notebook->InsertPage(0, panel, wxString::Format("Inserted %u", ++s_pageIns) );
-    m_notebook->SetSelection(0);
+int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
+{
+    switch (id)
+    {
+        case ID_NOTEBOOK:   return nb;
+        case ID_LISTBOOK:   return lb;
+        case ID_CHOICEBOOK: return chb;
+    }
+    return 0;
 }
 
-wxWindow *test = NULL;
+#define RECREATE( wxBookType , idBook, oldBook , newBook )                         \
+{                                                                                  \
+    int flags;                                                                     \
+                                                                                   \
+    switch ( m_orient )                                                            \
+    {                                                                              \
+        case ID_ORIENT_TOP:                                                        \
+            flags = SelectFlag(idBook, wxNB_TOP, wxLB_TOP, wxCHB_TOP);             \
+            break;                                                                 \
+                                                                                   \
+        case ID_ORIENT_BOTTOM:                                                     \
+            flags = SelectFlag(idBook, wxNB_BOTTOM, wxLB_BOTTOM, wxCHB_BOTTOM);    \
+            break;                                                                 \
+                                                                                   \
+        case ID_ORIENT_LEFT:                                                       \
+            flags = SelectFlag(idBook, wxNB_LEFT, wxLB_LEFT, wxCHB_LEFT);          \
+            break;                                                                 \
+                                                                                   \
+        case ID_ORIENT_RIGHT:                                                      \
+            flags = SelectFlag(idBook, wxNB_RIGHT, wxLB_RIGHT, wxCHB_RIGHT);       \
+            break;                                                                 \
+                                                                                   \
+        default:                                                                   \
+            flags = SelectFlag(idBook, wxNB_DEFAULT, wxLB_DEFAULT, wxCHB_DEFAULT); \
+    }                                                                              \
+                                                                                   \
+    if ( m_multi && ( idBook == ID_NOTEBOOK ) )                                    \
+        flags |= wxNB_MULTILINE;                                                   \
+                                                                                   \
+    wxBookType *oldBook = newBook;                                                 \
+                                                                                   \
+    newBook = new wxBookType(m_panel, idBook,                                      \
+                             wxDefaultPosition, wxDefaultSize,                     \
+                             flags);                                               \
+                                                                                   \
+    if ( m_chkShowImages )                                                         \
+    {                                                                              \
+        newBook->SetImageList(m_imageList);                                        \
+    }                                                                              \
+                                                                                   \
+    if (oldBook)                                                                   \
+    {                                                                              \
+        int sel = oldBook->GetSelection();                                         \
+                                                                                   \
+        int count = oldBook->GetPageCount();                                       \
+        for (int n = 0; n < count; n++)                                            \
+        {                                                                          \
+            wxString str = oldBook->GetPageText(n);                                \
+                                                                                   \
+            wxWindow *page = CreatePage(newBook, str);                             \
+            newBook->AddPage(page, str, false, GetIconIndex(newBook) );            \
+        }                                                                          \
+                                                                                   \
+        m_sizerFrame->Detach(oldBook);                                             \
+                                                                                   \
+        delete oldBook;                                                            \
+                                                                                   \
+        if (sel != wxNOT_FOUND)                                                    \
+        {                                                                          \
+            newBook->SetSelection(sel);                                            \
+        }                                                                          \
+                                                                                   \
+    }                                                                              \
+    else                                                                           \
+    {                                                                              \
+        wxPanel *panel = CreateRadioButtonsPage(newBook);                          \
+        newBook->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(newBook) ); \
+                                                                                   \
+        panel = CreateVetoPage(newBook);                                           \
+        newBook->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(newBook) );   \
+                                                                                   \
+        panel = CreateBigButtonPage(newBook);                                      \
+        newBook->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(newBook) ); \
+                                                                                   \
+        panel = CreateInsertPage(newBook);                                         \
+        newBook->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(newBook) ); \
+                                                                                   \
+        newBook->SetSelection(1);                                                  \
+    }                                                                              \
+                                                                                   \
+    m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, 4);                      \
+                                                                                   \
+    m_sizerFrame->Hide(newBook);                                                   \
+}
 
-void MyFrame::OnDeletePage(wxCommandEvent& WXUNUSED(event))
+void MyFrame::RecreateBooks()
 {
-    if (m_notebook->GetPageCount() > 0)
-        m_notebook->DeletePage( m_notebook->GetPageCount()-1 );
+#if wxUSE_NOTEBOOK
+    RECREATE( wxNotebook   , ID_NOTEBOOK   , notebook   , m_notebook );
+#endif
+#if wxUSE_LISTBOOK
+    RECREATE( wxListbook   , ID_LISTBOOK   , listbook   , m_listbook );
+#endif
+#if wxUSE_CHOICEBOOK
+    RECREATE( wxChoicebook , ID_CHOICEBOOK , choicebook , m_choicebook );
+#endif
 
-/*
-    if (test)
+    ShowCurrentBook();
+}
+
+wxBookCtrl *MyFrame::GetCurrentBook()
+{
+    switch (m_type)
     {
-       m_notebook->AddPage( test, "Readded" );
-       test = NULL;
+#if wxUSE_NOTEBOOK
+        case ID_BOOK_NOTEBOOK:   return m_notebook;
+#endif
+#if wxUSE_LISTBOOK
+        case ID_BOOK_LISTBOOK:   return m_listbook;
+#endif
+#if wxUSE_CHOICEBOOK
+        case ID_BOOK_CHOICEBOOK: return m_choicebook;
+#endif
     }
-    else
+    return NULL;
+}
+
+void MyFrame::ShowCurrentBook()
+{
+    switch(m_type)
     {
-       test = m_notebook->GetPage( m_notebook->GetPageCount()-1 );
-       m_notebook->RemovePage( m_notebook->GetPageCount()-1 );
+#if wxUSE_NOTEBOOK
+        case ID_BOOK_NOTEBOOK:   if(m_notebook)   m_sizerFrame->Show(m_notebook);   break;
+#endif
+#if wxUSE_LISTBOOK
+        case ID_BOOK_LISTBOOK:   if(m_listbook)   m_sizerFrame->Show(m_listbook);   break;
+#endif
+#if wxUSE_CHOICEBOOK
+        case ID_BOOK_CHOICEBOOK: if(m_choicebook) m_sizerFrame->Show(m_choicebook); break;
+#endif
     }
-*/
+
+    m_sizerFrame->Layout();
 }
 
-void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
+BEGIN_EVENT_TABLE(MyFrame, wxFrame)
+    // File menu
+    EVT_MENU_RANGE(ID_BOOK_NOTEBOOK,ID_BOOK_MAX,MyFrame::OnType)
+    EVT_MENU_RANGE(ID_ORIENT_DEFAULT,ID_ORIENT_MAX,MyFrame::OnOrient)
+    EVT_MENU(ID_SHOW_IMAGES, MyFrame::OnShowImages)
+    EVT_MENU(ID_MULTI, MyFrame::OnMulti)
+    EVT_MENU(wxID_EXIT,MyFrame::OnExit)
+
+    // Operations menu
+    EVT_MENU(ID_ADD_PAGE, MyFrame::OnAddPage)
+    EVT_MENU(ID_INSERT_PAGE, MyFrame::OnInsertPage)
+    EVT_MENU(ID_DELETE_CUR_PAGE, MyFrame::OnDeleteCurPage)
+    EVT_MENU(ID_DELETE_LAST_PAGE, MyFrame::OnDeleteLastPage)
+    EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
+
+    // Book controls
+#if wxUSE_NOTEBOOK
+    EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook)
+    EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook)
+#endif
+#if wxUSE_LISTBOOK
+    EVT_LISTBOOK_PAGE_CHANGED(ID_LISTBOOK, MyFrame::OnListbook)
+    EVT_LISTBOOK_PAGE_CHANGING(ID_LISTBOOK, MyFrame::OnListbook)
+#endif
+#if wxUSE_CHOICEBOOK
+    EVT_CHOICEBOOK_PAGE_CHANGED(ID_CHOICEBOOK, MyFrame::OnChoicebook)
+    EVT_CHOICEBOOK_PAGE_CHANGING(ID_CHOICEBOOK, MyFrame::OnChoicebook)
+#endif
+
+    // Update title in idle time
+    EVT_IDLE(MyFrame::OnIdle)
+END_EVENT_TABLE()
+
+void MyFrame::OnType(wxCommandEvent& event)
+{
+    wxBookCtrl *currBook = GetCurrentBook();
+
+    m_type = event.GetId();
+
+    if (currBook)
+        m_sizerFrame->Hide(currBook);
+
+    ShowCurrentBook();
+}
+
+void MyFrame::OnOrient(wxCommandEvent& event)
+{
+    m_orient = event.GetId();
+    RecreateBooks();
+    m_sizerFrame->Layout();
+}
+
+void MyFrame::OnShowImages(wxCommandEvent& event)
 {
-    m_notebook->AdvanceSelection();
+    m_chkShowImages = event.IsChecked();
+    RecreateBooks();
+    m_sizerFrame->Layout();
 }
 
-void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) )
+void MyFrame::OnMulti(wxCommandEvent& event)
 {
-    Destroy();
+    m_multi = event.IsChecked();
+    RecreateBooks();
+    m_sizerFrame->Layout();
+    wxLogMessage(_T("Multiline setting works only in wxNotebook."));
 }
 
-void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
+void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
 {
-    Destroy();
+    Close();
 }
 
-void MyFrame::Init()
+void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
 {
-  m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxCLIP_CHILDREN);
+    static unsigned s_pageAdded = 0;
 
-  wxLayoutConstraints* c = new wxLayoutConstraints;
-  c->left.SameAs(this, wxLeft);
-  c->right.SameAs(this, wxRight);
-  c->top.SameAs(this, wxTop);
-  c->bottom.SameAs(this, wxBottom);
-  m_panel->SetConstraints(c);
+    wxBookCtrl *currBook = GetCurrentBook();
 
-  m_notebook = new wxNotebook(m_panel, ID_NOTEBOOK);
+    if ( currBook )
+    {
+        wxPanel *panel = new wxPanel( currBook, wxID_ANY );
+        (void) new wxButton( panel, wxID_ANY, wxT("First button"),
+            wxPoint(10, 10), wxDefaultSize );
+        (void) new wxButton( panel, wxID_ANY, wxT("Second button"),
+            wxPoint(50, 100), wxDefaultSize );
+
+        currBook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
+            ++s_pageAdded), true, GetIconIndex(currBook) );
+    }
+}
 
-  c = new wxLayoutConstraints;
-  c->left.SameAs(m_panel, wxLeft, 4);
-  c->right.SameAs(m_panel, wxRight, 4);
-  c->top.SameAs(m_panel, wxTop, 4);
-  c->bottom.SameAs(m_panel, wxBottom, 40);
+void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
+{
+    static unsigned s_pageIns = 0;
 
-  m_notebook->SetConstraints(c);
+    wxBookCtrl *currBook = GetCurrentBook();
 
-  wxGetApp().InitTabView(m_notebook, m_panel);
+    if ( currBook )
+    {
+        wxPanel *panel = CreateUserCreatedPage( currBook );
 
-  m_panel->SetAutoLayout(TRUE);
-  SetAutoLayout(TRUE);
+        currBook->InsertPage( 0, panel,
+            wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false,
+            GetIconIndex(currBook) );
 
-  Centre(wxBOTH);
+        currBook->SetSelection(0);
+    }
+}
 
-  Show(TRUE);
+void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
+{
+    wxBookCtrl *currBook = GetCurrentBook();
+
+    if ( currBook )
+    {
+        int sel = currBook->GetSelection();
+
+        if (sel != wxNOT_FOUND)
+        {
+            currBook->DeletePage(sel);
+        }
+    }
 }
 
-void MyFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
+void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
 {
-    static int s_nPages = -1;
-    static int s_nSel = -1;
+    wxBookCtrl *currBook = GetCurrentBook();
 
-    int nPages = m_notebook->GetPageCount();
-    int nSel = m_notebook->GetSelection();
-    if ( nPages != s_nPages || nSel != s_nSel )
+    if ( currBook )
+    {
+        int page = currBook->GetPageCount();
+
+        if ( page != 0 )
+        {
+            currBook->DeletePage(page - 1);
+        }
+    }
+}
+
+void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
+{
+    wxBookCtrl *currBook = GetCurrentBook();
+
+    if ( currBook )
+    {
+        currBook->AdvanceSelection();
+    }
+}
+
+void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
+{
+    static int s_nPages = wxNOT_FOUND;
+    static int s_nSel = wxNOT_FOUND;
+    static wxBookCtrl *s_currBook = NULL;
+
+    wxBookCtrl *currBook = GetCurrentBook();
+
+    int nPages = currBook ? currBook->GetPageCount() : 0;
+    int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND;
+
+    if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook )
     {
         s_nPages = nPages;
         s_nSel = nSel;
+        s_currBook = currBook;
+
+        wxString selection;
+        if ( nSel == wxNOT_FOUND )
+            selection << wxT("not found");
+        else
+            selection << nSel;
 
         wxString title;
-        title.Printf("Notebook (%d pages, selection: %d)", nPages, nSel);
+        title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str());
 
         SetTitle(title);
     }
 }
 
-#endif // USE_TABBED_DIALOG
+#define BOOKEVENT(OnBook,wxBookEvent,bookStr,wxEVT_PAGE_CHANGED,wxEVT_PAGE_CHANGING,s_num) \
+void MyFrame::OnBook(wxBookEvent& event)                                                   \
+{                                                                                          \
+    wxString str = wxT("Unknown ");                                                        \
+    str << wxT(bookStr);                                                                   \
+    str << wxT(" event");                                                                  \
+                                                                                           \
+    wxEventType eventType = event.GetEventType();                                          \
+                                                                                           \
+    if (eventType == wxEVT_PAGE_CHANGED)                                                   \
+    {                                                                                      \
+        str = wxT("Changed");                                                              \
+    }                                                                                      \
+    else if (eventType == wxEVT_PAGE_CHANGING)                                             \
+    {                                                                                      \
+        int idx = event.GetOldSelection();                                                 \
+        wxBookCtrl *book = (wxBookCtrl *)event.GetEventObject();                           \
+        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();                                                              \
+            }                                                                              \
+                                                                                           \
+        }                                                                                  \
+                                                                                           \
+        str = wxT("Changing");                                                             \
+    }                                                                                      \
+                                                                                           \
+    static int s_num = 0;                                                                  \
+                                                                                           \
+    wxString logMsg;                                                                       \
+    logMsg.Printf(wxT("%s event #%d: %s (%d) Sel %d, OldSel %d"),                          \
+                  wxT(bookStr),s_num++, str.c_str(), eventType,                            \
+                  event.GetSelection(), event.GetOldSelection());                          \
+                                                                                           \
+    wxLogMessage(logMsg.c_str());                                                          \
+                                                                                           \
+    m_text->SetInsertionPointEnd();                                                        \
+}
+
+#if wxUSE_NOTEBOOK
+BOOKEVENT(OnNotebook,wxNotebookEvent,"wxNotebook",wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,s_numNotebookEvents)
+#endif
+#if wxUSE_CHOICEBOOK
+BOOKEVENT(OnChoicebook,wxChoicebookEvent,"wxChoicebook",wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,s_numChoicebookEvents)
+#endif
+#if wxUSE_LISTBOOK
+BOOKEVENT(OnListbook,wxListbookEvent,"wxListbook",wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,s_numListbookEvents)
+#endif