]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/notebook/notebook.cpp
typo
[wxWidgets.git] / samples / notebook / notebook.cpp
index 1328a8fe7b1bf50acc8c4101e61683af1ceb04e7..ad083b352e99d7d60dbddbfdefc5dfc04916603a 100644 (file)
@@ -5,7 +5,7 @@
 // Modified by: Dimitri Schoolwerth
 // Created:     26/10/98
 // RCS-ID:      $Id$
-// Copyright:   (c) 1998-2002 wxWindows team
+// Copyright:   (c) 1998-2002 wxWidgets team
 // License:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/artprov.h"
 #include "notebook.h"
 
+#if !defined(__WXMSW__) && !defined(__WXPM__)
+    #include "../sample.xpm"
+#endif
+
 IMPLEMENT_APP(MyApp)
 
 bool MyApp::OnInit()
@@ -36,82 +40,38 @@ bool MyApp::OnInit()
 #if defined(__WXMOTIF__)
     int width, height;
     frame->GetSize(& width, & height);
-    frame->SetSize(-1, -1, width, height);
+    frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height);
 #endif
 
     frame->Show();
 
-    return TRUE;
-}
-
-MyNotebook::MyNotebook(wxWindow *parent, wxWindowID id,
-    const wxPoint& pos, const wxSize& size, long style)
-    : wxNotebook(parent, id, pos, size, style)
-{
-    // Empty
-}
-
-wxPanel *MyNotebook::CreatePage(const wxString&pageName)
-{
-    if
-    (
-        pageName.Contains(INSERTED_PAGE_NAME)
-        || pageName.Contains(ADDED_PAGE_NAME)
-    )
-    {
-        return CreateUserCreatedPage();
-    }
-
-    if (pageName == I_WAS_INSERTED_PAGE_NAME)
-    {
-        return CreateInsertPage();
-    }
-
-    if (pageName == VETO_PAGE_NAME)
-    {
-        return CreateVetoPage();
-    }
-
-    if (pageName == RADIOBUTTONS_PAGE_NAME)
-    {
-        return CreateRadioButtonsPage();
-    }
-
-
-    if (pageName == MAXIMIZED_BUTTON_PAGE_NAME)
-    {
-        return CreateBigButtonPage();
-    }
-
-    wxFAIL;
-
-    return (wxPanel *) NULL;
+    return true;
 }
 
-wxPanel *MyNotebook::CreateUserCreatedPage()
+wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent)
 {
-    wxPanel *panel = new wxPanel(this);
+    wxPanel *panel = new wxPanel(parent);
 
-    (void) new wxButton( panel, -1, wxT("Button"),
-        wxPoint(10, 10), wxSize(-1, -1) );
+    (void) new wxButton( panel, wxID_ANY, wxT("Button"),
+        wxPoint(10, 10), wxDefaultSize );
 
     return panel;
 }
 
-wxPanel *MyNotebook::CreateRadioButtonsPage()
+wxPanel *CreateRadioButtonsPage(wxBookCtrlBase *parent)
 {
-    wxPanel *panel = new wxPanel(this);
+    wxPanel *panel = new wxPanel(parent);
 
     wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
         wxT("Sabre-toothed tiger"), wxT("T Rex") };
 
-    wxRadioBox *radiobox1 = new wxRadioBox(panel, -1, wxT("Choose one"),
+    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, -1,
+    wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY,
         wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize,
         4, computers, 0, wxRA_SPECIFY_COLS);
 
@@ -123,22 +83,21 @@ wxPanel *MyNotebook::CreateRadioButtonsPage()
     return panel;
 }
 
-wxPanel *MyNotebook::CreateVetoPage()
+wxPanel *CreateVetoPage(wxBookCtrlBase *parent)
 {
-    wxPanel *panel = new wxPanel(this);
+    wxPanel *panel = new wxPanel(parent);
 
-    (void) new wxStaticText( panel, -1,
+    (void) new wxStaticText( panel, wxID_ANY,
         wxT("This page intentionally left blank"), wxPoint(10, 10) );
 
     return panel;
 }
 
-wxPanel *MyNotebook::CreateBigButtonPage()
+wxPanel *CreateBigButtonPage(wxBookCtrlBase *parent)
 {
-    wxPanel *panel = new wxPanel(this);
+    wxPanel *panel = new wxPanel(parent);
 
-    wxButton *buttonBig = new wxButton( panel, -1, wxT("Maximized button"),
-        wxPoint(0, 0), wxSize(480, 360) );
+    wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button"));
 
     wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
     sizerPanel->Add(buttonBig, 1, wxEXPAND);
@@ -148,57 +107,161 @@ wxPanel *MyNotebook::CreateBigButtonPage()
 }
 
 
-wxPanel *MyNotebook::CreateInsertPage()
+wxPanel *CreateInsertPage(wxBookCtrlBase *parent)
 {
-    wxPanel *panel = new wxPanel(this);
+    wxPanel *panel = new wxPanel(parent);
 
     panel->SetBackgroundColour( wxColour( wxT("MAROON") ) );
-    (void) new wxStaticText( panel, -1,
+    (void) new wxStaticText( panel, wxID_ANY,
         wxT("This page has been inserted, not added."), wxPoint(10, 10) );
 
     return panel;
 }
 
-void MyNotebook::CreateInitialPages()
+int GetIconIndex(wxBookCtrlBase* bookCtrl)
 {
-    // Create and add some panels to the notebook
+    if (bookCtrl && bookCtrl->GetImageList())
+    {
+       int nImages = bookCtrl->GetImageList()->GetImageCount();
+       if (nImages > 0)
+       {
+           return bookCtrl->GetPageCount() % nImages;
+       }
+    }
+
+    return -1;
+}
 
-    wxPanel *panel = CreateRadioButtonsPage();
-    AddPage( panel, RADIOBUTTONS_PAGE_NAME, FALSE, GetIconIndex() );
+void CreateInitialPages(wxBookCtrlBase *parent)
+{
+    // Create and add some panels to the notebook
 
-    panel = CreateVetoPage();
-    AddPage( panel, VETO_PAGE_NAME, FALSE, GetIconIndex() );
+    wxPanel *panel = CreateRadioButtonsPage(parent);
+    parent->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(parent) );
 
-    panel = CreateBigButtonPage();
-    AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, FALSE, GetIconIndex() );
+    panel = CreateVetoPage(parent);
+    parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) );
 
-    panel = CreateInsertPage();
-    InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, FALSE, GetIconIndex() );
+    panel = CreateBigButtonPage(parent);
+    parent->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(parent) );
 
+    panel = CreateInsertPage(parent);
+    parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) );
 
-    SetSelection(1);
+    parent->SetSelection(1);
 }
 
-int MyNotebook::GetIconIndex() const
+wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
 {
-    if (m_imageList)
+    if
+    (
+        pageName.Contains(INSERTED_PAGE_NAME)
+        || pageName.Contains(ADDED_PAGE_NAME)
+    )
     {
-       int nImages = m_imageList->GetImageCount();
-       if (nImages > 0)
-       {
-           return GetPageCount() % nImages;
-       }
+        return CreateUserCreatedPage(parent);
     }
 
-    return -1;
+    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;
 }
 
 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
                  long style)
-    : wxFrame((wxWindow *) NULL, -1, title, pos, size, style)
+    : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
 {
-    m_panel = (wxPanel *) NULL;
-    m_notebook = (MyNotebook *) NULL;
+#if wxUSE_NOTEBOOK
+    m_type = ID_BOOK_NOTEBOOK;
+#elif wxUSE_CHOICEBOOK
+    m_type = ID_BOOK_CHOICEBOOK;
+#elif wxUSE_LISTBOOK
+    m_type = ID_BOOK_LISTBOOK;
+#elif
+    #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
+#endif
+
+    m_orient = ID_ORIENT_DEFAULT;
+    m_chkShowImages = true;
+    m_multi = false;
+
+    SetIcon(wxICON(sample));
+
+    // menu of the sample
+    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
+    menuType->Check(m_type, true);
+
+    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
 
     // create a dummy image list with a few icons
     wxSize imageSize(32, 32);
@@ -226,346 +289,424 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
             wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)
         );
 
-    m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
+    m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
         wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
 
-    // Create remaining controls
-
-    // must be in sync with Orient enum
-    wxString strOrientations[] =
-    {
-        wxT("&Top"),
-        wxT("&Bottom"),
-        wxT("&Left"),
-        wxT("&Right"),
-    };
-
-    wxASSERT_MSG( WXSIZEOF(strOrientations) == ORIENT_MAX,
-                  wxT("Forgot to update something") );
-
-    m_radioOrient = new wxRadioBox
-                    (
-                        m_panel, ID_RADIO_ORIENT,
-                        wxT("&Tab orientation"),
-                        wxDefaultPosition, wxDefaultSize,
-                        WXSIZEOF(strOrientations), strOrientations,
-                        1, wxRA_SPECIFY_COLS
-                    );
-
-    m_chkShowImages = new wxCheckBox( m_panel, ID_CHK_SHOWIMAGES,
-        wxT("&Show images") );
-#ifndef TEST_LISTBOOK
-    m_chkMultiLine = new wxCheckBox( m_panel, ID_CHK_MULTILINE,
-        wxT("&Multiple lines") );
-#endif // !TEST_LISTBOOK
-
-    m_btnAddPage = new wxButton( m_panel, ID_BTN_ADD_PAGE, wxT("&Add page") );
-
-    m_btnInsertPage = new wxButton( m_panel, ID_BTN_INSERT_PAGE,
-        wxT("&Insert page") );
-
-    m_btnDeleteCurPage = new wxButton( m_panel, ID_BTN_DELETE_CUR_PAGE,
-        wxT("&Delete current page") );
-
-    m_btnDeleteLastPage = new wxButton( m_panel, ID_BTN_DELETE_LAST_PAGE,
-        wxT("Delete las&t page") );
-
-    m_btnNextPage = new wxButton( m_panel, ID_BTN_NEXT_PAGE,
-        wxT("&Next page") );
-
-    m_btnExit = new wxButton( m_panel, wxID_OK, wxT("&Exit") );
-    m_btnExit->SetDefault();
-
-    m_text = new wxTextCtrl(m_panel, -1, wxEmptyString,
+#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);
 
-    m_sizerTop = new wxBoxSizer(wxHORIZONTAL);
+#if USE_LOG
+    m_sizerFrame->Add(m_text, 1, wxEXPAND);
+#endif // USE_LOG
 
-    wxBoxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL);
-    sizerLeft->Add(m_radioOrient, 0, wxEXPAND);
-    sizerLeft->Add(m_chkShowImages, 0, wxEXPAND | wxTOP, 4);
-#ifndef TEST_LISTBOOK
-    sizerLeft->Add(m_chkMultiLine, 0, wxEXPAND | wxTOP, 4);
-#endif // !TEST_LISTBOOK
-
-    sizerLeft->Add(0, 0, 1); // Spacer
-
-    sizerLeft->Add(m_btnAddPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4);
-    sizerLeft->Add(m_btnInsertPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4);
-    sizerLeft->Add(m_btnDeleteCurPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4);
-    sizerLeft->Add(m_btnDeleteLastPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4);
-    sizerLeft->Add(m_btnNextPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4);
-
-    sizerLeft->Add(0, 0, 1); // Spacer
-
-    sizerLeft->Add(m_btnExit, 0, wxEXPAND);
-
-    m_sizerTop->Add(sizerLeft, 0, wxEXPAND | wxALL, 4);
-
-
-    m_sizerFrame->Add(m_sizerTop, 1, wxEXPAND);
-    m_sizerFrame->Add(m_text, 0, wxEXPAND);
-
-    ReInitNotebook();
-    m_notebook->CreateInitialPages();
+    RecreateBooks();
 
     m_panel->SetSizer(m_sizerFrame);
 
-    m_panel->SetAutoLayout(TRUE);
-
     m_sizerFrame->Fit(this);
+    m_sizerFrame->SetSizeHints(this);
 
     Centre(wxBOTH);
-
 }
 
 MyFrame::~MyFrame()
 {
+#if USE_LOG
     delete wxLog::SetActiveTarget(m_logTargetOld);
+#endif // USE_LOG
 
     if (m_imageList)
     {
         delete m_imageList;
         m_imageList = (wxImageList *) NULL;
     }
-
 }
 
-void MyFrame::ReInitNotebook()
+int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
 {
-    int flags;
-
-    switch ( m_radioOrient->GetSelection() )
+    switch (id)
     {
-        default:
-            wxFAIL_MSG( wxT("unknown notebook orientation") );
-            // fall through
-
-        case ORIENT_TOP:
-            flags = wxNB_TOP;
-            break;
-
-        case ORIENT_BOTTOM:
-            flags = wxNB_BOTTOM;
-            break;
-
-        case ORIENT_LEFT:
-            flags = wxNB_LEFT;
-            break;
-
-        case ORIENT_RIGHT:
-            flags = wxNB_RIGHT;
-            break;
+        case ID_NOTEBOOK:   return nb;
+        case ID_LISTBOOK:   return lb;
+        case ID_CHOICEBOOK: return chb;
     }
+    return 0;
+}
+
+#ifdef __SMARTPHONE__
+    #define MARGIN 0
+#else
+    #define MARGIN 4
+#endif
 
-#ifndef TEST_LISTBOOK
-    if ( m_chkMultiLine->IsChecked() )
-        flags |= wxNB_MULTILINE;
-#endif // !TEST_LISTBOOK
+#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                                                                           \
+    {                                                                              \
+        CreateInitialPages(newBook);                                               \
+    }                                                                              \
+                                                                                   \
+    m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, MARGIN);                 \
+                                                                                   \
+    m_sizerFrame->Hide(newBook);                                                   \
+}
 
-    MyNotebook *notebook = m_notebook;
+void MyFrame::RecreateBooks()
+{
+#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
 
-    m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK,
-                                wxDefaultPosition, wxDefaultSize,
-                                flags);
+    ShowCurrentBook();
+}
 
-    if ( m_chkShowImages->IsChecked() )
+wxBookCtrlBase *MyFrame::GetCurrentBook()
+{
+    switch (m_type)
     {
-        m_notebook->SetImageList(m_imageList);
+#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
     }
+    return NULL;
+}
 
-    if (notebook)
+void MyFrame::ShowCurrentBook()
+{
+    switch(m_type)
     {
-        int sel = notebook->GetSelection();
-
-        int count = notebook->GetPageCount();
-        for (int n = 0; n < count; n++)
-        {
-            wxString str = notebook->GetPageText(n);
-
-            wxWindow *page = m_notebook->CreatePage(str);
-            m_notebook->AddPage(page, str, FALSE, m_notebook->GetIconIndex() );
-        }
-
-        if (m_sizerNotebook)
-        {
-            m_sizerTop->Remove(m_sizerNotebook);
-        }
-
-        delete notebook;
-
-        // restore selection
-        if (sel != -1)
-        {
-            m_notebook->SetSelection(sel);
-        }
-
+#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_sizerNotebook = new wxBookCtrlSizer(m_notebook);
-    m_sizerTop->Add(m_sizerNotebook, 1, wxEXPAND | wxALL, 4);
-    m_sizerTop->Layout();
+    m_sizerFrame->Layout();
 }
 
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
-    EVT_RADIOBOX(ID_RADIO_ORIENT, MyFrame::OnCheckOrRadioBox)
-    EVT_CHECKBOX(ID_CHK_SHOWIMAGES, MyFrame::OnCheckOrRadioBox)
-#ifndef TEST_LISTBOOK
-    EVT_CHECKBOX(ID_CHK_MULTILINE, MyFrame::OnCheckOrRadioBox)
-#endif // !TEST_LISTBOOK
-
-    EVT_BUTTON(ID_BTN_ADD_PAGE, MyFrame::OnButtonAddPage)
-    EVT_BUTTON(ID_BTN_INSERT_PAGE, MyFrame::OnButtonInsertPage)
-    EVT_BUTTON(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnButtonDeleteCurPage)
-    EVT_BUTTON(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnButtonDeleteLastPage)
-    EVT_BUTTON(ID_BTN_NEXT_PAGE, MyFrame::OnButtonNextPage)
-    EVT_BUTTON(wxID_OK, MyFrame::OnButtonExit)
-
-    EVT_UPDATE_UI(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnUpdateUIBtnDeleteCurPage)
-    EVT_UPDATE_UI(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnUpdateUIBtnDeleteLastPage)
-
+    // 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::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
+void MyFrame::OnType(wxCommandEvent& event)
 {
-    ReInitNotebook();
-}
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
-void MyFrame::OnButtonAddPage( wxCommandEvent& WXUNUSED(event) )
-{
-    static unsigned s_pageAdded = 0;
+    m_type = event.GetId();
 
-    wxPanel *panel = new wxPanel( m_notebook, -1 );
-    (void) new wxButton( panel, -1, wxT("First button"),
-        wxPoint(10, 10), wxSize(-1, -1) );
-    (void) new wxButton( panel, -1, wxT("Second button"),
-        wxPoint(50, 100), wxSize(-1, -1) );
+    if (currBook)
+        m_sizerFrame->Hide(currBook);
 
-    m_notebook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
-        ++s_pageAdded), TRUE, m_notebook->GetIconIndex() );
+    ShowCurrentBook();
 }
 
-void MyFrame::OnButtonInsertPage( wxCommandEvent& WXUNUSED(event) )
+void MyFrame::OnOrient(wxCommandEvent& event)
 {
-    static unsigned s_pageIns = 0;
+    m_orient = event.GetId();
+    RecreateBooks();
+    m_sizerFrame->Layout();
+}
 
-    wxPanel *panel = m_notebook->CreateUserCreatedPage();
+void MyFrame::OnShowImages(wxCommandEvent& event)
+{
+    m_chkShowImages = event.IsChecked();
+    RecreateBooks();
+    m_sizerFrame->Layout();
+}
 
-    m_notebook->InsertPage( 0, panel,
-        wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), FALSE,
-        m_notebook->GetIconIndex() );
+void MyFrame::OnMulti(wxCommandEvent& event)
+{
+    m_multi = event.IsChecked();
+    RecreateBooks();
+    m_sizerFrame->Layout();
+    wxLogMessage(_T("Multiline setting works only in wxNotebook."));
+}
 
-    m_notebook->SetSelection(0);
+void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
+{
+    Close();
 }
 
-void MyFrame::OnButtonDeleteLastPage( wxCommandEvent& WXUNUSED(event) )
+void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
 {
-    int page = m_notebook->GetPageCount();
+    static unsigned s_pageAdded = 0;
 
-    if ( page != 0 )
+    wxBookCtrlBase *currBook = GetCurrentBook();
+
+    if ( currBook )
     {
-        m_notebook->DeletePage(page - 1);
+        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) );
     }
 }
 
-void MyFrame::OnButtonDeleteCurPage( wxCommandEvent& WXUNUSED(event) )
+void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
 {
-    int sel = m_notebook->GetSelection();
+    static unsigned s_pageIns = 0;
+
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
-    if (sel != -1)
+    if ( currBook )
     {
-        m_notebook->DeletePage(sel);
+        wxPanel *panel = CreateUserCreatedPage( currBook );
+
+        currBook->InsertPage( 0, panel,
+            wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false,
+            GetIconIndex(currBook) );
+
+        currBook->SetSelection(0);
     }
 }
 
-void MyFrame::OnButtonNextPage( wxCommandEvent& WXUNUSED(event) )
+void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
 {
-    m_notebook->AdvanceSelection();
-}
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
-void MyFrame::OnButtonExit( wxCommandEvent& WXUNUSED(event) )
-{
-    Close();
+    if ( currBook )
+    {
+        int sel = currBook->GetSelection();
+
+        if (sel != wxNOT_FOUND)
+        {
+            currBook->DeletePage(sel);
+        }
+    }
 }
 
-void MyFrame::OnNotebook(wxNotebookEvent& event)
+void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
 {
-    wxString str = wxT("Unknown notebook event");
-
-    wxEventType eventType = event.GetEventType();
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
-    if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
-    {
-        str = wxT("Notebook changed");
-    }
-    else if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
+    if ( currBook )
     {
-        int idx = event.GetOldSelection();
-        if ( idx != -1 && m_notebook->GetPageText(idx) == VETO_PAGE_NAME )
-        {
-            if
-            (
-                wxMessageBox(
-                wxT("Are you sure you want to leave this notebook page?\n")
-                wxT("(This demonstrates veto-ing)"),
-                          wxT("Notebook sample"),
-                          wxICON_QUESTION | wxYES_NO, this) != wxYES )
-            {
-                event.Veto();
-
-                return;
-            }
+        int page = currBook->GetPageCount();
 
+        if ( page != 0 )
+        {
+            currBook->DeletePage(page - 1);
         }
-
-        str = wxT("Notebook changing");
     }
+}
 
-    static int s_numNotebookEvents = 0;
-
-    wxLogMessage(wxT("Notebook event #%d: %s (%d)"),
-        s_numNotebookEvents++, str.c_str(), eventType);
-
-    m_text->SetInsertionPointEnd();
+void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
+{
+    wxBookCtrlBase *currBook = GetCurrentBook();
 
-    event.Skip();
+    if ( currBook )
+    {
+        currBook->AdvanceSelection();
+    }
 }
 
 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
 {
-    static int s_nPages = -1;
-    static int s_nSel = -1;
+    static int s_nPages = wxNOT_FOUND;
+    static int s_nSel = wxNOT_FOUND;
+    static wxBookCtrlBase *s_currBook = NULL;
+
+    wxBookCtrlBase *currBook = GetCurrentBook();
+
+    int nPages = currBook ? currBook->GetPageCount() : 0;
+    int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND;
 
-    int nPages = m_notebook->GetPageCount();
-    int nSel = m_notebook->GetSelection();
-    if ( nPages != s_nPages || nSel != s_nSel )
+    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(wxT("Notebook (%d pages, selection: %d)"), nPages, nSel);
+        title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str());
 
         SetTitle(title);
     }
 }
 
-void MyFrame::OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event)
-{
-    event.Enable( m_notebook->GetSelection() != -1 );
-}
+#if USE_LOG
+    #define BOOKEVENT_LOG m_text->SetInsertionPointEnd();
+#else
+    #define BOOKEVENT_LOG
+#endif
 
-void MyFrame::OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event)
-{
-    event.Enable( m_notebook->GetPageCount() != 0 );
+#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();                                                 \
+        wxBookCtrlBase *book = (wxBookCtrlBase *)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());                                                          \
+                                                                                           \
+    BOOKEVENT_LOG                                                                          \
 }
+
+#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