1998-10-26 13:32:07 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2002-07-19 15:57:58 -04:00
|
|
|
// Name: samples/notebook/notebook.cpp
|
|
|
|
// Purpose: a sample demonstrating notebook usage
|
1998-10-26 13:32:07 -05:00
|
|
|
// Author: Julian Smart
|
2002-07-19 15:57:58 -04:00
|
|
|
// Modified by: Dimitri Schoolwerth
|
1998-10-26 13:32:07 -05:00
|
|
|
// Created: 26/10/98
|
|
|
|
// RCS-ID: $Id$
|
2002-07-19 15:57:58 -04:00
|
|
|
// Copyright: (c) 1998-2002 wxWindows team
|
|
|
|
// License: wxWindows license
|
1998-10-26 13:32:07 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
1999-08-02 17:31:09 -04:00
|
|
|
#pragma hdrstop
|
1998-10-26 13:32:07 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
1999-08-02 17:31:09 -04:00
|
|
|
#include "wx/wx.h"
|
1998-10-26 13:32:07 -05:00
|
|
|
#endif
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
#include "wx/imaglist.h"
|
|
|
|
#include "wx/artprov.h"
|
2000-03-14 14:24:14 -05:00
|
|
|
#include "notebook.h"
|
1998-10-26 13:32:07 -05:00
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2000-02-28 20:49:05 -05:00
|
|
|
bool MyApp::OnInit()
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
// 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
|
2000-09-01 04:35:30 -04:00
|
|
|
#if defined(__WIN16__) || defined(__WXMOTIF__)
|
2002-07-19 15:57:58 -04:00
|
|
|
int width, height;
|
|
|
|
frame->GetSize(& width, & height);
|
|
|
|
frame->SetSize(-1, -1, width, height);
|
1998-12-11 11:09:06 -05:00
|
|
|
#endif
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
frame->Show();
|
|
|
|
|
|
|
|
return TRUE;
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
MyNotebook::MyNotebook(wxWindow *parent, wxWindowID id,
|
|
|
|
const wxPoint& pos, const wxSize& size, long style)
|
|
|
|
: wxNotebook(parent, id, pos, size, style)
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
// Empty
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxPanel *MyNotebook::CreatePage(const wxString&pageName)
|
2002-07-19 15:57:58 -04:00
|
|
|
{
|
2002-07-21 10:43:09 -04:00
|
|
|
if
|
|
|
|
(
|
|
|
|
pageName.Contains(INSERTED_PAGE_NAME)
|
|
|
|
|| pageName.Contains(ADDED_PAGE_NAME)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return CreateUserCreatedPage();
|
|
|
|
}
|
1999-08-02 17:31:09 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
if (pageName == I_WAS_INSERTED_PAGE_NAME)
|
|
|
|
{
|
|
|
|
return CreateInsertPage();
|
|
|
|
}
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
if (pageName == VETO_PAGE_NAME)
|
|
|
|
{
|
|
|
|
return CreateVetoPage();
|
|
|
|
}
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
if (pageName == RADIOBUTTONS_PAGE_NAME)
|
|
|
|
{
|
|
|
|
return CreateRadioButtonsPage();
|
|
|
|
}
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
if (pageName == MAXIMIZED_BUTTON_PAGE_NAME)
|
|
|
|
{
|
|
|
|
return CreateBigButtonPage();
|
|
|
|
}
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxFAIL;
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
return (wxPanel *) NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPanel *MyNotebook::CreateUserCreatedPage()
|
|
|
|
{
|
|
|
|
wxPanel *panel = new wxPanel(this);
|
|
|
|
|
|
|
|
(void) new wxButton( panel, -1, wxT("Button"),
|
|
|
|
wxPoint(10, 10), wxSize(-1, -1) );
|
|
|
|
|
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPanel *MyNotebook::CreateRadioButtonsPage()
|
|
|
|
{
|
|
|
|
wxPanel *panel = new wxPanel(this);
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
|
|
|
|
wxT("Sabre-toothed tiger"), wxT("T Rex") };
|
2002-07-21 10:43:09 -04:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
wxRadioBox *radiobox1 = new wxRadioBox(panel, -1, wxT("Choose one"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS);
|
|
|
|
|
|
|
|
wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
|
|
|
|
wxT("Another") };
|
2002-07-21 10:43:09 -04:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
wxRadioBox *radiobox2 = new wxRadioBox(panel, -1,
|
|
|
|
wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize,
|
|
|
|
4, computers, 0, wxRA_SPECIFY_COLS);
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
|
2002-07-19 15:57:58 -04:00
|
|
|
sizerPanel->Add(radiobox1, 2, wxEXPAND);
|
|
|
|
sizerPanel->Add(radiobox2, 1, wxEXPAND);
|
|
|
|
panel->SetSizer(sizerPanel);
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
return panel;
|
|
|
|
}
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxPanel *MyNotebook::CreateVetoPage()
|
|
|
|
{
|
|
|
|
wxPanel *panel = new wxPanel(this);
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
(void) new wxStaticText( panel, -1,
|
|
|
|
wxT("This page intentionally left blank"), wxPoint(10, 10) );
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPanel *MyNotebook::CreateBigButtonPage()
|
|
|
|
{
|
|
|
|
wxPanel *panel = new wxPanel(this);
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxButton *buttonBig = new wxButton( panel, -1, wxT("Maximized button"),
|
2002-07-19 15:57:58 -04:00
|
|
|
wxPoint(0, 0), wxSize(480, 360) );
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
|
2002-07-19 15:57:58 -04:00
|
|
|
sizerPanel->Add(buttonBig, 1, wxEXPAND);
|
|
|
|
panel->SetSizer(sizerPanel);
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxPanel *MyNotebook::CreateInsertPage()
|
|
|
|
{
|
|
|
|
wxPanel *panel = new wxPanel(this);
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
panel->SetBackgroundColour( wxColour( wxT("MAROON") ) );
|
|
|
|
(void) new wxStaticText( panel, -1,
|
|
|
|
wxT("This page has been inserted, not added."), wxPoint(10, 10) );
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
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() );
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
panel = CreateBigButtonPage();
|
|
|
|
AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, FALSE, GetIconIndex() );
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
panel = CreateInsertPage();
|
|
|
|
InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, FALSE, GetIconIndex() );
|
|
|
|
|
|
|
|
|
|
|
|
SetSelection(1);
|
2002-07-19 15:57:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int MyNotebook::GetIconIndex() const
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
if (m_imageList)
|
|
|
|
{
|
|
|
|
int nImages = m_imageList->GetImageCount();
|
|
|
|
if (nImages > 0)
|
|
|
|
{
|
|
|
|
return GetPageCount() % nImages;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
|
|
|
|
long style)
|
|
|
|
: wxFrame((wxWindow *) NULL, -1, title, pos, size, style)
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
m_panel = (wxPanel *) NULL;
|
|
|
|
m_notebook = (MyNotebook *) NULL;
|
2002-07-21 10:43:09 -04:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
);
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
|
2002-07-21 10:43:09 -04:00
|
|
|
wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER);
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
// 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,
|
2002-07-21 10:43:09 -04:00
|
|
|
wxT("Forgot to update something") );
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
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") );
|
|
|
|
|
2002-08-15 20:09:29 -04:00
|
|
|
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") );
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
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_notebook = new MyNotebook(m_panel, ID_NOTEBOOK);
|
|
|
|
|
|
|
|
m_text = new wxTextCtrl(m_panel, -1, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
|
|
|
|
|
|
|
|
m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) );
|
|
|
|
|
|
|
|
// Create the notebook's panels
|
|
|
|
m_notebook->CreateInitialPages();
|
|
|
|
|
|
|
|
// 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);
|
2002-08-15 20:09:29 -04:00
|
|
|
sizerLeft->Add(m_btnDeleteCurPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4);
|
|
|
|
sizerLeft->Add(m_btnDeleteLastPage, 0, wxEXPAND | (wxTOP | wxBOTTOM), 4);
|
2002-07-19 15:57:58 -04:00
|
|
|
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_panel->SetSizer(m_sizerFrame);
|
|
|
|
|
|
|
|
m_panel->SetAutoLayout(TRUE);
|
|
|
|
|
|
|
|
m_sizerFrame->Fit(this);
|
|
|
|
|
|
|
|
Centre(wxBOTH);
|
|
|
|
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
MyFrame::~MyFrame()
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
delete wxLog::SetActiveTarget(m_logTargetOld);
|
2002-07-21 10:43:09 -04:00
|
|
|
|
|
|
|
if (m_imageList)
|
|
|
|
{
|
|
|
|
delete m_imageList;
|
|
|
|
m_imageList = (wxImageList *) NULL;
|
|
|
|
}
|
|
|
|
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::ReInitNotebook()
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
int flags;
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
switch ( m_radioOrient->GetSelection() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT("unknown notebook orientation") );
|
|
|
|
// fall through
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
case ORIENT_TOP:
|
|
|
|
flags = wxNB_TOP;
|
|
|
|
break;
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
case ORIENT_BOTTOM:
|
|
|
|
flags = wxNB_BOTTOM;
|
|
|
|
break;
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
case ORIENT_LEFT:
|
|
|
|
flags = wxNB_LEFT;
|
|
|
|
break;
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
case ORIENT_RIGHT:
|
|
|
|
flags = wxNB_RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyNotebook *notebook = m_notebook;
|
|
|
|
|
|
|
|
m_notebook = new MyNotebook(m_panel, ID_NOTEBOOK,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
flags);
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
if ( m_chkShowImages->IsChecked() )
|
|
|
|
{
|
|
|
|
m_notebook->SetImageList(m_imageList);
|
|
|
|
}
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
if (notebook)
|
2002-07-19 15:57:58 -04:00
|
|
|
{
|
|
|
|
int sel = notebook->GetSelection();
|
|
|
|
|
|
|
|
int count = notebook->GetPageCount();
|
2002-07-21 10:43:09 -04:00
|
|
|
for (int n = 0; n < count; n++)
|
2002-07-19 15:57:58 -04:00
|
|
|
{
|
2002-07-21 10:43:09 -04:00
|
|
|
wxString str = notebook->GetPageText(n);
|
2002-07-19 15:57:58 -04:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxNotebookPage *page = m_notebook->CreatePage(str);
|
|
|
|
m_notebook->AddPage(page, str, FALSE, m_notebook->GetIconIndex() );
|
2002-07-19 15:57:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_sizerNotebook)
|
|
|
|
{
|
|
|
|
m_sizerTop->Remove(m_sizerNotebook);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete notebook;
|
|
|
|
|
|
|
|
// restore selection
|
2002-07-21 10:43:09 -04:00
|
|
|
if (sel != -1)
|
2002-07-19 15:57:58 -04:00
|
|
|
{
|
|
|
|
m_notebook->SetSelection(sel);
|
|
|
|
}
|
2002-07-21 10:43:09 -04:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
}
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
m_sizerNotebook = new wxNotebookSizer(m_notebook);
|
|
|
|
m_sizerTop->Add(m_sizerNotebook, 1, wxEXPAND | wxALL, 4);
|
|
|
|
m_sizerTop->Layout();
|
|
|
|
}
|
|
|
|
|
1998-10-26 13:32:07 -05:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2002-07-19 15:57:58 -04:00
|
|
|
EVT_RADIOBOX(ID_RADIO_ORIENT, MyFrame::OnCheckOrRadioBox)
|
|
|
|
EVT_CHECKBOX(ID_CHK_SHOWIMAGES, MyFrame::OnCheckOrRadioBox)
|
|
|
|
|
|
|
|
EVT_BUTTON(ID_BTN_ADD_PAGE, MyFrame::OnButtonAddPage)
|
|
|
|
EVT_BUTTON(ID_BTN_INSERT_PAGE, MyFrame::OnButtonInsertPage)
|
2002-08-15 20:09:29 -04:00
|
|
|
EVT_BUTTON(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnButtonDeleteCurPage)
|
|
|
|
EVT_BUTTON(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnButtonDeleteLastPage)
|
2002-07-19 15:57:58 -04:00
|
|
|
EVT_BUTTON(ID_BTN_NEXT_PAGE, MyFrame::OnButtonNextPage)
|
|
|
|
EVT_BUTTON(wxID_OK, MyFrame::OnButtonExit)
|
|
|
|
|
2002-08-15 20:09:29 -04:00
|
|
|
EVT_UPDATE_UI(ID_BTN_DELETE_CUR_PAGE, MyFrame::OnUpdateUIBtnDeleteCurPage)
|
|
|
|
EVT_UPDATE_UI(ID_BTN_DELETE_LAST_PAGE, MyFrame::OnUpdateUIBtnDeleteLastPage)
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook)
|
|
|
|
EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook)
|
|
|
|
|
1999-06-24 17:27:52 -04:00
|
|
|
EVT_IDLE(MyFrame::OnIdle)
|
1998-10-26 13:32:07 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::OnCheckOrRadioBox(wxCommandEvent& event)
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
ReInitNotebook();
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::OnButtonAddPage( wxCommandEvent& WXUNUSED(event) )
|
1999-05-20 10:32:04 -04:00
|
|
|
{
|
2000-02-28 20:49:05 -05:00
|
|
|
static size_t s_pageAdded = 0;
|
|
|
|
|
|
|
|
wxPanel *panel = new wxPanel( m_notebook, -1 );
|
2003-06-02 06:27:03 -04:00
|
|
|
(void) new wxButton( panel, -1, wxT("First button"),
|
2002-07-19 15:57:58 -04:00
|
|
|
wxPoint(10, 10), wxSize(-1, -1) );
|
2002-12-04 09:11:26 -05:00
|
|
|
(void) new wxButton( panel, -1, wxT("Second button"),
|
|
|
|
wxPoint(50, 100), wxSize(-1, -1) );
|
2000-02-28 20:49:05 -05:00
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
m_notebook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"),
|
2002-12-04 09:11:26 -05:00
|
|
|
++s_pageAdded), TRUE, m_notebook->GetIconIndex() );
|
2000-02-28 20:49:05 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::OnButtonInsertPage( wxCommandEvent& WXUNUSED(event) )
|
2000-02-28 20:49:05 -05:00
|
|
|
{
|
|
|
|
static size_t s_pageIns = 0;
|
|
|
|
|
2002-07-21 10:43:09 -04:00
|
|
|
wxPanel *panel = m_notebook->CreateUserCreatedPage();
|
2002-07-19 15:57:58 -04:00
|
|
|
|
|
|
|
m_notebook->InsertPage( 0, panel,
|
2002-07-21 10:43:09 -04:00
|
|
|
wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), FALSE,
|
2002-07-19 15:57:58 -04:00
|
|
|
m_notebook->GetIconIndex() );
|
2000-02-28 20:49:05 -05:00
|
|
|
|
|
|
|
m_notebook->SetSelection(0);
|
1999-05-20 10:32:04 -04:00
|
|
|
}
|
|
|
|
|
2002-08-15 20:09:29 -04:00
|
|
|
void MyFrame::OnButtonDeleteLastPage( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
int page = m_notebook->GetPageCount();
|
|
|
|
|
|
|
|
if ( page != 0 )
|
|
|
|
{
|
|
|
|
m_notebook->DeletePage(page - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnButtonDeleteCurPage( wxCommandEvent& WXUNUSED(event) )
|
1999-05-25 06:40:07 -04:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
int sel = m_notebook->GetSelection();
|
2000-07-15 15:51:35 -04:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
if (sel != -1)
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
m_notebook->DeletePage(sel);
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
1999-05-25 06:40:07 -04:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::OnButtonNextPage( wxCommandEvent& WXUNUSED(event) )
|
2000-02-22 10:29:59 -05:00
|
|
|
{
|
|
|
|
m_notebook->AdvanceSelection();
|
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::OnButtonExit( wxCommandEvent& WXUNUSED(event) )
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
Close();
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::OnNotebook(wxNotebookEvent& event)
|
1998-10-26 13:32:07 -05:00
|
|
|
{
|
2002-07-19 15:57:58 -04:00
|
|
|
wxString str = wxT("Unknown notebook event");
|
1999-08-02 17:31:09 -04:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
wxEventType eventType = event.GetEventType();
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
|
|
|
|
{
|
|
|
|
str = wxT("Notebook changed");
|
|
|
|
}
|
|
|
|
else if (eventType == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
str = wxT("Notebook changing");
|
|
|
|
}
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
static int s_numNotebookEvents = 0;
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
wxLogMessage(wxT("Notebook event #%d: %s (%d)"),
|
2002-08-21 11:58:49 -04:00
|
|
|
s_numNotebookEvents++, str.c_str(), eventType);
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
m_text->SetInsertionPointEnd();
|
1998-10-26 13:32:07 -05:00
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
event.Skip();
|
1998-10-26 13:32:07 -05:00
|
|
|
}
|
|
|
|
|
2002-07-19 15:57:58 -04:00
|
|
|
void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
|
1999-06-24 17:27:52 -04:00
|
|
|
{
|
|
|
|
static int s_nPages = -1;
|
|
|
|
static int s_nSel = -1;
|
|
|
|
|
|
|
|
int nPages = m_notebook->GetPageCount();
|
|
|
|
int nSel = m_notebook->GetSelection();
|
|
|
|
if ( nPages != s_nPages || nSel != s_nSel )
|
|
|
|
{
|
|
|
|
s_nPages = nPages;
|
|
|
|
s_nSel = nSel;
|
|
|
|
|
|
|
|
wxString title;
|
2002-07-19 15:57:58 -04:00
|
|
|
title.Printf(wxT("Notebook (%d pages, selection: %d)"), nPages, nSel);
|
1999-06-24 17:27:52 -04:00
|
|
|
|
|
|
|
SetTitle(title);
|
|
|
|
}
|
|
|
|
}
|
2002-08-15 20:09:29 -04:00
|
|
|
|
|
|
|
void MyFrame::OnUpdateUIBtnDeleteCurPage(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable( m_notebook->GetSelection() != -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnUpdateUIBtnDeleteLastPage(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable( m_notebook->GetPageCount() != 0 );
|
|
|
|
}
|