1998-10-26 18:32:07 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2002-07-19 19:57:58 +00:00
|
|
|
// Name: samples/notebook/notebook.cpp
|
|
|
|
// Purpose: a sample demonstrating notebook usage
|
1998-10-26 18:32:07 +00:00
|
|
|
// Author: Julian Smart
|
2002-07-19 19:57:58 +00:00
|
|
|
// Modified by: Dimitri Schoolwerth
|
1998-10-26 18:32:07 +00:00
|
|
|
// Created: 26/10/98
|
|
|
|
// RCS-ID: $Id$
|
2004-05-25 11:20:37 +00:00
|
|
|
// Copyright: (c) 1998-2002 wxWidgets team
|
2002-07-19 19:57:58 +00:00
|
|
|
// License: wxWindows license
|
1998-10-26 18:32:07 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
1999-08-02 21:31:09 +00:00
|
|
|
#pragma hdrstop
|
1998-10-26 18:32:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
1999-08-02 21:31:09 +00:00
|
|
|
#include "wx/wx.h"
|
1998-10-26 18:32:07 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-19 19:57:58 +00:00
|
|
|
#include "wx/imaglist.h"
|
|
|
|
#include "wx/artprov.h"
|
2000-03-14 19:24:14 +00:00
|
|
|
#include "notebook.h"
|
1998-10-26 18:32:07 +00:00
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2000-02-29 01:49:05 +00:00
|
|
|
bool MyApp::OnInit()
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2002-07-19 19:57:58 +00: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
|
2004-03-28 13:10:14 +00:00
|
|
|
#if defined(__WXMOTIF__)
|
2002-07-19 19:57:58 +00:00
|
|
|
int width, height;
|
|
|
|
frame->GetSize(& width, & height);
|
2004-07-20 10:09:47 +00:00
|
|
|
frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height);
|
1998-12-11 16:09:06 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-19 19:57:58 +00:00
|
|
|
frame->Show();
|
|
|
|
|
2004-05-20 11:00:13 +00:00
|
|
|
return true;
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *CreateUserCreatedPage(wxBookCtrl *parent)
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *panel = new wxPanel(parent);
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2004-05-20 11:00:13 +00:00
|
|
|
(void) new wxButton( panel, wxID_ANY, wxT("Button"),
|
|
|
|
wxPoint(10, 10), wxDefaultSize );
|
2002-07-21 14:43:09 +00:00
|
|
|
|
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *CreateRadioButtonsPage(wxBookCtrl *parent)
|
2002-07-21 14:43:09 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *panel = new wxPanel(parent);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
|
|
|
wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
|
|
|
|
wxT("Sabre-toothed tiger"), wxT("T Rex") };
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2004-05-20 11:00:13 +00:00
|
|
|
wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"),
|
2002-07-19 19:57:58 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS);
|
|
|
|
|
|
|
|
wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
|
|
|
|
wxT("Another") };
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2004-05-20 11:00:13 +00:00
|
|
|
wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY,
|
2002-07-19 19:57:58 +00:00
|
|
|
wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize,
|
|
|
|
4, computers, 0, wxRA_SPECIFY_COLS);
|
1998-10-26 18:32:07 +00:00
|
|
|
|
2002-07-21 14:43:09 +00:00
|
|
|
wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
|
2002-07-19 19:57:58 +00:00
|
|
|
sizerPanel->Add(radiobox1, 2, wxEXPAND);
|
|
|
|
sizerPanel->Add(radiobox2, 1, wxEXPAND);
|
|
|
|
panel->SetSizer(sizerPanel);
|
|
|
|
|
2002-07-21 14:43:09 +00:00
|
|
|
return panel;
|
|
|
|
}
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *CreateVetoPage(wxBookCtrl *parent)
|
2002-07-21 14:43:09 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *panel = new wxPanel(parent);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-05-20 11:00:13 +00:00
|
|
|
(void) new wxStaticText( panel, wxID_ANY,
|
2002-07-19 19:57:58 +00:00
|
|
|
wxT("This page intentionally left blank"), wxPoint(10, 10) );
|
|
|
|
|
2002-07-21 14:43:09 +00:00
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *CreateBigButtonPage(wxBookCtrl *parent)
|
2002-07-21 14:43:09 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *panel = new wxPanel(parent);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-06-12 19:38:33 +00:00
|
|
|
wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button"));
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2002-07-21 14:43:09 +00:00
|
|
|
wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL);
|
2002-07-19 19:57:58 +00:00
|
|
|
sizerPanel->Add(buttonBig, 1, wxEXPAND);
|
|
|
|
panel->SetSizer(sizerPanel);
|
|
|
|
|
2002-07-21 14:43:09 +00:00
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *CreateInsertPage(wxBookCtrl *parent)
|
2002-07-21 14:43:09 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *panel = new wxPanel(parent);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
|
|
|
panel->SetBackgroundColour( wxColour( wxT("MAROON") ) );
|
2004-05-20 11:00:13 +00:00
|
|
|
(void) new wxStaticText( panel, wxID_ANY,
|
2002-07-19 19:57:58 +00:00
|
|
|
wxT("This page has been inserted, not added."), wxPoint(10, 10) );
|
|
|
|
|
2002-07-21 14:43:09 +00:00
|
|
|
return panel;
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
int GetIconIndex(wxBookCtrl* bookCtrl)
|
2002-07-21 14:43:09 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
if (bookCtrl && bookCtrl->GetImageList())
|
|
|
|
{
|
|
|
|
int nImages = bookCtrl->GetImageList()->GetImageCount();
|
|
|
|
if (nImages > 0)
|
|
|
|
{
|
|
|
|
return bookCtrl->GetPageCount() % nImages;
|
|
|
|
}
|
|
|
|
}
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void CreateInitialPages(wxBookCtrl *parent)
|
|
|
|
{
|
|
|
|
// Create and add some panels to the notebook
|
|
|
|
|
|
|
|
wxPanel *panel = CreateRadioButtonsPage(parent);
|
|
|
|
parent->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(parent) );
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
panel = CreateVetoPage(parent);
|
|
|
|
parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) );
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
panel = CreateBigButtonPage(parent);
|
|
|
|
parent->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(parent) );
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
panel = CreateInsertPage(parent);
|
|
|
|
parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) );
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
parent->SetSelection(1);
|
2002-07-19 19:57:58 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *CreatePage(wxBookCtrl *parent, const wxString&pageName)
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
if
|
|
|
|
(
|
|
|
|
pageName.Contains(INSERTED_PAGE_NAME)
|
|
|
|
|| pageName.Contains(ADDED_PAGE_NAME)
|
|
|
|
)
|
2002-07-19 19:57:58 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
return CreateUserCreatedPage(parent);
|
2002-07-19 19:57:58 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
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;
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2002-07-19 19:57:58 +00:00
|
|
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
|
|
|
|
long style)
|
2004-05-20 11:00:13 +00:00
|
|
|
: wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style)
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
m_type = ID_BOOK_NOTEBOOK;
|
|
|
|
m_orient = ID_ORIENT_DEFAULT;
|
|
|
|
m_chkShowImages = true;
|
|
|
|
m_multi = false;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
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;
|
2004-10-06 20:11:24 +00:00
|
|
|
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"));
|
2004-09-17 17:39:53 +00:00
|
|
|
|
|
|
|
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"));
|
2004-10-06 20:11:24 +00:00
|
|
|
menuFile->AppendCheckItem(ID_SHOW_IMAGES, wxT("&Show images\tAlt-S"));
|
|
|
|
menuFile->AppendCheckItem(ID_MULTI, wxT("&Multiple lines\tAlt-M"));
|
2004-09-17 17:39:53 +00:00
|
|
|
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;
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
m_notebook = (wxNotebook *) NULL;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_CHOICEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
m_choicebook = (wxChoicebook *) NULL;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_LISTBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
m_listbook = (wxListbook *) NULL;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2002-07-21 14:43:09 +00: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 19:57:58 +00:00
|
|
|
|
2004-05-20 11:00:13 +00:00
|
|
|
m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2003-07-31 13:59:28 +00:00
|
|
|
wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
#if USE_LOG
|
2004-05-20 11:00:13 +00:00
|
|
|
m_text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString,
|
2002-07-19 19:57:58 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
|
|
|
|
|
|
|
|
m_logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) );
|
2004-09-17 17:39:53 +00:00
|
|
|
#endif // USE_LOG
|
2002-07-19 19:57:58 +00:00
|
|
|
|
|
|
|
// Set sizers
|
|
|
|
m_sizerFrame = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
#if USE_LOG
|
|
|
|
m_sizerFrame->Add(m_text, 1, wxEXPAND);
|
|
|
|
#endif // USE_LOG
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
RecreateBooks();
|
2002-07-19 19:57:58 +00:00
|
|
|
|
|
|
|
m_panel->SetSizer(m_sizerFrame);
|
|
|
|
|
|
|
|
m_sizerFrame->Fit(this);
|
2004-06-12 19:38:33 +00:00
|
|
|
m_sizerFrame->SetSizeHints(this);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
|
|
|
Centre(wxBOTH);
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2002-07-19 19:57:58 +00:00
|
|
|
MyFrame::~MyFrame()
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
#if USE_LOG
|
2002-07-19 19:57:58 +00:00
|
|
|
delete wxLog::SetActiveTarget(m_logTargetOld);
|
2004-09-17 17:39:53 +00:00
|
|
|
#endif // USE_LOG
|
2002-07-21 14:43:09 +00:00
|
|
|
|
|
|
|
if (m_imageList)
|
|
|
|
{
|
|
|
|
delete m_imageList;
|
|
|
|
m_imageList = (wxImageList *) NULL;
|
|
|
|
}
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
int MyFrame::SelectFlag(int id, int nb, int lb, int chb)
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
switch (id)
|
2002-07-19 19:57:58 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
case ID_NOTEBOOK: return nb;
|
|
|
|
case ID_LISTBOOK: return lb;
|
|
|
|
case ID_CHOICEBOOK: return chb;
|
2002-07-19 19:57:58 +00:00
|
|
|
}
|
2004-09-17 17:39:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
#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 \
|
|
|
|
{ \
|
2004-11-19 16:49:15 +00:00
|
|
|
CreateInitialPages(newBook); \
|
2004-09-17 17:39:53 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, 4); \
|
|
|
|
\
|
|
|
|
m_sizerFrame->Hide(newBook); \
|
|
|
|
}
|
2004-02-07 20:20:29 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::RecreateBooks()
|
|
|
|
{
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
RECREATE( wxNotebook , ID_NOTEBOOK , notebook , m_notebook );
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_LISTBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
RECREATE( wxListbook , ID_LISTBOOK , listbook , m_listbook );
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_CHOICEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
RECREATE( wxChoicebook , ID_CHOICEBOOK , choicebook , m_choicebook );
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
ShowCurrentBook();
|
|
|
|
}
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxBookCtrl *MyFrame::GetCurrentBook()
|
|
|
|
{
|
|
|
|
switch (m_type)
|
2002-07-21 14:43:09 +00:00
|
|
|
{
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
case ID_BOOK_NOTEBOOK: return m_notebook;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_LISTBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
case ID_BOOK_LISTBOOK: return m_listbook;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_CHOICEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
case ID_BOOK_CHOICEBOOK: return m_choicebook;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2002-07-21 14:43:09 +00:00
|
|
|
}
|
2004-09-17 17:39:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::ShowCurrentBook()
|
|
|
|
{
|
|
|
|
switch(m_type)
|
2002-07-19 19:57:58 +00:00
|
|
|
{
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
case ID_BOOK_NOTEBOOK: if(m_notebook) m_sizerFrame->Show(m_notebook); break;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_LISTBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
case ID_BOOK_LISTBOOK: if(m_listbook) m_sizerFrame->Show(m_listbook); break;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_CHOICEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
case ID_BOOK_CHOICEBOOK: if(m_choicebook) m_sizerFrame->Show(m_choicebook); break;
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2002-07-19 19:57:58 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
m_sizerFrame->Layout();
|
2002-07-19 19:57:58 +00:00
|
|
|
}
|
|
|
|
|
1998-10-26 18:32:07 +00:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2004-09-17 17:39:53 +00:00
|
|
|
// 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
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2002-07-19 19:57:58 +00:00
|
|
|
EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, MyFrame::OnNotebook)
|
|
|
|
EVT_NOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, MyFrame::OnNotebook)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_LISTBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
EVT_LISTBOOK_PAGE_CHANGED(ID_LISTBOOK, MyFrame::OnListbook)
|
|
|
|
EVT_LISTBOOK_PAGE_CHANGING(ID_LISTBOOK, MyFrame::OnListbook)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_CHOICEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
EVT_CHOICEBOOK_PAGE_CHANGED(ID_CHOICEBOOK, MyFrame::OnChoicebook)
|
|
|
|
EVT_CHOICEBOOK_PAGE_CHANGING(ID_CHOICEBOOK, MyFrame::OnChoicebook)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
// Update title in idle time
|
1999-06-24 21:27:52 +00:00
|
|
|
EVT_IDLE(MyFrame::OnIdle)
|
1998-10-26 18:32:07 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnType(wxCommandEvent& event)
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxBookCtrl *currBook = GetCurrentBook();
|
1998-10-26 18:32:07 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
m_type = event.GetId();
|
2000-02-29 01:49:05 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
if (currBook)
|
|
|
|
m_sizerFrame->Hide(currBook);
|
2000-02-29 01:49:05 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
ShowCurrentBook();
|
2000-02-29 01:49:05 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnOrient(wxCommandEvent& event)
|
2000-02-29 01:49:05 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
m_orient = event.GetId();
|
|
|
|
RecreateBooks();
|
|
|
|
m_sizerFrame->Layout();
|
|
|
|
}
|
2000-02-29 01:49:05 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnShowImages(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_chkShowImages = event.IsChecked();
|
|
|
|
RecreateBooks();
|
|
|
|
m_sizerFrame->Layout();
|
|
|
|
}
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnMulti(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_multi = event.IsChecked();
|
|
|
|
RecreateBooks();
|
|
|
|
m_sizerFrame->Layout();
|
|
|
|
wxLogMessage(_T("Multiline setting works only in wxNotebook."));
|
|
|
|
}
|
2000-02-29 01:49:05 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Close();
|
1999-05-20 14:32:04 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
|
2002-08-16 00:09:29 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
static unsigned s_pageAdded = 0;
|
2002-08-16 00:09:29 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
wxBookCtrl *currBook = GetCurrentBook();
|
|
|
|
|
|
|
|
if ( currBook )
|
2002-08-16 00:09:29 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
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) );
|
2002-08-16 00:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event))
|
1999-05-25 10:40:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
static unsigned s_pageIns = 0;
|
|
|
|
|
|
|
|
wxBookCtrl *currBook = GetCurrentBook();
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
if ( currBook )
|
2000-07-15 19:51:35 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxPanel *panel = CreateUserCreatedPage( currBook );
|
|
|
|
|
|
|
|
currBook->InsertPage( 0, panel,
|
|
|
|
wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++s_pageIns), false,
|
|
|
|
GetIconIndex(currBook) );
|
|
|
|
|
|
|
|
currBook->SetSelection(0);
|
2000-07-15 19:51:35 +00:00
|
|
|
}
|
1999-05-25 10:40:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event))
|
2000-02-22 15:29:59 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxBookCtrl *currBook = GetCurrentBook();
|
2000-02-22 15:29:59 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
if ( currBook )
|
|
|
|
{
|
|
|
|
int sel = currBook->GetSelection();
|
|
|
|
|
|
|
|
if (sel != wxNOT_FOUND)
|
|
|
|
{
|
|
|
|
currBook->DeletePage(sel);
|
|
|
|
}
|
|
|
|
}
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnDeleteLastPage(wxCommandEvent& WXUNUSED(event))
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
wxBookCtrl *currBook = GetCurrentBook();
|
1999-08-02 21:31:09 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
if ( currBook )
|
2002-07-19 19:57:58 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
int page = currBook->GetPageCount();
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
if ( page != 0 )
|
|
|
|
{
|
|
|
|
currBook->DeletePage(page - 1);
|
2002-07-19 19:57:58 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-17 17:39:53 +00:00
|
|
|
}
|
1998-10-26 18:32:07 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnNextPage(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBookCtrl *currBook = GetCurrentBook();
|
1998-10-26 18:32:07 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
if ( currBook )
|
|
|
|
{
|
|
|
|
currBook->AdvanceSelection();
|
|
|
|
}
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2002-07-19 19:57:58 +00:00
|
|
|
void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
|
1999-06-24 21:27:52 +00:00
|
|
|
{
|
2004-09-17 17:39:53 +00:00
|
|
|
static int s_nPages = wxNOT_FOUND;
|
|
|
|
static int s_nSel = wxNOT_FOUND;
|
|
|
|
static wxBookCtrl *s_currBook = NULL;
|
|
|
|
|
|
|
|
wxBookCtrl *currBook = GetCurrentBook();
|
1999-06-24 21:27:52 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
int nPages = currBook ? currBook->GetPageCount() : 0;
|
|
|
|
int nSel = currBook ? currBook->GetSelection() : wxNOT_FOUND;
|
|
|
|
|
|
|
|
if ( nPages != s_nPages || nSel != s_nSel || s_currBook != currBook )
|
1999-06-24 21:27:52 +00:00
|
|
|
{
|
|
|
|
s_nPages = nPages;
|
|
|
|
s_nSel = nSel;
|
2004-09-17 17:39:53 +00:00
|
|
|
s_currBook = currBook;
|
|
|
|
|
|
|
|
wxString selection;
|
|
|
|
if ( nSel == wxNOT_FOUND )
|
|
|
|
selection << wxT("not found");
|
|
|
|
else
|
|
|
|
selection << nSel;
|
1999-06-24 21:27:52 +00:00
|
|
|
|
|
|
|
wxString title;
|
2004-09-17 17:39:53 +00:00
|
|
|
title.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages, selection.c_str());
|
1999-06-24 21:27:52 +00:00
|
|
|
|
|
|
|
SetTitle(title);
|
|
|
|
}
|
|
|
|
}
|
2002-08-16 00:09:29 +00:00
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
#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(); \
|
2002-08-16 00:09:29 +00:00
|
|
|
}
|
|
|
|
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
BOOKEVENT(OnNotebook,wxNotebookEvent,"wxNotebook",wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,s_numNotebookEvents)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_CHOICEBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
BOOKEVENT(OnChoicebook,wxChoicebookEvent,"wxChoicebook",wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,s_numChoicebookEvents)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_LISTBOOK
|
2004-09-17 17:39:53 +00:00
|
|
|
BOOKEVENT(OnListbook,wxListbookEvent,"wxListbook",wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,s_numListbookEvents)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|