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"
|
2006-06-14 15:54:24 +00:00
|
|
|
#include "wx/cshelp.h"
|
|
|
|
#include "wx/utils.h"
|
2000-03-14 19:24:14 +00:00
|
|
|
#include "notebook.h"
|
1998-10-26 18:32:07 +00:00
|
|
|
|
2005-06-17 14:36:24 +00:00
|
|
|
#if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
{
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
wxHelpProvider::Set( new wxSimpleHelpProvider );
|
|
|
|
#endif
|
|
|
|
|
2002-07-19 19:57:58 +00:00
|
|
|
// Create the main window
|
2005-10-09 18:40:36 +00:00
|
|
|
MyFrame *frame = new MyFrame();
|
2002-07-19 19:57:58 +00:00
|
|
|
|
|
|
|
// 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-11-23 11:45:07 +00:00
|
|
|
wxPanel *CreateUserCreatedPage(wxBookCtrlBase *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
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
panel->SetHelpText( wxT( "Panel with a Button" ) );
|
|
|
|
#endif
|
|
|
|
|
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-11-23 11:45:07 +00:00
|
|
|
wxPanel *CreateRadioButtonsPage(wxBookCtrlBase *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
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
panel->SetHelpText( wxT( "Panel with some Radio Buttons" ) );
|
|
|
|
#endif
|
|
|
|
|
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-11-23 11:45:07 +00:00
|
|
|
wxPanel *CreateVetoPage(wxBookCtrlBase *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
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
panel->SetHelpText( wxT( "An empty panel" ) );
|
|
|
|
#endif
|
|
|
|
|
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-11-23 11:45:07 +00:00
|
|
|
wxPanel *CreateBigButtonPage(wxBookCtrlBase *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
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
panel->SetHelpText( wxT( "Panel with a maximized button" ) );
|
|
|
|
#endif
|
|
|
|
|
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-11-23 11:45:07 +00:00
|
|
|
wxPanel *CreateInsertPage(wxBookCtrlBase *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
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
panel->SetHelpText( wxT( "Maroon panel" ) );
|
|
|
|
#endif
|
|
|
|
|
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-11-23 11:45:07 +00:00
|
|
|
int GetIconIndex(wxBookCtrlBase* 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-11-23 11:45:07 +00:00
|
|
|
void CreateInitialPages(wxBookCtrlBase *parent)
|
2004-09-17 17:39:53 +00:00
|
|
|
{
|
|
|
|
// 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-11-23 11:45:07 +00:00
|
|
|
wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2005-10-09 18:40:36 +00:00
|
|
|
if ( pageName.Contains(INSERTED_PAGE_NAME) ||
|
|
|
|
pageName.Contains(ADDED_PAGE_NAME) ||
|
|
|
|
pageName.Contains(ADDED_SUB_PAGE_NAME) ||
|
|
|
|
pageName.Contains(ADDED_PAGE_NAME_BEFORE) )
|
2004-09-17 17:39:53 +00:00
|
|
|
return CreateUserCreatedPage(parent);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
if ( pageName == I_WAS_INSERTED_PAGE_NAME )
|
2004-09-17 17:39:53 +00:00
|
|
|
return CreateInsertPage(parent);
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
if ( pageName == VETO_PAGE_NAME )
|
2004-09-17 17:39:53 +00:00
|
|
|
return CreateVetoPage(parent);
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
if ( pageName == RADIOBUTTONS_PAGE_NAME )
|
2004-09-17 17:39:53 +00:00
|
|
|
return CreateRadioButtonsPage(parent);
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
if ( pageName == MAXIMIZED_BUTTON_PAGE_NAME )
|
2004-09-17 17:39:53 +00:00
|
|
|
return CreateBigButtonPage(parent);
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
wxFAIL_MSG( _T("unknown page name") );
|
2004-09-17 17:39:53 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
return NULL;
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
MyFrame::MyFrame()
|
2006-06-14 18:32:26 +00:00
|
|
|
: wxFrame(NULL, wxID_ANY, wxString(wxT("wxWidgets book controls sample")))
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
SetExtraStyle(wxFRAME_EX_CONTEXTHELP);
|
|
|
|
#endif // wxUSE_HELP
|
|
|
|
|
2005-03-10 19:34:58 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
m_type = Type_Notebook;
|
2005-03-10 19:34:58 +00:00
|
|
|
#elif wxUSE_CHOICEBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
m_type = Type_Choicebook;
|
2005-03-10 19:34:58 +00:00
|
|
|
#elif wxUSE_LISTBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
m_type = Type_Listbook;
|
|
|
|
#elif wxUSE_TREEBOOK
|
|
|
|
m_type = Type_Treebook;
|
2005-03-10 19:34:58 +00:00
|
|
|
#elif
|
|
|
|
#error "Don't use Notebook sample without any book enabled in wxWidgets build!"
|
|
|
|
#endif
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
m_orient = ID_ORIENT_DEFAULT;
|
|
|
|
m_chkShowImages = true;
|
|
|
|
m_multi = false;
|
|
|
|
|
2005-06-17 14:36:24 +00:00
|
|
|
SetIcon(wxICON(sample));
|
2004-09-17 17:39:53 +00:00
|
|
|
|
2005-06-17 14:36:24 +00:00
|
|
|
// menu of the sample
|
2004-09-17 17:39:53 +00:00
|
|
|
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
|
2005-10-09 18:40:36 +00:00
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
menuType->AppendRadioItem(ID_BOOK_TREEBOOK, wxT("&Treebook\tCtrl-4"));
|
|
|
|
#endif
|
2006-01-30 15:40:32 +00:00
|
|
|
#if wxUSE_TOOLBOOK
|
|
|
|
menuType->AppendRadioItem(ID_BOOK_TOOLBOOK, wxT("T&oolbook\tCtrl-5"));
|
|
|
|
#endif
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
menuType->Check(ID_BOOK_NOTEBOOK + m_type, true);
|
2004-09-17 17:39:53 +00:00
|
|
|
|
|
|
|
wxMenu *menuOrient = new wxMenu;
|
2005-10-09 18:40:36 +00:00
|
|
|
menuOrient->AppendRadioItem(ID_ORIENT_DEFAULT, wxT("&Default\tCtrl-5"));
|
|
|
|
menuOrient->AppendRadioItem(ID_ORIENT_TOP, wxT("&Top\tCtrl-6"));
|
|
|
|
menuOrient->AppendRadioItem(ID_ORIENT_BOTTOM, wxT("&Bottom\tCtrl-7"));
|
|
|
|
menuOrient->AppendRadioItem(ID_ORIENT_LEFT, wxT("&Left\tCtrl-8"));
|
|
|
|
menuOrient->AppendRadioItem(ID_ORIENT_RIGHT, wxT("&Right\tCtrl-9"));
|
|
|
|
|
2006-06-14 15:54:24 +00:00
|
|
|
wxMenu *menuPageOperations = new wxMenu;
|
|
|
|
menuPageOperations->Append(ID_ADD_PAGE, wxT("&Add page\tAlt-A"));
|
2006-11-04 18:24:07 +00:00
|
|
|
menuPageOperations->Append(ID_ADD_PAGE_NO_SELECT, wxT("&Add page (don't select)\tAlt-B"));
|
2006-06-14 15:54:24 +00:00
|
|
|
menuPageOperations->Append(ID_INSERT_PAGE, wxT("&Insert page\tAlt-I"));
|
|
|
|
menuPageOperations->Append(ID_DELETE_CUR_PAGE, wxT("&Delete current page\tAlt-D"));
|
|
|
|
menuPageOperations->Append(ID_DELETE_LAST_PAGE, wxT("D&elete last page\tAlt-L"));
|
|
|
|
menuPageOperations->Append(ID_NEXT_PAGE, wxT("&Next page\tAlt-N"));
|
2005-10-09 18:40:36 +00:00
|
|
|
#if wxUSE_TREEBOOK
|
2006-06-14 15:54:24 +00:00
|
|
|
menuPageOperations->AppendSeparator();
|
|
|
|
menuPageOperations->Append(ID_ADD_PAGE_BEFORE, wxT("Insert page &before\tAlt-B"));
|
|
|
|
menuPageOperations->Append(ID_ADD_SUB_PAGE, wxT("Add s&ub page\tAlt-U"));
|
2005-10-09 18:40:36 +00:00
|
|
|
#endif
|
2006-10-08 17:37:23 +00:00
|
|
|
menuPageOperations->AppendSeparator();
|
|
|
|
menuPageOperations->Append(ID_GO_HOME, wxT("Go to the first page\tCtrl-F"));
|
2004-09-17 17:39:53 +00:00
|
|
|
|
2006-06-14 15:54:24 +00:00
|
|
|
wxMenu *menuOperations = new wxMenu;
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
menuOperations->Append(ID_CONTEXT_HELP, wxT("&Context help\tCtrl-F1"));
|
|
|
|
#endif // wxUSE_HELP
|
2006-06-14 15:54:24 +00:00
|
|
|
menuOperations->Append(ID_HITTEST, wxT("&Hit test\tCtrl-H"));
|
|
|
|
|
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"));
|
2006-06-14 15:54:24 +00:00
|
|
|
menuBar->Append(menuPageOperations, wxT("&Pages"));
|
2005-10-09 18:40:36 +00:00
|
|
|
menuBar->Append(menuOperations, wxT("&Operations"));
|
2004-09-17 17:39:53 +00:00
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
// books creation
|
2005-10-09 18:40:36 +00:00
|
|
|
m_panel = NULL;
|
|
|
|
m_bookCtrl = NULL;
|
2002-07-21 14:43:09 +00:00
|
|
|
|
|
|
|
// create a dummy image list with a few icons
|
2005-10-09 18:40:36 +00:00
|
|
|
const wxSize imageSize(32, 32);
|
2002-07-21 14:43:09 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
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-21 14:43:09 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
m_panel = new wxPanel(this);
|
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,
|
2005-10-09 18:40:36 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE | wxTE_READONLY);
|
2002-07-19 19:57:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
RecreateBook();
|
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
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
delete m_imageList;
|
1998-10-26 18:32:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
// DISPATCH_ON_TYPE() macro is an ugly way to write the "same" code for
|
|
|
|
// different wxBookCtrlBase-derived classes without duplicating code and
|
|
|
|
// without using templates, it expands into "before <xxx> after" where "xxx"
|
|
|
|
// part is control class-specific
|
|
|
|
#if wxUSE_NOTEBOOK
|
|
|
|
#define CASE_NOTEBOOK(x) case Type_Notebook: x; break;
|
2005-03-13 15:35:33 +00:00
|
|
|
#else
|
2005-10-09 18:40:36 +00:00
|
|
|
#define CASE_NOTEBOOK(x)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2005-10-09 18:40:36 +00:00
|
|
|
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_LISTBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
#define CASE_LISTBOOK(x) case Type_Listbook: x; break;
|
|
|
|
#else
|
|
|
|
#define CASE_LISTBOOK(x)
|
2005-10-09 22:09:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_CHOICEBOOK
|
|
|
|
#define CASE_CHOICEBOOK(x) case Type_Choicebook: x; break;
|
|
|
|
#else
|
|
|
|
#define CASE_CHOICEBOOK(x)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
#define CASE_TREEBOOK(x) case Type_Treebook: x; break;
|
|
|
|
#else
|
|
|
|
#define CASE_TREEBOOK(x)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2006-01-30 15:40:32 +00:00
|
|
|
#if wxUSE_TOOLBOOK
|
|
|
|
#define CASE_TOOLBOOK(x) case Type_Toolbook: x; break;
|
|
|
|
#else
|
|
|
|
#define CASE_TOOLBOOK(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, after) \
|
2005-10-09 18:40:36 +00:00
|
|
|
switch ( m_type ) \
|
|
|
|
{ \
|
|
|
|
CASE_NOTEBOOK(before nb after) \
|
|
|
|
CASE_LISTBOOK(before lb after) \
|
2005-10-09 22:09:35 +00:00
|
|
|
CASE_CHOICEBOOK(before cb after) \
|
2005-10-09 18:40:36 +00:00
|
|
|
CASE_TREEBOOK(before tb after) \
|
2006-01-30 15:40:32 +00:00
|
|
|
CASE_TOOLBOOK(before toolb after) \
|
2005-10-09 18:40:36 +00:00
|
|
|
\
|
|
|
|
default: \
|
|
|
|
wxFAIL_MSG( _T("unknown book control type") ); \
|
|
|
|
}
|
|
|
|
|
2006-01-30 15:40:32 +00:00
|
|
|
int MyFrame::TranslateBookFlag(int nb, int lb, int chb, int tbk, int toolbk) const
|
2005-10-09 18:40:36 +00:00
|
|
|
{
|
|
|
|
int flag = 0;
|
|
|
|
|
2006-01-30 15:40:32 +00:00
|
|
|
DISPATCH_ON_TYPE(flag =, nb, lb, chb, tbk, toolbk, + 0);
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
return flag;
|
2004-09-17 17:39:53 +00:00
|
|
|
}
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
void MyFrame::RecreateBook()
|
2004-09-17 17:39:53 +00:00
|
|
|
{
|
2005-10-09 18:40:36 +00:00
|
|
|
int flags;
|
|
|
|
switch ( m_orient )
|
2002-07-21 14:43:09 +00:00
|
|
|
{
|
2005-10-09 18:40:36 +00:00
|
|
|
case ID_ORIENT_TOP:
|
2005-10-21 19:03:06 +00:00
|
|
|
flags = wxBK_TOP;
|
2005-10-09 18:40:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ORIENT_BOTTOM:
|
2005-10-21 19:03:06 +00:00
|
|
|
flags = wxBK_BOTTOM;
|
2005-10-09 18:40:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ORIENT_LEFT:
|
2005-10-21 19:03:06 +00:00
|
|
|
flags = wxBK_LEFT;
|
2005-10-09 18:40:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_ORIENT_RIGHT:
|
2005-10-21 19:03:06 +00:00
|
|
|
flags = wxBK_RIGHT;
|
2005-10-09 18:40:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-10-21 19:03:06 +00:00
|
|
|
flags = wxBK_DEFAULT;
|
2002-07-21 14:43:09 +00:00
|
|
|
}
|
2002-07-19 19:57:58 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
if ( m_multi && m_type == Type_Notebook )
|
|
|
|
flags |= wxNB_MULTILINE;
|
|
|
|
flags |= wxDOUBLE_BORDER;
|
|
|
|
|
|
|
|
wxBookCtrlBase *oldBook = m_bookCtrl;
|
|
|
|
|
|
|
|
m_bookCtrl = NULL;
|
|
|
|
|
|
|
|
DISPATCH_ON_TYPE(m_bookCtrl = new,
|
|
|
|
wxNotebook,
|
|
|
|
wxListbook,
|
2005-10-09 22:09:35 +00:00
|
|
|
wxChoicebook,
|
2005-10-09 18:40:36 +00:00
|
|
|
wxTreebook,
|
2006-01-30 15:40:32 +00:00
|
|
|
wxToolbook,
|
2005-10-09 18:40:36 +00:00
|
|
|
(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, flags));
|
|
|
|
|
|
|
|
if ( !m_bookCtrl )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_bookCtrl->Hide();
|
|
|
|
|
|
|
|
if ( m_chkShowImages )
|
2002-07-19 19:57:58 +00:00
|
|
|
{
|
2005-10-09 18:40:36 +00:00
|
|
|
m_bookCtrl->SetImageList(m_imageList);
|
2002-07-19 19:57:58 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
if ( oldBook )
|
|
|
|
{
|
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
// we only need the old treebook if we're recreating another treebook
|
|
|
|
wxTreebook *tbkOld = m_type == Type_Treebook
|
|
|
|
? wxDynamicCast(oldBook, wxTreebook)
|
|
|
|
: NULL;
|
|
|
|
#endif // wxUSE_TREEBOOK
|
|
|
|
|
|
|
|
const int count = oldBook->GetPageCount();
|
|
|
|
for ( int n = 0; n < count; n++ )
|
|
|
|
{
|
|
|
|
const int image = GetIconIndex(m_bookCtrl);
|
|
|
|
const wxString str = oldBook->GetPageText(n);
|
|
|
|
|
|
|
|
wxWindow *page = CreatePage(m_bookCtrl, str);
|
|
|
|
|
|
|
|
// treebook complication: need to account for possible parent page
|
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
if ( tbkOld )
|
|
|
|
{
|
|
|
|
const int parent = tbkOld->GetPageParent(n);
|
|
|
|
if ( parent != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
wxStaticCast(m_bookCtrl, wxTreebook)->
|
2006-02-05 12:27:20 +00:00
|
|
|
InsertSubPage(parent, page, str, false, image);
|
2005-10-09 18:40:36 +00:00
|
|
|
|
|
|
|
// skip adding it again below
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // wxUSE_TREEBOOK
|
|
|
|
|
|
|
|
m_bookCtrl->AddPage(page, str, false, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int sel = oldBook->GetSelection();
|
|
|
|
if ( sel != wxNOT_FOUND )
|
|
|
|
m_bookCtrl->SetSelection(sel);
|
|
|
|
|
|
|
|
|
|
|
|
m_sizerFrame->Detach(oldBook);
|
|
|
|
delete oldBook;
|
|
|
|
}
|
|
|
|
else // no old book
|
|
|
|
{
|
|
|
|
CreateInitialPages(m_bookCtrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sizerFrame->Insert(0, m_bookCtrl, wxSizerFlags(5).Expand().Border());
|
|
|
|
|
|
|
|
m_sizerFrame->Show(m_bookCtrl);
|
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
|
2005-10-09 18:40:36 +00:00
|
|
|
EVT_MENU_RANGE(ID_BOOK_NOTEBOOK, ID_BOOK_MAX, MyFrame::OnType)
|
|
|
|
EVT_MENU_RANGE(ID_ORIENT_DEFAULT, ID_ORIENT_MAX, MyFrame::OnOrient)
|
2004-09-17 17:39:53 +00:00
|
|
|
EVT_MENU(ID_SHOW_IMAGES, MyFrame::OnShowImages)
|
|
|
|
EVT_MENU(ID_MULTI, MyFrame::OnMulti)
|
2005-10-09 18:40:36 +00:00
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
2004-09-17 17:39:53 +00:00
|
|
|
|
|
|
|
// Operations menu
|
|
|
|
EVT_MENU(ID_ADD_PAGE, MyFrame::OnAddPage)
|
2006-11-04 18:24:07 +00:00
|
|
|
EVT_MENU(ID_ADD_PAGE_NO_SELECT, MyFrame::OnAddPageNoSelect)
|
2004-09-17 17:39:53 +00:00
|
|
|
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)
|
2006-10-08 17:37:23 +00:00
|
|
|
EVT_MENU(ID_GO_HOME, MyFrame::OnGoHome)
|
2004-09-17 17:39:53 +00:00
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
EVT_MENU(ID_CONTEXT_HELP, MyFrame::OnContextHelp)
|
|
|
|
#endif // wxUSE_HELP
|
2006-06-14 15:54:24 +00:00
|
|
|
EVT_MENU(ID_HITTEST, MyFrame::OnHitTest)
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
// Book controls
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnNotebook)
|
|
|
|
EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnNotebook)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_LISTBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnListbook)
|
|
|
|
EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnListbook)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
|
|
|
#if wxUSE_CHOICEBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnChoicebook)
|
|
|
|
EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnChoicebook)
|
|
|
|
#endif
|
2005-10-09 22:09:35 +00:00
|
|
|
#if wxUSE_TREEBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
EVT_TREEBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnTreebook)
|
|
|
|
EVT_TREEBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnTreebook)
|
2005-10-09 22:09:35 +00:00
|
|
|
|
|
|
|
EVT_MENU(ID_ADD_SUB_PAGE, MyFrame::OnAddSubPage)
|
|
|
|
EVT_MENU(ID_ADD_PAGE_BEFORE, MyFrame::OnAddPageBefore)
|
|
|
|
EVT_UPDATE_UI_RANGE(ID_ADD_PAGE_BEFORE, ID_ADD_SUB_PAGE,
|
|
|
|
MyFrame::OnUpdateTreeMenu)
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2006-01-30 15:40:32 +00:00
|
|
|
#if wxUSE_TOOLBOOK
|
|
|
|
EVT_TOOLBOOK_PAGE_CHANGED(wxID_ANY, MyFrame::OnToolbook)
|
|
|
|
EVT_TOOLBOOK_PAGE_CHANGING(wxID_ANY, MyFrame::OnToolbook)
|
|
|
|
#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()
|
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
|
|
|
|
void MyFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// launches local event loop
|
|
|
|
wxContextHelp ch( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_HELP
|
|
|
|
|
2006-06-14 15:54:24 +00:00
|
|
|
void MyFrame::AddFlagStrIfFlagPresent(wxString & flagStr, long flags, long flag, const wxChar * flagName) const
|
|
|
|
{
|
|
|
|
if( (flags & flag) == flag )
|
|
|
|
{
|
|
|
|
if( !flagStr.empty() )
|
|
|
|
flagStr += _T(" | ");
|
|
|
|
flagStr += flagName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnHitTest(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBookCtrlBase * book = GetCurrentBook();
|
|
|
|
const wxPoint pt = ::wxGetMousePosition();
|
|
|
|
|
|
|
|
long flags;
|
|
|
|
int pagePos = book->HitTest( book->ScreenToClient(pt), &flags );
|
|
|
|
|
|
|
|
wxString flagsStr;
|
|
|
|
|
2006-07-05 12:21:13 +00:00
|
|
|
AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_NOWHERE, _T("wxBK_HITTEST_NOWHERE") );
|
|
|
|
AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONICON, _T("wxBK_HITTEST_ONICON") );
|
|
|
|
AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONLABEL, _T("wxBK_HITTEST_ONLABEL") );
|
|
|
|
AddFlagStrIfFlagPresent( flagsStr, flags, wxBK_HITTEST_ONPAGE, _T("wxBK_HITTEST_ONPAGE") );
|
2006-06-14 15:54:24 +00:00
|
|
|
|
|
|
|
wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"),
|
|
|
|
pt.x,
|
|
|
|
pt.y,
|
|
|
|
pagePos,
|
|
|
|
flagsStr.c_str());
|
|
|
|
}
|
|
|
|
|
2004-09-17 17:39:53 +00:00
|
|
|
void MyFrame::OnType(wxCommandEvent& event)
|
1998-10-26 18:32:07 +00:00
|
|
|
{
|
2005-10-09 18:40:36 +00:00
|
|
|
m_type = wx_static_cast(BookType, event.GetId() - ID_BOOK_NOTEBOOK);
|
|
|
|
|
|
|
|
if ( m_bookCtrl )
|
|
|
|
m_sizerFrame->Hide(m_bookCtrl);
|
1998-10-26 18:32:07 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
RecreateBook();
|
|
|
|
}
|
2000-02-29 01:49:05 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
#if wxUSE_TREEBOOK
|
2000-02-29 01:49:05 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable(m_type == Type_Treebook);
|
2000-02-29 01:49:05 +00:00
|
|
|
}
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
#endif // wxUSE_TREEBOOK
|
|
|
|
|
|
|
|
|
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();
|
2005-10-09 18:40:36 +00:00
|
|
|
RecreateBook();
|
2004-09-17 17:39:53 +00:00
|
|
|
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();
|
2005-10-09 18:40:36 +00:00
|
|
|
RecreateBook();
|
2004-09-17 17:39:53 +00:00
|
|
|
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();
|
2005-10-09 18:40:36 +00:00
|
|
|
RecreateBook();
|
2004-09-17 17:39:53 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
wxPanel *MyFrame::CreateNewPage() const
|
2002-08-16 00:09:29 +00:00
|
|
|
{
|
2005-10-09 18:40:36 +00:00
|
|
|
wxPanel *panel = new wxPanel(m_bookCtrl, wxID_ANY );
|
2006-06-14 15:54:24 +00:00
|
|
|
|
2006-06-14 18:32:26 +00:00
|
|
|
#if wxUSE_HELP
|
|
|
|
panel->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) );
|
|
|
|
#endif
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
(void) new wxButton(panel, wxID_ANY, wxT("First button"), wxPoint(10, 10));
|
|
|
|
(void) new wxButton(panel, wxID_ANY, wxT("Second button"), wxPoint(50, 100));
|
|
|
|
|
|
|
|
return panel;
|
|
|
|
}
|
2002-08-16 00:09:29 +00:00
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-11-23 11:45:07 +00:00
|
|
|
wxBookCtrlBase *currBook = GetCurrentBook();
|
2004-09-17 17:39:53 +00:00
|
|
|
|
|
|
|
if ( currBook )
|
2002-08-16 00:09:29 +00:00
|
|
|
{
|
2005-10-09 18:40:36 +00:00
|
|
|
static unsigned s_pageAdded = 0;
|
|
|
|
currBook->AddPage(CreateNewPage(),
|
|
|
|
wxString::Format
|
|
|
|
(
|
|
|
|
ADDED_PAGE_NAME wxT("%u"),
|
|
|
|
++s_pageAdded
|
|
|
|
),
|
|
|
|
true,
|
|
|
|
GetIconIndex(currBook));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-04 18:24:07 +00:00
|
|
|
void MyFrame::OnAddPageNoSelect(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBookCtrlBase *currBook = GetCurrentBook();
|
|
|
|
|
|
|
|
if ( currBook )
|
|
|
|
{
|
|
|
|
static unsigned s_pageAdded = 0;
|
|
|
|
currBook->AddPage(CreateNewPage(),
|
|
|
|
wxString::Format
|
|
|
|
(
|
|
|
|
ADDED_PAGE_NAME wxT("%u"),
|
|
|
|
++s_pageAdded
|
|
|
|
),
|
|
|
|
false,
|
|
|
|
GetIconIndex(currBook));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
void MyFrame::OnAddSubPage(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxTreebook *currBook = wxDynamicCast(GetCurrentBook(), wxTreebook);
|
|
|
|
if ( currBook )
|
|
|
|
{
|
|
|
|
const int selPos = currBook->GetSelection();
|
|
|
|
if ( selPos == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
wxLogError(_T("Select the parent page first!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned s_subPageAdded = 0;
|
2006-02-05 12:27:20 +00:00
|
|
|
currBook->InsertSubPage
|
|
|
|
(
|
|
|
|
selPos,
|
|
|
|
CreateNewPage(),
|
|
|
|
wxString::Format
|
|
|
|
(
|
|
|
|
ADDED_SUB_PAGE_NAME wxT("%u"),
|
|
|
|
++s_subPageAdded
|
|
|
|
),
|
|
|
|
true,
|
|
|
|
GetIconIndex(currBook)
|
|
|
|
);
|
2005-10-09 18:40:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAddPageBefore(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBookCtrlBase *currBook = GetCurrentBook();
|
|
|
|
if ( currBook )
|
|
|
|
{
|
|
|
|
const int selPos = currBook->GetSelection();
|
|
|
|
if ( selPos == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
wxLogError(_T("Select the parent page first!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned s_subPageAdded = 0;
|
|
|
|
currBook->InsertPage(selPos,
|
|
|
|
CreateNewPage(),
|
|
|
|
wxString::Format
|
|
|
|
(
|
|
|
|
ADDED_PAGE_NAME_BEFORE wxT("%u"),
|
|
|
|
++s_subPageAdded
|
|
|
|
),
|
|
|
|
true,
|
|
|
|
GetIconIndex(currBook));
|
2002-08-16 00:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-09 18:40:36 +00:00
|
|
|
#endif // wxUSE_TREEBOOK
|
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;
|
|
|
|
|
2004-11-23 11:45:07 +00:00
|
|
|
wxBookCtrlBase *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-11-23 11:45:07 +00:00
|
|
|
wxBookCtrlBase *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-11-23 11:45:07 +00:00
|
|
|
wxBookCtrlBase *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))
|
|
|
|
{
|
2004-11-23 11:45:07 +00:00
|
|
|
wxBookCtrlBase *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
|
|
|
}
|
|
|
|
|
2006-10-08 17:37:23 +00:00
|
|
|
void MyFrame::OnGoHome(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxBookCtrlBase *currBook = GetCurrentBook();
|
|
|
|
|
|
|
|
if ( currBook )
|
|
|
|
{
|
|
|
|
// ChangeSelection shouldn't send any events, SetSelection() should
|
|
|
|
currBook->ChangeSelection(0);
|
|
|
|
//currBook->SetSelection(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2004-11-23 11:45:07 +00:00
|
|
|
static wxBookCtrlBase *s_currBook = NULL;
|
2004-09-17 17:39:53 +00:00
|
|
|
|
2004-11-23 11:45:07 +00:00
|
|
|
wxBookCtrlBase *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
|
|
|
|
2005-10-09 18:40:36 +00:00
|
|
|
void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent& event)
|
|
|
|
{
|
|
|
|
static const struct EventInfo
|
|
|
|
{
|
|
|
|
wxEventType typeChanged,
|
|
|
|
typeChanging;
|
|
|
|
const wxChar *name;
|
|
|
|
} events[] =
|
|
|
|
{
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_NOTEBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
{
|
|
|
|
wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
|
|
|
|
wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,
|
|
|
|
_T("wxNotebook")
|
|
|
|
},
|
|
|
|
#endif // wxUSE_NOTEBOOK
|
2004-09-24 13:45:52 +00:00
|
|
|
#if wxUSE_LISTBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
{
|
|
|
|
wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED,
|
|
|
|
wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING,
|
|
|
|
_T("wxListbook")
|
|
|
|
},
|
|
|
|
#endif // wxUSE_LISTBOOK
|
2005-10-09 22:09:35 +00:00
|
|
|
#if wxUSE_CHOICEBOOK
|
|
|
|
{
|
|
|
|
wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,
|
|
|
|
wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING,
|
|
|
|
_T("wxChoicebook")
|
|
|
|
},
|
|
|
|
#endif // wxUSE_CHOICEBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
{
|
|
|
|
wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED,
|
|
|
|
wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING,
|
|
|
|
_T("wxTreebook")
|
|
|
|
},
|
|
|
|
#endif // wxUSE_TREEBOOK
|
2006-01-30 15:40:32 +00:00
|
|
|
#if wxUSE_TOOLBOOK
|
|
|
|
{
|
|
|
|
wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED,
|
|
|
|
wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING,
|
|
|
|
_T("wxToolbook")
|
|
|
|
},
|
|
|
|
#endif // wxUSE_TOOLBOOK
|
2005-10-09 18:40:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
wxString nameEvent,
|
|
|
|
nameControl,
|
|
|
|
veto;
|
|
|
|
const wxEventType eventType = event.GetEventType();
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(events); n++ )
|
|
|
|
{
|
|
|
|
const EventInfo& ei = events[n];
|
|
|
|
if ( eventType == ei.typeChanged )
|
|
|
|
{
|
|
|
|
nameEvent = wxT("Changed");
|
|
|
|
}
|
|
|
|
else if ( eventType == ei.typeChanging )
|
|
|
|
{
|
|
|
|
const int idx = event.GetOldSelection();
|
2005-11-16 16:31:35 +00:00
|
|
|
|
|
|
|
// NB: can't use wxStaticCast here as wxBookCtrlBase is not in
|
|
|
|
// wxRTTI
|
2005-10-09 18:40:36 +00:00
|
|
|
const wxBookCtrlBase * const
|
2005-11-16 16:31:35 +00:00
|
|
|
book = wx_static_cast(wxBookCtrlBase *, event.GetEventObject());
|
2005-10-09 18:40:36 +00:00
|
|
|
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();
|
|
|
|
veto = _T(" (vetoed)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nameEvent = wxT("Changing");
|
|
|
|
}
|
|
|
|
else // skip end of the loop
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nameControl = ei.name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s_num = 0;
|
|
|
|
|
|
|
|
wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d%s"),
|
|
|
|
++s_num,
|
|
|
|
nameControl.c_str(),
|
|
|
|
nameEvent.c_str(),
|
|
|
|
eventType,
|
|
|
|
event.GetSelection(),
|
|
|
|
event.GetOldSelection(),
|
|
|
|
veto.c_str());
|
|
|
|
|
|
|
|
#if USE_LOG
|
|
|
|
m_text->SetInsertionPointEnd();
|
2004-09-24 13:45:52 +00:00
|
|
|
#endif
|
2005-10-09 18:40:36 +00:00
|
|
|
}
|