+void MyNotebook::CreateInitialPages()
+{
+ wxPanel *panel = (wxPanel *) NULL;
+
+ // Create and add some panels to the notebook
+
+ panel = CreateRadioButtonsPage();
+ AddPage( panel, RADIOBUTTONS_PAGE_NAME, FALSE, GetIconIndex() );
+
+ panel = CreateVetoPage();
+ AddPage( panel, VETO_PAGE_NAME, FALSE, GetIconIndex() );
+
+ panel = CreateBigButtonPage();
+ AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, FALSE, GetIconIndex() );
+
+ panel = CreateInsertPage();
+ InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, FALSE, GetIconIndex() );
+
+
+ SetSelection(1);
+}
+
+int MyNotebook::GetIconIndex() const
+{
+ if (m_imageList)
+ {
+ int nImages = m_imageList->GetImageCount();
+ if (nImages > 0)
+ {
+ return GetPageCount() % nImages;
+ }
+ }
+
+ return -1;
+}
+
+MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
+ long style)
+ : wxFrame((wxWindow *) NULL, -1, title, pos, size, style)
+{
+ m_panel = (wxPanel *) NULL;
+ m_notebook = (MyNotebook *) NULL;
+
+ // 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, -1, 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") );
+
+ 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,
+ wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
+
+ m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) );
+
+ // Set sizers
+ m_sizerFrame = new wxBoxSizer(wxVERTICAL);
+
+ m_sizerTop = new wxBoxSizer(wxHORIZONTAL);
+
+ wxBoxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL);
+ {
+ sizerLeft->Add(m_radioOrient, 0, wxEXPAND);
+ sizerLeft->Add(m_chkShowImages, 0, wxEXPAND | wxTOP, 4);
+
+ 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();
+
+ m_panel->SetSizer(m_sizerFrame);
+
+ m_panel->SetAutoLayout(TRUE);
+
+ m_sizerFrame->Fit(this);
+
+ Centre(wxBOTH);
+
+}
+
+MyFrame::~MyFrame()
+{
+ delete wxLog::SetActiveTarget(m_logTargetOld);
+
+ if (m_imageList)
+ {
+ delete m_imageList;
+ m_imageList = (wxImageList *) NULL;
+ }
+
+}
+
+void MyFrame::ReInitNotebook()
+{
+ int flags;
+
+ switch ( m_radioOrient->GetSelection() )
+ {
+ 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;
+ }
+
+ MyNotebook *notebook = m_notebook;
+
+ m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK,
+ wxDefaultPosition, wxDefaultSize,
+ flags|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE);
+
+ if ( m_chkShowImages->IsChecked() )
+ {
+ m_notebook->SetImageList(m_imageList);
+ }
+
+ if (notebook)
+ {
+ 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);
+ }
+
+ }
+
+
+ m_sizerNotebook = new wxBookCtrlSizer(m_notebook);
+ m_sizerTop->Add(m_sizerNotebook, 1, wxEXPAND | wxALL, 4);
+ m_sizerTop->Layout();
+}